Skip to content

Commit a288ac0

Browse files
author
Scott Powell
committed
Merge branch 'dev' into reciprocal-path-retry
2 parents fa3e4f9 + 88786a9 commit a288ac0

File tree

7 files changed

+99
-147
lines changed

7 files changed

+99
-147
lines changed

src/helpers/BaseChatMesh.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
158158
data[len] = 0; // need to make a C string again, with null terminator
159159

160160
if (flags == TXT_TYPE_PLAIN) {
161+
from.lastmod = getRTCClock()->getCurrentTime(); // update last heard time
161162
onMessageRecv(from, packet, timestamp, (const char *) &data[5]); // let UI know
162163

163164
uint32_t ack_hash; // calc truncated hash of the message timestamp + text + sender pub_key, to prove to sender that we got it
@@ -184,6 +185,7 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
184185
if (timestamp > from.sync_since) { // make sure 'sync_since' is up-to-date
185186
from.sync_since = timestamp;
186187
}
188+
from.lastmod = getRTCClock()->getCurrentTime(); // update last heard time
187189
onSignedMessageRecv(from, packet, timestamp, &data[5], (const char *) &data[9]); // let UI know
188190

189191
uint32_t ack_hash; // calc truncated hash of the message timestamp + text + OUR pub_key, to prove to sender that we got it

variants/xiao_nrf52/XiaoNrf52Board.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
#ifdef XIAO_NRF52
22

33
#include <Arduino.h>
4-
#include "XiaoNrf52Board.h"
5-
6-
#include <bluefruit.h>
74
#include <Wire.h>
5+
#include <bluefruit.h>
6+
7+
#include "XiaoNrf52Board.h"
88

99
static BLEDfu bledfu;
1010

11-
static void connect_callback(uint16_t conn_handle)
12-
{
11+
static void connect_callback(uint16_t conn_handle) {
1312
(void)conn_handle;
1413
MESH_DEBUG_PRINTLN("BLE client connected");
1514
}
1615

17-
static void disconnect_callback(uint16_t conn_handle, uint8_t reason)
18-
{
16+
static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
1917
(void)conn_handle;
2018
(void)reason;
2119

@@ -41,12 +39,12 @@ void XiaoNrf52Board::begin() {
4139
digitalWrite(P_LORA_TX_LED, HIGH);
4240
#endif
4341

44-
// pinMode(SX126X_POWER_EN, OUTPUT);
45-
// digitalWrite(SX126X_POWER_EN, HIGH);
46-
delay(10); // give sx1262 some time to power up
42+
// pinMode(SX126X_POWER_EN, OUTPUT);
43+
// digitalWrite(SX126X_POWER_EN, HIGH);
44+
delay(10); // give sx1262 some time to power up
4745
}
4846

49-
bool XiaoNrf52Board::startOTAUpdate(const char* id, char reply[]) {
47+
bool XiaoNrf52Board::startOTAUpdate(const char *id, char reply[]) {
5048
// Config the peripheral connection with maximum bandwidth
5149
// more SRAM required by SoftDevice
5250
// Note: All config***() function must be called before begin()
@@ -86,10 +84,8 @@ bool XiaoNrf52Board::startOTAUpdate(const char* id, char reply[]) {
8684
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
8785

8886
strcpy(reply, "OK - started");
89-
return true;
9087

91-
92-
return false;
88+
return true;
9389
}
9490

9591
#endif

variants/xiao_nrf52/XiaoNrf52Board.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@
55

66
#ifdef XIAO_NRF52
77

8-
// redefine lora pins if using the S3 variant of SX1262 board
9-
#ifdef SX1262_XIAO_S3_VARIANT
10-
#undef P_LORA_DIO_1
11-
#undef P_LORA_BUSY
12-
#undef P_LORA_RESET
13-
#undef P_LORA_NSS
14-
#undef SX126X_RXEN
15-
#define P_LORA_DIO_1 D0
16-
#define P_LORA_BUSY D1
17-
#define P_LORA_RESET D2
18-
#define P_LORA_NSS D3
19-
#define SX126X_RXEN D4
20-
#endif
21-
228
class XiaoNrf52Board : public mesh::MainBoard {
239
protected:
2410
uint8_t startup_reason;
@@ -40,13 +26,13 @@ class XiaoNrf52Board : public mesh::MainBoard {
4026
// Please read befor going further ;)
4127
// https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
4228

43-
// We can't drive VBAT_ENABLE to HIGH as long
29+
// We can't drive VBAT_ENABLE to HIGH as long
4430
// as we don't know wether we are charging or not ...
4531
// this is a 3mA loss (4/1500)
4632
digitalWrite(VBAT_ENABLE, LOW);
4733
int adcvalue = 0;
4834
analogReadResolution(12);
49-
analogReference(AR_INTERNAL_3_0);
35+
analogReference(AR_INTERNAL_3_0);
5036
delay(10);
5137
adcvalue = analogRead(PIN_VBAT);
5238
return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096;

variants/xiao_nrf52/platformio.ini

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,19 @@
1-
[nrf52840_xiao]
1+
[Xiao_nrf52]
22
extends = nrf52_base
3-
platform_packages =
4-
toolchain-gccarmnoneeabi@~1.100301.0
5-
framework-arduinoadafruitnrf52
63
board = seeed-xiao-afruitnrf52-nrf52840
74
board_build.ldscript = boards/nrf52840_s140_v7.ld
85
build_flags = ${nrf52_base.build_flags}
9-
-D NRF52_PLATFORM -D XIAO_NRF52
6+
${sensor_base.build_flags}
107
-I lib/nrf52/s140_nrf52_7.3.0_API/include
118
-I lib/nrf52/s140_nrf52_7.3.0_API/include/nrf52
12-
lib_ignore =
13-
BluetoothOTA
14-
lvgl
15-
lib5b4
16-
lib_deps =
17-
${nrf52_base.lib_deps}
18-
rweather/Crypto @ ^0.4.0
19-
adafruit/Adafruit INA3221 Library @ ^1.0.1
20-
adafruit/Adafruit INA219 @ ^1.2.3
21-
adafruit/Adafruit AHTX0 @ ^2.0.5
22-
adafruit/Adafruit BME280 Library @ ^2.3.0
23-
24-
25-
[Xiao_nrf52]
26-
extends = nrf52840_xiao
27-
;board_build.ldscript = boards/nrf52840_s140_v7.ld
28-
build_flags = ${nrf52840_xiao.build_flags}
29-
-D P_LORA_TX_LED=11
309
-I variants/xiao_nrf52
31-
-I src/helpers/nrf52
10+
-UENV_INCLUDE_GPS
11+
-D NRF52_PLATFORM
12+
-D XIAO_NRF52
3213
-D RADIO_CLASS=CustomSX1262
3314
-D WRAPPER_CLASS=CustomSX1262Wrapper
3415
-D LORA_TX_POWER=22
16+
-D P_LORA_TX_LED=11
3517
-D P_LORA_DIO_1=D1
3618
-D P_LORA_RESET=D2
3719
-D P_LORA_BUSY=D3
@@ -42,18 +24,16 @@ build_flags = ${nrf52840_xiao.build_flags}
4224
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
4325
-D SX126X_CURRENT_LIMIT=140
4426
-D SX126X_RX_BOOSTED_GAIN=1
45-
-D PIN_WIRE_SCL=6
46-
-D PIN_WIRE_SDA=7
47-
-D ENV_INCLUDE_AHTX0=1
48-
-D ENV_INCLUDE_BME280=1
49-
-D ENV_INCLUDE_INA3221=1
50-
-D ENV_INCLUDE_INA219=1
51-
build_src_filter = ${nrf52840_xiao.build_src_filter}
27+
-D PIN_WIRE_SCL=D6
28+
-D PIN_WIRE_SDA=D7
29+
build_src_filter = ${nrf52_base.build_src_filter}
5230
+<helpers/*.cpp>
5331
+<helpers/sensors>
5432
+<../variants/xiao_nrf52>
5533
debug_tool = jlink
5634
upload_protocol = nrfutil
35+
lib_deps = ${nrf52_base.lib_deps}
36+
${sensor_base.lib_deps}
5737

5838
[env:Xiao_nrf52_companion_radio_ble]
5939
extends = Xiao_nrf52
@@ -94,12 +74,6 @@ lib_deps =
9474
${Xiao_nrf52.lib_deps}
9575
densaugeo/base64 @ ~1.4.0
9676

97-
[env:Xiao_nrf52_alt_pinout_companion_radio_ble]
98-
extends = env:Xiao_nrf52_companion_radio_ble
99-
build_flags =
100-
${env:Xiao_nrf52_companion_radio_ble.build_flags}
101-
-D SX1262_XIAO_S3_VARIANT
102-
10377
[env:Xiao_nrf52_repeater]
10478
extends = Xiao_nrf52
10579
build_flags =
@@ -114,12 +88,6 @@ build_flags =
11488
build_src_filter = ${Xiao_nrf52.build_src_filter}
11589
+<../examples/simple_repeater/*.cpp>
11690

117-
[env:Xiao_nrf52_alt_pinout_repeater]
118-
extends = env:Xiao_nrf52_repeater
119-
build_flags =
120-
${env:Xiao_nrf52_repeater.build_flags}
121-
-D SX1262_XIAO_S3_VARIANT
122-
12391
[env:Xiao_nrf52_room_server]
12492
extends = Xiao_nrf52
12593
build_flags =

variants/xiao_nrf52/target.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ WRAPPER_CLASS radio_driver(radio, board);
1010

1111
VolatileRTCClock fallback_clock;
1212
AutoDiscoverRTCClock rtc_clock(fallback_clock);
13+
1314
EnvironmentSensorManager sensors;
1415

1516
bool radio_init() {
16-
rtc_clock.begin(Wire);
17-
18-
return radio.std_init(&SPI);
17+
rtc_clock.begin(Wire);
18+
19+
return radio.std_init(&SPI);
1920
}
2021

2122
uint32_t radio_get_rng_seed() {
@@ -35,5 +36,5 @@ void radio_set_tx_power(uint8_t dbm) {
3536

3637
mesh::LocalIdentity radio_new_identity() {
3738
RadioNoiseListener rng(radio);
38-
return mesh::LocalIdentity(&rng); // create new random identity
39+
return mesh::LocalIdentity(&rng); // create new random identity
3940
}

variants/xiao_nrf52/variant.cpp

Lines changed: 67 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,85 @@
11
#include "variant.h"
2+
3+
#include "nrf.h"
24
#include "wiring_constants.h"
35
#include "wiring_digital.h"
4-
#include "nrf.h"
56

6-
const uint32_t g_ADigitalPinMap[] =
7-
{
8-
// D0 .. D10
9-
2, // D0 is P0.02 (A0)
10-
3, // D1 is P0.03 (A1)
11-
28, // D2 is P0.28 (A2)
12-
29, // D3 is P0.29 (A3)
13-
4, // D4 is P0.04 (A4,SDA)
14-
5, // D5 is P0.05 (A5,SCL)
15-
43, // D6 is P1.11 (TX)
16-
44, // D7 is P1.12 (RX)
17-
45, // D8 is P1.13 (SCK)
18-
46, // D9 is P1.14 (MISO)
19-
47, // D10 is P1.15 (MOSI)
7+
const uint32_t g_ADigitalPinMap[] = {
8+
// D0 .. D10
9+
2, // D0 is P0.02 (A0)
10+
3, // D1 is P0.03 (A1)
11+
28, // D2 is P0.28 (A2)
12+
29, // D3 is P0.29 (A3)
13+
4, // D4 is P0.04 (A4,SDA)
14+
5, // D5 is P0.05 (A5,SCL)
15+
43, // D6 is P1.11 (TX)
16+
44, // D7 is P1.12 (RX)
17+
45, // D8 is P1.13 (SCK)
18+
46, // D9 is P1.14 (MISO)
19+
47, // D10 is P1.15 (MOSI)
2020

21-
// LEDs
22-
26, // D11 is P0.26 (LED RED)
23-
6, // D12 is P0.06 (LED BLUE)
24-
30, // D13 is P0.30 (LED GREEN)
25-
14, // D14 is P0.14 (READ_BAT)
21+
// LEDs
22+
26, // D11 is P0.26 (LED RED)
23+
6, // D12 is P0.06 (LED BLUE)
24+
30, // D13 is P0.30 (LED GREEN)
25+
14, // D14 is P0.14 (READ_BAT)
2626

27-
// LSM6DS3TR
28-
40, // D15 is P1.08 (6D_PWR)
29-
27, // D16 is P0.27 (6D_I2C_SCL)
30-
7, // D17 is P0.07 (6D_I2C_SDA)
31-
11, // D18 is P0.11 (6D_INT1)
27+
// LSM6DS3TR
28+
40, // D15 is P1.08 (6D_PWR)
29+
27, // D16 is P0.27 (6D_I2C_SCL)
30+
7, // D17 is P0.07 (6D_I2C_SDA)
31+
11, // D18 is P0.11 (6D_INT1)
3232

33-
// MIC
34-
42, // D19 is P1.10 (MIC_PWR)
35-
32, // D20 is P1.00 (PDM_CLK)
36-
16, // D21 is P0.16 (PDM_DATA)
33+
// MIC
34+
42, // D19 is P1.10 (MIC_PWR)
35+
32, // D20 is P1.00 (PDM_CLK)
36+
16, // D21 is P0.16 (PDM_DATA)
3737

38-
// BQ25100
39-
13, // D22 is P0.13 (HICHG)
40-
17, // D23 is P0.17 (~CHG)
38+
// BQ25100
39+
13, // D22 is P0.13 (HICHG)
40+
17, // D23 is P0.17 (~CHG)
4141

42-
//
43-
21, // D24 is P0.21 (QSPI_SCK)
44-
25, // D25 is P0.25 (QSPI_CSN)
45-
20, // D26 is P0.20 (QSPI_SIO_0 DI)
46-
24, // D27 is P0.24 (QSPI_SIO_1 DO)
47-
22, // D28 is P0.22 (QSPI_SIO_2 WP)
48-
23, // D29 is P0.23 (QSPI_SIO_3 HOLD)
42+
//
43+
21, // D24 is P0.21 (QSPI_SCK)
44+
25, // D25 is P0.25 (QSPI_CSN)
45+
20, // D26 is P0.20 (QSPI_SIO_0 DI)
46+
24, // D27 is P0.24 (QSPI_SIO_1 DO)
47+
22, // D28 is P0.22 (QSPI_SIO_2 WP)
48+
23, // D29 is P0.23 (QSPI_SIO_3 HOLD)
4949

50-
// NFC
51-
9, // D30 is P0.09 (NFC1)
52-
10, // D31 is P0.10 (NFC2)
50+
// NFC
51+
9, // D30 is P0.09 (NFC1)
52+
10, // D31 is P0.10 (NFC2)
5353

54-
// VBAT
55-
31, // D32 is P0.31 (VBAT)
54+
// VBAT
55+
31, // D32 is P0.31 (VBAT)
5656
};
5757

58-
void initVariant()
59-
{
60-
// Disable reading of the BAT voltage.
61-
// https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
62-
pinMode(VBAT_ENABLE, OUTPUT);
63-
//digitalWrite(VBAT_ENABLE, HIGH);
64-
// This was taken from Seeed github butis not coherent with the doc,
65-
// VBAT_ENABLE should be kept to LOW to protect P0.14, (1500/500)*(4.2-3.3)+3.3 = 3.9V > 3.6V
66-
// This induces a 3mA current in the resistors :( but it's better than burning the nrf
67-
digitalWrite(VBAT_ENABLE, LOW);
58+
void initVariant() {
59+
// Disable reading of the BAT voltage.
60+
// https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
61+
pinMode(VBAT_ENABLE, OUTPUT);
62+
// digitalWrite(VBAT_ENABLE, HIGH);
63+
// This was taken from Seeed github butis not coherent with the doc,
64+
// VBAT_ENABLE should be kept to LOW to protect P0.14, (1500/500)*(4.2-3.3)+3.3 = 3.9V > 3.6V
65+
// This induces a 3mA current in the resistors :( but it's better than burning the nrf
66+
digitalWrite(VBAT_ENABLE, LOW);
6867

69-
// Low charging current (50mA)
70-
// https://wiki.seeedstudio.com/XIAO_BLE#battery-charging-current
71-
//pinMode(PIN_CHARGING_CURRENT, INPUT);
68+
// Low charging current (50mA)
69+
// https://wiki.seeedstudio.com/XIAO_BLE#battery-charging-current
70+
// pinMode(PIN_CHARGING_CURRENT, INPUT);
7271

73-
// High charging current (100mA)
74-
pinMode(PIN_CHARGING_CURRENT, OUTPUT);
75-
digitalWrite(PIN_CHARGING_CURRENT, LOW);
72+
// High charging current (100mA)
73+
pinMode(PIN_CHARGING_CURRENT, OUTPUT);
74+
digitalWrite(PIN_CHARGING_CURRENT, LOW);
7675

77-
pinMode(PIN_QSPI_CS, OUTPUT);
78-
digitalWrite(PIN_QSPI_CS, HIGH);
76+
pinMode(PIN_QSPI_CS, OUTPUT);
77+
digitalWrite(PIN_QSPI_CS, HIGH);
7978

80-
pinMode(LED_RED, OUTPUT);
81-
digitalWrite(LED_RED, HIGH);
82-
pinMode(LED_GREEN, OUTPUT);
83-
digitalWrite(LED_GREEN, HIGH);
84-
pinMode(LED_BLUE, OUTPUT);
85-
digitalWrite(LED_BLUE, HIGH);
79+
pinMode(LED_RED, OUTPUT);
80+
digitalWrite(LED_RED, HIGH);
81+
pinMode(LED_GREEN, OUTPUT);
82+
digitalWrite(LED_GREEN, HIGH);
83+
pinMode(LED_BLUE, OUTPUT);
84+
digitalWrite(LED_BLUE, HIGH);
8685
}

variants/xiao_nrf52/variant.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ static const uint8_t A5 = PIN_A5;
113113
// #define PIN_WIRE_SDA (17) // 4 and 5 are used for the sx1262 !
114114
// #define PIN_WIRE_SCL (16) // use WIRE1_SDA
115115

116-
static const uint8_t SDA = PIN_WIRE_SDA;
117-
static const uint8_t SCL = PIN_WIRE_SCL;
116+
// static const uint8_t SDA = PIN_WIRE_SDA;
117+
// static const uint8_t SCL = PIN_WIRE_SCL;
118118

119119
//#define PIN_WIRE1_SDA (17)
120120
//#define PIN_WIRE1_SCL (16)

0 commit comments

Comments
 (0)