mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-03-30 10:39:59 +00:00
Deduplicate DC/DC regulator enable for NRF52 boards
Some NRF52 boards are able to use the internal power-efficient DC/DC regulator. Add a new class that can be inherited by board classes to enable this feature and reduce the power consumption. Signed-off-by: Frieder Schrempf <frieder@fris.de>
This commit is contained in:
@@ -1,6 +1,23 @@
|
||||
#if defined(NRF52_PLATFORM)
|
||||
#include "NRF52Board.h"
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// Temperature from NRF52 MCU
|
||||
float NRF52Board::getMCUTemperature() {
|
||||
NRF_TEMP->TASKS_START = 1; // Start temperature measurement
|
||||
|
||||
@@ -10,9 +10,21 @@ protected:
|
||||
uint8_t startup_reason;
|
||||
|
||||
public:
|
||||
virtual void begin() { startup_reason = BD_STARTUP_NORMAL; }
|
||||
virtual void begin();
|
||||
virtual uint8_t getStartupReason() const override { return startup_reason; }
|
||||
float getMCUTemperature() override;
|
||||
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;
|
||||
};
|
||||
#endif
|
||||
@@ -19,16 +19,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
||||
}
|
||||
|
||||
void RAKWismeshTagBoard::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;
|
||||
}
|
||||
NRF52BoardDCDC::begin();
|
||||
|
||||
pinMode(PIN_VBAT_READ, INPUT);
|
||||
pinMode(PIN_USER_BTN, INPUT_PULLUP);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#define PIN_VBAT_READ 5
|
||||
#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000)
|
||||
|
||||
class RAKWismeshTagBoard : public NRF52Board {
|
||||
class RAKWismeshTagBoard : public NRF52BoardDCDC {
|
||||
public:
|
||||
void begin();
|
||||
|
||||
|
||||
@@ -5,18 +5,9 @@
|
||||
#include <bluefruit.h>
|
||||
|
||||
void T1000eBoard::begin() {
|
||||
NRF52Board::begin();
|
||||
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);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <helpers/NRF52Board.h>
|
||||
|
||||
class T1000eBoard : public NRF52Board {
|
||||
class T1000eBoard : public NRF52BoardDCDC {
|
||||
protected:
|
||||
uint8_t btn_prev_state;
|
||||
|
||||
|
||||
@@ -19,18 +19,9 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
||||
}
|
||||
|
||||
void WioTrackerL1Board::begin() {
|
||||
NRF52Board::begin();
|
||||
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);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <helpers/NRF52Board.h>
|
||||
|
||||
class WioTrackerL1Board : public NRF52Board {
|
||||
class WioTrackerL1Board : public NRF52BoardDCDC {
|
||||
protected:
|
||||
uint8_t btn_prev_state;
|
||||
|
||||
|
||||
@@ -21,16 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
||||
}
|
||||
|
||||
void WioWM1110Board::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;
|
||||
}
|
||||
NRF52BoardDCDC::begin();
|
||||
|
||||
pinMode(BATTERY_PIN, INPUT);
|
||||
pinMode(LED_GREEN, OUTPUT);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#endif
|
||||
#define Serial Serial1
|
||||
|
||||
class WioWM1110Board : public NRF52Board {
|
||||
class WioWM1110Board : public NRF52BoardDCDC {
|
||||
public:
|
||||
void begin();
|
||||
|
||||
|
||||
@@ -21,16 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
||||
}
|
||||
|
||||
void XiaoNrf52Board::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;
|
||||
}
|
||||
NRF52BoardDCDC::begin();
|
||||
|
||||
pinMode(PIN_VBAT, INPUT);
|
||||
pinMode(VBAT_ENABLE, OUTPUT);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#ifdef XIAO_NRF52
|
||||
|
||||
class XiaoNrf52Board : public NRF52Board {
|
||||
class XiaoNrf52Board : public NRF52BoardDCDC {
|
||||
public:
|
||||
void begin();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user