fix(operation): EXT0 wakeup on BOOT button so 5-sec-hold reset works during sleep

Bug: the device only woke from deep sleep on a timer; pressing BOOT
during sleep did nothing. The 5-second-hold reset only worked in the
brief awake window during a poll, which made the documented "hold BOOT
to reset" gesture appear broken to the user. Reported live 2026-05-09.

Fix: arm EXT0 wakeup on PIN_BTN_RESET (active-low — BOOT is pulled-up
on the dev board) at every esp_deep_sleep_start. After the press wakes
the chip, setup() runs and the existing check_reset_button() handles
the rest of the 5-second hold and triggers the NVS clear + reprovision.

Mocks: esp_sleep.h gains gpio_num_t typedef + g_ext0_wakeup_pin/level
globals so the native test can assert the call shape.

Test: FW-RESET-WAKE pins the contract — every deep_sleep_start must
arm EXT0 on PIN_BTN_RESET, level 0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-08 18:35:56 -04:00
parent 2df2a14df6
commit e37df03b7f
3 changed files with 37 additions and 0 deletions
+13
View File
@@ -3,6 +3,8 @@
extern uint64_t g_sleep_us;
extern bool g_deep_sleep_started;
extern int g_ext0_wakeup_pin;
extern int g_ext0_wakeup_level;
// Mirror of the ESP-IDF wakeup-cause enum that the firmware actually checks.
// Tests set g_wakeup_cause directly to simulate cold-boot vs timer-wake.
@@ -17,6 +19,17 @@ typedef enum {
extern esp_sleep_wakeup_cause_t g_wakeup_cause;
// gpio_num_t alias for the wakeup helper. The real header is part of
// esp-idf; for native tests we just use int.
typedef int gpio_num_t;
#ifndef GPIO_NUM_0
#define GPIO_NUM_0 0
#endif
inline void esp_sleep_enable_timer_wakeup(uint64_t us) { g_sleep_us = us; }
inline void esp_sleep_enable_ext0_wakeup(gpio_num_t pin, int level) {
g_ext0_wakeup_pin = pin;
g_ext0_wakeup_level = level;
}
inline void esp_deep_sleep_start() { g_deep_sleep_started = true; }
inline esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause() { return g_wakeup_cause; }