Skip to content

Instantly share code, notes, and snippets.

@summivox
Created October 21, 2017 02:44
Show Gist options
  • Save summivox/ffa7e273021a06f044dc1d4b5fa85168 to your computer and use it in GitHub Desktop.
Save summivox/ffa7e273021a06f044dc1d4b5fa85168 to your computer and use it in GitHub Desktop.
XHRA-2HPA configuration file for Untz v4.6
# vim: ft=python
from itertools import chain
def flatten(x):
return list(chain.from_iterable(x))
G = globals()
# USB Identification
VENDOR_ID = 0x20B1
PRODUCT_ID = 0x3066
# Format of the given USB strings
# ASCII = 0
# UNICODE = 1
# If format is mentioned as 1 (UNICODE), then the following
# USB strings are interpreted as unicode instead of ascii.
STRING_FORMAT = 0
VENDOR_STRING = "summivox"
PRODUCT_STRING = "Untz v4.6"
SERIAL_STRING = "0003"
LANGUAGE_ID = 0x0409
# Power options
MAX_POWER = 0xFA
SELF_POWER_ENABLE = 0
# USB Audio class 1.0 enable/disable
UAC_1_ENABLE = 0
# USB HID inputs enable/disable
HID_INPUTS_ENABLE = 0
# I2S data formats
# I2S_DEFAULT = 0
# I2S_LEFT_ALIGNED = 1
# I2S_RIGHT_ALIGNED = 2
#
I2S_DATA_FORMAT = 0
# Audio sample rates enable/disable
# Bitmap to enable/disable each supported sample rate.
# | Bit7 | Bit6 | Bit5 | Bit4 | Bit3 | Bit2 | Bit1 | Bit0 |
# | 352.8K | 176.4K | 88.2K | 44.1K | 384K | 192K | 96K | 48K |
SAMPLE_RATE_BITMAP = 0b01110111
# Any variables required for writing event actions can be declared here
# Example: I2C address of the DAC can be set as a variable called
# DAC_I2C_ADDR = 0x48; For ease of writing I2C_WRITE command, the register
# addresses can also be set to variables.
EN_48 = 2 # LOW => no clock, HIGH => play 48k multiple audio
EN_44 = 3 # LOW => no clock, HIGH => play 44.1k multiple audio
OEN = 5 # LOW => output muted, HIGH => output enabled
MUTE = 6 # LOW => play audio, HIGH => muted
NRST = 7 # LOW => reset, HIGH => play audio
# change clock:
# - mute, wait,
# - reset, disable both clocks, wait,
# - enable clock, wait,
# - no reset, wait
CLOCK_BEFORE = [
GPIO(MUTE, HIGH),
DELAY_MS(10),
GPIO(OEN, LOW),
DELAY_MS(1),
GPIO(NRST, LOW),
GPIO(EN_48, LOW),
GPIO(EN_44, LOW),
DELAY_MS(1),
]
CLOCK_AFTER = [
DELAY_MS(10),
GPIO(NRST, HIGH),
DELAY_MS(10),
GPIO(OEN, HIGH),
DELAY_MS(1),
]
EVT_SYS_INIT = [
GPIO(EN_48, LOW),
GPIO(EN_44, LOW),
GPIO(OEN, LOW),
GPIO(MUTE, HIGH),
GPIO(NRST, LOW),
]
EVT_USB_CONNECT = []
EVT_USB_DISCONNECT = []
EVT_STRM_START = [
GPIO(MUTE, LOW),
]
EVT_STRM_STOP = [
GPIO(MUTE, HIGH),
]
for ev in ['EVT_SEL_48K', 'EVT_SEL_96K', 'EVT_SEL_192K', 'EVT_SEL_384K']:
G[ev] = flatten([
CLOCK_BEFORE,
GPIO(EN_48, HIGH),
CLOCK_AFTER,
])
for ev in ['EVT_SEL_44_1K', 'EVT_SEL_88_2K', 'EVT_SEL_176_4K', 'EVT_SEL_352_8K']:
G[ev] = flatten([
CLOCK_BEFORE,
GPIO(EN_44, HIGH),
CLOCK_AFTER,
])
EVT_DSD_ACTIVE = []
EVT_PCM_ACTIVE = []
EVT_SEL_DSD128 = []
EVT_SEL_DSD64 = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment