From 23967b248476326620f2c141883e03b234c119fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 26 Sep 2024 13:23:44 +0200 Subject: [PATCH 1/3] enabled higher bandwidth settings for 2.4G lora --- src/modules/LR11x0/LR1120.cpp | 2 +- src/modules/LR11x0/LR11x0.cpp | 56 ++++++++++++++++++++++------------- src/modules/LR11x0/LR11x0.h | 7 +++-- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/modules/LR11x0/LR1120.cpp b/src/modules/LR11x0/LR1120.cpp index a69dc3593..0b67ee95b 100644 --- a/src/modules/LR11x0/LR1120.cpp +++ b/src/modules/LR11x0/LR1120.cpp @@ -7,7 +7,7 @@ LR1120::LR1120(Module* mod) : LR11x0(mod) { int16_t LR1120::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage) { // execute common part - int16_t state = LR11x0::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage); + int16_t state = LR11x0::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage, freq > 1000.0); RADIOLIB_ASSERT(state); // configure publicly accessible settings diff --git a/src/modules/LR11x0/LR11x0.cpp b/src/modules/LR11x0/LR11x0.cpp index 81eb9ade0..becc497b9 100644 --- a/src/modules/LR11x0/LR11x0.cpp +++ b/src/modules/LR11x0/LR11x0.cpp @@ -23,13 +23,13 @@ LR11x0::LR11x0(Module* mod) : PhysicalLayer(RADIOLIB_LR11X0_FREQUENCY_STEP_SIZE, this->irqMap[RADIOLIB_IRQ_TIMEOUT] = RADIOLIB_LR11X0_IRQ_TIMEOUT; } -int16_t LR11x0::begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage) { +int16_t LR11x0::begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool high) { // set module properties and perform initial setup int16_t state = this->modSetup(tcxoVoltage, RADIOLIB_LR11X0_PACKET_TYPE_LORA); RADIOLIB_ASSERT(state); // configure publicly accessible settings - state = setBandwidth(bw); + state = setBandwidth(bw, high); RADIOLIB_ASSERT(state); state = setSpreadingFactor(sf); @@ -623,7 +623,7 @@ int16_t LR11x0::getChannelScanResult() { return(RADIOLIB_ERR_UNKNOWN); } -int16_t LR11x0::setBandwidth(float bw) { +int16_t LR11x0::setBandwidth(float bw, bool high) { // check active modem uint8_t type = RADIOLIB_LR11X0_PACKET_TYPE_NONE; int16_t state = getPacketType(&type); @@ -633,25 +633,39 @@ int16_t LR11x0::setBandwidth(float bw) { } // ensure byte conversion doesn't overflow - RADIOLIB_CHECK_RANGE(bw, 0.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH); - - // check allowed bandwidth values - uint8_t bw_div2 = bw / 2 + 0.01; - switch (bw_div2) { - case 31: // 62.5: - this->bandwidth = RADIOLIB_LR11X0_LORA_BW_62_5; - break; - case 62: // 125.0: - this->bandwidth = RADIOLIB_LR11X0_LORA_BW_125_0; - break; - case 125: // 250.0 - this->bandwidth = RADIOLIB_LR11X0_LORA_BW_250_0; - break; - case 250: // 500.0 - this->bandwidth = RADIOLIB_LR11X0_LORA_BW_500_0; - break; - default: + if (high) { + RADIOLIB_CHECK_RANGE(bw, 203.125, 815.0, RADIOLIB_ERR_INVALID_BANDWIDTH); + + if(fabsf(bw - 203.125) <= 0.001) { + this->bandwidth = RADIOLIB_LR11X0_LORA_BW_203_125; + } else if(fabsf(bw - 406.25) <= 0.001) { + this->bandwidth = RADIOLIB_LR11X0_LORA_BW_406_25; + } else if(fabsf(bw - 812.5) <= 0.001) { + this->bandwidth = RADIOLIB_LR11X0_LORA_BW_812_50; + } else { return(RADIOLIB_ERR_INVALID_BANDWIDTH); + } + } else { + RADIOLIB_CHECK_RANGE(bw, 0.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH); + + // check allowed bandwidth values + uint8_t bw_div2 = bw / 2 + 0.01; + switch (bw_div2) { + case 31: // 62.5: + this->bandwidth = RADIOLIB_LR11X0_LORA_BW_62_5; + break; + case 62: // 125.0: + this->bandwidth = RADIOLIB_LR11X0_LORA_BW_125_0; + break; + case 125: // 250.0 + this->bandwidth = RADIOLIB_LR11X0_LORA_BW_250_0; + break; + case 250: // 500.0 + this->bandwidth = RADIOLIB_LR11X0_LORA_BW_500_0; + break; + default: + return(RADIOLIB_ERR_INVALID_BANDWIDTH); + } } // update modulation parameters diff --git a/src/modules/LR11x0/LR11x0.h b/src/modules/LR11x0/LR11x0.h index e5a7baf62..52aa4d042 100644 --- a/src/modules/LR11x0/LR11x0.h +++ b/src/modules/LR11x0/LR11x0.h @@ -364,6 +364,9 @@ #define RADIOLIB_LR11X0_LORA_BW_125_0 (0x04UL << 0) // 7 0 125.0 kHz #define RADIOLIB_LR11X0_LORA_BW_250_0 (0x05UL << 0) // 7 0 250.0 kHz #define RADIOLIB_LR11X0_LORA_BW_500_0 (0x06UL << 0) // 7 0 500.0 kHz +#define RADIOLIB_LR11X0_LORA_BW_203_125 (0x0DUL << 0) // 7 0 203.0 kHz (2.4GHz only) +#define RADIOLIB_LR11X0_LORA_BW_406_25 (0x0EUL << 0) // 7 0 406.0 kHz (2.4GHz only) +#define RADIOLIB_LR11X0_LORA_BW_812_50 (0x0FUL << 0) // 7 0 812.0 kHz (2.4GHz only) #define RADIOLIB_LR11X0_LORA_CR_4_5_SHORT (0x01UL << 0) // 7 0 coding rate: 4/5 with short interleaver #define RADIOLIB_LR11X0_LORA_CR_4_6_SHORT (0x02UL << 0) // 7 0 4/6 with short interleaver #define RADIOLIB_LR11X0_LORA_CR_4_7_SHORT (0x03UL << 0) // 7 0 4/7 with short interleaver @@ -775,7 +778,7 @@ class LR11x0: public PhysicalLayer { \param tcxoVoltage TCXO reference voltage to be set. \returns \ref status_codes */ - int16_t begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage); + int16_t begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool high = false); /*! \brief Initialization method for FSK modem. @@ -997,7 +1000,7 @@ class LR11x0: public PhysicalLayer { \param bw LoRa bandwidth to be set in kHz. \returns \ref status_codes */ - int16_t setBandwidth(float bw); + int16_t setBandwidth(float bw, bool high = false); /*! \brief Sets LoRa spreading factor. Allowed values range from 5 to 12. From 144d035f21394c59931966cbd4846f52d6891275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 26 Sep 2024 21:56:11 +0200 Subject: [PATCH 2/3] document new parameters --- src/modules/LR11x0/LR11x0.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/LR11x0/LR11x0.h b/src/modules/LR11x0/LR11x0.h index 52aa4d042..b2eba6bc2 100644 --- a/src/modules/LR11x0/LR11x0.h +++ b/src/modules/LR11x0/LR11x0.h @@ -776,6 +776,7 @@ class LR11x0: public PhysicalLayer { \param syncWord 1-byte LoRa sync word. \param preambleLength LoRa preamble length in symbols \param tcxoVoltage TCXO reference voltage to be set. + \param high defaults to false for Sub-GHz band, true for frequencies above 1.8GHz \returns \ref status_codes */ int16_t begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool high = false); @@ -996,8 +997,9 @@ class LR11x0: public PhysicalLayer { // configuration methods /*! - \brief Sets LoRa bandwidth. Allowed values are 62.5, 125.0, 250.0 and 500.0 kHz. + \brief Sets LoRa bandwidth. Allowed values are 62.5, 125.0, 250.0 and 500.0 kHz. (default, high = false) \param bw LoRa bandwidth to be set in kHz. + \param high if set to true, allowed bandwidth is 203.125, 406.25 and 812.5 kHz, frequency must be above 1.8GHz \returns \ref status_codes */ int16_t setBandwidth(float bw, bool high = false); From efb1a8b0b1e50838d66381c0a4f2b484bb4faa49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 26 Sep 2024 22:03:25 +0200 Subject: [PATCH 3/3] use the same cutoff as this->highFreq --- src/modules/LR11x0/LR11x0.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/LR11x0/LR11x0.h b/src/modules/LR11x0/LR11x0.h index b2eba6bc2..b9d27eef6 100644 --- a/src/modules/LR11x0/LR11x0.h +++ b/src/modules/LR11x0/LR11x0.h @@ -776,7 +776,7 @@ class LR11x0: public PhysicalLayer { \param syncWord 1-byte LoRa sync word. \param preambleLength LoRa preamble length in symbols \param tcxoVoltage TCXO reference voltage to be set. - \param high defaults to false for Sub-GHz band, true for frequencies above 1.8GHz + \param high defaults to false for Sub-GHz band, true for frequencies above 1GHz \returns \ref status_codes */ int16_t begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool high = false); @@ -999,7 +999,7 @@ class LR11x0: public PhysicalLayer { /*! \brief Sets LoRa bandwidth. Allowed values are 62.5, 125.0, 250.0 and 500.0 kHz. (default, high = false) \param bw LoRa bandwidth to be set in kHz. - \param high if set to true, allowed bandwidth is 203.125, 406.25 and 812.5 kHz, frequency must be above 1.8GHz + \param high if set to true, allowed bandwidth is 203.125, 406.25 and 812.5 kHz, frequency must be above 1GHz \returns \ref status_codes */ int16_t setBandwidth(float bw, bool high = false);