nrfx 4.5.0
Loading...
Searching...
No Matches
PDM driver

Pulse Density Modulation (PDM) peripheral driver. More...

Topics

 PDM peripheral driver configuration
 

Data Structures

struct  nrfx_pdm_evt_t
 PDM event structure. More...
 
struct  nrfx_pdm_prescalers_t
 PDM prescalers structure. More...
 
struct  nrfx_pdm_config_t
 PDM interface driver configuration structure. More...
 
struct  nrfx_pdm_output_t
 PDM output frequency and sampling rate values. More...
 
struct  nrfx_pdm_t
 Data structure of the Pulse Density Modulation (PDM) driver instance. More...
 

Macros

#define NRFX_PDM_MAX_BUFFER_SIZE   32767
 Maximum supported PDM buffer size.
 
#define NRFX_PDM_DEFAULT_CONFIG(_pin_clk, _pin_din)
 PDM driver default configuration.
 
#define NRFX_PDM_INSTANCE(reg)
 Macro for creating an instance of the PDM driver.
 

Typedefs

typedef void(* nrfx_pdm_event_handler_t) (nrfx_pdm_evt_t const *p_evt)
 Handler for the PDM interface ready events.
 

Enumerations

enum  nrfx_pdm_error_t {
  NRFX_PDM_NO_ERROR = 0 ,
  NRFX_PDM_ERROR_OVERFLOW = 1
}
 PDM error type. More...
 

Functions

int nrfx_pdm_init (nrfx_pdm_t *p_instance, nrfx_pdm_config_t const *p_config, nrfx_pdm_event_handler_t event_handler)
 Function for initializing the PDM driver instance.
 
int nrfx_pdm_reconfigure (nrfx_pdm_t *p_instance, nrfx_pdm_config_t const *p_config)
 Function for reconfiguring the PDM driver instance.
 
void nrfx_pdm_uninit (nrfx_pdm_t *p_instance)
 Function for uninitializing the PDM driver instance.
 
bool nrfx_pdm_init_check (nrfx_pdm_t const *p_instance)
 Function for checking if the PDM driver instance is initialized.
 
NRFX_STATIC_INLINE uint32_t nrfx_pdm_task_address_get (nrfx_pdm_t const *p_instance, nrf_pdm_task_t task)
 Function for getting the address of a PDM driver instance task.
 
NRFX_STATIC_INLINE bool nrfx_pdm_enable_check (nrfx_pdm_t const *p_instance)
 Function for getting the state of the PDM drivers instance.
 
int nrfx_pdm_start (nrfx_pdm_t *p_instance)
 Function for starting the PDM sampling.
 
int nrfx_pdm_stop (nrfx_pdm_t *p_instance)
 Function for stopping the PDM sampling.
 
int nrfx_pdm_buffer_set (nrfx_pdm_t *p_instance, int16_t *buffer, uint16_t buffer_length)
 Function for supplying the sample buffer.
 
int nrfx_pdm_prescalers_calc (nrfx_pdm_output_t const *output_config, nrfx_pdm_prescalers_t *prescalers)
 Function for calculating PDM clock prescaler values.
 
void nrfx_pdm_irq_handler (nrfx_pdm_t *p_instance)
 Driver interrupt handler.
 

Detailed Description

Pulse Density Modulation (PDM) peripheral driver.

Macro Definition Documentation

◆ NRFX_PDM_DEFAULT_CONFIG

#define NRFX_PDM_DEFAULT_CONFIG ( _pin_clk,
_pin_din )
Value:
{ \
.mode = NRF_PDM_MODE_MONO, \
.clk_pin = _pin_clk, \
.din_pin = _pin_din, \
.gain_l = NRF_PDM_GAIN_DEFAULT, \
.gain_r = NRF_PDM_GAIN_DEFAULT, \
.interrupt_priority = NRFX_PDM_DEFAULT_CONFIG_IRQ_PRIORITY, \
.prescalers = \
{ \
NRFX_COND_CODE_1(NRF_PDM_HAS_PDMCLKCTRL, \
(.clock_freq = NRF_PDM_FREQ_1032K,), ()) \
NRFX_COND_CODE_1(NRF_PDM_HAS_PRESCALER, \
(.prescaler = 4,), ()) \
NRFX_COND_CODE_1(NRF_PDM_HAS_RATIO_CONFIG, \
(.ratio = NRF_PDM_RATIO_64X,), ()) \
NRFX_COND_CODE_1(NRF_PDM_HAS_CUSTOM_RATIO, \
(.custom_ratio = { \
.ratio = 64, \
.compensation_gain = 0, \
.minor_compensation_gain = false, \
}), ()) \
}, \
NRFX_COND_CODE_1(NRF_PDM_HAS_SELECTABLE_CLOCK, \
(.mclksrc = NRF_PDM_MCLKSRC_PCLK32M,), ()) \
}
#define NRF_PDM_HAS_SELECTABLE_CLOCK
Symbol indicating whether PDM has selectable clock source.
Definition nrf_pdm.h:198
#define NRF_PDM_HAS_PDMCLKCTRL
Symbol indicating whether PDM clock control register is available.
Definition nrf_pdm.h:86
#define NRF_PDM_HAS_PRESCALER
Symbol indicating whether PDM prescaler register is available.
Definition nrf_pdm.h:114
#define NRF_PDM_HAS_CUSTOM_RATIO
Symbol indicating whether PDM custom ratio configuration is available.
Definition nrf_pdm.h:191
#define NRF_PDM_HAS_RATIO_CONFIG
Symbol indicating whether ratio configuration is available.
Definition nrf_pdm.h:71
#define NRF_PDM_GAIN_DEFAULT
Default value of PDM gain.
Definition nrf_pdm.h:206
@ NRF_PDM_MCLKSRC_PCLK32M
32MHz peripheral clock.
Definition nrf_pdm.h:330
@ NRF_PDM_FREQ_1032K
PDM_CLK = 1.032 MHz.
Definition nrf_pdm.h:261
@ NRF_PDM_RATIO_64X
Ratio of 64.
Definition nrf_pdm.h:288
@ NRF_PDM_FILTER_CIC_MSB_RANGE_5
OSR range low - 56 bits, OSR range high - 64 bits.
Definition nrf_pdm.h:357
@ NRF_PDM_EDGE_LEFTFALLING
Left (or mono) is sampled on falling edge of PDM_CLK.
Definition nrf_pdm.h:321
@ NRF_PDM_MODE_MONO
Sample and store two successive Left samples (16 bit each) per RAM word.
Definition nrf_pdm.h:315

PDM driver default configuration.

This configuration sets up PDM with the following options:

  • mono mode
  • data sampled on the clock falling edge
  • frequency: 1.032 MHz
  • standard gain
Parameters
[in]_pin_clkCLK output pin.
[in]_pin_dinDIN input pin.

◆ NRFX_PDM_INSTANCE

#define NRFX_PDM_INSTANCE ( reg)
Value:
{ \
.p_reg = (NRF_PDM_Type *)reg, \
.cb = {0} \
}

Macro for creating an instance of the PDM driver.

Typedef Documentation

◆ nrfx_pdm_event_handler_t

typedef void(* nrfx_pdm_event_handler_t) (nrfx_pdm_evt_t const *p_evt)

Handler for the PDM interface ready events.

This event handler is called on a buffer request, an error or when a buffer is full and ready to be processed.

Parameters
[in]p_evtPointer to the PDM event structure.

Enumeration Type Documentation

◆ nrfx_pdm_error_t

PDM error type.

Enumerator
NRFX_PDM_NO_ERROR 

No error.

NRFX_PDM_ERROR_OVERFLOW 

Overflow error.

Function Documentation

◆ nrfx_pdm_buffer_set()

int nrfx_pdm_buffer_set ( nrfx_pdm_t * p_instance,
int16_t * buffer,
uint16_t buffer_length )

Function for supplying the sample buffer.

Call this function after every buffer request event.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]bufferPointer to the receive buffer. Cannot be NULL.
[in]buffer_lengthLength of the receive buffer in 16-bit words.
Return values
0The buffer was applied successfully.
-EBUSYThe buffer was already supplied or the peripheral is currently being stopped.
-EINPROGRESSThe driver was not initialized.
-EINVALInvalid parameters were provided.

◆ nrfx_pdm_enable_check()

NRFX_STATIC_INLINE bool nrfx_pdm_enable_check ( nrfx_pdm_t const * p_instance)

Function for getting the state of the PDM drivers instance.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueThe PDM interface is enabled.
falseThe PDM interface is disabled.

◆ nrfx_pdm_init()

int nrfx_pdm_init ( nrfx_pdm_t * p_instance,
nrfx_pdm_config_t const * p_config,
nrfx_pdm_event_handler_t event_handler )

Function for initializing the PDM driver instance.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_configPointer to the structure with the initial configuration.
[in]event_handlerEvent handler provided by the user. Cannot be NULL.
Return values
0Initialization was successful.
-EALREADYThe driver is already initialized.
-EINVALInvalid configuration was specified.

◆ nrfx_pdm_init_check()

bool nrfx_pdm_init_check ( nrfx_pdm_t const * p_instance)

Function for checking if the PDM driver instance is initialized.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueInterface is already initialized.
falseInterface is not initialized.

◆ nrfx_pdm_irq_handler()

void nrfx_pdm_irq_handler ( nrfx_pdm_t * p_instance)

Driver interrupt handler.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_pdm_prescalers_calc()

int nrfx_pdm_prescalers_calc ( nrfx_pdm_output_t const * output_config,
nrfx_pdm_prescalers_t * prescalers )

Function for calculating PDM clock prescaler values.

Call this function to find suitable value for prescalers in nrfx_pdm_config_t structure.

Note
This function does not provide custom ratio configuration, even if the device supports it. Custom ratio configuration has to be provided the by the user.
Parameters
[in]output_configExpected output frequencies.
[out]prescalersPrescaler structure pointer to be filled with prescaler values.
Return values
0Suitable prescaler values were found.
-EINVALNo suitable prescaler values were found.

◆ nrfx_pdm_reconfigure()

int nrfx_pdm_reconfigure ( nrfx_pdm_t * p_instance,
nrfx_pdm_config_t const * p_config )

Function for reconfiguring the PDM driver instance.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_configPointer to the structure with the configuration.
Return values
0Reconfiguration was successful.
-EBUSYThere is ongoing sampling and driver cannot be reconfigured.
-EINPROGRESSThe driver is not initialized.
-EINVALInvalid configuration was specified.

◆ nrfx_pdm_start()

int nrfx_pdm_start ( nrfx_pdm_t * p_instance)

Function for starting the PDM sampling.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
0Sampling was started successfully or was already in progress.
-EBUSYPrevious start/stop operation is in progress.

◆ nrfx_pdm_stop()

int nrfx_pdm_stop ( nrfx_pdm_t * p_instance)

Function for stopping the PDM sampling.

When this function is called, the PDM driver instance is stopped after finishing the current frame. The event handler function might be called once more after calling this function.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
0Sampling was stopped successfully or was already stopped before.
-EBUSYPrevious start/stop operation is in progress.

◆ nrfx_pdm_task_address_get()

NRFX_STATIC_INLINE uint32_t nrfx_pdm_task_address_get ( nrfx_pdm_t const * p_instance,
nrf_pdm_task_t task )

Function for getting the address of a PDM driver instance task.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]taskTask.
Returns
Task address.

◆ nrfx_pdm_uninit()

void nrfx_pdm_uninit ( nrfx_pdm_t * p_instance)

Function for uninitializing the PDM driver instance.

Parameters
[in]p_instancePointer to the driver instance structure.

This function stops PDM sampling, if it is in progress.