|
arduino-audio-driver
|
Header only C++ driver for the DA7212 audio codec. More...
#include <DA7212.h>
Public Member Functions | |
| DA7212 () | |
| uint8_t | address () |
| Provides the actual I2C address of the codec. | |
| bool | begin (DA7212Protocol protocol=DA7212Protocol::I2S, uint32_t sample_rate=44100, uint8_t word_size=16, bool master=false, bool playback=true, bool capture=true) |
| bool | begin (uint32_t sample_rate, uint8_t bits) |
| Initialize the codec: soft reset, default routing, PLL disabled (MCLK is used directly as the system clock), DAI / protocol / sample rate / word length configuration and optional playback/capture path setup. | |
| 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 | configureInput () |
| Configure the input (capture) path: AUX -> MixIn routing, charge pump, AUX/MIC/MixIn amps, ADCs, gain ramp & charge pump delay, default ADC volume and unmute. | |
| bool | configureOutput () |
| Configure the output (playback) path: charge pump, DAC -> MixOut routing, DACs, headphone amps, MixOut amps, default DAC/HP gain and unmute. | |
| 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 | isInputVolumeSupported () override |
| Returns true: the input volume is supported. | |
| bool | routeDacInput (bool playback) |
| Route the DAI input to the DACs (playback) or bypass ADC->DAC. | |
| bool | routeInput (DA7212Channel channel=DA7212Channel::All) |
| Route the AUX input(s) to the input mixer(s) for the given channel(s) | |
| bool | routeOutput () |
| Route the DACs to the output mixers (MixOut) | |
| bool | setActive (codec_mode_t mode) override |
| void | setAddress (uint8_t addr) |
| Defines the I2C address of the codec. | |
| bool | setAudioFormat (uint32_t sample_rate, uint8_t word_size=16) |
| Configure sample rate (SR register) and word length (DAI_CTRL) | |
| bool | setClockMode (bool master, uint8_t word_size) |
| Configure master/slave clock mode. | |
| bool | setDevices (input_device_t input_device, output_device_t output_device) override |
| Stores the output device selection for use by configureOutput() | |
| bool | setInputMute (bool mute, DA7212Channel channel=DA7212Channel::All) |
| Mute / unmute the ADC input for the given channel(s) | |
| bool | setInputVolume (int volume) override |
| Sets the input volume in % (0...100) for all channels. | |
| bool | setInputVolume (uint8_t volume, DA7212Channel channel=DA7212Channel::All) |
| Set the ADC input volume (0..127, ADC_x_GAIN) for the given channel(s) | |
| bool | setMute (bool mute) override |
| Mutes/unmutes all outputs. | |
| bool | setOutputMute (bool mute, DA7212Channel channel=DA7212Channel::All) |
| Mute / unmute the headphone (and line) output for the given channel(s) | |
| bool | setOutputVolume (uint8_t volume, DA7212Channel channel=DA7212Channel::All) |
| Set the headphone output volume (0..63, HP_x_GAIN) for the given channel(s) | |
| bool | setProtocol (DA7212Protocol protocol) |
| Configure the digital audio interface protocol (I2S, LJ, RJ, DSP) | |
| bool | setVolume (int volume) override |
| Sets the output volume in % (0...100) for all channels. | |
| void | setWire (i2c_bus_handle_t w) |
| Defines the I2C communication object. | |
| bool | softReset () |
| Soft reset of the codec (CIF_CTRL soft reset bit) | |
Static Public Attributes | |
| static constexpr uint8_t | ADC_GAIN_MASK = 0x7F |
| static constexpr uint8_t | AMP_EN_MASK = (1U << 7) |
| static constexpr uint8_t | AMP_OE_MASK = (1U << 3) |
| static constexpr uint8_t | AMP_RAMP_EN_MASK = (1U << 5) |
| static constexpr uint8_t | AMP_ZC_EN_MASK = (1U << 4) |
| static constexpr uint8_t | AUX_AMP_EN_MASK = (1U << 7) |
| static constexpr uint8_t | AUX_AMP_RAMP_EN_MASK = (1U << 5) |
| static constexpr uint8_t | AUX_AMP_ZC_EN_MASK = (1U << 4) |
| static constexpr uint8_t | AUX_L_CTRL_AMP_ZC_SEL_INPUT_AUX_L_IF = (1U << 2) |
| static constexpr uint8_t | CIF_CTRL_SOFT_RESET = (1U << 7) |
| static constexpr uint8_t | CP_CTRL_ANALOG_VLL_LV_BOOSTS_CP = (1U << 0) |
| static constexpr uint8_t | CP_CTRL_EN_MASK = (1U << 7) |
| static constexpr uint8_t | CP_CTRL_MCHANGE_OUTPUT = (3U << 4) |
| static constexpr uint8_t | CP_CTRL_MOD_CPVDD_1 = (3U << 2) |
| static constexpr uint8_t | CP_CTRL_SMALL_SWITCH_FREQ_EN_MASK = (1U << 6) |
| static constexpr uint8_t | CP_DELAY_FCONTROL_0HZ_OR_1MHZ = (5U << 0) |
| static constexpr uint8_t | CP_DELAY_ON_OFF_LIMITER_AUT = (2U << 6) |
| static constexpr uint8_t | CP_DELAY_TAU_DELAY_4MS = (2U << 3) |
| static constexpr uint8_t | DAC_DEFAULT_GAIN = 0x67 |
| static constexpr uint8_t | DAI_BCLKS_PER_WCLK_BCLK128 = 2 |
| static constexpr uint8_t | DAI_BCLKS_PER_WCLK_BCLK256 = 3 |
| static constexpr uint8_t | DAI_BCLKS_PER_WCLK_BCLK32 = 0 |
| static constexpr uint8_t | DAI_BCLKS_PER_WCLK_BCLK64 = 1 |
| static constexpr uint8_t | DAI_BCLKS_PER_WCLK_MASK = 0x03 |
| static constexpr uint8_t | DAI_CLK_EN_MASK = (1U << 7) |
| static constexpr uint8_t | DAI_EN_MASK = (1U << 7) |
| static constexpr uint8_t | DAI_FORMAT_MASK = 0x03 |
| static constexpr uint8_t | DAI_OE_MASK = (1U << 6) |
| static constexpr uint8_t | DAI_WORD_LENGTH_16B = (0U << 2) |
| static constexpr uint8_t | DAI_WORD_LENGTH_20B = (1U << 2) |
| static constexpr uint8_t | DAI_WORD_LENGTH_24B = (2U << 2) |
| static constexpr uint8_t | DAI_WORD_LENGTH_32B = (3U << 2) |
| static constexpr uint8_t | DAI_WORD_LENGTH_MASK = 0x0C |
| static constexpr uint8_t | DIG_ROUTING_DAC_L_RSC_ADC_L_OUTPUT = (0U << 0) |
| static constexpr uint8_t | DIG_ROUTING_DAC_L_RSC_DAC_L = (2U << 0) |
| static constexpr uint8_t | DIG_ROUTING_DAC_R_RSC_ADC_R_OUTPUT = (1U << 4) |
| static constexpr uint8_t | DIG_ROUTING_DAC_R_RSC_DAC_R = (3U << 4) |
| static constexpr uint8_t | DIG_ROUTING_DAI_L_SRC_ADC_LEFT = (0U << 0) |
| static constexpr uint8_t | DIG_ROUTING_DAI_R_SRC_ADC_RIGHT = (1U << 4) |
| static constexpr uint8_t | EN_MASK = (1U << 7) |
| static constexpr uint8_t | GAIN_RAMP_CTRL_RATE_NR_MUL_16 = (2U << 0) |
| static constexpr uint8_t | HP_DEFAULT_GAIN = 0x2F |
| static constexpr uint8_t | HP_GAIN_MASK = 0x3F |
| static constexpr uint8_t | MIC_CTRL_AMP_IN_SEL_MIC_P = (1U << 2) |
| static constexpr uint8_t | MIXIN_AMP_EN_MASK = (1U << 7) |
| static constexpr uint8_t | MIXIN_AMP_MIX_EN_MASK = (1U << 3) |
| static constexpr uint8_t | MIXIN_L_SELECT_AUX_L_SEL_MASK = (1U << 0) |
| static constexpr uint8_t | MIXIN_R_SELECT_AUX_R_SEL_MASK = (1U << 0) |
| static constexpr uint8_t | MIXOUT_AMP_EN_MASK = (1U << 7) |
| static constexpr uint8_t | MIXOUT_AMP_MIX_EN_MASK = (1U << 3) |
| static constexpr uint8_t | MIXOUT_AMP_SOFT_MIX_EN_MASK = (1U << 4) |
| static constexpr uint8_t | MIXOUT_L_SELECT_DAC_L_MASK = (1U << 3) |
| static constexpr uint8_t | MIXOUT_R_SELECT_DAC_R_MASK = (1U << 3) |
| static constexpr uint8_t | MUTE_MASK = (3U << 6) |
| static constexpr uint8_t | PC_COUNT_RESYNC_MASK = (1U << 1) |
| static constexpr uint8_t | PLL_FBDIV_INTEGER_RESET_VALUE = 0x20 |
| static constexpr uint8_t | RAMP_EN_MASK = (1U << 5) |
| static constexpr uint8_t | REFERENCES_BIAS_EN_MASK = (1U << 3) |
| static constexpr uint8_t | UNMUTE_MASK = (1U << 7) |
| *_EN bit kept set | |
Protected Member Functions | |
| 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. | |
| bool | updateOutGain (DA7212Channel channel, uint8_t volume) |
| 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 | 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. | |
Protected Attributes | |
| 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() | |
| int | volume_percent = 100 |
| Last volume (in %) provided to setVolume() | |
| i2c_bus_handle_t | wire = nullptr |
Header only C++ driver for the DA7212 audio codec.
Provides soft reset, basic playback/capture configuration (I2S protocol, sample rate, word length), input routing and output/input volume & mute control, ported from the corresponding Zephyr RTOS driver.
| enum Reg : uint8_t |
|
inline |
|
inlineinherited |
Provides the actual I2C address of the codec.
|
inline |
|
inline |
Initialize the codec: soft reset, default routing, PLL disabled (MCLK is used directly as the system clock), DAI / protocol / sample rate / word length configuration and optional playback/capture path setup.
| protocol | Digital audio interface protocol |
| sample_rate | I2S sample rate in Hz |
| word_size | I2S word size in bits (16, 20, 24, 32) |
| master | true if the codec should drive BCLK/WCLK (master mode) |
| playback | Enable & configure the output (headphone) path |
| capture | Enable & configure the input path Initializes the codec for I2S with the given sample rate and bits per sample |
|
inlineoverridevirtual |
Initializes the codec for I2S with the given sample rate, bits per sample, enabling the playback and/or capture path depending on mode, using the given I2S data format and master/slave mode. The channels parameter is not configurable on this chip and is ignored.
Implements ZephyrDriverCommon.
|
inline |
Configure the input (capture) path: AUX -> MixIn routing, charge pump, AUX/MIC/MixIn amps, ADCs, gain ramp & charge pump delay, default ADC volume and unmute.
|
inline |
Configure the output (playback) path: charge pump, DAC -> MixOut routing, DACs, headphone amps, MixOut amps, default DAC/HP gain and unmute.
|
inlinevirtualinherited |
Provides the input volume in % (0...100) that was set with setInputVolume()
|
inlinevirtualinherited |
Provides the output volume in % (0...100) that was set with setVolume()
|
inlineinherited |
Provides the actual I2C communication object.
|
inlineoverridevirtual |
Returns true: the input volume is supported.
Reimplemented from ZephyrDriverCommon.
|
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.
|
inline |
Route the DAI input to the DACs (playback) or bypass ADC->DAC.
|
inline |
Route the AUX input(s) to the input mixer(s) for the given channel(s)
|
inline |
Route the DACs to the output mixers (MixOut)
|
inlineoverridevirtual |
Activates/deactivates the playback and/or capture path depending on codec_mode_t by muting/unmuting the output and input independently
Reimplemented from ZephyrDriverCommon.
|
inlineinherited |
Defines the I2C address of the codec.
|
inline |
Configure sample rate (SR register) and word length (DAI_CTRL)
|
inline |
Configure master/slave clock mode.
| master | true => codec drives BCLK/WCLK (DAI_CLK_EN=1) |
| word_size | BCLK count per WCLK period is derived from this |
|
inlineoverridevirtual |
Stores the output device selection for use by configureOutput()
Reimplemented from ZephyrDriverCommon.
|
inline |
Mute / unmute the ADC input for the given channel(s)
|
inlineoverridevirtual |
Sets the input volume in % (0...100) for all channels.
Reimplemented from ZephyrDriverCommon.
|
inline |
Set the ADC input volume (0..127, ADC_x_GAIN) for the given channel(s)
|
inlineoverridevirtual |
Mutes/unmutes all outputs.
Reimplemented from ZephyrDriverCommon.
|
inline |
Mute / unmute the headphone (and line) output for the given channel(s)
|
inline |
Set the headphone output volume (0..63, HP_x_GAIN) for the given channel(s)
|
inline |
Configure the digital audio interface protocol (I2S, LJ, RJ, DSP)
|
inlineoverridevirtual |
Sets the output volume in % (0...100) for all channels.
Reimplemented from ZephyrDriverCommon.
|
inlineinherited |
Defines the I2C communication object.
|
inline |
Soft reset of the codec (CIF_CTRL soft reset bit)
|
inlineprotected |
|
inlineprotectedinherited |
Read-Modify-Write of a single byte register.
|
inlineprotectedinherited |
Read-Modify-Write of a 16 bit (big endian) register.
|
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.
|
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 |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protectedinherited |
|
protectedinherited |
Last input volume (in %) provided to setInputVolume()
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protected |
Output device selection set via setDevices(), used by configureOutput()
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
*_EN bit kept set
|
protectedinherited |
Last volume (in %) provided to setVolume()
|
protectedinherited |