2026-01-27 18:50:15 +01:00
|
|
|
#include <HalGPIO.h>
|
|
|
|
|
#include <SPI.h>
|
|
|
|
|
|
|
|
|
|
void HalGPIO::begin() {
|
|
|
|
|
inputMgr.begin();
|
|
|
|
|
SPI.begin(EPD_SCLK, SPI_MISO, EPD_MOSI, EPD_CS);
|
|
|
|
|
pinMode(UART0_RXD, INPUT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HalGPIO::update() { inputMgr.update(); }
|
|
|
|
|
|
|
|
|
|
bool HalGPIO::isPressed(uint8_t buttonIndex) const { return inputMgr.isPressed(buttonIndex); }
|
|
|
|
|
|
|
|
|
|
bool HalGPIO::wasPressed(uint8_t buttonIndex) const { return inputMgr.wasPressed(buttonIndex); }
|
|
|
|
|
|
|
|
|
|
bool HalGPIO::wasAnyPressed() const { return inputMgr.wasAnyPressed(); }
|
|
|
|
|
|
|
|
|
|
bool HalGPIO::wasReleased(uint8_t buttonIndex) const { return inputMgr.wasReleased(buttonIndex); }
|
|
|
|
|
|
|
|
|
|
bool HalGPIO::wasAnyReleased() const { return inputMgr.wasAnyReleased(); }
|
|
|
|
|
|
|
|
|
|
unsigned long HalGPIO::getHeldTime() const { return inputMgr.getHeldTime(); }
|
|
|
|
|
|
|
|
|
|
bool HalGPIO::isUsbConnected() const {
|
|
|
|
|
// U0RXD/GPIO20 reads HIGH when USB is connected
|
|
|
|
|
return digitalRead(UART0_RXD) == HIGH;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-01 16:19:33 +05:00
|
|
|
HalGPIO::WakeupReason HalGPIO::getWakeupReason() const {
|
|
|
|
|
const bool usbConnected = isUsbConnected();
|
2026-01-27 18:50:15 +01:00
|
|
|
const auto wakeupCause = esp_sleep_get_wakeup_cause();
|
|
|
|
|
const auto resetReason = esp_reset_reason();
|
2026-02-01 16:19:33 +05:00
|
|
|
|
|
|
|
|
if ((wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED && resetReason == ESP_RST_POWERON && !usbConnected) ||
|
|
|
|
|
(wakeupCause == ESP_SLEEP_WAKEUP_GPIO && resetReason == ESP_RST_DEEPSLEEP && usbConnected)) {
|
|
|
|
|
return WakeupReason::PowerButton;
|
2026-01-27 18:50:15 +01:00
|
|
|
}
|
2026-02-01 16:19:33 +05:00
|
|
|
if (wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED && resetReason == ESP_RST_UNKNOWN && usbConnected) {
|
|
|
|
|
return WakeupReason::AfterFlash;
|
|
|
|
|
}
|
|
|
|
|
if (wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED && resetReason == ESP_RST_POWERON && usbConnected) {
|
|
|
|
|
return WakeupReason::AfterUSBPower;
|
|
|
|
|
}
|
|
|
|
|
return WakeupReason::Other;
|
|
|
|
|
}
|