From ceb27967e16f7f157c4cd8139d6f010d1beba794 Mon Sep 17 00:00:00 2001 From: GUVWAF Date: Mon, 1 Sep 2025 19:57:58 +0200 Subject: [PATCH] [SX128x] Add support for coding rate 4/4 --- src/modules/SX128x/SX128x.cpp | 17 +++++++++++++++-- src/modules/SX128x/SX128x.h | 6 ++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 5a8c9a1d..0f50aa0d 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -726,11 +726,24 @@ int16_t SX128x::setCodingRate(uint8_t cr, bool longInterleaving) { // LoRa/ranging if((modem == RADIOLIB_SX128X_PACKET_TYPE_LORA) || (modem == RADIOLIB_SX128X_PACKET_TYPE_RANGING)) { - RADIOLIB_CHECK_RANGE(cr, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE); + RADIOLIB_CHECK_RANGE(cr, 4, 8, RADIOLIB_ERR_INVALID_CODING_RATE); // update modulation parameters if(longInterleaving && (modem == RADIOLIB_SX128X_PACKET_TYPE_LORA)) { - this->codingRateLoRa = cr; + switch(cr) { + case 4: + this->codingRateLoRa = 0; + break; + case 5: + case 6: + this->codingRateLoRa = cr; + break; + case 8: + this->codingRateLoRa = cr - 1; + break; + default: + return(RADIOLIB_ERR_INVALID_CODING_RATE); + } } else { this->codingRateLoRa = cr - 4; } diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index 6c35f498..9f42f946 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -370,7 +370,8 @@ class SX128x: public PhysicalLayer { \param freq Carrier frequency in MHz. Defaults to 2400.0 MHz. \param bw LoRa bandwidth in kHz. Defaults to 812.5 kHz. \param sf LoRa spreading factor. Defaults to 9. - \param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7). + \param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7). Allowed values range from 4 to 8. Note that a value of 4 means no coding, + is undocumented and not recommended without your own FEC. \param syncWord 2-byte LoRa sync word. Defaults to RADIOLIB_SX128X_SYNC_WORD_PRIVATE (0x12). \param pwr Output power in dBm. Defaults to 10 dBm. \param preambleLength LoRa preamble length in symbols. Defaults to 12 symbols. @@ -626,7 +627,8 @@ class SX128x: public PhysicalLayer { int16_t setSpreadingFactor(uint8_t sf); /*! - \brief Sets LoRa coding rate denominator. Allowed values range from 5 to 8. + \brief Sets LoRa coding rate denominator. Allowed values range from 4 to 8. Note that a value of 4 + means no coding, is undocumented and not recommended without your own FEC. \param cr LoRa coding rate denominator to be set. \param longInterleaving Whether to enable long interleaving mode. Not available for coding rate 4/7, defaults to false.