arduino-audio-driver
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
TAS6422DAC Class Reference

Header only C++ driver for the TAS6422 2-channel Class-D amplifier. More...

#include <TAS6422DAC.h>

Inheritance diagram for TAS6422DAC:
ZephyrDriverCommon

Public Types

enum  Reg : uint8_t {
  MODE_CTRL_ADDR = 0x00 , MISC_CTRL_1_ADDR = 0x01 , MISC_CTRL_2_ADDR = 0x02 , SAP_CTRL_ADDR = 0x03 ,
  CH_STATE_CTRL_ADDR = 0x04 , CH1_VOLUME_CTRL_ADDR = 0x05 , CH2_VOLUME_CTRL_ADDR = 0x06 , DC_LDG_CTRL_1_ADDR = 0x09 ,
  DC_LDG_CTRL_2_ADDR = 0x0A , DC_LDG_REPORT_1_ADDR = 0x0C , DC_LDG_REPORT_3_ADDR = 0x0E , CH_FAULTS_ADDR = 0x10 ,
  GLOBAL_FAULTS_1_ADDR = 0x11 , GLOBAL_FAULTS_2_ADDR = 0x12 , WARNINGS_ADDR = 0x13 , PIN_CTRL_ADDR = 0x14 ,
  MISC_CTRL_3_ADDR = 0x21 , ILIMIT_STATUS_ADDR = 0x25 , MISC_CTRL_4_ADDR = 0x26 , MISC_CTRL_5_ADDR = 0x28
}
 

Public Member Functions

 TAS6422DAC ()
 
uint8_t address ()
 Provides the actual I2C address of the codec.
 
bool begin (uint32_t sample_rate, uint8_t bits)
 Initialize the codec: soft reset, configure the I2S input format/sample rate and apply default output settings (overcurrent level, PWM frequency). The channels are muted (Hiz state is not used) until start() is called.
 
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.
 
bool begin (uint32_t sample_rate=44100)
 
bool clearFaults ()
 
bool configureDai (uint32_t sample_rate)
 Configure the serial audio port: I2S input format and input sampling rate.
 
bool configureOutput ()
 Apply default output settings: overcurrent level = 1, PWM frequency = 10 fs (reduced from default to avoid component overtemperature).
 
bool getChannelFaults (uint8_t &value)
 Read the channel faults register (over-current / DC detection)
 
bool getGlobalFaults1 (uint8_t &value)
 Read the global faults 1 register (clock / supply voltage faults)
 
bool getGlobalFaults2 (uint8_t &value)
 Read the global faults 2 register (thermal shutdown faults)
 
virtual int getInputVolume ()
 
virtual int getVolume ()
 Provides the output volume in % (0...100) that was set with setVolume()
 
bool getWarnings (uint8_t &value)
 Read the warnings register (POR / over-temperature warnings)
 
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.
 
bool setChannelState (TAS6422Channel channel, TAS6422ChannelState state)
 Set the channel state (Play, Hiz, Mute or DcLoad) for the given channel(s)
 
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)
 
virtual bool setMute (bool mute)
 
bool setMute (bool mute, TAS6422Channel channel=TAS6422Channel::All)
 Mute / unmute the given channel(s)
 
bool setOutputVolume (int volume, TAS6422Channel channel=TAS6422Channel::All)
 Set the output volume in 0.5dB steps.
 
bool setVolume (int volume) override
 
void setWire (i2c_bus_handle_t w)
 Defines the I2C communication object.
 
bool softReset ()
 Trigger a soft reset (sets the RESET bit in MODE_CTRL)
 
bool start (TAS6422Channel channel=TAS6422Channel::All)
 Unmute (set to Play state) the given channel(s)
 
bool stop (TAS6422Channel channel=TAS6422Channel::All)
 Mute the given channel(s)
 

Static Public Attributes

static constexpr uint8_t CH_STATE_CTRL_CH1_STATE_CTRL_MASK = (0x3u << 6)
 
static constexpr uint8_t CH_STATE_CTRL_CH2_STATE_CTRL_MASK = (0x3u << 4)
 
static constexpr uint8_t CH_VOLUME_CTRL_VOLUME_MASK = 0xFFu
 
static constexpr uint8_t MISC_CTRL_1_GAIN_MASK = 0x3u
 
static constexpr uint8_t MISC_CTRL_1_HPF_BYPASS = (1u << 7)
 
static constexpr uint8_t MISC_CTRL_1_OC_CONTROL_MASK = (1u << 4)
 
static constexpr uint8_t MISC_CTRL_1_OTW_CONTROL_MASK = (0x3u << 5)
 
static constexpr uint8_t MISC_CTRL_1_VOLUME_RATE_MASK = (0x3u << 2)
 
static constexpr uint8_t MISC_CTRL_2_OUTPUT_PHASE_MASK = 0x3u
 
static constexpr uint8_t MISC_CTRL_2_PWM_FREQUENCY_10_FS = 1
 
static constexpr uint8_t MISC_CTRL_2_PWM_FREQUENCY_38_FS = 5
 
static constexpr uint8_t MISC_CTRL_2_PWM_FREQUENCY_44_FS = 6
 
static constexpr uint8_t MISC_CTRL_2_PWM_FREQUENCY_48_FS = 7
 
static constexpr uint8_t MISC_CTRL_2_PWM_FREQUENCY_8_FS = 0
 
static constexpr uint8_t MISC_CTRL_2_PWM_FREQUENCY_MASK = (0x7u << 4)
 
static constexpr uint8_t MISC_CTRL_2_SDM_OSR = (1u << 2)
 
static constexpr uint8_t MODE_CTRL_CH1_LO_MODE = (1u << 3)
 
static constexpr uint8_t MODE_CTRL_CH2_LO_MODE = (1u << 2)
 
static constexpr uint8_t MODE_CTRL_PBTL_CH12 = (1u << 4)
 
static constexpr uint8_t MODE_CTRL_RESET = (1u << 7)
 
static constexpr int OUTPUT_VOLUME_MAX = (24 * 2)
 
static constexpr int OUTPUT_VOLUME_MIN = (-100 * 2)
 
static constexpr uint8_t SAP_CTRL_INPUT_FORMAT_MASK = 0x7u
 
static constexpr uint8_t SAP_CTRL_INPUT_SAMPLING_RATE_44_1_KHZ = 0
 
static constexpr uint8_t SAP_CTRL_INPUT_SAMPLING_RATE_48_KHZ = 1
 
static constexpr uint8_t SAP_CTRL_INPUT_SAMPLING_RATE_96_KHZ = 2
 
static constexpr uint8_t SAP_CTRL_INPUT_SAMPLING_RATE_MASK = (0x3u << 6)
 
static constexpr uint8_t SAP_CTRL_TDM_SLOT_SELECT = (1u << 5)
 
static constexpr uint8_t SAP_CTRL_TDM_SLOT_SELECT_2 = (1u << 3)
 
static constexpr uint8_t SAP_CTRL_TDM_SLOT_SIZE = (1u << 4)
 

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.
 

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
 

Detailed Description

Header only C++ driver for the TAS6422 2-channel Class-D amplifier.

Provides a soft reset, I2S/sample-rate configuration, per-channel mute/play state control and output volume control, ported from the corresponding Zephyr RTOS driver.

Member Enumeration Documentation

◆ Reg

enum Reg : uint8_t
Enumerator
MODE_CTRL_ADDR 
MISC_CTRL_1_ADDR 
MISC_CTRL_2_ADDR 
SAP_CTRL_ADDR 
CH_STATE_CTRL_ADDR 
CH1_VOLUME_CTRL_ADDR 
CH2_VOLUME_CTRL_ADDR 
DC_LDG_CTRL_1_ADDR 
DC_LDG_CTRL_2_ADDR 
DC_LDG_REPORT_1_ADDR 
DC_LDG_REPORT_3_ADDR 
CH_FAULTS_ADDR 
GLOBAL_FAULTS_1_ADDR 
GLOBAL_FAULTS_2_ADDR 
WARNINGS_ADDR 
PIN_CTRL_ADDR 
MISC_CTRL_3_ADDR 
ILIMIT_STATUS_ADDR 
MISC_CTRL_4_ADDR 
MISC_CTRL_5_ADDR 

Constructor & Destructor Documentation

◆ TAS6422DAC()

TAS6422DAC ( )
inline

Member Function Documentation

◆ address()

uint8_t address ( )
inlineinherited

Provides the actual I2C address of the codec.

◆ begin() [1/3]

bool begin ( uint32_t  sample_rate,
uint8_t  bits 
)
inline

Initialize the codec: soft reset, configure the I2S input format/sample rate and apply default output settings (overcurrent level, PWM frequency). The channels are muted (Hiz state is not used) until start() is called.

Note: TAS6422 also has an optional hardware MUTE pin; if your board wires it, drive it externally (active = muted) in addition to the register based mute.

Parameters
sample_rateI2S sample rate in Hz (44100, 48000 or 96000) Initializes the codec for I2S with the given sample rate (bits per sample is not configurable on this chip)

◆ begin() [2/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.

◆ begin() [3/3]

bool begin ( uint32_t  sample_rate = 44100)
inline

◆ clearFaults()

bool clearFaults ( )
inline

Read and clear the global/channel fault registers (writing 1 to MISC_CTRL_3 CLEAR_FAULT)

◆ configureDai()

bool configureDai ( uint32_t  sample_rate)
inline

Configure the serial audio port: I2S input format and input sampling rate.

Parameters
sample_rate44100, 48000 or 96000 Hz

◆ configureOutput()

bool configureOutput ( )
inline

Apply default output settings: overcurrent level = 1, PWM frequency = 10 fs (reduced from default to avoid component overtemperature).

This chip only drives speaker outputs (no headphone path), so it is only configured for DAC_OUTPUT_LINE2 (speaker) and DAC_OUTPUT_ALL. For DAC_OUTPUT_NONE / DAC_OUTPUT_LINE1 (headphone, not supported) all channels are kept muted.

◆ getChannelFaults()

bool getChannelFaults ( uint8_t &  value)
inline

Read the channel faults register (over-current / DC detection)

◆ getGlobalFaults1()

bool getGlobalFaults1 ( uint8_t &  value)
inline

Read the global faults 1 register (clock / supply voltage faults)

◆ getGlobalFaults2()

bool getGlobalFaults2 ( uint8_t &  value)
inline

Read the global faults 2 register (thermal shutdown faults)

◆ 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()

◆ getWarnings()

bool getWarnings ( uint8_t &  value)
inline

Read the warnings register (POR / over-temperature warnings)

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

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

◆ setChannelState()

bool setChannelState ( TAS6422Channel  channel,
TAS6422ChannelState  state 
)
inline

Set the channel state (Play, Hiz, Mute or DcLoad) for the given channel(s)

◆ setDevices()

bool setDevices ( input_device_t  input_device,
output_device_t  output_device 
)
inlineoverridevirtual

Stores the output device selection for use by configureOutput()

Reimplemented from ZephyrDriverCommon.

◆ 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() [1/2]

virtual bool setMute ( bool  mute)
inlinevirtualinherited

Mutes/unmutes all outputs. Chip specific subclasses map this to their native mute functionality.

Reimplemented in AW88298, DA7212, MAX98091, PCM1681, TAS2563, TLV320AIC3110, TLV320DAC310x, WM8904, WM8962, and SF32LB.

◆ setMute() [2/2]

bool setMute ( bool  mute,
TAS6422Channel  channel = TAS6422Channel::All 
)
inline

Mute / unmute the given channel(s)

◆ setOutputVolume()

bool setOutputVolume ( int  volume,
TAS6422Channel  channel = TAS6422Channel::All 
)
inline

Set the output volume in 0.5dB steps.

Parameters
volumesigned volume in 0.5dB steps, range OUTPUT_VOLUME_MIN (-200, i.e. -100dB) .. OUTPUT_VOLUME_MAX (48, i.e. +24dB)

◆ setVolume()

bool setVolume ( int  volume)
inlineoverridevirtual

Sets the output volume in % (0...100) for all channels, mapped to [OUTPUT_VOLUME_MIN..OUTPUT_VOLUME_MAX] (0.5dB steps)

Reimplemented from ZephyrDriverCommon.

◆ setWire()

void setWire ( i2c_bus_handle_t  w)
inlineinherited

Defines the I2C communication object.

◆ softReset()

bool softReset ( )
inline

Trigger a soft reset (sets the RESET bit in MODE_CTRL)

◆ start()

bool start ( TAS6422Channel  channel = TAS6422Channel::All)
inline

Unmute (set to Play state) the given channel(s)

◆ stop()

bool stop ( TAS6422Channel  channel = TAS6422Channel::All)
inline

Mute the given channel(s)

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

◆ 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

◆ CH_STATE_CTRL_CH1_STATE_CTRL_MASK

constexpr uint8_t CH_STATE_CTRL_CH1_STATE_CTRL_MASK = (0x3u << 6)
staticconstexpr

◆ CH_STATE_CTRL_CH2_STATE_CTRL_MASK

constexpr uint8_t CH_STATE_CTRL_CH2_STATE_CTRL_MASK = (0x3u << 4)
staticconstexpr

◆ CH_VOLUME_CTRL_VOLUME_MASK

constexpr uint8_t CH_VOLUME_CTRL_VOLUME_MASK = 0xFFu
staticconstexpr

◆ i2c_addr

uint8_t i2c_addr = 0
protectedinherited

◆ input_volume_percent

int input_volume_percent = 100
protectedinherited

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

◆ MISC_CTRL_1_GAIN_MASK

constexpr uint8_t MISC_CTRL_1_GAIN_MASK = 0x3u
staticconstexpr

◆ MISC_CTRL_1_HPF_BYPASS

constexpr uint8_t MISC_CTRL_1_HPF_BYPASS = (1u << 7)
staticconstexpr

◆ MISC_CTRL_1_OC_CONTROL_MASK

constexpr uint8_t MISC_CTRL_1_OC_CONTROL_MASK = (1u << 4)
staticconstexpr

◆ MISC_CTRL_1_OTW_CONTROL_MASK

constexpr uint8_t MISC_CTRL_1_OTW_CONTROL_MASK = (0x3u << 5)
staticconstexpr

◆ MISC_CTRL_1_VOLUME_RATE_MASK

constexpr uint8_t MISC_CTRL_1_VOLUME_RATE_MASK = (0x3u << 2)
staticconstexpr

◆ MISC_CTRL_2_OUTPUT_PHASE_MASK

constexpr uint8_t MISC_CTRL_2_OUTPUT_PHASE_MASK = 0x3u
staticconstexpr

◆ MISC_CTRL_2_PWM_FREQUENCY_10_FS

constexpr uint8_t MISC_CTRL_2_PWM_FREQUENCY_10_FS = 1
staticconstexpr

◆ MISC_CTRL_2_PWM_FREQUENCY_38_FS

constexpr uint8_t MISC_CTRL_2_PWM_FREQUENCY_38_FS = 5
staticconstexpr

◆ MISC_CTRL_2_PWM_FREQUENCY_44_FS

constexpr uint8_t MISC_CTRL_2_PWM_FREQUENCY_44_FS = 6
staticconstexpr

◆ MISC_CTRL_2_PWM_FREQUENCY_48_FS

constexpr uint8_t MISC_CTRL_2_PWM_FREQUENCY_48_FS = 7
staticconstexpr

◆ MISC_CTRL_2_PWM_FREQUENCY_8_FS

constexpr uint8_t MISC_CTRL_2_PWM_FREQUENCY_8_FS = 0
staticconstexpr

◆ MISC_CTRL_2_PWM_FREQUENCY_MASK

constexpr uint8_t MISC_CTRL_2_PWM_FREQUENCY_MASK = (0x7u << 4)
staticconstexpr

◆ MISC_CTRL_2_SDM_OSR

constexpr uint8_t MISC_CTRL_2_SDM_OSR = (1u << 2)
staticconstexpr

◆ MODE_CTRL_CH1_LO_MODE

constexpr uint8_t MODE_CTRL_CH1_LO_MODE = (1u << 3)
staticconstexpr

◆ MODE_CTRL_CH2_LO_MODE

constexpr uint8_t MODE_CTRL_CH2_LO_MODE = (1u << 2)
staticconstexpr

◆ MODE_CTRL_PBTL_CH12

constexpr uint8_t MODE_CTRL_PBTL_CH12 = (1u << 4)
staticconstexpr

◆ MODE_CTRL_RESET

constexpr uint8_t MODE_CTRL_RESET = (1u << 7)
staticconstexpr

◆ output_device

output_device_t output_device = DAC_OUTPUT_ALL
protected

Output device selection set via setDevices(), used by configureOutput()

◆ OUTPUT_VOLUME_MAX

constexpr int OUTPUT_VOLUME_MAX = (24 * 2)
staticconstexpr

◆ OUTPUT_VOLUME_MIN

constexpr int OUTPUT_VOLUME_MIN = (-100 * 2)
staticconstexpr

◆ SAP_CTRL_INPUT_FORMAT_MASK

constexpr uint8_t SAP_CTRL_INPUT_FORMAT_MASK = 0x7u
staticconstexpr

◆ SAP_CTRL_INPUT_SAMPLING_RATE_44_1_KHZ

constexpr uint8_t SAP_CTRL_INPUT_SAMPLING_RATE_44_1_KHZ = 0
staticconstexpr

◆ SAP_CTRL_INPUT_SAMPLING_RATE_48_KHZ

constexpr uint8_t SAP_CTRL_INPUT_SAMPLING_RATE_48_KHZ = 1
staticconstexpr

◆ SAP_CTRL_INPUT_SAMPLING_RATE_96_KHZ

constexpr uint8_t SAP_CTRL_INPUT_SAMPLING_RATE_96_KHZ = 2
staticconstexpr

◆ SAP_CTRL_INPUT_SAMPLING_RATE_MASK

constexpr uint8_t SAP_CTRL_INPUT_SAMPLING_RATE_MASK = (0x3u << 6)
staticconstexpr

◆ SAP_CTRL_TDM_SLOT_SELECT

constexpr uint8_t SAP_CTRL_TDM_SLOT_SELECT = (1u << 5)
staticconstexpr

◆ SAP_CTRL_TDM_SLOT_SELECT_2

constexpr uint8_t SAP_CTRL_TDM_SLOT_SELECT_2 = (1u << 3)
staticconstexpr

◆ SAP_CTRL_TDM_SLOT_SIZE

constexpr uint8_t SAP_CTRL_TDM_SLOT_SIZE = (1u << 4)
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: