|
arduino-audio-driver
|
Header only C++ driver for the TLV320DAC3100 / TLV320DAC3101 audio DAC. More...
#include <TLV320DAC310x.h>
Public Member Functions | |
| TLV320DAC310x () | |
| uint8_t | address () |
| Provides the actual I2C address of the codec. | |
| bool | applyProperties () |
| no-op, nothing is cached that needs re-applying | |
| bool | begin (uint32_t sample_rate, uint8_t bits, codec_mode_t mode, i2s_format_t fmt, bool is_master, uint8_t channels) override |
| bool | begin (uint32_t sample_rate=44100, uint8_t word_size=16, uint32_t mclk_freq=12000000, TLV320DAC310xFormat fmt=TLV320DAC310xFormat::I2S, bool bclk_controller=false, bool wclk_controller=false) |
| Initialize the codec. | |
| bool | configureClocks (uint32_t mclk_freq, uint32_t sample_rate, bool bclk_controller=false, uint8_t word_size=16) |
| Configure NDAC/MDAC/OSR dividers (and optionally BCLK divider) to derive the DAC processing/modulator clocks from MCLK. | |
| bool | configureDai (uint8_t word_size=16, TLV320DAC310xFormat fmt=TLV320DAC310xFormat::I2S, bool bclk_controller=false, bool wclk_controller=false) |
| Configure the digital audio interface (format, word length, clock directions) | |
| bool | configureFilters (uint32_t sample_rate) |
| Select the decimation filter / processing block based on the sample rate. | |
| bool | configureOutput (TLV320DAC310xCmVoltage cm=TLV320DAC310xCmVoltage::V1P65) |
| Configure the output path(s) selected via setDevices(): common mode voltage, pop removal, route DAC -> mixer -> headphone and/or Class-D speaker, default analog volume, unmute and power up the corresponding drivers. | |
| bool | disableBeep () |
| Stop the beep generator immediately by clearing the enable bit. | |
| bool | enableBeep (uint32_t freq_hz, uint32_t duration_ms=500, int8_t left_db=0, int8_t right_db=0) |
| Start the hardware sine-wave beep generator. | |
| virtual int | getInputVolume () |
| virtual int | getVolume () |
| Provides the output volume in % (0...100) that was set with setVolume() | |
| i2c_bus_handle_t | getWire () |
| Provides the actual I2C communication object. | |
| bool | isBeepActive () |
| virtual bool | isInputVolumeSupported () |
| Returns true if the driver supports setting the input volume, false otherwise. By default we return false, but some drivers (e.g. WM8962) override this to return true. | |
| virtual bool | setActive (codec_mode_t mode) |
| void | setAddress (uint8_t addr) |
| Defines the I2C address of the codec. | |
| bool | setDevices (input_device_t input_device, output_device_t output_device) override |
| Stores the output device selection for use by configureOutput() | |
| virtual bool | setInputVolume (int volume) |
| bool | setMute (bool mute) override |
| Mutes/unmutes the output. | |
| bool | setOutputImpedance (TLV320DAC310xOutputMode mode) |
| Set the HP output driver impedance mode and apply it immediately to register 44. | |
| bool | setOutputMute () |
| Mute the output (DAC channel mute, output stage stays powered) | |
| bool | setOutputMute (bool mute) |
| Mute / unmute the output. | |
| bool | setOutputUnmute () |
| Unmute the output. | |
| bool | setOutputVolume (int vol) |
| Set the headphone output (analog) volume. | |
| bool | setVolume (int volume) override |
| void | setWire (i2c_bus_handle_t w) |
| Defines the I2C communication object. | |
| bool | softReset () |
| Soft reset of the codec. | |
| bool | startOutput () |
| Power up & unmute the DAC channels and start the output. | |
| bool | stopOutput () |
| Mute and power down the DAC channels. | |
Static Public Attributes | |
| static constexpr uint8_t | BCLK_DIV_ADDR = 30 |
| static constexpr uint8_t | BCLK_DIV_MASK = 0x7F |
| static constexpr uint8_t | BCLK_DIV_POWER_UP = 0x80 |
| static constexpr uint8_t | BCLK_DIV_POWER_UP_MASK = 0x80 |
| static constexpr uint8_t | BEEP_COS_LSB_ADDR = 79 |
| static constexpr uint8_t | BEEP_COS_MSB_ADDR = 78 |
| static constexpr uint8_t | BEEP_GEN_EN_BEEP = 0x80 |
| static constexpr uint8_t | BEEP_LEN_LSB_ADDR = 75 |
| static constexpr uint8_t | BEEP_LEN_MID_ADDR = 74 |
| static constexpr uint8_t | BEEP_LEN_MSB_ADDR = 73 |
| static constexpr uint8_t | BEEP_SIN_LSB_ADDR = 77 |
| static constexpr uint8_t | BEEP_SIN_MSB_ADDR = 76 |
| static constexpr uint8_t | BEEP_VOL_MASK = 0x3F |
| static constexpr uint8_t | DAC_LR_POWERDN_DEFAULT = (0x10 | 0x04) |
| static constexpr uint8_t | DAC_LR_POWERUP_DEFAULT |
| static constexpr uint32_t | DAC_MOD_CLK_FREQ_MAX = 6200000 |
| static constexpr uint32_t | DAC_MOD_CLK_FREQ_MIN = 2800000 |
| static constexpr uint32_t | DAC_PROC_CLK_FREQ_MAX = 49152000 |
| static constexpr uint8_t | DATA_PATH_SETUP_ADDR = 63 |
| static constexpr uint8_t | DRC_CTRL1_ADDR = 68 |
| static constexpr uint8_t | HEADPHONE_DRV_ADDR = 31 |
| static constexpr uint8_t | HEADPHONE_DRV_CM_MASK = (0x03 << 3) |
| static constexpr uint8_t | HEADPHONE_DRV_CTRL_ADDR = 44 |
| static constexpr uint8_t | HEADPHONE_DRV_LINEOUT = (0x02 | 0x04) |
| static constexpr uint8_t | HEADPHONE_DRV_POWERUP = (0x80 | 0x40) |
| static constexpr uint8_t | HEADPHONE_DRV_RESERVED = 0x04 |
| static constexpr uint8_t | HP_OUT_POP_RM_ADDR = 33 |
| static constexpr uint8_t | HP_OUT_POP_RM_ENABLE = 0x80 |
| static constexpr uint8_t | HPL_ANA_VOL_CTRL_ADDR = 36 |
| static constexpr uint8_t | HPL_DRV_GAIN_CTRL_ADDR = 40 |
| static constexpr uint8_t | HPR_ANA_VOL_CTRL_ADDR = 37 |
| static constexpr uint8_t | HPR_DRV_GAIN_CTRL_ADDR = 41 |
| static constexpr uint8_t | HPX_ANA_VOL_DEFAULT = 64 |
| static constexpr uint8_t | HPX_ANA_VOL_ENABLE = 0x80 |
| static constexpr uint8_t | HPX_ANA_VOL_FLOOR = 144 |
| static constexpr uint8_t | HPX_ANA_VOL_LOW_THRESH = 105 |
| static constexpr uint8_t | HPX_ANA_VOL_MASK = 0x7F |
| static constexpr uint8_t | HPX_ANA_VOL_MAX = 0 |
| static constexpr uint8_t | HPX_ANA_VOL_MIN = 127 |
| static constexpr uint8_t | HPX_DRV_UNMUTE = 0x04 |
| static constexpr uint8_t | IF_CTRL1_ADDR = 27 |
| static constexpr uint8_t | IF_CTRL_BCLK_OUT = 0x08 |
| static constexpr uint8_t | IF_CTRL_IFTYPE_MASK = 0x03 |
| static constexpr uint8_t | IF_CTRL_WCLK_OUT = 0x04 |
| static constexpr uint8_t | IF_CTRL_WLEN_MASK = 0x03 |
| static constexpr uint8_t | L_BEEP_GEN_ADDR = 71 |
| static constexpr uint8_t | L_DIG_VOL_CTRL_ADDR = 65 |
| static constexpr uint8_t | MDAC_DIV_ADDR = 12 |
| static constexpr uint8_t | MDAC_DIV_MASK = 0x7F |
| static constexpr uint8_t | MDAC_POWER_UP = 0x80 |
| static constexpr uint8_t | MDAC_POWER_UP_MASK = 0x80 |
| static constexpr uint8_t | NDAC_DIV_ADDR = 11 |
| static constexpr uint8_t | NDAC_DIV_MASK = 0x7F |
| static constexpr uint8_t | NDAC_POWER_UP = 0x80 |
| static constexpr uint8_t | NDAC_POWER_UP_MASK = 0x80 |
| static constexpr uint8_t | OSR_LSB_ADDR = 14 |
| static constexpr uint8_t | OSR_LSB_MASK = 0xFF |
| static constexpr uint8_t | OSR_MSB_ADDR = 13 |
| static constexpr uint8_t | OSR_MSB_MASK = 0x03 |
| static constexpr uint8_t | OUTPUT_ROUTING_ADDR = 35 |
| static constexpr uint8_t | OUTPUT_ROUTING_HPL = (2 << 6) |
| static constexpr uint8_t | OUTPUT_ROUTING_HPR = (2 << 2) |
| static constexpr uint8_t | OUTPUT_ROUTING_MIXERL = (1 << 6) |
| static constexpr uint8_t | OUTPUT_ROUTING_MIXERR = (1 << 2) |
| static constexpr int | OUTPUT_VOLUME_MAX = 0 |
| static constexpr int | OUTPUT_VOLUME_MIN = (-78 * 2) |
| static constexpr uint8_t | OVF_FLAG_ADDR = 39 |
| static constexpr uint8_t | PAGE_CONTROL_ADDR = 0 |
| static constexpr uint8_t | PROC_BLK_SEL_ADDR = 60 |
| static constexpr uint8_t | PROC_BLK_SEL_MASK = 0x1F |
| static constexpr uint8_t | R_BEEP_GEN_ADDR = 72 |
| static constexpr uint8_t | SOFT_RESET_ADDR = 1 |
| static constexpr uint8_t | SOFT_RESET_ASSERT = 1 |
| static constexpr uint8_t | SPEAKER_AMP_ADDR = 32 |
| static constexpr uint8_t | SPEAKER_AMP_POWERUP = 0x80 |
| static constexpr uint8_t | SPEAKER_AMP_RESERVED = (0x04 | 0x02) |
| static constexpr uint8_t | SPK_DRV_GAIN_CTRL_ADDR = 42 |
| static constexpr uint8_t | SPK_DRV_UNMUTE = 0x04 |
| static constexpr uint8_t | SPL_ANA_VOL_CTRL_ADDR = 38 |
| static constexpr uint8_t | TIMER_MCLK_DIV_ADDR = 16 |
| static constexpr uint8_t | TIMER_MCLK_DIV_EN_EXT = 0x80 |
| static constexpr uint8_t | TIMER_MCLK_DIV_MASK = 0x7F |
| static constexpr uint8_t | VOL_CTRL_ADDR = 64 |
| static constexpr uint8_t | VOL_CTRL_MUTE_DEFAULT = (0x08 | 0x04) |
| static constexpr uint8_t | VOL_CTRL_UNMUTE_DEFAULT = 0 |
| static constexpr uint8_t | VOL_MICDET_ADC_CTRL_ADDR = 116 |
| static constexpr uint8_t | VOL_MICDET_VOL_CTRL_PIN = 0x80 |
Protected Member Functions | |
| bool | readPagedReg (uint8_t page, uint8_t reg, uint8_t &value) |
| Read a register on the given page. | |
| bool | readReg (uint8_t reg, uint8_t &value) |
| Reads a single byte from an 8 bit register address. | |
| bool | readReg16 (uint8_t reg, uint16_t &value) |
| Reads a 16 bit (big endian) value from an 8 bit register address. | |
| TLV320DAC310xOutputMode | resolveOutputMode () const |
| Resolve Auto → Headphone when LINE1 is selected, LineOut otherwise. | |
| bool | selectPage (uint8_t page) |
| Select the active register page (cached, only writes if changed) | |
| bool | updatePagedReg (uint8_t page, uint8_t reg, uint8_t mask, uint8_t value) |
| Read-Modify-Write of a register on the given page. | |
| bool | updateReg (uint8_t reg, uint8_t mask, uint8_t value) |
| Read-Modify-Write of a single byte register. | |
| bool | updateReg16 (uint8_t reg, uint16_t mask, uint16_t value) |
| Read-Modify-Write of a 16 bit (big endian) register. | |
| bool | writePagedReg (uint8_t page, uint8_t reg, uint8_t value) |
| Write a register on the given page. | |
| bool | writeReg (uint8_t reg, uint8_t value) |
| Writes a single byte to an 8 bit register address. | |
| bool | writeReg16 (uint8_t reg, uint16_t value) |
| Writes a 16 bit (big endian) value to an 8 bit register address. | |
Static Protected Member Functions | |
| static uint8_t | analogVolReg (uint8_t vol) |
| Build the register value for the HPx analog volume control registers. | |
| static uint8_t | beepVolReg (int8_t vol_db) |
| static TLV320DAC310xOsrMultiple | getOsrMultiple (uint32_t sample_rate) |
| static TLV320DAC310xFormat | toFormat (i2s_format_t fmt) |
| Map the generic I2S format to the TLV320DAC310x specific format. | |
Protected Attributes | |
| uint8_t | active_page = 0xFF |
| 0xFF forces a page select on first access | |
| uint32_t | current_sample_rate = 44100 |
| uint8_t | i2c_addr = 0 |
| int | input_volume_percent = 100 |
| Last input volume (in %) provided to setInputVolume() | |
| output_device_t | output_device = DAC_OUTPUT_ALL |
| Output device selection set via setDevices(), used by configureOutput() | |
| TLV320DAC310xOutputMode | output_mode = TLV320DAC310xOutputMode::Auto |
| HP driver impedance mode, applied by configureOutput() and setOutputImpedance() | |
| int | volume_percent = 100 |
| Last volume (in %) provided to setVolume() | |
| i2c_bus_handle_t | wire = nullptr |
Header only C++ driver for the TLV320DAC3100 / TLV320DAC3101 audio DAC.
The register map of this chip is organized in pages: page 0 register 0 is the page-select register. selectPage()/writePagedReg()/readPagedReg() take care of switching pages as needed.
The RESET pin is not handled here - the chip must be taken out of reset (RESET pin driven high / inactive) by the caller before begin() is called.
|
inline |
|
inlineinherited |
Provides the actual I2C address of the codec.
|
inlinestaticprotected |
Build the register value for the HPx analog volume control registers.
|
inline |
no-op, nothing is cached that needs re-applying
|
inlinestaticprotected |
Convert a dB gain value to the 6-bit beep volume register code. Register encoding: code 0 = 2 dB, code 2 = 0 dB, code 63 = −61 dB.
|
inlineoverridevirtual |
Required by ZephyrDriverCommon: maps the generic parameters to the TLV320DAC310x specific begin() below (using the default MCLK frequency of 12 MHz).
Implements ZephyrDriverCommon.
|
inline |
Initialize the codec.
Note: the RESET pin must be driven inactive (high) by the caller before calling begin().
| sample_rate | I2S sample rate in Hz (e.g. 44100, 48000) |
| word_size | I2S word length in bits (16, 20, 24, 32) |
| mclk_freq | MCLK frequency in Hz as fed to the codec |
| fmt | digital audio interface format |
| bclk_controller | true if this device drives BCLK (master) |
| wclk_controller | true if this device drives WCLK/LRCLK (master) |
|
inline |
Configure NDAC/MDAC/OSR dividers (and optionally BCLK divider) to derive the DAC processing/modulator clocks from MCLK.
|
inline |
Configure the digital audio interface (format, word length, clock directions)
|
inline |
Select the decimation filter / processing block based on the sample rate.
|
inline |
Configure the output path(s) selected via setDevices(): common mode voltage, pop removal, route DAC -> mixer -> headphone and/or Class-D speaker, default analog volume, unmute and power up the corresponding drivers.
DAC_OUTPUT_LINE1 enables the headphone/line drivers (HPL/HPR), and DAC_OUTPUT_LINE2 enables the mono Class-D speaker driver (SPK), fed from DAC_L. DAC_OUTPUT_ALL enables both, DAC_OUTPUT_NONE powers both down.
|
inline |
Stop the beep generator immediately by clearing the enable bit.
|
inline |
Start the hardware sine-wave beep generator.
Programs the frequency, duration and per-channel volume, then sets the enable bit in register 71 (self-clears once all programmed samples have been played).
Note: the beep generator requires DAC processing block PRB_P25, which is selected automatically by configureFilters() for sample rates < 96 kHz. It will not function at 96 kHz or above.
| freq_hz | Sine-wave frequency in Hz |
| duration_ms | Duration in milliseconds; 0 uses the maximum (≈380 s at 44.1 kHz) |
| left_db | Left channel gain in dB, range [−61, 2] (default 0 dB) |
| right_db | Right channel gain in dB, range [−61, 2] (default 0 dB) |
|
inlinevirtualinherited |
Provides the input volume in % (0...100) that was set with setInputVolume()
|
inlinestaticprotected |
|
inlinevirtualinherited |
Provides the output volume in % (0...100) that was set with setVolume()
|
inlineinherited |
Provides the actual I2C communication object.
|
inline |
Returns true while the beep generator is still running (D7 of register 71 is self-clearing once the programmed samples complete)
|
inlinevirtualinherited |
|
inlineprotected |
Read a register on the given page.
|
inlineprotectedinherited |
Reads a single byte from an 8 bit register address.
|
inlineprotectedinherited |
Reads a 16 bit (big endian) value from an 8 bit register address.
|
inlineprotected |
Resolve Auto → Headphone when LINE1 is selected, LineOut otherwise.
|
inlineprotected |
Select the active register page (cached, only writes if changed)
|
inlinevirtualinherited |
Activates/deactivates the playback and/or capture path at runtime (without reconfiguring the codec), based on codec_mode_t (CODEC_MODE_DECODE: playback active, CODEC_MODE_ENCODE: capture active). By default this just mutes/unmutes all outputs depending on CODEC_MODE_DECODE; chip specific subclasses that support muting the input path independently override this to also mute/unmute the capture path depending on CODEC_MODE_ENCODE.
|
inlineinherited |
Defines the I2C address of the codec.
|
inlineoverridevirtual |
Stores the output device selection for use by configureOutput()
Reimplemented from ZephyrDriverCommon.
|
inlinevirtualinherited |
|
inlineoverridevirtual |
Mutes/unmutes the output.
Reimplemented from ZephyrDriverCommon.
|
inline |
Set the HP output driver impedance mode and apply it immediately to register 44.
Overrides the automatic selection that configureOutput() derives from output_device (LINE1 → Headphone, others → LineOut). Pass Auto to restore the automatic behaviour on the next configureOutput() call.
| mode | Headphone (16–32 Ω), LineOut (≥10 kΩ) or Auto |
|
inline |
Mute the output (DAC channel mute, output stage stays powered)
|
inline |
Mute / unmute the output.
|
inline |
Unmute the output.
|
inline |
Set the headphone output (analog) volume.
| vol | volume in units of 0.5dB, range [OUTPUT_VOLUME_MIN (-156, i.e. -78dB), OUTPUT_VOLUME_MAX (0, i.e. 0dB)] |
|
inlineoverridevirtual |
Sets the output volume in % (0...100), mapped to [OUTPUT_VOLUME_MIN..OUTPUT_VOLUME_MAX] (0.5dB steps)
Reimplemented from ZephyrDriverCommon.
|
inlineinherited |
Defines the I2C communication object.
|
inline |
Soft reset of the codec.
|
inline |
Power up & unmute the DAC channels and start the output.
|
inline |
Mute and power down the DAC channels.
|
inlinestaticprotected |
Map the generic I2S format to the TLV320DAC310x specific format.
|
inlineprotected |
Read-Modify-Write of a register on the given page.
|
inlineprotectedinherited |
Read-Modify-Write of a single byte register.
|
inlineprotectedinherited |
Read-Modify-Write of a 16 bit (big endian) register.
|
inlineprotected |
Write a register on the given page.
|
inlineprotectedinherited |
Writes a single byte to an 8 bit register address.
|
inlineprotectedinherited |
Writes a 16 bit (big endian) value to an 8 bit register address.
|
protected |
0xFF forces a page select on first access
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protected |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protectedinherited |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protectedinherited |
Last input volume (in %) provided to setInputVolume()
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protected |
Output device selection set via setDevices(), used by configureOutput()
|
protected |
HP driver impedance mode, applied by configureOutput() and setOutputImpedance()
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protectedinherited |
Last volume (in %) provided to setVolume()
|
protectedinherited |