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

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

#include <WM8731.h>

Public Types

enum  ActiveControl : uint16_t { Active = 1 << 0 }
 Bit flags for the Active Control register. More...
 
enum  AnaloguePath : uint16_t {
  MicBoost = 1 << 0 , MuteMic = 1 << 1 , InputSelectMic = 1 << 2 , Bypass = 1 << 3 ,
  DacSelect = 1 << 4 , SideTone = 1 << 5 , SideToneAttenuationMask = 0x3 << 6
}
 Bit flags for the Analogue Audio Path Control register. More...
 
enum  DigitalPath : uint16_t {
  AdcHighPassDisable = 1 << 0 , DeEmphasisDisable = 0x0 << 1 , DeEmphasis32k = 0x1 << 1 , DeEmphasis44_1k = 0x2 << 1 ,
  DeEmphasis48k = 0x3 << 1 , DacSoftMute = 1 << 3 , HighPassOnReset = 1 << 4
}
 Bit flags for the Digital Audio Path Control register. More...
 
enum  Format : uint16_t {
  FormatRightJustified = 0x0 , FormatLeftJustified = 0x1 , FormatI2S = 0x2 , FormatDsp = 0x3 ,
  FormatMask = 0x3 , WordLength16Bit = 0x0 << 2 , WordLength20Bit = 0x1 << 2 , WordLength24Bit = 0x2 << 2 ,
  WordLength32Bit = 0x3 << 2 , WordLengthMask = 0x3 << 2 , LrSwapPolarity = 1 << 4 , LrSwap = 1 << 5 ,
  MasterMode = 1 << 6 , BitClockInvert = 1 << 7
}
 Bit flags / values for the Digital Audio Interface Format register. More...
 
enum  HeadphoneOut : uint16_t { HeadphoneVolMask = 0x7F , HeadphoneZeroCross = 1 << 7 , HeadphoneBoth = 1 << 8 }
 Bit flags for the Left/Right Headphone Out registers. More...
 
enum  LineIn : uint16_t { LineInVolMask = 0x1F , LineInMute = 1 << 7 , LineInBoth = 1 << 8 }
 Bit flags for the Left/Right Line In registers. More...
 
enum  PowerDown : uint16_t {
  LineInPowerDown = 1 << 0 , MicPowerDown = 1 << 1 , AdcPowerDown = 1 << 2 , DacPowerDown = 1 << 3 ,
  OutputPowerDown = 1 << 4 , OscillatorPowerDown = 1 << 5 , ClockOutPowerDown = 1 << 6 , PowerOff = 1 << 7
}
 Bit flags for the Power Down Control register. More...
 
enum class  Reg : uint8_t {
  LeftLineIn = 0x00 , RightLineIn = 0x01 , LeftHeadphoneOut = 0x02 , RightHeadphoneOut = 0x03 ,
  AnaloguePath = 0x04 , DigitalPath = 0x05 , PowerDown = 0x06 , Format = 0x07 ,
  SamplingControl = 0x08 , Active = 0x09 , Reset = 0x0F
}
 WM8731 register addresses. More...
 
enum  SamplingControl : uint16_t {
  UsbMode = 1 << 0 , BaseOversamplingRate = 1 << 1 , SampleRateMask = 0xF << 2 , ClkInDiv2 = 1 << 6 ,
  ClkOutDiv2 = 1 << 7
}
 Bit flags for the Sampling Control register. More...
 

Public Member Functions

 WM8731 ()=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 standby the codec.
 
error_t deinit (void)
 Deinitialize the WM8731 codec chip.
 
error_t getVoiceVolume (int *volume)
 Get the headphone / line output volume (0~100)
 
error_t init (codec_config_t *cfg)
 Initialize the WM8731 codec chip.
 
error_t reset ()
 Reset all registers to their default values.
 
error_t resume (void)
 Restores the power configuration that was active before standby.
 
error_t setActive (bool active)
 Activates / deactivates the digital audio interface.
 
void setAddress (int addr)
 Defines the I2C device address.
 
error_t setVoiceMute (bool enable)
 Mute / unmute the DAC output.
 
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 standby (void)
 Powers down all sections (standby)
 
error_t writeReg (Reg reg_addr, uint16_t value)
 Write a value to a WM8731 register.
 

Protected Member Functions

uint16_t getSamplingControl (samplerate_t rate)
 Determine the SamplingControl register value for the requested sample rate.
 
error_t updatePower (input_device_t input_device, output_device_t output_device)
 Powers up the input/output sections that are actually used.
 

Protected Attributes

uint16_t active_control = 0
 
uint16_t analogue_path = 0
 
uint16_t digital_path = 0
 
int i2c_addr = WM8731_ADDR
 
i2c_bus_handle_t i2c_handle = nullptr
 
bool initialized = false
 
uint16_t power_down = 0
 
int voice_volume = 70
 

Detailed Description

Header-only driver class for the WM8731 codec chip.

Author
Phil Schatzmann

Member Enumeration Documentation

◆ ActiveControl

enum ActiveControl : uint16_t

Bit flags for the Active Control register.

Enumerator
Active 

◆ AnaloguePath

enum AnaloguePath : uint16_t

Bit flags for the Analogue Audio Path Control register.

Enumerator
MicBoost 
MuteMic 
InputSelectMic 
Bypass 
DacSelect 
SideTone 
SideToneAttenuationMask 

◆ DigitalPath

enum DigitalPath : uint16_t

Bit flags for the Digital Audio Path Control register.

Enumerator
AdcHighPassDisable 
DeEmphasisDisable 
DeEmphasis32k 
DeEmphasis44_1k 
DeEmphasis48k 
DacSoftMute 
HighPassOnReset 

◆ Format

enum Format : uint16_t

Bit flags / values for the Digital Audio Interface Format register.

Enumerator
FormatRightJustified 
FormatLeftJustified 
FormatI2S 
FormatDsp 
FormatMask 
WordLength16Bit 
WordLength20Bit 
WordLength24Bit 
WordLength32Bit 
WordLengthMask 
LrSwapPolarity 
LrSwap 
MasterMode 
BitClockInvert 

◆ HeadphoneOut

enum HeadphoneOut : uint16_t

Bit flags for the Left/Right Headphone Out registers.

Enumerator
HeadphoneVolMask 
HeadphoneZeroCross 
HeadphoneBoth 

◆ LineIn

enum LineIn : uint16_t

Bit flags for the Left/Right Line In registers.

Enumerator
LineInVolMask 
LineInMute 
LineInBoth 

◆ PowerDown

enum PowerDown : uint16_t

Bit flags for the Power Down Control register.

Enumerator
LineInPowerDown 
MicPowerDown 
AdcPowerDown 
DacPowerDown 
OutputPowerDown 
OscillatorPowerDown 
ClockOutPowerDown 
PowerOff 

◆ Reg

enum class Reg : uint8_t
strong

WM8731 register addresses.

Enumerator
LeftLineIn 
RightLineIn 
LeftHeadphoneOut 
RightHeadphoneOut 
AnaloguePath 
DigitalPath 
PowerDown 
Format 
SamplingControl 
Active 
Reset 

◆ SamplingControl

enum SamplingControl : uint16_t

Bit flags for the Sampling Control register.

Enumerator
UsbMode 
BaseOversamplingRate 
SampleRateMask 
ClkInDiv2 
ClkOutDiv2 

Constructor & Destructor Documentation

◆ WM8731()

WM8731 ( )
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 standby the codec.

◆ deinit()

error_t deinit ( void  )
inline

Deinitialize the WM8731 codec chip.

◆ getSamplingControl()

uint16_t getSamplingControl ( samplerate_t  rate)
inlineprotected

Determine the SamplingControl register value for the requested sample rate.

Note
Assumes a typical MCLK of 256*fs (12.288MHz for the 48kHz family, 11.2896MHz for the 44.1kHz family) in normal (non-USB) mode.

◆ 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 WM8731 codec chip.

◆ reset()

error_t reset ( )
inline

Reset all registers to their default values.

◆ resume()

error_t resume ( void  )
inline

Restores the power configuration that was active before standby.

◆ setActive()

error_t setActive ( bool  active)
inline

Activates / deactivates the digital audio interface.

◆ setAddress()

void setAddress ( int  addr)
inline

Defines the I2C device address.

◆ setVoiceMute()

error_t setVoiceMute ( bool  enable)
inline

Mute / unmute the DAC output.

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

◆ standby()

error_t standby ( void  )
inline

Powers down all sections (standby)

◆ updatePower()

error_t updatePower ( input_device_t  input_device,
output_device_t  output_device 
)
inlineprotected

Powers up the input/output sections that are actually used.

◆ writeReg()

error_t writeReg ( Reg  reg_addr,
uint16_t  value 
)
inline

Write a value to a WM8731 register.

Member Data Documentation

◆ active_control

uint16_t active_control = 0
protected

◆ analogue_path

uint16_t analogue_path = 0
protected

◆ digital_path

uint16_t digital_path = 0
protected

◆ i2c_addr

int i2c_addr = WM8731_ADDR
protected

◆ i2c_handle

i2c_bus_handle_t i2c_handle = nullptr
protected

◆ initialized

bool initialized = false
protected

◆ power_down

uint16_t power_down = 0
protected

◆ voice_volume

int voice_volume = 70
protected

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