Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
FlexIO I2S peripheral driver

This section describes the programming interface of the FlexIO I2S Peripheral driver. The FlexIO I2S Peripheral driver provides functions for a I2S device to send and receive data.

FlexIO I2S device structures

The driver uses an instantiation of the flexio_i2s_handler_t structure to maintain the current state of a particular FlexIO-simulated I2S driver. This structures holds data that is used by the FlexIO-simulated I2S Peripheral driver to communicate between the transmit and receive transfer functions and the interrupt handler. The interrupt handler also uses this information to keep track of its progress. Because the driver itself does not statically allocate memory, the caller provides memory for the driver state structure during initialization by providing a structure.

FlexIO I2S User configuration structures

The FlexIO-simulated I2S driver uses instances of the user configuration structure flexio_i2s_config_t for the FlexIO-simulated I2S driver. The user settings include: I2S mode(master or slave), sample rate, audio data bit count, FlexIO base pin DMA source and the associated FlexIO timers, shifters, and pin.

FlexIO I2S Initialization

  1. To initialize the FlexIO I2S driver, call the FLEXIO_I2S_DRV_Init() function and pass the instance number of the FlexIO peripheral, memory for the run-time state structure, and a pointer to the user configuration structure. For example, to use FlexIO0 pass a value of 0 to the initialization function.
  2. Then, pass the memory for the run-time state structure.
  3. Finally, pass a user configuration structure of the type flexio_i2s_config_t.

The flexio_i2s_user configuration contents can be easily modified to configure the FlexIO I2S peripheral driver either to a different audio data format or using different FlexIO hardware resource. This is an example code to set up a user FlexIO I2S configuration instantiation:

flexio_i2s_config_t i2sConfig;
i2sConfig.data_depth = 16;
i2sConfig.sample_rate = 12000;
i2sConfig.masterslave = kFlexioI2SSlave;
i2sConfig.txPinIdx = 0; //FlexIO pin0 as transmit data line
i2sConfig.rxPinIdx = 1; //FlexIO pin1 as receive data line
i2sConfig.sckPinIdx = 4; // FlexIO pin4 as SCLK
i2sConfig.wsPinIdx = 5; //FlexIO pin5 as Frame Sync
i2sConfig.shifterIdx[0] = 0; //Use shifter 0 for transmit data
i2sConfig.shifterIdx[1] = 1; // Use shifter 1 for receive data
i2sConfig.timerIdx[0] = 0; // Use Timer0 as SCLK controller.
i2sConfig.timerIdx[1] = 1; // Use Timer1 as Frame Sync controller.

FlexIO I2S Data Transactions

The driver implements transmit and receive functions to transfer buffers of data in an interrupt and DAM methods. Both interrupt and DMA transfer functions are non-blocking. This code examples shows how to use the functions, assuming that the FLEXIO I2S module has been initialized as described previously in the Initialization Section.

Ensure that data is consistent when there is cache in memory and when using DMA to transfer data. In other words, when reading the data from memory, ensure that data from or to the memory device is not cached.

For blocking transfer functions transmit and receive:

uint8_t music[MUSIC_LEN];
FLEXIO_I2S_DRV_SendDataInt(&i2s_handler, (uint8_t *)music, MUSIC_LEN);
osa_status_t status;
//Wait for data transfer finished
do
{
status = OSA_SemaWait(&(i2s_handler.tx_sem), OSA_WAIT_FOREVER);
}while(status == kStatus_OSA_Idle);