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

Header-only driver class for the WM8960 audio codec chip. More...

#include <WM8960.h>

Public Member Functions

 WM8960 ()=default
 
bool activate (void)
 This function powers up the modules the required for the features enabled using init. This function is called in conjunction with deactivate.
 
bool adjustHeadphoneOutputVolume (uint8_t volume)
 This function updates the volume of both the left and right channels of the headphone output.
 
bool adjustInputVolume (uint8_t volume)
 This function updates the volume of both the left and right channels of the microphone input.
 
bool adjustSpeakerOutputVolume (uint8_t volume)
 This function updates the volume of both the left and right channels of the speaker output.
 
bool adjustVolume (uint8_t volume, wm8960_reg_t left_vol_reg, wm8960_reg_t right_vol_reg, uint16_t update_bit, uint16_t volume_bits_mask)
 
bool clear (wm8960_reg_t reg, uint16_t mask)
 This function clears bits in a register.
 
bool configDefault (uint8_t features)
 
bool configureClocking (uint32_t mclk_hz, bool enable_pll, wm8960_adc_dac_sample_rate_t sample_rate, wm8960_word_length_t word_length, wm8960_mode_t mode)
 This function configures the master clock and the digital interface for the audio codec.
 
bool deactivate (void)
 This function powers down the modules the required for the features enabled using init.
 
void deinit ()
 Frees up any resources allocated by the driver as part of init().
 
bool dump ()
 This function dumps the actual register values.
 
bool i2cWrite (uint8_t address, uint8_t data[2])
 
bool init (uint8_t features)
 Initialize the I2C communication with the audio codec, reset the codec and apply default configuration based on the feature(s) requested.
 
bool read (wm8960_reg_t reg, uint16_t *data)
 This function reads value of an audio codec register.
 
bool set (wm8960_reg_t reg, uint16_t mask)
 This function sets bits in a register.
 
void setAddress (int addr)
 Defines the I2C device address.
 
bool setOutputVolume (uint8_t volume)
 This function updates the volume of both the left and right channels of the speaker and headphones.
 
bool setupPll (uint32_t mclk_hz, wm8960_adc_dac_sample_rate_t sample_rate)
 
void setWire (i2c_bus_handle_t handle)
 Defines the I2C bus instance to be used.
 
void setWriteRetryCount (uint32_t count)
 Defines the number of times we retry to update a register value via I2C. This might help if you have an instable I2C connection. By default we set it to 1 which will cause the initialization to fail when the register update fails.
 
bool write (wm8960_reg_t enum_reg, uint16_t value)
 This function writes data to an audio codec register.
 
bool writeEx (wm8960_reg_t enum_reg, uint16_t value)
 

Protected Attributes

uint8_t enabled_features = WM8960_FEATURE_NONE
 
int i2c_addr = WM8960_I2C_ADDRESS
 
i2c_bus_handle_t i2c_handle = nullptr
 
bool pll_enabled = false
 
uint16_t register_map [REGISTER_MAP_SIZE] = {0}
 
uint32_t write_retry_count = 1
 

Detailed Description

Header-only driver class for the WM8960 audio codec chip.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ WM8960()

WM8960 ( )
default

Member Function Documentation

◆ activate()

bool activate ( void  )
inline

This function powers up the modules the required for the features enabled using init. This function is called in conjunction with deactivate.

Note
This function only updates the power management registers (R25[0x19], R26[0x1A], R47[0x2F]) to enable the modules required for the enabled features.
Returns
true if properly initialized, else an error indicating what went wrong.

◆ adjustHeadphoneOutputVolume()

bool adjustHeadphoneOutputVolume ( uint8_t  volume)
inline

This function updates the volume of both the left and right channels of the headphone output.

Parameters
[in]volume- Steps of 1dB, where: Minimum volume: -73dB (0x30) Maximum volume: +6dB (0x7F) Mute: (0x00~0x2F)
Returns
true if properly initialized, else an error indicating what went wrong.

◆ adjustInputVolume()

bool adjustInputVolume ( uint8_t  volume)
inline

This function updates the volume of both the left and right channels of the microphone input.

Parameters
[in]volume- Steps of 0.75dB, where: Minimum volume: -17.25dB (0x00) Maximum volume: +30dB (0x3F)
Returns
true if properly initialized, else an error indicating what went wrong.

◆ adjustSpeakerOutputVolume()

bool adjustSpeakerOutputVolume ( uint8_t  volume)
inline

This function updates the volume of both the left and right channels of the speaker output.

Parameters
[in]volume- Steps of 1dB, where: Minimum volume: -73dB (0x30) Maximum volume: +6dB (0x7F) Mute: (0x00~0x2F)
Returns
true if properly initialized, else an error indicating what went wrong.

◆ adjustVolume()

bool adjustVolume ( uint8_t  volume,
wm8960_reg_t  left_vol_reg,
wm8960_reg_t  right_vol_reg,
uint16_t  update_bit,
uint16_t  volume_bits_mask 
)
inline

◆ clear()

bool clear ( wm8960_reg_t  reg,
uint16_t  mask 
)
inline

This function clears bits in a register.

Parameters
[in]regThe audio codec register to update
[in]maskThe mask used to clear bits in the register
Returns
true if properly initialized, else an error indicating what went wrong.

◆ configDefault()

bool configDefault ( uint8_t  features)
inline

◆ configureClocking()

bool configureClocking ( uint32_t  mclk_hz,
bool  enable_pll,
wm8960_adc_dac_sample_rate_t  sample_rate,
wm8960_word_length_t  word_length,
wm8960_mode_t  mode 
)
inline

This function configures the master clock and the digital interface for the audio codec.

Parameters
[in]mclk_hzThe master clock (MCLK) frequency
[in]enable_pllSet true to enable PLL and false to disable PLL
[in]sample_rateSample rate for the ADC and DAC
[in]word_lengthWord length
[in]modeMode the audio codec to operate as.
Returns
true if properly initialized, else an error indicating what went wrong.

◆ deactivate()

bool deactivate ( void  )
inline

This function powers down the modules the required for the features enabled using init.

Note
This function only updates the power management registers (R25[0x19], R26[0x1A], R47[0x2F]) to disable the modules required for the enabled features.
Returns
true if properly initialized, else an error indicating what went wrong.

◆ deinit()

void deinit ( )
inline

Frees up any resources allocated by the driver as part of init().

◆ dump()

bool dump ( )
inline

This function dumps the actual register values.

Returns
true if properly initialized, else an error indicating what went wrong.

◆ i2cWrite()

bool i2cWrite ( uint8_t  address,
uint8_t  data[2] 
)
inline

Platform dependent i2c write. If you compile this library outside of Arduino you need to provide your own implementation.

◆ init()

bool init ( uint8_t  features)
inline

Initialize the I2C communication with the audio codec, reset the codec and apply default configuration based on the feature(s) requested.

If either WM8960_FEATURE_MICROPHONE or WM8960_FEATURE_HEADPHONE is requested, the following operations will be performed, For either feature features,

  • Set VMID=50K and Enable VREF

For WM8960_FEATURE_MICROPHONE,

  • Enable AINL, AINR, ADCL and ADCR
  • Enable left (LMIC) and right channel (RMIC) input PGA
  • LINPUT1 to PGA (LMN1), Connect left input PGA to left input boost (LMIC2B), Left PGA Boost = 0dB
  • RINPUT1 to PGA (RMN1), Connect right input PGA to right input boost (RMIC2B), Right PGA Boost = 0dB
  • Unmute left input PGA (LINMUTE), Left Input PGA Vol = 0dB, Volume Update
  • Unmute right input PGA (RINMUTE), Right Input PGA Vol = 0dB, Volume Update
  • Left ADC Vol = 0dB, Volume Update
  • Right ADC Vol = 0dB, Volume Update

For WM8960_FEATURE_HEADPHONE,

  • Enable DACL, DACR, LOUT1 and ROUT1
  • Enable left output mixer (LOMIX) and right output mixer (ROMIX)
  • Left DAC to left output mixer enabled (LD2LO), 0dB
  • Right DAC to right output mixer enabled (RD2RO), 0dB
  • LOUT1 Vol = 0dB, volume update enabled
  • ROUT1 Vol = 0dB, volume update enabled
  • Unmute DAC digital soft mute
Parameters
[in]featuresFeatures to enabled during initialization. See wm8960_features_t
Returns
true if properly initialized, else an error indicating what went wrong.

◆ read()

bool read ( wm8960_reg_t  reg,
uint16_t *  data 
)
inline

This function reads value of an audio codec register.

Parameters
[in]regThe audio codec register to read
[out]dataThe reference to read the audio codec register data into.
Returns
true if properly initialized, else an error indicating what went wrong.

◆ set()

bool set ( wm8960_reg_t  reg,
uint16_t  mask 
)
inline

This function sets bits in a register.

Parameters
[in]regThe audio codec register to update
[in]maskThe mask used to set bits in the register
Returns
true if properly initialized, else an error indicating what went wrong.

◆ setAddress()

void setAddress ( int  addr)
inline

Defines the I2C device address.

◆ setOutputVolume()

bool setOutputVolume ( uint8_t  volume)
inline

This function updates the volume of both the left and right channels of the speaker and headphones.

Parameters
[in]volume- Steps of 1dB, where: Minimum volume: -73dB (0x30) Maximum volume: +6dB (0x7F) Mute: (0x00~0x2F)
Returns
true if properly initialized, else an error indicating what went wrong.

◆ setupPll()

bool setupPll ( uint32_t  mclk_hz,
wm8960_adc_dac_sample_rate_t  sample_rate 
)
inline

◆ setWire()

void setWire ( i2c_bus_handle_t  handle)
inline

Defines the I2C bus instance to be used.

◆ setWriteRetryCount()

void setWriteRetryCount ( uint32_t  count)
inline

Defines the number of times we retry to update a register value via I2C. This might help if you have an instable I2C connection. By default we set it to 1 which will cause the initialization to fail when the register update fails.

Parameters
count0: retry endlessly until success; any number > 0 = number of retries

◆ write()

bool write ( wm8960_reg_t  enum_reg,
uint16_t  value 
)
inline

This function writes data to an audio codec register.

Parameters
[in]regThe audio codec register to update
[in]valueThe data to be written to the audio codec register
Returns
true if properly initialized, else an error indicating what went wrong.

◆ writeEx()

bool writeEx ( wm8960_reg_t  enum_reg,
uint16_t  value 
)
inline

Member Data Documentation

◆ enabled_features

uint8_t enabled_features = WM8960_FEATURE_NONE
protected

◆ i2c_addr

int i2c_addr = WM8960_I2C_ADDRESS
protected

◆ i2c_handle

i2c_bus_handle_t i2c_handle = nullptr
protected

◆ pll_enabled

bool pll_enabled = false
protected

◆ register_map

uint16_t register_map[REGISTER_MAP_SIZE] = {0}
protected

◆ write_retry_count

uint32_t write_retry_count = 1
protected

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