e37df03b7f
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>
36 lines
1.2 KiB
C++
36 lines
1.2 KiB
C++
#pragma once
|
|
#include <cstdint>
|
|
|
|
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.
|
|
typedef enum {
|
|
ESP_SLEEP_WAKEUP_UNDEFINED = 0, // cold boot / power-on / hard reset
|
|
ESP_SLEEP_WAKEUP_EXT0 = 2,
|
|
ESP_SLEEP_WAKEUP_EXT1 = 3,
|
|
ESP_SLEEP_WAKEUP_TIMER = 4, // returned to userland after deep-sleep timer
|
|
ESP_SLEEP_WAKEUP_TOUCHPAD = 5,
|
|
ESP_SLEEP_WAKEUP_ULP = 6,
|
|
} esp_sleep_wakeup_cause_t;
|
|
|
|
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; }
|