Skip to content

Commit 7dea07a

Browse files
committed
modmachine: Implemented GPIO wake-up for ESP32-C3.
updated micropython#9583 to current codebase( 1.22.0). Signed-off-by: Rinaldi Jandrinata <puppet13th@gmail.com>
1 parent d1685a3 commit 7dea07a

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

ports/esp32/modesp32.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ static MP_DEFINE_CONST_FUN_OBJ_1(esp32_wake_on_touch_obj, esp32_wake_on_touch);
6363

6464
static mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
6565

66+
#if CONFIG_IDF_TARGET_ESP32C3
67+
68+
mp_raise_ValueError(MP_ERROR_TEXT("not supported"));
69+
70+
#else
71+
6672
if (machine_rtc_config.wake_on_touch) {
6773
mp_raise_ValueError(MP_ERROR_TEXT("no resources"));
6874
}
@@ -89,6 +95,8 @@ static mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_m
8995
machine_rtc_config.ext0_level = args[ARG_level].u_bool;
9096
machine_rtc_config.ext0_wake_types = MACHINE_WAKE_SLEEP | MACHINE_WAKE_DEEPSLEEP;
9197

98+
#endif
99+
92100
return mp_const_none;
93101
}
94102
static MP_DEFINE_CONST_FUN_OBJ_KW(esp32_wake_on_ext0_obj, 0, esp32_wake_on_ext0);

ports/esp32/modesp32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef MICROPY_INCLUDED_ESP32_MODESP32_H
22
#define MICROPY_INCLUDED_ESP32_MODESP32_H
33

4-
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
4+
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
55

66
#define RTC_VALID_EXT_PINS \
77
( \

ports/esp32/modmachine.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
{ MP_ROM_QSTR(MP_QSTR_PIN_WAKE), MP_ROM_INT(ESP_SLEEP_WAKEUP_EXT0) }, \
7777
{ MP_ROM_QSTR(MP_QSTR_EXT0_WAKE), MP_ROM_INT(ESP_SLEEP_WAKEUP_EXT0) }, \
7878
{ MP_ROM_QSTR(MP_QSTR_EXT1_WAKE), MP_ROM_INT(ESP_SLEEP_WAKEUP_EXT1) }, \
79+
{ MP_ROM_QSTR(MP_QSTR_EXT1_WAKE), MP_ROM_INT(ESP_SLEEP_WAKEUP_GPIO) }, \
7980
{ MP_ROM_QSTR(MP_QSTR_TIMER_WAKE), MP_ROM_INT(ESP_SLEEP_WAKEUP_TIMER) }, \
8081
{ MP_ROM_QSTR(MP_QSTR_TOUCHPAD_WAKE), MP_ROM_INT(ESP_SLEEP_WAKEUP_TOUCHPAD) }, \
8182
{ 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_
146147
esp_sleep_enable_timer_wakeup(((uint64_t)expiry) * 1000);
147148
}
148149

149-
#if !CONFIG_IDF_TARGET_ESP32C3
150+
#if CONFIG_IDF_TARGET_ESP32C3
151+
152+
if (machine_rtc_config.ext1_pins != 0) {
153+
gpio_int_type_t intr_type = machine_rtc_config.ext1_level ? GPIO_INTR_HIGH_LEVEL : GPIO_INTR_LOW_LEVEL;
154+
155+
for (int i = 0; i < GPIO_NUM_MAX; ++i) {
156+
gpio_num_t gpio = (gpio_num_t)i;
157+
uint64_t bm = 1ULL << i;
158+
159+
if (machine_rtc_config.ext1_pins & bm) {
160+
gpio_sleep_set_direction(gpio, GPIO_MODE_INPUT);
161+
162+
if (MACHINE_WAKE_SLEEP == wake_type) {
163+
gpio_wakeup_enable(gpio, intr_type);
164+
}
165+
}
166+
}
167+
168+
if (MACHINE_WAKE_DEEPSLEEP == wake_type) {
169+
if (ESP_OK != esp_deep_sleep_enable_gpio_wakeup(
170+
machine_rtc_config.ext1_pins,
171+
machine_rtc_config.ext1_level ? ESP_GPIO_WAKEUP_GPIO_HIGH : ESP_GPIO_WAKEUP_GPIO_LOW)) {
172+
mp_raise_ValueError(MP_ERROR_TEXT("wake-up pin not supported"));
173+
}
174+
} else {
175+
esp_sleep_enable_gpio_wakeup();
176+
}
177+
}
178+
179+
#else
150180

151181
if (machine_rtc_config.ext0_pin != -1 && (machine_rtc_config.ext0_wake_types & wake_type)) {
152182
esp_sleep_enable_ext0_wakeup(machine_rtc_config.ext0_pin, machine_rtc_config.ext0_level ? 1 : 0);

0 commit comments

Comments
 (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