Merge pull request #3115 from oltaco/meshnology_w12

Add support for Meshnology W12 and LR2021 Wrapper
This commit is contained in:
ripplebiz
2026-08-05 15:04:00 +10:00
committed by GitHub
15 changed files with 788 additions and 0 deletions
@@ -0,0 +1,83 @@
#include "MeshnologyW12Board.h"
void MeshnologyW12Board::begin() {
ESP32Board::begin();
pinMode(PIN_ADC_CTRL, OUTPUT);
digitalWrite(PIN_ADC_CTRL, LOW); // Disable battery sense until required
pinMode(P_LORA_LF_PA_POWER, OUTPUT);
digitalWrite(P_LORA_LF_PA_POWER, HIGH); // PA_EN_M — power the GC1109 FEM
pinMode(P_LORA_HF_PA_POWER, OUTPUT);
digitalWrite(P_LORA_HF_PA_POWER, LOW); // PA_EN_G — disable the 2.4GHz FEM
delay(100); // give the GC1109 some time to start
periph_power.begin();
esp_reset_reason_t reason = esp_reset_reason();
if (reason == ESP_RST_DEEPSLEEP) {
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
startup_reason = BD_STARTUP_RX_PACKET;
}
rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
}
}
void MeshnologyW12Board::onBeforeTransmit(void) {
neopixelWrite(NEOPIXEL_LED, NEOPIXEL_BRIGHTNESS, NEOPIXEL_BRIGHTNESS, NEOPIXEL_BRIGHTNESS); // turn TX neopixel on (White)
}
void MeshnologyW12Board::onAfterTransmit(void) {
neopixelWrite(NEOPIXEL_LED, 0, 0, 0); // turn TX neopixel off
}
void MeshnologyW12Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) {
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
// Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep
rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY);
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1);
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
if (pin_wake_btn < 0) {
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
} else {
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet OR wake btn
}
if (secs > 0) {
esp_sleep_enable_timer_wakeup(secs * 1000000);
}
// Finally set ESP32 into sleep
esp_deep_sleep_start(); // CPU halts here and never returns!
}
void MeshnologyW12Board::powerOff() {
enterDeepSleep(0);
}
uint16_t MeshnologyW12Board::getBattMilliVolts() {
analogReadResolution(12);
analogSetAttenuation(ADC_11db);
digitalWrite(PIN_ADC_CTRL, HIGH);
delay(10);
uint32_t raw = 0;
for (int i = 0; i < 8; i++) {
raw += analogRead(PIN_VBAT_READ);
}
raw = raw / 8;
digitalWrite(PIN_ADC_CTRL, LOW);
return (adc_mult * (3.3 / 4096.0) * raw) * 1000;
}
const char* MeshnologyW12Board::getManufacturerName() const {
return "Meshnology W12";
}
@@ -0,0 +1,37 @@
#pragma once
#include <Arduino.h>
#include <helpers/RefCountedDigitalPin.h>
#include <helpers/ESP32Board.h>
#include <driver/rtc_io.h>
#ifndef ADC_MULTIPLIER
#define ADC_MULTIPLIER 5.42
#endif
class MeshnologyW12Board : public ESP32Board {
protected:
float adc_mult = ADC_MULTIPLIER;
public:
RefCountedDigitalPin periph_power;
MeshnologyW12Board() : periph_power(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE) { }
void begin();
void onBeforeTransmit(void) override;
void onAfterTransmit(void) override;
void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1);
void powerOff() override;
uint16_t getBattMilliVolts() override;
bool setAdcMultiplier(float multiplier) override {
if (multiplier == 0.0f) {
adc_mult = ADC_MULTIPLIER;
} else {
adc_mult = multiplier;
}
return true;
}
float getAdcMultiplier() const override { return adc_mult; }
const char* getManufacturerName() const override;
};
+69
View File
@@ -0,0 +1,69 @@
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <stdint.h>
static const uint8_t LED_BUILTIN = -1;
#define BUILTIN_LED LED_BUILTIN // backward compatibility
#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN
static const uint8_t TX = 43;
static const uint8_t RX = 44;
static const uint8_t SDA = 3;
static const uint8_t SCL = 4;
static const uint8_t SS = 8;
static const uint8_t MOSI = 10;
static const uint8_t MISO = 11;
static const uint8_t SCK = 9;
static const uint8_t A0 = 1;
static const uint8_t A1 = 2;
static const uint8_t A2 = 3;
static const uint8_t A3 = 4;
static const uint8_t A4 = 5;
static const uint8_t A5 = 6;
static const uint8_t A6 = 7;
static const uint8_t A7 = 8;
static const uint8_t A8 = 9;
static const uint8_t A9 = 10;
static const uint8_t A10 = 11;
static const uint8_t A11 = 12;
static const uint8_t A12 = 13;
static const uint8_t A13 = 14;
static const uint8_t A14 = 15;
static const uint8_t A15 = 16;
static const uint8_t A16 = 17;
static const uint8_t A17 = 18;
static const uint8_t A18 = 19;
static const uint8_t A19 = 20;
static const uint8_t T1 = 1;
static const uint8_t T2 = 2;
static const uint8_t T3 = 3;
static const uint8_t T4 = 4;
static const uint8_t T5 = 5;
static const uint8_t T6 = 6;
static const uint8_t T7 = 7;
static const uint8_t T8 = 8;
static const uint8_t T9 = 9;
static const uint8_t T10 = 10;
static const uint8_t T11 = 11;
static const uint8_t T12 = 12;
static const uint8_t T13 = 13;
static const uint8_t T14 = 14;
static const uint8_t Vext = 45;
static const uint8_t LED = -1;
static const uint8_t RST_OLED = 21;
static const uint8_t SCL_OLED = 18;
static const uint8_t SDA_OLED = 17;
static const uint8_t RST_LoRa = 12;
static const uint8_t BUSY_LoRa = 13;
static const uint8_t DIO0 = 14;
#endif /* Pins_Arduino_h */
+216
View File
@@ -0,0 +1,216 @@
[meshnology_w12]
extends = esp32_base
board = meshnology_w12
build_flags =
${esp32_base.build_flags}
${sensor_base.build_flags}
-I variants/meshnology_w12
-D MESHNOLOGY_W12
-D ESP32_CPU_FREQ=80
-D RADIO_CLASS=CustomLR2021
-D WRAPPER_CLASS=CustomLR2021Wrapper
-D USE_LR2021
-D NEOPIXEL_LED=46
-D NEOPIXEL_BRIGHTNESS=64
-D P_LORA_DIO_1=14
-D LR2021_IRQ_DIO=8 ; GPIO14 is connected to LR2021 DIO8
-D P_LORA_NSS=8
-D P_LORA_SCLK=9
-D P_LORA_MOSI=10
-D P_LORA_MISO=11
-D P_LORA_RESET=12
-D P_LORA_BUSY=13
-D LR2021_TCXO_VOLTAGE=0.0f ; this board has no tcxo
-D RF_SWITCH_TABLE ; used below in commented code for the RF switch table.
-D P_LORA_LF_PA_POWER=4 ; PA_EN_M - power enable for the GC1109 868/915 PA
-D P_LORA_HF_PA_POWER=3 ; PA_EN_G - power enable for RFX2402E 2.4G PA
-D PIN_USER_BTN=0
-D PIN_VEXT_EN=45
-D PIN_VEXT_EN_ACTIVE=HIGH
-D LORA_TX_POWER=4
-D MAX_LORA_TX_POWER=4 ; GC1109 datasheet says max input at TX port is +5dbm, confirmed full saturation seems to occur at around 3-4dbm
-D PIN_GPS_RX=38
-D PIN_GPS_TX=39
-D PIN_GPS_RESET=42
-D PIN_GPS_RESET_ACTIVE=LOW
-D PIN_GPS_EN=48
-D PIN_GPS_EN_ACTIVE=LOW
; -D ENV_INCLUDE_GPS=1
-D PIN_VBAT_READ=1
-D PIN_ADC_CTRL=2
-D PIN_BOARD_SDA=17
-D PIN_BOARD_SCL=18
-D PIN_RESET=47
build_src_filter = ${esp32_base.build_src_filter}
+<../variants/meshnology_w12>
+<helpers/sensors>
lib_deps =
${esp32_base.lib_deps}
${sensor_base.lib_deps}
[env:meshnology_w12_repeater]
extends = meshnology_w12
build_flags =
${meshnology_w12.build_flags}
-D DISPLAY_CLASS=SSD1306Display
-D ADVERT_NAME='"Meshnology W12 Repeater"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
-D ADMIN_PASSWORD='"password"'
-D MAX_NEIGHBOURS=50
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
build_src_filter = ${meshnology_w12.build_src_filter}
+<helpers/ui/SSD1306Display.cpp>
+<../examples/simple_repeater>
lib_deps =
${meshnology_w12.lib_deps}
${esp32_ota.lib_deps}
bakercp/CRC32 @ ^2.0.0
[env:meshnology_w12_repeater_bridge_espnow]
extends = meshnology_w12
build_flags =
${meshnology_w12.build_flags}
-D DISPLAY_CLASS=SSD1306Display
-D ADVERT_NAME='"ESPNow Bridge"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
-D ADMIN_PASSWORD='"password"'
-D MAX_NEIGHBOURS=50
-D WITH_ESPNOW_BRIDGE=1
; -D BRIDGE_DEBUG=1
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
build_src_filter = ${meshnology_w12.build_src_filter}
+<helpers/bridges/ESPNowBridge.cpp>
+<helpers/ui/SSD1306Display.cpp>
+<../examples/simple_repeater>
lib_deps =
${meshnology_w12.lib_deps}
${esp32_ota.lib_deps}
[env:meshnology_w12_room_server]
extends = meshnology_w12
build_flags =
${meshnology_w12.build_flags}
-D DISPLAY_CLASS=SSD1306Display
-D ADVERT_NAME='"Meshnology W12 Room"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
-D ADMIN_PASSWORD='"password"'
-D ROOM_PASSWORD='"hello"'
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
build_src_filter = ${meshnology_w12.build_src_filter}
+<helpers/ui/SSD1306Display.cpp>
+<../examples/simple_room_server>
lib_deps =
${meshnology_w12.lib_deps}
${esp32_ota.lib_deps}
[env:meshnology_w12_terminal_chat]
extends = meshnology_w12
build_flags =
${meshnology_w12.build_flags}
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=1
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
build_src_filter = ${meshnology_w12.build_src_filter}
+<../examples/simple_secure_chat/main.cpp>
lib_deps =
${meshnology_w12.lib_deps}
densaugeo/base64 @ ~1.4.0
[env:meshnology_w12_companion_radio_usb]
extends = meshnology_w12
build_flags =
${meshnology_w12.build_flags}
-I examples/companion_radio/ui-new
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
-D DISPLAY_CLASS=SSD1306Display
; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1
; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1
build_src_filter = ${meshnology_w12.build_src_filter}
+<helpers/ui/SSD1306Display.cpp>
+<helpers/ui/MomentaryButton.cpp>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
${meshnology_w12.lib_deps}
densaugeo/base64 @ ~1.4.0
[env:meshnology_w12_companion_radio_ble]
extends = meshnology_w12
build_flags =
${meshnology_w12.build_flags}
-I examples/companion_radio/ui-new
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
-D DISPLAY_CLASS=SSD1306Display
-D BLE_PIN_CODE=123456 ; dynamic, random PIN
; -D AUTO_SHUTDOWN_MILLIVOLTS=3400 ; disabled by default, otherwise reading bounce causes shutdown when there's no battery connected.
; -D BLE_DEBUG_LOGGING=1
-D OFFLINE_QUEUE_SIZE=256
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
build_src_filter = ${meshnology_w12.build_src_filter}
+<helpers/ui/SSD1306Display.cpp>
+<helpers/ui/MomentaryButton.cpp>
+<helpers/esp32/*.cpp>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
${meshnology_w12.lib_deps}
densaugeo/base64 @ ~1.4.0
[env:meshnology_w12_companion_radio_wifi]
extends = meshnology_w12
build_flags =
${meshnology_w12.build_flags}
-I examples/companion_radio/ui-new
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
-D OFFLINE_QUEUE_SIZE=256
-D DISPLAY_CLASS=SSD1306Display
; -D WIFI_DEBUG_LOGGING=1
-D WIFI_SSID='"myssid"'
-D WIFI_PWD='"mypwd"'
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
build_src_filter = ${meshnology_w12.build_src_filter}
+<helpers/ui/SSD1306Display.cpp>
+<helpers/ui/MomentaryButton.cpp>
+<helpers/esp32/*.cpp>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
${meshnology_w12.lib_deps}
densaugeo/base64 @ ~1.4.0
[env:meshnology_w12_sensor]
extends = meshnology_w12
build_flags =
${meshnology_w12.build_flags}
-D ADVERT_NAME='"Meshnology W12 Sensor"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
-D ADMIN_PASSWORD='"password"'
-D ENV_PIN_SDA=3
-D ENV_PIN_SCL=4
-D DISPLAY_CLASS=SSD1306Display
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
build_src_filter = ${meshnology_w12.build_src_filter}
+<helpers/ui/SSD1306Display.cpp>
+<../examples/simple_sensor>
lib_deps =
${meshnology_w12.lib_deps}
${esp32_ota.lib_deps}
[env:meshnology_w12_kiss_modem]
extends = meshnology_w12
build_src_filter = ${meshnology_w12.build_src_filter}
+<../examples/kiss_modem/>
+73
View File
@@ -0,0 +1,73 @@
#include <Arduino.h>
#include "target.h"
MeshnologyW12Board board;
#if defined(P_LORA_SCLK)
static SPIClass spi;
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi);
#else
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY);
#endif
WRAPPER_CLASS radio_driver(radio, board);
ESP32RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#if ENV_INCLUDE_GPS
#include <helpers/sensors/MicroNMEALocationProvider.h>
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
#else
EnvironmentSensorManager sensors;
#endif
#ifdef DISPLAY_CLASS
DISPLAY_CLASS display(NULL);
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
#endif
const uint32_t rfswitch_dios[] = {
RADIOLIB_LR2021_DIO5, // RFX2402E 2.4G_TX_EN
RADIOLIB_LR2021_DIO6, // RFX2402E 2.4G_RX_EN
RADIOLIB_LR2021_DIO9, // GC1109 CTX (Transmit mode)
RADIOLIB_LR2021_DIO10, // GC1109 CPS (Bypass mode)
RADIOLIB_LR2021_DIO11, // GC1109 CSD (Shutdown)
};
static const Module::RfSwitchMode_t rfswitch_table[] = {
// DIO5 DIO6 DIO9 DIO10 DIO11
{ LR2021::MODE_STBY, { LOW, LOW, LOW, LOW, LOW } }, // everything off
{ LR2021::MODE_RX, { LOW, LOW, LOW, LOW, HIGH } }, // rx_lf: GC1109 LNA
{ LR2021::MODE_TX, { LOW, LOW, HIGH, HIGH, HIGH } }, // tx_lf: GC1109 full PA
{ LR2021::MODE_RX_HF, { LOW, HIGH, LOW, LOW, LOW } }, // rx_hf: 2G4 LNA, GC1109 off
{ LR2021::MODE_TX_HF, { HIGH, LOW, LOW, LOW, LOW } }, // tx_hf: 2G4 PA, GC1109 off
END_OF_MODE_TABLE,
};
bool radio_init() {
fallback_clock.begin();
rtc_clock.begin(Wire);
#if defined(P_LORA_SCLK)
int err = radio.std_init(&spi);
if (err != 1) return err;
#else
int err = radio.std_init();
if (err != 1) return err;
#endif
#ifdef RF_SWITCH_TABLE
radio.setRfSwitchTable(rfswitch_dios, rfswitch_table);
#endif
return true;
}
mesh::LocalIdentity radio_new_identity() {
RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng); // create new random identity
}
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#define RADIOLIB_STATIC_ONLY 1
#include <RadioLib.h>
#include <helpers/radiolib/RadioLibWrappers.h>
#include <MeshnologyW12Board.h>
#include <helpers/radiolib/CustomLR2021Wrapper.h>
#include <helpers/AutoDiscoverRTCClock.h>
#include <helpers/SensorManager.h>
#include <helpers/sensors/EnvironmentSensorManager.h>
#ifdef DISPLAY_CLASS
#include <helpers/ui/SSD1306Display.h>
#include <helpers/ui/MomentaryButton.h>
#endif
extern MeshnologyW12Board board;
extern WRAPPER_CLASS radio_driver;
extern AutoDiscoverRTCClock rtc_clock;
extern EnvironmentSensorManager sensors;
#ifdef DISPLAY_CLASS
extern DISPLAY_CLASS display;
extern MomentaryButton user_btn;
#endif
bool radio_init();
mesh::LocalIdentity radio_new_identity();