thinknode_m8: initial support

This commit is contained in:
Florent
2026-08-11 17:37:35 -04:00
parent 47154f02cb
commit 3e82827706
15 changed files with 705 additions and 12 deletions
@@ -0,0 +1,38 @@
#include <Arduino.h>
#include <Wire.h>
#include "ThinkNodeM8Board.h"
#ifdef THINKNODE_M8
void ThinkNodeM8Board::begin() {
NRF52Board::begin();
Wire.begin();
#ifdef P_LORA_TX_LED
pinMode(P_LORA_TX_LED, OUTPUT);
digitalWrite(P_LORA_TX_LED, LOW);
#endif
pinMode(SX126X_POWER_EN, OUTPUT);
digitalWrite(SX126X_POWER_EN, HIGH);
delay(10); // give sx1262 some time to power up
}
uint16_t ThinkNodeM8Board::getBattMilliVolts() {
int adcvalue = 0;
digitalWrite(ADC_EN, HIGH);
analogReference(AR_INTERNAL_2_4);
analogReadResolution(12);
delay(10);
// ADC range is 0..3000mV and resolution is 12-bit (0..4095)
adcvalue = analogRead(PIN_VBAT_READ);
// Convert the raw value to compensated mv, taking the resistor-
// divider into account (providing the actual LIPO voltage)
digitalWrite(ADC_EN, LOW);
return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB);
}
#endif
+50
View File
@@ -0,0 +1,50 @@
#pragma once
#include <MeshCore.h>
#include <Arduino.h>
#include <helpers/NRF52Board.h>
// built-ins
#define VBAT_MV_PER_LSB (0.5859375F) // 2.4V ADC range and 12-bit ADC resolution = 2400mV/4096
#define VBAT_DIVIDER (0.57F) // 150K + 150K voltage divider on VBAT
#define VBAT_DIVIDER_COMP (1.75F) // Compensation factor for the VBAT divider
#define PIN_VBAT_READ (4)
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
class ThinkNodeM8Board : public NRF52Board {
public:
ThinkNodeM8Board() : NRF52Board("THINKNODE_M8_OTA") {}
void begin();
uint16_t getBattMilliVolts() override;
#if defined(P_LORA_TX_LED)
void onBeforeTransmit() override {
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
}
void onAfterTransmit() override {
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off
}
#endif
const char* getManufacturerName() const override {
return "Elecrow ThinkNode-M8";
}
void shutdownPeripherals() override {
// power off board
NRF52Board::shutdownPeripherals();
// make sure every gate is closed
digitalWrite(DISP_EN, LOW);
digitalWrite(PIN_PWR_EN, LOW);
digitalWrite(PIN_GPS_EN, LOW);
digitalWrite(SX126X_ANT_SW, LOW);
digitalWrite(ADC_EN, LOW);
#ifdef PIN_BUTTON1 // Use BTN to go out of sleep
nrf_gpio_cfg_sense_input(PIN_BUTTON1, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
#endif
}
};
+160
View File
@@ -0,0 +1,160 @@
[ThinkNode_M8]
extends = nrf52_base
board = thinknode_m8
board_build.ldscript = boards/nrf52840_s140_v6.ld
build_flags = ${nrf52_base.build_flags}
-I src/helpers/nrf52
-I lib/nrf52/s140_nrf52_6.1.1_API/include
-I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52
-I variants/thinknode_m8
-D THINKNODE_M8=1
-D RADIO_CLASS=CustomSX1262
-D WRAPPER_CLASS=CustomSX1262Wrapper
-D P_LORA_DIO_1=25
-D P_LORA_DIO_2=32
-D P_LORA_NSS=21
-D P_LORA_RESET=24
-D P_LORA_BUSY=32 # DIO2
-D P_LORA_SCLK=19
-D P_LORA_MISO=22
-D P_LORA_MOSI=20
-D UI_SHOW_CLOCK=1
-D UI_HAS_ROTARY_INPUT=1
-D UI_HAS_NAV_INPUT=1
-D UI_RECENT_LIST_SIZE=9
-D UI_TZ_OFFSET=-4 # GMT-4
-D EINK_MAX_PARTIAL_REFRESH=60
-D EINK_DISPLAY_MODEL=GxEPD2_154_D67
; -D EINK_DISPLAY_MODEL=GxEPD2_154_GDEY0154D67
; -D EINK_DISPLAY_MODEL=GxEPD2_150_BN
-D EINK_SCALE_X=1.5625f
-D EINK_SCALE_Y=1.5625f
-D EINK_X_OFFSET=0
-D EINK_Y_OFFSET=10
-D DISABLE_DIAGNOSTIC_OUTPUT
-D SX126X_POWER_EN=37
-D SX126X_DIO2_AS_RF_SWITCH=true
-D SX126X_DIO3_TCXO_VOLTAGE=3.3
-D SX126X_CURRENT_LIMIT=140
-D SX126X_RX_BOOSTED_GAIN=1
-D LORA_TX_POWER=22
build_src_filter = ${nrf52_base.build_src_filter}
+<helpers/*.cpp>
+<ThinkNodeM8Board.cpp>
+<../variants/thinknode_m8>
lib_deps =
${nrf52_base.lib_deps}
stevemarple/MicroNMEA @ ^2.0.6
debug_tool = jlink
upload_protocol = nrfutil
[env:ThinkNode_M8_repeater]
extends = ThinkNode_M8
build_flags =
${ThinkNode_M8.build_flags}
-D ADVERT_NAME='"ThinkNode 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 = ${ThinkNode_M8.build_src_filter}
+<../examples/simple_repeater/*.cpp>
lib_deps =
${ThinkNode_M8.lib_deps}
[env:ThinkNode_M8_room_server]
extends = ThinkNode_M8
build_flags =
${ThinkNode_M8.build_flags}
-D ADVERT_NAME='"ThinkNode 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 = ${ThinkNode_M8.build_src_filter}
+<../examples/simple_room_server/*.cpp>
lib_deps =
${ThinkNode_M8.lib_deps}
[env:ThinkNode_M8_companion_radio_ble]
extends = ThinkNode_M8
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags =
${ThinkNode_M8.build_flags}
-I src/helpers/ui
-I examples/companion_radio/ui-new
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
-D BLE_PIN_CODE=123456
# -D BLE_DEBUG_LOGGING=1
-D DISPLAY_ROTATION=4
-D DISPLAY_CLASS=GxEPDDisplay
-D BACKLIGHT_BTN=PIN_BUTTON2
-D AUTO_OFF_MILLIS=0
-D OFFLINE_QUEUE_SIZE=256
-D PIN_BUZZER=33
-D AUTO_SHUTDOWN_MILLIVOLTS=3300
-D QSPIFLASH=1
-D ENV_INCLUDE_GPS=1
; -D GPS_NMEA_DEBUG=1
; -D MESH_PACKET_LOGGING=1
-D MESH_DEBUG=1
build_src_filter = ${ThinkNode_M8.build_src_filter}
+<helpers/nrf52/SerialBLEInterface.cpp>
+<helpers/ui/GxEPDDisplay.cpp>
+<helpers/ui/buzzer.cpp>
+<helpers/ui/MomentaryButton.cpp>
+<helpers/ui/RotaryInputGPIO.cpp>
+<helpers/sensors/EnvironmentSensorManager.cpp>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
${ThinkNode_M8.lib_deps}
densaugeo/base64 @ ~1.4.0
zinggjm/GxEPD2 @ 1.6.9
bakercp/CRC32 @ ^2.0.0
end2endzone/NonBlockingRTTTL@^1.3.0
[env:ThinkNode_M8_companion_radio_usb]
extends = ThinkNode_M8
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags =
${ThinkNode_M8.build_flags}
-I src/helpers/ui
-I examples/companion_radio/ui-new
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
-D DISPLAY_ROTATION=4
-D QSPIFLASH=1
-D DISPLAY_CLASS=GxEPDDisplay
-D BACKLIGHT_BTN=PIN_BUTTON2
-D AUTO_OFF_MILLIS=0
-D OFFLINE_QUEUE_SIZE=256
-D PIN_BUZZER=6
-D AUTO_SHUTDOWN_MILLIVOLTS=3300
-D ENABLE_USB_INTERFACE
build_src_filter = ${ThinkNode_M8.build_src_filter}
+<helpers/ui/GxEPDDisplay.cpp>
+<helpers/ui/buzzer.cpp>
+<helpers/ui/MomentaryButton.cpp>
+<helpers/ui/RotaryInputGPIO.cpp>
+<helpers/sensors/EnvironmentSensorManager.cpp>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
${ThinkNode_M8.lib_deps}
densaugeo/base64 @ ~1.4.0
zinggjm/GxEPD2 @ 1.6.2
bakercp/CRC32 @ ^2.0.0
end2endzone/NonBlockingRTTTL@^1.3.0
[env:ThinkNode_M8_kiss_modem]
extends = ThinkNode_M8
build_src_filter = ${ThinkNode_M8.build_src_filter}
+<../examples/kiss_modem/>
+36
View File
@@ -0,0 +1,36 @@
#include <Arduino.h>
#include "target.h"
#include <helpers/ArduinoHelpers.h>
#include <helpers/sensors/MicroNMEALocationProvider.h>
#include <Wire.h>
ThinkNodeM8Board board;
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
WRAPPER_CLASS radio_driver(radio, board);
VolatileRTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#ifdef ENV_INCLUDE_GPS
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
#else
EnvironmentSensorManager sensors = EnvironmentSensorManager();
#endif
#ifdef DISPLAY_CLASS
DISPLAY_CLASS display;
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
RotaryInputGPIO rotary_input(PIN_BUTTON1_A, PIN_BUTTON1_B);
#endif
bool radio_init() {
rtc_clock.begin(Wire);
return radio.std_init(&SPI);
}
mesh::LocalIdentity radio_new_identity() {
RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng); // create new random identity
}
+30
View File
@@ -0,0 +1,30 @@
#pragma once
#define RADIOLIB_STATIC_ONLY 1
#include <RadioLib.h>
#include <helpers/radiolib/RadioLibWrappers.h>
#include <ThinkNodeM8Board.h>
#include <helpers/radiolib/CustomSX1262Wrapper.h>
#include <helpers/AutoDiscoverRTCClock.h>
#include <helpers/SensorManager.h>
#include <helpers/sensors/LocationProvider.h>
#include <helpers/sensors/EnvironmentSensorManager.h>
#ifdef DISPLAY_CLASS
#include <helpers/ui/GxEPDDisplay.h>
#include <helpers/ui/RotaryInputGPIO.h>
#include <helpers/ui/MomentaryButton.h>
#endif
extern ThinkNodeM8Board board;
extern WRAPPER_CLASS radio_driver;
extern AutoDiscoverRTCClock rtc_clock;
extern EnvironmentSensorManager sensors;
#ifdef DISPLAY_CLASS
extern DISPLAY_CLASS display;
extern MomentaryButton user_btn;
extern RotaryInputGPIO rotary_input;
#endif
bool radio_init();
mesh::LocalIdentity radio_new_identity();
+39
View File
@@ -0,0 +1,39 @@
#include "variant.h"
#include "wiring_constants.h"
#include "wiring_digital.h"
const int MISO = PIN_SPI1_MISO;
const int MOSI = PIN_SPI1_MOSI;
const int SCK = PIN_SPI1_SCK;
const uint32_t g_ADigitalPinMap[] = {
0xff, 0xff, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47
};
void initVariant() {
pinMode(PIN_PWR_EN, OUTPUT);
digitalWrite(PIN_PWR_EN, HIGH);
pinMode(DISP_EN, OUTPUT);
digitalWrite(DISP_EN, HIGH);
pinMode(PIN_BUTTON1, INPUT_PULLDOWN);
pinMode(PIN_BUTTON1_A, INPUT_PULLDOWN);
pinMode(PIN_BUTTON1_B, INPUT_PULLDOWN);
pinMode(PIN_BUTTON2, INPUT_PULLUP);
// shutdown gps
pinMode(PIN_GPS_STANDBY, OUTPUT);
digitalWrite(PIN_GPS_STANDBY, HIGH);
pinMode(PIN_GPS_EN, OUTPUT);
digitalWrite(PIN_GPS_EN, LOW); // disable at startup
pinMode(SX126X_ANT_SW, OUTPUT); // ANT_SW
digitalWrite(SX126X_ANT_SW, HIGH);
pinMode(ADC_EN, OUTPUT);
digitalWrite(ADC_EN, LOW);
}
+141
View File
@@ -0,0 +1,141 @@
/*
* variant.h
* Copyright (C) 2023 Seeed K.K.
* MIT License
*/
#pragma once
#include "WVariant.h"
////////////////////////////////////////////////////////////////////////////////
// Low frequency clock source
#define USE_LFXO // 32.768 kHz crystal oscillator
#define VARIANT_MCK (64000000ul)
#define WIRE_INTERFACES_COUNT (1)
#define PIN_TXCO (21)
////////////////////////////////////////////////////////////////////////////////
// Power
#define PIN_PWR_EN (13) // I2C
#define BATTERY_PIN (4)
#define ADC_MULTIPLIER (1.75F)
#define ADC_RESOLUTION (14)
#define BATTERY_SENSE_RES (12)
#define AREF_VOLTAGE (2.4)
#define ADC_EN (40)
////////////////////////////////////////////////////////////////////////////////
// Number of pins
#define PINS_COUNT (48)
#define NUM_DIGITAL_PINS (48)
#define NUM_ANALOG_INPUTS (1)
#define NUM_ANALOG_OUTPUTS (0)
////////////////////////////////////////////////////////////////////////////////
// UART pin definition
#define PIN_SERIAL1_RX PIN_GPS_TX
#define PIN_SERIAL1_TX PIN_GPS_RX
////////////////////////////////////////////////////////////////////////////////
// I2C pin definition
#define PIN_WIRE_SDA (26) // P0.26
#define PIN_WIRE_SCL (27) // P0.27
////////////////////////////////////////////////////////////////////////////////
// SPI pin definition
#define SPI_INTERFACES_COUNT (2)
#define PIN_SPI_MISO (22)
#define PIN_SPI_MOSI (20)
#define PIN_SPI_SCK (19)
#define PIN_SPI_NSS (21)
////////////////////////////////////////////////////////////////////////////////
// Builtin LEDs
#define LED_BLUE (-1)
#define LED_BUILTIN LED_BLUE
#define LED_PIN LED_BUILTIN
#define LED_STATE_ON HIGH
////////////////////////////////////////////////////////////////////////////////
// Builtin buttons
#define PIN_BUTTON1 (6)
#define PIN_BUTTON1_A (8) // Rotary button/Encoder
#define PIN_BUTTON1_B (41)
#define BUTTON_PIN PIN_BUTTON1
#define PIN_BUTTON2 (12)
#define BUTTON_PIN2 PIN_BUTTON2
#define PIN_USER_BTN PIN_BUTTON1
////////////////////////////////////////////////////////////////////////////////
// Lora
#define USE_SX1262
#define LORA_CS (24)
#define SX126X_DIO1 (20)
#define SX126X_BUSY (17)
#define SX126X_RESET (25)
#define SX126X_ANT_SW (23)
#define SX126X_DIO2_AS_RF_SWITCH
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
////////////////////////////////////////////////////////////////////////////////
// SPI1
#define PIN_SPI1_NSS (30)
#define PIN_SPI1_SCK (31)
#define PIN_SPI1_MOSI (29)
#define PIN_SPI1_MISO (-1)
// GxEPD2 needs that for a panel that is not even used !
extern const int MISO;
extern const int MOSI;
extern const int SCK;
////////////////////////////////////////////////////////////////////////////////
// QSPI
#define EXTERNAL_FLASH_DEVICES MX25R1635F
#define EXTERNAL_FLASH_USE_QSPI
#define PIN_QSPI_SCK (46)
#define PIN_QSPI_CS (47)
#define PIN_QSPI_IO0 (44) // MOSI if using two bit interface
#define PIN_QSPI_IO1 (45) // MISO if using two bit interface
#define PIN_QSPI_IO2 (7) // WP if using two bit interface (i.e. not used)
#define PIN_QSPI_IO3 (5) // HOLD if using two bit interface (i.e. not used)
////////////////////////////////////////////////////////////////////////////////
// Display
#define DISP_MISO PIN_SPI1_MISO
#define DISP_MOSI PIN_SPI1_MOSI
#define DISP_SCLK PIN_SPI1_SCK
#define PIN_DISPLAY_CS PIN_SPI1_NSS
#define PIN_DISPLAY_DC (28)
#define PIN_DISPLAY_RST (2)
#define PIN_DISPLAY_BUSY (3)
#define DISP_BACKLIGHT (43)
#define DISP_EN (42)
////////////////////////////////////////////////////////////////////////////////
// GPS
#define PIN_GPS_RX (36)
#define PIN_GPS_TX (34)
#define PIN_GPS_EN (16)
#define PIN_GPS_RESET (-1)
#define PIN_GPS_PPS (14)
#define PIN_GPS_STANDBY (15) // Low = sleep
#define GPS_BAUD_RATE 115200