A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Revert "fix: don't wake up after USB connect" (#643)

Reverts crosspoint-reader/crosspoint-reader#576

Causing a boot loop on master

authored by

Dave Allie and committed by
GitHub
5a97334a 4dd73a21

+13 -35
+7 -16
lib/hal/HalGPIO.cpp
··· 24 24 unsigned long HalGPIO::getHeldTime() const { return inputMgr.getHeldTime(); } 25 25 26 26 void HalGPIO::startDeepSleep() { 27 + esp_deep_sleep_enable_gpio_wakeup(1ULL << InputManager::POWER_BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW); 27 28 // Ensure that the power button has been released to avoid immediately turning back on if you're holding it 28 29 while (inputMgr.isPressed(BTN_POWER)) { 29 30 delay(50); 30 31 inputMgr.update(); 31 32 } 32 - // Arm the wakeup trigger *after* the button is released 33 - esp_deep_sleep_enable_gpio_wakeup(1ULL << InputManager::POWER_BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW); 34 33 // Enter Deep Sleep 35 34 esp_deep_sleep_start(); 36 35 } ··· 45 44 return digitalRead(UART0_RXD) == HIGH; 46 45 } 47 46 48 - HalGPIO::WakeupReason HalGPIO::getWakeupReason() const { 49 - const bool usbConnected = isUsbConnected(); 47 + bool HalGPIO::isWakeupByPowerButton() const { 50 48 const auto wakeupCause = esp_sleep_get_wakeup_cause(); 51 49 const auto resetReason = esp_reset_reason(); 52 - 53 - if ((wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED && resetReason == ESP_RST_POWERON && !usbConnected) || 54 - (wakeupCause == ESP_SLEEP_WAKEUP_GPIO && resetReason == ESP_RST_DEEPSLEEP && usbConnected)) { 55 - return WakeupReason::PowerButton; 50 + if (isUsbConnected()) { 51 + return wakeupCause == ESP_SLEEP_WAKEUP_GPIO; 52 + } else { 53 + return (wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED) && (resetReason == ESP_RST_POWERON); 56 54 } 57 - if (wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED && resetReason == ESP_RST_UNKNOWN && usbConnected) { 58 - return WakeupReason::AfterFlash; 59 - } 60 - if (wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED && resetReason == ESP_RST_POWERON && usbConnected) { 61 - return WakeupReason::AfterUSBPower; 62 - } 63 - return WakeupReason::Other; 64 - } 55 + }
+2 -3
lib/hal/HalGPIO.h
··· 47 47 // Check if USB is connected 48 48 bool isUsbConnected() const; 49 49 50 - enum class WakeupReason { PowerButton, AfterFlash, AfterUSBPower, Other }; 51 - 52 - WakeupReason getWakeupReason() const; 50 + // Check if wakeup was caused by power button press 51 + bool isWakeupByPowerButton() const; 53 52 54 53 // Button indices 55 54 static constexpr uint8_t BTN_BACK = 0;
+4 -16
src/main.cpp
··· 294 294 SETTINGS.loadFromFile(); 295 295 KOREADER_STORE.loadFromFile(); 296 296 297 - switch (gpio.getWakeupReason()) { 298 - case HalGPIO::WakeupReason::PowerButton: 299 - // For normal wakeups, verify power button press duration 300 - Serial.printf("[%lu] [ ] Verifying power button press duration\n", millis()); 301 - verifyPowerButtonDuration(); 302 - break; 303 - case HalGPIO::WakeupReason::AfterUSBPower: 304 - // If USB power caused a cold boot, go back to sleep 305 - Serial.printf("[%lu] [ ] Wakeup reason: After USB Power\n", millis()); 306 - gpio.startDeepSleep(); 307 - break; 308 - case HalGPIO::WakeupReason::AfterFlash: 309 - // After flashing, just proceed to boot 310 - case HalGPIO::WakeupReason::Other: 311 - default: 312 - break; 297 + if (gpio.isWakeupByPowerButton()) { 298 + // For normal wakeups, verify power button press duration 299 + Serial.printf("[%lu] [ ] Verifying power button press duration\n", millis()); 300 + verifyPowerButtonDuration(); 313 301 } 314 302 315 303 // First serial output only here to avoid timing inconsistencies for power button press duration verification