Skip to content

Commit 4c7c2b0

Browse files
author
OSi (Ondrej Sienczak)
committed
modmachine, modesp32: Fixed deep/light sleep.
With ESP32-C3 there is different approach for setting wake-up pins. Signed-off-by: Ondrej Sienczak <ondrej.sienczak@gmail.com>
1 parent 7411293 commit 4c7c2b0

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

ports/esp32/modesp32.c

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

6666
STATIC mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
6767

68+
#if CONFIG_IDF_TARGET_ESP32C3
69+
70+
mp_raise_ValueError(MP_ERROR_TEXT("not supported"));
71+
72+
#else
73+
6874
if (machine_rtc_config.wake_on_touch) {
6975
mp_raise_ValueError(MP_ERROR_TEXT("no resources"));
7076
}
@@ -91,6 +97,8 @@ STATIC mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_m
9197
machine_rtc_config.ext0_level = args[ARG_level].u_bool;
9298
machine_rtc_config.ext0_wake_types = MACHINE_WAKE_SLEEP | MACHINE_WAKE_DEEPSLEEP;
9399

100+
#endif
101+
94102
return mp_const_none;
95103
}
96104
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 & 14 deletions
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
( \
@@ -30,19 +30,6 @@
3030
)
3131
#define RTC_LAST_EXT_PIN 21
3232

33-
#elif CONFIG_IDF_TARGET_ESP32C3
34-
35-
#define RTC_VALID_EXT_PINS \
36-
( \
37-
(1ll << 0) | \
38-
(1ll << 1) | \
39-
(1ll << 2) | \
40-
(1ll << 3) | \
41-
(1ll << 4) | \
42-
(1ll << 5) \
43-
)
44-
#define RTC_LAST_EXT_PIN 5
45-
4633
#else
4734

4835
#define RTC_VALID_EXT_PINS \

ports/esp32/modmachine.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,28 @@ STATIC mp_obj_t machine_sleep_helper(wake_type_t wake_type, size_t n_args, const
137137
#if CONFIG_IDF_TARGET_ESP32C3
138138

139139
if (machine_rtc_config.ext1_pins != 0) {
140+
gpio_int_type_t intr_type = machine_rtc_config.ext1_level ? GPIO_INTR_HIGH_LEVEL : GPIO_INTR_LOW_LEVEL;
141+
140142
for (int i = 0; i < GPIO_NUM_MAX; ++i) {
143+
gpio_num_t gpio = (gpio_num_t)i;
141144
uint64_t bm = 1ULL << i;
145+
142146
if (machine_rtc_config.ext1_pins & bm) {
143-
gpio_sleep_set_direction((gpio_num_t)i, GPIO_MODE_INPUT);
147+
gpio_sleep_set_direction(gpio, GPIO_MODE_INPUT);
148+
149+
if (MACHINE_WAKE_SLEEP == wake_type) {
150+
gpio_wakeup_enable(gpio, intr_type);
151+
}
144152
}
145153
}
146-
esp_deep_sleep_enable_gpio_wakeup(
147-
machine_rtc_config.ext1_pins,
148-
machine_rtc_config.ext1_level ? ESP_GPIO_WAKEUP_GPIO_HIGH : ESP_GPIO_WAKEUP_GPIO_LOW);
149-
esp_sleep_enable_gpio_wakeup();
154+
155+
if (MACHINE_WAKE_DEEPSLEEP == wake_type) {
156+
esp_deep_sleep_enable_gpio_wakeup(
157+
machine_rtc_config.ext1_pins,
158+
machine_rtc_config.ext1_level ? ESP_GPIO_WAKEUP_GPIO_HIGH : ESP_GPIO_WAKEUP_GPIO_LOW);
159+
} else {
160+
esp_sleep_enable_gpio_wakeup();
161+
}
150162
}
151163

152164
#else

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