# Conflicts: # MQTT_INTERNALS.md # build.sh # docs/cli_commands.md # examples/simple_repeater/MyMesh.cpp # examples/simple_repeater/MyMesh.h # examples/simple_repeater/UITask.cpp # examples/simple_room_server/MyMesh.cpp # examples/simple_room_server/MyMesh.h # examples/simple_room_server/UITask.cpp # examples/simple_sensor/SensorMesh.cpp # platformio.ini # scripts/generate_webconfig_html.py # src/MeshCore.h # src/helpers/CommonCLI.cpp # src/helpers/CommonCLI.h # src/helpers/CommonCLI_Observer.cpp # src/helpers/ESP32Board.h # src/helpers/MQTTMessageBuilder.cpp # src/helpers/MQTTPresets.h # src/helpers/NRF52Board.cpp # src/helpers/NRF52Board.h # src/helpers/bridges/MQTTBridge.cpp # src/helpers/bridges/MQTTBridge.h # src/helpers/esp32/WebConfigServer.cpp # src/helpers/esp32/WebConfigServer.h # src/helpers/radiolib/RadioLibWrappers.cpp # src/helpers/radiolib/RadioLibWrappers.h # variants/lilygo_tbeam_SX1262/platformio.ini # variants/lilygo_tbeam_SX1276/platformio.ini # variants/lilygo_tlora_v2_1/platformio.ini # webui/index.html
99 lines
3.7 KiB
C++
99 lines
3.7 KiB
C++
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
#include <MeshCore.h>
|
|
|
|
#if defined(NRF52_PLATFORM)
|
|
|
|
#ifdef NRF52_POWER_MANAGEMENT
|
|
// Shutdown Reason Codes (stored in GPREGRET before SYSTEMOFF)
|
|
#define SHUTDOWN_REASON_NONE 0x00
|
|
#define SHUTDOWN_REASON_LOW_VOLTAGE 0x4C // 'L' - Runtime low voltage threshold
|
|
#define SHUTDOWN_REASON_USER 0x55 // 'U' - User requested powerOff()
|
|
#define SHUTDOWN_REASON_BOOT_PROTECT 0x42 // 'B' - Boot voltage protection
|
|
|
|
// Boards provide this struct with their hardware-specific settings and callbacks.
|
|
struct PowerMgtConfig {
|
|
// LPCOMP wake configuration (for voltage recovery from SYSTEMOFF)
|
|
uint8_t lpcomp_ain_channel; // AIN0-7 for voltage sensing pin
|
|
uint8_t lpcomp_refsel; // REFSEL value: 0-6=1/8..7/8, 7=ARef, 8-15=1/16..15/16
|
|
|
|
// Boot protection voltage threshold (millivolts)
|
|
// Set to 0 to disable boot protection
|
|
uint16_t voltage_bootlock;
|
|
};
|
|
#endif
|
|
|
|
class NRF52Board : public mesh::MainBoard {
|
|
#ifdef NRF52_POWER_MANAGEMENT
|
|
void initPowerMgr();
|
|
void armVbusWake();
|
|
bool power_mgr_initialized;
|
|
#endif
|
|
|
|
protected:
|
|
uint8_t startup_reason;
|
|
char *ota_name;
|
|
|
|
#ifdef NRF52_POWER_MANAGEMENT
|
|
uint32_t reset_reason; // RESETREAS register value
|
|
uint8_t shutdown_reason; // GPREGRET value (why we entered last SYSTEMOFF)
|
|
uint16_t boot_voltage_mv; // Battery voltage at boot (millivolts)
|
|
|
|
bool checkBootVoltage(const PowerMgtConfig* config);
|
|
void enterSystemOff(uint8_t reason);
|
|
void configureVoltageWake(uint8_t ain_channel, uint8_t refsel);
|
|
virtual void initiateShutdown(uint8_t reason);
|
|
#endif
|
|
|
|
public:
|
|
NRF52Board(char *otaname) : ota_name(otaname)
|
|
#ifdef NRF52_POWER_MANAGEMENT
|
|
, power_mgr_initialized(false)
|
|
#endif
|
|
{}
|
|
virtual void begin();
|
|
// Feed the hardware main-loop watchdog. The first call starts it, so normal
|
|
// setup (including filesystem mount and radio initialization) is not timed.
|
|
// A loop blocked forever in SoftDevice-backed flash I/O will stop feeding it
|
|
// and be reset automatically.
|
|
void feedWatchdog(bool enabled = true);
|
|
void serviceWatchdog() override;
|
|
virtual uint8_t getStartupReason() const override { return startup_reason; }
|
|
virtual float getMCUTemperature() override;
|
|
virtual void reboot() override { NVIC_SystemReset(); }
|
|
virtual void shutdownPeripherals();
|
|
virtual void powerOff() override;
|
|
virtual bool getBootloaderVersion(char* version, size_t max_len) override;
|
|
virtual bool startOTAUpdate(const char *id, char reply[], bool force_ap = false) override;
|
|
virtual bool stopOTAUpdate(char reply[]) override;
|
|
virtual void sleep(uint32_t secs) override;
|
|
bool isExternalPowered() override;
|
|
bool isUsbDataConnected() override;
|
|
bool isUsbHostConnected() override;
|
|
|
|
#ifdef NRF52_POWER_MANAGEMENT
|
|
uint16_t getBootVoltage() override { return boot_voltage_mv; }
|
|
virtual uint32_t getResetReason() const override { return reset_reason; }
|
|
uint8_t getShutdownReason() const override { return shutdown_reason; }
|
|
const char* getResetReasonString(uint32_t reason) override;
|
|
const char* getShutdownReasonString(uint8_t reason) override;
|
|
bool isPowerManagementInitialized() const override { return power_mgr_initialized; }
|
|
bool supportsVoltageWake() const override { return true; }
|
|
#endif
|
|
};
|
|
|
|
/*
|
|
* The NRF52 has an internal DC/DC regulator that allows increased efficiency
|
|
* compared to the LDO regulator. For being able to use it, the module/board
|
|
* needs to have the required inductors and capacitors populated. If the
|
|
* hardware requirements are met, this subclass can be used to enable the DC/DC
|
|
* regulator.
|
|
*/
|
|
class NRF52BoardDCDC : virtual public NRF52Board {
|
|
public:
|
|
NRF52BoardDCDC() {}
|
|
virtual void begin() override;
|
|
};
|
|
#endif
|