123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- #ifndef NRF_PDM_H_
- #define NRF_PDM_H_
- #include <nrfx.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define NRF_PDM_GAIN_MINIMUM 0x00
- #define NRF_PDM_GAIN_DEFAULT 0x28
- #define NRF_PDM_GAIN_MAXIMUM 0x50
- typedef uint8_t nrf_pdm_gain_t;
- typedef enum
- {
- NRF_PDM_TASK_START = offsetof(NRF_PDM_Type, TASKS_START),
- NRF_PDM_TASK_STOP = offsetof(NRF_PDM_Type, TASKS_STOP)
- } nrf_pdm_task_t;
- typedef enum
- {
- NRF_PDM_EVENT_STARTED = offsetof(NRF_PDM_Type, EVENTS_STARTED),
- NRF_PDM_EVENT_STOPPED = offsetof(NRF_PDM_Type, EVENTS_STOPPED),
- NRF_PDM_EVENT_END = offsetof(NRF_PDM_Type, EVENTS_END)
- } nrf_pdm_event_t;
- typedef enum
- {
- NRF_PDM_INT_STARTED = PDM_INTENSET_STARTED_Msk,
- NRF_PDM_INT_STOPPED = PDM_INTENSET_STOPPED_Msk,
- NRF_PDM_INT_END = PDM_INTENSET_END_Msk
- } nrf_pdm_int_mask_t;
- typedef enum
- {
- NRF_PDM_FREQ_1000K = PDM_PDMCLKCTRL_FREQ_1000K,
- NRF_PDM_FREQ_1032K = PDM_PDMCLKCTRL_FREQ_Default,
- NRF_PDM_FREQ_1067K = PDM_PDMCLKCTRL_FREQ_1067K
- } nrf_pdm_freq_t;
- typedef enum
- {
- NRF_PDM_MODE_STEREO = PDM_MODE_OPERATION_Stereo,
- NRF_PDM_MODE_MONO = PDM_MODE_OPERATION_Mono
- } nrf_pdm_mode_t;
- typedef enum
- {
- NRF_PDM_EDGE_LEFTFALLING = PDM_MODE_EDGE_LeftFalling,
- NRF_PDM_EDGE_LEFTRISING = PDM_MODE_EDGE_LeftRising
- } nrf_pdm_edge_t;
- __STATIC_INLINE void nrf_pdm_task_trigger(nrf_pdm_task_t task);
- __STATIC_INLINE uint32_t nrf_pdm_task_address_get(nrf_pdm_task_t task);
- __STATIC_INLINE bool nrf_pdm_event_check(nrf_pdm_event_t event);
- __STATIC_INLINE void nrf_pdm_event_clear(nrf_pdm_event_t event);
- __STATIC_INLINE volatile uint32_t * nrf_pdm_event_address_get(nrf_pdm_event_t event);
- __STATIC_INLINE void nrf_pdm_int_enable(uint32_t int_mask);
- __STATIC_INLINE bool nrf_pdm_int_enable_check(uint32_t int_mask);
- __STATIC_INLINE void nrf_pdm_int_disable(uint32_t int_mask);
- #if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
- __STATIC_INLINE void nrf_pdm_subscribe_set(nrf_pdm_task_t task,
- uint8_t channel);
- __STATIC_INLINE void nrf_pdm_subscribe_clear(nrf_pdm_task_t task);
- __STATIC_INLINE void nrf_pdm_publish_set(nrf_pdm_event_t event,
- uint8_t channel);
- __STATIC_INLINE void nrf_pdm_publish_clear(nrf_pdm_event_t event);
- #endif
- __STATIC_INLINE void nrf_pdm_enable(void);
- __STATIC_INLINE void nrf_pdm_disable(void);
- __STATIC_INLINE bool nrf_pdm_enable_check(void);
- __STATIC_INLINE void nrf_pdm_mode_set(nrf_pdm_mode_t pdm_mode, nrf_pdm_edge_t pdm_edge);
- __STATIC_INLINE void nrf_pdm_mode_get(nrf_pdm_mode_t * p_pdm_mode, nrf_pdm_edge_t * p_pdm_edge);
- __STATIC_INLINE void nrf_pdm_clock_set(nrf_pdm_freq_t pdm_freq);
- __STATIC_INLINE nrf_pdm_freq_t nrf_pdm_clock_get(void);
- __STATIC_INLINE void nrf_pdm_psel_connect(uint32_t psel_clk, uint32_t psel_din);
- __STATIC_INLINE void nrf_pdm_psel_disconnect(void);
- __STATIC_INLINE void nrf_pdm_gain_set(nrf_pdm_gain_t gain_l, nrf_pdm_gain_t gain_r);
- __STATIC_INLINE void nrf_pdm_gain_get(nrf_pdm_gain_t * p_gain_l, nrf_pdm_gain_t * p_gain_r);
- __STATIC_INLINE void nrf_pdm_buffer_set(uint32_t * p_buffer, uint32_t num);
- __STATIC_INLINE uint32_t * nrf_pdm_buffer_get(void);
- #ifndef SUPPRESS_INLINE_IMPLEMENTATION
- __STATIC_INLINE void nrf_pdm_task_trigger(nrf_pdm_task_t task)
- {
- *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)task)) = 0x1UL;
- }
- __STATIC_INLINE uint32_t nrf_pdm_task_address_get(nrf_pdm_task_t task)
- {
- return (uint32_t)((uint8_t *)NRF_PDM + (uint32_t)task);
- }
- __STATIC_INLINE bool nrf_pdm_event_check(nrf_pdm_event_t event)
- {
- return (bool)*(volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)event);
- }
- __STATIC_INLINE void nrf_pdm_event_clear(nrf_pdm_event_t event)
- {
- *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)event)) = 0x0UL;
- #if __CORTEX_M == 0x04
- volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)event));
- (void)dummy;
- #endif
- }
- __STATIC_INLINE volatile uint32_t * nrf_pdm_event_address_get(nrf_pdm_event_t event)
- {
- return (volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)event);
- }
- __STATIC_INLINE void nrf_pdm_int_enable(uint32_t int_mask)
- {
- NRF_PDM->INTENSET = int_mask;
- }
- __STATIC_INLINE bool nrf_pdm_int_enable_check(uint32_t int_mask)
- {
- return (bool)(NRF_PDM->INTENSET & int_mask);
- }
- __STATIC_INLINE void nrf_pdm_int_disable(uint32_t int_mask)
- {
- NRF_PDM->INTENCLR = int_mask;
- }
- #if defined(DPPI_PRESENT)
- __STATIC_INLINE void nrf_pdm_subscribe_set(nrf_pdm_task_t task,
- uint8_t channel)
- {
- *((volatile uint32_t *) ((uint8_t *) NRF_PDM + (uint32_t) task + 0x80uL)) =
- ((uint32_t)channel | PDM_SUBSCRIBE_START_EN_Msk);
- }
- __STATIC_INLINE void nrf_pdm_subscribe_clear(nrf_pdm_task_t task)
- {
- *((volatile uint32_t *) ((uint8_t *) NRF_PDM + (uint32_t) task + 0x80uL)) = 0;
- }
- __STATIC_INLINE void nrf_pdm_publish_set(nrf_pdm_event_t event,
- uint8_t channel)
- {
- *((volatile uint32_t *) ((uint8_t *) NRF_PDM + (uint32_t) event + 0x80uL)) =
- ((uint32_t)channel | PDM_PUBLISH_STARTED_EN_Msk);
- }
- __STATIC_INLINE void nrf_pdm_publish_clear(nrf_pdm_event_t event)
- {
- *((volatile uint32_t *) ((uint8_t *) NRF_PDM + (uint32_t) event + 0x80uL)) = 0;
- }
- #endif
- __STATIC_INLINE void nrf_pdm_enable(void)
- {
- NRF_PDM->ENABLE = (PDM_ENABLE_ENABLE_Enabled << PDM_ENABLE_ENABLE_Pos);
- }
- __STATIC_INLINE void nrf_pdm_disable(void)
- {
- NRF_PDM->ENABLE = (PDM_ENABLE_ENABLE_Disabled << PDM_ENABLE_ENABLE_Pos);
- }
- __STATIC_INLINE bool nrf_pdm_enable_check(void)
- {
- return (NRF_PDM->ENABLE == (PDM_ENABLE_ENABLE_Enabled << PDM_ENABLE_ENABLE_Pos));
- }
- __STATIC_INLINE void nrf_pdm_mode_set(nrf_pdm_mode_t pdm_mode, nrf_pdm_edge_t pdm_edge)
- {
- NRF_PDM->MODE = ((pdm_mode << PDM_MODE_OPERATION_Pos) & PDM_MODE_OPERATION_Msk)
- | ((pdm_edge << PDM_MODE_EDGE_Pos) & PDM_MODE_EDGE_Msk);
- }
- __STATIC_INLINE void nrf_pdm_mode_get(nrf_pdm_mode_t * p_pdm_mode, nrf_pdm_edge_t * p_pdm_edge)
- {
- uint32_t mode = NRF_PDM->MODE;
- *p_pdm_mode = (nrf_pdm_mode_t)((mode & PDM_MODE_OPERATION_Msk ) >> PDM_MODE_OPERATION_Pos);
- *p_pdm_edge = (nrf_pdm_edge_t)((mode & PDM_MODE_EDGE_Msk ) >> PDM_MODE_EDGE_Pos);
- }
- __STATIC_INLINE void nrf_pdm_clock_set(nrf_pdm_freq_t pdm_freq)
- {
- NRF_PDM->PDMCLKCTRL = ((pdm_freq << PDM_PDMCLKCTRL_FREQ_Pos) & PDM_PDMCLKCTRL_FREQ_Msk);
- }
- __STATIC_INLINE nrf_pdm_freq_t nrf_pdm_clock_get(void)
- {
- return (nrf_pdm_freq_t) ((NRF_PDM->PDMCLKCTRL << PDM_PDMCLKCTRL_FREQ_Pos) & PDM_PDMCLKCTRL_FREQ_Msk);
- }
- __STATIC_INLINE void nrf_pdm_psel_connect(uint32_t psel_clk, uint32_t psel_din)
- {
- NRF_PDM->PSEL.CLK = psel_clk;
- NRF_PDM->PSEL.DIN = psel_din;
- }
- __STATIC_INLINE void nrf_pdm_psel_disconnect(void)
- {
- NRF_PDM->PSEL.CLK = ((PDM_PSEL_CLK_CONNECT_Disconnected << PDM_PSEL_CLK_CONNECT_Pos)
- & PDM_PSEL_CLK_CONNECT_Msk);
- NRF_PDM->PSEL.DIN = ((PDM_PSEL_DIN_CONNECT_Disconnected << PDM_PSEL_DIN_CONNECT_Pos)
- & PDM_PSEL_DIN_CONNECT_Msk);
- }
- __STATIC_INLINE void nrf_pdm_gain_set(nrf_pdm_gain_t gain_l, nrf_pdm_gain_t gain_r)
- {
- NRF_PDM->GAINL = gain_l;
- NRF_PDM->GAINR = gain_r;
- }
- __STATIC_INLINE void nrf_pdm_gain_get(nrf_pdm_gain_t * p_gain_l, nrf_pdm_gain_t * p_gain_r)
- {
- *p_gain_l = NRF_PDM->GAINL;
- *p_gain_r = NRF_PDM->GAINR;
- }
- __STATIC_INLINE void nrf_pdm_buffer_set(uint32_t * p_buffer, uint32_t num)
- {
- NRF_PDM->SAMPLE.PTR = (uint32_t)p_buffer;
- NRF_PDM->SAMPLE.MAXCNT = num;
- }
- __STATIC_INLINE uint32_t * nrf_pdm_buffer_get(void)
- {
- return (uint32_t *)NRF_PDM->SAMPLE.PTR;
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|