Skip to content

Commit ec05d40

Browse files
Add Seeed Wio WM1110 Dev Board variant
1 parent 633538d commit ec05d40

File tree

7 files changed

+586
-0
lines changed

7 files changed

+586
-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: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
build_src_filter = ${nrf52_base.build_src_filter}
28+
+<helpers/*.cpp>
29+
+<helpers/sensors>
30+
+<../variants/wio_wm1110>
31+
debug_tool = jlink
32+
upload_protocol = jlink
33+
lib_deps = ${nrf52_base.lib_deps}
34+
${sensor_base.lib_deps}
35+
adafruit/Adafruit LIS3DH @ ^1.2.4
36+
adafruit/Adafruit SHT4x Library @ ^1.0.4
37+
38+
[env:wio_wm1110_repeater]
39+
extends = wio_wm1110
40+
build_flags =
41+
${wio_wm1110.build_flags}
42+
-D ADVERT_NAME='"WM1110 Repeater"'
43+
-D ADVERT_LAT=0.0
44+
-D ADVERT_LON=0.0
45+
-D ADMIN_PASSWORD='"password"'
46+
-D MAX_NEIGHBOURS=50
47+
; -D MESH_PACKET_LOGGING=1
48+
; -D MESH_DEBUG=1
49+
build_src_filter = ${wio_wm1110.build_src_filter}
50+
+<../examples/simple_repeater/*.cpp>
51+
52+
[env:wio_wm1110_room_server]
53+
extends = wio_wm1110
54+
build_flags =
55+
${wio_wm1110.build_flags}
56+
-D ADVERT_NAME='"WM1110 Room"'
57+
-D ADVERT_LAT=0.0
58+
-D ADVERT_LON=0.0
59+
-D ADMIN_PASSWORD='"password"'
60+
-D ROOM_PASSWORD='"hello"'
61+
; -D MESH_PACKET_LOGGING=1
62+
; -D MESH_DEBUG=1
63+
build_src_filter = ${wio_wm1110.build_src_filter}
64+
+<../examples/simple_room_server/*.cpp>
65+
66+
[env:wio_wm1110_companion_radio_ble]
67+
extends = wio_wm1110
68+
board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
69+
board_upload.maximum_size = 708608
70+
build_flags =
71+
${wio_wm1110.build_flags}
72+
-D MAX_CONTACTS=350
73+
-D MAX_GROUP_CHANNELS=40
74+
-D BLE_PIN_CODE=123456
75+
-D QSPIFLASH=1
76+
-D OFFLINE_QUEUE_SIZE=256
77+
; -D BLE_DEBUG_LOGGING=1
78+
; -D MESH_PACKET_LOGGING=1
79+
; -D MESH_DEBUG=1
80+
build_src_filter = ${wio_wm1110.build_src_filter}
81+
+<helpers/nrf52/SerialBLEInterface.cpp>
82+
+<../examples/companion_radio/*.cpp>
83+
lib_deps =
84+
${wio_wm1110.lib_deps}
85+
densaugeo/base64 @ ~1.4.0

variants/wio_wm1110/target.cpp

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

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)