arduino-audio-driver
Loading...
Searching...
No Matches
AW88298 Class Reference

Header only C++ driver for the AW88298 smart amplifier. More...

#include <AW88298.h>

Inheritance diagram for AW88298:
ZephyrDriverCommon

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, bool stopBit=true)
 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

Detailed Description

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).

Member Enumeration Documentation

◆ Reg

enum Reg : uint8_t
Enumerator
REG_ID 
REG_SYSST 
REG_SYSINT 
REG_SYSINTM 
REG_SYSCTRL 
REG_SYSCTRL2 
REG_I2SCTRL 
REG_HAGCCFG1 
REG_HAGCCFG2 
REG_HAGCCFG3 
REG_HAGCCFG4 

Constructor & Destructor Documentation

◆ AW88298()

AW88298 ( )
inline

AW88298 I2C address is board dependent; 0x36 is a common default.

Member Function Documentation

◆ address()

uint8_t address ( )
inlineinherited

Provides the actual I2C address of the codec.

◆ begin() [1/3]

bool begin ( AW88298Mode mode = AW88298Mode::I2S,
uint8_t word_size = 16,
uint32_t sample_rate = 44100 )
inline

◆ begin() [2/3]

bool begin ( uint32_t sample_rate,
uint8_t bits )
inline

Initialize the amplifier: software reset, power up (clear PWDN/AMPPD), unmute, and configure the digital audio interface (mode, word size, sample rate).

Parameters
modeI2S protocol variant
word_sizeI2S word size in bits (16, 20, 24, 32)
sample_rateI2S sample rate in Hz Initializes the codec for I2S with the given sample rate and bits per sample

◆ begin() [3/3]

bool begin ( uint32_t sample_rate,
uint8_t bits,
codec_mode_t mode,
i2s_format_t fmt,
bool is_master,
uint8_t channels )
inlineoverridevirtual

Initializes the codec.

Implements ZephyrDriverCommon.

◆ db2vol()

uint8_t db2vol ( int db)
inlinestaticprotected

Convert a dB attenuation value (<=0) to the AW88298 volume code (high nibble = 6dB steps, low nibble = 0.5dB steps)

◆ getInputVolume()

virtual int getInputVolume ( )
inlinevirtualinherited

Provides the input volume in % (0...100) that was set with setInputVolume()

◆ getVolume()

virtual int getVolume ( )
inlinevirtualinherited

Provides the output volume in % (0...100) that was set with setVolume().

◆ getWire()

i2c_bus_handle_t getWire ( )
inlineinherited

Provides the actual I2C communication object.

◆ isInputVolumeSupported()

virtual bool isInputVolumeSupported ( )
inlinevirtualinherited

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.

Reimplemented in DA7212, WM8904, and WM8962.

◆ readReg()

bool readReg ( uint8_t reg,
uint8_t & value,
bool stopBit = true )
inlineprotectedinherited

Reads a single byte from an 8 bit register address.

◆ readReg16()

bool readReg16 ( uint8_t reg,
uint16_t & value )
inlineprotectedinherited

Reads a 16 bit (big endian) value from an 8 bit register address.

◆ sampleRateCode()

bool sampleRateCode ( uint32_t sample_rate,
uint16_t & code )
inlinestaticprotected

◆ setActive()

virtual bool setActive ( codec_mode_t mode)
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.

Reimplemented in DA7212, WM8904, and WM8962.

◆ setAddress()

void setAddress ( uint8_t addr)
inlineinherited

Defines the I2C address of the codec.

◆ setDevices()

virtual bool setDevices ( input_device_t input_device,
output_device_t output_device )
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, TLV320AIC3104, TLV320AIC3110, TLV320DAC310x, WM8904, and WM8962.

◆ setFormat()

bool setFormat ( AW88298Mode mode,
uint8_t word_size,
uint32_t sample_rate )
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.

◆ setInputVolume()

virtual bool setInputVolume ( int volume)
inlinevirtualinherited

Defines the input volume in % (0...100). Chip specific subclasses map this to their native input volume range.

Reimplemented in DA7212, WM8904, and WM8962.

◆ setMute()

bool setMute ( bool mute)
inlineoverridevirtual

Mute / unmute the output (HAGCCFG4/SYSCTRL2 HMUTE bit).

Reimplemented from ZephyrDriverCommon.

◆ setVolume()

bool setVolume ( int volume)
inlineoverridevirtual

Sets the output volume in % (0...100), mapped to [VOLUME_DB_MIN..VOLUME_DB_MAX] dB.

Reimplemented from ZephyrDriverCommon.

◆ setVolumeDb()

bool setVolumeDb ( int db)
inline

Set the output volume in dB.

Parameters
dbvolume in dB, range [-96..0]

◆ setWire()

void setWire ( i2c_bus_handle_t w)
inlineinherited

Defines the I2C communication object.

◆ softReset()

bool softReset ( )
inline

Trigger a software reset via REG_ID.

◆ startOutput()

bool startOutput ( )
inline

Enable the power amplifier output stage (clears AMPPD).

◆ stopOutput()

bool stopOutput ( )
inline

Disable the power amplifier output stage (sets AMPPD).

◆ updateReg()

bool updateReg ( uint8_t reg,
uint8_t mask,
uint8_t value )
inlineprotectedinherited

Read-Modify-Write of a single byte register.

◆ updateReg16()

bool updateReg16 ( uint8_t reg,
uint16_t mask,
uint16_t value )
inlineprotectedinherited

Read-Modify-Write of a 16 bit (big endian) register.

◆ wordSizeCodes()

bool wordSizeCodes ( uint8_t word_size,
uint16_t & fs_code,
uint16_t & bck_code )
inlinestaticprotected

◆ writeReg()

bool writeReg ( uint8_t reg,
uint8_t value )
inlineprotectedinherited

Writes a single byte to an 8 bit register address.

◆ writeReg16()

bool writeReg16 ( uint8_t reg,
uint16_t value )
inlineprotectedinherited

Writes a 16 bit (big endian) value to an 8 bit register address.

Member Data Documentation

◆ HAGCCFG4_VOL_MASK

uint16_t HAGCCFG4_VOL_MASK = (0xFFU << 8)
staticconstexpr

◆ i2c_addr

uint8_t i2c_addr = 0
protectedinherited

◆ I2SCTRL_I2SBCK_MASK

uint16_t I2SCTRL_I2SBCK_MASK = (0x03U << 4)
staticconstexpr

◆ I2SCTRL_I2SFS_MASK

uint16_t I2SCTRL_I2SFS_MASK = (0x03U << 6)
staticconstexpr

◆ I2SCTRL_I2SMD_MASK

uint16_t I2SCTRL_I2SMD_MASK = (0x07U << 8)
staticconstexpr

◆ I2SCTRL_I2SSR_MASK

uint16_t I2SCTRL_I2SSR_MASK = (0x0FU << 0)
staticconstexpr

◆ ID_SOFTRESET

uint16_t ID_SOFTRESET = 0x55AA
staticconstexpr

Magic value written to REG_ID to trigger a software reset.

◆ input_volume_percent

int input_volume_percent = 100
protectedinherited

Last input volume (in %) provided to setInputVolume().

◆ SYSCTRL2_HMUTE

uint16_t SYSCTRL2_HMUTE = (1U << 4)
staticconstexpr

◆ SYSCTRL_AMPPD

uint16_t SYSCTRL_AMPPD = (1U << 1)
staticconstexpr

◆ SYSCTRL_I2SEN

uint16_t SYSCTRL_I2SEN = (1U << 6)
staticconstexpr

◆ SYSCTRL_PWDN

uint16_t SYSCTRL_PWDN = (1U << 0)
staticconstexpr

◆ VOLUME_DB_MAX

int VOLUME_DB_MAX = 0
staticconstexpr

◆ VOLUME_DB_MIN

int VOLUME_DB_MIN = -96
staticconstexpr

◆ volume_percent

int volume_percent = 100
protectedinherited

Last volume (in %) provided to setVolume().

◆ wire

i2c_bus_handle_t wire = nullptr
protectedinherited

The documentation for this class was generated from the following file: