am_hal_pdm.h 26 KB

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