Skip to content

Commit c17bd5d

Browse files
authored
Merge pull request #1122 from fschrempf/xiao-nrf-ui-and-power-optimizations
Companion Power Optimizations and UI Support for XIAO NRF52
2 parents 8340d0e + 7723a4c commit c17bd5d

File tree

14 files changed

+64
-7
lines changed

14 files changed

+64
-7
lines changed

examples/companion_radio/ui-new/UITask.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ void UITask::userLedHandler() {
618618
led_state = 0;
619619
next_led_change = cur_time + LED_CYCLE_MILLIS - last_led_increment;
620620
}
621-
digitalWrite(PIN_STATUS_LED, led_state);
621+
digitalWrite(PIN_STATUS_LED, led_state == LED_STATE_ON);
622622
}
623623
#endif
624624
}
@@ -650,6 +650,7 @@ void UITask::shutdown(bool restart){
650650
_board->reboot();
651651
} else {
652652
_display->turnOff();
653+
radio_driver.powerOff();
653654
_board->powerOff();
654655
}
655656
}

examples/companion_radio/ui-orig/UITask.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ void UITask::userLedHandler() {
269269
state = 0;
270270
next_change = cur_time + LED_CYCLE_MILLIS - last_increment;
271271
}
272-
digitalWrite(PIN_STATUS_LED, state);
272+
digitalWrite(PIN_STATUS_LED, state == LED_STATE_ON);
273273
}
274274
#endif
275275
}
@@ -292,10 +292,12 @@ void UITask::shutdown(bool restart){
292292

293293
#endif // PIN_BUZZER
294294

295-
if (restart)
295+
if (restart) {
296296
_board->reboot();
297-
else
297+
} else {
298+
radio_driver.powerOff();
298299
_board->powerOff();
300+
}
299301
}
300302

301303
void UITask::loop() {

src/helpers/radiolib/CustomSX1262Wrapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ class CustomSX1262Wrapper : public RadioLibWrapper {
1919
int sf = ((CustomSX1262 *)_radio)->spreadingFactor;
2020
return packetScoreInt(snr, sf, packet_len);
2121
}
22+
virtual void powerOff() override {
23+
((CustomSX1262 *)_radio)->sleep(false);
24+
}
2225
};

src/helpers/radiolib/RadioLibWrappers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class RadioLibWrapper : public mesh::Radio {
2121
RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board) : _radio(&radio), _board(&board) { n_recv = n_sent = 0; }
2222

2323
void begin() override;
24+
virtual void powerOff() { _radio->sleep(); }
2425
int recvRaw(uint8_t* bytes, int sz) override;
2526
uint32_t getEstAirtimeFor(int len_bytes) override;
2627
bool startSendRaw(const uint8_t* bytes, int len) override;

variants/heltec_t114/T114Board.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
2121
void T114Board::begin() {
2222
// for future use, sub-classes SHOULD call this from their begin()
2323
startup_reason = BD_STARTUP_NORMAL;
24+
NRF_POWER->DCDCEN = 1;
2425

2526
pinMode(PIN_VBAT_READ, INPUT);
2627

variants/heltec_t114/T114Board.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ class T114Board : public mesh::MainBoard {
4848
}
4949

5050
void powerOff() override {
51+
#ifdef LED_PIN
52+
digitalWrite(LED_PIN, HIGH);
53+
#endif
54+
#if ENV_INCLUDE_GPS == 1
55+
pinMode(GPS_EN, OUTPUT);
56+
digitalWrite(GPS_EN, LOW);
57+
#endif
5158
sd_power_system_off();
5259
}
5360

variants/rak_wismesh_tag/RAKWismeshTagBoard.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
2121
void RAKWismeshTagBoard::begin() {
2222
// for future use, sub-classes SHOULD call this from their begin()
2323
startup_reason = BD_STARTUP_NORMAL;
24+
NRF_POWER->DCDCEN = 1;
25+
2426
pinMode(PIN_VBAT_READ, INPUT);
2527
pinMode(PIN_USER_BTN, INPUT_PULLUP);
2628

variants/rak_wismesh_tag/variant.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
#define LED_BLUE (36)
6767
#define LED_GREEN (35)
6868

69-
//#define PIN_STATUS_LED LED_BLUE
69+
#define PIN_STATUS_LED LED_BLUE
7070
#define LED_BUILTIN LED_GREEN
7171
#define LED_PIN LED_GREEN
7272
#define LED_STATE_ON HIGH

variants/xiao_nrf52/XiaoNrf52Board.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
2323
void XiaoNrf52Board::begin() {
2424
// for future use, sub-classes SHOULD call this from their begin()
2525
startup_reason = BD_STARTUP_NORMAL;
26+
NRF_POWER->DCDCEN = 1;
2627

2728
pinMode(PIN_VBAT, INPUT);
2829
pinMode(VBAT_ENABLE, OUTPUT);
2930
digitalWrite(VBAT_ENABLE, HIGH);
3031

32+
#ifdef PIN_USER_BTN
33+
pinMode(PIN_USER_BTN, INPUT);
34+
#endif
35+
3136
#if defined(PIN_WIRE_SDA) && defined(PIN_WIRE_SCL)
3237
Wire.setPins(PIN_WIRE_SDA, PIN_WIRE_SCL);
3338
#endif

variants/xiao_nrf52/XiaoNrf52Board.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ class XiaoNrf52Board : public mesh::MainBoard {
4646
NVIC_SystemReset();
4747
}
4848

49+
void powerOff() override {
50+
// set led on and wait for button release before poweroff
51+
digitalWrite(PIN_LED, LOW);
52+
#ifdef PIN_USER_BTN
53+
while(digitalRead(PIN_USER_BTN) == LOW);
54+
#endif
55+
digitalWrite(LED_GREEN, HIGH);
56+
digitalWrite(LED_BLUE, HIGH);
57+
digitalWrite(PIN_LED, HIGH);
58+
59+
#ifdef PIN_USER_BTN
60+
// configure button press to wake up when in powered off state
61+
nrf_gpio_cfg_sense_input(digitalPinToInterrupt(g_ADigitalPinMap[PIN_USER_BTN]), NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);
62+
#endif
63+
64+
sd_power_system_off();
65+
}
66+
4967
bool startOTAUpdate(const char* id, char reply[]) override;
5068
};
5169

0 commit comments

Comments
 (0)