From 3dea712d37ac285466e2d33fdff77d5678266719 Mon Sep 17 00:00:00 2001 From: Alex Wolden Date: Wed, 5 Mar 2025 19:52:24 -0800 Subject: [PATCH 01/19] Fix heltec v3.2 pin polarity reversal --- src/helpers/HeltecV3Board.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/helpers/HeltecV3Board.h b/src/helpers/HeltecV3Board.h index 927d537..75f9385 100644 --- a/src/helpers/HeltecV3Board.h +++ b/src/helpers/HeltecV3Board.h @@ -24,11 +24,20 @@ #include class HeltecV3Board : public ESP32Board { +private: + bool adc_active_state; + public: void begin() { ESP32Board::begin(); + // Auto-detect correct ADC_CTRL pin polarity (different for boards >3.2) + pinMode(PIN_ADC_CTRL, INPUT); + adc_active_state = !digitalRead(PIN_ADC_CTRL); + pinMode(PIN_ADC_CTRL, OUTPUT); + digitalWrite(PIN_ADC_CTRL, !adc_active_state); // Initially inactive + pinMode(PIN_VEXT_EN, OUTPUT); digitalWrite(PIN_VEXT_EN, LOW); // for V3.2 boards @@ -69,7 +78,7 @@ public: uint16_t getBattMilliVolts() override { analogReadResolution(10); - digitalWrite(PIN_ADC_CTRL, PIN_ADC_CTRL_ACTIVE); + digitalWrite(PIN_ADC_CTRL, adc_active_state); uint32_t raw = 0; for (int i = 0; i < 8; i++) { @@ -77,7 +86,7 @@ public: } raw = raw / 8; - digitalWrite(PIN_ADC_CTRL, PIN_ADC_CTRL_INACTIVE); + digitalWrite(PIN_ADC_CTRL, !adc_active_state); return (5.2 * (3.3 / 1024.0) * raw) * 1000; } From 7bb16cd7f3c91397e3757a8449dc6fce4b3ffcad Mon Sep 17 00:00:00 2001 From: Florent de Lamotte Date: Mon, 10 Mar 2025 17:11:55 +0100 Subject: [PATCH 02/19] enhancement on the UI and support for power off and status_led for t1000e --- examples/companion_radio/UITask.cpp | 161 +++++++++++++++++++--------- examples/companion_radio/UITask.h | 19 +++- examples/companion_radio/main.cpp | 23 ++-- platformio.ini | 8 +- src/MeshCore.h | 1 + src/helpers/HeltecV3Board.h | 4 + src/helpers/nrf52/T1000eBoard.h | 4 +- 7 files changed, 157 insertions(+), 63 deletions(-) diff --git a/examples/companion_radio/UITask.cpp b/examples/companion_radio/UITask.cpp index 8ffb2c1..f498198 100644 --- a/examples/companion_radio/UITask.cpp +++ b/examples/companion_radio/UITask.cpp @@ -28,7 +28,16 @@ void UITask::begin(const char* node_name, const char* build_date, uint32_t pin_c _node_name = node_name; _build_date = build_date; _pin_code = pin_code; - _display->turnOn(); + if (_display != NULL) { + _display->turnOn(); + } +} + +void UITask::msgRead(int msgcount) { + _msgcount = msgcount; + if (msgcount == 0) { + clearMsgPreview(); + } } void UITask::clearMsgPreview() { @@ -36,7 +45,9 @@ void UITask::clearMsgPreview() { _msg[0] = 0; } -void UITask::showMsgPreview(uint8_t path_len, const char* from_name, const char* text) { +void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) { + _msgcount = msgcount; + if (path_len == 0xFF) { sprintf(_origin, "(F) %s", from_name); } else { @@ -44,67 +55,121 @@ void UITask::showMsgPreview(uint8_t path_len, const char* from_name, const char* } StrHelper::strncpy(_msg, text, sizeof(_msg)); - if (!_display->isOn()) _display->turnOn(); - _auto_off = millis() + AUTO_OFF_MILLIS; // extend the auto-off timer + if (_display != NULL) { + if (!_display->isOn()) _display->turnOn(); + _auto_off = millis() + AUTO_OFF_MILLIS; // extend the auto-off timer + } } void UITask::renderCurrScreen() { - char tmp[80]; - if (_origin[0] && _msg[0]) { - // render message preview - _display->setCursor(0, 0); - _display->setTextSize(1); - _display->print(_node_name); + if (_display != NULL) { + char tmp[80]; + if (_origin[0] && _msg[0]) { + // render message preview + _display->setCursor(0, 0); + _display->setTextSize(1); + _display->print(_node_name); - _display->setCursor(0, 12); - _display->print(_origin); - _display->setCursor(0, 24); - _display->print(_msg); + _display->setCursor(0, 12); + _display->print(_origin); + _display->setCursor(0, 24); + _display->print(_msg); - //_display->setCursor(100, 9); TODO - //_display->setTextSize(2); - //_display->printf("%d", msgs); - } else { - // render 'home' screen - _display->drawXbm(0, 0, meshcore_logo, 128, 13); - _display->setCursor(0, 20); - _display->setTextSize(1); - _display->print(_node_name); - - sprintf(tmp, "Build: %s", _build_date); - _display->setCursor(0, 32); - _display->print(tmp); - - if (_connected) { - //_display->printf("freq : %03.2f sf %d\n", _prefs.freq, _prefs.sf); - //_display->printf("bw : %03.2f cr %d\n", _prefs.bw, _prefs.cr); - } else if (_pin_code != 0) { + _display->setCursor(100, 9); _display->setTextSize(2); - _display->setCursor(0, 43); - sprintf(tmp, "Pin:%d", _pin_code); + sprintf(tmp, "%d", _msgcount); _display->print(tmp); + } else { + // render 'home' screen + _display->drawXbm(0, 0, meshcore_logo, 128, 13); + _display->setCursor(0, 20); + _display->setTextSize(1); + _display->print(_node_name); + + sprintf(tmp, "Build: %s", _build_date); + _display->setCursor(0, 32); + _display->print(tmp); + + if (_connected) { + //_display->printf("freq : %03.2f sf %d\n", _prefs.freq, _prefs.sf); + //_display->printf("bw : %03.2f cr %d\n", _prefs.bw, _prefs.cr); + } else if (_pin_code != 0) { + _display->setTextSize(2); + _display->setCursor(0, 43); + sprintf(tmp, "Pin:%d", _pin_code); + _display->print(tmp); + } } } } -void UITask::loop() { - if (millis() >= _next_read) { - int btnState = digitalRead(PIN_USER_BTN); - if (btnState != _prevBtnState) { - if (btnState == LOW) { // pressed? - if (_display->isOn()) { - clearMsgPreview(); - } else { - _display->turnOn(); - } - _auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer +void UITask::userLedHandler() { +#ifdef PIN_STATUS_LED + static int state = 0; + static int next_change = 0; + int cur_time = millis(); + if (cur_time > next_change) { + if (state == 0) { + state = 1; // led on, short = unread msg + if (_msgcount > 0) { + next_change = cur_time + 500; + } else { + next_change = cur_time + 2000; + } + } else { + state = 0; + if (_board->getBattMilliVolts() > 3800) { + next_change = cur_time + 2000; + } else { + next_change = cur_time + 4000; // 4s blank if bat level low } - _prevBtnState = btnState; } - _next_read = millis() + 100; // 10 reads per second + digitalWrite(PIN_STATUS_LED, state); } +#endif +} - if (_display->isOn()) { +void UITask::buttonHandler() { +#ifdef PIN_USER_BTN + static int prev_btn_state = HIGH; + static unsigned long btn_state_change_time = 0; + static unsigned long next_read = 0; + int cur_time = millis(); + if (cur_time >= next_read) { + int btn_state = digitalRead(PIN_USER_BTN); + if (btn_state != prev_btn_state) { + if (btn_state == USER_BTN_PRESSED) { // pressed? + if (_display != NULL) { + if (_display->isOn()) { + clearMsgPreview(); + } else { + _display->turnOn(); + } + _auto_off = cur_time + AUTO_OFF_MILLIS; // extend auto-off timer + } + } else { // unpressed ? check pressed time ... + if ((cur_time - btn_state_change_time) > 5000) { + Serial.println("power off"); + #ifdef PIN_STATUS_LED + digitalWrite(PIN_STATUS_LED, LOW); + delay(10); + #endif + _board->powerOff(); + } + } + btn_state_change_time = millis(); + prev_btn_state = btn_state; + } + next_read = millis() + 100; // 10 reads per second + } +#endif +} + +void UITask::loop() { + buttonHandler(); + userLedHandler(); + + if (_display != NULL && _display->isOn()) { if (millis() >= _next_refresh) { _display->startFrame(); renderCurrScreen(); diff --git a/examples/companion_radio/UITask.h b/examples/companion_radio/UITask.h index f1a6322..fa64532 100644 --- a/examples/companion_radio/UITask.h +++ b/examples/companion_radio/UITask.h @@ -1,10 +1,12 @@ #pragma once +#include #include class UITask { DisplayDriver* _display; - unsigned long _next_read, _next_refresh, _auto_off; + mesh::MainBoard* _board; + unsigned long _next_refresh, _auto_off; int _prevBtnState; bool _connected; uint32_t _pin_code; @@ -12,14 +14,23 @@ class UITask { const char* _build_date; char _origin[62]; char _msg[80]; + int _msgcount; void renderCurrScreen(); + void buttonHandler(); + void userLedHandler(); + public: - UITask(DisplayDriver& display) : _display(&display) { _next_read = _next_refresh = 0; _connected = false; } + + UITask(mesh::MainBoard* board, DisplayDriver* display) : _board(board), _display(display){ + _next_refresh = 0; + _connected = false; + } void begin(const char* node_name, const char* build_date, uint32_t pin_code); void setHasConnection(bool connected) { _connected = connected; } void clearMsgPreview(); - void showMsgPreview(uint8_t path_len, const char* from_name, const char* text); + void msgRead(int msgcount); + void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount); void loop(); -}; \ No newline at end of file +}; diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 833e41d..a400977 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -97,12 +97,16 @@ #endif #ifdef DISPLAY_CLASS + #include "UITask.h" #include static DISPLAY_CLASS display; - + static UITask ui_task(&board, &display); + #define HAS_UI +#elif defined(HAS_UI) #include "UITask.h" - static UITask ui_task(display); + + static UITask ui_task(&board, NULL); #endif // Believe it or not, this std C function is busted on some platforms! @@ -508,8 +512,8 @@ protected: } else { soundBuzzer(); } - #ifdef DISPLAY_CLASS - ui_task.showMsgPreview(path_len, from.name, text); + #ifdef HAS_UI + ui_task.newMsg(path_len, from.name, text, offline_queue_len); #endif } @@ -550,8 +554,8 @@ protected: } else { soundBuzzer(); } - #ifdef DISPLAY_CLASS - ui_task.showMsgPreview(in_path_len < 0 ? 0xFF : in_path_len, "Public", text); + #ifdef HAS_UI + ui_task.newMsg(in_path_len < 0 ? 0xFF : in_path_len, "Public", text, offline_queue_len); #endif } @@ -1010,6 +1014,9 @@ public: int out_len; if ((out_len = getFromOfflineQueue(out_frame)) > 0) { _serial->writeFrame(out_frame, out_len); + #ifdef HAS_UI + ui_task.msgRead(offline_queue_len); + #endif } else { out_frame[0] = RESP_CODE_NO_MORE_MESSAGES; _serial->writeFrame(out_frame, 1); @@ -1190,7 +1197,7 @@ public: checkConnections(); } - #ifdef DISPLAY_CLASS + #ifdef HAS_UI ui_task.setHasConnection(_serial->isConnected()); ui_task.loop(); #endif @@ -1315,6 +1322,8 @@ void setup() { #ifdef DISPLAY_CLASS display.begin(); +#endif +#ifdef HAS_UI ui_task.begin(the_mesh.getNodeName(), FIRMWARE_BUILD_DATE, the_mesh.getBLEPin()); #endif } diff --git a/platformio.ini b/platformio.ini index 02ce189..a8bdf21 100644 --- a/platformio.ini +++ b/platformio.ini @@ -22,6 +22,7 @@ build_flags = -w -DNDEBUG -DRADIOLIB_STATIC_ONLY=1 -DRADIOLIB_GODMODE=1 -D LORA_FREQ=867.5 -D LORA_BW=250 -D LORA_SF=10 + -D USER_BTN_PRESSED=LOW build_src_filter = +<*.cpp> + @@ -774,10 +775,14 @@ board = tracker-t1000-e board_build.ldscript = boards/nrf52840_s140_v7.ld build_flags = ${nrf52840_t1000e.build_flags} -Ivariants/t1000-e - -DT1000_E + -D T1000_E -D PIN_USER_BTN=6 + -D USER_BTN_PRESSED=HIGH + -D PIN_STATUS_LED=24 -D RADIO_CLASS=CustomLR1110 -D WRAPPER_CLASS=CustomLR1110Wrapper + -D MAX_LORA_TX_POWER=22 + -D LORA_TX_POWER=22 build_src_filter = ${nrf52840_t1000e.build_src_filter} + + @@ -794,6 +799,7 @@ build_flags = ${t1000-e.build_flags} -D BLE_DEBUG_LOGGING=1 -D MESH_PACKET_LOGGING=1 -D MESH_DEBUG=1 + -D HAS_UI build_src_filter = ${t1000-e.build_src_filter} + +<../examples/companion_radio/*.cpp> diff --git a/src/MeshCore.h b/src/MeshCore.h index 6bb1198..5f9956a 100644 --- a/src/MeshCore.h +++ b/src/MeshCore.h @@ -40,6 +40,7 @@ public: virtual void onBeforeTransmit() { } virtual void onAfterTransmit() { } virtual void reboot() = 0; + virtual void powerOff() { while (1) { }}; // hope it's overriden or never called ;) virtual uint8_t getStartupReason() const = 0; virtual bool startOTAUpdate() { return false; } // not supported }; diff --git a/src/helpers/HeltecV3Board.h b/src/helpers/HeltecV3Board.h index 927d537..c61189f 100644 --- a/src/helpers/HeltecV3Board.h +++ b/src/helpers/HeltecV3Board.h @@ -67,6 +67,10 @@ public: esp_deep_sleep_start(); // CPU halts here and never returns! } + void powerOff() override { + enterDeepSleep(0); + } + uint16_t getBattMilliVolts() override { analogReadResolution(10); digitalWrite(PIN_ADC_CTRL, PIN_ADC_CTRL_ACTIVE); diff --git a/src/helpers/nrf52/T1000eBoard.h b/src/helpers/nrf52/T1000eBoard.h index 3c0f30b..ce2206e 100644 --- a/src/helpers/nrf52/T1000eBoard.h +++ b/src/helpers/nrf52/T1000eBoard.h @@ -3,8 +3,6 @@ #include #include -#define HAS_T1000e_POWEROFF - // LoRa and SPI pins #define P_LORA_DIO_1 (32 + 1) // P1.1 #define P_LORA_NSS (0 + 12) // P0.12 @@ -61,7 +59,7 @@ public: return 0; } - void powerOff() { + void powerOff() override { #ifdef HAS_GPS digitalWrite(GPS_VRTC_EN, LOW); digitalWrite(GPS_RESET, LOW); From 4cfdb0ef7c648bab05f2916241e3243cf86b967f Mon Sep 17 00:00:00 2001 From: Florent Date: Mon, 10 Mar 2025 22:42:52 +0100 Subject: [PATCH 03/19] better handling of BTN_USER_PRESSED definition --- examples/companion_radio/UITask.cpp | 4 ++++ platformio.ini | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/companion_radio/UITask.cpp b/examples/companion_radio/UITask.cpp index f498198..df09e26 100644 --- a/examples/companion_radio/UITask.cpp +++ b/examples/companion_radio/UITask.cpp @@ -4,6 +4,10 @@ #define AUTO_OFF_MILLIS 15000 // 15 seconds +#ifndef USER_BTN_PRESSED +#define USER_BTN_PRESSED LOW +#endif + // 'meshcore', 128x13px static const uint8_t meshcore_logo [] PROGMEM = { 0x3c, 0x01, 0xe3, 0xff, 0xc7, 0xff, 0x8f, 0x03, 0x87, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, diff --git a/platformio.ini b/platformio.ini index a8bdf21..f6221c5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -22,7 +22,6 @@ build_flags = -w -DNDEBUG -DRADIOLIB_STATIC_ONLY=1 -DRADIOLIB_GODMODE=1 -D LORA_FREQ=867.5 -D LORA_BW=250 -D LORA_SF=10 - -D USER_BTN_PRESSED=LOW build_src_filter = +<*.cpp> + From 8e793dc55e0287de8506413bace968c5e84cd629 Mon Sep 17 00:00:00 2001 From: taco Date: Thu, 20 Feb 2025 22:24:46 +1100 Subject: [PATCH 04/19] Faketec board support, including build targets --- boards/supermini_nrf52840.json | 78 +++++++++++ examples/companion_radio/main.cpp | 6 + examples/simple_repeater/main.cpp | 4 + examples/simple_room_server/main.cpp | 4 + examples/simple_secure_chat/main.cpp | 4 + platformio.ini | 88 ++++++++++++ src/helpers/nrf52/faketecBoard.cpp | 63 +++++++++ src/helpers/nrf52/faketecBoard.h | 61 ++++++++ variants/supermini_nrf52840/variant.cpp | 52 +++++++ variants/supermini_nrf52840/variant.h | 176 ++++++++++++++++++++++++ 10 files changed, 536 insertions(+) create mode 100644 boards/supermini_nrf52840.json create mode 100644 src/helpers/nrf52/faketecBoard.cpp create mode 100644 src/helpers/nrf52/faketecBoard.h create mode 100644 variants/supermini_nrf52840/variant.cpp create mode 100644 variants/supermini_nrf52840/variant.h diff --git a/boards/supermini_nrf52840.json b/boards/supermini_nrf52840.json new file mode 100644 index 0000000..328c0c9 --- /dev/null +++ b/boards/supermini_nrf52840.json @@ -0,0 +1,78 @@ +{ + "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": "SuperMini nRF52840", + "mcu": "nrf52840", + "variant": "supermini_nrf52840", + "variants_dir": "variants", + "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" + }, + "frameworks": [ + "arduino", + "zephyr" + ], + "name": "Nologo SuperMini nRF52840", + "upload": { + "maximum_ram_size": 248832, + "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://www.nologo.tech/en/product/otherboard/NRF52840.html", + "vendor": "Nologo" + } \ No newline at end of file diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 833e41d..75dbfba 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -92,6 +92,10 @@ #include #include static TechoBoard board; +#elif defined(FAKETEC) + #include + #include + static faketecBoard board; #else #error "need to provide a 'board' object" #endif @@ -1290,7 +1294,9 @@ void setup() { sprintf(dev_name, "MeshCore-%s", the_mesh.getNodeName()); serial_interface.begin(dev_name, the_mesh.getBLEPin()); #else +#ifdef RAK_4631 pinMode(WB_IO2, OUTPUT); +#endif serial_interface.begin(Serial); #endif the_mesh.startInterface(serial_interface); diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 5743647..3f57e81 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -96,6 +96,10 @@ #include #include static TechoBoard board; +#elif defined(FAKETEC) + #include + #include + static faketecBoard board; #else #error "need to provide a 'board' object" #endif diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index 285d59c..76412d9 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -100,6 +100,10 @@ #include #include static TechoBoard board; +#elif defined(FAKETEC) + #include + #include + static faketecBoard board; #else #error "need to provide a 'board' object" #endif diff --git a/examples/simple_secure_chat/main.cpp b/examples/simple_secure_chat/main.cpp index 951d51d..64e5c32 100644 --- a/examples/simple_secure_chat/main.cpp +++ b/examples/simple_secure_chat/main.cpp @@ -78,6 +78,10 @@ #include #include static T1000eBoard board; +#elif defined(FAKETEC) + #include + #include + static faketecBoard board; #else #error "need to provide a 'board' object" #endif diff --git a/platformio.ini b/platformio.ini index 02ce189..a1e154c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -947,3 +947,91 @@ build_src_filter = ${LilyGo_Techo.build_src_filter} lib_deps = ${LilyGo_Techo.lib_deps} densaugeo/base64 @ ~1.4.0 + + +[faketec] +extends = nrf52840_base +board = supermini_nrf52840 +#board_check = true +build_src_filter = ${nrf52840_base.build_src_filter} + +build_flags = ${nrf52840_base.build_flags} + -D FAKETEC + -D RADIO_CLASS=CustomSX1262 + -D WRAPPER_CLASS=CustomSX1262Wrapper + -D LORA_TX_POWER=22 + -D SX126X_CURRENT_LIMIT=130 + +[env:Faketec_Repeater] +extends = faketec +build_src_filter = ${faketec.build_src_filter} +<../examples/simple_repeater/main.cpp> +build_flags = + ${faketec.build_flags} + -D ADVERT_NAME="\"Faketec Repeater\"" + -D ADVERT_LAT=-37.0 + -D ADVERT_LON=145.0 + -D ADMIN_PASSWORD="\"password\"" +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +lib_deps = + ${faketec.lib_deps} + adafruit/RTClib @ ^2.1.3 + +[env:Faketec_room_server] +extends = faketec +build_src_filter = ${faketec.build_src_filter} +<../examples/simple_room_server/main.cpp> +build_flags = + ${faketec.build_flags} + -D ADVERT_NAME="\"Test Room\"" + -D ADVERT_LAT=-37.0 + -D ADVERT_LON=145.0 + -D ADMIN_PASSWORD="\"password\"" + -D ROOM_PASSWORD="\"hello\"" +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +lib_deps = + ${faketec.lib_deps} + adafruit/RTClib @ ^2.1.3 + +[env:Faketec_terminal_chat] +extends = faketec +build_flags = + ${faketec.build_flags} + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=1 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${faketec.build_src_filter} +<../examples/simple_secure_chat/main.cpp> +lib_deps = + ${faketec.lib_deps} + densaugeo/base64 @ ~1.4.0 + adafruit/RTClib @ ^2.1.3 + +[env:Faketec_companion_radio_usb] +extends = faketec +build_flags = + ${faketec.build_flags} + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=1 +; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 +; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1 +build_src_filter = ${faketec.build_src_filter} +<../examples/companion_radio/main.cpp> +lib_deps = + ${faketec.lib_deps} + adafruit/RTClib @ ^2.1.3 + densaugeo/base64 @ ~1.4.0 + +[env:Faketec_companion_radio_ble] +extends = faketec +build_flags = + ${faketec.build_flags} + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=1 + -D BLE_PIN_CODE=123456 + -D BLE_DEBUG_LOGGING=1 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${faketec.build_src_filter} + +<../examples/companion_radio/main.cpp> +lib_deps = + ${faketec.lib_deps} + adafruit/RTClib @ ^2.1.3 + densaugeo/base64 @ ~1.4.0 \ No newline at end of file diff --git a/src/helpers/nrf52/faketecBoard.cpp b/src/helpers/nrf52/faketecBoard.cpp new file mode 100644 index 0000000..6ef294b --- /dev/null +++ b/src/helpers/nrf52/faketecBoard.cpp @@ -0,0 +1,63 @@ +#include +#include "faketecBoard.h" + +#include +#include + +static BLEDfu bledfu; + +static void connect_callback(uint16_t conn_handle) +{ + (void)conn_handle; + MESH_DEBUG_PRINTLN("BLE client connected"); +} + +static void disconnect_callback(uint16_t conn_handle, uint8_t reason) +{ + (void)conn_handle; + (void)reason; + + MESH_DEBUG_PRINTLN("BLE client disconnected"); +} + +bool faketecBoard::startOTAUpdate() { + // Config the peripheral connection with maximum bandwidth + // more SRAM required by SoftDevice + // Note: All config***() function must be called before begin() + Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); + Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); + + Bluefruit.begin(1, 0); + // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 + Bluefruit.setTxPower(4); + // Set the BLE device name + Bluefruit.setName("Faketec_OTA"); + + Bluefruit.Periph.setConnectCallback(connect_callback); + Bluefruit.Periph.setDisconnectCallback(disconnect_callback); + + // To be consistent OTA DFU should be added first if it exists + bledfu.begin(); + + // Set up and start advertising + // Advertising packet + Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); + Bluefruit.Advertising.addTxPower(); + Bluefruit.Advertising.addName(); + + /* Start Advertising + - Enable auto advertising if disconnected + - Interval: fast mode = 20 ms, slow mode = 152.5 ms + - Timeout for fast mode is 30 seconds + - Start(timeout) with timeout = 0 will advertise forever (until connected) + + For recommended advertising interval + https://developer.apple.com/library/content/qa/qa1931/_index.html + */ + Bluefruit.Advertising.restartOnDisconnect(true); + Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms + Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode + Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds + + return true; +} diff --git a/src/helpers/nrf52/faketecBoard.h b/src/helpers/nrf52/faketecBoard.h new file mode 100644 index 0000000..42ea37d --- /dev/null +++ b/src/helpers/nrf52/faketecBoard.h @@ -0,0 +1,61 @@ +#pragma once + +#include +#include + +#define P_LORA_NSS D13 +#define P_LORA_DIO_1 D11 +#define P_LORA_RESET D10 +#define P_LORA_BUSY D16 +#define P_LORA_MISO D15 +#define P_LORA_SCLK D12 +#define P_LORA_MOSI D14 +#define SX126X_POWER_EN EXT_VCC + +#define SX126X_DIO2_AS_RF_SWITCH true +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 + +#define PIN_VBAT_READ PIN_A2 +#define ADC_MULTIPLIER (1.815) // dependent on voltage divider resistors. TODO: more accurate battery tracking + +class faketecBoard : public mesh::MainBoard { +protected: + uint8_t startup_reason; + +public: + void begin() { + // for future use, sub-classes SHOULD call this from their begin() + startup_reason = BD_STARTUP_NORMAL; + + pinMode(PIN_VBAT_READ, INPUT); + + pinMode(SX126X_POWER_EN, OUTPUT); + digitalWrite(SX126X_POWER_EN, HIGH); + delay(10); // give sx1262 some time to power up + } + + uint8_t getStartupReason() const override { return startup_reason; } + + #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 (ADC_MULTIPLIER * raw); + } + + const char* getManufacturerName() const override { + return "Faketec DIY"; + } + + void reboot() override { + NVIC_SystemReset(); + } + + bool startOTAUpdate() override; +}; diff --git a/variants/supermini_nrf52840/variant.cpp b/variants/supermini_nrf52840/variant.cpp new file mode 100644 index 0000000..2e832f3 --- /dev/null +++ b/variants/supermini_nrf52840/variant.cpp @@ -0,0 +1,52 @@ +#include "variant.h" +#include "wiring_constants.h" +#include "wiring_digital.h" +#include "nrf.h" + +const uint32_t g_ADigitalPinMap[] = +{ + // D0 - D9 (left side, top to bottom) + 6, // D0 is P0.06 (D0, TX) + 8, // D1 is P0.08 (D1, RX) + 17, // D2 is P0.17 (D2, SCK) + 20, // D3 is P0.20 (D3, MISO) + 22, // D4 is P0.22 (D4, MOSI) + 24, // D5 is P0.24 (D5, CS) + 32, // D6 is P1.00 (D6, SDA) + 11, // D7 is P0.11 (D7, SCL) + 36, // D8 is P1.04 (D8) + 38, // D9 is P1.06 (D9) + + // D10 - D17 (right side, bottom to top) + 9, // D10 is P0.09 (D10, NFC1) + 10, // D11 is P0.10 (D11, NFC2) + 43, // D12 is P1.11 (D12) + 45, // D13 is P1.13 (D13, SDA1) + 47, // D14 is P1.15 (D14, SCL1) + 2, // D15 is P0.02 (D15, A0) + 29, // D16 is P0.29 (D16, A1) + 31, // D17 is P0.31 (D17, A2) + + // D18 - D20 (extra center pins, left to right) + 33, // D18 is P1.01 (D18, SCK1) + 34, // D19 is P1.02 (D19, MISO1) + 39, // D20 is P1.07 (D20, MOSI1) + + // EXT_VCC + 13, // 'D21' is P0.13 (EXT_VCC) [active high] + + // LED + 15, // 'D22' is P0.15 (LED) +}; + +void initVariant() +{ + // enable EXT_VCC by default + pinMode(EXT_VCC, OUTPUT); + digitalWrite(EXT_VCC, HIGH); + + // enable LED by default + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, HIGH); +} + diff --git a/variants/supermini_nrf52840/variant.h b/variants/supermini_nrf52840/variant.h new file mode 100644 index 0000000..b7b59c8 --- /dev/null +++ b/variants/supermini_nrf52840/variant.h @@ -0,0 +1,176 @@ +#ifndef _SUPERMINI_NRF52840_H_ +#define _SUPERMINI_NRF52840_H_ + +#define TARGET_SUPERMINI_NRF52840 + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +//#define USE_LFXO // Board uses 32khz crystal for LF +#define USE_LFRC // Board uses RC for LF + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "WVariant.h" + +#ifdef __cplusplus +extern "C" +{ +#endif // __cplusplus + +#define PINS_COUNT (23) +#define NUM_DIGITAL_PINS (23) +#define NUM_ANALOG_INPUTS (3) +#define NUM_ANALOG_OUTPUTS (0) + +// NOTE: +// +// BATTERY VOLTAGE IS READ VIA VDDH/5 BY CALLING +// +// analogReadVDDHDIV5() // returns uint32_t + +// 3V3 Regulator Disable +#define PIN_EXT_VCC (21) // EXT_VCC is P0.13 (set low to disable 3v3) +#define EXT_VCC (PIN_EXT_VCC) + +// LEDs +#define PIN_LED (22) // USR LED is P0.15 +#define LED_PWR (PINS_COUNT) // no LED_PWR +#define PIN_NEOPIXEL (PINS_COUNT) // no neopixel +#define NEOPIXEL_NUM 0 +#define LED_BLUE PIN_LED // required by bluefruit library + +#define LED_BUILTIN PIN_LED + +#define LED_STATE_ON 1 // State when LED is on + +/* + * Buttons + */ +#define PIN_BUTTON1 (PINS_COUNT) // no button + +// Digital PINs +// NOTE: THIS IS A RENUMBERING OF THE PINS +// AND DOES NOT CORRESPOND TO THE NICENANO DIAGRAM + +// left side (top to bottom) +#define D0 (0ul) // P0.06 (TX) +#define D1 (1ul) // P0.08 (RX) +#define D2 (2ul) // P0.17 (SCK) +#define D3 (3ul) // P0.20 (MISO) +#define D4 (4ul) // P0.22 (MOSI) +#define D5 (5ul) // P0.24 (CS) +#define D6 (6ul) // P1.00 (SDA) +#define D7 (7ul) // P0.11 (SCL) +#define D8 (8ul) // P1.04 +#define D9 (9ul) // P1.06 + +// right side (bottom to top) +#define D10 (10ul) // P0.09 (NFC1) +#define D11 (11ul) // P0.10 (NFC2) +#define D12 (12ul) // P1.11 +#define D13 (13ul) // P1.13 (SDA1) +#define D14 (14ul) // P1.15 (SCL1) +#define D15 (15ul) // P0.02/AIN0 (A0) +#define D16 (16ul) // P0.29/AIN6 (A1) +#define D17 (17ul) // P0.31/AIN7 (A2) + +// extra center pins (left to right) +#define D18 (18ul) // P1.01 (SCK1) +#define D19 (19ul) // P1.02 (MISO1) +#define D20 (20ul) // P1.07 (MOSI1) + +/* + * Macros for nRF pin numbers for compatibility + */ +#define P0_06 (D0) +#define P0_08 (D1) +#define P0_17 (D2) +#define P0_20 (D3) +#define P0_22 (D4) +#define P0_24 (D5) +#define P1_00 (D6) +#define P0_11 (D7) +#define P1_04 (D8) +#define P1_06 (D9) +#define P0_09 (D10) +#define P0_10 (D11) +#define P1_11 (D12) +#define P1_13 (D13) +#define P1_15 (D14) +#define P0_02 (D15) +#define P0_29 (D16) +#define P0_31 (D17) +#define P1_01 (D18) +#define P1_02 (D19) +#define P1_07 (D20) +#define P0_13 (EXT_VCC) +#define P0_15 (PIN_LED) + +/* + * Analog pins + */ +#define PIN_A0 (15) // P0.02 (D15) +#define PIN_A1 (16) // P0.29 (D16) +#define PIN_A2 (17) // P0.31 (D17) + +static const uint8_t A0 = PIN_A0 ; +static const uint8_t A1 = PIN_A1 ; +static const uint8_t A2 = PIN_A2 ; +#define ADC_RESOLUTION 12 + +/* + * Other pins + */ +#define PIN_NFC1 (10) // P0.09 - also D10 +#define PIN_NFC2 (11) // P0.10 - also D11 + +/* + * Serial interfaces + */ +#define PIN_SERIAL1_TX (0) // P0.06 - also D0 +#define PIN_SERIAL1_RX (1) // P0.08 - also D1 + +/* + * SPI Interfaces + */ +#define SPI_INTERFACES_COUNT 2 + +#define PIN_SPI_SCK (2) // P0.17 - D2 +#define PIN_SPI_MISO (3) // P0.20 - D3 +#define PIN_SPI_MOSI (4) // P0.22 - D4 + +static const uint8_t SS = (5); // P0.24 - D5 +static const uint8_t MOSI = PIN_SPI_MOSI ; +static const uint8_t MISO = PIN_SPI_MISO ; +static const uint8_t SCK = PIN_SPI_SCK ; + +#define PIN_SPI1_SCK (18) // P1.01 - D18 +#define PIN_SPI1_MISO (19) // P1.02 - D19 +#define PIN_SPI1_MOSI (20) // P1.07 - D20 + +/* + * Wire Interfaces + */ +#define WIRE_INTERFACES_COUNT 2 + +#define PIN_WIRE_SDA (6) // P1.00 - D6 +#define PIN_WIRE_SCL (7) // P0.11 - D7 + +static const uint8_t SDA = PIN_WIRE_SDA; +static const uint8_t SCL = PIN_WIRE_SCL; + +#define PIN_WIRE1_SDA (13) // P1.13 - D13 +#define PIN_WIRE1_SCL (14) // P1.15 - D14 + +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#endif From a57053207f98464edd0cc1bd786a4d8fd6385ef6 Mon Sep 17 00:00:00 2001 From: taco Date: Tue, 25 Feb 2025 16:20:35 +1100 Subject: [PATCH 05/19] Added defines for SX126X_RXEN, SX126X_TXEN. Updated build target to enable privkey import/export. --- platformio.ini | 2 ++ src/helpers/nrf52/faketecBoard.h | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/platformio.ini b/platformio.ini index a1e154c..a3abb38 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1030,6 +1030,8 @@ build_flags = -D BLE_DEBUG_LOGGING=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 + -D ENABLE_PRIVATE_KEY_EXPORT=1 + -D ENABLE_PRIVATE_KEY_IMPORT=1 build_src_filter = ${faketec.build_src_filter} + +<../examples/companion_radio/main.cpp> lib_deps = ${faketec.lib_deps} diff --git a/src/helpers/nrf52/faketecBoard.h b/src/helpers/nrf52/faketecBoard.h index 42ea37d..5e6e86c 100644 --- a/src/helpers/nrf52/faketecBoard.h +++ b/src/helpers/nrf52/faketecBoard.h @@ -3,20 +3,21 @@ #include #include -#define P_LORA_NSS D13 -#define P_LORA_DIO_1 D11 -#define P_LORA_RESET D10 -#define P_LORA_BUSY D16 -#define P_LORA_MISO D15 -#define P_LORA_SCLK D12 -#define P_LORA_MOSI D14 -#define SX126X_POWER_EN EXT_VCC - +#define P_LORA_NSS D13 //P1.13 45 +#define P_LORA_DIO_1 D11 //P0.10 10 +#define P_LORA_RESET D10 //P0.09 9 +#define P_LORA_BUSY D16 //P0.29 29 +#define P_LORA_MISO D15 //P0.02 2 +#define P_LORA_SCLK D12 //P1.11 43 +#define P_LORA_MOSI D14 //P1.15 47 +#define SX126X_POWER_EN EXT_VCC //P0.13 13 +#define SX126X_RXEN D2 //P0.17 +#define SX126X_TXEN RADIOLIB_NC #define SX126X_DIO2_AS_RF_SWITCH true -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#define SX126X_DIO3_TCXO_VOLTAGE (1.8f) #define PIN_VBAT_READ PIN_A2 -#define ADC_MULTIPLIER (1.815) // dependent on voltage divider resistors. TODO: more accurate battery tracking +#define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking class faketecBoard : public mesh::MainBoard { protected: From 027b7d83cb45c8f35c44fecd345535040f70234f Mon Sep 17 00:00:00 2001 From: taco Date: Tue, 25 Feb 2025 16:35:54 +1100 Subject: [PATCH 06/19] Added logic to companion_radio firmware to hopefully fix the radio bringup for Faketec with RA01-SH. --- examples/companion_radio/main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 75dbfba..97ee2e6 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -1263,6 +1263,13 @@ void setup() { spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI); #endif int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); +#if defined(FAKETEC) + if (status == RADIOLIB_ERR_SPI_CMD_FAILED || status == RADIOLIB_ERR_SPI_CMD_INVALID) { + #define SX126X_DIO3_TCXO_VOLTAGE (0.0f); + tcxo = SX126X_DIO3_TCXO_VOLTAGE; + status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); + } +#endif if (status != RADIOLIB_ERR_NONE) { Serial.print("ERROR: radio init failed: "); Serial.println(status); From c1faaf5e828c333f8bab79abdc17d023140a96ba Mon Sep 17 00:00:00 2001 From: taco Date: Fri, 28 Feb 2025 12:07:16 +1100 Subject: [PATCH 07/19] build fix to support RTC detection code --- src/helpers/nrf52/faketecBoard.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/helpers/nrf52/faketecBoard.h b/src/helpers/nrf52/faketecBoard.h index 5e6e86c..cd4a73f 100644 --- a/src/helpers/nrf52/faketecBoard.h +++ b/src/helpers/nrf52/faketecBoard.h @@ -2,6 +2,7 @@ #include #include +#include #define P_LORA_NSS D13 //P1.13 45 #define P_LORA_DIO_1 D11 //P0.10 10 @@ -30,6 +31,12 @@ public: pinMode(PIN_VBAT_READ, INPUT); + #if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL) + Wire.begin(PIN_BOARD_SDA, PIN_BOARD_SCL); + #else + Wire.begin(); + #endif + pinMode(SX126X_POWER_EN, OUTPUT); digitalWrite(SX126X_POWER_EN, HIGH); delay(10); // give sx1262 some time to power up From 92bb6a844fd205f1c3ba3ed9f27b4aa4561c4cf6 Mon Sep 17 00:00:00 2001 From: taco Date: Sun, 2 Mar 2025 11:31:57 +1100 Subject: [PATCH 08/19] added conditional to radio bringup for RA01-SH support on faketec --- examples/simple_repeater/main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 3f57e81..7b8dff8 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -686,6 +686,13 @@ void setup() { spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI); #endif int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); +#if defined(FAKETEC) + if (status == RADIOLIB_ERR_SPI_CMD_FAILED || status == RADIOLIB_ERR_SPI_CMD_INVALID) { + #define SX126X_DIO3_TCXO_VOLTAGE (0.0f); + tcxo = SX126X_DIO3_TCXO_VOLTAGE; + status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); + } +#endif if (status != RADIOLIB_ERR_NONE) { delay(5000); Serial.print("ERROR: radio init failed: "); From 1a21a08845b1d89476fe97152592eb79bf74b515 Mon Sep 17 00:00:00 2001 From: taco Date: Tue, 11 Mar 2025 15:38:37 +1100 Subject: [PATCH 09/19] updated to MIT licensed board variant --- boards/promicro_nrf52840.json | 78 +++++++++++ platformio.ini | 3 +- src/helpers/nrf52/faketecBoard.h | 20 +-- variants/promicro_nrf52840/variant.cpp | 15 ++ variants/promicro_nrf52840/variant.h | 82 +++++++++++ variants/supermini_nrf52840/variant.cpp | 52 ------- variants/supermini_nrf52840/variant.h | 176 ------------------------ 7 files changed, 186 insertions(+), 240 deletions(-) create mode 100644 boards/promicro_nrf52840.json create mode 100644 variants/promicro_nrf52840/variant.cpp create mode 100644 variants/promicro_nrf52840/variant.h delete mode 100644 variants/supermini_nrf52840/variant.cpp delete mode 100644 variants/supermini_nrf52840/variant.h diff --git a/boards/promicro_nrf52840.json b/boards/promicro_nrf52840.json new file mode 100644 index 0000000..346f0f2 --- /dev/null +++ b/boards/promicro_nrf52840.json @@ -0,0 +1,78 @@ +{ + "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": "ProMicro NRF52840", + "mcu": "nrf52840", + "variant": "promicro_nrf52840", + "variants_dir": "variants", + "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" + }, + "frameworks": [ + "arduino", + "zephyr" + ], + "name": "ProMicro NRF52840", + "upload": { + "maximum_ram_size": 248832, + "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://www.nologo.tech/en/product/otherboard/NRF52840.html", + "vendor": "Nologo" + } \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index a3abb38..5e22eb5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -951,8 +951,7 @@ lib_deps = [faketec] extends = nrf52840_base -board = supermini_nrf52840 -#board_check = true +board = promicro_nrf52840 build_src_filter = ${nrf52840_base.build_src_filter} + build_flags = ${nrf52840_base.build_flags} -D FAKETEC diff --git a/src/helpers/nrf52/faketecBoard.h b/src/helpers/nrf52/faketecBoard.h index cd4a73f..b5cebb7 100644 --- a/src/helpers/nrf52/faketecBoard.h +++ b/src/helpers/nrf52/faketecBoard.h @@ -4,20 +4,20 @@ #include #include -#define P_LORA_NSS D13 //P1.13 45 -#define P_LORA_DIO_1 D11 //P0.10 10 -#define P_LORA_RESET D10 //P0.09 9 -#define P_LORA_BUSY D16 //P0.29 29 -#define P_LORA_MISO D15 //P0.02 2 -#define P_LORA_SCLK D12 //P1.11 43 -#define P_LORA_MOSI D14 //P1.15 47 -#define SX126X_POWER_EN EXT_VCC //P0.13 13 -#define SX126X_RXEN D2 //P0.17 +#define P_LORA_NSS 13 //P1.13 45 +#define P_LORA_DIO_1 11 //P0.10 10 +#define P_LORA_RESET 10 //P0.09 9 +#define P_LORA_BUSY 16 //P0.29 29 +#define P_LORA_MISO 15 //P0.02 2 +#define P_LORA_SCLK 12 //P1.11 43 +#define P_LORA_MOSI 14 //P1.15 47 +#define SX126X_POWER_EN 21 //P0.13 13 +#define SX126X_RXEN 2 //P0.17 #define SX126X_TXEN RADIOLIB_NC #define SX126X_DIO2_AS_RF_SWITCH true #define SX126X_DIO3_TCXO_VOLTAGE (1.8f) -#define PIN_VBAT_READ PIN_A2 +#define PIN_VBAT_READ 17 #define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking class faketecBoard : public mesh::MainBoard { diff --git a/variants/promicro_nrf52840/variant.cpp b/variants/promicro_nrf52840/variant.cpp new file mode 100644 index 0000000..0a4c3aa --- /dev/null +++ b/variants/promicro_nrf52840/variant.cpp @@ -0,0 +1,15 @@ +#include "variant.h" +#include "wiring_constants.h" +#include "wiring_digital.h" + +const uint32_t g_ADigitalPinMap[] = { + 8, 6, 17, 20, 22, 24, 32, 11, 36, 38, + 9, 10, 43, 45, 47, 2, 29, 31, + 33, 34, 37, + 13, 15 +}; + +void initVariant() +{ +} + diff --git a/variants/promicro_nrf52840/variant.h b/variants/promicro_nrf52840/variant.h new file mode 100644 index 0000000..98489da --- /dev/null +++ b/variants/promicro_nrf52840/variant.h @@ -0,0 +1,82 @@ +/* + * variant.h + * Copyright (C) 2023 Seeed K.K. + * MIT License + */ + + #pragma once + + #include "WVariant.h" + + //////////////////////////////////////////////////////////////////////////////// + // Low frequency clock source + +#define VARIANT_MCK (64000000ul) + +//#define USE_LFXO // 32.768 kHz crystal oscillator +#define USE_LFRC // 32.768 kHz RC oscillator + +//////////////////////////////////////////////////////////////////////////////// +// Power + +#define PIN_EXT_VCC (21) +#define EXT_VCC (PIN_EXT_VCC) + +#define BATTERY_PIN (17) +#define ADC_RESOLUTION 12 + +//////////////////////////////////////////////////////////////////////////////// +// Number of pins + +#define PINS_COUNT (23) +#define NUM_DIGITAL_PINS (23) +#define NUM_ANALOG_INPUTS (3) +#define NUM_ANALOG_OUTPUTS (0) + +//////////////////////////////////////////////////////////////////////////////// +// UART pin definition + +#define PIN_SERIAL1_TX (1) +#define PIN_SERIAL1_RX (0) + +//////////////////////////////////////////////////////////////////////////////// +// I2C pin definition + +#define WIRE_INTERFACES_COUNT 2 + +#define PIN_WIRE_SDA (6) +#define PIN_WIRE_SCL (7) +#define PIN_WIRE1_SDA (13) +#define PIN_WIRE1_SCL (14) + +//////////////////////////////////////////////////////////////////////////////// +// SPI pin definition + +#define SPI_INTERFACES_COUNT 2 + +#define PIN_SPI_SCK (2) +#define PIN_SPI_MISO (3) +#define PIN_SPI_MOSI (4) + +#define PIN_SPI_NSS (5) + +#define PIN_SPI1_SCK (18) +#define PIN_SPI1_MISO (19) +#define PIN_SPI1_MOSI (20) + +//////////////////////////////////////////////////////////////////////////////// +// Builtin LEDs + +#define PIN_LED (22) +#define LED_PIN PIN_LED +#define LED_BLUE PIN_LED +#define LED_BUILTIN PIN_LED +#define LED_STATE_ON 1 + +//////////////////////////////////////////////////////////////////////////////// +// Builtin buttons + +#define PIN_BUTTON1 (6) +#define BUTTON_PIN PIN_BUTTON1 + + diff --git a/variants/supermini_nrf52840/variant.cpp b/variants/supermini_nrf52840/variant.cpp deleted file mode 100644 index 2e832f3..0000000 --- a/variants/supermini_nrf52840/variant.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "variant.h" -#include "wiring_constants.h" -#include "wiring_digital.h" -#include "nrf.h" - -const uint32_t g_ADigitalPinMap[] = -{ - // D0 - D9 (left side, top to bottom) - 6, // D0 is P0.06 (D0, TX) - 8, // D1 is P0.08 (D1, RX) - 17, // D2 is P0.17 (D2, SCK) - 20, // D3 is P0.20 (D3, MISO) - 22, // D4 is P0.22 (D4, MOSI) - 24, // D5 is P0.24 (D5, CS) - 32, // D6 is P1.00 (D6, SDA) - 11, // D7 is P0.11 (D7, SCL) - 36, // D8 is P1.04 (D8) - 38, // D9 is P1.06 (D9) - - // D10 - D17 (right side, bottom to top) - 9, // D10 is P0.09 (D10, NFC1) - 10, // D11 is P0.10 (D11, NFC2) - 43, // D12 is P1.11 (D12) - 45, // D13 is P1.13 (D13, SDA1) - 47, // D14 is P1.15 (D14, SCL1) - 2, // D15 is P0.02 (D15, A0) - 29, // D16 is P0.29 (D16, A1) - 31, // D17 is P0.31 (D17, A2) - - // D18 - D20 (extra center pins, left to right) - 33, // D18 is P1.01 (D18, SCK1) - 34, // D19 is P1.02 (D19, MISO1) - 39, // D20 is P1.07 (D20, MOSI1) - - // EXT_VCC - 13, // 'D21' is P0.13 (EXT_VCC) [active high] - - // LED - 15, // 'D22' is P0.15 (LED) -}; - -void initVariant() -{ - // enable EXT_VCC by default - pinMode(EXT_VCC, OUTPUT); - digitalWrite(EXT_VCC, HIGH); - - // enable LED by default - pinMode(LED_BUILTIN, OUTPUT); - digitalWrite(LED_BUILTIN, HIGH); -} - diff --git a/variants/supermini_nrf52840/variant.h b/variants/supermini_nrf52840/variant.h deleted file mode 100644 index b7b59c8..0000000 --- a/variants/supermini_nrf52840/variant.h +++ /dev/null @@ -1,176 +0,0 @@ -#ifndef _SUPERMINI_NRF52840_H_ -#define _SUPERMINI_NRF52840_H_ - -#define TARGET_SUPERMINI_NRF52840 - -/** Master clock frequency */ -#define VARIANT_MCK (64000000ul) - -//#define USE_LFXO // Board uses 32khz crystal for LF -#define USE_LFRC // Board uses RC for LF - -/*---------------------------------------------------------------------------- - * Headers - *----------------------------------------------------------------------------*/ - -#include "WVariant.h" - -#ifdef __cplusplus -extern "C" -{ -#endif // __cplusplus - -#define PINS_COUNT (23) -#define NUM_DIGITAL_PINS (23) -#define NUM_ANALOG_INPUTS (3) -#define NUM_ANALOG_OUTPUTS (0) - -// NOTE: -// -// BATTERY VOLTAGE IS READ VIA VDDH/5 BY CALLING -// -// analogReadVDDHDIV5() // returns uint32_t - -// 3V3 Regulator Disable -#define PIN_EXT_VCC (21) // EXT_VCC is P0.13 (set low to disable 3v3) -#define EXT_VCC (PIN_EXT_VCC) - -// LEDs -#define PIN_LED (22) // USR LED is P0.15 -#define LED_PWR (PINS_COUNT) // no LED_PWR -#define PIN_NEOPIXEL (PINS_COUNT) // no neopixel -#define NEOPIXEL_NUM 0 -#define LED_BLUE PIN_LED // required by bluefruit library - -#define LED_BUILTIN PIN_LED - -#define LED_STATE_ON 1 // State when LED is on - -/* - * Buttons - */ -#define PIN_BUTTON1 (PINS_COUNT) // no button - -// Digital PINs -// NOTE: THIS IS A RENUMBERING OF THE PINS -// AND DOES NOT CORRESPOND TO THE NICENANO DIAGRAM - -// left side (top to bottom) -#define D0 (0ul) // P0.06 (TX) -#define D1 (1ul) // P0.08 (RX) -#define D2 (2ul) // P0.17 (SCK) -#define D3 (3ul) // P0.20 (MISO) -#define D4 (4ul) // P0.22 (MOSI) -#define D5 (5ul) // P0.24 (CS) -#define D6 (6ul) // P1.00 (SDA) -#define D7 (7ul) // P0.11 (SCL) -#define D8 (8ul) // P1.04 -#define D9 (9ul) // P1.06 - -// right side (bottom to top) -#define D10 (10ul) // P0.09 (NFC1) -#define D11 (11ul) // P0.10 (NFC2) -#define D12 (12ul) // P1.11 -#define D13 (13ul) // P1.13 (SDA1) -#define D14 (14ul) // P1.15 (SCL1) -#define D15 (15ul) // P0.02/AIN0 (A0) -#define D16 (16ul) // P0.29/AIN6 (A1) -#define D17 (17ul) // P0.31/AIN7 (A2) - -// extra center pins (left to right) -#define D18 (18ul) // P1.01 (SCK1) -#define D19 (19ul) // P1.02 (MISO1) -#define D20 (20ul) // P1.07 (MOSI1) - -/* - * Macros for nRF pin numbers for compatibility - */ -#define P0_06 (D0) -#define P0_08 (D1) -#define P0_17 (D2) -#define P0_20 (D3) -#define P0_22 (D4) -#define P0_24 (D5) -#define P1_00 (D6) -#define P0_11 (D7) -#define P1_04 (D8) -#define P1_06 (D9) -#define P0_09 (D10) -#define P0_10 (D11) -#define P1_11 (D12) -#define P1_13 (D13) -#define P1_15 (D14) -#define P0_02 (D15) -#define P0_29 (D16) -#define P0_31 (D17) -#define P1_01 (D18) -#define P1_02 (D19) -#define P1_07 (D20) -#define P0_13 (EXT_VCC) -#define P0_15 (PIN_LED) - -/* - * Analog pins - */ -#define PIN_A0 (15) // P0.02 (D15) -#define PIN_A1 (16) // P0.29 (D16) -#define PIN_A2 (17) // P0.31 (D17) - -static const uint8_t A0 = PIN_A0 ; -static const uint8_t A1 = PIN_A1 ; -static const uint8_t A2 = PIN_A2 ; -#define ADC_RESOLUTION 12 - -/* - * Other pins - */ -#define PIN_NFC1 (10) // P0.09 - also D10 -#define PIN_NFC2 (11) // P0.10 - also D11 - -/* - * Serial interfaces - */ -#define PIN_SERIAL1_TX (0) // P0.06 - also D0 -#define PIN_SERIAL1_RX (1) // P0.08 - also D1 - -/* - * SPI Interfaces - */ -#define SPI_INTERFACES_COUNT 2 - -#define PIN_SPI_SCK (2) // P0.17 - D2 -#define PIN_SPI_MISO (3) // P0.20 - D3 -#define PIN_SPI_MOSI (4) // P0.22 - D4 - -static const uint8_t SS = (5); // P0.24 - D5 -static const uint8_t MOSI = PIN_SPI_MOSI ; -static const uint8_t MISO = PIN_SPI_MISO ; -static const uint8_t SCK = PIN_SPI_SCK ; - -#define PIN_SPI1_SCK (18) // P1.01 - D18 -#define PIN_SPI1_MISO (19) // P1.02 - D19 -#define PIN_SPI1_MOSI (20) // P1.07 - D20 - -/* - * Wire Interfaces - */ -#define WIRE_INTERFACES_COUNT 2 - -#define PIN_WIRE_SDA (6) // P1.00 - D6 -#define PIN_WIRE_SCL (7) // P0.11 - D7 - -static const uint8_t SDA = PIN_WIRE_SDA; -static const uint8_t SCL = PIN_WIRE_SCL; - -#define PIN_WIRE1_SDA (13) // P1.13 - D13 -#define PIN_WIRE1_SCL (14) // P1.15 - D14 - -#ifdef __cplusplus -} -#endif - -/*---------------------------------------------------------------------------- - * Arduino objects - C++ only - *----------------------------------------------------------------------------*/ - -#endif From dc4a139f88437500d37bbfa3427751352fea213c Mon Sep 17 00:00:00 2001 From: Florent de Lamotte Date: Tue, 11 Mar 2025 09:18:50 +0100 Subject: [PATCH 10/19] resolve conflict --- platformio.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index f6221c5..be098c4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -781,7 +781,6 @@ build_flags = ${nrf52840_t1000e.build_flags} -D RADIO_CLASS=CustomLR1110 -D WRAPPER_CLASS=CustomLR1110Wrapper -D MAX_LORA_TX_POWER=22 - -D LORA_TX_POWER=22 build_src_filter = ${nrf52840_t1000e.build_src_filter} + + From 9c3b4dd5208e3e1511589604c7744d6a3d1b099f Mon Sep 17 00:00:00 2001 From: taco Date: Thu, 13 Mar 2025 17:46:58 +1100 Subject: [PATCH 11/19] added SX126X_RX_BOOSTED_GAIN=1 to faketec target --- platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/platformio.ini b/platformio.ini index 7b91655..0086c2a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -970,6 +970,7 @@ build_flags = ${nrf52840_base.build_flags} -D WRAPPER_CLASS=CustomSX1262Wrapper -D LORA_TX_POWER=22 -D SX126X_CURRENT_LIMIT=130 + -D SX126X_RX_BOOSTED_GAIN=1 [env:Faketec_Repeater] extends = faketec From 5632e2771e00ab9f98160376e761ad105a89f6cf Mon Sep 17 00:00:00 2001 From: taco Date: Fri, 14 Mar 2025 15:22:42 +1100 Subject: [PATCH 12/19] added conditional to room server radio bringup for supporting RA01sh radio on faketec --- examples/simple_room_server/main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index bd4564e..e257261 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -751,6 +751,13 @@ void setup() { spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI); #endif int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); +#if defined(FAKETEC) + if (status == RADIOLIB_ERR_SPI_CMD_FAILED || status == RADIOLIB_ERR_SPI_CMD_INVALID) { + #define SX126X_DIO3_TCXO_VOLTAGE (0.0f); + tcxo = SX126X_DIO3_TCXO_VOLTAGE; + status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); + } +#endif if (status != RADIOLIB_ERR_NONE) { delay(5000); Serial.print("ERROR: radio init failed: "); From fbb879600d53331cc38f1f3e17d6ec28dc965de3 Mon Sep 17 00:00:00 2001 From: taco Date: Fri, 14 Mar 2025 15:24:58 +1100 Subject: [PATCH 13/19] MAX_GROUP_CHANNELS=8 for faketec --- platformio.ini | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/platformio.ini b/platformio.ini index 0086c2a..c6e3126 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1022,7 +1022,7 @@ extends = faketec build_flags = ${faketec.build_flags} -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=1 + -D MAX_GROUP_CHANNELS=8 ; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 ; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1 build_src_filter = ${faketec.build_src_filter} +<../examples/companion_radio/main.cpp> @@ -1036,13 +1036,13 @@ extends = faketec build_flags = ${faketec.build_flags} -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=1 + -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456 -D BLE_DEBUG_LOGGING=1 -; -D MESH_PACKET_LOGGING=1 -; -D MESH_DEBUG=1 -D ENABLE_PRIVATE_KEY_EXPORT=1 -D ENABLE_PRIVATE_KEY_IMPORT=1 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 build_src_filter = ${faketec.build_src_filter} + +<../examples/companion_radio/main.cpp> lib_deps = ${faketec.lib_deps} From 6a4b7463ef79058fe4e5248cfff39595b5ea5f6d Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Fri, 14 Mar 2025 19:08:41 +1100 Subject: [PATCH 14/19] * some fixes around the powerOff(). Tidy ups --- examples/companion_radio/UITask.cpp | 74 ++++++++++++++--------------- examples/companion_radio/UITask.h | 1 - src/MeshCore.h | 2 +- src/helpers/HeltecV3Board.h | 3 +- 4 files changed, 39 insertions(+), 41 deletions(-) diff --git a/examples/companion_radio/UITask.cpp b/examples/companion_radio/UITask.cpp index df09e26..b454d93 100644 --- a/examples/companion_radio/UITask.cpp +++ b/examples/companion_radio/UITask.cpp @@ -26,7 +26,6 @@ static const uint8_t meshcore_logo [] PROGMEM = { }; void UITask::begin(const char* node_name, const char* build_date, uint32_t pin_code) { - _prevBtnState = HIGH; _auto_off = millis() + AUTO_OFF_MILLIS; clearMsgPreview(); _node_name = node_name; @@ -66,43 +65,43 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i } void UITask::renderCurrScreen() { - if (_display != NULL) { - char tmp[80]; - if (_origin[0] && _msg[0]) { - // render message preview - _display->setCursor(0, 0); - _display->setTextSize(1); - _display->print(_node_name); + if (_display == NULL) return; // assert() ?? - _display->setCursor(0, 12); - _display->print(_origin); - _display->setCursor(0, 24); - _display->print(_msg); + char tmp[80]; + if (_origin[0] && _msg[0]) { + // render message preview + _display->setCursor(0, 0); + _display->setTextSize(1); + _display->print(_node_name); - _display->setCursor(100, 9); + _display->setCursor(0, 12); + _display->print(_origin); + _display->setCursor(0, 24); + _display->print(_msg); + + _display->setCursor(100, 9); + _display->setTextSize(2); + sprintf(tmp, "%d", _msgcount); + _display->print(tmp); + } else { + // render 'home' screen + _display->drawXbm(0, 0, meshcore_logo, 128, 13); + _display->setCursor(0, 20); + _display->setTextSize(1); + _display->print(_node_name); + + sprintf(tmp, "Build: %s", _build_date); + _display->setCursor(0, 32); + _display->print(tmp); + + if (_connected) { + //_display->printf("freq : %03.2f sf %d\n", _prefs.freq, _prefs.sf); + //_display->printf("bw : %03.2f cr %d\n", _prefs.bw, _prefs.cr); + } else if (_pin_code != 0) { _display->setTextSize(2); - sprintf(tmp, "%d", _msgcount); + _display->setCursor(0, 43); + sprintf(tmp, "Pin:%d", _pin_code); _display->print(tmp); - } else { - // render 'home' screen - _display->drawXbm(0, 0, meshcore_logo, 128, 13); - _display->setCursor(0, 20); - _display->setTextSize(1); - _display->print(_node_name); - - sprintf(tmp, "Build: %s", _build_date); - _display->setCursor(0, 32); - _display->print(tmp); - - if (_connected) { - //_display->printf("freq : %03.2f sf %d\n", _prefs.freq, _prefs.sf); - //_display->printf("bw : %03.2f cr %d\n", _prefs.bw, _prefs.cr); - } else if (_pin_code != 0) { - _display->setTextSize(2); - _display->setCursor(0, 43); - sprintf(tmp, "Pin:%d", _pin_code); - _display->print(tmp); - } } } } @@ -135,7 +134,7 @@ void UITask::userLedHandler() { void UITask::buttonHandler() { #ifdef PIN_USER_BTN - static int prev_btn_state = HIGH; + static int prev_btn_state = !USER_BTN_PRESSED; static unsigned long btn_state_change_time = 0; static unsigned long next_read = 0; int cur_time = millis(); @@ -153,11 +152,10 @@ void UITask::buttonHandler() { } } else { // unpressed ? check pressed time ... if ((cur_time - btn_state_change_time) > 5000) { - Serial.println("power off"); - #ifdef PIN_STATUS_LED + #ifdef PIN_STATUS_LED digitalWrite(PIN_STATUS_LED, LOW); delay(10); - #endif + #endif _board->powerOff(); } } diff --git a/examples/companion_radio/UITask.h b/examples/companion_radio/UITask.h index fa64532..4cea0b8 100644 --- a/examples/companion_radio/UITask.h +++ b/examples/companion_radio/UITask.h @@ -7,7 +7,6 @@ class UITask { DisplayDriver* _display; mesh::MainBoard* _board; unsigned long _next_refresh, _auto_off; - int _prevBtnState; bool _connected; uint32_t _pin_code; const char* _node_name; diff --git a/src/MeshCore.h b/src/MeshCore.h index 5f9956a..9593877 100644 --- a/src/MeshCore.h +++ b/src/MeshCore.h @@ -40,7 +40,7 @@ public: virtual void onBeforeTransmit() { } virtual void onAfterTransmit() { } virtual void reboot() = 0; - virtual void powerOff() { while (1) { }}; // hope it's overriden or never called ;) + virtual void powerOff() { /* no op */ } virtual uint8_t getStartupReason() const = 0; virtual bool startOTAUpdate() { return false; } // not supported }; diff --git a/src/helpers/HeltecV3Board.h b/src/helpers/HeltecV3Board.h index c61189f..88e4997 100644 --- a/src/helpers/HeltecV3Board.h +++ b/src/helpers/HeltecV3Board.h @@ -68,7 +68,8 @@ public: } void powerOff() override { - enterDeepSleep(0); + // TODO: re-enable this when there is a definite wake-up source pin: + // enterDeepSleep(0); } uint16_t getBattMilliVolts() override { From 6931887424cb756028c678ff9433b7800a1c7000 Mon Sep 17 00:00:00 2001 From: taco Date: Sat, 15 Mar 2025 10:54:37 +1100 Subject: [PATCH 15/19] remove old unused board.json --- boards/supermini_nrf52840.json | 78 ---------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 boards/supermini_nrf52840.json diff --git a/boards/supermini_nrf52840.json b/boards/supermini_nrf52840.json deleted file mode 100644 index 328c0c9..0000000 --- a/boards/supermini_nrf52840.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "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": "SuperMini nRF52840", - "mcu": "nrf52840", - "variant": "supermini_nrf52840", - "variants_dir": "variants", - "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" - }, - "frameworks": [ - "arduino", - "zephyr" - ], - "name": "Nologo SuperMini nRF52840", - "upload": { - "maximum_ram_size": 248832, - "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://www.nologo.tech/en/product/otherboard/NRF52840.html", - "vendor": "Nologo" - } \ No newline at end of file From 27aa7a7bb03d97da6d3a610adca39c5bb27fb620 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Sat, 15 Mar 2025 14:55:52 +1100 Subject: [PATCH 16/19] * minor refactor for RAK_4631 SerialInterface --- examples/companion_radio/main.cpp | 3 --- src/helpers/ArduinoSerialInterface.h | 7 ++++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 3411db9..4427522 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -1399,9 +1399,6 @@ void setup() { sprintf(dev_name, "%s%s", BLE_NAME_PREFIX, the_mesh.getNodeName()); serial_interface.begin(dev_name, the_mesh.getBLEPin()); #else -#ifdef RAK_4631 - pinMode(WB_IO2, OUTPUT); -#endif serial_interface.begin(Serial); #endif the_mesh.startInterface(serial_interface); diff --git a/src/helpers/ArduinoSerialInterface.h b/src/helpers/ArduinoSerialInterface.h index 43613af..e84f6d3 100644 --- a/src/helpers/ArduinoSerialInterface.h +++ b/src/helpers/ArduinoSerialInterface.h @@ -23,7 +23,12 @@ public: #ifdef LILYGO_T3S3 void begin(HWCDC& serial) { _serial = &serial; } #elif defined(NRF52_PLATFORM) - void begin(Adafruit_USBD_CDC& serial) { _serial = &serial; } + void begin(Adafruit_USBD_CDC& serial) { + _serial = &serial; + #ifdef RAK_4631 + pinMode(WB_IO2, OUTPUT); + #endif + } #else void begin(HardwareSerial& serial) { _serial = &serial; } #endif From 6056c303c10385155d501862f8563c20d8ab67ea Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Sat, 15 Mar 2025 21:41:44 +1100 Subject: [PATCH 17/19] * companion: can now sign arbitrary data (up to 8K) --- examples/companion_radio/main.cpp | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 4427522..f4c52b9 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -171,6 +171,9 @@ static uint32_t _atoi(const char* sp) { #define CMD_GET_CONTACT_BY_KEY 30 #define CMD_GET_CHANNEL 31 #define CMD_SET_CHANNEL 32 +#define CMD_SIGN_START 33 +#define CMD_SIGN_DATA 34 +#define CMD_SIGN_FINISH 35 #define RESP_CODE_OK 0 #define RESP_CODE_ERR 1 @@ -190,6 +193,8 @@ static uint32_t _atoi(const char* sp) { #define RESP_CODE_DISABLED 15 // ... _V3 stuff in here #define RESP_CODE_CHANNEL_INFO 18 // a reply to CMD_GET_CHANNEL +#define RESP_CODE_SIGN_START 19 +#define RESP_CODE_SIGNATURE 20 // these are _pushed_ to client app at any time #define PUSH_CODE_ADVERT 0x80 @@ -204,6 +209,8 @@ static uint32_t _atoi(const char* sp) { /* -------------------------------------------------------------------------------------- */ +#define MAX_SIGN_DATA_LEN (8*1024) // 8K + struct NodePrefs { // persisted to file float airtime_factor; char node_name[32]; @@ -236,6 +243,8 @@ class MyMesh : public BaseChatMesh { uint32_t _active_ble_pin; bool _iter_started; uint8_t app_target_ver; + uint8_t* sign_data; + uint32_t sign_data_len; uint8_t cmd_frame[MAX_FRAME_SIZE+1]; uint8_t out_frame[MAX_FRAME_SIZE+1]; @@ -696,6 +705,7 @@ public: app_target_ver = 0; _identity_store = NULL; pending_login = pending_status = 0; + sign_data = NULL; // defaults memset(&_prefs, 0, sizeof(_prefs)); @@ -1259,6 +1269,38 @@ public: } else { writeErrFrame(); } + } else if (cmd_frame[0] == CMD_SIGN_START) { + out_frame[0] = RESP_CODE_SIGN_START; + out_frame[1] = 0; // reserved + uint32_t len = MAX_SIGN_DATA_LEN; + memcpy(&out_frame[2], &len, 4); + _serial->writeFrame(out_frame, 6); + + if (sign_data) { + free(sign_data); + } + sign_data = (uint8_t *) malloc(MAX_SIGN_DATA_LEN); + sign_data_len = 0; + } else if (cmd_frame[0] == CMD_SIGN_DATA && len > 1) { + if (sign_data_len + (len - 1) > MAX_SIGN_DATA_LEN) { + writeErrFrame(); // error: too long + } else { + memcpy(&sign_data[sign_data_len], &cmd_frame[1], len - 1); + sign_data_len += (len - 1); + writeOKFrame(); + } + } else if (cmd_frame[0] == CMD_SIGN_FINISH) { + if (sign_data) { + self_id.sign(&out_frame[1], sign_data, sign_data_len); + + free(sign_data); // don't need sign_data now + sign_data = NULL; + + out_frame[0] = RESP_CODE_SIGNATURE; + _serial->writeFrame(out_frame, 1 + SIGNATURE_SIZE); + } else { + writeErrFrame(); + } } else { writeErrFrame(); MESH_DEBUG_PRINTLN("ERROR: unknown command: %02X", cmd_frame[0]); From 31f8576640e9e5f4b7d16bc87acd6fc2725700fe Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Sat, 15 Mar 2025 22:06:57 +1100 Subject: [PATCH 18/19] * CMD_SIGN_DATA null check --- examples/companion_radio/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index f4c52b9..3733470 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -1282,7 +1282,7 @@ public: sign_data = (uint8_t *) malloc(MAX_SIGN_DATA_LEN); sign_data_len = 0; } else if (cmd_frame[0] == CMD_SIGN_DATA && len > 1) { - if (sign_data_len + (len - 1) > MAX_SIGN_DATA_LEN) { + if (sign_data == NULL || sign_data_len + (len - 1) > MAX_SIGN_DATA_LEN) { writeErrFrame(); // error: too long } else { memcpy(&sign_data[sign_data_len], &cmd_frame[1], len - 1); From 7ee81f4f07e075d1008d3e18c87f09f6ada540a9 Mon Sep 17 00:00:00 2001 From: recrof Date: Sat, 15 Mar 2025 13:07:18 +0100 Subject: [PATCH 19/19] added display support for t3s3 --- examples/simple_room_server/main.cpp | 2 +- platformio.ini | 60 +++++++++++++++++++++------- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index e257261..eb69bf5 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -76,7 +76,7 @@ #include #include static XiaoC3Board board; -#elif defined(SEEED_XIAO_S3) +#elif defined(SEEED_XIAO_S3) || defined(LILYGO_T3S3) #include #include static ESP32Board board; diff --git a/platformio.ini b/platformio.ini index 2b11856..fe008c5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -130,7 +130,7 @@ build_flags = build_src_filter = ${esp32_base.build_src_filter} lib_deps = ${esp32_base.lib_deps} - adafruit/Adafruit SSD1306 @ ^2.5.13 + adafruit/Adafruit SSD1306 @ ^2.5.13 [env:Heltec_v3_repeater] extends = Heltec_lora32_v3 @@ -149,9 +149,6 @@ build_src_filter = ${Heltec_lora32_v3.build_src_filter} [env:Heltec_v3_room_server] extends = Heltec_lora32_v3 -build_src_filter = ${Heltec_lora32_v3.build_src_filter} - + - +<../examples/simple_room_server> build_flags = ${Heltec_lora32_v3.build_flags} -D DISPLAY_CLASS=SSD1306Display @@ -162,6 +159,9 @@ build_flags = -D ROOM_PASSWORD='"hello"' ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 +build_src_filter = ${Heltec_lora32_v3.build_src_filter} + + + +<../examples/simple_room_server> [env:Heltec_v3_terminal_chat] extends = Heltec_lora32_v3 @@ -522,7 +522,8 @@ build_flags = [LilyGo_T3S3_sx1262] extends = esp32_base board = t3_s3_v1_x -build_flags = ${esp32_base.build_flags} +build_flags = + ${esp32_base.build_flags} -D LILYGO_T3S3 -D P_LORA_DIO_1=33 -D P_LORA_NSS=7 @@ -533,6 +534,11 @@ build_flags = ${esp32_base.build_flags} -D P_LORA_MOSI=6 -D P_LORA_TX_LED=37 -D PIN_VBAT_READ=1 + -D PIN_USER_BTN=0 + -D PIN_BOARD_SDA=18 + -D PIN_BOARD_SCL=17 + -D P_LORA_TX_LED=37 + -D PIN_OLED_RESET=21 -D SX126X_DIO2_AS_RF_SWITCH=true -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_CURRENT_LIMIT=130 @@ -540,20 +546,26 @@ build_flags = ${esp32_base.build_flags} -D WRAPPER_CLASS=CustomSX1262Wrapper -D LORA_TX_POWER=22 -D SX126X_RX_BOOSTED_GAIN=1 +build_src_filter = ${esp32_base.build_src_filter} +lib_deps = + ${esp32_base.lib_deps} + adafruit/Adafruit SSD1306 @ ^2.5.13 ; === LilyGo T3S3 with SX1262 environments === [env:LilyGo_T3S3_sx1262_Repeater] extends = LilyGo_T3S3_sx1262 -build_src_filter = ${LilyGo_T3S3_sx1262.build_src_filter} - +<../examples/simple_repeater/main.cpp> build_flags = ${LilyGo_T3S3_sx1262.build_flags} + -D DISPLAY_CLASS=SSD1306Display -D ADVERT_NAME='"T3S3-1262 Repeater"' -D ADVERT_LAT=-37.0 -D ADVERT_LON=145.0 -D ADMIN_PASSWORD='"password"' ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 +build_src_filter = ${LilyGo_T3S3_sx1262.build_src_filter} + + + +<../examples/simple_repeater> [env:LilyGo_T3S3_sx1262_terminal_chat] extends = LilyGo_T3S3_sx1262 @@ -569,10 +581,27 @@ lib_deps = ${LilyGo_T3S3_sx1262.lib_deps} densaugeo/base64 @ ~1.4.0 +[env:LilyGo_T3S3_sx1262_room_server] +extends = LilyGo_T3S3_sx1262 +build_flags = + ${LilyGo_T3S3_sx1262.build_flags} + -D DISPLAY_CLASS=SSD1306Display + -D ADVERT_NAME='"T3S3-1262 Room"' + -D ADVERT_LAT=-37.0 + -D ADVERT_LON=145.0 + -D ADMIN_PASSWORD='"password"' + -D ROOM_PASSWORD='"hello"' +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${LilyGo_T3S3_sx1262.build_src_filter} + + + +<../examples/simple_room_server> + [env:LilyGo_T3S3_sx1262_companion_radio_usb] extends = LilyGo_T3S3_sx1262 build_flags = ${LilyGo_T3S3_sx1262.build_flags} + -D DISPLAY_CLASS=SSD1306Display -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=8 ; -D ENABLE_PRIVATE_KEY_IMPORT=1 @@ -580,7 +609,8 @@ build_flags = ; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 ; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1 build_src_filter = ${LilyGo_T3S3_sx1262.build_src_filter} - +<../examples/companion_radio/main.cpp> + + + +<../examples/companion_radio> lib_deps = ${LilyGo_T3S3_sx1262.lib_deps} densaugeo/base64 @ ~1.4.0 @@ -589,6 +619,7 @@ lib_deps = extends = LilyGo_T3S3_sx1262 build_flags = ${LilyGo_T3S3_sx1262.build_flags} + -D DISPLAY_CLASS=SSD1306Display -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456 @@ -599,7 +630,8 @@ build_flags = ; -D MESH_DEBUG=1 build_src_filter = ${LilyGo_T3S3_sx1262.build_src_filter} + - +<../examples/companion_radio/main.cpp> + + + +<../examples/companion_radio> lib_deps = ${LilyGo_T3S3_sx1262.lib_deps} densaugeo/base64 @ ~1.4.0 @@ -979,7 +1011,7 @@ build_flags = ${nrf52840_base.build_flags} extends = faketec build_src_filter = ${faketec.build_src_filter} +<../examples/simple_repeater/main.cpp> build_flags = - ${faketec.build_flags} + ${faketec.build_flags} -D ADVERT_NAME="\"Faketec Repeater\"" -D ADVERT_LAT=-37.0 -D ADVERT_LON=145.0 @@ -994,7 +1026,7 @@ lib_deps = extends = faketec build_src_filter = ${faketec.build_src_filter} +<../examples/simple_room_server/main.cpp> build_flags = - ${faketec.build_flags} + ${faketec.build_flags} -D ADVERT_NAME="\"Test Room\"" -D ADVERT_LAT=-37.0 -D ADVERT_LON=145.0 @@ -1009,7 +1041,7 @@ lib_deps = [env:Faketec_terminal_chat] extends = faketec build_flags = - ${faketec.build_flags} + ${faketec.build_flags} -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=1 ; -D MESH_PACKET_LOGGING=1 @@ -1023,7 +1055,7 @@ lib_deps = [env:Faketec_companion_radio_usb] extends = faketec build_flags = - ${faketec.build_flags} + ${faketec.build_flags} -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=8 ; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 @@ -1037,7 +1069,7 @@ lib_deps = [env:Faketec_companion_radio_ble] extends = faketec build_flags = - ${faketec.build_flags} + ${faketec.build_flags} -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456