Skip to content

Commit 89350fb

Browse files
committed
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 <[email protected]>
1 parent 509d586 commit 89350fb

File tree

12 files changed

+39
-58
lines changed

12 files changed

+39
-58
lines changed

src/helpers/nrf52/NRF52Board.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
11
#include "NRF52Board.h"
22

3+
void NRF52Board::begin() {
4+
startup_reason = BD_STARTUP_NORMAL;
5+
}
6+
7+
void NRF52BoardDCDC::begin() {
8+
NRF52Board::begin();
9+
10+
// Enable DC/DC converter for improved power efficiency
11+
uint8_t sd_enabled = 0;
12+
sd_softdevice_is_enabled(&sd_enabled);
13+
if (sd_enabled) {
14+
sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
15+
} else {
16+
NRF_POWER->DCDCEN = 1;
17+
}
18+
}

src/helpers/nrf52/NRF52Board.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ class NRF52Board : public mesh::MainBoard {
88
uint8_t startup_reason;
99

1010
public:
11-
virtual void begin() {
12-
startup_reason = BD_STARTUP_NORMAL;
13-
}
11+
virtual void begin();
1412

1513
virtual uint8_t getStartupReason() const override {
1614
return startup_reason;
@@ -19,4 +17,16 @@ class NRF52Board : public mesh::MainBoard {
1917
virtual void reboot() override {
2018
NVIC_SystemReset();
2119
}
20+
};
21+
22+
/*
23+
* The NRF52 has an internal DC/DC regulator that allows increased efficiency
24+
* compared to the LDO regulator. For being able to use it, the module/board
25+
* needs to have the required inductors and and capacitors populated. If the
26+
* hardware requirements are met, this subclass can be used to enable the DC/DC
27+
* regulator.
28+
*/
29+
class NRF52BoardDCDC : virtual public NRF52Board {
30+
public:
31+
virtual void begin() override;
2232
};

variants/rak_wismesh_tag/RAKWismeshTagBoard.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
1919
}
2020

2121
void RAKWismeshTagBoard::begin() {
22-
NRF52Board::begin();
23-
24-
// Enable DC/DC converter for improved power efficiency
25-
uint8_t sd_enabled = 0;
26-
sd_softdevice_is_enabled(&sd_enabled);
27-
if (sd_enabled) {
28-
sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
29-
} else {
30-
NRF_POWER->DCDCEN = 1;
31-
}
22+
NRF52BoardDCDC::begin();
3223

3324
pinMode(PIN_VBAT_READ, INPUT);
3425
pinMode(PIN_USER_BTN, INPUT_PULLUP);

variants/rak_wismesh_tag/RAKWismeshTagBoard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define PIN_VBAT_READ 5
99
#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000)
1010

11-
class RAKWismeshTagBoard : public NRF52Board {
11+
class RAKWismeshTagBoard : public NRF52BoardDCDC {
1212
public:
1313
void begin();
1414

variants/t1000-e/T1000eBoard.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,9 @@
55
#include <bluefruit.h>
66

77
void T1000eBoard::begin() {
8-
NRF52Board::begin();
8+
NRF52BoardDCDC::begin();
99
btn_prev_state = HIGH;
1010

11-
// Enable DC/DC converter for improved power efficiency
12-
uint8_t sd_enabled = 0;
13-
sd_softdevice_is_enabled(&sd_enabled);
14-
if (sd_enabled) {
15-
sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
16-
} else {
17-
NRF_POWER->DCDCEN = 1;
18-
}
19-
2011
#ifdef BUTTON_PIN
2112
pinMode(BATTERY_PIN, INPUT);
2213
pinMode(BUTTON_PIN, INPUT);

variants/t1000-e/T1000eBoard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <Arduino.h>
55
#include <helpers/nrf52/NRF52Board.h>
66

7-
class T1000eBoard : public NRF52Board {
7+
class T1000eBoard : public NRF52BoardDCDC {
88
protected:
99
uint8_t btn_prev_state;
1010

variants/wio-tracker-l1/WioTrackerL1Board.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,9 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
1919
}
2020

2121
void WioTrackerL1Board::begin() {
22-
NRF52Board::begin();
22+
NRF52BoardDCDC::begin();
2323
btn_prev_state = HIGH;
2424

25-
// Enable DC/DC converter for improved power efficiency
26-
uint8_t sd_enabled = 0;
27-
sd_softdevice_is_enabled(&sd_enabled);
28-
if (sd_enabled) {
29-
sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
30-
} else {
31-
NRF_POWER->DCDCEN = 1;
32-
}
33-
3425
pinMode(PIN_VBAT_READ, INPUT); // VBAT ADC input
3526
// Set all button pins to INPUT_PULLUP
3627
pinMode(PIN_BUTTON1, INPUT_PULLUP);

variants/wio-tracker-l1/WioTrackerL1Board.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <Arduino.h>
55
#include <helpers/nrf52/NRF52Board.h>
66

7-
class WioTrackerL1Board : public NRF52Board {
7+
class WioTrackerL1Board : public NRF52BoardDCDC {
88
protected:
99
uint8_t btn_prev_state;
1010

variants/wio_wm1110/WioWM1110Board.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
2121
}
2222

2323
void WioWM1110Board::begin() {
24-
NRF52Board::begin();
25-
26-
// Enable DC/DC converter for improved power efficiency
27-
uint8_t sd_enabled = 0;
28-
sd_softdevice_is_enabled(&sd_enabled);
29-
if (sd_enabled) {
30-
sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
31-
} else {
32-
NRF_POWER->DCDCEN = 1;
33-
}
24+
NRF52BoardDCDC::begin();
3425

3526
pinMode(BATTERY_PIN, INPUT);
3627
pinMode(LED_GREEN, OUTPUT);

variants/wio_wm1110/WioWM1110Board.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#endif
1212
#define Serial Serial1
1313

14-
class WioWM1110Board : public NRF52Board {
14+
class WioWM1110Board : public NRF52BoardDCDC {
1515
public:
1616
void begin();
1717

0 commit comments

Comments
 (0)