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 /******************************************************************************* 16 * NOTICE 17 * The hal is not public api, don't use in application code. 18 * See readme.md in hal/include/hal/readme.md 19 ******************************************************************************/ 20 21 // The HAL layer for I2S. 22 // There is no parameter check in the hal layer, so the caller must ensure the correctness of the parameters. 23 24 #pragma once 25 26 #include "soc/i2s_periph.h" 27 #include "soc/soc_caps.h" 28 #include "hal/i2s_ll.h" 29 #include "hal/i2s_types.h" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /** 36 * Context that should be maintained by both the driver and the HAL 37 */ 38 typedef struct { 39 i2s_dev_t *dev; 40 uint32_t version; 41 } i2s_hal_context_t; 42 43 /** 44 * @brief Get I2S interrupt status 45 * 46 * @param hal Context of the HAL layer 47 * @param status interrupt status 48 */ 49 #define i2s_hal_get_intr_status(hal, status) i2s_ll_get_intr_status((hal)->dev, status) 50 51 /** 52 * @brief Clear I2S interrupt status 53 * 54 * @param hal Context of the HAL layer 55 * @param mask interrupt status mask 56 */ 57 #define i2s_hal_clear_intr_status(hal, mask) i2s_ll_clear_intr_status((hal)->dev, mask) 58 59 /** 60 * @brief Get I2S out eof des address 61 * 62 * @param hal Context of the HAL layer 63 * @param addr out eof des address 64 */ 65 #define i2s_hal_get_out_eof_des_addr(hal, addr) i2s_ll_get_out_eof_des_addr((hal)->dev, addr) 66 67 /** 68 * @brief Get I2S in eof des address 69 * 70 * @param hal Context of the HAL layer 71 * @param addr in eof des address 72 */ 73 #define i2s_hal_get_in_eof_des_addr(hal, addr) i2s_ll_get_in_eof_des_addr((hal)->dev, addr) 74 75 /** 76 * @brief Enable I2S rx interrupt 77 * 78 * @param hal Context of the HAL layer 79 */ 80 #define i2s_hal_enable_rx_intr(hal) i2s_ll_enable_rx_intr((hal)->dev) 81 82 /** 83 * @brief Disable I2S rx interrupt 84 * 85 * @param hal Context of the HAL layer 86 */ 87 #define i2s_hal_disable_rx_intr(hal) i2s_ll_disable_rx_intr((hal)->dev) 88 89 /** 90 * @brief Disable I2S tx interrupt 91 * 92 * @param hal Context of the HAL layer 93 */ 94 #define i2s_hal_disable_tx_intr(hal) i2s_ll_disable_tx_intr((hal)->dev) 95 96 /** 97 * @brief Enable I2S tx interrupt 98 * 99 * @param hal Context of the HAL layer 100 */ 101 #define i2s_hal_enable_tx_intr(hal) i2s_ll_enable_tx_intr((hal)->dev) 102 103 /** 104 * @brief Set I2S tx mode 105 * 106 * @param hal Context of the HAL layer 107 * @param ch i2s channel 108 * @param bits bits per sample 109 */ 110 void i2s_hal_set_tx_mode(i2s_hal_context_t *hal, i2s_channel_t ch, i2s_bits_per_sample_t bits); 111 112 /** 113 * @brief Set I2S rx mode 114 * 115 * @param hal Context of the HAL layer 116 * @param ch i2s channel 117 * @param bits bits per sample 118 */ 119 void i2s_hal_set_rx_mode(i2s_hal_context_t *hal, i2s_channel_t ch, i2s_bits_per_sample_t bits); 120 121 /** 122 * @brief Set I2S out link address 123 * 124 * @param hal Context of the HAL layer 125 * @param addr out link address 126 */ 127 #define i2s_hal_set_out_link_addr(hal, addr) i2s_ll_set_out_link_addr((hal)->dev, addr) 128 129 /** 130 * @brief Set I2S out link address 131 * 132 * @param hal Context of the HAL layer 133 * @param addr out link address 134 */ 135 #define i2s_hal_set_out_link_addr(hal, addr) i2s_ll_set_out_link_addr((hal)->dev, addr) 136 137 /** 138 * @brief Set I2S out link address 139 * 140 * @param hal Context of the HAL layer 141 * @param addr out link address 142 */ 143 #define i2s_hal_set_out_link_addr(hal, addr) i2s_ll_set_out_link_addr((hal)->dev, addr) 144 145 /** 146 * @brief Set I2S in link 147 * 148 * @param hal Context of the HAL layer 149 * @param rx_eof_num in link eof num 150 * @param addr in link address 151 */ 152 void i2s_hal_set_in_link(i2s_hal_context_t *hal, uint32_t rx_eof_num, uint32_t addr); 153 154 /** 155 * @brief Set I2S clk div 156 * 157 * @param hal Context of the HAL layer 158 * @param div_num i2s clkm div num 159 * @param div_a i2s clkm div a 160 * @param div_b i2s clkm div b 161 * @param tx_bck_div tx bck div num 162 * @param rx_bck_div rx bck div num 163 */ 164 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); 165 166 /** 167 * @brief Set I2S clock sel 168 * 169 * @param hal Context of the HAL layer 170 * @param sel clock sel 171 */ 172 #define i2s_hal_set_clock_sel(hal, sel) i2s_ll_set_clk_sel((hal)->dev, sel) 173 174 /** 175 * @brief Set I2S tx bits mod 176 * 177 * @param hal Context of the HAL layer 178 * @param bits bit width per sample. 179 */ 180 void i2s_hal_set_tx_bits_mod(i2s_hal_context_t *hal, i2s_bits_per_sample_t bits); 181 182 /** 183 * @brief Set I2S rx bits mod 184 * 185 * @param hal Context of the HAL layer 186 * @param bits bit width per sample. 187 */ 188 void i2s_hal_set_rx_bits_mod(i2s_hal_context_t *hal, i2s_bits_per_sample_t bits); 189 190 /** 191 * @brief Reset I2S TX & RX module, including DMA and FIFO 192 * 193 * @param hal Context of the HAL layer 194 */ 195 void i2s_hal_reset(i2s_hal_context_t *hal); 196 197 /** 198 * @brief Start I2S tx 199 * 200 * @param hal Context of the HAL layer 201 */ 202 void i2s_hal_start_tx(i2s_hal_context_t *hal); 203 204 /** 205 * @brief Start I2S rx 206 * 207 * @param hal Context of the HAL layer 208 */ 209 void i2s_hal_start_rx(i2s_hal_context_t *hal); 210 211 /** 212 * @brief Stop I2S tx 213 * 214 * @param hal Context of the HAL layer 215 */ 216 void i2s_hal_stop_tx(i2s_hal_context_t *hal); 217 218 /** 219 * @brief Stop I2S rx 220 * 221 * @param hal Context of the HAL layer 222 */ 223 void i2s_hal_stop_rx(i2s_hal_context_t *hal); 224 225 /** 226 * @brief Config I2S param 227 * 228 * @param hal Context of the HAL layer 229 * @param i2s_config I2S configurations - see i2s_config_t struct 230 */ 231 void i2s_hal_config_param(i2s_hal_context_t *hal, const i2s_config_t *i2s_config); 232 233 /** 234 * @brief Enable I2S sig loopback 235 * 236 * @param hal Context of the HAL layer 237 */ 238 #define i2s_hal_enable_sig_loopback(hal) i2s_ll_set_sig_loopback((hal)->dev, 1) 239 240 /** 241 * @brief Enable I2S master mode 242 * 243 * @param hal Context of the HAL layer 244 */ 245 void i2s_hal_enable_master_mode(i2s_hal_context_t *hal); 246 247 /** 248 * @brief Enable I2S slave mode 249 * 250 * @param hal Context of the HAL layer 251 */ 252 void i2s_hal_enable_slave_mode(i2s_hal_context_t *hal); 253 254 /** 255 * @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 256 * 257 * @param hal Context of the HAL layer 258 * @param i2s_num The uart port number, the max port number is (I2S_NUM_MAX -1) 259 */ 260 void i2s_hal_init(i2s_hal_context_t *hal, int i2s_num); 261 262 #if SOC_I2S_SUPPORTS_PDM 263 /** 264 * @brief Set I2S tx pdm 265 * 266 * @param hal Context of the HAL layer 267 * @param fp tx pdm fp 268 * @param fs tx pdm fs 269 */ 270 void i2s_hal_tx_pdm_cfg(i2s_hal_context_t *hal, uint32_t fp, uint32_t fs); 271 272 /** 273 * @brief Get I2S tx pdm 274 * 275 * @param hal Context of the HAL layer 276 * @param dsr rx pdm dsr 277 */ 278 void i2s_hal_rx_pdm_cfg(i2s_hal_context_t *hal, uint32_t dsr); 279 280 /** 281 * @brief Get I2S tx pdm configuration 282 * 283 * @param hal Context of the HAL layer 284 * @param fp Pointer to receive tx PDM fp configuration 285 * @param fs Pointer to receive tx PDM fs configuration 286 */ 287 void i2s_hal_get_tx_pdm(i2s_hal_context_t *hal, uint32_t *fp, uint32_t *fs); 288 289 /** 290 * @brief Get I2S rx pdm configuration 291 * 292 * @param hal Context of the HAL layer 293 * @param dsr rx pdm dsr 294 */ 295 void i2s_hal_get_rx_pdm(i2s_hal_context_t *hal, uint32_t *dsr); 296 #endif 297 298 #ifdef __cplusplus 299 } 300 #endif 301