nrf_i2s.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. /**
  13. * @defgroup nrf_i2s_hal I2S HAL
  14. * @{
  15. * @ingroup nrf_i2s
  16. *
  17. * @brief @tagAPI52 Hardware access layer for managing the Inter-IC Sound (I2S) peripheral.
  18. */
  19. #ifndef NRF_I2S_H__
  20. #define NRF_I2S_H__
  21. #include <stddef.h>
  22. #include <stdbool.h>
  23. #include <stdint.h>
  24. #include "nrf.h"
  25. /**
  26. * @brief This value can be provided as a parameter for the @ref nrf_i2s_pins_set
  27. * function call to specify that a given I2S signal (SDOUT, SDIN, or MCK)
  28. * shall not be connected to a physical pin.
  29. */
  30. #define NRF_I2S_PIN_NOT_CONNECTED 0xFFFFFFFF
  31. /**
  32. * @brief I2S tasks.
  33. */
  34. typedef enum
  35. {
  36. /*lint -save -e30*/
  37. NRF_I2S_TASK_START = offsetof(NRF_I2S_Type, TASKS_START), ///< Starts continuous I2S transfer. Also starts the MCK generator if this is enabled.
  38. NRF_I2S_TASK_STOP = offsetof(NRF_I2S_Type, TASKS_STOP) ///< Stops I2S transfer. Also stops the MCK generator.
  39. /*lint -restore*/
  40. } nrf_i2s_task_t;
  41. /**
  42. * @brief I2S events.
  43. */
  44. typedef enum
  45. {
  46. /*lint -save -e30*/
  47. NRF_I2S_EVENT_RXPTRUPD = offsetof(NRF_I2S_Type, EVENTS_RXPTRUPD), ///< The RXD.PTR register has been copied to internal double-buffers.
  48. NRF_I2S_EVENT_TXPTRUPD = offsetof(NRF_I2S_Type, EVENTS_TXPTRUPD), ///< The TXD.PTR register has been copied to internal double-buffers.
  49. NRF_I2S_EVENT_STOPPED = offsetof(NRF_I2S_Type, EVENTS_STOPPED) ///< I2S transfer stopped.
  50. /*lint -restore*/
  51. } nrf_i2s_event_t;
  52. /**
  53. * @brief I2S interrupts.
  54. */
  55. typedef enum
  56. {
  57. NRF_I2S_INT_RXPTRUPD_MASK = I2S_INTENSET_RXPTRUPD_Msk, ///< Interrupt on RXPTRUPD event.
  58. NRF_I2S_INT_TXPTRUPD_MASK = I2S_INTENSET_TXPTRUPD_Msk, ///< Interrupt on TXPTRUPD event.
  59. NRF_I2S_INT_STOPPED_MASK = I2S_INTENSET_STOPPED_Msk ///< Interrupt on STOPPED event.
  60. } nrf_i2s_int_mask_t;
  61. /**
  62. * @brief I2S modes of operation.
  63. */
  64. typedef enum
  65. {
  66. NRF_I2S_MODE_MASTER = I2S_CONFIG_MODE_MODE_Master, ///< Master mode.
  67. NRF_I2S_MODE_SLAVE = I2S_CONFIG_MODE_MODE_Slave ///< Slave mode.
  68. } nrf_i2s_mode_t;
  69. /**
  70. * @brief I2S master clock generator settings.
  71. */
  72. typedef enum
  73. {
  74. NRF_I2S_MCK_DISABLED = 0, ///< MCK disabled.
  75. // [conversion to 'int' needed to prevent compilers from complaining
  76. // that the provided value (0x80000000UL) is out of range of "int"]
  77. NRF_I2S_MCK_32MDIV2 = (int)I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV2, ///< 32 MHz / 2 = 16.0 MHz.
  78. NRF_I2S_MCK_32MDIV3 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV3, ///< 32 MHz / 3 = 10.6666667 MHz.
  79. NRF_I2S_MCK_32MDIV4 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV4, ///< 32 MHz / 4 = 8.0 MHz.
  80. NRF_I2S_MCK_32MDIV5 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV5, ///< 32 MHz / 5 = 6.4 MHz.
  81. NRF_I2S_MCK_32MDIV6 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV6, ///< 32 MHz / 6 = 5.3333333 MHz.
  82. NRF_I2S_MCK_32MDIV8 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV8, ///< 32 MHz / 8 = 4.0 MHz.
  83. NRF_I2S_MCK_32MDIV10 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV10, ///< 32 MHz / 10 = 3.2 MHz.
  84. NRF_I2S_MCK_32MDIV11 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV11, ///< 32 MHz / 11 = 2.9090909 MHz.
  85. NRF_I2S_MCK_32MDIV15 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV15, ///< 32 MHz / 15 = 2.1333333 MHz.
  86. NRF_I2S_MCK_32MDIV16 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV16, ///< 32 MHz / 16 = 2.0 MHz.
  87. NRF_I2S_MCK_32MDIV21 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV21, ///< 32 MHz / 21 = 1.5238095 MHz.
  88. NRF_I2S_MCK_32MDIV23 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV23, ///< 32 MHz / 23 = 1.3913043 MHz.
  89. NRF_I2S_MCK_32MDIV31 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV31, ///< 32 MHz / 31 = 1.0322581 MHz.
  90. NRF_I2S_MCK_32MDIV42 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV42, ///< 32 MHz / 42 = 0.7619048 MHz.
  91. NRF_I2S_MCK_32MDIV63 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV63, ///< 32 MHz / 63 = 0.5079365 MHz.
  92. NRF_I2S_MCK_32MDIV125 = I2S_CONFIG_MCKFREQ_MCKFREQ_32MDIV125 ///< 32 MHz / 125 = 0.256 MHz.
  93. } nrf_i2s_mck_t;
  94. /**
  95. * @brief I2S MCK/LRCK ratios.
  96. */
  97. typedef enum
  98. {
  99. NRF_I2S_RATIO_32X = I2S_CONFIG_RATIO_RATIO_32X, ///< LRCK = MCK / 32.
  100. NRF_I2S_RATIO_48X = I2S_CONFIG_RATIO_RATIO_48X, ///< LRCK = MCK / 48.
  101. NRF_I2S_RATIO_64X = I2S_CONFIG_RATIO_RATIO_64X, ///< LRCK = MCK / 64.
  102. NRF_I2S_RATIO_96X = I2S_CONFIG_RATIO_RATIO_96X, ///< LRCK = MCK / 96.
  103. NRF_I2S_RATIO_128X = I2S_CONFIG_RATIO_RATIO_128X, ///< LRCK = MCK / 128.
  104. NRF_I2S_RATIO_192X = I2S_CONFIG_RATIO_RATIO_192X, ///< LRCK = MCK / 192.
  105. NRF_I2S_RATIO_256X = I2S_CONFIG_RATIO_RATIO_256X, ///< LRCK = MCK / 256.
  106. NRF_I2S_RATIO_384X = I2S_CONFIG_RATIO_RATIO_384X, ///< LRCK = MCK / 384.
  107. NRF_I2S_RATIO_512X = I2S_CONFIG_RATIO_RATIO_512X ///< LRCK = MCK / 512.
  108. } nrf_i2s_ratio_t;
  109. /**
  110. * @brief I2S sample widths.
  111. */
  112. typedef enum
  113. {
  114. NRF_I2S_SWIDTH_8BIT = I2S_CONFIG_SWIDTH_SWIDTH_8Bit, ///< 8 bit.
  115. NRF_I2S_SWIDTH_16BIT = I2S_CONFIG_SWIDTH_SWIDTH_16Bit, ///< 16 bit.
  116. NRF_I2S_SWIDTH_24BIT = I2S_CONFIG_SWIDTH_SWIDTH_24Bit ///< 24 bit.
  117. } nrf_i2s_swidth_t;
  118. /**
  119. * @brief I2S alignments of sample within a frame.
  120. */
  121. typedef enum
  122. {
  123. NRF_I2S_ALIGN_LEFT = I2S_CONFIG_ALIGN_ALIGN_Left, ///< Left-aligned.
  124. NRF_I2S_ALIGN_RIGHT = I2S_CONFIG_ALIGN_ALIGN_Right ///< Right-aligned.
  125. } nrf_i2s_align_t;
  126. /**
  127. * @brief I2S frame formats.
  128. */
  129. typedef enum
  130. {
  131. NRF_I2S_FORMAT_I2S = I2S_CONFIG_FORMAT_FORMAT_I2S, ///< Original I2S format.
  132. NRF_I2S_FORMAT_ALIGNED = I2S_CONFIG_FORMAT_FORMAT_Aligned ///< Alternate (left- or right-aligned) format.
  133. } nrf_i2s_format_t;
  134. /**
  135. * @brief I2S enabled channels.
  136. */
  137. typedef enum
  138. {
  139. NRF_I2S_CHANNELS_STEREO = I2S_CONFIG_CHANNELS_CHANNELS_Stereo, ///< Stereo.
  140. NRF_I2S_CHANNELS_LEFT = I2S_CONFIG_CHANNELS_CHANNELS_Left, ///< Left only.
  141. NRF_I2S_CHANNELS_RIGHT = I2S_CONFIG_CHANNELS_CHANNELS_Right ///< Right only.
  142. } nrf_i2s_channels_t;
  143. /**
  144. * @brief Function for activating a specific I2S task.
  145. *
  146. * @param[in] p_i2s I2S instance.
  147. * @param[in] task Task to activate.
  148. */
  149. __STATIC_INLINE void nrf_i2s_task_trigger(NRF_I2S_Type * p_i2s,
  150. nrf_i2s_task_t task);
  151. /**
  152. * @brief Function for getting the address of a specific I2S task register.
  153. *
  154. * @param[in] p_i2s I2S instance.
  155. * @param[in] task Requested task.
  156. *
  157. * @return Address of the specified task register.
  158. */
  159. __STATIC_INLINE uint32_t nrf_i2s_task_address_get(NRF_I2S_Type const * p_i2s,
  160. nrf_i2s_task_t task);
  161. /**
  162. * @brief Function for clearing a specific I2S event.
  163. *
  164. * @param[in] p_i2s I2S instance.
  165. * @param[in] event Event to clear.
  166. */
  167. __STATIC_INLINE void nrf_i2s_event_clear(NRF_I2S_Type * p_i2s,
  168. nrf_i2s_event_t event);
  169. /**
  170. * @brief Function for checking the state of a specific I2S event.
  171. *
  172. * @param[in] p_i2s I2S instance.
  173. * @param[in] event Event to check.
  174. *
  175. * @retval true If the event is set.
  176. * @retval false If the event is not set.
  177. */
  178. __STATIC_INLINE bool nrf_i2s_event_check(NRF_I2S_Type const * p_i2s,
  179. nrf_i2s_event_t event);
  180. /**
  181. * @brief Function for getting the address of a specific I2S event register.
  182. *
  183. * @param[in] p_i2s I2S instance.
  184. * @param[in] event Requested event.
  185. *
  186. * @return Address of the specified event register.
  187. */
  188. __STATIC_INLINE uint32_t nrf_i2s_event_address_get(NRF_I2S_Type const * p_i2s,
  189. nrf_i2s_event_t event);
  190. /**
  191. * @brief Function for enabling specified interrupts.
  192. *
  193. * @param[in] p_i2s I2S instance.
  194. * @param[in] mask Interrupts to enable.
  195. */
  196. __STATIC_INLINE void nrf_i2s_int_enable(NRF_I2S_Type * p_i2s, uint32_t mask);
  197. /**
  198. * @brief Function for disabling specified interrupts.
  199. *
  200. * @param[in] p_i2s I2S instance.
  201. * @param[in] mask Interrupts to disable.
  202. */
  203. __STATIC_INLINE void nrf_i2s_int_disable(NRF_I2S_Type * p_i2s, uint32_t mask);
  204. /**
  205. * @brief Function for retrieving the state of a given interrupt.
  206. *
  207. * @param[in] p_i2s I2S instance.
  208. * @param[in] i2s_int Interrupt to check.
  209. *
  210. * @retval true If the interrupt is enabled.
  211. * @retval false If the interrupt is not enabled.
  212. */
  213. __STATIC_INLINE bool nrf_i2s_int_enable_check(NRF_I2S_Type const * p_i2s,
  214. nrf_i2s_int_mask_t i2s_int);
  215. /**
  216. * @brief Function for enabling the I2S peripheral.
  217. *
  218. * @param[in] p_i2s I2S instance.
  219. */
  220. __STATIC_INLINE void nrf_i2s_enable(NRF_I2S_Type * p_i2s);
  221. /**
  222. * @brief Function for disabling the I2S peripheral.
  223. *
  224. * @param[in] p_i2s I2S instance.
  225. */
  226. __STATIC_INLINE void nrf_i2s_disable(NRF_I2S_Type * p_i2s);
  227. /**
  228. * @brief Function for configuring I2S pins.
  229. *
  230. * Usage of the SDOUT, SDIN, and MCK signals is optional.
  231. * If a given signal is not needed, pass the @ref NRF_I2S_PIN_NOT_CONNECTED
  232. * value instead of its pin number.
  233. *
  234. * @param[in] p_i2s I2S instance.
  235. * @param[in] sck_pin SCK pin number.
  236. * @param[in] lrck_pin LRCK pin number.
  237. * @param[in] mck_pin MCK pin number.
  238. * @param[in] sdout_pin SDOUT pin number.
  239. * @param[in] sdin_pin SDIN pin number.
  240. */
  241. __STATIC_INLINE void nrf_i2s_pins_set(NRF_I2S_Type * p_i2s,
  242. uint32_t sck_pin,
  243. uint32_t lrck_pin,
  244. uint32_t mck_pin,
  245. uint32_t sdout_pin,
  246. uint32_t sdin_pin);
  247. /**
  248. * @brief Function for setting the I2S peripheral configuration.
  249. *
  250. * @param[in] p_i2s I2S instance.
  251. * @param[in] mode Mode of operation (master or slave).
  252. * @param[in] format I2S frame format.
  253. * @param[in] alignment Alignment of sample within a frame.
  254. * @param[in] sample_width Sample width.
  255. * @param[in] channels Enabled channels.
  256. * @param[in] mck_setup Master clock generator setup.
  257. * @param[in] ratio MCK/LRCK ratio.
  258. *
  259. * @retval true If the configuration has been set successfully.
  260. * @retval false If the requested configuration is not allowed.
  261. */
  262. __STATIC_INLINE bool nrf_i2s_configure(NRF_I2S_Type * p_i2s,
  263. nrf_i2s_mode_t mode,
  264. nrf_i2s_format_t format,
  265. nrf_i2s_align_t alignment,
  266. nrf_i2s_swidth_t sample_width,
  267. nrf_i2s_channels_t channels,
  268. nrf_i2s_mck_t mck_setup,
  269. nrf_i2s_ratio_t ratio);
  270. /**
  271. * @brief Function for setting up the I2S transfer.
  272. *
  273. * This function sets up the RX and TX buffers and enables reception and/or
  274. * transmission accordingly. If the transfer in a given direction is not
  275. * required, pass NULL instead of the pointer to the corresponding buffer.
  276. *
  277. * @param[in] p_i2s I2S instance.
  278. * @param[in] size Size of the buffers (in 32-bit words).
  279. * @param[in] p_rx_buffer Pointer to the receive buffer.
  280. * Pass NULL to disable reception.
  281. * @param[in] p_tx_buffer Pointer to the transmit buffer.
  282. * Pass NULL to disable transmission.
  283. */
  284. __STATIC_INLINE void nrf_i2s_transfer_set(NRF_I2S_Type * p_i2s,
  285. uint16_t size,
  286. uint32_t * p_rx_buffer,
  287. uint32_t const * p_tx_buffer);
  288. /**
  289. * @brief Function for setting the pointer to the receive buffer.
  290. *
  291. * @note The size of the buffer can be set only by calling
  292. * @ref nrf_i2s_transfer_set.
  293. *
  294. * @param[in] p_i2s I2S instance.
  295. * @param[in] p_buffer Pointer to the receive buffer.
  296. */
  297. __STATIC_INLINE void nrf_i2s_rx_buffer_set(NRF_I2S_Type * p_i2s,
  298. uint32_t * p_buffer);
  299. /**
  300. * @brief Function for getting the pointer to the receive buffer.
  301. *
  302. * @param[in] p_i2s I2S instance.
  303. *
  304. * @return Pointer to the receive buffer.
  305. */
  306. __STATIC_INLINE uint32_t * nrf_i2s_rx_buffer_get(NRF_I2S_Type const * p_i2s);
  307. /**
  308. * @brief Function for setting the pointer to the transmit buffer.
  309. *
  310. * @note The size of the buffer can be set only by calling
  311. * @ref nrf_i2s_transfer_set.
  312. *
  313. * @param[in] p_i2s I2S instance.
  314. * @param[in] p_buffer Pointer to the transmit buffer.
  315. */
  316. __STATIC_INLINE void nrf_i2s_tx_buffer_set(NRF_I2S_Type * p_i2s,
  317. uint32_t const * p_buffer);
  318. /**
  319. * @brief Function for getting the pointer to the transmit buffer.
  320. *
  321. * @param[in] p_i2s I2S instance.
  322. *
  323. * @return Pointer to the transmit buffer.
  324. */
  325. __STATIC_INLINE uint32_t * nrf_i2s_tx_buffer_get(NRF_I2S_Type const * p_i2s);
  326. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  327. __STATIC_INLINE void nrf_i2s_task_trigger(NRF_I2S_Type * p_i2s,
  328. nrf_i2s_task_t task)
  329. {
  330. *((volatile uint32_t *)((uint8_t *)p_i2s + (uint32_t)task)) = 0x1UL;
  331. }
  332. __STATIC_INLINE uint32_t nrf_i2s_task_address_get(NRF_I2S_Type const * p_i2s,
  333. nrf_i2s_task_t task)
  334. {
  335. return ((uint32_t)p_i2s + (uint32_t)task);
  336. }
  337. __STATIC_INLINE void nrf_i2s_event_clear(NRF_I2S_Type * p_i2s,
  338. nrf_i2s_event_t event)
  339. {
  340. *((volatile uint32_t *)((uint8_t *)p_i2s + (uint32_t)event)) = 0x0UL;
  341. }
  342. __STATIC_INLINE bool nrf_i2s_event_check(NRF_I2S_Type const * p_i2s,
  343. nrf_i2s_event_t event)
  344. {
  345. return (bool)*(volatile uint32_t *)((uint8_t *)p_i2s + (uint32_t)event);
  346. }
  347. __STATIC_INLINE uint32_t nrf_i2s_event_address_get(NRF_I2S_Type const * p_i2s,
  348. nrf_i2s_event_t event)
  349. {
  350. return ((uint32_t)p_i2s + (uint32_t)event);
  351. }
  352. __STATIC_INLINE void nrf_i2s_int_enable(NRF_I2S_Type * p_i2s, uint32_t mask)
  353. {
  354. p_i2s->INTENSET = mask;
  355. }
  356. __STATIC_INLINE void nrf_i2s_int_disable(NRF_I2S_Type * p_i2s, uint32_t mask)
  357. {
  358. p_i2s->INTENCLR = mask;
  359. }
  360. __STATIC_INLINE bool nrf_i2s_int_enable_check(NRF_I2S_Type const * p_i2s,
  361. nrf_i2s_int_mask_t i2s_int)
  362. {
  363. return (bool)(p_i2s->INTENSET & i2s_int);
  364. }
  365. __STATIC_INLINE void nrf_i2s_enable(NRF_I2S_Type * p_i2s)
  366. {
  367. p_i2s->ENABLE = (I2S_ENABLE_ENABLE_Enabled << I2S_ENABLE_ENABLE_Pos);
  368. }
  369. __STATIC_INLINE void nrf_i2s_disable(NRF_I2S_Type * p_i2s)
  370. {
  371. p_i2s->ENABLE = (I2S_ENABLE_ENABLE_Disabled << I2S_ENABLE_ENABLE_Pos);
  372. }
  373. __STATIC_INLINE void nrf_i2s_pins_set(NRF_I2S_Type * p_i2s,
  374. uint32_t sck_pin,
  375. uint32_t lrck_pin,
  376. uint32_t mck_pin,
  377. uint32_t sdout_pin,
  378. uint32_t sdin_pin)
  379. {
  380. p_i2s->PSEL.SCK = sck_pin;
  381. p_i2s->PSEL.LRCK = lrck_pin;
  382. p_i2s->PSEL.MCK = mck_pin;
  383. p_i2s->PSEL.SDOUT = sdout_pin;
  384. p_i2s->PSEL.SDIN = sdin_pin;
  385. }
  386. __STATIC_INLINE bool nrf_i2s_configure(NRF_I2S_Type * p_i2s,
  387. nrf_i2s_mode_t mode,
  388. nrf_i2s_format_t format,
  389. nrf_i2s_align_t alignment,
  390. nrf_i2s_swidth_t sample_width,
  391. nrf_i2s_channels_t channels,
  392. nrf_i2s_mck_t mck_setup,
  393. nrf_i2s_ratio_t ratio)
  394. {
  395. if (mode == NRF_I2S_MODE_MASTER)
  396. {
  397. // The MCK/LRCK ratio shall be a multiple of 2 * sample width.
  398. if (((sample_width == NRF_I2S_SWIDTH_16BIT) &&
  399. (ratio == NRF_I2S_RATIO_48X))
  400. ||
  401. ((sample_width == NRF_I2S_SWIDTH_24BIT) &&
  402. ((ratio == NRF_I2S_RATIO_32X) ||
  403. (ratio == NRF_I2S_RATIO_64X) ||
  404. (ratio == NRF_I2S_RATIO_128X) ||
  405. (ratio == NRF_I2S_RATIO_256X) ||
  406. (ratio == NRF_I2S_RATIO_512X))))
  407. {
  408. return false;
  409. }
  410. }
  411. p_i2s->CONFIG.MODE = mode;
  412. p_i2s->CONFIG.FORMAT = format;
  413. p_i2s->CONFIG.ALIGN = alignment;
  414. p_i2s->CONFIG.SWIDTH = sample_width;
  415. p_i2s->CONFIG.CHANNELS = channels;
  416. p_i2s->CONFIG.RATIO = ratio;
  417. if (mck_setup == NRF_I2S_MCK_DISABLED)
  418. {
  419. p_i2s->CONFIG.MCKEN =
  420. (I2S_CONFIG_MCKEN_MCKEN_Disabled << I2S_CONFIG_MCKEN_MCKEN_Pos);
  421. }
  422. else
  423. {
  424. p_i2s->CONFIG.MCKFREQ = mck_setup;
  425. p_i2s->CONFIG.MCKEN =
  426. (I2S_CONFIG_MCKEN_MCKEN_Enabled << I2S_CONFIG_MCKEN_MCKEN_Pos);
  427. }
  428. return true;
  429. }
  430. __STATIC_INLINE void nrf_i2s_transfer_set(NRF_I2S_Type * p_i2s,
  431. uint16_t size,
  432. uint32_t * p_buffer_rx,
  433. uint32_t const * p_buffer_tx)
  434. {
  435. p_i2s->RXTXD.MAXCNT = size;
  436. nrf_i2s_rx_buffer_set(p_i2s, p_buffer_rx);
  437. p_i2s->CONFIG.RXEN = (p_buffer_rx != NULL) ? 1 : 0;
  438. nrf_i2s_tx_buffer_set(p_i2s, p_buffer_tx);
  439. p_i2s->CONFIG.TXEN = (p_buffer_tx != NULL) ? 1 : 0;
  440. }
  441. __STATIC_INLINE void nrf_i2s_rx_buffer_set(NRF_I2S_Type * p_i2s,
  442. uint32_t * p_buffer)
  443. {
  444. p_i2s->RXD.PTR = (uint32_t)p_buffer;
  445. }
  446. __STATIC_INLINE uint32_t * nrf_i2s_rx_buffer_get(NRF_I2S_Type const * p_i2s)
  447. {
  448. return (uint32_t *)(p_i2s->RXD.PTR);
  449. }
  450. __STATIC_INLINE void nrf_i2s_tx_buffer_set(NRF_I2S_Type * p_i2s,
  451. uint32_t const * p_buffer)
  452. {
  453. p_i2s->TXD.PTR = (uint32_t)p_buffer;
  454. }
  455. __STATIC_INLINE uint32_t * nrf_i2s_tx_buffer_get(NRF_I2S_Type const * p_i2s)
  456. {
  457. return (uint32_t *)(p_i2s->TXD.PTR);
  458. }
  459. #endif // SUPPRESS_INLINE_IMPLEMENTATION
  460. #endif // NRF_I2S_H__
  461. /** @} */