2121#include "soc/gpio_struct.h"
2222#include "soc/lp_aon_struct.h"
2323#include "soc/pmu_struct.h"
24- #include "soc/usb_serial_jtag_reg.h"
2524#include "soc/pcr_struct.h"
2625#include "soc/clk_tree_defs.h"
26+ #include "soc/io_mux_struct.h"
27+ #include "soc/usb_serial_jtag_struct.h"
2728#include "hal/gpio_types.h"
2829#include "hal/misc.h"
2930#include "hal/assert.h"
@@ -48,18 +49,17 @@ extern "C" {
4849static inline void gpio_ll_get_io_config (gpio_dev_t * hw , uint32_t gpio_num , gpio_io_config_t * io_config )
4950{
5051 uint32_t bit_mask = 1 << gpio_num ;
51- uint32_t iomux_reg_val = REG_READ (IO_MUX_GPIO0_REG + (gpio_num * 4 ));
52- io_config -> pu = (iomux_reg_val & FUN_PU_M ) >> FUN_PU_S ;
53- io_config -> pd = (iomux_reg_val & FUN_PD_M ) >> FUN_PD_S ;
54- io_config -> ie = (iomux_reg_val & FUN_IE_M ) >> FUN_IE_S ;
52+ io_config -> pu = IO_MUX .gpio [gpio_num ].fun_wpu ;
53+ io_config -> pd = IO_MUX .gpio [gpio_num ].fun_wpd ;
54+ io_config -> ie = IO_MUX .gpio [gpio_num ].fun_ie ;
5555 io_config -> oe = (hw -> enable .val & bit_mask ) >> gpio_num ;
5656 io_config -> oe_ctrl_by_periph = !(hw -> funcn_out_sel_cfg [gpio_num ].funcn_oe_sel );
5757 io_config -> oe_inv = hw -> funcn_out_sel_cfg [gpio_num ].funcn_oe_inv_sel ;
5858 io_config -> od = hw -> pinn [gpio_num ].pinn_pad_driver ;
59- io_config -> drv = (gpio_drive_cap_t )(( iomux_reg_val & FUN_DRV_M ) >> FUN_DRV_S ) ;
60- io_config -> fun_sel = ( iomux_reg_val & MCU_SEL_M ) >> MCU_SEL_S ;
59+ io_config -> drv = (gpio_drive_cap_t )IO_MUX . gpio [ gpio_num ]. fun_drv ;
60+ io_config -> fun_sel = IO_MUX . gpio [ gpio_num ]. mcu_sel ;
6161 io_config -> sig_out = hw -> funcn_out_sel_cfg [gpio_num ].funcn_out_sel ;
62- io_config -> slp_sel = ( iomux_reg_val & SLP_SEL_M ) >> SLP_SEL_S ;
62+ io_config -> slp_sel = IO_MUX . gpio [ gpio_num ]. slp_sel ;
6363}
6464
6565/**
@@ -70,7 +70,7 @@ static inline void gpio_ll_get_io_config(gpio_dev_t *hw, uint32_t gpio_num, gpio
7070 */
7171static inline void gpio_ll_pullup_en (gpio_dev_t * hw , gpio_num_t gpio_num )
7272{
73- REG_SET_BIT ( IO_MUX_GPIO0_REG + ( gpio_num * 4 ), FUN_PU ) ;
73+ IO_MUX . gpio [ gpio_num ]. fun_wpu = 1 ;
7474}
7575
7676/**
@@ -88,10 +88,10 @@ static inline void gpio_ll_pullup_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
8888 // which should be checked is USB_INT_PHY0_DM_GPIO_NUM instead.
8989 // TODO: read the specific efuse with efuse_ll.h
9090 if (gpio_num == USB_INT_PHY0_DP_GPIO_NUM ) {
91- SET_PERI_REG_MASK ( USB_SERIAL_JTAG_CONF0_REG , USB_SERIAL_JTAG_PAD_PULL_OVERRIDE ) ;
92- CLEAR_PERI_REG_MASK ( USB_SERIAL_JTAG_CONF0_REG , USB_SERIAL_JTAG_DP_PULLUP ) ;
91+ USB_SERIAL_JTAG . serial_jtag_conf0 . serial_jtag_pad_pull_override = 1 ;
92+ USB_SERIAL_JTAG . serial_jtag_conf0 . serial_jtag_dp_pullup = 0 ;
9393 }
94- REG_CLR_BIT ( IO_MUX_GPIO0_REG + ( gpio_num * 4 ), FUN_PU ) ;
94+ IO_MUX . gpio [ gpio_num ]. fun_wpu = 0 ;
9595}
9696
9797/**
@@ -102,7 +102,7 @@ static inline void gpio_ll_pullup_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
102102 */
103103static inline void gpio_ll_pulldown_en (gpio_dev_t * hw , gpio_num_t gpio_num )
104104{
105- REG_SET_BIT ( IO_MUX_GPIO0_REG + ( gpio_num * 4 ), FUN_PD ) ;
105+ IO_MUX . gpio [ gpio_num ]. fun_wpd = 1 ;
106106}
107107
108108/**
@@ -114,7 +114,7 @@ static inline void gpio_ll_pulldown_en(gpio_dev_t *hw, gpio_num_t gpio_num)
114114__attribute__((always_inline ))
115115static inline void gpio_ll_pulldown_dis (gpio_dev_t * hw , gpio_num_t gpio_num )
116116{
117- REG_CLR_BIT ( IO_MUX_GPIO0_REG + ( gpio_num * 4 ), FUN_PD ) ;
117+ IO_MUX . gpio [ gpio_num ]. fun_wpd = 0 ;
118118}
119119
120120/**
@@ -215,7 +215,7 @@ static inline void gpio_ll_intr_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
215215__attribute__((always_inline ))
216216static inline void gpio_ll_input_disable (gpio_dev_t * hw , gpio_num_t gpio_num )
217217{
218- PIN_INPUT_DISABLE ( IO_MUX_GPIO0_REG + ( gpio_num * 4 )) ;
218+ IO_MUX . gpio [ gpio_num ]. fun_ie = 0 ;
219219}
220220
221221/**
@@ -227,7 +227,7 @@ static inline void gpio_ll_input_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
227227__attribute__((always_inline ))
228228static inline void gpio_ll_input_enable (gpio_dev_t * hw , gpio_num_t gpio_num )
229229{
230- PIN_INPUT_ENABLE ( IO_MUX_GPIO0_REG + ( gpio_num * 4 )) ;
230+ IO_MUX . gpio [ gpio_num ]. fun_ie = 1 ;
231231}
232232
233233/**
@@ -238,7 +238,7 @@ static inline void gpio_ll_input_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
238238 */
239239static inline void gpio_ll_pin_filter_enable (gpio_dev_t * hw , uint32_t gpio_num )
240240{
241- PIN_FILTER_EN ( IO_MUX_GPIO0_REG + ( gpio_num * 4 )) ;
241+ IO_MUX . gpio [ gpio_num ]. filter_en = 1 ;
242242}
243243
244244/**
@@ -249,29 +249,7 @@ static inline void gpio_ll_pin_filter_enable(gpio_dev_t *hw, uint32_t gpio_num)
249249 */
250250static inline void gpio_ll_pin_filter_disable (gpio_dev_t * hw , uint32_t gpio_num )
251251{
252- PIN_FILTER_DIS (IO_MUX_GPIO0_REG + (gpio_num * 4 ));
253- }
254-
255- /**
256- * @brief Select gpio hysteresis control by efuse.
257- *
258- * @param hw Peripheral GPIO hardware instance address.
259- * @param gpio_num GPIO number
260- */
261- static inline void gpio_ll_pin_input_hysteresis_ctrl_sel_efuse (gpio_dev_t * hw , uint32_t gpio_num )
262- {
263- PIN_HYS_EN_SEL_EFUSE (IO_MUX_GPIO0_REG + (gpio_num * 4 ));
264- }
265-
266- /**
267- * @brief Select gpio hysteresis control by software.
268- *
269- * @param hw Peripheral GPIO hardware instance address.
270- * @param gpio_num GPIO number
271- */
272- static inline void gpio_ll_pin_input_hysteresis_ctrl_sel_soft (gpio_dev_t * hw , uint32_t gpio_num )
273- {
274- PIN_HYS_EN_SEL_SOFT (IO_MUX_GPIO0_REG + (gpio_num * 4 ));
252+ IO_MUX .gpio [gpio_num ].filter_en = 0 ;
275253}
276254
277255/**
@@ -282,7 +260,12 @@ static inline void gpio_ll_pin_input_hysteresis_ctrl_sel_soft(gpio_dev_t *hw, ui
282260 */
283261static inline void gpio_ll_pin_input_hysteresis_enable (gpio_dev_t * hw , uint32_t gpio_num )
284262{
285- PIN_HYS_SOFT_ENABLE (IO_MUX_GPIO0_REG + (gpio_num * 4 ));
263+ // On ESP32H21, there is an efuse bit that controls the hysteresis enable or not for all IOs.
264+ // We are not going to use the hardware control for H21.
265+ // Therefore, we need to always switch to use software control first.
266+ // i.e. Swt hys_sel to 1, so that hys_en determines whether hysteresis is enabled or not
267+ IO_MUX .gpio [gpio_num ].hys_sel = 1 ;
268+ IO_MUX .gpio [gpio_num ].hys_en = 1 ;
286269}
287270
288271/**
@@ -293,7 +276,8 @@ static inline void gpio_ll_pin_input_hysteresis_enable(gpio_dev_t *hw, uint32_t
293276 */
294277static inline void gpio_ll_pin_input_hysteresis_disable (gpio_dev_t * hw , uint32_t gpio_num )
295278{
296- PIN_HYS_SOFT_DISABLE (IO_MUX_GPIO0_REG + (gpio_num * 4 ));
279+ IO_MUX .gpio [gpio_num ].hys_sel = 1 ;
280+ IO_MUX .gpio [gpio_num ].hys_en = 0 ;
297281}
298282
299283/**
@@ -424,7 +408,7 @@ static inline void gpio_ll_wakeup_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
424408 */
425409static inline void gpio_ll_set_drive_capability (gpio_dev_t * hw , gpio_num_t gpio_num , gpio_drive_cap_t strength )
426410{
427- SET_PERI_REG_BITS ( IO_MUX_GPIO0_REG + ( gpio_num * 4 ), FUN_DRV_V , strength , FUN_DRV_S ) ;
411+ IO_MUX . gpio [ gpio_num ]. fun_drv = strength ;
428412}
429413
430414/**
@@ -436,7 +420,7 @@ static inline void gpio_ll_set_drive_capability(gpio_dev_t *hw, gpio_num_t gpio_
436420 */
437421static inline void gpio_ll_get_drive_capability (gpio_dev_t * hw , gpio_num_t gpio_num , gpio_drive_cap_t * strength )
438422{
439- * strength = (gpio_drive_cap_t )GET_PERI_REG_BITS2 ( IO_MUX_GPIO0_REG + ( gpio_num * 4 ), FUN_DRV_V , FUN_DRV_S );
423+ * strength = (gpio_drive_cap_t )( IO_MUX . gpio [ gpio_num ]. fun_drv );
440424}
441425
442426/**
@@ -518,11 +502,11 @@ static inline void gpio_ll_set_output_enable_ctrl(gpio_dev_t *hw, uint8_t gpio_n
518502__attribute__((always_inline ))
519503static inline void gpio_ll_func_sel (gpio_dev_t * hw , uint8_t gpio_num , uint32_t func )
520504{
521- // Disable USB Serial JTAG if pins 26 or pins 27 needs to select an IOMUX function
505+ // Disable USB Serial JTAG if pins 17 or pins 18 needs to select an IOMUX function
522506 if (gpio_num == USB_INT_PHY0_DM_GPIO_NUM || gpio_num == USB_INT_PHY0_DP_GPIO_NUM ) {
523- CLEAR_PERI_REG_MASK ( USB_SERIAL_JTAG_CONF0_REG , USB_SERIAL_JTAG_USB_PAD_ENABLE ) ;
507+ USB_SERIAL_JTAG . serial_jtag_conf0 . serial_jtag_usb_pad_enable = 0 ;
524508 }
525- PIN_FUNC_SELECT ( IO_MUX_GPIO0_REG + ( gpio_num * 4 ), func ) ;
509+ IO_MUX . gpio [ gpio_num ]. mcu_sel = func ;
526510}
527511
528512/**
@@ -594,7 +578,7 @@ static inline void gpio_ll_force_unhold_all(void)
594578 */
595579static inline void gpio_ll_sleep_sel_en (gpio_dev_t * hw , gpio_num_t gpio_num )
596580{
597- PIN_SLP_SEL_ENABLE ( IO_MUX_GPIO0_REG + ( gpio_num * 4 )) ;
581+ IO_MUX . gpio [ gpio_num ]. slp_sel = 1 ;
598582}
599583
600584/**
@@ -606,7 +590,7 @@ static inline void gpio_ll_sleep_sel_en(gpio_dev_t *hw, gpio_num_t gpio_num)
606590 */
607591static inline void gpio_ll_sleep_sel_dis (gpio_dev_t * hw , gpio_num_t gpio_num )
608592{
609- PIN_SLP_SEL_DISABLE ( IO_MUX_GPIO0_REG + ( gpio_num * 4 )) ;
593+ IO_MUX . gpio [ gpio_num ]. slp_sel = 0 ;
610594}
611595
612596/**
@@ -617,7 +601,7 @@ static inline void gpio_ll_sleep_sel_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
617601 */
618602static inline void gpio_ll_sleep_pullup_dis (gpio_dev_t * hw , gpio_num_t gpio_num )
619603{
620- PIN_SLP_PULLUP_DISABLE ( IO_MUX_GPIO0_REG + ( gpio_num * 4 )) ;
604+ IO_MUX . gpio [ gpio_num ]. mcu_wpu = 0 ;
621605}
622606
623607/**
@@ -628,7 +612,7 @@ static inline void gpio_ll_sleep_pullup_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
628612 */
629613static inline void gpio_ll_sleep_pullup_en (gpio_dev_t * hw , gpio_num_t gpio_num )
630614{
631- PIN_SLP_PULLUP_ENABLE ( IO_MUX_GPIO0_REG + ( gpio_num * 4 )) ;
615+ IO_MUX . gpio [ gpio_num ]. mcu_wpu = 1 ;
632616}
633617
634618/**
@@ -639,7 +623,7 @@ static inline void gpio_ll_sleep_pullup_en(gpio_dev_t *hw, gpio_num_t gpio_num)
639623 */
640624static inline void gpio_ll_sleep_pulldown_en (gpio_dev_t * hw , gpio_num_t gpio_num )
641625{
642- PIN_SLP_PULLDOWN_ENABLE ( IO_MUX_GPIO0_REG + ( gpio_num * 4 )) ;
626+ IO_MUX . gpio [ gpio_num ]. mcu_wpd = 1 ;
643627}
644628
645629/**
@@ -650,9 +634,8 @@ static inline void gpio_ll_sleep_pulldown_en(gpio_dev_t *hw, gpio_num_t gpio_num
650634 */
651635static inline void gpio_ll_sleep_pulldown_dis (gpio_dev_t * hw , gpio_num_t gpio_num )
652636{
653- PIN_SLP_PULLDOWN_DISABLE ( IO_MUX_GPIO0_REG + ( gpio_num * 4 )) ;
637+ IO_MUX . gpio [ gpio_num ]. mcu_wpd = 0 ;
654638}
655-
656639/**
657640 * @brief Disable GPIO input in sleep mode.
658641 *
@@ -661,7 +644,7 @@ static inline void gpio_ll_sleep_pulldown_dis(gpio_dev_t *hw, gpio_num_t gpio_nu
661644 */
662645static inline void gpio_ll_sleep_input_disable (gpio_dev_t * hw , gpio_num_t gpio_num )
663646{
664- PIN_SLP_INPUT_DISABLE ( IO_MUX_GPIO0_REG + ( gpio_num * 4 )) ;
647+ IO_MUX . gpio [ gpio_num ]. mcu_ie = 0 ;
665648}
666649
667650/**
@@ -672,7 +655,7 @@ static inline void gpio_ll_sleep_input_disable(gpio_dev_t *hw, gpio_num_t gpio_n
672655 */
673656static inline void gpio_ll_sleep_input_enable (gpio_dev_t * hw , gpio_num_t gpio_num )
674657{
675- PIN_SLP_INPUT_ENABLE ( IO_MUX_GPIO0_REG + ( gpio_num * 4 )) ;
658+ IO_MUX . gpio [ gpio_num ]. mcu_ie = 1 ;
676659}
677660
678661/**
@@ -683,7 +666,7 @@ static inline void gpio_ll_sleep_input_enable(gpio_dev_t *hw, gpio_num_t gpio_nu
683666 */
684667static inline void gpio_ll_sleep_output_disable (gpio_dev_t * hw , gpio_num_t gpio_num )
685668{
686- PIN_SLP_OUTPUT_DISABLE ( IO_MUX_GPIO0_REG + ( gpio_num * 4 )) ;
669+ IO_MUX . gpio [ gpio_num ]. mcu_oe = 0 ;
687670}
688671
689672/**
@@ -694,7 +677,7 @@ static inline void gpio_ll_sleep_output_disable(gpio_dev_t *hw, gpio_num_t gpio_
694677 */
695678static inline void gpio_ll_sleep_output_enable (gpio_dev_t * hw , gpio_num_t gpio_num )
696679{
697- PIN_SLP_OUTPUT_ENABLE ( IO_MUX_GPIO0_REG + ( gpio_num * 4 )) ;
680+ IO_MUX . gpio [ gpio_num ]. mcu_oe = 1 ;
698681}
699682
700683/**
0 commit comments