|
arduino-audio-driver
|
Header only C++ driver for the AW88298 smart amplifier. More...
#include <AW88298.h>
Public Types | |
| enum | Reg : uint8_t { REG_ID = 0x00 , REG_SYSST = 0x01 , REG_SYSINT = 0x02 , REG_SYSINTM = 0x03 , REG_SYSCTRL = 0x04 , REG_SYSCTRL2 = 0x05 , REG_I2SCTRL = 0x06 , REG_HAGCCFG1 = 0x09 , REG_HAGCCFG2 = 0x0A , REG_HAGCCFG3 = 0x0B , REG_HAGCCFG4 = 0x0C } |
Public Member Functions | |
| AW88298 () | |
| AW88298 I2C address is board dependent; 0x36 is a common default. | |
| uint8_t | address () |
| Provides the actual I2C address of the codec. | |
| bool | begin (AW88298Mode mode=AW88298Mode::I2S, uint8_t word_size=16, uint32_t sample_rate=44100) |
| bool | begin (uint32_t sample_rate, uint8_t bits) |
| Initialize the amplifier: software reset, power up (clear PWDN/AMPPD), unmute, and configure the digital audio interface (mode, word size, sample rate). | |
| bool | begin (uint32_t sample_rate, uint8_t bits, codec_mode_t mode, i2s_format_t fmt, bool is_master, uint8_t channels) override |
| Initializes the codec. | |
| 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. | |
| virtual bool | setDevices (input_device_t input_device, output_device_t output_device) |
| bool | setFormat (AW88298Mode mode, uint8_t word_size, uint32_t sample_rate) |
| Configure the digital audio interface: protocol mode, word size and sample rate, and enable the I2S interface (I2SEN). The AW88298 always operates as I2S clock slave. | |
| virtual bool | setInputVolume (int volume) |
| bool | setMute (bool mute) override |
| Mute / unmute the output (HAGCCFG4/SYSCTRL2 HMUTE bit) | |
| bool | setVolume (int volume) override |
| Sets the output volume in % (0...100), mapped to [VOLUME_DB_MIN..VOLUME_DB_MAX] dB. | |
| bool | setVolumeDb (int db) |
| Set the output volume in dB. | |
| void | setWire (i2c_bus_handle_t w) |
| Defines the I2C communication object. | |
| bool | softReset () |
| Trigger a software reset via REG_ID. | |
| bool | startOutput () |
| Enable the power amplifier output stage (clears AMPPD) | |
| bool | stopOutput () |
| Disable the power amplifier output stage (sets AMPPD) | |
Static Public Attributes | |
| static constexpr uint16_t | HAGCCFG4_VOL_MASK = (0xFFU << 8) |
| static constexpr uint16_t | I2SCTRL_I2SBCK_MASK = (0x03U << 4) |
| static constexpr uint16_t | I2SCTRL_I2SFS_MASK = (0x03U << 6) |
| static constexpr uint16_t | I2SCTRL_I2SMD_MASK = (0x07U << 8) |
| static constexpr uint16_t | I2SCTRL_I2SSR_MASK = (0x0FU << 0) |
| static constexpr uint16_t | ID_SOFTRESET = 0x55AA |
| Magic value written to REG_ID to trigger a software reset. | |
| static constexpr uint16_t | SYSCTRL2_HMUTE = (1U << 4) |
| static constexpr uint16_t | SYSCTRL_AMPPD = (1U << 1) |
| static constexpr uint16_t | SYSCTRL_I2SEN = (1U << 6) |
| static constexpr uint16_t | SYSCTRL_PWDN = (1U << 0) |
| static constexpr int | VOLUME_DB_MAX = 0 |
| static constexpr int | VOLUME_DB_MIN = -96 |
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 | 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. | |
Static Protected Member Functions | |
| static uint8_t | db2vol (int db) |
| static bool | sampleRateCode (uint32_t sample_rate, uint16_t &code) |
| static bool | wordSizeCodes (uint8_t word_size, uint16_t &fs_code, uint16_t &bck_code) |
Protected Attributes | |
| uint8_t | i2c_addr = 0 |
| int | input_volume_percent = 100 |
| Last input volume (in %) provided to setInputVolume() | |
| int | volume_percent = 100 |
| Last volume (in %) provided to setVolume() | |
| i2c_bus_handle_t | wire = nullptr |
Header only C++ driver for the AW88298 smart amplifier.
The AW88298 is controlled via a set of 16-bit (big endian) registers addressed with an 8-bit register address, so the ZephyrDriver writeReg16/readReg16/updateReg16 helpers are used.
The reset pin (if present on the board) must be driven externally (the Zephyr driver toggles a devicetree-defined GPIO during init when available, otherwise it issues a software reset via AW88298_REG_ID).
| enum Reg : uint8_t |
|
inlineinherited |
Provides the actual I2C address of the codec.
|
inline |
|
inline |
Initialize the amplifier: software reset, power up (clear PWDN/AMPPD), unmute, and configure the digital audio interface (mode, word size, sample rate).
| mode | I2S protocol variant |
| word_size | I2S word size in bits (16, 20, 24, 32) |
| sample_rate | I2S sample rate in Hz Initializes the codec for I2S with the given sample rate and bits per sample |
|
inlineoverridevirtual |
Initializes the codec.
Implements ZephyrDriverCommon.
|
inlinestaticprotected |
Convert a dB attenuation value (<=0) to the AW88298 volume code (high nibble = 6dB steps, low nibble = 0.5dB steps)
|
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 |
|
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.
|
inlinestaticprotected |
|
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.
|
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.
|
inline |
Configure the digital audio interface: protocol mode, word size and sample rate, and enable the I2S interface (I2SEN). The AW88298 always operates as I2S clock slave.
|
inlinevirtualinherited |
|
inlineoverridevirtual |
Mute / unmute the output (HAGCCFG4/SYSCTRL2 HMUTE bit)
Reimplemented from ZephyrDriverCommon.
|
inlineoverridevirtual |
Sets the output volume in % (0...100), mapped to [VOLUME_DB_MIN..VOLUME_DB_MAX] dB.
Reimplemented from ZephyrDriverCommon.
|
inline |
Set the output volume in dB.
| db | volume in dB, range [-96..0] |
|
inlineinherited |
Defines the I2C communication object.
|
inline |
Trigger a software reset via REG_ID.
|
inline |
Enable the power amplifier output stage (clears AMPPD)
|
inline |
Disable the power amplifier output stage (sets AMPPD)
|
inlineprotectedinherited |
Read-Modify-Write of a single byte register.
|
inlineprotectedinherited |
Read-Modify-Write of a 16 bit (big endian) register.
|
inlinestaticprotected |
|
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 |
|
protectedinherited |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
Magic value written to REG_ID to trigger a software reset.
|
protectedinherited |
Last input volume (in %) provided to setInputVolume()
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
protectedinherited |
Last volume (in %) provided to setVolume()
|
protectedinherited |