Standardize PMU IRQ handling and enable power button cancel on tbeam-s3 (#10285)

* Standardize PMU IRQ handling and enable power button as cancel on tbeam s3

* Original T-beam, too
This commit is contained in:
Jonathan Bennett
2026-04-26 19:58:23 -05:00
committed by GitHub
parent b148fac340
commit 24c4162a75
4 changed files with 16 additions and 27 deletions
+8 -21
View File
@@ -1000,11 +1000,8 @@ int32_t Power::runOnce()
powerFSM.trigger(EVENT_POWER_CONNECTED); powerFSM.trigger(EVENT_POWER_CONNECTED);
} }
#ifdef T_WATCH_S3 #ifdef PMU_POWER_BUTTON_IS_CANCEL
/* // cancel action also turns the screen on and off.
In the T-Watch S3 this code fragment reacts to the short press of the button by switching the
display on and off
*/
if (PMU->isPekeyShortPressIrq()) { if (PMU->isPekeyShortPressIrq()) {
LOG_INFO("Input: Corona Button Click"); LOG_INFO("Input: Corona Button Click");
InputEvent event = {.inputEvent = (input_broker_event)INPUT_BROKER_CANCEL, .kbchar = 0, .touchX = 0, .touchY = 0}; InputEvent event = {.inputEvent = (input_broker_event)INPUT_BROKER_CANCEL, .kbchar = 0, .touchX = 0, .touchY = 0};
@@ -1027,13 +1024,6 @@ int32_t Power::runOnce()
LOG_DEBUG("Battery removed"); LOG_DEBUG("Battery removed");
} }
*/ */
#ifndef T_WATCH_S3 // FIXME - why is this triggering on the T-Watch S3?
if (PMU->isPekeyLongPressIrq()) {
LOG_DEBUG("PEK long button press");
if (screen)
screen->setOn(false);
}
#endif
PMU->clearIrqStatus(); PMU->clearIrqStatus();
} }
@@ -1102,7 +1092,7 @@ void Power::attachPowerInterrupts()
if (PMU) { if (PMU) {
attachInterrupt( attachInterrupt(
PMU_IRQ, PMU_IRQ,
[] { []() {
pmu_irq = true; pmu_irq = true;
power->setIntervalFromNow(0); power->setIntervalFromNow(0);
runASAP = true; runASAP = true;
@@ -1405,19 +1395,16 @@ bool Power::axpChipInit()
uint64_t pmuIrqMask = 0; uint64_t pmuIrqMask = 0;
if (PMU->getChipModel() == XPOWERS_AXP192) { if (PMU->getChipModel() == XPOWERS_AXP192) {
pmuIrqMask = XPOWERS_AXP192_VBUS_INSERT_IRQ | XPOWERS_AXP192_BAT_INSERT_IRQ | XPOWERS_AXP192_PKEY_SHORT_IRQ; pmuIrqMask = XPOWERS_AXP192_VBUS_INSERT_IRQ | XPOWERS_AXP192_VBUS_REMOVE_IRQ | XPOWERS_AXP192_PKEY_SHORT_IRQ;
} else if (PMU->getChipModel() == XPOWERS_AXP2101) { } else if (PMU->getChipModel() == XPOWERS_AXP2101) {
pmuIrqMask = XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_PKEY_SHORT_IRQ; pmuIrqMask = XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_VBUS_REMOVE_IRQ | XPOWERS_AXP2101_PKEY_SHORT_IRQ;
} }
pinMode(PMU_IRQ, INPUT); pinMode(PMU_IRQ, INPUT);
// we do not look for AXPXXX_CHARGING_FINISHED_IRQ & AXPXXX_CHARGING_IRQ // We wake on IRQ, so only enable the IRQs that we care about.
// because it occurs repeatedly while there is no battery also it could cause // we want USB plug and unplug to update the screen and LED status,
// inadvertent waking from light sleep just because the battery filled we // and short press on the power button to trigger the "cancel" action in the UI (which also turns the screen on and off).
// don't look for AXPXXX_BATT_REMOVED_IRQ because it occurs repeatedly while
// no battery installed we don't look at AXPXXX_VBUS_REMOVED_IRQ because we
// don't have anything hooked to vbus
PMU->enableIRQ(pmuIrqMask); PMU->enableIRQ(pmuIrqMask);
PMU->clearIrqStatus(); PMU->clearIrqStatus();
+4 -3
View File
@@ -35,9 +35,10 @@
// code) // code)
#endif #endif
// Leave undefined to disable our PMU IRQ handler. DO NOT ENABLE THIS because the pmuirq can cause sperious interrupts // Voiding more warranties.
// and waking from light sleep #define PMU_IRQ 35
// #define PMU_IRQ 35 #define PMU_POWER_BUTTON_IS_CANCEL // maps a short click of the power button to a cancel action (turning off the screen)
#define HAS_AXP192 #define HAS_AXP192
#define GPS_UBLOX #define GPS_UBLOX
#define GPS_RX_PIN 34 #define GPS_RX_PIN 34
+1
View File
@@ -42,6 +42,7 @@
#define DAC_I2S_MCLK -1 #define DAC_I2S_MCLK -1
#define HAS_AXP2101 #define HAS_AXP2101
#define PMU_POWER_BUTTON_IS_CANCEL // maps a short click of the power button to a cancel action (turning off the screen)
// PCF8563 RTC Module // PCF8563 RTC Module
#define PCF8563_RTC 0x51 #define PCF8563_RTC 0x51
+3 -3
View File
@@ -46,9 +46,9 @@
#define LR11X0_DIO_AS_RF_SWITCH #define LR11X0_DIO_AS_RF_SWITCH
#endif #endif
// Leave undefined to disable our PMU IRQ handler. DO NOT ENABLE THIS because the pmuirq can cause sperious interrupts // Voiding warrenties, we're gonna try the IRQ
// and waking from light sleep #define PMU_IRQ 40
// #define PMU_IRQ 40 #define PMU_POWER_BUTTON_IS_CANCEL // maps a short click of the power button to a cancel action (turning off the screen)
#define HAS_AXP2101 #define HAS_AXP2101
// PCF8563 RTC Module // PCF8563 RTC Module