Skip to content

Commit fbd5f27

Browse files
committed
Ignore ESP-IDF wakeup cause when light sleeping
The IDF's wakeup cause is only for deep sleep. Without ignoring it, light sleep will wake up too early when done after a deep sleep wake. Fixes #7300
1 parent 895cd26 commit fbd5f27

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

ports/espressif/common-hal/alarm/__init__.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void alarm_reset(void) {
7676
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
7777
}
7878

79-
STATIC esp_sleep_wakeup_cause_t _get_wakeup_cause(void) {
79+
STATIC esp_sleep_wakeup_cause_t _get_wakeup_cause(bool deep_sleep) {
8080
// First check if the modules remember what last woke up
8181
if (alarm_pin_pinalarm_woke_this_cycle()) {
8282
return ESP_SLEEP_WAKEUP_GPIO;
@@ -94,17 +94,20 @@ STATIC esp_sleep_wakeup_cause_t _get_wakeup_cause(void) {
9494
#endif
9595
// If waking from true deep sleep, modules will have lost their state,
9696
// so check the deep wakeup cause manually
97-
return esp_sleep_get_wakeup_cause();
97+
if (deep_sleep) {
98+
return esp_sleep_get_wakeup_cause();
99+
}
100+
return ESP_SLEEP_WAKEUP_UNDEFINED;
98101
}
99102

100103
bool common_hal_alarm_woken_from_sleep(void) {
101-
return _get_wakeup_cause() != ESP_SLEEP_WAKEUP_UNDEFINED;
104+
return _get_wakeup_cause(false) != ESP_SLEEP_WAKEUP_UNDEFINED;
102105
}
103106

104107
mp_obj_t common_hal_alarm_record_wake_alarm(void) {
105108
// If woken from deep sleep, create a copy alarm similar to what would have
106109
// been passed in originally. Otherwise, just return none
107-
esp_sleep_wakeup_cause_t cause = _get_wakeup_cause();
110+
esp_sleep_wakeup_cause_t cause = _get_wakeup_cause(true);
108111
switch (cause) {
109112
case ESP_SLEEP_WAKEUP_TIMER: {
110113
return alarm_time_timealarm_record_wake_alarm();
@@ -154,7 +157,7 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
154157
RUN_BACKGROUND_TASKS;
155158
// Detect if interrupt was alarm or ctrl-C interrupt.
156159
if (common_hal_alarm_woken_from_sleep()) {
157-
esp_sleep_wakeup_cause_t cause = _get_wakeup_cause();
160+
esp_sleep_wakeup_cause_t cause = _get_wakeup_cause(false);
158161
switch (cause) {
159162
case ESP_SLEEP_WAKEUP_TIMER: {
160163
wake_alarm = alarm_time_timealarm_find_triggered_alarm(n_alarms,alarms);

0 commit comments

Comments
 (0)