Added enterDeepSleep() for NRF52 and shutdownPeripherals() for ESP32
This commit is contained in:
1 parent
166fd6a941
commit
d9c42964eb
41 files changed
+120
-115
No files matched your search
@@ -62,6 +62,7 @@ public:
|
||||
virtual void onAfterTransmit() { }
|
||||
virtual void reboot() = 0;
|
||||
virtual void powerOff() { /* no op */ }
|
||||
virtual void enterDeepSleep(uint32_t secs) { /* no op */ }
|
||||
// Called by example setup() functions to signal that boot is complete.
|
||||
// Boards may override to stop a boot-indicator LED sequence or similar.
|
||||
// Default no-op: boards that don't care need not implement anything.
|
||||
|
||||
@@ -45,11 +45,7 @@ bool ESP32Board::startOTAUpdate(const char* id, char reply[]) {
|
||||
}
|
||||
#endif
|
||||
|
||||
void ESP32Board::powerOff() {
|
||||
enterDeepSleep(0); // Do not wakeup
|
||||
}
|
||||
|
||||
void ESP32Board::enterDeepSleep(uint32_t secs) {
|
||||
void ESP32Board::shutdownPeripherals() {
|
||||
// Power off the display if any
|
||||
#ifdef DISPLAY_CLASS
|
||||
display.turnOff();
|
||||
@@ -74,6 +70,14 @@ void ESP32Board::enterDeepSleep(uint32_t secs) {
|
||||
// Flush serial buffers
|
||||
Serial.flush();
|
||||
delay(100);
|
||||
}
|
||||
|
||||
void ESP32Board::powerOff() {
|
||||
enterDeepSleep(0); // Do not wakeup
|
||||
}
|
||||
|
||||
void ESP32Board::enterDeepSleep(uint32_t secs) {
|
||||
shutdownPeripherals();
|
||||
|
||||
// Clear stale wakeup sources to avoid ghost wakeup
|
||||
// This is required when Power Management and automatic lightsleep are enabled
|
||||
|
||||
@@ -64,8 +64,9 @@ public:
|
||||
return raw / 4;
|
||||
}
|
||||
|
||||
virtual void shutdownPeripherals();
|
||||
virtual void powerOff() override;
|
||||
void enterDeepSleep(uint32_t secs);
|
||||
virtual void enterDeepSleep(uint32_t secs) override;
|
||||
|
||||
uint32_t getIRQGpio() override {
|
||||
return P_LORA_DIO_1; // default for SX1262
|
||||
|
||||
@@ -383,6 +383,29 @@ void NRF52Board::powerOff() {
|
||||
}
|
||||
}
|
||||
|
||||
void NRF52Board::enterDeepSleep(uint32_t secs) {
|
||||
if (secs == 0) {
|
||||
powerOff(); // Not wake up
|
||||
} else {
|
||||
shutdownPeripherals();
|
||||
|
||||
// Clear FPU interrupt flags to avoid insomnia
|
||||
// see errata 87 for details
|
||||
// https://docs.nordicsemi.com/bundle/errata_nRF52840_Rev3/page/ERR/nRF52840/Rev3/latest/anomaly_840_87.html
|
||||
#if (__FPU_USED == 1)
|
||||
__set_FPSCR(__get_FPSCR() & ~(0x0000009F));
|
||||
(void)__get_FPSCR();
|
||||
NVIC_ClearPendingIRQ(FPU_IRQn);
|
||||
#endif
|
||||
|
||||
// Attemp to sleep
|
||||
vTaskDelay(pdMS_TO_TICKS(secs * 1000));
|
||||
|
||||
// Reboot for a fresh recovery
|
||||
reboot();
|
||||
}
|
||||
}
|
||||
|
||||
bool NRF52Board::getBootloaderVersion(char* out, size_t max_len) {
|
||||
static const char BOOTLOADER_MARKER[] = "UF2 Bootloader ";
|
||||
const uint8_t* flash = (const uint8_t*)0x000FB000; // earliest known info.txt location is 0xFB90B, latest is 0xFCC4B
|
||||
|
||||
@@ -52,6 +52,7 @@ public:
|
||||
virtual void reboot() override { NVIC_SystemReset(); }
|
||||
virtual void shutdownPeripherals();
|
||||
virtual void powerOff() override;
|
||||
virtual void enterDeepSleep(uint32_t secs) override;
|
||||
virtual bool getBootloaderVersion(char* version, size_t max_len) override;
|
||||
virtual bool startOTAUpdate(const char *id, char reply[]) override;
|
||||
virtual void sleep(uint32_t secs) override;
|
||||
|
||||
Reference in new issue
Block a user