Skip to content
3 changes: 2 additions & 1 deletion examples/companion_radio/ui-new/UITask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ void UITask::userLedHandler() {
led_state = 0;
next_led_change = cur_time + LED_CYCLE_MILLIS - last_led_increment;
}
digitalWrite(PIN_STATUS_LED, led_state);
digitalWrite(PIN_STATUS_LED, led_state == LED_STATE_ON);
}
#endif
}
Expand Down Expand Up @@ -650,6 +650,7 @@ void UITask::shutdown(bool restart){
_board->reboot();
} else {
_display->turnOff();
radio_driver.powerOff();
_board->powerOff();
}
}
Expand Down
8 changes: 5 additions & 3 deletions examples/companion_radio/ui-orig/UITask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void UITask::userLedHandler() {
state = 0;
next_change = cur_time + LED_CYCLE_MILLIS - last_increment;
}
digitalWrite(PIN_STATUS_LED, state);
digitalWrite(PIN_STATUS_LED, state == LED_STATE_ON);
}
#endif
}
Expand All @@ -292,10 +292,12 @@ void UITask::shutdown(bool restart){

#endif // PIN_BUZZER

if (restart)
if (restart) {
_board->reboot();
else
} else {
radio_driver.powerOff();
_board->powerOff();
}
}

void UITask::loop() {
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/radiolib/CustomSX1262Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ class CustomSX1262Wrapper : public RadioLibWrapper {
int sf = ((CustomSX1262 *)_radio)->spreadingFactor;
return packetScoreInt(snr, sf, packet_len);
}
virtual void powerOff() override {
((CustomSX1262 *)_radio)->sleep(false);
}
};
1 change: 1 addition & 0 deletions src/helpers/radiolib/RadioLibWrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class RadioLibWrapper : public mesh::Radio {
RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board) : _radio(&radio), _board(&board) { n_recv = n_sent = 0; }

void begin() override;
virtual void powerOff() { _radio->sleep(); }
int recvRaw(uint8_t* bytes, int sz) override;
uint32_t getEstAirtimeFor(int len_bytes) override;
bool startSendRaw(const uint8_t* bytes, int len) override;
Expand Down
1 change: 1 addition & 0 deletions variants/heltec_t114/T114Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
void T114Board::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF_POWER->DCDCEN = 1;

pinMode(PIN_VBAT_READ, INPUT);

Expand Down
7 changes: 7 additions & 0 deletions variants/heltec_t114/T114Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ class T114Board : public mesh::MainBoard {
}

void powerOff() override {
#ifdef LED_PIN
digitalWrite(LED_PIN, HIGH);
#endif
#if ENV_INCLUDE_GPS == 1
pinMode(GPS_EN, OUTPUT);
digitalWrite(GPS_EN, LOW);
#endif
sd_power_system_off();
}

Expand Down
2 changes: 2 additions & 0 deletions variants/rak_wismesh_tag/RAKWismeshTagBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
void RAKWismeshTagBoard::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF_POWER->DCDCEN = 1;

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

Expand Down
2 changes: 1 addition & 1 deletion variants/rak_wismesh_tag/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#define LED_BLUE (36)
#define LED_GREEN (35)

//#define PIN_STATUS_LED LED_BLUE
#define PIN_STATUS_LED LED_BLUE
#define LED_BUILTIN LED_GREEN
#define LED_PIN LED_GREEN
#define LED_STATE_ON HIGH
Expand Down
5 changes: 5 additions & 0 deletions variants/xiao_nrf52/XiaoNrf52Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
void XiaoNrf52Board::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
NRF_POWER->DCDCEN = 1;

pinMode(PIN_VBAT, INPUT);
pinMode(VBAT_ENABLE, OUTPUT);
digitalWrite(VBAT_ENABLE, HIGH);

#ifdef PIN_USER_BTN
pinMode(PIN_USER_BTN, INPUT);
#endif

#if defined(PIN_WIRE_SDA) && defined(PIN_WIRE_SCL)
Wire.setPins(PIN_WIRE_SDA, PIN_WIRE_SCL);
#endif
Expand Down
18 changes: 18 additions & 0 deletions variants/xiao_nrf52/XiaoNrf52Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ class XiaoNrf52Board : public mesh::MainBoard {
NVIC_SystemReset();
}

void powerOff() override {
// set led on and wait for button release before poweroff
digitalWrite(PIN_LED, LOW);
#ifdef PIN_USER_BTN
while(digitalRead(PIN_USER_BTN) == LOW);
#endif
digitalWrite(LED_GREEN, HIGH);
digitalWrite(LED_BLUE, HIGH);
digitalWrite(PIN_LED, HIGH);

#ifdef PIN_USER_BTN
// configure button press to wake up when in powered off state
nrf_gpio_cfg_sense_input(digitalPinToInterrupt(g_ADigitalPinMap[PIN_USER_BTN]), NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);
#endif

sd_power_system_off();
}

bool startOTAUpdate(const char* id, char reply[]) override;
};

Expand Down
7 changes: 7 additions & 0 deletions variants/xiao_nrf52/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ build_flags = ${nrf52_base.build_flags}
-D SX126X_RX_BOOSTED_GAIN=1
-D PIN_WIRE_SCL=D6
-D PIN_WIRE_SDA=D7
-D PIN_USER_BTN=PIN_BUTTON1
-D DISPLAY_CLASS=NullDisplayDriver
build_src_filter = ${nrf52_base.build_src_filter}
+<helpers/*.cpp>
+<helpers/sensors>
+<../variants/xiao_nrf52>
+<helpers/ui/NullDisplayDriver.cpp>
debug_tool = jlink
upload_protocol = nrfutil
lib_deps = ${nrf52_base.lib_deps}
Expand All @@ -41,6 +44,7 @@ board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
board_upload.maximum_size = 708608
build_flags =
${Xiao_nrf52.build_flags}
-I examples/companion_radio/ui-orig
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
-D BLE_PIN_CODE=123456
Expand All @@ -52,6 +56,7 @@ build_flags =
build_src_filter = ${Xiao_nrf52.build_src_filter}
+<helpers/nrf52/SerialBLEInterface.cpp>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-orig/*.cpp>
lib_deps =
${Xiao_nrf52.lib_deps}
densaugeo/base64 @ ~1.4.0
Expand All @@ -62,6 +67,7 @@ board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
board_upload.maximum_size = 708608
build_flags =
${Xiao_nrf52.build_flags}
-I examples/companion_radio/ui-orig
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
-D QSPIFLASH=1
Expand All @@ -70,6 +76,7 @@ build_flags =
build_src_filter = ${Xiao_nrf52.build_src_filter}
+<helpers/nrf52/SerialBLEInterface.cpp>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-orig/*.cpp>
lib_deps =
${Xiao_nrf52.lib_deps}
densaugeo/base64 @ ~1.4.0
Expand Down
4 changes: 4 additions & 0 deletions variants/xiao_nrf52/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "target.h"
#include <helpers/ArduinoHelpers.h>

#ifdef DISPLAY_CLASS
DISPLAY_CLASS display;
#endif

XiaoNrf52Board board;

RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
Expand Down
5 changes: 5 additions & 0 deletions variants/xiao_nrf52/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include <helpers/ArduinoHelpers.h>
#include <helpers/sensors/EnvironmentSensorManager.h>

#ifdef DISPLAY_CLASS
#include <helpers/ui/NullDisplayDriver.h>
extern DISPLAY_CLASS display;
#endif

extern XiaoNrf52Board board;
extern WRAPPER_CLASS radio_driver;
extern AutoDiscoverRTCClock rtc_clock;
Expand Down
5 changes: 3 additions & 2 deletions variants/xiao_nrf52/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ extern "C"
#define LED_RED (11)
#define LED_GREEN (13)
#define LED_BLUE (12)
#define PIN_STATUS_LED (LED_BLUE)

#define LED_STATE_ON (1) // State when LED is litted
#define LED_STATE_ON (0) // State when LED is on

// Buttons
#define PIN_BUTTON1 (PINS_COUNT)
#define PIN_BUTTON1 (0)

// Digital PINs
static const uint8_t D0 = 0 ;
Expand Down