The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 143:86740a56073b 1 /*
AnnaBridge 143:86740a56073b 2 * Copyright (c) 2015 Nordic Semiconductor ASA
AnnaBridge 143:86740a56073b 3 * All rights reserved.
AnnaBridge 143:86740a56073b 4 *
AnnaBridge 143:86740a56073b 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 143:86740a56073b 6 * are permitted provided that the following conditions are met:
AnnaBridge 143:86740a56073b 7 *
AnnaBridge 143:86740a56073b 8 * 1. Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 143:86740a56073b 9 * of conditions and the following disclaimer.
AnnaBridge 143:86740a56073b 10 *
AnnaBridge 143:86740a56073b 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
AnnaBridge 143:86740a56073b 12 * integrated circuit in a product or a software update for such product, must reproduce
AnnaBridge 143:86740a56073b 13 * the above copyright notice, this list of conditions and the following disclaimer in
AnnaBridge 143:86740a56073b 14 * the documentation and/or other materials provided with the distribution.
AnnaBridge 143:86740a56073b 15 *
AnnaBridge 143:86740a56073b 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
AnnaBridge 143:86740a56073b 17 * used to endorse or promote products derived from this software without specific prior
AnnaBridge 143:86740a56073b 18 * written permission.
AnnaBridge 143:86740a56073b 19 *
AnnaBridge 143:86740a56073b 20 * 4. This software, with or without modification, must only be used with a
AnnaBridge 143:86740a56073b 21 * Nordic Semiconductor ASA integrated circuit.
AnnaBridge 143:86740a56073b 22 *
AnnaBridge 143:86740a56073b 23 * 5. Any software provided in binary or object form under this license must not be reverse
AnnaBridge 143:86740a56073b 24 * engineered, decompiled, modified and/or disassembled.
AnnaBridge 143:86740a56073b 25 *
AnnaBridge 143:86740a56073b 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 143:86740a56073b 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 143:86740a56073b 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 143:86740a56073b 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 143:86740a56073b 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 143:86740a56073b 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 143:86740a56073b 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 143:86740a56073b 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 143:86740a56073b 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 143:86740a56073b 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 143:86740a56073b 36 *
AnnaBridge 143:86740a56073b 37 */
AnnaBridge 143:86740a56073b 38
AnnaBridge 143:86740a56073b 39
AnnaBridge 143:86740a56073b 40
AnnaBridge 143:86740a56073b 41 #ifndef NRF_PDM_H_
AnnaBridge 143:86740a56073b 42 #define NRF_PDM_H_
AnnaBridge 143:86740a56073b 43
AnnaBridge 143:86740a56073b 44 /**
AnnaBridge 143:86740a56073b 45 * @defgroup nrf_pdm_hal PDM HAL
AnnaBridge 143:86740a56073b 46 * @{
AnnaBridge 143:86740a56073b 47 * @ingroup nrf_pdm
AnnaBridge 143:86740a56073b 48 *
AnnaBridge 143:86740a56073b 49 * @brief @tagAPI52 Hardware abstraction layer for accessing the pulse density modulation (PDM) peripheral.
AnnaBridge 143:86740a56073b 50 */
AnnaBridge 143:86740a56073b 51
AnnaBridge 143:86740a56073b 52 #include <stdbool.h>
AnnaBridge 143:86740a56073b 53 #include <stddef.h>
AnnaBridge 143:86740a56073b 54 #include "nrf.h"
AnnaBridge 143:86740a56073b 55 #include "nrf_assert.h"
AnnaBridge 143:86740a56073b 56
AnnaBridge 143:86740a56073b 57
AnnaBridge 143:86740a56073b 58 #define NRF_PDM_GAIN_MINIMUM 0x00
AnnaBridge 143:86740a56073b 59 #define NRF_PDM_GAIN_DEFAULT 0x28
AnnaBridge 143:86740a56073b 60 #define NRF_PDM_GAIN_MAXIMUM 0x50
AnnaBridge 143:86740a56073b 61
AnnaBridge 143:86740a56073b 62 typedef uint8_t nrf_pdm_gain_t;
AnnaBridge 143:86740a56073b 63
AnnaBridge 143:86740a56073b 64
AnnaBridge 143:86740a56073b 65 /**
AnnaBridge 143:86740a56073b 66 * @brief PDM tasks.
AnnaBridge 143:86740a56073b 67 */
AnnaBridge 143:86740a56073b 68 typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
AnnaBridge 143:86740a56073b 69 {
AnnaBridge 143:86740a56073b 70 NRF_PDM_TASK_START = offsetof(NRF_PDM_Type, TASKS_START), ///< Starts continuous PDM transfer.
AnnaBridge 143:86740a56073b 71 NRF_PDM_TASK_STOP = offsetof(NRF_PDM_Type, TASKS_STOP) ///< Stops PDM transfer.
AnnaBridge 143:86740a56073b 72 } nrf_pdm_task_t;
AnnaBridge 143:86740a56073b 73
AnnaBridge 143:86740a56073b 74
AnnaBridge 143:86740a56073b 75 /**
AnnaBridge 143:86740a56073b 76 * @brief PDM events.
AnnaBridge 143:86740a56073b 77 */
AnnaBridge 143:86740a56073b 78 typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
AnnaBridge 143:86740a56073b 79 {
AnnaBridge 143:86740a56073b 80 NRF_PDM_EVENT_STARTED = offsetof(NRF_PDM_Type, EVENTS_STARTED), ///< PDM transfer has started.
AnnaBridge 143:86740a56073b 81 NRF_PDM_EVENT_STOPPED = offsetof(NRF_PDM_Type, EVENTS_STOPPED), ///< PDM transfer has finished.
AnnaBridge 143:86740a56073b 82 NRF_PDM_EVENT_END = offsetof(NRF_PDM_Type, EVENTS_END) ///< The PDM has written the last sample specified by SAMPLE.MAXCNT (or the last sample after a STOP task has been received) to Data RAM.
AnnaBridge 143:86740a56073b 83 } nrf_pdm_event_t;
AnnaBridge 143:86740a56073b 84
AnnaBridge 143:86740a56073b 85
AnnaBridge 143:86740a56073b 86 /**
AnnaBridge 143:86740a56073b 87 * @brief PDM interrupt masks.
AnnaBridge 143:86740a56073b 88 */
AnnaBridge 143:86740a56073b 89 typedef enum
AnnaBridge 143:86740a56073b 90 {
AnnaBridge 143:86740a56073b 91 NRF_PDM_INT_STARTED = PDM_INTENSET_STARTED_Msk, ///< Interrupt on EVENTS_STARTED event.
AnnaBridge 143:86740a56073b 92 NRF_PDM_INT_STOPPED = PDM_INTENSET_STOPPED_Msk, ///< Interrupt on EVENTS_STOPPED event.
AnnaBridge 143:86740a56073b 93 NRF_PDM_INT_END = PDM_INTENSET_END_Msk ///< Interrupt on EVENTS_END event.
AnnaBridge 143:86740a56073b 94 } nrf_pdm_int_mask_t;
AnnaBridge 143:86740a56073b 95
AnnaBridge 143:86740a56073b 96 /**
AnnaBridge 143:86740a56073b 97 * @brief PDM clock frequency.
AnnaBridge 143:86740a56073b 98 */
AnnaBridge 143:86740a56073b 99 typedef enum
AnnaBridge 143:86740a56073b 100 {
AnnaBridge 143:86740a56073b 101 NRF_PDM_FREQ_1000K = PDM_PDMCLKCTRL_FREQ_1000K, ///< PDM_CLK = 1.000 MHz.
AnnaBridge 143:86740a56073b 102 NRF_PDM_FREQ_1032K = PDM_PDMCLKCTRL_FREQ_Default, ///< PDM_CLK = 1.032 MHz.
AnnaBridge 143:86740a56073b 103 NRF_PDM_FREQ_1067K = PDM_PDMCLKCTRL_FREQ_1067K ///< PDM_CLK = 1.067 MHz.
AnnaBridge 143:86740a56073b 104 } nrf_pdm_freq_t;
AnnaBridge 143:86740a56073b 105
AnnaBridge 143:86740a56073b 106
AnnaBridge 143:86740a56073b 107 /**
AnnaBridge 143:86740a56073b 108 * @brief PDM operation mode.
AnnaBridge 143:86740a56073b 109 */
AnnaBridge 143:86740a56073b 110 typedef enum
AnnaBridge 143:86740a56073b 111 {
AnnaBridge 143:86740a56073b 112 NRF_PDM_MODE_STEREO = PDM_MODE_OPERATION_Stereo, ///< Sample and store one pair (Left + Right) of 16-bit samples per RAM word.
AnnaBridge 143:86740a56073b 113 NRF_PDM_MODE_MONO = PDM_MODE_OPERATION_Mono ///< Sample and store two successive Left samples (16 bit each) per RAM word.
AnnaBridge 143:86740a56073b 114 } nrf_pdm_mode_t;
AnnaBridge 143:86740a56073b 115
AnnaBridge 143:86740a56073b 116
AnnaBridge 143:86740a56073b 117 /**
AnnaBridge 143:86740a56073b 118 * @brief PDM sampling mode.
AnnaBridge 143:86740a56073b 119 */
AnnaBridge 143:86740a56073b 120 typedef enum
AnnaBridge 143:86740a56073b 121 {
AnnaBridge 143:86740a56073b 122 NRF_PDM_EDGE_LEFTFALLING = PDM_MODE_EDGE_LeftFalling, ///< Left (or mono) is sampled on falling edge of PDM_CLK.
AnnaBridge 143:86740a56073b 123 NRF_PDM_EDGE_LEFTRISING = PDM_MODE_EDGE_LeftRising ///< Left (or mono) is sampled on rising edge of PDM_CLK.
AnnaBridge 143:86740a56073b 124 } nrf_pdm_edge_t;
AnnaBridge 143:86740a56073b 125
AnnaBridge 143:86740a56073b 126
AnnaBridge 143:86740a56073b 127 /**
AnnaBridge 143:86740a56073b 128 * @brief Function for triggering a PDM task.
AnnaBridge 143:86740a56073b 129 *
AnnaBridge 143:86740a56073b 130 * @param[in] pdm_task PDM task.
AnnaBridge 143:86740a56073b 131 */
AnnaBridge 143:86740a56073b 132 __STATIC_INLINE void nrf_pdm_task_trigger(nrf_pdm_task_t pdm_task)
AnnaBridge 143:86740a56073b 133 {
AnnaBridge 143:86740a56073b 134 *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_task)) = 0x1UL;
AnnaBridge 143:86740a56073b 135 }
AnnaBridge 143:86740a56073b 136
AnnaBridge 143:86740a56073b 137
AnnaBridge 143:86740a56073b 138 /**
AnnaBridge 143:86740a56073b 139 * @brief Function for getting the address of a PDM task register.
AnnaBridge 143:86740a56073b 140 *
AnnaBridge 143:86740a56073b 141 * @param[in] pdm_task PDM task.
AnnaBridge 143:86740a56073b 142 *
AnnaBridge 143:86740a56073b 143 * @return Address of the specified PDM task.
AnnaBridge 143:86740a56073b 144 */
AnnaBridge 143:86740a56073b 145 __STATIC_INLINE uint32_t nrf_pdm_task_address_get(nrf_pdm_task_t pdm_task)
AnnaBridge 143:86740a56073b 146 {
AnnaBridge 143:86740a56073b 147 return (uint32_t)((uint8_t *)NRF_PDM + (uint32_t)pdm_task);
AnnaBridge 143:86740a56073b 148 }
AnnaBridge 143:86740a56073b 149
AnnaBridge 143:86740a56073b 150
AnnaBridge 143:86740a56073b 151 /**
AnnaBridge 143:86740a56073b 152 * @brief Function for getting the state of a PDM event.
AnnaBridge 143:86740a56073b 153 *
AnnaBridge 143:86740a56073b 154 * @param[in] pdm_event PDM event.
AnnaBridge 143:86740a56073b 155 *
AnnaBridge 143:86740a56073b 156 * @return State of the specified PDM event.
AnnaBridge 143:86740a56073b 157 */
AnnaBridge 143:86740a56073b 158 __STATIC_INLINE bool nrf_pdm_event_check(nrf_pdm_event_t pdm_event)
AnnaBridge 143:86740a56073b 159 {
AnnaBridge 143:86740a56073b 160 return (bool)*(volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event);
AnnaBridge 143:86740a56073b 161 }
AnnaBridge 143:86740a56073b 162
AnnaBridge 143:86740a56073b 163
AnnaBridge 143:86740a56073b 164 /**
AnnaBridge 143:86740a56073b 165 * @brief Function for clearing a PDM event.
AnnaBridge 143:86740a56073b 166 *
AnnaBridge 143:86740a56073b 167 * @param[in] pdm_event PDM event.
AnnaBridge 143:86740a56073b 168 */
AnnaBridge 143:86740a56073b 169 __STATIC_INLINE void nrf_pdm_event_clear(nrf_pdm_event_t pdm_event)
AnnaBridge 143:86740a56073b 170 {
AnnaBridge 143:86740a56073b 171 *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event)) = 0x0UL;
AnnaBridge 143:86740a56073b 172 }
AnnaBridge 143:86740a56073b 173
AnnaBridge 143:86740a56073b 174
AnnaBridge 143:86740a56073b 175 /**
AnnaBridge 143:86740a56073b 176 * @brief Function for getting the address of a PDM event register.
AnnaBridge 143:86740a56073b 177 *
AnnaBridge 143:86740a56073b 178 * @param[in] pdm_event PDM event.
AnnaBridge 143:86740a56073b 179 *
AnnaBridge 143:86740a56073b 180 * @return Address of the specified PDM event.
AnnaBridge 143:86740a56073b 181 */
AnnaBridge 143:86740a56073b 182 __STATIC_INLINE volatile uint32_t * nrf_pdm_event_address_get(nrf_pdm_event_t pdm_event)
AnnaBridge 143:86740a56073b 183 {
AnnaBridge 143:86740a56073b 184 return (volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event);
AnnaBridge 143:86740a56073b 185 }
AnnaBridge 143:86740a56073b 186
AnnaBridge 143:86740a56073b 187
AnnaBridge 143:86740a56073b 188 /**
AnnaBridge 143:86740a56073b 189 * @brief Function for enabling PDM interrupts.
AnnaBridge 143:86740a56073b 190 *
AnnaBridge 143:86740a56073b 191 * @param[in] pdm_int_mask Interrupts to enable.
AnnaBridge 143:86740a56073b 192 */
AnnaBridge 143:86740a56073b 193 __STATIC_INLINE void nrf_pdm_int_enable(uint32_t pdm_int_mask)
AnnaBridge 143:86740a56073b 194 {
AnnaBridge 143:86740a56073b 195 NRF_PDM->INTENSET = pdm_int_mask;
AnnaBridge 143:86740a56073b 196 }
AnnaBridge 143:86740a56073b 197
AnnaBridge 143:86740a56073b 198
AnnaBridge 143:86740a56073b 199 /**
AnnaBridge 143:86740a56073b 200 * @brief Function for retrieving the state of PDM interrupts.
AnnaBridge 143:86740a56073b 201 *
AnnaBridge 143:86740a56073b 202 * @param[in] pdm_int_mask Interrupts to check.
AnnaBridge 143:86740a56073b 203 *
AnnaBridge 143:86740a56073b 204 * @retval true If all specified interrupts are enabled.
AnnaBridge 143:86740a56073b 205 * @retval false If at least one of the given interrupts is not enabled.
AnnaBridge 143:86740a56073b 206 */
AnnaBridge 143:86740a56073b 207 __STATIC_INLINE bool nrf_pdm_int_enable_check(uint32_t pdm_int_mask)
AnnaBridge 143:86740a56073b 208 {
AnnaBridge 143:86740a56073b 209 return (bool)(NRF_PDM->INTENSET & pdm_int_mask);
AnnaBridge 143:86740a56073b 210 }
AnnaBridge 143:86740a56073b 211
AnnaBridge 143:86740a56073b 212
AnnaBridge 143:86740a56073b 213 /**
AnnaBridge 143:86740a56073b 214 * @brief Function for disabling interrupts.
AnnaBridge 143:86740a56073b 215 *
AnnaBridge 143:86740a56073b 216 * @param pdm_int_mask Interrupts to disable.
AnnaBridge 143:86740a56073b 217 */
AnnaBridge 143:86740a56073b 218 __STATIC_INLINE void nrf_pdm_int_disable(uint32_t pdm_int_mask)
AnnaBridge 143:86740a56073b 219 {
AnnaBridge 143:86740a56073b 220 NRF_PDM->INTENCLR = pdm_int_mask;
AnnaBridge 143:86740a56073b 221 }
AnnaBridge 143:86740a56073b 222
AnnaBridge 143:86740a56073b 223
AnnaBridge 143:86740a56073b 224 /**
AnnaBridge 143:86740a56073b 225 * @brief Function for enabling the PDM peripheral.
AnnaBridge 143:86740a56073b 226 *
AnnaBridge 143:86740a56073b 227 * The PDM peripheral must be enabled before use.
AnnaBridge 143:86740a56073b 228 */
AnnaBridge 143:86740a56073b 229 __STATIC_INLINE void nrf_pdm_enable(void)
AnnaBridge 143:86740a56073b 230 {
AnnaBridge 143:86740a56073b 231 NRF_PDM->ENABLE = (PDM_ENABLE_ENABLE_Enabled << PDM_ENABLE_ENABLE_Pos);
AnnaBridge 143:86740a56073b 232 }
AnnaBridge 143:86740a56073b 233
AnnaBridge 143:86740a56073b 234
AnnaBridge 143:86740a56073b 235 /**
AnnaBridge 143:86740a56073b 236 * @brief Function for disabling the PDM peripheral.
AnnaBridge 143:86740a56073b 237 */
AnnaBridge 143:86740a56073b 238 __STATIC_INLINE void nrf_pdm_disable(void)
AnnaBridge 143:86740a56073b 239 {
AnnaBridge 143:86740a56073b 240 NRF_PDM->ENABLE = (PDM_ENABLE_ENABLE_Disabled << PDM_ENABLE_ENABLE_Pos);
AnnaBridge 143:86740a56073b 241 }
AnnaBridge 143:86740a56073b 242
AnnaBridge 143:86740a56073b 243
AnnaBridge 143:86740a56073b 244 /**
AnnaBridge 143:86740a56073b 245 * @brief Function for checking if the PDM peripheral is enabled.
AnnaBridge 143:86740a56073b 246 *
AnnaBridge 143:86740a56073b 247 * @retval true If the PDM peripheral is enabled.
AnnaBridge 143:86740a56073b 248 * @retval false If the PDM peripheral is not enabled.
AnnaBridge 143:86740a56073b 249 */
AnnaBridge 143:86740a56073b 250 __STATIC_INLINE bool nrf_pdm_enable_check(void)
AnnaBridge 143:86740a56073b 251 {
AnnaBridge 143:86740a56073b 252 return (NRF_PDM->ENABLE == (PDM_ENABLE_ENABLE_Enabled << PDM_ENABLE_ENABLE_Pos));
AnnaBridge 143:86740a56073b 253 }
AnnaBridge 143:86740a56073b 254
AnnaBridge 143:86740a56073b 255
AnnaBridge 143:86740a56073b 256 /**
AnnaBridge 143:86740a56073b 257 * @brief Function for setting the PDM operation mode.
AnnaBridge 143:86740a56073b 258 *
AnnaBridge 143:86740a56073b 259 * @param[in] pdm_mode PDM operation mode.
AnnaBridge 143:86740a56073b 260 * @param[in] pdm_edge PDM sampling mode.
AnnaBridge 143:86740a56073b 261 */
AnnaBridge 143:86740a56073b 262 __STATIC_INLINE void nrf_pdm_mode_set(nrf_pdm_mode_t pdm_mode, nrf_pdm_edge_t pdm_edge)
AnnaBridge 143:86740a56073b 263 {
AnnaBridge 143:86740a56073b 264 NRF_PDM->MODE = ((pdm_mode << PDM_MODE_OPERATION_Pos) & PDM_MODE_OPERATION_Msk)
AnnaBridge 143:86740a56073b 265 | ((pdm_edge << PDM_MODE_EDGE_Pos) & PDM_MODE_EDGE_Msk);
AnnaBridge 143:86740a56073b 266 }
AnnaBridge 143:86740a56073b 267
AnnaBridge 143:86740a56073b 268
AnnaBridge 143:86740a56073b 269 /**
AnnaBridge 143:86740a56073b 270 * @brief Function for getting the PDM operation mode.
AnnaBridge 143:86740a56073b 271 *
AnnaBridge 143:86740a56073b 272 * @param[out] p_pdm_mode PDM operation mode.
AnnaBridge 143:86740a56073b 273 * @param[out] p_pdm_edge PDM sampling mode.
AnnaBridge 143:86740a56073b 274 */
AnnaBridge 143:86740a56073b 275 __STATIC_INLINE void nrf_pdm_mode_get(nrf_pdm_mode_t * p_pdm_mode, nrf_pdm_edge_t * p_pdm_edge)
AnnaBridge 143:86740a56073b 276 {
AnnaBridge 143:86740a56073b 277 uint32_t mode = NRF_PDM->MODE;
AnnaBridge 143:86740a56073b 278 *p_pdm_mode = (nrf_pdm_mode_t)((mode & PDM_MODE_OPERATION_Msk ) >> PDM_MODE_OPERATION_Pos);
AnnaBridge 143:86740a56073b 279 *p_pdm_edge = (nrf_pdm_edge_t)((mode & PDM_MODE_EDGE_Msk ) >> PDM_MODE_EDGE_Pos);
AnnaBridge 143:86740a56073b 280 }
AnnaBridge 143:86740a56073b 281
AnnaBridge 143:86740a56073b 282
AnnaBridge 143:86740a56073b 283 /**
AnnaBridge 143:86740a56073b 284 * @brief Function for setting the PDM clock frequency.
AnnaBridge 143:86740a56073b 285 *
AnnaBridge 143:86740a56073b 286 * @param[in] pdm_freq PDM clock frequency.
AnnaBridge 143:86740a56073b 287 */
AnnaBridge 143:86740a56073b 288 __STATIC_INLINE void nrf_pdm_clock_set(nrf_pdm_freq_t pdm_freq)
AnnaBridge 143:86740a56073b 289 {
AnnaBridge 143:86740a56073b 290 NRF_PDM->PDMCLKCTRL = ((pdm_freq << PDM_PDMCLKCTRL_FREQ_Pos) & PDM_PDMCLKCTRL_FREQ_Msk);
AnnaBridge 143:86740a56073b 291 }
AnnaBridge 143:86740a56073b 292
AnnaBridge 143:86740a56073b 293
AnnaBridge 143:86740a56073b 294 /**
AnnaBridge 143:86740a56073b 295 * @brief Function for getting the PDM clock frequency.
AnnaBridge 143:86740a56073b 296 */
AnnaBridge 143:86740a56073b 297 __STATIC_INLINE nrf_pdm_freq_t nrf_pdm_clock_get(void)
AnnaBridge 143:86740a56073b 298 {
AnnaBridge 143:86740a56073b 299 return (nrf_pdm_freq_t) ((NRF_PDM->PDMCLKCTRL << PDM_PDMCLKCTRL_FREQ_Pos) & PDM_PDMCLKCTRL_FREQ_Msk);
AnnaBridge 143:86740a56073b 300 }
AnnaBridge 143:86740a56073b 301
AnnaBridge 143:86740a56073b 302
AnnaBridge 143:86740a56073b 303 /**
AnnaBridge 143:86740a56073b 304 * @brief Function for setting up the PDM pins.
AnnaBridge 143:86740a56073b 305 *
AnnaBridge 143:86740a56073b 306 * @param[in] psel_clk CLK pin number.
AnnaBridge 143:86740a56073b 307 * @param[in] psel_din DIN pin number.
AnnaBridge 143:86740a56073b 308 */
AnnaBridge 143:86740a56073b 309 __STATIC_INLINE void nrf_pdm_psel_connect(uint32_t psel_clk, uint32_t psel_din)
AnnaBridge 143:86740a56073b 310 {
AnnaBridge 143:86740a56073b 311 NRF_PDM->PSEL.CLK = ((psel_clk << PDM_PSEL_CLK_PIN_Pos) & PDM_PSEL_CLK_PIN_Msk)
AnnaBridge 143:86740a56073b 312 | ((PDM_PSEL_CLK_CONNECT_Connected << PDM_PSEL_CLK_CONNECT_Pos) & PDM_PSEL_CLK_CONNECT_Msk);
AnnaBridge 143:86740a56073b 313 NRF_PDM->PSEL.DIN = ((psel_din << PDM_PSEL_DIN_PIN_Pos) & PDM_PSEL_DIN_PIN_Msk)
AnnaBridge 143:86740a56073b 314 | ((PDM_PSEL_DIN_CONNECT_Connected << PDM_PSEL_CLK_CONNECT_Pos) & PDM_PSEL_DIN_CONNECT_Msk);
AnnaBridge 143:86740a56073b 315 }
AnnaBridge 143:86740a56073b 316
AnnaBridge 143:86740a56073b 317 /**
AnnaBridge 143:86740a56073b 318 * @brief Function for disconnecting the PDM pins.
AnnaBridge 143:86740a56073b 319 */
AnnaBridge 143:86740a56073b 320 __STATIC_INLINE void nrf_pdm_psel_disconnect()
AnnaBridge 143:86740a56073b 321 {
AnnaBridge 143:86740a56073b 322 NRF_PDM->PSEL.CLK = ((PDM_PSEL_CLK_CONNECT_Disconnected << PDM_PSEL_CLK_CONNECT_Pos)
AnnaBridge 143:86740a56073b 323 & PDM_PSEL_CLK_CONNECT_Msk);
AnnaBridge 143:86740a56073b 324 NRF_PDM->PSEL.DIN = ((PDM_PSEL_DIN_CONNECT_Disconnected << PDM_PSEL_DIN_CONNECT_Pos)
AnnaBridge 143:86740a56073b 325 & PDM_PSEL_DIN_CONNECT_Msk);
AnnaBridge 143:86740a56073b 326 }
AnnaBridge 143:86740a56073b 327
AnnaBridge 143:86740a56073b 328
AnnaBridge 143:86740a56073b 329 /**
AnnaBridge 143:86740a56073b 330 * @brief Function for setting the PDM gain.
AnnaBridge 143:86740a56073b 331 *
AnnaBridge 143:86740a56073b 332 * @param[in] gain_l Left channel gain.
AnnaBridge 143:86740a56073b 333 * @param[in] gain_r Right channel gain.
AnnaBridge 143:86740a56073b 334 */
AnnaBridge 143:86740a56073b 335 __STATIC_INLINE void nrf_pdm_gain_set(nrf_pdm_gain_t gain_l, nrf_pdm_gain_t gain_r)
AnnaBridge 143:86740a56073b 336 {
AnnaBridge 143:86740a56073b 337 NRF_PDM->GAINL = gain_l;
AnnaBridge 143:86740a56073b 338 NRF_PDM->GAINR = gain_r;
AnnaBridge 143:86740a56073b 339 }
AnnaBridge 143:86740a56073b 340
AnnaBridge 143:86740a56073b 341
AnnaBridge 143:86740a56073b 342 /**
AnnaBridge 143:86740a56073b 343 * @brief Function for getting the PDM gain.
AnnaBridge 143:86740a56073b 344 *
AnnaBridge 143:86740a56073b 345 * @param[out] p_gain_l Left channel gain.
AnnaBridge 143:86740a56073b 346 * @param[out] p_gain_r Right channel gain.
AnnaBridge 143:86740a56073b 347 */
AnnaBridge 143:86740a56073b 348 __STATIC_INLINE void nrf_pdm_gain_get(nrf_pdm_gain_t * p_gain_l, nrf_pdm_gain_t * p_gain_r)
AnnaBridge 143:86740a56073b 349 {
AnnaBridge 143:86740a56073b 350 *p_gain_l = NRF_PDM->GAINL;
AnnaBridge 143:86740a56073b 351 *p_gain_r = NRF_PDM->GAINR;
AnnaBridge 143:86740a56073b 352 }
AnnaBridge 143:86740a56073b 353
AnnaBridge 143:86740a56073b 354
AnnaBridge 143:86740a56073b 355 /**
AnnaBridge 143:86740a56073b 356 * @brief Function for setting the PDM sample buffer.
AnnaBridge 143:86740a56073b 357 *
AnnaBridge 143:86740a56073b 358 * @param[in] p_buffer Pointer to the RAM address where samples should be written with EasyDMA.
AnnaBridge 143:86740a56073b 359 * @param[in] num Number of samples to allocate memory for in EasyDMA mode.
AnnaBridge 143:86740a56073b 360 *
AnnaBridge 143:86740a56073b 361 * The amount of allocated RAM depends on the operation mode.
AnnaBridge 143:86740a56073b 362 * - For stereo mode: N 32-bit words.
AnnaBridge 143:86740a56073b 363 * - For mono mode: Ceil(N/2) 32-bit words.
AnnaBridge 143:86740a56073b 364 */
AnnaBridge 143:86740a56073b 365 __STATIC_INLINE void nrf_pdm_buffer_set(uint32_t * p_buffer, uint32_t num)
AnnaBridge 143:86740a56073b 366 {
AnnaBridge 143:86740a56073b 367 NRF_PDM->SAMPLE.PTR = (uint32_t)p_buffer;
AnnaBridge 143:86740a56073b 368 NRF_PDM->SAMPLE.MAXCNT = num;
AnnaBridge 143:86740a56073b 369 }
AnnaBridge 143:86740a56073b 370
AnnaBridge 143:86740a56073b 371 /**
AnnaBridge 143:86740a56073b 372 * @brief Function for getting the current PDM sample buffer address.
AnnaBridge 143:86740a56073b 373 *
AnnaBridge 143:86740a56073b 374 * @return Pointer to the current sample buffer.
AnnaBridge 143:86740a56073b 375 */
AnnaBridge 143:86740a56073b 376 __STATIC_INLINE uint32_t * nrf_pdm_buffer_get()
AnnaBridge 143:86740a56073b 377 {
AnnaBridge 143:86740a56073b 378 return (uint32_t *)NRF_PDM->SAMPLE.PTR;
AnnaBridge 143:86740a56073b 379 }
AnnaBridge 143:86740a56073b 380
AnnaBridge 143:86740a56073b 381
AnnaBridge 143:86740a56073b 382 /**
AnnaBridge 143:86740a56073b 383 *@}
AnnaBridge 143:86740a56073b 384 **/
AnnaBridge 143:86740a56073b 385
AnnaBridge 143:86740a56073b 386 #endif /* NRF_PDM_H_ */