Skip to content

Commit 3f95c01

Browse files
authored
Merge pull request #10513 from dhalbert/esp32-correct-wakeup-pin
ESP32: Return correct deep sleep wakeup pin
2 parents 1c19926 + b16d18e commit 3f95c01

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ports/espressif/common-hal/alarm/pin/PinAlarm.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,17 @@ mp_obj_t alarm_pin_pinalarm_record_wake_alarm(void) {
108108

109109
#ifdef SOC_PM_SUPPORT_EXT0_WAKEUP
110110
if (cause == ESP_SLEEP_WAKEUP_EXT0) {
111-
pin_number = REG_GET_FIELD(RTC_IO_EXT_WAKEUP0_REG, RTC_IO_EXT_WAKEUP0_SEL);
111+
int rtc_io_pin_number = REG_GET_FIELD(RTC_IO_EXT_WAKEUP0_REG, RTC_IO_EXT_WAKEUP0_SEL);
112+
// Look up the GPIO equivalent pin for this RTC GPIO pin. On ESP32, the numbering
113+
// is different for RTC_GPIO and regular GPIO, and there's no mapping table.
114+
// The RTC and GPIO pin numbers match for all other current chips, so we could skip this
115+
// for those chips, but it's not expensive, and maybe there will be another mismatch in the future.
116+
for (gpio_num_t gpio_num = 0; gpio_num < SOC_GPIO_PIN_COUNT; gpio_num++) {
117+
if (rtc_io_number_get(gpio_num) == rtc_io_pin_number) {
118+
pin_number = gpio_num;
119+
break;
120+
}
121+
}
112122
} else {
113123
#endif
114124
#ifdef SOC_PM_SUPPORT_EXT1_WAKEUP

0 commit comments

Comments
 (0)