• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 LL layer for ESP32 I2S register operations
22 
23 #pragma once
24 
25 #include <stdbool.h>
26 #include "soc/rtc_periph.h"
27 #include "soc/rtc.h"
28 #include "soc/efuse_periph.h"
29 #include "soc/i2s_periph.h"
30 #include "hal/i2s_types.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 // Get I2S hardware instance with giving i2s num
37 #define I2S_LL_GET_HW(num) (((num) == 0) ? (&I2S0) : (((num) == 1) ? (&I2S1) : NULL))
38 
39 #define I2S_INTR_IN_SUC_EOF   BIT(9)
40 #define I2S_INTR_OUT_EOF      BIT(12)
41 #define I2S_INTR_IN_DSCR_ERR  BIT(13)
42 #define I2S_INTR_OUT_DSCR_ERR BIT(14)
43 #define I2S_INTR_MAX          (0xFFFFFFFF)
44 
45 /**
46  * @brief Reset rx fifo
47  *
48  * @param hw Peripheral I2S hardware instance address.
49  */
i2s_ll_reset_rx_fifo(i2s_dev_t * hw)50 static inline void i2s_ll_reset_rx_fifo(i2s_dev_t *hw)
51 {
52     hw->conf.rx_fifo_reset = 1;
53     hw->conf.rx_fifo_reset = 0;
54 }
55 
56 /**
57  * @brief Reset tx fifo
58  *
59  * @param hw Peripheral I2S hardware instance address.
60  */
i2s_ll_reset_tx_fifo(i2s_dev_t * hw)61 static inline void i2s_ll_reset_tx_fifo(i2s_dev_t *hw)
62 {
63     hw->conf.tx_fifo_reset = 1;
64     hw->conf.tx_fifo_reset = 0;
65 }
66 
67 /**
68  * @brief Enable rx interrupt
69  *
70  * @param hw Peripheral I2S hardware instance address.
71  */
i2s_ll_enable_rx_intr(i2s_dev_t * hw)72 static inline void i2s_ll_enable_rx_intr(i2s_dev_t *hw)
73 {
74     hw->int_ena.in_suc_eof = 1;
75     hw->int_ena.in_dscr_err = 1;
76 }
77 
78 /**
79  * @brief Disable rx interrupt
80  *
81  * @param hw Peripheral I2S hardware instance address.
82  */
i2s_ll_disable_rx_intr(i2s_dev_t * hw)83 static inline void i2s_ll_disable_rx_intr(i2s_dev_t *hw)
84 {
85     hw->int_ena.in_suc_eof = 0;
86     hw->int_ena.in_dscr_err = 0;
87 }
88 
89 /**
90  * @brief Disable tx interrupt
91  *
92  * @param hw Peripheral I2S hardware instance address.
93  */
i2s_ll_disable_tx_intr(i2s_dev_t * hw)94 static inline void i2s_ll_disable_tx_intr(i2s_dev_t *hw)
95 {
96     hw->int_ena.out_eof = 0;
97     hw->int_ena.out_dscr_err = 0;
98 }
99 
100 /**
101  * @brief Enable tx interrupt
102  *
103  * @param hw Peripheral I2S hardware instance address.
104  */
i2s_ll_enable_tx_intr(i2s_dev_t * hw)105 static inline void i2s_ll_enable_tx_intr(i2s_dev_t *hw)
106 {
107     hw->int_ena.out_eof = 1;
108     hw->int_ena.out_dscr_err = 1;
109 }
110 
111 /**
112  * @brief Reset dma in
113  *
114  * @param hw Peripheral I2S hardware instance address.
115  */
i2s_ll_reset_dma_in(i2s_dev_t * hw)116 static inline void i2s_ll_reset_dma_in(i2s_dev_t *hw)
117 {
118     hw->lc_conf.in_rst = 1;
119     hw->lc_conf.in_rst = 0;
120 }
121 
122 /**
123  * @brief Reset dma out
124  *
125  * @param hw Peripheral I2S hardware instance address.
126  */
i2s_ll_reset_dma_out(i2s_dev_t * hw)127 static inline void i2s_ll_reset_dma_out(i2s_dev_t *hw)
128 {
129     hw->lc_conf.out_rst = 1;
130     hw->lc_conf.out_rst = 0;
131 }
132 
133 /**
134  * @brief Reset tx
135  *
136  * @param hw Peripheral I2S hardware instance address.
137  */
i2s_ll_reset_tx(i2s_dev_t * hw)138 static inline void i2s_ll_reset_tx(i2s_dev_t *hw)
139 {
140     hw->conf.tx_reset = 1;
141     hw->conf.tx_reset = 0;
142 }
143 
144 /**
145  * @brief Reset rx
146  *
147  * @param hw Peripheral I2S hardware instance address.
148  */
i2s_ll_reset_rx(i2s_dev_t * hw)149 static inline void i2s_ll_reset_rx(i2s_dev_t *hw)
150 {
151     hw->conf.rx_reset = 1;
152     hw->conf.rx_reset = 0;
153 }
154 
155 /**
156  * @brief Start out link
157  *
158  * @param hw Peripheral I2S hardware instance address.
159  */
i2s_ll_start_out_link(i2s_dev_t * hw)160 static inline void i2s_ll_start_out_link(i2s_dev_t *hw)
161 {
162     hw->out_link.start = 1;
163 }
164 
165 /**
166  * @brief Start tx
167  *
168  * @param hw Peripheral I2S hardware instance address.
169  */
i2s_ll_start_tx(i2s_dev_t * hw)170 static inline void i2s_ll_start_tx(i2s_dev_t *hw)
171 {
172     hw->conf.tx_start = 1;
173 }
174 
175 /**
176  * @brief Start in link
177  *
178  * @param hw Peripheral I2S hardware instance address.
179  */
i2s_ll_start_in_link(i2s_dev_t * hw)180 static inline void i2s_ll_start_in_link(i2s_dev_t *hw)
181 {
182     hw->in_link.start = 1;
183 }
184 
185 /**
186  * @brief Start rx
187  *
188  * @param hw Peripheral I2S hardware instance address.
189  */
i2s_ll_start_rx(i2s_dev_t * hw)190 static inline void i2s_ll_start_rx(i2s_dev_t *hw)
191 {
192     hw->conf.rx_start = 1;
193 }
194 
195 /**
196  * @brief Stop out link
197  *
198  * @param hw Peripheral I2S hardware instance address.
199  */
i2s_ll_stop_out_link(i2s_dev_t * hw)200 static inline void i2s_ll_stop_out_link(i2s_dev_t *hw)
201 {
202     hw->out_link.stop = 1;
203 }
204 
205 /**
206  * @brief Stop tx
207  *
208  * @param hw Peripheral I2S hardware instance address.
209  */
i2s_ll_stop_tx(i2s_dev_t * hw)210 static inline void i2s_ll_stop_tx(i2s_dev_t *hw)
211 {
212     hw->conf.tx_start = 0;
213 }
214 
215 /**
216  * @brief Stop in link
217  *
218  * @param hw Peripheral I2S hardware instance address.
219  */
i2s_ll_stop_in_link(i2s_dev_t * hw)220 static inline void i2s_ll_stop_in_link(i2s_dev_t *hw)
221 {
222     hw->in_link.stop = 1;
223 }
224 
225 /**
226  * @brief Stop rx
227  *
228  * @param hw Peripheral I2S hardware instance address.
229  */
i2s_ll_stop_rx(i2s_dev_t * hw)230 static inline void i2s_ll_stop_rx(i2s_dev_t *hw)
231 {
232     hw->conf.rx_start = 0;
233 }
234 
235 /**
236  * @brief Enable dma
237  *
238  * @param hw Peripheral I2S hardware instance address.
239  */
i2s_ll_enable_dma(i2s_dev_t * hw)240 static inline void i2s_ll_enable_dma(i2s_dev_t *hw)
241 {
242     //Enable and configure DMA
243     typeof(hw->lc_conf) lc_conf;
244     lc_conf.val = 0;
245     lc_conf.out_eof_mode = 1;
246     hw->lc_conf.val = lc_conf.val;
247 }
248 
249 /**
250  * @brief Get I2S interrupt status
251  *
252  * @param hw Peripheral I2S hardware instance address.
253  * @param val value to get interrupt status
254  */
i2s_ll_get_intr_status(i2s_dev_t * hw,uint32_t * val)255 static inline void i2s_ll_get_intr_status(i2s_dev_t *hw, uint32_t *val)
256 {
257     *val = hw->int_st.val;
258 }
259 
260 /**
261  * @brief Clear I2S interrupt status
262  *
263  * @param hw Peripheral I2S hardware instance address.
264  * @param val value to clear interrupt status
265  */
i2s_ll_clear_intr_status(i2s_dev_t * hw,uint32_t val)266 static inline void i2s_ll_clear_intr_status(i2s_dev_t *hw, uint32_t val)
267 {
268     hw->int_clr.val = val;
269 }
270 
271 /**
272  * @brief Get I2S out eof des address
273  *
274  * @param hw Peripheral I2S hardware instance address.
275  * @param val value to get out eof des address
276  */
i2s_ll_get_out_eof_des_addr(i2s_dev_t * hw,uint32_t * val)277 static inline void i2s_ll_get_out_eof_des_addr(i2s_dev_t *hw, uint32_t *val)
278 {
279     *val = hw->out_eof_des_addr;
280 }
281 
282 /**
283  * @brief Get I2S in eof des address
284  *
285  * @param hw Peripheral I2S hardware instance address.
286  * @param val value to get in eof des address
287  */
i2s_ll_get_in_eof_des_addr(i2s_dev_t * hw,uint32_t * val)288 static inline void i2s_ll_get_in_eof_des_addr(i2s_dev_t *hw, uint32_t *val)
289 {
290     *val = hw->in_eof_des_addr;
291 }
292 
293 /**
294  * @brief Get I2S tx fifo mode
295  *
296  * @param hw Peripheral I2S hardware instance address.
297  * @param val value to get tx fifo mode
298  */
i2s_ll_get_tx_fifo_mod(i2s_dev_t * hw,uint32_t * val)299 static inline void i2s_ll_get_tx_fifo_mod(i2s_dev_t *hw, uint32_t *val)
300 {
301     *val = hw->fifo_conf.tx_fifo_mod;
302 }
303 
304 /**
305  * @brief Set I2S tx fifo mode
306  *
307  * @param hw Peripheral I2S hardware instance address.
308  * @param val value to set tx fifo mode
309  */
i2s_ll_set_tx_fifo_mod(i2s_dev_t * hw,uint32_t val)310 static inline void i2s_ll_set_tx_fifo_mod(i2s_dev_t *hw, uint32_t val)
311 {
312     hw->fifo_conf.tx_fifo_mod = val;
313 }
314 
315 /**
316  * @brief Get I2S rx fifo mode
317  *
318  * @param hw Peripheral I2S hardware instance address.
319  * @param val value to get rx fifo mode
320  */
i2s_ll_get_rx_fifo_mod(i2s_dev_t * hw,uint32_t * val)321 static inline void i2s_ll_get_rx_fifo_mod(i2s_dev_t *hw, uint32_t *val)
322 {
323     *val = hw->fifo_conf.rx_fifo_mod;
324 }
325 
326 /**
327  * @brief Set I2S rx fifo mode
328  *
329  * @param hw Peripheral I2S hardware instance address.
330  * @param val value to set rx fifo mode
331  */
i2s_ll_set_rx_fifo_mod(i2s_dev_t * hw,uint32_t val)332 static inline void i2s_ll_set_rx_fifo_mod(i2s_dev_t *hw, uint32_t val)
333 {
334     hw->fifo_conf.rx_fifo_mod = val;
335 }
336 
337 /**
338  * @brief Set I2S tx chan mode
339  *
340  * @param hw Peripheral I2S hardware instance address.
341  * @param val value to set tx chan mode
342  */
i2s_ll_set_tx_chan_mod(i2s_dev_t * hw,uint32_t val)343 static inline void i2s_ll_set_tx_chan_mod(i2s_dev_t *hw, uint32_t val)
344 {
345     hw->conf_chan.tx_chan_mod = val;
346 }
347 
348 /**
349  * @brief Set I2S rx chan mode
350  *
351  * @param hw Peripheral I2S hardware instance address.
352  * @param val value to set rx chan mode
353  */
i2s_ll_set_rx_chan_mod(i2s_dev_t * hw,uint32_t val)354 static inline void i2s_ll_set_rx_chan_mod(i2s_dev_t *hw, uint32_t val)
355 {
356     hw->conf_chan.rx_chan_mod = val;
357 }
358 
359 /**
360  * @brief Set I2S out link address
361  *
362  * @param hw Peripheral I2S hardware instance address.
363  * @param val value to set out link address
364  */
i2s_ll_set_out_link_addr(i2s_dev_t * hw,uint32_t val)365 static inline void i2s_ll_set_out_link_addr(i2s_dev_t *hw, uint32_t val)
366 {
367     hw->out_link.addr = val;
368 }
369 
370 /**
371  * @brief Set I2S in link address
372  *
373  * @param hw Peripheral I2S hardware instance address.
374  * @param val value to set in link address
375  */
i2s_ll_set_in_link_addr(i2s_dev_t * hw,uint32_t val)376 static inline void i2s_ll_set_in_link_addr(i2s_dev_t *hw, uint32_t val)
377 {
378     hw->in_link.addr = val;
379 }
380 
381 /**
382  * @brief Set I2S rx eof num
383  *
384  * @param hw Peripheral I2S hardware instance address.
385  * @param val value to set rx eof num
386  */
i2s_ll_set_rx_eof_num(i2s_dev_t * hw,uint32_t val)387 static inline void i2s_ll_set_rx_eof_num(i2s_dev_t *hw, uint32_t val)
388 {
389     // On ESP32, the eof_num count in words.
390     hw->rx_eof_num = val / 4;
391 }
392 
393 /**
394  * @brief Set I2S clkm div num
395  *
396  * @param hw Peripheral I2S hardware instance address.
397  * @param val value to set clkm div num
398  */
i2s_ll_set_clkm_div_num(i2s_dev_t * hw,uint32_t val)399 static inline void i2s_ll_set_clkm_div_num(i2s_dev_t *hw, uint32_t val)
400 {
401     hw->clkm_conf.clkm_div_num = val;
402 }
403 
404 /**
405  * @brief Set I2S clkm div b
406  *
407  * @param hw Peripheral I2S hardware instance address.
408  * @param val value to set clkm div b
409  */
i2s_ll_set_clkm_div_b(i2s_dev_t * hw,uint32_t val)410 static inline void i2s_ll_set_clkm_div_b(i2s_dev_t *hw, uint32_t val)
411 {
412     hw->clkm_conf.clkm_div_b = val;
413 }
414 
415 /**
416  * @brief Set I2S clkm div a
417  *
418  * @param hw Peripheral I2S hardware instance address.
419  * @param val value to set clkm div a
420  */
i2s_ll_set_clkm_div_a(i2s_dev_t * hw,uint32_t val)421 static inline void i2s_ll_set_clkm_div_a(i2s_dev_t *hw, uint32_t val)
422 {
423     hw->clkm_conf.clkm_div_a = val;
424 }
425 
426 /**
427  * @brief Set I2S tx bck div num
428  *
429  * @param hw Peripheral I2S hardware instance address.
430  * @param val value to set tx bck div num
431  */
i2s_ll_set_tx_bck_div_num(i2s_dev_t * hw,uint32_t val)432 static inline void i2s_ll_set_tx_bck_div_num(i2s_dev_t *hw, uint32_t val)
433 {
434     hw->sample_rate_conf.tx_bck_div_num = val;
435 }
436 
437 /**
438  * @brief Set I2S rx bck div num
439  *
440  * @param hw Peripheral I2S hardware instance address.
441  * @param val value to set rx bck div num
442  */
i2s_ll_set_rx_bck_div_num(i2s_dev_t * hw,uint32_t val)443 static inline void i2s_ll_set_rx_bck_div_num(i2s_dev_t *hw, uint32_t val)
444 {
445     hw->sample_rate_conf.rx_bck_div_num = val;
446 }
447 
448 /**
449  * @brief Set I2S clk sel
450  *
451  * @param hw Peripheral I2S hardware instance address.
452  * @param val value to set clk sel
453  */
i2s_ll_set_clk_sel(i2s_dev_t * hw,uint32_t val)454 static inline void i2s_ll_set_clk_sel(i2s_dev_t *hw, uint32_t val)
455 {
456     hw->clkm_conf.clka_en = (val == 1) ? 1 : 0;
457 }
458 
459 /**
460  * @brief Set I2S tx bits mod
461  *
462  * @param hw Peripheral I2S hardware instance address.
463  * @param val value to set tx bits mod
464  */
i2s_ll_set_tx_bits_mod(i2s_dev_t * hw,uint32_t val)465 static inline void i2s_ll_set_tx_bits_mod(i2s_dev_t *hw, uint32_t val)
466 {
467     hw->sample_rate_conf.tx_bits_mod = val;
468 }
469 
470 /**
471  * @brief Set I2S rx bits mod
472  *
473  * @param hw Peripheral I2S hardware instance address.
474  * @param val value to set rx bits mod
475  */
i2s_ll_set_rx_bits_mod(i2s_dev_t * hw,uint32_t val)476 static inline void i2s_ll_set_rx_bits_mod(i2s_dev_t *hw, uint32_t val)
477 {
478     hw->sample_rate_conf.rx_bits_mod = val;
479 }
480 
481 /**
482  * @brief Set I2S dscr en
483  *
484  * @param hw Peripheral I2S hardware instance address.
485  * @param val value to set dscr en
486  */
i2s_ll_set_dscr_en(i2s_dev_t * hw,bool val)487 static inline void i2s_ll_set_dscr_en(i2s_dev_t *hw, bool val)
488 {
489     hw->fifo_conf.dscr_en = val;
490 }
491 
492 /**
493  * @brief Set I2S lcd en
494  *
495  * @param hw Peripheral I2S hardware instance address.
496  * @param val value to set lcd en
497  */
i2s_ll_set_lcd_en(i2s_dev_t * hw,bool val)498 static inline void i2s_ll_set_lcd_en(i2s_dev_t *hw, bool val)
499 {
500     hw->conf2.lcd_en = val;
501 }
502 
503 /**
504  * @brief Set I2S camera en
505  *
506  * @param hw Peripheral I2S hardware instance address.
507  * @param val value to set camera en
508  */
i2s_ll_set_camera_en(i2s_dev_t * hw,bool val)509 static inline void i2s_ll_set_camera_en(i2s_dev_t *hw, bool val)
510 {
511     hw->conf2.camera_en = val;
512 }
513 
514 /**
515  * @brief Set I2S tx fifo mod force en
516  *
517  * @param hw Peripheral I2S hardware instance address.
518  * @param val value to set tx fifo mod force en
519  */
i2s_ll_set_tx_fifo_mod_force_en(i2s_dev_t * hw,bool val)520 static inline void i2s_ll_set_tx_fifo_mod_force_en(i2s_dev_t *hw, bool val)
521 {
522     hw->fifo_conf.tx_fifo_mod_force_en = val;
523 }
524 
525 /**
526  * @brief Set I2S rx fifo mod force en
527  *
528  * @param hw Peripheral I2S hardware instance address.
529  * @param val value to set rx fifo mod force en
530  */
i2s_ll_set_rx_fifo_mod_force_en(i2s_dev_t * hw,bool val)531 static inline void i2s_ll_set_rx_fifo_mod_force_en(i2s_dev_t *hw, bool val)
532 {
533     hw->fifo_conf.rx_fifo_mod_force_en = val;
534 }
535 
536 /**
537  * @brief Set I2S tx right first
538  *
539  * @param hw Peripheral I2S hardware instance address.
540  * @param val value to set tx right first
541  */
i2s_ll_set_tx_right_first(i2s_dev_t * hw,uint32_t val)542 static inline void i2s_ll_set_tx_right_first(i2s_dev_t *hw, uint32_t val)
543 {
544     hw->conf.tx_right_first = val;
545 }
546 
547 /**
548  * @brief Set I2S rx right first
549  *
550  * @param hw Peripheral I2S hardware instance address.
551  * @param val value to set rx right first
552  */
i2s_ll_set_rx_right_first(i2s_dev_t * hw,uint32_t val)553 static inline void i2s_ll_set_rx_right_first(i2s_dev_t *hw, uint32_t val)
554 {
555     hw->conf.rx_right_first = val;
556 }
557 
558 /**
559  * @brief Set I2S tx slave mod
560  *
561  * @param hw Peripheral I2S hardware instance address.
562  * @param val value to set tx slave mod
563  */
i2s_ll_set_tx_slave_mod(i2s_dev_t * hw,uint32_t val)564 static inline void i2s_ll_set_tx_slave_mod(i2s_dev_t *hw, uint32_t val)
565 {
566     hw->conf.tx_slave_mod = val;
567 }
568 
569 /**
570  * @brief Set I2S rx slave mod
571  *
572  * @param hw Peripheral I2S hardware instance address.
573  * @param val value to set rx slave mod
574  */
i2s_ll_set_rx_slave_mod(i2s_dev_t * hw,uint32_t val)575 static inline void i2s_ll_set_rx_slave_mod(i2s_dev_t *hw, uint32_t val)
576 {
577     hw->conf.rx_slave_mod = val;
578 }
579 
580 /**
581  * @brief Get I2S tx msb right
582  *
583  * @param hw Peripheral I2S hardware instance address.
584  * @param val value to get tx msb right
585  */
i2s_ll_get_tx_msb_right(i2s_dev_t * hw,uint32_t * val)586 static inline void i2s_ll_get_tx_msb_right(i2s_dev_t *hw, uint32_t *val)
587 {
588      *val = hw->conf.tx_msb_right;
589 }
590 
591 /**
592  * @brief Get I2S rx msb right
593  *
594  * @param hw Peripheral I2S hardware instance address.
595  * @param val value to get rx msb right
596  */
i2s_ll_get_rx_msb_right(i2s_dev_t * hw,uint32_t * val)597 static inline void i2s_ll_get_rx_msb_right(i2s_dev_t *hw, uint32_t *val)
598 {
599      *val = hw->conf.rx_msb_right;
600 }
601 
602 /**
603  * @brief Set I2S tx msb right
604  *
605  * @param hw Peripheral I2S hardware instance address.
606  * @param val value to set tx msb right
607  */
i2s_ll_set_tx_msb_right(i2s_dev_t * hw,uint32_t val)608 static inline void i2s_ll_set_tx_msb_right(i2s_dev_t *hw, uint32_t val)
609 {
610     hw->conf.tx_msb_right = val;
611 }
612 
613 /**
614  * @brief Set I2S rx msb right
615  *
616  * @param hw Peripheral I2S hardware instance address.
617  * @param val value to set rx msb right
618  */
i2s_ll_set_rx_msb_right(i2s_dev_t * hw,uint32_t val)619 static inline void i2s_ll_set_rx_msb_right(i2s_dev_t *hw, uint32_t val)
620 {
621     hw->conf.rx_msb_right = val;
622 }
623 
624 /**
625  * @brief Set I2S tx mono
626  *
627  * @param hw Peripheral I2S hardware instance address.
628  * @param val value to set tx mono
629  */
i2s_ll_set_tx_mono(i2s_dev_t * hw,uint32_t val)630 static inline void i2s_ll_set_tx_mono(i2s_dev_t *hw, uint32_t val)
631 {
632     hw->conf.tx_mono = val;
633 }
634 
635 /**
636  * @brief Set I2S rx mono
637  *
638  * @param hw Peripheral I2S hardware instance address.
639  * @param val value to set rx mono
640  */
i2s_ll_set_rx_mono(i2s_dev_t * hw,uint32_t val)641 static inline void i2s_ll_set_rx_mono(i2s_dev_t *hw, uint32_t val)
642 {
643     hw->conf.rx_mono = val;
644 }
645 
646 /**
647  * @brief Set I2S sig loopback
648  *
649  * @param hw Peripheral I2S hardware instance address.
650  * @param val value to set sig loopback
651  */
i2s_ll_set_sig_loopback(i2s_dev_t * hw,uint32_t val)652 static inline void i2s_ll_set_sig_loopback(i2s_dev_t *hw, uint32_t val)
653 {
654     hw->conf.sig_loopback = val;
655 }
656 
657 /**
658  * @brief Set I2S TX to philip standard
659  *
660  * @param hw Peripheral I2S hardware instance address.
661  */
i2s_ll_set_tx_format_philip(i2s_dev_t * hw)662 static inline void i2s_ll_set_tx_format_philip(i2s_dev_t *hw)
663 {
664     hw->conf.tx_short_sync = 0;
665     hw->conf.tx_msb_shift = 1;
666 }
667 
668 /**
669  * @brief Set I2S RX to philip standard
670  *
671  * @param hw Peripheral I2S hardware instance address.
672  */
i2s_ll_set_rx_format_philip(i2s_dev_t * hw)673 static inline void i2s_ll_set_rx_format_philip(i2s_dev_t *hw)
674 {
675     hw->conf.rx_short_sync = 0;
676     hw->conf.rx_msb_shift = 1;
677 }
678 
679 /**
680  * @brief Set I2S TX to MSB Alignment Standard
681  *
682  * @param hw Peripheral I2S hardware instance address.
683  */
i2s_ll_set_tx_format_msb_align(i2s_dev_t * hw)684 static inline void i2s_ll_set_tx_format_msb_align(i2s_dev_t *hw)
685 {
686     hw->conf.tx_short_sync = 0;
687     hw->conf.tx_msb_shift = 0;
688 }
689 
690 /**
691  * @brief Set I2S RX to MSB Alignment Standard
692  *
693  * @param hw Peripheral I2S hardware instance address.
694  */
i2s_ll_set_rx_format_msb_align(i2s_dev_t * hw)695 static inline void i2s_ll_set_rx_format_msb_align(i2s_dev_t *hw)
696 {
697     hw->conf.rx_short_sync = 0;
698     hw->conf.rx_msb_shift = 0;
699 }
700 
701 /**
702  * @brief Set I2S TX to PCM short standard
703  *
704  * @param hw Peripheral I2S hardware instance address.
705  */
i2s_ll_set_tx_pcm_short(i2s_dev_t * hw)706 static inline void i2s_ll_set_tx_pcm_short(i2s_dev_t *hw)
707 {
708     hw->conf.tx_short_sync = 1;
709     hw->conf.tx_msb_shift = 0;
710 }
711 
712 /**
713  * @brief Set I2S RX to PCM short standard
714  *
715  * @param hw Peripheral I2S hardware instance address.
716  */
i2s_ll_set_rx_pcm_short(i2s_dev_t * hw)717 static inline void i2s_ll_set_rx_pcm_short(i2s_dev_t *hw)
718 {
719     hw->conf.rx_short_sync = 1;
720     hw->conf.rx_msb_shift = 0;
721 }
722 
723 /**
724  * @brief Set I2S TX to PCM long standard
725  *
726  * @param hw Peripheral I2S hardware instance address.
727  */
i2s_ll_set_tx_pcm_long(i2s_dev_t * hw)728 static inline void i2s_ll_set_tx_pcm_long(i2s_dev_t *hw)
729 {
730     hw->conf.tx_short_sync = 0;
731     hw->conf.tx_msb_shift = 0;
732 }
733 
734 /**
735  * @brief Set I2S RX to PCM long standard
736  *
737  * @param hw Peripheral I2S hardware instance address.
738  */
i2s_ll_set_rx_pcm_long(i2s_dev_t * hw)739 static inline void i2s_ll_set_rx_pcm_long(i2s_dev_t *hw)
740 {
741     hw->conf.rx_short_sync = 0;
742     hw->conf.rx_msb_shift = 0;
743 }
744 
745 /**
746  * @brief Enable I2S build in ADC mode
747  *
748  * @param hw Peripheral I2S hardware instance address.
749  */
i2s_ll_build_in_adc_ena(i2s_dev_t * hw)750 static inline void i2s_ll_build_in_adc_ena(i2s_dev_t *hw)
751 {
752     hw->conf2.lcd_en = 1;
753     hw->conf2.camera_en = 0;
754     hw->conf.rx_msb_shift = 0;
755     hw->conf.rx_short_sync = 0;
756 }
757 
758 /**
759  * @brief Enable I2S build in DAC mode
760  *
761  * @param hw Peripheral I2S hardware instance address.
762  */
i2s_ll_build_in_dac_ena(i2s_dev_t * hw)763 static inline void i2s_ll_build_in_dac_ena(i2s_dev_t *hw)
764 {
765     hw->conf2.lcd_en = 1;
766     hw->conf2.camera_en = 0;
767     hw->conf.tx_right_first = 1;
768     hw->conf.tx_msb_shift = 0;
769     hw->conf.tx_short_sync = 0;
770 }
771 
772 
773 /**
774  * @brief Enable I2S RX PDM mode
775  *
776  * @param hw Peripheral I2S hardware instance address.
777  * @param pdm_en Set true to enable rx PDM mode
778  */
i2s_ll_set_rx_pdm_en(i2s_dev_t * hw,bool pdm_en)779 static inline void i2s_ll_set_rx_pdm_en(i2s_dev_t *hw, bool pdm_en)
780 {
781     hw->pdm_conf.rx_pdm_en = pdm_en;
782 }
783 
784 /**
785  * @brief Enable I2S tx pdm mode
786  *
787  * @param hw Peripheral I2S hardware instance address.
788  * @param pdm_en Set true to enable tx PDM mode
789  */
i2s_ll_set_tx_pdm_en(i2s_dev_t * hw,bool pdm_en)790 static inline void i2s_ll_set_tx_pdm_en(i2s_dev_t *hw, bool pdm_en)
791 {
792     hw->pdm_conf.tx_pdm_en = pdm_en;
793 }
794 
795 /**
796  * @brief Configure I2S tx PDM filter module group0
797  *
798  * @param hw Peripheral I2S hardware instance address.
799  * @param fp The fp value of TX PDM filter module group0.
800  * @param fs The fs value of TX PDM filter module group0.
801  */
i2s_ll_tx_pdm_cfg(i2s_dev_t * hw,uint32_t fp,uint32_t fs)802 static inline void i2s_ll_tx_pdm_cfg(i2s_dev_t *hw, uint32_t fp, uint32_t fs)
803 {
804     hw->pdm_freq_conf.tx_pdm_fp = fp;
805     hw->pdm_freq_conf.tx_pdm_fs = fs;
806     hw->pdm_conf.tx_sinc_osr2 = fp/fs;
807     hw->pdm_conf.pcm2pdm_conv_en = 1;
808     hw->pdm_conf.tx_pdm_en = 1;
809 }
810 
811 /**
812  * @brief Configure I2S rx PDM
813  *
814  * @param hw Peripheral I2S hardware instance address.
815  * @param dsr Down-sampling rate value of rx PDM
816  */
i2s_ll_rx_pdm_cfg(i2s_dev_t * hw,uint32_t dsr)817 static inline void i2s_ll_rx_pdm_cfg(i2s_dev_t *hw, uint32_t dsr)
818 {
819     hw->pdm_conf.rx_sinc_dsr_16_en = dsr;
820     hw->pdm_conf.pdm2pcm_conv_en = 1;
821     hw->pdm_conf.rx_pdm_en = 1;
822 }
823 
824 /**
825  * @brief Get I2S tx PDM  configuration
826  *
827  * @param hw Peripheral I2S hardware instance address.
828  * @param fp Pointer to store tx PDM fp configuration
829  * @param fs Pointer to store tx PDM fs configuration
830  */
i2s_ll_get_tx_pdm(i2s_dev_t * hw,uint32_t * fp,uint32_t * fs)831 static inline void i2s_ll_get_tx_pdm(i2s_dev_t *hw, uint32_t *fp, uint32_t *fs)
832 {
833     *fp = hw->pdm_freq_conf.tx_pdm_fp;
834     *fs = hw->pdm_freq_conf.tx_pdm_fs;
835 }
836 
837 /**
838  * @brief Get I2S rx PDM configuration
839  *
840  * @param hw Peripheral I2S hardware instance address.
841  * @param dsr Pointer to stoe the rx PDM down-sample rate configuration
842  */
i2s_ll_get_rx_pdm(i2s_dev_t * hw,uint32_t * dsr)843 static inline void i2s_ll_get_rx_pdm(i2s_dev_t *hw, uint32_t *dsr)
844 {
845     *dsr = hw->pdm_conf.rx_sinc_dsr_16_en;
846 }
847 
848 #ifdef __cplusplus
849 }
850 #endif
851