add more deep sleep support for nrf52 boards

This commit is contained in:
Kevin Hester 2020-11-13 09:33:59 +08:00
parent 93afc71e2e
commit d407db5ee1
3 changed files with 32 additions and 14 deletions

View File

@ -172,6 +172,10 @@ class ButtonThread : public OSThread
{ {
#ifdef BUTTON_PIN #ifdef BUTTON_PIN
userButton = OneButton(BUTTON_PIN, true, true); userButton = OneButton(BUTTON_PIN, true, true);
#ifdef INPUT_PULLUP_SENSE
// Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did
pinMode(BUTTON_PIN, INPUT_PULLUP_SENSE);
#endif
userButton.attachClick(userButtonPressed); userButton.attachClick(userButtonPressed);
userButton.attachDuringLongPress(userButtonPressedLong); userButton.attachDuringLongPress(userButtonPressedLong);
userButton.attachDoubleClick(userButtonDoublePressed); userButton.attachDoubleClick(userButtonDoublePressed);
@ -179,6 +183,10 @@ class ButtonThread : public OSThread
#endif #endif
#ifdef BUTTON_PIN_ALT #ifdef BUTTON_PIN_ALT
userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true); userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true);
#ifdef INPUT_PULLUP_SENSE
// Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did
pinMode(BUTTON_PIN_ALT, INPUT_PULLUP_SENSE);
#endif
userButtonAlt.attachClick(userButtonPressed); userButtonAlt.attachClick(userButtonPressed);
userButtonAlt.attachDuringLongPress(userButtonPressedLong); userButtonAlt.attachDuringLongPress(userButtonPressedLong);
userButtonAlt.attachDoubleClick(userButtonDoublePressed); userButtonAlt.attachDoubleClick(userButtonDoublePressed);

View File

@ -1,6 +1,8 @@
#include "NRF52Bluetooth.h" #include "NRF52Bluetooth.h"
#include "configuration.h" #include "configuration.h"
#include "graphics/TFTDisplay.h" #include "graphics/TFTDisplay.h"
#include <SPI.h>
#include <Wire.h>
#include <assert.h> #include <assert.h>
#include <ble_gap.h> #include <ble_gap.h>
#include <memory.h> #include <memory.h>
@ -64,7 +66,7 @@ void setBluetoothEnable(bool on)
} }
} }
} else { } else {
if(nrf52Bluetooth) if (nrf52Bluetooth)
nrf52Bluetooth->shutdown(); nrf52Bluetooth->shutdown();
} }
bleOn = on; bleOn = on;
@ -98,7 +100,7 @@ void nrf52Setup()
#ifdef BQ25703A_ADDR #ifdef BQ25703A_ADDR
auto *bq = new BQ25713(); auto *bq = new BQ25713();
if(!bq->setup()) if (!bq->setup())
DEBUG_MSG("ERROR! Charge controller init failed\n"); DEBUG_MSG("ERROR! Charge controller init failed\n");
#endif #endif
@ -114,18 +116,26 @@ void nrf52Setup()
void cpuDeepSleep(uint64_t msecToWake) void cpuDeepSleep(uint64_t msecToWake)
{ {
DEBUG_MSG("FIXME: implement NRF52 deep sleep enter actions\n"); // FIXME, configure RTC or button press to wake us
// FIXME, configure RTC to wake us // FIXME, power down SPI, I2C, RAMs
// FIXME, power down SPI, I2C, RAMs Wire.end();
SPI.end();
Serial.end();
Serial1.end();
// FIXME, use system off mode with ram retention for key state? // FIXME, use system off mode with ram retention for key state?
// FIXME, use non-init RAM per https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled // FIXME, use non-init RAM per
// https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled
while(1) { auto ok = sd_power_system_off();
delay(5000); if(ok != NRF_SUCCESS) {
DEBUG_MSG("."); DEBUG_MSG("FIXME: Ignoring soft device (EasyDMA pending?) and forcing system-off!\n");
} NRF_POWER->SYSTEMOFF = 1;
}
// FIXME, after wake power up SPI, I2C, RAMs, reinit LORA // The following code should not be run, because we are off
DEBUG_MSG("FIXME: implement NRF52 deep sleep wake actions\n"); while (1) {
delay(5000);
DEBUG_MSG(".");
}
} }

View File

@ -142,7 +142,7 @@ static void waitEnterSleep()
void doDeepSleep(uint64_t msecToWake) void doDeepSleep(uint64_t msecToWake)
{ {
DEBUG_MSG("Entering deep sleep for %llu seconds\n", msecToWake / 1000); DEBUG_MSG("Entering deep sleep for %lu seconds\n", msecToWake / 1000);
// not using wifi yet, but once we are this is needed to shutoff the radio hw // not using wifi yet, but once we are this is needed to shutoff the radio hw
// esp_wifi_stop(); // esp_wifi_stop();