Skip to content

Commit a623e53

Browse files
committed
add wehooper4 SolarXiao builds
remap I2C to prevent boot lock up (cherry picked from commit 2253a38) fix broken bridge solarxiao bridge build (cherry picked from commit 27e5aac) add wehooper4 SolarXiao builds
1 parent e6e87fb commit a623e53

7 files changed

Lines changed: 625 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifdef SOLARXIAO
2+
3+
#include <Arduino.h>
4+
#include <Wire.h>
5+
6+
#include "SolarXiaoBoard.h"
7+
8+
#ifdef NRF52_POWER_MANAGEMENT
9+
// Static configuration for power management
10+
// Values set in variant.h defines
11+
const PowerMgtConfig power_config = {
12+
.lpcomp_ain_channel = PWRMGT_LPCOMP_AIN,
13+
.lpcomp_refsel = PWRMGT_LPCOMP_REFSEL,
14+
.voltage_bootlock = PWRMGT_VOLTAGE_BOOTLOCK
15+
};
16+
17+
void SolarXiaoBoard::initiateShutdown(uint8_t reason) {
18+
bool enable_lpcomp = (reason == SHUTDOWN_REASON_LOW_VOLTAGE ||
19+
reason == SHUTDOWN_REASON_BOOT_PROTECT);
20+
21+
pinMode(VBAT_ENABLE, OUTPUT);
22+
digitalWrite(VBAT_ENABLE, enable_lpcomp ? LOW : HIGH);
23+
24+
if (enable_lpcomp) {
25+
configureVoltageWake(power_config.lpcomp_ain_channel, power_config.lpcomp_refsel);
26+
}
27+
28+
enterSystemOff(reason);
29+
}
30+
#endif // NRF52_POWER_MANAGEMENT
31+
32+
void SolarXiaoBoard::begin() {
33+
NRF52BoardDCDC::begin();
34+
35+
// Configure battery voltage ADC
36+
pinMode(PIN_VBAT, INPUT);
37+
pinMode(VBAT_ENABLE, OUTPUT);
38+
digitalWrite(VBAT_ENABLE, LOW); // Enable VBAT divider for reading
39+
analogReadResolution(12);
40+
analogReference(AR_INTERNAL_3_0);
41+
delay(50); // Allow ADC to settle
42+
43+
#ifdef PIN_USER_BTN
44+
pinMode(PIN_USER_BTN, INPUT_PULLUP);
45+
#endif
46+
47+
#if defined(PIN_WIRE_SDA) && defined(PIN_WIRE_SCL)
48+
Wire.setPins(PIN_WIRE_SDA, PIN_WIRE_SCL);
49+
#endif
50+
51+
Wire.begin();
52+
53+
#ifdef P_LORA_TX_LED
54+
pinMode(P_LORA_TX_LED, OUTPUT);
55+
digitalWrite(P_LORA_TX_LED, HIGH);
56+
#endif
57+
58+
#ifdef NRF52_POWER_MANAGEMENT
59+
// Boot voltage protection check (may not return if voltage too low)
60+
checkBootVoltage(&power_config);
61+
#endif
62+
63+
delay(10); // Give sx1262 some time to power up
64+
}
65+
66+
uint16_t SolarXiaoBoard::getBattMilliVolts() {
67+
// https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
68+
// VBAT_ENABLE must be LOW to read battery voltage
69+
digitalWrite(VBAT_ENABLE, LOW);
70+
int adcvalue = analogRead(PIN_VBAT);
71+
return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096;
72+
}
73+
74+
#endif
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#pragma once
2+
3+
#include <MeshCore.h>
4+
#include <Arduino.h>
5+
#include <helpers/NRF52Board.h>
6+
7+
#ifdef SOLARXIAO
8+
9+
class SolarXiaoBoard : public NRF52BoardDCDC {
10+
protected:
11+
#if NRF52_POWER_MANAGEMENT
12+
void initiateShutdown(uint8_t reason) override;
13+
#endif
14+
15+
public:
16+
SolarXiaoBoard() : NRF52Board("XIAO_NRF52_OTA") {}
17+
void begin();
18+
19+
#if defined(P_LORA_TX_LED)
20+
void onBeforeTransmit() override {
21+
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED on
22+
}
23+
void onAfterTransmit() override {
24+
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED off
25+
}
26+
#endif
27+
28+
uint16_t getBattMilliVolts() override;
29+
30+
const char* getManufacturerName() const override {
31+
return "Seeed Xiao-nrf52";
32+
}
33+
34+
void powerOff() override {
35+
// set led on and wait for button release before poweroff
36+
digitalWrite(PIN_LED, LOW);
37+
#ifdef PIN_USER_BTN
38+
while(digitalRead(PIN_USER_BTN) == LOW);
39+
#endif
40+
digitalWrite(LED_GREEN, HIGH);
41+
digitalWrite(LED_BLUE, HIGH);
42+
digitalWrite(PIN_LED, HIGH);
43+
44+
#ifdef PIN_USER_BTN
45+
// configure button press to wake up when in powered off state
46+
nrf_gpio_cfg_sense_input(digitalPinToInterrupt(g_ADigitalPinMap[PIN_USER_BTN]), NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);
47+
#endif
48+
49+
sd_power_system_off();
50+
}
51+
};
52+
53+
#endif

variants/solarxiao/platformio.ini

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
[solarxiao]
2+
extends = nrf52_base
3+
board = seeed-xiao-afruitnrf52-nrf52840
4+
board_build.ldscript = boards/nrf52840_s140_v7.ld
5+
build_flags = ${nrf52_base.build_flags}
6+
${sensor_base.build_flags}
7+
-I lib/nrf52/s140_nrf52_7.3.0_API/include
8+
-I lib/nrf52/s140_nrf52_7.3.0_API/include/nrf52
9+
-I variants/solarxiao
10+
-D NRF52_PLATFORM
11+
-D NRF52_POWER_MANAGEMENT
12+
-D SOLARXIAO
13+
-D RADIO_CLASS=CustomSX1262
14+
-D WRAPPER_CLASS=CustomSX1262Wrapper
15+
-D LORA_TX_POWER=22
16+
-D P_LORA_TX_LED=11
17+
-D P_LORA_DIO_1=D1
18+
-D P_LORA_RESET=D2
19+
-D P_LORA_BUSY=D3
20+
-D P_LORA_NSS=D4
21+
-D SX126X_RXEN=D5
22+
-D SX126X_TXEN=RADIOLIB_NC
23+
-D SX126X_DIO2_AS_RF_SWITCH=1
24+
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
25+
-D SX126X_CURRENT_LIMIT=140
26+
-D SX126X_RX_BOOSTED_GAIN=1
27+
-D PIN_WIRE_SCL=PIN_NFC1
28+
-D PIN_WIRE_SDA=PIN_NFC2
29+
-D PIN_USER_BTN=PIN_BUTTON1
30+
-D QSPIFLASH=1
31+
-D DISPLAY_CLASS=NullDisplayDriver
32+
build_src_filter = ${nrf52_base.build_src_filter}
33+
+<helpers/*.cpp>
34+
+<helpers/sensors>
35+
+<../variants/solarxiao>
36+
+<helpers/ui/NullDisplayDriver.cpp>
37+
debug_tool = jlink
38+
upload_protocol = nrfutil
39+
lib_deps = ${nrf52_base.lib_deps}
40+
${sensor_base.lib_deps}
41+
42+
[env:solarxiao_30S_companion_radio_ble]
43+
extends = solarxiao
44+
board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
45+
board_upload.maximum_size = 708608
46+
build_flags =
47+
${solarxiao.build_flags}
48+
-I examples/companion_radio/ui-orig
49+
-D MAX_CONTACTS=350
50+
-D MAX_GROUP_CHANNELS=40
51+
-D BLE_PIN_CODE=123456
52+
-D OFFLINE_QUEUE_SIZE=256
53+
; -D BLE_DEBUG_LOGGING=1
54+
; -D MESH_PACKET_LOGGING=1
55+
; -D MESH_DEBUG=1
56+
build_src_filter = ${solarxiao.build_src_filter}
57+
+<helpers/nrf52/SerialBLEInterface.cpp>
58+
+<../examples/companion_radio/*.cpp>
59+
+<../examples/companion_radio/ui-orig/*.cpp>
60+
lib_deps =
61+
${solarxiao.lib_deps}
62+
densaugeo/base64 @ ~1.4.0
63+
64+
[env:solarxiao_33S_companion_radio_ble]
65+
extends = env:solarxiao_30S_companion_radio_ble
66+
build_flags =
67+
${env:solarxiao_30S_companion_radio_ble.build_flags}
68+
-D LORA_TX_POWER=9
69+
70+
[env:solarxiao_30S_companion_radio_usb]
71+
extends = solarxiao
72+
board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
73+
board_upload.maximum_size = 708608
74+
build_flags =
75+
${solarxiao.build_flags}
76+
-I examples/companion_radio/ui-orig
77+
-D MAX_CONTACTS=350
78+
-D MAX_GROUP_CHANNELS=40
79+
; -D MESH_PACKET_LOGGING=1
80+
; -D MESH_DEBUG=1
81+
build_src_filter = ${solarxiao.build_src_filter}
82+
+<helpers/nrf52/SerialBLEInterface.cpp>
83+
+<../examples/companion_radio/*.cpp>
84+
+<../examples/companion_radio/ui-orig/*.cpp>
85+
lib_deps =
86+
${solarxiao.lib_deps}
87+
densaugeo/base64 @ ~1.4.0
88+
89+
[env:solarxiao_33S_companion_radio_usb]
90+
extends = env:solarxiao_30S_companion_radio_usb
91+
build_flags =
92+
${env:solarxiao_30S_companion_radio_usb.build_flags}
93+
-D LORA_TX_POWER=9
94+
95+
96+
[env:solarxiao_30S_repeater]
97+
extends = solarxiao
98+
build_flags =
99+
${solarxiao.build_flags}
100+
-D ADVERT_NAME='"SolarXiao 30S Repeater"'
101+
-D ADVERT_LAT=0.0
102+
-D ADVERT_LON=0.0
103+
-D ADMIN_PASSWORD='"password"'
104+
-D MAX_NEIGHBOURS=50
105+
; -D MESH_PACKET_LOGGING=1
106+
; -D MESH_DEBUG=1
107+
build_src_filter = ${solarxiao.build_src_filter}
108+
+<../examples/simple_repeater/*.cpp>
109+
110+
[env:solarxiao_33S_repeater]
111+
extends = env:solarxiao_30S_repeater
112+
build_flags =
113+
${env:solarxiao_30S_repeater.build_flags}
114+
-D LORA_TX_POWER=9
115+
-D ADVERT_NAME='"SolarXiao 33S Repeater"'
116+
117+
118+
[env:solarxiao_30S_repeater_bridge_rs232]
119+
extends = env:solarxiao_30S_repeater
120+
build_flags =
121+
${env:solarxiao_30S_repeater.build_flags}
122+
-D ADVERT_NAME='"SolarXiao 30S RS232"'
123+
-UENV_INCLUDE_GPS
124+
-D WITH_RS232_BRIDGE=Serial1
125+
-D WITH_RS232_BRIDGE_RX=PIN_SERIAL1_RX
126+
-D WITH_RS232_BRIDGE_TX=PIN_SERIAL1_TX
127+
-D BRIDGE_MAX_BAUD=500000
128+
build_src_filter =
129+
${env:solarxiao_30S_repeater.build_src_filter}
130+
+<helpers/bridges/RS232Bridge.cpp>
131+
132+
[env:solarxiao_33S_repeater_bridge_rs232]
133+
extends = env:solarxiao_30S_repeater_bridge_rs232
134+
build_flags =
135+
${env:solarxiao_30S_repeater_bridge_rs232.build_flags}
136+
-D LORA_TX_POWER=9
137+
-D ADVERT_NAME='"SolarXiao 33S RS232"'
138+
139+
[env:solarxiao_30S_room_server]
140+
extends = solarxiao
141+
build_flags =
142+
${solarxiao.build_flags}
143+
-D ADVERT_NAME='"SolarXiao 30S Room"'
144+
-D ADVERT_LAT=0.0
145+
-D ADVERT_LON=0.0
146+
-D ADMIN_PASSWORD='"password"'
147+
; -D MESH_PACKET_LOGGING=1
148+
; -D MESH_DEBUG=1
149+
build_src_filter = ${solarxiao.build_src_filter}
150+
+<../examples/simple_room_server/*.cpp>
151+
152+
[env:solarxiao_33S_room_server]
153+
extends = env:solarxiao_30S_room_server
154+
build_flags =
155+
${env:solarxiao_30S_room_server.build_flags}
156+
-D LORA_TX_POWER=9
157+
-D ADVERT_NAME='"SolarXiao 33S Room"'
158+
159+
[env:solarxiao_30S_kiss_modem]
160+
extends = solarxiao
161+
build_flags =
162+
${solarxiao.build_flags}
163+
build_src_filter = ${solarxiao.build_src_filter}
164+
+<../examples/kiss_modem/*.cpp>
165+
lib_deps =
166+
${solarxiao.lib_deps}
167+
168+
[env:solarxiao_33S_kiss_modem]
169+
extends = solarxiao_30S_kiss_modem
170+
build_flags =
171+
${env:solarxiao_30S_kiss_modem.build_flags}
172+
-D LORA_TX_POWER=9

variants/solarxiao/target.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <Arduino.h>
2+
#include "target.h"
3+
#include <helpers/ArduinoHelpers.h>
4+
5+
#ifdef DISPLAY_CLASS
6+
DISPLAY_CLASS display;
7+
#endif
8+
9+
SolarXiaoBoard board;
10+
11+
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
12+
13+
WRAPPER_CLASS radio_driver(radio, board);
14+
15+
VolatileRTCClock fallback_clock;
16+
AutoDiscoverRTCClock rtc_clock(fallback_clock);
17+
18+
#if ENV_INCLUDE_GPS
19+
#include <helpers/sensors/MicroNMEALocationProvider.h>
20+
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
21+
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
22+
#else
23+
EnvironmentSensorManager sensors;
24+
#endif
25+
26+
bool radio_init() {
27+
rtc_clock.begin(Wire);
28+
29+
return radio.std_init(&SPI);
30+
}
31+
32+
uint32_t radio_get_rng_seed() {
33+
return radio.random(0x7FFFFFFF);
34+
}
35+
36+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
37+
radio.setFrequency(freq);
38+
radio.setSpreadingFactor(sf);
39+
radio.setBandwidth(bw);
40+
radio.setCodingRate(cr);
41+
}
42+
43+
void radio_set_tx_power(int8_t dbm) {
44+
radio.setOutputPower(dbm);
45+
}
46+
47+
mesh::LocalIdentity radio_new_identity() {
48+
RadioNoiseListener rng(radio);
49+
return mesh::LocalIdentity(&rng); // create new random identity
50+
}

variants/solarxiao/target.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#define RADIOLIB_STATIC_ONLY 1
4+
#include <RadioLib.h>
5+
#include <helpers/radiolib/RadioLibWrappers.h>
6+
#include <SolarXiaoBoard.h>
7+
#include <helpers/radiolib/CustomSX1262Wrapper.h>
8+
#include <helpers/AutoDiscoverRTCClock.h>
9+
#include <helpers/ArduinoHelpers.h>
10+
#include <helpers/sensors/EnvironmentSensorManager.h>
11+
12+
#ifdef DISPLAY_CLASS
13+
#include <helpers/ui/NullDisplayDriver.h>
14+
extern DISPLAY_CLASS display;
15+
#endif
16+
17+
extern SolarXiaoBoard board;
18+
extern WRAPPER_CLASS radio_driver;
19+
extern AutoDiscoverRTCClock rtc_clock;
20+
extern EnvironmentSensorManager sensors;
21+
22+
bool radio_init();
23+
uint32_t radio_get_rng_seed();
24+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
25+
void radio_set_tx_power(int8_t dbm);
26+
mesh::LocalIdentity radio_new_identity();

0 commit comments

Comments
 (0)