diff --git a/boards/nicenano.json b/boards/nicenano.json new file mode 100644 index 00000000..3ec7d732 --- /dev/null +++ b/boards/nicenano.json @@ -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" +} diff --git a/variants/moonshine_NRF52_ebyte/MoonshineNRF52EbyteBoard.cpp b/variants/moonshine_NRF52_ebyte/MoonshineNRF52EbyteBoard.cpp new file mode 100644 index 00000000..de840248 --- /dev/null +++ b/variants/moonshine_NRF52_ebyte/MoonshineNRF52EbyteBoard.cpp @@ -0,0 +1,25 @@ +#include +#include + +#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(); +} diff --git a/variants/moonshine_NRF52_ebyte/MoonshineNRF52EbyteBoard.h b/variants/moonshine_NRF52_ebyte/MoonshineNRF52EbyteBoard.h new file mode 100644 index 00000000..fe01def5 --- /dev/null +++ b/variants/moonshine_NRF52_ebyte/MoonshineNRF52EbyteBoard.h @@ -0,0 +1,49 @@ +#pragma once + +#include +#include +#include + +#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(); + } +}; diff --git a/variants/moonshine_NRF52_ebyte/platformio.ini b/variants/moonshine_NRF52_ebyte/platformio.ini new file mode 100644 index 00000000..12f4b939 --- /dev/null +++ b/variants/moonshine_NRF52_ebyte/platformio.ini @@ -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} + + + +<../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} + + + +<../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} + + + +<../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} + + + + + + + +<../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} + + + + + + + + + +<../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} diff --git a/variants/moonshine_NRF52_ebyte/target.cpp b/variants/moonshine_NRF52_ebyte/target.cpp new file mode 100644 index 00000000..23ef95ab --- /dev/null +++ b/variants/moonshine_NRF52_ebyte/target.cpp @@ -0,0 +1,39 @@ +#include +#include "target.h" +#include + +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 + 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); +} diff --git a/variants/moonshine_NRF52_ebyte/target.h b/variants/moonshine_NRF52_ebyte/target.h new file mode 100644 index 00000000..fd3758ec --- /dev/null +++ b/variants/moonshine_NRF52_ebyte/target.h @@ -0,0 +1,27 @@ +#pragma once + +#define RADIOLIB_STATIC_ONLY 1 +#include +#include +#include +#include +#include +#include + +#ifdef DISPLAY_CLASS + #include + #include +#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(); diff --git a/variants/moonshine_NRF52_ebyte/variant.cpp b/variants/moonshine_NRF52_ebyte/variant.cpp new file mode 100644 index 00000000..aedffdaa --- /dev/null +++ b/variants/moonshine_NRF52_ebyte/variant.cpp @@ -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); +} diff --git a/variants/moonshine_NRF52_ebyte/variant.h b/variants/moonshine_NRF52_ebyte/variant.h new file mode 100644 index 00000000..ef20fd43 --- /dev/null +++ b/variants/moonshine_NRF52_ebyte/variant.h @@ -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)