MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
ESAI: Enhanced Serial Audio Interface

Overview

The MCUXpresso SDK provides a peripheral driver for the Enhanced Serial Audio Interface (ESAI) module of MCUXpresso SDK devices.

ESAI driver includes functional APIs and transactional APIs.

Functional APIs are feature/property target low-level APIs. Functional APIs can be used for ESAI initialization/configuration/operation for optimization/customization purpose. Using the functional API requires the knowledge of the ESAI peripheral and how to organize functional APIs to meet the application requirements. All functional API use the peripheral base address as the first parameter. ESAI functional operation groups provide the functional API set.

Transactional APIs are transaction target high-level APIs. Transactional APIs can be used to enable the peripheral and in the application if the code size and performance of transactional APIs satisfy the requirements. If the code size and performance are a critical requirement, see the transactional API implementation and write a custom code. All transactional APIs use the esai_handle_t as the first parameter. Initialize the handle by calling the ESAI_TransferTxCreateHandle() or ESAI_TransferRxCreateHandle() API.

Transactional APIs support asynchronous transfer. This means that the functions ESAI_TransferSendNonBlocking() and ESAI_TransferReceiveNonBlocking() set up the interrupt for data transfer. When the transfer completes, the upper layer is notified through a callback function with the kStatus_ESAI_TxIdle and kStatus_ESAI_RxIdle status.

Typical use case

ESAI Send/Receive using an interrupt method

esai_handle_t g_esaiTxHandle;
esai_config_t user_config;
esai_transfer_t sendXfer;
volatile bool txFinished;
volatile bool rxFinished;
const uint8_t sendData[] = [......];
void ESAI_UserCallback(esai_handle_t *handle, status_t status, void *userData)
{
userData = userData;
if (kStatus_ESAI_TxIdle == status)
{
txFinished = true;
}
}
void main(void)
{
//...
ESAI_TxGetDefaultConfig(&user_config);
ESAI_TxInit(ESAI0, &user_config);
ESAI_TransferTxCreateHandle(ESAI0, &g_esaiHandle, ESAI_UserCallback, NULL);
//Configure esai format
ESAI_TransferTxSetTransferFormat(ESAI0, &g_esaiHandle, mclkSource, mclk);
// Prepare to send.
sendXfer.data = sendData
sendXfer.dataSize = sizeof(sendData)/sizeof(sendData[0]);
txFinished = false;
// Send out.
ESAI_TransferSendNonBlocking(ESAI0, &g_esaiHandle, &sendXfer);
// Wait send finished.
while (!txFinished)
{
}
// ...
}

ESAI Send/receive using a DMA method

esai_handle_t g_esaiHandle;
dma_handle_t g_esaiTxDmaHandle;
dma_handle_t g_esaiRxDmaHandle;
esai_config_t user_config;
esai_transfer_t sendXfer;
volatile bool txFinished;
uint8_t sendData[] = ...;
void ESAI_UserCallback(esai_handle_t *handle, status_t status, void *userData)
{
userData = userData;
if (kStatus_ESAI_TxIdle == status)
{
txFinished = true;
}
}
void main(void)
{
//...
ESAI_TxGetDefaultConfig(&user_config);
ESAI_TxInit(ESAI0, &user_config);
// Sets up the DMA.
DMAMUX_Init(DMAMUX0);
DMAMUX_SetSource(DMAMUX0, ESAI_TX_DMA_CHANNEL, ESAI_TX_DMA_REQUEST);
DMAMUX_EnableChannel(DMAMUX0, ESAI_TX_DMA_CHANNEL);
DMA_Init(DMA0);
/* Creates the DMA handle. */
DMA_CreateHandle(&g_esaiTxDmaHandle, DMA0, ESAI_TX_DMA_CHANNEL);
ESAI_TransferTxCreateHandleDMA(ESAI0, &g_esaiTxDmaHandle, ESAI_UserCallback, NULL);
// Prepares to send.
sendXfer.data = sendData
sendXfer.dataSize = sizeof(sendData)/sizeof(sendData[0]);
txFinished = false;
// Sends out.
ESAI_TransferSendDMA(&g_esaiHandle, &sendXfer);
// Waits for send to complete.
while (!txFinished)
{
}
// ...
}

Modules

 ESAI eDMA Driver
 

Data Structures

struct  esai_customer_protocol_t
 ESAI customer defined audio format. More...
 
struct  esai_config_t
 ESAI user configuration structure. More...
 
struct  esai_format_t
 esai transfer format More...
 
struct  esai_transfer_t
 ESAI transfer structure. More...
 
struct  esai_handle_t
 ESAI handle structure. More...
 

Macros

#define ESAI_XFER_QUEUE_SIZE   (4)
 ESAI transfer queue size, user can refine it according to use case. More...
 

Typedefs

typedef void(* esai_transfer_callback_t )(ESAI_Type *base, esai_handle_t *handle, status_t status, void *userData)
 ESAI transfer callback prototype.
 

Enumerations

enum  _esai_status_t {
  kStatus_ESAI_TxBusy = MAKE_STATUS(kStatusGroup_ESAI, 0),
  kStatus_ESAI_RxBusy = MAKE_STATUS(kStatusGroup_ESAI, 1),
  kStatus_ESAI_TxError = MAKE_STATUS(kStatusGroup_ESAI, 2),
  kStatus_ESAI_RxError = MAKE_STATUS(kStatusGroup_ESAI, 3),
  kStatus_ESAI_QueueFull = MAKE_STATUS(kStatusGroup_ESAI, 4),
  kStatus_ESAI_TxIdle = MAKE_STATUS(kStatusGroup_ESAI, 5),
  kStatus_ESAI_RxIdle = MAKE_STATUS(kStatusGroup_ESAI, 6)
}
 ESAI return status. More...
 
enum  esai_mode_t {
  kESAI_NormalMode = 0x0U,
  kESAI_NetworkMode
}
 Define the ESAI bus type. More...
 
enum  esai_protocol_t {
  kESAI_BusLeftJustified = 0x0U,
  kESAI_BusRightJustified,
  kESAI_BusI2S,
  kESAI_BusPCMA,
  kESAI_BusPCMB,
  kESAI_BusTDM,
  kESAI_BusCustomerNormal,
  kESAI_BusCustomerNetwork
}
 Define the ESAI bus type. More...
 
enum  esai_master_slave_t {
  kESAI_Master = 0x0U,
  kESAI_Slave = 0x1U
}
 Master or slave mode. More...
 
enum  esai_sync_mode_t {
  kESAI_ModeAsync = 0x0U,
  kESAI_ModeSync
}
 Synchronous or asynchronous mode. More...
 
enum  esai_hclk_source_t { ,
  kESAI_rxHckSourceInternal = ESAI_ECR_ERI_MASK,
  kESAI_rxHckSourceExternal = ESAI_ECR_ERO_MASK
}
 Mater clock source. More...
 
enum  esai_clock_polarity_t {
  kESAI_ClockActiveHigh = 0x0U,
  kESAI_ClockActiveLow
}
 Bit clock source. More...
 
enum  esai_shift_direction_t {
  kESAI_ShifterMSB = 0x0,
  kESAI_ShifterLSB = 0x1
}
 
enum  esai_clock_direction_t {
  kESAI_ClockInput = 0x0,
  kESAI_ClockOutput = 0x1
}
 
enum  _esai_interrupt_enable_t {
  kESAI_LastSlotInterruptEnable,
  kESAI_TransmitInterruptEnable = ESAI_TCR_TIE_MASK,
  kESAI_EvenSlotDataInterruptEnable = ESAI_TCR_TEDIE_MASK,
  kESAI_ExceptionInterruptEnable = ESAI_TCR_TEIE_MASK
}
 The ESAI interrupt enable flag. More...
 
enum  _esai_flags {
  kESAI_TransmitInitFlag = ESAI_ESR_TINIT_MASK,
  kESAI_ReceiveFIFOFullFlag = ESAI_ESR_RFF_MASK,
  kESAI_TransmitFIFOEmptyFlag = ESAI_ESR_TFE_MASK,
  kESAI_TransmitLastSlotFlag = ESAI_ESR_TLS_MASK,
  kESAI_TransmitDataExceptionFlag = ESAI_ESR_TDE_MASK,
  kESAI_TransmitEvenDataFlag = ESAI_ESR_TED_MASK,
  kESAI_TransmitDataFlag = ESAI_ESR_TD_MASK,
  kESAI_ReceiveLastSlot = ESAI_ESR_RLS_MASK,
  kESAI_ReceiveDataException = ESAI_ESR_RDE_MASK,
  kESAI_ReceiveEvenData = ESAI_ESR_RED_MASK,
  kESAI_ReceiveData = ESAI_ESR_RD_MASK
}
 The ESAI status flag. More...
 
enum  _esai_sai_flags {
  kESAI_TransmitOddRegEmpty = ESAI_SAISR_TODFE_MASK,
  kESAI_TransmitEvenRegEmpty = ESAI_SAISR_TEDE_MASK,
  kESAI_TransmitRegEmpty = ESAI_SAISR_TDE_MASK,
  kESAI_TransmitUnderrunError = ESAI_SAISR_TUE_MASK,
  kESAI_TransmitFrameSync = ESAI_SAISR_TFS_MASK,
  kESAI_RecceiveOddRegFull = ESAI_SAISR_RODF_MASK,
  kESAI_ReceiveEvenRegFull = ESAI_SAISR_RDF_MASK,
  kESAI_RecceiveOverrunError = ESAI_SAISR_ROE_MASK,
  kESAI_ReceiveFrameSync = ESAI_SAISR_RFS_MASK,
  kESAI_SerialInputFlag2 = ESAI_SAISR_IF2_MASK,
  kESAI_SerialInputFlag1 = ESAI_SAISR_IF1_MASK,
  kESAI_SerialInputFlag0 = ESAI_SAISR_IF0_MASK
}
 SAI interface port status flag. More...
 
enum  esai_sample_rate_t {
  kESAI_SampleRate8KHz = 8000U,
  kESAI_SampleRate11025Hz = 11025U,
  kESAI_SampleRate12KHz = 12000U,
  kESAI_SampleRate16KHz = 16000U,
  kESAI_SampleRate22050Hz = 22050U,
  kESAI_SampleRate24KHz = 24000U,
  kESAI_SampleRate32KHz = 32000U,
  kESAI_SampleRate44100Hz = 44100U,
  kESAI_SampleRate48KHz = 48000U,
  kESAI_SampleRate96KHz = 96000U
}
 Audio sample rate. More...
 
enum  esai_word_width_t {
  kESAI_WordWidth8bits = 8U,
  kESAI_WordWidth16bits = 16U,
  kESAI_WordWidth24bits = 24U,
  kESAI_WordWidth32bits = 32U
}
 Audio word width. More...
 
enum  esai_slot_format_t {
  kESAI_SlotLen8WordLen8 = 0x0U,
  kESAI_SlotLen12WordLen8 = 0x04U,
  kESAI_SlotLen12WordLen12 = 0x01U,
  kESAI_SlotLen16WordLen8 = 0x08U,
  kESAI_SlotLen16WordLen12 = 0x05U,
  kESAI_SlotLen16WordLen16 = 0x02U,
  kESAI_SlotLen20WordLen8 = 0x0CU,
  kESAI_SlotLen20WordLen12 = 0x09U,
  kESAI_SlotLen20WordLen16 = 0x06U,
  kESAI_SlotLen20WordLen20 = 0x03U,
  kESAI_SlotLen24WordLen8 = 0x10U,
  kESAI_SlotLen24WordLen12 = 0x0DU,
  kESAI_SlotLen24WordLen16 = 0x0AU,
  kESAI_SlotLen24WordLen20 = 0x07U,
  kESAI_SlotLen24WordLen24 = 0x1EU,
  kESAI_SlotLen32WordLen8 = 0x18U,
  kESAI_SlotLen32WordLen12 = 0x15U,
  kESAI_SlotLen32WordLen16 = 0x12U,
  kESAI_SlotLen32WordLen20 = 0x0FU,
  kESAI_SlotLen32WordLen24 = 0x1FU
}
 

Driver version

#define FSL_ESAI_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
 Version 2.0.0.
 

Initialization and deinitialization

void ESAI_Init (ESAI_Type *base, esai_config_t *config)
 Initializes the ESAI peripheral. More...
 
void ESAI_GetDefaultConfig (esai_config_t *config)
 Sets the ESAI configuration structure to default values. More...
 
void ESAI_Deinit (ESAI_Type *base)
 De-initializes the ESAI peripheral. More...
 
static void ESAI_Enable (ESAI_Type *base, bool enable)
 Enable/Disable the ESAI peripheral internal logic. More...
 
static void ESAI_Reset (ESAI_Type *base)
 Reset ESAI internal logic. More...
 
void ESAI_TxReset (ESAI_Type *base)
 Reset ESAI all tx sections. More...
 
void ESAI_RxReset (ESAI_Type *base)
 Reset ESAI all rx sections. More...
 
static void ESAI_TxResetFIFO (ESAI_Type *base)
 Resets the ESAI Tx FIFO. More...
 
static void ESAI_RxResetFIFO (ESAI_Type *base)
 Resets the ESAI Rx FIFO. More...
 
void ESAI_TxEnable (ESAI_Type *base, uint8_t sectionMap)
 Enables/disables ESAI Tx. More...
 
void ESAI_RxEnable (ESAI_Type *base, uint8_t sectionMap)
 Enables/disables ESAI Rx. More...
 
static void ESAI_TxEnableFIFO (ESAI_Type *base, bool enable)
 Enables/disables ESAI Tx FIFO. More...
 
static void ESAI_RxEnableFIFO (ESAI_Type *base, bool enable)
 Enables/disables ESAI Rx FIFO. More...
 
static void ESAI_TxSetSlotMask (ESAI_Type *base, uint32_t slot)
 Set ESAI Tx slot mask value. More...
 
static void EASI_RxSetSlotMask (ESAI_Type *base, uint32_t slot)
 Set ESAI Rx slot mask value. More...
 

Status

static uint32_t ESAI_GetStatusFlag (ESAI_Type *base)
 Gets the ESAI status flag state. More...
 
static uint32_t ESAI_GetSAIStatusFlag (ESAI_Type *base)
 Gets the ESAI SAI port status flag state. More...
 
static uint32_t ESAI_GetTxFIFOStatus (ESAI_Type *base)
 Gets the ESAI Tx FIFO state. More...
 
static uint32_t ESAI_GetRxFIFOStatus (ESAI_Type *base)
 Gets the ESAI Tx status flag state. More...
 

Interrupts

static void ESAI_TxEnableInterrupts (ESAI_Type *base, uint32_t mask)
 Enables ESAI Tx interrupt requests. More...
 
static void ESAI_RxEnableInterrupts (ESAI_Type *base, uint32_t mask)
 Enables ESAI Rx interrupt requests. More...
 
static void ESAI_TxDisableInterrupts (ESAI_Type *base, uint32_t mask)
 Disables ESAI Tx interrupt requests. More...
 
static void ESAI_RxDisableInterrupts (ESAI_Type *base, uint32_t mask)
 Disables ESAI Rx interrupt requests. More...
 

DMA Control

static uint32_t ESAI_TxGetDataRegisterAddress (ESAI_Type *base)
 Gets the ESAI Tx data register address. More...
 
static uint32_t ESAI_RxGetDataRegisterAddress (ESAI_Type *base)
 Gets the ESAI Rx data register address. More...
 

Bus Operations

void ESAI_TxSetFormat (ESAI_Type *base, esai_format_t *format, uint32_t hckClockHz, uint32_t hckSourceClockHz)
 Configures the ESAI Tx audio format. More...
 
void ESAI_RxSetFormat (ESAI_Type *base, esai_format_t *format, uint32_t hckClockHz, uint32_t hckSourceClockHz)
 Configures the ESAI Rx audio format. More...
 
void ESAI_WriteBlocking (ESAI_Type *base, uint32_t bitWidth, uint8_t *buffer, uint32_t size)
 Sends data using a blocking method. More...
 
static void ESAI_WriteData (ESAI_Type *base, uint32_t data)
 Writes data into ESAI FIFO. More...
 
void ESAI_ReadBlocking (ESAI_Type *base, uint32_t bitWidth, uint8_t *buffer, uint32_t size)
 Receives data using a blocking method. More...
 
static uint32_t ESAI_ReadData (ESAI_Type *base, uint32_t channel)
 Reads data from ESAI FIFO. More...
 

Transactional

void ESAI_TransferTxCreateHandle (ESAI_Type *base, esai_handle_t *handle, esai_transfer_callback_t callback, void *userData)
 Initializes the ESAI Tx handle. More...
 
void ESAI_TransferRxCreateHandle (ESAI_Type *base, esai_handle_t *handle, esai_transfer_callback_t callback, void *userData)
 Initializes the ESAI Rx handle. More...
 
status_t ESAI_TransferTxSetFormat (ESAI_Type *base, esai_handle_t *handle, esai_format_t *format, uint32_t hckClockHz, uint32_t hckSourceClockHz)
 Configures the ESAI Tx audio format. More...
 
status_t ESAI_TransferRxSetFormat (ESAI_Type *base, esai_handle_t *handle, esai_format_t *format, uint32_t hckClockHz, uint32_t hckSourceClockHz)
 Configures the ESAI Rx audio format. More...
 
status_t ESAI_TransferSendNonBlocking (ESAI_Type *base, esai_handle_t *handle, esai_transfer_t *xfer)
 Performs an interrupt non-blocking send transfer on ESAI. More...
 
status_t ESAI_TransferReceiveNonBlocking (ESAI_Type *base, esai_handle_t *handle, esai_transfer_t *xfer)
 Performs an interrupt non-blocking receive transfer on ESAI. More...
 
status_t ESAI_TransferGetSendCount (ESAI_Type *base, esai_handle_t *handle, size_t *count)
 Gets a set byte count. More...
 
status_t ESAI_TransferGetReceiveCount (ESAI_Type *base, esai_handle_t *handle, size_t *count)
 Gets a received byte count. More...
 
void ESAI_TransferAbortSend (ESAI_Type *base, esai_handle_t *handle)
 Aborts the current send. More...
 
void ESAI_TransferAbortReceive (ESAI_Type *base, esai_handle_t *handle)
 Aborts the the current IRQ receive. More...
 
void ESAI_TransferTxHandleIRQ (ESAI_Type *base, esai_handle_t *handle)
 Tx interrupt handler. More...
 
void ESAI_TransferRxHandleIRQ (ESAI_Type *base, esai_handle_t *handle)
 Tx interrupt handler. More...
 

Data Structure Documentation

struct esai_customer_protocol_t

Data Fields

esai_mode_t mode
 ESAI mode, network, normal or on demand mode.
 
esai_shift_direction_t shiftDirection
 Data shift direction, MSB or LSB.
 
bool fsEarly
 If the frame sync one bit early.
 
bool ifZeroPading
 If padding zero.
 
bool dataAlign
 Data left aligned or right aligned.
 
bool fsOneBit
 If the frame sync one word length or one bit length.
 
uint8_t slotNum
 Slot number for the audio format.
 
struct esai_config_t

Data Fields

esai_sync_mode_t syncMode
 ESAI sync mode, control Tx/Rx clock sync.
 
esai_protocol_t txProtocol
 Use which kind of protocol.
 
esai_protocol_t rxProtocol
 Use which kind of protocol.
 
esai_customer_protocol_t txCustomer
 Audio protocol customer uses for tx.
 
esai_customer_protocol_t rxCustomer
 Audio protocol customer uses for rx.
 
esai_master_slave_t master
 Master or slave.
 
esai_clock_direction_t txHckDirection
 Tx HCK direction, input or output.
 
esai_clock_direction_t rxHckDirection
 Rx HCK direction, input or output.
 
esai_hclk_source_t txHckSource
 Tx HCK clock source.
 
esai_hclk_source_t rxHckSource
 Rx HCK clock source.
 
esai_clock_polarity_t txHckPolarity
 Tx HCK polarity.
 
esai_clock_polarity_t txFsPolarity
 Tx frame sync polarity.
 
esai_clock_polarity_t txSckPolarity
 Tx bit clock polarity.
 
esai_clock_polarity_t rxHckPolarity
 Rx HCK polarity.
 
esai_clock_polarity_t rxFsPolarity
 Rx frame sync polarity.
 
esai_clock_polarity_t rxSckPolarity
 Rx bit clock polarity.
 
uint8_t txWatermark
 Tx transfer watermark.
 
uint8_t rxWatermark
 Rx receive watermark.
 
struct esai_format_t

Data Fields

esai_sample_rate_t sampleRate_Hz
 Sample rate of audio data.
 
esai_slot_format_t slotType
 Slot format for audio format.
 
uint8_t sectionMap
 The sections enabled, 0x1 means TE0 enabled, 0x2 means TE1 enabled, 0x4 means TE2, etc.
 
struct esai_transfer_t

Data Fields

uint8_t * data
 Data start address to transfer. More...
 
size_t dataSize
 Transfer size. More...
 

Field Documentation

uint8_t* esai_transfer_t::data
size_t esai_transfer_t::dataSize
struct _esai_handle

Data Fields

uint32_t state
 Transfer status.
 
esai_transfer_callback_t callback
 Callback function called at transfer event.
 
void * userData
 Callback parameter passed to callback function.
 
uint8_t bitWidth
 Bit width for transfer, 8/16/24/32 bits.
 
uint8_t slotLen
 Slot length of the audio data.
 
uint8_t sectionMap
 Enabled section map.
 
esai_transfer_t esaiQueue [ESAI_XFER_QUEUE_SIZE]
 Transfer queue storing queued transfer.
 
size_t transferSize [ESAI_XFER_QUEUE_SIZE]
 Data bytes need to transfer.
 
volatile uint8_t queueUser
 Index for user to queue transfer.
 
volatile uint8_t queueDriver
 Index for driver to get the transfer data and size.
 
uint8_t watermark
 Watermark value.
 

Macro Definition Documentation

#define ESAI_XFER_QUEUE_SIZE   (4)

Enumeration Type Documentation

Enumerator
kStatus_ESAI_TxBusy 

ESAI Tx is busy.

kStatus_ESAI_RxBusy 

ESAI Rx is busy.

kStatus_ESAI_TxError 

ESAI Tx FIFO error.

kStatus_ESAI_RxError 

ESAI Rx FIFO error.

kStatus_ESAI_QueueFull 

ESAI transfer queue is full.

kStatus_ESAI_TxIdle 

ESAI Tx is idle.

kStatus_ESAI_RxIdle 

ESAI Rx is idle.

Enumerator
kESAI_NormalMode 

Use normal mode.

kESAI_NetworkMode 

Network mode.

Enumerator
kESAI_BusLeftJustified 

Uses left justified format.

kESAI_BusRightJustified 

Uses right justified format.

kESAI_BusI2S 

Uses I2S format.

kESAI_BusPCMA 

Uses I2S PCM A format.

kESAI_BusPCMB 

Uses I2S PCM B format.

kESAI_BusTDM 

Use TDM mode.

kESAI_BusCustomerNormal 

Customer defined normal mode.

kESAI_BusCustomerNetwork 

Customer defined network mode.

Enumerator
kESAI_Master 

Master mode.

kESAI_Slave 

Slave mode.

Enumerator
kESAI_ModeAsync 

Asynchronous mode.

kESAI_ModeSync 

Synchronous mode (with receiver or transmit)

Enumerator
kESAI_rxHckSourceInternal 

Rx HCK source is ESAI internal clock.

kESAI_rxHckSourceExternal 

Rx HCK source is external.

Enumerator
kESAI_ClockActiveHigh 

Clock active while high.

kESAI_ClockActiveLow 

Clock actie while low.

Enumerator
kESAI_ShifterMSB 

Data is shifted MSB first.

kESAI_ShifterLSB 

Data is shifted LSB first.

Enumerator
kESAI_ClockInput 

Clock direction is input.

kESAI_ClockOutput 

Clock direction is output.

Enumerator
kESAI_LastSlotInterruptEnable 

Enable interrupt at the beginning of last slot of frame in network mode.

kESAI_TransmitInterruptEnable 

Transmit/receive even slot data interrupt.

kESAI_EvenSlotDataInterruptEnable 

Transmit/receive even slot data interrupt.

kESAI_ExceptionInterruptEnable 

FIFO error flag.

Enumerator
kESAI_TransmitInitFlag 

Indicates transmit FIFO is writing the first word.

kESAI_ReceiveFIFOFullFlag 

Receive FIFO full flag.

kESAI_TransmitFIFOEmptyFlag 

Transmit FIFO empty.

kESAI_TransmitLastSlotFlag 

Transmit last slot.

kESAI_TransmitDataExceptionFlag 

Transmit data exception.

kESAI_TransmitEvenDataFlag 

Transmit even data.

kESAI_TransmitDataFlag 

Transmit data.

kESAI_ReceiveLastSlot 

Receive last slot.

kESAI_ReceiveDataException 

Receive data exception.

kESAI_ReceiveEvenData 

Receive even data.

kESAI_ReceiveData 

Receive data.

Enumerator
kESAI_TransmitOddRegEmpty 

Enabled transmitter register empty at odd slot.

kESAI_TransmitEvenRegEmpty 

Enabled transmitter register empty at even slot.

kESAI_TransmitRegEmpty 

All data in enabled transmitter regsiter send to shifter.

kESAI_TransmitUnderrunError 

Serial shifter empty and a transmit slot begins.

kESAI_TransmitFrameSync 

A transmit frame sync occurred in the current time slot.

kESAI_RecceiveOddRegFull 

Enabled receiver register full at odd slot.

kESAI_ReceiveEvenRegFull 

Enabled receiver register full at even slot.

kESAI_RecceiveOverrunError 

Receive data register overrun flag.

kESAI_ReceiveFrameSync 

Receive frame sync flag, indicate a frame sync occurs.

kESAI_SerialInputFlag2 

Serial input flag 2.

kESAI_SerialInputFlag1 

Serial in out flag 1.

kESAI_SerialInputFlag0 

Serial input flag 0.

Enumerator
kESAI_SampleRate8KHz 

Sample rate 8000 Hz.

kESAI_SampleRate11025Hz 

Sample rate 11025 Hz.

kESAI_SampleRate12KHz 

Sample rate 12000 Hz.

kESAI_SampleRate16KHz 

Sample rate 16000 Hz.

kESAI_SampleRate22050Hz 

Sample rate 22050 Hz.

kESAI_SampleRate24KHz 

Sample rate 24000 Hz.

kESAI_SampleRate32KHz 

Sample rate 32000 Hz.

kESAI_SampleRate44100Hz 

Sample rate 44100 Hz.

kESAI_SampleRate48KHz 

Sample rate 48000 Hz.

kESAI_SampleRate96KHz 

Sample rate 96000 Hz.

Enumerator
kESAI_WordWidth8bits 

Audio data width 8 bits.

kESAI_WordWidth16bits 

Audio data width 16 bits.

kESAI_WordWidth24bits 

Audio data width 24 bits.

kESAI_WordWidth32bits 

Audio data width 32 bits.

Enumerator
kESAI_SlotLen8WordLen8 

Slot length 8 bits, word length 8 bits.

kESAI_SlotLen12WordLen8 

Slot length 12 bits, word length 8 bits.

kESAI_SlotLen12WordLen12 

Slot length 12 bits, word length 12 bits.

kESAI_SlotLen16WordLen8 

Slot length 16 bits, word length 8 bits.

kESAI_SlotLen16WordLen12 

Slot length 16 bits, word length 12 bits.

kESAI_SlotLen16WordLen16 

Slot length 16 bits, word length 16 bits.

kESAI_SlotLen20WordLen8 

Slot length 20 bits, word length 8 bits.

kESAI_SlotLen20WordLen12 

Slot length 20 bits, word length 12 bits.

kESAI_SlotLen20WordLen16 

Slot length 20 bits, word length 16 bits.

kESAI_SlotLen20WordLen20 

Slot length 20 bits, word length 20 bits.

kESAI_SlotLen24WordLen8 

Slot length 24 bits, word length 8 bits.

kESAI_SlotLen24WordLen12 

Slot length 24 bits, word length 12 bits.

kESAI_SlotLen24WordLen16 

Slot length 24 bits, word length 16 bits.

kESAI_SlotLen24WordLen20 

Slot length 24 bits, word length 20 bits.

kESAI_SlotLen24WordLen24 

Slot length 24 bits, word length 24 bits.

kESAI_SlotLen32WordLen8 

Slot length 32 bits, word length 8 bits.

kESAI_SlotLen32WordLen12 

Slot length 32 bits, word length 12 bits.

kESAI_SlotLen32WordLen16 

Slot length 32 bits, word length 16 bits.

kESAI_SlotLen32WordLen20 

Slot length 32 bits, word length 20 bits.

kESAI_SlotLen32WordLen24 

Slot length 32 bits, word length 24 bits.

Function Documentation

void ESAI_Init ( ESAI_Type *  base,
esai_config_t config 
)

Ungates the ESAI clock, resets the module, and configures ESAI with a configuration structure. The configuration structure can be custom filled or set with default values by ESAI_GetDefaultConfig().

Note
This API should be called at the beginning of the application to use the ESAI driver. Otherwise, accessing the ESAI module can cause a hard fault because the clock is not enabled.
Parameters
baseESAI base pointer
configESAI configuration structure.
void ESAI_GetDefaultConfig ( esai_config_t config)

This API initializes the configuration structure for use in ESAI_TxConfig(). The initialized structure can remain unchanged in ESAI_Init(), or it can be modified before calling ESAI_Init().

Parameters
configpointer to master configuration structure
void ESAI_Deinit ( ESAI_Type *  base)

This API gates the ESAI clock. The ESAI module can't operate unless ESAI_Init is called to enable the clock.

Parameters
baseESAI base pointer
static void ESAI_Enable ( ESAI_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseESAI base pointer
enableTrue meanse enable, false means disable.
static void ESAI_Reset ( ESAI_Type *  base)
inlinestatic

This API only resets the core logic, including the configuration registers, but not the ESAI FIFOs, users still needs to reset the ESAI fifo by calling ESAI_TxResetFIFO and ESAI_RxResetFIFO.

Parameters
baseESAI base pointer
void ESAI_TxReset ( ESAI_Type *  base)

This API only resets the core logic of tx and all tx sections.

Parameters
baseESAI base pointer
void ESAI_RxReset ( ESAI_Type *  base)

This API only resets the core logic of rx and all rx sections.

Parameters
baseESAI base pointer
static void ESAI_TxResetFIFO ( ESAI_Type *  base)
inlinestatic

This function only resets the ESAI Tx FIFO.

Parameters
baseESAI base pointer
static void ESAI_RxResetFIFO ( ESAI_Type *  base)
inlinestatic

This function only resets the ESAI Rx FIFO.

Parameters
baseESAI base pointer
void ESAI_TxEnable ( ESAI_Type *  base,
uint8_t  sectionMap 
)
Parameters
baseESAI base pointer
sectionMapWhich sections need to be enabled. 0 means all section disabled. This parameter can be a combination of each sections, every section N is 2^N in section map.
void ESAI_RxEnable ( ESAI_Type *  base,
uint8_t  sectionMap 
)
Parameters
baseESAI base pointer
sectionMapWhich sections need to be enabled. 0 means all section disabled. This parameter can be a combination of each sections, every section N is 2^N in section map.
static void ESAI_TxEnableFIFO ( ESAI_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseESAI base pointer
enableTrue means enable ESAI Tx, false means disable.
static void ESAI_RxEnableFIFO ( ESAI_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseESAI base pointer
enableTrue means enable ESAI Rx, false means disable.
static void ESAI_TxSetSlotMask ( ESAI_Type *  base,
uint32_t  slot 
)
inlinestatic
Parameters
baseESAI base pointer
slotSlot number need to be masked for Tx.
static void EASI_RxSetSlotMask ( ESAI_Type *  base,
uint32_t  slot 
)
inlinestatic
Parameters
baseESAI base pointer
slotSlot number need to be masked for Rx
static uint32_t ESAI_GetStatusFlag ( ESAI_Type *  base)
inlinestatic
Parameters
baseESAI base pointer
Returns
ESAI staus flag value. Use status flag to AND _esai_flags to get the related status.
static uint32_t ESAI_GetSAIStatusFlag ( ESAI_Type *  base)
inlinestatic
Parameters
baseESAI base pointer
Returns
ESAI staus flag value. Use status flag to AND _esai_sai_flags to get the related status.
static uint32_t ESAI_GetTxFIFOStatus ( ESAI_Type *  base)
inlinestatic
Parameters
baseESAI base pointer
Returns
ESAI Tx status flag value.
static uint32_t ESAI_GetRxFIFOStatus ( ESAI_Type *  base)
inlinestatic
Parameters
baseESAI base pointer
Returns
ESAI Rx status flag value.
static void ESAI_TxEnableInterrupts ( ESAI_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseESAI base pointer
maskinterrupt source. The parameter can be a combination of elements in _esai_interrupt_enable_t.
static void ESAI_RxEnableInterrupts ( ESAI_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseESAI base pointer
maskinterrupt source. The parameter can be a combination of elements in _esai_interrupt_enable_t.
static void ESAI_TxDisableInterrupts ( ESAI_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseESAI base pointer
maskinterrupt source. The parameter can be a combination of elements in _esai_interrupt_enable_t.
static void ESAI_RxDisableInterrupts ( ESAI_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseESAI base pointer
maskinterrupt source. The parameter can be a combination of elements in _esai_interrupt_enable_t.
static uint32_t ESAI_TxGetDataRegisterAddress ( ESAI_Type *  base)
inlinestatic

This API is used to provide a transfer address for ESAI DMA transfer configuration.

Parameters
baseESAI base pointer.
Returns
data register address.
static uint32_t ESAI_RxGetDataRegisterAddress ( ESAI_Type *  base)
inlinestatic

This API is used to provide a transfer address for ESAI DMA transfer configuration.

Parameters
baseESAI base pointer.
Returns
data register address.
void ESAI_TxSetFormat ( ESAI_Type *  base,
esai_format_t format,
uint32_t  hckClockHz,
uint32_t  hckSourceClockHz 
)

The audio format can be changed at run-time. This function configures the sample rate and audio data format to be transferred.

Parameters
baseESAI base pointer.
formatPointer to ESAI audio data format structure.
hckClockHzHCK clock frequency in Hz.
hckSourceClockHzHCK source clock frequency in Hz.
void ESAI_RxSetFormat ( ESAI_Type *  base,
esai_format_t format,
uint32_t  hckClockHz,
uint32_t  hckSourceClockHz 
)

The audio format can be changed at run-time. This function configures the sample rate and audio data format to be transferred.

Parameters
baseESAI base pointer.
formatPointer to ESAI audio data format structure.
hckClockHzHCK clock frequency in Hz.
hckSourceClockHzHCK source clock frequency in Hz.
void ESAI_WriteBlocking ( ESAI_Type *  base,
uint32_t  bitWidth,
uint8_t *  buffer,
uint32_t  size 
)
Note
This function blocks by polling until data is ready to be sent.
Parameters
baseESAI base pointer.
bitWidthHow many bits in a audio word, usually 8/16/24 bits.
bufferPointer to the data to be written.
sizeBytes to be written.
static void ESAI_WriteData ( ESAI_Type *  base,
uint32_t  data 
)
inlinestatic
Parameters
baseESAI base pointer.
dataData needs to be written.
void ESAI_ReadBlocking ( ESAI_Type *  base,
uint32_t  bitWidth,
uint8_t *  buffer,
uint32_t  size 
)
Note
This function blocks by polling until data is ready to be sent.
Parameters
baseESAI base pointer.
bitWidthHow many bits in a audio word, usually 8/16/24 bits.
bufferPointer to the data to be read.
sizeBytes to be read.
static uint32_t ESAI_ReadData ( ESAI_Type *  base,
uint32_t  channel 
)
inlinestatic
Parameters
baseESAI base pointer.
channelData channel used.
Returns
Data in ESAI FIFO.
void ESAI_TransferTxCreateHandle ( ESAI_Type *  base,
esai_handle_t *  handle,
esai_transfer_callback_t  callback,
void *  userData 
)

This function initializes the Tx handle for ESAI Tx transactional APIs. Call this function one time to get the handle initialized.

Parameters
baseESAI base pointer
handleESAI handle pointer.
callbackpointer to user callback function
userDatauser parameter passed to the callback function
void ESAI_TransferRxCreateHandle ( ESAI_Type *  base,
esai_handle_t *  handle,
esai_transfer_callback_t  callback,
void *  userData 
)

This function initializes the Rx handle for ESAI Rx transactional APIs. Call this function one time to get the handle initialized.

Parameters
baseESAI base pointer.
handleESAI handle pointer.
callbackpointer to user callback function
userDatauser parameter passed to the callback function
status_t ESAI_TransferTxSetFormat ( ESAI_Type *  base,
esai_handle_t *  handle,
esai_format_t format,
uint32_t  hckClockHz,
uint32_t  hckSourceClockHz 
)

The audio format can be changed at run-time. This function configures the sample rate and audio data format to be transferred.

Parameters
baseESAI base pointer.
handleESAI handle pointer.
formatPointer to ESAI audio data format structure.
hckClockHzHCK clock frequency in Hz.
hckSourceClockHzHCK clock source frequency in Hz.
Returns
Status of this function. Return value is one of status_t.
status_t ESAI_TransferRxSetFormat ( ESAI_Type *  base,
esai_handle_t *  handle,
esai_format_t format,
uint32_t  hckClockHz,
uint32_t  hckSourceClockHz 
)

The audio format can be changed at run-time. This function configures the sample rate and audio data format to be transferred.

Parameters
baseESAI base pointer.
handleESAI handle pointer.
formatPointer to ESAI audio data format structure.
hckClockHzHCK clock frequency in Hz.
hckSourceClockHzHCK clock source frequency in Hz.
Returns
Status of this function. Return value is one of status_t.
status_t ESAI_TransferSendNonBlocking ( ESAI_Type *  base,
esai_handle_t *  handle,
esai_transfer_t xfer 
)
Note
This API returns immediately after the transfer initiates. Call the ESAI_TxGetTransferStatusIRQ to poll the transfer status and check whether the transfer is finished. If the return status is not kStatus_ESAI_Busy, the transfer is finished.
Parameters
baseESAI base pointer
handlepointer to esai_handle_t structure which stores the transfer state
xferpointer to esai_transfer_t structure
Return values
kStatus_SuccessSuccessfully started the data receive.
kStatus_ESAI_TxBusyPrevious receive still not finished.
kStatus_InvalidArgumentThe input parameter is invalid.
status_t ESAI_TransferReceiveNonBlocking ( ESAI_Type *  base,
esai_handle_t *  handle,
esai_transfer_t xfer 
)
Note
This API returns immediately after the transfer initiates. Call the ESAI_RxGetTransferStatusIRQ to poll the transfer status and check whether the transfer is finished. If the return status is not kStatus_ESAI_Busy, the transfer is finished.
Parameters
baseESAI base pointer
handlepointer to esai_handle_t structure which stores the transfer state
xferpointer to esai_transfer_t structure
Return values
kStatus_SuccessSuccessfully started the data receive.
kStatus_ESAI_RxBusyPrevious receive still not finished.
kStatus_InvalidArgumentThe input parameter is invalid.
status_t ESAI_TransferGetSendCount ( ESAI_Type *  base,
esai_handle_t *  handle,
size_t *  count 
)
Parameters
baseESAI base pointer.
handlepointer to esai_handle_t structure which stores the transfer state.
countBytes count sent.
Return values
kStatus_SuccessSucceed get the transfer count.
kStatus_NoTransferInProgressThere is not a non-blocking transaction currently in progress.
status_t ESAI_TransferGetReceiveCount ( ESAI_Type *  base,
esai_handle_t *  handle,
size_t *  count 
)
Parameters
baseESAI base pointer.
handlepointer to esai_handle_t structure which stores the transfer state.
countBytes count received.
Return values
kStatus_SuccessSucceed get the transfer count.
kStatus_NoTransferInProgressThere is not a non-blocking transaction currently in progress.
void ESAI_TransferAbortSend ( ESAI_Type *  base,
esai_handle_t *  handle 
)
Note
This API can be called any time when an interrupt non-blocking transfer initiates to abort the transfer early.
Parameters
baseESAI base pointer.
handlepointer to esai_handle_t structure which stores the transfer state.
void ESAI_TransferAbortReceive ( ESAI_Type *  base,
esai_handle_t *  handle 
)
Note
This API can be called any time when an interrupt non-blocking transfer initiates to abort the transfer early.
Parameters
baseESAI base pointer
handlepointer to esai_handle_t structure which stores the transfer state.
void ESAI_TransferTxHandleIRQ ( ESAI_Type *  base,
esai_handle_t *  handle 
)
Parameters
baseESAI base pointer.
handlepointer to esai_handle_t structure.
void ESAI_TransferRxHandleIRQ ( ESAI_Type *  base,
esai_handle_t *  handle 
)
Parameters
baseESAI base pointer.
handlepointer to esai_handle_t structure.