PDM HAL

group nrf_pdm_hal

Hardware access layer for managing the Pulse Density Modulation (PDM) peripheral.

Defines

NRF_PDM_HAS_MCLKCONFIG

Symbol indicating whether master clock source configuration is available.

NRF_PDM_HAS_RATIO_CONFIG

Symbol indicating whether ratio configuration is available.

NRF_PDM_HAS_DMA_REG

Symbol indicating whether dedicated DMA register is present.

NRF_PDM_HAS_DMA_TASKS_EVENTS

Symbol indicating whether PDM DMA tasks and events are present.

NRF_PDM_GAIN_MINIMUM

Minimum value of PDM gain.

NRF_PDM_GAIN_DEFAULT

Default value of PDM gain.

NRF_PDM_GAIN_MAXIMUM

Maximum value of PDM gain.

Typedefs

typedef uint8_t nrf_pdm_gain_t

PDM gain type.

Enums

enum nrf_pdm_task_t

PDM tasks.

Values:

enumerator NRF_PDM_TASK_START

Starts continuous PDM transfer.

enumerator NRF_PDM_TASK_STOP

Stops PDM transfer.

enum nrf_pdm_event_t

PDM events.

Values:

enumerator NRF_PDM_EVENT_STARTED

PDM transfer is started.

enumerator NRF_PDM_EVENT_STOPPED

PDM transfer is finished.

enumerator NRF_PDM_EVENT_END

The PDM has written the last sample specified by MAXCNT (or the last sample after a STOP task has been received) to Data RAM.

enum nrf_pdm_int_mask_t

PDM interrupt masks.

Values:

enumerator NRF_PDM_INT_STARTED

Interrupt on EVENTS_STARTED event.

enumerator NRF_PDM_INT_STOPPED

Interrupt on EVENTS_STOPPED event.

enumerator NRF_PDM_INT_END

Interrupt on EVENTS_END event.

enum nrf_pdm_freq_t

PDM clock frequency.

Values:

enumerator NRF_PDM_FREQ_1000K

PDM_CLK = 1.000 MHz.

enumerator NRF_PDM_FREQ_1032K

PDM_CLK = 1.032 MHz.

enumerator NRF_PDM_FREQ_1067K

PDM_CLK = 1.067 MHz.

enumerator NRF_PDM_FREQ_1231K

PDM_CLK = 1.231 MHz.

enumerator NRF_PDM_FREQ_1280K

PDM_CLK = 1.280 MHz.

enumerator NRF_PDM_FREQ_1333K

PDM_CLK = 1.333 MHz.

enum nrf_pdm_ratio_t

PDM ratio between PDM_CLK and output sample rate.

Values:

enumerator NRF_PDM_RATIO_64X

Ratio of 64.

enumerator NRF_PDM_RATIO_80X

Ratio of 80.

enum nrf_pdm_mode_t

PDM operation mode.

Values:

enumerator NRF_PDM_MODE_STEREO

Sample and store one pair (Left + Right) of 16-bit samples per RAM word.

enumerator NRF_PDM_MODE_MONO

Sample and store two successive Left samples (16 bit each) per RAM word.

enum nrf_pdm_edge_t

PDM sampling mode.

Values:

enumerator NRF_PDM_EDGE_LEFTFALLING

Left (or mono) is sampled on falling edge of PDM_CLK.

enumerator NRF_PDM_EDGE_LEFTRISING

Left (or mono) is sampled on rising edge of PDM_CLK.

enum nrf_pdm_mclksrc_t

PDM master clock source selection.

Values:

enumerator NRF_PDM_MCLKSRC_PCLK32M

32MHz peripheral clock.

enumerator NRF_PDM_MCLKSRC_ACLK

Audio PLL clock.

Functions

NRF_STATIC_INLINE void nrf_pdm_task_trigger(NRF_PDM_Type *p_reg, nrf_pdm_task_t task)

Function for triggering a PDM task.

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

  • task[in] PDM task.

NRF_STATIC_INLINE uint32_t nrf_pdm_task_address_get(NRF_PDM_Type const *p_reg, nrf_pdm_task_t task)

Function for getting the address of a PDM task register.

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

  • task[in] PDM task.

Returns:

Address of the specified PDM task.

NRF_STATIC_INLINE bool nrf_pdm_event_check(NRF_PDM_Type const *p_reg, nrf_pdm_event_t event)

Function for retrieving the state of the PDM 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 void nrf_pdm_event_clear(NRF_PDM_Type *p_reg, nrf_pdm_event_t event)

Function for clearing a PDM event.

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

  • event[in] PDM event.

NRF_STATIC_INLINE uint32_t nrf_pdm_event_address_get(NRF_PDM_Type const *p_reg, nrf_pdm_event_t event)

Function for getting the address of a PDM event register.

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

  • event[in] PDM event.

Returns:

Address of the specified PDM event.

NRF_STATIC_INLINE void nrf_pdm_int_enable(NRF_PDM_Type *p_reg, uint32_t mask)

Function for enabling PDM interrupts.

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

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

NRF_STATIC_INLINE uint32_t nrf_pdm_int_enable_check(NRF_PDM_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_pdm_int_mask_t values for bit masking.

Returns:

Mask of enabled interrupts.

NRF_STATIC_INLINE void nrf_pdm_int_disable(NRF_PDM_Type *p_reg, uint32_t mask)

Function for disabling interrupts.

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

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

NRF_STATIC_INLINE void nrf_pdm_subscribe_set(NRF_PDM_Type *p_reg, nrf_pdm_task_t task, uint8_t channel)

Function for setting the subscribe configuration for a given PDM 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_pdm_subscribe_clear(NRF_PDM_Type *p_reg, nrf_pdm_task_t task)

Function for clearing the subscribe configuration for a given PDM 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_pdm_publish_set(NRF_PDM_Type *p_reg, nrf_pdm_event_t event, uint8_t channel)

Function for setting the publish configuration for a given PDM 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_pdm_publish_clear(NRF_PDM_Type *p_reg, nrf_pdm_event_t event)

Function for clearing the publish configuration for a given PDM 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_pdm_enable(NRF_PDM_Type *p_reg)

Function for enabling the PDM peripheral.

The PDM peripheral must be enabled before use.

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

NRF_STATIC_INLINE void nrf_pdm_disable(NRF_PDM_Type *p_reg)

Function for disabling the PDM peripheral.

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

NRF_STATIC_INLINE bool nrf_pdm_enable_check(NRF_PDM_Type const *p_reg)

Function for checking if the PDM peripheral is enabled.

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

Return values:
  • true – The PDM peripheral is enabled.

  • false – The PDM peripheral is not enabled.

NRF_STATIC_INLINE void nrf_pdm_mode_set(NRF_PDM_Type *p_reg, nrf_pdm_mode_t pdm_mode, nrf_pdm_edge_t pdm_edge)

Function for setting the PDM operation mode.

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

  • pdm_mode[in] PDM operation mode.

  • pdm_edge[in] PDM sampling mode.

NRF_STATIC_INLINE void nrf_pdm_mode_get(NRF_PDM_Type const *p_reg, nrf_pdm_mode_t *p_pdm_mode, nrf_pdm_edge_t *p_pdm_edge)

Function for getting the PDM operation mode.

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

  • p_pdm_mode[out] PDM operation mode.

  • p_pdm_edge[out] PDM sampling mode.

NRF_STATIC_INLINE void nrf_pdm_clock_set(NRF_PDM_Type *p_reg, nrf_pdm_freq_t pdm_freq)

Function for setting the PDM clock frequency.

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

  • pdm_freq[in] PDM clock frequency.

NRF_STATIC_INLINE nrf_pdm_freq_t nrf_pdm_clock_get(NRF_PDM_Type const *p_reg)

Function for getting the PDM clock frequency.

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

Returns:

PDM clock frequency.

NRF_STATIC_INLINE void nrf_pdm_psel_connect(NRF_PDM_Type *p_reg, uint32_t psel_clk, uint32_t psel_din)

Function for setting up the PDM pins.

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

  • psel_clk[in] CLK pin number.

  • psel_din[in] DIN pin number.

NRF_STATIC_INLINE uint32_t nrf_pdm_clk_pin_get(NRF_PDM_Type const *p_reg)

Function for getting the CLK pin selection.

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

Returns:

CLK pin selection;

NRF_STATIC_INLINE uint32_t nrf_pdm_din_pin_get(NRF_PDM_Type const *p_reg)

Function for getting the DIN pin selection.

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

Returns:

DIN pin selection;

NRF_STATIC_INLINE void nrf_pdm_psel_disconnect(NRF_PDM_Type *p_reg)

Function for disconnecting the PDM pins.

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

NRF_STATIC_INLINE void nrf_pdm_gain_set(NRF_PDM_Type *p_reg, nrf_pdm_gain_t gain_l, nrf_pdm_gain_t gain_r)

Function for setting the PDM gain.

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

  • gain_l[in] Left channel gain.

  • gain_r[in] Right channel gain.

NRF_STATIC_INLINE void nrf_pdm_gain_get(NRF_PDM_Type const *p_reg, nrf_pdm_gain_t *p_gain_l, nrf_pdm_gain_t *p_gain_r)

Function for getting the PDM gain.

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

  • p_gain_l[out] Left channel gain.

  • p_gain_r[out] Right channel gain.

NRF_STATIC_INLINE void nrf_pdm_buffer_set(NRF_PDM_Type *p_reg, uint32_t *p_buffer, uint32_t num)

Function for setting the PDM sample buffer.

The amount of allocated RAM depends on the operation mode.

  • For stereo mode: N 32-bit words.

  • For mono mode: Ceil(N/2) 32-bit words.

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

  • p_buffer[in] Pointer to the RAM address where samples are to be written with EasyDMA.

  • num[in] Number of samples to allocate memory for in EasyDMA mode.

NRF_STATIC_INLINE uint32_t *nrf_pdm_buffer_get(NRF_PDM_Type const *p_reg)

Function for getting the current PDM sample buffer address.

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

Returns:

Pointer to the current sample buffer.

NRF_STATIC_INLINE void nrf_pdm_ratio_set(NRF_PDM_Type *p_reg, nrf_pdm_ratio_t ratio)

Function for setting ratio between PDM_CLK and output sample rate.

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

  • ratio[in] Ratio between PDM_CLK and output sample rate.

NRF_STATIC_INLINE void nrf_pdm_mclksrc_configure(NRF_PDM_Type *p_reg, nrf_pdm_mclksrc_t mclksrc)

Function for configuring PDM master clock source.

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

  • mclksrc[in] Master Clock source selection.