I2S#
Introduction#
Inter-IC Sound (I2S) is a serial communication protocol intended to convey digital audio data between integrated circuits (ICs) in electronic devices. It is commonly used for connecting audio components like digital signal processors, digital-to-analog converters, and microphones.
In an I2S connection, one device typically serves as the master, generating the clock signals, while the other device operates as the slave, synchronizing its data transmission to the master's clock. The following is a brief discussion of the I2S peripheral's capabilities:
Programmable audio resolutions
Sampling rates
Full duplex communication
Configuration#
I2S can be configured using several parameters:
The I2S module supports 5 programmable audio resolutions sl_i2s_data_resolution_t
I2S also supports 11 audio sampling rates sl_i2s_sampling_rate_t
For more information on configuring available parameters, see the respective peripheral example readme document.
Usage#
The default I2S is initialized and configured with a 16-bit resolution and an 8 kHz sampling rate. Just after calling the register callback, it will go into transmit-receive mode and communicate over the given interrupt.
Initialize the I2S: sl_si91x_i2s_init
Register event callback: sl_si91x_i2s_register_event_callback
Perform data operations:
Transmit data: sl_si91x_i2s_transmit_data
Receive data: sl_si91x_i2s_receive_data
Deinitialize the I2S: sl_si91x_i2s_deinit
Some I2S APIs to configure the power modes, unregister the callback, get the data count, and abort the transfer include:
Configure power mode: sl_si91x_i2s_configure_power_mode
Unregister event callback: sl_si91x_i2s_unregister_event_callback
Get received data count: sl_si91x_i2s_get_receive_data_count
Abort I2S transfer: sl_si91x_i2s_end_transfer
Modules#
Enumerations#
Enumeration for different I2S callback events.
Enumeration for I2S power states.
Enumeration for I2S primary and secondary modes.
Enumeration for SAI protocol type.
Enumeration for I2S SYNC/ASYNC modes.
Enumeration for I2S transfer types.
Enumeration for I2S transfer data size.
Enumeration for I2S audio data resolutions.
Enumeration for I2S sample rates.
Typedefs#
Renamed signal event structure.
Renamed status structure.
Renamed I2S driver structure.
Created I2S handle type.
Functions#
To initialize the I2S peripheral.
To uninitialize the I2S peripheral.
To configure the I2S power mode.
To configure transmit/receive parameters for I2S transfer.
To transmit I2S data.
To receive I2S data.
To register the event callback function.
To unregister the event callback function.
To get the transmitted data count of I2S.
To get the received data count of I2S.
To get the release, major, and minor version of the I2S peripheral.
To get the I2S peripheral status.
To abort the I2S transfer.
Enumeration Documentation#
i2s_event_typedef_t#
i2s_event_typedef_t
Enumeration for different I2S callback events.
This enumeration defines the various events that can trigger I2S callbacks. These events are used to notify the application of different I2S operation statuses.
Enumerator | |
---|---|
SL_I2S_SEND_COMPLETE | Send complete event. |
SL_I2S_RECEIVE_COMPLETE | Receive complete event. |
SL_I2S_TX_UNDERFLOW | TX underflow event. |
SL_I2S_RX_OVERFLOW | RX overflow event. |
SL_I2S_FRAME_ERROR | Frame error event. |
63
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_i2s_power_state_t#
sl_i2s_power_state_t
Enumeration for I2S power states.
This enumeration defines the different power states for the I2S peripheral. These states are used to manage the power consumption of the I2S module.
Enumerator | |
---|---|
SL_I2S_POWER_OFF | Power mode OFF. |
SL_I2S_FULL_POWER | Full power mode. |
78
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_i2s_mode_t#
sl_i2s_mode_t
Enumeration for I2S primary and secondary modes.
This enumeration defines the modes for the I2S peripheral, specifying whether it operates as a master or a slave. The master mode controls the clock generation, while the slave mode relies on an external clock.
Enumerator | |
---|---|
SL_I2S_MASTER | I2S primary (master) mode. |
SL_I2S_SLAVE | I2S secondary (slave) mode. |
91
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_sai_protocol_t#
sl_sai_protocol_t
Enumeration for SAI protocol type.
This enumeration defines the protocol types for the SAI (Serial Audio Interface). It specifies whether the I2S or PCM protocol is used. Note that the PCM protocol is currently not supported in the driver.
Enumerator | |
---|---|
SL_I2S_PROTOCOL | I2S protocol. |
SL_PCM_PROTOCOL | PCM protocol, currently not supported in the driver. |
104
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_i2s_sync_t#
sl_i2s_sync_t
Enumeration for I2S SYNC/ASYNC modes.
This enumeration defines the synchronization modes for the I2S peripheral. It specifies whether the I2S operates in synchronous or asynchronous mode.
Enumerator | |
---|---|
SL_I2S_SYNC | I2S synchronous mode. |
SL_I2S_ASYNC | I2S asynchronous mode. |
116
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_i2s_xfer_type_t#
sl_i2s_xfer_type_t
Enumeration for I2S transfer types.
This enumeration defines the various transfer types for the I2S peripheral. It specifies whether the I2S is configured for transmitting, receiving, or aborting ongoing transfers.
Enumerator | |
---|---|
SL_I2S_TRANSMIT | I2S transmit. |
SL_I2S_RECEIVE | I2S receive. |
SL_I2S_SEND_ABORT | I2S abort transmit. |
SL_I2S_RECEIVE_ABORT | I2S abort receive. |
129
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_i2s_xfer_size_t#
sl_i2s_xfer_size_t
Enumeration for I2S transfer data size.
This enumeration defines the data sizes for I2S transfers. It specifies the number of bits per data word that can be transferred.
Enumerator | |
---|---|
SL_I2S_DATA_SIZE8 | 8 bits per data word. |
SL_I2S_DATA_SIZE16 | 16 bits per data word. |
SL_I2S_DATA_SIZE32 | 32 bits per data word. |
143
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_i2s_data_resolution_t#
sl_i2s_data_resolution_t
Enumeration for I2S audio data resolutions.
This enumeration defines the various audio data resolutions for the I2S peripheral. It specifies the number of bits per audio sample that can be used.
Enumerator | |
---|---|
SL_I2S_RESOLUTION_12 | 12-bit resolution. |
SL_I2S_RESOLUTION_16 | 16-bit resolution. |
SL_I2S_RESOLUTION_20 | 20-bit resolution. |
SL_I2S_RESOLUTION_24 | 24-bit resolution. |
SL_I2S_RESOLUTION_32 | 32-bit resolution. |
156
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_i2s_sampling_rate_t#
sl_i2s_sampling_rate_t
Enumeration for I2S sample rates.
This enumeration defines the various sample rates for the I2S peripheral. It specifies the number of samples per second (in Hz) that can be used.
Enumerator | |
---|---|
SL_I2S_SAMPLING_RATE_8000 | 8 kHz |
SL_I2S_SAMPLING_RATE_11025 | 11.025 kHz |
SL_I2S_SAMPLING_RATE_16000 | 16 kHz |
SL_I2S_SAMPLING_RATE_22050 | 22.05 kHz |
SL_I2S_SAMPLING_RATE_24000 | 24 kHz |
SL_I2S_SAMPLING_RATE_32000 | 32 kHz |
SL_I2S_SAMPLING_RATE_44100 | 44.1 kHz |
SL_I2S_SAMPLING_RATE_48000 | 48 kHz |
SL_I2S_SAMPLING_RATE_88200 | 88.2 kHz |
SL_I2S_SAMPLING_RATE_96000 | 96 kHz |
SL_I2S_SAMPLING_RATE_192000 | 192 kHz |
171
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
Typedef Documentation#
sl_i2s_signal_event_t#
typedef ARM_SAI_SignalEvent_t sl_i2s_signal_event_t
Renamed signal event structure.
51
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_i2s_status_t#
typedef ARM_SAI_STATUS sl_i2s_status_t
Renamed status structure.
52
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_i2s_driver_t#
typedef ARM_DRIVER_SAI sl_i2s_driver_t
Renamed I2S driver structure.
53
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_i2s_handle_t#
typedef const void* sl_i2s_handle_t
Created I2S handle type.
54
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
Function Documentation#
sl_si91x_i2s_init#
sl_status_t sl_si91x_i2s_init (uint32_t i2s_instance, sl_i2s_handle_t * i2s_handle)
To initialize the I2S peripheral.
[in] | i2s_instance | 0 - I2S0, 1 - I2S1 |
[in] | i2s_handle | Double pointer to the I2S driver handle. |
This API enables the clock for the I2S peripheral and configures the SCLK, WSCLK, DIN, and DOUT pins. It also requires the address of a pointer for storing the I2S handle, which can be used for other function calls.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Operation successful.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
SL_STATUS_NULL_POINTER - Invalid null pointer received as an argument.
SL_STATUS_BUSY - Driver is busy.
For more information on status codes, see SL STATUS DOCUMENTATION.
237
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_si91x_i2s_deinit#
sl_status_t sl_si91x_i2s_deinit (sl_i2s_handle_t * i2s_handle)
To uninitialize the I2S peripheral.
[in] | i2s_handle | Pointer to the I2S driver handle. |
This API disables the DMA instance used for I2S transfer and powers down the I2S peripheral by disabling the clock supply to I2S.
Pre-condition:
sl_si91x_i2s_init must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Operation successful.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
SL_STATUS_NULL_POINTER - Invalid null pointer received as an argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
Note
When the I2S module is used in combination with other peripherals, see the notes below while deinitializing in the application:
Whenever sl_si91x_i2s_deinit() is called, it will disable the clock for the peripheral. To power off the peripheral, you have to power down the power domain (PERI_EFUSE) which contains the following peripherals: USART, UART, I2C, SSI Master, SSI Slave, Generic-SPI Master, I2S Master, I2S Slave, Micro-DMA Controller, Config Timer, Random-Number Generator, CRC Accelerator, SIO, QEI, MCPWM, and EFUSE. Use the following API to power down the particular power domain if other peripherals are not being used: sl_si91x_peri_efuse_power_down()
Some peripherals (ULP Peripherals, UULP Peripherals, GPDMA, and SDIO-SPI) have separate domains and can be powered down independently. For additional details, see the Power Architecture section in the Hardware Reference Manual. The ULP_UART has a separate power domain, ULPSS_PWRGATE_ULP_UART, which can be powered down independently. See the rsi_power_save.h file for all power gate definitions.
272
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_si91x_i2s_configure_power_mode#
sl_status_t sl_si91x_i2s_configure_power_mode (sl_i2s_handle_t i2s_handle, sl_i2s_power_state_t state)
To configure the I2S power mode.
[in] | i2s_handle | Pointer to the I2S driver handle. |
[in] | state | Power state, either SL_I2S_POWER_OFF or SL_I2S_FULL_POWER. |
This API configures the power mode of the I2S peripheral. The supported modes are:
SL_I2S_POWER_OFF: I2S peripheral clocks and I2S DMA channel are disabled.
SL_I2S_FULL_POWER: Enables I2S peripheral clocks and configures the I2S DMA channel.
Pre-conditions:
sl_si91x_i2s_init must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
SL_STATUS_NULL_POINTER - Invalid null pointer received as an argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
295
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_si91x_i2s_config_transmit_receive#
sl_status_t sl_si91x_i2s_config_transmit_receive (sl_i2s_handle_t i2s_handle, sl_i2s_xfer_config_t * xfer_config)
To configure transmit/receive parameters for I2S transfer.
[in] | i2s_handle | Pointer to the I2S driver handle. |
[in] | xfer_config | Pointer to the structure that stores transfer parameters. |
This API configures the I2S DMA transmit and receive channels. Setting the transfer_type to SL_I2S_TRANSMIT will configure the Tx channel, while setting it to SL_I2S_RECEIVE will configure the Rx channel.
Pre-conditions:
sl_si91x_i2s_init must be called before this function.
sl_si91x_i2s_configure_power_mode must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Operation successful.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
SL_STATUS_NULL_POINTER - Invalid null pointer received as an argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
319
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_si91x_i2s_transmit_data#
sl_status_t sl_si91x_i2s_transmit_data (sl_i2s_handle_t i2s_handle, const void * data, uint32_t size)
To transmit I2S data.
[in] | i2s_handle | Pointer to the I2S driver handle. |
[in] | data | Address of the transmit data. |
[in] | size | Size of the data to be transmitted. |
This API configures the I2S Tx DMA channel descriptors and triggers the DMA transfer. The function sl_si91x_i2s_config_transmit_receive() should be called with transfer_type set to SL_I2S_TRANSMIT before sending data.
Pre-conditions:
sl_si91x_i2s_init must be called before this function.
sl_si91x_i2s_configure_power_mode must be called before this function.
sl_si91x_i2s_config_transmit_receive must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
SL_STATUS_NULL_POINTER - Invalid null pointer received as an argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
345
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_si91x_i2s_receive_data#
sl_status_t sl_si91x_i2s_receive_data (sl_i2s_handle_t i2s_handle, const void * data, uint32_t size)
To receive I2S data.
[in] | i2s_handle | Pointer to the I2S driver handle. |
[in] | data | Address of the receive data buffer. |
[in] | size | Size of the data to be received. |
This API configures the I2S Rx DMA channel descriptors and enables the DMA channel to receive data. The function sl_si91x_i2s_config_transmit_receive() should be called with transfer_type set to SL_I2S_RECEIVE before receiving data.
Pre-conditions:
sl_si91x_i2s_init must be called before this function.
sl_si91x_i2s_configure_power_mode must be called before this function.
sl_si91x_i2s_config_transmit_receive must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
SL_STATUS_NULL_POINTER - Invalid null pointer received as an argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
371
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_si91x_i2s_register_event_callback#
sl_status_t sl_si91x_i2s_register_event_callback (sl_i2s_handle_t i2s_handle, sl_i2s_signal_event_t callback_event)
To register the event callback function.
[in] | i2s_handle | Pointer to the I2S driver handle. |
[in] | callback_event | Pointer to the function to be called at the time of interrupt. |
This API registers a callback function to notify the application of transfer complete events. Callbacks should be registered before starting the I2S transfer.
Pre-conditions:
sl_si91x_i2s_init must be called before this function.
sl_si91x_i2s_configure_power_mode must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_BUSY - Driver is busy.
SL_STATUS_NULL_POINTER - The parameter is a null pointer.
For more information on status codes, see SL STATUS DOCUMENTATION.
394
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_si91x_i2s_unregister_event_callback#
sl_status_t sl_si91x_i2s_unregister_event_callback (sl_i2s_handle_t i2s_handle)
To unregister the event callback function.
[in] | i2s_handle | Pointer to the I2S driver handle. |
This function unregisters the previously registered callback function. It can be used only if callbacks are registered using sl_si91x_i2s_register_event_callback().
Pre-condition:
sl_si91x_i2s_register_event_callback must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
SL_STATUS_NULL_POINTER - Invalid null pointer received as argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
415
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_si91x_i2s_get_transmit_data_count#
uint32_t sl_si91x_i2s_get_transmit_data_count (sl_i2s_handle_t i2s_handle)
To get the transmitted data count of I2S.
[in] | i2s_handle | Pointer to the I2S driver handle. |
This function retrieves the count of data bytes that have been transmitted by the I2S peripheral. It can be used to monitor the progress of an ongoing I2S data transfer.
Pre-conditions:
sl_si91x_i2s_init must be called before this function.
sl_si91x_i2s_configure_power_mode must be called before this function.
sl_si91x_i2s_config_transmit_receive must be called before this function.
sl_si91x_i2s_transmit_data must be called before this function.
Returns
uint32_t The number of data bytes transmitted.
434
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_si91x_i2s_get_receive_data_count#
uint32_t sl_si91x_i2s_get_receive_data_count (sl_i2s_handle_t i2s_handle)
To get the received data count of I2S.
[in] | i2s_handle | Pointer to the I2S driver handle. |
This function retrieves the count of data bytes that have been received by the I2S peripheral. It can be used to monitor the progress of an ongoing I2S data reception.
Pre-conditions:
sl_si91x_i2s_init must be called before this function.
sl_si91x_i2s_configure_power_mode must be called before this function.
sl_si91x_i2s_config_transmit_receive must be called before this function.
sl_si91x_i2s_receive_data must be called before this function.
Returns
uint32_t The number of data bytes received.
453
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_si91x_i2s_get_version#
sl_i2s_version_t sl_si91x_i2s_get_version (void )
To get the release, major, and minor version of the I2S peripheral.
N/A |
This function retrieves the version information of the I2S peripheral, including the release, major, and minor version numbers.
Returns
sl_i2s_version_t Structure containing the version information:
release: Release version number.
major: Major version number.
minor: Minor version number.
467
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_si91x_i2s_get_status#
sl_i2s_status_t sl_si91x_i2s_get_status (sl_i2s_handle_t i2s_handle)
To get the I2S peripheral status.
[in] | i2s_handle | Pointer to the I2S driver handle. |
This function retrieves the current status of the I2S peripheral, including:
Frame error
Rx busy
Rx overflow
Tx busy
Tx underflow
Pre-conditions:
sl_si91x_i2s_init must be called before this function.
sl_si91x_i2s_configure_power_mode must be called before this function.
sl_si91x_i2s_config_transmit_receive must be called before this function.
Returns
sl_i2s_status_t Structure containing the I2S status information.
489
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h
sl_si91x_i2s_end_transfer#
sl_status_t sl_si91x_i2s_end_transfer (sl_i2s_handle_t i2s_handle, sl_i2s_xfer_type_t abort_type)
To abort the I2S transfer.
[in] | i2s_handle | Pointer to the I2S driver handle. |
[in] | abort_type | Abort type, either ARM_SAI_ABORT_SEND or ARM_SAI_ABORT_RECEIVE. |
This function disables the I2S clocks and DMA channel, stopping the WSCLK generation.
Pre-conditions:
sl_si91x_i2s_init must be called before this function.
sl_si91x_i2s_configure_power_mode must be called before this function.
sl_si91x_i2s_config_transmit_receive must be called before this function.
sl_si91x_i2s_transmit_data or sl_si91x_i2s_receive_data must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
SL_STATUS_NULL_POINTER - Invalid null pointer received as an argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
513
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_i2s.h