am_hal_pdm.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. //*****************************************************************************
  2. //
  3. // am_hal_pdm.h
  4. //! @file
  5. //!
  6. //! @brief Functions for accessing and configuring the PDM module
  7. //!
  8. //! @addtogroup pdm2 Pulse Density Modulation (PDM) Input Module.
  9. //! @ingroup apollo2hal
  10. //! @{
  11. //*****************************************************************************
  12. //*****************************************************************************
  13. //
  14. // Copyright (c) 2017, Ambiq Micro
  15. // All rights reserved.
  16. //
  17. // Redistribution and use in source and binary forms, with or without
  18. // modification, are permitted provided that the following conditions are met:
  19. //
  20. // 1. Redistributions of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // 2. Redistributions in binary form must reproduce the above copyright
  24. // notice, this list of conditions and the following disclaimer in the
  25. // documentation and/or other materials provided with the distribution.
  26. //
  27. // 3. Neither the name of the copyright holder nor the names of its
  28. // contributors may be used to endorse or promote products derived from this
  29. // software without specific prior written permission.
  30. //
  31. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  32. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  35. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  36. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  37. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  38. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  39. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. // POSSIBILITY OF SUCH DAMAGE.
  42. //
  43. // This is part of revision 1.2.11 of the AmbiqSuite Development Package.
  44. //
  45. //*****************************************************************************
  46. #ifndef AM_HAL_PDM_H
  47. #define AM_HAL_PDM_H
  48. #ifdef __cplusplus
  49. extern "C"
  50. {
  51. #endif
  52. //*****************************************************************************
  53. //
  54. // Macro definitions
  55. //
  56. //*****************************************************************************
  57. //*****************************************************************************
  58. //
  59. //! @name PDM Left Right Swap Control
  60. //! @brief Macro definitions for the PDM LRSWAP bit field
  61. //!
  62. //! These macros may be used with the am_hal_pdm_config_t structure to set the
  63. //! left right swap bit.
  64. //!
  65. //! @{
  66. //
  67. //*****************************************************************************
  68. #define AM_HAL_PDM_PCFG_LRSWAP_ENABLE \
  69. AM_REG_PDM_PCFG_LRSWAP_EN
  70. #define AM_HAL_PDM_PCFG_LRSWAP_DISABLE \
  71. AM_REG_PDM_PCFG_LRSWAP_NOSWAP
  72. //! @}
  73. //*****************************************************************************
  74. //
  75. //! @name PDM Right Gain Setting
  76. //! @brief Macro definitions for the PDM Right Gain Setting.
  77. //!
  78. //! These macros may be used with the am_hal_pdm_config_t structure to set the
  79. //! right gain value.
  80. //!
  81. //! @{
  82. //
  83. //*****************************************************************************
  84. #define AM_HAL_PDM_PCFG_RIGHT_PGA_M15DB AM_REG_PDM_PCFG_PGARIGHT_M15DB
  85. #define AM_HAL_PDM_PCFG_RIGHT_PGA_M300DB AM_REG_PDM_PCFG_PGARIGHT_M300DB
  86. #define AM_HAL_PDM_PCFG_RIGHT_PGA_M45DB AM_REG_PDM_PCFG_PGARIGHT_M45DB
  87. #define AM_HAL_PDM_PCFG_RIGHT_PGA_M60DB AM_REG_PDM_PCFG_PGARIGHT_M60DB
  88. #define AM_HAL_PDM_PCFG_RIGHT_PGA_M75DB AM_REG_PDM_PCFG_PGARIGHT_M75DB
  89. #define AM_HAL_PDM_PCFG_RIGHT_PGA_M90DB AM_REG_PDM_PCFG_PGARIGHT_M90DB
  90. #define AM_HAL_PDM_PCFG_RIGHT_PGA_M105DB AM_REG_PDM_PCFG_PGARIGHT_M105DB
  91. #define AM_HAL_PDM_PCFG_RIGHT_PGA_M120DB AM_REG_PDM_PCFG_PGARIGHT_M120DB
  92. #define AM_HAL_PDM_PCFG_RIGHT_PGA_P105DB AM_REG_PDM_PCFG_PGARIGHT_P105DB
  93. #define AM_HAL_PDM_PCFG_RIGHT_PGA_P90DB AM_REG_PDM_PCFG_PGARIGHT_P90DB
  94. #define AM_HAL_PDM_PCFG_RIGHT_PGA_P75DB AM_REG_PDM_PCFG_PGARIGHT_P75DB
  95. #define AM_HAL_PDM_PCFG_RIGHT_PGA_P60DB AM_REG_PDM_PCFG_PGARIGHT_P60DB
  96. #define AM_HAL_PDM_PCFG_RIGHT_PGA_P45DB AM_REG_PDM_PCFG_PGARIGHT_P45DB
  97. #define AM_HAL_PDM_PCFG_RIGHT_PGA_P300DB AM_REG_PDM_PCFG_PGARIGHT_P300DB
  98. #define AM_HAL_PDM_PCFG_RIGHT_PGA_P15DB AM_REG_PDM_PCFG_PGARIGHT_P15DB
  99. #define AM_HAL_PDM_PCFG_RIGHT_PGA_0DB AM_REG_PDM_PCFG_PGARIGHT_0DB
  100. //! @}
  101. //*****************************************************************************
  102. //
  103. //! @name PDM Left Gain Setting
  104. //! @brief Macro definitions for the PDM Left Gain Setting.
  105. //!
  106. //! These macros may be used with the am_hal_pdm_config_t structure to set the
  107. //! left gain value.
  108. //!
  109. //! @{
  110. //
  111. //*****************************************************************************
  112. #define AM_HAL_PDM_PCFG_LEFT_PGA_M15DB AM_REG_PDM_PCFG_PGALEFT_M15DB
  113. #define AM_HAL_PDM_PCFG_LEFT_PGA_M300DB AM_REG_PDM_PCFG_PGALEFT_M300DB
  114. #define AM_HAL_PDM_PCFG_LEFT_PGA_M45DB AM_REG_PDM_PCFG_PGALEFT_M45DB
  115. #define AM_HAL_PDM_PCFG_LEFT_PGA_M60DB AM_REG_PDM_PCFG_PGALEFT_M60DB
  116. #define AM_HAL_PDM_PCFG_LEFT_PGA_M75DB AM_REG_PDM_PCFG_PGALEFT_M75DB
  117. #define AM_HAL_PDM_PCFG_LEFT_PGA_M90DB AM_REG_PDM_PCFG_PGALEFT_M90DB
  118. #define AM_HAL_PDM_PCFG_LEFT_PGA_M105DB AM_REG_PDM_PCFG_PGALEFT_M105DB
  119. #define AM_HAL_PDM_PCFG_LEFT_PGA_M120DB AM_REG_PDM_PCFG_PGALEFT_M120DB
  120. #define AM_HAL_PDM_PCFG_LEFT_PGA_P105DB AM_REG_PDM_PCFG_PGALEFT_P105DB
  121. #define AM_HAL_PDM_PCFG_LEFT_PGA_P90DB AM_REG_PDM_PCFG_PGALEFT_P90DB
  122. #define AM_HAL_PDM_PCFG_LEFT_PGA_P75DB AM_REG_PDM_PCFG_PGALEFT_P75DB
  123. #define AM_HAL_PDM_PCFG_LEFT_PGA_P60DB AM_REG_PDM_PCFG_PGALEFT_P60DB
  124. #define AM_HAL_PDM_PCFG_LEFT_PGA_P45DB AM_REG_PDM_PCFG_PGALEFT_P45DB
  125. #define AM_HAL_PDM_PCFG_LEFT_PGA_P300DB AM_REG_PDM_PCFG_PGALEFT_P300DB
  126. #define AM_HAL_PDM_PCFG_LEFT_PGA_P15DB AM_REG_PDM_PCFG_PGALEFT_P15DB
  127. #define AM_HAL_PDM_PCFG_LEFT_PGA_0DB AM_REG_PDM_PCFG_PGALEFT_0DB
  128. //! @}
  129. //*****************************************************************************
  130. //
  131. //! @name PDM Configuration MCLK Divider
  132. //! @brief Macro definitions for the PDM MCLK Divider
  133. //!
  134. //! These macros may be used with the am_hal_pdm_config_t structure to set the
  135. //! sinc decimation rate relative to the PDM sample clock (OSR).
  136. //!
  137. //! @{
  138. //
  139. //*****************************************************************************
  140. #define AM_HAL_PDM_PCFG_MCLKDIV_DIV1 AM_REG_PDM_PCFG_MCLKDIV_MCKDIV1
  141. #define AM_HAL_PDM_PCFG_MCLKDIV_DIV2 AM_REG_PDM_PCFG_MCLKDIV_MCKDIV2
  142. #define AM_HAL_PDM_PCFG_MCLKDIV_DIV3 AM_REG_PDM_PCFG_MCLKDIV_MCKDIV3
  143. #define AM_HAL_PDM_PCFG_MCLKDIV_DIV4 AM_REG_PDM_PCFG_MCLKDIV_MCKDIV4
  144. #define AM_HAL_PDM_PCFG_MCLKDIV(DIV) AM_REG_PDM_PCFG_MCLKDIV(DIV)
  145. //! @}
  146. //*****************************************************************************
  147. //
  148. //! @name PDM Configuration SINC Decimation Rate
  149. //! @brief Macro definitions for the PDM SINC decimation rate
  150. //!
  151. //! These macros may be used with the am_hal_pdm_config_t structure to set the
  152. //! sinc decimation rate relative to the PDM sample clock (OSR).
  153. //!
  154. //! @{
  155. //
  156. //*****************************************************************************
  157. #define AM_HAL_PDM_PCFG_SINC_RATE(OSR) \
  158. AM_REG_PDM_PCFG_SINCRATE(OSR)
  159. //! @}
  160. //*****************************************************************************
  161. //
  162. //! @name PDM Configuration High Pass Filter Enable
  163. //! @brief Macro definitions for the PDM ADCHPD
  164. //!
  165. //! These macros may be used with the am_hal_pdm_config_t structure to enable
  166. //! the high pass filter.
  167. //!
  168. //! @{
  169. //
  170. //*****************************************************************************
  171. #define AM_HAL_PDM_PCFG_ADCHPD_ENABLE AM_REG_PDM_PCFG_ADCHPD_EN
  172. #define AM_HAL_PDM_PCFG_ADCHPD_DISABLE AM_REG_PDM_PCFG_ADCHPD_DIS
  173. //! @}
  174. //*****************************************************************************
  175. //
  176. //! @name PDM Configuration HPCUTOFF
  177. //! @brief Macro definitions for the PDM High Pass Filter Cutoff Selector.
  178. //!
  179. //! These macros may be used with the am_hal_pdm_config_t structure to set the
  180. //! high pass filter cutoff frequency. Valid range is 0 to 7.
  181. //!
  182. //! @{
  183. //
  184. //*****************************************************************************
  185. #define AM_HAL_PDM_PCFG_HPCUTOFF(HPSEL) \
  186. AM_REG_PDM_PCFG_HPCUTOFF(HPSEL)
  187. //! @}
  188. //*****************************************************************************
  189. //
  190. //! @name PDM Configuration Gain Set Change Clock Delay
  191. //! @brief Macro definitions for the PDM clock delay for gain set changes.
  192. //!
  193. //! These macros may be used with the am_hal_pdm_config_t structure to set the
  194. //! number of clocks for spreading gain setting changes. Valid range is 0 to 7.
  195. //!
  196. //! @{
  197. //
  198. //*****************************************************************************
  199. #define AM_HAL_PDM_PCFG_CYCLES(CLOCKS) \
  200. AM_REG_PDM_PCFG_CYCLES(CLOCKS)
  201. //! @}
  202. //*****************************************************************************
  203. //
  204. //! @name PDM Configuration SOFTMUTE enable/disable.
  205. //! @brief Macro definitions for the PDM PCFG register mute controls.
  206. //!
  207. //! These macros may be used with the am_hal_pdm_config_t structure to enable
  208. //! or disable the SOFTMUTE option.
  209. //!
  210. //! @{
  211. //
  212. //*****************************************************************************
  213. #define AM_HAL_PDM_PCFG_SOFTMUTE_ENABLE AM_REG_PDM_PCFG_SOFTMUTE_EN
  214. #define AM_HAL_PDM_PCFG_SOFTMUTE_DISABLE AM_REG_PDM_PCFG_SOFTMUTE_DIS
  215. //! @}
  216. //*****************************************************************************
  217. //
  218. //! @name PDM Configuration PDM Core enable/disable.
  219. //! @brief Macro definitions for the PDM PCFG register filter engine enable.
  220. //!
  221. //! These macros may be used with the am_hal_pdm_config_t structure to enable
  222. //! or disable the PDM filter engine core.
  223. //!
  224. //! @{
  225. //
  226. //*****************************************************************************
  227. #define AM_HAL_PDM_PCFG_PDMCORE_ENABLE AM_REG_PDM_PCFG_PDMCORE_EN
  228. #define AM_HAL_PDM_PCFG_PDMCORE_DISABLE AM_REG_PDM_PCFG_PDMCORE_DIS
  229. //! @}
  230. //*****************************************************************************
  231. //
  232. //! @name PDM Clock Frequencies
  233. //! @brief Macro definitions for the PDM clock (from clkgen) frequencies.
  234. //!
  235. //! These macros may be used with the am_hal_pdm_config_t structure to set the
  236. //! source clock frequency of the PDM interface.
  237. //!
  238. //! @{
  239. //
  240. //*****************************************************************************
  241. #define AM_HAL_PDM_IOCLK_12MHZ \
  242. (AM_REG_PDM_VCFG_PDMCLKSEL_12MHz | AM_REG_PDM_VCFG_IOCLKEN_EN)
  243. #define AM_HAL_PDM_IOCLK_6MHZ \
  244. (AM_REG_PDM_VCFG_PDMCLKSEL_6MHz | AM_REG_PDM_VCFG_IOCLKEN_EN)
  245. #define AM_HAL_PDM_IOCLK_3MHZ \
  246. (AM_REG_PDM_VCFG_PDMCLKSEL_3MHz | AM_REG_PDM_VCFG_IOCLKEN_EN)
  247. #define AM_HAL_PDM_IOCLK_1_5MHZ \
  248. (AM_REG_PDM_VCFG_PDMCLKSEL_1_5MHz | AM_REG_PDM_VCFG_IOCLKEN_EN)
  249. #define AM_HAL_PDM_IOCLK_750KHZ \
  250. (AM_REG_PDM_VCFG_PDMCLKSEL_750KHz | AM_REG_PDM_VCFG_IOCLKEN_EN)
  251. #define AM_HAL_PDM_IOCLK_375KHZ \
  252. (AM_REG_PDM_VCFG_PDMCLKSEL_375KHz | AM_REG_PDM_VCFG_IOCLKEN_EN)
  253. #define AM_HAL_PDM_IOCLK_187KHZ \
  254. (AM_REG_PDM_VCFG_PDMCLKSEL_187KHz | AM_REG_PDM_VCFG_IOCLKEN_EN)
  255. //! @}
  256. //*****************************************************************************
  257. //
  258. //! @name PDM Voice Configuration RSTB
  259. //! @brief Reset the IP core.
  260. //!
  261. //! @{
  262. //
  263. //*****************************************************************************
  264. #define AM_HAL_PDM_VCFG_RSTB_RESET AM_REG_PDM_VCFG_RSTB_RESET
  265. #define AM_HAL_PDM_VCFG_RSTB_NORMAL AM_REG_PDM_VCFG_RSTB_NORM
  266. //! @}
  267. //*****************************************************************************
  268. //
  269. //! @name PDM Voice Configuration PDM Clock Enable/Disable
  270. //! @brief Macro definitions for the PDM VCFG register PDMCLKEN.
  271. //!
  272. //! These macros may be used with the am_hal_pdm_config_t structure to enable
  273. //! or disable the PDM clock output to the pad mux and from there to the world.
  274. //!
  275. //! @{
  276. //
  277. //*****************************************************************************
  278. #define AM_HAL_PDM_VCFG_PDMCLK_ENABLE AM_REG_PDM_VCFG_PDMCLK_EN
  279. #define AM_HAL_PDM_VCFG_PDMCLK_DISABLE AM_REG_PDM_VCFG_PDMCLK_DIS
  280. //! @}
  281. //*****************************************************************************
  282. //
  283. //! @name PDM Voice Configuration I2S Mode Enable/Disable
  284. //! @brief Macro definitions for the PDM VCFG register I2SMODE.
  285. //!
  286. //! These macros may be used with the am_hal_pdm_config_t structure to enable
  287. //! or disable the PDM clock output to the pad mux and from there to the world.
  288. //!
  289. //! @{
  290. //
  291. //*****************************************************************************
  292. #define AM_HAL_PDM_VCFG_I2SMODE_ENABLE AM_REG_PDM_VCFG_I2SMODE_EN
  293. #define AM_HAL_PDM_VCFG_I2SMODE_DISABLE AM_REG_PDM_VCFG_I2SMODE_DIS
  294. //! @}
  295. //*****************************************************************************
  296. //
  297. //! @name PDM Voice Configuration BCLK Inversion Enable/Disable
  298. //! @brief Macro definitions for the PDM VCFG register BCLKINV.
  299. //!
  300. //! These macros may be used with the am_hal_pdm_config_t structure to enable
  301. //! or disable the PDM clock output to the pad mux and from there to the world.
  302. //!
  303. //! @{
  304. //
  305. //*****************************************************************************
  306. #define AM_HAL_PDM_VCFG_BCLKINV_ENABLE AM_REG_PDM_VCFG_BCLKINV_INV
  307. #define AM_HAL_PDM_VCFG_BCLKINV_DISABLE AM_REG_PDM_VCFG_BCLKINV_NORM
  308. //! @}
  309. //*****************************************************************************
  310. //
  311. //! @name PDM Voice Configuration DMICDEL Enable/Disable
  312. //! @brief Macro definitions for the PDM VCFG register Digital Mic Delay.
  313. //!
  314. //! These macros may be used with the am_hal_pdm_config_t structure to enable
  315. //! or disable the PDM digital microphone clock delay.
  316. //!
  317. //! @{
  318. //
  319. //*****************************************************************************
  320. #define AM_HAL_PDM_VCFG_DMICDEL_1CYC AM_REG_PDM_VCFG_DMICKDEL_1CYC
  321. #define AM_HAL_PDM_VCFG_DMICDEL_0CYC AM_REG_PDM_VCFG_DMICKDEL_0CYC
  322. #define AM_HAL_PDM_VCFG_DMICDEL_ENABLE AM_REG_PDM_VCFG_DMICKDEL_1CYC
  323. #define AM_HAL_PDM_VCFG_DMICDEL_DISABLE AM_REG_PDM_VCFG_DMICKDEL_0CYC
  324. //! @}
  325. //*****************************************************************************
  326. //
  327. //! @name PDM Voice Configuration Select Apps Processor (AP) versus Internal
  328. //! @brief Macro definitions for the PDM VCFG register Digital Mic Delay.
  329. //!
  330. //! These macros may be used with the am_hal_pdm_config_t structure to select
  331. //! the Application Processor (I2S slave) mode or the Internal FIFO interface
  332. //! to the Apollo Cortex M4.
  333. //!
  334. //! @{
  335. //
  336. //*****************************************************************************
  337. #define AM_HAL_PDM_VCFG_SELAP_I2S AM_REG_PDM_VCFG_SELAP_I2S
  338. #define AM_HAL_PDM_VCFG_SELAP_INTERNAL AM_REG_PDM_VCFG_SELAP_INTERNAL
  339. #define AM_HAL_PDM_VCFG_SELAP_AP_I2S AM_REG_PDM_VCFG_SELAP_I2S
  340. #define AM_HAL_PDM_VCFG_SELAP_CM4_FIFO AM_REG_PDM_VCFG_SELAP_INTERNAL
  341. //! @}
  342. //*****************************************************************************
  343. //
  344. //! @name PDM Voice Configuration PACK Enable/Disable
  345. //! @brief Macro definitions for the PDM VCFG register sample packing mode.
  346. //!
  347. //! These macros may be used with the am_hal_pdm_config_t structure to enable
  348. //! or disable the PDM sample packing mode. This mode puts two 16-bit samples
  349. //! per 32-bit FIFO word. The following packed modes are available:
  350. //!
  351. //! mono left: LEFT_NEW, LEFT_OLD
  352. //! mono right: RIGHT_NEW,RIGHT_OLD
  353. //! stereo right: LEFT, RIGHT
  354. //! stereo right(LRSWAP): RIGHT, LEFT
  355. //!
  356. //!
  357. //!
  358. //! @{
  359. //
  360. //*****************************************************************************
  361. #define AM_HAL_PDM_VCFG_PACK_ENABLE AM_REG_PDM_VCFG_PCMPACK_EN
  362. #define AM_HAL_PDM_VCFG_PACK_DISABLE AM_REG_PDM_VCFG_PCMPACK_DIS
  363. //! @}
  364. //*****************************************************************************
  365. //
  366. //! @name PDM Channel Selects
  367. //! @brief Macro definitions for the PDM Channel Selection.
  368. //!
  369. //! These macros may be used with the am_hal_pdm_config_t structure to set the
  370. //! channel selection for the PDM interface.
  371. //!
  372. //! @{
  373. //
  374. //*****************************************************************************
  375. #define AM_HAL_PDM_VCFG_CHANNEL_LEFT AM_REG_PDM_VCFG_CHSET_LEFT
  376. #define AM_HAL_PDM_VCFG_CHANNEL_RIGHT AM_REG_PDM_VCFG_CHSET_RIGHT
  377. #define AM_HAL_PDM_VCFG_CHANNEL_STEREO AM_REG_PDM_VCFG_CHSET_STEREO
  378. //! @}
  379. //*****************************************************************************
  380. //
  381. //! @name PDM Interrupts
  382. //! @brief Macro definitions for the PDM interrupt status bits.
  383. //!
  384. //! These macros correspond to the bits in the PDM interrupt status register.
  385. //! They may be used for any of the am_hal_pdm_int_x() functions.
  386. //!
  387. //! @{
  388. //
  389. //*****************************************************************************
  390. #define AM_HAL_PDM_INT_UNDFL AM_REG_PDM_INTEN_UNDFL_M
  391. #define AM_HAL_PDM_INT_OVF AM_REG_PDM_INTEN_OVF_M
  392. #define AM_HAL_PDM_INT_FIFO AM_REG_PDM_INTEN_THR_M
  393. //! @}
  394. //*****************************************************************************
  395. //
  396. //! @brief Configuration structure for the PDM module.
  397. //
  398. //*****************************************************************************
  399. typedef struct
  400. {
  401. //
  402. //! @brief Set the PDM configuration reg with the values in this member.
  403. //! Choose from AM_HAL_PDM_PCFG macros.
  404. //! AM_HAL_PDM_PCFG_LRSWAP_xxx
  405. //! AM_HAL_PDM_PCFG_RIGHT_PGA_xxx
  406. //! AM_HAL_PDM_PCFG_LEFT_PGA_xxx
  407. //! AM_HAL_PDM_PCFG_MCLKDIV_xxx
  408. //! AM_HAL_PDM_PCFG_SINC_RATE()
  409. //! AM_HAL_PDM_PCFG_ADCHPD_xxx
  410. //! AM_HAL_PDM_PCFG_HPCUTOFF()
  411. //! AM_HAL_PDM_PCFG_CYCLES()
  412. //! AM_HAL_PDM_PCFG_SOFTMUTE_xxx
  413. //! * AM_HAL_PDM_PCFG_PDMCORE_EN
  414. //! AM_HAL_PDM_PCFG_PDMCORE_DISABLE
  415. //
  416. uint32_t ui32PDMConfigReg;
  417. //
  418. //! @brief Set the Voice Configuration reg with the values in this member.
  419. //! Choose from AM_HAL_PDM_VCFG macros.
  420. //! AM_HAL_PDM_IOCLK_xxx (also sets AM_REG_PDM_VCFG_IOCLKEN_EN)
  421. //! * AM_REG_PDM_VCFG_IOCLKEN_EN
  422. //! * AM_HAL_PDM_VCFG_RSTB_RESET
  423. //! AM_HAL_PDM_VCFG_RSTB_NORMAL
  424. //! * AM_HAL_PDM_VCFG_PDMCLK_EN
  425. //! AM_HAL_PDM_VCFG_PDMCLK_DIS
  426. //! AM_HAL_PDM_VCFG_I2SMODE_xxx
  427. //! AM_HAL_PDM_VCFG_BCLKINV_xxx
  428. //! AM_HAL_PDM_VCFG_DMICDEL_xxx
  429. //! AM_HAL_PDM_VCFG_SELAP_xxx
  430. //! AM_HAL_PDM_VCFG_PACK_xxx
  431. //! AM_HAL_PDM_VCFG_CHANNEL_xxx
  432. //!
  433. //! * = These bits are set or cleared by the HAL PDM functions
  434. //! am_hal_pdm_enable() or am_hal_pdm_disable().
  435. //
  436. uint32_t ui32VoiceConfigReg;
  437. //
  438. //! @brief Select the FIFO PCM sample threshold.
  439. //!
  440. //! The PDM controller will generate a processor interrupt when the number
  441. //! of entries in the FIFO goes *above* this number.
  442. //
  443. uint32_t ui32FIFOThreshold;
  444. } am_hal_pdm_config_t;
  445. //*****************************************************************************
  446. //
  447. // Define function-like macros.
  448. //
  449. //*****************************************************************************
  450. //*****************************************************************************
  451. //
  452. //! @brief Read the FIFO depth information as an in-line macro
  453. //
  454. //*****************************************************************************
  455. #define am_hal_pdm_fifo_depth_read() (AM_REG(PDM, FR))
  456. //*****************************************************************************
  457. //
  458. //! @brief Read the FIFO READ DATA as an in-line macro
  459. //
  460. //*****************************************************************************
  461. #define am_hal_pdm_fifo_data_read() (AM_REG(PDM, FRD))
  462. //*****************************************************************************
  463. //
  464. //! @brief Flush the FIFO as an in-line macro
  465. //
  466. //*****************************************************************************
  467. #define am_hal_pdm_fifo_flush() (AM_REG(PDM, FLUSH) = 0)
  468. //*****************************************************************************
  469. //
  470. //! @brief Set the PDM Configuration (PCFG) Register
  471. //!
  472. //! This function sets the PDM configuration register
  473. //
  474. //*****************************************************************************
  475. #define am_hal_pdm_pcfg_set(Value) (AM_REG(PDM, PCFG) = Value)
  476. //*****************************************************************************
  477. //
  478. //! @brief Get the PCFG register value from PDM module.
  479. //
  480. //*****************************************************************************
  481. #define am_hal_pdm_pcfg_get() (AM_REG(PDM, PCFG))
  482. //*****************************************************************************
  483. //
  484. //! @brief Set the Voice Configuration (VCFG) Register
  485. //
  486. //*****************************************************************************
  487. #define am_hal_pdm_vcfg_set(Value) (AM_REG(PDM, VCFG) = Value)
  488. //*****************************************************************************
  489. //
  490. //! @brief Get the VCFG register value from PDM module.
  491. //
  492. //*****************************************************************************
  493. #define am_hal_pdm_vcfg_get() (AM_REG(PDM, VCFG))
  494. //*****************************************************************************
  495. //
  496. //! @brief Set the FIFO Threshold
  497. //
  498. //*****************************************************************************
  499. #define am_hal_pdm_thresh_set(thresh) (AM_REG(PDM, FTHR) = thresh)
  500. //*****************************************************************************
  501. //
  502. //! @brief Get the FIFO Threshold register value from PDM module.
  503. //
  504. //*****************************************************************************
  505. #define am_hal_pdm_thresh_get() (AM_REG(PDM, FTHR))
  506. //*****************************************************************************
  507. //
  508. //! @brief Set the left microphone PGA gain.
  509. //!
  510. //*****************************************************************************
  511. #define am_hal_pdm_left_gain_set(gain) (AM_BFW(PDM, PCFG, PGALEFT, gain))
  512. //*****************************************************************************
  513. //
  514. //! @brief Set the right microphone PGA gain.
  515. //
  516. //*****************************************************************************
  517. #define am_hal_pdm_right_gain_set(gain) (AM_BFW(PDM, PCFG, PGARIGHT, gain))
  518. //*****************************************************************************
  519. //
  520. //! @brief Get the left microphone PGA gain value.
  521. //
  522. //*****************************************************************************
  523. #define am_hal_pdm_left_gain_get() (AM_BFR(PDM, PCFG, PGALEFT))
  524. //*****************************************************************************
  525. //
  526. //! @brief Get the right microphone PGA gain value.
  527. //
  528. //*****************************************************************************
  529. #define am_hal_pdm_right_gain_get() (AM_BFR(PDM, PCFG, PGARIGHT))
  530. //*****************************************************************************
  531. //
  532. //! @brief Enable the Soft Mute functionality.
  533. //
  534. //*****************************************************************************
  535. #define am_hal_pdm_soft_mute_enable() (AM_BFWe(PDM, PCFG, SOFTMUTE, EN))
  536. //*****************************************************************************
  537. //
  538. //! @brief Disable the Soft Mute functionality.
  539. //
  540. //*****************************************************************************
  541. #define am_hal_pdm_soft_mute_disable() (AM_BFWe(PDM, PCFG, SOFTMUTE, DIS))
  542. //*****************************************************************************
  543. //
  544. //! @brief Enable selected PDM Interrupts.
  545. //!
  546. //! @param ui32Interrupt - Use the macro bit fields provided in am_hal_pdm.h\n
  547. //! AM_HAL_PDM_INT_UNDFL\n
  548. //! AM_HAL_PDM_INT_OVF\n
  549. //! AM_HAL_PDM_INT_FIFO\n
  550. //
  551. //*****************************************************************************
  552. #define am_hal_pdm_int_enable(intrpt) (AM_REG(PDM, INTEN) |= intrpt)
  553. //*****************************************************************************
  554. //
  555. //! @brief Return the enabled PDM Interrupts.
  556. //!
  557. //! Use this function to return all enabled PDM interrupts.
  558. //!
  559. //! @return all enabled PDM interrupts as a mask.\n
  560. //! AM_HAL_PDM_INT_UNDFL\n
  561. //! AM_HAL_PDM_INT_OVF\n
  562. //! AM_HAL_PDM_INT_FIFO\n
  563. //
  564. //*****************************************************************************
  565. #define am_hal_pdm_int_enable_get() (AM_REG(PDM, INTEN))
  566. //*****************************************************************************
  567. //
  568. //! @brief Disable selected PDM Interrupts.
  569. //!
  570. //! @param ui32Interrupt - Use the macro bit fields provided in am_hal_pdm.h\n
  571. //! AM_HAL_PDM_INT_UNDFL\n
  572. //! AM_HAL_PDM_INT_OVF\n
  573. //! AM_HAL_PDM_INT_FIFO\n
  574. //
  575. //*****************************************************************************
  576. #define am_hal_pdm_int_disable(intrpt) (AM_REG(PDM, INTEN) &= ~intrpt)
  577. //*****************************************************************************
  578. //
  579. //! @brief Clear selected PDM Interrupts.
  580. //!
  581. //! @param ui32Interrupt - Use the macro bit fields provided in am_hal_pdm.h\n
  582. //! AM_HAL_PDM_INT_UNDFL\n
  583. //! AM_HAL_PDM_INT_OVF\n
  584. //! AM_HAL_PDM_INT_FIFO\n
  585. //
  586. //*****************************************************************************
  587. #define am_hal_pdm_int_clear(intrpt) (AM_REG(PDM, INTCLR) = intrpt)
  588. //*****************************************************************************
  589. //
  590. //! @brief Set selected PDM Interrupts.
  591. //!
  592. //! Use this function to set the PDM interrupts.
  593. //!
  594. //! @param ui32Interrupt - Use the macro bit fields provided in am_hal_pdm.h\n
  595. //! AM_HAL_PDM_INT_UNDFL\n
  596. //! AM_HAL_PDM_INT_OVF\n
  597. //! AM_HAL_PDM_INT_FIFO\n
  598. //
  599. //*****************************************************************************
  600. #define am_hal_pdm_int_set(intrpt) (AM_REG(PDM, INTSET) = intrpt)
  601. //*****************************************************************************
  602. //
  603. // External function definitions
  604. //
  605. //*****************************************************************************
  606. extern void am_hal_pdm_config(am_hal_pdm_config_t * cfg);
  607. extern void am_hal_pdm_enable(void);
  608. extern void am_hal_pdm_disable(void);
  609. extern uint32_t am_hal_pdm_int_status_get(bool bEnabledOnly);
  610. #ifdef __cplusplus
  611. }
  612. #endif
  613. #endif // AM_HAL_PDM_H
  614. //*****************************************************************************
  615. //
  616. // End Doxygen group.
  617. //! @}
  618. //
  619. //*****************************************************************************