MCUXpresso SDK API Reference Manual: WM8960 Driver

| MCUXpresso SDK API Reference Manual Rev 2.11.1 NXP Semiconductors

- Main Page
- Related Pages
- API Reference

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Data Structures | Macros | Enumerations | Functions
WM8960 Driver
CODEC Driver

## Overview

The wm8960 driver provides a codec control interface.

## Data Structures
struct | wm8960_audio_format_t
| wm8960 audio format More...
struct | wm8960_master_sysclk_config_t
| wm8960 master system clock configuration More...
struct | wm8960_config_t
| Initialize structure of WM8960. More...
struct | wm8960_handle_t
| wm8960 codec handler More...

## Macros
#define | WM8960_I2C_HANDLER_SIZE CODEC_I2C_MASTER_HANDLER_SIZE
| wm8960 handle size
#define | WM8960_LINVOL 0x0U
| Define the register address of WM8960. More...
#define | WM8960_CACHEREGNUM 56U
| Cache register number.
#define | WM8960_CLOCK2_BCLK_DIV_MASK 0xFU
| WM8960 CLOCK2 bits.
#define | WM8960_IFACE1_FORMAT_MASK 0x03U
| WM8960_IFACE1 FORMAT bits.
#define | WM8960_IFACE1_WL_MASK 0x0CU
| WM8960_IFACE1 WL bits.
#define | WM8960_IFACE1_LRP_MASK 0x10U
| WM8960_IFACE1 LRP bit.
#define | WM8960_IFACE1_DLRSWAP_MASK 0x20U
| WM8960_IFACE1 DLRSWAP bit.
#define | WM8960_IFACE1_MS_MASK 0x40U
| WM8960_IFACE1 MS bit.
#define | WM8960_IFACE1_BCLKINV_MASK 0x80U
| WM8960_IFACE1 BCLKINV bit.
#define | WM8960_IFACE1_ALRSWAP_MASK 0x100U
| WM8960_IFACE1 ALRSWAP bit.
#define | WM8960_POWER1_VREF_MASK 0x40U
| WM8960_POWER1.
#define | WM8960_POWER2_DACL_MASK 0x100U
| WM8960_POWER2.
#define | WM8960_I2C_ADDR 0x1A
| WM8960 I2C address. More...
#define | WM8960_I2C_BAUDRATE (100000U)
| WM8960 I2C baudrate.
#define | WM8960_ADC_MAX_VOLUME_vALUE 0xFFU
| WM8960 maximum volume value.

## Enumerations
enum | wm8960_module_t { kWM8960_ModuleADC = 0, kWM8960_ModuleDAC = 1, kWM8960_ModuleVREF = 2, kWM8960_ModuleHP = 3, kWM8960_ModuleMICB = 4, kWM8960_ModuleMIC = 5, kWM8960_ModuleLineIn = 6, kWM8960_ModuleLineOut = 7, kWM8960_ModuleSpeaker = 8, kWM8960_ModuleOMIX = 9 }
| Modules in WM8960 board. More...
enum | { kWM8960_HeadphoneLeft = 1, kWM8960_HeadphoneRight = 2, kWM8960_SpeakerLeft = 4, kWM8960_SpeakerRight = 8 }
| wm8960 play channel More...
enum | wm8960_play_source_t { kWM8960_PlaySourcePGA = 1, kWM8960_PlaySourceInput = 2, kWM8960_PlaySourceDAC = 4 }
| wm8960 play source More...
enum | wm8960_route_t { kWM8960_RouteBypass = 0, kWM8960_RoutePlayback = 1, kWM8960_RoutePlaybackandRecord = 2, kWM8960_RouteRecord = 5 }
| WM8960 data route. More...
enum | wm8960_protocol_t { kWM8960_BusI2S = 2, kWM8960_BusLeftJustified = 1, kWM8960_BusRightJustified = 0, kWM8960_BusPCMA = 3, kWM8960_BusPCMB = 3 | (1 << 4) }
| The audio data transfer protocol choice. More...
enum | wm8960_input_t { kWM8960_InputClosed = 0, kWM8960_InputSingleEndedMic = 1, kWM8960_InputDifferentialMicInput2 = 2, kWM8960_InputDifferentialMicInput3 = 3, kWM8960_InputLineINPUT2 = 4, kWM8960_InputLineINPUT3 = 5 }
| wm8960 input source More...
enum | { kWM8960_AudioSampleRate8KHz = 8000U, kWM8960_AudioSampleRate11025Hz = 11025U, kWM8960_AudioSampleRate12KHz = 12000U, kWM8960_AudioSampleRate16KHz = 16000U, kWM8960_AudioSampleRate22050Hz = 22050U, kWM8960_AudioSampleRate24KHz = 24000U, kWM8960_AudioSampleRate32KHz = 32000U, kWM8960_AudioSampleRate44100Hz = 44100U, kWM8960_AudioSampleRate48KHz = 48000U, kWM8960_AudioSampleRate96KHz = 96000U, kWM8960_AudioSampleRate192KHz = 192000U, kWM8960_AudioSampleRate384KHz = 384000U }
| audio sample rate definition More...
enum | { kWM8960_AudioBitWidth16bit = 16U, kWM8960_AudioBitWidth20bit = 20U, kWM8960_AudioBitWidth24bit = 24U, kWM8960_AudioBitWidth32bit = 32U }
| audio bit width More...
enum | wm8960_sysclk_source_t { kWM8960_SysClkSourceMclk = 0U, kWM8960_SysClkSourceInternalPLL = 1U }
| wm8960 sysclk source More...

## Functions
status_t | WM8960_Init (wm8960_handle_t *handle, const wm8960_config_t *config)
| WM8960 initialize function. More...
status_t | WM8960_Deinit (wm8960_handle_t *handle)
| Deinit the WM8960 codec. More...
status_t | WM8960_SetDataRoute (wm8960_handle_t *handle, wm8960_route_t route)
| Set audio data route in WM8960. More...
status_t | WM8960_SetLeftInput (wm8960_handle_t *handle, wm8960_input_t input)
| Set left audio input source in WM8960. More...
status_t | WM8960_SetRightInput (wm8960_handle_t *handle, wm8960_input_t input)
| Set right audio input source in WM8960. More...
status_t | WM8960_SetProtocol (wm8960_handle_t *handle, wm8960_protocol_t protocol)
| Set the audio transfer protocol. More...
void | WM8960_SetMasterSlave (wm8960_handle_t *handle, bool master)
| Set WM8960 as master or slave. More...
status_t | WM8960_SetVolume (wm8960_handle_t *handle, wm8960_module_t module, uint32_t volume)
| Set the volume of different modules in WM8960. More...
uint32_t | WM8960_GetVolume (wm8960_handle_t *handle, wm8960_module_t module)
| Get the volume of different modules in WM8960. More...
status_t | WM8960_SetMute (wm8960_handle_t *handle, wm8960_module_t module, bool isEnabled)
| Mute modules in WM8960. More...
status_t | WM8960_SetModule (wm8960_handle_t *handle, wm8960_module_t module, bool isEnabled)
| Enable/disable expected devices. More...
status_t | WM8960_SetPlay (wm8960_handle_t *handle, uint32_t playSource)
| SET the WM8960 play source. More...
status_t | WM8960_ConfigDataFormat (wm8960_handle_t *handle, uint32_t sysclk, uint32_t sample_rate, uint32_t bits)
| Configure the data format of audio data. More...
status_t | WM8960_SetJackDetect (wm8960_handle_t *handle, bool isEnabled)
| Enable/disable jack detect feature. More...
status_t | WM8960_WriteReg (wm8960_handle_t *handle, uint8_t reg, uint16_t val)
| Write register to WM8960 using I2C. More...
status_t | WM8960_ReadReg (uint8_t reg, uint16_t *val)
| Read register from WM8960 using I2C. More...
status_t | WM8960_ModifyReg (wm8960_handle_t *handle, uint8_t reg, uint16_t mask, uint16_t val)
| Modify some bits in the register using I2C. More...

## Driver version
#define | FSL_WM8960_DRIVER_VERSION (MAKE_VERSION(2, 2, 0))
| CLOCK driver version 2.2.0.

## Data Structure Documentation

struct wm8960_audio_format_t

### Data Fields
uint32_t | mclk_HZ
| master clock frequency
uint32_t | sampleRate
| sample rate
uint32_t | bitWidth
| bit width

struct wm8960_master_sysclk_config_t

### Data Fields
wm8960_sysclk_source_t | sysclkSource
| sysclk source
uint32_t | sysclkFreq
| PLL output frequency value.

struct wm8960_config_t

### Data Fields
wm8960_route_t | route
| Audio data route. More...
wm8960_protocol_t | bus
| Audio transfer protocol.
wm8960_audio_format_t | format
| Audio format.
bool | master_slave
| Master or slave. More...
wm8960_master_sysclk_config_t | masterClock
| master clock configurations
bool | enableSpeaker
| True means enable class D speaker as output, false means no.
wm8960_input_t | leftInputSource
| Left input source for WM8960.
wm8960_input_t | rightInputSource
| Right input source for wm8960.
wm8960_play_source_t | playSource
| play source
uint8_t | slaveAddress
| wm8960 device address
codec_i2c_config_t | i2cConfig
| i2c configuration

#### Field Documentation

wm8960_route_t wm8960_config_t::route

bool wm8960_config_t::master_slave

struct wm8960_handle_t

### Data Fields
const wm8960_config_t * | config
| wm8904 config pointer
uint8_t | i2cHandle [WM8960_I2C_HANDLER_SIZE]
| i2c handle

## Macro Definition Documentation

#define WM8960_LINVOL 0x0U

#define WM8960_I2C_ADDR 0x1A

## Enumeration Type Documentation

enum wm8960_module_t

Enumerator
kWM8960_ModuleADC | ADC module in WM8960.
kWM8960_ModuleDAC | DAC module in WM8960.
kWM8960_ModuleVREF | VREF module.
kWM8960_ModuleHP | Headphone.
kWM8960_ModuleMICB | Mic bias.
kWM8960_ModuleMIC | Input Mic.
kWM8960_ModuleLineIn | Analog in PGA.
kWM8960_ModuleLineOut | Line out module.
kWM8960_ModuleSpeaker | Speaker module.
kWM8960_ModuleOMIX | Output mixer.

anonymous enum

Enumerator
kWM8960_HeadphoneLeft | wm8960 headphone left channel
kWM8960_HeadphoneRight | wm8960 headphone right channel
kWM8960_SpeakerLeft | wm8960 speaker left channel
kWM8960_SpeakerRight | wm8960 speaker right channel

enum wm8960_play_source_t

Enumerator
kWM8960_PlaySourcePGA | wm8960 play source PGA
kWM8960_PlaySourceInput | wm8960 play source Input
kWM8960_PlaySourceDAC | wm8960 play source DAC

enum wm8960_route_t

Only provide some typical data route, not all route listed. Note: Users cannot combine any routes, once a new route is set, the previous one would be replaced.

Enumerator
kWM8960_RouteBypass | LINEIN->Headphone.
kWM8960_RoutePlayback | I2SIN->DAC->Headphone.
kWM8960_RoutePlaybackandRecord | I2SIN->DAC->Headphone, LINEIN->ADC->I2SOUT.
kWM8960_RouteRecord | LINEIN->ADC->I2SOUT.

enum wm8960_protocol_t

WM8960 only supports I2S format and PCM format.

Enumerator
kWM8960_BusI2S | I2S type.
kWM8960_BusLeftJustified | Left justified mode.
kWM8960_BusRightJustified | Right justified mode.
kWM8960_BusPCMA | PCM A mode.
kWM8960_BusPCMB | PCM B mode.

enum wm8960_input_t

Enumerator
kWM8960_InputClosed | Input device is closed.
kWM8960_InputSingleEndedMic | Input as single ended mic, only use L/RINPUT1.
kWM8960_InputDifferentialMicInput2 | Input as differential mic, use L/RINPUT1 and L/RINPUT2.
kWM8960_InputDifferentialMicInput3 | Input as differential mic, use L/RINPUT1 and L/RINPUT3.
kWM8960_InputLineINPUT2 | Input as line input, only use L/RINPUT2.
kWM8960_InputLineINPUT3 | Input as line input, only use L/RINPUT3.

anonymous enum

Enumerator
kWM8960_AudioSampleRate8KHz | Sample rate 8000 Hz.
kWM8960_AudioSampleRate11025Hz | Sample rate 11025 Hz.
kWM8960_AudioSampleRate12KHz | Sample rate 12000 Hz.
kWM8960_AudioSampleRate16KHz | Sample rate 16000 Hz.
kWM8960_AudioSampleRate22050Hz | Sample rate 22050 Hz.
kWM8960_AudioSampleRate24KHz | Sample rate 24000 Hz.
kWM8960_AudioSampleRate32KHz | Sample rate 32000 Hz.
kWM8960_AudioSampleRate44100Hz | Sample rate 44100 Hz.
kWM8960_AudioSampleRate48KHz | Sample rate 48000 Hz.
kWM8960_AudioSampleRate96KHz | Sample rate 96000 Hz.
kWM8960_AudioSampleRate192KHz | Sample rate 192000 Hz.
kWM8960_AudioSampleRate384KHz | Sample rate 384000 Hz.

anonymous enum

Enumerator
kWM8960_AudioBitWidth16bit | audio bit width 16
kWM8960_AudioBitWidth20bit | audio bit width 20
kWM8960_AudioBitWidth24bit | audio bit width 24
kWM8960_AudioBitWidth32bit | audio bit width 32

enum wm8960_sysclk_source_t

Enumerator
kWM8960_SysClkSourceMclk | sysclk source from external MCLK
kWM8960_SysClkSourceInternalPLL | sysclk source from internal PLL

## Function Documentation

status_t WM8960_Init | ( | wm8960_handle_t * | handle,
|  | const wm8960_config_t * | config
| ) |  |

The second parameter is NULL to WM8960 in this version. If users want to change the settings, they have to use wm8960_write_reg() or wm8960_modify_reg() to set the register value of WM8960. Note: If the codec_config is NULL, it would initialize WM8960 using default settings. The default setting: codec_config->route = kWM8960_RoutePlaybackandRecord codec_config->bus = kWM8960_BusI2S codec_config->master = slave

Parameters

  handle | WM8960 handle structure.
  config | WM8960 configuration structure.

status_t WM8960_Deinit | ( | wm8960_handle_t * | handle | ) |

This function close all modules in WM8960 to save power.

Parameters

  handle | WM8960 handle structure pointer.

status_t WM8960_SetDataRoute | ( | wm8960_handle_t * | handle,
|  | wm8960_route_t | route
| ) |  |

This function would set the data route according to route. The route cannot be combined, as all route would enable different modules. Note: If a new route is set, the previous route would not work.

Parameters

  handle | WM8960 handle structure.
  route | Audio data route in WM8960.

status_t WM8960_SetLeftInput | ( | wm8960_handle_t * | handle,
|  | wm8960_input_t | input
| ) |  |

Parameters

  handle | WM8960 handle structure.
  input | Audio input source.

status_t WM8960_SetRightInput | ( | wm8960_handle_t * | handle,
|  | wm8960_input_t | input
| ) |  |

Parameters

  handle | WM8960 handle structure.
  input | Audio input source.

status_t WM8960_SetProtocol | ( | wm8960_handle_t * | handle,
|  | wm8960_protocol_t | protocol
| ) |  |

WM8960 only supports I2S, left justified, right justified, PCM A, PCM B format.

Parameters

  handle | WM8960 handle structure.
  protocol | Audio data transfer protocol.

void WM8960_SetMasterSlave | ( | wm8960_handle_t * | handle,
|  | bool | master
| ) |  |

Parameters

  handle | WM8960 handle structure.
  master | 1 represent master, 0 represent slave.

status_t WM8960_SetVolume | ( | wm8960_handle_t * | handle,
|  | wm8960_module_t | module,
|  | uint32_t | volume
| ) |  |

This function would set the volume of WM8960 modules. Uses need to appoint the module. The function assume that left channel and right channel has the same volume.

Module:kWM8960_ModuleADC, volume range value: 0 is mute, 1-255 is -97db to 30db Module:kWM8960_ModuleDAC, volume range value: 0 is mute, 1-255 is -127db to 0db Module:kWM8960_ModuleHP, volume range value: 0 - 2F is mute, 0x30 - 0x7F is -73db to 6db Module:kWM8960_ModuleLineIn, volume range value: 0 - 0x3F is -17.25db to 30db Module:kWM8960_ModuleSpeaker, volume range value: 0 - 2F is mute, 0x30 - 0x7F is -73db to 6db

Parameters

  handle | WM8960 handle structure.
  module | Module to set volume, it can be ADC, DAC, Headphone and so on.
  volume | Volume value need to be set.

uint32_t WM8960_GetVolume | ( | wm8960_handle_t * | handle,
|  | wm8960_module_t | module
| ) |  |

This function gets the volume of WM8960 modules. Uses need to appoint the module. The function assume that left channel and right channel has the same volume.

Parameters

  handle | WM8960 handle structure.
  module | Module to set volume, it can be ADC, DAC, Headphone and so on.

Returns
  Volume value of the module.

status_t WM8960_SetMute | ( | wm8960_handle_t * | handle,
|  | wm8960_module_t | module,
|  | bool | isEnabled
| ) |  |

Parameters

  handle | WM8960 handle structure.
  module | Modules need to be mute.
  isEnabled | Mute or unmute, 1 represent mute.

status_t WM8960_SetModule | ( | wm8960_handle_t * | handle,
|  | wm8960_module_t | module,
|  | bool | isEnabled
| ) |  |

Parameters

  handle | WM8960 handle structure.
  module | Module expected to enable.
  isEnabled | Enable or disable moudles.

status_t WM8960_SetPlay | ( | wm8960_handle_t * | handle,
|  | uint32_t | playSource
| ) |  |

Parameters

  handle | WM8960 handle structure.
  playSource | play source , can be a value combine of kWM8960_ModuleHeadphoneSourcePGA, kWM8960_ModuleHeadphoneSourceDAC, kWM8960_ModulePlaySourceInput, kWM8960_ModulePlayMonoRight, kWM8960_ModulePlayMonoLeft.

Returns
  kStatus_WM8904_Success if successful, different code otherwise..

status_t WM8960_ConfigDataFormat | ( | wm8960_handle_t * | handle,
|  | uint32_t | sysclk,
|  | uint32_t | sample_rate,
|  | uint32_t | bits
| ) |  |

This function would configure the registers about the sample rate, bit depths.

Parameters

  handle | WM8960 handle structure pointer.
  sysclk | system clock of the codec which can be generated by MCLK or PLL output.
  sample_rate | Sample rate of audio file running in WM8960. WM8960 now supports 8k, 11.025k, 12k, 16k, 22.05k, 24k, 32k, 44.1k, 48k and 96k sample rate.
  bits | Bit depth of audio file (WM8960 only supports 16bit, 20bit, 24bit and 32 bit in HW).

status_t WM8960_SetJackDetect | ( | wm8960_handle_t * | handle,
|  | bool | isEnabled
| ) |  |

Parameters

  handle | WM8960 handle structure.
  isEnabled | Enable or disable moudles.

status_t WM8960_WriteReg | ( | wm8960_handle_t * | handle,
|  | uint8_t | reg,
|  | uint16_t | val
| ) |  |

Parameters

  handle | WM8960 handle structure.
  reg | The register address in WM8960.
  val | Value needs to write into the register.

status_t WM8960_ReadReg | ( | uint8_t | reg,
|  | uint16_t * | val
| ) |  |

Parameters

  reg | The register address in WM8960.
  val | Value written to.

status_t WM8960_ModifyReg | ( | wm8960_handle_t * | handle,
|  | uint8_t | reg,
|  | uint16_t | mask,
|  | uint16_t | val
| ) |  |

Parameters

  handle | WM8960 handle structure.
  reg | The register address in WM8960.
  mask | The mask code for the bits want to write. The bit you want to write should be 0.
  val | Value needs to write into the register.