PDMEMLIB
Detailed Description
Pulse Density Modulation (PDM) peripheral API.
PDM API functions provide full support for the PDM peripheral. The PDM peripheral accept PDM bitstreams and produce PCM encoded output.
Example PDM usage when interfacing to two PDM microphones:
Configure clocks and GPIO pins:
Initialize and start PDM, then read PCM samples from FIFO:
Data Structures |
|
struct | PDM_Init_TypeDef |
Macros |
|
#define | PDM_INIT_DEFAULT |
Enumerations |
|
enum |
PDM_Ch0ClkPolarity_Typedef
{
pdmCh0ClkPolarityRisingEdge = _PDM_CFG0_CH0CLKPOL_NORMAL, pdmCh0ClkPolarityFallingEdge = _PDM_CFG0_CH0CLKPOL_INVERT } |
enum |
PDM_Ch1ClkPolarity_Typedef
{
pdmCh1ClkPolarityRisingEdge = _PDM_CFG0_CH1CLKPOL_NORMAL, pdmCh1ClkPolarityFallingEdge = _PDM_CFG0_CH1CLKPOL_INVERT } |
enum |
PDM_Ch2ClkPolarity_Typedef
{
pdmCh2ClkPolarityRisingEdge = _PDM_CFG0_CH2CLKPOL_NORMAL, pdmCh2ClkPolarityFallingEdge = _PDM_CFG0_CH2CLKPOL_INVERT } |
enum |
PDM_Ch3ClkPolarity_Typedef
{
pdmCh3ClkPolarityRisingEdge = _PDM_CFG0_CH3CLKPOL_NORMAL, pdmCh3ClkPolarityFallingEdge = _PDM_CFG0_CH3CLKPOL_INVERT } |
enum |
PDM_DataFormat_TypeDef
{
pdmDataFormatRight16 = _PDM_CFG0_DATAFORMAT_RIGHT16, pdmDataFormatDouble16 = _PDM_CFG0_DATAFORMAT_DOUBLE16, pdmDataFormatRight24 = _PDM_CFG0_DATAFORMAT_RIGHT24, pdmDataFormatFull32bit = _PDM_CFG0_DATAFORMAT_FULL32BIT, pdmDataFormatLeft16 = _PDM_CFG0_DATAFORMAT_LEFT16, pdmDataFormatLeft24 = _PDM_CFG0_DATAFORMAT_LEFT24, pdmDataFormatRaw32bit = _PDM_CFG0_DATAFORMAT_RAW32BIT } |
enum |
PDM_FifoValidWatermark_Typedef
{
pdmFifoValidWatermarkOne = _PDM_CFG0_FIFODVL_ONE, pdmFifoValidWatermarkTwo = _PDM_CFG0_FIFODVL_TWO, pdmFifoValidWatermarkThree = _PDM_CFG0_FIFODVL_THREE, pdmFifoValidWatermarkFour = _PDM_CFG0_FIFODVL_FOUR } |
enum |
PDM_FilterOrder_TypeDef
{
pdmFilterOrderSecond = _PDM_CFG0_FORDER_SECOND, pdmFilterOrderThird = _PDM_CFG0_FORDER_THIRD, pdmFilterOrderFourth = _PDM_CFG0_FORDER_FOURTH, pdmFilterOrderFifth = _PDM_CFG0_FORDER_FIFTH } |
enum |
PDM_NumberOfChannels_TypeDef
{
pdmNumberOfChannelsOne = _PDM_CFG0_NUMCH_ONE, pdmNumberOfChannelsTwo = _PDM_CFG0_NUMCH_TWO, pdmNumberOfChannelsThree = _PDM_CFG0_NUMCH_THREE, pdmNumberOfChannelsFour = _PDM_CFG0_NUMCH_FOUR } |
Functions |
|
__STATIC_INLINE void | PDM_Clear ( PDM_TypeDef *pdm) |
Clear PDM filter.
|
|
void | PDM_DeInit ( PDM_TypeDef *pdm) |
De-initialize the PDM peripheral.
|
|
__STATIC_INLINE void | PDM_FifoFlush ( PDM_TypeDef *pdm) |
Flush the PDM sample FIFO.
|
|
void | PDM_Init ( PDM_TypeDef *pdm, const PDM_Init_TypeDef *init) |
Initialize the PDM peripheral.
|
|
__STATIC_INLINE void | PDM_IntClear ( PDM_TypeDef *pdm, uint32_t flags) |
Clear one or more pending PDM interrupts.
|
|
__STATIC_INLINE void | PDM_IntDisable ( PDM_TypeDef *pdm, uint32_t flags) |
Disable one or more PDM interrupts.
|
|
__STATIC_INLINE void | PDM_IntEnable ( PDM_TypeDef *pdm, uint32_t flags) |
Enable one or more PDM interrupts.
|
|
__STATIC_INLINE uint32_t | PDM_IntGet ( PDM_TypeDef *pdm) |
Get pending PDM interrupt flags.
|
|
__STATIC_INLINE uint32_t | PDM_IntGetEnabled ( PDM_TypeDef *pdm) |
Get enabled and pending PDM interrupt flags. Useful for handling more interrupt sources in the same interrupt handler.
|
|
__STATIC_INLINE void | PDM_IntSet ( PDM_TypeDef *pdm, uint32_t flags) |
Set one or more pending PDM interrupts.
|
|
void | PDM_Reset ( PDM_TypeDef *pdm) |
Initialize PDM registers with reset values.
|
|
__STATIC_INLINE uint32_t | PDM_Rx ( PDM_TypeDef *pdm) |
Read one entry from the PDM FIFO.
|
|
__STATIC_INLINE void | PDM_Start ( PDM_TypeDef *pdm) |
Start PDM operation (start the PDM filter).
|
|
__STATIC_INLINE uint32_t | PDM_StatusGet ( PDM_TypeDef *pdm) |
Get PDM STATUS register.
|
|
__STATIC_INLINE void | PDM_Stop ( PDM_TypeDef *pdm) |
Stop PDM operation (stop the PDM filter).
|
|
Macro Definition Documentation
#define PDM_INIT_DEFAULT |
Default configuration for PDM. Stereo Ch0/1, 16bit samples, 44,100 Hz sampling rate, 32 times oversampling (requires 1,411,209 Hz PDM clock).
Definition at line
202
of file
em_pdm.h
.
Enumeration Type Documentation
Configure PDM filter data output format.
Definition at line
145
of file
em_pdm.h
.
Function Documentation
__STATIC_INLINE void PDM_Clear | ( | PDM_TypeDef * |
pdm
|
) |
Clear PDM filter.
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block.
Definition at line
236
of file
em_pdm.h
.
References PDM_TypeDef::CMD , PDM_CMD_CLEAR , and PDM_TypeDef::SYNCBUSY .
Referenced by PDM_DeInit() , and PDM_Init() .
void PDM_DeInit | ( | PDM_TypeDef * |
pdm
|
) |
De-initialize the PDM peripheral.
This function will stop the PDM filter and set PDM control registers to their reset values.
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block.
Definition at line
58
of file
em_pdm.c
.
References PDM_Clear() , PDM_FifoFlush() , PDM_Reset() , and PDM_Stop() .
__STATIC_INLINE void PDM_FifoFlush | ( | PDM_TypeDef * |
pdm
|
) |
Flush the PDM sample FIFO.
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block.
Definition at line
251
of file
em_pdm.h
.
References PDM_TypeDef::CMD , PDM_CMD_FIFOFL , and PDM_TypeDef::SYNCBUSY .
Referenced by PDM_DeInit() , and PDM_Init() .
void PDM_Init | ( | PDM_TypeDef * |
pdm,
|
const PDM_Init_TypeDef * |
init
|
||
) |
Initialize the PDM peripheral.
This function will configure basic settings in PDM according to values in the initialization data structure.
Notice that enabling of PDM clock, setup of PDM pins and setup of PRS is not covered by this function.
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block. [in] init
A pointer to the initialization structure used to configure the PDM.
Definition at line
83
of file
em_pdm.c
.
References _PDM_CFG0_CH0CLKPOL_SHIFT , _PDM_CFG0_CH1CLKPOL_SHIFT , _PDM_CFG0_CH2CLKPOL_SHIFT , _PDM_CFG0_CH3CLKPOL_SHIFT , _PDM_CFG0_DATAFORMAT_SHIFT , _PDM_CFG0_FIFODVL_SHIFT , _PDM_CFG0_FORDER_SHIFT , _PDM_CFG0_NUMCH_SHIFT , _PDM_CFG1_PRESC_MASK , _PDM_CFG1_PRESC_SHIFT , _PDM_CTRL_DSR_MASK , _PDM_CTRL_DSR_SHIFT , _PDM_CTRL_GAIN_MASK , _PDM_CTRL_GAIN_SHIFT , PDM_TypeDef::CFG0 , PDM_TypeDef::CFG1 , PDM_Init_TypeDef::ch0ClkPolarity , PDM_Init_TypeDef::ch1ClkPolarity , PDM_Init_TypeDef::ch2ClkPolarity , PDM_Init_TypeDef::ch3ClkPolarity , PDM_TypeDef::CTRL , PDM_Init_TypeDef::dataFormat , PDM_Init_TypeDef::dsr , PDM_TypeDef::EN , PDM_Init_TypeDef::enableCh0Ch1Stereo , PDM_Init_TypeDef::enableCh2Ch3Stereo , PDM_Init_TypeDef::fifoValidWatermark , PDM_Init_TypeDef::filterOrder , PDM_Init_TypeDef::gain , PDM_Init_TypeDef::numChannels , PDM_Init_TypeDef::outClkEn , PDM_CFG0_STEREOMODECH01_CH01ENABLE , PDM_CFG0_STEREOMODECH23_CH23ENABLE , PDM_Clear() , PDM_CTRL_OUTCLKEN , PDM_EN_EN_DISABLE , PDM_EN_EN_ENABLE , PDM_FifoFlush() , PDM_Start() , PDM_Init_TypeDef::prescaler , PDM_Init_TypeDef::start , and PDM_TypeDef::SYNCBUSY .
__STATIC_INLINE void PDM_IntClear | ( | PDM_TypeDef * |
pdm,
|
uint32_t |
flags
|
||
) |
Clear one or more pending PDM interrupts.
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block. [in] flags
Pending PDM interrupt sources to clear. Use one or more valid interrupt flags for the PDM module. The flags are PDM_IFC_DV , PDM_IFC_DVL , PDM_IFC_OF and PDM_IFC_UF .
Definition at line
271
of file
em_pdm.h
.
References PDM_TypeDef::IFC .
__STATIC_INLINE void PDM_IntDisable | ( | PDM_TypeDef * |
pdm,
|
uint32_t |
flags
|
||
) |
Disable one or more PDM interrupts.
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block. [in] flags
PDM interrupt sources to disable. Use one or more valid interrupt flags for the PDM module. The flags are PDM_IEN_DV , PDM_IEN_DVL , PDM_IEN_OF and PDM_IEN_UF .
Definition at line
288
of file
em_pdm.h
.
References PDM_TypeDef::IEN .
__STATIC_INLINE void PDM_IntEnable | ( | PDM_TypeDef * |
pdm,
|
uint32_t |
flags
|
||
) |
Enable one or more PDM interrupts.
- Note
- Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. To ignore a pending interrupt, consider using PDM_IntClear() prior to enabling the interrupt.
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block. [in] flags
PDM interrupt sources to enable. Use one or more valid interrupt flags for the PDM module. The flags are PDM_IEN_DV , PDM_IEN_DVL , PDM_IEN_OF and PDM_IEN_UF .
Definition at line
310
of file
em_pdm.h
.
References PDM_TypeDef::IEN .
__STATIC_INLINE uint32_t PDM_IntGet | ( | PDM_TypeDef * |
pdm
|
) |
Get pending PDM interrupt flags.
- Note
- Event bits are not cleared by the use of this function.
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block.
- Returns
- PDM interrupt sources pending. Returns one or more valid interrupt flags for PDM module. The flags are PDM_IF_DV , PDM_IF_DVL , PDM_IF_OF and PDM_IF_UF .
Definition at line
330
of file
em_pdm.h
.
References PDM_TypeDef::IF .
__STATIC_INLINE uint32_t PDM_IntGetEnabled | ( | PDM_TypeDef * |
pdm
|
) |
Get enabled and pending PDM interrupt flags. Useful for handling more interrupt sources in the same interrupt handler.
- Note
- Interrupt flags are not cleared by the use of this function.
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block.
- Returns
-
Pending and enabled PDM interrupt sources Return value is the bitwise AND of
- the enabled interrupt sources in PDM_IEN and
- the pending interrupt flags PDM_IF
Definition at line
352
of file
em_pdm.h
.
References PDM_TypeDef::IEN , and PDM_TypeDef::IF .
__STATIC_INLINE void PDM_IntSet | ( | PDM_TypeDef * |
pdm,
|
uint32_t |
flags
|
||
) |
Set one or more pending PDM interrupts.
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block. [in] flags
PDM interrupt sources to set to pending. Use one or more valid interrupt flags for the PDM module. The flags are PDM_IFS_DV , PDM_IFS_DVL , PDM_IFS_OF and PDM_IFS_UF .
Definition at line
372
of file
em_pdm.h
.
References PDM_TypeDef::IFS .
void PDM_Reset | ( | PDM_TypeDef * |
pdm
|
) |
Initialize PDM registers with reset values.
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block.
Definition at line
128
of file
em_pdm.c
.
References _PDM_CFG0_RESETVALUE , _PDM_CFG1_RESETVALUE , _PDM_CTRL_RESETVALUE , _PDM_EN_RESETVALUE , _PDM_IEN_RESETVALUE , _PDM_IFC_MASK , _PDM_ROUTELOC0_RESETVALUE , _PDM_ROUTELOC1_RESETVALUE , _PDM_ROUTEPEN_RESETVALUE , PDM_TypeDef::CFG0 , PDM_TypeDef::CFG1 , PDM_TypeDef::CTRL , PDM_TypeDef::EN , PDM_TypeDef::IEN , PDM_TypeDef::IFC , PDM_TypeDef::ROUTELOC0 , PDM_TypeDef::ROUTELOC1 , PDM_TypeDef::ROUTEPEN , and PDM_TypeDef::SYNCBUSY .
Referenced by PDM_DeInit() .
__STATIC_INLINE uint32_t PDM_Rx | ( | PDM_TypeDef * |
pdm
|
) |
Read one entry from the PDM FIFO.
- Note
- This function will wait until a sample is available in the FIFO. Depending on PDM configuration, a FIFO entry can consist of one or two samples.
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block.
- Returns
- The entry read from the FIFO.
Definition at line
392
of file
em_pdm.h
.
References PDM_STATUS_EMPTY , PDM_TypeDef::RXDATA , and PDM_TypeDef::STATUS .
__STATIC_INLINE void PDM_Start | ( | PDM_TypeDef * |
pdm
|
) |
Start PDM operation (start the PDM filter).
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block.
Definition at line
407
of file
em_pdm.h
.
References PDM_TypeDef::CMD , PDM_CMD_START , and PDM_TypeDef::SYNCBUSY .
Referenced by PDM_Init() .
__STATIC_INLINE uint32_t PDM_StatusGet | ( | PDM_TypeDef * |
pdm
|
) |
Get PDM STATUS register.
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block.
- Returns
- STATUS register value.
Definition at line
425
of file
em_pdm.h
.
References PDM_TypeDef::STATUS .
__STATIC_INLINE void PDM_Stop | ( | PDM_TypeDef * |
pdm
|
) |
Stop PDM operation (stop the PDM filter).
- Parameters
-
[in] pdm
A pointer to the PDM peripheral register block.
Definition at line
437
of file
em_pdm.h
.
References PDM_TypeDef::CMD , PDM_CMD_STOP , and PDM_TypeDef::SYNCBUSY .
Referenced by PDM_DeInit() .