InPlay API
I2S Profile

HAL I2S. More...

Macros

#define I2S_CCR_WSS_16   0
 I2S each sample size.
 

Enumerations

enum  i2s_id { MI2S_ID = 1, SI2S_ID = 2 }
 I2S Core ID. More...
 
enum  i2s_word_size { I2S_WS_16BITS = 16, I2S_WS_24BITS = 24, I2S_WS_32BITS = 32 }
 I2S Core max word size. More...
 
enum  i2s_sr {
  I2S_SR_8K = 8000, I2S_SR_16K = 16000, I2S_SR_24K = 24000, I2S_SR_32K = 32000,
  I2S_SR_36K = 36000, I2S_SR_44K = 44100, I2S_SR_48K = 48000
}
 I2S sample rate. More...
 
enum  i2s_type { I2S_MONO = 1, I2S_STEREO }
 I2S data type. More...
 
enum  i2s_ch_id { I2S_CH_1, I2S_CH_2, I2S_CH_MAX }
 Each I2S Core can have 2 Channel. More...
 
enum  i2s_ch_dir { I2S_DIR_TX = 1, I2S_DIR_RX = 2 }
 Each I2S channel can be either TX or RX. More...
 
enum  i2s_ch_word_sz {
  I2S_CH_WS_0_BIT = 0, I2S_CH_WS_12_BITS, I2S_CH_WS_16_BITS, I2S_CH_WS_20_BITS,
  I2S_CH_WS_24_BITS, I2S_CH_WS_32_BITS
}
 Each I2S channel word size. More...
 
enum  i2s_error {
  I2S_ERR_OK = 0, I2S_ERR_INVALID_PARAM = -1, I2S_ERR_INVALID_STATE = -2, I2S_ERR_RX_OV = -4,
  I2S_ERR_TX_OV = -5, I2S_ERR_DMA_NOT_AVAIL = -6, I2S_ERR_DMA_TRAN = -7
}
 I2S driver return code. More...
 

Functions

void * hal_i2s_open (int id, int sr, int word_sz)
 Initialize I2S driver. More...
 
int hal_i2s_close (void *hdl)
 Close I2S driver. More...
 
int hal_i2s_ch_en (void *hdl, int ch_id, int dir, int ch_word_sz, void *buffer0, void *buffer1, uint16_t buffer_len, void *arg, void(*callback)(void *arg, int id, int status))
 Enable I2S channel. More...
 
int hal_i2s_ch_dis (void *hdl, int ch_id, int dir)
 Disable I2S channel. More...
 

Detailed Description

HAL I2S.

Enumeration Type Documentation

◆ i2s_ch_dir

enum i2s_ch_dir

Each I2S channel can be either TX or RX.

Enumerator
I2S_DIR_TX 

Transmit.

I2S_DIR_RX 

Receive.

◆ i2s_ch_id

enum i2s_ch_id

Each I2S Core can have 2 Channel.

Enumerator
I2S_CH_1 

I2S Channel 1.

I2S_CH_2 

I2S Channel 2.

I2S_CH_MAX 

I2S max channel.

◆ i2s_ch_word_sz

Each I2S channel word size.

Enumerator
I2S_CH_WS_0_BIT 

Don't care.

I2S_CH_WS_12_BITS 

Channel word size is 12 bits.

I2S_CH_WS_16_BITS 

Channel word size is 16 bits.

I2S_CH_WS_20_BITS 

Channel word size is 20 bits.

I2S_CH_WS_24_BITS 

Channel word size is 24 bits.

I2S_CH_WS_32_BITS 

Channel word size is 32 bits.

◆ i2s_error

enum i2s_error

I2S driver return code.

Enumerator
I2S_ERR_OK 

No error. Good.

I2S_ERR_INVALID_PARAM 

Error. Invalid param.

I2S_ERR_INVALID_STATE 

Error. Invalid state.

I2S_ERR_RX_OV 

Error. I2S channel RX overflow.

I2S_ERR_TX_OV 

Error. I2S channel TX overflow.

I2S_ERR_DMA_NOT_AVAIL 

Error. DMA is not available.

I2S_ERR_DMA_TRAN 

Error. DMA tranfer.

◆ i2s_id

enum i2s_id

I2S Core ID.

Enumerator
MI2S_ID 

I2S Master Core.

SI2S_ID 

I2S Slave Core.

◆ i2s_sr

enum i2s_sr

I2S sample rate.

Enumerator
I2S_SR_8K 

Sample rate at 8Khz.

I2S_SR_16K 

Sample rate at 16Khz.

I2S_SR_24K 

Sample rate at 24Khz.

I2S_SR_32K 

Sample rate at 32Khz.

I2S_SR_36K 

Sample rate at 36Khz.

I2S_SR_44K 

Sample rate at 44.1Khz.

I2S_SR_48K 

Sample rate at 48Khz.

◆ i2s_type

enum i2s_type

I2S data type.

Enumerator
I2S_MONO 

Mono data.

I2S_STEREO 

Stereo data.

◆ i2s_word_size

I2S Core max word size.

Enumerator
I2S_WS_16BITS 

Max sample word size is 16 bits.

I2S_WS_24BITS 

Max sample word size is 24 bits.

I2S_WS_32BITS 

Max sample word size is 32 bits.

Function Documentation

◆ hal_i2s_ch_dis()

int hal_i2s_ch_dis ( void *  hdl,
int  ch_id,
int  dir 
)

Disable I2S channel.

Parameters
[in]hdlThe handle from the previous "open" function.
[in]ch_idChannel Id,
See also
enum i2s_ch_id.
Returns
See also
enum i2s_error for the possible return code.

◆ hal_i2s_ch_en()

int hal_i2s_ch_en ( void *  hdl,
int  ch_id,
int  dir,
int  ch_word_sz,
void *  buffer0,
void *  buffer1,
uint16_t  buffer_len,
void *  arg,
void(*)(void *arg, int id, int status)  callback 
)

Enable I2S channel.

Note
  1. For Slave I2S, there is only 1 channel,
  2. For ADPCM with I2S input or output, specify buffers and length to 0,
  3. The movement of the I2s data are as follow:
    1. Initially, user should allocate two buffers with the same length,
    2. For TX, user should fill both buffers before calling this function, The data should be organized by left channel first and then followed by the right channel data. For mono data, there is no need to duplicate the same data. For channel data size is 12 bits, user should use 16 bits buffer with the lower 12 bits to store data, For data size are 20 or 24 bits, user should use 32 bits buffer with the lower 20 or 24 bits to store data.
      3. Driver enables I2s HW,
    3. When HW finish the first buffer, driver will call user's provided call back function to inform user that the first buffer is ready to be either read (RX) or write (TX),
      5. While user handles the first buffer, the driver will hand over the second buffer to the HW for it to either consume (TX) or fill (RX) the second buffer.
    4. The step 4 and 5 will continue switching between first and second buffers (ping and pong) until user stop the operation,
    5. The RX data has the same format as TX data which means the left channel data followed by right channel data,
    6. The driver's call back is in the interrupt context, so user should off load the processing to the other context.
Parameters
[in]hdlThe handle from the previous "open" function.
[in]ch_idChannel Id,
See also
enum i2s_ch_id. Master can have 2 channels. Slave can have only 1 channel.
Parameters
[in]dirDirection,
See also
enum i2s_ch_dir. Each channel can be either TX or RX.
Parameters
[in]ch_word_szEach channel's left and right word size,
See also
enum i2s_ch_word_sz.
Parameters
[in]buffer0Pointer to the first buffer. Can be either 16 or 32 bits buffer depends on the word size.
[in]buffer1Pointer to the second buffer. The same as buffer 0.
[in]buffer_lenThe length of the buffer.
[in]argCall back argument provided by the caller.
[in]callbackCall back function provided by the caller.
1. arg - user's provided argument,
  1. id - the buffer index, 0 or 1,
  2. status -
See also
enum i2s_error.
Returns
See also
enum i2s_error for the possible return code.

◆ hal_i2s_close()

int hal_i2s_close ( void *  hdl)

Close I2S driver.

Parameters
[in]hdlThe handle from the previous "open" function.
Returns
See also
enum i2s_error for the possible return code.

◆ hal_i2s_open()

void* hal_i2s_open ( int  id,
int  sr,
int  word_sz 
)

Initialize I2S driver.

Parameters
[in]idI2s core Id,
See also
enum i2s_id
Parameters
[in]srSample rate,
See also
enum i2s_sample_rate. This is only related to I2s master.
Parameters
[in]word_szMax. word size for left and right word select,
See also
enum i2s_word_size.
Returns
Handle to the I2s driver, NULL means open failed.