TDM HAL

group nrf_tdm_hal

Hardware access layer for managing the Time Division Multiplexed Audio Interface (TDM) peripheral.

Defines

NRF_TDM_PIN_NOT_CONNECTED

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

Enums

enum nrf_tdm_task_t

TDM tasks.

Values:

enumerator NRF_TDM_TASK_START

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

enumerator NRF_TDM_TASK_STOP

Stops TDM transfer after completion of MAXCNT words.

enumerator NRF_TDM_TASK_ABORT

Aborts TDM transfer without completing MAXCNT words.

enum nrf_tdm_event_t

TDM events.

Values:

enumerator NRF_TDM_EVENT_RXPTRUPD

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

enumerator NRF_TDM_EVENT_STOPPED

TDM transfer stopped.

enumerator NRF_TDM_EVENT_ABORTED

TDM transfer aborted.

enumerator NRF_TDM_EVENT_TXPTRUPD

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

enumerator NRF_TDM_EVENT_MAXCNT

MAXCNT block event, generated on the active edge of FSYNC of every MAXCNT block.

enum nrf_tdm_int_mask_t

TDM interrupts.

Values:

enumerator NRF_TDM_INT_RXPTRUPD_MASK_MASK

Interrupt on RXPTRUPD event.

enumerator NRF_TDM_INT_STOPPED_MASK_MASK

Interrupt on STOPPED event.

enumerator NRF_TDM_INT_ABORTED_MASK

Interrupt on EVENTS_ABORTED event.

enumerator NRF_TDM_INT_TXPTRUPD_MASK_MASK

Interrupt on TXPTRUPD event.

enumerator NRF_TDM_INT_MAXCNT_MASK

Interrupt on EVENTS_MAXCNT event.

enum nrf_tdm_mode_t

TDM modes of operation.

Values:

enumerator NRF_TDM_MODE_MASTER

Master mode.

enumerator NRF_TDM_MODE_SLAVE

Slave mode.

enum nrf_tdm_rxtxen_t

TDM Reception and transmission settings.

Values:

enumerator NRF_TDM_RXTXEN_DUPLEX

Enable reception and transmission.

enumerator NRF_TDM_RXTXEN_RX

Enable reception, disable transmission.

enumerator NRF_TDM_RXTXEN_TX

Enable transmission, disable reception.

enum nrf_tdm_mck_div_t

TDM master clock divider settings.

Values:

enumerator NRF_TDM_MCK_DIV_2

MCK divided by 2.

enumerator NRF_TDM_MCK_DIV_3

MCK divided by 3.

enumerator NRF_TDM_MCK_DIV_4

MCK divided by 4.

enumerator NRF_TDM_MCK_DIV_5

MCK divided by 5.

enumerator NRF_TDM_MCK_DIV_6

MCK divided by 6.

enumerator NRF_TDM_MCK_DIV_8

MCK divided by 8.

enumerator NRF_TDM_MCK_DIV_10

MCK divided by 10.

enumerator NRF_TDM_MCK_DIV_11

MCK divided by 11.

enumerator NRF_TDM_MCK_DIV_15

MCK divided by 15.

enumerator NRF_TDM_MCK_DIV_16

MCK divided by 16.

enumerator NRF_TDM_MCK_DIV_21

MCK divided by 21.

enumerator NRF_TDM_MCK_DIV_23

MCK divided by 23.

enumerator NRF_TDM_MCK_DIV_30

MCK divided by 30.

enumerator NRF_TDM_MCK_DIV_31

MCK divided by 31.

enumerator NRF_TDM_MCK_DIV_32

MCK divided by 32.

enumerator NRF_TDM_MCK_DIV_42

MCK divided by 42.

enumerator NRF_TDM_MCK_DIV_63

MCK divided by 63.

enumerator NRF_TDM_MCK_DIV_125

MCK divided by 125.

enum nrf_tdm_sck_div_t

TDM serial clock divider settings.

Values:

enumerator NRF_TDM_SCK_DIV_2

SCK divided by 2.

enumerator NRF_TDM_SCK_DIV_3

SCK divided by 3.

enumerator NRF_TDM_SCK_DIV_4

SCK divided by 4.

enumerator NRF_TDM_SCK_DIV_5

SCK divided by 5.

enumerator NRF_TDM_SCK_DIV_6

SCK divided by 6.

enumerator NRF_TDM_SCK_DIV_8

SCK divided by 8.

enumerator NRF_TDM_SCK_DIV_10

SCK divided by 10.

enumerator NRF_TDM_SCK_DIV_11

SCK divided by 11.

enumerator NRF_TDM_SCK_DIV_15

SCK divided by 15.

enumerator NRF_TDM_SCK_DIV_16

SCK divided by 16.

enumerator NRF_TDM_SCK_DIV_21

SCK divided by 21.

enumerator NRF_TDM_SCK_DIV_23

SCK divided by 23.

enumerator NRF_TDM_SCK_DIV_30

SCK divided by 30.

enumerator NRF_TDM_SCK_DIV_31

SCK divided by 31.

enumerator NRF_TDM_SCK_DIV_32

SCK divided by 32.

enumerator NRF_TDM_SCK_DIV_42

SCK divided by 42.

enumerator NRF_TDM_SCK_DIV_63

SCK divided by 63.

enumerator NRF_TDM_SCK_DIV_125

SCK divided by 125.

enum nrf_tdm_src_t

TDM clock source selection.

Values:

enumerator NRF_TDM_SRC_PCLK32M

32MHz peripheral clock.

enumerator NRF_TDM_SRC_ACLK

Audio PLL clock.

enum nrf_tdm_swidth_t

TDM sample widths.

Values:

enumerator NRF_TDM_SWIDTH_8BIT

8 bit.

enumerator NRF_TDM_SWIDTH_16BIT

16 bit.

enumerator NRF_TDM_SWIDTH_24BIT

24 bit.

enumerator NRF_TDM_SWIDTH_32BIT

32 bit.

enumerator NRF_TDM_SWIDTH_8BIT_IN16BIT

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

enumerator NRF_TDM_SWIDTH_8BIT_IN32BIT

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

enumerator NRF_TDM_SWIDTH_16BIT_IN32BIT

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

enumerator NRF_TDM_SWIDTH_24BIT_IN32BIT

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

enum nrf_tdm_align_t

TDM alignments of sample within a frame.

Values:

enumerator NRF_TDM_ALIGN_LEFT

Left-aligned.

enumerator NRF_TDM_ALIGN_RIGHT

Right-aligned.

enum nrf_tdm_channel_mask_t

TDM channel mask.

Values:

enumerator NRF_TDM_CHANNEL_RX0_MASK

Enable RX channel 0 data.

enumerator NRF_TDM_CHANNEL_RX1_MASK

Enable RX channel 1 data.

enumerator NRF_TDM_CHANNEL_RX2_MASK

Enable RX channel 2 data.

enumerator NRF_TDM_CHANNEL_RX3_MASK

Enable RX channel 3 data.

enumerator NRF_TDM_CHANNEL_RX4_MASK

Enable RX channel 4 data.

enumerator NRF_TDM_CHANNEL_RX5_MASK

Enable RX channel 5 data.

enumerator NRF_TDM_CHANNEL_RX6_MASK

Enable RX channel 6 data.

enumerator NRF_TDM_CHANNEL_RX7_MASK

Enable RX channel 7 data.

enumerator NRF_TDM_CHANNEL_TX0_MASK

Enable TX channel 0 data.

enumerator NRF_TDM_CHANNEL_TX1_MASK

Enable TX channel 1 data.

enumerator NRF_TDM_CHANNEL_TX2_MASK

Enable TX channel 2 data.

enumerator NRF_TDM_CHANNEL_TX3_MASK

Enable TX channel 3 data.

enumerator NRF_TDM_CHANNEL_TX4_MASK

Enable TX channel 4 data.

enumerator NRF_TDM_CHANNEL_TX5_MASK

Enable TX channel 5 data.

enumerator NRF_TDM_CHANNEL_TX6_MASK

Enable TX channel 6 data.

enumerator NRF_TDM_CHANNEL_TX7_MASK

Enable TX channel 7 data.

enum nrf_tdm_channels_count_t

TDM number of channels.

Values:

enumerator NRF_TDM_CHANNELS_COUNT_1

1 channel audio (mono).

enumerator NRF_TDM_CHANNELS_COUNT_2

2 channels audio (stereo).

enumerator NRF_TDM_CHANNELS_COUNT_3

3 channels audio.

enumerator NRF_TDM_CHANNELS_COUNT_4

4 channels audio.

enumerator NRF_TDM_CHANNELS_COUNT_5

5 channels audio.

enumerator NRF_TDM_CHANNELS_COUNT_6

6 channels audio.

enumerator NRF_TDM_CHANNELS_COUNT_7

7 channels audio.

enumerator NRF_TDM_CHANNELS_COUNT_8

8 channels audio.

enum nrf_tdm_channel_delay_t

TDM channel delay.

Values:

enumerator NRF_TDM_CHANNEL_DELAY_NONE

No delay. Use with DSP/Aligned format.

enumerator NRF_TDM_CHANNEL_DELAY_1CK

1 clock pulse delay. Used with original TDM format.

enumerator NRF_TDM_CHANNEL_DELAY_2CK

2 clock pulses delay.

enum nrf_tdm_polarity_t

TDM signal polarity.

Values:

enumerator NRF_TDM_POLARITY_POSEDGE

Synchronization at rising edge of the reference signal.

enumerator NRF_TDM_POLARITY_NEGEDGE

Synchronization at falling edge of the reference signal.

enum nrf_tdm_fsync_duration_t

TDM frame synchronization pulse duration.

Values:

enumerator NRF_TDM_FSYNC_DURATION_SCK

FSYNC is active for the duration of one SCK pulse.

enumerator NRF_TDM_FSYNC_DURATION_CHANNEL

FSYNC is active for the duration of channel transmission.

Functions

NRF_STATIC_INLINE void nrf_tdm_task_trigger(NRF_TDM_Type *p_reg, nrf_tdm_task_t task)

Function for activating the specified TDM 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_tdm_task_address_get(NRF_TDM_Type const *p_reg, nrf_tdm_task_t task)

Function for getting the address of the specified TDM 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_tdm_event_clear(NRF_TDM_Type *p_reg, nrf_tdm_event_t event)

Function for clearing the specified TDM event.

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

  • event[in] Event to clear.

NRF_STATIC_INLINE bool nrf_tdm_event_check(NRF_TDM_Type const *p_reg, nrf_tdm_event_t event)

Function for retrieving the state of the TDM 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_tdm_event_address_get(NRF_TDM_Type const *p_reg, nrf_tdm_event_t event)

Function for getting the address of the specified TDM 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_tdm_int_enable(NRF_TDM_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_tdm_int_mask_t values for bit masking.

NRF_STATIC_INLINE void nrf_tdm_int_disable(NRF_TDM_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_tdm_int_mask_t values for bit masking.

NRF_STATIC_INLINE uint32_t nrf_tdm_int_enable_check(NRF_TDM_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_tdm_int_mask_t values for bit masking.

Returns:

Mask of enabled interrupts.

NRF_STATIC_INLINE void nrf_tdm_enable(NRF_TDM_Type *p_reg)

Function for enabling the TDM peripheral.

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

NRF_STATIC_INLINE void nrf_tdm_disable(NRF_TDM_Type *p_reg)

Function for disabling the TDM peripheral.

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

NRF_STATIC_INLINE bool nrf_tdm_enable_check(NRF_TDM_Type *p_reg)

Function for checking if the TDM peripheral is enabled.

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

Return values:
  • true – The TDM is enabled.

  • false – The TDM is not enabled.

NRF_STATIC_INLINE void nrf_tdm_subscribe_set(NRF_TDM_Type *p_reg, nrf_tdm_task_t task, uint8_t channel)

Function for setting the subscribe configuration for a given TDM 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_tdm_subscribe_clear(NRF_TDM_Type *p_reg, nrf_tdm_task_t task)

Function for clearing the subscribe configuration for a given TDM 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_tdm_publish_set(NRF_TDM_Type *p_reg, nrf_tdm_event_t event, uint8_t channel)

Function for setting the publish configuration for a given TDM 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_tdm_publish_clear(NRF_TDM_Type *p_reg, nrf_tdm_event_t event)

Function for clearing the publish configuration for a given TDM 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_tdm_pins_set(NRF_TDM_Type *p_reg, nrf_tdm_pins_t const *p_pins)

Function for configuring TDM pins.

Usage of the SDOUT, SDIN, and MCK signals is optional. If a given signal is not needed, pass the NRF_TDM_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_tdm_sck_pin_get(NRF_TDM_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_tdm_fsync_pin_get(NRF_TDM_Type const *p_reg)

Function for getting the FSYNC pin selection.

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

Returns:

FSYNC pin selection.

NRF_STATIC_INLINE uint32_t nrf_tdm_mck_pin_get(NRF_TDM_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_tdm_sdout_pin_get(NRF_TDM_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_tdm_sdin_pin_get(NRF_TDM_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_tdm_configure(NRF_TDM_Type *p_reg, nrf_tdm_config_t const *p_config)

Function for setting the TDM 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_tdm_mck_set(NRF_TDM_Type *p_reg, bool enable)

Function for setting the master clock generator.

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

  • enable[in] True if the master clock generator is to be enabled, false otherwise.

NRF_STATIC_INLINE void nrf_tdm_rx_count_set(NRF_TDM_Type *p_reg, uint16_t size)

Function for setting up the TDM RX transfer length.

Note

This function sets up the RX buffer size. At least one of nrf_tdm_rx_count_set or nrf_tdm_tx_count_set functions must be called before starting the transmission. Also nrf_tdm_transfer_direction_set and nrf_tdm_rx_buffer_set should be called before starting the transmission.

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

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

NRF_STATIC_INLINE void nrf_tdm_tx_count_set(NRF_TDM_Type *p_reg, uint16_t size)

Function for setting up the TDM TX transfer length.

Note

This function sets up the RX buffer size. At least one of nrf_tdm_rx_count_set or nrf_tdm_tx_count_set functions must be called before starting the transmission. Also nrf_tdm_transfer_direction_set and nrf_tdm_tx_buffer_set should be called before starting the transmission.

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

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

NRF_STATIC_INLINE void nrf_tdm_transfer_direction_set(NRF_TDM_Type *p_reg, nrf_tdm_rxtxen_t dir)

Function for setting up the direction of the TDM transfer.

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

  • dir[in] Transmission direction.

NRF_STATIC_INLINE void nrf_tdm_rx_buffer_set(NRF_TDM_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_tdm_rx_count_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_tdm_rx_buffer_get(NRF_TDM_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_tdm_tx_buffer_set(NRF_TDM_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_tdm_tx_count_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_tdm_current_tx_transfer_amount_get(NRF_TDM_Type const *p_reg)

Function for getting the number of bytes transferred in the current transaction.

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

Returns:

Number of bytes transferred.

NRF_STATIC_INLINE uint32_t nrf_tdm_last_tx_transfer_amount_get(NRF_TDM_Type const *p_reg)

Function for getting the number of bytes transferred in the last transaction. The value has been updated after the END event.

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

Returns:

Number of bytes transferred.

NRF_STATIC_INLINE uint32_t nrf_tdm_current_rx_transfer_amount_get(NRF_TDM_Type const *p_reg)

Function for getting the number of bytes received in the current transaction.

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

Returns:

Number of bytes received.

NRF_STATIC_INLINE uint32_t nrf_tdm_last_rx_transfer_amount_get(NRF_TDM_Type const *p_reg)

Function for getting the number of bytes received in the last transaction. The value has been updated after the END event.

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

Returns:

Number of bytes received.

NRF_STATIC_INLINE uint32_t *nrf_tdm_tx_buffer_get(NRF_TDM_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_tdm_mck_configure(NRF_TDM_Type *p_reg, nrf_tdm_src_t clksrc, bool enable_bypass)

Function for configuring TDM master Clock.

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

  • clksrc[in] TDM master clock source selection.

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

NRF_STATIC_INLINE void nrf_tdm_sck_configure(NRF_TDM_Type *p_reg, nrf_tdm_src_t clksrc, bool enable_bypass)

Function for configuring TDM serial Clock.

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

  • clksrc[in] TDM serial clock source selection.

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

struct nrf_tdm_config_t
#include <nrf_tdm.h>

TDM configuration.

Public Members

nrf_tdm_mode_t mode

Mode of operation (master or slave).

nrf_tdm_align_t alignment

Alignment of sample within a frame.

nrf_tdm_swidth_t sample_width

Sample width.

nrf_tdm_channel_mask_t channels

Enabled channels.

nrf_tdm_channels_count_t num_of_channels

Nnumber of channels within a frame.

nrf_tdm_channel_delay_t channel_delay

Channel delay settings.

nrf_tdm_mck_div_t mck_setup

Master clock divider setup.

nrf_tdm_sck_div_t sck_setup

Serial clock divider setup.

nrf_tdm_polarity_t sck_polarity

Serial clock polarity.

nrf_tdm_polarity_t fsync_polarity

Frame Synchronization pulse polarity.

nrf_tdm_fsync_duration_t fsync_duration

Frame Synchronization pulse duration.

struct nrf_tdm_pins_t
#include <nrf_tdm.h>

TDM pins.

Public Members

uint32_t sck_pin

SCK pin number.

uint32_t fsync_pin

FSYNC pin number.

uint32_t mck_pin

MCK pin number.

Optional. Use NRF_TDM_PIN_NOT_CONNECTED if this signal is not needed.

uint32_t sdout_pin

SDOUT pin number.

Optional. Use NRF_TDM_PIN_NOT_CONNECTED if this signal is not needed.

uint32_t sdin_pin

SDIN pin number.

Optional. Use NRF_TDM_PIN_NOT_CONNECTED if this signal is not needed.