Skip to content

Commit 6520c61

Browse files
esp-wzhespressif-bot
authored andcommitted
change(esp_hw_support): improve gpio deepsleep wakeup configuration code
1 parent 9ffd8aa commit 6520c61

File tree

7 files changed

+25
-16
lines changed

7 files changed

+25
-16
lines changed

components/esp_hw_support/include/esp_private/io_mux.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ esp_err_t io_mux_set_clock_source(soc_module_clk_t clk_src);
3232

3333
#if SOC_LP_IO_CLOCK_IS_INDEPENDENT
3434
typedef struct {
35-
uint8_t rtc_io_enabled_cnt[MAX_RTC_GPIO_NUM];
35+
uint8_t rtc_io_enabled_cnt[MAX_RTC_GPIO_NUM + 1];
3636
uint32_t rtc_io_using_mask;
3737
} rtc_io_status_t;
3838

components/esp_hw_support/port/esp32p4/io_mux.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include "hal/rtc_io_ll.h"
1616
#include "soc/soc_caps.h"
1717

18-
static const char __attribute__((__unused__)) *IOMUX_TAG = "IO_MUX";
19-
2018
#define RTCIO_RCC_ATOMIC() PERIPH_RCC_ATOMIC()
2119

2220
static portMUX_TYPE s_io_mux_spinlock = portMUX_INITIALIZER_UNLOCKED;
@@ -55,7 +53,10 @@ esp_err_t io_mux_set_clock_source(soc_module_clk_t clk_src)
5553

5654
void io_mux_enable_lp_io_clock(gpio_num_t gpio_num, bool enable)
5755
{
58-
ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, IOMUX_TAG, "RTCIO number error");
56+
if (gpio_num > MAX_RTC_GPIO_NUM) {
57+
assert(false && "RTCIO number error");
58+
return;
59+
}
5960
portENTER_CRITICAL(&s_io_mux_spinlock);
6061
if (enable) {
6162
if (s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] == 0) {

components/esp_hw_support/sleep_modes.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,8 +1967,9 @@ uint64_t esp_sleep_get_gpio_wakeup_status(void)
19671967

19681968
static void gpio_deep_sleep_wakeup_prepare(void)
19691969
{
1970-
for (gpio_num_t gpio_idx = GPIO_NUM_0; gpio_idx < GPIO_NUM_MAX; gpio_idx++) {
1971-
if (((1ULL << gpio_idx) & s_config.gpio_wakeup_mask) == 0) {
1970+
uint32_t valid_wake_io_mask = SOC_GPIO_DEEP_SLEEP_WAKE_VALID_GPIO_MASK;
1971+
for (gpio_num_t gpio_idx = __builtin_ctz(valid_wake_io_mask); valid_wake_io_mask >> gpio_idx; gpio_idx++) {
1972+
if ((s_config.gpio_wakeup_mask & BIT64(gpio_idx)) == 0) {
19721973
continue;
19731974
}
19741975
#if CONFIG_ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS
@@ -1994,13 +1995,20 @@ esp_err_t esp_deep_sleep_enable_gpio_wakeup(uint64_t gpio_pin_mask, esp_deepslee
19941995
}
19951996
gpio_int_type_t intr_type = ((mode == ESP_GPIO_WAKEUP_GPIO_LOW) ? GPIO_INTR_LOW_LEVEL : GPIO_INTR_HIGH_LEVEL);
19961997
esp_err_t err = ESP_OK;
1997-
for (gpio_num_t gpio_idx = GPIO_NUM_0; gpio_idx < GPIO_NUM_MAX; gpio_idx++, gpio_pin_mask >>= 1) {
1998-
if ((gpio_pin_mask & 1) == 0) {
1999-
continue;
1998+
1999+
uint64_t invalid_io_mask = gpio_pin_mask & ~SOC_GPIO_DEEP_SLEEP_WAKE_VALID_GPIO_MASK;
2000+
if (invalid_io_mask != 0) {
2001+
for (gpio_num_t gpio_idx = __builtin_ctzll(invalid_io_mask); invalid_io_mask >> gpio_idx; gpio_idx++) {
2002+
if (invalid_io_mask & BIT64(gpio_idx)) {
2003+
ESP_LOGE(TAG, "gpio %d is an invalid deep sleep wakeup IO", gpio_idx);
2004+
return ESP_ERR_INVALID_ARG;
2005+
}
20002006
}
2001-
if (!esp_sleep_is_valid_wakeup_gpio(gpio_idx)) {
2002-
ESP_LOGE(TAG, "gpio %d is an invalid deep sleep wakeup IO", gpio_idx);
2003-
return ESP_ERR_INVALID_ARG;
2007+
}
2008+
2009+
for (gpio_num_t gpio_idx = __builtin_ctzll(gpio_pin_mask); gpio_pin_mask >> gpio_idx; gpio_idx++) {
2010+
if ((gpio_pin_mask & BIT64(gpio_idx)) == 0) {
2011+
continue;
20042012
}
20052013
err = gpio_deep_sleep_wakeup_enable(gpio_idx, intr_type);
20062014

components/soc/esp32c5/include/soc/io_mux_reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ extern "C" {
144144

145145
#define EXT_OSC_SLOW_GPIO_NUM 0
146146

147-
#define MAX_RTC_GPIO_NUM 8
147+
#define MAX_RTC_GPIO_NUM 7
148148
#define MAX_PAD_GPIO_NUM 28
149149
#define MAX_GPIO_NUM 32
150150
#define DIG_IO_HOLD_BIT_SHIFT 32

components/soc/esp32c6/include/soc/io_mux_reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148

149149
#define EXT_OSC_SLOW_GPIO_NUM 0
150150

151-
#define MAX_RTC_GPIO_NUM 8
151+
#define MAX_RTC_GPIO_NUM 7
152152
#define MAX_PAD_GPIO_NUM 30
153153
#define MAX_GPIO_NUM 34
154154
#define DIG_IO_HOLD_BIT_SHIFT 32

components/soc/esp32c61/include/soc/io_mux_reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ extern "C" {
129129

130130
#define EXT_OSC_SLOW_GPIO_NUM 0
131131

132-
#define MAX_RTC_GPIO_NUM 7
132+
#define MAX_RTC_GPIO_NUM 6
133133
#define MAX_PAD_GPIO_NUM 21
134134
#define MAX_GPIO_NUM 28
135135
#define HIGH_IO_HOLD_BIT_SHIFT 32

components/soc/esp32p4/include/soc/io_mux_reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194

195195
#define EXT_OSC_SLOW_GPIO_NUM 0 // XTAL_32K_N
196196

197-
#define MAX_RTC_GPIO_NUM 16
197+
#define MAX_RTC_GPIO_NUM 15
198198
#define MAX_PAD_GPIO_NUM 54
199199
#define MAX_GPIO_NUM 56
200200
#define HIGH_IO_HOLD_BIT_SHIFT 32

0 commit comments

Comments
 (0)