|
|
@@ -14,32 +14,24 @@
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
+#include <stdlib.h>
|
|
|
+#include <stdbool.h>
|
|
|
#include "soc/soc.h"
|
|
|
#include "soc/gpio_periph.h"
|
|
|
#include "soc/gpio_struct.h"
|
|
|
-#include "soc/lp_aon_reg.h"
|
|
|
+#include "soc/lp_aon_struct.h"
|
|
|
#include "soc/pmu_reg.h"
|
|
|
+#include "soc/usb_serial_jtag_reg.h"
|
|
|
+#include "soc/pcr_struct.h"
|
|
|
+#include "soc/clk_tree_defs.h"
|
|
|
#include "hal/gpio_types.h"
|
|
|
-#include <stdlib.h>
|
|
|
-#include <stdbool.h>
|
|
|
+#include "hal/misc.h"
|
|
|
+#include "hal/assert.h"
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
extern "C" {
|
|
|
#endif
|
|
|
|
|
|
-// ESP32H2-TODO: comment some code, please add support on gpio, IDF-6227
|
|
|
-
|
|
|
-/*
|
|
|
- * The following defines are used to disable USB JTAG when pins 18 and pins 19
|
|
|
- * are set to be used as GPIO.
|
|
|
- * See gpio_pad_select_gpio() below.
|
|
|
- *
|
|
|
- * TODO: Delete these definitions once the USB device registers definition is
|
|
|
- * merged.
|
|
|
- */
|
|
|
-#define USB_DEVICE_CONF0_REG (0x60043018)
|
|
|
-#define USB_DEVICE_USB_PAD_ENABLE (BIT(14))
|
|
|
-
|
|
|
// Get GPIO hardware instance with giving gpio num
|
|
|
#define GPIO_LL_GET_HW(num) (((num) == 0) ? (&GPIO) : NULL)
|
|
|
|
|
|
@@ -53,7 +45,7 @@ extern "C" {
|
|
|
*/
|
|
|
static inline void gpio_ll_pullup_en(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- REG_SET_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PU);
|
|
|
+ REG_SET_BIT(IO_MUX_GPIO0_REG + (gpio_num * 4), FUN_PU);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -62,9 +54,10 @@ static inline void gpio_ll_pullup_en(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
* @param hw Peripheral GPIO hardware instance address.
|
|
|
* @param gpio_num GPIO number
|
|
|
*/
|
|
|
+__attribute__((always_inline))
|
|
|
static inline void gpio_ll_pullup_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- REG_CLR_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PU);
|
|
|
+ REG_CLR_BIT(IO_MUX_GPIO0_REG + (gpio_num * 4), FUN_PU);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -75,7 +68,7 @@ static inline void gpio_ll_pullup_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
*/
|
|
|
static inline void gpio_ll_pulldown_en(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- REG_SET_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PD);
|
|
|
+ REG_SET_BIT(IO_MUX_GPIO0_REG + (gpio_num * 4), FUN_PD);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -84,9 +77,19 @@ static inline void gpio_ll_pulldown_en(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
* @param hw Peripheral GPIO hardware instance address.
|
|
|
* @param gpio_num GPIO number
|
|
|
*/
|
|
|
+__attribute__((always_inline))
|
|
|
static inline void gpio_ll_pulldown_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- REG_CLR_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PD);
|
|
|
+ // The pull-up value of the USB pins are controlled by the pins’ pull-up value together with USB pull-up value
|
|
|
+ // USB DP pin is default to PU enabled
|
|
|
+ // Note that esp32h2 has supported USB_EXCHG_PINS feature. If this efuse is burnt, the gpio pin
|
|
|
+ // which should be checked is USB_DM_GPIO_NUM instead.
|
|
|
+ // TODO: read the specific efuse with efuse_ll.h
|
|
|
+ if (gpio_num == USB_DP_GPIO_NUM) {
|
|
|
+ SET_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_PAD_PULL_OVERRIDE);
|
|
|
+ CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_DP_PULLUP);
|
|
|
+ }
|
|
|
+ REG_CLR_BIT(IO_MUX_GPIO0_REG + (gpio_num * 4), FUN_PD);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -98,8 +101,7 @@ static inline void gpio_ll_pulldown_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
*/
|
|
|
static inline void gpio_ll_set_intr_type(gpio_dev_t *hw, gpio_num_t gpio_num, gpio_int_type_t intr_type)
|
|
|
{
|
|
|
- // hw->pin[gpio_num].int_type = intr_type;
|
|
|
- // ESP32H2-TODO: IDF-6227 updated struct file not support yet
|
|
|
+ hw->pin[gpio_num].int_type = intr_type;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -112,7 +114,8 @@ static inline void gpio_ll_set_intr_type(gpio_dev_t *hw, gpio_num_t gpio_num, gp
|
|
|
__attribute__((always_inline))
|
|
|
static inline void gpio_ll_get_intr_status(gpio_dev_t *hw, uint32_t core_id, uint32_t *status)
|
|
|
{
|
|
|
- *status = hw->pcpu_int.val;
|
|
|
+ (void)core_id;
|
|
|
+ *status = hw->pcpu_int.procpu_int;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -137,7 +140,7 @@ static inline void gpio_ll_get_intr_status_high(gpio_dev_t *hw, uint32_t core_id
|
|
|
__attribute__((always_inline))
|
|
|
static inline void gpio_ll_clear_intr_status(gpio_dev_t *hw, uint32_t mask)
|
|
|
{
|
|
|
- // hw->status_w1tc = mask;
|
|
|
+ hw->status_w1tc.status_w1tc = mask;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -149,7 +152,7 @@ static inline void gpio_ll_clear_intr_status(gpio_dev_t *hw, uint32_t mask)
|
|
|
__attribute__((always_inline))
|
|
|
static inline void gpio_ll_clear_intr_status_high(gpio_dev_t *hw, uint32_t mask)
|
|
|
{
|
|
|
- // Not supported on H2
|
|
|
+ // Less than 32 GPIOs on ESP32-H2 Do nothing.
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -159,16 +162,11 @@ static inline void gpio_ll_clear_intr_status_high(gpio_dev_t *hw, uint32_t mask)
|
|
|
* @param core_id Interrupt enabled CPU to corresponding ID
|
|
|
* @param gpio_num GPIO number. If you want to enable the interrupt of e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
|
|
|
*/
|
|
|
+__attribute__((always_inline))
|
|
|
static inline void gpio_ll_intr_enable_on_core(gpio_dev_t *hw, uint32_t core_id, gpio_num_t gpio_num)
|
|
|
{
|
|
|
-// ESP32H2-TODO: IDF-6227 updated struct file not support yet
|
|
|
-#if 0
|
|
|
- if (core_id == 0) {
|
|
|
- GPIO.pin[gpio_num].int_ena = GPIO_LL_PRO_CPU_INTR_ENA; //enable pro cpu intr
|
|
|
- } else {
|
|
|
- // GPIO.pin[gpio_num].int_ena = GPIO_APP_CPU_INTR_ENA; //enable pro cpu intr
|
|
|
- }
|
|
|
-#endif
|
|
|
+ HAL_ASSERT(core_id == 0 && "target SoC only has a single core");
|
|
|
+ GPIO.pin[gpio_num].int_ena = GPIO_LL_PRO_CPU_INTR_ENA; //enable pro cpu intr
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -177,10 +175,10 @@ static inline void gpio_ll_intr_enable_on_core(gpio_dev_t *hw, uint32_t core_id,
|
|
|
* @param hw Peripheral GPIO hardware instance address.
|
|
|
* @param gpio_num GPIO number. If you want to disable the interrupt of e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
|
|
|
*/
|
|
|
+__attribute__((always_inline))
|
|
|
static inline void gpio_ll_intr_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2-TODO: IDF-6227 updated struct file not support yet
|
|
|
- // hw->pin[gpio_num].int_ena = 0; //disable GPIO intr
|
|
|
+ hw->pin[gpio_num].int_ena = 0; //disable GPIO intr
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -189,9 +187,10 @@ static inline void gpio_ll_intr_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
* @param hw Peripheral GPIO hardware instance address.
|
|
|
* @param gpio_num GPIO number
|
|
|
*/
|
|
|
+__attribute__((always_inline))
|
|
|
static inline void gpio_ll_input_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[gpio_num]);
|
|
|
+ PIN_INPUT_DISABLE(IO_MUX_GPIO0_REG + (gpio_num * 4));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -202,7 +201,29 @@ static inline void gpio_ll_input_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
*/
|
|
|
static inline void gpio_ll_input_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[gpio_num]);
|
|
|
+ PIN_INPUT_ENABLE(IO_MUX_GPIO0_REG + (gpio_num * 4));
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief Enable GPIO pin filter
|
|
|
+ *
|
|
|
+ * @param hw Peripheral GPIO hardware instance address.
|
|
|
+ * @param gpio_num GPIO number of the pad.
|
|
|
+ */
|
|
|
+static inline void gpio_ll_pin_filter_enable(gpio_dev_t *hw, uint32_t gpio_num)
|
|
|
+{
|
|
|
+ PIN_FILTER_EN(IO_MUX_GPIO0_REG + (gpio_num * 4));
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief Disable GPIO pin filter
|
|
|
+ *
|
|
|
+ * @param hw Peripheral GPIO hardware instance address.
|
|
|
+ * @param gpio_num GPIO number of the pad.
|
|
|
+ */
|
|
|
+static inline void gpio_ll_pin_filter_disable(gpio_dev_t *hw, uint32_t gpio_num)
|
|
|
+{
|
|
|
+ PIN_FILTER_DIS(IO_MUX_GPIO0_REG + (gpio_num * 4));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -211,12 +232,12 @@ static inline void gpio_ll_input_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
* @param hw Peripheral GPIO hardware instance address.
|
|
|
* @param gpio_num GPIO number
|
|
|
*/
|
|
|
+__attribute__((always_inline))
|
|
|
static inline void gpio_ll_output_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // hw->enable_w1tc = (0x1 << gpio_num);
|
|
|
- // // Ensure no other output signal is routed via GPIO matrix to this pin
|
|
|
- // REG_WRITE(GPIO_FUNC0_OUT_SEL_CFG_REG + (gpio_num * 4),
|
|
|
- // SIG_GPIO_OUT_IDX);
|
|
|
+ hw->enable_w1tc.enable_w1tc = (0x1 << gpio_num);
|
|
|
+ // Ensure no other output signal is routed via GPIO matrix to this pin
|
|
|
+ REG_WRITE(GPIO_FUNC0_OUT_SEL_CFG_REG + (gpio_num * 4), SIG_GPIO_OUT_IDX);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -227,7 +248,7 @@ static inline void gpio_ll_output_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
*/
|
|
|
static inline void gpio_ll_output_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // hw->enable_w1ts = (0x1 << gpio_num);
|
|
|
+ hw->enable_w1ts.enable_w1ts = (0x1 << gpio_num);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -238,8 +259,7 @@ static inline void gpio_ll_output_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
*/
|
|
|
static inline void gpio_ll_od_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2-TODO: IDF-6227 updated struct file not support yet
|
|
|
- // hw->pin[gpio_num].pad_driver = 0;
|
|
|
+ hw->pin[gpio_num].pad_driver = 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -250,8 +270,7 @@ static inline void gpio_ll_od_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
*/
|
|
|
static inline void gpio_ll_od_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2-TODO: IDF-6227 updated struct file not support yet
|
|
|
- // hw->pin[gpio_num].pad_driver = 1;
|
|
|
+ hw->pin[gpio_num].pad_driver = 1;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -264,11 +283,11 @@ static inline void gpio_ll_od_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
__attribute__((always_inline))
|
|
|
static inline void gpio_ll_set_level(gpio_dev_t *hw, gpio_num_t gpio_num, uint32_t level)
|
|
|
{
|
|
|
- // if (level) {
|
|
|
- // hw->out_w1ts = (1 << gpio_num);
|
|
|
- // } else {
|
|
|
- // hw->out_w1tc = (1 << gpio_num);
|
|
|
- // }
|
|
|
+ if (level) {
|
|
|
+ hw->out_w1ts.out_w1ts = (1 << gpio_num);
|
|
|
+ } else {
|
|
|
+ hw->out_w1tc.out_w1tc = (1 << gpio_num);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -285,7 +304,7 @@ static inline void gpio_ll_set_level(gpio_dev_t *hw, gpio_num_t gpio_num, uint32
|
|
|
*/
|
|
|
static inline int gpio_ll_get_level(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- return 0;//(hw->in >> gpio_num) & 0x1;
|
|
|
+ return (hw->in.in_data_next >> gpio_num) & 0x1;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -297,11 +316,7 @@ static inline int gpio_ll_get_level(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
*/
|
|
|
static inline void gpio_ll_wakeup_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
-// ESP32H2-TODO: IDF-6227 updated struct file not support yet
|
|
|
-#if 0
|
|
|
- hw->pin[gpio_num].int_type = intr_type;
|
|
|
hw->pin[gpio_num].wakeup_enable = 0x1;
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -312,8 +327,7 @@ static inline void gpio_ll_wakeup_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
*/
|
|
|
static inline void gpio_ll_wakeup_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2-TODO: IDF-6227 updated struct file not support yet
|
|
|
- // hw->pin[gpio_num].wakeup_enable = 0;
|
|
|
+ hw->pin[gpio_num].wakeup_enable = 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -325,7 +339,7 @@ static inline void gpio_ll_wakeup_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
*/
|
|
|
static inline void gpio_ll_set_drive_capability(gpio_dev_t *hw, gpio_num_t gpio_num, gpio_drive_cap_t strength)
|
|
|
{
|
|
|
- SET_PERI_REG_BITS(GPIO_PIN_MUX_REG[gpio_num], FUN_DRV_V, strength, FUN_DRV_S);
|
|
|
+ SET_PERI_REG_BITS(IO_MUX_GPIO0_REG + (gpio_num * 4), FUN_DRV_V, strength, FUN_DRV_S);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -337,7 +351,7 @@ static inline void gpio_ll_set_drive_capability(gpio_dev_t *hw, gpio_num_t gpio_
|
|
|
*/
|
|
|
static inline void gpio_ll_get_drive_capability(gpio_dev_t *hw, gpio_num_t gpio_num, gpio_drive_cap_t *strength)
|
|
|
{
|
|
|
- *strength = (gpio_drive_cap_t)GET_PERI_REG_BITS2(GPIO_PIN_MUX_REG[gpio_num], FUN_DRV_V, FUN_DRV_S);
|
|
|
+ *strength = (gpio_drive_cap_t)GET_PERI_REG_BITS2(IO_MUX_GPIO0_REG + (gpio_num * 4), FUN_DRV_V, FUN_DRV_S);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -347,7 +361,7 @@ static inline void gpio_ll_get_drive_capability(gpio_dev_t *hw, gpio_num_t gpio_
|
|
|
*/
|
|
|
static inline void gpio_ll_deep_sleep_hold_en(gpio_dev_t *hw)
|
|
|
{
|
|
|
- // ESP32H2 has removed deepsleep and replace with software backup sleep
|
|
|
+ REG_SET_BIT(PMU_IMM_PAD_HOLD_ALL_REG, PMU_TIE_HIGH_HP_PAD_HOLD_ALL);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -357,7 +371,7 @@ static inline void gpio_ll_deep_sleep_hold_en(gpio_dev_t *hw)
|
|
|
*/
|
|
|
static inline void gpio_ll_deep_sleep_hold_dis(gpio_dev_t *hw)
|
|
|
{
|
|
|
- // ESP32H2 has removed deepsleep and replace with software backup sleep
|
|
|
+ REG_SET_BIT(PMU_IMM_PAD_HOLD_ALL_REG, PMU_TIE_LOW_HP_PAD_HOLD_ALL);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -368,11 +382,7 @@ static inline void gpio_ll_deep_sleep_hold_dis(gpio_dev_t *hw)
|
|
|
*/
|
|
|
static inline void gpio_ll_hold_en(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- if (gpio_num <32){
|
|
|
- SET_PERI_REG_MASK(LP_AON_GPIO_HOLD0_REG, GPIO_HOLD_MASK[gpio_num]);
|
|
|
- } else if (gpio_num <= MAX_PAD_GPIO_NUM){
|
|
|
- SET_PERI_REG_MASK(LP_AON_GPIO_HOLD1_REG, GPIO_HOLD_MASK[gpio_num]);
|
|
|
- }
|
|
|
+ LP_AON.gpio_hold0.gpio_hold0 |= GPIO_HOLD_MASK[gpio_num];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -383,11 +393,7 @@ static inline void gpio_ll_hold_en(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
*/
|
|
|
static inline void gpio_ll_hold_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- if (gpio_num <32){
|
|
|
- CLEAR_PERI_REG_MASK(LP_AON_GPIO_HOLD0_REG, GPIO_HOLD_MASK[gpio_num]);
|
|
|
- } else if (gpio_num <= MAX_PAD_GPIO_NUM){
|
|
|
- CLEAR_PERI_REG_MASK(LP_AON_GPIO_HOLD1_REG, GPIO_HOLD_MASK[gpio_num]);
|
|
|
- }
|
|
|
+ LP_AON.gpio_hold0.gpio_hold0 &= ~GPIO_HOLD_MASK[gpio_num];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -397,10 +403,11 @@ static inline void gpio_ll_hold_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
* @param gpio_num GPIO number of the pad.
|
|
|
* @param signal_idx Peripheral signal id to input. One of the ``*_IN_IDX`` signals in ``soc/gpio_sig_map.h``.
|
|
|
*/
|
|
|
+__attribute__((always_inline))
|
|
|
static inline void gpio_ll_iomux_in(gpio_dev_t *hw, uint32_t gpio, uint32_t signal_idx)
|
|
|
{
|
|
|
hw->func_in_sel_cfg[signal_idx].sig_in_sel = 0;
|
|
|
- PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[gpio]);
|
|
|
+ PIN_INPUT_ENABLE(IO_MUX_GPIO0_REG + (gpio * 4));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -411,12 +418,30 @@ static inline void gpio_ll_iomux_in(gpio_dev_t *hw, uint32_t gpio, uint32_t sign
|
|
|
*/
|
|
|
static inline void gpio_ll_iomux_func_sel(uint32_t pin_name, uint32_t func)
|
|
|
{
|
|
|
- if (pin_name == IO_MUX_GPIO18_REG || pin_name == IO_MUX_GPIO19_REG) {
|
|
|
- CLEAR_PERI_REG_MASK(USB_DEVICE_CONF0_REG, USB_DEVICE_USB_PAD_ENABLE);
|
|
|
+ // Disable USB Serial JTAG if pins 26 or pins 27 needs to select an IOMUX function
|
|
|
+ if (pin_name == IO_MUX_GPIO26_REG || pin_name == IO_MUX_GPIO27_REG) {
|
|
|
+ CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE);
|
|
|
}
|
|
|
PIN_FUNC_SELECT(pin_name, func);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @brief Select a function for the pin in the IOMUX
|
|
|
+ *
|
|
|
+ * @param hw Peripheral GPIO hardware instance address.
|
|
|
+ * @param gpio_num GPIO number
|
|
|
+ * @param func Function to assign to the pin
|
|
|
+ */
|
|
|
+__attribute__((always_inline))
|
|
|
+static inline void gpio_ll_func_sel(gpio_dev_t *hw, uint8_t gpio_num, uint32_t func)
|
|
|
+{
|
|
|
+ // Disable USB Serial JTAG if pins 26 or pins 27 needs to select an IOMUX function
|
|
|
+ if (gpio_num == USB_DM_GPIO_NUM || gpio_num == USB_DP_GPIO_NUM) {
|
|
|
+ CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE);
|
|
|
+ }
|
|
|
+ PIN_FUNC_SELECT(IO_MUX_GPIO0_REG + (gpio_num * 4), func);
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* @brief Set peripheral output to an GPIO pad through the IOMUX.
|
|
|
*
|
|
|
@@ -428,47 +453,52 @@ static inline void gpio_ll_iomux_func_sel(uint32_t pin_name, uint32_t func)
|
|
|
*/
|
|
|
static inline void gpio_ll_iomux_out(gpio_dev_t *hw, uint8_t gpio_num, int func, uint32_t oen_inv)
|
|
|
{
|
|
|
-#if 0
|
|
|
hw->func_out_sel_cfg[gpio_num].oen_sel = 0;
|
|
|
hw->func_out_sel_cfg[gpio_num].oen_inv_sel = oen_inv;
|
|
|
- gpio_ll_iomux_func_sel(GPIO_PIN_MUX_REG[gpio_num], func);
|
|
|
-#endif
|
|
|
+ gpio_ll_iomux_func_sel(IO_MUX_GPIO0_REG + (gpio_num * 4), func);
|
|
|
}
|
|
|
|
|
|
-static inline void gpio_ll_force_hold_all(void)
|
|
|
-{
|
|
|
- REG_SET_BIT(PMU_IMM_PAD_HOLD_ALL_REG, PMU_TIE_HIGH_HP_PAD_HOLD_ALL);
|
|
|
- REG_SET_BIT(PMU_IMM_PAD_HOLD_ALL_REG, PMU_TIE_HIGH_LP_PAD_HOLD_ALL);
|
|
|
-}
|
|
|
-
|
|
|
-static inline void gpio_ll_force_unhold_all(void)
|
|
|
-{
|
|
|
- REG_SET_BIT(PMU_IMM_PAD_HOLD_ALL_REG, PMU_TIE_LOW_HP_PAD_HOLD_ALL);
|
|
|
- REG_SET_BIT(PMU_IMM_PAD_HOLD_ALL_REG, PMU_TIE_LOW_LP_PAD_HOLD_ALL);
|
|
|
+/**
|
|
|
+ * @brief Set clock source of IO MUX module
|
|
|
+ *
|
|
|
+ * @param src IO MUX clock source (only a subset of soc_module_clk_t values are valid)
|
|
|
+ */
|
|
|
+static inline void gpio_ll_iomux_set_clk_src(soc_module_clk_t src)
|
|
|
+{
|
|
|
+ switch (src) {
|
|
|
+ case SOC_MOD_CLK_XTAL:
|
|
|
+ PCR.iomux_clk_conf.iomux_func_clk_sel = 0;
|
|
|
+ break;
|
|
|
+ case SOC_MOD_CLK_PLL_F48M:
|
|
|
+ PCR.iomux_clk_conf.iomux_func_clk_sel = 2;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ // Unsupported IO_MUX clock source
|
|
|
+ HAL_ASSERT(false);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @brief Enable GPIO pin used for wakeup from sleep.
|
|
|
+ * @brief Enable GPIO pin to use sleep mode pin functions during light sleep.
|
|
|
*
|
|
|
* @param hw Peripheral GPIO hardware instance address.
|
|
|
* @param gpio_num GPIO number
|
|
|
*/
|
|
|
static inline void gpio_ll_sleep_sel_en(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2-TODO: IDF-6227
|
|
|
- // PIN_SLP_SEL_ENABLE(GPIO_PIN_MUX_REG[gpio_num]);
|
|
|
+ PIN_SLP_SEL_ENABLE(IO_MUX_GPIO0_REG + (gpio_num * 4));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @brief Disable GPIO pin used for wakeup from sleep.
|
|
|
+ * @brief Disable GPIO pin to use sleep mode pin functions during light sleep.
|
|
|
+ * Pin functions remains the same in both normal execution and in light-sleep mode.
|
|
|
*
|
|
|
* @param hw Peripheral GPIO hardware instance address.
|
|
|
* @param gpio_num GPIO number
|
|
|
*/
|
|
|
static inline void gpio_ll_sleep_sel_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2-TODO: IDF-6227
|
|
|
- // PIN_SLP_SEL_DISABLE(GPIO_PIN_MUX_REG[gpio_num]);
|
|
|
+ PIN_SLP_SEL_DISABLE(IO_MUX_GPIO0_REG + (gpio_num * 4));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -479,8 +509,7 @@ static inline void gpio_ll_sleep_sel_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
*/
|
|
|
static inline void gpio_ll_sleep_pullup_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2-TODO: IDF-6227
|
|
|
- // PIN_SLP_PULLUP_DISABLE(GPIO_PIN_MUX_REG[gpio_num]);
|
|
|
+ PIN_SLP_PULLUP_DISABLE(IO_MUX_GPIO0_REG + (gpio_num * 4));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -491,8 +520,7 @@ static inline void gpio_ll_sleep_pullup_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
*/
|
|
|
static inline void gpio_ll_sleep_pullup_en(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2-TODO: IDF-6227
|
|
|
- // PIN_SLP_PULLUP_ENABLE(GPIO_PIN_MUX_REG[gpio_num]);
|
|
|
+ PIN_SLP_PULLUP_ENABLE(IO_MUX_GPIO0_REG + (gpio_num * 4));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -503,8 +531,7 @@ static inline void gpio_ll_sleep_pullup_en(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
*/
|
|
|
static inline void gpio_ll_sleep_pulldown_en(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2-TODO: IDF-6227
|
|
|
- // PIN_SLP_PULLDOWN_ENABLE(GPIO_PIN_MUX_REG[gpio_num]);
|
|
|
+ PIN_SLP_PULLDOWN_ENABLE(IO_MUX_GPIO0_REG + (gpio_num * 4));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -515,8 +542,7 @@ static inline void gpio_ll_sleep_pulldown_en(gpio_dev_t *hw, gpio_num_t gpio_num
|
|
|
*/
|
|
|
static inline void gpio_ll_sleep_pulldown_dis(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2-TODO: IDF-6227
|
|
|
- // PIN_SLP_PULLDOWN_DISABLE(GPIO_PIN_MUX_REG[gpio_num]);
|
|
|
+ PIN_SLP_PULLDOWN_DISABLE(IO_MUX_GPIO0_REG + (gpio_num * 4));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -527,8 +553,7 @@ static inline void gpio_ll_sleep_pulldown_dis(gpio_dev_t *hw, gpio_num_t gpio_nu
|
|
|
*/
|
|
|
static inline void gpio_ll_sleep_input_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2-TODO: IDF-6227
|
|
|
- // PIN_SLP_INPUT_DISABLE(GPIO_PIN_MUX_REG[gpio_num]);
|
|
|
+ PIN_SLP_INPUT_DISABLE(IO_MUX_GPIO0_REG + (gpio_num * 4));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -539,8 +564,7 @@ static inline void gpio_ll_sleep_input_disable(gpio_dev_t *hw, gpio_num_t gpio_n
|
|
|
*/
|
|
|
static inline void gpio_ll_sleep_input_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2-TODO: IDF-6227
|
|
|
- // PIN_SLP_INPUT_ENABLE(GPIO_PIN_MUX_REG[gpio_num]);
|
|
|
+ PIN_SLP_INPUT_ENABLE(IO_MUX_GPIO0_REG + (gpio_num * 4));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -551,8 +575,7 @@ static inline void gpio_ll_sleep_input_enable(gpio_dev_t *hw, gpio_num_t gpio_nu
|
|
|
*/
|
|
|
static inline void gpio_ll_sleep_output_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2-TODO: IDF-6227
|
|
|
- // PIN_SLP_OUTPUT_DISABLE(GPIO_PIN_MUX_REG[gpio_num]);
|
|
|
+ PIN_SLP_OUTPUT_DISABLE(IO_MUX_GPIO0_REG + (gpio_num * 4));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -563,8 +586,7 @@ static inline void gpio_ll_sleep_output_disable(gpio_dev_t *hw, gpio_num_t gpio_
|
|
|
*/
|
|
|
static inline void gpio_ll_sleep_output_enable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2-TODO: IDF-6227
|
|
|
- // PIN_SLP_OUTPUT_ENABLE(GPIO_PIN_MUX_REG[gpio_num]);
|
|
|
+ PIN_SLP_OUTPUT_ENABLE(IO_MUX_GPIO0_REG + (gpio_num * 4));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -576,11 +598,23 @@ static inline void gpio_ll_sleep_output_enable(gpio_dev_t *hw, gpio_num_t gpio_n
|
|
|
*/
|
|
|
static inline void gpio_ll_deepsleep_wakeup_enable(gpio_dev_t *hw, gpio_num_t gpio_num, gpio_int_type_t intr_type)
|
|
|
{
|
|
|
- if (gpio_num > GPIO_NUM_5) {
|
|
|
- abort(); // gpio lager than 5 doesn't support.
|
|
|
+ HAL_ASSERT((gpio_num >= GPIO_NUM_7 && gpio_num <= GPIO_NUM_14) &&
|
|
|
+ "only gpio7~14 support deep sleep wake-up function");
|
|
|
+
|
|
|
+ LP_AON.ext_wakeup_cntl.ext_wakeup_filter = 1;
|
|
|
+
|
|
|
+ uint32_t wakeup_sel_mask = HAL_FORCE_READ_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_sel);
|
|
|
+ wakeup_sel_mask |= BIT(gpio_num - 7);
|
|
|
+ HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_sel, wakeup_sel_mask);
|
|
|
+
|
|
|
+ bool trigger_level = (intr_type == GPIO_INTR_LOW_LEVEL) ? 0 : 1;
|
|
|
+ uint32_t wakeup_level_mask = HAL_FORCE_READ_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_lv);
|
|
|
+ if (trigger_level) {
|
|
|
+ wakeup_level_mask |= BIT(gpio_num - 7);
|
|
|
+ } else {
|
|
|
+ wakeup_level_mask &= ~BIT(gpio_num - 7);
|
|
|
}
|
|
|
- // SET_PERI_REG_MASK( LP_IO_PIN0_REG + 0x4 * gpio_num, LP_IO_LP_GPIO0_WAKEUP_ENABLE);
|
|
|
- // REG_SET_FIELD( LP_IO_PIN0_REG + 0x4 * gpio_num, LP_IO_LP_GPIO0_INT_TYPE, intr_type);
|
|
|
+ HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_lv, wakeup_level_mask);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -591,12 +625,12 @@ static inline void gpio_ll_deepsleep_wakeup_enable(gpio_dev_t *hw, gpio_num_t gp
|
|
|
*/
|
|
|
static inline void gpio_ll_deepsleep_wakeup_disable(gpio_dev_t *hw, gpio_num_t gpio_num)
|
|
|
{
|
|
|
- if (gpio_num > GPIO_NUM_5) {
|
|
|
- abort(); // gpio lager than 5 doesn't support.
|
|
|
- }
|
|
|
- // ESP32H2 LP_IO check: IDF-6403
|
|
|
- // CLEAR_PERI_REG_MASK(LP_IO_PIN0_REG + 0x4 * gpio_num, LP_IO_LP_GPIO0_WAKEUP_ENABLE);
|
|
|
- // CLEAR_PERI_REG_MASK(LP_IO_PIN0_REG + 0x4 * gpio_num, LP_IO_LP_GPIO0_INT_TYPE);
|
|
|
+ HAL_ASSERT((gpio_num >= GPIO_NUM_7 && gpio_num <= GPIO_NUM_14) &&
|
|
|
+ "only gpio7~14 support deep sleep wake-up function");
|
|
|
+
|
|
|
+ uint32_t wakeup_sel_mask = HAL_FORCE_READ_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_sel);
|
|
|
+ wakeup_sel_mask &= ~BIT(gpio_num - 7);
|
|
|
+ HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_sel, wakeup_sel_mask);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -608,12 +642,12 @@ static inline void gpio_ll_deepsleep_wakeup_disable(gpio_dev_t *hw, gpio_num_t g
|
|
|
*/
|
|
|
static inline bool gpio_ll_deepsleep_wakeup_is_enabled(gpio_dev_t *hw, uint32_t gpio_num)
|
|
|
{
|
|
|
- // ESP32H2 LP_IO check: IDF-6403
|
|
|
- // HAL_ASSERT(gpio_num <= GPIO_NUM_7 && "gpio larger than 7 does not support deep sleep wake-up function");
|
|
|
- // On ESP32-H2, (lp_io pin number) == (gpio pin number)
|
|
|
- return true;//LP_IO.pin[gpio_num].wakeup_enable;
|
|
|
-}
|
|
|
+ HAL_ASSERT((gpio_num >= GPIO_NUM_7 && gpio_num <= GPIO_NUM_14) &&
|
|
|
+ "only gpio7~14 support deep sleep wake-up function");
|
|
|
|
|
|
+ uint32_t wakeup_sel_mask = HAL_FORCE_READ_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_sel);
|
|
|
+ return wakeup_sel_mask & BIT(gpio_num - 7);
|
|
|
+}
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
}
|