|
arduino-audio-driver
|
SF32LB (SiFli SF32LB5x) on-chip AUDCODEC driver, ported from the Zephyr RTOS driver drivers/audio/sf32lb_codec.c (https://github.com/zephyrproject-rtos/zephyr, Apache-2.0) using the register definitions from hal_sifli cmsis/sf32lb52x/audcodec.h.
More...
#include <SF32LB.h>
Classes | |
| struct | AdcClockConfig |
| struct | DacClockConfig |
| Clock divider settings for the non-PLL (48 MHz XTAL) sample rates. More... | |
Public Member Functions | |
| uint8_t | address () |
| Provides the actual I2C address of the codec. | |
| virtual bool | begin (uint32_t sample_rate, uint8_t bits, codec_mode_t mode, i2s_format_t fmt, bool is_master, uint8_t channels)=0 |
| Initializes the codec. | |
| bool | begin (uintptr_t base, uint32_t sample_rate=48000) |
| bool | beginInput (uint32_t sample_rate=48000) |
| 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. | |
| 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. | |
| void | setBaseAddress (uintptr_t base) |
| virtual bool | setDevices (input_device_t input_device, output_device_t output_device) |
| virtual bool | setInputVolume (int volume) |
| bool | setMute (bool mute_flag) override |
| bool | setVolume (int volume) override |
| bool | setVolumeDb (int volume_db) |
| Sets the DAC output volume in dB, range MIN_VOLUME_DB..MAX_VOLUME_DB. | |
| void | setWire (i2c_bus_handle_t w) |
| Defines the I2C communication object. | |
| void | start () |
| Starts (un-mutes) the DAC output path. | |
| void | stop () |
| Mutes and disables the DAC output path. | |
| void | stopInput () |
| Disables the ADC input path. | |
Static Public Attributes | |
| static constexpr uint32_t | ADC_ANA_CFG_MICBIAS_CHOP_EN = 1UL << 0 |
| static constexpr uint32_t | ADC_ANA_CFG_MICBIAS_EN = 1UL << 1 |
| static constexpr uint32_t | ADC_CFG_CLK_DIV_Msk = 0xFFUL << 8 |
| static constexpr uint32_t | ADC_CFG_CLK_SRC_SEL_Msk = 0x1UL << 6 |
| static constexpr uint32_t | ADC_CFG_OP_MODE_Msk = 0x3UL << 3 |
| static constexpr uint32_t | ADC_CFG_OSR_SEL_Msk = 0x7UL << 0 |
| static constexpr uint32_t | ADC_CFG_PATH_RESET = 1UL << 5 |
| static constexpr uint32_t | ADC_CH_CFG_DATA_FORMAT = 1UL << 16 |
| static constexpr uint32_t | ADC_CH_CFG_DMA_EN = 1UL << 7 |
| static constexpr uint32_t | ADC_CH_CFG_ENABLE = 1UL << 0 |
| static constexpr uint32_t | ADC_CH_CFG_FINE_VOL_Msk = 0xFUL << 12 |
| static constexpr uint32_t | ADC_CH_CFG_HPF_BYPASS = 1UL << 1 |
| static constexpr uint32_t | ADC_CH_CFG_HPF_COEF_Msk = 0xFUL << 2 |
| static constexpr uint32_t | ADC_CH_CFG_ROUGH_VOL_Msk = 0xFUL << 8 |
| static constexpr uint32_t | ADC_CH_CFG_STB_INV = 1UL << 6 |
| static constexpr uint32_t | ADCx_CFG1_DACN_EN = 1UL << 21 |
| static constexpr uint32_t | ADCx_CFG1_DIFF_EN = 1UL << 22 |
| static constexpr uint32_t | ADCx_CFG1_FSP_Msk = 0x3UL << 23 |
| static constexpr uint32_t | ADCx_CFG1_GC_Msk = 0x7UL << 18 |
| static constexpr uint32_t | ADCx_CFG1_VCMST = 1UL << 3 |
| static constexpr uint32_t | ADCx_CFG1_VREF_SEL_Msk = 0x7UL << 6 |
| static constexpr uint32_t | ADCx_CFG2_CLEAR = 1UL << 0 |
| static constexpr uint32_t | ADCx_CFG2_EN = 1UL << 3 |
| static constexpr uint32_t | ADCx_CFG2_RSTB = 1UL << 2 |
| static constexpr uint32_t | BG_CFG0_EN = 1UL << 0 |
| static constexpr uint32_t | BG_CFG0_EN_AMP = 1UL << 12 |
| static constexpr uint32_t | BG_CFG0_EN_RCFLT = 1UL << 8 |
| static constexpr uint32_t | BG_CFG0_EN_SMPL = 1UL << 7 |
| static constexpr uint32_t | BG_CFG0_LP_MODE = 1UL << 1 |
| static constexpr uint32_t | BG_CFG0_MIC_VREF_SEL_Msk = 0x7UL << 9 |
| static constexpr uint32_t | BG_CFG0_SET_VC = 1UL << 13 |
| static constexpr uint32_t | BG_CFG0_VREF_SEL_Msk = 0xFUL << 2 |
| static constexpr uint32_t | CFG_ADC_EN_DLY_SEL_Msk = 0x3UL << 3 |
| static constexpr uint32_t | CFG_ADC_ENABLE = 1UL << 0 |
| static constexpr uint32_t | CFG_DAC_ENABLE = 1UL << 1 |
| static constexpr uint32_t | DAC_CFG_CLK_DIV_Msk = 0xFFUL << 8 |
| static constexpr uint32_t | DAC_CFG_CLK_SRC_SEL_Msk = 0x1UL << 7 |
| static constexpr uint32_t | DAC_CFG_OP_MODE_Msk = 0x3UL << 4 |
| static constexpr uint32_t | DAC_CFG_OSR_SEL_Msk = 0xFUL << 0 |
| static constexpr uint32_t | DAC_CFG_PATH_RESET = 1UL << 6 |
| static constexpr uint32_t | DAC_CH_CFG_DATA_FORMAT = 1UL << 16 |
| static constexpr uint32_t | DAC_CH_CFG_DEM_MODE_Msk = 0x3UL << 2 |
| static constexpr uint32_t | DAC_CH_CFG_DITHER_EN = 1UL << 29 |
| static constexpr uint32_t | DAC_CH_CFG_DITHER_GAIN_Msk = 0x7UL << 26 |
| static constexpr uint32_t | DAC_CH_CFG_DMA_EN = 1UL << 7 |
| static constexpr uint32_t | DAC_CH_CFG_DOUT_MUTE = 1UL << 1 |
| static constexpr uint32_t | DAC_CH_CFG_ENABLE = 1UL << 0 |
| static constexpr uint32_t | DAC_CH_CFG_EXT_RAMP_EN = 1UL << 0 |
| static constexpr uint32_t | DAC_CH_CFG_EXT_RAMP_INTERVAL_Msk = 0xFUL << 3 |
| static constexpr uint32_t | DAC_CH_CFG_EXT_RAMP_MODE = 1UL << 1 |
| static constexpr uint32_t | DAC_CH_CFG_EXT_RAMP_STAT_Msk = 0x3UL << 7 |
| static constexpr uint32_t | DAC_CH_CFG_EXT_ZERO_ADJUST_EN = 1UL << 2 |
| static constexpr uint32_t | DAC_CH_CFG_FINE_VOL_Msk = 0xFUL << 12 |
| static constexpr uint32_t | DAC_CH_CFG_ROUGH_VOL_Msk = 0xFUL << 8 |
| static constexpr uint32_t | DAC_CH_CFG_SINC_GAIN_Msk = 0x1FFUL << 17 |
| static constexpr uint32_t | DAC_CH_DEBUG_BYPASS = 1UL << 16 |
| static constexpr uint32_t | DAC_CH_DEBUG_DATA_OUT_Msk = 0xFFFFUL << 0 |
| static constexpr uint32_t | DACx_CFG_EN_AMP = 1UL << 21 |
| static constexpr uint32_t | DACx_CFG_EN_DAC = 1UL << 25 |
| static constexpr uint32_t | DACx_CFG_EN_OS_DAC = 1UL << 0 |
| static constexpr uint32_t | DACx_CFG_EN_VCM = 1UL << 24 |
| static constexpr uint32_t | DACx_CFG_LP_MODE = 1UL << 14 |
| static constexpr uint32_t | DACx_CFG_SR = 1UL << 12 |
| static constexpr int | MAX_VOLUME_DB = 54 |
| static constexpr int | MIN_VOLUME_DB = -36 |
| static constexpr uint32_t | PLL_CFG0_EN_ANA = 1UL << 15 |
| static constexpr uint32_t | PLL_CFG0_EN_IARY = 1UL << 28 |
| static constexpr uint32_t | PLL_CFG0_EN_VCO = 1UL << 27 |
| static constexpr uint32_t | PLL_CFG0_ICP_SEL_Msk = 0x1FUL << 6 |
| static constexpr uint32_t | PLL_CFG1_C2_SEL_Msk = 0x7UL << 8 |
| static constexpr uint32_t | PLL_CFG1_CZ_SEL_Msk = 0x7UL << 11 |
| static constexpr uint32_t | PLL_CFG1_R3_SEL_Msk = 0xFUL << 0 |
| static constexpr uint32_t | PLL_CFG1_RZ_SEL_Msk = 0xFUL << 4 |
| static constexpr uint32_t | PLL_CFG2_EN_DIG = 1UL << 13 |
| static constexpr uint32_t | PLL_CFG2_RSTB = 1UL << 8 |
| static constexpr uint32_t | PLL_CFG3_EN_SDM = 1UL << 30 |
| static constexpr uint32_t | PLL_CFG4_DIVA_CLK_DAC_Msk = 0x1FUL << 6 |
| static constexpr uint32_t | PLL_CFG4_DIVA_CLK_DIG_Msk = 0x1FUL << 18 |
| static constexpr uint32_t | PLL_CFG4_EN_CLK_CHOP_DAC = 1UL << 5 |
| static constexpr uint32_t | PLL_CFG4_EN_CLK_DAC = 1UL << 11 |
| static constexpr uint32_t | PLL_CFG4_EN_CLK_DIG = 1UL << 23 |
| static constexpr uint32_t | PLL_CFG4_SEL_CLK_DAC = 1UL << 12 |
| static constexpr uint32_t | PLL_CFG4_SEL_CLK_DAC_SOURCE_Msk = 0x3UL << 13 |
| static constexpr uint32_t | PLL_CFG4_SEL_CLK_DIG = 1UL << 15 |
| static constexpr uint32_t | PLL_CFG5_EN_CLK_CHOP_BG = 1UL << 7 |
| static constexpr uint32_t | PLL_CFG5_EN_CLK_CHOP_REFGEN = 1UL << 15 |
| static constexpr uint32_t | PLL_CFG6_DIVA_CLK_ADC0_Msk = 0x7UL << 20 |
| static constexpr uint32_t | PLL_CFG6_DIVA_CLK_ADC1_Msk = 0x7UL << 15 |
| static constexpr uint32_t | PLL_CFG6_DIVA_CLK_ADC2_Msk = 0x7UL << 10 |
| static constexpr uint32_t | PLL_CFG6_EN_CLK_ADC0 = 1UL << 23 |
| static constexpr uint32_t | PLL_CFG6_EN_CLK_ADC1 = 1UL << 18 |
| static constexpr uint32_t | PLL_CFG6_EN_CLK_ADC2 = 1UL << 13 |
| static constexpr uint32_t | PLL_CFG6_EN_CLK_CHOP_MICBIAS = 1UL << 8 |
| static constexpr uint32_t | PLL_CFG6_SEL_CLK_ADC0 = 1UL << 19 |
| static constexpr uint32_t | PLL_CFG6_SEL_CLK_ADC1 = 1UL << 14 |
| static constexpr uint32_t | PLL_CFG6_SEL_CLK_ADC2 = 1UL << 9 |
| static constexpr uint32_t | PLL_CFG6_SEL_CLK_ADC_SOURCE = 1UL << 24 |
| static constexpr uint32_t | PLL_CFG6_SEL_CLK_CHOP_MICBIAS_Msk = 0x3UL << 6 |
| static constexpr uint32_t | REFGEN_CFG_EN = 1UL << 0 |
| static constexpr uint32_t | REFGEN_CFG_EN_CHOP = 1UL << 1 |
| static constexpr uint32_t | REFGEN_CFG_LV_MODE = 1UL << 5 |
Protected Member Functions | |
| void | clearBit (uint32_t offset, uint32_t mask) |
| void | closeAnalogAdcPath () |
| Powers down the analog ADC path (mirrors close_analog_adc_path()). | |
| void | closeAnalogDacPath () |
| Powers down the analog DAC path (mirrors close_analog_dac_path()). | |
| void | configAnalogAdcPath (const AdcClockConfig &clk) |
| Configures the analog ADC bias/clock tree and enables ADC1. | |
| void | configAnalogDacPath (const DacClockConfig &clk) |
| Configures the analog DAC bias/clock tree and enables the DAC amps. | |
| void | configDacPath (bool bypass) |
| Enables/disables the digital bypass path on both DAC channels. | |
| void | configRxChannel (const AdcClockConfig &clk) |
| Configures the digital ADC channel 0 path (DMA disabled). | |
| void | configTxChannel (const DacClockConfig &clk) |
| void | mute (bool mute_flag) |
| void | pllAndReferencesOn () |
| uint32_t | read32 (uint32_t offset) |
| 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. | |
| void | refgenInit () |
| void | setBit (uint32_t offset, uint32_t mask) |
| 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. | |
| void | updateReg32 (uint32_t offset, uint32_t mask, uint32_t value) |
| Read-Modify-Write of selected bits of a 32 bit register. | |
| void | write32 (uint32_t offset, uint32_t value) |
| 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 const AdcClockConfig * | adcClockConfig (uint32_t sample_rate) |
| static const DacClockConfig * | dacClockConfig (uint32_t sample_rate) |
Protected Attributes | |
| uint8_t | i2c_addr = 0 |
| int | input_volume_percent = 100 |
| Last input volume (in %) provided to setInputVolume() | |
| uint32_t | last_fine_vol = 0 |
| uintptr_t | reg_base = 0 |
| int | volume_percent = 100 |
| Last volume (in %) provided to setVolume() | |
| i2c_bus_handle_t | wire = nullptr |
SF32LB (SiFli SF32LB5x) on-chip AUDCODEC driver, ported from the Zephyr RTOS driver drivers/audio/sf32lb_codec.c (https://github.com/zephyrproject-rtos/zephyr, Apache-2.0) using the register definitions from hal_sifli cmsis/sf32lb52x/audcodec.h.
Unlike the other codecs in this library, the SF32LB AUDCODEC is a memory mapped peripheral that is part of the SoC itself - there is no I2C control bus. It therefore extends ZephyrDriver (for API consistency) but does not use the wire/i2c_addr members; instead it operates on a 32 bit register block whose base address is provided via begin().
Only the register level audio path setup (analog DAC/ADC bias, clock dividers for the non-PLL sample rates 8/12/16/24/32/48 kHz, channel enable, volume and mute) is implemented. The fractional audio PLL (needed for the 44.1 kHz family and for PLL based clocking) requires factory trim/calibration data and SoC specific calibration routines that are out of scope for a register level port; CODEC_CLK_USING_PLL is therefore always treated as 0 (XTAL 48 MHz reference).
| enum Reg : uint32_t |
Register offsets (byte offsets from the AUDCODEC base address)
|
inlinestaticprotected |
|
inlineinherited |
Provides the actual I2C address of the codec.
|
pure virtualinherited |
Initializes the codec.
Implemented in AW88298, DA7212, MAX98091, PCM1681, TAS2563, TAS6422DAC, TLV320AIC3110, TLV320DAC310x, WM8904, and WM8962.
|
inline |
Initializes the analog references (bandgap/refgen/PLL digital clocks) and configures the DAC output path for the given sample rate.
| base | AUDCODEC peripheral base address |
| sample_rate | one of 8000, 12000, 16000, 24000, 32000, 48000 |
|
inline |
Configures and enables the ADC input path for the given sample rate. begin() must have been called first (for the shared bandgap/refgen).
|
inlineprotected |
|
inlineprotected |
Powers down the analog ADC path (mirrors close_analog_adc_path()).
|
inlineprotected |
Powers down the analog DAC path (mirrors close_analog_dac_path()).
|
inlineprotected |
Configures the analog ADC bias/clock tree and enables ADC1.
|
inlineprotected |
Configures the analog DAC bias/clock tree and enables the DAC amps.
|
inlineprotected |
Enables/disables the digital bypass path on both DAC channels.
|
inlineprotected |
Configures the digital ADC channel 0 path (DMA disabled).
|
inlineprotected |
Configures the digital DAC channel 0 path (DMA disabled - data is fed via DAC_CH0_ENTRY or, if bypass is used, DAC_CH0_DEBUG).
|
inlinestaticprotected |
|
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.
|
inlinevirtualinherited |
|
inlineprotected |
Mutes/unmutes DAC channel 0 by forcing the fine volume to its mute value (0xF) and restoring the previous value on unmute (mirrors mute_dac_path()).
|
inlineprotected |
Enables the bandgap reference, reference generator and PLL digital clocks (no PLL frequency calibration, see class documentation).
|
inlineprotected |
|
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 |
|
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.
|
inline |
Provides the (memory mapped) base address of the AUDCODEC register block. Must be called before begin().
|
inlineprotected |
|
inlinevirtualinherited |
Selects the ADC input source / DAC output destination. By default this is a no-op; chip specific subclasses that support input/output routing override this to configure the corresponding registers.
Reimplemented in DA7212, MAX98091, TAS6422DAC, TLV320AIC3110, TLV320DAC310x, WM8904, and WM8962.
|
inlinevirtualinherited |
|
inlineoverridevirtual |
Mutes/unmutes the DAC output (channel 0). The previous fine volume setting is restored when un-muting.
Reimplemented from ZephyrDriverCommon.
|
inlineoverridevirtual |
Sets the DAC output volume in % (0...100), mapped to [MIN_VOLUME_DB..MAX_VOLUME_DB]
Reimplemented from ZephyrDriverCommon.
|
inline |
Sets the DAC output volume in dB, range MIN_VOLUME_DB..MAX_VOLUME_DB.
|
inlineinherited |
Defines the I2C communication object.
|
inline |
Starts (un-mutes) the DAC output path.
|
inline |
Mutes and disables the DAC output path.
|
inline |
Disables the ADC input path.
|
inlineprotectedinherited |
Read-Modify-Write of a single byte register.
|
inlineprotectedinherited |
Read-Modify-Write of a 16 bit (big endian) register.
|
inlineprotected |
Read-Modify-Write of selected bits of a 32 bit register.
|
inlineprotected |
|
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 |
|
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()
|
protected |
|
staticconstexpr |
|
staticconstexpr |
DAC volume range (1 dB units): -36 dB .. +54 dB, applied via rough (6 dB step) + fine (0.5 dB step) volume fields.
|
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 |
|
protected |
|
protectedinherited |
Last volume (in %) provided to setVolume()
|
protectedinherited |