MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Wm8904

Overview

Data Structures

struct  wm8904_fll_config_t
 wm8904 fll configuration More...
 
struct  wm8904_audio_format_t
 Audio format configuration. More...
 
struct  wm8904_config_t
 Configuration structure of WM8904. More...
 
struct  wm8904_handle_t
 wm8904 codec handler More...
 

Macros

#define WM8904_I2C_HANDLER_SIZE   (CODEC_I2C_MASTER_HANDLER_SIZE)
 wm8904 handle size
 
#define WM8904_DEBUG_REGISTER   0
 wm8904 debug macro
 
#define WM8904_RESET   (0x00)
 WM8904 register map.
 
#define WM8904_I2C_ADDRESS   (0x1A)
 WM8904 I2C address. More...
 
#define WM8904_I2C_BITRATE   (400000U)
 WM8904 I2C bit rate. More...
 
#define WM8904_MAP_HEADPHONE_LINEOUT_MAX_VOLUME   0x3FU
 WM8904 maximum headphone/lineout volume.
 

Enumerations

enum  {
  kStatus_WM8904_Success = 0x0,
  kStatus_WM8904_Fail = 0x1
}
 WM8904 status return codes. More...
 
enum  {
  kWM8904_LRCPolarityNormal = 0U,
  kWM8904_LRCPolarityInverted = 1U << 4U
}
 WM8904 lrc polarity. More...
 
enum  wm8904_module_t {
  kWM8904_ModuleADC = 0,
  kWM8904_ModuleDAC = 1,
  kWM8904_ModulePGA = 2,
  kWM8904_ModuleHeadphone = 3,
  kWM8904_ModuleLineout = 4
}
 wm8904 module value More...
 
enum  
 wm8904 play channel More...
 
enum  wm8904_timeslot_t {
  kWM8904_TimeSlot0 = 0U,
  kWM8904_TimeSlot1 = 1U
}
 WM8904 time slot. More...
 
enum  wm8904_protocol_t {
  kWM8904_ProtocolI2S = 0x2,
  kWM8904_ProtocolLeftJustified = 0x1,
  kWM8904_ProtocolRightJustified = 0x0,
  kWM8904_ProtocolPCMA = 0x3,
  kWM8904_ProtocolPCMB = 0x3 | (1 << 4)
}
 The audio data transfer protocol. More...
 
enum  wm8904_fs_ratio_t {
  kWM8904_FsRatio64X = 0x0,
  kWM8904_FsRatio128X = 0x1,
  kWM8904_FsRatio192X = 0x2,
  kWM8904_FsRatio256X = 0x3,
  kWM8904_FsRatio384X = 0x4,
  kWM8904_FsRatio512X = 0x5,
  kWM8904_FsRatio768X = 0x6,
  kWM8904_FsRatio1024X = 0x7,
  kWM8904_FsRatio1408X = 0x8,
  kWM8904_FsRatio1536X = 0x9
}
 The SYSCLK / fs ratio. More...
 
enum  wm8904_sample_rate_t {
  kWM8904_SampleRate8kHz = 0x0,
  kWM8904_SampleRate12kHz = 0x1,
  kWM8904_SampleRate16kHz = 0x2,
  kWM8904_SampleRate24kHz = 0x3,
  kWM8904_SampleRate32kHz = 0x4,
  kWM8904_SampleRate48kHz = 0x5
}
 Sample rate. More...
 
enum  wm8904_bit_width_t {
  kWM8904_BitWidth16 = 0x0,
  kWM8904_BitWidth20 = 0x1,
  kWM8904_BitWidth24 = 0x2,
  kWM8904_BitWidth32 = 0x3
}
 Bit width. More...
 
enum  {
  kWM8904_RecordSourceDifferentialLine = 1U,
  kWM8904_RecordSourceLineInput = 2U,
  kWM8904_RecordSourceDifferentialMic = 4U,
  kWM8904_RecordSourceDigitalMic = 8U
}
 wm8904 record source More...
 
enum  {
  kWM8904_RecordChannelLeft1 = 1U,
  kWM8904_RecordChannelLeft2 = 2U,
  kWM8904_RecordChannelLeft3 = 4U,
  kWM8904_RecordChannelRight1 = 1U,
  kWM8904_RecordChannelRight2 = 2U,
  kWM8904_RecordChannelRight3 = 4U,
  kWM8904_RecordChannelDifferentialPositive1 = 1U,
  kWM8904_RecordChannelDifferentialPositive2 = 2U,
  kWM8904_RecordChannelDifferentialPositive3 = 4U,
  kWM8904_RecordChannelDifferentialNegative1 = 8U,
  kWM8904_RecordChannelDifferentialNegative2 = 16U,
  kWM8904_RecordChannelDifferentialNegative3 = 32U
}
 wm8904 record channel More...
 
enum  {
  kWM8904_PlaySourcePGA = 1U,
  kWM8904_PlaySourceDAC = 4U
}
 wm8904 play source More...
 
enum  wm8904_sys_clk_source_t {
  kWM8904_SysClkSourceMCLK = 0U,
  kWM8904_SysClkSourceFLL = 1U << 14
}
 wm8904 system clock source More...
 
enum  wm8904_fll_clk_source_t { kWM8904_FLLClkSourceMCLK = 0U }
 wm8904 fll clock source More...
 

Functions

status_t WM8904_WriteRegister (wm8904_handle_t *handle, uint8_t reg, uint16_t value)
 WM8904 write register. More...
 
status_t WM8904_ReadRegister (wm8904_handle_t *handle, uint8_t reg, uint16_t *value)
 WM8904 write register. More...
 
status_t WM8904_ModifyRegister (wm8904_handle_t *handle, uint8_t reg, uint16_t mask, uint16_t value)
 WM8904 modify register. More...
 
status_t WM8904_Init (wm8904_handle_t *handle, wm8904_config_t *wm8904Config)
 Initializes WM8904. More...
 
status_t WM8904_Deinit (wm8904_handle_t *handle)
 Deinitializes the WM8904 codec. More...
 
void WM8904_GetDefaultConfig (wm8904_config_t *config)
 Fills the configuration structure with default values. More...
 
status_t WM8904_SetMasterSlave (wm8904_handle_t *handle, bool master)
 Sets WM8904 as master or slave. More...
 
status_t WM8904_SeMasterClock (wm8904_handle_t *handle, uint32_t sysclk, uint32_t sampleRate, uint32_t bitWidth)
 Sets WM8904 master clock configuration. More...
 
status_t WM8904_SetFLLConfig (wm8904_handle_t *handle, wm8904_fll_config_t *config)
 WM8904 set PLL configuration This function will enable the GPIO1 FLL clock output function, so user can see the generated fll output clock frequency from WM8904 GPIO1. More...
 
status_t WM8904_SetProtocol (wm8904_handle_t *handle, wm8904_protocol_t protocol)
 Sets the audio data transfer protocol. More...
 
status_t WM8904_SetAudioFormat (wm8904_handle_t *handle, uint32_t sysclk, uint32_t sampleRate, uint32_t bitWidth)
 Sets the audio data format. More...
 
status_t WM8904_CheckAudioFormat (wm8904_handle_t *handle, wm8904_audio_format_t *format, uint32_t mclkFreq)
 check and update the audio data format. More...
 
status_t WM8904_SetVolume (wm8904_handle_t *handle, uint16_t volumeLeft, uint16_t volumeRight)
 Sets the module output volume. More...
 
status_t WM8904_SetMute (wm8904_handle_t *handle, bool muteLeft, bool muteRight)
 Sets the headphone output mute. More...
 
status_t WM8904_SelectLRCPolarity (wm8904_handle_t *handle, uint32_t polarity)
 Select LRC polarity. More...
 
status_t WM8904_EnableDACTDMMode (wm8904_handle_t *handle, wm8904_timeslot_t timeSlot)
 Enable WM8904 DAC time slot. More...
 
status_t WM8904_EnableADCTDMMode (wm8904_handle_t *handle, wm8904_timeslot_t timeSlot)
 Enable WM8904 ADC time slot. More...
 
status_t WM8904_SetModulePower (wm8904_handle_t *handle, wm8904_module_t module, bool isEnabled)
 brief SET the module output power. More...
 
status_t WM8904_SetChannelVolume (wm8904_handle_t *handle, uint32_t channel, uint32_t volume)
 Sets the channel output volume. More...
 
status_t WM8904_SetRecord (wm8904_handle_t *handle, uint32_t recordSource)
 SET the WM8904 record source. More...
 
status_t WM8904_SetRecordChannel (wm8904_handle_t *handle, uint32_t leftRecordChannel, uint32_t rightRecordChannel)
 SET the WM8904 record source. More...
 
status_t WM8904_SetPlay (wm8904_handle_t *handle, uint32_t playSource)
 SET the WM8904 play source. More...
 
status_t WM8904_SetChannelMute (wm8904_handle_t *handle, uint32_t channel, bool isMute)
 Sets the channel mute. More...
 

Driver version

#define FSL_WM8904_DRIVER_VERSION   (MAKE_VERSION(2, 4, 3))
 WM8904 driver version 2.4.3. More...
 

Data Structure Documentation

struct wm8904_fll_config_t

Data Fields

wm8904_fll_clk_source_t source
 fll reference clock source
 
uint32_t refClock_HZ
 fll reference clock frequency
 
uint32_t outputClock_HZ
 fll output clock frequency
 
struct wm8904_audio_format_t

Data Fields

wm8904_fs_ratio_t fsRatio
 SYSCLK / fs ratio.
 
wm8904_sample_rate_t sampleRate
 Sample rate.
 
wm8904_bit_width_t bitWidth
 Bit width.
 
struct wm8904_config_t

Data Fields

bool master
 Master or slave.
 
wm8904_sys_clk_source_t sysClkSource
 system clock source
 
wm8904_fll_config_tfll
 fll configuration
 
wm8904_protocol_t protocol
 Audio transfer protocol.
 
wm8904_audio_format_t format
 Audio format.
 
uint32_t mclk_HZ
 MCLK frequency value.
 
uint16_t recordSource
 record source
 
uint16_t recordChannelLeft
 record channel
 
uint16_t recordChannelRight
 record channel
 
uint16_t playSource
 play source
 
uint8_t slaveAddress
 code device slave address
 
codec_i2c_config_t i2cConfig
 i2c bus configuration
 
struct wm8904_handle_t

Data Fields

wm8904_config_tconfig
 wm8904 config pointer
 
uint8_t i2cHandle [WM8904_I2C_HANDLER_SIZE]
 i2c handle
 

Macro Definition Documentation

#define FSL_WM8904_DRIVER_VERSION   (MAKE_VERSION(2, 4, 3))
#define WM8904_I2C_ADDRESS   (0x1A)
#define WM8904_I2C_BITRATE   (400000U)

Enumeration Type Documentation

anonymous enum

Enumerator
kStatus_WM8904_Success 

Success.

kStatus_WM8904_Fail 

Failure.

anonymous enum

Enumerator
kWM8904_LRCPolarityNormal 

LRC polarity normal.

kWM8904_LRCPolarityInverted 

LRC polarity inverted.

Enumerator
kWM8904_ModuleADC 

moduel ADC

kWM8904_ModuleDAC 

module DAC

kWM8904_ModulePGA 

module PGA

kWM8904_ModuleHeadphone 

module headphone

kWM8904_ModuleLineout 

module line out

anonymous enum

Enumerator
kWM8904_TimeSlot0 

time slot0

kWM8904_TimeSlot1 

time slot1

Enumerator
kWM8904_ProtocolI2S 

I2S type.

kWM8904_ProtocolLeftJustified 

Left justified mode.

kWM8904_ProtocolRightJustified 

Right justified mode.

kWM8904_ProtocolPCMA 

PCM A mode.

kWM8904_ProtocolPCMB 

PCM B mode.

Enumerator
kWM8904_FsRatio64X 

SYSCLK is 64 * sample rate * frame width.

kWM8904_FsRatio128X 

SYSCLK is 128 * sample rate * frame width.

kWM8904_FsRatio192X 

SYSCLK is 192 * sample rate * frame width.

kWM8904_FsRatio256X 

SYSCLK is 256 * sample rate * frame width.

kWM8904_FsRatio384X 

SYSCLK is 384 * sample rate * frame width.

kWM8904_FsRatio512X 

SYSCLK is 512 * sample rate * frame width.

kWM8904_FsRatio768X 

SYSCLK is 768 * sample rate * frame width.

kWM8904_FsRatio1024X 

SYSCLK is 1024 * sample rate * frame width.

kWM8904_FsRatio1408X 

SYSCLK is 1408 * sample rate * frame width.

kWM8904_FsRatio1536X 

SYSCLK is 1536 * sample rate * frame width.

Enumerator
kWM8904_SampleRate8kHz 

8 kHz

kWM8904_SampleRate12kHz 

11.025kHz, 12kHz

kWM8904_SampleRate16kHz 

16kHz

kWM8904_SampleRate24kHz 

22.05kHz, 24kHz

kWM8904_SampleRate32kHz 

32kHz

kWM8904_SampleRate48kHz 

44.1kHz, 48kHz

Enumerator
kWM8904_BitWidth16 

16 bits

kWM8904_BitWidth20 

20 bits

kWM8904_BitWidth24 

24 bits

kWM8904_BitWidth32 

32 bits

anonymous enum

Enumerator
kWM8904_RecordSourceDifferentialLine 

record source from differential line

kWM8904_RecordSourceLineInput 

record source from line input

kWM8904_RecordSourceDifferentialMic 

record source from differential mic

kWM8904_RecordSourceDigitalMic 

record source from digital microphone

anonymous enum

Enumerator
kWM8904_RecordChannelLeft1 

left record channel 1

kWM8904_RecordChannelLeft2 

left record channel 2

kWM8904_RecordChannelLeft3 

left record channel 3

kWM8904_RecordChannelRight1 

right record channel 1

kWM8904_RecordChannelRight2 

right record channel 2

kWM8904_RecordChannelRight3 

right record channel 3

kWM8904_RecordChannelDifferentialPositive1 

differential positive record channel 1

kWM8904_RecordChannelDifferentialPositive2 

differential positive record channel 2

kWM8904_RecordChannelDifferentialPositive3 

differential positive record channel 3

kWM8904_RecordChannelDifferentialNegative1 

differential negative record channel 1

kWM8904_RecordChannelDifferentialNegative2 

differential negative record channel 2

kWM8904_RecordChannelDifferentialNegative3 

differential negative record channel 3

anonymous enum

Enumerator
kWM8904_PlaySourcePGA 

play source PGA, bypass ADC

kWM8904_PlaySourceDAC 

play source Input3

Enumerator
kWM8904_SysClkSourceMCLK 

wm8904 system clock soure from MCLK

kWM8904_SysClkSourceFLL 

wm8904 system clock soure from FLL

Enumerator
kWM8904_FLLClkSourceMCLK 

wm8904 FLL clock source from MCLK

Function Documentation

status_t WM8904_WriteRegister ( wm8904_handle_t handle,
uint8_t  reg,
uint16_t  value 
)
Parameters
handleWM8904 handle structure.
regregister address.
valuevalue to write.
Returns
kStatus_Success, else failed.
status_t WM8904_ReadRegister ( wm8904_handle_t handle,
uint8_t  reg,
uint16_t *  value 
)
Parameters
handleWM8904 handle structure.
regregister address.
valuevalue to read.
Returns
kStatus_Success, else failed.
status_t WM8904_ModifyRegister ( wm8904_handle_t handle,
uint8_t  reg,
uint16_t  mask,
uint16_t  value 
)
Parameters
handleWM8904 handle structure.
regregister address.
maskregister bits mask.
valuevalue to write.
Returns
kStatus_Success, else failed.
status_t WM8904_Init ( wm8904_handle_t handle,
wm8904_config_t wm8904Config 
)
Parameters
handleWM8904 handle structure.
wm8904ConfigWM8904 configuration structure.
status_t WM8904_Deinit ( wm8904_handle_t handle)

This function resets WM8904.

Parameters
handleWM8904 handle structure.
Returns
kStatus_WM8904_Success if successful, different code otherwise.
void WM8904_GetDefaultConfig ( wm8904_config_t config)

The default values are:

master = false; protocol = kWM8904_ProtocolI2S; format.fsRatio = kWM8904_FsRatio64X; format.sampleRate = kWM8904_SampleRate48kHz; format.bitWidth = kWM8904_BitWidth16;

Parameters
configdefault configurations of wm8904.
status_t WM8904_SetMasterSlave ( wm8904_handle_t handle,
bool  master 
)
Deprecated:
DO NOT USE THIS API ANYMORE. IT HAS BEEN SUPERCEDED BY WM8904_SeMasterClock
Parameters
handleWM8904 handle structure.
mastertrue for master, false for slave.
Returns
kStatus_WM8904_Success if successful, different code otherwise.
status_t WM8904_SeMasterClock ( wm8904_handle_t handle,
uint32_t  sysclk,
uint32_t  sampleRate,
uint32_t  bitWidth 
)
Parameters
handleWM8904 handle structure.
sysclksystem clock rate.
sampleRatesample rate
bitWidthbit width
Returns
kStatus_WM8904_Success if successful, different code otherwise.
status_t WM8904_SetFLLConfig ( wm8904_handle_t handle,
wm8904_fll_config_t config 
)
Parameters
handlewm8904 handler pointer.
configFLL configuration pointer.
status_t WM8904_SetProtocol ( wm8904_handle_t handle,
wm8904_protocol_t  protocol 
)
Parameters
handleWM8904 handle structure.
protocolAudio transfer protocol.
Returns
kStatus_WM8904_Success if successful, different code otherwise.
status_t WM8904_SetAudioFormat ( wm8904_handle_t handle,
uint32_t  sysclk,
uint32_t  sampleRate,
uint32_t  bitWidth 
)
Parameters
handleWM8904 handle structure.
sysclkSystem clock frequency for codec, user should pay attention to this parater, sysclk is caculate as SYSCLK = MCLK / MCLKDIV, MCLKDIV is bit0 of WM8904_CLK_RATES_0.
sampleRateSample rate frequency in Hz.
bitWidthAudio data bit width.
Returns
kStatus_WM8904_Success if successful, different code otherwise.
status_t WM8904_CheckAudioFormat ( wm8904_handle_t handle,
wm8904_audio_format_t format,
uint32_t  mclkFreq 
)

This api is used check the fsRatio setting based on the mclk and sample rate, if fsRatio setting is not correct, it will correct it according to mclk and sample rate.

Parameters
handleWM8904 handle structure.
formataudio data format
mclkFreqmclk frequency
Returns
kStatus_WM8904_Success if successful, different code otherwise.
status_t WM8904_SetVolume ( wm8904_handle_t handle,
uint16_t  volumeLeft,
uint16_t  volumeRight 
)

The parameter should be from 0 to 63. The resulting volume will be. 0 for -57DB, 63 for 6DB.

Parameters
handleWM8904 handle structure.
volumeLeftleft channel volume.
volumeRightright channel volume.
Returns
kStatus_WM8904_Success if successful, different code otherwise.
status_t WM8904_SetMute ( wm8904_handle_t handle,
bool  muteLeft,
bool  muteRight 
)
Parameters
handleWM8904 handle structure.
muteLefttrue to mute left channel, false to unmute.
muteRighttrue to mute right channel, false to unmute.
Returns
kStatus_WM8904_Success if successful, different code otherwise.
status_t WM8904_SelectLRCPolarity ( wm8904_handle_t handle,
uint32_t  polarity 
)
Parameters
handleWM8904 handle structure.
polarityLRC clock polarity.
Returns
kStatus_WM8904_Success if successful, different code otherwise.
status_t WM8904_EnableDACTDMMode ( wm8904_handle_t handle,
wm8904_timeslot_t  timeSlot 
)
Parameters
handleWM8904 handle structure.
timeSlottimeslot number.
Returns
kStatus_WM8904_Success if successful, different code otherwise.
status_t WM8904_EnableADCTDMMode ( wm8904_handle_t handle,
wm8904_timeslot_t  timeSlot 
)
Parameters
handleWM8904 handle structure.
timeSlottimeslot number.
Returns
kStatus_WM8904_Success if successful, different code otherwise.
status_t WM8904_SetModulePower ( wm8904_handle_t handle,
wm8904_module_t  module,
bool  isEnabled 
)

param handle WM8904 handle structure. param module wm8904 module. param isEnabled, true is power on, false is power down.

return kStatus_WM8904_Success if successful, different code otherwise..

status_t WM8904_SetChannelVolume ( wm8904_handle_t handle,
uint32_t  channel,
uint32_t  volume 
)

The parameter should be from 0 to 63. The resulting volume will be. 0 for -57dB, 63 for 6DB.

Parameters
handlecodec handle structure.
channelcodec channel.
volumevolume value from 0 -63.
Returns
kStatus_WM8904_Success if successful, different code otherwise.
status_t WM8904_SetRecord ( wm8904_handle_t handle,
uint32_t  recordSource 
)
Parameters
handleWM8904 handle structure.
recordSourcerecord source , can be a value of kCODEC_ModuleRecordSourceDifferentialLine, kCODEC_ModuleRecordSourceDifferentialMic, kCODEC_ModuleRecordSourceSingleEndMic, kCODEC_ModuleRecordSourceDigitalMic.
Returns
kStatus_WM8904_Success if successful, different code otherwise.
status_t WM8904_SetRecordChannel ( wm8904_handle_t handle,
uint32_t  leftRecordChannel,
uint32_t  rightRecordChannel 
)
Parameters
handleWM8904 handle structure.
leftRecordChannelchannel number of left record channel when using differential source, channel number of single end left channel when using single end source, channel number of digital mic when using digital mic source.
rightRecordChannelchannel number of right record channel when using differential source, channel number of single end right channel when using single end source.
Returns
kStatus_WM8904_Success if successful, different code otherwise..
status_t WM8904_SetPlay ( wm8904_handle_t handle,
uint32_t  playSource 
)
Parameters
handleWM8904 handle structure.
playSourceplay source , can be a value of kCODEC_ModuleHeadphoneSourcePGA, kCODEC_ModuleHeadphoneSourceDAC, kCODEC_ModuleLineoutSourcePGA, kCODEC_ModuleLineoutSourceDAC.
Returns
kStatus_WM8904_Success if successful, different code otherwise..
status_t WM8904_SetChannelMute ( wm8904_handle_t handle,
uint32_t  channel,
bool  isMute 
)
Parameters
handlecodec handle structure.
channelcodec module name.
isMutetrue is mute, false unmute.
Returns
kStatus_WM8904_Success if successful, different code otherwise.