From 5b31d490361719ed7de945307ba0fcbde58f128b Mon Sep 17 00:00:00 2001 From: jpirnay Date: Mon, 20 Apr 2026 17:42:27 +0200 Subject: [PATCH] One more safety net --- lib/hal/HalGPIO.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/hal/HalGPIO.cpp b/lib/hal/HalGPIO.cpp index 7cefa64d..2ac53db4 100644 --- a/lib/hal/HalGPIO.cpp +++ b/lib/hal/HalGPIO.cpp @@ -339,17 +339,18 @@ HalGPIO::WakeupReason HalGPIO::getWakeupReason() const { const auto wakeupCause = esp_sleep_get_wakeup_cause(); const auto resetReason = esp_reset_reason(); - const bool usbConnected = isUsbConnected(); - LOG_DBG("GPIO", "getWakeupReason: wakeupCause=%d, resetReason=%d, usbConnected=%d", static_cast(wakeupCause), - static_cast(resetReason), usbConnected); - // X3: USB alone cannot cold-boot the MCU — the battery-latch MOSFET must be // closed by a physical power-button press. So any POWERON reset on X3 is a // button press, regardless of whether USB happens to be plugged in as well. + // Short-circuit before isUsbConnected() to skip the BQ27220 I2C probe/retry. if (deviceIsX3() && wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED && resetReason == ESP_RST_POWERON) { return WakeupReason::PowerButton; } + const bool usbConnected = isUsbConnected(); + LOG_DBG("GPIO", "getWakeupReason: wakeupCause=%d, resetReason=%d, usbConnected=%d", static_cast(wakeupCause), + static_cast(resetReason), usbConnected); + if ((wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED && resetReason == ESP_RST_POWERON && !usbConnected) || (wakeupCause == ESP_SLEEP_WAKEUP_GPIO && resetReason == ESP_RST_DEEPSLEEP && usbConnected)) { return WakeupReason::PowerButton;