Merge pull request #1246 from fschrempf/nrf-dcdc
NRF52 boards: Enable internal DC/DC regulator to reduce power consumption and enable OTA support for all boards
This commit is contained in:
@@ -271,7 +271,7 @@ float NRF52Board::getMCUTemperature() {
|
|||||||
return temp * 0.25f; // Convert to *C
|
return temp * 0.25f; // Convert to *C
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NRF52BoardOTA::startOTAUpdate(const char *id, char reply[]) {
|
bool NRF52Board::startOTAUpdate(const char *id, char reply[]) {
|
||||||
// Config the peripheral connection with maximum bandwidth
|
// Config the peripheral connection with maximum bandwidth
|
||||||
// more SRAM required by SoftDevice
|
// more SRAM required by SoftDevice
|
||||||
// Note: All config***() function must be called before begin()
|
// Note: All config***() function must be called before begin()
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class NRF52Board : public mesh::MainBoard {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t startup_reason;
|
uint8_t startup_reason;
|
||||||
|
char *ota_name;
|
||||||
|
|
||||||
#ifdef NRF52_POWER_MANAGEMENT
|
#ifdef NRF52_POWER_MANAGEMENT
|
||||||
uint32_t reset_reason; // RESETREAS register value
|
uint32_t reset_reason; // RESETREAS register value
|
||||||
@@ -44,10 +45,12 @@ protected:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
NRF52Board(char *otaname) : ota_name(otaname) {}
|
||||||
virtual void begin();
|
virtual void begin();
|
||||||
virtual uint8_t getStartupReason() const override { return startup_reason; }
|
virtual uint8_t getStartupReason() const override { return startup_reason; }
|
||||||
virtual float getMCUTemperature() override;
|
virtual float getMCUTemperature() override;
|
||||||
virtual void reboot() override { NVIC_SystemReset(); }
|
virtual void reboot() override { NVIC_SystemReset(); }
|
||||||
|
virtual bool startOTAUpdate(const char *id, char reply[]) override;
|
||||||
|
|
||||||
#ifdef NRF52_POWER_MANAGEMENT
|
#ifdef NRF52_POWER_MANAGEMENT
|
||||||
bool isExternalPowered() override;
|
bool isExternalPowered() override;
|
||||||
@@ -68,15 +71,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
class NRF52BoardDCDC : virtual public NRF52Board {
|
class NRF52BoardDCDC : virtual public NRF52Board {
|
||||||
public:
|
public:
|
||||||
|
NRF52BoardDCDC() {}
|
||||||
virtual void begin() override;
|
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;
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
@@ -20,9 +20,9 @@
|
|||||||
#define SX126X_DIO2_AS_RF_SWITCH true
|
#define SX126X_DIO2_AS_RF_SWITCH true
|
||||||
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
|
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
|
||||||
|
|
||||||
class MeshSolarBoard : public NRF52BoardOTA {
|
class MeshSolarBoard : public NRF52BoardDCDC {
|
||||||
public:
|
public:
|
||||||
MeshSolarBoard() : NRF52BoardOTA("MESH_SOLAR_OTA") {}
|
MeshSolarBoard() : NRF52Board("MESH_SOLAR_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
uint16_t getBattMilliVolts() override {
|
uint16_t getBattMilliVolts() override {
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
#define PIN_BAT_CTL 6
|
#define PIN_BAT_CTL 6
|
||||||
#define MV_LSB (3000.0F / 4096.0F) // 12-bit ADC with 3.0V input range
|
#define MV_LSB (3000.0F / 4096.0F) // 12-bit ADC with 3.0V input range
|
||||||
|
|
||||||
class T114Board : public NRF52BoardOTA {
|
class T114Board : public NRF52BoardDCDC {
|
||||||
protected:
|
protected:
|
||||||
#ifdef NRF52_POWER_MANAGEMENT
|
#ifdef NRF52_POWER_MANAGEMENT
|
||||||
void initiateShutdown(uint8_t reason) override;
|
void initiateShutdown(uint8_t reason) override;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
T114Board() : NRF52BoardOTA("T114_OTA") {}
|
T114Board() : NRF52Board("T114_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
#if defined(P_LORA_TX_LED)
|
#if defined(P_LORA_TX_LED)
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
#ifdef IKOKA_NRF52
|
#ifdef IKOKA_NRF52
|
||||||
|
|
||||||
class IkokaNrf52Board : public NRF52BoardOTA {
|
class IkokaNrf52Board : public NRF52BoardDCDC {
|
||||||
public:
|
public:
|
||||||
IkokaNrf52Board() : NRF52BoardOTA("XIAO_NRF52_OTA") {}
|
IkokaNrf52Board() : NRF52Board("XIAO_NRF52_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
#if defined(P_LORA_TX_LED)
|
#if defined(P_LORA_TX_LED)
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
#ifdef XIAO_NRF52
|
#ifdef XIAO_NRF52
|
||||||
|
|
||||||
class IkokaNanoNRFBoard : public NRF52BoardOTA {
|
class IkokaNanoNRFBoard : public NRF52BoardDCDC {
|
||||||
public:
|
public:
|
||||||
IkokaNanoNRFBoard() : NRF52BoardOTA("XIAO_NRF52_OTA") {}
|
IkokaNanoNRFBoard() : NRF52Board("XIAO_NRF52_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
#if defined(P_LORA_TX_LED)
|
#if defined(P_LORA_TX_LED)
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
#ifdef XIAO_NRF52
|
#ifdef XIAO_NRF52
|
||||||
|
|
||||||
class IkokaStickNRFBoard : public NRF52BoardOTA {
|
class IkokaStickNRFBoard : public NRF52BoardDCDC {
|
||||||
public:
|
public:
|
||||||
IkokaStickNRFBoard() : NRF52BoardOTA("XIAO_NRF52_OTA") {}
|
IkokaStickNRFBoard() : NRF52Board("XIAO_NRF52_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
#if defined(P_LORA_TX_LED)
|
#if defined(P_LORA_TX_LED)
|
||||||
|
|||||||
@@ -4,12 +4,12 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <helpers/NRF52Board.h>
|
#include <helpers/NRF52Board.h>
|
||||||
|
|
||||||
class KeepteenLT1Board : public NRF52BoardOTA {
|
class KeepteenLT1Board : public NRF52Board {
|
||||||
protected:
|
protected:
|
||||||
uint8_t btn_prev_state;
|
uint8_t btn_prev_state;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KeepteenLT1Board() : NRF52BoardOTA("KeepteenLT1_OTA") {}
|
KeepteenLT1Board() : NRF52Board("KeepteenLT1_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
#define BATTERY_SAMPLES 8
|
#define BATTERY_SAMPLES 8
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
#define PIN_VBAT_READ (4)
|
#define PIN_VBAT_READ (4)
|
||||||
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
|
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
|
||||||
|
|
||||||
class TechoBoard : public NRF52BoardOTA {
|
class TechoBoard : public NRF52BoardDCDC {
|
||||||
public:
|
public:
|
||||||
TechoBoard() : NRF52BoardOTA("TECHO_OTA") {}
|
TechoBoard() : NRF52Board("TECHO_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
uint16_t getBattMilliVolts() override;
|
uint16_t getBattMilliVolts() override;
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
#define PIN_VBAT_READ (4)
|
#define PIN_VBAT_READ (4)
|
||||||
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
|
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
|
||||||
|
|
||||||
class TechoBoard : public NRF52BoardOTA {
|
class TechoBoard : public NRF52BoardDCDC {
|
||||||
public:
|
public:
|
||||||
TechoBoard() : NRF52BoardOTA("TECHO_OTA") {}
|
TechoBoard() : NRF52Board("TECHO_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
uint16_t getBattMilliVolts() override;
|
uint16_t getBattMilliVolts() override;
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
#define PIN_BAT_CTL 34
|
#define PIN_BAT_CTL 34
|
||||||
#define MV_LSB (3000.0F / 4096.0F) // 12-bit ADC with 3.0V input range
|
#define MV_LSB (3000.0F / 4096.0F) // 12-bit ADC with 3.0V input range
|
||||||
|
|
||||||
class HeltecMeshPocket : public NRF52BoardOTA {
|
class HeltecMeshPocket : public NRF52BoardDCDC {
|
||||||
public:
|
public:
|
||||||
HeltecMeshPocket() : NRF52BoardOTA("MESH_POCKET_OTA") {}
|
HeltecMeshPocket() : NRF52Board("MESH_POCKET_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
uint16_t getBattMilliVolts() override {
|
uint16_t getBattMilliVolts() override {
|
||||||
|
|||||||
@@ -20,12 +20,12 @@
|
|||||||
#define PIN_VBAT_READ BATTERY_PIN
|
#define PIN_VBAT_READ BATTERY_PIN
|
||||||
#define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking
|
#define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking
|
||||||
|
|
||||||
class MinewsemiME25LS01Board : public NRF52BoardOTA {
|
class MinewsemiME25LS01Board : public NRF52BoardDCDC {
|
||||||
protected:
|
protected:
|
||||||
uint8_t btn_prev_state;
|
uint8_t btn_prev_state;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MinewsemiME25LS01Board() : NRF52BoardOTA("Minewsemi_OTA") {}
|
MinewsemiME25LS01Board() : NRF52Board("Minewsemi_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
#define BATTERY_SAMPLES 8
|
#define BATTERY_SAMPLES 8
|
||||||
|
|||||||
@@ -3,25 +3,8 @@
|
|||||||
|
|
||||||
#ifdef NANO_G2_ULTRA
|
#ifdef NANO_G2_ULTRA
|
||||||
|
|
||||||
#include <bluefruit.h>
|
|
||||||
#include <Wire.h>
|
#include <Wire.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 NanoG2Ultra::begin()
|
void NanoG2Ultra::begin()
|
||||||
{
|
{
|
||||||
NRF52Board::begin();
|
NRF52Board::begin();
|
||||||
@@ -56,48 +39,4 @@ uint16_t NanoG2Ultra::getBattMilliVolts()
|
|||||||
// divider into account (providing the actual LIPO voltage)
|
// divider into account (providing the actual LIPO voltage)
|
||||||
return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB);
|
return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NanoG2Ultra::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("NANO_G2_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
|
#endif
|
||||||
|
|||||||
@@ -37,9 +37,9 @@
|
|||||||
|
|
||||||
class NanoG2Ultra : public NRF52Board {
|
class NanoG2Ultra : public NRF52Board {
|
||||||
public:
|
public:
|
||||||
|
NanoG2Ultra() : NRF52Board("NANO_G2_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
uint16_t getBattMilliVolts() override;
|
uint16_t getBattMilliVolts() override;
|
||||||
bool startOTAUpdate(const char *id, char reply[]) override;
|
|
||||||
|
|
||||||
const char *getManufacturerName() const override { return "Nano G2 Ultra"; }
|
const char *getManufacturerName() const override { return "Nano G2 Ultra"; }
|
||||||
|
|
||||||
|
|||||||
@@ -20,13 +20,13 @@
|
|||||||
#define PIN_VBAT_READ 17
|
#define PIN_VBAT_READ 17
|
||||||
#define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking
|
#define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking
|
||||||
|
|
||||||
class PromicroBoard : public NRF52BoardOTA {
|
class PromicroBoard : public NRF52BoardDCDC {
|
||||||
protected:
|
protected:
|
||||||
uint8_t btn_prev_state;
|
uint8_t btn_prev_state;
|
||||||
float adc_mult = ADC_MULTIPLIER;
|
float adc_mult = ADC_MULTIPLIER;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PromicroBoard() : NRF52BoardOTA("ProMicro_OTA") {}
|
PromicroBoard() : NRF52Board("ProMicro_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
#define BATTERY_SAMPLES 8
|
#define BATTERY_SAMPLES 8
|
||||||
|
|||||||
@@ -29,14 +29,14 @@
|
|||||||
#define PIN_VBAT_READ 5
|
#define PIN_VBAT_READ 5
|
||||||
#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000)
|
#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000)
|
||||||
|
|
||||||
class RAK4631Board : public NRF52BoardDCDC, public NRF52BoardOTA {
|
class RAK4631Board : public NRF52BoardDCDC {
|
||||||
protected:
|
protected:
|
||||||
#ifdef NRF52_POWER_MANAGEMENT
|
#ifdef NRF52_POWER_MANAGEMENT
|
||||||
void initiateShutdown(uint8_t reason) override;
|
void initiateShutdown(uint8_t reason) override;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RAK4631Board() : NRF52BoardOTA("RAK4631_OTA") {}
|
RAK4631Board() : NRF52Board("RAK4631_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
#define BATTERY_SAMPLES 8
|
#define BATTERY_SAMPLES 8
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
#define PIN_VBAT_READ 5
|
#define PIN_VBAT_READ 5
|
||||||
#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000)
|
#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000)
|
||||||
|
|
||||||
class RAKWismeshTagBoard : public NRF52BoardDCDC, public NRF52BoardOTA {
|
class RAKWismeshTagBoard : public NRF52BoardDCDC {
|
||||||
public:
|
public:
|
||||||
RAKWismeshTagBoard() : NRF52BoardOTA("WISMESHTAG_OTA") {}
|
RAKWismeshTagBoard() : NRF52Board("WISMESHTAG_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
#if defined(P_LORA_TX_LED) && defined(LED_STATE_ON)
|
#if defined(P_LORA_TX_LED) && defined(LED_STATE_ON)
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <helpers/NRF52Board.h>
|
#include <helpers/NRF52Board.h>
|
||||||
|
|
||||||
class SenseCapSolarBoard : public NRF52BoardOTA {
|
class SenseCapSolarBoard : public NRF52BoardDCDC {
|
||||||
public:
|
public:
|
||||||
SenseCapSolarBoard() : NRF52BoardOTA("SENSECAP_SOLAR_OTA") {}
|
SenseCapSolarBoard() : NRF52Board("SENSECAP_SOLAR_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
#if defined(P_LORA_TX_LED)
|
#if defined(P_LORA_TX_LED)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ protected:
|
|||||||
uint8_t btn_prev_state;
|
uint8_t btn_prev_state;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
T1000eBoard() : NRF52Board("T1000E_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
uint16_t getBattMilliVolts() override {
|
uint16_t getBattMilliVolts() override {
|
||||||
@@ -89,6 +90,4 @@ public:
|
|||||||
|
|
||||||
sd_power_system_off();
|
sd_power_system_off();
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool startOTAUpdate(const char* id, char reply[]) override;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
#define PIN_VBAT_READ (4)
|
#define PIN_VBAT_READ (4)
|
||||||
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
|
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
|
||||||
|
|
||||||
class ThinkNodeM1Board : public NRF52BoardOTA {
|
class ThinkNodeM1Board : public NRF52Board {
|
||||||
public:
|
public:
|
||||||
ThinkNodeM1Board() : NRF52BoardOTA("THINKNODE_M1_OTA") {}
|
ThinkNodeM1Board() : NRF52Board("THINKNODE_M1_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
uint16_t getBattMilliVolts() override;
|
uint16_t getBattMilliVolts() override;
|
||||||
|
|
||||||
|
|||||||
@@ -5,76 +5,10 @@
|
|||||||
#include <bluefruit.h>
|
#include <bluefruit.h>
|
||||||
|
|
||||||
void ThinknodeM3Board::begin() {
|
void ThinknodeM3Board::begin() {
|
||||||
// for future use, sub-classes SHOULD call this from their begin()
|
Nrf52BoardDCDC::begin();
|
||||||
startup_reason = BD_STARTUP_NORMAL;
|
|
||||||
btn_prev_state = HIGH;
|
btn_prev_state = HIGH;
|
||||||
|
|
||||||
sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
|
|
||||||
|
|
||||||
// Enable DC/DC converter for improved power efficiency
|
|
||||||
NRF_POWER->DCDCEN = 1;
|
|
||||||
|
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
|
||||||
delay(10); // give sx1262 some time to power up
|
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 TrackerThinknodeM3Board::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
|
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <MeshCore.h>
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <MeshCore.h>
|
||||||
|
#include <helpers/NRF52Board.h>
|
||||||
|
|
||||||
#define ADC_FACTOR ((1000.0*ADC_MULTIPLIER*AREF_VOLTAGE)/ADC_MAX)
|
#define ADC_FACTOR ((1000.0*ADC_MULTIPLIER*AREF_VOLTAGE)/ADC_MAX)
|
||||||
|
|
||||||
class ThinknodeM3Board : public mesh::MainBoard {
|
class ThinknodeM3Board : public Nrf52BoardDCDC {
|
||||||
protected:
|
protected:
|
||||||
uint8_t startup_reason;
|
|
||||||
uint8_t btn_prev_state;
|
uint8_t btn_prev_state;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -27,12 +27,10 @@ public:
|
|||||||
return (uint16_t)((float)adcvalue * ADC_FACTOR);
|
return (uint16_t)((float)adcvalue * ADC_FACTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getStartupReason() const override { return startup_reason; }
|
#if defined(P_LORA_TX_LED)
|
||||||
|
#if !defined(P_LORA_TX_LED_ON)
|
||||||
#if defined(P_LORA_TX_LED)
|
#define P_LORA_TX_LED_ON HIGH
|
||||||
#if !defined(P_LORA_TX_LED_ON)
|
#endif
|
||||||
#define P_LORA_TX_LED_ON HIGH
|
|
||||||
#endif
|
|
||||||
void onBeforeTransmit() override {
|
void onBeforeTransmit() override {
|
||||||
digitalWrite(P_LORA_TX_LED, P_LORA_TX_LED_ON); // turn TX LED on
|
digitalWrite(P_LORA_TX_LED, P_LORA_TX_LED_ON); // turn TX LED on
|
||||||
}
|
}
|
||||||
@@ -56,13 +54,5 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void powerOff() override {
|
void powerOff() override { sd_power_system_off(); }
|
||||||
sd_power_system_off();
|
|
||||||
}
|
|
||||||
|
|
||||||
void reboot() override {
|
|
||||||
NVIC_SystemReset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// bool startOTAUpdate(const char* id, char reply[]) override;
|
|
||||||
};
|
};
|
||||||
@@ -4,25 +4,9 @@
|
|||||||
#ifdef THINKNODE_M6
|
#ifdef THINKNODE_M6
|
||||||
|
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <bluefruit.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 ThinkNodeM6Board::begin() {
|
void ThinkNodeM6Board::begin() {
|
||||||
// for future use, sub-classes SHOULD call this from their begin()
|
NRF52Board::begin();
|
||||||
startup_reason = BD_STARTUP_NORMAL;
|
|
||||||
|
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
|
||||||
@@ -49,47 +33,4 @@ uint16_t ThinkNodeM6Board::getBattMilliVolts() {
|
|||||||
// divider into account (providing the actual LIPO voltage)
|
// divider into account (providing the actual LIPO voltage)
|
||||||
return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB);
|
return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ThinkNodeM6Board::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
|
#endif
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <MeshCore.h>
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <MeshCore.h>
|
||||||
|
#include <helpers/NRF52Board.h>
|
||||||
|
|
||||||
// built-ins
|
// built-ins
|
||||||
#define VBAT_MV_PER_LSB (0.73242188F) // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096
|
#define VBAT_MV_PER_LSB (0.73242188F) // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096
|
||||||
@@ -11,21 +12,13 @@
|
|||||||
#define PIN_VBAT_READ BATTERY_PIN
|
#define PIN_VBAT_READ BATTERY_PIN
|
||||||
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
|
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
|
||||||
|
|
||||||
class ThinkNodeM6Board : public mesh::MainBoard {
|
class ThinkNodeM6Board : public Nrf52BoardOTA {
|
||||||
protected:
|
|
||||||
uint8_t startup_reason;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
ThinkNodeM6Board() : NRF52BoardOTA("THINKNODE_M1_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
uint16_t getBattMilliVolts() override;
|
uint16_t getBattMilliVolts() override;
|
||||||
bool startOTAUpdate(const char* id, char reply[]) override;
|
|
||||||
|
|
||||||
uint8_t getStartupReason() const override {
|
#if defined(P_LORA_TX_LED)
|
||||||
return startup_reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(P_LORA_TX_LED)
|
|
||||||
void onBeforeTransmit() override {
|
void onBeforeTransmit() override {
|
||||||
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
|
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
|
||||||
}
|
}
|
||||||
@@ -38,10 +31,6 @@ public:
|
|||||||
return "Elecrow ThinkNode-M6";
|
return "Elecrow ThinkNode-M6";
|
||||||
}
|
}
|
||||||
|
|
||||||
void reboot() override {
|
|
||||||
NVIC_SystemReset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void powerOff() override {
|
void powerOff() override {
|
||||||
|
|
||||||
// turn off all leds, sd_power_system_off will not do this for us
|
// turn off all leds, sd_power_system_off will not do this for us
|
||||||
@@ -51,6 +40,5 @@ public:
|
|||||||
|
|
||||||
// power off board
|
// power off board
|
||||||
sd_power_system_off();
|
sd_power_system_off();
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,12 +4,12 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <helpers/NRF52Board.h>
|
#include <helpers/NRF52Board.h>
|
||||||
|
|
||||||
class WioTrackerL1Board : public NRF52BoardDCDC, public NRF52BoardOTA {
|
class WioTrackerL1Board : public NRF52BoardDCDC {
|
||||||
protected:
|
protected:
|
||||||
uint8_t btn_prev_state;
|
uint8_t btn_prev_state;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WioTrackerL1Board() : NRF52BoardOTA("WioTrackerL1 OTA") {}
|
WioTrackerL1Board() : NRF52Board("WioTrackerL1 OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
#if defined(P_LORA_TX_LED)
|
#if defined(P_LORA_TX_LED)
|
||||||
|
|||||||
@@ -1,24 +1,9 @@
|
|||||||
#ifdef WIO_WM1110
|
#ifdef WIO_WM1110
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include <Wire.h>
|
|
||||||
#include <bluefruit.h>
|
|
||||||
|
|
||||||
#include "WioWM1110Board.h"
|
#include "WioWM1110Board.h"
|
||||||
|
|
||||||
static BLEDfu bledfu;
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
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 WioWM1110Board::begin() {
|
void WioWM1110Board::begin() {
|
||||||
NRF52BoardDCDC::begin();
|
NRF52BoardDCDC::begin();
|
||||||
@@ -42,31 +27,5 @@ void WioWM1110Board::begin() {
|
|||||||
|
|
||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WioWM1110Board::startOTAUpdate(const char *id, char reply[]) {
|
|
||||||
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
|
|
||||||
Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16);
|
|
||||||
|
|
||||||
Bluefruit.begin(1, 0);
|
|
||||||
Bluefruit.setTxPower(4);
|
|
||||||
Bluefruit.setName("WM1110_OTA");
|
|
||||||
|
|
||||||
Bluefruit.Periph.setConnectCallback(connect_callback);
|
|
||||||
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
|
|
||||||
|
|
||||||
bledfu.begin();
|
|
||||||
|
|
||||||
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
|
||||||
Bluefruit.Advertising.addTxPower();
|
|
||||||
Bluefruit.Advertising.addName();
|
|
||||||
Bluefruit.Advertising.restartOnDisconnect(true);
|
|
||||||
Bluefruit.Advertising.setInterval(32, 244);
|
|
||||||
Bluefruit.Advertising.setFastTimeout(30);
|
|
||||||
Bluefruit.Advertising.start(0);
|
|
||||||
|
|
||||||
strcpy(reply, "OK - started");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
class WioWM1110Board : public NRF52BoardDCDC {
|
class WioWM1110Board : public NRF52BoardDCDC {
|
||||||
public:
|
public:
|
||||||
|
WioWM1110Board() : NRF52Board("WM1110_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
#if defined(LED_GREEN)
|
#if defined(LED_GREEN)
|
||||||
@@ -37,8 +38,6 @@ public:
|
|||||||
return "Seeed Wio WM1110";
|
return "Seeed Wio WM1110";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool startOTAUpdate(const char* id, char reply[]) override;
|
|
||||||
|
|
||||||
void enableSensorPower(bool enable) {
|
void enableSensorPower(bool enable) {
|
||||||
digitalWrite(SENSOR_POWER_PIN, enable ? HIGH : LOW);
|
digitalWrite(SENSOR_POWER_PIN, enable ? HIGH : LOW);
|
||||||
if (enable) {
|
if (enable) {
|
||||||
|
|||||||
@@ -6,14 +6,14 @@
|
|||||||
|
|
||||||
#ifdef XIAO_NRF52
|
#ifdef XIAO_NRF52
|
||||||
|
|
||||||
class XiaoNrf52Board : public NRF52BoardDCDC, public NRF52BoardOTA {
|
class XiaoNrf52Board : public NRF52BoardDCDC {
|
||||||
protected:
|
protected:
|
||||||
#if NRF52_POWER_MANAGEMENT
|
#if NRF52_POWER_MANAGEMENT
|
||||||
void initiateShutdown(uint8_t reason) override;
|
void initiateShutdown(uint8_t reason) override;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
XiaoNrf52Board() : NRF52BoardOTA("XIAO_NRF52_OTA") {}
|
XiaoNrf52Board() : NRF52Board("XIAO_NRF52_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
#if defined(P_LORA_TX_LED)
|
#if defined(P_LORA_TX_LED)
|
||||||
|
|||||||
Reference in New Issue
Block a user