From 26112ba0017606704f06127717810332ba3ee6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 25 Sep 2024 18:56:17 +0200 Subject: [PATCH 1/3] Support T3S3 LR1121 variant --- src/FSCommon.cpp | 6 +++--- src/detect/LoRaRadioType.h | 3 ++- src/main.cpp | 31 ++++++++++++++++++++------- src/mesh/InterfacesTemplates.cpp | 1 + src/mesh/LR1120Interface.cpp | 5 +++++ src/mesh/LR1120Interface.h | 1 + src/mesh/LR1121Interface.cpp | 14 +++++++++++++ src/mesh/LR1121Interface.h | 14 +++++++++++++ src/mesh/LR11x0Interface.cpp | 36 ++++++++++++++++++++++++++------ variants/tlora_t3s3_v1/variant.h | 17 +++++++++++++++ 10 files changed, 111 insertions(+), 17 deletions(-) create mode 100644 src/mesh/LR1121Interface.cpp create mode 100644 src/mesh/LR1121Interface.h diff --git a/src/FSCommon.cpp b/src/FSCommon.cpp index d6a542808..24d3f477e 100644 --- a/src/FSCommon.cpp +++ b/src/FSCommon.cpp @@ -370,8 +370,8 @@ void setupSDCard() } uint64_t cardSize = SD.cardSize() / (1024 * 1024); - LOG_DEBUG("SD Card Size: %lluMB\n", cardSize); - LOG_DEBUG("Total space: %llu MB\n", SD.totalBytes() / (1024 * 1024)); - LOG_DEBUG("Used space: %llu MB\n", SD.usedBytes() / (1024 * 1024)); + LOG_DEBUG("SD Card Size: %lu MB\n", (uint32_t)cardSize); + LOG_DEBUG("Total space: %lu MB\n", (uint32_t)(SD.totalBytes() / (1024 * 1024))); + LOG_DEBUG("Used space: %lu MB\n", (uint32_t)(SD.usedBytes() / (1024 * 1024))); #endif } \ No newline at end of file diff --git a/src/detect/LoRaRadioType.h b/src/detect/LoRaRadioType.h index 3975153b5..a059a3668 100644 --- a/src/detect/LoRaRadioType.h +++ b/src/detect/LoRaRadioType.h @@ -10,7 +10,8 @@ enum LoRaRadioType { LLCC68_RADIO, SX1280_RADIO, LR1110_RADIO, - LR1120_RADIO + LR1120_RADIO, + LR1121_RADIO }; extern LoRaRadioType radioType; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index c2d275177..fa032a209 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -71,6 +71,7 @@ NRF52Bluetooth *nrf52Bluetooth = nullptr; #include "LLCC68Interface.h" #include "LR1110Interface.h" #include "LR1120Interface.h" +#include "LR1121Interface.h" #include "RF95Interface.h" #include "SX1262Interface.h" #include "SX1268Interface.h" @@ -880,7 +881,7 @@ void setup() #endif #if defined(RF95_IRQ) - if (!rIf) { + if ((!rIf) && (config.lora.region != meshtastic_Config_LoRaConfig_RegionCode_LORA_24)) { rIf = new RF95Interface(RadioLibHAL, LORA_CS, RF95_IRQ, RF95_RESET, RF95_DIO1); if (!rIf->init()) { LOG_WARN("Failed to find RF95 radio\n"); @@ -894,7 +895,7 @@ void setup() #endif #if defined(USE_SX1262) && !defined(ARCH_PORTDUINO) && !defined(TCXO_OPTIONAL) - if (!rIf) { + if ((!rIf) && (config.lora.region != meshtastic_Config_LoRaConfig_RegionCode_LORA_24)) { rIf = new SX1262Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY); if (!rIf->init()) { LOG_WARN("Failed to find SX1262 radio\n"); @@ -908,7 +909,7 @@ void setup() #endif #if defined(USE_SX1262) && !defined(ARCH_PORTDUINO) && defined(TCXO_OPTIONAL) - if (!rIf) { + if ((!rIf) && (config.lora.region != meshtastic_Config_LoRaConfig_RegionCode_LORA_24)) { // Try using the specified TCXO voltage rIf = new SX1262Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY); if (!rIf->init()) { @@ -924,7 +925,7 @@ void setup() } } - if (!rIf) { + if ((!rIf) && (config.lora.region != meshtastic_Config_LoRaConfig_RegionCode_LORA_24)) { // If specified TCXO voltage fails, attempt to use DIO3 as a reference instea rIf = new SX1262Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY); if (!rIf->init()) { @@ -942,7 +943,7 @@ void setup() #endif #if defined(USE_SX1268) - if (!rIf) { + if ((!rIf) && (config.lora.region != meshtastic_Config_LoRaConfig_RegionCode_LORA_24)) { rIf = new SX1268Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY); if (!rIf->init()) { LOG_WARN("Failed to find SX1268 radio\n"); @@ -956,7 +957,7 @@ void setup() #endif #if defined(USE_LLCC68) - if (!rIf) { + if ((!rIf) && (config.lora.region != meshtastic_Config_LoRaConfig_RegionCode_LORA_24)) { rIf = new LLCC68Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY); if (!rIf->init()) { LOG_WARN("Failed to find LLCC68 radio\n"); @@ -970,7 +971,7 @@ void setup() #endif #if defined(USE_LR1110) - if (!rIf) { + if ((!rIf) && (config.lora.region != meshtastic_Config_LoRaConfig_RegionCode_LORA_24)) { rIf = new LR1110Interface(RadioLibHAL, LR1110_SPI_NSS_PIN, LR1110_IRQ_PIN, LR1110_NRESER_PIN, LR1110_BUSY_PIN); if (!rIf->init()) { LOG_WARN("Failed to find LR1110 radio\n"); @@ -978,6 +979,7 @@ void setup() rIf = NULL; } else { LOG_INFO("LR1110 Radio init succeeded, using LR1110 radio\n"); + radioType = LR1110_RADIO; } } #endif @@ -991,6 +993,21 @@ void setup() rIf = NULL; } else { LOG_INFO("LR1120 Radio init succeeded, using LR1120 radio\n"); + radioType = LR1120_RADIO; + } + } +#endif + +#if defined(USE_LR1121) + if (!rIf) { + rIf = new LR1121Interface(RadioLibHAL, LR1121_SPI_NSS_PIN, LR1121_IRQ_PIN, LR1121_NRESER_PIN, LR1121_BUSY_PIN); + if (!rIf->init()) { + LOG_WARN("Failed to find LR1121 radio\n"); + delete rIf; + rIf = NULL; + } else { + LOG_INFO("LR1121 Radio init succeeded, using LR1121 radio\n"); + radioType = LR1121_RADIO; } } #endif diff --git a/src/mesh/InterfacesTemplates.cpp b/src/mesh/InterfacesTemplates.cpp index f2cac8028..329f0b48e 100644 --- a/src/mesh/InterfacesTemplates.cpp +++ b/src/mesh/InterfacesTemplates.cpp @@ -14,6 +14,7 @@ template class SX126xInterface; template class SX128xInterface; template class LR11x0Interface; template class LR11x0Interface; +template class LR11x0Interface; #ifdef ARCH_STM32WL template class SX126xInterface; #endif diff --git a/src/mesh/LR1120Interface.cpp b/src/mesh/LR1120Interface.cpp index 94f3568f7..07e9e508d 100644 --- a/src/mesh/LR1120Interface.cpp +++ b/src/mesh/LR1120Interface.cpp @@ -6,4 +6,9 @@ LR1120Interface::LR1120Interface(LockingArduinoHal *hal, RADIOLIB_PIN_TYPE cs, R RADIOLIB_PIN_TYPE busy) : LR11x0Interface(hal, cs, irq, rst, busy) { +} + +bool LR1120Interface::wideLora() +{ + return true; } \ No newline at end of file diff --git a/src/mesh/LR1120Interface.h b/src/mesh/LR1120Interface.h index fc59293ec..a03fa0b20 100644 --- a/src/mesh/LR1120Interface.h +++ b/src/mesh/LR1120Interface.h @@ -10,4 +10,5 @@ class LR1120Interface : public LR11x0Interface public: LR1120Interface(LockingArduinoHal *hal, RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy); + bool wideLora() override; }; \ No newline at end of file diff --git a/src/mesh/LR1121Interface.cpp b/src/mesh/LR1121Interface.cpp new file mode 100644 index 000000000..0d6bba6ea --- /dev/null +++ b/src/mesh/LR1121Interface.cpp @@ -0,0 +1,14 @@ +#include "LR1121Interface.h" +#include "configuration.h" +#include "error.h" + +LR1121Interface::LR1121Interface(LockingArduinoHal *hal, RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, + RADIOLIB_PIN_TYPE busy) + : LR11x0Interface(hal, cs, irq, rst, busy) +{ +} + +bool LR1121Interface::wideLora() +{ + return true; +} \ No newline at end of file diff --git a/src/mesh/LR1121Interface.h b/src/mesh/LR1121Interface.h new file mode 100644 index 000000000..32a6f9492 --- /dev/null +++ b/src/mesh/LR1121Interface.h @@ -0,0 +1,14 @@ +#pragma once + +#include "LR11x0Interface.h" + +/** + * Our adapter for LR1121 wideband radios + */ +class LR1121Interface : public LR11x0Interface +{ + public: + LR1121Interface(LockingArduinoHal *hal, RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, + RADIOLIB_PIN_TYPE busy); + bool wideLora() override; +}; \ No newline at end of file diff --git a/src/mesh/LR11x0Interface.cpp b/src/mesh/LR11x0Interface.cpp index e237c354f..9e911107a 100644 --- a/src/mesh/LR11x0Interface.cpp +++ b/src/mesh/LR11x0Interface.cpp @@ -10,8 +10,14 @@ // Particular boards might define a different max power based on what their hardware can do, default to max power output if not // specified (may be dangerous if using external PA and LR11x0 power config forgotten) -#ifndef LR11X0_MAX_POWER -#define LR11X0_MAX_POWER 22 +#ifndef LR1110_MAX_POWER +#define LR1110_MAX_POWER 22 +#endif + +// the 2.4G part maxes at 13dBm + +#ifndef LR1120_MAX_POWER +#define LR1120_MAX_POWER 13 #endif template @@ -47,8 +53,12 @@ template bool LR11x0Interface::init() RadioLibInterface::init(); - if (power > LR11X0_MAX_POWER) // Clamp power to maximum defined level - power = LR11X0_MAX_POWER; + if (power > LR1110_MAX_POWER) // Clamp power to maximum defined level + power = LR1110_MAX_POWER; + + if ((power > LR1120_MAX_POWER) && + (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_LORA_24)) // clamp again if wide freq range + power = LR1120_MAX_POWER; limitPower(); @@ -65,6 +75,18 @@ template bool LR11x0Interface::init() {LR11x0::MODE_WIFI, {LOW, LOW, LOW, LOW}}, END_OF_MODE_TABLE, }; +#elif defined(TLORA_T3S3_V1) + static const uint32_t rfswitch_dio_pins[] = {RADIOLIB_LR11X0_DIO5, RADIOLIB_LR11X0_DIO6, RADIOLIB_NC, RADIOLIB_NC, + RADIOLIB_NC}; + + static const Module::RfSwitchMode_t rfswitch_table[] = { + // mode DIO5 DIO6 + {LR11x0::MODE_STBY, {LOW, LOW}}, {LR11x0::MODE_RX, {HIGH, LOW}}, + {LR11x0::MODE_TX, {LOW, HIGH}}, {LR11x0::MODE_TX_HP, {LOW, HIGH}}, + {LR11x0::MODE_TX_HF, {LOW, LOW}}, {LR11x0::MODE_GNSS, {LOW, LOW}}, + {LR11x0::MODE_WIFI, {LOW, LOW}}, END_OF_MODE_TABLE, + }; + #else // set RF switch configuration for Wio WM1110 @@ -174,8 +196,10 @@ template bool LR11x0Interface::reconfigure() if (err != RADIOLIB_ERR_NONE) RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); - if (power > LR11X0_MAX_POWER) // This chip has lower power limits than some - power = LR11X0_MAX_POWER; + if (power > LR1110_MAX_POWER) // This chip has lower power limits than some + power = LR1110_MAX_POWER; + if ((power > LR1120_MAX_POWER) && (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_LORA_24)) // 2.4G power limit + power = LR1120_MAX_POWER; err = lora.setOutputPower(power); assert(err == RADIOLIB_ERR_NONE); diff --git a/variants/tlora_t3s3_v1/variant.h b/variants/tlora_t3s3_v1/variant.h index 8a1af1ec2..ca10ef5fb 100644 --- a/variants/tlora_t3s3_v1/variant.h +++ b/variants/tlora_t3s3_v1/variant.h @@ -24,6 +24,7 @@ #define USE_RF95 // RFM95/SX127x #define USE_SX1262 #define USE_SX1280 +#define USE_LR1121 #define LORA_SCK 5 #define LORA_MISO 3 @@ -60,3 +61,19 @@ #define SX128X_TXEN 10 #define SX128X_MAX_POWER 3 #endif + +// LR1121 +#ifdef USE_LR1121 +#define LR1121_IRQ_PIN 36 +#define LR1121_NRESER_PIN LORA_RESET +#define LR1121_BUSY_PIN LORA_DIO2 +#define LR1121_SPI_NSS_PIN LORA_CS +#define LR1121_SPI_SCK_PIN LORA_SCK +#define LR1121_SPI_MOSI_PIN LORA_MOSI +#define LR1121_SPI_MISO_PIN LORA_MISO +#define LR11X0_DIO3_TCXO_VOLTAGE 3.0 +#define LR11X0_DIO_AS_RF_SWITCH +#endif + +#define HAS_SDCARD // Have SPI interface SD card slot +#define SDCARD_USE_SPI1 \ No newline at end of file From a32233bb92635d15a3998f19269bd6f57834f784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 26 Sep 2024 12:15:37 +0200 Subject: [PATCH 2/3] fixa de typo too --- src/main.cpp | 2 +- variants/tlora_t3s3_v1/variant.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c1ce1cd0c..4e16f565f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1001,7 +1001,7 @@ void setup() #if defined(USE_LR1121) if (!rIf) { - rIf = new LR1121Interface(RadioLibHAL, LR1121_SPI_NSS_PIN, LR1121_IRQ_PIN, LR1121_NRESER_PIN, LR1121_BUSY_PIN); + rIf = new LR1121Interface(RadioLibHAL, LR1121_SPI_NSS_PIN, LR1121_IRQ_PIN, LR1121_NRESET_PIN, LR1121_BUSY_PIN); if (!rIf->init()) { LOG_WARN("Failed to find LR1121 radio\n"); delete rIf; diff --git a/variants/tlora_t3s3_v1/variant.h b/variants/tlora_t3s3_v1/variant.h index ca10ef5fb..babe44a58 100644 --- a/variants/tlora_t3s3_v1/variant.h +++ b/variants/tlora_t3s3_v1/variant.h @@ -65,7 +65,7 @@ // LR1121 #ifdef USE_LR1121 #define LR1121_IRQ_PIN 36 -#define LR1121_NRESER_PIN LORA_RESET +#define LR1121_NRESET_PIN LORA_RESET #define LR1121_BUSY_PIN LORA_DIO2 #define LR1121_SPI_NSS_PIN LORA_CS #define LR1121_SPI_SCK_PIN LORA_SCK From 479b0856b4d9b04628086b70fd02e5f26712bc78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 28 Sep 2024 19:07:11 +0200 Subject: [PATCH 3/3] use rfswitch definition and update radiolib --- platformio.ini | 2 +- variants/tlora_t3s3_v1/rfswitch.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 variants/tlora_t3s3_v1/rfswitch.h diff --git a/platformio.ini b/platformio.ini index f528a6fde..d781f0b12 100644 --- a/platformio.ini +++ b/platformio.ini @@ -91,7 +91,7 @@ monitor_filters = direct lib_deps = ;jgromes/RadioLib@~7.0.0 ;7.0.1pre needed for LR1121 support and SX127x CRC Bugfix - https://github.com/jgromes/RadioLib.git#98ad30eb103d22bb7e75f3cc900597403b0cfb1f + https://github.com/jgromes/RadioLib.git#38fc7a97a4c195b7c10aa94215a1c53ec18a56ef https://github.com/meshtastic/esp8266-oled-ssd1306.git#e16cee124fe26490cb14880c679321ad8ac89c95 ; ESP8266_SSD1306 https://github.com/mathertel/OneButton@~2.6.1 ; OneButton library for non-blocking button debounce https://github.com/meshtastic/arduino-fsm.git#7db3702bf0cfe97b783d6c72595e3f38e0b19159 diff --git a/variants/tlora_t3s3_v1/rfswitch.h b/variants/tlora_t3s3_v1/rfswitch.h new file mode 100644 index 000000000..19080cec6 --- /dev/null +++ b/variants/tlora_t3s3_v1/rfswitch.h @@ -0,0 +1,11 @@ +#include "RadioLib.h" + +static const uint32_t rfswitch_dio_pins[] = {RADIOLIB_LR11X0_DIO5, RADIOLIB_LR11X0_DIO6, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC}; + +static const Module::RfSwitchMode_t rfswitch_table[] = { + // mode DIO5 DIO6 + {LR11x0::MODE_STBY, {LOW, LOW}}, {LR11x0::MODE_RX, {HIGH, LOW}}, + {LR11x0::MODE_TX, {LOW, HIGH}}, {LR11x0::MODE_TX_HP, {LOW, HIGH}}, + {LR11x0::MODE_TX_HF, {LOW, LOW}}, {LR11x0::MODE_GNSS, {LOW, LOW}}, + {LR11x0::MODE_WIFI, {LOW, LOW}}, END_OF_MODE_TABLE, +}; \ No newline at end of file