diff --git a/ports/esp32/modesp32.c b/ports/esp32/modesp32.c index 1ee9153d7d620..c4b2bf9ae24f9 100644 --- a/ports/esp32/modesp32.c +++ b/ports/esp32/modesp32.c @@ -63,6 +63,12 @@ static MP_DEFINE_CONST_FUN_OBJ_1(esp32_wake_on_touch_obj, esp32_wake_on_touch); static mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + #if CONFIG_IDF_TARGET_ESP32C3 + + mp_raise_ValueError(MP_ERROR_TEXT("not supported")); + + #else + if (machine_rtc_config.wake_on_touch) { mp_raise_ValueError(MP_ERROR_TEXT("no resources")); } @@ -89,6 +95,8 @@ static mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_m machine_rtc_config.ext0_level = args[ARG_level].u_bool; machine_rtc_config.ext0_wake_types = MACHINE_WAKE_SLEEP | MACHINE_WAKE_DEEPSLEEP; + #endif + return mp_const_none; } static MP_DEFINE_CONST_FUN_OBJ_KW(esp32_wake_on_ext0_obj, 0, esp32_wake_on_ext0); diff --git a/ports/esp32/modesp32.h b/ports/esp32/modesp32.h index a685b7b38fe6f..7064f3eadbb67 100644 --- a/ports/esp32/modesp32.h +++ b/ports/esp32/modesp32.h @@ -1,7 +1,7 @@ #ifndef MICROPY_INCLUDED_ESP32_MODESP32_H #define MICROPY_INCLUDED_ESP32_MODESP32_H -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 #define RTC_VALID_EXT_PINS \ ( \ diff --git a/ports/esp32/modmachine.c b/ports/esp32/modmachine.c index 759455a59a5d6..928605fc277af 100644 --- a/ports/esp32/modmachine.c +++ b/ports/esp32/modmachine.c @@ -76,6 +76,7 @@ { MP_ROM_QSTR(MP_QSTR_PIN_WAKE), MP_ROM_INT(ESP_SLEEP_WAKEUP_EXT0) }, \ { MP_ROM_QSTR(MP_QSTR_EXT0_WAKE), MP_ROM_INT(ESP_SLEEP_WAKEUP_EXT0) }, \ { MP_ROM_QSTR(MP_QSTR_EXT1_WAKE), MP_ROM_INT(ESP_SLEEP_WAKEUP_EXT1) }, \ + { MP_ROM_QSTR(MP_QSTR_GPIO_WAKE), MP_ROM_INT(ESP_SLEEP_WAKEUP_GPIO) }, \ { MP_ROM_QSTR(MP_QSTR_TIMER_WAKE), MP_ROM_INT(ESP_SLEEP_WAKEUP_TIMER) }, \ { MP_ROM_QSTR(MP_QSTR_TOUCHPAD_WAKE), MP_ROM_INT(ESP_SLEEP_WAKEUP_TOUCHPAD) }, \ { MP_ROM_QSTR(MP_QSTR_ULP_WAKE), MP_ROM_INT(ESP_SLEEP_WAKEUP_ULP) }, \ @@ -146,7 +147,36 @@ static void machine_sleep_helper(wake_type_t wake_type, size_t n_args, const mp_ esp_sleep_enable_timer_wakeup(((uint64_t)expiry) * 1000); } - #if !CONFIG_IDF_TARGET_ESP32C3 + #if CONFIG_IDF_TARGET_ESP32C3 + + if (machine_rtc_config.ext1_pins != 0) { + gpio_int_type_t intr_type = machine_rtc_config.ext1_level ? GPIO_INTR_HIGH_LEVEL : GPIO_INTR_LOW_LEVEL; + + for (int i = 0; i < GPIO_NUM_MAX; ++i) { + gpio_num_t gpio = (gpio_num_t)i; + uint64_t bm = 1ULL << i; + + if (machine_rtc_config.ext1_pins & bm) { + gpio_sleep_set_direction(gpio, GPIO_MODE_INPUT); + + if (MACHINE_WAKE_SLEEP == wake_type) { + gpio_wakeup_enable(gpio, intr_type); + } + } + } + + if (MACHINE_WAKE_DEEPSLEEP == wake_type) { + if (ESP_OK != esp_deep_sleep_enable_gpio_wakeup( + machine_rtc_config.ext1_pins, + machine_rtc_config.ext1_level ? ESP_GPIO_WAKEUP_GPIO_HIGH : ESP_GPIO_WAKEUP_GPIO_LOW)) { + mp_raise_ValueError(MP_ERROR_TEXT("wake-up pin not supported")); + } + } else { + esp_sleep_enable_gpio_wakeup(); + } + } + + #else if (machine_rtc_config.ext0_pin != -1 && (machine_rtc_config.ext0_wake_types & wake_type)) { esp_sleep_enable_ext0_wakeup(machine_rtc_config.ext0_pin, machine_rtc_config.ext0_level ? 1 : 0); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy