Skip to content

Commit 228b073

Browse files
authored
Merge pull request #982 from ViezeVingertjes/feat/wio-wm1110-variant
Add Seeed Wio WM1110 Dev Board variant
2 parents 7ad45d1 + 5088444 commit 228b073

File tree

7 files changed

+569
-0
lines changed

7 files changed

+569
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#ifdef WIO_WM1110
2+
3+
#include <Arduino.h>
4+
#include <Wire.h>
5+
#include <bluefruit.h>
6+
7+
#include "WioWM1110Board.h"
8+
9+
static BLEDfu bledfu;
10+
11+
static void connect_callback(uint16_t conn_handle) {
12+
(void)conn_handle;
13+
MESH_DEBUG_PRINTLN("BLE client connected");
14+
}
15+
16+
static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
17+
(void)conn_handle;
18+
(void)reason;
19+
20+
MESH_DEBUG_PRINTLN("BLE client disconnected");
21+
}
22+
23+
void WioWM1110Board::begin() {
24+
startup_reason = BD_STARTUP_NORMAL;
25+
26+
sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
27+
NRF_POWER->DCDCEN = 1;
28+
29+
pinMode(BATTERY_PIN, INPUT);
30+
pinMode(LED_GREEN, OUTPUT);
31+
pinMode(LED_RED, OUTPUT);
32+
pinMode(SENSOR_POWER_PIN, OUTPUT);
33+
34+
digitalWrite(LED_GREEN, HIGH);
35+
digitalWrite(LED_RED, LOW);
36+
digitalWrite(SENSOR_POWER_PIN, LOW);
37+
38+
Serial1.begin(115200);
39+
40+
#if defined(PIN_WIRE_SDA) && defined(PIN_WIRE_SCL)
41+
Wire.setPins(PIN_WIRE_SDA, PIN_WIRE_SCL);
42+
#endif
43+
44+
Wire.begin();
45+
46+
delay(10);
47+
}
48+
49+
bool WioWM1110Board::startOTAUpdate(const char *id, char reply[]) {
50+
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
51+
Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16);
52+
53+
Bluefruit.begin(1, 0);
54+
Bluefruit.setTxPower(4);
55+
Bluefruit.setName("WM1110_OTA");
56+
57+
Bluefruit.Periph.setConnectCallback(connect_callback);
58+
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
59+
60+
bledfu.begin();
61+
62+
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
63+
Bluefruit.Advertising.addTxPower();
64+
Bluefruit.Advertising.addName();
65+
Bluefruit.Advertising.restartOnDisconnect(true);
66+
Bluefruit.Advertising.setInterval(32, 244);
67+
Bluefruit.Advertising.setFastTimeout(30);
68+
Bluefruit.Advertising.start(0);
69+
70+
strcpy(reply, "OK - started");
71+
return true;
72+
}
73+
74+
#endif
75+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#pragma once
2+
3+
#include <MeshCore.h>
4+
#include <Arduino.h>
5+
6+
#ifdef WIO_WM1110
7+
8+
#ifdef Serial
9+
#undef Serial
10+
#endif
11+
#define Serial Serial1
12+
13+
class WioWM1110Board : public mesh::MainBoard {
14+
protected:
15+
uint8_t startup_reason;
16+
17+
public:
18+
void begin();
19+
uint8_t getStartupReason() const override { return startup_reason; }
20+
21+
#if defined(LED_GREEN)
22+
void onBeforeTransmit() override {
23+
digitalWrite(LED_RED, HIGH);
24+
}
25+
void onAfterTransmit() override {
26+
digitalWrite(LED_RED, LOW);
27+
}
28+
#endif
29+
30+
uint16_t getBattMilliVolts() override {
31+
int adcvalue = 0;
32+
analogReadResolution(12);
33+
analogReference(AR_INTERNAL_3_0);
34+
delay(10);
35+
adcvalue = analogRead(BATTERY_PIN);
36+
return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE * 1000.0) / 4096.0;
37+
}
38+
39+
const char* getManufacturerName() const override {
40+
return "Seeed Wio WM1110";
41+
}
42+
43+
void reboot() override {
44+
NVIC_SystemReset();
45+
}
46+
47+
bool startOTAUpdate(const char* id, char reply[]) override;
48+
49+
void enableSensorPower(bool enable) {
50+
digitalWrite(SENSOR_POWER_PIN, enable ? HIGH : LOW);
51+
if (enable) {
52+
delay(100);
53+
}
54+
}
55+
};
56+
57+
#endif
58+

variants/wio_wm1110/platformio.ini

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
[wio_wm1110]
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/wio_wm1110
10+
-D NRF52_PLATFORM
11+
-D WIO_WM1110
12+
; -D MESH_DEBUG=1
13+
-D RADIO_CLASS=CustomLR1110
14+
-D WRAPPER_CLASS=CustomLR1110Wrapper
15+
-D LORA_TX_POWER=22
16+
-D RX_BOOSTED_GAIN=true
17+
-D P_LORA_DIO_1=40
18+
-D P_LORA_RESET=42
19+
-D P_LORA_BUSY=43
20+
-D P_LORA_NSS=44
21+
-D P_LORA_SCLK=45
22+
-D P_LORA_MOSI=46
23+
-D P_LORA_MISO=47
24+
-D LR11X0_DIO_AS_RF_SWITCH=true
25+
-D LR11X0_DIO3_TCXO_VOLTAGE=1.8
26+
-D RF_SWITCH_TABLE
27+
-D ENV_INCLUDE_GPS=0
28+
build_src_filter = ${nrf52_base.build_src_filter}
29+
+<helpers/*.cpp>
30+
+<helpers/sensors>
31+
+<../variants/wio_wm1110>
32+
debug_tool = jlink
33+
upload_protocol = jlink
34+
lib_deps = ${nrf52_base.lib_deps}
35+
${sensor_base.lib_deps}
36+
adafruit/Adafruit LIS3DH @ ^1.2.4
37+
adafruit/Adafruit SHT4x Library @ ^1.0.4
38+
39+
[env:wio_wm1110_repeater]
40+
extends = wio_wm1110
41+
build_flags =
42+
${wio_wm1110.build_flags}
43+
-D ADVERT_NAME='"WM1110 Repeater"'
44+
-D ADVERT_LAT=0.0
45+
-D ADVERT_LON=0.0
46+
-D ADMIN_PASSWORD='"password"'
47+
-D MAX_NEIGHBOURS=50
48+
; -D MESH_PACKET_LOGGING=1
49+
; -D MESH_DEBUG=1
50+
build_src_filter = ${wio_wm1110.build_src_filter}
51+
+<../examples/simple_repeater/*.cpp>
52+
53+
[env:wio_wm1110_room_server]
54+
extends = wio_wm1110
55+
build_flags =
56+
${wio_wm1110.build_flags}
57+
-D ADVERT_NAME='"WM1110 Room"'
58+
-D ADVERT_LAT=0.0
59+
-D ADVERT_LON=0.0
60+
-D ADMIN_PASSWORD='"password"'
61+
-D ROOM_PASSWORD='"hello"'
62+
; -D MESH_PACKET_LOGGING=1
63+
; -D MESH_DEBUG=1
64+
build_src_filter = ${wio_wm1110.build_src_filter}
65+
+<../examples/simple_room_server/*.cpp>
66+
67+
[env:wio_wm1110_companion_radio_ble]
68+
extends = wio_wm1110
69+
board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
70+
board_upload.maximum_size = 708608
71+
build_flags =
72+
${wio_wm1110.build_flags}
73+
-D MAX_CONTACTS=350
74+
-D MAX_GROUP_CHANNELS=40
75+
-D BLE_PIN_CODE=123456
76+
-D QSPIFLASH=1
77+
-D OFFLINE_QUEUE_SIZE=256
78+
; -D BLE_DEBUG_LOGGING=1
79+
; -D MESH_PACKET_LOGGING=1
80+
; -D MESH_DEBUG=1
81+
build_src_filter = ${wio_wm1110.build_src_filter}
82+
+<helpers/nrf52/SerialBLEInterface.cpp>
83+
+<../examples/companion_radio/*.cpp>
84+
lib_deps =
85+
${wio_wm1110.lib_deps}
86+
densaugeo/base64 @ ~1.4.0

variants/wio_wm1110/target.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#include <Arduino.h>
2+
#include "target.h"
3+
#include <helpers/ArduinoHelpers.h>
4+
5+
WioWM1110Board board;
6+
7+
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
8+
9+
WRAPPER_CLASS radio_driver(radio, board);
10+
11+
VolatileRTCClock rtc_clock;
12+
EnvironmentSensorManager sensors;
13+
14+
#ifndef LORA_CR
15+
#define LORA_CR 5
16+
#endif
17+
18+
#ifdef RF_SWITCH_TABLE
19+
static const uint32_t rfswitch_dios[Module::RFSWITCH_MAX_PINS] = {
20+
RADIOLIB_LR11X0_DIO5,
21+
RADIOLIB_LR11X0_DIO6,
22+
RADIOLIB_LR11X0_DIO7,
23+
RADIOLIB_LR11X0_DIO8,
24+
RADIOLIB_NC
25+
};
26+
27+
static const Module::RfSwitchMode_t rfswitch_table[] = {
28+
// mode DIO5 DIO6 DIO7 DIO8
29+
{ LR11x0::MODE_STBY, {LOW, LOW, LOW, LOW }},
30+
{ LR11x0::MODE_RX, {HIGH, LOW, LOW, HIGH }},
31+
{ LR11x0::MODE_TX, {HIGH, HIGH, LOW, HIGH }},
32+
{ LR11x0::MODE_TX_HP, {LOW, HIGH, LOW, HIGH }},
33+
{ LR11x0::MODE_TX_HF, {LOW, LOW, LOW, LOW }},
34+
{ LR11x0::MODE_GNSS, {LOW, LOW, HIGH, LOW }},
35+
{ LR11x0::MODE_WIFI, {LOW, LOW, LOW, LOW }},
36+
END_OF_MODE_TABLE,
37+
};
38+
#endif
39+
40+
bool radio_init() {
41+
board.enableSensorPower(true);
42+
43+
#ifdef LR11X0_DIO3_TCXO_VOLTAGE
44+
float tcxo = LR11X0_DIO3_TCXO_VOLTAGE;
45+
#else
46+
float tcxo = 1.8f;
47+
#endif
48+
49+
SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI);
50+
SPI.begin();
51+
52+
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_LR11X0_LORA_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo);
53+
if (status != RADIOLIB_ERR_NONE) {
54+
Serial.print("ERROR: radio init failed: ");
55+
Serial.println(status);
56+
return false; // fail
57+
}
58+
59+
radio.setCRC(2);
60+
radio.explicitHeader();
61+
62+
#ifdef RF_SWITCH_TABLE
63+
radio.setRfSwitchTable(rfswitch_dios, rfswitch_table);
64+
#endif
65+
66+
#ifdef RX_BOOSTED_GAIN
67+
radio.setRxBoostedGainMode(RX_BOOSTED_GAIN);
68+
#endif
69+
70+
return true; // success
71+
}
72+
73+
uint32_t radio_get_rng_seed() {
74+
return radio.random(0x7FFFFFFF);
75+
}
76+
77+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
78+
radio.setFrequency(freq);
79+
radio.setSpreadingFactor(sf);
80+
radio.setBandwidth(bw);
81+
radio.setCodingRate(cr);
82+
}
83+
84+
void radio_set_tx_power(uint8_t dbm) {
85+
radio.setOutputPower(dbm);
86+
}
87+
88+
mesh::LocalIdentity radio_new_identity() {
89+
RadioNoiseListener rng(radio);
90+
return mesh::LocalIdentity(&rng); // create new random identity
91+
}
92+

variants/wio_wm1110/target.h

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

0 commit comments

Comments
 (0)