From 996c95bfef0bfdb4d4d4ac4ab5505d2ecbd2db76 Mon Sep 17 00:00:00 2001 From: lbibass Date: Tue, 31 Mar 2026 10:44:02 -0400 Subject: [PATCH] fix radio type, update to dev branch. added lr1121 radiolib helper. fixed reset pin and rfswitch table. --- src/helpers/radiolib/CustomLR1121.h | 39 ++++++++++++++++++++++ src/helpers/radiolib/CustomLR1121Wrapper.h | 34 +++++++++++++++++++ variants/muzi_base_duo/platformio.ini | 4 +-- variants/muzi_base_duo/target.cpp | 18 +++++----- variants/muzi_base_duo/target.h | 2 +- variants/muzi_base_duo/variant.h | 4 +-- 6 files changed, 86 insertions(+), 15 deletions(-) create mode 100644 src/helpers/radiolib/CustomLR1121.h create mode 100644 src/helpers/radiolib/CustomLR1121Wrapper.h diff --git a/src/helpers/radiolib/CustomLR1121.h b/src/helpers/radiolib/CustomLR1121.h new file mode 100644 index 00000000..e549d6e7 --- /dev/null +++ b/src/helpers/radiolib/CustomLR1121.h @@ -0,0 +1,39 @@ +#pragma once + +#include +#include "MeshCore.h" + +class CustomLR1121 : public LR1121 { + bool _rx_boosted = false; + + public: + CustomLR1121(Module *mod) : LR1121(mod) { } + + size_t getPacketLength(bool update) override { + size_t len = LR1121::getPacketLength(update); + if (len == 0 && getIrqStatus() & RADIOLIB_LR11X0_IRQ_HEADER_ERR) { + // we've just received a corrupted packet + // this may have triggered a bug causing subsequent packets to be shifted + // call standby() to return radio to known-good state + // recvRaw will call startReceive() to restart rx + MESH_DEBUG_PRINTLN("LR1121: got header err, calling standby()"); + standby(); + } + return len; + } + + float getFreqMHz() const { return freqMHz; } + + int16_t setRxBoostedGainMode(bool en) { + _rx_boosted = en; + return LR1121::setRxBoostedGainMode(en); + } + + bool getRxBoostedGainMode() const { return _rx_boosted; } + + bool isReceiving() { + uint16_t irq = getIrqStatus(); + bool detected = ((irq & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID) || (irq & RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED)); + return detected; + } +}; \ No newline at end of file diff --git a/src/helpers/radiolib/CustomLR1121Wrapper.h b/src/helpers/radiolib/CustomLR1121Wrapper.h new file mode 100644 index 00000000..6017c1c1 --- /dev/null +++ b/src/helpers/radiolib/CustomLR1121Wrapper.h @@ -0,0 +1,34 @@ +#pragma once + +#include "CustomLR1121.h" +#include "RadioLibWrappers.h" +#include "LR11x0Reset.h" + +class CustomLR1121Wrapper : public RadioLibWrapper { +public: + CustomLR1121Wrapper(CustomLR1121& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { } + void doResetAGC() override { lr11x0ResetAGC((LR11x0 *)_radio, ((CustomLR1121 *)_radio)->getFreqMHz()); } + bool isReceivingPacket() override { + return ((CustomLR1121 *)_radio)->isReceiving(); + } + float getCurrentRSSI() override { + float rssi = -110; + ((CustomLR1121 *)_radio)->getRssiInst(&rssi); + return rssi; + } + + void onSendFinished() override { + RadioLibWrapper::onSendFinished(); + _radio->setPreambleLength(16); // overcomes weird issues with small and big pkts + } + + float getLastRSSI() const override { return ((CustomLR1121 *)_radio)->getRSSI(); } + float getLastSNR() const override { return ((CustomLR1121 *)_radio)->getSNR(); } + + void setRxBoostedGainMode(bool en) override { + ((CustomLR1121 *)_radio)->setRxBoostedGainMode(en); + } + bool getRxBoostedGainMode() const override { + return ((CustomLR1121 *)_radio)->getRxBoostedGainMode(); + } +}; diff --git a/variants/muzi_base_duo/platformio.ini b/variants/muzi_base_duo/platformio.ini index 2c395748..5c2d4e82 100644 --- a/variants/muzi_base_duo/platformio.ini +++ b/variants/muzi_base_duo/platformio.ini @@ -13,8 +13,8 @@ build_flags = ${nrf52_base.build_flags} -D PIN_USER_BTN=PIN_BUTTON1 -D USER_BTN_PRESSED=LOW -D PIN_STATUS_LED=35 - -D RADIO_CLASS=CustomLR1110 - -D WRAPPER_CLASS=CustomLR1110Wrapper + -D RADIO_CLASS=CustomLR1121 + -D WRAPPER_CLASS=CustomLR1121Wrapper -D LORA_TX_POWER=22 -D RF_SWITCH_TABLE -D RX_BOOSTED_GAIN=true diff --git a/variants/muzi_base_duo/target.cpp b/variants/muzi_base_duo/target.cpp index 0c51ebed..c0521a73 100644 --- a/variants/muzi_base_duo/target.cpp +++ b/variants/muzi_base_duo/target.cpp @@ -25,20 +25,18 @@ EnvironmentSensorManager sensors; // only enable environment sensors. GPS is di static const uint32_t rfswitch_dios[Module::RFSWITCH_MAX_PINS] = { RADIOLIB_LR11X0_DIO5, RADIOLIB_LR11X0_DIO6, - RADIOLIB_LR11X0_DIO7, - RADIOLIB_LR11X0_DIO8, RADIOLIB_NC }; static const Module::RfSwitchMode_t rfswitch_table[] = { - // mode DIO5 DIO6 DIO7 DIO8 - { LR11x0::MODE_STBY, {LOW, LOW, LOW, LOW }}, - { LR11x0::MODE_RX, {HIGH, LOW, LOW, HIGH }}, - { LR11x0::MODE_TX, {HIGH, HIGH, LOW, HIGH }}, - { LR11x0::MODE_TX_HP, {LOW, HIGH, LOW, HIGH }}, - { LR11x0::MODE_TX_HF, {LOW, LOW, LOW, LOW }}, - { LR11x0::MODE_GNSS, {LOW, LOW, HIGH, LOW }}, - { LR11x0::MODE_WIFI, {LOW, LOW, LOW, LOW }}, + // 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, }; #endif diff --git a/variants/muzi_base_duo/target.h b/variants/muzi_base_duo/target.h index 1b862ee0..babaaafb 100644 --- a/variants/muzi_base_duo/target.h +++ b/variants/muzi_base_duo/target.h @@ -4,7 +4,7 @@ #include #include #include "muzi_base_duoBoard.h" -#include +#include #include #include #include diff --git a/variants/muzi_base_duo/variant.h b/variants/muzi_base_duo/variant.h index 02dfeb9b..4e60e372 100644 --- a/variants/muzi_base_duo/variant.h +++ b/variants/muzi_base_duo/variant.h @@ -107,11 +107,11 @@ static const uint8_t AREF = (PIN_AREF); // not used #define PIN_BACK_BTN PIN_BUTTON6 //////////////////////////////////////////////////////////////////////////////// -// LR1110 +// LR1121 #define LORA_DIO_1 (32+8) // P1.08 #define LORA_NSS (PIN_SPI_NSS) // P1.12 -#define LORA_RESET (32+12) // P1.12 +#define LORA_RESET (32+10) // P1.10 #define LORA_BUSY (32+11) // P1.11 #define LORA_SCLK (PIN_SPI_SCK) #define LORA_MISO (PIN_SPI_MISO)