From 3ff3c7dd439926d356cfa18ebbfe00473be39b21 Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Thu, 28 May 2026 19:39:18 +0100 Subject: [PATCH] RAK3401: powerOff() override + AIN1 SENSE LOW wake from SYSTEMOFF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two board-level pieces from dorfman2's PR #2414 that are useful for any RAK3401 firmware, not just the repeater variant the PR targets: 1. RAK3401Board::powerOff() override — routes _board->powerOff() through initiateShutdown(SHUTDOWN_REASON_USER) so the shutdown reason is properly tagged in GPREGRET2 instead of falling through to the base class default. 2. AIN1 GPIO SENSE LOW config in initiateShutdown() — when an env defines PIN_USER_BTN_ANA, configure that pin with pull-up + SENSE LOW before entering SYSTEMOFF, so pressing the AIN1 button wakes the board from the off state via the GPIO LATCH/SENSE mechanism. Waits for button release first (level-triggered SENSE would otherwise wake immediately if the user is still holding the button when we arm it). The repeater-specific UI redesign, status screen, and simple_repeater main.cpp button handler from the same PR are out of scope here; the companion radio UI tree already has its own equivalent button handling in examples/companion_radio/ui-new/UITask.cpp. Co-Authored-By: dorfman2 Co-Authored-By: Claude Opus 4.7 (1M context) --- variants/rak3401/RAK3401Board.cpp | 14 ++++++++++++++ variants/rak3401/RAK3401Board.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/variants/rak3401/RAK3401Board.cpp b/variants/rak3401/RAK3401Board.cpp index cbf7c1087d..77f1174c27 100644 --- a/variants/rak3401/RAK3401Board.cpp +++ b/variants/rak3401/RAK3401Board.cpp @@ -24,6 +24,20 @@ void RAK3401Board::initiateShutdown(uint8_t reason) { configureVoltageWake(power_config.lpcomp_ain_channel, power_config.lpcomp_refsel); } +#ifdef PIN_USER_BTN_ANA + // Configure AIN1 button as GPIO SENSE wake source (active LOW). + // Wait for button release first — SENSE is level-triggered, so if the user is + // still holding the button when we arm SENSE, the chip wakes immediately. + while (digitalRead(PIN_USER_BTN_ANA) == LOW) delay(10); + delay(50); // debounce + + uint32_t pin = (uint32_t)PIN_USER_BTN_ANA; + NRF_GPIO->PIN_CNF[pin] = (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) + | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) + | (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) + | (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos); +#endif + enterSystemOff(reason); } #endif diff --git a/variants/rak3401/RAK3401Board.h b/variants/rak3401/RAK3401Board.h index 3a080d5e2c..6b1d398735 100644 --- a/variants/rak3401/RAK3401Board.h +++ b/variants/rak3401/RAK3401Board.h @@ -20,6 +20,10 @@ class RAK3401Board : public NRF52BoardDCDC { RAK3401Board() : NRF52Board("RAK3401_OTA") {} void begin(); +#ifdef NRF52_POWER_MANAGEMENT + void powerOff() override { initiateShutdown(SHUTDOWN_REASON_USER); } +#endif + #define BATTERY_SAMPLES 8 uint16_t getBattMilliVolts() override {