Use common NRF52 begin() and deduplicate() startup reason init

Use a common begin() method that can be called from derived classes
to contain the shared initialization code.

Signed-off-by: Frieder Schrempf <frieder@fris.de>
This commit is contained in:
Frieder Schrempf
2025-12-09 15:00:08 +01:00
parent 87b0e432bb
commit 93d1560d14
41 changed files with 26 additions and 128 deletions

View File

@@ -6,7 +6,12 @@
#if defined(NRF52_PLATFORM)
class NRF52Board : public mesh::MainBoard {
protected:
uint8_t startup_reason;
public:
virtual void begin() { startup_reason = BD_STARTUP_NORMAL; }
virtual uint8_t getStartupReason() const override { return startup_reason; }
float getMCUTemperature() override;
virtual void reboot() override { NVIC_SystemReset(); }
};

View File

@@ -21,8 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason)
}
void MeshSolarBoard::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
meshSolarStart();

View File

@@ -22,12 +22,8 @@
class MeshSolarBoard : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
uint16_t getBattMilliVolts() override {
return meshSolarGetBattVoltage();

View File

@@ -19,8 +19,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
}
void T114Board::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
NRF_POWER->DCDCEN = 1;
pinMode(PIN_VBAT_READ, INPUT);

View File

@@ -10,12 +10,8 @@
#define MV_LSB (3000.0F / 4096.0F) // 12-bit ADC with 3.0V input range
class T114Board : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
#if defined(P_LORA_TX_LED)
void onBeforeTransmit() override {

View File

@@ -21,8 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
}
void IkokaNrf52Board::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
// ensure we have pull ups on the screen i2c, this isn't always available
// in hardware and it should only be 20k ohms. Disable the pullups if we

View File

@@ -7,12 +7,8 @@
#ifdef IKOKA_NRF52
class IkokaNrf52Board : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
#if defined(P_LORA_TX_LED)
void onBeforeTransmit() override {

View File

@@ -21,8 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
}
void IkokaNanoNRFBoard::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
pinMode(PIN_VBAT, INPUT);
pinMode(VBAT_ENABLE, OUTPUT);

View File

@@ -7,12 +7,8 @@
#ifdef XIAO_NRF52
class IkokaNanoNRFBoard : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
#if defined(P_LORA_TX_LED)
void onBeforeTransmit() override {

View File

@@ -21,8 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
}
void IkokaStickNRFBoard::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
pinMode(PIN_VBAT, INPUT);
pinMode(VBAT_ENABLE, OUTPUT);

View File

@@ -7,12 +7,8 @@
#ifdef XIAO_NRF52
class IkokaStickNRFBoard : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
#if defined(P_LORA_TX_LED)
void onBeforeTransmit() override {

View File

@@ -7,8 +7,7 @@
static BLEDfu bledfu;
void KeepteenLT1Board::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
btn_prev_state = HIGH;
pinMode(PIN_VBAT_READ, INPUT);

View File

@@ -6,14 +6,11 @@
class KeepteenLT1Board : public NRF52Board {
protected:
uint8_t startup_reason;
uint8_t btn_prev_state;
public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
#define BATTERY_SAMPLES 8
uint16_t getBattMilliVolts() override {

View File

@@ -21,8 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
}
void TechoBoard::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
Wire.begin();

View File

@@ -14,19 +14,11 @@
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
class TechoBoard : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint16_t getBattMilliVolts() override;
bool startOTAUpdate(const char* id, char reply[]) override;
uint8_t getStartupReason() const override {
return startup_reason;
}
const char* getManufacturerName() const override {
return "LilyGo T-Echo";
}

View File

@@ -21,8 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
}
void TechoBoard::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
Wire.begin();

View File

@@ -14,19 +14,11 @@
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
class TechoBoard : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint16_t getBattMilliVolts() override;
bool startOTAUpdate(const char* id, char reply[]) override;
uint8_t getStartupReason() const override {
return startup_reason;
}
const char* getManufacturerName() const override {
return "LilyGo T-Echo";
}

View File

@@ -20,8 +20,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason)
}
void HeltecMeshPocket::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
Serial.begin(115200);
pinMode(PIN_VBAT_READ, INPUT);

View File

@@ -10,14 +10,8 @@
#define MV_LSB (3000.0F / 4096.0F) // 12-bit ADC with 3.0V input range
class HeltecMeshPocket : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
uint16_t getBattMilliVolts() override {
int adcvalue = 0;

View File

@@ -5,8 +5,7 @@
#include <bluefruit.h>
void MinewsemiME25LS01Board::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
btn_prev_state = HIGH;
pinMode(PIN_VBAT_READ, INPUT);

View File

@@ -23,7 +23,6 @@
class MinewsemiME25LS01Board : public NRF52Board {
protected:
uint8_t startup_reason;
uint8_t btn_prev_state;
public:
@@ -42,8 +41,6 @@ public:
return (ADC_MULTIPLIER * raw);
}
uint8_t getStartupReason() const override { return startup_reason; }
const char* getManufacturerName() const override {
return "Minewsemi";
}

View File

@@ -24,8 +24,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason)
void NanoG2Ultra::begin()
{
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
// set user button
pinMode(PIN_BUTTON1, INPUT);

View File

@@ -36,16 +36,11 @@
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
class NanoG2Ultra : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint16_t getBattMilliVolts() override;
bool startOTAUpdate(const char *id, char reply[]) override;
uint8_t getStartupReason() const override { return startup_reason; }
const char *getManufacturerName() const override { return "Nano G2 Ultra"; }
void powerOff() override {

View File

@@ -7,8 +7,7 @@
static BLEDfu bledfu;
void PromicroBoard::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
btn_prev_state = HIGH;
pinMode(PIN_VBAT_READ, INPUT);

View File

@@ -22,15 +22,12 @@
class PromicroBoard : public NRF52Board {
protected:
uint8_t startup_reason;
uint8_t btn_prev_state;
float adc_mult = ADC_MULTIPLIER;
public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
#define BATTERY_SAMPLES 8
uint16_t getBattMilliVolts() override {

View File

@@ -19,8 +19,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
}
void RAK4631Board::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
pinMode(PIN_VBAT_READ, INPUT);
#ifdef PIN_USER_BTN
pinMode(PIN_USER_BTN, INPUT_PULLUP);

View File

@@ -30,12 +30,8 @@
#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000)
class RAK4631Board : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
#define BATTERY_SAMPLES 8

View File

@@ -19,9 +19,8 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
}
void RAKWismeshTagBoard::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
// Enable DC/DC converter for improved power efficiency
uint8_t sd_enabled = 0;
sd_softdevice_is_enabled(&sd_enabled);

View File

@@ -9,12 +9,8 @@
#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000)
class RAKWismeshTagBoard : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
#if defined(P_LORA_TX_LED) && defined(LED_STATE_ON)
void onBeforeTransmit() override {

View File

@@ -19,8 +19,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
}
void SenseCapSolarBoard::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
#if defined(PIN_WIRE_SDA) && defined(PIN_WIRE_SCL)
Wire.setPins(PIN_WIRE_SDA, PIN_WIRE_SCL);

View File

@@ -5,12 +5,8 @@
#include <helpers/NRF52Board.h>
class SenseCapSolarBoard : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
#if defined(P_LORA_TX_LED)
void onBeforeTransmit() override {

View File

@@ -5,8 +5,7 @@
#include <bluefruit.h>
void T1000eBoard::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
btn_prev_state = HIGH;
// Enable DC/DC converter for improved power efficiency

View File

@@ -6,7 +6,6 @@
class T1000eBoard : public NRF52Board {
protected:
uint8_t startup_reason;
uint8_t btn_prev_state;
public:
@@ -34,8 +33,6 @@ public:
#endif
}
uint8_t getStartupReason() const override { return startup_reason; }
const char* getManufacturerName() const override {
return "Seeed Tracker T1000-e";
}

View File

@@ -21,8 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
}
void ThinkNodeM1Board::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
Wire.begin();

View File

@@ -14,19 +14,12 @@
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
class ThinkNodeM1Board : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint16_t getBattMilliVolts() override;
bool startOTAUpdate(const char* id, char reply[]) override;
uint8_t getStartupReason() const override {
return startup_reason;
}
#if defined(P_LORA_TX_LED)
void onBeforeTransmit() override {
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on

View File

@@ -19,8 +19,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
}
void WioTrackerL1Board::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
btn_prev_state = HIGH;
// Enable DC/DC converter for improved power efficiency

View File

@@ -6,12 +6,10 @@
class WioTrackerL1Board : public NRF52Board {
protected:
uint8_t startup_reason;
uint8_t btn_prev_state;
public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
#if defined(P_LORA_TX_LED)
void onBeforeTransmit() override {

View File

@@ -21,7 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
}
void WioWM1110Board::begin() {
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
// Enable DC/DC converter for improved power efficiency
uint8_t sd_enabled = 0;

View File

@@ -12,12 +12,8 @@
#define Serial Serial1
class WioWM1110Board : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
#if defined(LED_GREEN)
void onBeforeTransmit() override {

View File

@@ -21,8 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
}
void XiaoNrf52Board::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF52Board::begin();
// Enable DC/DC converter for improved power efficiency
uint8_t sd_enabled = 0;

View File

@@ -7,12 +7,8 @@
#ifdef XIAO_NRF52
class XiaoNrf52Board : public NRF52Board {
protected:
uint8_t startup_reason;
public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
#if defined(P_LORA_TX_LED)
void onBeforeTransmit() override {