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

Header only C++ driver for the PCM1681 8-channel audio DAC. More...

#include <PCM1681.h>

Inheritance diagram for PCM1681:
ZephyrDriverCommon

Public Types

enum  Reg : uint8_t {
  REG_0 = 0x00 , AT1x_REG = 0x01 , AT2x_REG = 0x02 , AT3x_REG = 0x03 ,
  AT4x_REG = 0x04 , AT5x_REG = 0x05 , AT6x_REG = 0x06 , MUTx_REG = 0x07 ,
  DACx_REG = 0x08 , FMTx_REG = 0x09 , SRST_REG = 0x0A , REVx_REG = 0x0B ,
  FLTx_REG = 0x0C , DAMS_REG = 0x0D , REG_14 = 0x0E , REG_15 = 0x0F ,
  AT7x_REG = 0x10 , AT8x_REG = 0x11 , MUT_OR_REG = 0x12 , DAC_OR_REG = 0x13
}

Public Member Functions

 PCM1681 ()
uint8_t address ()
 Provides the actual I2C address of the codec.
bool applyProperties ()
bool begin (PCM1681Format format=PCM1681Format::I2S_16_24)
bool begin (uint32_t sample_rate, uint8_t bits)
 Initialize the codec: reset the local register shadow to the factory defaults, configure the DAI format and write everything to the device.
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.
bool setAttenuationScale (PCM1681AttenuationScale scale, bool apply=true)
 Configure the attenuation scale (fine 0.5dB / wide 1.0dB steps).
bool setDacEnabled (bool enable)
 Enable or disable the DAC output of all channels.
bool setDacEnabled (uint8_t channel, bool enable, bool apply=true)
 Enable or disable the DAC output of a single channel (used for start_output / stop_output).
bool setDeemphasisEnabled (bool enable, bool apply=true)
 Enable or disable the digital de-emphasis filter.
bool setDeemphasisRate (PCM1681DeemphasisRate rate, bool apply=true)
 Configure the digital de-emphasis filter sample rate.
virtual bool setDevices (input_device_t input_device, output_device_t output_device)
bool setFilterRollOff (PCM1681FilterRollOff roll_off, bool apply=true)
 Configure the digital filter roll-off characteristic.
bool setFormat (PCM1681Format format, bool apply=true)
 Configure the digital audio interface format.
virtual bool setInputVolume (int volume)
bool setMute (bool mute) override
 Mute or unmute all 8 channels.
bool setMute (uint8_t channel, bool mute, bool apply=true)
 Mute or unmute a single output channel.
bool setVolume (uint8_t channel, uint8_t volume, bool apply=true)
 Set the volume (attenuation) of a single output channel.
bool setVolume (uint8_t volume)
 Set the volume (attenuation) for all 8 channels (0..100).
virtual bool setVolume (int volume)
void setWire (i2c_bus_handle_t w)
 Defines the I2C communication object.

Static Public Attributes

static constexpr int N_CHANNELS = 8
static constexpr int N_REGISTERS = 20

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.
void updateBit (uint8_t reg, uint8_t pos, bool value)
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 attenuationReg (uint8_t channel)
static bool isAccessible (uint8_t reg)
static bool isWriteable (uint8_t reg)

Protected Attributes

uint8_t i2c_addr = 0
int input_volume_percent = 100
 Last input volume (in %) provided to setInputVolume().
uint8_t reg_map [N_REGISTERS] = {0}
int volume_percent = 100
 Last volume (in %) provided to setVolume().
i2c_bus_handle_t wire = nullptr

Detailed Description

Header only C++ driver for the PCM1681 8-channel audio DAC.

Maintains a local shadow of the PCM1681 register map (matching the factory default values) and writes it out via I2C. Provides per-channel volume (attenuation) and mute control plus DAI format configuration, ported from the corresponding Zephyr RTOS driver.

Member Enumeration Documentation

◆ Reg

enum Reg : uint8_t
Enumerator
REG_0 

Factory use only - not accessible.

AT1x_REG 
AT2x_REG 
AT3x_REG 
AT4x_REG 
AT5x_REG 
AT6x_REG 
MUTx_REG 
DACx_REG 
FMTx_REG 

also FLT_REG (shares same register)

SRST_REG 

also ZREV/DREV/DMFx/DMC

REVx_REG 
FLTx_REG 

also OVER_REG

DAMS_REG 

also AZROx

REG_14 

read only - not writeable

REG_15 

factory use only - not accessible

AT7x_REG 
AT8x_REG 
MUT_OR_REG 
DAC_OR_REG 

Constructor & Destructor Documentation

◆ PCM1681()

PCM1681 ( )
inline

Member Function Documentation

◆ address()

uint8_t address ( )
inlineinherited

Provides the actual I2C address of the codec.

◆ applyProperties()

bool applyProperties ( )
inline

Write the full local register shadow to the device (skips registers that are not writeable: REG_0, REG_14 and REG_15)

◆ attenuationReg()

uint8_t attenuationReg ( uint8_t channel)
inlinestaticprotected

◆ begin() [1/3]

bool begin ( PCM1681Format format = PCM1681Format::I2S_16_24)
inline

◆ begin() [2/3]

bool begin ( uint32_t sample_rate,
uint8_t bits )
inline

Initialize the codec: reset the local register shadow to the factory defaults, configure the DAI format and write everything to the device.

Parameters
formatDigital audio interface format Initializes the codec for I2S (sample rate and word size are determined by the external I2S clock/format, not configurable here)

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

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

◆ isAccessible()

bool isAccessible ( uint8_t reg)
inlinestaticprotected

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

◆ isWriteable()

bool isWriteable ( uint8_t reg)
inlinestaticprotected

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

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

◆ setAttenuationScale()

bool setAttenuationScale ( PCM1681AttenuationScale scale,
bool apply = true )
inline

Configure the attenuation scale (fine 0.5dB / wide 1.0dB steps).

◆ setDacEnabled() [1/2]

bool setDacEnabled ( bool enable)
inline

Enable or disable the DAC output of all channels.

◆ setDacEnabled() [2/2]

bool setDacEnabled ( uint8_t channel,
bool enable,
bool apply = true )
inline

Enable or disable the DAC output of a single channel (used for start_output / stop_output).

Parameters
channelchannel number, 1..8
enabletrue to enable the DAC output
applywrite the change to the device immediately

◆ setDeemphasisEnabled()

bool setDeemphasisEnabled ( bool enable,
bool apply = true )
inline

Enable or disable the digital de-emphasis filter.

◆ setDeemphasisRate()

bool setDeemphasisRate ( PCM1681DeemphasisRate rate,
bool apply = true )
inline

Configure the digital de-emphasis filter sample rate.

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

◆ setFilterRollOff()

bool setFilterRollOff ( PCM1681FilterRollOff roll_off,
bool apply = true )
inline

Configure the digital filter roll-off characteristic.

◆ setFormat()

bool setFormat ( PCM1681Format format,
bool apply = true )
inline

Configure the digital audio interface format.

Parameters
formatDigital audio interface format
applywrite the change to the device immediately

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

bool setMute ( bool mute)
inlineoverridevirtual

Mute or unmute all 8 channels.

Reimplemented from ZephyrDriverCommon.

◆ setMute() [2/2]

bool setMute ( uint8_t channel,
bool mute,
bool apply = true )
inline

Mute or unmute a single output channel.

Parameters
channelchannel number, 1..8
mutetrue to mute
applywrite the change to the device immediately

◆ setVolume() [1/3]

bool setVolume ( uint8_t channel,
uint8_t volume,
bool apply = true )
inline

Set the volume (attenuation) of a single output channel.

Parameters
channelchannel number, 1..8
volumevolume in percent, 0..100
applywrite the change to the device immediately

◆ setVolume() [2/3]

bool setVolume ( uint8_t volume)
inline

Set the volume (attenuation) for all 8 channels (0..100).

◆ setVolume() [3/3]

virtual bool setVolume ( int volume)
inlinevirtualinherited

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

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

◆ setWire()

void setWire ( i2c_bus_handle_t w)
inlineinherited

Defines the I2C communication object.

◆ updateBit()

void updateBit ( uint8_t reg,
uint8_t pos,
bool value )
inlineprotected

◆ 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

◆ i2c_addr

uint8_t i2c_addr = 0
protectedinherited

◆ input_volume_percent

int input_volume_percent = 100
protectedinherited

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

◆ N_CHANNELS

int N_CHANNELS = 8
staticconstexpr

◆ N_REGISTERS

int N_REGISTERS = 20
staticconstexpr

◆ reg_map

uint8_t reg_map[N_REGISTERS] = {0}
protected

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