Add moonshine_NRF52_ebyte variant (nice!nano + E22-400M33S SX1268)

- nRF52840 board with nice!nano UF2 bootloader
- Ebyte E22-400M33S LoRa module (SX1268 + PA, 33dBm/2W)
- LoRa: 480.375MHz, BW=125, SF=11, CR=5
- Pins: SPI(P1.0/P0.22/P0.20), CS(P0.17), DIO1(P1.10), RESET(P1.13),
  BUSY(P0.28), RXEN(P1.09), LED(P0.15), Button(P0.24), Buzzer(P1.11),
  VBAT_ADC(P0.03), CHAG_DET(P0.13), I2C(P0.08/P0.04)
- 6 build environments: repeater, room_server, companion_radio_usb/ble,
  terminal_chat, kiss_modem
- Custom nicenano board definition with s140 v6 softdevice
This commit is contained in:
2026-07-27 20:44:59 +08:00
parent a3a1aa5e3b
commit 9621c11990
8 files changed
+494

No files matched your search

+77
View File
@@ -0,0 +1,77 @@
{
"build": {
"arduino": {
"ldscript": "nrf52840_s140_v6.ld"
},
"core": "nRF5",
"cpu": "cortex-m4",
"extra_flags": "-DARDUINO_NRF52840_FEATHER -DNRF52840_XXAA",
"f_cpu": "64000000L",
"hwids": [
[
"0x239A",
"0x00B3"
],
[
"0x239A",
"0x8029"
],
[
"0x239A",
"0x0029"
],
[
"0x239A",
"0x002A"
],
[
"0x239A",
"0x802A"
]
],
"usb_product": "Moonshine NRF52 Ebyte",
"mcu": "nrf52840",
"variant": "moonshine_nrf52_ebyte",
"bsp": {
"name": "adafruit"
},
"softdevice": {
"sd_flags": "-DS140",
"sd_name": "s140",
"sd_version": "6.1.1",
"sd_fwid": "0x00B6"
},
"bootloader": {
"settings_addr": "0xFF000"
}
},
"connectivity": [
"bluetooth"
],
"debug": {
"jlink_device": "nRF52840_xxAA",
"svd_path": "nrf52840.svd",
"openocd_target": "nrf52.cfg"
},
"frameworks": [
"arduino"
],
"name": "Moonshine NRF52 Ebyte (nice!nano)",
"upload": {
"maximum_ram_size": 235520,
"maximum_size": 815104,
"speed": 115200,
"protocol": "nrfutil",
"protocols": [
"jlink",
"nrfjprog",
"nrfutil",
"stlink"
],
"use_1200bps_touch": true,
"require_upload_port": true,
"wait_for_upload_port": true
},
"url": "https://github.com/meshcore-dev/MeshCore",
"vendor": "Moonshine"
}
@@ -0,0 +1,25 @@
#include <Arduino.h>
#include <Wire.h>
#include "MoonshineNRF52EbyteBoard.h"
void MoonshineNRF52EbyteBoard::begin() {
NRF52BoardDCDC::begin();
btn_prev_state = HIGH;
pinMode(PIN_VBAT_READ, INPUT);
#ifdef BUTTON_PIN
pinMode(BUTTON_PIN, INPUT_PULLUP);
#endif
#ifdef EXT_CHRG_DETECT
pinMode(EXT_CHRG_DETECT, INPUT);
#endif
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);
#endif
Wire.begin();
}
@@ -0,0 +1,49 @@
#pragma once
#include <MeshCore.h>
#include <Arduino.h>
#include <helpers/NRF52Board.h>
#define PIN_VBAT_READ BATTERY_PIN
class MoonshineNRF52EbyteBoard : public NRF52BoardDCDC {
protected:
uint8_t btn_prev_state = HIGH;
public:
MoonshineNRF52EbyteBoard() : NRF52Board("MoonshineEbyte_OTA") {}
void begin();
#define BATTERY_SAMPLES 8
uint16_t getBattMilliVolts() override {
analogReadResolution(12);
uint32_t raw = 0;
for (int i = 0; i < BATTERY_SAMPLES; i++) {
raw += analogRead(PIN_VBAT_READ);
}
raw = raw / BATTERY_SAMPLES;
return (uint16_t)(raw * ADC_MULTIPLIER * AREF_VOLTAGE * 1000.0F / 4096.0F);
}
const char* getManufacturerName() const override {
return "Moonshine NRF52 Ebyte";
}
int buttonStateChanged() {
#ifdef BUTTON_PIN
uint8_t v = digitalRead(BUTTON_PIN);
if (v != btn_prev_state) {
btn_prev_state = v;
return (v == LOW) ? 1 : -1;
}
#endif
return 0;
}
void powerOff() override {
sd_power_system_off();
}
};
@@ -0,0 +1,140 @@
[moonshine_NRF52_ebyte]
extends = nrf52_base
board = nicenano
build_flags = ${nrf52_base.build_flags}
-I variants/moonshine_NRF52_ebyte
-D MOONSHINE_NRF52_EBYTE
-D USE_SX1268
-D RADIO_CLASS=CustomSX1268
-D WRAPPER_CLASS=CustomSX1268Wrapper
-D LORA_TX_POWER=21
-D LORA_FREQ=480.375
-D LORA_BW=125
-D LORA_SF=11
-D LORA_CR=5
-D SX126X_CURRENT_LIMIT=140
-D SX126X_RX_BOOSTED_GAIN=1
-D PIN_BOARD_SCL=4
-D PIN_BOARD_SDA=8
-D PIN_OLED_RESET=-1
-D PIN_USER_BTN=24
build_src_filter = ${nrf52_base.build_src_filter}
+<helpers/sensors>
+<../variants/moonshine_NRF52_ebyte>
lib_deps =
${nrf52_base.lib_deps}
adafruit/Adafruit SSD1306 @ ^2.5.13
[env:moonshine_ebyte_repeater]
extends = moonshine_NRF52_ebyte
build_flags =
${moonshine_NRF52_ebyte.build_flags}
-D DISPLAY_CLASS=SSD1306Display
-D ADVERT_NAME='"Moonshine 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 = ${moonshine_NRF52_ebyte.build_src_filter}
+<helpers/ui/SSD1306Display.cpp>
+<../examples/simple_repeater>
lib_deps = ${moonshine_NRF52_ebyte.lib_deps}
adafruit/RTClib @ ^2.1.3
[env:moonshine_ebyte_room_server]
extends = moonshine_NRF52_ebyte
build_flags =
${moonshine_NRF52_ebyte.build_flags}
-D DISPLAY_CLASS=SSD1306Display
-D ADVERT_NAME='"Moonshine 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 = ${moonshine_NRF52_ebyte.build_src_filter}
+<helpers/ui/SSD1306Display.cpp>
+<../examples/simple_room_server>
lib_deps = ${moonshine_NRF52_ebyte.lib_deps}
adafruit/RTClib @ ^2.1.3
[env:moonshine_ebyte_companion_radio_usb]
extends = moonshine_NRF52_ebyte
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags =
${moonshine_NRF52_ebyte.build_flags}
-I examples/companion_radio/ui-new
-D PIN_BUZZER=43
-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 = ${moonshine_NRF52_ebyte.build_src_filter}
+<helpers/ui/SSD1306Display.cpp>
+<helpers/ui/MomentaryButton.cpp>
+<helpers/ui/buzzer.cpp>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
${moonshine_NRF52_ebyte.lib_deps}
adafruit/RTClib @ ^2.1.3
densaugeo/base64 @ ~1.4.0
end2endzone/NonBlockingRTTTL@^1.3.0
[env:moonshine_ebyte_companion_radio_ble]
extends = moonshine_NRF52_ebyte
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags =
${moonshine_NRF52_ebyte.build_flags}
-I examples/companion_radio/ui-new
-D PIN_BUZZER=43
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
-D BLE_PIN_CODE=123456
-D BLE_DEBUG_LOGGING=1
-D OFFLINE_QUEUE_SIZE=256
-D DISPLAY_CLASS=SSD1306Display
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
build_src_filter = ${moonshine_NRF52_ebyte.build_src_filter}
+<helpers/nrf52/SerialBLEInterface.cpp>
+<helpers/ui/SSD1306Display.cpp>
+<helpers/ui/MomentaryButton.cpp>
+<helpers/ui/buzzer.cpp>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
${moonshine_NRF52_ebyte.lib_deps}
adafruit/RTClib @ ^2.1.3
densaugeo/base64 @ ~1.4.0
end2endzone/NonBlockingRTTTL@^1.3.0
[env:moonshine_ebyte_terminal_chat]
extends = moonshine_NRF52_ebyte
build_flags =
${moonshine_NRF52_ebyte.build_flags}
-D MAX_CONTACTS=100
-D MAX_GROUP_CHANNELS=1
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
build_src_filter = ${moonshine_NRF52_ebyte.build_src_filter}
+<../examples/simple_secure_chat/main.cpp>
lib_deps =
${moonshine_NRF52_ebyte.lib_deps}
adafruit/RTClib @ ^2.1.3
densaugeo/base64 @ ~1.4.0
[env:moonshine_ebyte_kiss_modem]
extends = moonshine_NRF52_ebyte
build_flags =
${moonshine_NRF52_ebyte.build_flags}
build_src_filter = ${moonshine_NRF52_ebyte.build_src_filter}
+<../examples/kiss_modem/>
lib_deps =
${moonshine_NRF52_ebyte.lib_deps}
+39
View File
@@ -0,0 +1,39 @@
#include <Arduino.h>
#include "target.h"
#include <helpers/ArduinoHelpers.h>
MoonshineNRF52EbyteBoard board;
#ifndef PIN_USER_BTN
#define PIN_USER_BTN (-1)
#endif
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);
#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;
MomentaryButton user_btn(PIN_USER_BTN, 1000, true, true);
#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);
}
+27
View File
@@ -0,0 +1,27 @@
#pragma once
#define RADIOLIB_STATIC_ONLY 1
#include <RadioLib.h>
#include <helpers/radiolib/RadioLibWrappers.h>
#include <MoonshineNRF52EbyteBoard.h>
#include <helpers/radiolib/CustomSX1268Wrapper.h>
#include <helpers/AutoDiscoverRTCClock.h>
#include <helpers/sensors/EnvironmentSensorManager.h>
#ifdef DISPLAY_CLASS
#include <helpers/ui/SSD1306Display.h>
#include <helpers/ui/MomentaryButton.h>
#endif
extern MoonshineNRF52EbyteBoard 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();
@@ -0,0 +1,31 @@
/*
* variant.cpp
* Moonshine NRF52 Ebyte (nice!nano)
*/
#include "variant.h"
#include "wiring_constants.h"
#include "wiring_digital.h"
const uint32_t g_ADigitalPinMap[] = {
// P0
0, 1, 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,
// P1
32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47
};
void initVariant()
{
// LED
pinMode(PIN_LED, OUTPUT);
ledOff(PIN_LED);
// Buzzer - pull low to avoid power draw
pinMode(PIN_BUZZER, OUTPUT);
digitalWrite(PIN_BUZZER, LOW);
}
+106
View File
@@ -0,0 +1,106 @@
/*
* variant.h
* Moonshine NRF52 Ebyte (nice!nano)
* MIT License
*/
#pragma once
#define _PINNUM(port, pin) ((port) * 32 + (pin))
#include "WVariant.h"
////////////////////////////////////////////////////////////////////////////////
// Low frequency clock source
#define USE_LFXO // 32.768 kHz crystal oscillator
#define VARIANT_MCK (64000000ul)
#define WIRE_INTERFACES_COUNT (1)
////////////////////////////////////////////////////////////////////////////////
// Power / Battery
#define BATTERY_PIN _PINNUM(0, 3) // P0.03 - VBAT_ADC
#define ADC_MULTIPLIER (2.0F)
#define AREF_VOLTAGE (3.6F)
#define ADC_RESOLUTION (12)
////////////////////////////////////////////////////////////////////////////////
// Charge detection
#define EXT_CHRG_DETECT _PINNUM(0, 13) // P0.13 - CHAG_DET
////////////////////////////////////////////////////////////////////////////////
// Number of pins
#define PINS_COUNT (48)
#define NUM_DIGITAL_PINS (48)
#define NUM_ANALOG_INPUTS (6)
#define NUM_ANALOG_OUTPUTS (0)
////////////////////////////////////////////////////////////////////////////////
// UART pin definition
#define PIN_SERIAL1_RX (0)
#define PIN_SERIAL1_TX (1)
////////////////////////////////////////////////////////////////////////////////
// I2C pin definition (routed, no device)
#define PIN_WIRE_SDA _PINNUM(0, 8) // P0.08
#define PIN_WIRE_SCL _PINNUM(0, 4) // P0.04
////////////////////////////////////////////////////////////////////////////////
// SPI pin definition
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO _PINNUM(1, 0) // P1.00
#define PIN_SPI_MOSI _PINNUM(0, 22) // P0.22
#define PIN_SPI_SCK _PINNUM(0, 20) // P0.20
#define PIN_SPI_NSS _PINNUM(0, 17) // P0.17
static const uint8_t SS = PIN_SPI_NSS;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
////////////////////////////////////////////////////////////////////////////////
// Builtin LEDs
#define PIN_LED _PINNUM(0, 15) // P0.15
#define LED_PIN PIN_LED
#define LED_BUILTIN PIN_LED
#define LED_BLUE PIN_LED
#define LED_STATE_ON 1 // Active-HIGH
////////////////////////////////////////////////////////////////////////////////
// Builtin buttons
#define PIN_BUTTON1 _PINNUM(0, 24) // P0.24
#define BUTTON_PIN PIN_BUTTON1
#define PIN_USER_BTN BUTTON_PIN
////////////////////////////////////////////////////////////////////////////////
// Buzzer
#define PIN_BUZZER _PINNUM(1, 11) // P1.11
////////////////////////////////////////////////////////////////////////////////
// LoRa radio (Ebyte E22-400M33S, SX1268 + PA)
#define USE_SX1268
#define P_LORA_NSS _PINNUM(0, 17) // P0.17 - LORA_CS
#define P_LORA_DIO_1 _PINNUM(1, 10) // P1.10 - LORA_DIO1
#define P_LORA_RESET _PINNUM(1, 13) // P1.13 - LORA_RESET
#define P_LORA_BUSY _PINNUM(0, 28) // P0.28 - LORA_BUSY
#define P_LORA_MISO PIN_SPI_MISO // P1.00
#define P_LORA_SCLK PIN_SPI_SCK // P0.20
#define P_LORA_MOSI PIN_SPI_MOSI // P0.22
#define SX126X_RXEN _PINNUM(1, 9) // P1.09 - LORA_RXEN
#define SX126X_TXEN RADIOLIB_NC
#define SX126X_DIO2_AS_RF_SWITCH true
#define SX126X_DIO3_TCXO_VOLTAGE (1.8f)