From cc8c8f2eedbe6162d1fa73967c9be25afee5f99b Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 23 Apr 2023 22:42:13 +0200 Subject: [PATCH] [SX127x] General reformatting --- src/modules/RFM9x/RFM95.cpp | 2 +- src/modules/RFM9x/RFM95.h | 25 +- src/modules/RFM9x/RFM96.cpp | 2 +- src/modules/RFM9x/RFM96.h | 40 +- src/modules/RFM9x/RFM97.cpp | 2 +- src/modules/RFM9x/RFM97.h | 4 - src/modules/SX127x/SX1272.cpp | 134 ++-- src/modules/SX127x/SX1272.h | 160 ++--- src/modules/SX127x/SX1273.cpp | 2 +- src/modules/SX127x/SX1273.h | 13 - src/modules/SX127x/SX1276.cpp | 2 +- src/modules/SX127x/SX1276.h | 21 - src/modules/SX127x/SX1277.cpp | 4 +- src/modules/SX127x/SX1277.h | 23 - src/modules/SX127x/SX1278.cpp | 182 ++--- src/modules/SX127x/SX1278.h | 184 ++--- src/modules/SX127x/SX1279.cpp | 2 +- src/modules/SX127x/SX1279.h | 21 - src/modules/SX127x/SX127x.cpp | 482 ++++++------- src/modules/SX127x/SX127x.h | 1239 +++++++++++++++------------------ 20 files changed, 1093 insertions(+), 1451 deletions(-) diff --git a/src/modules/RFM9x/RFM95.cpp b/src/modules/RFM9x/RFM95.cpp index 892fc53c..90f1bc46 100644 --- a/src/modules/RFM9x/RFM95.cpp +++ b/src/modules/RFM9x/RFM95.cpp @@ -85,7 +85,7 @@ int16_t RFM95::setFrequency(float freq) { // set frequency and if successful, save the new setting int16_t state = SX127x::setFrequencyRaw(freq); if(state == RADIOLIB_ERR_NONE) { - SX127x::_freq = freq; + SX127x::frequency = freq; } return(state); } diff --git a/src/modules/RFM9x/RFM95.h b/src/modules/RFM9x/RFM95.h index 18d2a91e..c0128003 100644 --- a/src/modules/RFM9x/RFM95.h +++ b/src/modules/RFM9x/RFM95.h @@ -10,12 +10,11 @@ #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 +#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 { @@ -25,7 +24,6 @@ class RFM95: public SX1278 { /*! \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); @@ -34,47 +32,30 @@ class RFM95: public SX1278 { /*! \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); @@ -83,9 +64,7 @@ class RFM95: public SX1278 { /*! \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); diff --git a/src/modules/RFM9x/RFM96.cpp b/src/modules/RFM9x/RFM96.cpp index 2f7f451a..0c744184 100644 --- a/src/modules/RFM9x/RFM96.cpp +++ b/src/modules/RFM9x/RFM96.cpp @@ -86,7 +86,7 @@ int16_t RFM96::setFrequency(float freq) { // set frequency and if successful, save the new setting int16_t state = SX127x::setFrequencyRaw(freq); if(state == RADIOLIB_ERR_NONE) { - SX127x::_freq = freq; + SX127x::frequency = freq; } return(state); } diff --git a/src/modules/RFM9x/RFM96.h b/src/modules/RFM9x/RFM96.h index 51bd481a..e5990197 100644 --- a/src/modules/RFM9x/RFM96.h +++ b/src/modules/RFM9x/RFM96.h @@ -10,12 +10,11 @@ #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 +#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 { @@ -25,7 +24,6 @@ class RFM96: public SX1278 { /*! \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); @@ -34,47 +32,32 @@ class RFM96: public SX1278 { /*! \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 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). - + \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 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); @@ -83,9 +66,7 @@ class RFM96: public SX1278 { /*! \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); @@ -98,7 +79,6 @@ class RFM96: public SX1278 { /*! \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); diff --git a/src/modules/RFM9x/RFM97.cpp b/src/modules/RFM9x/RFM97.cpp index e51e5a99..0d02c707 100644 --- a/src/modules/RFM9x/RFM97.cpp +++ b/src/modules/RFM9x/RFM97.cpp @@ -34,7 +34,7 @@ int16_t RFM97::setSpreadingFactor(uint8_t sf) { // set spreading factor and if successful, save the new setting int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor); if(state == RADIOLIB_ERR_NONE) { - SX127x::_sf = sf; + SX127x::spreadingFactor = sf; } return(state); } diff --git a/src/modules/RFM9x/RFM97.h b/src/modules/RFM9x/RFM97.h index aee0c0ad..b4623495 100644 --- a/src/modules/RFM9x/RFM97.h +++ b/src/modules/RFM9x/RFM97.h @@ -12,7 +12,6 @@ /*! \class RFM97 - \brief Derived class for %RFM97 modules. Overrides some methods from RFM95 due to different parameter ranges. */ class RFM97: public RFM95 { @@ -22,7 +21,6 @@ class RFM97: public RFM95 { /*! \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); @@ -31,9 +29,7 @@ class RFM97: public RFM95 { /*! \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); diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index cd1514f1..5ab4c136 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -72,11 +72,11 @@ int16_t SX1272::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t } void SX1272::reset() { - _mod->hal->pinMode(_mod->getRst(), _mod->hal->GpioModeOutput); - _mod->hal->digitalWrite(_mod->getRst(), _mod->hal->GpioLevelHigh); - _mod->hal->delay(1); - _mod->hal->digitalWrite(_mod->getRst(), _mod->hal->GpioLevelLow); - _mod->hal->delay(5); + this->mod->hal->pinMode(this->mod->getRst(), this->mod->hal->GpioModeOutput); + this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh); + this->mod->hal->delay(1); + this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow); + this->mod->hal->delay(5); } int16_t SX1272::setFrequency(float freq) { @@ -85,7 +85,7 @@ int16_t SX1272::setFrequency(float freq) { // set frequency and if successful, save the new setting int16_t state = SX127x::setFrequencyRaw(freq); if(state == RADIOLIB_ERR_NONE) { - SX127x::_freq = freq; + SX127x::frequency = freq; } return(state); } @@ -112,16 +112,16 @@ int16_t SX1272::setBandwidth(float bw) { // set bandwidth and if successful, save the new setting int16_t state = SX1272::setBandwidthRaw(newBandwidth); if(state == RADIOLIB_ERR_NONE) { - SX127x::_bw = bw; + SX127x::bandwidth = bw; // calculate symbol length and set low data rate optimization, if auto-configuration is enabled - if(_ldroAuto) { - float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; + if(this->ldroAuto) { + float symbolLength = (float)(uint32_t(1) << SX127x::spreadingFactor) / (float)SX127x::bandwidth; RADIOLIB_DEBUG_PRINTLN("Symbol length: %f ms", symbolLength); if(symbolLength >= 16.0) { - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0); } else { - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0); } } } @@ -166,16 +166,16 @@ int16_t SX1272::setSpreadingFactor(uint8_t sf) { // set spreading factor and if successful, save the new setting int16_t state = SX1272::setSpreadingFactorRaw(newSpreadingFactor); if(state == RADIOLIB_ERR_NONE) { - SX127x::_sf = sf; + SX127x::spreadingFactor = sf; // calculate symbol length and set low data rate optimization, if auto-configuration is enabled - if(_ldroAuto) { - float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; + if(this->ldroAuto) { + float symbolLength = (float)(uint32_t(1) << SX127x::spreadingFactor) / (float)SX127x::bandwidth; RADIOLIB_DEBUG_PRINTLN("Symbol length: %f ms", symbolLength); if(symbolLength >= 16.0) { - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0); } else { - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0); } } } @@ -211,7 +211,7 @@ int16_t SX1272::setCodingRate(uint8_t cr) { // set coding rate and if successful, save the new setting int16_t state = SX1272::setCodingRateRaw(newCodingRate); if(state == RADIOLIB_ERR_NONE) { - SX127x::_cr = cr; + SX127x::codingRate = cr; } return(state); } @@ -233,22 +233,22 @@ int16_t SX1272::setOutputPower(int8_t power, bool useRfo) { if(useRfo) { // RFO output - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_RFO, 7, 7); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power + 1), 3, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_RFO, 7, 7); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power + 1), 3, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0); } else { if(power <= 17) { // power is 2 - 17 dBm, enable PA1 + PA2 on PA_BOOST - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power - 2), 3, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power - 2), 3, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0); } else { // power is 18 - 20 dBm, enable PA1 + PA2 on PA_BOOST and enable high power control - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power - 5), 3, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_ON, 2, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power - 5), 3, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_ON, 2, 0); } @@ -272,20 +272,20 @@ int16_t SX1272::setGain(uint8_t gain) { // set gain if(gain == 0) { // gain set to 0, enable AGC loop - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_AGC_AUTO_ON, 2, 2); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_AGC_AUTO_ON, 2, 2); } else { - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_AGC_AUTO_OFF, 2, 2); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_AGC_AUTO_OFF, 2, 2); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON); } } else if(modem == RADIOLIB_SX127X_FSK_OOK) { // set gain if(gain == 0) { // gain set to 0, enable AGC loop - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3); } else { - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON); } } @@ -300,7 +300,7 @@ int16_t SX1272::setDataShaping(uint8_t sh) { } // check modulation - if(SX127x::_ook) { + if(SX127x::ookEnabled) { return(RADIOLIB_ERR_INVALID_MODULATION); } @@ -311,13 +311,13 @@ int16_t SX1272::setDataShaping(uint8_t sh) { // set data shaping switch(sh) { case RADIOLIB_SHAPING_NONE: - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_NO_SHAPING, 4, 3)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_NO_SHAPING, 4, 3)); case RADIOLIB_SHAPING_0_3: - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_0_3, 4, 3)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_0_3, 4, 3)); case RADIOLIB_SHAPING_0_5: - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_0_5, 4, 3)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_0_5, 4, 3)); case RADIOLIB_SHAPING_1_0: - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_1_0, 4, 3)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_1_0, 4, 3)); default: return(RADIOLIB_ERR_INVALID_DATA_SHAPING); } @@ -330,7 +330,7 @@ int16_t SX1272::setDataShapingOOK(uint8_t sh) { } // check modulation - if(!SX127x::_ook) { + if(!SX127x::ookEnabled) { return(RADIOLIB_ERR_INVALID_MODULATION); } @@ -340,13 +340,13 @@ int16_t SX1272::setDataShapingOOK(uint8_t sh) { // set data shaping switch(sh) { case 0: - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_NO_SHAPING, 4, 3); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_NO_SHAPING, 4, 3); break; case 1: - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_OOK_FILTER_BR, 4, 3); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_OOK_FILTER_BR, 4, 3); break; case 2: - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_OOK_FILTER_2BR, 4, 3); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_OOK_FILTER_2BR, 4, 3); break; default: state = RADIOLIB_ERR_INVALID_DATA_SHAPING; @@ -363,27 +363,27 @@ float SX1272::getRSSI(bool packet, bool skipReceive) { int16_t SX1272::setCRC(bool enable, bool mode) { if(getActiveModem() == RADIOLIB_SX127X_LORA) { // set LoRa CRC - SX127x::_crcEnabled = enable; + SX127x::crcEnabled = enable; if(enable) { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_RX_CRC_MODE_ON, 2, 2)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_RX_CRC_MODE_ON, 2, 2)); } else { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_RX_CRC_MODE_OFF, 2, 2)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_RX_CRC_MODE_OFF, 2, 2)); } } else { // set FSK CRC int16_t state = RADIOLIB_ERR_NONE; if(enable) { - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_ON, 4, 4); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_ON, 4, 4); } else { - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_OFF, 4, 4); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_OFF, 4, 4); } RADIOLIB_ASSERT(state); // set FSK CRC mode if(mode) { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM, 0, 0)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM, 0, 0)); } else { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT, 0, 0)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT, 0, 0)); } } } @@ -393,11 +393,11 @@ int16_t SX1272::forceLDRO(bool enable) { return(RADIOLIB_ERR_WRONG_MODEM); } - _ldroAuto = false; + this->ldroAuto = false; if(enable) { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0)); } else { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0)); } } @@ -406,7 +406,7 @@ int16_t SX1272::autoLDRO() { return(RADIOLIB_ERR_WRONG_MODEM); } - _ldroAuto = true; + this->ldroAuto = true; return(RADIOLIB_ERR_NONE); } @@ -423,7 +423,7 @@ int16_t SX1272::setBandwidthRaw(uint8_t newBandwidth) { int16_t state = SX127x::standby(); // write register - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newBandwidth, 7, 6); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newBandwidth, 7, 6); return(state); } @@ -433,15 +433,15 @@ int16_t SX1272::setSpreadingFactorRaw(uint8_t newSpreadingFactor) { // write registers if(newSpreadingFactor == RADIOLIB_SX127X_SF_6) { - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_HEADER_IMPL_MODE | (SX127x::_crcEnabled ? RADIOLIB_SX1272_RX_CRC_MODE_ON : RADIOLIB_SX1272_RX_CRC_MODE_OFF), 2, 1); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_HEADER_IMPL_MODE | (SX127x::crcEnabled ? RADIOLIB_SX1272_RX_CRC_MODE_ON : RADIOLIB_SX1272_RX_CRC_MODE_OFF), 2, 1); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6); } else { - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_HEADER_EXPL_MODE | (SX127x::_crcEnabled ? RADIOLIB_SX1272_RX_CRC_MODE_ON : RADIOLIB_SX1272_RX_CRC_MODE_OFF), 2, 1); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_HEADER_EXPL_MODE | (SX127x::crcEnabled ? RADIOLIB_SX1272_RX_CRC_MODE_ON : RADIOLIB_SX1272_RX_CRC_MODE_OFF), 2, 1); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12); } return(state); } @@ -451,7 +451,7 @@ int16_t SX1272::setCodingRateRaw(uint8_t newCodingRate) { int16_t state = SX127x::standby(); // write register - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newCodingRate, 5, 3); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newCodingRate, 5, 3); return(state); } @@ -462,15 +462,15 @@ int16_t SX1272::setHeaderType(uint8_t headerType, size_t len) { } // set requested packet mode - int16_t state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 2, 2); + int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 2, 2); RADIOLIB_ASSERT(state); // set length to register - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len); RADIOLIB_ASSERT(state); // update cached value - _packetLength = len; + SX127x::packetLength = len; return(state); } @@ -481,7 +481,7 @@ int16_t SX1272::configFSK() { RADIOLIB_ASSERT(state); // set fast PLL hop - state = _mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PLL_HOP, RADIOLIB_SX127X_FAST_HOP_ON, 7, 7); + state = this->mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PLL_HOP, RADIOLIB_SX127X_FAST_HOP_ON, 7, 7); return(state); } @@ -490,7 +490,7 @@ void SX1272::errataFix(bool rx) { // mitigation of receiver spurious response // see SX1272/73 Errata, section 2.2 for details - _mod->SPIsetRegValue(0x31, 0b10000000, 7, 7); + this->mod->SPIsetRegValue(0x31, 0b10000000, 7, 7); } #endif diff --git a/src/modules/SX127x/SX1272.h b/src/modules/SX127x/SX1272.h index ccd21fdb..f997647d 100644 --- a/src/modules/SX127x/SX1272.h +++ b/src/modules/SX127x/SX1272.h @@ -9,86 +9,85 @@ #include "SX127x.h" // SX1272 specific register map -#define RADIOLIB_SX1272_REG_AGC_REF 0x43 -#define RADIOLIB_SX1272_REG_AGC_THRESH_1 0x44 -#define RADIOLIB_SX1272_REG_AGC_THRESH_2 0x45 -#define RADIOLIB_SX1272_REG_AGC_THRESH_3 0x46 -#define RADIOLIB_SX1272_REG_PLL_HOP 0x4B -#define RADIOLIB_SX1272_REG_TCXO 0x58 -#define RADIOLIB_SX1272_REG_PA_DAC 0x5A -#define RADIOLIB_SX1272_REG_PLL 0x5C -#define RADIOLIB_SX1272_REG_PLL_LOW_PN 0x5E -#define RADIOLIB_SX1272_REG_FORMER_TEMP 0x6C -#define RADIOLIB_SX1272_REG_BIT_RATE_FRAC 0x70 +#define RADIOLIB_SX1272_REG_AGC_REF 0x43 +#define RADIOLIB_SX1272_REG_AGC_THRESH_1 0x44 +#define RADIOLIB_SX1272_REG_AGC_THRESH_2 0x45 +#define RADIOLIB_SX1272_REG_AGC_THRESH_3 0x46 +#define RADIOLIB_SX1272_REG_PLL_HOP 0x4B +#define RADIOLIB_SX1272_REG_TCXO 0x58 +#define RADIOLIB_SX1272_REG_PA_DAC 0x5A +#define RADIOLIB_SX1272_REG_PLL 0x5C +#define RADIOLIB_SX1272_REG_PLL_LOW_PN 0x5E +#define RADIOLIB_SX1272_REG_FORMER_TEMP 0x6C +#define RADIOLIB_SX1272_REG_BIT_RATE_FRAC 0x70 // SX1272 LoRa modem settings // RADIOLIB_SX1272_REG_FRF_MSB + REG_FRF_MID + REG_FRF_LSB -#define RADIOLIB_SX1272_FRF_MSB 0xE4 // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19 -#define RADIOLIB_SX1272_FRF_MID 0xC0 // 7 0 where F(XOSC) = 32 MHz -#define RADIOLIB_SX1272_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers +#define RADIOLIB_SX1272_FRF_MSB 0xE4 // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19 +#define RADIOLIB_SX1272_FRF_MID 0xC0 // 7 0 where F(XOSC) = 32 MHz +#define RADIOLIB_SX1272_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers // RADIOLIB_SX127X_REG_MODEM_CONFIG_1 -#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_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 -#define RADIOLIB_SX1272_HEADER_EXPL_MODE 0b00000000 // 2 2 explicit header mode -#define RADIOLIB_SX1272_HEADER_IMPL_MODE 0b00000100 // 2 2 implicit header mode -#define RADIOLIB_SX1272_RX_CRC_MODE_OFF 0b00000000 // 1 1 CRC disabled -#define RADIOLIB_SX1272_RX_CRC_MODE_ON 0b00000010 // 1 1 CRC enabled -#define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF 0b00000000 // 0 0 low data rate optimization disabled -#define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON 0b00000001 // 0 0 low data rate optimization enabled, mandatory for SF 11 and 12 with BW 125 kHz +#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_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 +#define RADIOLIB_SX1272_HEADER_EXPL_MODE 0b00000000 // 2 2 explicit header mode +#define RADIOLIB_SX1272_HEADER_IMPL_MODE 0b00000100 // 2 2 implicit header mode +#define RADIOLIB_SX1272_RX_CRC_MODE_OFF 0b00000000 // 1 1 CRC disabled +#define RADIOLIB_SX1272_RX_CRC_MODE_ON 0b00000010 // 1 1 CRC enabled +#define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF 0b00000000 // 0 0 low data rate optimization disabled +#define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON 0b00000001 // 0 0 low data rate optimization enabled, mandatory for SF 11 and 12 with BW 125 kHz // RADIOLIB_SX127X_REG_MODEM_CONFIG_2 -#define RADIOLIB_SX1272_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA -#define RADIOLIB_SX1272_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop +#define RADIOLIB_SX1272_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA +#define RADIOLIB_SX1272_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop // RADIOLIB_SX127X_REG_VERSION -#define RADIOLIB_SX1272_CHIP_VERSION 0x22 +#define RADIOLIB_SX1272_CHIP_VERSION 0x22 // SX1272 FSK modem settings // RADIOLIB_SX127X_REG_OP_MODE -#define RADIOLIB_SX1272_NO_SHAPING 0b00000000 // 4 3 data shaping: no shaping (default) -#define RADIOLIB_SX1272_FSK_GAUSSIAN_1_0 0b00001000 // 4 3 FSK modulation Gaussian filter, BT = 1.0 -#define RADIOLIB_SX1272_FSK_GAUSSIAN_0_5 0b00010000 // 4 3 FSK modulation Gaussian filter, BT = 0.5 -#define RADIOLIB_SX1272_FSK_GAUSSIAN_0_3 0b00011000 // 4 3 FSK modulation Gaussian filter, BT = 0.3 -#define RADIOLIB_SX1272_OOK_FILTER_BR 0b00001000 // 4 3 OOK modulation filter, f_cutoff = BR -#define RADIOLIB_SX1272_OOK_FILTER_2BR 0b00010000 // 4 3 OOK modulation filter, f_cutoff = 2*BR +#define RADIOLIB_SX1272_NO_SHAPING 0b00000000 // 4 3 data shaping: no shaping (default) +#define RADIOLIB_SX1272_FSK_GAUSSIAN_1_0 0b00001000 // 4 3 FSK modulation Gaussian filter, BT = 1.0 +#define RADIOLIB_SX1272_FSK_GAUSSIAN_0_5 0b00010000 // 4 3 FSK modulation Gaussian filter, BT = 0.5 +#define RADIOLIB_SX1272_FSK_GAUSSIAN_0_3 0b00011000 // 4 3 FSK modulation Gaussian filter, BT = 0.3 +#define RADIOLIB_SX1272_OOK_FILTER_BR 0b00001000 // 4 3 OOK modulation filter, f_cutoff = BR +#define RADIOLIB_SX1272_OOK_FILTER_2BR 0b00010000 // 4 3 OOK modulation filter, f_cutoff = 2*BR // RADIOLIB_SX127X_REG_PA_RAMP -#define RADIOLIB_SX1272_LOW_PN_TX_PLL_OFF 0b00010000 // 4 4 use standard PLL in transmit mode (default) -#define RADIOLIB_SX1272_LOW_PN_TX_PLL_ON 0b00000000 // 4 4 use lower phase noise PLL in transmit mode +#define RADIOLIB_SX1272_LOW_PN_TX_PLL_OFF 0b00010000 // 4 4 use standard PLL in transmit mode (default) +#define RADIOLIB_SX1272_LOW_PN_TX_PLL_ON 0b00000000 // 4 4 use lower phase noise PLL in transmit mode // RADIOLIB_SX127X_REG_SYNC_CONFIG -#define RADIOLIB_SX1272_FIFO_FILL_CONDITION_SYNC_ADDRESS 0b00000000 // 3 3 FIFO will be filled when sync address interrupt occurs (default) -#define RADIOLIB_SX1272_FIFO_FILL_CONDITION_ALWAYS 0b00001000 // 3 3 FIFO will be filled as long as this bit is set +#define RADIOLIB_SX1272_FIFO_FILL_CONDITION_SYNC_ADDRESS 0b00000000 // 3 3 FIFO will be filled when sync address interrupt occurs (default) +#define RADIOLIB_SX1272_FIFO_FILL_CONDITION_ALWAYS 0b00001000 // 3 3 FIFO will be filled as long as this bit is set // RADIOLIB_SX1272_REG_AGC_REF -#define RADIOLIB_SX1272_AGC_REFERENCE_LEVEL 0x13 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm] +#define RADIOLIB_SX1272_AGC_REFERENCE_LEVEL 0x13 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm] // RADIOLIB_SX1272_REG_AGC_THRESH_1 -#define RADIOLIB_SX1272_AGC_STEP_1 0x0E // 4 0 1st AGC threshold +#define RADIOLIB_SX1272_AGC_STEP_1 0x0E // 4 0 1st AGC threshold // RADIOLIB_SX1272_REG_AGC_THRESH_2 -#define RADIOLIB_SX1272_AGC_STEP_2 0x50 // 7 4 2nd AGC threshold -#define RADIOLIB_SX1272_AGC_STEP_3 0x0B // 4 0 3rd AGC threshold +#define RADIOLIB_SX1272_AGC_STEP_2 0x50 // 7 4 2nd AGC threshold +#define RADIOLIB_SX1272_AGC_STEP_3 0x0B // 4 0 3rd AGC threshold // RADIOLIB_SX1272_REG_AGC_THRESH_3 -#define RADIOLIB_SX1272_AGC_STEP_4 0xD0 // 7 4 4th AGC threshold -#define RADIOLIB_SX1272_AGC_STEP_5 0x0B // 4 0 5th AGC threshold +#define RADIOLIB_SX1272_AGC_STEP_4 0xD0 // 7 4 4th AGC threshold +#define RADIOLIB_SX1272_AGC_STEP_5 0x0B // 4 0 5th AGC threshold // RADIOLIB_SX1272_REG_PLL_LOW_PN -#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_75_KHZ 0b00000000 // 7 6 low phase noise PLL bandwidth: 75 kHz -#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_150_KHZ 0b01000000 // 7 6 150 kHz -#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_225_KHZ 0b10000000 // 7 6 225 kHz -#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_300_KHZ 0b11000000 // 7 6 300 kHz (default) +#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_75_KHZ 0b00000000 // 7 6 low phase noise PLL bandwidth: 75 kHz +#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_150_KHZ 0b01000000 // 7 6 150 kHz +#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_225_KHZ 0b10000000 // 7 6 225 kHz +#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_300_KHZ 0b11000000 // 7 6 300 kHz (default) /*! \class SX1272 - \brief Derived class for %SX1272 modules. Also used as base class for SX1273. Both modules use the same basic hardware and only differ in parameter ranges. */ @@ -99,7 +98,6 @@ class SX1272: public SX127x { /*! \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. */ SX1272(Module* mod); @@ -108,48 +106,31 @@ class SX1272: public SX127x { /*! \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 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 syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks. - \param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. Set to 0 to disable OCP (not recommended). - \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 860.0 MHz to 1020.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 = 915.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false); @@ -163,56 +144,43 @@ class SX1272: public SX127x { /*! \brief Sets carrier frequency. Allowed values range from 860.0 MHz to 1020.0 MHz. - \param freq Carrier frequency to be set in MHz. - \returns \ref status_codes */ int16_t setFrequency(float freq); /*! \brief Sets %LoRa link bandwidth. Allowed values are 125, 250 and 500 kHz. Only available in %LoRa mode. - \param bw %LoRa link bandwidth to be set in kHz. - \returns \ref status_codes */ int16_t setBandwidth(float bw); /*! \brief Sets %LoRa link spreading factor. Allowed values range from 6 to 12. Only available in %LoRa mode. - \param sf %LoRa link spreading factor to be set. - \returns \ref status_codes */ 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. - \param cr %LoRa link coding rate denominator to be set. - \returns \ref status_codes */ int16_t setCodingRate(uint8_t cr); /*! \brief Sets FSK bit rate. Allowed values range from 0.5 to 300 kbps. Only available in FSK mode. - \param br Bit rate to be set (in kbps). - \returns \ref status_codes */ int16_t setBitRate(float br) override; /*! \brief Sets transmission output power. Allowed values range from -1 to 14 dBm (RFO pin) or +2 to +20 dBm (PA_BOOST pin). - \param power Transmission output power in dBm. - \param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output. Defaults to PA_BOOST. - \returns \ref status_codes */ int16_t setOutputPower(int8_t power, bool useRfo = false); @@ -220,9 +188,7 @@ class SX1272: public SX127x { /*! \brief Sets 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). - \param gain Gain of receiver LNA (low-noise amplifier) to be set. - \returns \ref status_codes */ int16_t setGain(uint8_t gain); @@ -230,9 +196,7 @@ class SX1272: public SX127x { /*! \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. Only available in FSK mode with FSK modulation. Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping. - \param sh Gaussian shaping bandwidth-time product that will be used for data shaping - \returns \ref status_codes */ int16_t setDataShaping(uint8_t sh) override; @@ -241,31 +205,25 @@ class SX1272: public SX127x { \brief Sets filter cutoff frequency that will be used for data shaping. Allowed values are 1 for frequency equal to bit rate and 2 for frequency equal to 2x bit rate. Set to 0 to disable data shaping. Only available in FSK mode with OOK modulation. - \param sh Cutoff frequency that will be used for data shaping - \returns \ref status_codes */ int16_t setDataShapingOOK(uint8_t sh); /*! \brief Gets recorded signal strength indicator. - \param packet Whether to read last packet RSSI, or the current value. LoRa mode only, ignored for FSK. - \param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FSK/OOK mode. - \returns RSSI value in dBm. */ float getRSSI(bool packet = true, bool skipReceive = false); /*! \brief Enables/disables CRC check of received packets. - \param enable Enable (true) or disable (false) CRC. - - \param mode Set CRC mode to RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT for CCITT, polynomial X16 + X12 + X5 + 1 (false) or RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM for IBM, polynomial X16 + X15 + X2 + 1 (true). Only valid in FSK mode. - + \param mode Set CRC mode to RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT for CCITT, + polynomial X16 + X12 + X5 + 1 (false) or RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM for IBM, + polynomial X16 + X15 + X2 + 1 (true). Only valid in FSK mode. \returns \ref status_codes */ int16_t setCRC(bool enable, bool mode = false); @@ -273,9 +231,7 @@ class SX1272: public SX127x { /*! \brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method, LDRO will always be set to the provided value, regardless of symbol length. To re-enable automatic LDRO configuration, call SX1278::autoLDRO() - \param enable Force LDRO to be always enabled (true) or disabled (false). - \returns \ref status_codes */ int16_t forceLDRO(bool enable); @@ -283,23 +239,19 @@ class SX1272: public SX127x { /*! \brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method, LDRO will be enabled automatically when symbol length exceeds 16 ms. - \returns \ref status_codes */ int16_t autoLDRO(); /*! - \brief Set implicit header mode for future reception/transmission. Required for spreading factor 6. - + \brief Set implicit header mode for future reception/transmission. Required for spreading factor 6. \param len Payload length in bytes. - \returns \ref status_codes */ int16_t implicitHeader(size_t len); /*! \brief Set explicit header mode for future reception/transmission. - \returns \ref status_codes */ int16_t explicitHeader(); @@ -318,8 +270,8 @@ class SX1272: public SX127x { #if !defined(RADIOLIB_GODMODE) private: #endif - bool _ldroAuto = true; - bool _ldroEnabled = false; + bool ldroAuto = true; + bool ldroEnabled = false; }; diff --git a/src/modules/SX127x/SX1273.cpp b/src/modules/SX127x/SX1273.cpp index 06f7b785..0e4d287c 100644 --- a/src/modules/SX127x/SX1273.cpp +++ b/src/modules/SX127x/SX1273.cpp @@ -60,7 +60,7 @@ int16_t SX1273::setSpreadingFactor(uint8_t sf) { // set spreading factor and if successful, save the new setting int16_t state = setSpreadingFactorRaw(newSpreadingFactor); if(state == RADIOLIB_ERR_NONE) { - SX127x::_sf = sf; + SX127x::spreadingFactor = sf; } return(state); diff --git a/src/modules/SX127x/SX1273.h b/src/modules/SX127x/SX1273.h index 46127ba5..4fab6215 100644 --- a/src/modules/SX127x/SX1273.h +++ b/src/modules/SX127x/SX1273.h @@ -9,7 +9,6 @@ /*! \class SX1273 - \brief Derived class for %SX1273 modules. Overrides some methods from SX1272 due to different parameter ranges. */ class SX1273: public SX1272 { @@ -19,7 +18,6 @@ class SX1273: public SX1272 { /*! \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. */ SX1273(Module* mod); @@ -28,25 +26,16 @@ class SX1273: public SX1272 { /*! \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 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 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); @@ -55,9 +44,7 @@ class SX1273: public SX1272 { /*! \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); diff --git a/src/modules/SX127x/SX1276.cpp b/src/modules/SX127x/SX1276.cpp index b937a8f4..21eadb57 100644 --- a/src/modules/SX127x/SX1276.cpp +++ b/src/modules/SX127x/SX1276.cpp @@ -72,7 +72,7 @@ int16_t SX1276::setFrequency(float freq) { // set frequency and if successful, save the new setting int16_t state = SX127x::setFrequencyRaw(freq); if(state == RADIOLIB_ERR_NONE) { - SX127x::_freq = freq; + SX127x::frequency = freq; } return(state); } diff --git a/src/modules/SX127x/SX1276.h b/src/modules/SX127x/SX1276.h index cdc4cac5..0d83fb36 100644 --- a/src/modules/SX127x/SX1276.h +++ b/src/modules/SX127x/SX1276.h @@ -9,7 +9,6 @@ /*! \class SX1276 - \brief Derived class for %SX1276 modules. Overrides some methods from SX1278 due to different parameter ranges. */ class SX1276: public SX1278 { @@ -19,7 +18,6 @@ class SX1276: public SX1278 { /*! \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. */ SX1276(Module* mod); @@ -28,47 +26,30 @@ class SX1276: public SX1278 { /*! \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 137.0 MHz to 1020.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 1020.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); @@ -77,9 +58,7 @@ class SX1276: public SX1278 { /*! \brief Sets carrier frequency. Allowed values range from 137.0 MHz to 1020.0 MHz. - \param freq Carrier frequency to be set in MHz. - \returns \ref status_codes */ int16_t setFrequency(float freq); diff --git a/src/modules/SX127x/SX1277.cpp b/src/modules/SX127x/SX1277.cpp index cc49a69c..7e635756 100644 --- a/src/modules/SX127x/SX1277.cpp +++ b/src/modules/SX127x/SX1277.cpp @@ -72,7 +72,7 @@ int16_t SX1277::setFrequency(float freq) { // set frequency and if successful, save the new setting int16_t state = SX127x::setFrequencyRaw(freq); if(state == RADIOLIB_ERR_NONE) { - SX127x::_freq = freq; + SX127x::frequency = freq; } return(state); } @@ -101,7 +101,7 @@ int16_t SX1277::setSpreadingFactor(uint8_t sf) { // set spreading factor and if successful, save the new setting int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor); if(state == RADIOLIB_ERR_NONE) { - SX127x::_sf = sf; + SX127x::spreadingFactor = sf; } return(state); diff --git a/src/modules/SX127x/SX1277.h b/src/modules/SX127x/SX1277.h index b9f7a5cf..76d8854b 100644 --- a/src/modules/SX127x/SX1277.h +++ b/src/modules/SX127x/SX1277.h @@ -9,7 +9,6 @@ /*! \class SX1277 - \brief Derived class for %SX1277 modules. Overrides some methods from SX1278 due to different parameter ranges. */ class SX1277: public SX1278 { @@ -19,7 +18,6 @@ class SX1277: public SX1278 { /*! \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. */ SX1277(Module* mod); @@ -28,47 +26,30 @@ class SX1277: public SX1278 { /*! \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 137.0 MHz to 1020.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 9. - \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); @@ -77,18 +58,14 @@ class SX1277: public SX1278 { /*! \brief Sets carrier frequency. Allowed values range from 137.0 MHz to 1020.0 MHz. - \param freq Carrier frequency to be set in MHz. - \returns \ref status_codes */ int16_t setFrequency(float freq); /*! \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); diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index 4c8159a4..a1b92c0d 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -72,11 +72,11 @@ int16_t SX1278::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t } void SX1278::reset() { - _mod->hal->pinMode(_mod->getRst(), _mod->hal->GpioModeOutput); - _mod->hal->digitalWrite(_mod->getRst(), _mod->hal->GpioLevelLow); - _mod->hal->delay(1); - _mod->hal->digitalWrite(_mod->getRst(), _mod->hal->GpioLevelHigh); - _mod->hal->delay(5); + this->mod->hal->pinMode(this->mod->getRst(), this->mod->hal->GpioModeOutput); + this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow); + this->mod->hal->delay(1); + this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh); + this->mod->hal->delay(5); } int16_t SX1278::setFrequency(float freq) { @@ -85,7 +85,7 @@ int16_t SX1278::setFrequency(float freq) { // set frequency and if successful, save the new setting int16_t state = SX127x::setFrequencyRaw(freq); if(state == RADIOLIB_ERR_NONE) { - SX127x::_freq = freq; + SX127x::frequency = freq; } return(state); } @@ -126,16 +126,16 @@ int16_t SX1278::setBandwidth(float bw) { // set bandwidth and if successful, save the new setting int16_t state = SX1278::setBandwidthRaw(newBandwidth); if(state == RADIOLIB_ERR_NONE) { - SX127x::_bw = bw; + SX127x::bandwidth = bw; // calculate symbol length and set low data rate optimization, if auto-configuration is enabled - if(_ldroAuto) { - float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; + if(this->ldroAuto) { + float symbolLength = (float)(uint32_t(1) << SX127x::spreadingFactor) / (float)SX127x::bandwidth; RADIOLIB_DEBUG_PRINTLN("Symbol length: %f ms", symbolLength); if(symbolLength >= 16.0) { - state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3); + state = this->mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3); } else { - state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3); + state = this->mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3); } } } @@ -180,16 +180,16 @@ int16_t SX1278::setSpreadingFactor(uint8_t sf) { // set spreading factor and if successful, save the new setting int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor); if(state == RADIOLIB_ERR_NONE) { - SX127x::_sf = sf; + SX127x::spreadingFactor = sf; // calculate symbol length and set low data rate optimization, if auto-configuration is enabled - if(_ldroAuto) { - float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; + if(this->ldroAuto) { + float symbolLength = (float)(uint32_t(1) << SX127x::spreadingFactor) / (float)SX127x::bandwidth; RADIOLIB_DEBUG_PRINT("Symbol length: %f ms", symbolLength); if(symbolLength >= 16.0) { - state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3); + state = this->mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3); } else { - state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3); + state = this->mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3); } } } @@ -225,7 +225,7 @@ int16_t SX1278::setCodingRate(uint8_t cr) { // set coding rate and if successful, save the new setting int16_t state = SX1278::setCodingRateRaw(newCodingRate); if(state == RADIOLIB_ERR_NONE) { - SX127x::_cr = cr; + SX127x::codingRate = cr; } return(state); } @@ -259,22 +259,22 @@ int16_t SX1278::setOutputPower(int8_t power, bool useRfo) { paCfg = RADIOLIB_SX1278_MAX_POWER | power; } - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_RFO, 7, 7); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, paCfg, 6, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_RFO, 7, 7); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, paCfg, 6, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0); } else { if(power != 20) { // power is 2 - 17 dBm, enable PA1 + PA2 on PA_BOOST - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX1278_MAX_POWER | (power - 2), 6, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX1278_MAX_POWER | (power - 2), 6, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0); } else { // power is 20 dBm, enable PA1 + PA2 on PA_BOOST and enable high power control - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX1278_MAX_POWER | 0x0F, 6, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_ON, 2, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX1278_MAX_POWER | 0x0F, 6, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_ON, 2, 0); } } @@ -297,20 +297,20 @@ int16_t SX1278::setGain(uint8_t gain) { // set gain if(gain == 0) { // gain set to 0, enable AGC loop - state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_AGC_AUTO_ON, 2, 2); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_AGC_AUTO_ON, 2, 2); } else { - state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_AGC_AUTO_OFF, 2, 2); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_AGC_AUTO_OFF, 2, 2); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON); } } else if(modem == RADIOLIB_SX127X_FSK_OOK) { // set gain if(gain == 0) { // gain set to 0, enable AGC loop - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3); } else { - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX1278_AGC_AUTO_OFF, 3, 3); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX1278_AGC_AUTO_OFF, 3, 3); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON); } } @@ -325,7 +325,7 @@ int16_t SX1278::setDataShaping(uint8_t sh) { } // check modulation - if(SX127x::_ook) { + if(SX127x::ookEnabled) { // we're in OOK mode, the only thing we can do is disable if(sh == RADIOLIB_SHAPING_NONE) { return(setDataShapingOOK(0)); @@ -341,13 +341,13 @@ int16_t SX1278::setDataShaping(uint8_t sh) { // set data shaping switch(sh) { case RADIOLIB_SHAPING_NONE: - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_NO_SHAPING, 6, 5)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_NO_SHAPING, 6, 5)); case RADIOLIB_SHAPING_0_3: - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_0_3, 6, 5)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_0_3, 6, 5)); case RADIOLIB_SHAPING_0_5: - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_0_5, 6, 5)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_0_5, 6, 5)); case RADIOLIB_SHAPING_1_0: - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_1_0, 6, 5)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_1_0, 6, 5)); default: return(RADIOLIB_ERR_INVALID_DATA_SHAPING); } @@ -360,7 +360,7 @@ int16_t SX1278::setDataShapingOOK(uint8_t sh) { } // check modulation - if(!SX127x::_ook) { + if(!SX127x::ookEnabled) { return(RADIOLIB_ERR_INVALID_MODULATION); } @@ -370,13 +370,13 @@ int16_t SX1278::setDataShapingOOK(uint8_t sh) { // set data shaping switch(sh) { case 0: - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_NO_SHAPING, 6, 5); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_NO_SHAPING, 6, 5); break; case 1: - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_OOK_FILTER_BR, 6, 5); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_OOK_FILTER_BR, 6, 5); break; case 2: - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_OOK_FILTER_2BR, 6, 5); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_OOK_FILTER_2BR, 6, 5); break; default: return(RADIOLIB_ERR_INVALID_DATA_SHAPING); @@ -387,7 +387,7 @@ int16_t SX1278::setDataShapingOOK(uint8_t sh) { float SX1278::getRSSI(bool packet, bool skipReceive) { int16_t offset = -157; - if(_freq < 868.0) { + if(frequency < 868.0) { offset = -164; } return(SX127x::getRSSI(packet, skipReceive, offset)); @@ -396,27 +396,27 @@ float SX1278::getRSSI(bool packet, bool skipReceive) { int16_t SX1278::setCRC(bool enable, bool mode) { if(getActiveModem() == RADIOLIB_SX127X_LORA) { // set LoRa CRC - SX127x::_crcEnabled = enable; + SX127x::crcEnabled = enable; if(enable) { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1278_RX_CRC_MODE_ON, 2, 2)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1278_RX_CRC_MODE_ON, 2, 2)); } else { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1278_RX_CRC_MODE_OFF, 2, 2)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1278_RX_CRC_MODE_OFF, 2, 2)); } } else { // set FSK CRC int16_t state = RADIOLIB_ERR_NONE; if(enable) { - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_ON, 4, 4); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_ON, 4, 4); } else { - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_OFF, 4, 4); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_OFF, 4, 4); } RADIOLIB_ASSERT(state); // set FSK CRC mode if(mode) { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM, 0, 0)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM, 0, 0)); } else { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT, 0, 0)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT, 0, 0)); } } } @@ -426,11 +426,11 @@ int16_t SX1278::forceLDRO(bool enable) { return(RADIOLIB_ERR_WRONG_MODEM); } - _ldroAuto = false; + this->ldroAuto = false; if(enable) { - return(_mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3)); } else { - return(_mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3)); } } @@ -439,7 +439,7 @@ int16_t SX1278::autoLDRO() { return(RADIOLIB_ERR_WRONG_MODEM); } - _ldroAuto = true; + this->ldroAuto = true; return(RADIOLIB_ERR_NONE); } @@ -456,7 +456,7 @@ int16_t SX1278::setBandwidthRaw(uint8_t newBandwidth) { int16_t state = SX127x::standby(); // write register - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newBandwidth, 7, 4); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newBandwidth, 7, 4); return(state); } @@ -466,15 +466,15 @@ int16_t SX1278::setSpreadingFactorRaw(uint8_t newSpreadingFactor) { // write registers if(newSpreadingFactor == RADIOLIB_SX127X_SF_6) { - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_IMPL_MODE, 0, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_IMPL_MODE, 0, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6); } else { - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_EXPL_MODE, 0, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_EXPL_MODE, 0, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12); } return(state); } @@ -484,7 +484,7 @@ int16_t SX1278::setCodingRateRaw(uint8_t newCodingRate) { int16_t state = SX127x::standby(); // write register - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newCodingRate, 3, 1); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newCodingRate, 3, 1); return(state); } @@ -495,15 +495,15 @@ int16_t SX1278::setHeaderType(uint8_t headerType, size_t len) { } // set requested packet mode - int16_t state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 0, 0); + int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 0, 0); RADIOLIB_ASSERT(state); // set length to register - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len); RADIOLIB_ASSERT(state); // update cached value - _packetLength = len; + SX127x::packetLength = len; return(state); } @@ -514,7 +514,7 @@ int16_t SX1278::configFSK() { RADIOLIB_ASSERT(state); // set fast PLL hop - state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PLL_HOP, RADIOLIB_SX127X_FAST_HOP_ON, 7, 7); + state = this->mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PLL_HOP, RADIOLIB_SX127X_FAST_HOP_ON, 7, 7); return(state); } @@ -526,13 +526,13 @@ void SX1278::errataFix(bool rx) { // sensitivity optimization for 500kHz bandwidth // see SX1276/77/78 Errata, section 2.1 for details - if(fabs(_bw - 500.0) <= 0.001) { - if((_freq >= 862.0) && (_freq <= 1020.0)) { - _mod->SPIwriteRegister(0x36, 0x02); - _mod->SPIwriteRegister(0x3a, 0x64); - } else if((_freq >= 410.0) && (_freq <= 525.0)) { - _mod->SPIwriteRegister(0x36, 0x02); - _mod->SPIwriteRegister(0x3a, 0x7F); + if(fabs(SX127x::bandwidth - 500.0) <= 0.001) { + if((frequency >= 862.0) && (frequency <= 1020.0)) { + this->mod->SPIwriteRegister(0x36, 0x02); + this->mod->SPIwriteRegister(0x3a, 0x64); + } else if((frequency >= 410.0) && (frequency <= 525.0)) { + this->mod->SPIwriteRegister(0x36, 0x02); + this->mod->SPIwriteRegister(0x3a, 0x7F); } } @@ -541,53 +541,53 @@ void SX1278::errataFix(bool rx) { // figure out what we need to set uint8_t fixedRegs[3] = { 0x00, 0x00, 0x00 }; - float rxFreq = _freq; - if(fabs(_bw - 7.8) <= 0.001) { + float rxFreq = frequency; + if(fabs(SX127x::bandwidth - 7.8) <= 0.001) { fixedRegs[0] = 0b0000000; fixedRegs[1] = 0x48; fixedRegs[2] = 0x00; rxFreq += 0.00781; - } else if(fabs(_bw - 10.4) <= 0.001) { + } else if(fabs(SX127x::bandwidth - 10.4) <= 0.001) { fixedRegs[0] = 0b0000000; fixedRegs[1] = 0x44; fixedRegs[2] = 0x00; rxFreq += 0.01042; - } else if(fabs(_bw - 15.6) <= 0.001) { + } else if(fabs(SX127x::bandwidth - 15.6) <= 0.001) { fixedRegs[0] = 0b0000000; fixedRegs[1] = 0x44; fixedRegs[2] = 0x00; rxFreq += 0.01562; - } else if(fabs(_bw - 20.8) <= 0.001) { + } else if(fabs(SX127x::bandwidth - 20.8) <= 0.001) { fixedRegs[0] = 0b0000000; fixedRegs[1] = 0x44; fixedRegs[2] = 0x00; rxFreq += 0.02083; - } else if(fabs(_bw - 31.25) <= 0.001) { + } else if(fabs(SX127x::bandwidth - 31.25) <= 0.001) { fixedRegs[0] = 0b0000000; fixedRegs[1] = 0x44; fixedRegs[2] = 0x00; rxFreq += 0.03125; - } else if(fabs(_bw - 41.7) <= 0.001) { + } else if(fabs(SX127x::bandwidth - 41.7) <= 0.001) { fixedRegs[0] = 0b0000000; fixedRegs[1] = 0x44; fixedRegs[2] = 0x00; rxFreq += 0.04167; - } else if(fabs(_bw - 62.5) <= 0.001) { + } else if(fabs(SX127x::bandwidth - 62.5) <= 0.001) { fixedRegs[0] = 0b0000000; fixedRegs[1] = 0x40; fixedRegs[2] = 0x00; - } else if(fabs(_bw - 125.0) <= 0.001) { + } else if(fabs(SX127x::bandwidth - 125.0) <= 0.001) { fixedRegs[0] = 0b0000000; fixedRegs[1] = 0x40; fixedRegs[2] = 0x00; - } else if(fabs(_bw - 250.0) <= 0.001) { + } else if(fabs(SX127x::bandwidth - 250.0) <= 0.001) { fixedRegs[0] = 0b0000000; fixedRegs[1] = 0x40; fixedRegs[2] = 0x00; - } else if(fabs(_bw - 500.0) <= 0.001) { + } else if(fabs(SX127x::bandwidth - 500.0) <= 0.001) { fixedRegs[0] = 0b1000000; - fixedRegs[1] = _mod->SPIreadRegister(0x2F); - fixedRegs[2] = _mod->SPIreadRegister(0x30); + fixedRegs[1] = this->mod->SPIreadRegister(0x2F); + fixedRegs[2] = this->mod->SPIreadRegister(0x30); } else { return; } @@ -599,13 +599,13 @@ void SX1278::errataFix(bool rx) { if(rx) { SX127x::setFrequencyRaw(rxFreq); } else { - SX127x::setFrequencyRaw(_freq); + SX127x::setFrequencyRaw(frequency); } // finally, apply errata fixes - _mod->SPIsetRegValue(0x31, fixedRegs[0], 7, 7); - _mod->SPIsetRegValue(0x2F, fixedRegs[1]); - _mod->SPIsetRegValue(0x30, fixedRegs[2]); + this->mod->SPIsetRegValue(0x31, fixedRegs[0], 7, 7); + this->mod->SPIsetRegValue(0x2F, fixedRegs[1]); + this->mod->SPIsetRegValue(0x30, fixedRegs[2]); } #endif diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index 92273a19..e5f8781c 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -9,95 +9,94 @@ #include "SX127x.h" // SX1278 specific register map -#define RADIOLIB_SX1278_REG_MODEM_CONFIG_3 0x26 -#define RADIOLIB_SX1278_REG_PLL_HOP 0x44 -#define RADIOLIB_SX1278_REG_TCXO 0x4B -#define RADIOLIB_SX1278_REG_PA_DAC 0x4D -#define RADIOLIB_SX1278_REG_FORMER_TEMP 0x5B -#define RADIOLIB_SX1278_REG_BIT_RATE_FRAC 0x5D -#define RADIOLIB_SX1278_REG_AGC_REF 0x61 -#define RADIOLIB_SX1278_REG_AGC_THRESH_1 0x62 -#define RADIOLIB_SX1278_REG_AGC_THRESH_2 0x63 -#define RADIOLIB_SX1278_REG_AGC_THRESH_3 0x64 -#define RADIOLIB_SX1278_REG_PLL 0x70 +#define RADIOLIB_SX1278_REG_MODEM_CONFIG_3 0x26 +#define RADIOLIB_SX1278_REG_PLL_HOP 0x44 +#define RADIOLIB_SX1278_REG_TCXO 0x4B +#define RADIOLIB_SX1278_REG_PA_DAC 0x4D +#define RADIOLIB_SX1278_REG_FORMER_TEMP 0x5B +#define RADIOLIB_SX1278_REG_BIT_RATE_FRAC 0x5D +#define RADIOLIB_SX1278_REG_AGC_REF 0x61 +#define RADIOLIB_SX1278_REG_AGC_THRESH_1 0x62 +#define RADIOLIB_SX1278_REG_AGC_THRESH_2 0x63 +#define RADIOLIB_SX1278_REG_AGC_THRESH_3 0x64 +#define RADIOLIB_SX1278_REG_PLL 0x70 // SX1278 LoRa modem settings -// RADIOLIB_SX1278_REG_OP_MODE MSB LSB DESCRIPTION -#define RADIOLIB_SX1278_HIGH_FREQ 0b00000000 // 3 3 access HF test registers -#define RADIOLIB_SX1278_LOW_FREQ 0b00001000 // 3 3 access LF test registers +// RADIOLIB_SX1278_REG_OP_MODE MSB LSB DESCRIPTION +#define RADIOLIB_SX1278_HIGH_FREQ 0b00000000 // 3 3 access HF test registers +#define RADIOLIB_SX1278_LOW_FREQ 0b00001000 // 3 3 access LF test registers // RADIOLIB_SX1278_REG_FRF_MSB + REG_FRF_MID + REG_FRF_LSB -#define RADIOLIB_SX1278_FRF_MSB 0x6C // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19 -#define RADIOLIB_SX1278_FRF_MID 0x80 // 7 0 where F(XOSC) = 32 MHz -#define RADIOLIB_SX1278_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers +#define RADIOLIB_SX1278_FRF_MSB 0x6C // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19 +#define RADIOLIB_SX1278_FRF_MID 0x80 // 7 0 where F(XOSC) = 32 MHz +#define RADIOLIB_SX1278_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers // RADIOLIB_SX1278_REG_PA_CONFIG -#define RADIOLIB_SX1278_MAX_POWER 0b01110000 // 6 4 max power: P_max = 10.8 + 0.6*MAX_POWER [dBm]; P_max(MAX_POWER = 0b111) = 15 dBm -#define RADIOLIB_SX1278_LOW_POWER 0b00100000 // 6 4 +#define RADIOLIB_SX1278_MAX_POWER 0b01110000 // 6 4 max power: P_max = 10.8 + 0.6*MAX_POWER [dBm]; P_max(MAX_POWER = 0b111) = 15 dBm +#define RADIOLIB_SX1278_LOW_POWER 0b00100000 // 6 4 // RADIOLIB_SX1278_REG_LNA -#define RADIOLIB_SX1278_LNA_BOOST_LF_OFF 0b00000000 // 4 3 default LNA current +#define RADIOLIB_SX1278_LNA_BOOST_LF_OFF 0b00000000 // 4 3 default LNA current // SX127X_REG_MODEM_CONFIG_1 -#define RADIOLIB_SX1278_BW_7_80_KHZ 0b00000000 // 7 4 bandwidth: 7.80 kHz -#define RADIOLIB_SX1278_BW_10_40_KHZ 0b00010000 // 7 4 10.40 kHz -#define RADIOLIB_SX1278_BW_15_60_KHZ 0b00100000 // 7 4 15.60 kHz -#define RADIOLIB_SX1278_BW_20_80_KHZ 0b00110000 // 7 4 20.80 kHz -#define RADIOLIB_SX1278_BW_31_25_KHZ 0b01000000 // 7 4 31.25 kHz -#define RADIOLIB_SX1278_BW_41_70_KHZ 0b01010000 // 7 4 41.70 kHz -#define RADIOLIB_SX1278_BW_62_50_KHZ 0b01100000 // 7 4 62.50 kHz -#define RADIOLIB_SX1278_BW_125_00_KHZ 0b01110000 // 7 4 125.00 kHz -#define RADIOLIB_SX1278_BW_250_00_KHZ 0b10000000 // 7 4 250.00 kHz -#define RADIOLIB_SX1278_BW_500_00_KHZ 0b10010000 // 7 4 500.00 kHz -#define RADIOLIB_SX1278_CR_4_5 0b00000010 // 3 1 error coding rate: 4/5 -#define RADIOLIB_SX1278_CR_4_6 0b00000100 // 3 1 4/6 -#define RADIOLIB_SX1278_CR_4_7 0b00000110 // 3 1 4/7 -#define RADIOLIB_SX1278_CR_4_8 0b00001000 // 3 1 4/8 -#define RADIOLIB_SX1278_HEADER_EXPL_MODE 0b00000000 // 0 0 explicit header mode -#define RADIOLIB_SX1278_HEADER_IMPL_MODE 0b00000001 // 0 0 implicit header mode +#define RADIOLIB_SX1278_BW_7_80_KHZ 0b00000000 // 7 4 bandwidth: 7.80 kHz +#define RADIOLIB_SX1278_BW_10_40_KHZ 0b00010000 // 7 4 10.40 kHz +#define RADIOLIB_SX1278_BW_15_60_KHZ 0b00100000 // 7 4 15.60 kHz +#define RADIOLIB_SX1278_BW_20_80_KHZ 0b00110000 // 7 4 20.80 kHz +#define RADIOLIB_SX1278_BW_31_25_KHZ 0b01000000 // 7 4 31.25 kHz +#define RADIOLIB_SX1278_BW_41_70_KHZ 0b01010000 // 7 4 41.70 kHz +#define RADIOLIB_SX1278_BW_62_50_KHZ 0b01100000 // 7 4 62.50 kHz +#define RADIOLIB_SX1278_BW_125_00_KHZ 0b01110000 // 7 4 125.00 kHz +#define RADIOLIB_SX1278_BW_250_00_KHZ 0b10000000 // 7 4 250.00 kHz +#define RADIOLIB_SX1278_BW_500_00_KHZ 0b10010000 // 7 4 500.00 kHz +#define RADIOLIB_SX1278_CR_4_5 0b00000010 // 3 1 error coding rate: 4/5 +#define RADIOLIB_SX1278_CR_4_6 0b00000100 // 3 1 4/6 +#define RADIOLIB_SX1278_CR_4_7 0b00000110 // 3 1 4/7 +#define RADIOLIB_SX1278_CR_4_8 0b00001000 // 3 1 4/8 +#define RADIOLIB_SX1278_HEADER_EXPL_MODE 0b00000000 // 0 0 explicit header mode +#define RADIOLIB_SX1278_HEADER_IMPL_MODE 0b00000001 // 0 0 implicit header mode // SX127X_REG_MODEM_CONFIG_2 -#define RADIOLIB_SX1278_RX_CRC_MODE_OFF 0b00000000 // 2 2 CRC disabled -#define RADIOLIB_SX1278_RX_CRC_MODE_ON 0b00000100 // 2 2 CRC enabled +#define RADIOLIB_SX1278_RX_CRC_MODE_OFF 0b00000000 // 2 2 CRC disabled +#define RADIOLIB_SX1278_RX_CRC_MODE_ON 0b00000100 // 2 2 CRC enabled // RADIOLIB_SX1278_REG_MODEM_CONFIG_3 -#define RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF 0b00000000 // 3 3 low data rate optimization disabled -#define RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON 0b00001000 // 3 3 low data rate optimization enabled -#define RADIOLIB_SX1278_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA -#define RADIOLIB_SX1278_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop +#define RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF 0b00000000 // 3 3 low data rate optimization disabled +#define RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON 0b00001000 // 3 3 low data rate optimization enabled +#define RADIOLIB_SX1278_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA +#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 // SX1278 FSK modem settings // SX127X_REG_PA_RAMP -#define RADIOLIB_SX1278_NO_SHAPING 0b00000000 // 6 5 data shaping: no shaping (default) -#define RADIOLIB_SX1278_FSK_GAUSSIAN_1_0 0b00100000 // 6 5 FSK modulation Gaussian filter, BT = 1.0 -#define RADIOLIB_SX1278_FSK_GAUSSIAN_0_5 0b01000000 // 6 5 FSK modulation Gaussian filter, BT = 0.5 -#define RADIOLIB_SX1278_FSK_GAUSSIAN_0_3 0b01100000 // 6 5 FSK modulation Gaussian filter, BT = 0.3 -#define RADIOLIB_SX1278_OOK_FILTER_BR 0b00100000 // 6 5 OOK modulation filter, f_cutoff = BR -#define RADIOLIB_SX1278_OOK_FILTER_2BR 0b01000000 // 6 5 OOK modulation filter, f_cutoff = 2*BR +#define RADIOLIB_SX1278_NO_SHAPING 0b00000000 // 6 5 data shaping: no shaping (default) +#define RADIOLIB_SX1278_FSK_GAUSSIAN_1_0 0b00100000 // 6 5 FSK modulation Gaussian filter, BT = 1.0 +#define RADIOLIB_SX1278_FSK_GAUSSIAN_0_5 0b01000000 // 6 5 FSK modulation Gaussian filter, BT = 0.5 +#define RADIOLIB_SX1278_FSK_GAUSSIAN_0_3 0b01100000 // 6 5 FSK modulation Gaussian filter, BT = 0.3 +#define RADIOLIB_SX1278_OOK_FILTER_BR 0b00100000 // 6 5 OOK modulation filter, f_cutoff = BR +#define RADIOLIB_SX1278_OOK_FILTER_2BR 0b01000000 // 6 5 OOK modulation filter, f_cutoff = 2*BR // RADIOLIB_SX1278_REG_AGC_REF -#define RADIOLIB_SX1278_AGC_REFERENCE_LEVEL_LF 0x19 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm]: below 525 MHz -#define RADIOLIB_SX1278_AGC_REFERENCE_LEVEL_HF 0x1C // 5 0 above 779 MHz +#define RADIOLIB_SX1278_AGC_REFERENCE_LEVEL_LF 0x19 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm]: below 525 MHz +#define RADIOLIB_SX1278_AGC_REFERENCE_LEVEL_HF 0x1C // 5 0 above 779 MHz // RADIOLIB_SX1278_REG_AGC_THRESH_1 -#define RADIOLIB_SX1278_AGC_STEP_1_LF 0x0C // 4 0 1st AGC threshold: below 525 MHz -#define RADIOLIB_SX1278_AGC_STEP_1_HF 0x0E // 4 0 above 779 MHz +#define RADIOLIB_SX1278_AGC_STEP_1_LF 0x0C // 4 0 1st AGC threshold: below 525 MHz +#define RADIOLIB_SX1278_AGC_STEP_1_HF 0x0E // 4 0 above 779 MHz // RADIOLIB_SX1278_REG_AGC_THRESH_2 -#define RADIOLIB_SX1278_AGC_STEP_2_LF 0x40 // 7 4 2nd AGC threshold: below 525 MHz -#define RADIOLIB_SX1278_AGC_STEP_2_HF 0x50 // 7 4 above 779 MHz -#define RADIOLIB_SX1278_AGC_STEP_3 0x0B // 3 0 3rd AGC threshold +#define RADIOLIB_SX1278_AGC_STEP_2_LF 0x40 // 7 4 2nd AGC threshold: below 525 MHz +#define RADIOLIB_SX1278_AGC_STEP_2_HF 0x50 // 7 4 above 779 MHz +#define RADIOLIB_SX1278_AGC_STEP_3 0x0B // 3 0 3rd AGC threshold // RADIOLIB_SX1278_REG_AGC_THRESH_3 -#define RADIOLIB_SX1278_AGC_STEP_4 0xC0 // 7 4 4th AGC threshold -#define RADIOLIB_SX1278_AGC_STEP_5 0x0C // 4 0 5th AGC threshold +#define RADIOLIB_SX1278_AGC_STEP_4 0xC0 // 7 4 4th AGC threshold +#define RADIOLIB_SX1278_AGC_STEP_5 0x0C // 4 0 5th AGC threshold /*! \class SX1278 - \brief Derived class for %SX1278 modules. Also used as base class for SX1276, SX1277, SX1279, RFM95 and RFM96. All of these modules use the same basic hardware and only differ in parameter ranges (and names). */ @@ -108,7 +107,6 @@ class SX1278: public SX127x { /*! \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. */ SX1278(Module* mod); @@ -117,47 +115,30 @@ class SX1278: public SX127x { /*! \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 137.0 MHz to 525.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); @@ -171,45 +152,35 @@ class SX1278: public SX127x { /*! \brief Sets carrier frequency. Allowed values range from 137.0 MHz to 525.0 MHz. - \param freq Carrier frequency to be set in MHz. - \returns \ref status_codes */ int16_t setFrequency(float freq); /*! \brief Sets %LoRa link bandwidth. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. Only available in %LoRa mode. - \param bw %LoRa link bandwidth to be set in kHz. - \returns \ref status_codes */ int16_t setBandwidth(float bw); /*! \brief Sets %LoRa link spreading factor. Allowed values range from 6 to 12. Only available in %LoRa mode. - \param sf %LoRa link spreading factor to be set. - \returns \ref status_codes */ 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. - \param cr %LoRa link coding rate denominator to be set. - \returns \ref status_codes */ int16_t setCodingRate(uint8_t cr); /*! \brief Sets FSK bit rate. Allowed values range from 0.5 to 300 kbps. Only available in FSK mode. - \param br Bit rate to be set (in kbps). - \returns \ref status_codes */ int16_t setBitRate(float br) override; @@ -217,11 +188,8 @@ class SX1278: public SX127x { /*! \brief Sets transmission output power. Allowed values range from -3 to 15 dBm (RFO pin) or +2 to +17 dBm (PA_BOOST pin). High power +20 dBm operation is also supported, on the PA_BOOST pin. - \param power Transmission output power in dBm. - \param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output. Defaults to PA_BOOST. - \returns \ref status_codes */ int16_t setOutputPower(int8_t power, bool useRfo = false); @@ -229,9 +197,7 @@ class SX1278: public SX127x { /*! \brief Sets 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). - \param gain Gain of receiver LNA (low-noise amplifier) to be set. - \returns \ref status_codes */ int16_t setGain(uint8_t gain); @@ -239,9 +205,7 @@ class SX1278: public SX127x { /*! \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. Only available in FSK mode with FSK modulation. Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping. - \param sh Gaussian shaping bandwidth-time product that will be used for data shaping - \returns \ref status_codes */ int16_t setDataShaping(uint8_t sh) override; @@ -250,65 +214,53 @@ class SX1278: public SX127x { \brief Sets filter cutoff frequency that will be used for data shaping. Allowed values are 1 for frequency equal to bit rate and 2 for frequency equal to 2x bit rate. Set to 0 to disable data shaping. Only available in FSK mode with OOK modulation. - \param sh Cutoff frequency that will be used for data shaping - \returns \ref status_codes */ int16_t setDataShapingOOK(uint8_t sh); /*! \brief Gets recorded signal strength indicator. - \param packet Whether to read last packet RSSI, or the current value. LoRa mode only, ignored for FSK. - \param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FSK/OOK mode. - \returns RSSI value in dBm. */ float getRSSI(bool packet = true, bool skipReceive = false); /*! \brief Enables/disables CRC check of received packets. - \param enable Enable (true) or disable (false) CRC. - - \param mode Set CRC mode to SX127X_CRC_WHITENING_TYPE_CCITT for CCITT, polynomial X16 + X12 + X5 + 1 (false) or SX127X_CRC_WHITENING_TYPE_IBM for IBM, polynomial X16 + X15 + X2 + 1 (true). Only valid in FSK mode. - + \param mode Set CRC mode to SX127X_CRC_WHITENING_TYPE_CCITT for CCITT, polynomial X16 + X12 + X5 + 1 (false) + or SX127X_CRC_WHITENING_TYPE_IBM for IBM, polynomial X16 + X15 + X2 + 1 (true). Only valid in FSK mode. \returns \ref status_codes */ int16_t setCRC(bool enable, bool mode = false); /*! - \brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method, LDRO will always be set to - the provided value, regardless of symbol length. To re-enable automatic LDRO configuration, call SX1278::autoLDRO() - + \brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method, + LDRO will always be set to the provided value, regardless of symbol length. + To re-enable automatic LDRO configuration, call SX1278::autoLDRO() \param enable Force LDRO to be always enabled (true) or disabled (false). - \returns \ref status_codes */ int16_t forceLDRO(bool enable); /*! - \brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method, LDRO will be enabled automatically - when symbol length exceeds 16 ms. - + \brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method, + LDRO will be enabled automatically when symbol length exceeds 16 ms. \returns \ref status_codes */ int16_t autoLDRO(); /*! - \brief Set implicit header mode for future reception/transmission. Required for spreading factor 6. - + \brief Set implicit header mode for future reception/transmission. Required for spreading factor 6. \param len Payload length in bytes. - \returns \ref status_codes */ int16_t implicitHeader(size_t len); /*! \brief Set explicit header mode for future reception/transmission. - \returns \ref status_codes */ int16_t explicitHeader(); @@ -327,8 +279,8 @@ class SX1278: public SX127x { #if !defined(RADIOLIB_GODMODE) private: #endif - bool _ldroAuto = true; - bool _ldroEnabled = false; + bool ldroAuto = true; + bool ldroEnabled = false; }; diff --git a/src/modules/SX127x/SX1279.cpp b/src/modules/SX127x/SX1279.cpp index e191e6c7..ae79f0f8 100644 --- a/src/modules/SX127x/SX1279.cpp +++ b/src/modules/SX127x/SX1279.cpp @@ -72,7 +72,7 @@ int16_t SX1279::setFrequency(float freq) { // set frequency and if successful, save the new setting int16_t state = SX127x::setFrequencyRaw(freq); if(state == RADIOLIB_ERR_NONE) { - SX127x::_freq = freq; + SX127x::frequency = freq; } return(state); } diff --git a/src/modules/SX127x/SX1279.h b/src/modules/SX127x/SX1279.h index c9ff8ab0..1b01368f 100644 --- a/src/modules/SX127x/SX1279.h +++ b/src/modules/SX127x/SX1279.h @@ -9,7 +9,6 @@ /*! \class SX1279 - \brief Derived class for %SX1279 modules. Overrides some methods from SX1278 due to different parameter ranges. */ class SX1279: public SX1278 { @@ -19,7 +18,6 @@ class SX1279: public SX1278 { /*! \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. */ SX1279(Module* mod); @@ -28,47 +26,30 @@ class SX1279: public SX1278 { /*! \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 137.0 MHz to 960.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); @@ -77,9 +58,7 @@ class SX1279: public SX1278 { /*! \brief Sets carrier frequency. Allowed values range from 137.0 MHz to 960.0 MHz. - \param freq Carrier frequency to be set in MHz. - \returns \ref status_codes */ int16_t setFrequency(float freq); diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index e08ad181..4abac652 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -3,23 +3,23 @@ #if !defined(RADIOLIB_EXCLUDE_SX127X) SX127x::SX127x(Module* mod) : PhysicalLayer(RADIOLIB_SX127X_FREQUENCY_STEP_SIZE, RADIOLIB_SX127X_MAX_PACKET_LENGTH) { - _mod = mod; + this->mod = mod; } Module* SX127x::getMod() { - return(_mod); + return(this->mod); } int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint16_t preambleLength) { // set module properties - _mod->init(); - _mod->hal->pinMode(_mod->getIrq(), _mod->hal->GpioModeInput); - _mod->hal->pinMode(_mod->getGpio(), _mod->hal->GpioModeInput); + 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)) { RADIOLIB_DEBUG_PRINTLN("No SX127x found!"); - _mod->term(); + this->mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } RADIOLIB_DEBUG_PRINTLN("M\tSX127x"); @@ -52,21 +52,21 @@ int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint16_t preambleLe RADIOLIB_ASSERT(state); // initialize internal variables - _dataRate = 0.0; + this->dataRate = 0.0; return(state); } int16_t SX127x::beginFSK(uint8_t chipVersion, float freqDev, float rxBw, uint16_t preambleLength, bool enableOOK) { // set module properties - _mod->init(); - _mod->hal->pinMode(_mod->getIrq(), _mod->hal->GpioModeInput); - _mod->hal->pinMode(_mod->getGpio(), _mod->hal->GpioModeInput); + 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)) { RADIOLIB_DEBUG_PRINTLN("No SX127x found!"); - _mod->term(); + this->mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } RADIOLIB_DEBUG_PRINTLN("M\tSX127x"); @@ -153,10 +153,10 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) { RADIOLIB_ASSERT(state); // wait for packet transmission or timeout - start = _mod->hal->micros(); - while(!_mod->hal->digitalRead(_mod->getIrq())) { - _mod->hal->yield(); - if(_mod->hal->micros() - start > timeout) { + start = this->mod->hal->micros(); + while(!this->mod->hal->digitalRead(this->mod->getIrq())) { + this->mod->hal->yield(); + if(this->mod->hal->micros() - start > timeout) { finishTransmit(); return(RADIOLIB_ERR_TX_TIMEOUT); } @@ -171,10 +171,10 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) { RADIOLIB_ASSERT(state); // wait for transmission end or timeout - start = _mod->hal->micros(); - while(!_mod->hal->digitalRead(_mod->getIrq())) { - _mod->hal->yield(); - if(_mod->hal->micros() - start > timeout) { + start = this->mod->hal->micros(); + while(!this->mod->hal->digitalRead(this->mod->getIrq())) { + this->mod->hal->yield(); + if(this->mod->hal->micros() - start > timeout) { finishTransmit(); return(RADIOLIB_ERR_TX_TIMEOUT); } @@ -184,8 +184,8 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) { } // update data rate - uint32_t elapsed = _mod->hal->micros() - start; - _dataRate = (len*8.0)/((float)elapsed/1000000.0); + uint32_t elapsed = this->mod->hal->micros() - start; + this->dataRate = (len*8.0)/((float)elapsed/1000000.0); return(finishTransmit()); } @@ -203,25 +203,25 @@ int16_t SX127x::receive(uint8_t* data, size_t len) { // if no DIO1 is provided, use software timeout (100 LoRa symbols, same as hardware timeout) uint32_t timeout = 0; - if(_mod->getGpio() == RADIOLIB_NC) { - float symbolLength = (float) (uint32_t(1) << _sf) / (float) _bw; + if(this->mod->getGpio() == RADIOLIB_NC) { + float symbolLength = (float) (uint32_t(1) << this->spreadingFactor) / (float) this->bandwidth; timeout = 100*symbolLength; } // wait for packet reception or timeout - uint32_t start = _mod->hal->micros(); - while(!_mod->hal->digitalRead(_mod->getIrq())) { - _mod->hal->yield(); + uint32_t start = this->mod->hal->micros(); + while(!this->mod->hal->digitalRead(this->mod->getIrq())) { + this->mod->hal->yield(); - if(_mod->getGpio() == RADIOLIB_NC) { + if(this->mod->getGpio() == RADIOLIB_NC) { // no GPIO pin provided, use software timeout - if(_mod->hal->micros() - start > timeout) { + if(this->mod->hal->micros() - start > timeout) { clearIRQFlags(); return(RADIOLIB_ERR_RX_TIMEOUT); } } else { // GPIO provided, use that - if(_mod->hal->digitalRead(_mod->getGpio())) { + if(this->mod->hal->digitalRead(this->mod->getGpio())) { clearIRQFlags(); return(RADIOLIB_ERR_RX_TIMEOUT); } @@ -238,10 +238,10 @@ int16_t SX127x::receive(uint8_t* data, size_t len) { RADIOLIB_ASSERT(state); // wait for packet reception or timeout - uint32_t start = _mod->hal->micros(); - while(!_mod->hal->digitalRead(_mod->getIrq())) { - _mod->hal->yield(); - if(_mod->hal->micros() - start > timeout) { + uint32_t start = this->mod->hal->micros(); + while(!this->mod->hal->digitalRead(this->mod->getIrq())) { + this->mod->hal->yield(); + if(this->mod->hal->micros() - start > timeout) { clearIRQFlags(); return(RADIOLIB_ERR_RX_TIMEOUT); } @@ -260,9 +260,9 @@ int16_t SX127x::scanChannel() { RADIOLIB_ASSERT(state); // wait for channel activity detected or timeout - while(!_mod->hal->digitalRead(_mod->getIrq())) { - _mod->hal->yield(); - if(_mod->hal->digitalRead(_mod->getGpio())) { + while(!this->mod->hal->digitalRead(this->mod->getIrq())) { + this->mod->hal->yield(); + if(this->mod->hal->digitalRead(this->mod->getGpio())) { return(RADIOLIB_PREAMBLE_DETECTED); } } @@ -272,7 +272,7 @@ int16_t SX127x::scanChannel() { int16_t SX127x::sleep() { // set RF switch (if present) - _mod->setRfSwitchState(Module::MODE_IDLE); + this->mod->setRfSwitchState(Module::MODE_IDLE); // set mode to sleep return(setMode(RADIOLIB_SX127X_SLEEP)); @@ -280,7 +280,7 @@ int16_t SX127x::sleep() { int16_t SX127x::standby() { // set RF switch (if present) - _mod->setRfSwitchState(Module::MODE_IDLE); + this->mod->setRfSwitchState(Module::MODE_IDLE); // set mode to standby return(setMode(RADIOLIB_SX127X_STANDBY)); @@ -298,13 +298,13 @@ int16_t SX127x::transmitDirect(uint32_t frf) { } // set RF switch (if present) - _mod->setRfSwitchState(Module::MODE_TX); + this->mod->setRfSwitchState(Module::MODE_TX); // user requested to start transmitting immediately (required for RTTY) if(frf != 0) { - _mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FRF_MSB, (frf & 0xFF0000) >> 16); - _mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FRF_MID, (frf & 0x00FF00) >> 8); - _mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FRF_LSB, frf & 0x0000FF); + this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FRF_MSB, (frf & 0xFF0000) >> 16); + this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FRF_MID, (frf & 0x00FF00) >> 8); + this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FRF_LSB, frf & 0x0000FF); return(setMode(RADIOLIB_SX127X_TX)); } @@ -327,7 +327,7 @@ int16_t SX127x::receiveDirect() { } // set RF switch (if present) - _mod->setRfSwitchState(Module::MODE_RX); + this->mod->setRfSwitchState(Module::MODE_RX); // activate direct mode int16_t state = directMode(); @@ -346,7 +346,7 @@ int16_t SX127x::directMode() { RADIOLIB_ASSERT(state); // set DIO mapping - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO1_CONT_DCLK | RADIOLIB_SX127X_DIO2_CONT_DATA, 5, 2); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO1_CONT_DCLK | RADIOLIB_SX127X_DIO2_CONT_DATA, 5, 2); RADIOLIB_ASSERT(state); // enable receiver startup without preamble or RSSI @@ -354,7 +354,7 @@ int16_t SX127x::directMode() { RADIOLIB_ASSERT(state); // set continuous mode - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_2, RADIOLIB_SX127X_DATA_MODE_CONTINUOUS, 6, 6)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_2, RADIOLIB_SX127X_DATA_MODE_CONTINUOUS, 6, 6)); } int16_t SX127x::packetMode() { @@ -363,7 +363,7 @@ int16_t SX127x::packetMode() { return(RADIOLIB_ERR_WRONG_MODEM); } - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_2, RADIOLIB_SX127X_DATA_MODE_PACKET, 6, 6)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_2, RADIOLIB_SX127X_DATA_MODE_PACKET, 6, 6)); } int16_t SX127x::startReceive(uint8_t len, uint8_t mode) { @@ -374,16 +374,16 @@ int16_t SX127x::startReceive(uint8_t len, uint8_t mode) { int16_t modem = getActiveModem(); if(modem == RADIOLIB_SX127X_LORA) { // set DIO pin mapping - if(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD) > RADIOLIB_SX127X_HOP_PERIOD_OFF) { - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_LORA_RX_DONE | RADIOLIB_SX127X_DIO1_LORA_FHSS_CHANGE_CHANNEL, 7, 4); + if(this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD) > RADIOLIB_SX127X_HOP_PERIOD_OFF) { + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_LORA_RX_DONE | RADIOLIB_SX127X_DIO1_LORA_FHSS_CHANGE_CHANNEL, 7, 4); } else { - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_LORA_RX_DONE | RADIOLIB_SX127X_DIO1_LORA_RX_TIMEOUT, 7, 4); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_LORA_RX_DONE | RADIOLIB_SX127X_DIO1_LORA_RX_TIMEOUT, 7, 4); } // set expected packet length for SF6 - if(_sf == 6) { - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len); - _packetLength = len; + if(this->spreadingFactor == 6) { + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len); + this->packetLength = len; } // apply fixes to errata @@ -393,13 +393,13 @@ int16_t SX127x::startReceive(uint8_t len, uint8_t mode) { clearIRQFlags(); // set FIFO pointers - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_RX_BASE_ADDR, RADIOLIB_SX127X_FIFO_RX_BASE_ADDR_MAX); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_ADDR_PTR, RADIOLIB_SX127X_FIFO_RX_BASE_ADDR_MAX); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_RX_BASE_ADDR, RADIOLIB_SX127X_FIFO_RX_BASE_ADDR_MAX); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_ADDR_PTR, RADIOLIB_SX127X_FIFO_RX_BASE_ADDR_MAX); RADIOLIB_ASSERT(state); } else if(modem == RADIOLIB_SX127X_FSK_OOK) { // set DIO pin mapping - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_PACK_PAYLOAD_READY, 7, 6); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_PACK_PAYLOAD_READY, 7, 6); RADIOLIB_ASSERT(state); // clear interrupt flags @@ -408,13 +408,13 @@ int16_t SX127x::startReceive(uint8_t len, uint8_t mode) { // FSK modem does not distinguish between Rx single and continuous if(mode == RADIOLIB_SX127X_RXCONTINUOUS) { // set RF switch (if present) - _mod->setRfSwitchState(Module::MODE_RX); + this->mod->setRfSwitchState(Module::MODE_RX); return(setMode(RADIOLIB_SX127X_RX)); } } // set RF switch (if present) - _mod->setRfSwitchState(Module::MODE_RX); + this->mod->setRfSwitchState(Module::MODE_RX); // set mode to receive return(setMode(mode)); @@ -427,30 +427,30 @@ int16_t SX127x::startReceive(uint32_t mode, uint16_t irqFlags, uint16_t irqMask, } void SX127x::setDio0Action(void (*func)(void), uint32_t dir) { - _mod->hal->attachInterrupt(_mod->hal->pinToInterrupt(_mod->getIrq()), func, dir); + this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()), func, dir); } void SX127x::clearDio0Action() { - _mod->hal->detachInterrupt(_mod->hal->pinToInterrupt(_mod->getIrq())); + this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq())); } void SX127x::setDio1Action(void (*func)(void), uint32_t dir) { - if(_mod->getGpio() == RADIOLIB_NC) { + if(this->mod->getGpio() == RADIOLIB_NC) { return; } - _mod->hal->attachInterrupt(_mod->hal->pinToInterrupt(_mod->getGpio()), func, dir); + this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getGpio()), func, dir); } void SX127x::clearDio1Action() { - if(_mod->getGpio() == RADIOLIB_NC) { + if(this->mod->getGpio() == RADIOLIB_NC) { return; } - _mod->hal->detachInterrupt(_mod->hal->pinToInterrupt(_mod->getGpio())); + this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getGpio())); } void SX127x::setFifoEmptyAction(void (*func)(void)) { // set DIO1 to the FIFO empty event (the register setting is done in startTransmit) - setDio1Action(func, _mod->hal->GpioInterruptRising); + setDio1Action(func, this->mod->hal->GpioInterruptRising); } void SX127x::clearFifoEmptyAction() { @@ -459,16 +459,16 @@ void SX127x::clearFifoEmptyAction() { void SX127x::setFifoFullAction(void (*func)(void)) { // set the interrupt - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_THRESH, RADIOLIB_SX127X_FIFO_THRESH, 5, 0); - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO1_PACK_FIFO_LEVEL, 5, 4); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_THRESH, RADIOLIB_SX127X_FIFO_THRESH, 5, 0); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO1_PACK_FIFO_LEVEL, 5, 4); // set DIO1 to the FIFO full event - setDio1Action(func, _mod->hal->GpioInterruptRising); + setDio1Action(func, this->mod->hal->GpioInterruptRising); } void SX127x::clearFifoFullAction() { clearDio1Action(); - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, 0x00, 5, 4); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, 0x00, 5, 4); } bool SX127x::fifoAdd(uint8_t* data, int totalLen, int* remLen) { @@ -488,7 +488,7 @@ bool SX127x::fifoAdd(uint8_t* data, int totalLen, int* remLen) { } // copy the bytes to the FIFO - _mod->SPIwriteRegisterBurst(RADIOLIB_SX127X_REG_FIFO, &data[totalLen - *remLen], len); + this->mod->SPIwriteRegisterBurst(RADIOLIB_SX127X_REG_FIFO, &data[totalLen - *remLen], len); // we're not done yet return(false); @@ -506,7 +506,7 @@ bool SX127x::fifoGet(volatile uint8_t* data, int totalLen, volatile int* rcvLen) } // get the data - _mod->SPIreadRegisterBurst(RADIOLIB_SX127X_REG_FIFO, len, dataPtr); + this->mod->SPIreadRegisterBurst(RADIOLIB_SX127X_REG_FIFO, len, dataPtr); (*rcvLen) += (len); // check if we're done @@ -528,10 +528,10 @@ int16_t SX127x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { } // set DIO mapping - if(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD) > RADIOLIB_SX127X_HOP_PERIOD_OFF) { - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_LORA_TX_DONE | RADIOLIB_SX127X_DIO1_LORA_FHSS_CHANGE_CHANNEL, 7, 4); + if(this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD) > RADIOLIB_SX127X_HOP_PERIOD_OFF) { + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_LORA_TX_DONE | RADIOLIB_SX127X_DIO1_LORA_FHSS_CHANGE_CHANNEL, 7, 4); } else { - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_LORA_TX_DONE, 7, 6); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_LORA_TX_DONE, 7, 6); } // apply fixes to errata @@ -541,11 +541,11 @@ int16_t SX127x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { clearIRQFlags(); // set packet length - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len); // set FIFO pointers - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_TX_BASE_ADDR, RADIOLIB_SX127X_FIFO_TX_BASE_ADDR_MAX); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_ADDR_PTR, RADIOLIB_SX127X_FIFO_TX_BASE_ADDR_MAX); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_TX_BASE_ADDR, RADIOLIB_SX127X_FIFO_TX_BASE_ADDR_MAX); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_ADDR_PTR, RADIOLIB_SX127X_FIFO_TX_BASE_ADDR_MAX); } else if(modem == RADIOLIB_SX127X_FSK_OOK) { // clear interrupt flags @@ -553,20 +553,20 @@ int16_t SX127x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { // set DIO mapping if(len > RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK) { - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO1_PACK_FIFO_EMPTY, 5, 4); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO1_PACK_FIFO_EMPTY, 5, 4); } else { - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_PACK_PACKET_SENT, 7, 6); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_PACK_PACKET_SENT, 7, 6); } // set packet length - if (_packetLengthConfig == RADIOLIB_SX127X_PACKET_VARIABLE) { - _mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FIFO, len); + if (this->packetLengthConfig == RADIOLIB_SX127X_PACKET_VARIABLE) { + this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FIFO, len); } // check address filtering - uint8_t filter = _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, 2, 1); + uint8_t filter = this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, 2, 1); if((filter == RADIOLIB_SX127X_ADDRESS_FILTERING_NODE) || (filter == RADIOLIB_SX127X_ADDRESS_FILTERING_NODE_BROADCAST)) { - _mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FIFO, addr); + this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FIFO, addr); } } @@ -574,12 +574,12 @@ int16_t SX127x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { size_t packetLen = len; if((modem == RADIOLIB_SX127X_FSK_OOK) && (len > RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK)) { packetLen = RADIOLIB_SX127X_FIFO_THRESH - 1; - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_THRESH, RADIOLIB_SX127X_TX_START_FIFO_NOT_EMPTY, 7, 7); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_THRESH, RADIOLIB_SX127X_TX_START_FIFO_NOT_EMPTY, 7, 7); } - _mod->SPIwriteRegisterBurst(RADIOLIB_SX127X_REG_FIFO, data, packetLen); + this->mod->SPIwriteRegisterBurst(RADIOLIB_SX127X_REG_FIFO, data, packetLen); // set RF switch (if present) - _mod->setRfSwitchState(Module::MODE_TX); + this->mod->setRfSwitchState(Module::MODE_TX); // start transmission state |= setMode(RADIOLIB_SX127X_TX); @@ -610,13 +610,13 @@ int16_t SX127x::readData(uint8_t* data, size_t len) { // check payload CRC int16_t state = RADIOLIB_ERR_NONE; - if(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_IRQ_FLAGS, 5, 5) == RADIOLIB_SX127X_CLEAR_IRQ_FLAG_PAYLOAD_CRC_ERROR) { + if(this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_IRQ_FLAGS, 5, 5) == RADIOLIB_SX127X_CLEAR_IRQ_FLAG_PAYLOAD_CRC_ERROR) { state = RADIOLIB_ERR_CRC_MISMATCH; } if(modem == RADIOLIB_SX127X_LORA) { // check packet header integrity - if(_crcEnabled && (state == RADIOLIB_ERR_NONE) && (_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_CHANNEL, 6, 6) == 0)) { + if(this->crcEnabled && (state == RADIOLIB_ERR_NONE) && (this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_CHANNEL, 6, 6) == 0)) { // CRC is disabled according to packet header and enabled according to user // most likely damaged packet header state = RADIOLIB_ERR_LORA_HEADER_DAMAGED; @@ -624,14 +624,14 @@ int16_t SX127x::readData(uint8_t* data, size_t len) { } else if(modem == RADIOLIB_SX127X_FSK_OOK) { // check address filtering - uint8_t filter = _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, 2, 1); + uint8_t filter = this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, 2, 1); if((filter == RADIOLIB_SX127X_ADDRESS_FILTERING_NODE) || (filter == RADIOLIB_SX127X_ADDRESS_FILTERING_NODE_BROADCAST)) { - _mod->SPIreadRegister(RADIOLIB_SX127X_REG_FIFO); + this->mod->SPIreadRegister(RADIOLIB_SX127X_REG_FIFO); } } // read packet data - _mod->SPIreadRegisterBurst(RADIOLIB_SX127X_REG_FIFO, length, data); + this->mod->SPIreadRegisterBurst(RADIOLIB_SX127X_REG_FIFO, length, data); // dump the bytes that weren't requested if(dumpLen != 0) { @@ -639,7 +639,7 @@ int16_t SX127x::readData(uint8_t* data, size_t len) { } // clear internal flag so getPacketLength can return the new packet length - _packetLengthQueried = false; + this->packetLengthQueried = false; // clear interrupt flags clearIRQFlags(); @@ -661,11 +661,11 @@ int16_t SX127x::startChannelScan() { clearIRQFlags(); // set DIO pin mapping - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_LORA_CAD_DONE | RADIOLIB_SX127X_DIO1_LORA_CAD_DETECTED, 7, 4); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_LORA_CAD_DONE | RADIOLIB_SX127X_DIO1_LORA_CAD_DETECTED, 7, 4); RADIOLIB_ASSERT(state); // set RF switch (if present) - _mod->setRfSwitchState(Module::MODE_RX); + this->mod->setRfSwitchState(Module::MODE_RX); // set mode to CAD state = setMode(RADIOLIB_SX127X_CAD); @@ -682,7 +682,7 @@ int16_t SX127x::setSyncWord(uint8_t syncWord) { setMode(RADIOLIB_SX127X_STANDBY); // write register - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_WORD, syncWord)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_WORD, syncWord)); } int16_t SX127x::setCurrentLimit(uint8_t currentLimit) { @@ -698,13 +698,13 @@ int16_t SX127x::setCurrentLimit(uint8_t currentLimit) { uint8_t raw; if(currentLimit == 0) { // limit set to 0, disable OCP - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OCP, RADIOLIB_SX127X_OCP_OFF, 5, 5); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OCP, RADIOLIB_SX127X_OCP_OFF, 5, 5); } else if(currentLimit <= 120) { raw = (currentLimit - 45) / 5; - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OCP, RADIOLIB_SX127X_OCP_ON | raw, 5, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OCP, RADIOLIB_SX127X_OCP_ON | raw, 5, 0); } else if(currentLimit <= 240) { raw = (currentLimit + 30) / 10; - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OCP, RADIOLIB_SX127X_OCP_ON | raw, 5, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OCP, RADIOLIB_SX127X_OCP_ON | raw, 5, 0); } return(state); } @@ -723,15 +723,15 @@ int16_t SX127x::setPreambleLength(uint16_t preambleLength) { } // set preamble length - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_MSB, (uint8_t)((preambleLength >> 8) & 0xFF)); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_LSB, (uint8_t)(preambleLength & 0xFF)); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_MSB, (uint8_t)((preambleLength >> 8) & 0xFF)); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_LSB, (uint8_t)(preambleLength & 0xFF)); return(state); } else if(modem == RADIOLIB_SX127X_FSK_OOK) { // set preamble length (in bytes) uint16_t numBytes = preambleLength / 8; - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_MSB_FSK, (uint8_t)((numBytes >> 8) & 0xFF)); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_LSB_FSK, (uint8_t)(numBytes & 0xFF)); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_MSB_FSK, (uint8_t)((numBytes >> 8) & 0xFF)); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_LSB_FSK, (uint8_t)(numBytes & 0xFF)); return(state); } @@ -742,9 +742,9 @@ float SX127x::getFrequencyError(bool autoCorrect) { int16_t modem = getActiveModem(); if(modem == RADIOLIB_SX127X_LORA) { // get raw frequency error - uint32_t raw = (uint32_t)_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_FEI_MSB, 3, 0) << 16; - raw |= (uint16_t)_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_FEI_MID) << 8; - raw |= _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_FEI_LSB); + uint32_t raw = (uint32_t)this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_FEI_MSB, 3, 0) << 16; + raw |= (uint16_t)this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_FEI_MID) << 8; + raw |= this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_FEI_LSB); uint32_t base = (uint32_t)2 << 23; float error; @@ -754,23 +754,23 @@ float SX127x::getFrequencyError(bool autoCorrect) { // frequency error is negative raw |= (uint32_t)0xFFF00000; raw = ~raw + 1; - error = (((float)raw * (float)base)/32000000.0) * (_bw/500.0) * -1.0; + error = (((float)raw * (float)base)/32000000.0) * (this->bandwidth/500.0) * -1.0; } else { - error = (((float)raw * (float)base)/32000000.0) * (_bw/500.0); + error = (((float)raw * (float)base)/32000000.0) * (this->bandwidth/500.0); } if(autoCorrect) { // adjust LoRa modem data rate float ppmOffset = 0.95 * (error/32.0); - _mod->SPIwriteRegister(0x27, (uint8_t)ppmOffset); + this->mod->SPIwriteRegister(0x27, (uint8_t)ppmOffset); } return(error); } else if(modem == RADIOLIB_SX127X_FSK_OOK) { // get raw frequency error - uint16_t raw = (uint16_t)_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_FEI_MSB_FSK) << 8; - raw |= _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_FEI_LSB_FSK); + uint16_t raw = (uint16_t)this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_FEI_MSB_FSK) << 8; + raw |= this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_FEI_LSB_FSK); uint32_t base = 1; float error; @@ -800,8 +800,8 @@ float SX127x::getAFCError() } // get raw frequency error - int16_t raw = (uint16_t)_mod->SPIreadRegister(RADIOLIB_SX127X_REG_AFC_MSB) << 8; - raw |= _mod->SPIreadRegister(RADIOLIB_SX127X_REG_AFC_LSB); + int16_t raw = (uint16_t)this->mod->SPIreadRegister(RADIOLIB_SX127X_REG_AFC_MSB) << 8; + raw |= this->mod->SPIreadRegister(RADIOLIB_SX127X_REG_AFC_LSB); uint32_t base = 1; return raw * (32000000.0 / (float)(base << 19)); @@ -814,12 +814,12 @@ float SX127x::getSNR() { } // get SNR value - int8_t rawSNR = (int8_t)_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PKT_SNR_VALUE); + int8_t rawSNR = (int8_t)this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PKT_SNR_VALUE); return(rawSNR / 4.0); } float SX127x::getDataRate() const { - return(_dataRate); + return(this->dataRate); } int16_t SX127x::setBitRateCommon(float br, uint8_t fracRegAddr) { @@ -830,7 +830,7 @@ int16_t SX127x::setBitRateCommon(float br, uint8_t fracRegAddr) { // check allowed bit rate // datasheet says 1.2 kbps should be the smallest possible, but 0.512 works fine - if(_ook) { + if(ookEnabled) { RADIOLIB_CHECK_RANGE(br, 0.5, 32.768002, RADIOLIB_ERR_INVALID_BIT_RATE); // Found that 32.768 is 32.768002 } else { RADIOLIB_CHECK_RANGE(br, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE); @@ -842,18 +842,18 @@ int16_t SX127x::setBitRateCommon(float br, uint8_t fracRegAddr) { // set bit rate uint16_t bitRate = (RADIOLIB_SX127X_CRYSTAL_FREQ * 1000.0) / br; - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0); // set fractional part of bit rate - if(!_ook) { + if(!ookEnabled) { float bitRateRem = ((RADIOLIB_SX127X_CRYSTAL_FREQ * 1000.0) / (float)br) - (float)bitRate; uint8_t bitRateFrac = bitRateRem * 16; - state |= _mod->SPIsetRegValue(fracRegAddr, bitRateFrac, 7, 0); + state |= this->mod->SPIsetRegValue(fracRegAddr, bitRateFrac, 7, 0); } if(state == RADIOLIB_ERR_NONE) { - SX127x::_br = br; + this->bitRate = br; } return(state); } @@ -871,7 +871,7 @@ int16_t SX127x::setFrequencyDeviation(float freqDev) { } // check frequency deviation range - if(!((newFreqDev + _br/2.0 <= 250.0) && (freqDev <= 200.0))) { + if(!((newFreqDev + this->bitRate/2.0 <= 250.0) && (freqDev <= 200.0))) { return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION); } @@ -882,8 +882,8 @@ int16_t SX127x::setFrequencyDeviation(float freqDev) { // set allowed frequency deviation uint32_t base = 1; uint32_t FDEV = (newFreqDev * (base << 19)) / 32000; - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FDEV_MSB, (FDEV & 0xFF00) >> 8, 5, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FDEV_LSB, FDEV & 0x00FF, 7, 0); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FDEV_MSB, (FDEV & 0xFF00) >> 8, 5, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FDEV_LSB, FDEV & 0x00FF, 7, 0); return(state); } @@ -913,7 +913,7 @@ int16_t SX127x::setRxBandwidth(float rxBw) { RADIOLIB_ASSERT(state); // set Rx bandwidth - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_BW, calculateBWManExp(rxBw), 4, 0)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_BW, calculateBWManExp(rxBw), 4, 0)); } int16_t SX127x::setAFCBandwidth(float rxBw) { @@ -929,7 +929,7 @@ int16_t SX127x::setAFCBandwidth(float rxBw) { RADIOLIB_ASSERT(state); // set AFC bandwidth - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_AFC_BW, calculateBWManExp(rxBw), 4, 0)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_AFC_BW, calculateBWManExp(rxBw), 4, 0)); } int16_t SX127x::setAFC(bool isEnabled) { @@ -939,7 +939,7 @@ int16_t SX127x::setAFC(bool isEnabled) { } //set AFC auto on/off - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, isEnabled ? RADIOLIB_SX127X_AFC_AUTO_ON : RADIOLIB_SX127X_AFC_AUTO_OFF, 4, 4)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, isEnabled ? RADIOLIB_SX127X_AFC_AUTO_ON : RADIOLIB_SX127X_AFC_AUTO_OFF, 4, 4)); } int16_t SX127x::setAFCAGCTrigger(uint8_t trigger) { @@ -948,7 +948,7 @@ int16_t SX127x::setAFCAGCTrigger(uint8_t trigger) { } //set AFC&AGC trigger - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, trigger, 2, 0)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, trigger, 2, 0)); } int16_t SX127x::setSyncWord(uint8_t* syncWord, size_t len) { @@ -967,12 +967,12 @@ int16_t SX127x::setSyncWord(uint8_t* syncWord, size_t len) { } // enable sync word recognition - int16_t state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, RADIOLIB_SX127X_SYNC_ON, 4, 4); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, len - 1, 2, 0); + int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, RADIOLIB_SX127X_SYNC_ON, 4, 4); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, len - 1, 2, 0); RADIOLIB_ASSERT(state); // set sync word - _mod->SPIwriteRegisterBurst(RADIOLIB_SX127X_REG_SYNC_VALUE_1, syncWord, len); + this->mod->SPIwriteRegisterBurst(RADIOLIB_SX127X_REG_SYNC_VALUE_1, syncWord, len); return(RADIOLIB_ERR_NONE); } @@ -983,11 +983,11 @@ int16_t SX127x::setNodeAddress(uint8_t nodeAddr) { } // enable address filtering (node only) - int16_t state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_ADDRESS_FILTERING_NODE, 2, 1); + int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_ADDRESS_FILTERING_NODE, 2, 1); RADIOLIB_ASSERT(state); // set node address - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_NODE_ADRS, nodeAddr)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_NODE_ADRS, nodeAddr)); } int16_t SX127x::setBroadcastAddress(uint8_t broadAddr) { @@ -997,11 +997,11 @@ int16_t SX127x::setBroadcastAddress(uint8_t broadAddr) { } // enable address filtering (node + broadcast) - int16_t state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_ADDRESS_FILTERING_NODE_BROADCAST, 2, 1); + int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_ADDRESS_FILTERING_NODE_BROADCAST, 2, 1); RADIOLIB_ASSERT(state); // set broadcast address - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BROADCAST_ADRS, broadAddr)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BROADCAST_ADRS, broadAddr)); } int16_t SX127x::disableAddressFiltering() { @@ -1011,15 +1011,15 @@ int16_t SX127x::disableAddressFiltering() { } // disable address filtering - int16_t state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_ADDRESS_FILTERING_OFF, 2, 1); + int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_ADDRESS_FILTERING_OFF, 2, 1); RADIOLIB_ASSERT(state); // set node address to default (0x00) - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_NODE_ADRS, 0x00); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_NODE_ADRS, 0x00); RADIOLIB_ASSERT(state); // set broadcast address to default (0x00) - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BROADCAST_ADRS, 0x00)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BROADCAST_ADRS, 0x00)); } int16_t SX127x::setOokThresholdType(uint8_t type) { @@ -1027,7 +1027,7 @@ int16_t SX127x::setOokThresholdType(uint8_t type) { if(getActiveModem() != RADIOLIB_SX127X_FSK_OOK) { return(RADIOLIB_ERR_WRONG_MODEM); } - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OOK_PEAK, type, 4, 3, 5)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OOK_PEAK, type, 4, 3, 5)); } int16_t SX127x::setOokFixedOrFloorThreshold(uint8_t value) { @@ -1035,7 +1035,7 @@ int16_t SX127x::setOokFixedOrFloorThreshold(uint8_t value) { if(getActiveModem() != RADIOLIB_SX127X_FSK_OOK) { return(RADIOLIB_ERR_WRONG_MODEM); } - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OOK_FIX, value, 7, 0, 5)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OOK_FIX, value, 7, 0, 5)); } int16_t SX127x::setOokPeakThresholdDecrement(uint8_t value) { @@ -1043,7 +1043,7 @@ int16_t SX127x::setOokPeakThresholdDecrement(uint8_t value) { if(getActiveModem() != RADIOLIB_SX127X_FSK_OOK) { return(RADIOLIB_ERR_WRONG_MODEM); } - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OOK_AVG, value, 7, 5, 5)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OOK_AVG, value, 7, 5, 5)); } int16_t SX127x::setOokPeakThresholdStep(uint8_t value) { @@ -1051,15 +1051,15 @@ int16_t SX127x::setOokPeakThresholdStep(uint8_t value) { if(getActiveModem() != RADIOLIB_SX127X_FSK_OOK) { return(RADIOLIB_ERR_WRONG_MODEM); } - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OOK_PEAK, value, 2, 0, 5)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OOK_PEAK, value, 2, 0, 5)); } int16_t SX127x::enableBitSync() { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OOK_PEAK, RADIOLIB_SX127X_BIT_SYNC_ON, 5, 5, 5)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OOK_PEAK, RADIOLIB_SX127X_BIT_SYNC_ON, 5, 5, 5)); } int16_t SX127x::disableBitSync() { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OOK_PEAK, RADIOLIB_SX127X_BIT_SYNC_OFF, 5, 5, 5)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OOK_PEAK, RADIOLIB_SX127X_BIT_SYNC_OFF, 5, 5, 5)); } int16_t SX127x::setOOK(bool enableOOK) { @@ -1071,14 +1071,14 @@ int16_t SX127x::setOOK(bool enableOOK) { // set OOK and if successful, save the new setting int16_t state = RADIOLIB_ERR_NONE; if(enableOOK) { - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX127X_MODULATION_OOK, 6, 5, 5); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX127X_MODULATION_OOK, 6, 5, 5); state |= SX127x::setAFCAGCTrigger(RADIOLIB_SX127X_RX_TRIGGER_RSSI_INTERRUPT); } else { - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX127X_MODULATION_FSK, 6, 5, 5); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX127X_MODULATION_FSK, 6, 5, 5); state |= SX127x::setAFCAGCTrigger(RADIOLIB_SX127X_RX_TRIGGER_BOTH); } if(state == RADIOLIB_ERR_NONE) { - _ook = enableOOK; + ookEnabled = enableOOK; } return(state); @@ -1088,7 +1088,7 @@ int16_t SX127x::setFrequencyRaw(float newFreq) { int16_t state = RADIOLIB_ERR_NONE; // set mode to standby if not FHSS - if(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD) == RADIOLIB_SX127X_HOP_PERIOD_OFF) { + if(this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD) == RADIOLIB_SX127X_HOP_PERIOD_OFF) { state = setMode(RADIOLIB_SX127X_STANDBY); } @@ -1096,9 +1096,9 @@ int16_t SX127x::setFrequencyRaw(float newFreq) { uint32_t FRF = (newFreq * (uint32_t(1) << RADIOLIB_SX127X_DIV_EXPONENT)) / RADIOLIB_SX127X_CRYSTAL_FREQ; // write registers - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FRF_MSB, (FRF & 0xFF0000) >> 16); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FRF_MID, (FRF & 0x00FF00) >> 8); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FRF_LSB, FRF & 0x0000FF); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FRF_MSB, (FRF & 0xFF0000) >> 16); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FRF_MID, (FRF & 0x00FF00) >> 8); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FRF_LSB, FRF & 0x0000FF); return(state); } @@ -1106,28 +1106,28 @@ size_t SX127x::getPacketLength(bool update) { int16_t modem = getActiveModem(); if(modem == RADIOLIB_SX127X_LORA) { - if(_sf != 6) { + if(this->spreadingFactor != 6) { // get packet length for SF7 - SF12 - return(_mod->SPIreadRegister(RADIOLIB_SX127X_REG_RX_NB_BYTES)); + return(this->mod->SPIreadRegister(RADIOLIB_SX127X_REG_RX_NB_BYTES)); } else { // return the cached value for SF6 - return(_packetLength); + return(this->packetLength); } } else if(modem == RADIOLIB_SX127X_FSK_OOK) { // get packet length - if(!_packetLengthQueried && update) { - if (_packetLengthConfig == RADIOLIB_SX127X_PACKET_VARIABLE) { - _packetLength = _mod->SPIreadRegister(RADIOLIB_SX127X_REG_FIFO); + if(!this->packetLengthQueried && update) { + if (this->packetLengthConfig == RADIOLIB_SX127X_PACKET_VARIABLE) { + this->packetLength = this->mod->SPIreadRegister(RADIOLIB_SX127X_REG_FIFO); } else { - _packetLength = _mod->SPIreadRegister(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH_FSK); + this->packetLength = this->mod->SPIreadRegister(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH_FSK); } - _packetLengthQueried = true; + this->packetLengthQueried = true; } } - return(_packetLength); + return(this->packetLength); } int16_t SX127x::fixedPacketLengthMode(uint8_t len) { @@ -1143,61 +1143,61 @@ uint32_t SX127x::getTimeOnAir(size_t len) { uint8_t modem = getActiveModem(); if (modem == RADIOLIB_SX127X_LORA) { // Get symbol length in us - float symbolLength = (float) (uint32_t(1) << _sf) / (float) _bw; + float symbolLength = (float) (uint32_t(1) << this->spreadingFactor) / (float) this->bandwidth; // Get Low Data Rate optimization flag float de = 0; if (symbolLength >= 16.0) { de = 1; } // Get explicit/implicit header enabled flag - float ih = (float) _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, 0, 0); + float ih = (float) this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, 0, 0); // Get CRC enabled flag - float crc = (float) (_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, 2, 2) >> 2); + float crc = (float) (this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, 2, 2) >> 2); // Get number of bits preamble - float n_pre = (float) ((_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_MSB) << 8) | _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_LSB)); + float n_pre = (float) ((this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_MSB) << 8) | this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_LSB)); // Get number of bits payload - float n_pay = 8.0 + max(ceil((8.0 * (float) len - 4.0 * (float) _sf + 28.0 + 16.0 * crc - 20.0 * ih) / (4.0 * (float) _sf - 8.0 * de)) * (float) _cr, 0.0); + float n_pay = 8.0 + max(ceil((8.0 * (float) len - 4.0 * (float) this->spreadingFactor + 28.0 + 16.0 * crc - 20.0 * ih) / (4.0 * (float) this->spreadingFactor - 8.0 * de)) * (float) this->codingRate, 0.0); // Get time-on-air in us return ceil(symbolLength * (n_pre + n_pay + 4.25)) * 1000; } else if(modem == RADIOLIB_SX127X_FSK_OOK) { // Get number of bits preamble - float n_pre = (float) ((_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_MSB_FSK) << 8) | _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_LSB_FSK)) * 8; + float n_pre = (float) ((this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_MSB_FSK) << 8) | this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_LSB_FSK)) * 8; //Get the number of bits of the sync word - float n_syncWord = (float) (_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, 2, 0) + 1) * 8; + float n_syncWord = (float) (this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, 2, 0) + 1) * 8; //Get CRC bits - float crc = (_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, 4, 4) == RADIOLIB_SX127X_CRC_ON) * 16; + float crc = (this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, 4, 4) == RADIOLIB_SX127X_CRC_ON) * 16; - if (_packetLengthConfig == RADIOLIB_SX127X_PACKET_FIXED) { + if (this->packetLengthConfig == RADIOLIB_SX127X_PACKET_FIXED) { //If Packet size fixed -> len = fixed packet length - len = _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH_FSK); + len = this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH_FSK); } else { //if packet variable -> Add 1 extra byte for payload length len += 1; } // Calculate time-on-air in us {[(length in bytes) * (8 bits / 1 byte)] / [(Bit Rate in kbps) * (1000 bps / 1 kbps)]} * (1000000 us in 1 sec) - return (uint32_t) (((crc + n_syncWord + n_pre + (float) (len * 8)) / (_br * 1000.0)) * 1000000.0); + return (uint32_t) (((crc + n_syncWord + n_pre + (float) (len * 8)) / (this->bitRate * 1000.0)) * 1000000.0); } else { return(RADIOLIB_ERR_UNKNOWN); } } -int16_t SX127x::setCrcFiltering(bool crcOn) { - _crcOn = crcOn; +int16_t SX127x::setCrcFiltering(bool enable) { + this->crcOn = enable; - if (crcOn == true) { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_ON, 4, 4)); + if (enable == true) { + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_ON, 4, 4)); } else { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_OFF, 4, 4)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_OFF, 4, 4)); } } int16_t SX127x::setRSSIThreshold(float dbm) { RADIOLIB_CHECK_RANGE(dbm, -127.5, 0, RADIOLIB_ERR_INVALID_RSSI_THRESHOLD); - return _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RSSI_THRESH, (uint8_t)(-2.0 * dbm), 7, 0); + return this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RSSI_THRESH, (uint8_t)(-2.0 * dbm), 7, 0); } int16_t SX127x::setRSSIConfig(uint8_t smoothingSamples, int8_t offset) { @@ -1218,8 +1218,8 @@ int16_t SX127x::setRSSIConfig(uint8_t smoothingSamples, int8_t offset) { RADIOLIB_CHECK_RANGE(offset, -16, 15, RADIOLIB_ERR_INVALID_RSSI_OFFSET); // set new register values - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RSSI_CONFIG, offset << 3, 7, 3); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RSSI_CONFIG, smoothingSamples, 2, 0); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RSSI_CONFIG, offset << 3, 7, 3); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RSSI_CONFIG, smoothingSamples, 2, 0); return(state); } @@ -1232,11 +1232,11 @@ int16_t SX127x::setEncoding(uint8_t encoding) { // set encoding switch(encoding) { case RADIOLIB_ENCODING_NRZ: - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_DC_FREE_NONE, 6, 5)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_DC_FREE_NONE, 6, 5)); case RADIOLIB_ENCODING_MANCHESTER: - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_DC_FREE_MANCHESTER, 6, 5)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_DC_FREE_MANCHESTER, 6, 5)); case RADIOLIB_ENCODING_WHITENING: - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_DC_FREE_WHITENING, 6, 5)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_DC_FREE_WHITENING, 6, 5)); default: return(RADIOLIB_ERR_INVALID_ENCODING); } @@ -1246,12 +1246,12 @@ uint16_t SX127x::getIRQFlags() { // check active modem if(getActiveModem() == RADIOLIB_SX127X_LORA) { // LoRa, just 8-bit value - return((uint16_t)_mod->SPIreadRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS)); + return((uint16_t)this->mod->SPIreadRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS)); } else { // FSK, the IRQ flags are 16 bits in total - uint16_t flags = ((uint16_t)_mod->SPIreadRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS_2)) << 8; - flags |= (uint16_t)_mod->SPIreadRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS_1); + uint16_t flags = ((uint16_t)this->mod->SPIreadRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS_2)) << 8; + flags |= (uint16_t)this->mod->SPIreadRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS_1); return(flags); } @@ -1264,15 +1264,15 @@ uint8_t SX127x::getModemStatus() { } // read the register - return(_mod->SPIreadRegister(RADIOLIB_SX127X_REG_MODEM_STAT)); + return(this->mod->SPIreadRegister(RADIOLIB_SX127X_REG_MODEM_STAT)); } void SX127x::setRfSwitchPins(uint32_t rxEn, uint32_t txEn) { - _mod->setRfSwitchPins(rxEn, txEn); + this->mod->setRfSwitchPins(rxEn, txEn); } void SX127x::setRfSwitchTable(const uint32_t (&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[]) { - _mod->setRfSwitchTable(pins, table); + this->mod->setRfSwitchTable(pins, table); } uint8_t SX127x::randomByte() { @@ -1286,12 +1286,12 @@ uint8_t SX127x::randomByte() { setMode(RADIOLIB_SX127X_RX); // wait a bit for the RSSI reading to stabilise - _mod->hal->delay(10); + this->mod->hal->delay(10); // read RSSI value 8 times, always keep just the least significant bit uint8_t randByte = 0x00; for(uint8_t i = 0; i < 8; i++) { - randByte |= ((_mod->SPIreadRegister(rssiValueReg) & 0x01) << i); + randByte |= ((this->mod->SPIreadRegister(rssiValueReg) & 0x01) << i); } // set mode to standby @@ -1301,7 +1301,7 @@ uint8_t SX127x::randomByte() { } int16_t SX127x::getChipVersion() { - return(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_VERSION)); + return(this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_VERSION)); } int8_t SX127x::getTempRaw() { @@ -1310,33 +1310,33 @@ int8_t SX127x::getTempRaw() { uint8_t ival; // save current Op Mode - previousOpMode = _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_OP_MODE); + previousOpMode = this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_OP_MODE); // check if we need to step out of LoRa mode first if((previousOpMode & RADIOLIB_SX127X_LORA) == RADIOLIB_SX127X_LORA) { - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, (RADIOLIB_SX127X_LORA | RADIOLIB_SX127X_SLEEP)); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, (RADIOLIB_SX127X_LORA | RADIOLIB_SX127X_SLEEP)); } // put device in FSK sleep - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, (RADIOLIB_SX127X_FSK_OOK | RADIOLIB_SX127X_SLEEP)); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, (RADIOLIB_SX127X_FSK_OOK | RADIOLIB_SX127X_SLEEP)); // put device in FSK RxSynth - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, (RADIOLIB_SX127X_FSK_OOK | RADIOLIB_SX127X_FSRX)); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, (RADIOLIB_SX127X_FSK_OOK | RADIOLIB_SX127X_FSRX)); // enable temperature reading - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_IMAGE_CAL, RADIOLIB_SX127X_TEMP_MONITOR_ON, 0, 0); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_IMAGE_CAL, RADIOLIB_SX127X_TEMP_MONITOR_ON, 0, 0); // wait - _mod->hal->delayMicroseconds(200); + this->mod->hal->delayMicroseconds(200); // disable temperature reading - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_IMAGE_CAL, RADIOLIB_SX127X_TEMP_MONITOR_OFF, 0, 0); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_IMAGE_CAL, RADIOLIB_SX127X_TEMP_MONITOR_OFF, 0, 0); // put device in FSK sleep - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, (RADIOLIB_SX127X_FSK_OOK | RADIOLIB_SX127X_SLEEP)); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, (RADIOLIB_SX127X_FSK_OOK | RADIOLIB_SX127X_SLEEP)); // read temperature - ival = _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_TEMP); + ival = this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_TEMP); // convert very raw value if((ival & 0x80) == 0x80) { @@ -1347,51 +1347,51 @@ int8_t SX127x::getTempRaw() { // check if we need to step back into LoRa mode if((previousOpMode & RADIOLIB_SX127X_LORA) == RADIOLIB_SX127X_LORA) { - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, (RADIOLIB_SX127X_LORA | RADIOLIB_SX127X_SLEEP)); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, (RADIOLIB_SX127X_LORA | RADIOLIB_SX127X_SLEEP)); } // reload previous Op Mode - _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, previousOpMode); + this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, previousOpMode); return(temp); } int16_t SX127x::config() { // turn off frequency hopping - int16_t state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD, RADIOLIB_SX127X_HOP_PERIOD_OFF); + int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD, RADIOLIB_SX127X_HOP_PERIOD_OFF); return(state); } int16_t SX127x::configFSK() { // set RSSI threshold - int16_t state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RSSI_THRESH, RADIOLIB_SX127X_RSSI_THRESHOLD); + int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RSSI_THRESH, RADIOLIB_SX127X_RSSI_THRESHOLD); RADIOLIB_ASSERT(state); // reset FIFO flag - _mod->SPIwriteRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS_2, RADIOLIB_SX127X_FLAG_FIFO_OVERRUN); + this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS_2, RADIOLIB_SX127X_FLAG_FIFO_OVERRUN); // set packet configuration - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_PACKET_VARIABLE | RADIOLIB_SX127X_DC_FREE_NONE | RADIOLIB_SX127X_CRC_ON | RADIOLIB_SX127X_CRC_AUTOCLEAR_ON | RADIOLIB_SX127X_ADDRESS_FILTERING_OFF | RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT, 7, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_2, RADIOLIB_SX127X_DATA_MODE_PACKET | RADIOLIB_SX127X_IO_HOME_OFF, 6, 5); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_PACKET_VARIABLE | RADIOLIB_SX127X_DC_FREE_NONE | RADIOLIB_SX127X_CRC_ON | RADIOLIB_SX127X_CRC_AUTOCLEAR_ON | RADIOLIB_SX127X_ADDRESS_FILTERING_OFF | RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT, 7, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_2, RADIOLIB_SX127X_DATA_MODE_PACKET | RADIOLIB_SX127X_IO_HOME_OFF, 6, 5); RADIOLIB_ASSERT(state); // set preamble polarity - state =_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, RADIOLIB_SX127X_PREAMBLE_POLARITY_55, 5, 5); + state =this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, RADIOLIB_SX127X_PREAMBLE_POLARITY_55, 5, 5); RADIOLIB_ASSERT(state); // set FIFO threshold - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_THRESH, RADIOLIB_SX127X_TX_START_FIFO_NOT_EMPTY, 7, 7); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_THRESH, RADIOLIB_SX127X_FIFO_THRESH, 5, 0); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_THRESH, RADIOLIB_SX127X_TX_START_FIFO_NOT_EMPTY, 7, 7); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_THRESH, RADIOLIB_SX127X_FIFO_THRESH, 5, 0); RADIOLIB_ASSERT(state); // disable Rx timeouts - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_TIMEOUT_1, RADIOLIB_SX127X_TIMEOUT_RX_RSSI_OFF); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_TIMEOUT_2, RADIOLIB_SX127X_TIMEOUT_RX_PREAMBLE_OFF); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_TIMEOUT_3, RADIOLIB_SX127X_TIMEOUT_SIGNAL_SYNC_OFF); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_TIMEOUT_1, RADIOLIB_SX127X_TIMEOUT_RX_RSSI_OFF); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_TIMEOUT_2, RADIOLIB_SX127X_TIMEOUT_RX_PREAMBLE_OFF); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_TIMEOUT_3, RADIOLIB_SX127X_TIMEOUT_SIGNAL_SYNC_OFF); RADIOLIB_ASSERT(state); // enable preamble detector - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_DETECT, RADIOLIB_SX127X_PREAMBLE_DETECTOR_ON | RADIOLIB_SX127X_PREAMBLE_DETECTOR_2_BYTE | RADIOLIB_SX127X_PREAMBLE_DETECTOR_TOL); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_DETECT, RADIOLIB_SX127X_PREAMBLE_DETECTOR_ON | RADIOLIB_SX127X_PREAMBLE_DETECTOR_2_BYTE | RADIOLIB_SX127X_PREAMBLE_DETECTOR_TOL); return(state); } @@ -1408,15 +1408,15 @@ int16_t SX127x::setPacketMode(uint8_t mode, uint8_t len) { } // set to fixed packet length - int16_t state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, mode, 7, 7); + int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, mode, 7, 7); RADIOLIB_ASSERT(state); // set length to register - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH_FSK, len); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH_FSK, len); RADIOLIB_ASSERT(state); // update cached value - _packetLengthConfig = mode; + this->packetLengthConfig = mode; return(state); } @@ -1433,7 +1433,7 @@ bool SX127x::findChip(uint8_t 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); - _mod->hal->delay(10); + this->mod->hal->delay(10); i++; } } @@ -1447,11 +1447,11 @@ int16_t SX127x::setMode(uint8_t mode) { // disable checking of RX bit in FSK RX mode, as it sometimes seem to fail (#276) checkMask = 0xFE; } - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, mode, 2, 0, 5, checkMask)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, mode, 2, 0, 5, checkMask)); } int16_t SX127x::getActiveModem() { - return(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_OP_MODE, 7, 7)); + return(this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_OP_MODE, 7, 7)); } int16_t SX127x::setActiveModem(uint8_t modem) { @@ -1459,7 +1459,7 @@ int16_t SX127x::setActiveModem(uint8_t modem) { int16_t state = setMode(RADIOLIB_SX127X_SLEEP); // set modem - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, modem, 7, 7, 5); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, modem, 7, 7, 5); // set mode to STANDBY state |= setMode(RADIOLIB_SX127X_STANDBY); @@ -1469,16 +1469,16 @@ int16_t SX127x::setActiveModem(uint8_t modem) { void SX127x::clearIRQFlags() { int16_t modem = getActiveModem(); if(modem == RADIOLIB_SX127X_LORA) { - _mod->SPIwriteRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS, 0b11111111); + this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS, 0b11111111); } else if(modem == RADIOLIB_SX127X_FSK_OOK) { - _mod->SPIwriteRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS_1, 0b11111111); - _mod->SPIwriteRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS_2, 0b11111111); + this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS_1, 0b11111111); + this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS_2, 0b11111111); } } void SX127x::clearFIFO(size_t count) { while(count) { - _mod->SPIreadRegister(RADIOLIB_SX127X_REG_FIFO); + this->mod->SPIreadRegister(RADIOLIB_SX127X_REG_FIFO); count--; } } @@ -1491,13 +1491,13 @@ int16_t SX127x::invertIQ(bool invertIQ) { int16_t state; if(invertIQ) { - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_INVERT_IQ, RADIOLIB_SX127X_INVERT_IQ_RXPATH_ON, 6, 6); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_INVERT_IQ, RADIOLIB_SX127X_INVERT_IQ_TXPATH_ON, 0, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_INVERT_IQ2, RADIOLIB_SX127X_IQ2_ENABLE); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_INVERT_IQ, RADIOLIB_SX127X_INVERT_IQ_RXPATH_ON, 6, 6); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_INVERT_IQ, RADIOLIB_SX127X_INVERT_IQ_TXPATH_ON, 0, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_INVERT_IQ2, RADIOLIB_SX127X_IQ2_ENABLE); } else { - state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_INVERT_IQ, RADIOLIB_SX127X_INVERT_IQ_RXPATH_OFF, 6, 6); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_INVERT_IQ, RADIOLIB_SX127X_INVERT_IQ_TXPATH_OFF, 0, 0); - state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_INVERT_IQ2, RADIOLIB_SX127X_IQ2_DISABLE); + state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_INVERT_IQ, RADIOLIB_SX127X_INVERT_IQ_RXPATH_OFF, 6, 6); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_INVERT_IQ, RADIOLIB_SX127X_INVERT_IQ_TXPATH_OFF, 0, 0); + state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_INVERT_IQ2, RADIOLIB_SX127X_IQ2_DISABLE); } return(state); @@ -1505,30 +1505,30 @@ int16_t SX127x::invertIQ(bool invertIQ) { #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE) void SX127x::setDirectAction(void (*func)(void)) { - setDio1Action(func, _mod->hal->GpioInterruptRising); + setDio1Action(func, this->mod->hal->GpioInterruptRising); } void SX127x::readBit(uint32_t pin) { - updateDirectBuffer((uint8_t)_mod->hal->digitalRead(pin)); + updateDirectBuffer((uint8_t)this->mod->hal->digitalRead(pin)); } #endif int16_t SX127x::setFHSSHoppingPeriod(uint8_t freqHoppingPeriod) { - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD, freqHoppingPeriod)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD, freqHoppingPeriod)); } uint8_t SX127x::getFHSSHoppingPeriod(void) { - return(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD)); + return(this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD)); } uint8_t SX127x::getFHSSChannel(void) { - return(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_CHANNEL, 5, 0)); + return(this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_CHANNEL, 5, 0)); } void SX127x::clearFHSSInt(void) { int16_t modem = getActiveModem(); if(modem == RADIOLIB_SX127X_LORA) { - _mod->SPIwriteRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS, getIRQFlags() | RADIOLIB_SX127X_CLEAR_IRQ_FLAG_FHSS_CHANGE_CHANNEL); + this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS, getIRQFlags() | RADIOLIB_SX127X_CLEAR_IRQ_FLAG_FHSS_CHANGE_CHANNEL); } else if(modem == RADIOLIB_SX127X_FSK_OOK) { return; //These are not the interrupts you are looking for } @@ -1539,20 +1539,20 @@ int16_t SX127x::setDIOMapping(uint32_t pin, uint32_t value) { return RADIOLIB_ERR_INVALID_DIO_PIN; if (pin < 4) - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, value, 7 - 2 * pin, 6 - 2 * pin)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, value, 7 - 2 * pin, 6 - 2 * pin)); else - return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_2, value, 15 - 2 * pin, 14 - 2 * pin)); + return(this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_2, value, 15 - 2 * pin, 14 - 2 * pin)); } int16_t SX127x::setDIOPreambleDetect(bool usePreambleDetect) { - return _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_2, (usePreambleDetect) ? RADIOLIB_SX127X_DIO_MAP_PREAMBLE_DETECT : RADIOLIB_SX127X_DIO_MAP_RSSI, 0, 0); + return this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_2, (usePreambleDetect) ? RADIOLIB_SX127X_DIO_MAP_PREAMBLE_DETECT : RADIOLIB_SX127X_DIO_MAP_RSSI, 0, 0); } float SX127x::getRSSI(bool packet, bool skipReceive, int16_t offset) { if(getActiveModem() == RADIOLIB_SX127X_LORA) { if(packet) { // LoRa packet mode, get RSSI of the last packet - float lastPacketRSSI = offset + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PKT_RSSI_VALUE); + float lastPacketRSSI = offset + this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PKT_RSSI_VALUE); // spread-spectrum modulation signal can be received below noise floor // check last packet SNR and if it's less than 0, add it to reported RSSI to get the correct value @@ -1564,7 +1564,7 @@ float SX127x::getRSSI(bool packet, bool skipReceive, int16_t offset) { } else { // LoRa instant, get current RSSI - float currentRSSI = offset + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE); + float currentRSSI = offset + this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE); return(currentRSSI); } @@ -1577,7 +1577,7 @@ float SX127x::getRSSI(bool packet, bool skipReceive, int16_t offset) { } // read the value for FSK - float rssi = (float)_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE_FSK) / -2.0; + float rssi = (float)this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE_FSK) / -2.0; // set mode back to standby if(!skipReceive) { diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 112e7d43..ebc0fb19 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -10,573 +10,572 @@ #include "../../protocols/PhysicalLayer/PhysicalLayer.h" // SX127x physical layer properties -#define RADIOLIB_SX127X_FREQUENCY_STEP_SIZE 61.03515625 -#define RADIOLIB_SX127X_MAX_PACKET_LENGTH 255 -#define RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK 64 -#define RADIOLIB_SX127X_CRYSTAL_FREQ 32.0 -#define RADIOLIB_SX127X_DIV_EXPONENT 19 +#define RADIOLIB_SX127X_FREQUENCY_STEP_SIZE 61.03515625 +#define RADIOLIB_SX127X_MAX_PACKET_LENGTH 255 +#define RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK 64 +#define RADIOLIB_SX127X_CRYSTAL_FREQ 32.0 +#define RADIOLIB_SX127X_DIV_EXPONENT 19 // SX127x series common LoRa registers -#define RADIOLIB_SX127X_REG_FIFO 0x00 -#define RADIOLIB_SX127X_REG_OP_MODE 0x01 -#define RADIOLIB_SX127X_REG_FRF_MSB 0x06 -#define RADIOLIB_SX127X_REG_FRF_MID 0x07 -#define RADIOLIB_SX127X_REG_FRF_LSB 0x08 -#define RADIOLIB_SX127X_REG_PA_CONFIG 0x09 -#define RADIOLIB_SX127X_REG_PA_RAMP 0x0A -#define RADIOLIB_SX127X_REG_OCP 0x0B -#define RADIOLIB_SX127X_REG_LNA 0x0C -#define RADIOLIB_SX127X_REG_FIFO_ADDR_PTR 0x0D -#define RADIOLIB_SX127X_REG_FIFO_TX_BASE_ADDR 0x0E -#define RADIOLIB_SX127X_REG_FIFO_RX_BASE_ADDR 0x0F -#define RADIOLIB_SX127X_REG_FIFO_RX_CURRENT_ADDR 0x10 -#define RADIOLIB_SX127X_REG_IRQ_FLAGS_MASK 0x11 -#define RADIOLIB_SX127X_REG_IRQ_FLAGS 0x12 -#define RADIOLIB_SX127X_REG_RX_NB_BYTES 0x13 -#define RADIOLIB_SX127X_REG_RX_HEADER_CNT_VALUE_MSB 0x14 -#define RADIOLIB_SX127X_REG_RX_HEADER_CNT_VALUE_LSB 0x15 -#define RADIOLIB_SX127X_REG_RX_PACKET_CNT_VALUE_MSB 0x16 -#define RADIOLIB_SX127X_REG_RX_PACKET_CNT_VALUE_LSB 0x17 -#define RADIOLIB_SX127X_REG_MODEM_STAT 0x18 -#define RADIOLIB_SX127X_REG_PKT_SNR_VALUE 0x19 -#define RADIOLIB_SX127X_REG_PKT_RSSI_VALUE 0x1A -#define RADIOLIB_SX127X_REG_RSSI_VALUE 0x1B -#define RADIOLIB_SX127X_REG_HOP_CHANNEL 0x1C -#define RADIOLIB_SX127X_REG_MODEM_CONFIG_1 0x1D -#define RADIOLIB_SX127X_REG_MODEM_CONFIG_2 0x1E -#define RADIOLIB_SX127X_REG_SYMB_TIMEOUT_LSB 0x1F -#define RADIOLIB_SX127X_REG_PREAMBLE_MSB 0x20 -#define RADIOLIB_SX127X_REG_PREAMBLE_LSB 0x21 -#define RADIOLIB_SX127X_REG_PAYLOAD_LENGTH 0x22 -#define RADIOLIB_SX127X_REG_MAX_PAYLOAD_LENGTH 0x23 -#define RADIOLIB_SX127X_REG_HOP_PERIOD 0x24 -#define RADIOLIB_SX127X_REG_FIFO_RX_BYTE_ADDR 0x25 -#define RADIOLIB_SX127X_REG_FEI_MSB 0x28 -#define RADIOLIB_SX127X_REG_FEI_MID 0x29 -#define RADIOLIB_SX127X_REG_FEI_LSB 0x2A -#define RADIOLIB_SX127X_REG_RSSI_WIDEBAND 0x2C -#define RADIOLIB_SX127X_REG_DETECT_OPTIMIZE 0x31 -#define RADIOLIB_SX127X_REG_INVERT_IQ 0x33 -#define RADIOLIB_SX127X_REG_DETECTION_THRESHOLD 0x37 -#define RADIOLIB_SX127X_REG_SYNC_WORD 0x39 -#define RADIOLIB_SX127X_REG_INVERT_IQ2 0x3B -#define RADIOLIB_SX127X_REG_DIO_MAPPING_1 0x40 -#define RADIOLIB_SX127X_REG_DIO_MAPPING_2 0x41 -#define RADIOLIB_SX127X_REG_VERSION 0x42 +#define RADIOLIB_SX127X_REG_FIFO 0x00 +#define RADIOLIB_SX127X_REG_OP_MODE 0x01 +#define RADIOLIB_SX127X_REG_FRF_MSB 0x06 +#define RADIOLIB_SX127X_REG_FRF_MID 0x07 +#define RADIOLIB_SX127X_REG_FRF_LSB 0x08 +#define RADIOLIB_SX127X_REG_PA_CONFIG 0x09 +#define RADIOLIB_SX127X_REG_PA_RAMP 0x0A +#define RADIOLIB_SX127X_REG_OCP 0x0B +#define RADIOLIB_SX127X_REG_LNA 0x0C +#define RADIOLIB_SX127X_REG_FIFO_ADDR_PTR 0x0D +#define RADIOLIB_SX127X_REG_FIFO_TX_BASE_ADDR 0x0E +#define RADIOLIB_SX127X_REG_FIFO_RX_BASE_ADDR 0x0F +#define RADIOLIB_SX127X_REG_FIFO_RX_CURRENT_ADDR 0x10 +#define RADIOLIB_SX127X_REG_IRQ_FLAGS_MASK 0x11 +#define RADIOLIB_SX127X_REG_IRQ_FLAGS 0x12 +#define RADIOLIB_SX127X_REG_RX_NB_BYTES 0x13 +#define RADIOLIB_SX127X_REG_RX_HEADER_CNT_VALUE_MSB 0x14 +#define RADIOLIB_SX127X_REG_RX_HEADER_CNT_VALUE_LSB 0x15 +#define RADIOLIB_SX127X_REG_RX_PACKET_CNT_VALUE_MSB 0x16 +#define RADIOLIB_SX127X_REG_RX_PACKET_CNT_VALUE_LSB 0x17 +#define RADIOLIB_SX127X_REG_MODEM_STAT 0x18 +#define RADIOLIB_SX127X_REG_PKT_SNR_VALUE 0x19 +#define RADIOLIB_SX127X_REG_PKT_RSSI_VALUE 0x1A +#define RADIOLIB_SX127X_REG_RSSI_VALUE 0x1B +#define RADIOLIB_SX127X_REG_HOP_CHANNEL 0x1C +#define RADIOLIB_SX127X_REG_MODEM_CONFIG_1 0x1D +#define RADIOLIB_SX127X_REG_MODEM_CONFIG_2 0x1E +#define RADIOLIB_SX127X_REG_SYMB_TIMEOUT_LSB 0x1F +#define RADIOLIB_SX127X_REG_PREAMBLE_MSB 0x20 +#define RADIOLIB_SX127X_REG_PREAMBLE_LSB 0x21 +#define RADIOLIB_SX127X_REG_PAYLOAD_LENGTH 0x22 +#define RADIOLIB_SX127X_REG_MAX_PAYLOAD_LENGTH 0x23 +#define RADIOLIB_SX127X_REG_HOP_PERIOD 0x24 +#define RADIOLIB_SX127X_REG_FIFO_RX_BYTE_ADDR 0x25 +#define RADIOLIB_SX127X_REG_FEI_MSB 0x28 +#define RADIOLIB_SX127X_REG_FEI_MID 0x29 +#define RADIOLIB_SX127X_REG_FEI_LSB 0x2A +#define RADIOLIB_SX127X_REG_RSSI_WIDEBAND 0x2C +#define RADIOLIB_SX127X_REG_DETECT_OPTIMIZE 0x31 +#define RADIOLIB_SX127X_REG_INVERT_IQ 0x33 +#define RADIOLIB_SX127X_REG_DETECTION_THRESHOLD 0x37 +#define RADIOLIB_SX127X_REG_SYNC_WORD 0x39 +#define RADIOLIB_SX127X_REG_INVERT_IQ2 0x3B +#define RADIOLIB_SX127X_REG_DIO_MAPPING_1 0x40 +#define RADIOLIB_SX127X_REG_DIO_MAPPING_2 0x41 +#define RADIOLIB_SX127X_REG_VERSION 0x42 // SX127x common LoRa modem settings -// SX127X_REG_OP_MODE MSB LSB DESCRIPTION -#define RADIOLIB_SX127X_FSK_OOK 0b00000000 // 7 7 FSK/OOK mode -#define RADIOLIB_SX127X_LORA 0b10000000 // 7 7 LoRa mode -#define RADIOLIB_SX127X_ACCESS_SHARED_REG_OFF 0b00000000 // 6 6 access LoRa registers (0x0D:0x3F) in LoRa mode -#define RADIOLIB_SX127X_ACCESS_SHARED_REG_ON 0b01000000 // 6 6 access FSK registers (0x0D:0x3F) in LoRa mode -#define RADIOLIB_SX127X_SLEEP 0b00000000 // 2 0 sleep -#define RADIOLIB_SX127X_STANDBY 0b00000001 // 2 0 standby -#define RADIOLIB_SX127X_FSTX 0b00000010 // 2 0 frequency synthesis TX -#define RADIOLIB_SX127X_TX 0b00000011 // 2 0 transmit -#define RADIOLIB_SX127X_FSRX 0b00000100 // 2 0 frequency synthesis RX -#define RADIOLIB_SX127X_RXCONTINUOUS 0b00000101 // 2 0 receive continuous -#define RADIOLIB_SX127X_RXSINGLE 0b00000110 // 2 0 receive single -#define RADIOLIB_SX127X_CAD 0b00000111 // 2 0 channel activity detection +// RADIOLIB_SX127X_REG_OP_MODE MSB LSB DESCRIPTION +#define RADIOLIB_SX127X_FSK_OOK 0b00000000 // 7 7 FSK/OOK mode +#define RADIOLIB_SX127X_LORA 0b10000000 // 7 7 LoRa mode +#define RADIOLIB_SX127X_ACCESS_SHARED_REG_OFF 0b00000000 // 6 6 access LoRa registers (0x0D:0x3F) in LoRa mode +#define RADIOLIB_SX127X_ACCESS_SHARED_REG_ON 0b01000000 // 6 6 access FSK registers (0x0D:0x3F) in LoRa mode +#define RADIOLIB_SX127X_SLEEP 0b00000000 // 2 0 sleep +#define RADIOLIB_SX127X_STANDBY 0b00000001 // 2 0 standby +#define RADIOLIB_SX127X_FSTX 0b00000010 // 2 0 frequency synthesis TX +#define RADIOLIB_SX127X_TX 0b00000011 // 2 0 transmit +#define RADIOLIB_SX127X_FSRX 0b00000100 // 2 0 frequency synthesis RX +#define RADIOLIB_SX127X_RXCONTINUOUS 0b00000101 // 2 0 receive continuous +#define RADIOLIB_SX127X_RXSINGLE 0b00000110 // 2 0 receive single +#define RADIOLIB_SX127X_CAD 0b00000111 // 2 0 channel activity detection -// SX127X_REG_PA_CONFIG -#define RADIOLIB_SX127X_PA_SELECT_RFO 0b00000000 // 7 7 RFO pin output, power limited to +14 dBm -#define RADIOLIB_SX127X_PA_SELECT_BOOST 0b10000000 // 7 7 PA_BOOST pin output, power limited to +20 dBm -#define RADIOLIB_SX127X_OUTPUT_POWER 0b00001111 // 3 0 output power: P_out = 2 + OUTPUT_POWER [dBm] for PA_SELECT_BOOST - // P_out = -1 + OUTPUT_POWER [dBm] for PA_SELECT_RFO +// RADIOLIB_SX127X_REG_PA_CONFIG +#define RADIOLIB_SX127X_PA_SELECT_RFO 0b00000000 // 7 7 RFO pin output, power limited to +14 dBm +#define RADIOLIB_SX127X_PA_SELECT_BOOST 0b10000000 // 7 7 PA_BOOST pin output, power limited to +20 dBm +#define RADIOLIB_SX127X_OUTPUT_POWER 0b00001111 // 3 0 output power: P_out = 2 + OUTPUT_POWER [dBm] for PA_SELECT_BOOST + // P_out = -1 + OUTPUT_POWER [dBm] for PA_SELECT_RFO -// SX127X_REG_OCP -#define RADIOLIB_SX127X_OCP_OFF 0b00000000 // 5 5 PA overload current protection disabled -#define RADIOLIB_SX127X_OCP_ON 0b00100000 // 5 5 PA overload current protection enabled -#define RADIOLIB_SX127X_OCP_TRIM 0b00001011 // 4 0 OCP current: I_max(OCP_TRIM = 0b1011) = 100 mA +// RADIOLIB_SX127X_REG_OCP +#define RADIOLIB_SX127X_OCP_OFF 0b00000000 // 5 5 PA overload current protection disabled +#define RADIOLIB_SX127X_OCP_ON 0b00100000 // 5 5 PA overload current protection enabled +#define RADIOLIB_SX127X_OCP_TRIM 0b00001011 // 4 0 OCP current: I_max(OCP_TRIM = 0b1011) = 100 mA -// SX127X_REG_LNA -#define RADIOLIB_SX127X_LNA_GAIN_1 0b00100000 // 7 5 LNA gain setting: max gain -#define RADIOLIB_SX127X_LNA_GAIN_2 0b01000000 // 7 5 . -#define RADIOLIB_SX127X_LNA_GAIN_3 0b01100000 // 7 5 . -#define RADIOLIB_SX127X_LNA_GAIN_4 0b10000000 // 7 5 . -#define RADIOLIB_SX127X_LNA_GAIN_5 0b10100000 // 7 5 . -#define RADIOLIB_SX127X_LNA_GAIN_6 0b11000000 // 7 5 min gain -#define RADIOLIB_SX127X_LNA_BOOST_OFF 0b00000000 // 1 0 default LNA current -#define RADIOLIB_SX127X_LNA_BOOST_ON 0b00000011 // 1 0 150% LNA current +// RADIOLIB_SX127X_REG_LNA +#define RADIOLIB_SX127X_LNA_GAIN_1 0b00100000 // 7 5 LNA gain setting: max gain +#define RADIOLIB_SX127X_LNA_GAIN_2 0b01000000 // 7 5 . +#define RADIOLIB_SX127X_LNA_GAIN_3 0b01100000 // 7 5 . +#define RADIOLIB_SX127X_LNA_GAIN_4 0b10000000 // 7 5 . +#define RADIOLIB_SX127X_LNA_GAIN_5 0b10100000 // 7 5 . +#define RADIOLIB_SX127X_LNA_GAIN_6 0b11000000 // 7 5 min gain +#define RADIOLIB_SX127X_LNA_BOOST_OFF 0b00000000 // 1 0 default LNA current +#define RADIOLIB_SX127X_LNA_BOOST_ON 0b00000011 // 1 0 150% LNA current -// SX127X_REG_MODEM_CONFIG_2 -#define RADIOLIB_SX127X_SF_6 0b01100000 // 7 4 spreading factor: 64 chips/bit -#define RADIOLIB_SX127X_SF_7 0b01110000 // 7 4 128 chips/bit -#define RADIOLIB_SX127X_SF_8 0b10000000 // 7 4 256 chips/bit -#define RADIOLIB_SX127X_SF_9 0b10010000 // 7 4 512 chips/bit -#define RADIOLIB_SX127X_SF_10 0b10100000 // 7 4 1024 chips/bit -#define RADIOLIB_SX127X_SF_11 0b10110000 // 7 4 2048 chips/bit -#define RADIOLIB_SX127X_SF_12 0b11000000 // 7 4 4096 chips/bit -#define RADIOLIB_SX127X_TX_MODE_SINGLE 0b00000000 // 3 3 single TX -#define RADIOLIB_SX127X_TX_MODE_CONT 0b00001000 // 3 3 continuous TX -#define RADIOLIB_SX127X_RX_TIMEOUT_MSB 0b00000000 // 1 0 +// RADIOLIB_SX127X_REG_MODEM_CONFIG_2 +#define RADIOLIB_SX127X_SF_6 0b01100000 // 7 4 spreading factor: 64 chips/bit +#define RADIOLIB_SX127X_SF_7 0b01110000 // 7 4 128 chips/bit +#define RADIOLIB_SX127X_SF_8 0b10000000 // 7 4 256 chips/bit +#define RADIOLIB_SX127X_SF_9 0b10010000 // 7 4 512 chips/bit +#define RADIOLIB_SX127X_SF_10 0b10100000 // 7 4 1024 chips/bit +#define RADIOLIB_SX127X_SF_11 0b10110000 // 7 4 2048 chips/bit +#define RADIOLIB_SX127X_SF_12 0b11000000 // 7 4 4096 chips/bit +#define RADIOLIB_SX127X_TX_MODE_SINGLE 0b00000000 // 3 3 single TX +#define RADIOLIB_SX127X_TX_MODE_CONT 0b00001000 // 3 3 continuous TX +#define RADIOLIB_SX127X_RX_TIMEOUT_MSB 0b00000000 // 1 0 -// SX127X_REG_SYMB_TIMEOUT_LSB -#define RADIOLIB_SX127X_RX_TIMEOUT_LSB 0b01100100 // 7 0 10 bit RX operation timeout +// RADIOLIB_SX127X_REG_SYMB_TIMEOUT_LSB +#define RADIOLIB_SX127X_RX_TIMEOUT_LSB 0b01100100 // 7 0 10-bit RX operation timeout -// SX127X_REG_PREAMBLE_MSB + REG_PREAMBLE_LSB -#define RADIOLIB_SX127X_PREAMBLE_LENGTH_MSB 0b00000000 // 7 0 2 byte preamble length setting: l_P = PREAMBLE_LENGTH + 4.25 -#define RADIOLIB_SX127X_PREAMBLE_LENGTH_LSB 0b00001000 // 7 0 where l_p = preamble length +// RADIOLIB_SX127X_REG_PREAMBLE_MSB + REG_PREAMBLE_LSB +#define RADIOLIB_SX127X_PREAMBLE_LENGTH_MSB 0b00000000 // 7 0 2-byte preamble length setting: l_P = PREAMBLE_LENGTH + 4.25 +#define RADIOLIB_SX127X_PREAMBLE_LENGTH_LSB 0b00001000 // 7 0 where l_p = preamble length -// SX127X_REG_DETECT_OPTIMIZE -#define RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6 0b00000101 // 2 0 SF6 detection optimization -#define RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12 0b00000011 // 2 0 SF7 to SF12 detection optimization +// RADIOLIB_SX127X_REG_DETECT_OPTIMIZE +#define RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6 0b00000101 // 2 0 SF6 detection optimization +#define RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12 0b00000011 // 2 0 SF7 to SF12 detection optimization -// SX127X_REG_INVERT_IQ -#define RADIOLIB_SX127X_INVERT_IQ_RXPATH_ON 0b01000000 // 6 6 I and Q signals are inverted -#define RADIOLIB_SX127X_INVERT_IQ_RXPATH_OFF 0b00000000 // 6 6 normal mode -#define RADIOLIB_SX127X_INVERT_IQ_TXPATH_ON 0b00000001 // 0 0 I and Q signals are inverted -#define RADIOLIB_SX127X_INVERT_IQ_TXPATH_OFF 0b00000000 // 0 0 normal mode +// RADIOLIB_SX127X_REG_INVERT_IQ +#define RADIOLIB_SX127X_INVERT_IQ_RXPATH_ON 0b01000000 // 6 6 I and Q signals are inverted +#define RADIOLIB_SX127X_INVERT_IQ_RXPATH_OFF 0b00000000 // 6 6 normal mode +#define RADIOLIB_SX127X_INVERT_IQ_TXPATH_ON 0b00000001 // 0 0 I and Q signals are inverted +#define RADIOLIB_SX127X_INVERT_IQ_TXPATH_OFF 0b00000000 // 0 0 normal mode -// SX127X_REG_DETECTION_THRESHOLD -#define RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6 0b00001100 // 7 0 SF6 detection threshold -#define RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12 0b00001010 // 7 0 SF7 to SF12 detection threshold +// RADIOLIB_SX127X_REG_DETECTION_THRESHOLD +#define RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6 0b00001100 // 7 0 SF6 detection threshold +#define RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12 0b00001010 // 7 0 SF7 to SF12 detection threshold -// SX127X_REG_PA_DAC -#define RADIOLIB_SX127X_PA_BOOST_OFF 0b00000100 // 2 0 PA_BOOST disabled -#define RADIOLIB_SX127X_PA_BOOST_ON 0b00000111 // 2 0 +20 dBm on PA_BOOST when OUTPUT_POWER = 0b1111 +// RADIOLIB_SX127X_REG_PA_DAC +#define RADIOLIB_SX127X_PA_BOOST_OFF 0b00000100 // 2 0 PA_BOOST disabled +#define RADIOLIB_SX127X_PA_BOOST_ON 0b00000111 // 2 0 +20 dBm on PA_BOOST when OUTPUT_POWER = 0b1111 -// SX127X_REG_HOP_PERIOD -#define RADIOLIB_SX127X_HOP_PERIOD_OFF 0b00000000 // 7 0 number of periods between frequency hops; 0 = disabled -#define RADIOLIB_SX127X_HOP_PERIOD_MAX 0b11111111 // 7 0 +// RADIOLIB_SX127X_REG_HOP_PERIOD +#define RADIOLIB_SX127X_HOP_PERIOD_OFF 0b00000000 // 7 0 number of periods between frequency hops; 0 = disabled +#define RADIOLIB_SX127X_HOP_PERIOD_MAX 0b11111111 // 7 0 -// SX127X_REG_IRQ_FLAGS -#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_RX_TIMEOUT 0b10000000 // 7 7 timeout -#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_RX_DONE 0b01000000 // 6 6 packet reception complete -#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_PAYLOAD_CRC_ERROR 0b00100000 // 5 5 payload CRC error -#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_VALID_HEADER 0b00010000 // 4 4 valid header received -#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_TX_DONE 0b00001000 // 3 3 payload transmission complete -#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_CAD_DONE 0b00000100 // 2 2 CAD complete -#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_FHSS_CHANGE_CHANNEL 0b00000010 // 1 1 FHSS change channel -#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_CAD_DETECTED 0b00000001 // 0 0 valid LoRa signal detected during CAD operation +// RADIOLIB_SX127X_REG_IRQ_FLAGS +#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_RX_TIMEOUT 0b10000000 // 7 7 timeout +#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_RX_DONE 0b01000000 // 6 6 packet reception complete +#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_PAYLOAD_CRC_ERROR 0b00100000 // 5 5 payload CRC error +#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_VALID_HEADER 0b00010000 // 4 4 valid header received +#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_TX_DONE 0b00001000 // 3 3 payload transmission complete +#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_CAD_DONE 0b00000100 // 2 2 CAD complete +#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_FHSS_CHANGE_CHANNEL 0b00000010 // 1 1 FHSS change channel +#define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_CAD_DETECTED 0b00000001 // 0 0 valid LoRa signal detected during CAD operation -// SX127X_REG_IRQ_FLAGS_MASK -#define RADIOLIB_SX127X_MASK_IRQ_FLAG_RX_TIMEOUT 0b01111111 // 7 7 timeout -#define RADIOLIB_SX127X_MASK_IRQ_FLAG_RX_DONE 0b10111111 // 6 6 packet reception complete -#define RADIOLIB_SX127X_MASK_IRQ_FLAG_PAYLOAD_CRC_ERROR 0b11011111 // 5 5 payload CRC error -#define RADIOLIB_SX127X_MASK_IRQ_FLAG_VALID_HEADER 0b11101111 // 4 4 valid header received -#define RADIOLIB_SX127X_MASK_IRQ_FLAG_TX_DONE 0b11110111 // 3 3 payload transmission complete -#define RADIOLIB_SX127X_MASK_IRQ_FLAG_CAD_DONE 0b11111011 // 2 2 CAD complete -#define RADIOLIB_SX127X_MASK_IRQ_FLAG_FHSS_CHANGE_CHANNEL 0b11111101 // 1 1 FHSS change channel -#define RADIOLIB_SX127X_MASK_IRQ_FLAG_CAD_DETECTED 0b11111110 // 0 0 valid LoRa signal detected during CAD operation +// RADIOLIB_SX127X_REG_IRQ_FLAGS_MASK +#define RADIOLIB_SX127X_MASK_IRQ_FLAG_RX_TIMEOUT 0b01111111 // 7 7 timeout +#define RADIOLIB_SX127X_MASK_IRQ_FLAG_RX_DONE 0b10111111 // 6 6 packet reception complete +#define RADIOLIB_SX127X_MASK_IRQ_FLAG_PAYLOAD_CRC_ERROR 0b11011111 // 5 5 payload CRC error +#define RADIOLIB_SX127X_MASK_IRQ_FLAG_VALID_HEADER 0b11101111 // 4 4 valid header received +#define RADIOLIB_SX127X_MASK_IRQ_FLAG_TX_DONE 0b11110111 // 3 3 payload transmission complete +#define RADIOLIB_SX127X_MASK_IRQ_FLAG_CAD_DONE 0b11111011 // 2 2 CAD complete +#define RADIOLIB_SX127X_MASK_IRQ_FLAG_FHSS_CHANGE_CHANNEL 0b11111101 // 1 1 FHSS change channel +#define RADIOLIB_SX127X_MASK_IRQ_FLAG_CAD_DETECTED 0b11111110 // 0 0 valid LoRa signal detected during CAD operation -// SX127X_REG_FIFO_TX_BASE_ADDR -#define RADIOLIB_SX127X_FIFO_TX_BASE_ADDR_MAX 0b00000000 // 7 0 allocate the entire FIFO buffer for TX only +// RADIOLIB_SX127X_REG_FIFO_TX_BASE_ADDR +#define RADIOLIB_SX127X_FIFO_TX_BASE_ADDR_MAX 0b00000000 // 7 0 allocate the entire FIFO buffer for TX only -// SX127X_REG_FIFO_RX_BASE_ADDR -#define RADIOLIB_SX127X_FIFO_RX_BASE_ADDR_MAX 0b00000000 // 7 0 allocate the entire FIFO buffer for RX only +// RADIOLIB_SX127X_REG_FIFO_RX_BASE_ADDR +#define RADIOLIB_SX127X_FIFO_RX_BASE_ADDR_MAX 0b00000000 // 7 0 allocate the entire FIFO buffer for RX only -// SX127X_REG_SYNC_WORD -#define RADIOLIB_SX127X_SYNC_WORD 0x12 // 7 0 default LoRa sync word -#define RADIOLIB_SX127X_SYNC_WORD_LORAWAN 0x34 // 7 0 sync word reserved for LoRaWAN networks +// RADIOLIB_SX127X_REG_SYNC_WORD +#define RADIOLIB_SX127X_SYNC_WORD 0x12 // 7 0 default LoRa sync word +#define RADIOLIB_SX127X_SYNC_WORD_LORAWAN 0x34 // 7 0 sync word reserved for LoRaWAN networks -// SX127X_REG_INVERT_IQ2 -#define RADIOLIB_SX127X_IQ2_ENABLE 0x19 // 7 0 enable optimize for inverted IQ -#define RADIOLIB_SX127X_IQ2_DISABLE 0x1D // 7 0 reset optimize for inverted IQ +// RADIOLIB_SX127X_REG_INVERT_IQ2 +#define RADIOLIB_SX127X_IQ2_ENABLE 0x19 // 7 0 enable optimize for inverted IQ +#define RADIOLIB_SX127X_IQ2_DISABLE 0x1D // 7 0 reset optimize for inverted IQ // SX127x series common FSK registers // NOTE: FSK register names that are conflicting with LoRa registers are marked with "_FSK" suffix -#define RADIOLIB_SX127X_REG_BITRATE_MSB 0x02 -#define RADIOLIB_SX127X_REG_BITRATE_LSB 0x03 -#define RADIOLIB_SX127X_REG_FDEV_MSB 0x04 -#define RADIOLIB_SX127X_REG_FDEV_LSB 0x05 -#define RADIOLIB_SX127X_REG_RX_CONFIG 0x0D -#define RADIOLIB_SX127X_REG_RSSI_CONFIG 0x0E -#define RADIOLIB_SX127X_REG_RSSI_COLLISION 0x0F -#define RADIOLIB_SX127X_REG_RSSI_THRESH 0x10 -#define RADIOLIB_SX127X_REG_RSSI_VALUE_FSK 0x11 -#define RADIOLIB_SX127X_REG_RX_BW 0x12 -#define RADIOLIB_SX127X_REG_AFC_BW 0x13 -#define RADIOLIB_SX127X_REG_OOK_PEAK 0x14 -#define RADIOLIB_SX127X_REG_OOK_FIX 0x15 -#define RADIOLIB_SX127X_REG_OOK_AVG 0x16 -#define RADIOLIB_SX127X_REG_AFC_FEI 0x1A -#define RADIOLIB_SX127X_REG_AFC_MSB 0x1B -#define RADIOLIB_SX127X_REG_AFC_LSB 0x1C -#define RADIOLIB_SX127X_REG_FEI_MSB_FSK 0x1D -#define RADIOLIB_SX127X_REG_FEI_LSB_FSK 0x1E -#define RADIOLIB_SX127X_REG_PREAMBLE_DETECT 0x1F -#define RADIOLIB_SX127X_REG_RX_TIMEOUT_1 0x20 -#define RADIOLIB_SX127X_REG_RX_TIMEOUT_2 0x21 -#define RADIOLIB_SX127X_REG_RX_TIMEOUT_3 0x22 -#define RADIOLIB_SX127X_REG_RX_DELAY 0x23 -#define RADIOLIB_SX127X_REG_OSC 0x24 -#define RADIOLIB_SX127X_REG_PREAMBLE_MSB_FSK 0x25 -#define RADIOLIB_SX127X_REG_PREAMBLE_LSB_FSK 0x26 -#define RADIOLIB_SX127X_REG_SYNC_CONFIG 0x27 -#define RADIOLIB_SX127X_REG_SYNC_VALUE_1 0x28 -#define RADIOLIB_SX127X_REG_SYNC_VALUE_2 0x29 -#define RADIOLIB_SX127X_REG_SYNC_VALUE_3 0x2A -#define RADIOLIB_SX127X_REG_SYNC_VALUE_4 0x2B -#define RADIOLIB_SX127X_REG_SYNC_VALUE_5 0x2C -#define RADIOLIB_SX127X_REG_SYNC_VALUE_6 0x2D -#define RADIOLIB_SX127X_REG_SYNC_VALUE_7 0x2E -#define RADIOLIB_SX127X_REG_SYNC_VALUE_8 0x2F -#define RADIOLIB_SX127X_REG_PACKET_CONFIG_1 0x30 -#define RADIOLIB_SX127X_REG_PACKET_CONFIG_2 0x31 -#define RADIOLIB_SX127X_REG_PAYLOAD_LENGTH_FSK 0x32 -#define RADIOLIB_SX127X_REG_NODE_ADRS 0x33 -#define RADIOLIB_SX127X_REG_BROADCAST_ADRS 0x34 -#define RADIOLIB_SX127X_REG_FIFO_THRESH 0x35 -#define RADIOLIB_SX127X_REG_SEQ_CONFIG_1 0x36 -#define RADIOLIB_SX127X_REG_SEQ_CONFIG_2 0x37 -#define RADIOLIB_SX127X_REG_TIMER_RESOL 0x38 -#define RADIOLIB_SX127X_REG_TIMER1_COEF 0x39 -#define RADIOLIB_SX127X_REG_TIMER2_COEF 0x3A -#define RADIOLIB_SX127X_REG_IMAGE_CAL 0x3B -#define RADIOLIB_SX127X_REG_TEMP 0x3C -#define RADIOLIB_SX127X_REG_LOW_BAT 0x3D -#define RADIOLIB_SX127X_REG_IRQ_FLAGS_1 0x3E -#define RADIOLIB_SX127X_REG_IRQ_FLAGS_2 0x3F +#define RADIOLIB_SX127X_REG_BITRATE_MSB 0x02 +#define RADIOLIB_SX127X_REG_BITRATE_LSB 0x03 +#define RADIOLIB_SX127X_REG_FDEV_MSB 0x04 +#define RADIOLIB_SX127X_REG_FDEV_LSB 0x05 +#define RADIOLIB_SX127X_REG_RX_CONFIG 0x0D +#define RADIOLIB_SX127X_REG_RSSI_CONFIG 0x0E +#define RADIOLIB_SX127X_REG_RSSI_COLLISION 0x0F +#define RADIOLIB_SX127X_REG_RSSI_THRESH 0x10 +#define RADIOLIB_SX127X_REG_RSSI_VALUE_FSK 0x11 +#define RADIOLIB_SX127X_REG_RX_BW 0x12 +#define RADIOLIB_SX127X_REG_AFC_BW 0x13 +#define RADIOLIB_SX127X_REG_OOK_PEAK 0x14 +#define RADIOLIB_SX127X_REG_OOK_FIX 0x15 +#define RADIOLIB_SX127X_REG_OOK_AVG 0x16 +#define RADIOLIB_SX127X_REG_AFC_FEI 0x1A +#define RADIOLIB_SX127X_REG_AFC_MSB 0x1B +#define RADIOLIB_SX127X_REG_AFC_LSB 0x1C +#define RADIOLIB_SX127X_REG_FEI_MSB_FSK 0x1D +#define RADIOLIB_SX127X_REG_FEI_LSB_FSK 0x1E +#define RADIOLIB_SX127X_REG_PREAMBLE_DETECT 0x1F +#define RADIOLIB_SX127X_REG_RX_TIMEOUT_1 0x20 +#define RADIOLIB_SX127X_REG_RX_TIMEOUT_2 0x21 +#define RADIOLIB_SX127X_REG_RX_TIMEOUT_3 0x22 +#define RADIOLIB_SX127X_REG_RX_DELAY 0x23 +#define RADIOLIB_SX127X_REG_OSC 0x24 +#define RADIOLIB_SX127X_REG_PREAMBLE_MSB_FSK 0x25 +#define RADIOLIB_SX127X_REG_PREAMBLE_LSB_FSK 0x26 +#define RADIOLIB_SX127X_REG_SYNC_CONFIG 0x27 +#define RADIOLIB_SX127X_REG_SYNC_VALUE_1 0x28 +#define RADIOLIB_SX127X_REG_SYNC_VALUE_2 0x29 +#define RADIOLIB_SX127X_REG_SYNC_VALUE_3 0x2A +#define RADIOLIB_SX127X_REG_SYNC_VALUE_4 0x2B +#define RADIOLIB_SX127X_REG_SYNC_VALUE_5 0x2C +#define RADIOLIB_SX127X_REG_SYNC_VALUE_6 0x2D +#define RADIOLIB_SX127X_REG_SYNC_VALUE_7 0x2E +#define RADIOLIB_SX127X_REG_SYNC_VALUE_8 0x2F +#define RADIOLIB_SX127X_REG_PACKET_CONFIG_1 0x30 +#define RADIOLIB_SX127X_REG_PACKET_CONFIG_2 0x31 +#define RADIOLIB_SX127X_REG_PAYLOAD_LENGTH_FSK 0x32 +#define RADIOLIB_SX127X_REG_NODE_ADRS 0x33 +#define RADIOLIB_SX127X_REG_BROADCAST_ADRS 0x34 +#define RADIOLIB_SX127X_REG_FIFO_THRESH 0x35 +#define RADIOLIB_SX127X_REG_SEQ_CONFIG_1 0x36 +#define RADIOLIB_SX127X_REG_SEQ_CONFIG_2 0x37 +#define RADIOLIB_SX127X_REG_TIMER_RESOL 0x38 +#define RADIOLIB_SX127X_REG_TIMER1_COEF 0x39 +#define RADIOLIB_SX127X_REG_TIMER2_COEF 0x3A +#define RADIOLIB_SX127X_REG_IMAGE_CAL 0x3B +#define RADIOLIB_SX127X_REG_TEMP 0x3C +#define RADIOLIB_SX127X_REG_LOW_BAT 0x3D +#define RADIOLIB_SX127X_REG_IRQ_FLAGS_1 0x3E +#define RADIOLIB_SX127X_REG_IRQ_FLAGS_2 0x3F // SX127x common FSK modem settings -// SX127X_REG_OP_MODE -#define RADIOLIB_SX127X_MODULATION_FSK 0b00000000 // 6 5 FSK modulation scheme -#define RADIOLIB_SX127X_MODULATION_OOK 0b00100000 // 6 5 OOK modulation scheme -#define RADIOLIB_SX127X_RX 0b00000101 // 2 0 receiver mode +// RADIOLIB_SX127X_REG_OP_MODE +#define RADIOLIB_SX127X_MODULATION_FSK 0b00000000 // 6 5 FSK modulation scheme +#define RADIOLIB_SX127X_MODULATION_OOK 0b00100000 // 6 5 OOK modulation scheme +#define RADIOLIB_SX127X_RX 0b00000101 // 2 0 receiver mode -// SX127X_REG_BITRATE_MSB + SX127X_REG_BITRATE_LSB -#define RADIOLIB_SX127X_BITRATE_MSB 0x1A // 7 0 bit rate setting: BitRate = F(XOSC)/(BITRATE + BITRATE_FRAC/16) -#define RADIOLIB_SX127X_BITRATE_LSB 0x0B // 7 0 default value: 4.8 kbps +// RADIOLIB_SX127X_REG_BITRATE_MSB + SX127X_REG_BITRATE_LSB +#define RADIOLIB_SX127X_BITRATE_MSB 0x1A // 7 0 bit rate setting: BitRate = F(XOSC)/(BITRATE + BITRATE_FRAC/16) +#define RADIOLIB_SX127X_BITRATE_LSB 0x0B // 7 0 default value: 4.8 kbps -// SX127X_REG_FDEV_MSB + SX127X_REG_FDEV_LSB -#define RADIOLIB_SX127X_FDEV_MSB 0x00 // 5 0 frequency deviation: Fdev = Fstep * FDEV -#define RADIOLIB_SX127X_FDEV_LSB 0x52 // 7 0 default value: 5 kHz +// RADIOLIB_SX127X_REG_FDEV_MSB + SX127X_REG_FDEV_LSB +#define RADIOLIB_SX127X_FDEV_MSB 0x00 // 5 0 frequency deviation: Fdev = Fstep * FDEV +#define RADIOLIB_SX127X_FDEV_LSB 0x52 // 7 0 default value: 5 kHz -// SX127X_REG_RX_CONFIG -#define RADIOLIB_SX127X_RESTART_RX_ON_COLLISION_OFF 0b00000000 // 7 7 automatic receiver restart disabled (default) -#define RADIOLIB_SX127X_RESTART_RX_ON_COLLISION_ON 0b10000000 // 7 7 automatically restart receiver if it gets saturated or on packet collision -#define RADIOLIB_SX127X_RESTART_RX_WITHOUT_PLL_LOCK 0b01000000 // 6 6 manually restart receiver without frequency change -#define RADIOLIB_SX127X_RESTART_RX_WITH_PLL_LOCK 0b00100000 // 5 5 manually restart receiver with frequency change -#define RADIOLIB_SX127X_AFC_AUTO_OFF 0b00000000 // 4 4 no AFC performed (default) -#define RADIOLIB_SX127X_AFC_AUTO_ON 0b00010000 // 4 4 AFC performed at each receiver startup -#define RADIOLIB_SX127X_AGC_AUTO_OFF 0b00000000 // 3 3 LNA gain set manually by register -#define RADIOLIB_SX127X_AGC_AUTO_ON 0b00001000 // 3 3 LNA gain controlled by AGC -#define RADIOLIB_SX127X_RX_TRIGGER_NONE 0b00000000 // 2 0 receiver startup at: none -#define RADIOLIB_SX127X_RX_TRIGGER_RSSI_INTERRUPT 0b00000001 // 2 0 RSSI interrupt -#define RADIOLIB_SX127X_RX_TRIGGER_PREAMBLE_DETECT 0b00000110 // 2 0 preamble detected -#define RADIOLIB_SX127X_RX_TRIGGER_BOTH 0b00000111 // 2 0 RSSI interrupt and preamble detected +// RADIOLIB_SX127X_REG_RX_CONFIG +#define RADIOLIB_SX127X_RESTART_RX_ON_COLLISION_OFF 0b00000000 // 7 7 automatic receiver restart disabled (default) +#define RADIOLIB_SX127X_RESTART_RX_ON_COLLISION_ON 0b10000000 // 7 7 automatically restart receiver if it gets saturated or on packet collision +#define RADIOLIB_SX127X_RESTART_RX_WITHOUT_PLL_LOCK 0b01000000 // 6 6 manually restart receiver without frequency change +#define RADIOLIB_SX127X_RESTART_RX_WITH_PLL_LOCK 0b00100000 // 5 5 manually restart receiver with frequency change +#define RADIOLIB_SX127X_AFC_AUTO_OFF 0b00000000 // 4 4 no AFC performed (default) +#define RADIOLIB_SX127X_AFC_AUTO_ON 0b00010000 // 4 4 AFC performed at each receiver startup +#define RADIOLIB_SX127X_AGC_AUTO_OFF 0b00000000 // 3 3 LNA gain set manually by register +#define RADIOLIB_SX127X_AGC_AUTO_ON 0b00001000 // 3 3 LNA gain controlled by AGC +#define RADIOLIB_SX127X_RX_TRIGGER_NONE 0b00000000 // 2 0 receiver startup at: none +#define RADIOLIB_SX127X_RX_TRIGGER_RSSI_INTERRUPT 0b00000001 // 2 0 RSSI interrupt +#define RADIOLIB_SX127X_RX_TRIGGER_PREAMBLE_DETECT 0b00000110 // 2 0 preamble detected +#define RADIOLIB_SX127X_RX_TRIGGER_BOTH 0b00000111 // 2 0 RSSI interrupt and preamble detected -// SX127X_REG_RSSI_CONFIG -#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_2 0b00000000 // 2 0 number of samples for RSSI average: 2 -#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_4 0b00000001 // 2 0 4 -#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_8 0b00000010 // 2 0 8 (default) -#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_16 0b00000011 // 2 0 16 -#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_32 0b00000100 // 2 0 32 -#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_64 0b00000101 // 2 0 64 -#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_128 0b00000110 // 2 0 128 -#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_256 0b00000111 // 2 0 256 +// RADIOLIB_SX127X_REG_RSSI_CONFIG +#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_2 0b00000000 // 2 0 number of samples for RSSI average: 2 +#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_4 0b00000001 // 2 0 4 +#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_8 0b00000010 // 2 0 8 (default) +#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_16 0b00000011 // 2 0 16 +#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_32 0b00000100 // 2 0 32 +#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_64 0b00000101 // 2 0 64 +#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_128 0b00000110 // 2 0 128 +#define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_256 0b00000111 // 2 0 256 -// SX127X_REG_RSSI_COLLISION -#define RADIOLIB_SX127X_RSSI_COLLISION_THRESHOLD 0x0A // 7 0 RSSI threshold in dB that will be considered a collision, default value: 10 dB +// RADIOLIB_SX127X_REG_RSSI_COLLISION +#define RADIOLIB_SX127X_RSSI_COLLISION_THRESHOLD 0x0A // 7 0 RSSI threshold in dB that will be considered a collision, default value: 10 dB -// SX127X_REG_RSSI_THRESH -#define RADIOLIB_SX127X_RSSI_THRESHOLD 0xFF // 7 0 RSSI threshold that will trigger RSSI interrupt, RssiThreshold = RSSI_THRESHOLD / 2 [dBm] +// RADIOLIB_SX127X_REG_RSSI_THRESH +#define RADIOLIB_SX127X_RSSI_THRESHOLD 0xFF // 7 0 RSSI threshold that will trigger RSSI interrupt, RssiThreshold = RSSI_THRESHOLD / 2 [dBm] -// SX127X_REG_RX_BW -#define RADIOLIB_SX127X_RX_BW_MANT_16 0b00000000 // 4 3 channel filter bandwidth: RxBw = F(XOSC) / (RxBwMant * 2^(RxBwExp + 2)) [kHz] -#define RADIOLIB_SX127X_RX_BW_MANT_20 0b00001000 // 4 3 -#define RADIOLIB_SX127X_RX_BW_MANT_24 0b00010000 // 4 3 default RxBwMant parameter -#define RADIOLIB_SX127X_RX_BW_EXP 0b00000101 // 2 0 default RxBwExp parameter +// RADIOLIB_SX127X_REG_RX_BW +#define RADIOLIB_SX127X_RX_BW_MANT_16 0b00000000 // 4 3 channel filter bandwidth: RxBw = F(XOSC) / (RxBwMant * 2^(RxBwExp + 2)) [kHz] +#define RADIOLIB_SX127X_RX_BW_MANT_20 0b00001000 // 4 3 +#define RADIOLIB_SX127X_RX_BW_MANT_24 0b00010000 // 4 3 default RxBwMant parameter +#define RADIOLIB_SX127X_RX_BW_EXP 0b00000101 // 2 0 default RxBwExp parameter -// SX127X_REG_AFC_BW -#define RADIOLIB_SX127X_RX_BW_MANT_AFC 0b00001000 // 4 3 default RxBwMant parameter used during AFC -#define RADIOLIB_SX127X_RX_BW_EXP_AFC 0b00000011 // 2 0 default RxBwExp parameter used during AFC +// RADIOLIB_SX127X_REG_AFC_BW +#define RADIOLIB_SX127X_RX_BW_MANT_AFC 0b00001000 // 4 3 default RxBwMant parameter used during AFC +#define RADIOLIB_SX127X_RX_BW_EXP_AFC 0b00000011 // 2 0 default RxBwExp parameter used during AFC -// SX127X_REG_OOK_PEAK -#define RADIOLIB_SX127X_BIT_SYNC_OFF 0b00000000 // 5 5 bit synchronizer disabled (not allowed in packet mode) -#define RADIOLIB_SX127X_BIT_SYNC_ON 0b00100000 // 5 5 bit synchronizer enabled (default) -#define RADIOLIB_SX127X_OOK_THRESH_FIXED 0b00000000 // 4 3 OOK threshold type: fixed value -#define RADIOLIB_SX127X_OOK_THRESH_PEAK 0b00001000 // 4 3 peak mode (default) -#define RADIOLIB_SX127X_OOK_THRESH_AVERAGE 0b00010000 // 4 3 average mode -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_0_5_DB 0b00000000 // 2 0 OOK demodulator step size: 0.5 dB (default) -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_1_0_DB 0b00000001 // 2 0 1.0 dB -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_1_5_DB 0b00000010 // 2 0 1.5 dB -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_2_0_DB 0b00000011 // 2 0 2.0 dB -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_3_0_DB 0b00000100 // 2 0 3.0 dB -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_4_0_DB 0b00000101 // 2 0 4.0 dB -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_5_0_DB 0b00000110 // 2 0 5.0 dB -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_6_0_DB 0b00000111 // 2 0 6.0 dB +// RADIOLIB_SX127X_REG_OOK_PEAK +#define RADIOLIB_SX127X_BIT_SYNC_OFF 0b00000000 // 5 5 bit synchronizer disabled (not allowed in packet mode) +#define RADIOLIB_SX127X_BIT_SYNC_ON 0b00100000 // 5 5 bit synchronizer enabled (default) +#define RADIOLIB_SX127X_OOK_THRESH_FIXED 0b00000000 // 4 3 OOK threshold type: fixed value +#define RADIOLIB_SX127X_OOK_THRESH_PEAK 0b00001000 // 4 3 peak mode (default) +#define RADIOLIB_SX127X_OOK_THRESH_AVERAGE 0b00010000 // 4 3 average mode +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_0_5_DB 0b00000000 // 2 0 OOK demodulator step size: 0.5 dB (default) +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_1_0_DB 0b00000001 // 2 0 1.0 dB +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_1_5_DB 0b00000010 // 2 0 1.5 dB +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_2_0_DB 0b00000011 // 2 0 2.0 dB +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_3_0_DB 0b00000100 // 2 0 3.0 dB +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_4_0_DB 0b00000101 // 2 0 4.0 dB +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_5_0_DB 0b00000110 // 2 0 5.0 dB +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_6_0_DB 0b00000111 // 2 0 6.0 dB -// SX127X_REG_OOK_FIX -#define RADIOLIB_SX127X_OOK_FIXED_THRESHOLD 0x0C // 7 0 default fixed threshold for OOK data slicer +// RADIOLIB_SX127X_REG_OOK_FIX +#define RADIOLIB_SX127X_OOK_FIXED_THRESHOLD 0x0C // 7 0 default fixed threshold for OOK data slicer -// SX127X_REG_OOK_AVG -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_1_1_CHIP 0b00000000 // 7 5 OOK demodulator step period: once per chip (default) -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_1_2_CHIP 0b00100000 // 7 5 once every 2 chips -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_1_4_CHIP 0b01000000 // 7 5 once every 4 chips -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_1_8_CHIP 0b01100000 // 7 5 once every 8 chips -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_2_1_CHIP 0b10000000 // 7 5 2 times per chip -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_4_1_CHIP 0b10100000 // 7 5 4 times per chip -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_8_1_CHIP 0b11000000 // 7 5 8 times per chip -#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_16_1_CHIP 0b11100000 // 7 5 16 times per chip -#define RADIOLIB_SX127X_OOK_AVERAGE_OFFSET_0_DB 0b00000000 // 3 2 OOK average threshold offset: 0.0 dB (default) -#define RADIOLIB_SX127X_OOK_AVERAGE_OFFSET_2_DB 0b00000100 // 3 2 2.0 dB -#define RADIOLIB_SX127X_OOK_AVERAGE_OFFSET_4_DB 0b00001000 // 3 2 4.0 dB -#define RADIOLIB_SX127X_OOK_AVERAGE_OFFSET_6_DB 0b00001100 // 3 2 6.0 dB -#define RADIOLIB_SX127X_OOK_AVG_THRESH_FILT_32_PI 0b00000000 // 1 0 OOK average filter coefficient: chip rate / 32*pi -#define RADIOLIB_SX127X_OOK_AVG_THRESH_FILT_8_PI 0b00000001 // 1 0 chip rate / 8*pi -#define RADIOLIB_SX127X_OOK_AVG_THRESH_FILT_4_PI 0b00000010 // 1 0 chip rate / 4*pi (default) -#define RADIOLIB_SX127X_OOK_AVG_THRESH_FILT_2_PI 0b00000011 // 1 0 chip rate / 2*pi +// RADIOLIB_SX127X_REG_OOK_AVG +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_1_1_CHIP 0b00000000 // 7 5 OOK demodulator step period: once per chip (default) +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_1_2_CHIP 0b00100000 // 7 5 once every 2 chips +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_1_4_CHIP 0b01000000 // 7 5 once every 4 chips +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_1_8_CHIP 0b01100000 // 7 5 once every 8 chips +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_2_1_CHIP 0b10000000 // 7 5 2 times per chip +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_4_1_CHIP 0b10100000 // 7 5 4 times per chip +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_8_1_CHIP 0b11000000 // 7 5 8 times per chip +#define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_16_1_CHIP 0b11100000 // 7 5 16 times per chip +#define RADIOLIB_SX127X_OOK_AVERAGE_OFFSET_0_DB 0b00000000 // 3 2 OOK average threshold offset: 0.0 dB (default) +#define RADIOLIB_SX127X_OOK_AVERAGE_OFFSET_2_DB 0b00000100 // 3 2 2.0 dB +#define RADIOLIB_SX127X_OOK_AVERAGE_OFFSET_4_DB 0b00001000 // 3 2 4.0 dB +#define RADIOLIB_SX127X_OOK_AVERAGE_OFFSET_6_DB 0b00001100 // 3 2 6.0 dB +#define RADIOLIB_SX127X_OOK_AVG_THRESH_FILT_32_PI 0b00000000 // 1 0 OOK average filter coefficient: chip rate / 32*pi +#define RADIOLIB_SX127X_OOK_AVG_THRESH_FILT_8_PI 0b00000001 // 1 0 chip rate / 8*pi +#define RADIOLIB_SX127X_OOK_AVG_THRESH_FILT_4_PI 0b00000010 // 1 0 chip rate / 4*pi (default) +#define RADIOLIB_SX127X_OOK_AVG_THRESH_FILT_2_PI 0b00000011 // 1 0 chip rate / 2*pi -// SX127X_REG_AFC_FEI -#define RADIOLIB_SX127X_AGC_START 0b00010000 // 4 4 manually start AGC sequence -#define RADIOLIB_SX127X_AFC_CLEAR 0b00000010 // 1 1 manually clear AFC register -#define RADIOLIB_SX127X_AFC_AUTO_CLEAR_OFF 0b00000000 // 0 0 AFC register will not be cleared at the start of AFC (default) -#define RADIOLIB_SX127X_AFC_AUTO_CLEAR_ON 0b00000001 // 0 0 AFC register will be cleared at the start of AFC +// RADIOLIB_SX127X_REG_AFC_FEI +#define RADIOLIB_SX127X_AGC_START 0b00010000 // 4 4 manually start AGC sequence +#define RADIOLIB_SX127X_AFC_CLEAR 0b00000010 // 1 1 manually clear AFC register +#define RADIOLIB_SX127X_AFC_AUTO_CLEAR_OFF 0b00000000 // 0 0 AFC register will not be cleared at the start of AFC (default) +#define RADIOLIB_SX127X_AFC_AUTO_CLEAR_ON 0b00000001 // 0 0 AFC register will be cleared at the start of AFC -// SX127X_REG_PREAMBLE_DETECT -#define RADIOLIB_SX127X_PREAMBLE_DETECTOR_OFF 0b00000000 // 7 7 preamble detection disabled -#define RADIOLIB_SX127X_PREAMBLE_DETECTOR_ON 0b10000000 // 7 7 preamble detection enabled (default) -#define RADIOLIB_SX127X_PREAMBLE_DETECTOR_1_BYTE 0b00000000 // 6 5 preamble detection size: 1 byte (default) -#define RADIOLIB_SX127X_PREAMBLE_DETECTOR_2_BYTE 0b00100000 // 6 5 2 bytes -#define RADIOLIB_SX127X_PREAMBLE_DETECTOR_3_BYTE 0b01000000 // 6 5 3 bytes -#define RADIOLIB_SX127X_PREAMBLE_DETECTOR_TOL 0x0A // 4 0 default number of tolerated errors per chip (4 chips per bit) +// RADIOLIB_SX127X_REG_PREAMBLE_DETECT +#define RADIOLIB_SX127X_PREAMBLE_DETECTOR_OFF 0b00000000 // 7 7 preamble detection disabled +#define RADIOLIB_SX127X_PREAMBLE_DETECTOR_ON 0b10000000 // 7 7 preamble detection enabled (default) +#define RADIOLIB_SX127X_PREAMBLE_DETECTOR_1_BYTE 0b00000000 // 6 5 preamble detection size: 1 byte (default) +#define RADIOLIB_SX127X_PREAMBLE_DETECTOR_2_BYTE 0b00100000 // 6 5 2 bytes +#define RADIOLIB_SX127X_PREAMBLE_DETECTOR_3_BYTE 0b01000000 // 6 5 3 bytes +#define RADIOLIB_SX127X_PREAMBLE_DETECTOR_TOL 0x0A // 4 0 default number of tolerated errors per chip (4 chips per bit) -// SX127X_REG_RX_TIMEOUT_1 -#define RADIOLIB_SX127X_TIMEOUT_RX_RSSI_OFF 0x00 // 7 0 disable receiver timeout when RSSI interrupt doesn't occur (default) +// RADIOLIB_SX127X_REG_RX_TIMEOUT_1 +#define RADIOLIB_SX127X_TIMEOUT_RX_RSSI_OFF 0x00 // 7 0 disable receiver timeout when RSSI interrupt doesn't occur (default) -// SX127X_REG_RX_TIMEOUT_2 -#define RADIOLIB_SX127X_TIMEOUT_RX_PREAMBLE_OFF 0x00 // 7 0 disable receiver timeout when preamble interrupt doesn't occur (default) +// RADIOLIB_SX127X_REG_RX_TIMEOUT_2 +#define RADIOLIB_SX127X_TIMEOUT_RX_PREAMBLE_OFF 0x00 // 7 0 disable receiver timeout when preamble interrupt doesn't occur (default) -// SX127X_REG_RX_TIMEOUT_3 -#define RADIOLIB_SX127X_TIMEOUT_SIGNAL_SYNC_OFF 0x00 // 7 0 disable receiver timeout when sync address interrupt doesn't occur (default) +// RADIOLIB_SX127X_REG_RX_TIMEOUT_3 +#define RADIOLIB_SX127X_TIMEOUT_SIGNAL_SYNC_OFF 0x00 // 7 0 disable receiver timeout when sync address interrupt doesn't occur (default) -// SX127X_REG_OSC -#define RADIOLIB_SX127X_RC_CAL_START 0b00000000 // 3 3 manually start RC oscillator calibration -#define RADIOLIB_SX127X_CLK_OUT_FXOSC 0b00000000 // 2 0 ClkOut frequency: F(XOSC) -#define RADIOLIB_SX127X_CLK_OUT_FXOSC_2 0b00000001 // 2 0 F(XOSC) / 2 -#define RADIOLIB_SX127X_CLK_OUT_FXOSC_4 0b00000010 // 2 0 F(XOSC) / 4 -#define RADIOLIB_SX127X_CLK_OUT_FXOSC_8 0b00000011 // 2 0 F(XOSC) / 8 -#define RADIOLIB_SX127X_CLK_OUT_FXOSC_16 0b00000100 // 2 0 F(XOSC) / 16 -#define RADIOLIB_SX127X_CLK_OUT_FXOSC_32 0b00000101 // 2 0 F(XOSC) / 32 -#define RADIOLIB_SX127X_CLK_OUT_RC 0b00000110 // 2 0 RC -#define RADIOLIB_SX127X_CLK_OUT_OFF 0b00000111 // 2 0 disabled (default) +// RADIOLIB_SX127X_REG_OSC +#define RADIOLIB_SX127X_RC_CAL_START 0b00000000 // 3 3 manually start RC oscillator calibration +#define RADIOLIB_SX127X_CLK_OUT_FXOSC 0b00000000 // 2 0 ClkOut frequency: F(XOSC) +#define RADIOLIB_SX127X_CLK_OUT_FXOSC_2 0b00000001 // 2 0 F(XOSC) / 2 +#define RADIOLIB_SX127X_CLK_OUT_FXOSC_4 0b00000010 // 2 0 F(XOSC) / 4 +#define RADIOLIB_SX127X_CLK_OUT_FXOSC_8 0b00000011 // 2 0 F(XOSC) / 8 +#define RADIOLIB_SX127X_CLK_OUT_FXOSC_16 0b00000100 // 2 0 F(XOSC) / 16 +#define RADIOLIB_SX127X_CLK_OUT_FXOSC_32 0b00000101 // 2 0 F(XOSC) / 32 +#define RADIOLIB_SX127X_CLK_OUT_RC 0b00000110 // 2 0 RC +#define RADIOLIB_SX127X_CLK_OUT_OFF 0b00000111 // 2 0 disabled (default) -// SX127X_REG_PREAMBLE_MSB_FSK + SX127X_REG_PREAMBLE_LSB_FSK -#define RADIOLIB_SX127X_PREAMBLE_SIZE_MSB 0x00 // 7 0 preamble size in bytes -#define RADIOLIB_SX127X_PREAMBLE_SIZE_LSB 0x03 // 7 0 default value: 3 bytes +// RADIOLIB_SX127X_REG_PREAMBLE_MSB_FSK + SX127X_REG_PREAMBLE_LSB_FSK +#define RADIOLIB_SX127X_PREAMBLE_SIZE_MSB 0x00 // 7 0 preamble size in bytes +#define RADIOLIB_SX127X_PREAMBLE_SIZE_LSB 0x03 // 7 0 default value: 3 bytes -// SX127X_REG_SYNC_CONFIG -#define RADIOLIB_SX127X_AUTO_RESTART_RX_MODE_OFF 0b00000000 // 7 6 Rx mode restart after packet reception: disabled -#define RADIOLIB_SX127X_AUTO_RESTART_RX_MODE_NO_PLL 0b01000000 // 7 6 enabled, don't wait for PLL lock -#define RADIOLIB_SX127X_AUTO_RESTART_RX_MODE_PLL 0b10000000 // 7 6 enabled, wait for PLL lock (default) -#define RADIOLIB_SX127X_PREAMBLE_POLARITY_AA 0b00000000 // 5 5 preamble polarity: 0xAA = 0b10101010 (default) -#define RADIOLIB_SX127X_PREAMBLE_POLARITY_55 0b00100000 // 5 5 0x55 = 0b01010101 -#define RADIOLIB_SX127X_SYNC_OFF 0b00000000 // 4 4 sync word disabled -#define RADIOLIB_SX127X_SYNC_ON 0b00010000 // 4 4 sync word enabled (default) -#define RADIOLIB_SX127X_SYNC_SIZE 0x03 // 2 0 sync word size in bytes, SyncSize = SYNC_SIZE + 1 bytes +// RADIOLIB_SX127X_REG_SYNC_CONFIG +#define RADIOLIB_SX127X_AUTO_RESTART_RX_MODE_OFF 0b00000000 // 7 6 Rx mode restart after packet reception: disabled +#define RADIOLIB_SX127X_AUTO_RESTART_RX_MODE_NO_PLL 0b01000000 // 7 6 enabled, don't wait for PLL lock +#define RADIOLIB_SX127X_AUTO_RESTART_RX_MODE_PLL 0b10000000 // 7 6 enabled, wait for PLL lock (default) +#define RADIOLIB_SX127X_PREAMBLE_POLARITY_AA 0b00000000 // 5 5 preamble polarity: 0xAA = 0b10101010 (default) +#define RADIOLIB_SX127X_PREAMBLE_POLARITY_55 0b00100000 // 5 5 0x55 = 0b01010101 +#define RADIOLIB_SX127X_SYNC_OFF 0b00000000 // 4 4 sync word disabled +#define RADIOLIB_SX127X_SYNC_ON 0b00010000 // 4 4 sync word enabled (default) +#define RADIOLIB_SX127X_SYNC_SIZE 0x03 // 2 0 sync word size in bytes, SyncSize = SYNC_SIZE + 1 bytes -// SX127X_REG_SYNC_VALUE_1 - SX127X_REG_SYNC_VALUE_8 -#define RADIOLIB_SX127X_SYNC_VALUE_1 0x01 // 7 0 sync word: 1st byte (MSB) -#define RADIOLIB_SX127X_SYNC_VALUE_2 0x01 // 7 0 2nd byte -#define RADIOLIB_SX127X_SYNC_VALUE_3 0x01 // 7 0 3rd byte -#define RADIOLIB_SX127X_SYNC_VALUE_4 0x01 // 7 0 4th byte -#define RADIOLIB_SX127X_SYNC_VALUE_5 0x01 // 7 0 5th byte -#define RADIOLIB_SX127X_SYNC_VALUE_6 0x01 // 7 0 6th byte -#define RADIOLIB_SX127X_SYNC_VALUE_7 0x01 // 7 0 7th byte -#define RADIOLIB_SX127X_SYNC_VALUE_8 0x01 // 7 0 8th byte (LSB) +// RADIOLIB_SX127X_REG_SYNC_VALUE_1 - SX127X_REG_SYNC_VALUE_8 +#define RADIOLIB_SX127X_SYNC_VALUE_1 0x01 // 7 0 sync word: 1st byte (MSB) +#define RADIOLIB_SX127X_SYNC_VALUE_2 0x01 // 7 0 2nd byte +#define RADIOLIB_SX127X_SYNC_VALUE_3 0x01 // 7 0 3rd byte +#define RADIOLIB_SX127X_SYNC_VALUE_4 0x01 // 7 0 4th byte +#define RADIOLIB_SX127X_SYNC_VALUE_5 0x01 // 7 0 5th byte +#define RADIOLIB_SX127X_SYNC_VALUE_6 0x01 // 7 0 6th byte +#define RADIOLIB_SX127X_SYNC_VALUE_7 0x01 // 7 0 7th byte +#define RADIOLIB_SX127X_SYNC_VALUE_8 0x01 // 7 0 8th byte (LSB) -// SX127X_REG_PACKET_CONFIG_1 -#define RADIOLIB_SX127X_PACKET_FIXED 0b00000000 // 7 7 packet format: fixed length -#define RADIOLIB_SX127X_PACKET_VARIABLE 0b10000000 // 7 7 variable length (default) -#define RADIOLIB_SX127X_DC_FREE_NONE 0b00000000 // 6 5 DC-free encoding: disabled (default) -#define RADIOLIB_SX127X_DC_FREE_MANCHESTER 0b00100000 // 6 5 Manchester -#define RADIOLIB_SX127X_DC_FREE_WHITENING 0b01000000 // 6 5 Whitening -#define RADIOLIB_SX127X_CRC_OFF 0b00000000 // 4 4 CRC disabled -#define RADIOLIB_SX127X_CRC_ON 0b00010000 // 4 4 CRC enabled (default) -#define RADIOLIB_SX127X_CRC_AUTOCLEAR_OFF 0b00001000 // 3 3 keep FIFO on CRC mismatch, issue payload ready interrupt -#define RADIOLIB_SX127X_CRC_AUTOCLEAR_ON 0b00000000 // 3 3 clear FIFO on CRC mismatch, do not issue payload ready interrupt -#define RADIOLIB_SX127X_ADDRESS_FILTERING_OFF 0b00000000 // 2 1 address filtering: none (default) -#define RADIOLIB_SX127X_ADDRESS_FILTERING_NODE 0b00000010 // 2 1 node -#define RADIOLIB_SX127X_ADDRESS_FILTERING_NODE_BROADCAST 0b00000100 // 2 1 node or broadcast -#define RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT 0b00000000 // 0 0 CRC and whitening algorithms: CCITT CRC with standard whitening (default) -#define RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM 0b00000001 // 0 0 IBM CRC with alternate whitening +// RADIOLIB_SX127X_REG_PACKET_CONFIG_1 +#define RADIOLIB_SX127X_PACKET_FIXED 0b00000000 // 7 7 packet format: fixed length +#define RADIOLIB_SX127X_PACKET_VARIABLE 0b10000000 // 7 7 variable length (default) +#define RADIOLIB_SX127X_DC_FREE_NONE 0b00000000 // 6 5 DC-free encoding: disabled (default) +#define RADIOLIB_SX127X_DC_FREE_MANCHESTER 0b00100000 // 6 5 Manchester +#define RADIOLIB_SX127X_DC_FREE_WHITENING 0b01000000 // 6 5 Whitening +#define RADIOLIB_SX127X_CRC_OFF 0b00000000 // 4 4 CRC disabled +#define RADIOLIB_SX127X_CRC_ON 0b00010000 // 4 4 CRC enabled (default) +#define RADIOLIB_SX127X_CRC_AUTOCLEAR_OFF 0b00001000 // 3 3 keep FIFO on CRC mismatch, issue payload ready interrupt +#define RADIOLIB_SX127X_CRC_AUTOCLEAR_ON 0b00000000 // 3 3 clear FIFO on CRC mismatch, do not issue payload ready interrupt +#define RADIOLIB_SX127X_ADDRESS_FILTERING_OFF 0b00000000 // 2 1 address filtering: none (default) +#define RADIOLIB_SX127X_ADDRESS_FILTERING_NODE 0b00000010 // 2 1 node +#define RADIOLIB_SX127X_ADDRESS_FILTERING_NODE_BROADCAST 0b00000100 // 2 1 node or broadcast +#define RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT 0b00000000 // 0 0 CRC and whitening algorithms: CCITT CRC with standard whitening (default) +#define RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM 0b00000001 // 0 0 IBM CRC with alternate whitening -// SX127X_REG_PACKET_CONFIG_2 -#define RADIOLIB_SX127X_DATA_MODE_PACKET 0b01000000 // 6 6 data mode: packet (default) -#define RADIOLIB_SX127X_DATA_MODE_CONTINUOUS 0b00000000 // 6 6 continuous -#define RADIOLIB_SX127X_IO_HOME_OFF 0b00000000 // 5 5 io-homecontrol compatibility disabled (default) -#define RADIOLIB_SX127X_IO_HOME_ON 0b00100000 // 5 5 io-homecontrol compatibility enabled +// RADIOLIB_SX127X_REG_PACKET_CONFIG_2 +#define RADIOLIB_SX127X_DATA_MODE_PACKET 0b01000000 // 6 6 data mode: packet (default) +#define RADIOLIB_SX127X_DATA_MODE_CONTINUOUS 0b00000000 // 6 6 continuous +#define RADIOLIB_SX127X_IO_HOME_OFF 0b00000000 // 5 5 io-homecontrol compatibility disabled (default) +#define RADIOLIB_SX127X_IO_HOME_ON 0b00100000 // 5 5 io-homecontrol compatibility enabled -// SX127X_REG_FIFO_THRESH -#define RADIOLIB_SX127X_TX_START_FIFO_LEVEL 0b00000000 // 7 7 start packet transmission when: number of bytes in FIFO exceeds FIFO_THRESHOLD -#define RADIOLIB_SX127X_TX_START_FIFO_NOT_EMPTY 0b10000000 // 7 7 at least one byte in FIFO (default) -#define RADIOLIB_SX127X_FIFO_THRESH 0x1F // 5 0 FIFO level threshold +// RADIOLIB_SX127X_REG_FIFO_THRESH +#define RADIOLIB_SX127X_TX_START_FIFO_LEVEL 0b00000000 // 7 7 start packet transmission when: number of bytes in FIFO exceeds FIFO_THRESHOLD +#define RADIOLIB_SX127X_TX_START_FIFO_NOT_EMPTY 0b10000000 // 7 7 at least one byte in FIFO (default) +#define RADIOLIB_SX127X_FIFO_THRESH 0x1F // 5 0 FIFO level threshold -// SX127X_REG_SEQ_CONFIG_1 -#define RADIOLIB_SX127X_SEQUENCER_START 0b10000000 // 7 7 manually start sequencer -#define RADIOLIB_SX127X_SEQUENCER_STOP 0b01000000 // 6 6 manually stop sequencer -#define RADIOLIB_SX127X_IDLE_MODE_STANDBY 0b00000000 // 5 5 chip mode during sequencer idle mode: standby (default) -#define RADIOLIB_SX127X_IDLE_MODE_SLEEP 0b00100000 // 5 5 sleep -#define RADIOLIB_SX127X_FROM_START_LP_SELECTION 0b00000000 // 4 3 mode that will be set after starting sequencer: low power selection (default) -#define RADIOLIB_SX127X_FROM_START_RECEIVE 0b00001000 // 4 3 receive -#define RADIOLIB_SX127X_FROM_START_TRANSMIT 0b00010000 // 4 3 transmit -#define RADIOLIB_SX127X_FROM_START_TRANSMIT_FIFO_LEVEL 0b00011000 // 4 3 transmit on a FIFO level interrupt -#define RADIOLIB_SX127X_LP_SELECTION_SEQ_OFF 0b00000000 // 2 2 mode that will be set after exiting low power selection: sequencer off (default) -#define RADIOLIB_SX127X_LP_SELECTION_IDLE 0b00000100 // 2 2 idle state -#define RADIOLIB_SX127X_FROM_IDLE_TRANSMIT 0b00000000 // 1 1 mode that will be set after exiting idle mode: transmit (default) -#define RADIOLIB_SX127X_FROM_IDLE_RECEIVE 0b00000010 // 1 1 receive -#define RADIOLIB_SX127X_FROM_TRANSMIT_LP_SELECTION 0b00000000 // 0 0 mode that will be set after exiting transmit mode: low power selection (default) -#define RADIOLIB_SX127X_FROM_TRANSMIT_RECEIVE 0b00000001 // 0 0 receive +// RADIOLIB_SX127X_REG_SEQ_CONFIG_1 +#define RADIOLIB_SX127X_SEQUENCER_START 0b10000000 // 7 7 manually start sequencer +#define RADIOLIB_SX127X_SEQUENCER_STOP 0b01000000 // 6 6 manually stop sequencer +#define RADIOLIB_SX127X_IDLE_MODE_STANDBY 0b00000000 // 5 5 chip mode during sequencer idle mode: standby (default) +#define RADIOLIB_SX127X_IDLE_MODE_SLEEP 0b00100000 // 5 5 sleep +#define RADIOLIB_SX127X_FROM_START_LP_SELECTION 0b00000000 // 4 3 mode that will be set after starting sequencer: low power selection (default) +#define RADIOLIB_SX127X_FROM_START_RECEIVE 0b00001000 // 4 3 receive +#define RADIOLIB_SX127X_FROM_START_TRANSMIT 0b00010000 // 4 3 transmit +#define RADIOLIB_SX127X_FROM_START_TRANSMIT_FIFO_LEVEL 0b00011000 // 4 3 transmit on a FIFO level interrupt +#define RADIOLIB_SX127X_LP_SELECTION_SEQ_OFF 0b00000000 // 2 2 mode that will be set after exiting low power selection: sequencer off (default) +#define RADIOLIB_SX127X_LP_SELECTION_IDLE 0b00000100 // 2 2 idle state +#define RADIOLIB_SX127X_FROM_IDLE_TRANSMIT 0b00000000 // 1 1 mode that will be set after exiting idle mode: transmit (default) +#define RADIOLIB_SX127X_FROM_IDLE_RECEIVE 0b00000010 // 1 1 receive +#define RADIOLIB_SX127X_FROM_TRANSMIT_LP_SELECTION 0b00000000 // 0 0 mode that will be set after exiting transmit mode: low power selection (default) +#define RADIOLIB_SX127X_FROM_TRANSMIT_RECEIVE 0b00000001 // 0 0 receive -// SX127X_REG_SEQ_CONFIG_2 -#define RADIOLIB_SX127X_FROM_RECEIVE_PACKET_RECEIVED_PAYLOAD 0b00100000 // 7 5 mode that will be set after exiting receive mode: packet received on payload ready interrupt (default) -#define RADIOLIB_SX127X_FROM_RECEIVE_LP_SELECTION 0b01000000 // 7 5 low power selection -#define RADIOLIB_SX127X_FROM_RECEIVE_PACKET_RECEIVED_CRC_OK 0b01100000 // 7 5 packet received on CRC OK interrupt -#define RADIOLIB_SX127X_FROM_RECEIVE_SEQ_OFF_RSSI 0b10000000 // 7 5 sequencer off on RSSI interrupt -#define RADIOLIB_SX127X_FROM_RECEIVE_SEQ_OFF_SYNC_ADDR 0b10100000 // 7 5 sequencer off on sync address interrupt -#define RADIOLIB_SX127X_FROM_RECEIVE_SEQ_OFF_PREAMBLE_DETECT 0b11000000 // 7 5 sequencer off on preamble detect interrupt -#define RADIOLIB_SX127X_FROM_RX_TIMEOUT_RECEIVE 0b00000000 // 4 3 mode that will be set after Rx timeout: receive (default) -#define RADIOLIB_SX127X_FROM_RX_TIMEOUT_TRANSMIT 0b00001000 // 4 3 transmit -#define RADIOLIB_SX127X_FROM_RX_TIMEOUT_LP_SELECTION 0b00010000 // 4 3 low power selection -#define RADIOLIB_SX127X_FROM_RX_TIMEOUT_SEQ_OFF 0b00011000 // 4 3 sequencer off -#define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_SEQ_OFF 0b00000000 // 2 0 mode that will be set after packet received: sequencer off (default) -#define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_TRANSMIT 0b00000001 // 2 0 transmit -#define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_LP_SELECTION 0b00000010 // 2 0 low power selection -#define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_RECEIVE_FS 0b00000011 // 2 0 receive via FS -#define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_RECEIVE 0b00000100 // 2 0 receive +// RADIOLIB_SX127X_REG_SEQ_CONFIG_2 +#define RADIOLIB_SX127X_FROM_RECEIVE_PACKET_RECEIVED_PAYLOAD 0b00100000 // 7 5 mode that will be set after exiting receive mode: packet received on payload ready interrupt (default) +#define RADIOLIB_SX127X_FROM_RECEIVE_LP_SELECTION 0b01000000 // 7 5 low power selection +#define RADIOLIB_SX127X_FROM_RECEIVE_PACKET_RECEIVED_CRC_OK 0b01100000 // 7 5 packet received on CRC OK interrupt +#define RADIOLIB_SX127X_FROM_RECEIVE_SEQ_OFF_RSSI 0b10000000 // 7 5 sequencer off on RSSI interrupt +#define RADIOLIB_SX127X_FROM_RECEIVE_SEQ_OFF_SYNC_ADDR 0b10100000 // 7 5 sequencer off on sync address interrupt +#define RADIOLIB_SX127X_FROM_RECEIVE_SEQ_OFF_PREAMBLE_DETECT 0b11000000 // 7 5 sequencer off on preamble detect interrupt +#define RADIOLIB_SX127X_FROM_RX_TIMEOUT_RECEIVE 0b00000000 // 4 3 mode that will be set after Rx timeout: receive (default) +#define RADIOLIB_SX127X_FROM_RX_TIMEOUT_TRANSMIT 0b00001000 // 4 3 transmit +#define RADIOLIB_SX127X_FROM_RX_TIMEOUT_LP_SELECTION 0b00010000 // 4 3 low power selection +#define RADIOLIB_SX127X_FROM_RX_TIMEOUT_SEQ_OFF 0b00011000 // 4 3 sequencer off +#define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_SEQ_OFF 0b00000000 // 2 0 mode that will be set after packet received: sequencer off (default) +#define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_TRANSMIT 0b00000001 // 2 0 transmit +#define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_LP_SELECTION 0b00000010 // 2 0 low power selection +#define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_RECEIVE_FS 0b00000011 // 2 0 receive via FS +#define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_RECEIVE 0b00000100 // 2 0 receive -// SX127X_REG_TIMER_RESOL -#define RADIOLIB_SX127X_TIMER1_OFF 0b00000000 // 3 2 timer 1 resolution: disabled (default) -#define RADIOLIB_SX127X_TIMER1_RESOLUTION_64_US 0b00000100 // 3 2 64 us -#define RADIOLIB_SX127X_TIMER1_RESOLUTION_4_1_MS 0b00001000 // 3 2 4.1 ms -#define RADIOLIB_SX127X_TIMER1_RESOLUTION_262_MS 0b00001100 // 3 2 262 ms -#define RADIOLIB_SX127X_TIMER2_OFF 0b00000000 // 3 2 timer 2 resolution: disabled (default) -#define RADIOLIB_SX127X_TIMER2_RESOLUTION_64_US 0b00000001 // 3 2 64 us -#define RADIOLIB_SX127X_TIMER2_RESOLUTION_4_1_MS 0b00000010 // 3 2 4.1 ms -#define RADIOLIB_SX127X_TIMER2_RESOLUTION_262_MS 0b00000011 // 3 2 262 ms +// RADIOLIB_SX127X_REG_TIMER_RESOL +#define RADIOLIB_SX127X_TIMER1_OFF 0b00000000 // 3 2 timer 1 resolution: disabled (default) +#define RADIOLIB_SX127X_TIMER1_RESOLUTION_64_US 0b00000100 // 3 2 64 us +#define RADIOLIB_SX127X_TIMER1_RESOLUTION_4_1_MS 0b00001000 // 3 2 4.1 ms +#define RADIOLIB_SX127X_TIMER1_RESOLUTION_262_MS 0b00001100 // 3 2 262 ms +#define RADIOLIB_SX127X_TIMER2_OFF 0b00000000 // 3 2 timer 2 resolution: disabled (default) +#define RADIOLIB_SX127X_TIMER2_RESOLUTION_64_US 0b00000001 // 3 2 64 us +#define RADIOLIB_SX127X_TIMER2_RESOLUTION_4_1_MS 0b00000010 // 3 2 4.1 ms +#define RADIOLIB_SX127X_TIMER2_RESOLUTION_262_MS 0b00000011 // 3 2 262 ms -// SX127X_REG_TIMER1_COEF -#define RADIOLIB_SX127X_TIMER1_COEFFICIENT 0xF5 // 7 0 multiplication coefficient for timer 1 +// RADIOLIB_SX127X_REG_TIMER1_COEF +#define RADIOLIB_SX127X_TIMER1_COEFFICIENT 0xF5 // 7 0 multiplication coefficient for timer 1 -// SX127X_REG_TIMER2_COEF -#define RADIOLIB_SX127X_TIMER2_COEFFICIENT 0x20 // 7 0 multiplication coefficient for timer 2 +// RADIOLIB_SX127X_REG_TIMER2_COEF +#define RADIOLIB_SX127X_TIMER2_COEFFICIENT 0x20 // 7 0 multiplication coefficient for timer 2 -// SX127X_REG_IMAGE_CAL -#define RADIOLIB_SX127X_AUTO_IMAGE_CAL_OFF 0b00000000 // 7 7 temperature calibration disabled (default) -#define RADIOLIB_SX127X_AUTO_IMAGE_CAL_ON 0b10000000 // 7 7 temperature calibration enabled -#define RADIOLIB_SX127X_IMAGE_CAL_START 0b01000000 // 6 6 start temperature calibration -#define RADIOLIB_SX127X_IMAGE_CAL_RUNNING 0b00100000 // 5 5 temperature calibration is on-going -#define RADIOLIB_SX127X_IMAGE_CAL_COMPLETE 0b00000000 // 5 5 temperature calibration finished -#define RADIOLIB_SX127X_TEMP_CHANGED 0b00001000 // 3 3 temperature changed more than TEMP_THRESHOLD since last calibration -#define RADIOLIB_SX127X_TEMP_THRESHOLD_5_DEG_C 0b00000000 // 2 1 temperature change threshold: 5 deg. C -#define RADIOLIB_SX127X_TEMP_THRESHOLD_10_DEG_C 0b00000010 // 2 1 10 deg. C (default) -#define RADIOLIB_SX127X_TEMP_THRESHOLD_15_DEG_C 0b00000100 // 2 1 15 deg. C -#define RADIOLIB_SX127X_TEMP_THRESHOLD_20_DEG_C 0b00000110 // 2 1 20 deg. C -#define RADIOLIB_SX127X_TEMP_MONITOR_ON 0b00000000 // 0 0 temperature monitoring enabled (default) -#define RADIOLIB_SX127X_TEMP_MONITOR_OFF 0b00000001 // 0 0 temperature monitoring disabled +// RADIOLIB_SX127X_REG_IMAGE_CAL +#define RADIOLIB_SX127X_AUTO_IMAGE_CAL_OFF 0b00000000 // 7 7 temperature calibration disabled (default) +#define RADIOLIB_SX127X_AUTO_IMAGE_CAL_ON 0b10000000 // 7 7 temperature calibration enabled +#define RADIOLIB_SX127X_IMAGE_CAL_START 0b01000000 // 6 6 start temperature calibration +#define RADIOLIB_SX127X_IMAGE_CAL_RUNNING 0b00100000 // 5 5 temperature calibration is on-going +#define RADIOLIB_SX127X_IMAGE_CAL_COMPLETE 0b00000000 // 5 5 temperature calibration finished +#define RADIOLIB_SX127X_TEMP_CHANGED 0b00001000 // 3 3 temperature changed more than TEMP_THRESHOLD since last calibration +#define RADIOLIB_SX127X_TEMP_THRESHOLD_5_DEG_C 0b00000000 // 2 1 temperature change threshold: 5 deg. C +#define RADIOLIB_SX127X_TEMP_THRESHOLD_10_DEG_C 0b00000010 // 2 1 10 deg. C (default) +#define RADIOLIB_SX127X_TEMP_THRESHOLD_15_DEG_C 0b00000100 // 2 1 15 deg. C +#define RADIOLIB_SX127X_TEMP_THRESHOLD_20_DEG_C 0b00000110 // 2 1 20 deg. C +#define RADIOLIB_SX127X_TEMP_MONITOR_ON 0b00000000 // 0 0 temperature monitoring enabled (default) +#define RADIOLIB_SX127X_TEMP_MONITOR_OFF 0b00000001 // 0 0 temperature monitoring disabled -// SX127X_REG_LOW_BAT -#define RADIOLIB_SX127X_LOW_BAT_OFF 0b00000000 // 3 3 low battery detector disabled -#define RADIOLIB_SX127X_LOW_BAT_ON 0b00001000 // 3 3 low battery detector enabled -#define RADIOLIB_SX127X_LOW_BAT_TRIM_1_695_V 0b00000000 // 2 0 battery voltage threshold: 1.695 V -#define RADIOLIB_SX127X_LOW_BAT_TRIM_1_764_V 0b00000001 // 2 0 1.764 V -#define RADIOLIB_SX127X_LOW_BAT_TRIM_1_835_V 0b00000010 // 2 0 1.835 V (default) -#define RADIOLIB_SX127X_LOW_BAT_TRIM_1_905_V 0b00000011 // 2 0 1.905 V -#define RADIOLIB_SX127X_LOW_BAT_TRIM_1_976_V 0b00000100 // 2 0 1.976 V -#define RADIOLIB_SX127X_LOW_BAT_TRIM_2_045_V 0b00000101 // 2 0 2.045 V -#define RADIOLIB_SX127X_LOW_BAT_TRIM_2_116_V 0b00000110 // 2 0 2.116 V -#define RADIOLIB_SX127X_LOW_BAT_TRIM_2_185_V 0b00000111 // 2 0 2.185 V +// RADIOLIB_SX127X_REG_LOW_BAT +#define RADIOLIB_SX127X_LOW_BAT_OFF 0b00000000 // 3 3 low battery detector disabled +#define RADIOLIB_SX127X_LOW_BAT_ON 0b00001000 // 3 3 low battery detector enabled +#define RADIOLIB_SX127X_LOW_BAT_TRIM_1_695_V 0b00000000 // 2 0 battery voltage threshold: 1.695 V +#define RADIOLIB_SX127X_LOW_BAT_TRIM_1_764_V 0b00000001 // 2 0 1.764 V +#define RADIOLIB_SX127X_LOW_BAT_TRIM_1_835_V 0b00000010 // 2 0 1.835 V (default) +#define RADIOLIB_SX127X_LOW_BAT_TRIM_1_905_V 0b00000011 // 2 0 1.905 V +#define RADIOLIB_SX127X_LOW_BAT_TRIM_1_976_V 0b00000100 // 2 0 1.976 V +#define RADIOLIB_SX127X_LOW_BAT_TRIM_2_045_V 0b00000101 // 2 0 2.045 V +#define RADIOLIB_SX127X_LOW_BAT_TRIM_2_116_V 0b00000110 // 2 0 2.116 V +#define RADIOLIB_SX127X_LOW_BAT_TRIM_2_185_V 0b00000111 // 2 0 2.185 V -// SX127X_REG_IRQ_FLAGS_1 -#define RADIOLIB_SX127X_FLAG_MODE_READY 0b10000000 // 7 7 requested mode is ready -#define RADIOLIB_SX127X_FLAG_RX_READY 0b01000000 // 6 6 reception ready (after RSSI, AGC, AFC) -#define RADIOLIB_SX127X_FLAG_TX_READY 0b00100000 // 5 5 transmission ready (after PA ramp-up) -#define RADIOLIB_SX127X_FLAG_PLL_LOCK 0b00010000 // 4 4 PLL locked -#define RADIOLIB_SX127X_FLAG_RSSI 0b00001000 // 3 3 RSSI value exceeds RSSI threshold -#define RADIOLIB_SX127X_FLAG_TIMEOUT 0b00000100 // 2 2 timeout occurred -#define RADIOLIB_SX127X_FLAG_PREAMBLE_DETECT 0b00000010 // 1 1 valid preamble was detected -#define RADIOLIB_SX127X_FLAG_SYNC_ADDRESS_MATCH 0b00000001 // 0 0 sync address matched +// RADIOLIB_SX127X_REG_IRQ_FLAGS_1 +#define RADIOLIB_SX127X_FLAG_MODE_READY 0b10000000 // 7 7 requested mode is ready +#define RADIOLIB_SX127X_FLAG_RX_READY 0b01000000 // 6 6 reception ready (after RSSI, AGC, AFC) +#define RADIOLIB_SX127X_FLAG_TX_READY 0b00100000 // 5 5 transmission ready (after PA ramp-up) +#define RADIOLIB_SX127X_FLAG_PLL_LOCK 0b00010000 // 4 4 PLL locked +#define RADIOLIB_SX127X_FLAG_RSSI 0b00001000 // 3 3 RSSI value exceeds RSSI threshold +#define RADIOLIB_SX127X_FLAG_TIMEOUT 0b00000100 // 2 2 timeout occurred +#define RADIOLIB_SX127X_FLAG_PREAMBLE_DETECT 0b00000010 // 1 1 valid preamble was detected +#define RADIOLIB_SX127X_FLAG_SYNC_ADDRESS_MATCH 0b00000001 // 0 0 sync address matched -// SX127X_REG_IRQ_FLAGS_2 -#define RADIOLIB_SX127X_FLAG_FIFO_FULL 0b10000000 // 7 7 FIFO is full -#define RADIOLIB_SX127X_FLAG_FIFO_EMPTY 0b01000000 // 6 6 FIFO is empty -#define RADIOLIB_SX127X_FLAG_FIFO_LEVEL 0b00100000 // 5 5 number of bytes in FIFO exceeds FIFO_THRESHOLD -#define RADIOLIB_SX127X_FLAG_FIFO_OVERRUN 0b00010000 // 4 4 FIFO overrun occurred -#define RADIOLIB_SX127X_FLAG_PACKET_SENT 0b00001000 // 3 3 packet was successfully sent -#define RADIOLIB_SX127X_FLAG_PAYLOAD_READY 0b00000100 // 2 2 packet was successfully received -#define RADIOLIB_SX127X_FLAG_CRC_OK 0b00000010 // 1 1 CRC check passed -#define RADIOLIB_SX127X_FLAG_LOW_BAT 0b00000001 // 0 0 battery voltage dropped below threshold +// RADIOLIB_SX127X_REG_IRQ_FLAGS_2 +#define RADIOLIB_SX127X_FLAG_FIFO_FULL 0b10000000 // 7 7 FIFO is full +#define RADIOLIB_SX127X_FLAG_FIFO_EMPTY 0b01000000 // 6 6 FIFO is empty +#define RADIOLIB_SX127X_FLAG_FIFO_LEVEL 0b00100000 // 5 5 number of bytes in FIFO exceeds FIFO_THRESHOLD +#define RADIOLIB_SX127X_FLAG_FIFO_OVERRUN 0b00010000 // 4 4 FIFO overrun occurred +#define RADIOLIB_SX127X_FLAG_PACKET_SENT 0b00001000 // 3 3 packet was successfully sent +#define RADIOLIB_SX127X_FLAG_PAYLOAD_READY 0b00000100 // 2 2 packet was successfully received +#define RADIOLIB_SX127X_FLAG_CRC_OK 0b00000010 // 1 1 CRC check passed +#define RADIOLIB_SX127X_FLAG_LOW_BAT 0b00000001 // 0 0 battery voltage dropped below threshold -// SX127X_REG_DIO_MAPPING_1 -#define RADIOLIB_SX127X_DIO0_LORA_RX_DONE 0b00000000 // 7 6 -#define RADIOLIB_SX127X_DIO0_LORA_TX_DONE 0b01000000 // 7 6 -#define RADIOLIB_SX127X_DIO0_LORA_CAD_DONE 0b10000000 // 7 6 -#define RADIOLIB_SX127X_DIO0_CONT_MODE_READY 0b11000000 // 7 6 -#define RADIOLIB_SX127X_DIO0_CONT_SYNC_ADDRESS 0b00000000 // 7 6 -#define RADIOLIB_SX127X_DIO0_CONT_RSSI_PREAMBLE_DETECT 0b01000000 // 7 6 -#define RADIOLIB_SX127X_DIO0_CONT_RX_READY 0b10000000 // 7 6 -#define RADIOLIB_SX127X_DIO0_CONT_TX_READY 0b00000000 // 7 6 -#define RADIOLIB_SX127X_DIO0_PACK_PAYLOAD_READY 0b00000000 // 7 6 -#define RADIOLIB_SX127X_DIO0_PACK_PACKET_SENT 0b00000000 // 7 6 -#define RADIOLIB_SX127X_DIO0_PACK_CRC_OK 0b01000000 // 7 6 -#define RADIOLIB_SX127X_DIO0_PACK_TEMP_CHANGE_LOW_BAT 0b11000000 // 7 6 -#define RADIOLIB_SX127X_DIO1_LORA_RX_TIMEOUT 0b00000000 // 5 4 -#define RADIOLIB_SX127X_DIO1_LORA_FHSS_CHANGE_CHANNEL 0b00010000 // 5 4 -#define RADIOLIB_SX127X_DIO1_LORA_CAD_DETECTED 0b00100000 // 5 4 -#define RADIOLIB_SX127X_DIO1_CONT_DCLK 0b00000000 // 5 4 -#define RADIOLIB_SX127X_DIO1_CONT_RSSI_PREAMBLE_DETECT 0b00010000 // 5 4 -#define RADIOLIB_SX127X_DIO1_PACK_FIFO_LEVEL 0b00000000 // 5 4 -#define RADIOLIB_SX127X_DIO1_PACK_FIFO_EMPTY 0b00010000 // 5 4 -#define RADIOLIB_SX127X_DIO1_PACK_FIFO_FULL 0b00100000 // 5 4 -#define RADIOLIB_SX127X_DIO2_LORA_FHSS_CHANGE_CHANNEL 0b00000000 // 3 2 -#define RADIOLIB_SX127X_DIO2_CONT_DATA 0b00000000 // 3 2 -#define RADIOLIB_SX127X_DIO2_PACK_FIFO_FULL 0b00000000 // 3 2 -#define RADIOLIB_SX127X_DIO2_PACK_RX_READY 0b00000100 // 3 2 -#define RADIOLIB_SX127X_DIO2_PACK_TIMEOUT 0b00001000 // 3 2 -#define RADIOLIB_SX127X_DIO2_PACK_SYNC_ADDRESS 0b00011000 // 3 2 -#define RADIOLIB_SX127X_DIO3_LORA_CAD_DONE 0b00000000 // 1 0 -#define RADIOLIB_SX127X_DIO3_LORA_VALID_HEADER 0b00000001 // 1 0 -#define RADIOLIB_SX127X_DIO3_LORA_PAYLOAD_CRC_ERROR 0b00000010 // 1 0 -#define RADIOLIB_SX127X_DIO3_CONT_TIMEOUT 0b00000000 // 1 0 -#define RADIOLIB_SX127X_DIO3_CONT_RSSI_PREAMBLE_DETECT 0b00000001 // 1 0 -#define RADIOLIB_SX127X_DIO3_CONT_TEMP_CHANGE_LOW_BAT 0b00000011 // 1 0 -#define RADIOLIB_SX127X_DIO3_PACK_FIFO_EMPTY 0b00000000 // 1 0 -#define RADIOLIB_SX127X_DIO3_PACK_TX_READY 0b00000001 // 1 0 +// RADIOLIB_SX127X_REG_DIO_MAPPING_1 +#define RADIOLIB_SX127X_DIO0_LORA_RX_DONE 0b00000000 // 7 6 +#define RADIOLIB_SX127X_DIO0_LORA_TX_DONE 0b01000000 // 7 6 +#define RADIOLIB_SX127X_DIO0_LORA_CAD_DONE 0b10000000 // 7 6 +#define RADIOLIB_SX127X_DIO0_CONT_MODE_READY 0b11000000 // 7 6 +#define RADIOLIB_SX127X_DIO0_CONT_SYNC_ADDRESS 0b00000000 // 7 6 +#define RADIOLIB_SX127X_DIO0_CONT_RSSI_PREAMBLE_DETECT 0b01000000 // 7 6 +#define RADIOLIB_SX127X_DIO0_CONT_RX_READY 0b10000000 // 7 6 +#define RADIOLIB_SX127X_DIO0_CONT_TX_READY 0b00000000 // 7 6 +#define RADIOLIB_SX127X_DIO0_PACK_PAYLOAD_READY 0b00000000 // 7 6 +#define RADIOLIB_SX127X_DIO0_PACK_PACKET_SENT 0b00000000 // 7 6 +#define RADIOLIB_SX127X_DIO0_PACK_CRC_OK 0b01000000 // 7 6 +#define RADIOLIB_SX127X_DIO0_PACK_TEMP_CHANGE_LOW_BAT 0b11000000 // 7 6 +#define RADIOLIB_SX127X_DIO1_LORA_RX_TIMEOUT 0b00000000 // 5 4 +#define RADIOLIB_SX127X_DIO1_LORA_FHSS_CHANGE_CHANNEL 0b00010000 // 5 4 +#define RADIOLIB_SX127X_DIO1_LORA_CAD_DETECTED 0b00100000 // 5 4 +#define RADIOLIB_SX127X_DIO1_CONT_DCLK 0b00000000 // 5 4 +#define RADIOLIB_SX127X_DIO1_CONT_RSSI_PREAMBLE_DETECT 0b00010000 // 5 4 +#define RADIOLIB_SX127X_DIO1_PACK_FIFO_LEVEL 0b00000000 // 5 4 +#define RADIOLIB_SX127X_DIO1_PACK_FIFO_EMPTY 0b00010000 // 5 4 +#define RADIOLIB_SX127X_DIO1_PACK_FIFO_FULL 0b00100000 // 5 4 +#define RADIOLIB_SX127X_DIO2_LORA_FHSS_CHANGE_CHANNEL 0b00000000 // 3 2 +#define RADIOLIB_SX127X_DIO2_CONT_DATA 0b00000000 // 3 2 +#define RADIOLIB_SX127X_DIO2_PACK_FIFO_FULL 0b00000000 // 3 2 +#define RADIOLIB_SX127X_DIO2_PACK_RX_READY 0b00000100 // 3 2 +#define RADIOLIB_SX127X_DIO2_PACK_TIMEOUT 0b00001000 // 3 2 +#define RADIOLIB_SX127X_DIO2_PACK_SYNC_ADDRESS 0b00011000 // 3 2 +#define RADIOLIB_SX127X_DIO3_LORA_CAD_DONE 0b00000000 // 1 0 +#define RADIOLIB_SX127X_DIO3_LORA_VALID_HEADER 0b00000001 // 1 0 +#define RADIOLIB_SX127X_DIO3_LORA_PAYLOAD_CRC_ERROR 0b00000010 // 1 0 +#define RADIOLIB_SX127X_DIO3_CONT_TIMEOUT 0b00000000 // 1 0 +#define RADIOLIB_SX127X_DIO3_CONT_RSSI_PREAMBLE_DETECT 0b00000001 // 1 0 +#define RADIOLIB_SX127X_DIO3_CONT_TEMP_CHANGE_LOW_BAT 0b00000011 // 1 0 +#define RADIOLIB_SX127X_DIO3_PACK_FIFO_EMPTY 0b00000000 // 1 0 +#define RADIOLIB_SX127X_DIO3_PACK_TX_READY 0b00000001 // 1 0 -// SX127X_REG_DIO_MAPPING_2 -#define RADIOLIB_SX127X_DIO4_LORA_CAD_DETECTED 0b10000000 // 7 6 -#define RADIOLIB_SX127X_DIO4_LORA_PLL_LOCK 0b01000000 // 7 6 -#define RADIOLIB_SX127X_DIO4_CONT_TEMP_CHANGE_LOW_BAT 0b00000000 // 7 6 -#define RADIOLIB_SX127X_DIO4_CONT_PLL_LOCK 0b01000000 // 7 6 -#define RADIOLIB_SX127X_DIO4_CONT_TIMEOUT 0b10000000 // 7 6 -#define RADIOLIB_SX127X_DIO4_CONT_MODE_READY 0b11000000 // 7 6 -#define RADIOLIB_SX127X_DIO4_PACK_TEMP_CHANGE_LOW_BAT 0b00000000 // 7 6 -#define RADIOLIB_SX127X_DIO4_PACK_PLL_LOCK 0b01000000 // 7 6 -#define RADIOLIB_SX127X_DIO4_PACK_TIMEOUT 0b10000000 // 7 6 -#define RADIOLIB_SX127X_DIO4_PACK_RSSI_PREAMBLE_DETECT 0b11000000 // 7 6 -#define RADIOLIB_SX127X_DIO5_LORA_MODE_READY 0b00000000 // 5 4 -#define RADIOLIB_SX127X_DIO5_LORA_CLK_OUT 0b00010000 // 5 4 -#define RADIOLIB_SX127X_DIO5_CONT_CLK_OUT 0b00000000 // 5 4 -#define RADIOLIB_SX127X_DIO5_CONT_PLL_LOCK 0b00010000 // 5 4 -#define RADIOLIB_SX127X_DIO5_CONT_RSSI_PREAMBLE_DETECT 0b00100000 // 5 4 -#define RADIOLIB_SX127X_DIO5_CONT_MODE_READY 0b00110000 // 5 4 -#define RADIOLIB_SX127X_DIO5_PACK_CLK_OUT 0b00000000 // 5 4 -#define RADIOLIB_SX127X_DIO5_PACK_PLL_LOCK 0b00010000 // 5 4 -#define RADIOLIB_SX127X_DIO5_PACK_DATA 0b00100000 // 5 4 -#define RADIOLIB_SX127X_DIO5_PACK_MODE_READY 0b00110000 // 5 4 -#define RADIOLIB_SX127X_DIO_MAP_PREAMBLE_DETECT 0b00000001 // 0 0 -#define RADIOLIB_SX127X_DIO_MAP_RSSI 0b00000000 // 0 0 +// RADIOLIB_SX127X_REG_DIO_MAPPING_2 +#define RADIOLIB_SX127X_DIO4_LORA_CAD_DETECTED 0b10000000 // 7 6 +#define RADIOLIB_SX127X_DIO4_LORA_PLL_LOCK 0b01000000 // 7 6 +#define RADIOLIB_SX127X_DIO4_CONT_TEMP_CHANGE_LOW_BAT 0b00000000 // 7 6 +#define RADIOLIB_SX127X_DIO4_CONT_PLL_LOCK 0b01000000 // 7 6 +#define RADIOLIB_SX127X_DIO4_CONT_TIMEOUT 0b10000000 // 7 6 +#define RADIOLIB_SX127X_DIO4_CONT_MODE_READY 0b11000000 // 7 6 +#define RADIOLIB_SX127X_DIO4_PACK_TEMP_CHANGE_LOW_BAT 0b00000000 // 7 6 +#define RADIOLIB_SX127X_DIO4_PACK_PLL_LOCK 0b01000000 // 7 6 +#define RADIOLIB_SX127X_DIO4_PACK_TIMEOUT 0b10000000 // 7 6 +#define RADIOLIB_SX127X_DIO4_PACK_RSSI_PREAMBLE_DETECT 0b11000000 // 7 6 +#define RADIOLIB_SX127X_DIO5_LORA_MODE_READY 0b00000000 // 5 4 +#define RADIOLIB_SX127X_DIO5_LORA_CLK_OUT 0b00010000 // 5 4 +#define RADIOLIB_SX127X_DIO5_CONT_CLK_OUT 0b00000000 // 5 4 +#define RADIOLIB_SX127X_DIO5_CONT_PLL_LOCK 0b00010000 // 5 4 +#define RADIOLIB_SX127X_DIO5_CONT_RSSI_PREAMBLE_DETECT 0b00100000 // 5 4 +#define RADIOLIB_SX127X_DIO5_CONT_MODE_READY 0b00110000 // 5 4 +#define RADIOLIB_SX127X_DIO5_PACK_CLK_OUT 0b00000000 // 5 4 +#define RADIOLIB_SX127X_DIO5_PACK_PLL_LOCK 0b00010000 // 5 4 +#define RADIOLIB_SX127X_DIO5_PACK_DATA 0b00100000 // 5 4 +#define RADIOLIB_SX127X_DIO5_PACK_MODE_READY 0b00110000 // 5 4 +#define RADIOLIB_SX127X_DIO_MAP_PREAMBLE_DETECT 0b00000001 // 0 0 +#define RADIOLIB_SX127X_DIO_MAP_RSSI 0b00000000 // 0 0 // SX1272_REG_PLL_HOP + SX1278_REG_PLL_HOP -#define RADIOLIB_SX127X_FAST_HOP_OFF 0b00000000 // 7 7 carrier frequency validated when FRF registers are written -#define RADIOLIB_SX127X_FAST_HOP_ON 0b10000000 // 7 7 carrier frequency validated when FS modes are requested +#define RADIOLIB_SX127X_FAST_HOP_OFF 0b00000000 // 7 7 carrier frequency validated when FRF registers are written +#define RADIOLIB_SX127X_FAST_HOP_ON 0b10000000 // 7 7 carrier frequency validated when FS modes are requested // SX1272_REG_TCXO + SX1278_REG_TCXO -#define RADIOLIB_SX127X_TCXO_INPUT_EXTERNAL 0b00000000 // 4 4 use external crystal oscillator -#define RADIOLIB_SX127X_TCXO_INPUT_EXTERNAL_CLIPPED 0b00010000 // 4 4 use external crystal oscillator clipped sine connected to XTA pin +#define RADIOLIB_SX127X_TCXO_INPUT_EXTERNAL 0b00000000 // 4 4 use external crystal oscillator +#define RADIOLIB_SX127X_TCXO_INPUT_EXTERNAL_CLIPPED 0b00010000 // 4 4 use external crystal oscillator clipped sine connected to XTA pin // SX1272_REG_PLL + SX1278_REG_PLL -#define RADIOLIB_SX127X_PLL_BANDWIDTH_75_KHZ 0b00000000 // 7 6 PLL bandwidth: 75 kHz -#define RADIOLIB_SX127X_PLL_BANDWIDTH_150_KHZ 0b01000000 // 7 6 150 kHz -#define RADIOLIB_SX127X_PLL_BANDWIDTH_225_KHZ 0b10000000 // 7 6 225 kHz -#define RADIOLIB_SX127X_PLL_BANDWIDTH_300_KHZ 0b11000000 // 7 6 300 kHz (default) +#define RADIOLIB_SX127X_PLL_BANDWIDTH_75_KHZ 0b00000000 // 7 6 PLL bandwidth: 75 kHz +#define RADIOLIB_SX127X_PLL_BANDWIDTH_150_KHZ 0b01000000 // 7 6 150 kHz +#define RADIOLIB_SX127X_PLL_BANDWIDTH_225_KHZ 0b10000000 // 7 6 225 kHz +#define RADIOLIB_SX127X_PLL_BANDWIDTH_300_KHZ 0b11000000 // 7 6 300 kHz (default) /*! \class SX127x - \brief Base class for SX127x series. All derived classes for SX127x (e.g. SX1278 or SX1272) inherit from this base class. This class should not be instantiated directly from Arduino sketch, only from its derived classes. */ @@ -592,7 +591,6 @@ class SX127x: public PhysicalLayer { /*! \brief Default constructor. Called internally when creating new LoRa instance. - \param mod Instance of Module that will be used to communicate with the %LoRa chip. */ SX127x(Module* mod); @@ -603,13 +601,9 @@ 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 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); @@ -621,17 +615,11 @@ 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 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); @@ -639,13 +627,9 @@ class SX127x: public PhysicalLayer { /*! \brief Binary transmit method. Will transmit arbitrary binary data up to 255 bytes long using %LoRa or up to 63 bytes using FSK modem. For overloads to transmit Arduino String or C-string, see PhysicalLayer::transmit. - \param data Binary data that will be transmitted. - \param len Length of binary data to transmit (in bytes). - \param addr Node address to transmit the packet to. Only used in FSK mode. - \returns \ref status_codes */ int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override; @@ -653,18 +637,14 @@ class SX127x: public PhysicalLayer { /*! \brief Binary receive method. Will attempt to receive arbitrary binary data up to 255 bytes long using %LoRa or up to 63 bytes using FSK modem. For overloads to receive Arduino String, see PhysicalLayer::receive. - \param data Pointer to array to save the received binary data. - \param len Number of bytes that will be received. Must be known in advance for binary transmissions. - \returns \ref status_codes */ int16_t receive(uint8_t* data, size_t len) override; /*! \brief Performs scan for valid %LoRa preamble in the current channel. - \returns \ref status_codes */ int16_t scanChannel(); @@ -672,23 +652,19 @@ class SX127x: public PhysicalLayer { /*! \brief Sets the %LoRa module to sleep to save power. %Module will not be able to transmit or receive any data while in sleep mode. %Module will wake up automatically when methods like transmit or receive are called. - \returns \ref status_codes */ int16_t sleep(); /*! \brief Sets the %LoRa module to standby. - \returns \ref status_codes */ int16_t standby() override; /*! \brief Sets the %LoRa module to standby. - \param mode Standby mode to be used. No effect, implemented only for PhysicalLayer compatibility. - \returns \ref status_codes */ int16_t standby(uint8_t mode) override; @@ -696,9 +672,7 @@ class SX127x: public PhysicalLayer { /*! \brief Enables direct transmission mode on pins DIO1 (clock) and DIO2 (data). While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode. - \param frf 24-bit raw frequency value to start transmitting at. Required for quick frequency shifts in RTTY. - \returns \ref status_codes */ int16_t transmitDirect(uint32_t frf = 0) override; @@ -706,14 +680,12 @@ class SX127x: public PhysicalLayer { /*! \brief Enables direct reception mode on pins DIO1 (clock) and DIO2 (data). While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode. - \returns \ref status_codes */ int16_t receiveDirect() override; /*! \brief Disables direct mode and enables packet mode, allowing the module to receive packets. Can only be activated in FSK mode. - \returns \ref status_codes */ int16_t packetMode(); @@ -722,9 +694,7 @@ class SX127x: public PhysicalLayer { /*! \brief Set interrupt service routine function to call when DIO0 activates. - \param func Pointer to interrupt service routine. - \param dir Signal change direction. */ void setDio0Action(void (*func)(void), uint32_t dir); @@ -736,9 +706,7 @@ class SX127x: public PhysicalLayer { /*! \brief Set interrupt service routine function to call when DIO1 activates. - \param func Pointer to interrupt service routine. - \param dir Signal change direction. */ void setDio1Action(void (*func)(void), uint32_t dir); @@ -750,7 +718,6 @@ class SX127x: public PhysicalLayer { /*! \brief Set interrupt service routine function to call when FIFO is empty. - \param func Pointer to interrupt service routine. */ void setFifoEmptyAction(void (*func)(void)); @@ -762,7 +729,6 @@ class SX127x: public PhysicalLayer { /*! \brief Set interrupt service routine function to call when FIFO is full. - \param func Pointer to interrupt service routine. */ void setFifoFullAction(void (*func)(void)); @@ -774,84 +740,60 @@ class SX127x: public PhysicalLayer { /*! \brief Set interrupt service routine function to call when FIFO is empty. - \param data Pointer to the transmission buffer. - \param totalLen Total number of bytes to transmit. - \param remLen Pointer to a counter holding the number of bytes that have been transmitted so far. - \returns True when a complete packet is sent, false if more data is needed. */ bool fifoAdd(uint8_t* data, int totalLen, int* remLen); /*! \brief Set interrupt service routine function to call when FIFO is sufficently full to read. - \param data Pointer to a buffer that stores the receive data. - \param totalLen Total number of bytes to receive. - \param rcvLen Pointer to a counter holding the number of bytes that have been received so far. - \returns True when a complete packet is received, false if more data is needed. */ bool fifoGet(volatile uint8_t* data, int totalLen, volatile int* rcvLen); /*! \brief Interrupt-driven binary transmit method. Will start transmitting arbitrary binary data up to 255 bytes long using %LoRa or up to 63 bytes using FSK modem. - \param data Binary data that will be transmitted. - \param len Length of binary data to transmit (in bytes). - \param addr Node address to transmit the packet to. Only used in FSK mode. - \returns \ref status_codes */ int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override; /*! \brief Clean up after transmission is done. - \returns \ref status_codes */ int16_t finishTransmit() override; /*! \brief Interrupt-driven receive method. DIO0 will be activated when full valid packet is received. - \param len Expected length of packet to be received. Required for LoRa spreading factor 6. - \param mode Receive mode to be used. Defaults to RxContinuous. - \returns \ref status_codes */ int16_t startReceive(uint8_t len = 0, uint8_t mode = RADIOLIB_SX127X_RXCONTINUOUS); /*! \brief Interrupt-driven receive method, implemented for compatibility with PhysicalLayer. - \param mode Receive mode to be used. - \param irqFlags Ignored. - \param irqMask Ignored. - \param len Expected length of packet to be received. Required for LoRa spreading factor 6. - \returns \ref status_codes */ int16_t startReceive(uint32_t mode, uint16_t irqFlags, uint16_t irqMask, size_t len); /*! \brief Reads data that was received after calling startReceive method. This method reads len characters. - \param data Pointer to array to save the received binary data. - \param len Number of bytes that will be read. When set to 0, the packet length will be retreived automatically. When more bytes than received are requested, only the number of bytes requested will be returned. - \returns \ref status_codes */ int16_t readData(uint8_t* data, size_t len) override; @@ -859,7 +801,6 @@ class SX127x: public PhysicalLayer { /*! \brief Interrupt-driven channel activity detection method. DIO0 will be activated when LoRa preamble is detected. DIO1 will be activated if there's no preamble detected before timeout. - \returns \ref status_codes */ int16_t startChannelScan(); @@ -868,264 +809,208 @@ class SX127x: public PhysicalLayer { /*! \brief Sets %LoRa sync word. Only available in %LoRa mode. - \param syncWord Sync word to be set. - \returns \ref status_codes */ int16_t setSyncWord(uint8_t syncWord); /*! \brief Sets current limit for over current protection at transmitter amplifier. Allowed values range from 45 to 120 mA in 5 mA steps and 120 to 240 mA in 10 mA steps. - \param currentLimit Current limit to be set (in mA). - \returns \ref status_codes */ int16_t setCurrentLimit(uint8_t currentLimit); /*! \brief Sets %LoRa or FSK preamble length. Allowed values range from 6 to 65535 in %LoRa mode or 0 to 65535 in FSK mode. - \param preambleLength Preamble length to be set (in symbols when in LoRa mode or bits in FSK mode). - \returns \ref status_codes */ int16_t setPreambleLength(uint16_t preambleLength); /*! \brief Gets frequency error of the latest received packet. - \param autoCorrect When set to true, frequency will be automatically corrected. - \returns Frequency error in Hz. */ float getFrequencyError(bool autoCorrect = false); /*! \brief Gets current AFC error. - \returns Frequency offset from RF in Hz if AFC is enabled and triggered, zero otherwise. */ float getAFCError(); /*! \brief Gets signal-to-noise ratio of the latest received packet. Only available in LoRa mode. - \returns Last packet signal-to-noise ratio (SNR). */ float getSNR(); /*! \brief Get data rate of the latest transmitted packet. - \returns Last packet data rate in bps (bits per second). */ float getDataRate() const; /*! \brief Sets FSK frequency deviation from carrier frequency. Allowed values depend on bit rate setting and must be lower than 200 kHz. Only available in FSK mode. - \param freqDev Frequency deviation to be set (in kHz). - \returns \ref status_codes */ int16_t setFrequencyDeviation(float freqDev) override; /*! \brief Sets FSK receiver bandwidth. Allowed values range from 2.6 to 250 kHz. Only available in FSK mode. - \param rxBw Receiver bandwidth to be set (in kHz). - \returns \ref status_codes */ int16_t setRxBandwidth(float rxBw); /*! \brief Sets FSK automatic frequency correction bandwidth. Allowed values range from 2.6 to 250 kHz. Only available in FSK mode. - \param rxBw Receiver AFC bandwidth to be set (in kHz). - \returns \ref status_codes */ int16_t setAFCBandwidth(float afcBw); /*! \brief Enables or disables FSK automatic frequency correction(AFC) - \param isEnabled AFC enabled or disabled - \return \ref status_codes */ int16_t setAFC(bool isEnabled); /*! \brief Controls trigger of AFC and AGC - \param trigger one from SX127X_RX_TRIGGER_NONE, SX127X_RX_TRIGGER_RSSI_INTERRUPT, SX127X_RX_TRIGGER_PREAMBLE_DETECT, SX127X_RX_TRIGGER_BOTH - \return \ref status_codes */ int16_t setAFCAGCTrigger(uint8_t trigger); /*! \brief Sets FSK sync word. Allowed sync words are up to 8 bytes long and can not contain null bytes. Only available in FSK mode. - \param syncWord Sync word array. - \param len Sync word length (in bytes). - \returns \ref status_codes */ int16_t setSyncWord(uint8_t* syncWord, size_t len); /*! \brief Sets FSK node address. Calling this method will enable address filtering. Only available in FSK mode. - \param nodeAddr Node address to be set. - \returns \ref status_codes */ int16_t setNodeAddress(uint8_t nodeAddr); /*! \brief Sets FSK broadcast address. Calling this method will enable address filtering. Only available in FSK mode. - \param broadAddr Broadcast address to be set. - \returns \ref status_codes */ int16_t setBroadcastAddress(uint8_t broadAddr); /*! \brief Disables FSK address filtering. - \returns \ref status_codes */ int16_t disableAddressFiltering(); /*! \brief Enables/disables OOK modulation instead of FSK. - \param enableOOK Enable (true) or disable (false) OOK. - \returns \ref status_codes */ int16_t setOOK(bool enableOOK); /*! \brief Selects the type of threshold in the OOK data slicer. - \param type Threshold type: SX127X_OOK_THRESH_PEAK(default), SX127X_OOK_THRESH_FIXED, SX127X_OOK_THRESH_AVERAGE - \returns \ref status_codes */ int16_t setOokThresholdType(uint8_t type); /*! \brief Period of decrement of the RSSI threshold in the OOK demodulator. - \param value Use defines RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_X_X_CHIP - \returns \ref status_codes */ int16_t setOokPeakThresholdDecrement(uint8_t value); /*! \brief Fixed threshold for the Data Slicer in OOK mode or floor threshold for the Data Slicer in OOK when Peak mode is used. - \param value Threshold level in steps of 0.5 dB. - \returns \ref status_codes */ int16_t setOokFixedOrFloorThreshold(uint8_t value); - /*! + /*! \brief Size of each decrement of the RSSI threshold in the OOK demodulator. - \param value Step size: RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_0_5_DB (default), RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_1_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_1_5_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_2_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_3_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_4_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_5_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_6_0_DB - \returns \ref status_codes */ int16_t setOokPeakThresholdStep(uint8_t value); /*! - \brief Enable Bit synchronizer. - - \returns \ref status_codes + \brief Enable Bit synchronizer. + \returns \ref status_codes */ int16_t enableBitSync(); /*! \brief Disable Bit synchronizer (not allowed in Packet mode). - \returns \ref status_codes */ int16_t disableBitSync(); /*! \brief Query modem for the packet length of received payload. - \param update Update received packet length. Will return cached value when set to false. - \returns Length of last received packet in bytes. */ size_t getPacketLength(bool update = true) override; /*! - \brief Set modem in fixed packet length mode. Available in FSK mode only. - - \param len Packet length. - - \returns \ref status_codes - */ - int16_t fixedPacketLengthMode(uint8_t len = RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK); + \brief Set modem in fixed packet length mode. Available in FSK mode only. + \param len Packet length. + \returns \ref status_codes + */ + int16_t fixedPacketLengthMode(uint8_t len = RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK); /*! - \brief Set modem in variable packet length mode. Available in FSK mode only. - - \param len Maximum packet length. - - \returns \ref status_codes - */ - int16_t variablePacketLengthMode(uint8_t maxLen = RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK); - - /*! - \brief Get expected time-on-air for a given size of payload - - \param len Payload length in bytes. - - \returns Expected time-on-air in microseconds. - */ - uint32_t getTimeOnAir(size_t len); - - /*! - \brief Enable CRC filtering and generation. - - \param crcOn Set or unset CRC filtering and generation. - + \brief Set modem in variable packet length mode. Available in FSK mode only. + \param len Maximum packet length. \returns \ref status_codes - */ - int16_t setCrcFiltering(bool crcOn = true); + */ + int16_t variablePacketLengthMode(uint8_t maxLen = RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK); + + /*! + \brief Get expected time-on-air for a given size of payload + \param len Payload length in bytes. + \returns Expected time-on-air in microseconds. + */ + uint32_t getTimeOnAir(size_t len); + + /*! + \brief Enable CRC filtering and generation. + \param enable Set or unset CRC filtering and generation. + \returns \ref status_codes + */ + int16_t setCrcFiltering(bool enable = true); /*! \brief Sets RSSI measurement configuration in FSK mode. - \param smoothingSamples Number of samples taken to average the RSSI result. numSamples = 2 ^ (1 + smoothingSamples), allowed values are in range 0 (2 samples) - 7 (256 samples) - \param offset Signed RSSI offset that will be automatically compensated. 1 dB per LSB, defaults to 0, allowed values are in range -16 dB to +15 dB. - \returns \ref status_codes */ int16_t setRSSIConfig(uint8_t smoothingSamples, int8_t offset = 0); /*! \brief Sets transmission encoding. Only available in FSK mode. - Allowed values are RADIOLIB_ENCODING_NRZ, RADIOLIB_ENCODING_MANCHESTER and RADIOLIB_ENCODING_WHITENING. - + Allowed values are RADIOLIB_ENCODING_NRZ, RADIOLIB_ENCODING_MANCHESTER and RADIOLIB_ENCODING_WHITENING. \param encoding Encoding to be used. - \returns \ref status_codes */ int16_t setEncoding(uint8_t encoding) override; @@ -1134,14 +1019,12 @@ class SX127x: public PhysicalLayer { \brief Reads currently active IRQ flags, can be used to check which event caused an interrupt. In LoRa mode, this is the content of SX127X_REG_IRQ_FLAGS register. In FSK mode, this is the contents of SX127X_REG_IRQ_FLAGS_2 (MSB) and SX127X_REG_IRQ_FLAGS_1 (LSB) registers. - \returns IRQ flags. */ uint16_t getIRQFlags(); /*! \brief Reads modem status. Only available in LoRa mode. - \returns Modem status. */ uint8_t getModemStatus(); @@ -1149,7 +1032,6 @@ class SX127x: public PhysicalLayer { /*! \brief Reads uncalibrated temperature value. This function will change operating mode and should not be called during Tx, Rx or CAD. - \returns Uncalibrated temperature sensor reading. */ int8_t getTempRaw(); @@ -1161,24 +1043,20 @@ class SX127x: public PhysicalLayer { void setRfSwitchTable(const uint32_t (&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[]); /*! - \brief Get one truly random byte from RSSI noise. - - \returns TRNG byte. - */ + \brief Get one truly random byte from RSSI noise. + \returns TRNG byte. + */ uint8_t randomByte(); /*! - \brief Read version SPI register. Should return SX1278_CHIP_VERSION (0x12) or SX1272_CHIP_VERSION (0x22) if SX127x is connected and working. - - \returns Version register contents or \ref status_codes - */ + \brief Read version SPI register. Should return SX1278_CHIP_VERSION (0x12) or SX1272_CHIP_VERSION (0x22) if SX127x is connected and working. + \returns Version register contents or \ref status_codes + */ int16_t getChipVersion(); /*! \brief Enable/disable inversion of the I and Q signals - \param invertIQ QI inversion enabled (true) or disabled (false); - \returns \ref status_codes */ int16_t invertIQ(bool invertIQ); @@ -1186,14 +1064,12 @@ class SX127x: public PhysicalLayer { #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE) /*! \brief Set interrupt service routine function to call when data bit is receveid in direct mode. - \param func Pointer to interrupt service routine. */ void setDirectAction(void (*func)(void)); /*! \brief Function to read and process data bit in direct reception mode. - \param pin Pin on which to read. */ void readBit(uint32_t pin); @@ -1201,23 +1077,19 @@ class SX127x: public PhysicalLayer { /*! \brief Sets the hopping period and enables FHSS - \param freqHoppingPeriod Integer multiple of symbol periods between hops - \returns \ref status_codes */ int16_t setFHSSHoppingPeriod(uint8_t freqHoppingPeriod); - /*! + /*! \brief Gets FHSS hopping period - \returns 8 bit period */ uint8_t getFHSSHoppingPeriod(void); /*! \brief Gets the FHSS channel in use - \returns 6 bit channel number */ uint8_t getFHSSChannel(void); @@ -1229,40 +1101,30 @@ class SX127x: public PhysicalLayer { /*! \brief Configure DIO pin mapping to get a given signal on a DIO pin (if available). - \param pin Pin number onto which a signal is to be placed. - \param value The value that indicates which function to place on that pin. See chip datasheet for details. - \returns \ref status_codes */ int16_t setDIOMapping(uint32_t pin, uint32_t value); /*! \brief Configure DIO mapping to use RSSI or Preamble Detect for pins that support it. - \param usePreambleDetect Whether to use PreambleDetect (true) or RSSI (false) on the pins that are mapped to this function. - \returns \ref status_codes */ int16_t setDIOPreambleDetect(bool usePreambleDetect); /*! \brief Gets recorded signal strength indicator. - \param packet Whether to read last packet RSSI, or the current value. LoRa mode only, ignored for FSK. - \param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FSK/OOK mode. - \returns RSSI value in dBm. */ float getRSSI(bool packet, bool skipReceive, int16_t offset); /*! \brief Sets the RSSI value above which the RSSI interrupt is signaled - \param dbm A dBm value between -127.5 and 0 inclusive - \returns \ref status_codes */ int16_t setRSSIThreshold(float dbm); @@ -1270,21 +1132,21 @@ class SX127x: public PhysicalLayer { #if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL) protected: #endif - Module* _mod; + Module* mod; #if !defined(RADIOLIB_GODMODE) protected: #endif - float _freq = 0; - float _bw = 0; - uint8_t _sf = 0; - uint8_t _cr = 0; - float _br = 0; - bool _ook = false; - bool _crcEnabled = false; - bool _crcOn = true; // default value used in FSK mode - size_t _packetLength = 0; + float frequency = 0; + float bandwidth = 0; + uint8_t spreadingFactor = 0; + uint8_t codingRate = 0; + float bitRate = 0; + bool ookEnabled = false; + bool crcEnabled = false; + bool crcOn = true; // default value used in FSK mode + size_t packetLength = 0; int16_t setFrequencyRaw(float newFreq); int16_t setBitRateCommon(float br, uint8_t fracRegAddr); @@ -1297,22 +1159,21 @@ class SX127x: public PhysicalLayer { #if !defined(RADIOLIB_GODMODE) private: #endif - float _dataRate = 0; - 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; + float dataRate = 0; + 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); int16_t setMode(uint8_t mode); int16_t setActiveModem(uint8_t modem); void clearIRQFlags(); void clearFIFO(size_t count); // used mostly to clear remaining bytes in FIFO after a packet read - /** - * @brief Calculate exponent and mantissa values for receiver bandwidth and AFC - * - * \param bandwidth bandwidth to be set (in kHz). - * - * \returns bandwidth in manitsa and exponent format - */ + + /*! + \brief Calculate exponent and mantissa values for receiver bandwidth and AFC + \param bandwidth bandwidth to be set (in kHz). + \returns bandwidth in manitsa and exponent format + */ static uint8_t calculateBWManExp(float bandwidth); virtual void errataFix(bool rx) = 0;