diff --git a/platformio.ini b/platformio.ini index 75d37e869..74d42242f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -86,6 +86,8 @@ build_flags = ${arduino_base.build_flags} -D NRF52_PLATFORM -D LFS_NO_ASSERT=1 -D EXTRAFS=1 +build_src_filter = ${arduino_base.build_src_filter} + + lib_deps = ${arduino_base.lib_deps} https://github.com/oltaco/CustomLFS @ 0.2.1 diff --git a/src/helpers/nrf52/NRF52Board.cpp b/src/helpers/nrf52/NRF52Board.cpp new file mode 100644 index 000000000..bf9adab22 --- /dev/null +++ b/src/helpers/nrf52/NRF52Board.cpp @@ -0,0 +1,81 @@ +#include "NRF52Board.h" +#include + +static BLEDfu bledfu; + +static void connect_callback(uint16_t conn_handle) { + (void)conn_handle; + MESH_DEBUG_PRINTLN("BLE client connected"); +} + +static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { + (void)conn_handle; + (void)reason; + + MESH_DEBUG_PRINTLN("BLE client disconnected"); +} + +void NRF52Board::begin() { + startup_reason = BD_STARTUP_NORMAL; +} + +void NRF52BoardDCDC::begin() { + NRF52Board::begin(); + + // Enable DC/DC converter for improved power efficiency + uint8_t sd_enabled = 0; + sd_softdevice_is_enabled(&sd_enabled); + if (sd_enabled) { + sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE); + } else { + NRF_POWER->DCDCEN = 1; + } +} + +bool NRF52BoardOTA::startOTAUpdate(const char *id, char reply[]) { + // Config the peripheral connection with maximum bandwidth + // more SRAM required by SoftDevice + // Note: All config***() function must be called before begin() + Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); + Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); + + Bluefruit.begin(1, 0); + // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 + Bluefruit.setTxPower(4); + // Set the BLE device name + Bluefruit.setName(ota_name); + + Bluefruit.Periph.setConnectCallback(connect_callback); + Bluefruit.Periph.setDisconnectCallback(disconnect_callback); + + // To be consistent OTA DFU should be added first if it exists + bledfu.begin(); + + // Set up and start advertising + // Advertising packet + Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); + Bluefruit.Advertising.addTxPower(); + Bluefruit.Advertising.addName(); + + /* Start Advertising + - Enable auto advertising if disconnected + - Interval: fast mode = 20 ms, slow mode = 152.5 ms + - Timeout for fast mode is 30 seconds + - Start(timeout) with timeout = 0 will advertise forever (until connected) + + For recommended advertising interval + https://developer.apple.com/library/content/qa/qa1931/_index.html + */ + Bluefruit.Advertising.restartOnDisconnect(true); + Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms + Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode + Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds + + uint8_t mac_addr[6]; + memset(mac_addr, 0, sizeof(mac_addr)); + Bluefruit.getAddr(mac_addr); + sprintf(reply, "OK - mac: %02X:%02X:%02X:%02X:%02X:%02X", + mac_addr[5], mac_addr[4], mac_addr[3], mac_addr[2], mac_addr[1], mac_addr[0]); + + return true; +} \ No newline at end of file diff --git a/src/helpers/nrf52/NRF52Board.h b/src/helpers/nrf52/NRF52Board.h new file mode 100644 index 000000000..fd3601fb0 --- /dev/null +++ b/src/helpers/nrf52/NRF52Board.h @@ -0,0 +1,40 @@ +#pragma once + +#include +#include + +class NRF52Board : public mesh::MainBoard { +protected: + uint8_t startup_reason; + +public: + virtual void begin(); + + virtual uint8_t getStartupReason() const override { + return startup_reason; + } + + virtual void reboot() override { + NVIC_SystemReset(); + } +}; + +/* + * 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 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: + virtual void begin() override; +}; + +class NRF52BoardOTA : virtual public NRF52Board { +private: + char *ota_name; +public: + NRF52BoardOTA(char *name) : ota_name(name) {} + virtual bool startOTAUpdate(const char *id, char reply[]) override; +}; \ No newline at end of file diff --git a/variants/heltec_mesh_solar/MeshSolarBoard.cpp b/variants/heltec_mesh_solar/MeshSolarBoard.cpp index 54929cd1e..bc955fb53 100644 --- a/variants/heltec_mesh_solar/MeshSolarBoard.cpp +++ b/variants/heltec_mesh_solar/MeshSolarBoard.cpp @@ -1,28 +1,10 @@ #include -#include "MeshSolarBoard.h" - -#include #include -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) -{ - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) -{ - (void)conn_handle; - (void)reason; - - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} +#include "MeshSolarBoard.h" void MeshSolarBoard::begin() { - // for future use, sub-classes SHOULD call this from their begin() - startup_reason = BD_STARTUP_NORMAL; + NRF52Board::begin(); meshSolarStart(); @@ -32,46 +14,3 @@ void MeshSolarBoard::begin() { Wire.begin(); } - -bool MeshSolarBoard::startOTAUpdate(const char* id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("MESH_SOLAR_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - return true; -} diff --git a/variants/heltec_mesh_solar/MeshSolarBoard.h b/variants/heltec_mesh_solar/MeshSolarBoard.h index 3bec144f7..e3c284d64 100644 --- a/variants/heltec_mesh_solar/MeshSolarBoard.h +++ b/variants/heltec_mesh_solar/MeshSolarBoard.h @@ -2,6 +2,7 @@ #include #include +#include #ifdef HELTEC_MESH_SOLAR #include "meshSolarApp.h" @@ -20,13 +21,10 @@ #define SX126X_DIO3_TCXO_VOLTAGE 1.8 -class MeshSolarBoard : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class MeshSolarBoard : public NRF52BoardOTA { public: + MeshSolarBoard() : NRF52BoardOTA("MESH_SOLAR_OTA") {} void begin(); - uint8_t getStartupReason() const override { return startup_reason; } uint16_t getBattMilliVolts() override { return meshSolarGetBattVoltage(); @@ -35,10 +33,4 @@ class MeshSolarBoard : public mesh::MainBoard { const char* getManufacturerName() const override { return "Heltec Mesh Solar"; } - - void reboot() override { - NVIC_SystemReset(); - } - - bool startOTAUpdate(const char* id, char reply[]) override; }; diff --git a/variants/heltec_t114/T114Board.cpp b/variants/heltec_t114/T114Board.cpp index f46a1a84b..4995e7de1 100644 --- a/variants/heltec_t114/T114Board.cpp +++ b/variants/heltec_t114/T114Board.cpp @@ -2,25 +2,9 @@ #include #include -#include - -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; - - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} 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); @@ -39,47 +23,4 @@ void T114Board::begin() { pinMode(SX126X_POWER_EN, OUTPUT); digitalWrite(SX126X_POWER_EN, HIGH); delay(10); // give sx1262 some time to power up -} - -bool T114Board::startOTAUpdate(const char *id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("T114_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - return true; -} +} \ No newline at end of file diff --git a/variants/heltec_t114/T114Board.h b/variants/heltec_t114/T114Board.h index 0f7fc47fa..4b635ddf7 100644 --- a/variants/heltec_t114/T114Board.h +++ b/variants/heltec_t114/T114Board.h @@ -2,19 +2,17 @@ #include #include +#include // built-ins #define PIN_VBAT_READ 4 #define PIN_BAT_CTL 6 #define MV_LSB (3000.0F / 4096.0F) // 12-bit ADC with 3.0V input range -class T114Board : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class T114Board : public NRF52BoardOTA { public: + T114Board() : NRF52BoardOTA("T114_OTA") {} void begin(); - uint8_t getStartupReason() const override { return startup_reason; } #if defined(P_LORA_TX_LED) void onBeforeTransmit() override { @@ -43,10 +41,6 @@ class T114Board : public mesh::MainBoard { return "Heltec T114"; } - void reboot() override { - NVIC_SystemReset(); - } - void powerOff() override { #ifdef LED_PIN digitalWrite(LED_PIN, HIGH); @@ -57,6 +51,4 @@ class T114Board : public mesh::MainBoard { #endif sd_power_system_off(); } - - bool startOTAUpdate(const char* id, char reply[]) override; }; diff --git a/variants/ikoka_handheld_nrf/IkokaNrf52Board.cpp b/variants/ikoka_handheld_nrf/IkokaNrf52Board.cpp index 44940b8ff..f1d9f17d3 100644 --- a/variants/ikoka_handheld_nrf/IkokaNrf52Board.cpp +++ b/variants/ikoka_handheld_nrf/IkokaNrf52Board.cpp @@ -2,27 +2,11 @@ #include #include -#include #include "IkokaNrf52Board.h" -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; - - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} - 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 @@ -53,48 +37,4 @@ void IkokaNrf52Board::begin() { delay(10); // give sx1262 some time to power up } -bool IkokaNrf52Board::startOTAUpdate(const char *id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("XIAO_NRF52_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - - return true; -} - #endif diff --git a/variants/ikoka_handheld_nrf/IkokaNrf52Board.h b/variants/ikoka_handheld_nrf/IkokaNrf52Board.h index 9dfc3833e..1f3823f6d 100644 --- a/variants/ikoka_handheld_nrf/IkokaNrf52Board.h +++ b/variants/ikoka_handheld_nrf/IkokaNrf52Board.h @@ -2,16 +2,14 @@ #include #include +#include #ifdef IKOKA_NRF52 -class IkokaNrf52Board : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class IkokaNrf52Board : public NRF52BoardOTA { public: + IkokaNrf52Board() : NRF52BoardOTA("XIAO_NRF52_OTA") {} void begin(); - uint8_t getStartupReason() const override { return startup_reason; } #if defined(P_LORA_TX_LED) void onBeforeTransmit() override { @@ -41,12 +39,6 @@ class IkokaNrf52Board : public mesh::MainBoard { const char* getManufacturerName() const override { return "Ikoka Handheld E22 30dBm (Xiao_nrf52)"; } - - void reboot() override { - NVIC_SystemReset(); - } - - bool startOTAUpdate(const char* id, char reply[]) override; }; #endif diff --git a/variants/ikoka_nano_nrf/IkokaNanoNRFBoard.cpp b/variants/ikoka_nano_nrf/IkokaNanoNRFBoard.cpp index ee7996921..b963b2f4b 100644 --- a/variants/ikoka_nano_nrf/IkokaNanoNRFBoard.cpp +++ b/variants/ikoka_nano_nrf/IkokaNanoNRFBoard.cpp @@ -1,28 +1,12 @@ #ifdef XIAO_NRF52 #include -#include "IkokaNanoNRFBoard.h" - -#include #include -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; - - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} +#include "IkokaNanoNRFBoard.h" 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); @@ -48,47 +32,4 @@ void IkokaNanoNRFBoard::begin() { delay(10); // give sx1262 some time to power up } -bool IkokaNanoNRFBoard::startOTAUpdate(const char *id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("XIAO_NRF52_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - return true; -} - #endif diff --git a/variants/ikoka_nano_nrf/IkokaNanoNRFBoard.h b/variants/ikoka_nano_nrf/IkokaNanoNRFBoard.h index 8484085b0..cf357ac4c 100644 --- a/variants/ikoka_nano_nrf/IkokaNanoNRFBoard.h +++ b/variants/ikoka_nano_nrf/IkokaNanoNRFBoard.h @@ -2,16 +2,14 @@ #include #include +#include #ifdef XIAO_NRF52 -class IkokaNanoNRFBoard : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class IkokaNanoNRFBoard : public NRF52BoardOTA { public: + IkokaNanoNRFBoard() : NRF52BoardOTA("XIAO_NRF52_OTA") {} void begin(); - uint8_t getStartupReason() const override { return startup_reason; } #if defined(P_LORA_TX_LED) void onBeforeTransmit() override { @@ -49,12 +47,6 @@ class IkokaNanoNRFBoard : public mesh::MainBoard { const char *getManufacturerName() const override { return MANUFACTURER_STRING; } - - void reboot() override { - NVIC_SystemReset(); - } - - bool startOTAUpdate(const char *id, char reply[]) override; }; #endif diff --git a/variants/ikoka_stick_nrf/IkokaStickNRFBoard.cpp b/variants/ikoka_stick_nrf/IkokaStickNRFBoard.cpp index 6b660383a..1c416039d 100644 --- a/variants/ikoka_stick_nrf/IkokaStickNRFBoard.cpp +++ b/variants/ikoka_stick_nrf/IkokaStickNRFBoard.cpp @@ -1,28 +1,12 @@ #ifdef XIAO_NRF52 #include -#include "IkokaStickNRFBoard.h" - -#include #include -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; - - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} +#include "IkokaStickNRFBoard.h" 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); @@ -48,47 +32,4 @@ void IkokaStickNRFBoard::begin() { delay(10); // give sx1262 some time to power up } -bool IkokaStickNRFBoard::startOTAUpdate(const char *id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("XIAO_NRF52_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - return true; -} - #endif diff --git a/variants/ikoka_stick_nrf/IkokaStickNRFBoard.h b/variants/ikoka_stick_nrf/IkokaStickNRFBoard.h index 4a061d42f..76d319e4a 100644 --- a/variants/ikoka_stick_nrf/IkokaStickNRFBoard.h +++ b/variants/ikoka_stick_nrf/IkokaStickNRFBoard.h @@ -2,16 +2,14 @@ #include #include +#include #ifdef XIAO_NRF52 -class IkokaStickNRFBoard : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class IkokaStickNRFBoard : public NRF52BoardOTA { public: + IkokaStickNRFBoard() : NRF52BoardOTA("XIAO_NRF52_OTA") {} void begin(); - uint8_t getStartupReason() const override { return startup_reason; } #if defined(P_LORA_TX_LED) void onBeforeTransmit() override { @@ -49,12 +47,6 @@ class IkokaStickNRFBoard : public mesh::MainBoard { const char *getManufacturerName() const override { return MANUFACTURER_STRING; } - - void reboot() override { - NVIC_SystemReset(); - } - - bool startOTAUpdate(const char *id, char reply[]) override; }; #endif diff --git a/variants/keepteen_lt1/KeepteenLT1Board.cpp b/variants/keepteen_lt1/KeepteenLT1Board.cpp index 46bff1fc2..2f1fa5f9a 100644 --- a/variants/keepteen_lt1/KeepteenLT1Board.cpp +++ b/variants/keepteen_lt1/KeepteenLT1Board.cpp @@ -1,14 +1,10 @@ #include -#include "KeepteenLT1Board.h" - -#include #include -static BLEDfu bledfu; +#include "KeepteenLT1Board.h" 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); @@ -18,58 +14,4 @@ void KeepteenLT1Board::begin() { #endif Wire.begin(); -} - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} - -bool KeepteenLT1Board::startOTAUpdate(const char* id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("KeepteenLT1_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - return true; -} +} \ No newline at end of file diff --git a/variants/keepteen_lt1/KeepteenLT1Board.h b/variants/keepteen_lt1/KeepteenLT1Board.h index 9892638b2..27fec18a1 100644 --- a/variants/keepteen_lt1/KeepteenLT1Board.h +++ b/variants/keepteen_lt1/KeepteenLT1Board.h @@ -2,17 +2,16 @@ #include #include +#include -class KeepteenLT1Board : public mesh::MainBoard { +class KeepteenLT1Board : public NRF52BoardOTA { protected: - uint8_t startup_reason; uint8_t btn_prev_state; public: + KeepteenLT1Board() : NRF52BoardOTA("KeepteenLT1_OTA") {} void begin(); - uint8_t getStartupReason() const override { return startup_reason; } - #define BATTERY_SAMPLES 8 uint16_t getBattMilliVolts() override { @@ -39,13 +38,7 @@ class KeepteenLT1Board : public mesh::MainBoard { } #endif - void reboot() override { - NVIC_SystemReset(); - } - void powerOff() override { sd_power_system_off(); } - - bool startOTAUpdate(const char* id, char reply[]) override; }; diff --git a/variants/lilygo_techo/TechoBoard.cpp b/variants/lilygo_techo/TechoBoard.cpp index dee146880..81d3d0c9a 100644 --- a/variants/lilygo_techo/TechoBoard.cpp +++ b/variants/lilygo_techo/TechoBoard.cpp @@ -1,28 +1,12 @@ #include -#include "TechoBoard.h" - -#ifdef LILYGO_TECHO - -#include #include -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; +#include "TechoBoard.h" - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} +#ifdef LILYGO_TECHO void TechoBoard::begin() { - // for future use, sub-classes SHOULD call this from their begin() - startup_reason = BD_STARTUP_NORMAL; + NRF52Board::begin(); Wire.begin(); @@ -44,47 +28,4 @@ uint16_t TechoBoard::getBattMilliVolts() { // divider into account (providing the actual LIPO voltage) return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB); } - -bool TechoBoard::startOTAUpdate(const char* id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("TECHO_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - return true; -} #endif diff --git a/variants/lilygo_techo/TechoBoard.h b/variants/lilygo_techo/TechoBoard.h index 4792153a9..b7d0227ba 100644 --- a/variants/lilygo_techo/TechoBoard.h +++ b/variants/lilygo_techo/TechoBoard.h @@ -2,6 +2,7 @@ #include #include +#include // built-ins #define VBAT_MV_PER_LSB (0.73242188F) // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096 @@ -12,19 +13,11 @@ #define PIN_VBAT_READ (4) #define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) -class TechoBoard : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class TechoBoard : public NRF52BoardOTA { public: - + TechoBoard() : NRF52BoardOTA("TECHO_OTA") {} 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"; @@ -48,8 +41,4 @@ class TechoBoard : public mesh::MainBoard { #endif sd_power_system_off(); } - - void reboot() override { - NVIC_SystemReset(); - } }; diff --git a/variants/lilygo_techo_lite/TechoBoard.cpp b/variants/lilygo_techo_lite/TechoBoard.cpp index dee146880..81d3d0c9a 100644 --- a/variants/lilygo_techo_lite/TechoBoard.cpp +++ b/variants/lilygo_techo_lite/TechoBoard.cpp @@ -1,28 +1,12 @@ #include -#include "TechoBoard.h" - -#ifdef LILYGO_TECHO - -#include #include -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; +#include "TechoBoard.h" - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} +#ifdef LILYGO_TECHO void TechoBoard::begin() { - // for future use, sub-classes SHOULD call this from their begin() - startup_reason = BD_STARTUP_NORMAL; + NRF52Board::begin(); Wire.begin(); @@ -44,47 +28,4 @@ uint16_t TechoBoard::getBattMilliVolts() { // divider into account (providing the actual LIPO voltage) return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB); } - -bool TechoBoard::startOTAUpdate(const char* id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("TECHO_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - return true; -} #endif diff --git a/variants/lilygo_techo_lite/TechoBoard.h b/variants/lilygo_techo_lite/TechoBoard.h index 4792153a9..b7d0227ba 100644 --- a/variants/lilygo_techo_lite/TechoBoard.h +++ b/variants/lilygo_techo_lite/TechoBoard.h @@ -2,6 +2,7 @@ #include #include +#include // built-ins #define VBAT_MV_PER_LSB (0.73242188F) // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096 @@ -12,19 +13,11 @@ #define PIN_VBAT_READ (4) #define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) -class TechoBoard : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class TechoBoard : public NRF52BoardOTA { public: - + TechoBoard() : NRF52BoardOTA("TECHO_OTA") {} 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"; @@ -48,8 +41,4 @@ class TechoBoard : public mesh::MainBoard { #endif sd_power_system_off(); } - - void reboot() override { - NVIC_SystemReset(); - } }; diff --git a/variants/mesh_pocket/MeshPocket.cpp b/variants/mesh_pocket/MeshPocket.cpp index 0d0e8993c..0c53121f2 100644 --- a/variants/mesh_pocket/MeshPocket.cpp +++ b/variants/mesh_pocket/MeshPocket.cpp @@ -1,72 +1,12 @@ #include -#include "MeshPocket.h" -#include #include -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) -{ - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) -{ - (void)conn_handle; - (void)reason; - - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} +#include "MeshPocket.h" 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); pinMode(PIN_USER_BTN, INPUT); } - -bool HeltecMeshPocket::startOTAUpdate(const char* id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("MESH_POCKET_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - return true; -} diff --git a/variants/mesh_pocket/MeshPocket.h b/variants/mesh_pocket/MeshPocket.h index 8f5b09c9f..16c10c6bd 100644 --- a/variants/mesh_pocket/MeshPocket.h +++ b/variants/mesh_pocket/MeshPocket.h @@ -2,21 +2,17 @@ #include #include +#include // built-ins #define PIN_VBAT_READ 29 #define PIN_BAT_CTL 34 #define MV_LSB (3000.0F / 4096.0F) // 12-bit ADC with 3.0V input range -class HeltecMeshPocket : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class HeltecMeshPocket : public NRF52BoardOTA { public: + HeltecMeshPocket() : NRF52BoardOTA("MESH_POCKET_OTA") {} void begin(); - uint8_t getStartupReason() const override { return startup_reason; } - - uint16_t getBattMilliVolts() override { int adcvalue = 0; @@ -37,13 +33,7 @@ class HeltecMeshPocket : public mesh::MainBoard { return "Heltec MeshPocket"; } - void reboot() override { - NVIC_SystemReset(); - } - void powerOff() override { sd_power_system_off(); } - - bool startOTAUpdate(const char* id, char reply[]) override; }; diff --git a/variants/minewsemi_me25ls01/MinewsemiME25LS01Board.cpp b/variants/minewsemi_me25ls01/MinewsemiME25LS01Board.cpp index 561ed5049..0267185c9 100644 --- a/variants/minewsemi_me25ls01/MinewsemiME25LS01Board.cpp +++ b/variants/minewsemi_me25ls01/MinewsemiME25LS01Board.cpp @@ -1,12 +1,10 @@ #include -#include "MinewsemiME25LS01Board.h" #include -#include +#include "MinewsemiME25LS01Board.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); @@ -28,62 +26,4 @@ void MinewsemiME25LS01Board::begin() { #endif delay(10); // give sx1262 some time to power up -} - -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; - - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} - - -bool MinewsemiME25LS01Board::startOTAUpdate(const char* id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("Minewsemi_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - return true; } \ No newline at end of file diff --git a/variants/minewsemi_me25ls01/MinewsemiME25LS01Board.h b/variants/minewsemi_me25ls01/MinewsemiME25LS01Board.h index 777606a6d..dea38a2b8 100644 --- a/variants/minewsemi_me25ls01/MinewsemiME25LS01Board.h +++ b/variants/minewsemi_me25ls01/MinewsemiME25LS01Board.h @@ -2,6 +2,7 @@ #include #include +#include // LoRa and SPI pins @@ -20,12 +21,12 @@ #define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking -class MinewsemiME25LS01Board : public mesh::MainBoard { +class MinewsemiME25LS01Board : public NRF52BoardOTA { protected: - uint8_t startup_reason; uint8_t btn_prev_state; public: + MinewsemiME25LS01Board() : NRF52BoardOTA("Minewsemi_OTA") {} void begin(); #define BATTERY_SAMPLES 8 @@ -41,8 +42,6 @@ class MinewsemiME25LS01Board : public mesh::MainBoard { return (ADC_MULTIPLIER * raw); } - uint8_t getStartupReason() const override { return startup_reason; } - const char* getManufacturerName() const override { return "Minewsemi"; } @@ -78,11 +77,4 @@ class MinewsemiME25LS01Board : public mesh::MainBoard { digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off } #endif - - - void reboot() override { - NVIC_SystemReset(); - } - - bool startOTAUpdate(const char* id, char reply[]) override; }; \ No newline at end of file diff --git a/variants/nano_g2_ultra/nano-g2.cpp b/variants/nano_g2_ultra/nano-g2.cpp index 9a2782871..6a749aab6 100644 --- a/variants/nano_g2_ultra/nano-g2.cpp +++ b/variants/nano_g2_ultra/nano-g2.cpp @@ -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); diff --git a/variants/nano_g2_ultra/nano-g2.h b/variants/nano_g2_ultra/nano-g2.h index 5cedb0f99..b98adf0c3 100644 --- a/variants/nano_g2_ultra/nano-g2.h +++ b/variants/nano_g2_ultra/nano-g2.h @@ -4,6 +4,7 @@ #include #include +#include // LoRa radio module pins #define P_LORA_DIO_1 (32 + 10) @@ -34,21 +35,14 @@ #define PIN_VBAT_READ (0 + 2) #define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) -class NanoG2Ultra : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class NanoG2Ultra : public NRF52Board { 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 reboot() override { NVIC_SystemReset(); } - void powerOff() override { // put GPS chip to sleep digitalWrite(PIN_GPS_STANDBY, LOW); diff --git a/variants/promicro/PromicroBoard.cpp b/variants/promicro/PromicroBoard.cpp index b923e16e5..7011521b8 100644 --- a/variants/promicro/PromicroBoard.cpp +++ b/variants/promicro/PromicroBoard.cpp @@ -1,14 +1,10 @@ #include -#include "PromicroBoard.h" - -#include #include -static BLEDfu bledfu; +#include "PromicroBoard.h" 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); @@ -26,58 +22,4 @@ void PromicroBoard::begin() { pinMode(SX126X_POWER_EN, OUTPUT); digitalWrite(SX126X_POWER_EN, HIGH); delay(10); // give sx1262 some time to power up -} - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} - -bool PromicroBoard::startOTAUpdate(const char* id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("ProMicro_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - return true; -} +} \ No newline at end of file diff --git a/variants/promicro/PromicroBoard.h b/variants/promicro/PromicroBoard.h index dc20e5500..4d944ec43 100644 --- a/variants/promicro/PromicroBoard.h +++ b/variants/promicro/PromicroBoard.h @@ -2,6 +2,7 @@ #include #include +#include #define P_LORA_NSS 13 //P1.13 45 #define P_LORA_DIO_1 11 //P0.10 10 @@ -19,17 +20,15 @@ #define PIN_VBAT_READ 17 #define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking -class PromicroBoard : public mesh::MainBoard { +class PromicroBoard : public NRF52BoardOTA { protected: - uint8_t startup_reason; uint8_t btn_prev_state; float adc_mult = ADC_MULTIPLIER; public: + PromicroBoard() : NRF52BoardOTA("ProMicro_OTA") {} void begin(); - uint8_t getStartupReason() const override { return startup_reason; } - #define BATTERY_SAMPLES 8 uint16_t getBattMilliVolts() override { @@ -74,13 +73,7 @@ class PromicroBoard : public mesh::MainBoard { return 0; } - void reboot() override { - NVIC_SystemReset(); - } - void powerOff() override { sd_power_system_off(); } - - bool startOTAUpdate(const char* id, char reply[]) override; }; diff --git a/variants/rak4631/RAK4631Board.cpp b/variants/rak4631/RAK4631Board.cpp index 97a966022..65c54711d 100644 --- a/variants/rak4631/RAK4631Board.cpp +++ b/variants/rak4631/RAK4631Board.cpp @@ -1,26 +1,10 @@ #include -#include "RAK4631Board.h" - -#include #include -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; - - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} +#include "RAK4631Board.h" void RAK4631Board::begin() { - // for future use, sub-classes SHOULD call this from their begin() - startup_reason = BD_STARTUP_NORMAL; + NRF52BoardDCDC::begin(); pinMode(PIN_VBAT_READ, INPUT); #ifdef PIN_USER_BTN pinMode(PIN_USER_BTN, INPUT_PULLUP); @@ -39,52 +23,4 @@ void RAK4631Board::begin() { pinMode(SX126X_POWER_EN, OUTPUT); digitalWrite(SX126X_POWER_EN, HIGH); delay(10); // give sx1262 some time to power up -} - -bool RAK4631Board::startOTAUpdate(const char* id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("RAK4631_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - uint8_t mac_addr[6]; - memset(mac_addr, 0, sizeof(mac_addr)); - Bluefruit.getAddr(mac_addr); - sprintf(reply, "OK - mac: %02X:%02X:%02X:%02X:%02X:%02X", - mac_addr[5], mac_addr[4], mac_addr[3], mac_addr[2], mac_addr[1], mac_addr[0]); - - return true; -} +} \ No newline at end of file diff --git a/variants/rak4631/RAK4631Board.h b/variants/rak4631/RAK4631Board.h index 7f3a8fea9..b7e41d859 100644 --- a/variants/rak4631/RAK4631Board.h +++ b/variants/rak4631/RAK4631Board.h @@ -2,6 +2,7 @@ #include #include +#include // LoRa radio module pins for RAK4631 #define P_LORA_DIO_1 47 @@ -28,13 +29,10 @@ #define PIN_VBAT_READ 5 #define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000) -class RAK4631Board : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class RAK4631Board : public NRF52BoardDCDC, public NRF52BoardOTA { public: + RAK4631Board() : NRF52BoardOTA("RAK4631_OTA") {} void begin(); - uint8_t getStartupReason() const override { return startup_reason; } #define BATTERY_SAMPLES 8 @@ -53,10 +51,4 @@ class RAK4631Board : public mesh::MainBoard { const char* getManufacturerName() const override { return "RAK 4631"; } - - void reboot() override { - NVIC_SystemReset(); - } - - bool startOTAUpdate(const char* id, char reply[]) override; }; diff --git a/variants/rak_wismesh_tag/RAKWismeshTagBoard.cpp b/variants/rak_wismesh_tag/RAKWismeshTagBoard.cpp index 68638f0dd..7eab4bc9e 100644 --- a/variants/rak_wismesh_tag/RAKWismeshTagBoard.cpp +++ b/variants/rak_wismesh_tag/RAKWismeshTagBoard.cpp @@ -1,35 +1,10 @@ #include -#include "RAKWismeshTagBoard.h" - -#include #include -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; - - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} +#include "RAKWismeshTagBoard.h" void RAKWismeshTagBoard::begin() { - // for future use, sub-classes SHOULD call this from their begin() - startup_reason = BD_STARTUP_NORMAL; - - // Enable DC/DC converter for improved power efficiency - uint8_t sd_enabled = 0; - sd_softdevice_is_enabled(&sd_enabled); - if (sd_enabled) { - sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE); - } else { - NRF_POWER->DCDCEN = 1; - } + NRF52BoardDCDC::begin(); pinMode(PIN_VBAT_READ, INPUT); pinMode(PIN_USER_BTN, INPUT_PULLUP); @@ -40,52 +15,4 @@ void RAKWismeshTagBoard::begin() { pinMode(SX126X_POWER_EN, OUTPUT); digitalWrite(SX126X_POWER_EN, HIGH); delay(10); // give sx1262 some time to power up -} - -bool RAKWismeshTagBoard::startOTAUpdate(const char* id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("WISMESHTAG_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - uint8_t mac_addr[6]; - memset(mac_addr, 0, sizeof(mac_addr)); - Bluefruit.getAddr(mac_addr); - sprintf(reply, "OK - mac: %02X:%02X:%02X:%02X:%02X:%02X", - mac_addr[5], mac_addr[4], mac_addr[3], mac_addr[2], mac_addr[1], mac_addr[0]); - - return true; -} +} \ No newline at end of file diff --git a/variants/rak_wismesh_tag/RAKWismeshTagBoard.h b/variants/rak_wismesh_tag/RAKWismeshTagBoard.h index e5104a58d..c0042c647 100644 --- a/variants/rak_wismesh_tag/RAKWismeshTagBoard.h +++ b/variants/rak_wismesh_tag/RAKWismeshTagBoard.h @@ -2,18 +2,16 @@ #include #include +#include // built-ins #define PIN_VBAT_READ 5 #define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000) -class RAKWismeshTagBoard : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class RAKWismeshTagBoard : public NRF52BoardDCDC, public NRF52BoardOTA { public: + RAKWismeshTagBoard() : NRF52BoardOTA("WISMESHTAG_OTA") {} void begin(); - uint8_t getStartupReason() const override { return startup_reason; } #if defined(P_LORA_TX_LED) && defined(LED_STATE_ON) void onBeforeTransmit() override { @@ -42,12 +40,6 @@ class RAKWismeshTagBoard : public mesh::MainBoard { return "RAK WisMesh Tag"; } - void reboot() override { - NVIC_SystemReset(); - } - - bool startOTAUpdate(const char* id, char reply[]) override; - void powerOff() override { #ifdef BUZZER_EN digitalWrite(BUZZER_EN, LOW); diff --git a/variants/sensecap_solar/SenseCapSolarBoard.cpp b/variants/sensecap_solar/SenseCapSolarBoard.cpp index d6c044d1d..c08830359 100644 --- a/variants/sensecap_solar/SenseCapSolarBoard.cpp +++ b/variants/sensecap_solar/SenseCapSolarBoard.cpp @@ -1,26 +1,10 @@ #include -#include "SenseCapSolarBoard.h" - -#include #include -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; - - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} +#include "SenseCapSolarBoard.h" 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); @@ -34,48 +18,4 @@ void SenseCapSolarBoard::begin() { #endif delay(10); // give sx1262 some time to power up -} - -bool SenseCapSolarBoard::startOTAUpdate(const char* id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("SENSECAP_SOLAR_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - - return true; -} +} \ No newline at end of file diff --git a/variants/sensecap_solar/SenseCapSolarBoard.h b/variants/sensecap_solar/SenseCapSolarBoard.h index b1e5f8f17..cec106343 100644 --- a/variants/sensecap_solar/SenseCapSolarBoard.h +++ b/variants/sensecap_solar/SenseCapSolarBoard.h @@ -2,14 +2,12 @@ #include #include +#include -class SenseCapSolarBoard : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class SenseCapSolarBoard : public NRF52BoardOTA { public: + SenseCapSolarBoard() : NRF52BoardOTA("SENSECAP_SOLAR_OTA") {} void begin(); - uint8_t getStartupReason() const override { return startup_reason; } #if defined(P_LORA_TX_LED) void onBeforeTransmit() override { @@ -33,10 +31,4 @@ class SenseCapSolarBoard : public mesh::MainBoard { const char* getManufacturerName() const override { return "Seeed SenseCap Solar"; } - - void reboot() override { - NVIC_SystemReset(); - } - - bool startOTAUpdate(const char* id, char reply[]) override; }; diff --git a/variants/t1000-e/T1000eBoard.cpp b/variants/t1000-e/T1000eBoard.cpp index a41abd92e..0d390f798 100644 --- a/variants/t1000-e/T1000eBoard.cpp +++ b/variants/t1000-e/T1000eBoard.cpp @@ -1,23 +1,12 @@ #include -#include "T1000eBoard.h" #include -#include +#include "T1000eBoard.h" void T1000eBoard::begin() { - // for future use, sub-classes SHOULD call this from their begin() - startup_reason = BD_STARTUP_NORMAL; + NRF52BoardDCDC::begin(); btn_prev_state = HIGH; - // Enable DC/DC converter for improved power efficiency - uint8_t sd_enabled = 0; - sd_softdevice_is_enabled(&sd_enabled); - if (sd_enabled) { - sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE); - } else { - NRF_POWER->DCDCEN = 1; - } - #ifdef BUTTON_PIN pinMode(BATTERY_PIN, INPUT); pinMode(BUTTON_PIN, INPUT); @@ -31,64 +20,4 @@ void T1000eBoard::begin() { Wire.begin(); delay(10); // give sx1262 some time to power up -} - -#if 0 -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; - - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} - - -bool TrackerT1000eBoard::startOTAUpdate(const char* id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("T1000E_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - return true; -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/variants/t1000-e/T1000eBoard.h b/variants/t1000-e/T1000eBoard.h index 359e5e9a1..226f75aed 100644 --- a/variants/t1000-e/T1000eBoard.h +++ b/variants/t1000-e/T1000eBoard.h @@ -2,10 +2,10 @@ #include #include +#include -class T1000eBoard : public mesh::MainBoard { +class T1000eBoard : public NRF52BoardDCDC { protected: - uint8_t startup_reason; uint8_t btn_prev_state; public: @@ -33,8 +33,6 @@ class T1000eBoard : public mesh::MainBoard { #endif } - uint8_t getStartupReason() const override { return startup_reason; } - const char* getManufacturerName() const override { return "Seeed Tracker T1000-e"; } @@ -92,9 +90,5 @@ class T1000eBoard : public mesh::MainBoard { sd_power_system_off(); } - void reboot() override { - NVIC_SystemReset(); - } - // bool startOTAUpdate(const char* id, char reply[]) override; }; \ No newline at end of file diff --git a/variants/thinknode_m1/ThinkNodeM1Board.cpp b/variants/thinknode_m1/ThinkNodeM1Board.cpp index 12dd73624..45449bafc 100644 --- a/variants/thinknode_m1/ThinkNodeM1Board.cpp +++ b/variants/thinknode_m1/ThinkNodeM1Board.cpp @@ -1,28 +1,12 @@ -#include "ThinkNodeM1Board.h" #include - -#ifdef THINKNODE_M1 - #include -#include - -static BLEDfu bledfu; -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; +#include "ThinkNodeM1Board.h" - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} +#ifdef THINKNODE_M1 void ThinkNodeM1Board::begin() { - // for future use, sub-classes SHOULD call this from their begin() - startup_reason = BD_STARTUP_NORMAL; + NRF52Board::begin(); Wire.begin(); @@ -49,47 +33,4 @@ uint16_t ThinkNodeM1Board::getBattMilliVolts() { // divider into account (providing the actual LIPO voltage) return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB); } - -bool ThinkNodeM1Board::startOTAUpdate(const char *id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("THINKNODE_M1_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - return true; -} #endif diff --git a/variants/thinknode_m1/ThinkNodeM1Board.h b/variants/thinknode_m1/ThinkNodeM1Board.h index cffa0aaaf..1c86c7bb6 100644 --- a/variants/thinknode_m1/ThinkNodeM1Board.h +++ b/variants/thinknode_m1/ThinkNodeM1Board.h @@ -2,6 +2,7 @@ #include #include +#include // built-ins #define VBAT_MV_PER_LSB (0.73242188F) // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096 @@ -12,19 +13,11 @@ #define PIN_VBAT_READ (4) #define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) -class ThinkNodeM1Board : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class ThinkNodeM1Board : public NRF52BoardOTA { public: - + ThinkNodeM1Board() : NRF52BoardOTA("THINKNODE_M1_OTA") {} 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 { @@ -39,10 +32,6 @@ class ThinkNodeM1Board : public mesh::MainBoard { return "Elecrow ThinkNode-M1"; } - void reboot() override { - NVIC_SystemReset(); - } - void powerOff() override { // turn off all leds, sd_power_system_off will not do this for us diff --git a/variants/wio-tracker-l1/WioTrackerL1Board.cpp b/variants/wio-tracker-l1/WioTrackerL1Board.cpp index 34d9a8745..4153714e9 100644 --- a/variants/wio-tracker-l1/WioTrackerL1Board.cpp +++ b/variants/wio-tracker-l1/WioTrackerL1Board.cpp @@ -1,37 +1,12 @@ #include -#include "WioTrackerL1Board.h" - -#include #include -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; - - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} +#include "WioTrackerL1Board.h" void WioTrackerL1Board::begin() { - // for future use, sub-classes SHOULD call this from their begin() - startup_reason = BD_STARTUP_NORMAL; + NRF52BoardDCDC::begin(); btn_prev_state = HIGH; - // Enable DC/DC converter for improved power efficiency - uint8_t sd_enabled = 0; - sd_softdevice_is_enabled(&sd_enabled); - if (sd_enabled) { - sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE); - } else { - NRF_POWER->DCDCEN = 1; - } - pinMode(PIN_VBAT_READ, INPUT); // VBAT ADC input // Set all button pins to INPUT_PULLUP pinMode(PIN_BUTTON1, INPUT_PULLUP); @@ -55,51 +30,3 @@ void WioTrackerL1Board::begin() { delay(10); // give sx1262 some time to power up } - -bool WioTrackerL1Board::startOTAUpdate(const char* id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("WioTrackerL1 OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - uint8_t mac_addr[6]; - memset(mac_addr, 0, sizeof(mac_addr)); - Bluefruit.getAddr(mac_addr); - sprintf(reply, "OK - mac: %02X:%02X:%02X:%02X:%02X:%02X", - mac_addr[5], mac_addr[4], mac_addr[3], mac_addr[2], mac_addr[1], mac_addr[0]); - - return true; -} diff --git a/variants/wio-tracker-l1/WioTrackerL1Board.h b/variants/wio-tracker-l1/WioTrackerL1Board.h index f04b673f8..4947885e4 100644 --- a/variants/wio-tracker-l1/WioTrackerL1Board.h +++ b/variants/wio-tracker-l1/WioTrackerL1Board.h @@ -2,15 +2,15 @@ #include #include +#include -class WioTrackerL1Board : public mesh::MainBoard { +class WioTrackerL1Board : public NRF52BoardDCDC, public NRF52BoardOTA { protected: - uint8_t startup_reason; uint8_t btn_prev_state; public: + WioTrackerL1Board() : NRF52BoardOTA("WioTrackerL1 OTA") {} void begin(); - uint8_t getStartupReason() const override { return startup_reason; } #if defined(P_LORA_TX_LED) void onBeforeTransmit() override { @@ -34,13 +34,7 @@ class WioTrackerL1Board : public mesh::MainBoard { return "Seeed Wio Tracker L1"; } - void reboot() override { - NVIC_SystemReset(); - } - void powerOff() override { sd_power_system_off(); } - - bool startOTAUpdate(const char* id, char reply[]) override; }; diff --git a/variants/wio_wm1110/WioWM1110Board.cpp b/variants/wio_wm1110/WioWM1110Board.cpp index 153d476c4..d0ab97858 100644 --- a/variants/wio_wm1110/WioWM1110Board.cpp +++ b/variants/wio_wm1110/WioWM1110Board.cpp @@ -21,16 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { } void WioWM1110Board::begin() { - startup_reason = BD_STARTUP_NORMAL; - - // Enable DC/DC converter for improved power efficiency - uint8_t sd_enabled = 0; - sd_softdevice_is_enabled(&sd_enabled); - if (sd_enabled) { - sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE); - } else { - NRF_POWER->DCDCEN = 1; - } + NRF52BoardDCDC::begin(); pinMode(BATTERY_PIN, INPUT); pinMode(LED_GREEN, OUTPUT); diff --git a/variants/wio_wm1110/WioWM1110Board.h b/variants/wio_wm1110/WioWM1110Board.h index 823acbc7d..0e2db19c4 100644 --- a/variants/wio_wm1110/WioWM1110Board.h +++ b/variants/wio_wm1110/WioWM1110Board.h @@ -2,6 +2,7 @@ #include #include +#include #ifdef WIO_WM1110 @@ -10,13 +11,9 @@ #endif #define Serial Serial1 -class WioWM1110Board : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class WioWM1110Board : public NRF52BoardDCDC { public: void begin(); - uint8_t getStartupReason() const override { return startup_reason; } #if defined(LED_GREEN) void onBeforeTransmit() override { @@ -40,10 +37,6 @@ class WioWM1110Board : public mesh::MainBoard { return "Seeed Wio WM1110"; } - void reboot() override { - NVIC_SystemReset(); - } - bool startOTAUpdate(const char* id, char reply[]) override; void enableSensorPower(bool enable) { diff --git a/variants/xiao_nrf52/XiaoNrf52Board.cpp b/variants/xiao_nrf52/XiaoNrf52Board.cpp index f847c6543..b7b60dc63 100644 --- a/variants/xiao_nrf52/XiaoNrf52Board.cpp +++ b/variants/xiao_nrf52/XiaoNrf52Board.cpp @@ -2,36 +2,11 @@ #include #include -#include #include "XiaoNrf52Board.h" -static BLEDfu bledfu; - -static void connect_callback(uint16_t conn_handle) { - (void)conn_handle; - MESH_DEBUG_PRINTLN("BLE client connected"); -} - -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { - (void)conn_handle; - (void)reason; - - MESH_DEBUG_PRINTLN("BLE client disconnected"); -} - void XiaoNrf52Board::begin() { - // for future use, sub-classes SHOULD call this from their begin() - startup_reason = BD_STARTUP_NORMAL; - - // Enable DC/DC converter for improved power efficiency - uint8_t sd_enabled = 0; - sd_softdevice_is_enabled(&sd_enabled); - if (sd_enabled) { - sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE); - } else { - NRF_POWER->DCDCEN = 1; - } + NRF52BoardDCDC::begin(); pinMode(PIN_VBAT, INPUT); pinMode(VBAT_ENABLE, OUTPUT); @@ -57,48 +32,4 @@ void XiaoNrf52Board::begin() { delay(10); // give sx1262 some time to power up } -bool XiaoNrf52Board::startOTAUpdate(const char *id, char reply[]) { - // Config the peripheral connection with maximum bandwidth - // more SRAM required by SoftDevice - // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); - - Bluefruit.begin(1, 0); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(4); - // Set the BLE device name - Bluefruit.setName("XIAO_NRF52_OTA"); - - Bluefruit.Periph.setConnectCallback(connect_callback); - Bluefruit.Periph.setDisconnectCallback(disconnect_callback); - - // To be consistent OTA DFU should be added first if it exists - bledfu.begin(); - - // Set up and start advertising - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addName(); - - /* Start Advertising - - Enable auto advertising if disconnected - - Interval: fast mode = 20 ms, slow mode = 152.5 ms - - Timeout for fast mode is 30 seconds - - Start(timeout) with timeout = 0 will advertise forever (until connected) - - For recommended advertising interval - https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds - - strcpy(reply, "OK - started"); - - return true; -} - #endif \ No newline at end of file diff --git a/variants/xiao_nrf52/XiaoNrf52Board.h b/variants/xiao_nrf52/XiaoNrf52Board.h index f37660123..c4c77c6a5 100644 --- a/variants/xiao_nrf52/XiaoNrf52Board.h +++ b/variants/xiao_nrf52/XiaoNrf52Board.h @@ -2,16 +2,14 @@ #include #include +#include #ifdef XIAO_NRF52 -class XiaoNrf52Board : public mesh::MainBoard { -protected: - uint8_t startup_reason; - +class XiaoNrf52Board : public NRF52BoardDCDC, public NRF52BoardOTA { public: + XiaoNrf52Board() : NRF52BoardOTA("XIAO_NRF52_OTA") {} void begin(); - uint8_t getStartupReason() const override { return startup_reason; } #if defined(P_LORA_TX_LED) void onBeforeTransmit() override { @@ -42,10 +40,6 @@ class XiaoNrf52Board : public mesh::MainBoard { return "Seeed Xiao-nrf52"; } - void reboot() override { - NVIC_SystemReset(); - } - void powerOff() override { // set led on and wait for button release before poweroff digitalWrite(PIN_LED, LOW); @@ -63,8 +57,6 @@ class XiaoNrf52Board : public mesh::MainBoard { sd_power_system_off(); } - - bool startOTAUpdate(const char* id, char reply[]) override; }; #endif \ No newline at end of file