I2S HAL

group nrf_i2s_hal

Hardware access layer for managing the Inter-IC Sound (I2S) peripheral.

Defines

NRF_I2S_HAS_CLKCONFIG

Symbol indicating whether clock source configuration is available.

NRF_I2S_HAS_FRAMESTART

Symbol indicating whether frame start event is available.

NRF_I2S_HAS_GPIO_PORT_SELECTION

Symbol indicating whether GPIO port selection for pins is available.

NRF_I2S_HAS_SWIDTH_32BIT

Symbol indicating whether 32-bit sample width is available.

NRF_I2S_PIN_NOT_CONNECTED

This value can be provided as a parameter for the nrf_i2s_pins_set function call to specify that the given I2S signal (SDOUT, SDIN, or MCK) shall not be connected to a physical pin.

NRF_I2S_PSEL_SCK_PIN_MASK

I2S SCK pin selection mask.

NRF_I2S_PSEL_SCK_PORT_MASK

I2S SCK port selection mask.

Enums

enum nrf_i2s_task_t

I2S tasks.

Values:

enumerator NRF_I2S_TASK_START

Starts continuous I2S transfer. Also starts the MCK generator if this is enabled.

enumerator NRF_I2S_TASK_STOP

Stops I2S transfer. Also stops the MCK generator.

enum nrf_i2s_event_t

I2S events.

Values:

enumerator NRF_I2S_EVENT_RXPTRUPD

The RXD.PTR register has been copied to internal double buffers.

enumerator NRF_I2S_EVENT_TXPTRUPD

The TXD.PTR register has been copied to internal double buffers.

enumerator NRF_I2S_EVENT_STOPPED

I2S transfer stopped.

enumerator NRF_I2S_EVENT_FRAMESTART

Frame start event, generated on the active edge of LRCK.

enum nrf_i2s_int_mask_t

I2S interrupts.

Values:

enumerator NRF_I2S_INT_RXPTRUPD_MASK

Interrupt on RXPTRUPD event.

enumerator NRF_I2S_INT_TXPTRUPD_MASK

Interrupt on TXPTRUPD event.

enumerator NRF_I2S_INT_STOPPED_MASK

Interrupt on STOPPED event.

enumerator NRF_I2S_INT_FRAMESTART_MASK

Interrupt on FRAMESTART event.

enum nrf_i2s_mode_t

I2S modes of operation.

Values:

enumerator NRF_I2S_MODE_MASTER

Master mode.

enumerator NRF_I2S_MODE_SLAVE

Slave mode.

enum nrf_i2s_mck_t

I2S master clock generator settings.

Values:

enumerator NRF_I2S_MCK_DISABLED

MCK disabled.

enumerator NRF_I2S_MCK_32MDIV2

32 MHz / 2 = 16.0 MHz.

enumerator NRF_I2S_MCK_32MDIV3

32 MHz / 3 = 10.6666667 MHz.

enumerator NRF_I2S_MCK_32MDIV4

32 MHz / 4 = 8.0 MHz.

enumerator NRF_I2S_MCK_32MDIV5

32 MHz / 5 = 6.4 MHz.

enumerator NRF_I2S_MCK_32MDIV6

32 MHz / 6 = 5.3333333 MHz.

enumerator NRF_I2S_MCK_32MDIV8

32 MHz / 8 = 4.0 MHz.

enumerator NRF_I2S_MCK_32MDIV10

32 MHz / 10 = 3.2 MHz.

enumerator NRF_I2S_MCK_32MDIV11

32 MHz / 11 = 2.9090909 MHz.

enumerator NRF_I2S_MCK_32MDIV15

32 MHz / 15 = 2.1333333 MHz.

enumerator NRF_I2S_MCK_32MDIV16

32 MHz / 16 = 2.0 MHz.

enumerator NRF_I2S_MCK_32MDIV21

32 MHz / 21 = 1.5238095 MHz.

enumerator NRF_I2S_MCK_32MDIV23

32 MHz / 23 = 1.3913043 MHz.

enumerator NRF_I2S_MCK_32MDIV30

32 MHz / 30 = 1.0666667 MHz.

enumerator NRF_I2S_MCK_32MDIV31

32 MHz / 31 = 1.0322581 MHz.

enumerator NRF_I2S_MCK_32MDIV32

32 MHz / 32 = 1.0 MHz.

enumerator NRF_I2S_MCK_32MDIV42

32 MHz / 42 = 0.7619048 MHz.

enumerator NRF_I2S_MCK_32MDIV63

32 MHz / 63 = 0.5079365 MHz.

enumerator NRF_I2S_MCK_32MDIV125

32 MHz / 125 = 0.256 MHz.

enum nrf_i2s_ratio_t

I2S MCK/LRCK ratios.

Values:

enumerator NRF_I2S_RATIO_32X

LRCK = MCK / 32.

enumerator NRF_I2S_RATIO_48X

LRCK = MCK / 48.

enumerator NRF_I2S_RATIO_64X

LRCK = MCK / 64.

enumerator NRF_I2S_RATIO_96X

LRCK = MCK / 96.

enumerator NRF_I2S_RATIO_128X

LRCK = MCK / 128.

enumerator NRF_I2S_RATIO_192X

LRCK = MCK / 192.

enumerator NRF_I2S_RATIO_256X

LRCK = MCK / 256.

enumerator NRF_I2S_RATIO_384X

LRCK = MCK / 384.

enumerator NRF_I2S_RATIO_512X

LRCK = MCK / 512.

enum nrf_i2s_swidth_t

I2S sample widths.

Values:

enumerator NRF_I2S_SWIDTH_8BIT

8 bit.

enumerator NRF_I2S_SWIDTH_16BIT

16 bit.

enumerator NRF_I2S_SWIDTH_24BIT

24 bit.

enumerator NRF_I2S_SWIDTH_32BIT

32 bit.

enumerator NRF_I2S_SWIDTH_8BIT_IN16BIT

8 bit sample in a 16-bit half-frame.

enumerator NRF_I2S_SWIDTH_8BIT_IN32BIT

8 bit sample in a 32-bit half-frame.

enumerator NRF_I2S_SWIDTH_16BIT_IN32BIT

16 bit sample in a 32-bit half-frame.

enumerator NRF_I2S_SWIDTH_24BIT_IN32BIT

24 bit sample in a 32-bit half-frame.

enum nrf_i2s_align_t

I2S alignments of sample within a frame.

Values:

enumerator NRF_I2S_ALIGN_LEFT

Left-aligned.

enumerator NRF_I2S_ALIGN_RIGHT

Right-aligned.

enum nrf_i2s_format_t

I2S frame formats.

Values:

enumerator NRF_I2S_FORMAT_I2S

Original I2S format.

enumerator NRF_I2S_FORMAT_ALIGNED

Alternate (left-aligned or right-aligned) format.

enum nrf_i2s_channels_t

I2S enabled channels.

Values:

enumerator NRF_I2S_CHANNELS_STEREO

Stereo.

enumerator NRF_I2S_CHANNELS_LEFT

Left only.

enumerator NRF_I2S_CHANNELS_RIGHT

Right only.

enum nrf_i2s_clksrc_t

I2S Clock source selection.

Values:

enumerator NRF_I2S_CLKSRC_PCLK32M

32MHz peripheral clock.

enumerator NRF_I2S_CLKSRC_ACLK

Audio PLL clock.

Functions

NRF_STATIC_INLINE void nrf_i2s_task_trigger(NRF_I2S_Type *p_reg, nrf_i2s_task_t task)

Function for activating the specified I2S task.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • task[in] Task to be activated.

NRF_STATIC_INLINE uint32_t nrf_i2s_task_address_get(NRF_I2S_Type const *p_reg, nrf_i2s_task_t task)

Function for getting the address of the specified I2S task register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • task[in] Specified task.

Returns:

Address of the specified task register.

NRF_STATIC_INLINE void nrf_i2s_event_clear(NRF_I2S_Type *p_reg, nrf_i2s_event_t event)

Function for clearing the specified I2S event.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] Event to clear.

NRF_STATIC_INLINE bool nrf_i2s_event_check(NRF_I2S_Type const *p_reg, nrf_i2s_event_t event)

Function for retrieving the state of the I2S event.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] Event to be checked.

Return values:
  • true – The event has been generated.

  • false – The event has not been generated.

NRF_STATIC_INLINE uint32_t nrf_i2s_event_address_get(NRF_I2S_Type const *p_reg, nrf_i2s_event_t event)

Function for getting the address of the specified I2S event register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] Specified event.

Returns:

Address of the specified event register.

NRF_STATIC_INLINE void nrf_i2s_int_enable(NRF_I2S_Type *p_reg, uint32_t mask)

Function for enabling specified interrupts.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be enabled. Use nrf_i2s_int_mask_t values for bit masking.

NRF_STATIC_INLINE void nrf_i2s_int_disable(NRF_I2S_Type *p_reg, uint32_t mask)

Function for disabling specified interrupts.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be disabled. Use nrf_i2s_int_mask_t values for bit masking.

NRF_STATIC_INLINE uint32_t nrf_i2s_int_enable_check(NRF_I2S_Type const *p_reg, uint32_t mask)

Function for checking if the specified interrupts are enabled.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be checked. Use nrf_i2s_int_mask_t values for bit masking.

Returns:

Mask of enabled interrupts.

NRF_STATIC_INLINE void nrf_i2s_enable(NRF_I2S_Type *p_reg)

Function for enabling the I2S peripheral.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

NRF_STATIC_INLINE void nrf_i2s_disable(NRF_I2S_Type *p_reg)

Function for disabling the I2S peripheral.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

NRF_STATIC_INLINE void nrf_i2s_subscribe_set(NRF_I2S_Type *p_reg, nrf_i2s_task_t task, uint8_t channel)

Function for setting the subscribe configuration for a given I2S task.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • task[in] Task for which to set the configuration.

  • channel[in] Channel through which to subscribe events.

NRF_STATIC_INLINE void nrf_i2s_subscribe_clear(NRF_I2S_Type *p_reg, nrf_i2s_task_t task)

Function for clearing the subscribe configuration for a given I2S task.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • task[in] Task for which to clear the configuration.

NRF_STATIC_INLINE void nrf_i2s_publish_set(NRF_I2S_Type *p_reg, nrf_i2s_event_t event, uint8_t channel)

Function for setting the publish configuration for a given I2S event.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] Event for which to set the configuration.

  • channel[in] Channel through which to publish the event.

NRF_STATIC_INLINE void nrf_i2s_publish_clear(NRF_I2S_Type *p_reg, nrf_i2s_event_t event)

Function for clearing the publish configuration for a given I2S event.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] Event for which to clear the configuration.

NRF_STATIC_INLINE void nrf_i2s_pins_set(NRF_I2S_Type *p_reg, nrf_i2s_pins_t const *p_pins)

Function for configuring I2S pins.

Usage of the SDOUT, SDIN, and MCK signals is optional. If a given signal is not needed, pass the NRF_I2S_PIN_NOT_CONNECTED value instead of its pin number.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • p_pins[in] Pointer to the structure with pins selection.

NRF_STATIC_INLINE uint32_t nrf_i2s_sck_pin_get(NRF_I2S_Type const *p_reg)

Function for getting the SCK pin selection.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

SCK pin selection.

NRF_STATIC_INLINE uint32_t nrf_i2s_lrck_pin_get(NRF_I2S_Type const *p_reg)

Function for getting the LRCK pin selection.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

LRCK pin selection.

NRF_STATIC_INLINE uint32_t nrf_i2s_mck_pin_get(NRF_I2S_Type const *p_reg)

Function for getting the MCK pin selection.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

MCK pin selection.

NRF_STATIC_INLINE uint32_t nrf_i2s_sdout_pin_get(NRF_I2S_Type const *p_reg)

Function for getting the SDOUT pin selection.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

SDOUT pin selection.

NRF_STATIC_INLINE uint32_t nrf_i2s_sdin_pin_get(NRF_I2S_Type const *p_reg)

Function for getting the SDIN pin selection.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

SDIN pin selection.

NRF_STATIC_INLINE void nrf_i2s_configure(NRF_I2S_Type *p_reg, nrf_i2s_config_t const *p_config)

Function for setting the I2S peripheral configuration.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • p_config[in] Pointer to the structure with configuration.

NRF_STATIC_INLINE void nrf_i2s_transfer_set(NRF_I2S_Type *p_reg, uint16_t size, uint32_t *p_rx_buffer, uint32_t const *p_tx_buffer)

Function for setting up the I2S transfer.

This function sets up the RX and TX buffers and enables reception or transmission (or both) accordingly. If the transfer in a given direction is not required, pass NULL instead of the pointer to the corresponding buffer.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • size[in] Size of the buffers (in 32-bit words).

  • p_rx_buffer[in] Pointer to the receive buffer. Pass NULL to disable reception.

  • p_tx_buffer[in] Pointer to the transmit buffer. Pass NULL to disable transmission.

NRF_STATIC_INLINE void nrf_i2s_rx_buffer_set(NRF_I2S_Type *p_reg, uint32_t *p_buffer)

Function for setting the pointer to the receive buffer.

Note

The size of the buffer can be set only by calling nrf_i2s_transfer_set.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • p_buffer[in] Pointer to the receive buffer.

NRF_STATIC_INLINE uint32_t *nrf_i2s_rx_buffer_get(NRF_I2S_Type const *p_reg)

Function for getting the pointer to the receive buffer.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Pointer to the receive buffer.

NRF_STATIC_INLINE void nrf_i2s_tx_buffer_set(NRF_I2S_Type *p_reg, uint32_t const *p_buffer)

Function for setting the pointer to the transmit buffer.

Note

The size of the buffer can be set only by calling nrf_i2s_transfer_set.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • p_buffer[in] Pointer to the transmit buffer.

NRF_STATIC_INLINE uint32_t *nrf_i2s_tx_buffer_get(NRF_I2S_Type const *p_reg)

Function for getting the pointer to the transmit buffer.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Pointer to the transmit buffer.

NRF_STATIC_INLINE void nrf_i2s_clk_configure(NRF_I2S_Type *p_reg, nrf_i2s_clksrc_t clksrc, bool enable_bypass)

Function for configuring I2S Clock.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • clksrc[in] I2S Clock source selection.

  • enable_bypass[in] Bypass clock generator. MCK will be equal to source input. If bypass is enabled the MCKFREQ setting has no effect.

struct nrf_i2s_config_t
#include <nrf_i2s.h>

I2S configuration.

Public Members

nrf_i2s_mode_t mode

Mode of operation (master or slave).

nrf_i2s_format_t format

I2S frame format.

nrf_i2s_align_t alignment

Alignment of sample within a frame.

nrf_i2s_swidth_t sample_width

Sample width.

nrf_i2s_channels_t channels

Enabled channels.

nrf_i2s_mck_t mck_setup

Master clock generator setup.

nrf_i2s_ratio_t ratio

MCK/LRCK ratio.

struct nrf_i2s_pins_t
#include <nrf_i2s.h>

I2S pins.

Public Members

uint32_t sck_pin

SCK pin number.

uint32_t lrck_pin

LRCK pin number.

uint32_t mck_pin

MCK pin number.

Optional. Use NRF_I2S_PIN_NOT_CONNECTED if this signal is not needed.

uint32_t sdout_pin

SDOUT pin number.

Optional. Use NRF_I2S_PIN_NOT_CONNECTED if this signal is not needed.

uint32_t sdin_pin

SDIN pin number.

Optional. Use NRF_I2S_PIN_NOT_CONNECTED if this signal is not needed.