From bfb4b1c496126183eba06f63f913dc8f04c782a8 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Fri, 21 Mar 2025 18:57:12 +1100 Subject: [PATCH] * BIG refactor: 'board' and 'radio' objects now defined in 'target.h/.cpp' * mesh::RTCClock class moved to MeshCore.h --- examples/companion_radio/main.cpp | 105 +--------------------- examples/simple_repeater/main.cpp | 97 +------------------- examples/simple_room_server/main.cpp | 97 +------------------- examples/simple_secure_chat/main.cpp | 78 +--------------- src/Mesh.h | 28 ------ src/MeshCore.h | 28 ++++++ src/helpers/ESP32Board.h | 1 + src/helpers/nrf52/faketecBoard.cpp | 4 +- src/helpers/nrf52/faketecBoard.h | 2 +- variants/heltec_v2/platformio.ini | 2 + variants/heltec_v2/target.cpp | 31 +++++++ variants/heltec_v2/target.h | 9 ++ variants/heltec_v3/platformio.ini | 2 + variants/heltec_v3/target.cpp | 47 ++++++++++ variants/heltec_v3/target.h | 9 ++ variants/lilygo_t3s3/platformio.ini | 2 + variants/lilygo_t3s3/target.cpp | 47 ++++++++++ variants/lilygo_t3s3/target.h | 9 ++ variants/lilygo_tbeam/platformio.ini | 2 + variants/lilygo_tbeam/target.cpp | 31 +++++++ variants/lilygo_tbeam/target.h | 9 ++ variants/lilygo_tlora_v2_1/platformio.ini | 3 + variants/lilygo_tlora_v2_1/target.cpp | 25 ++++++ variants/lilygo_tlora_v2_1/target.h | 9 ++ variants/promicro_nrf52840/platformio.ini | 12 ++- variants/promicro_nrf52840/target.cpp | 46 ++++++++++ variants/promicro_nrf52840/target.h | 10 +++ variants/rak4631/platformio.ini | 2 + variants/rak4631/target.cpp | 41 +++++++++ variants/rak4631/target.h | 9 ++ variants/station_g2/platformio.ini | 3 +- variants/station_g2/target.cpp | 47 ++++++++++ variants/station_g2/target.h | 9 ++ variants/t1000-e/platformio.ini | 4 +- variants/t1000-e/target.cpp | 41 +++++++++ variants/t1000-e/target.h | 9 ++ variants/t114/platformio.ini | 2 +- variants/t114/target.cpp | 41 +++++++++ variants/t114/target.h | 9 ++ variants/techo/platformio.ini | 2 +- variants/techo/target.cpp | 41 +++++++++ variants/techo/target.h | 9 ++ variants/xiao_c3/platformio.ini | 3 + variants/xiao_c3/target.cpp | 47 ++++++++++ variants/xiao_c3/target.h | 10 +++ variants/xiao_s3_wio/platformio.ini | 3 + variants/xiao_s3_wio/target.cpp | 47 ++++++++++ variants/xiao_s3_wio/target.h | 9 ++ 48 files changed, 726 insertions(+), 407 deletions(-) create mode 100644 variants/heltec_v2/target.cpp create mode 100644 variants/heltec_v2/target.h create mode 100644 variants/heltec_v3/target.cpp create mode 100644 variants/heltec_v3/target.h create mode 100644 variants/lilygo_t3s3/target.cpp create mode 100644 variants/lilygo_t3s3/target.h create mode 100644 variants/lilygo_tbeam/target.cpp create mode 100644 variants/lilygo_tbeam/target.h create mode 100644 variants/lilygo_tlora_v2_1/target.cpp create mode 100644 variants/lilygo_tlora_v2_1/target.h create mode 100644 variants/promicro_nrf52840/target.cpp create mode 100644 variants/promicro_nrf52840/target.h create mode 100644 variants/rak4631/target.cpp create mode 100644 variants/rak4631/target.h create mode 100644 variants/station_g2/target.cpp create mode 100644 variants/station_g2/target.h create mode 100644 variants/t1000-e/target.cpp create mode 100644 variants/t1000-e/target.h create mode 100644 variants/t114/target.cpp create mode 100644 variants/t114/target.h create mode 100644 variants/techo/target.cpp create mode 100644 variants/techo/target.h create mode 100644 variants/xiao_c3/target.cpp create mode 100644 variants/xiao_c3/target.h create mode 100644 variants/xiao_s3_wio/target.cpp create mode 100644 variants/xiao_s3_wio/target.h diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 1acf5c2c..994a90c0 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -16,6 +16,7 @@ #include #include #include +#include /* ---------------------------------- CONFIGURATION ------------------------------------- */ @@ -59,59 +60,6 @@ #define PUBLIC_GROUP_PSK "izOH6cXN6mrJ5e26oRXNcg==" -#if defined(HELTEC_LORA_V3) - #include - #include - static HeltecV3Board board; -#elif defined(HELTEC_LORA_V2) - #include - #include - static HeltecV2Board board; -#elif defined(ARDUINO_XIAO_ESP32C3) - #include - #include - #include - static XiaoC3Board board; -#elif defined(SEEED_XIAO_S3) || defined(LILYGO_T3S3) - #include - #include - static ESP32Board board; -#elif defined(LILYGO_TLORA) - #include - #include - static LilyGoTLoraBoard board; -#elif defined(RAK_4631) - #include - #include - static RAK4631Board board; -#elif defined(T1000_E) - #include - #include - static T1000eBoard board; -#elif defined(HELTEC_T114) - #include - #include - static T114Board board; -#elif defined(LILYGO_TECHO) - #include - #include - static TechoBoard board; - -#elif defined(LILYGO_TBEAM) - #include - #include - static TBeamBoard board; - -#elif defined(FAKETEC) - #include - #include - #include - static faketecBoard board; - -#else - #error "need to provide a 'board' object" -#endif - #ifdef DISPLAY_CLASS #include "UITask.h" #include @@ -1473,20 +1421,6 @@ public: #error "need to define a serial interface" #endif -#if defined(NRF52_PLATFORM) -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); -#elif defined(LILYGO_TLORA) -SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_0, P_LORA_RESET, P_LORA_DIO_1, spi); -#elif defined(LILYGO_TBEAM) -SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_0, P_LORA_RESET, P_LORA_DIO_1, spi); -#elif defined(P_LORA_SCLK) -SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); -#else -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); -#endif StdRNG fast_rng; SimpleMeshTables tables; MyMesh the_mesh(radio, *new WRAPPER_CLASS(radio, board), fast_rng, *new VolatileRTCClock(), tables); @@ -1499,43 +1433,8 @@ void setup() { Serial.begin(115200); board.begin(); -#ifdef SX126X_DIO3_TCXO_VOLTAGE - float tcxo = SX126X_DIO3_TCXO_VOLTAGE; -#else - float tcxo = 1.6f; -#endif -#if defined(NRF52_PLATFORM) - SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); - SPI.begin(); -#elif defined(P_LORA_SCLK) - 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); - halt(); - } - - radio.setCRC(1); - -#ifdef SX126X_CURRENT_LIMIT - radio.setCurrentLimit(SX126X_CURRENT_LIMIT); -#endif -#ifdef SX126X_DIO2_AS_RF_SWITCH - radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); -#endif -#ifdef SX126X_RX_BOOSTED_GAIN - radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); -#endif + if (!radio_init()) { halt(); } fast_rng.begin(radio.random(0x7FFFFFFF)); diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 8c056cd2..f3467a8a 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -18,6 +18,7 @@ #include #include #include +#include /* ------------------------------ Config -------------------------------- */ @@ -59,52 +60,6 @@ #define ADMIN_PASSWORD "password" #endif -#if defined(HELTEC_LORA_V3) - #include - #include - static HeltecV3Board board; -#elif defined(HELTEC_LORA_V2) - #include - #include - static HeltecV2Board board; -#elif defined(ARDUINO_XIAO_ESP32C3) - #include - #include - #include - static XiaoC3Board board; -#elif defined(SEEED_XIAO_S3) || defined(LILYGO_T3S3) - #include - #include - static ESP32Board board; -#elif defined(LILYGO_TLORA) - #include - #include - static LilyGoTLoraBoard board; -#elif defined(STATION_G2) - #include - #include - static StationG2Board board; -#elif defined(RAK_4631) - #include - #include - static RAK4631Board board; -#elif defined(HELTEC_T114) - #include - #include - static T114Board board; -#elif defined(LILYGO_TECHO) - #include - #include - static TechoBoard board; -#elif defined(FAKETEC) - #include - #include - #include - static faketecBoard board; -#else - #error "need to provide a 'board' object" -#endif - #ifdef DISPLAY_CLASS #include @@ -638,17 +593,6 @@ public: } }; -#if defined(NRF52_PLATFORM) -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); -#elif defined(LILYGO_TLORA) -SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_0, P_LORA_RESET, P_LORA_DIO_1, spi); -#elif defined(P_LORA_SCLK) -SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); -#else -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); -#endif StdRNG fast_rng; SimpleMeshTables tables; @@ -677,44 +621,7 @@ void setup() { #endif rtc_clock.begin(Wire); -#ifdef SX126X_DIO3_TCXO_VOLTAGE - float tcxo = SX126X_DIO3_TCXO_VOLTAGE; -#else - float tcxo = 1.6f; -#endif - -#if defined(NRF52_PLATFORM) - SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); - SPI.begin(); -#elif defined(P_LORA_SCLK) - 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: "); - Serial.println(status); - halt(); - } - - radio.setCRC(1); - -#ifdef SX126X_CURRENT_LIMIT - radio.setCurrentLimit(SX126X_CURRENT_LIMIT); -#endif -#ifdef SX126X_DIO2_AS_RF_SWITCH - radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); -#endif -#ifdef SX126X_RX_BOOSTED_GAIN - radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); -#endif + if (!radio_init()) { halt(); } fast_rng.begin(radio.random(0x7FFFFFFF)); diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index 1821ecc7..4cef1365 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -18,6 +18,7 @@ #include #include #include +#include /* ------------------------------ Config -------------------------------- */ @@ -67,52 +68,6 @@ #define MAX_UNSYNCED_POSTS 16 #endif -#if defined(HELTEC_LORA_V3) - #include - #include - static HeltecV3Board board; -#elif defined(HELTEC_LORA_V2) - #include - #include - static HeltecV2Board board; -#elif defined(ARDUINO_XIAO_ESP32C3) - #include - #include - #include - static XiaoC3Board board; -#elif defined(SEEED_XIAO_S3) || defined(LILYGO_T3S3) - #include - #include - static ESP32Board board; -#elif defined(LILYGO_TLORA) - #include - #include - static LilyGoTLoraBoard board; -#elif defined(STATION_G2) - #include - #include - static StationG2Board board; -#elif defined(RAK_4631) - #include - #include - static RAK4631Board board; -#elif defined(HELTEC_T114) - #include - #include - static T114Board board; -#elif defined(LILYGO_TECHO) - #include - #include - static TechoBoard board; -#elif defined(FAKETEC) - #include - #include - #include - static faketecBoard board; -#else - #error "need to provide a 'board' object" -#endif - #ifdef DISPLAY_CLASS #include @@ -773,17 +728,6 @@ public: } }; -#if defined(NRF52_PLATFORM) -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); -#elif defined(LILYGO_TLORA) -SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_0, P_LORA_RESET, P_LORA_DIO_1, spi); -#elif defined(P_LORA_SCLK) -SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); -#else -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); -#endif StdRNG fast_rng; SimpleMeshTables tables; @@ -812,44 +756,7 @@ void setup() { #endif rtc_clock.begin(Wire); -#ifdef SX126X_DIO3_TCXO_VOLTAGE - float tcxo = SX126X_DIO3_TCXO_VOLTAGE; -#else - float tcxo = 1.6f; -#endif - -#if defined(NRF52_PLATFORM) - SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); - SPI.begin(); -#elif defined(P_LORA_SCLK) - 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: "); - Serial.println(status); - halt(); - } - - radio.setCRC(1); - -#ifdef SX126X_CURRENT_LIMIT - radio.setCurrentLimit(SX126X_CURRENT_LIMIT); -#endif -#ifdef SX126X_DIO2_AS_RF_SWITCH - radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); -#endif -#ifdef SX126X_RX_BOOSTED_GAIN - radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); -#endif + if (!radio_init()) { halt(); } fast_rng.begin(radio.random(0x7FFFFFFF)); diff --git a/examples/simple_secure_chat/main.cpp b/examples/simple_secure_chat/main.cpp index e695fa03..4eae2e34 100644 --- a/examples/simple_secure_chat/main.cpp +++ b/examples/simple_secure_chat/main.cpp @@ -15,6 +15,7 @@ #include #include #include +#include /* ---------------------------------- CONFIGURATION ------------------------------------- */ @@ -49,44 +50,6 @@ #define PUBLIC_GROUP_PSK "izOH6cXN6mrJ5e26oRXNcg==" -#if defined(HELTEC_LORA_V3) - #include - #include - static HeltecV3Board board; -#elif defined(HELTEC_LORA_V2) - #include - #include - static HeltecV2Board board; -#elif defined(ARDUINO_XIAO_ESP32C3) - #include - #include - #include - static XiaoC3Board board; -#elif defined(SEEED_XIAO_S3) || defined(LILYGO_T3S3) - #include - #include - static ESP32Board board; -#elif defined(LILYGO_TLORA) - #include - #include - static LilyGoTLoraBoard board; -#elif defined(RAK_4631) - #include - #include - static RAK4631Board board; -#elif defined(T1000_E) - #include - #include - static T1000eBoard board; -#elif defined(FAKETEC) - #include - #include - #include - static faketecBoard board; -#else - #error "need to provide a 'board' object" -#endif - // Believe it or not, this std C function is busted on some platforms! static uint32_t _atoi(const char* sp) { uint32_t n = 0; @@ -548,17 +511,6 @@ public: } }; -#if defined(NRF52_PLATFORM) -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); -#elif defined(LILYGO_TLORA) -SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_0, P_LORA_RESET, P_LORA_DIO_1, spi); -#elif defined(P_LORA_SCLK) -SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); -#else -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); -#endif StdRNG fast_rng; SimpleMeshTables tables; MyMesh the_mesh(*new WRAPPER_CLASS(radio, board), fast_rng, *new VolatileRTCClock(), tables); @@ -571,34 +523,8 @@ void setup() { Serial.begin(115200); board.begin(); -#ifdef SX126X_DIO3_TCXO_VOLTAGE - float tcxo = SX126X_DIO3_TCXO_VOLTAGE; -#else - float tcxo = 1.6f; -#endif -#if defined(NRF52_PLATFORM) - SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); - SPI.begin(); -#elif defined(P_LORA_SCLK) - 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 (status != RADIOLIB_ERR_NONE) { - Serial.print("ERROR: radio init failed: "); - Serial.println(status); - halt(); - } - - radio.setCRC(1); - -#ifdef SX126X_CURRENT_LIMIT - radio.setCurrentLimit(SX126X_CURRENT_LIMIT); -#endif - -#ifdef SX126X_DIO2_AS_RF_SWITCH - radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); -#endif + if (!radio_init()) { halt(); } fast_rng.begin(radio.random(0x7FFFFFFF)); diff --git a/src/Mesh.h b/src/Mesh.h index cfacebc9..cb81f8de 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -4,34 +4,6 @@ namespace mesh { -/** - * An abstraction of the device's Realtime Clock. -*/ -class RTCClock { - uint32_t last_unique; -protected: - RTCClock() { last_unique = 0; } - -public: - /** - * \returns the current time. in UNIX epoch seconds. - */ - virtual uint32_t getCurrentTime() = 0; - - /** - * \param time current time in UNIX epoch seconds. - */ - virtual void setCurrentTime(uint32_t time) = 0; - - uint32_t getCurrentTimeUnique() { - uint32_t t = getCurrentTime(); - if (t <= last_unique) { - return ++last_unique; - } - return last_unique = t; - } -}; - class GroupChannel { public: uint8_t hash[PATH_HASH_SIZE]; diff --git a/src/MeshCore.h b/src/MeshCore.h index 9593877d..e134d3e6 100644 --- a/src/MeshCore.h +++ b/src/MeshCore.h @@ -45,4 +45,32 @@ public: virtual bool startOTAUpdate() { return false; } // not supported }; +/** + * An abstraction of the device's Realtime Clock. +*/ +class RTCClock { + uint32_t last_unique; +protected: + RTCClock() { last_unique = 0; } + +public: + /** + * \returns the current time. in UNIX epoch seconds. + */ + virtual uint32_t getCurrentTime() = 0; + + /** + * \param time current time in UNIX epoch seconds. + */ + virtual void setCurrentTime(uint32_t time) = 0; + + uint32_t getCurrentTimeUnique() { + uint32_t t = getCurrentTime(); + if (t <= last_unique) { + return ++last_unique; + } + return last_unique = t; + } +}; + } \ No newline at end of file diff --git a/src/helpers/ESP32Board.h b/src/helpers/ESP32Board.h index 70e29575..a2aa484d 100644 --- a/src/helpers/ESP32Board.h +++ b/src/helpers/ESP32Board.h @@ -7,6 +7,7 @@ #include #include +#include class ESP32Board : public mesh::MainBoard { protected: diff --git a/src/helpers/nrf52/faketecBoard.cpp b/src/helpers/nrf52/faketecBoard.cpp index 638c8119..94054998 100644 --- a/src/helpers/nrf52/faketecBoard.cpp +++ b/src/helpers/nrf52/faketecBoard.cpp @@ -6,7 +6,7 @@ static BLEDfu bledfu; -void faketecBoard::begin() { +void FaketecBoard::begin() { // for future use, sub-classes SHOULD call this from their begin() startup_reason = BD_STARTUP_NORMAL; btn_prev_state = HIGH; @@ -39,7 +39,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { MESH_DEBUG_PRINTLN("BLE client disconnected"); } -bool faketecBoard::startOTAUpdate() { +bool FaketecBoard::startOTAUpdate() { // Config the peripheral connection with maximum bandwidth // more SRAM required by SoftDevice // Note: All config***() function must be called before begin() diff --git a/src/helpers/nrf52/faketecBoard.h b/src/helpers/nrf52/faketecBoard.h index 53ba9917..f072c959 100644 --- a/src/helpers/nrf52/faketecBoard.h +++ b/src/helpers/nrf52/faketecBoard.h @@ -20,7 +20,7 @@ #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 { +class FaketecBoard : public mesh::MainBoard { protected: uint8_t startup_reason; uint8_t btn_prev_state; diff --git a/variants/heltec_v2/platformio.ini b/variants/heltec_v2/platformio.ini index 99638c2b..117432bf 100644 --- a/variants/heltec_v2/platformio.ini +++ b/variants/heltec_v2/platformio.ini @@ -3,6 +3,7 @@ extends = esp32_base board = heltec_wifi_lora_32_V2 ; heltec_wifi_lora_32_V2 build_flags = ${esp32_base.build_flags} + -I variants/heltec_v2 -D HELTEC_LORA_V2 -D PIN_BOARD_SDA=4 -D PIN_BOARD_SCL=15 @@ -13,6 +14,7 @@ build_flags = -D LORA_TX_POWER=20 -D P_LORA_TX_LED=25 build_src_filter = ${esp32_base.build_src_filter} + +<../variants/heltec_v2> lib_deps = ${esp32_base.lib_deps} adafruit/Adafruit SSD1306 @ ^2.5.13 diff --git a/variants/heltec_v2/target.cpp b/variants/heltec_v2/target.cpp new file mode 100644 index 00000000..5f2251b2 --- /dev/null +++ b/variants/heltec_v2/target.cpp @@ -0,0 +1,31 @@ +#include +#include "target.h" + +HeltecV2Board board; + +#if defined(P_LORA_SCLK) + static SPIClass spi; + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +#else + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +#endif + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { +#if defined(P_LORA_SCLK) + 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); + if (status != RADIOLIB_ERR_NONE) { + Serial.print("ERROR: radio init failed: "); + Serial.println(status); + return false; // fail + } + + radio.setCRC(1); + + return true; // success +} diff --git a/variants/heltec_v2/target.h b/variants/heltec_v2/target.h new file mode 100644 index 00000000..999e15f7 --- /dev/null +++ b/variants/heltec_v2/target.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +extern HeltecV2Board board; +extern RADIO_CLASS radio; + +bool radio_init(); diff --git a/variants/heltec_v3/platformio.ini b/variants/heltec_v3/platformio.ini index f32a12c4..bfd7accb 100644 --- a/variants/heltec_v3/platformio.ini +++ b/variants/heltec_v3/platformio.ini @@ -3,6 +3,7 @@ extends = esp32_base board = esp32-s3-devkitc-1 build_flags = ${esp32_base.build_flags} + -I variants/heltec_v3 -D HELTEC_LORA_V3 -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper @@ -16,6 +17,7 @@ build_flags = -D SX126X_CURRENT_LIMIT=130.0f ; for best TX power! -D SX126X_RX_BOOSTED_GAIN=1 build_src_filter = ${esp32_base.build_src_filter} + +<../variants/heltec_v3> lib_deps = ${esp32_base.lib_deps} adafruit/Adafruit SSD1306 @ ^2.5.13 diff --git a/variants/heltec_v3/target.cpp b/variants/heltec_v3/target.cpp new file mode 100644 index 00000000..decffa9e --- /dev/null +++ b/variants/heltec_v3/target.cpp @@ -0,0 +1,47 @@ +#include +#include "target.h" + +HeltecV3Board board; + +#if defined(P_LORA_SCLK) + static SPIClass spi; + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +#else + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +#endif + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { +#ifdef SX126X_DIO3_TCXO_VOLTAGE + float tcxo = SX126X_DIO3_TCXO_VOLTAGE; +#else + float tcxo = 1.6f; +#endif + +#if defined(P_LORA_SCLK) + 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 (status != RADIOLIB_ERR_NONE) { + Serial.print("ERROR: radio init failed: "); + Serial.println(status); + return false; // fail + } + + radio.setCRC(1); + +#ifdef SX126X_CURRENT_LIMIT + radio.setCurrentLimit(SX126X_CURRENT_LIMIT); +#endif +#ifdef SX126X_DIO2_AS_RF_SWITCH + radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); +#endif +#ifdef SX126X_RX_BOOSTED_GAIN + radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); +#endif + + return true; // success +} diff --git a/variants/heltec_v3/target.h b/variants/heltec_v3/target.h new file mode 100644 index 00000000..1d1007f9 --- /dev/null +++ b/variants/heltec_v3/target.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +extern HeltecV3Board board; +extern RADIO_CLASS radio; + +bool radio_init(); diff --git a/variants/lilygo_t3s3/platformio.ini b/variants/lilygo_t3s3/platformio.ini index f86657f5..698d7c86 100644 --- a/variants/lilygo_t3s3/platformio.ini +++ b/variants/lilygo_t3s3/platformio.ini @@ -3,6 +3,7 @@ extends = esp32_base board = t3_s3_v1_x build_flags = ${esp32_base.build_flags} + -I variants/lilygo_t3s3 -D LILYGO_T3S3 -D P_LORA_DIO_1=33 -D P_LORA_NSS=7 @@ -26,6 +27,7 @@ build_flags = -D LORA_TX_POWER=22 -D SX126X_RX_BOOSTED_GAIN=1 build_src_filter = ${esp32_base.build_src_filter} + +<../variants/lilygo_t3s3> lib_deps = ${esp32_base.lib_deps} adafruit/Adafruit SSD1306 @ ^2.5.13 diff --git a/variants/lilygo_t3s3/target.cpp b/variants/lilygo_t3s3/target.cpp new file mode 100644 index 00000000..6ae1a533 --- /dev/null +++ b/variants/lilygo_t3s3/target.cpp @@ -0,0 +1,47 @@ +#include +#include "target.h" + +ESP32Board board; + +#if defined(P_LORA_SCLK) + static SPIClass spi; + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +#else + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +#endif + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { +#ifdef SX126X_DIO3_TCXO_VOLTAGE + float tcxo = SX126X_DIO3_TCXO_VOLTAGE; +#else + float tcxo = 1.6f; +#endif + +#if defined(P_LORA_SCLK) + 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 (status != RADIOLIB_ERR_NONE) { + Serial.print("ERROR: radio init failed: "); + Serial.println(status); + return false; // fail + } + + radio.setCRC(1); + +#ifdef SX126X_CURRENT_LIMIT + radio.setCurrentLimit(SX126X_CURRENT_LIMIT); +#endif +#ifdef SX126X_DIO2_AS_RF_SWITCH + radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); +#endif +#ifdef SX126X_RX_BOOSTED_GAIN + radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); +#endif + + return true; // success +} diff --git a/variants/lilygo_t3s3/target.h b/variants/lilygo_t3s3/target.h new file mode 100644 index 00000000..90c629db --- /dev/null +++ b/variants/lilygo_t3s3/target.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +extern ESP32Board board; +extern RADIO_CLASS radio; + +bool radio_init(); diff --git a/variants/lilygo_tbeam/platformio.ini b/variants/lilygo_tbeam/platformio.ini index ca233571..fdf833b1 100644 --- a/variants/lilygo_tbeam/platformio.ini +++ b/variants/lilygo_tbeam/platformio.ini @@ -3,12 +3,14 @@ extends = esp32_base board = ttgo-t-beam build_flags = ${esp32_base.build_flags} + -I variants/lilygo_tbeam -D LILYGO_TBEAM -D RADIO_CLASS=CustomSX1276 -D WRAPPER_CLASS=CustomSX1276Wrapper -D LORA_TX_POWER=20 -D P_LORA_TX_LED=4 build_src_filter = ${esp32_base.build_src_filter} + +<../variants/lilygo_tbeam> board_build.partitions = min_spiffs.csv ; get around 4mb flash limit [env:Tbeam_companion_radio_ble] diff --git a/variants/lilygo_tbeam/target.cpp b/variants/lilygo_tbeam/target.cpp new file mode 100644 index 00000000..22493327 --- /dev/null +++ b/variants/lilygo_tbeam/target.cpp @@ -0,0 +1,31 @@ +#include +#include "target.h" + +TBeamBoard board; + +#if defined(P_LORA_SCLK) + static SPIClass spi; + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +#else + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +#endif + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { +#if defined(P_LORA_SCLK) + 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); + if (status != RADIOLIB_ERR_NONE) { + Serial.print("ERROR: radio init failed: "); + Serial.println(status); + return false; // fail + } + + radio.setCRC(1); + + return true; // success +} diff --git a/variants/lilygo_tbeam/target.h b/variants/lilygo_tbeam/target.h new file mode 100644 index 00000000..699bd964 --- /dev/null +++ b/variants/lilygo_tbeam/target.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +extern TBeamBoard board; +extern RADIO_CLASS radio; + +bool radio_init(); diff --git a/variants/lilygo_tlora_v2_1/platformio.ini b/variants/lilygo_tlora_v2_1/platformio.ini index 0cf3ac92..017857d6 100644 --- a/variants/lilygo_tlora_v2_1/platformio.ini +++ b/variants/lilygo_tlora_v2_1/platformio.ini @@ -6,6 +6,7 @@ build_type = release ; Set build type to release board_build.partitions = min_spiffs.csv ; get around 4mb flash limit build_flags = ${esp32_base.build_flags} + -I variants/lilygo_tlora_v2_1 -Os -ffunction-sections -fdata-sections ; Optimize for size -D LILYGO_TLORA ; LILYGO T-LoRa V2.1-1.6 ESP32 with SX1276 -D P_LORA_DIO_0=26 ; SX1276 DIO0 interrupt pin @@ -23,6 +24,8 @@ build_flags = -D DISPLAY_CLASS=SSD1306Display -D WRAPPER_CLASS=CustomSX1276Wrapper -D LORA_TX_POWER=20 +build_src_filter = ${esp32_base.build_src_filter} + +<../variants/lilygo_tlora_v2_1> lib_deps = ${esp32_base.lib_deps} adafruit/Adafruit SSD1306 @ ^2.5.13 diff --git a/variants/lilygo_tlora_v2_1/target.cpp b/variants/lilygo_tlora_v2_1/target.cpp new file mode 100644 index 00000000..cd22a6ec --- /dev/null +++ b/variants/lilygo_tlora_v2_1/target.cpp @@ -0,0 +1,25 @@ +#include +#include "target.h" + +LilyGoTLoraBoard board; + +static SPIClass spi; +RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_0, P_LORA_RESET, P_LORA_DIO_1, spi); + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { + spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI); + int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8); + if (status != RADIOLIB_ERR_NONE) { + Serial.print("ERROR: radio init failed: "); + Serial.println(status); + return false; // fail + } + + radio.setCRC(1); + + return true; // success +} diff --git a/variants/lilygo_tlora_v2_1/target.h b/variants/lilygo_tlora_v2_1/target.h new file mode 100644 index 00000000..757460f8 --- /dev/null +++ b/variants/lilygo_tlora_v2_1/target.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +extern LilyGoTLoraBoard board; +extern RADIO_CLASS radio; + +bool radio_init(); diff --git a/variants/promicro_nrf52840/platformio.ini b/variants/promicro_nrf52840/platformio.ini index a815a9af..38b39ef8 100644 --- a/variants/promicro_nrf52840/platformio.ini +++ b/variants/promicro_nrf52840/platformio.ini @@ -1,8 +1,10 @@ [faketec] extends = nrf52840_base board = promicro_nrf52840 -build_src_filter = ${nrf52840_base.build_src_filter} + build_flags = ${nrf52840_base.build_flags} + -I src + -I src/helpers/nrf52 + -I variants/promicro_nrf52840 -D FAKETEC -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper @@ -14,6 +16,9 @@ build_flags = ${nrf52840_base.build_flags} -D PIN_BOARD_SDA=8 -D PIN_OLED_RESET=-1 -D PIN_USER_BTN=6 +build_src_filter = ${nrf52840_base.build_src_filter} + + + +<../variants/promicro_nrf52840> lib_deps= ${nrf52840_base.lib_deps} adafruit/Adafruit SSD1306 @ ^2.5.13 @@ -98,14 +103,17 @@ lib_deps = [ProMicroLLCC68] extends = nrf52840_base board = promicro_nrf52840 -build_src_filter = ${nrf52840_base.build_src_filter} + build_flags = ${nrf52840_base.build_flags} + -I variants/promicro_nrf52840 -D FAKETEC -D RADIO_CLASS=CustomLLCC68 -D WRAPPER_CLASS=CustomLLCC68Wrapper -D LORA_TX_POWER=22 -D SX126X_CURRENT_LIMIT=130 -D SX126X_RX_BOOSTED_GAIN=1 +build_src_filter = ${nrf52840_base.build_src_filter} + + + +<../variants/promicro_nrf52840> [env:ProMicroLLCC68_Repeater] extends = ProMicroLLCC68 diff --git a/variants/promicro_nrf52840/target.cpp b/variants/promicro_nrf52840/target.cpp new file mode 100644 index 00000000..45488f21 --- /dev/null +++ b/variants/promicro_nrf52840/target.cpp @@ -0,0 +1,46 @@ +#include +#include "target.h" + +FaketecBoard board; + +RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { +#ifdef SX126X_DIO3_TCXO_VOLTAGE + float tcxo = SX126X_DIO3_TCXO_VOLTAGE; +#else + float tcxo = 1.6f; +#endif + + SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); + SPI.begin(); + int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); + 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); + } + if (status != RADIOLIB_ERR_NONE) { + Serial.print("ERROR: radio init failed: "); + Serial.println(status); + return false; // fail + } + + radio.setCRC(1); + +#ifdef SX126X_CURRENT_LIMIT + radio.setCurrentLimit(SX126X_CURRENT_LIMIT); +#endif +#ifdef SX126X_DIO2_AS_RF_SWITCH + radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); +#endif +#ifdef SX126X_RX_BOOSTED_GAIN + radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); +#endif + + return true; // success +} diff --git a/variants/promicro_nrf52840/target.h b/variants/promicro_nrf52840/target.h new file mode 100644 index 00000000..dc08b6cc --- /dev/null +++ b/variants/promicro_nrf52840/target.h @@ -0,0 +1,10 @@ +#pragma once + +#include +#include +#include + +extern FaketecBoard board; +extern RADIO_CLASS radio; + +bool radio_init(); diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index 50931655..518ab8b9 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -4,6 +4,7 @@ platform = https://github.com/maxgerhardt/platform-nordicnrf52.git#rak board = wiscore_rak4631 board_check = true build_flags = ${nrf52840_base.build_flags} + -I variants/rak4631 -D RAK_4631 -D PIN_USER_BTN=9 -D RADIO_CLASS=CustomSX1262 @@ -13,6 +14,7 @@ build_flags = ${nrf52840_base.build_flags} -D SX126X_RX_BOOSTED_GAIN=1 build_src_filter = ${nrf52840_base.build_src_filter} + + +<../variants/rak4631> lib_deps = ${nrf52840_base.lib_deps} adafruit/Adafruit SSD1306 @ ^2.5.13 diff --git a/variants/rak4631/target.cpp b/variants/rak4631/target.cpp new file mode 100644 index 00000000..c4155182 --- /dev/null +++ b/variants/rak4631/target.cpp @@ -0,0 +1,41 @@ +#include +#include "target.h" + +RAK4631Board board; + +RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { +#ifdef SX126X_DIO3_TCXO_VOLTAGE + float tcxo = SX126X_DIO3_TCXO_VOLTAGE; +#else + float tcxo = 1.6f; +#endif + + SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); + SPI.begin(); + int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); + if (status != RADIOLIB_ERR_NONE) { + Serial.print("ERROR: radio init failed: "); + Serial.println(status); + return false; // fail + } + + radio.setCRC(1); + +#ifdef SX126X_CURRENT_LIMIT + radio.setCurrentLimit(SX126X_CURRENT_LIMIT); +#endif +#ifdef SX126X_DIO2_AS_RF_SWITCH + radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); +#endif +#ifdef SX126X_RX_BOOSTED_GAIN + radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); +#endif + + return true; // success +} diff --git a/variants/rak4631/target.h b/variants/rak4631/target.h new file mode 100644 index 00000000..d03485b6 --- /dev/null +++ b/variants/rak4631/target.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +extern RAK4631Board board; +extern RADIO_CLASS radio; + +bool radio_init(); diff --git a/variants/station_g2/platformio.ini b/variants/station_g2/platformio.ini index c4d1c1b0..e11cb0a1 100644 --- a/variants/station_g2/platformio.ini +++ b/variants/station_g2/platformio.ini @@ -3,6 +3,7 @@ extends = esp32_base board = station-g2 build_flags = ${esp32_base.build_flags} + -I variants/station_g2 -D STATION_G2 -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper @@ -16,8 +17,8 @@ build_flags = -D SX126X_CURRENT_LIMIT=130.0f ; for best TX power! ; -D SX126X_RX_BOOSTED_GAIN=1 - DO NOT ENABLE THIS! ; https://wiki.uniteng.com/en/meshtastic/station-g2#impact-of-lora-node-dense-areashigh-noise-environments-on-rf-performance - build_src_filter = ${esp32_base.build_src_filter} + +<../variants/station_g2> lib_deps = ${esp32_base.lib_deps} diff --git a/variants/station_g2/target.cpp b/variants/station_g2/target.cpp new file mode 100644 index 00000000..c6c0505f --- /dev/null +++ b/variants/station_g2/target.cpp @@ -0,0 +1,47 @@ +#include +#include "target.h" + +StationG2Board board; + +#if defined(P_LORA_SCLK) + static SPIClass spi; + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +#else + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +#endif + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { +#ifdef SX126X_DIO3_TCXO_VOLTAGE + float tcxo = SX126X_DIO3_TCXO_VOLTAGE; +#else + float tcxo = 1.6f; +#endif + +#if defined(P_LORA_SCLK) + 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 (status != RADIOLIB_ERR_NONE) { + Serial.print("ERROR: radio init failed: "); + Serial.println(status); + return false; // fail + } + + radio.setCRC(1); + +#ifdef SX126X_CURRENT_LIMIT + radio.setCurrentLimit(SX126X_CURRENT_LIMIT); +#endif +#ifdef SX126X_DIO2_AS_RF_SWITCH + radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); +#endif +#ifdef SX126X_RX_BOOSTED_GAIN + radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); +#endif + + return true; // success +} diff --git a/variants/station_g2/target.h b/variants/station_g2/target.h new file mode 100644 index 00000000..faae2378 --- /dev/null +++ b/variants/station_g2/target.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +extern StationG2Board board; +extern RADIO_CLASS radio; + +bool radio_init(); diff --git a/variants/t1000-e/platformio.ini b/variants/t1000-e/platformio.ini index c2f21d9c..e1f58193 100644 --- a/variants/t1000-e/platformio.ini +++ b/variants/t1000-e/platformio.ini @@ -19,14 +19,14 @@ extends = nrf52840_t1000e board = tracker-t1000-e board_build.ldscript = boards/nrf52840_s140_v7.ld build_flags = ${nrf52840_t1000e.build_flags} - -Ivariants/t1000-e + -I variants/t1000-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} + + diff --git a/variants/t1000-e/target.cpp b/variants/t1000-e/target.cpp new file mode 100644 index 00000000..8e661f39 --- /dev/null +++ b/variants/t1000-e/target.cpp @@ -0,0 +1,41 @@ +#include +#include "target.h" + +T1000eBoard board; + +RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { +#ifdef SX126X_DIO3_TCXO_VOLTAGE + float tcxo = SX126X_DIO3_TCXO_VOLTAGE; +#else + float tcxo = 1.6f; +#endif + + SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); + SPI.begin(); + int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); + if (status != RADIOLIB_ERR_NONE) { + Serial.print("ERROR: radio init failed: "); + Serial.println(status); + return false; // fail + } + + radio.setCRC(1); + +#ifdef SX126X_CURRENT_LIMIT + radio.setCurrentLimit(SX126X_CURRENT_LIMIT); +#endif +#ifdef SX126X_DIO2_AS_RF_SWITCH + radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); +#endif +#ifdef SX126X_RX_BOOSTED_GAIN + radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); +#endif + + return true; // success +} diff --git a/variants/t1000-e/target.h b/variants/t1000-e/target.h new file mode 100644 index 00000000..fd118ea9 --- /dev/null +++ b/variants/t1000-e/target.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +extern T1000eBoard board; +extern RADIO_CLASS radio; + +bool radio_init(); diff --git a/variants/t114/platformio.ini b/variants/t114/platformio.ini index b979f1f4..754839dd 100644 --- a/variants/t114/platformio.ini +++ b/variants/t114/platformio.ini @@ -14,7 +14,7 @@ extends = nrf52840_t114 board = heltec_t114 board_build.ldscript = boards/nrf52840_s140_v6.ld build_flags = ${nrf52840_t114.build_flags} - -Ivariants/t114 + -I variants/t114 -DHELTEC_T114 -D P_LORA_TX_LED=35 -D RADIO_CLASS=CustomSX1262 diff --git a/variants/t114/target.cpp b/variants/t114/target.cpp new file mode 100644 index 00000000..e6da1ffb --- /dev/null +++ b/variants/t114/target.cpp @@ -0,0 +1,41 @@ +#include +#include "target.h" + +T114Board board; + +RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { +#ifdef SX126X_DIO3_TCXO_VOLTAGE + float tcxo = SX126X_DIO3_TCXO_VOLTAGE; +#else + float tcxo = 1.6f; +#endif + + SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); + SPI.begin(); + int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); + if (status != RADIOLIB_ERR_NONE) { + Serial.print("ERROR: radio init failed: "); + Serial.println(status); + return false; // fail + } + + radio.setCRC(1); + +#ifdef SX126X_CURRENT_LIMIT + radio.setCurrentLimit(SX126X_CURRENT_LIMIT); +#endif +#ifdef SX126X_DIO2_AS_RF_SWITCH + radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); +#endif +#ifdef SX126X_RX_BOOSTED_GAIN + radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); +#endif + + return true; // success +} diff --git a/variants/t114/target.h b/variants/t114/target.h new file mode 100644 index 00000000..301d0849 --- /dev/null +++ b/variants/t114/target.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +extern T114Board board; +extern RADIO_CLASS radio; + +bool radio_init(); diff --git a/variants/techo/platformio.ini b/variants/techo/platformio.ini index f2a9432b..2c825e64 100644 --- a/variants/techo/platformio.ini +++ b/variants/techo/platformio.ini @@ -14,7 +14,7 @@ extends = nrf52840_techo board = t-echo board_build.ldscript = boards/nrf52840_s140_v6.ld build_flags = ${nrf52840_techo.build_flags} - -Ivariants/techo + -I variants/techo -DLILYGO_TECHO -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper diff --git a/variants/techo/target.cpp b/variants/techo/target.cpp new file mode 100644 index 00000000..a5592ba5 --- /dev/null +++ b/variants/techo/target.cpp @@ -0,0 +1,41 @@ +#include +#include "target.h" + +TechoBoard board; + +RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { +#ifdef SX126X_DIO3_TCXO_VOLTAGE + float tcxo = SX126X_DIO3_TCXO_VOLTAGE; +#else + float tcxo = 1.6f; +#endif + + SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); + SPI.begin(); + int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); + if (status != RADIOLIB_ERR_NONE) { + Serial.print("ERROR: radio init failed: "); + Serial.println(status); + return false; // fail + } + + radio.setCRC(1); + +#ifdef SX126X_CURRENT_LIMIT + radio.setCurrentLimit(SX126X_CURRENT_LIMIT); +#endif +#ifdef SX126X_DIO2_AS_RF_SWITCH + radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); +#endif +#ifdef SX126X_RX_BOOSTED_GAIN + radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); +#endif + + return true; // success +} diff --git a/variants/techo/target.h b/variants/techo/target.h new file mode 100644 index 00000000..d2ed51b1 --- /dev/null +++ b/variants/techo/target.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +extern TechoBoard board; +extern RADIO_CLASS radio; + +bool radio_init(); diff --git a/variants/xiao_c3/platformio.ini b/variants/xiao_c3/platformio.ini index 05688b2d..b66c238f 100644 --- a/variants/xiao_c3/platformio.ini +++ b/variants/xiao_c3/platformio.ini @@ -3,6 +3,7 @@ extends = esp32_base board = seeed_xiao_esp32c3 build_flags = ${esp32_base.build_flags} + -I variants/xiao_c3 -D LORA_TX_BOOST_PIN=D3 -D P_LORA_TX_LED=D5 -D PIN_VBAT_READ=D0 @@ -15,6 +16,8 @@ build_flags = -D SX126X_DIO2_AS_RF_SWITCH=true -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_CURRENT_LIMIT=130.0f ; for best TX power! +build_src_filter = ${esp32_base.build_src_filter} + +<../variants/xiao_c3> [env:Xiao_C3_Repeater_sx1262] extends = Xiao_esp32_C3 diff --git a/variants/xiao_c3/target.cpp b/variants/xiao_c3/target.cpp new file mode 100644 index 00000000..ffe17979 --- /dev/null +++ b/variants/xiao_c3/target.cpp @@ -0,0 +1,47 @@ +#include +#include "target.h" + +XiaoC3Board board; + +#if defined(P_LORA_SCLK) + static SPIClass spi; + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +#else + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +#endif + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { +#ifdef SX126X_DIO3_TCXO_VOLTAGE + float tcxo = SX126X_DIO3_TCXO_VOLTAGE; +#else + float tcxo = 1.6f; +#endif + +#if defined(P_LORA_SCLK) + 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 (status != RADIOLIB_ERR_NONE) { + Serial.print("ERROR: radio init failed: "); + Serial.println(status); + return false; // fail + } + + radio.setCRC(1); + +#ifdef SX126X_CURRENT_LIMIT + radio.setCurrentLimit(SX126X_CURRENT_LIMIT); +#endif +#ifdef SX126X_DIO2_AS_RF_SWITCH + radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); +#endif +#ifdef SX126X_RX_BOOSTED_GAIN + radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); +#endif + + return true; // success +} diff --git a/variants/xiao_c3/target.h b/variants/xiao_c3/target.h new file mode 100644 index 00000000..e0ff1d0d --- /dev/null +++ b/variants/xiao_c3/target.h @@ -0,0 +1,10 @@ +#pragma once + +#include +#include +#include + +extern XiaoC3Board board; +extern RADIO_CLASS radio; + +bool radio_init(); diff --git a/variants/xiao_s3_wio/platformio.ini b/variants/xiao_s3_wio/platformio.ini index 01931f4f..7255f8f2 100644 --- a/variants/xiao_s3_wio/platformio.ini +++ b/variants/xiao_s3_wio/platformio.ini @@ -4,6 +4,7 @@ board = seeed_xiao_esp32s3 board_check = true board_build.mcu = esp32s3 build_flags = ${esp32_base.build_flags} + -I variants/xiao_s3_wio -D SEEED_XIAO_S3 -D P_LORA_DIO_1=39 -D P_LORA_NSS=41 @@ -19,6 +20,8 @@ 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} + +<../variants/xiao_s3_wio> [env:Xiao_S3_WIO_Repeater] extends = Xiao_S3_WIO diff --git a/variants/xiao_s3_wio/target.cpp b/variants/xiao_s3_wio/target.cpp new file mode 100644 index 00000000..6ae1a533 --- /dev/null +++ b/variants/xiao_s3_wio/target.cpp @@ -0,0 +1,47 @@ +#include +#include "target.h" + +ESP32Board board; + +#if defined(P_LORA_SCLK) + static SPIClass spi; + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +#else + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +#endif + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { +#ifdef SX126X_DIO3_TCXO_VOLTAGE + float tcxo = SX126X_DIO3_TCXO_VOLTAGE; +#else + float tcxo = 1.6f; +#endif + +#if defined(P_LORA_SCLK) + 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 (status != RADIOLIB_ERR_NONE) { + Serial.print("ERROR: radio init failed: "); + Serial.println(status); + return false; // fail + } + + radio.setCRC(1); + +#ifdef SX126X_CURRENT_LIMIT + radio.setCurrentLimit(SX126X_CURRENT_LIMIT); +#endif +#ifdef SX126X_DIO2_AS_RF_SWITCH + radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); +#endif +#ifdef SX126X_RX_BOOSTED_GAIN + radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); +#endif + + return true; // success +} diff --git a/variants/xiao_s3_wio/target.h b/variants/xiao_s3_wio/target.h new file mode 100644 index 00000000..90c629db --- /dev/null +++ b/variants/xiao_s3_wio/target.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +extern ESP32Board board; +extern RADIO_CLASS radio; + +bool radio_init();