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

Overview

The codec common driver provide codec control abstraction interface.

Data Structures

struct  codec_config_t
 Initialize structure of the codec. More...
 
struct  codec_capability_t
 codec capability More...
 
struct  codec_handle_t
 Codec handle definition. More...
 

Macros

#define CODEC_VOLUME_MAX_VALUE   (100U)
 codec maximum volume range
 

Enumerations

enum  _codec_status {
  kStatus_CODEC_NotSupport = MAKE_STATUS(kStatusGroup_CODEC, 0U),
  kStatus_CODEC_DeviceNotRegistered = MAKE_STATUS(kStatusGroup_CODEC, 1U),
  kStatus_CODEC_I2CBusInitialFailed,
  kStatus_CODEC_I2CCommandTransferFailed
}
 CODEC status. More...
 
enum  codec_audio_protocol_t {
  kCODEC_BusI2S = 0U,
  kCODEC_BusLeftJustified = 1U,
  kCODEC_BusRightJustified = 2U,
  kCODEC_BusPCMA = 3U,
  kCODEC_BusPCMB = 4U,
  kCODEC_BusTDM = 5U
}
 AUDIO format definition. More...
 
enum  _codec_audio_sample_rate {
  kCODEC_AudioSampleRate8KHz = 8000U,
  kCODEC_AudioSampleRate11025Hz = 11025U,
  kCODEC_AudioSampleRate12KHz = 12000U,
  kCODEC_AudioSampleRate16KHz = 16000U,
  kCODEC_AudioSampleRate22050Hz = 22050U,
  kCODEC_AudioSampleRate24KHz = 24000U,
  kCODEC_AudioSampleRate32KHz = 32000U,
  kCODEC_AudioSampleRate44100Hz = 44100U,
  kCODEC_AudioSampleRate48KHz = 48000U,
  kCODEC_AudioSampleRate96KHz = 96000U,
  kCODEC_AudioSampleRate192KHz = 192000U,
  kCODEC_AudioSampleRate384KHz = 384000U
}
 audio sample rate definition More...
 
enum  _codec_audio_bit_width {
  kCODEC_AudioBitWidth16bit = 16U,
  kCODEC_AudioBitWidth20bit = 20U,
  kCODEC_AudioBitWidth24bit = 24U,
  kCODEC_AudioBitWidth32bit = 32U
}
 audio bit width More...
 
enum  codec_module_t {
  kCODEC_ModuleADC = 0U,
  kCODEC_ModuleDAC = 1U,
  kCODEC_ModulePGA = 2U,
  kCODEC_ModuleHeadphone = 3U,
  kCODEC_ModuleSpeaker = 4U,
  kCODEC_ModuleLinein = 5U,
  kCODEC_ModuleLineout = 6U,
  kCODEC_ModuleVref = 7U,
  kCODEC_ModuleMicbias = 8U,
  kCODEC_ModuleMic = 9U,
  kCODEC_ModuleI2SIn = 10U,
  kCODEC_ModuleI2SOut = 11U,
  kCODEC_ModuleMxier = 12U
}
 audio codec module More...
 
enum  codec_module_ctrl_cmd_t { kCODEC_ModuleSwitchI2SInInterface = 0U }
 audio codec module control cmd More...
 
enum  _codec_module_ctrl_i2s_in_interface {
  kCODEC_ModuleI2SInInterfacePCM = 0U,
  kCODEC_ModuleI2SInInterfaceDSD = 1U
}
 audio codec module digital interface More...
 
enum  _codec_record_source {
  kCODEC_RecordSourceDifferentialLine = 1U,
  kCODEC_RecordSourceLineInput = 2U,
  kCODEC_RecordSourceDifferentialMic = 4U,
  kCODEC_RecordSourceDigitalMic = 8U,
  kCODEC_RecordSourceSingleEndMic = 16U
}
 audio codec module record source value More...
 
enum  _codec_reocrd_channel {
  kCODEC_RecordChannelLeft1 = 1U,
  kCODEC_RecordChannelLeft2 = 2U,
  kCODEC_RecordChannelLeft3 = 4U,
  kCODEC_RecordChannelRight1 = 1U,
  kCODEC_RecordChannelRight2 = 2U,
  kCODEC_RecordChannelRight3 = 4U,
  kCODEC_RecordChannelDifferentialPositive1 = 1U,
  kCODEC_RecordChannelDifferentialPositive2 = 2U,
  kCODEC_RecordChannelDifferentialPositive3 = 4U,
  kCODEC_RecordChannelDifferentialNegative1 = 8U,
  kCODEC_RecordChannelDifferentialNegative2 = 16U,
  kCODEC_RecordChannelDifferentialNegative3 = 32U
}
 audio codec record channel More...
 
enum  _codec_play_source {
  kCODEC_PlaySourcePGA = 1U,
  kCODEC_PlaySourceInput = 2U,
  kCODEC_PlaySourceDAC = 4U,
  kCODEC_PlaySourceMixerIn = 1U,
  kCODEC_PlaySourceMixerInLeft = 2U,
  kCODEC_PlaySourceMixerInRight = 4U,
  kCODEC_PlaySourceAux = 8U
}
 audio codec module play source value More...
 
enum  _codec_play_channel {
  kCODEC_PlayChannelHeadphoneLeft = 1U,
  kCODEC_PlayChannelHeadphoneRight = 2U,
  kCODEC_PlayChannelSpeakerLeft = 4U,
  kCODEC_PlayChannelSpeakerRight = 8U,
  kCODEC_PlayChannelLineOutLeft = 16U,
  kCODEC_PlayChannelLineOutRight = 32U,
  kCODEC_PlayChannelLeft0 = 1U,
  kCODEC_PlayChannelRight0 = 2U,
  kCODEC_PlayChannelLeft1 = 4U,
  kCODEC_PlayChannelRight1 = 8U,
  kCODEC_PlayChannelLeft2 = 16U,
  kCODEC_PlayChannelRight2 = 32U,
  kCODEC_PlayChannelLeft3 = 64U,
  kCODEC_PlayChannelRight3 = 128U
}
 codec play channel More...
 
enum  _codec_capability_flag {
  kCODEC_SupportModuleADC = 1U << 0U,
  kCODEC_SupportModuleDAC = 1U << 1U,
  kCODEC_SupportModulePGA = 1U << 2U,
  kCODEC_SupportModuleHeadphone = 1U << 3U,
  kCODEC_SupportModuleSpeaker = 1U << 4U,
  kCODEC_SupportModuleLinein = 1U << 5U,
  kCODEC_SupportModuleLineout = 1U << 6U,
  kCODEC_SupportModuleVref = 1U << 7U,
  kCODEC_SupportModuleMicbias = 1U << 8U,
  kCODEC_SupportModuleMic = 1U << 9U,
  kCODEC_SupportModuleI2SIn = 1U << 10U,
  kCODEC_SupportModuleI2SOut = 1U << 11U,
  kCODEC_SupportModuleMixer = 1U << 12U,
  kCODEC_SupportModuleI2SInSwitchInterface = 1U << 13U,
  kCODEC_SupportPlayChannelLeft0 = 1U << 0U,
  kCODEC_SupportPlayChannelRight0 = 1U << 1U,
  kCODEC_SupportPlayChannelLeft1 = 1U << 2U,
  kCODEC_SupportPlayChannelRight1 = 1U << 3U,
  kCODEC_SupportPlayChannelLeft2 = 1U << 4U,
  kCODEC_SupportPlayChannelRight2 = 1U << 5U,
  kCODEC_SupportPlayChannelLeft3 = 1U << 6U,
  kCODEC_SupportPlayChannelRight3 = 1U << 7U,
  kCODEC_SupportPlaySourcePGA = 1U << 8U,
  kCODEC_SupportPlaySourceInput = 1U << 9U,
  kCODEC_SupportPlaySourceDAC = 1U << 10U,
  kCODEC_SupportPlaySourceMixerIn = 1U << 11U,
  kCODEC_SupportPlaySourceMixerInLeft = 1U << 12U,
  kCODEC_SupportPlaySourceMixerInRight = 1U << 13U,
  kCODEC_SupportPlaySourceAux = 1U << 14U,
  kCODEC_SupportRecordSourceDifferentialLine = 1U << 0U,
  kCODEC_SupportRecordSourceLineInput = 1U << 1U,
  kCODEC_SupportRecordSourceDifferentialMic = 1U << 2U,
  kCODEC_SupportRecordSourceDigitalMic = 1U << 3U,
  kCODEC_SupportRecordSourceSingleEndMic = 1U << 4U,
  kCODEC_SupportRecordChannelLeft1 = 1U << 6U,
  kCODEC_SupportRecordChannelLeft2 = 1U << 7U,
  kCODEC_SupportRecordChannelLeft3 = 1U << 8U,
  kCODEC_SupportRecordChannelRight1 = 1U << 9U,
  kCODEC_SupportRecordChannelRight2 = 1U << 10U,
  kCODEC_SupportRecordChannelRight3 = 1U << 11U
}
 audio codec capability More...
 

Functions

status_t CODEC_Init (codec_handle_t *handle, codec_config_t *config)
 Codec initilization. More...
 
status_t CODEC_Deinit (codec_handle_t *handle)
 Codec de-initilization. More...
 
status_t CODEC_SetFormat (codec_handle_t *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth)
 set audio data format. More...
 
status_t CODEC_ModuleControl (codec_handle_t *handle, codec_module_ctrl_cmd_t cmd, uint32_t data)
 codec module control. More...
 
status_t CODEC_SetVolume (codec_handle_t *handle, uint32_t channel, uint32_t volume)
 set audio codec pl volume. More...
 
status_t CODEC_SetMute (codec_handle_t *handle, uint32_t channel, bool mute)
 set audio codec module mute. More...
 
status_t CODEC_SetPower (codec_handle_t *handle, codec_module_t module, bool powerOn)
 set audio codec power. More...
 
status_t CODEC_SetRecord (codec_handle_t *handle, uint32_t recordRource)
 codec set record source. More...
 
status_t CODEC_SetRecordChannel (codec_handle_t *handle, uint32_t leftRecordChannel, uint32_t rightRecordChannel)
 codec set record channel. More...
 
status_t CODEC_SetPlay (codec_handle_t *handle, uint32_t playSource)
 codec set play source. More...
 

Driver version

#define FSL_CODEC_DRIVER_VERSION   (MAKE_VERSION(2, 2, 0))
 CLOCK driver version 2.2.0. More...
 

Data Structure Documentation

struct codec_config_t

Data Fields

uint32_t codecDevType
 codec type
 
void * codecDevConfig
 Codec device specific configuration.
 
struct codec_capability_t

Data Fields

uint32_t codecModuleCapability
 codec module capability
 
uint32_t codecPlayCapability
 codec play capability
 
uint32_t codecRecordCapability
 codec record capability
 
struct _codec_handle

codec handle declaration

  • Application should allocate a buffer with CODEC_HANDLE_SIZE for handle definition, such as uint8_t codecHandleBuffer[CODEC_HANDLE_SIZE]; codec_handle_t *codecHandle = codecHandleBuffer;

Data Fields

codec_config_tcodecConfig
 codec configuration function pointer
 
const codec_capability_tcodecCapability
 codec capability
 
uint8_t codecDevHandle [HAL_CODEC_HANDLER_SIZE]
 codec device handle
 

Macro Definition Documentation

#define FSL_CODEC_DRIVER_VERSION   (MAKE_VERSION(2, 2, 0))

Enumeration Type Documentation

Enumerator
kStatus_CODEC_NotSupport 

CODEC not support status.

kStatus_CODEC_DeviceNotRegistered 

CODEC device register failed status.

kStatus_CODEC_I2CBusInitialFailed 

CODEC i2c bus initialization failed status.

kStatus_CODEC_I2CCommandTransferFailed 

CODEC i2c bus command transfer failed status.

Enumerator
kCODEC_BusI2S 

I2S type.

kCODEC_BusLeftJustified 

Left justified mode.

kCODEC_BusRightJustified 

Right justified mode.

kCODEC_BusPCMA 

DSP/PCM A mode.

kCODEC_BusPCMB 

DSP/PCM B mode.

kCODEC_BusTDM 

TDM mode.

Enumerator
kCODEC_AudioSampleRate8KHz 

Sample rate 8000 Hz.

kCODEC_AudioSampleRate11025Hz 

Sample rate 11025 Hz.

kCODEC_AudioSampleRate12KHz 

Sample rate 12000 Hz.

kCODEC_AudioSampleRate16KHz 

Sample rate 16000 Hz.

kCODEC_AudioSampleRate22050Hz 

Sample rate 22050 Hz.

kCODEC_AudioSampleRate24KHz 

Sample rate 24000 Hz.

kCODEC_AudioSampleRate32KHz 

Sample rate 32000 Hz.

kCODEC_AudioSampleRate44100Hz 

Sample rate 44100 Hz.

kCODEC_AudioSampleRate48KHz 

Sample rate 48000 Hz.

kCODEC_AudioSampleRate96KHz 

Sample rate 96000 Hz.

kCODEC_AudioSampleRate192KHz 

Sample rate 192000 Hz.

kCODEC_AudioSampleRate384KHz 

Sample rate 384000 Hz.

Enumerator
kCODEC_AudioBitWidth16bit 

audio bit width 16

kCODEC_AudioBitWidth20bit 

audio bit width 20

kCODEC_AudioBitWidth24bit 

audio bit width 24

kCODEC_AudioBitWidth32bit 

audio bit width 32

Enumerator
kCODEC_ModuleADC 

codec module ADC

kCODEC_ModuleDAC 

codec module DAC

kCODEC_ModulePGA 

codec module PGA

kCODEC_ModuleHeadphone 

codec module headphone

kCODEC_ModuleSpeaker 

codec module speaker

kCODEC_ModuleLinein 

codec module linein

kCODEC_ModuleLineout 

codec module lineout

kCODEC_ModuleVref 

codec module VREF

kCODEC_ModuleMicbias 

codec module MIC BIAS

kCODEC_ModuleMic 

codec module MIC

kCODEC_ModuleI2SIn 

codec module I2S in

kCODEC_ModuleI2SOut 

codec module I2S out

kCODEC_ModuleMxier 

codec module mixer

Enumerator
kCODEC_ModuleSwitchI2SInInterface 

module digital interface siwtch.

Enumerator
kCODEC_ModuleI2SInInterfacePCM 

Pcm interface.

kCODEC_ModuleI2SInInterfaceDSD 

DSD interface.

Enumerator
kCODEC_RecordSourceDifferentialLine 

record source from differential line

kCODEC_RecordSourceLineInput 

record source from line input

kCODEC_RecordSourceDifferentialMic 

record source from differential mic

kCODEC_RecordSourceDigitalMic 

record source from digital microphone

kCODEC_RecordSourceSingleEndMic 

record source from single microphone

Enumerator
kCODEC_RecordChannelLeft1 

left record channel 1

kCODEC_RecordChannelLeft2 

left record channel 2

kCODEC_RecordChannelLeft3 

left record channel 3

kCODEC_RecordChannelRight1 

right record channel 1

kCODEC_RecordChannelRight2 

right record channel 2

kCODEC_RecordChannelRight3 

right record channel 3

kCODEC_RecordChannelDifferentialPositive1 

differential positive record channel 1

kCODEC_RecordChannelDifferentialPositive2 

differential positive record channel 2

kCODEC_RecordChannelDifferentialPositive3 

differential positive record channel 3

kCODEC_RecordChannelDifferentialNegative1 

differential negative record channel 1

kCODEC_RecordChannelDifferentialNegative2 

differential negative record channel 2

kCODEC_RecordChannelDifferentialNegative3 

differential negative record channel 3

Enumerator
kCODEC_PlaySourcePGA 

play source PGA, bypass ADC

kCODEC_PlaySourceInput 

play source Input3

kCODEC_PlaySourceDAC 

play source DAC

kCODEC_PlaySourceMixerIn 

play source mixer in

kCODEC_PlaySourceMixerInLeft 

play source mixer in left

kCODEC_PlaySourceMixerInRight 

play source mixer in right

kCODEC_PlaySourceAux 

play source mixer in AUx

Enumerator
kCODEC_PlayChannelHeadphoneLeft 

play channel headphone left

kCODEC_PlayChannelHeadphoneRight 

play channel headphone right

kCODEC_PlayChannelSpeakerLeft 

play channel speaker left

kCODEC_PlayChannelSpeakerRight 

play channel speaker right

kCODEC_PlayChannelLineOutLeft 

play channel lineout left

kCODEC_PlayChannelLineOutRight 

play channel lineout right

kCODEC_PlayChannelLeft0 

play channel left0

kCODEC_PlayChannelRight0 

play channel right0

kCODEC_PlayChannelLeft1 

play channel left1

kCODEC_PlayChannelRight1 

play channel right1

kCODEC_PlayChannelLeft2 

play channel left2

kCODEC_PlayChannelRight2 

play channel right2

kCODEC_PlayChannelLeft3 

play channel left3

kCODEC_PlayChannelRight3 

play channel right3

Enumerator
kCODEC_SupportModuleADC 

codec capability of module ADC

kCODEC_SupportModuleDAC 

codec capability of module DAC

kCODEC_SupportModulePGA 

codec capability of module PGA

kCODEC_SupportModuleHeadphone 

codec capability of module headphone

kCODEC_SupportModuleSpeaker 

codec capability of module speaker

kCODEC_SupportModuleLinein 

codec capability of module linein

kCODEC_SupportModuleLineout 

codec capability of module lineout

kCODEC_SupportModuleVref 

codec capability of module vref

kCODEC_SupportModuleMicbias 

codec capability of module mic bias

kCODEC_SupportModuleMic 

codec capability of module mic bias

kCODEC_SupportModuleI2SIn 

codec capability of module I2S in

kCODEC_SupportModuleI2SOut 

codec capability of module I2S out

kCODEC_SupportModuleMixer 

codec capability of module mixer

kCODEC_SupportModuleI2SInSwitchInterface 

codec capability of module I2S in switch interface

kCODEC_SupportPlayChannelLeft0 

codec capability of play channel left 0

kCODEC_SupportPlayChannelRight0 

codec capability of play channel right 0

kCODEC_SupportPlayChannelLeft1 

codec capability of play channel left 1

kCODEC_SupportPlayChannelRight1 

codec capability of play channel right 1

kCODEC_SupportPlayChannelLeft2 

codec capability of play channel left 2

kCODEC_SupportPlayChannelRight2 

codec capability of play channel right 2

kCODEC_SupportPlayChannelLeft3 

codec capability of play channel left 3

kCODEC_SupportPlayChannelRight3 

codec capability of play channel right 3

kCODEC_SupportPlaySourcePGA 

codec capability of set playback source PGA

kCODEC_SupportPlaySourceInput 

codec capability of set playback source INPUT

kCODEC_SupportPlaySourceDAC 

codec capability of set playback source DAC

kCODEC_SupportPlaySourceMixerIn 

codec capability of set play source Mixer in

kCODEC_SupportPlaySourceMixerInLeft 

codec capability of set play source Mixer in left

kCODEC_SupportPlaySourceMixerInRight 

codec capability of set play source Mixer in right

kCODEC_SupportPlaySourceAux 

codec capability of set play source aux

kCODEC_SupportRecordSourceDifferentialLine 

codec capability of record source differential line

kCODEC_SupportRecordSourceLineInput 

codec capability of record source line input

kCODEC_SupportRecordSourceDifferentialMic 

codec capability of record source differential mic

kCODEC_SupportRecordSourceDigitalMic 

codec capability of record digital mic

kCODEC_SupportRecordSourceSingleEndMic 

codec capability of single end mic

kCODEC_SupportRecordChannelLeft1 

left record channel 1

kCODEC_SupportRecordChannelLeft2 

left record channel 2

kCODEC_SupportRecordChannelLeft3 

left record channel 3

kCODEC_SupportRecordChannelRight1 

right record channel 1

kCODEC_SupportRecordChannelRight2 

right record channel 2

kCODEC_SupportRecordChannelRight3 

right record channel 3

Function Documentation

status_t CODEC_Init ( codec_handle_t *  handle,
codec_config_t config 
)
Parameters
handlecodec handle.
configcodec configurations.
Returns
kStatus_Success is success, else de-initial failed.
status_t CODEC_Deinit ( codec_handle_t *  handle)
Parameters
handlecodec handle.
Returns
kStatus_Success is success, else de-initial failed.
status_t CODEC_SetFormat ( codec_handle_t *  handle,
uint32_t  mclk,
uint32_t  sampleRate,
uint32_t  bitWidth 
)
Parameters
handlecodec handle.
mclkmaster clock frequency in HZ.
sampleRatesample rate in HZ.
bitWidthbit width.
Returns
kStatus_Success is success, else configure failed.
status_t CODEC_ModuleControl ( codec_handle_t *  handle,
codec_module_ctrl_cmd_t  cmd,
uint32_t  data 
)

This function is used for codec module control, support switch digital interface cmd, can be expand to support codec module specific feature.

Parameters
handlecodec handle.
cmdmodule control cmd, reference _codec_module_ctrl_cmd.
datavalue to write, when cmd is kCODEC_ModuleRecordSourceChannel, the data should be a value combine of channel and source, please reference macro CODEC_MODULE_RECORD_SOURCE_CHANNEL(source, LP, LN, RP, RN), reference codec specific driver for detail configurations.
Returns
kStatus_Success is success, else configure failed.
status_t CODEC_SetVolume ( codec_handle_t *  handle,
uint32_t  channel,
uint32_t  volume 
)
Parameters
handlecodec handle.
channelaudio codec play channel, can be a value or combine value of _codec_play_channel.
volumevolume value, support 0 ~ 100, 0 is mute, 100 is the maximum volume value.
Returns
kStatus_Success is success, else configure failed.
status_t CODEC_SetMute ( codec_handle_t *  handle,
uint32_t  channel,
bool  mute 
)
Parameters
handlecodec handle.
channelaudio codec play channel, can be a value or combine value of _codec_play_channel.
mutetrue is mute, false is unmute.
Returns
kStatus_Success is success, else configure failed.
status_t CODEC_SetPower ( codec_handle_t *  handle,
codec_module_t  module,
bool  powerOn 
)
Parameters
handlecodec handle.
moduleaudio codec module.
powerOntrue is power on, false is power down.
Returns
kStatus_Success is success, else configure failed.
status_t CODEC_SetRecord ( codec_handle_t *  handle,
uint32_t  recordRource 
)
Parameters
handlecodec handle.
recordRourceaudio codec record source, can be a value or combine value of _codec_record_source.
Returns
kStatus_Success is success, else configure failed.
status_t CODEC_SetRecordChannel ( codec_handle_t *  handle,
uint32_t  leftRecordChannel,
uint32_t  rightRecordChannel 
)
Parameters
handlecodec handle.
leftRecordChannelaudio codec record channel, reference _codec_record_channel, can be a value combine of member in _codec_record_channel.
rightRecordChannelaudio codec record channel, reference _codec_record_channel, can be a value combine of member in _codec_record_channel.
Returns
kStatus_Success is success, else configure failed.
status_t CODEC_SetPlay ( codec_handle_t *  handle,
uint32_t  playSource 
)
Parameters
handlecodec handle.
playSourceaudio codec play source, can be a value or combine value of _codec_play_source.
Returns
kStatus_Success is success, else configure failed.