From 1f11cd1dd574c6ac9a2e1b8aadb34a2ec9cc0953 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 6 Oct 2024 10:13:56 +0200 Subject: [PATCH] [LR1110] Added configurable LR-FHSS grid spacing --- src/modules/LR11x0/LR1110.cpp | 4 ++-- src/modules/LR11x0/LR1110.h | 3 ++- src/modules/LR11x0/LR1120.cpp | 4 ++-- src/modules/LR11x0/LR1120.h | 3 ++- src/modules/LR11x0/LR11x0.cpp | 9 ++++++--- src/modules/LR11x0/LR11x0.h | 5 +++-- src/protocols/PhysicalLayer/PhysicalLayer.h | 6 ++++++ 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/modules/LR11x0/LR1110.cpp b/src/modules/LR11x0/LR1110.cpp index 62bf116f..7ebf5a7b 100644 --- a/src/modules/LR11x0/LR1110.cpp +++ b/src/modules/LR11x0/LR1110.cpp @@ -31,9 +31,9 @@ int16_t LR1110::beginGFSK(float freq, float br, float freqDev, float rxBw, int8_ return(state); } -int16_t LR1110::beginLRFHSS(float freq, uint8_t bw, uint8_t cr, int8_t power, float tcxoVoltage) { +int16_t LR1110::beginLRFHSS(float freq, uint8_t bw, uint8_t cr, bool narrowGrid, int8_t power, float tcxoVoltage) { // execute common part - int16_t state = LR11x0::beginLRFHSS(bw, cr, tcxoVoltage); + int16_t state = LR11x0::beginLRFHSS(bw, cr, narrowGrid, tcxoVoltage); RADIOLIB_ASSERT(state); // configure publicly accessible settings diff --git a/src/modules/LR11x0/LR1110.h b/src/modules/LR11x0/LR1110.h index fcc65f2e..3e1bc5fc 100644 --- a/src/modules/LR11x0/LR1110.h +++ b/src/modules/LR11x0/LR1110.h @@ -58,13 +58,14 @@ class LR1110: public LR11x0 { \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. \param bw LR-FHSS bandwidth, one of RADIOLIB_LR11X0_LR_FHSS_BW_* values. Defaults to 722.66 kHz. \param cr LR-FHSS coding rate, one of RADIOLIB_LR11X0_LR_FHSS_CR_* values. Defaults to 2/3 coding rate. + \param narrowGrid Whether to use narrow (3.9 kHz) or wide (25.39 kHz) grid spacing. Defaults to true (narrow/non-FCC) grid. \param power Output power in dBm. Defaults to 10 dBm. \param tcxoVoltage TCXO reference voltage to be set. Defaults to 1.6 V. If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL. To use XTAL, either set this value to 0, or set LR11x0::XTAL to true. \returns \ref status_codes */ - int16_t beginLRFHSS(float freq = 434.0, uint8_t bw = RADIOLIB_LR11X0_LR_FHSS_BW_722_66, uint8_t cr = RADIOLIB_LR11X0_LR_FHSS_CR_2_3, int8_t power = 10, float tcxoVoltage = 1.6); + int16_t beginLRFHSS(float freq = 434.0, uint8_t bw = RADIOLIB_LR11X0_LR_FHSS_BW_722_66, uint8_t cr = RADIOLIB_LR11X0_LR_FHSS_CR_2_3, bool narrowGrid = true, int8_t power = 10, float tcxoVoltage = 1.6); // configuration methods diff --git a/src/modules/LR11x0/LR1120.cpp b/src/modules/LR11x0/LR1120.cpp index 0b67ee95..9afa8dfb 100644 --- a/src/modules/LR11x0/LR1120.cpp +++ b/src/modules/LR11x0/LR1120.cpp @@ -31,9 +31,9 @@ int16_t LR1120::beginGFSK(float freq, float br, float freqDev, float rxBw, int8_ return(state); } -int16_t LR1120::beginLRFHSS(float freq, uint8_t bw, uint8_t cr, int8_t power, float tcxoVoltage) { +int16_t LR1120::beginLRFHSS(float freq, uint8_t bw, uint8_t cr, bool narrowGrid, int8_t power, float tcxoVoltage) { // execute common part - int16_t state = LR11x0::beginLRFHSS(bw, cr, tcxoVoltage); + int16_t state = LR11x0::beginLRFHSS(bw, cr, narrowGrid, tcxoVoltage); RADIOLIB_ASSERT(state); // configure publicly accessible settings diff --git a/src/modules/LR11x0/LR1120.h b/src/modules/LR11x0/LR1120.h index c4fbbde5..4abae5a9 100644 --- a/src/modules/LR11x0/LR1120.h +++ b/src/modules/LR11x0/LR1120.h @@ -58,13 +58,14 @@ class LR1120: public LR11x0 { \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. \param bw LR-FHSS bandwidth, one of RADIOLIB_LR11X0_LR_FHSS_BW_* values. Defaults to 722.66 kHz. \param cr LR-FHSS coding rate, one of RADIOLIB_LR11X0_LR_FHSS_CR_* values. Defaults to 2/3 coding rate. + \param narrowGrid Whether to use narrow (3.9 kHz) or wide (25.39 kHz) grid spacing. Defaults to true (narrow/non-FCC) grid. \param power Output power in dBm. Defaults to 10 dBm. \param tcxoVoltage TCXO reference voltage to be set. Defaults to 1.6 V. If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL. To use XTAL, either set this value to 0, or set LR11x0::XTAL to true. \returns \ref status_codes */ - int16_t beginLRFHSS(float freq = 434.0, uint8_t bw = RADIOLIB_LR11X0_LR_FHSS_BW_722_66, uint8_t cr = RADIOLIB_LR11X0_LR_FHSS_CR_2_3, int8_t power = 10, float tcxoVoltage = 1.6); + int16_t beginLRFHSS(float freq = 434.0, uint8_t bw = RADIOLIB_LR11X0_LR_FHSS_BW_722_66, uint8_t cr = RADIOLIB_LR11X0_LR_FHSS_CR_2_3, bool narrowGrid = true, int8_t power = 10, float tcxoVoltage = 1.6); // configuration methods diff --git a/src/modules/LR11x0/LR11x0.cpp b/src/modules/LR11x0/LR11x0.cpp index 8a879591..70da0d35 100644 --- a/src/modules/LR11x0/LR11x0.cpp +++ b/src/modules/LR11x0/LR11x0.cpp @@ -98,11 +98,14 @@ int16_t LR11x0::beginGFSK(float br, float freqDev, float rxBw, uint16_t preamble return(RADIOLIB_ERR_NONE); } -int16_t LR11x0::beginLRFHSS(uint8_t bw, uint8_t cr, float tcxoVoltage) { +int16_t LR11x0::beginLRFHSS(uint8_t bw, uint8_t cr, bool narrowGrid, float tcxoVoltage) { // set module properties and perform initial setup int16_t state = this->modSetup(tcxoVoltage, RADIOLIB_LR11X0_PACKET_TYPE_LR_FHSS); RADIOLIB_ASSERT(state); + // set grid spacing + this->lrFhssGrid = narrowGrid ? RADIOLIB_LR11X0_LR_FHSS_GRID_STEP_NON_FCC : RADIOLIB_LR11X0_LR_FHSS_GRID_STEP_FCC; + // configure publicly accessible settings state = setLrFhssConfig(bw, cr); RADIOLIB_ASSERT(state); @@ -418,8 +421,8 @@ int16_t LR11x0::startTransmit(const uint8_t* data, size_t len, uint8_t addr) { if(modem == RADIOLIB_LR11X0_PACKET_TYPE_LR_FHSS) { // in LR-FHSS mode, the packet is built by the device - // TODO add configurable grid step and device offset - state = lrFhssBuildFrame(this->lrFhssHdrCount, this->lrFhssCr, RADIOLIB_LR11X0_LR_FHSS_GRID_STEP_FCC, true, this->lrFhssBw, this->lrFhssHopSeq, 0, const_cast(data), len); + // TODO add configurable device offset + state = lrFhssBuildFrame(this->lrFhssHdrCount, this->lrFhssCr, this->lrFhssGrid, true, this->lrFhssBw, this->lrFhssHopSeq, 0, const_cast(data), len); RADIOLIB_ASSERT(state); } else { diff --git a/src/modules/LR11x0/LR11x0.h b/src/modules/LR11x0/LR11x0.h index f6a4b44e..a52d64af 100644 --- a/src/modules/LR11x0/LR11x0.h +++ b/src/modules/LR11x0/LR11x0.h @@ -796,10 +796,11 @@ class LR11x0: public PhysicalLayer { \brief Initialization method for LR-FHSS modem. \param bw LR-FHSS bandwidth, one of RADIOLIB_LR11X0_LR_FHSS_BW_* values. \param cr LR-FHSS coding rate, one of RADIOLIB_LR11X0_LR_FHSS_CR_* values. + \param narrowGrid Whether to use narrow (3.9 kHz) or wide (25.39 kHz) grid spacing. \param tcxoVoltage TCXO reference voltage to be set. \returns \ref status_codes */ - int16_t beginLRFHSS(uint8_t bw, uint8_t cr, float tcxoVoltage); + int16_t beginLRFHSS(uint8_t bw, uint8_t cr, bool narrowGrid, float tcxoVoltage); /*! \brief Reset method. Will reset the chip to the default state using RST pin. @@ -1594,7 +1595,7 @@ class LR11x0: public PhysicalLayer { uint16_t preambleLengthGFSK = 0; // cached LR-FHSS parameters - uint8_t lrFhssCr = 0, lrFhssBw = 0, lrFhssHdrCount = 0; + uint8_t lrFhssCr = 0, lrFhssBw = 0, lrFhssHdrCount = 0, lrFhssGrid = 0; uint16_t lrFhssHopSeq = 0; float dataRateMeasured = 0; diff --git a/src/protocols/PhysicalLayer/PhysicalLayer.h b/src/protocols/PhysicalLayer/PhysicalLayer.h index b4218b5e..c463e8b2 100644 --- a/src/protocols/PhysicalLayer/PhysicalLayer.h +++ b/src/protocols/PhysicalLayer/PhysicalLayer.h @@ -62,6 +62,9 @@ struct LrFhssRate_t { /*! \brief Coding rate */ uint8_t cr; + + /*! \brief Grid spacing */ + bool narrowGrid; }; /*! @@ -74,6 +77,9 @@ union DataRate_t { /*! \brief Interpretation for FSK modems */ FSKRate_t fsk; + + /*! \brief Interpretation for LR-FHSS modems */ + LrFhssRate_t lrFhss; }; /*!