i2s_hal.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /*******************************************************************************
  15. * NOTICE
  16. * The hal is not public api, don't use in application code.
  17. * See readme.md in soc/include/hal/readme.md
  18. ******************************************************************************/
  19. // The HAL layer for I2S.
  20. // There is no parameter check in the hal layer, so the caller must ensure the correctness of the parameters.
  21. #pragma once
  22. #include "soc/i2s_periph.h"
  23. #include "soc/i2s_caps.h"
  24. #include "hal/i2s_ll.h"
  25. #include "hal/i2s_types.h"
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /**
  30. * Context that should be maintained by both the driver and the HAL
  31. */
  32. typedef struct {
  33. i2s_dev_t *dev;
  34. uint32_t version;
  35. } i2s_hal_context_t;
  36. /**
  37. * @brief Get I2S interrupt status
  38. *
  39. * @param hal Context of the HAL layer
  40. * @param status interrupt status
  41. */
  42. #define i2s_hal_get_intr_status(hal, status) i2s_ll_get_intr_status((hal)->dev, status)
  43. /**
  44. * @brief Clear I2S interrupt status
  45. *
  46. * @param hal Context of the HAL layer
  47. * @param mask interrupt status mask
  48. */
  49. #define i2s_hal_clear_intr_status(hal, mask) i2s_ll_clear_intr_status((hal)->dev, mask)
  50. /**
  51. * @brief Get I2S out eof des address
  52. *
  53. * @param hal Context of the HAL layer
  54. * @param addr out eof des address
  55. */
  56. #define i2s_hal_get_out_eof_des_addr(hal, addr) i2s_ll_get_out_eof_des_addr((hal)->dev, addr)
  57. /**
  58. * @brief Get I2S in eof des address
  59. *
  60. * @param hal Context of the HAL layer
  61. * @param addr in eof des address
  62. */
  63. #define i2s_hal_get_in_eof_des_addr(hal, addr) i2s_ll_get_in_eof_des_addr((hal)->dev, addr)
  64. /**
  65. * @brief Enable I2S rx interrupt
  66. *
  67. * @param hal Context of the HAL layer
  68. */
  69. #define i2s_hal_enable_rx_intr(hal) i2s_ll_enable_rx_intr((hal)->dev)
  70. /**
  71. * @brief Disable I2S rx interrupt
  72. *
  73. * @param hal Context of the HAL layer
  74. */
  75. #define i2s_hal_disable_rx_intr(hal) i2s_ll_disable_rx_intr((hal)->dev)
  76. /**
  77. * @brief Disable I2S tx interrupt
  78. *
  79. * @param hal Context of the HAL layer
  80. */
  81. #define i2s_hal_disable_tx_intr(hal) i2s_ll_disable_tx_intr((hal)->dev)
  82. /**
  83. * @brief Enable I2S tx interrupt
  84. *
  85. * @param hal Context of the HAL layer
  86. */
  87. #define i2s_hal_enable_tx_intr(hal) i2s_ll_enable_tx_intr((hal)->dev)
  88. /**
  89. * @brief Set I2S tx mode
  90. *
  91. * @param hal Context of the HAL layer
  92. * @param ch i2s channel
  93. * @param bits bits per sample
  94. */
  95. void i2s_hal_set_tx_mode(i2s_hal_context_t *hal, i2s_channel_t ch, i2s_bits_per_sample_t bits);
  96. /**
  97. * @brief Set I2S rx mode
  98. *
  99. * @param hal Context of the HAL layer
  100. * @param ch i2s channel
  101. * @param bits bits per sample
  102. */
  103. void i2s_hal_set_rx_mode(i2s_hal_context_t *hal, i2s_channel_t ch, i2s_bits_per_sample_t bits);
  104. /**
  105. * @brief Set I2S out link address
  106. *
  107. * @param hal Context of the HAL layer
  108. * @param addr out link address
  109. */
  110. #define i2s_hal_set_out_link_addr(hal, addr) i2s_ll_set_out_link_addr((hal)->dev, addr)
  111. /**
  112. * @brief Set I2S out link address
  113. *
  114. * @param hal Context of the HAL layer
  115. * @param addr out link address
  116. */
  117. #define i2s_hal_set_out_link_addr(hal, addr) i2s_ll_set_out_link_addr((hal)->dev, addr)
  118. /**
  119. * @brief Set I2S out link address
  120. *
  121. * @param hal Context of the HAL layer
  122. * @param addr out link address
  123. */
  124. #define i2s_hal_set_out_link_addr(hal, addr) i2s_ll_set_out_link_addr((hal)->dev, addr)
  125. /**
  126. * @brief Set I2S in link
  127. *
  128. * @param hal Context of the HAL layer
  129. * @param rx_eof_num in link eof num
  130. * @param addr in link address
  131. */
  132. void i2s_hal_set_in_link(i2s_hal_context_t *hal, uint32_t rx_eof_num, uint32_t addr);
  133. /**
  134. * @brief Get I2S tx pdm
  135. *
  136. * @param hal Context of the HAL layer
  137. * @param fp tx pdm fp
  138. * @param fs tx pdm fs
  139. */
  140. void i2s_hal_get_tx_pdm(i2s_hal_context_t *hal, int *fp, int *fs);
  141. /**
  142. * @brief Get I2S rx sinc dsr 16 en
  143. *
  144. * @param hal Context of the HAL layer
  145. * @param en 0: disable, 1: enable
  146. */
  147. #define i2s_hal_get_rx_sinc_dsr_16_en(hal, en) i2s_ll_get_rx_sinc_dsr_16_en((hal)->dev, en)
  148. /**
  149. * @brief Set I2S clk div
  150. *
  151. * @param hal Context of the HAL layer
  152. * @param div_num i2s clkm div num
  153. * @param div_a i2s clkm div a
  154. * @param div_b i2s clkm div b
  155. * @param tx_bck_div tx bck div num
  156. * @param rx_bck_div rx bck div num
  157. */
  158. void i2s_hal_set_clk_div(i2s_hal_context_t *hal, int div_num, int div_a, int div_b, int tx_bck_div, int rx_bck_div);
  159. /**
  160. * @brief Set I2S clock sel
  161. *
  162. * @param hal Context of the HAL layer
  163. * @param sel clock sel
  164. */
  165. #define i2s_hal_set_clock_sel(hal, sel) i2s_ll_set_clk_sel((hal)->dev, sel)
  166. /**
  167. * @brief Set I2S tx bits mod
  168. *
  169. * @param hal Context of the HAL layer
  170. * @param bits bit width per sample.
  171. */
  172. void i2s_hal_set_tx_bits_mod(i2s_hal_context_t *hal, i2s_bits_per_sample_t bits);
  173. /**
  174. * @brief Set I2S rx bits mod
  175. *
  176. * @param hal Context of the HAL layer
  177. * @param bits bit width per sample.
  178. */
  179. void i2s_hal_set_rx_bits_mod(i2s_hal_context_t *hal, i2s_bits_per_sample_t bits);
  180. /**
  181. * @brief Reset I2S TX & RX module, including DMA and FIFO
  182. *
  183. * @param hal Context of the HAL layer
  184. */
  185. void i2s_hal_reset(i2s_hal_context_t *hal);
  186. /**
  187. * @brief Start I2S tx
  188. *
  189. * @param hal Context of the HAL layer
  190. */
  191. void i2s_hal_start_tx(i2s_hal_context_t *hal);
  192. /**
  193. * @brief Start I2S rx
  194. *
  195. * @param hal Context of the HAL layer
  196. */
  197. void i2s_hal_start_rx(i2s_hal_context_t *hal);
  198. /**
  199. * @brief Stop I2S tx
  200. *
  201. * @param hal Context of the HAL layer
  202. */
  203. void i2s_hal_stop_tx(i2s_hal_context_t *hal);
  204. /**
  205. * @brief Stop I2S rx
  206. *
  207. * @param hal Context of the HAL layer
  208. */
  209. void i2s_hal_stop_rx(i2s_hal_context_t *hal);
  210. /**
  211. * @brief Set I2S pdm rx down sample
  212. *
  213. * @param hal Context of the HAL layer
  214. * @param dsr 0:disable, 1: enable
  215. */
  216. #define i2s_hal_set_pdm_rx_down_sample(hal, dsr) i2s_ll_set_rx_sinc_dsr_16_en((hal)->dev, dsr)
  217. /**
  218. * @brief Config I2S param
  219. *
  220. * @param hal Context of the HAL layer
  221. * @param i2s_config I2S configurations - see i2s_config_t struct
  222. */
  223. void i2s_hal_config_param(i2s_hal_context_t *hal, const i2s_config_t *i2s_config);
  224. /**
  225. * @brief Enable I2S sig loopback
  226. *
  227. * @param hal Context of the HAL layer
  228. */
  229. #define i2s_hal_enable_sig_loopback(hal) i2s_ll_set_sig_loopback((hal)->dev, 1)
  230. /**
  231. * @brief Enable I2S master mode
  232. *
  233. * @param hal Context of the HAL layer
  234. */
  235. void i2s_hal_enable_master_mode(i2s_hal_context_t *hal);
  236. /**
  237. * @brief Enable I2S slave mode
  238. *
  239. * @param hal Context of the HAL layer
  240. */
  241. void i2s_hal_enable_slave_mode(i2s_hal_context_t *hal);
  242. /**
  243. * @brief Init the I2S hal and set the I2S to the default configuration. This function should be called first before other hal layer function is called
  244. *
  245. * @param hal Context of the HAL layer
  246. * @param i2s_num The uart port number, the max port number is (I2S_NUM_MAX -1)
  247. */
  248. void i2s_hal_init(i2s_hal_context_t *hal, int i2s_num);
  249. #ifdef __cplusplus
  250. }
  251. #endif