Loading...
Searching...
No Matches
Pulse Density Modulation (PDM)

Low-level Pulse Density Modulation (PDM) driver. More...

Detailed Description

Low-level Pulse Density Modulation (PDM) driver.

Files

file  pdm.h
 

Data Structures

struct  pdm_isr_ctx_t
 Interrupt context for a PDM device. More...
 

Macros

#define PDM_GAIN_MIN   (-20)
 Minimum PDM gain (in dB)
 
#define PDM_GAIN_MAX   (20)
 Maximum PDM gain (in dB)
 
#define PDM_BUF_SIZE   (64U)
 Default PDM sample buffer size.
 

Typedefs

typedef void(* pdm_data_cb_t) (void *arg, int16_t *buf)
 Signature for data received interrupt callback.
 

Functions

int32_t pdm_init (pdm_mode_t mode, uint32_t rate, int8_t gain, pdm_data_cb_t cb, void *arg)
 Initialize and enable the PDM peripheral.
 
void pdm_start (void)
 Start the PDM peripheral.
 
void pdm_stop (void)
 Stop the PDM peripheral.
 
void pdm_deinit (void)
 Disable the PDM peripheral.
 
enum  pdm_mode_t { PDM_MODE_MONO = 0 , PDM_MODE_STEREO }
 PDM operation modes. More...
 

Macro Definition Documentation

◆ PDM_BUF_SIZE

#define PDM_BUF_SIZE   (64U)

Default PDM sample buffer size.

Definition at line 60 of file pdm.h.

◆ PDM_GAIN_MAX

#define PDM_GAIN_MAX   (20)

Maximum PDM gain (in dB)

Definition at line 53 of file pdm.h.

◆ PDM_GAIN_MIN

#define PDM_GAIN_MIN   (-20)

Minimum PDM gain (in dB)

Definition at line 46 of file pdm.h.

Typedef Documentation

◆ pdm_data_cb_t

typedef void(* pdm_data_cb_t) (void *arg, int16_t *buf)

Signature for data received interrupt callback.

Parameters
[in]argcontext passed to the callback (optional)
[in]bufthe buffer containing the current sample frame

Definition at line 69 of file pdm.h.

Enumeration Type Documentation

◆ pdm_mode_t

enum pdm_mode_t

PDM operation modes.

Enumerator
PDM_MODE_MONO 

Mono mode.

PDM_MODE_STEREO 

Stereo mode.

Definition at line 35 of file pdm.h.

Function Documentation

◆ pdm_init()

int32_t pdm_init ( pdm_mode_t mode,
uint32_t rate,
int8_t gain,
pdm_data_cb_t cb,
void * arg )

Initialize and enable the PDM peripheral.

The requested rate is approximated to the closest rate the hardware can produce. The actually configured rate is returned so the caller can use it for further processing.

Parameters
[in]modemode (Mono or Stereo)
[in]ratesample rate in Hz
[in]gaingain in dB [PDM_GAIN_MIN...PDM_GAIN_MAX]
[in]cbdata received callback function
[in]argcontext passed to the callback function
Return values
>0actual configured PDM sample rate in Hz on success
-ENOTSUPmode is not supported

◆ pdm_start()

void pdm_start ( void )

Start the PDM peripheral.

Note
After calling this function, transients in the audio signal can occur while the PDM peripheral and the microphone start up. Depending on the hardware and configuration used, this start-up phase can last up to a few hundred ms. If the application needs clean audio from the start, it must discard the samples from this start-up phase itself, for example by ignoring the first buffers passed to the data received callback.