Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore ESP-IDF wakeup cause when light sleeping #7441

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions ports/espressif/common-hal/alarm/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void alarm_reset(void) {
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
}

STATIC esp_sleep_wakeup_cause_t _get_wakeup_cause(void) {
STATIC esp_sleep_wakeup_cause_t _get_wakeup_cause(bool deep_sleep) {
// First check if the modules remember what last woke up
if (alarm_pin_pinalarm_woke_this_cycle()) {
return ESP_SLEEP_WAKEUP_GPIO;
Expand All @@ -94,17 +94,20 @@ STATIC esp_sleep_wakeup_cause_t _get_wakeup_cause(void) {
#endif
// If waking from true deep sleep, modules will have lost their state,
// so check the deep wakeup cause manually
return esp_sleep_get_wakeup_cause();
if (deep_sleep) {
return esp_sleep_get_wakeup_cause();
}
return ESP_SLEEP_WAKEUP_UNDEFINED;
}

bool common_hal_alarm_woken_from_sleep(void) {
return _get_wakeup_cause() != ESP_SLEEP_WAKEUP_UNDEFINED;
return _get_wakeup_cause(false) != ESP_SLEEP_WAKEUP_UNDEFINED;
}

mp_obj_t common_hal_alarm_record_wake_alarm(void) {
// If woken from deep sleep, create a copy alarm similar to what would have
// been passed in originally. Otherwise, just return none
esp_sleep_wakeup_cause_t cause = _get_wakeup_cause();
esp_sleep_wakeup_cause_t cause = _get_wakeup_cause(true);
switch (cause) {
case ESP_SLEEP_WAKEUP_TIMER: {
return alarm_time_timealarm_record_wake_alarm();
Expand Down Expand Up @@ -154,7 +157,7 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
RUN_BACKGROUND_TASKS;
// Detect if interrupt was alarm or ctrl-C interrupt.
if (common_hal_alarm_woken_from_sleep()) {
esp_sleep_wakeup_cause_t cause = _get_wakeup_cause();
esp_sleep_wakeup_cause_t cause = _get_wakeup_cause(false);
switch (cause) {
case ESP_SLEEP_WAKEUP_TIMER: {
wake_alarm = alarm_time_timealarm_find_triggered_alarm(n_alarms,alarms);
Expand Down