• 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 GPIO register operations
22 
23 #pragma once
24 
25 #include <stdbool.h>
26 #include "soc/soc.h"
27 #include "soc/gpio_periph.h"
28 #include "soc/rtc_cntl_reg.h"
29 #include "soc/rtc_io_reg.h"
30 #include "hal/gpio_types.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 // Get GPIO hardware instance with giving gpio num
37 #define GPIO_LL_GET_HW(num) (((num) == 0) ? (&GPIO) : NULL)
38 
39 #define GPIO_LL_APP_CPU_INTR_ENA      (BIT(0))
40 #define GPIO_LL_APP_CPU_NMI_INTR_ENA  (BIT(1))
41 #define GPIO_LL_PRO_CPU_INTR_ENA      (BIT(2))
42 #define GPIO_LL_PRO_CPU_NMI_INTR_ENA  (BIT(3))
43 #define GPIO_LL_SDIO_EXT_INTR_ENA     (BIT(4))
44 
45 /**
46   * @brief Enable pull-up on GPIO.
47   *
48   * @param hw Peripheral GPIO hardware instance address.
49   * @param gpio_num GPIO number
50   */
gpio_ll_pullup_en(gpio_dev_t * hw,gpio_num_t gpio_num)51 static inline void gpio_ll_pullup_en(gpio_dev_t *hw, gpio_num_t gpio_num)
52 {
53     REG_SET_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PU);
54 }
55 
56 /**
57   * @brief Disable pull-up on GPIO.
58   *
59   * @param hw Peripheral GPIO hardware instance address.
60   * @param gpio_num GPIO number
61   */
gpio_ll_pullup_dis(gpio_dev_t * hw,gpio_num_t gpio_num)62 static inline void gpio_ll_pullup_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
63 {
64     REG_CLR_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PU);
65 }
66 
67 /**
68   * @brief Return pull-up status on GPIO.
69   *
70   * @param hw Peripheral GPIO hardware instance address.
71   * @param gpio_num GPIO number
72   * @return if GPIO gpio_num`s FUN_PU is true
73   */
gpio_ll_pullup_is_enabled(gpio_dev_t * hw,gpio_num_t gpio_num)74 static inline bool gpio_ll_pullup_is_enabled(gpio_dev_t *hw, gpio_num_t gpio_num)
75 {
76     return REG_GET_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PU) ? true : false;
77 }
78 
79 /**
80   * @brief Enable pull-down on GPIO.
81   *
82   * @param hw Peripheral GPIO hardware instance address.
83   * @param gpio_num GPIO number
84   */
gpio_ll_pulldown_en(gpio_dev_t * hw,gpio_num_t gpio_num)85 static inline void gpio_ll_pulldown_en(gpio_dev_t *hw, gpio_num_t gpio_num)
86 {
87     REG_SET_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PD);
88 }
89 
90 /**
91   * @brief Disable pull-down on GPIO.
92   *
93   * @param hw Peripheral GPIO hardware instance address.
94   * @param gpio_num GPIO number
95   */
gpio_ll_pulldown_dis(gpio_dev_t * hw,gpio_num_t gpio_num)96 static inline void gpio_ll_pulldown_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
97 {
98     REG_CLR_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PD);
99 }
100 
101 /**
102   * @brief Return pull-down status on GPIO.
103   *
104   * @param hw Peripheral GPIO hardware instance address.
105   * @param gpio_num GPIO number
106   * @return if GPIO gpio_num`s FUN_PD is true
107   */
gpio_ll_pulldown_is_enabled(gpio_dev_t * hw,gpio_num_t gpio_num)108 static inline bool gpio_ll_pulldown_is_enabled(gpio_dev_t *hw, gpio_num_t gpio_num)
109 {
110     return REG_GET_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PD) ? true : false;
111 }
112 
113 /**
114   * @brief Enable GPIO pin used for wakeup from sleep.
115   *
116   * @param hw Peripheral GPIO hardware instance address.
117   * @param gpio_num GPIO number
118   */
gpio_ll_sleep_sel_en(gpio_dev_t * hw,gpio_num_t gpio_num)119 static inline void gpio_ll_sleep_sel_en(gpio_dev_t *hw, gpio_num_t gpio_num)
120 {
121     PIN_SLP_SEL_ENABLE(GPIO_PIN_MUX_REG[gpio_num]);
122 }
123 
124 /**
125   * @brief Disable GPIO pin used for wakeup from sleep.
126   *
127   * @param hw Peripheral GPIO hardware instance address.
128   * @param gpio_num GPIO number
129   */
gpio_ll_sleep_sel_dis(gpio_dev_t * hw,gpio_num_t gpio_num)130 static inline void gpio_ll_sleep_sel_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
131 {
132     PIN_SLP_SEL_DISABLE(GPIO_PIN_MUX_REG[gpio_num]);
133 }
134 
135 /**
136   * @brief Return slp-sel status on GPIO.
137   *
138   * @param hw Peripheral GPIO hardware instance address.
139   * @param gpio_num GPIO number
140   * @return if GPIO gpio_num`s SLP_SEL is true
141   */
gpio_ll_sleep_sel_is_enabled(gpio_dev_t * hw,gpio_num_t gpio_num)142 static inline bool gpio_ll_sleep_sel_is_enabled(gpio_dev_t *hw, gpio_num_t gpio_num)
143 {
144     return REG_GET_BIT(GPIO_PIN_MUX_REG[gpio_num], SLP_SEL) ? true : false;
145 }
146 
147 /**
148   * @brief Disable GPIO pull-up in sleep mode.
149   *
150   * @param hw Peripheral GPIO hardware instance address.
151   * @param gpio_num GPIO number
152   */
gpio_ll_sleep_pullup_dis(gpio_dev_t * hw,gpio_num_t gpio_num)153 static inline void gpio_ll_sleep_pullup_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
154 {
155     PIN_SLP_PULLUP_DISABLE(GPIO_PIN_MUX_REG[gpio_num]);
156 }
157 
158 /**
159   * @brief Enable GPIO pull-up in sleep mode.
160   *
161   * @param hw Peripheral GPIO hardware instance address.
162   * @param gpio_num GPIO number
163   */
gpio_ll_sleep_pullup_en(gpio_dev_t * hw,gpio_num_t gpio_num)164 static inline void gpio_ll_sleep_pullup_en(gpio_dev_t *hw, gpio_num_t gpio_num)
165 {
166     PIN_SLP_PULLUP_ENABLE(GPIO_PIN_MUX_REG[gpio_num]);
167 }
168 
169 /**
170   * @brief Return slp-pull-up status on GPIO.
171   *
172   * @param hw Peripheral GPIO hardware instance address.
173   * @param gpio_num GPIO number
174   * @return if GPIO gpio_num`s SLP_PU is true
175   */
gpio_ll_sleep_pullup_is_enabled(gpio_dev_t * hw,gpio_num_t gpio_num)176 static inline bool gpio_ll_sleep_pullup_is_enabled(gpio_dev_t *hw, gpio_num_t gpio_num)
177 {
178     return REG_GET_BIT(GPIO_PIN_MUX_REG[gpio_num], SLP_PU) ? true : false;
179 }
180 
181 /**
182   * @brief Enable GPIO pull-down in sleep mode.
183   *
184   * @param hw Peripheral GPIO hardware instance address.
185   * @param gpio_num GPIO number
186   */
gpio_ll_sleep_pulldown_en(gpio_dev_t * hw,gpio_num_t gpio_num)187 static inline void gpio_ll_sleep_pulldown_en(gpio_dev_t *hw, gpio_num_t gpio_num)
188 {
189     PIN_SLP_PULLDOWN_ENABLE(GPIO_PIN_MUX_REG[gpio_num]);
190 }
191 
192 /**
193   * @brief Disable GPIO pull-down in sleep mode.
194   *
195   * @param hw Peripheral GPIO hardware instance address.
196   * @param gpio_num GPIO number
197   */
gpio_ll_sleep_pulldown_dis(gpio_dev_t * hw,gpio_num_t gpio_num)198 static inline void gpio_ll_sleep_pulldown_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
199 {
200     PIN_SLP_PULLDOWN_DISABLE(GPIO_PIN_MUX_REG[gpio_num]);
201 }
202 
203 /**
204   * @brief Return slp-pull-down status on GPIO.
205   *
206   * @param hw Peripheral GPIO hardware instance address.
207   * @param gpio_num GPIO number
208   * @return if GPIO gpio_num`s SLP_PD is true
209   */
gpio_ll_sleep_pulldown_is_enabled(gpio_dev_t * hw,gpio_num_t gpio_num)210 static inline bool gpio_ll_sleep_pulldown_is_enabled(gpio_dev_t *hw, gpio_num_t gpio_num)
211 {
212     return REG_GET_BIT(GPIO_PIN_MUX_REG[gpio_num], SLP_PD) ? true : false;
213 }
214 
215 /**
216  * @brief  GPIO set interrupt trigger type
217  *
218  * @param  hw Peripheral GPIO hardware instance address.
219  * @param  gpio_num GPIO number. If you want to set the trigger type of e.g. of GPIO16, gpio_num should be GPIO_NUM_16 (16);
220  * @param  intr_type Interrupt type, select from gpio_int_type_t
221  */
gpio_ll_set_intr_type(gpio_dev_t * hw,gpio_num_t gpio_num,gpio_int_type_t intr_type)222 static inline void gpio_ll_set_intr_type(gpio_dev_t *hw, gpio_num_t gpio_num, gpio_int_type_t intr_type)
223 {
224     hw->pin[gpio_num].int_type = intr_type;
225 }
226 
227 /**
228   * @brief Get GPIO interrupt status
229   *
230   * @param hw Peripheral GPIO hardware instance address.
231   * @param core_id interrupt core id
232   * @param status interrupt status
233   */
gpio_ll_get_intr_status(gpio_dev_t * hw,uint32_t core_id,uint32_t * status)234 static inline void gpio_ll_get_intr_status(gpio_dev_t *hw, uint32_t core_id, uint32_t *status)
235 {
236     *status = (core_id == 0) ? hw->pcpu_int : hw->acpu_int;
237 }
238 
239 /**
240   * @brief Get GPIO interrupt status high
241   *
242   * @param hw Peripheral GPIO hardware instance address.
243   * @param core_id interrupt core id
244   * @param status interrupt status high
245   */
gpio_ll_get_intr_status_high(gpio_dev_t * hw,uint32_t core_id,uint32_t * status)246 static inline void gpio_ll_get_intr_status_high(gpio_dev_t *hw, uint32_t core_id, uint32_t *status)
247 {
248     *status = (core_id == 0) ? hw->pcpu_int1.intr : hw->acpu_int1.intr;
249 }
250 
251 /**
252   * @brief Clear GPIO interrupt status
253   *
254   * @param hw Peripheral GPIO hardware instance address.
255   * @param mask interrupt status clear mask
256   */
gpio_ll_clear_intr_status(gpio_dev_t * hw,uint32_t mask)257 static inline void gpio_ll_clear_intr_status(gpio_dev_t *hw, uint32_t mask)
258 {
259     hw->status_w1tc = mask;
260 }
261 
262 /**
263   * @brief Clear GPIO interrupt status high
264   *
265   * @param hw Peripheral GPIO hardware instance address.
266   * @param mask interrupt status high clear mask
267   */
gpio_ll_clear_intr_status_high(gpio_dev_t * hw,uint32_t mask)268 static inline void gpio_ll_clear_intr_status_high(gpio_dev_t *hw, uint32_t mask)
269 {
270     hw->status1_w1tc.intr_st = mask;
271 }
272 
273 /**
274  * @brief  Enable GPIO module interrupt signal
275  *
276  * @param  hw Peripheral GPIO hardware instance address.
277  * @param  core_id Interrupt enabled CPU to corresponding ID
278  * @param  gpio_num GPIO number. If you want to enable the interrupt of e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
279  */
gpio_ll_intr_enable_on_core(gpio_dev_t * hw,uint32_t core_id,gpio_num_t gpio_num)280 static inline void gpio_ll_intr_enable_on_core(gpio_dev_t *hw, uint32_t core_id, gpio_num_t gpio_num)
281 {
282     if (core_id == 0) {
283         hw->pin[gpio_num].int_ena = GPIO_LL_PRO_CPU_INTR_ENA;     //enable pro cpu intr
284     } else {
285         hw->pin[gpio_num].int_ena = GPIO_LL_APP_CPU_INTR_ENA;     //enable pro cpu intr
286     }
287 }
288 
289 /**
290  * @brief  Disable GPIO module interrupt signal
291  *
292  * @param  hw Peripheral GPIO hardware instance address.
293  * @param  gpio_num GPIO number. If you want to disable the interrupt of e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
294  */
gpio_ll_intr_disable(gpio_dev_t * hw,gpio_num_t gpio_num)295 static inline void gpio_ll_intr_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
296 {
297     hw->pin[gpio_num].int_ena = 0;                             //disable GPIO intr
298 }
299 
300 /**
301   * @brief Disable input mode on GPIO.
302   *
303   * @param hw Peripheral GPIO hardware instance address.
304   * @param gpio_num GPIO number
305   */
gpio_ll_input_disable(gpio_dev_t * hw,gpio_num_t gpio_num)306 static inline void gpio_ll_input_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
307 {
308     PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[gpio_num]);
309 }
310 
311 /**
312   * @brief Enable input mode on GPIO.
313   *
314   * @param hw Peripheral GPIO hardware instance address.
315   * @param gpio_num GPIO number
316   */
gpio_ll_input_enable(gpio_dev_t * hw,gpio_num_t gpio_num)317 static inline void gpio_ll_input_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
318 {
319     PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[gpio_num]);
320 }
321 
322 /**
323   * @brief Disable output mode on GPIO.
324   *
325   * @param hw Peripheral GPIO hardware instance address.
326   * @param gpio_num GPIO number
327   */
gpio_ll_output_disable(gpio_dev_t * hw,gpio_num_t gpio_num)328 static inline void gpio_ll_output_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
329 {
330     if (gpio_num < 32) {
331         hw->enable_w1tc = (0x1 << gpio_num);
332     } else {
333         hw->enable1_w1tc.data = (0x1 << (gpio_num - 32));
334     }
335 
336     // Ensure no other output signal is routed via GPIO matrix to this pin
337     REG_WRITE(GPIO_FUNC0_OUT_SEL_CFG_REG + (gpio_num * 4),
338               SIG_GPIO_OUT_IDX);
339 }
340 
341 /**
342   * @brief Enable output mode on GPIO.
343   *
344   * @param hw Peripheral GPIO hardware instance address.
345   * @param gpio_num GPIO number
346   */
gpio_ll_output_enable(gpio_dev_t * hw,gpio_num_t gpio_num)347 static inline void gpio_ll_output_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
348 {
349     if (gpio_num < 32) {
350         hw->enable_w1ts = (0x1 << gpio_num);
351     } else {
352         hw->enable1_w1ts.data = (0x1 << (gpio_num - 32));
353     }
354 }
355 
356 /**
357   * @brief Disable GPIO input in sleep mode.
358   *
359   * @param hw Peripheral GPIO hardware instance address.
360   * @param gpio_num GPIO number
361   */
gpio_ll_sleep_input_disable(gpio_dev_t * hw,gpio_num_t gpio_num)362 static inline void gpio_ll_sleep_input_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
363 {
364     PIN_SLP_INPUT_DISABLE(GPIO_PIN_MUX_REG[gpio_num]);
365 }
366 
367 /**
368   * @brief Enable GPIO input in sleep mode.
369   *
370   * @param hw Peripheral GPIO hardware instance address.
371   * @param gpio_num GPIO number
372   */
gpio_ll_sleep_input_enable(gpio_dev_t * hw,gpio_num_t gpio_num)373 static inline void gpio_ll_sleep_input_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
374 {
375     PIN_SLP_INPUT_ENABLE(GPIO_PIN_MUX_REG[gpio_num]);
376 }
377 
378 /**
379   * @brief Disable GPIO output in sleep mode.
380   *
381   * @param hw Peripheral GPIO hardware instance address.
382   * @param gpio_num GPIO number
383   */
gpio_ll_sleep_output_disable(gpio_dev_t * hw,gpio_num_t gpio_num)384 static inline void gpio_ll_sleep_output_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
385 {
386     PIN_SLP_OUTPUT_DISABLE(GPIO_PIN_MUX_REG[gpio_num]);
387 }
388 
389 /**
390   * @brief Enable GPIO output in sleep mode.
391   *
392   * @param hw Peripheral GPIO hardware instance address.
393   * @param gpio_num GPIO number
394   */
gpio_ll_sleep_output_enable(gpio_dev_t * hw,gpio_num_t gpio_num)395 static inline void gpio_ll_sleep_output_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
396 {
397     PIN_SLP_OUTPUT_ENABLE(GPIO_PIN_MUX_REG[gpio_num]);
398 }
399 
400 /**
401   * @brief Disable open-drain mode on GPIO.
402   *
403   * @param hw Peripheral GPIO hardware instance address.
404   * @param gpio_num GPIO number
405   */
gpio_ll_od_disable(gpio_dev_t * hw,gpio_num_t gpio_num)406 static inline void gpio_ll_od_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
407 {
408     hw->pin[gpio_num].pad_driver = 0;
409 }
410 
411 /**
412   * @brief Enable open-drain mode on GPIO.
413   *
414   * @param hw Peripheral GPIO hardware instance address.
415   * @param gpio_num GPIO number
416   */
gpio_ll_od_enable(gpio_dev_t * hw,gpio_num_t gpio_num)417 static inline void gpio_ll_od_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
418 {
419     hw->pin[gpio_num].pad_driver = 1;
420 }
421 
422 /**
423  * @brief  GPIO set output level
424  *
425  * @param  hw Peripheral GPIO hardware instance address.
426  * @param  gpio_num GPIO number. If you want to set the output level of e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
427  * @param  level Output level. 0: low ; 1: high
428  */
gpio_ll_set_level(gpio_dev_t * hw,gpio_num_t gpio_num,uint32_t level)429 static inline void gpio_ll_set_level(gpio_dev_t *hw, gpio_num_t gpio_num, uint32_t level)
430 {
431     if (level) {
432         if (gpio_num < 32) {
433             hw->out_w1ts = (1 << gpio_num);
434         } else {
435             hw->out1_w1ts.data = (1 << (gpio_num - 32));
436         }
437     } else {
438         if (gpio_num < 32) {
439             hw->out_w1tc = (1 << gpio_num);
440         } else {
441             hw->out1_w1tc.data = (1 << (gpio_num - 32));
442         }
443     }
444 }
445 
446 /**
447  * @brief  GPIO get input level
448  *
449  * @warning If the pad is not configured for input (or input and output) the returned value is always 0.
450  *
451  * @param  hw Peripheral GPIO hardware instance address.
452  * @param  gpio_num GPIO number. If you want to get the logic level of e.g. pin GPIO16, gpio_num should be GPIO_NUM_16 (16);
453  *
454  * @return
455  *     - 0 the GPIO input level is 0
456  *     - 1 the GPIO input level is 1
457  */
gpio_ll_get_level(gpio_dev_t * hw,gpio_num_t gpio_num)458 static inline int gpio_ll_get_level(gpio_dev_t *hw, gpio_num_t gpio_num)
459 {
460     if (gpio_num < 32) {
461         return (hw->in >> gpio_num) & 0x1;
462     } else {
463         return (hw->in1.data >> (gpio_num - 32)) & 0x1;
464     }
465 }
466 
467 /**
468  * @brief Enable GPIO wake-up function.
469  *
470  * @param hw Peripheral GPIO hardware instance address.
471  * @param gpio_num GPIO number.
472  * @param intr_type GPIO wake-up type. Only GPIO_INTR_LOW_LEVEL or GPIO_INTR_HIGH_LEVEL can be used.
473  */
gpio_ll_wakeup_enable(gpio_dev_t * hw,gpio_num_t gpio_num,gpio_int_type_t intr_type)474 static inline void gpio_ll_wakeup_enable(gpio_dev_t *hw, gpio_num_t gpio_num, gpio_int_type_t intr_type)
475 {
476     hw->pin[gpio_num].int_type = intr_type;
477     hw->pin[gpio_num].wakeup_enable = 0x1;
478 }
479 
480 /**
481  * @brief Disable GPIO wake-up function.
482  *
483  * @param hw Peripheral GPIO hardware instance address.
484  * @param gpio_num GPIO number
485  */
gpio_ll_wakeup_disable(gpio_dev_t * hw,gpio_num_t gpio_num)486 static inline void gpio_ll_wakeup_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
487 {
488     hw->pin[gpio_num].wakeup_enable = 0;
489 }
490 
491 /**
492   * @brief Set GPIO pad drive capability
493   *
494   * @param hw Peripheral GPIO hardware instance address.
495   * @param gpio_num GPIO number, only support output GPIOs
496   * @param strength Drive capability of the pad
497   */
gpio_ll_set_drive_capability(gpio_dev_t * hw,gpio_num_t gpio_num,gpio_drive_cap_t strength)498 static inline void gpio_ll_set_drive_capability(gpio_dev_t *hw, gpio_num_t gpio_num, gpio_drive_cap_t strength)
499 {
500     SET_PERI_REG_BITS(GPIO_PIN_MUX_REG[gpio_num], FUN_DRV_V, strength, FUN_DRV_S);
501 }
502 
503 /**
504   * @brief Get GPIO pad drive capability
505   *
506   * @param hw Peripheral GPIO hardware instance address.
507   * @param gpio_num GPIO number, only support output GPIOs
508   * @param strength Pointer to accept drive capability of the pad
509   */
gpio_ll_get_drive_capability(gpio_dev_t * hw,gpio_num_t gpio_num,gpio_drive_cap_t * strength)510 static inline void gpio_ll_get_drive_capability(gpio_dev_t *hw, gpio_num_t gpio_num, gpio_drive_cap_t *strength)
511 {
512     *strength = GET_PERI_REG_BITS2(GPIO_PIN_MUX_REG[gpio_num], FUN_DRV_V, FUN_DRV_S);
513 }
514 
515 /**
516   * @brief Enable all digital gpio pad hold function during Deep-sleep.
517   *
518   * @param hw Peripheral GPIO hardware instance address.
519   */
gpio_ll_deep_sleep_hold_en(gpio_dev_t * hw)520 static inline void gpio_ll_deep_sleep_hold_en(gpio_dev_t *hw)
521 {
522     SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_AUTOHOLD_EN_M);
523 }
524 
525 /**
526   * @brief Disable all digital gpio pad hold function during Deep-sleep.
527   *
528   * @param hw Peripheral GPIO hardware instance address.
529   */
gpio_ll_deep_sleep_hold_dis(gpio_dev_t * hw)530 static inline void gpio_ll_deep_sleep_hold_dis(gpio_dev_t *hw)
531 {
532     CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_AUTOHOLD_EN_M);
533 }
534 
535 /**
536   * @brief Enable gpio pad hold function.
537   *
538   * @param hw Peripheral GPIO hardware instance address.
539   * @param gpio_num GPIO number, only support output GPIOs
540   */
gpio_ll_hold_en(gpio_dev_t * hw,gpio_num_t gpio_num)541 static inline void gpio_ll_hold_en(gpio_dev_t *hw, gpio_num_t gpio_num)
542 {
543     SET_PERI_REG_MASK(RTC_IO_DIG_PAD_HOLD_REG, GPIO_HOLD_MASK[gpio_num]);
544 }
545 
546 /**
547   * @brief Disable gpio pad hold function.
548   *
549   * @param hw Peripheral GPIO hardware instance address.
550   * @param gpio_num GPIO number, only support output GPIOs
551   */
gpio_ll_hold_dis(gpio_dev_t * hw,gpio_num_t gpio_num)552 static inline void gpio_ll_hold_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
553 {
554     CLEAR_PERI_REG_MASK(RTC_IO_DIG_PAD_HOLD_REG, GPIO_HOLD_MASK[gpio_num]);
555 }
556 
557 /**
558   * @brief Set pad input to a peripheral signal through the IOMUX.
559   *
560   * @param hw Peripheral GPIO hardware instance address.
561   * @param gpio_num GPIO number of the pad.
562   * @param signal_idx Peripheral signal id to input. One of the ``*_IN_IDX`` signals in ``soc/gpio_sig_map.h``.
563   */
gpio_ll_iomux_in(gpio_dev_t * hw,uint32_t gpio,uint32_t signal_idx)564 static inline void gpio_ll_iomux_in(gpio_dev_t *hw, uint32_t gpio, uint32_t signal_idx)
565 {
566     hw->func_in_sel_cfg[signal_idx].sig_in_sel = 0;
567     PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[gpio]);
568 }
569 
570 /**
571  * @brief  Select a function for the pin in the IOMUX
572  *
573  * @param  pin_name Pin name to configure
574  * @param  func Function to assign to the pin
575  */
gpio_ll_iomux_func_sel(uint32_t pin_name,uint32_t func)576 static inline void gpio_ll_iomux_func_sel(uint32_t pin_name, uint32_t func)
577 {
578     PIN_FUNC_SELECT(pin_name, func);
579 }
580 
581 /**
582   * @brief Set peripheral output to an GPIO pad through the IOMUX.
583   *
584   * @param hw Peripheral GPIO hardware instance address.
585   * @param gpio_num gpio_num GPIO number of the pad.
586   * @param func The function number of the peripheral pin to output pin.
587   *        One of the ``FUNC_X_*`` of specified pin (X) in ``soc/io_mux_reg.h``.
588   * @param oen_inv True if the output enable needs to be inverted, otherwise False.
589   */
gpio_ll_iomux_out(gpio_dev_t * hw,uint8_t gpio_num,int func,uint32_t oen_inv)590 static inline void gpio_ll_iomux_out(gpio_dev_t *hw, uint8_t gpio_num, int func, uint32_t oen_inv)
591 {
592     hw->func_out_sel_cfg[gpio_num].oen_sel = 0;
593     hw->func_out_sel_cfg[gpio_num].oen_inv_sel = oen_inv;
594     gpio_ll_iomux_func_sel(GPIO_PIN_MUX_REG[gpio_num], func);
595 }
596 
597 #ifdef __cplusplus
598 }
599 #endif
600