Stop nRF52 automatic LEDs before shutdown and sleep
This commit is contained in:
1 parent
9a451dc160
commit
fb5ed7e4ee
4 files changed
+396
No files matched your search
@@ -4,6 +4,7 @@
|
||||
#include "NRF52VoltagePolicy.h"
|
||||
#include "Nrf52BootloaderVersion.h"
|
||||
#include "nrf52/SoftDeviceState.h"
|
||||
#include "nrf52/ShutdownLeds.h"
|
||||
#include <target.h>
|
||||
#include "UserGpioPinPolicy.h"
|
||||
|
||||
@@ -339,6 +340,10 @@ void NRF52Board::initiateShutdown(uint8_t reason) {
|
||||
void NRF52Board::enterSystemOff(uint8_t reason) {
|
||||
MESH_DEBUG_PRINTLN("PWRMGT: Entering SYSTEMOFF (%s)", getShutdownReasonString(reason));
|
||||
|
||||
// This path can run before BLE begin() during boot voltage protection.
|
||||
// autoConnLed(false) is safe then too and stops future automatic LED writes.
|
||||
Bluefruit.autoConnLed(false);
|
||||
|
||||
// Record shutdown reason in GPREGRET2
|
||||
uint8_t sd_enabled = 0;
|
||||
mesh_nrf52::softdeviceIsEnabled(sd_enabled);
|
||||
@@ -352,6 +357,7 @@ void NRF52Board::enterSystemOff(uint8_t reason) {
|
||||
// Flush serial buffers
|
||||
Serial.flush();
|
||||
delay(100);
|
||||
mesh_nrf52::turnOffShutdownLeds();
|
||||
|
||||
// Enter SYSTEMOFF
|
||||
if (sd_enabled) {
|
||||
@@ -556,6 +562,11 @@ float NRF52Board::getMCUTemperature() {
|
||||
}
|
||||
|
||||
void NRF52Board::shutdownPeripherals() {
|
||||
// Stop Bluefruit's LED owner before setting a final OFF latch. Its timer
|
||||
// stop is queued, so allow the existing shutdown delay to drain a pending
|
||||
// blinky callback before the final write below (also safe before BLE begin).
|
||||
Bluefruit.autoConnLed(false);
|
||||
|
||||
// Power off the display if any
|
||||
#ifdef DISPLAY_CLASS
|
||||
if (display.isOn()) {
|
||||
@@ -613,10 +624,13 @@ void NRF52Board::shutdownPeripherals() {
|
||||
// Flush serial buffers
|
||||
Serial.flush();
|
||||
delay(100);
|
||||
mesh_nrf52::turnOffShutdownLeds();
|
||||
}
|
||||
|
||||
void NRF52Board::powerOff() {
|
||||
shutdownPeripherals();
|
||||
// Board-specific hooks may signal button release after calling the base.
|
||||
mesh_nrf52::turnOffShutdownLeds();
|
||||
|
||||
// Enter SYSTEMOFF
|
||||
uint8_t sd_enabled = 0;
|
||||
@@ -633,6 +647,7 @@ void NRF52Board::enterDeepSleep(uint32_t secs) {
|
||||
powerOff(); // Not wake up
|
||||
} else {
|
||||
shutdownPeripherals();
|
||||
mesh_nrf52::turnOffShutdownLeds();
|
||||
|
||||
// Clear FPU interrupt flags to avoid insomnia
|
||||
// see errata 87 for details
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
namespace mesh_nrf52 {
|
||||
|
||||
inline void turnOffShutdownLed(int32_t pin) {
|
||||
// Several variants use -1, 0xff or PINS_COUNT for an absent LED. Never
|
||||
// convert one of these sentinels into an actual GPIO during shutdown.
|
||||
if (pin < 0 || static_cast<uint32_t>(pin) >= PINS_COUNT) return;
|
||||
if (digitalPinToPinName(pin) == 0xff) return;
|
||||
// Set the latch before enabling the output, including early boot shutdown.
|
||||
digitalWrite(pin, !LED_STATE_ON);
|
||||
pinMode(pin, OUTPUT);
|
||||
}
|
||||
|
||||
inline void turnOffShutdownLeds() {
|
||||
// Bluefruit uses LED_BLUE. Prefer it over the legacy LED_CONN alias: some
|
||||
// variants retain an unused LED_CONN definition without a corresponding pin.
|
||||
#if defined(LED_BLUE)
|
||||
turnOffShutdownLed(LED_BLUE);
|
||||
#elif defined(LED_CONN)
|
||||
turnOffShutdownLed(LED_CONN);
|
||||
#endif
|
||||
#if defined(LED_BUILTIN)
|
||||
turnOffShutdownLed(LED_BUILTIN);
|
||||
#endif
|
||||
#if defined(LED_PIN)
|
||||
turnOffShutdownLed(LED_PIN);
|
||||
#endif
|
||||
#if defined(LED_RED)
|
||||
turnOffShutdownLed(LED_RED);
|
||||
#endif
|
||||
#if defined(LED_GREEN)
|
||||
turnOffShutdownLed(LED_GREEN);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace mesh_nrf52
|
||||
Reference in new issue
Block a user