Skip to content

rak4631: implement button power-off and fix immediate wakeup (closes #1411) - #3705

Open
komacke wants to merge 1 commit into
meshcore-dev:mainfrom
komacke:fix-1411-r1-button-power
Open

komacke wants to merge 1 commit into
meshcore-dev:mainfrom
komacke:fix-1411-r1-button-power

Conversation

@komacke

@komacke komacke commented Oct 28, 2026

Copy link
Copy Markdown

Summary

This PR implements hardware button power management for RAK4631 / Muziworks R1 hardware, enabling deep sleep power-down via long-press, and fixes the immediate wakeup from SYSTEMOFF (superseding #2701).

Background & Root Cause

  • Issue Configure Muziworks R1 button for power down #1411: The Muziworks R1 (built on RAK4631 + WisBlock base with a button wired to WB_A1 / Pin 31) had no hardware button power-off monitoring in rak4631.
  • Immediate Wakeup: Entering SYSTEMOFF previously triggered an immediate reboot (RESETREAS=0x00010000, GPIO DETECT) because:
    1. RadioLib interrupts attached on DIO1 and BUSY fired as the SX1262 power rail collapsed.
    2. Pin transitions during button release and peripheral shutdown remained latched in the nRF52 LATCH registers.

Key Changes

  1. Button Power-Down: Monitor BOARD_BUTTON_PIN (WB_A1 / PIN_USER_BTN_ANA) in RAK4631Board::loop(). A 3-second long press illuminates the green LED (PIN_LED1) as confirmation (leaving the blue LED for BLE status) and initiates deep sleep upon button release.
  2. Debounce & Settle Window: Wait for stable button release before power-down, and enforce a 50ms settle window before arming NRF_GPIO_PIN_SENSE_LOW.
  3. Radio & Peripheral Isolation: Call detachInterrupt() and reset SX1262 pins to default prior to pulling SX126X_POWER_EN low. Disable SENSE on all non-button pins.
  4. BLE Disconnect: Gracefully disconnect active BLE connections (Bluefruit.disconnect()) and stop advertising before entering sleep.
  5. Clear LATCH Registers: Write 0xFFFFFFFF to NRF_P0->LATCH and NRF_P1->LATCH right before entering SYSTEMOFF.
  6. Zero Impact on Other Variants: Changes are strictly confined to variants/rak4631/. Other variants and newer Muziworks hardware (muzi_base, muziworks_r1_neo) remain untouched. All RAK4631 build targets (BLE, USB, Repeater, Room Server, Terminal Chat) compile cleanly.

Hardware Testing

  • Verified on a physical Muziworks R1 unit (RAK4631 + WisBlock base with hardware button on WB_A1 / Pin 31).
  • Confirmed normal BLE connection and operation.
  • Confirmed 3-second button hold illuminates the green LED, releases cleanly, and disconnects BLE.
  • Confirmed sustained deep sleep with all LEDs completely off (no spurious wakeups).
  • Confirmed clean wake via reset button back to operational state.

Closes #1411
Supersedes #2701

…eshcore-dev#1411)

Add hardware button power management for RAK4631 and Muziworks R1 builds,
and resolve immediate wakeup from SYSTEMOFF sleep (supersedes meshcore-dev#2701).

Key Changes:
- Button Power-Down: Monitor BOARD_BUTTON_PIN (WB_A1 / PIN_USER_BTN_ANA)
  in RAK4631Board::loop(). A 3-second long press illuminates the green
  LED (PIN_LED1) as power-down confirmation (leaving the blue LED for BLE
  status) and initiates deep sleep upon button release.
- Debounce & Release Settle: Wait for stable button release before power
  down, and enforce a 50ms settle window before arming SENSE LOW.
- Radio Isolation: Detach RadioLib interrupts (DIO1, BUSY) and reset
  SX1262 pins to default prior to disabling SX126X_POWER_EN. This prevents
  the collapsing power rail from triggering a false GPIO DETECT interrupt.
- BLE Graceful Disconnect: Disconnect active BLE connections and stop
  advertising before entering sleep so companion apps disconnect cleanly.
- LATCH Clearing: Disable SENSE on non-button pins and clear NRF_P0/P1 LATCH
  registers right before entering SYSTEMOFF, preventing immediate auto-wake.

Hardware Testing:
- Verified on a physical Muziworks R1 unit (RAK4631 + WisBlock base with
  hardware button on WB_A1 / Pin 31).
- Confirmed normal BLE operation, 3-second long-press detection with green
  LED indicator, graceful mobile app disconnect, and sustained SYSTEMOFF deep
  sleep with all LEDs off (no spurious or immediate wakeups).
- Confirmed wake from sleep via reset button back to full operational state.

Fixes meshcore-dev#1411
Supersedes meshcore-dev#2701

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configure Muziworks R1 button for power down

1 participant