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

Header-only driver class for the CS42L51 codec chip. More...

#include <CS42L51.h>

Public Member Functions

 CS42L51 ()=default
 
void deinit ()
 Deinitializes the audio codec.
 
uint8_t getVolume ()
 Get the output codec volume level.
 
uint32_t init (uint32_t inputDevice, uint32_t outputDevice, uint8_t volume, uint32_t audioFreq)
 
uint32_t pause ()
 Pauses playing on the audio codec.
 
uint32_t play ()
 Start the audio Codec play feature.
 
uint32_t readID ()
 Get the CS42L51 ID.
 
uint8_t readReg (uint8_t reg)
 
uint32_t reset ()
 Resets cs42l51 registers.
 
uint32_t resume ()
 Resumes playing on the audio codec.
 
void setAddress (uint16_t addr)
 Defines the I2C device address.
 
uint32_t setFrequency (uint32_t audioFreq)
 Sets new frequency.
 
uint32_t setMute (uint32_t cmd)
 
uint32_t setOutputMode (uint32_t output)
 
uint32_t setVolume (uint8_t volume)
 
void setWire (i2c_bus_handle_t handle)
 Defines the I2C bus instance to be used.
 
uint32_t stop (uint32_t cmd)
 
constexpr uint8_t volumeConvert (uint8_t volume)
 Converts a volume in the range 0-100 to the codec's register value.
 
constexpr uint8_t volumeInvert (uint8_t reg)
 Converts a codec register value back to a volume in the range 0-100.
 
uint8_t writeReg (uint8_t reg, uint8_t value)
 

Protected Attributes

uint32_t current_devices = CS42L51_OUT_NONE
 
uint16_t device_addr = 0
 
i2c_bus_handle_t i2c_handle = nullptr
 
uint8_t is_initialized = 0
 

Detailed Description

Header-only driver class for the CS42L51 codec chip.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ CS42L51()

CS42L51 ( )
default

Member Function Documentation

◆ deinit()

void deinit ( )
inline

Deinitializes the audio codec.

◆ getVolume()

uint8_t getVolume ( )
inline

Get the output codec volume level.

◆ init()

uint32_t init ( uint32_t  inputDevice,
uint32_t  outputDevice,
uint8_t  volume,
uint32_t  audioFreq 
)
inline

Initializes the audio codec and the control interface.

Parameters
inputDevicecombination of CS42L51_IN_MIC1, CS42L51_IN_MIC2, CS42L51_IN_LINE1, CS42L51_IN_LINE2, CS42L51_IN_LINE3 or CS42L51_IN_NONE
outputDeviceCS42L51_OUT_HEADPHONE or CS42L51_OUT_NONE
volumeInitial volume level (from 0 (Mute) to 100 (Max))
audioFreqAudio frequency (not used)

◆ pause()

uint32_t pause ( )
inline

Pauses playing on the audio codec.

◆ play()

uint32_t play ( )
inline

Start the audio Codec play feature.

◆ readID()

uint32_t readID ( )
inline

Get the CS42L51 ID.

◆ readReg()

uint8_t readReg ( uint8_t  reg)
inline

◆ reset()

uint32_t reset ( )
inline

Resets cs42l51 registers.

◆ resume()

uint32_t resume ( )
inline

Resumes playing on the audio codec.

◆ setAddress()

void setAddress ( uint16_t  addr)
inline

Defines the I2C device address.

◆ setFrequency()

uint32_t setFrequency ( uint32_t  audioFreq)
inline

Sets new frequency.

◆ setMute()

uint32_t setMute ( uint32_t  cmd)
inline

Enables or disables the mute feature on the audio codec.

Parameters
cmdCS42L51_MUTE_ON to enable the mute or CS42L51_MUTE_OFF to disable the mute mode.

◆ setOutputMode()

uint32_t setOutputMode ( uint32_t  output)
inline

Switch dynamically (while audio file is played) the output target.

Note
Only CS42L51_OUT_HEADPHONE output is supported by this codec.

◆ setVolume()

uint32_t setVolume ( uint8_t  volume)
inline

Sets higher or lower the output codec volume level.

Parameters
volumea value from 0 to 100 (refer to codec registers description for more details).

◆ setWire()

void setWire ( i2c_bus_handle_t  handle)
inline

Defines the I2C bus instance to be used.

◆ stop()

uint32_t stop ( uint32_t  cmd)
inline

Stops audio Codec playing. It powers down the codec.

Parameters
cmdCS42L51_PDWN_SW (mute only) or CS42L51_PDWN_HW (full power down)

◆ volumeConvert()

constexpr uint8_t volumeConvert ( uint8_t  volume)
inlineconstexpr

Converts a volume in the range 0-100 to the codec's register value.

◆ volumeInvert()

constexpr uint8_t volumeInvert ( uint8_t  reg)
inlineconstexpr

Converts a codec register value back to a volume in the range 0-100.

◆ writeReg()

uint8_t writeReg ( uint8_t  reg,
uint8_t  value 
)
inline

Member Data Documentation

◆ current_devices

uint32_t current_devices = CS42L51_OUT_NONE
protected

◆ device_addr

uint16_t device_addr = 0
protected

◆ i2c_handle

i2c_bus_handle_t i2c_handle = nullptr
protected

◆ is_initialized

uint8_t is_initialized = 0
protected

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