8000 esp32/modesp32: Add wake_on_ulp() so ULP can wake CPU from deepsleep. · micropython/micropython@ba21f76 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba21f76

Browse files
cwaltherdpgeorge
authored andcommitted
esp32/modesp32: Add wake_on_ulp() so ULP can wake CPU from deepsleep.
Add esp32.wake_on_ulp() to give access to esp_sleep_enable_ulp_wakeup(), which is needed to allow the ULP co-processor to wake the main CPU from deep sleep.
1 parent cf550ad commit ba21f76

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

docs/library/esp32.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ Functions
1818
Configure whether or not a touch will wake the device from sleep.
1919
*wake* should be a boolean value.
2020

21+
.. function:: wake_on_ulp(wake)
22+
23+
Configure whether or not the Ultra-Low-Power co-processor can wake the
24+
device from sleep. *wake* should be a boolean value.
25+
2126
.. function:: wake_on_ext0(pin, level)
2227

2328
Configure how EXT0 wakes the device from sleep. *pin* can be ``None``

ports/esp32/machine_rtc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef struct {
3434
uint64_t ext1_pins; // set bit == pin#
3535
int8_t ext0_pin; // just the pin#, -1 == None
3636
bool wake_on_touch : 1;
37+
bool wake_on_ulp : 1;
3738
bool ext0_level : 1;
3839
wake_type_t ext0_wake_types;
3940
bool ext1_level : 1;

ports/esp32/modesp32.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ STATIC mp_obj_t esp32_wake_on_ext1(size_t n_args, const mp_obj_t *pos_args, mp_m
131131
}
132132
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp32_wake_on_ext1_obj, 0, esp32_wake_on_ext1);
133133

134+
STATIC mp_obj_t esp32_wake_on_ulp(const mp_obj_t wake) {
135+
if (machine_rtc_config.ext0_pin != -1) {
136+
mp_raise_ValueError(MP_ERROR_TEXT("no resources"));
137+
}
138+
machine_rtc_config.wake_on_ulp = mp_obj_is_true(wake);
139+
return mp_const_none;
140+
}
141+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_wake_on_ulp_obj, esp32_wake_on_ulp);
142+
134143
STATIC mp_obj_t esp32_gpio_deep_sleep_hold(const mp_obj_t enable) {
135144
if (mp_obj_is_true(enable)) {
136145
gpio_deep_sleep_hold_en();
@@ -197,6 +206,7 @@ STATIC const mp_rom_map_elem_t esp32_module_globals_table[] = {
197206
{ MP_ROM_QSTR(MP_QSTR_wake_on_touch), MP_ROM_PTR(&esp32_wake_on_touch_obj) },
198207
{ MP_ROM_QSTR(MP_QSTR_wake_on_ext0), MP_ROM_PTR(&esp32_wake_on_ext0_obj) },
199208
{ MP_ROM_QSTR(MP_QSTR_wake_on_ext1), MP_ROM_PTR(&esp32_wake_on_ext1_obj) },
209+
{ MP_ROM_QSTR(MP_QSTR_wake_on_ulp), MP_ROM_PTR(&esp32_wake_on_ulp_obj) },
200210
{ MP_ROM_QSTR(MP_QSTR_gpio_deep_sleep_hold), MP_ROM_PTR(&esp32_gpio_deep_sleep_hold_obj) },
201211
#if CONFIG_IDF_TARGET_ESP32
202212
{ MP_ROM_QSTR(MP_QSTR_raw_temperature), MP_ROM_PTR(&esp32_raw_temperature_obj) },

ports/esp32/modmachine.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ STATIC mp_obj_t machine_sleep_helper(wake_type_t wake_type, size_t n_args, const
144144
}
145145
}
146146

147+
if (machine_rtc_config.wake_on_ulp) {
148+
if (esp_sleep_enable_ulp_wakeup() != ESP_OK) {
149+
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("esp_sleep_enable_ulp_wakeup() failed"));
150+
}
151+
}
152+
147153
#endif
148154

149155
switch (wake_type) {

0 commit comments

Comments
 (0)
0