From 47bc673bc557642d06909388382daf245c2ac89e Mon Sep 17 00:00:00 2001 From: GUVWAF Date: Mon, 1 Sep 2025 19:50:55 +0200 Subject: [PATCH] [SX1272] Add support for coding rate 4/4 --- src/modules/SX127x/SX1272.cpp | 5 ++++- src/modules/SX127x/SX1272.h | 9 ++++++--- src/modules/SX127x/SX1273.cpp | 2 +- src/modules/SX127x/SX1273.h | 3 ++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index e6e4406d..313cbff0 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -195,6 +195,9 @@ int16_t SX1272::setCodingRate(uint8_t cr) { // check allowed coding rate values switch(cr) { + case 4: + newCodingRate = RADIOLIB_SX1272_CR_4_4; + break; case 5: newCodingRate = RADIOLIB_SX1272_CR_4_5; break; @@ -267,7 +270,7 @@ int16_t SX1272::checkDataRate(DataRate_t dr) { } else if(modem == RADIOLIB_SX127X_LORA) { RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 12, RADIOLIB_ERR_INVALID_SPREADING_FACTOR); RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 100.0f, 510.0f, RADIOLIB_ERR_INVALID_BANDWIDTH); - RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE); + RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 4, 8, RADIOLIB_ERR_INVALID_CODING_RATE); return(RADIOLIB_ERR_NONE); } diff --git a/src/modules/SX127x/SX1272.h b/src/modules/SX127x/SX1272.h index f3d83545..92760148 100644 --- a/src/modules/SX127x/SX1272.h +++ b/src/modules/SX127x/SX1272.h @@ -31,7 +31,8 @@ #define RADIOLIB_SX1272_BW_125_00_KHZ 0b00000000 // 7 6 bandwidth: 125 kHz #define RADIOLIB_SX1272_BW_250_00_KHZ 0b01000000 // 7 6 250 kHz #define RADIOLIB_SX1272_BW_500_00_KHZ 0b10000000 // 7 6 500 kHz -#define RADIOLIB_SX1272_CR_4_5 0b00001000 // 5 3 error coding rate: 4/5 +#define RADIOLIB_SX1272_CR_4_4 0b00000000 // 5 3 error coding rate: 4/4 (undocumented) +#define RADIOLIB_SX1272_CR_4_5 0b00001000 // 5 3 4/5 #define RADIOLIB_SX1272_CR_4_6 0b00010000 // 5 3 4/6 #define RADIOLIB_SX1272_CR_4_7 0b00011000 // 5 3 4/7 #define RADIOLIB_SX1272_CR_4_8 0b00100000 // 5 3 4/8 @@ -109,7 +110,8 @@ class SX1272: public SX127x { \param freq Carrier frequency in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz. \param bw %LoRa link bandwidth in kHz. Allowed values are 125, 250 and 500 kHz. \param sf %LoRa link spreading factor. Allowed values range from 6 to 12. - \param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8. + \param cr %LoRa link 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 syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks. \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. @@ -163,7 +165,8 @@ class SX1272: public SX127x { virtual int16_t setSpreadingFactor(uint8_t sf); /*! - \brief Sets %LoRa link coding rate denominator. Allowed values range from 5 to 8. Only available in %LoRa mode. + \brief Sets %LoRa link coding rate denominator. Allowed values range from 4 to 8. Only available in %LoRa mode. + Note that a value of 4 means no coding, is undocumented and not recommended without your own FEC. \param cr %LoRa link coding rate denominator to be set. \returns \ref status_codes */ diff --git a/src/modules/SX127x/SX1273.cpp b/src/modules/SX127x/SX1273.cpp index 11aace90..c9b1f4b2 100644 --- a/src/modules/SX127x/SX1273.cpp +++ b/src/modules/SX127x/SX1273.cpp @@ -107,7 +107,7 @@ int16_t SX1273::checkDataRate(DataRate_t dr) { } else if(modem == RADIOLIB_SX127X_LORA) { RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 9, RADIOLIB_ERR_INVALID_SPREADING_FACTOR); RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 100.0f, 510.0f, RADIOLIB_ERR_INVALID_BANDWIDTH); - RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE); + RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 4, 8, RADIOLIB_ERR_INVALID_CODING_RATE); return(RADIOLIB_ERR_NONE); } diff --git a/src/modules/SX127x/SX1273.h b/src/modules/SX127x/SX1273.h index 2a2e3b5e..40395d99 100644 --- a/src/modules/SX127x/SX1273.h +++ b/src/modules/SX127x/SX1273.h @@ -29,7 +29,8 @@ class SX1273: public SX1272 { \param freq Carrier frequency in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz. \param bw %LoRa link bandwidth in kHz. Allowed values are 125, 250 and 500 kHz. \param sf %LoRa link spreading factor. Allowed values range from 6 to 9. - \param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8. + \param cr %LoRa link 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 syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks. \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.