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

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

#include <SGTL5000.h>

Public Types

enum  AnaCtrlBits : uint16_t {
  MuteLineOut = 1 << 8 , SelectHeadphoneLineIn = 1 << 6 , EnableZeroCrossHp = 1 << 5 , MuteHeadphone = 1 << 4 ,
  SelectAdcLineIn = 1 << 2 , EnableZeroCrossAdc = 1 << 1 , MuteAdc = 1 << 0
}
 Bit flags for the ANA_CTRL register (0x0024). More...
enum  I2SMode : uint16_t { I2SModeI2SOrLeftJustified = 0x0 , I2SModeRightJustified = 0x1 , I2SModePcm = 0x2 }
 I2S_MODE field of the I2S_CTRL register (0x0006). More...
enum class  Reg : uint16_t {
  ChipId = 0x0000 , DigPower = 0x0002 , ClkCtrl = 0x0004 , I2SCtrl = 0x0006 ,
  SssCtrl = 0x000A , AdcDacCtrl = 0x000E , DacVol = 0x0010 , PadStrength = 0x0014 ,
  AnaAdcCtrl = 0x0020 , AnaHpCtrl = 0x0022 , AnaCtrl = 0x0024 , LinregCtrl = 0x0026 ,
  RefCtrl = 0x0028 , MicCtrl = 0x002A , LineOutCtrl = 0x002C , LineOutVol = 0x002E ,
  AnaPower = 0x0030 , PllCtrl = 0x0032 , ClkTopCtrl = 0x0034 , AnaStatus = 0x0036 ,
  ShortCtrl = 0x003C , DapControl = 0x0100
}
 SGTL5000 register addresses. More...

Public Member Functions

 SGTL5000 ()=default
error_t configI2S (codec_mode_t mode, I2SDefinition *iface)
 Configure the digital audio interface format and sample rate.
error_t ctrlStateActive (codec_mode_t mode, bool ctrl_state_active)
 Activate or mute the codec.
error_t deinit (void)
 Deinitialize the SGTL5000 codec chip.
uint16_t getClkCtrl (samplerate_t rate)
 Determine the CLK_CTRL register value for the requested sample rate.
error_t getVoiceVolume (int *volume)
 Get the headphone / line output volume (0~100).
error_t init (codec_config_t *cfg)
 Initialize the SGTL5000 codec chip.
uint16_t readReg (Reg reg)
 Read a 16 bit value from a SGTL5000 register.
void setAddress (int addr)
 Defines the I2C device address.
error_t setVoiceMute (bool enable)
 Mute / unmute the headphone and line outputs.
error_t setVoiceVolume (int volume)
 Set the headphone / line output volume.
void setWire (i2c_bus_handle_t handle)
 Defines the I2C bus instance to be used.
error_t writeReg (Reg reg, uint16_t value)
 Write a 16 bit value to a SGTL5000 register.

Protected Attributes

uint16_t ana_ctrl = 0
int i2c_addr = SGTL5000_ADDR
i2c_bus_handle_t i2c_handle = nullptr
bool initialized = false
int voice_volume = 70

Detailed Description

Header-only driver class for the SGTL5000 codec chip.

Author
Phil Schatzmann

Member Enumeration Documentation

◆ AnaCtrlBits

enum AnaCtrlBits : uint16_t

Bit flags for the ANA_CTRL register (0x0024).

Enumerator
MuteLineOut 
SelectHeadphoneLineIn 
EnableZeroCrossHp 
MuteHeadphone 
SelectAdcLineIn 
EnableZeroCrossAdc 
MuteAdc 

◆ I2SMode

enum I2SMode : uint16_t

I2S_MODE field of the I2S_CTRL register (0x0006).

Enumerator
I2SModeI2SOrLeftJustified 
I2SModeRightJustified 
I2SModePcm 

◆ Reg

enum class Reg : uint16_t
strong

SGTL5000 register addresses.

Enumerator
ChipId 
DigPower 
ClkCtrl 
I2SCtrl 
SssCtrl 
AdcDacCtrl 
DacVol 
PadStrength 
AnaAdcCtrl 
AnaHpCtrl 
AnaCtrl 
LinregCtrl 
RefCtrl 
MicCtrl 
LineOutCtrl 
LineOutVol 
AnaPower 
PllCtrl 
ClkTopCtrl 
AnaStatus 
ShortCtrl 
DapControl 

Constructor & Destructor Documentation

◆ SGTL5000()

SGTL5000 ( )
default

Member Function Documentation

◆ configI2S()

error_t configI2S ( codec_mode_t mode,
I2SDefinition * iface )
inline

Configure the digital audio interface format and sample rate.

◆ ctrlStateActive()

error_t ctrlStateActive ( codec_mode_t mode,
bool ctrl_state_active )
inline

Activate or mute the codec.

◆ deinit()

error_t deinit ( void )
inline

Deinitialize the SGTL5000 codec chip.

◆ getClkCtrl()

uint16_t getClkCtrl ( samplerate_t rate)
inline

Determine the CLK_CTRL register value for the requested sample rate.

Note
Assumes the codec is an I2S slave clocked with MCLK = 256*fs.

◆ getVoiceVolume()

error_t getVoiceVolume ( int * volume)
inline

Get the headphone / line output volume (0~100).

◆ init()

error_t init ( codec_config_t * cfg)
inline

Initialize the SGTL5000 codec chip.

◆ readReg()

uint16_t readReg ( Reg reg)
inline

Read a 16 bit value from a SGTL5000 register.

◆ setAddress()

void setAddress ( int addr)
inline

Defines the I2C device address.

◆ setVoiceMute()

error_t setVoiceMute ( bool enable)
inline

Mute / unmute the headphone and line outputs.

◆ setVoiceVolume()

error_t setVoiceVolume ( int volume)
inline

Set the headphone / line output volume.

Parameters
volumevoice volume (0~100)

◆ setWire()

void setWire ( i2c_bus_handle_t handle)
inline

Defines the I2C bus instance to be used.

◆ writeReg()

error_t writeReg ( Reg reg,
uint16_t value )
inline

Write a 16 bit value to a SGTL5000 register.

Member Data Documentation

◆ ana_ctrl

uint16_t ana_ctrl = 0
protected

◆ i2c_addr

int i2c_addr = SGTL5000_ADDR
protected

◆ i2c_handle

i2c_bus_handle_t i2c_handle = nullptr
protected

◆ initialized

bool initialized = false
protected

◆ voice_volume

int voice_volume = 70
protected

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