From b65fb885260fe1c345f61433645e09b5752497fc Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 24 Sep 2023 18:17:32 +0200 Subject: [PATCH 1/3] [RFM9x] Use RFM9x only as alias for SX127x (#833) --- src/modules/RFM9x/RFM95.cpp | 93 ------------------------------------ src/modules/RFM9x/RFM95.h | 80 ------------------------------- src/modules/RFM9x/RFM96.cpp | 94 ------------------------------------- src/modules/RFM9x/RFM96.h | 88 ---------------------------------- src/modules/RFM9x/RFM97.cpp | 42 ----------------- src/modules/RFM9x/RFM97.h | 45 ------------------ src/modules/SX127x/SX1276.h | 6 +++ src/modules/SX127x/SX1277.h | 6 +++ src/modules/SX127x/SX1278.h | 6 +++ 9 files changed, 18 insertions(+), 442 deletions(-) delete mode 100644 src/modules/RFM9x/RFM95.cpp delete mode 100644 src/modules/RFM9x/RFM95.h delete mode 100644 src/modules/RFM9x/RFM96.cpp delete mode 100644 src/modules/RFM9x/RFM96.h delete mode 100644 src/modules/RFM9x/RFM97.cpp delete mode 100644 src/modules/RFM9x/RFM97.h diff --git a/src/modules/RFM9x/RFM95.cpp b/src/modules/RFM9x/RFM95.cpp deleted file mode 100644 index 90f1bc46..00000000 --- a/src/modules/RFM9x/RFM95.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "RFM95.h" -#if !defined(RADIOLIB_EXCLUDE_RFM9X) - -RFM95::RFM95(Module* mod) : SX1278(mod) { - -} - -int16_t RFM95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { - // execute common part - int16_t state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, syncWord, preambleLength); - if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) { - // SX127X_REG_VERSION might be set 0x12 - state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, preambleLength); - RADIOLIB_ASSERT(state); - } else if(state != RADIOLIB_ERR_NONE) { - // some other error - return(state); - } - RADIOLIB_DEBUG_PRINTLN("M\tSX1278"); - RADIOLIB_DEBUG_PRINTLN("M\tRFM95"); - - // configure publicly accessible settings - state = setBandwidth(bw); - RADIOLIB_ASSERT(state); - - state = setFrequency(freq); - RADIOLIB_ASSERT(state); - - state = setSpreadingFactor(sf); - RADIOLIB_ASSERT(state); - - state = setCodingRate(cr); - RADIOLIB_ASSERT(state); - - state = setOutputPower(power); - RADIOLIB_ASSERT(state); - - state = setGain(gain); - - return(state); -} - -int16_t RFM95::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) { - // execute common part - int16_t state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, freqDev, rxBw, preambleLength, enableOOK); - if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) { - // SX127X_REG_VERSION might be set 0x12 - state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, freqDev, rxBw, preambleLength, enableOOK); - RADIOLIB_ASSERT(state); - } else if(state != RADIOLIB_ERR_NONE) { - // some other error - return(state); - } - RADIOLIB_DEBUG_PRINTLN("M\tSX1278"); - RADIOLIB_DEBUG_PRINTLN("M\tRFM95"); - - // configure settings not accessible by API - state = configFSK(); - RADIOLIB_ASSERT(state); - - // configure publicly accessible settings - state = setFrequency(freq); - RADIOLIB_ASSERT(state); - - state = setBitRate(br); - RADIOLIB_ASSERT(state); - - state = setOutputPower(power); - RADIOLIB_ASSERT(state); - - if(enableOOK) { - state = setDataShapingOOK(RADIOLIB_SHAPING_NONE); - RADIOLIB_ASSERT(state); - } else { - state = setDataShaping(RADIOLIB_SHAPING_NONE); - RADIOLIB_ASSERT(state); - } - - return(state); -} - -int16_t RFM95::setFrequency(float freq) { - RADIOLIB_CHECK_RANGE(freq, 862.0, 1020.0, RADIOLIB_ERR_INVALID_FREQUENCY); - - // set frequency and if successful, save the new setting - int16_t state = SX127x::setFrequencyRaw(freq); - if(state == RADIOLIB_ERR_NONE) { - SX127x::frequency = freq; - } - return(state); -} - -#endif diff --git a/src/modules/RFM9x/RFM95.h b/src/modules/RFM9x/RFM95.h deleted file mode 100644 index c0128003..00000000 --- a/src/modules/RFM9x/RFM95.h +++ /dev/null @@ -1,80 +0,0 @@ -#if !defined(_RADIOLIB_RFM95_H) -#define _RADIOLIB_RFM95_H - -#include "../../TypeDef.h" - -#if !defined(RADIOLIB_EXCLUDE_RFM9X) - -#include "../../Module.h" -#include "../SX127x/SX127x.h" -#include "../SX127x/SX1278.h" - -// SX127X_REG_VERSION -#define RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL 0x11 -#define RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL 0x12 // according to datasheet, only 0x11 should be possible, but some modules seem to have 0x12 - -/*! - \class RFM95 - \brief Derived class for %RFM95 modules. Overrides some methods from SX1278 due to different parameter ranges. -*/ -class RFM95: public SX1278 { - public: - - // constructor - - /*! - \brief Default constructor. Called from Arduino sketch when creating new LoRa instance. - \param mod Instance of Module that will be used to communicate with the %LoRa chip. - */ - RFM95(Module* mod); - - // basic methods - - /*! - \brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module. - \param freq Carrier frequency in MHz. Allowed values range from 868.0 MHz to 915.0 MHz. - \param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 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 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. - Allowed values range from 6 to 65535. - \param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain. - Set to 0 to enable automatic gain control (recommended). - \returns \ref status_codes - */ - int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); - - /*! - \brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module. - \param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz. - \param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps. - \param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz. - Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met. - \param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz. - \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - \param preambleLength Length of FSK preamble in bits. - \param enableOOK Use OOK modulation instead of FSK. - \returns \ref status_codes - */ - int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false); - - // configuration methods - - /*! - \brief Sets carrier frequency. Allowed values range from 868.0 MHz to 915.0 MHz. - \param freq Carrier frequency to be set in MHz. - \returns \ref status_codes - */ - int16_t setFrequency(float freq); - -#if !defined(RADIOLIB_GODMODE) - private: -#endif - -}; - -#endif - -#endif diff --git a/src/modules/RFM9x/RFM96.cpp b/src/modules/RFM9x/RFM96.cpp deleted file mode 100644 index 0c744184..00000000 --- a/src/modules/RFM9x/RFM96.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "RFM96.h" -#if !defined(RADIOLIB_EXCLUDE_RFM9X) - -RFM96::RFM96(Module* mod) : SX1278(mod) { - -} - -int16_t RFM96::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { - // execute common part - int16_t state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, syncWord, preambleLength); - if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) { - // SX127X_REG_VERSION might be set 0x12 - state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, preambleLength); - RADIOLIB_ASSERT(state); - } else if(state != RADIOLIB_ERR_NONE) { - // some other error - return(state); - } - RADIOLIB_DEBUG_PRINTLN("M\tSX1278"); - RADIOLIB_DEBUG_PRINTLN("M\tRFM96"); - - // configure publicly accessible settings - state = setBandwidth(bw); - RADIOLIB_ASSERT(state); - - state = setFrequency(freq); - RADIOLIB_ASSERT(state); - - state = setSpreadingFactor(sf); - RADIOLIB_ASSERT(state); - - state = setCodingRate(cr); - RADIOLIB_ASSERT(state); - - state = setOutputPower(power); - RADIOLIB_ASSERT(state); - - state = setGain(gain); - RADIOLIB_ASSERT(state); - - return(state); -} - -int16_t RFM96::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) { - // execute common part - int16_t state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, freqDev, rxBw, preambleLength, enableOOK); - if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) { - // SX127X_REG_VERSION might be set 0x12 - state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, freqDev, rxBw, preambleLength, enableOOK); - RADIOLIB_ASSERT(state); - } else if(state != RADIOLIB_ERR_NONE) { - // some other error - return(state); - } - RADIOLIB_DEBUG_PRINTLN("M\tSX1278"); - RADIOLIB_DEBUG_PRINTLN("M\tRFM96"); - - // configure settings not accessible by API - state = configFSK(); - RADIOLIB_ASSERT(state); - - // configure publicly accessible settings - state = setFrequency(freq); - RADIOLIB_ASSERT(state); - - state = setBitRate(br); - RADIOLIB_ASSERT(state); - - state = setOutputPower(power); - RADIOLIB_ASSERT(state); - - if(enableOOK) { - state = setDataShapingOOK(RADIOLIB_SHAPING_NONE); - RADIOLIB_ASSERT(state); - } else { - state = setDataShaping(RADIOLIB_SHAPING_NONE); - RADIOLIB_ASSERT(state); - } - - return(state); -} - -int16_t RFM96::setFrequency(float freq) { - RADIOLIB_CHECK_RANGE(freq, 410.0, 525.0, RADIOLIB_ERR_INVALID_FREQUENCY); - - // set frequency and if successful, save the new setting - int16_t state = SX127x::setFrequencyRaw(freq); - if(state == RADIOLIB_ERR_NONE) { - SX127x::frequency = freq; - } - return(state); -} - -#endif diff --git a/src/modules/RFM9x/RFM96.h b/src/modules/RFM9x/RFM96.h deleted file mode 100644 index e5990197..00000000 --- a/src/modules/RFM9x/RFM96.h +++ /dev/null @@ -1,88 +0,0 @@ -#if !defined(_RADIOLIB_RFM96_H) -#define _RADIOLIB_RFM96_H - -#include "../../TypeDef.h" - -#if !defined(RADIOLIB_EXCLUDE_RFM9X) - -#include "../../Module.h" -#include "../SX127x/SX127x.h" -#include "../SX127x/SX1278.h" - -// SX127X_REG_VERSION -#define RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL 0x11 -#define RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL 0x12 // according to datasheet, only 0x11 should be possible, but some modules seem to have 0x12 - -/*! - \class RFM96 - \brief Derived class for %RFM96 modules. Overrides some methods from SX1278 due to different parameter ranges. -*/ -class RFM96: public SX1278 { - public: - - // constructor - - /*! - \brief Default constructor. Called from Arduino sketch when creating new LoRa instance. - \param mod Instance of Module that will be used to communicate with the %LoRa chip. - */ - RFM96(Module* mod); - - // basic methods - - /*! - \brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module. - \param freq Carrier frequency in MHz. Allowed values range from 433.0 MHz to 470.0 MHz. - \param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 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 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. Allowed values range from 6 to 65535. - \param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 - where 1 is the highest gain. Set to 0 to enable automatic gain control (recommended). - \returns \ref status_codes - */ - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); - - /*! - \brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module. - \param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz. - \param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps. - \param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz. - Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met. - \param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, - 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz. - \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - \param preambleLength Length of FSK preamble in bits. - \param enableOOK Use OOK modulation instead of FSK. - \returns \ref status_codes - */ - int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false); - - // configuration methods - - /*! - \brief Sets carrier frequency. Allowed values range from 433.0 MHz to 470.0 MHz. - \param freq Carrier frequency to be set in MHz. - \returns \ref status_codes - */ - int16_t setFrequency(float freq); - -#if !defined(RADIOLIB_GODMODE) - private: -#endif - -}; - -/*! - \class RFM98 - \brief Only exists as alias for RFM96, since there seems to be no difference between %RFM96 and %RFM98 modules. -*/ -RADIOLIB_TYPE_ALIAS(RFM96, RFM98); - -#endif - -#endif diff --git a/src/modules/RFM9x/RFM97.cpp b/src/modules/RFM9x/RFM97.cpp deleted file mode 100644 index 0d02c707..00000000 --- a/src/modules/RFM9x/RFM97.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "RFM97.h" -#if !defined(RADIOLIB_EXCLUDE_RFM9X) - -RFM97::RFM97(Module* mod) : RFM95(mod) { - -}; - -int16_t RFM97::setSpreadingFactor(uint8_t sf) { - // check active modem - if(getActiveModem() != RADIOLIB_SX127X_LORA) { - return(RADIOLIB_ERR_WRONG_MODEM); - } - - uint8_t newSpreadingFactor; - - // check allowed spreading factor values - switch(sf) { - case 6: - newSpreadingFactor = RADIOLIB_SX127X_SF_6; - break; - case 7: - newSpreadingFactor = RADIOLIB_SX127X_SF_7; - break; - case 8: - newSpreadingFactor = RADIOLIB_SX127X_SF_8; - break; - case 9: - newSpreadingFactor = RADIOLIB_SX127X_SF_9; - break; - default: - return(RADIOLIB_ERR_INVALID_SPREADING_FACTOR); - } - - // set spreading factor and if successful, save the new setting - int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor); - if(state == RADIOLIB_ERR_NONE) { - SX127x::spreadingFactor = sf; - } - return(state); -} - -#endif diff --git a/src/modules/RFM9x/RFM97.h b/src/modules/RFM9x/RFM97.h deleted file mode 100644 index b4623495..00000000 --- a/src/modules/RFM9x/RFM97.h +++ /dev/null @@ -1,45 +0,0 @@ -#if !defined(_RADIOLIB_RFM97_H) -#define _RADIOLIB_RFM97_H - -#include "../../TypeDef.h" - -#if !defined(RADIOLIB_EXCLUDE_RFM9X) - -#include "../../Module.h" -#include "../SX127x/SX127x.h" -#include "../SX127x/SX1278.h" -#include "RFM95.h" - -/*! - \class RFM97 - \brief Derived class for %RFM97 modules. Overrides some methods from RFM95 due to different parameter ranges. -*/ -class RFM97: public RFM95 { - public: - - // constructor - - /*! - \brief Default constructor. Called from Arduino sketch when creating new LoRa instance. - \param mod Instance of Module that will be used to communicate with the %LoRa chip. - */ - RFM97(Module* mod); - - // configuration methods - - /*! - \brief Sets %LoRa link spreading factor. Allowed values range from 6 to 9. Only available in %LoRa mode. - \param sf %LoRa link spreading factor to be set. - \returns \ref status_codes - */ - int16_t setSpreadingFactor(uint8_t sf); - -#if !defined(RADIOLIB_GODMODE) - private: -#endif - -}; - -#endif - -#endif diff --git a/src/modules/SX127x/SX1276.h b/src/modules/SX127x/SX1276.h index 0d83fb36..659e22d7 100644 --- a/src/modules/SX127x/SX1276.h +++ b/src/modules/SX127x/SX1276.h @@ -69,6 +69,12 @@ class SX1276: public SX1278 { }; +/*! + \class RFM96 + \brief Only exists as alias for SX1276, since there seems to be no difference between %RFM96 and %SX1276 modules. +*/ +RADIOLIB_TYPE_ALIAS(SX1276, RFM96); + #endif #endif diff --git a/src/modules/SX127x/SX1277.h b/src/modules/SX127x/SX1277.h index 88fb58fe..15804d61 100644 --- a/src/modules/SX127x/SX1277.h +++ b/src/modules/SX127x/SX1277.h @@ -83,6 +83,12 @@ class SX1277: public SX1278 { }; +/*! + \class RFM97 + \brief Only exists as alias for SX1277, since there seems to be no difference between %RFM97 and %SX1277 modules. +*/ +RADIOLIB_TYPE_ALIAS(SX1277, RFM97); + #endif #endif diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index 92c996ed..a6db4297 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -299,6 +299,12 @@ class SX1278: public SX127x { }; +/*! + \class RFM98 + \brief Only exists as alias for SX1278, since there seems to be no difference between %RFM98 and %SX1278 modules. +*/ +RADIOLIB_TYPE_ALIAS(SX1278, RFM98); + #endif #endif From 10d225fadb6bcecea440788689330d66cee2fca2 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 24 Sep 2023 18:19:19 +0200 Subject: [PATCH 2/3] [SX127x] Allow alternate chip versions --- src/modules/SX127x/SX1272.cpp | 6 ++++-- src/modules/SX127x/SX1273.cpp | 3 ++- src/modules/SX127x/SX1276.cpp | 6 ++++-- src/modules/SX127x/SX1277.cpp | 6 ++++-- src/modules/SX127x/SX1278.cpp | 6 ++++-- src/modules/SX127x/SX1278.h | 4 +++- src/modules/SX127x/SX1279.cpp | 6 ++++-- src/modules/SX127x/SX127x.cpp | 24 +++++++++++++++--------- src/modules/SX127x/SX127x.h | 12 +++++++----- 9 files changed, 47 insertions(+), 26 deletions(-) diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index ac572101..45bf8802 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -8,7 +8,8 @@ SX1272::SX1272(Module* mod) : SX127x(mod) { int16_t SX1272::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(RADIOLIB_SX1272_CHIP_VERSION, syncWord, preambleLength); + uint8_t version = RADIOLIB_SX1272_CHIP_VERSION; + int16_t state = SX127x::begin(&version, 1, syncWord, preambleLength); RADIOLIB_ASSERT(state); // configure publicly accessible settings @@ -39,7 +40,8 @@ int16_t SX1272::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync int16_t SX1272::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) { // execute common part - int16_t state = SX127x::beginFSK(RADIOLIB_SX1272_CHIP_VERSION, freqDev, rxBw, preambleLength, enableOOK); + uint8_t version = RADIOLIB_SX1272_CHIP_VERSION; + int16_t state = SX127x::beginFSK(&version, 1, freqDev, rxBw, preambleLength, enableOOK); RADIOLIB_ASSERT(state); // configure settings not accessible by API diff --git a/src/modules/SX127x/SX1273.cpp b/src/modules/SX127x/SX1273.cpp index 4b180694..ea021c66 100644 --- a/src/modules/SX127x/SX1273.cpp +++ b/src/modules/SX127x/SX1273.cpp @@ -7,7 +7,8 @@ SX1273::SX1273(Module* mod) : SX1272(mod) { int16_t SX1273::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(RADIOLIB_SX1272_CHIP_VERSION, syncWord, preambleLength); + uint8_t version = RADIOLIB_SX1272_CHIP_VERSION; + int16_t state = SX127x::begin(&version, 1, syncWord, preambleLength); RADIOLIB_ASSERT(state); // configure publicly accessible settings diff --git a/src/modules/SX127x/SX1276.cpp b/src/modules/SX127x/SX1276.cpp index 21eadb57..b20fd7d1 100644 --- a/src/modules/SX127x/SX1276.cpp +++ b/src/modules/SX127x/SX1276.cpp @@ -7,7 +7,8 @@ SX1276::SX1276(Module* mod) : SX1278(mod) { int16_t SX1276::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(RADIOLIB_SX1278_CHIP_VERSION, syncWord, preambleLength); + uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X }; + int16_t state = SX127x::begin(versions, 3, syncWord, preambleLength); RADIOLIB_ASSERT(state); // configure publicly accessible settings @@ -38,7 +39,8 @@ int16_t SX1276::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync int16_t SX1276::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) { // execute common part - int16_t state = SX127x::beginFSK(RADIOLIB_SX1278_CHIP_VERSION, freqDev, rxBw, preambleLength, enableOOK); + uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X }; + int16_t state = SX127x::beginFSK(versions, 3, freqDev, rxBw, preambleLength, enableOOK); RADIOLIB_ASSERT(state); // configure settings not accessible by API diff --git a/src/modules/SX127x/SX1277.cpp b/src/modules/SX127x/SX1277.cpp index d466a385..5875bd9f 100644 --- a/src/modules/SX127x/SX1277.cpp +++ b/src/modules/SX127x/SX1277.cpp @@ -7,7 +7,8 @@ SX1277::SX1277(Module* mod) : SX1278(mod) { int16_t SX1277::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(RADIOLIB_SX1278_CHIP_VERSION, syncWord, preambleLength); + uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X }; + int16_t state = SX127x::begin(versions, 3, syncWord, preambleLength); RADIOLIB_ASSERT(state); // configure publicly accessible settings @@ -38,7 +39,8 @@ int16_t SX1277::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync int16_t SX1277::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) { // execute common part - int16_t state = SX127x::beginFSK(RADIOLIB_SX1278_CHIP_VERSION, freqDev, rxBw, preambleLength, enableOOK); + uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X }; + int16_t state = SX127x::beginFSK(versions, 3, freqDev, rxBw, preambleLength, enableOOK); RADIOLIB_ASSERT(state); // configure settings not accessible by API diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index 9fb0c5df..90325ff0 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -8,7 +8,8 @@ SX1278::SX1278(Module* mod) : SX127x(mod) { int16_t SX1278::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(RADIOLIB_SX1278_CHIP_VERSION, syncWord, preambleLength); + uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X }; + int16_t state = SX127x::begin(versions, 3, syncWord, preambleLength); RADIOLIB_ASSERT(state); // configure publicly accessible settings @@ -39,7 +40,8 @@ int16_t SX1278::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync int16_t SX1278::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) { // execute common part - int16_t state = SX127x::beginFSK(RADIOLIB_SX1278_CHIP_VERSION, freqDev, rxBw, preambleLength, enableOOK); + uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X }; + int16_t state = SX127x::beginFSK(versions, 3, freqDev, rxBw, preambleLength, enableOOK); RADIOLIB_ASSERT(state); // configure settings not accessible by API diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index a6db4297..c9f966a2 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -67,7 +67,9 @@ #define RADIOLIB_SX1278_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop // SX127X_REG_VERSION -#define RADIOLIB_SX1278_CHIP_VERSION 0x12 +#define RADIOLIB_SX1278_CHIP_VERSION 0x12 // this is the "official" version listed in datasheet +#define RADIOLIB_SX1278_CHIP_VERSION_ALT 0x13 // appears sometimes +#define RADIOLIB_SX1278_CHIP_VERSION_RFM9X 0x11 // this value is used for the RFM9x // SX1278 FSK modem settings // SX127X_REG_PA_RAMP diff --git a/src/modules/SX127x/SX1279.cpp b/src/modules/SX127x/SX1279.cpp index ae79f0f8..4fdd4daa 100644 --- a/src/modules/SX127x/SX1279.cpp +++ b/src/modules/SX127x/SX1279.cpp @@ -7,7 +7,8 @@ SX1279::SX1279(Module* mod) : SX1278(mod) { int16_t SX1279::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(RADIOLIB_SX1278_CHIP_VERSION, syncWord, preambleLength); + uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X }; + int16_t state = SX127x::begin(versions, 3, syncWord, preambleLength); RADIOLIB_ASSERT(state); // configure publicly accessible settings @@ -38,7 +39,8 @@ int16_t SX1279::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync int16_t SX1279::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) { // execute common part - int16_t state = SX127x::beginFSK(RADIOLIB_SX1278_CHIP_VERSION, freqDev, rxBw, preambleLength, enableOOK); + uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X }; + int16_t state = SX127x::beginFSK(versions, 3, freqDev, rxBw, preambleLength, enableOOK); RADIOLIB_ASSERT(state); // configure settings not accessible by API diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 1a8f2eaf..7198e432 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -10,14 +10,14 @@ Module* SX127x::getMod() { return(this->mod); } -int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint16_t preambleLength) { +int16_t SX127x::begin(uint8_t* chipVersions, uint8_t numVersions, uint8_t syncWord, uint16_t preambleLength) { // set module properties this->mod->init(); this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput); this->mod->hal->pinMode(this->mod->getGpio(), this->mod->hal->GpioModeInput); // try to find the SX127x chip - if(!SX127x::findChip(chipVersion)) { + if(!SX127x::findChip(chipVersions, numVersions)) { RADIOLIB_DEBUG_PRINTLN("No SX127x found!"); this->mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); @@ -61,14 +61,14 @@ int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint16_t preambleLe return(state); } -int16_t SX127x::beginFSK(uint8_t chipVersion, float freqDev, float rxBw, uint16_t preambleLength, bool enableOOK) { +int16_t SX127x::beginFSK(uint8_t* chipVersions, uint8_t numVersions, float freqDev, float rxBw, uint16_t preambleLength, bool enableOOK) { // set module properties this->mod->init(); this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput); this->mod->hal->pinMode(this->mod->getGpio(), this->mod->hal->GpioModeInput); // try to find the SX127x chip - if(!SX127x::findChip(chipVersion)) { + if(!SX127x::findChip(chipVersions, numVersions)) { RADIOLIB_DEBUG_PRINTLN("No SX127x found!"); this->mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); @@ -1473,7 +1473,7 @@ int16_t SX127x::setPacketMode(uint8_t mode, uint8_t len) { return(state); } -bool SX127x::findChip(uint8_t ver) { +bool SX127x::findChip(uint8_t* vers, uint8_t num) { uint8_t i = 0; bool flagFound = false; while((i < 10) && !flagFound) { @@ -1482,13 +1482,19 @@ bool SX127x::findChip(uint8_t ver) { // check version register int16_t version = getChipVersion(); - if(version == ver) { - flagFound = true; - } else { - RADIOLIB_DEBUG_PRINTLN("SX127x not found! (%d of 10 tries) RADIOLIB_SX127X_REG_VERSION == 0x%04X, expected 0x00%X", i + 1, version, ver); + for(uint8_t i = 0; i < num; i++) { + if(version == vers[i]) { + flagFound = true; + break; + } + } + + if(!flagFound) { + RADIOLIB_DEBUG_PRINTLN("SX127x not found! (%d of 10 tries) RADIOLIB_SX127X_REG_VERSION == 0x%04X", i + 1, version); this->mod->hal->delay(10); i++; } + } return(flagFound); diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 9ef2890f..9a622538 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -601,12 +601,13 @@ class SX127x: public PhysicalLayer { /*! \brief Initialization method. Will be called with appropriate parameters when calling initialization method from derived class. - \param chipVersion Value in SPI version register. Used to verify the connection and hardware version. + \param chipVersion Array of possible values in SPI version register. Used to verify the connection and hardware version. + \param numVersions Number of possible chip versions. \param syncWord %LoRa sync word. \param preambleLength Length of %LoRa transmission preamble in symbols. \returns \ref status_codes */ - int16_t begin(uint8_t chipVersion, uint8_t syncWord, uint16_t preambleLength); + int16_t begin(uint8_t* chipVersions, uint8_t numVersions, uint8_t syncWord, uint16_t preambleLength); /*! \brief Reset method. Will reset the chip to the default state using RST pin. Declared pure virtual since SX1272 and SX1278 implementations differ. @@ -615,14 +616,15 @@ class SX127x: public PhysicalLayer { /*! \brief Initialization method for FSK modem. Will be called with appropriate parameters when calling FSK initialization method from derived class. - \param chipVersion Value in SPI version register. Used to verify the connection and hardware version. + \param chipVersion Array of possible values in SPI version register. Used to verify the connection and hardware version. + \param numVersions Number of possible chip versions. \param freqDev Frequency deviation of the FSK transmission in kHz. \param rxBw Receiver bandwidth in kHz. \param preambleLength Length of FSK preamble in bits. \param enableOOK Flag to specify OOK mode. This modulation is similar to FSK. \returns \ref status_codes */ - int16_t beginFSK(uint8_t chipVersion, float freqDev, float rxBw, uint16_t preambleLength, bool enableOOK); + int16_t beginFSK(uint8_t* chipVersions, uint8_t numVersions, float freqDev, float rxBw, uint16_t preambleLength, bool enableOOK); /*! \brief Binary transmit method. Will transmit arbitrary binary data up to 255 bytes long using %LoRa or up to 63 bytes using FSK modem. @@ -1211,7 +1213,7 @@ class SX127x: public PhysicalLayer { bool packetLengthQueried = false; // FSK packet length is the first byte in FIFO, length can only be queried once uint8_t packetLengthConfig = RADIOLIB_SX127X_PACKET_VARIABLE; - bool findChip(uint8_t ver); + bool findChip(uint8_t* vers, uint8_t num); int16_t setMode(uint8_t mode); int16_t setActiveModem(uint8_t modem); void clearIRQFlags(); From b817819c60b1b2af6dcd69f678ce4dcaa41db1b0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 24 Sep 2023 18:19:48 +0200 Subject: [PATCH 3/3] [RM9x] Drop RFM9x as separate class --- src/BuildOpt.h | 1 - src/RadioLib.h | 3 --- 2 files changed, 4 deletions(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 5fe2e0ba..275539c6 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -68,7 +68,6 @@ //#define RADIOLIB_EXCLUDE_SI443X //#define RADIOLIB_EXCLUDE_RFM2X // dependent on RADIOLIB_EXCLUDE_SI443X //#define RADIOLIB_EXCLUDE_SX127X - //#define RADIOLIB_EXCLUDE_RFM9X // dependent on RADIOLIB_EXCLUDE_SX127X //#define RADIOLIB_EXCLUDE_SX126X //#define RADIOLIB_EXCLUDE_STM32WLX // dependent on RADIOLIB_EXCLUDE_SX126X //#define RADIOLIB_EXCLUDE_SX128X diff --git a/src/RadioLib.h b/src/RadioLib.h index 8eaa072a..ee7026d2 100644 --- a/src/RadioLib.h +++ b/src/RadioLib.h @@ -76,9 +76,6 @@ #include "modules/RF69/RF69.h" #include "modules/RFM2x/RFM22.h" #include "modules/RFM2x/RFM23.h" -#include "modules/RFM9x/RFM95.h" -#include "modules/RFM9x/RFM96.h" -#include "modules/RFM9x/RFM97.h" #include "modules/Si443x/Si4430.h" #include "modules/Si443x/Si4431.h" #include "modules/Si443x/Si4432.h"