diff --git a/src/modules/LLCC68/LLCC68.cpp b/src/modules/LLCC68/LLCC68.cpp index a0d077aa..1a087c40 100644 --- a/src/modules/LLCC68/LLCC68.cpp +++ b/src/modules/LLCC68/LLCC68.cpp @@ -2,7 +2,7 @@ #if !defined(RADIOLIB_EXCLUDE_SX126X) LLCC68::LLCC68(Module* mod) : SX1262(mod) { - _chipType = RADIOLIB_LLCC68_CHIP_TYPE; + chipType = RADIOLIB_LLCC68_CHIP_TYPE; } int16_t LLCC68::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { @@ -35,7 +35,7 @@ int16_t LLCC68::setBandwidth(float bw) { } int16_t LLCC68::setSpreadingFactor(uint8_t sf) { - switch(SX126x::_bw) { + switch(SX126x::bandwidth) { case RADIOLIB_SX126X_LORA_BW_125_0: RADIOLIB_CHECK_RANGE(sf, 5, 9, RADIOLIB_ERR_INVALID_SPREADING_FACTOR); break; diff --git a/src/modules/LLCC68/LLCC68.h b/src/modules/LLCC68/LLCC68.h index 424563ad..d735aab1 100644 --- a/src/modules/LLCC68/LLCC68.h +++ b/src/modules/LLCC68/LLCC68.h @@ -9,43 +9,31 @@ #include "../SX126x/SX1262.h" //RADIOLIB_SX126X_REG_VERSION_STRING -#define RADIOLIB_LLCC68_CHIP_TYPE "LLCC68" +#define RADIOLIB_LLCC68_CHIP_TYPE "LLCC68" /*! \class LLCC68 - \brief Derived class for %LLCC68 modules. */ class LLCC68: public SX1262 { public: /*! \brief Default constructor. - \param mod Instance of Module that will be used to communicate with the radio. */ LLCC68(Module* mod); /*! \brief Initialization method for LoRa modem. - \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. - \param bw LoRa bandwidth in kHz. Defaults to 125.0 kHz. - \param sf LoRa spreading factor. Defaults to 9. - \param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7). - \param syncWord 1-byte LoRa sync word. Defaults to RADIOLIB_SX126X_SYNC_WORD_PRIVATE (0x12). - \param power Output power in dBm. Defaults to 10 dBm. - \param preambleLength LoRa preamble length in symbols. Defaults to 8 symbols. - \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. - \param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false. - \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_SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); @@ -54,18 +42,14 @@ class LLCC68: public SX1262 { /*! \brief Sets LoRa bandwidth. Allowed values are 125.0, 250.0 and 500.0 kHz. - \param bw LoRa bandwidth to be set in kHz. - \returns \ref status_codes */ int16_t setBandwidth(float bw); /*! \brief Sets LoRa spreading factor. Allowed values range from 5 to 11, depending on currently set spreading factor. - \param sf LoRa spreading factor to be set. - \returns \ref status_codes */ int16_t setSpreadingFactor(uint8_t sf); diff --git a/src/modules/SX126x/STM32WLx.cpp b/src/modules/SX126x/STM32WLx.cpp index 5a88d8c1..dcc8c822 100644 --- a/src/modules/SX126x/STM32WLx.cpp +++ b/src/modules/SX126x/STM32WLx.cpp @@ -1,5 +1,4 @@ /* - Copyright (c) 2018 Jan Gromeš Copyright (c) 2022 STMicroelectronics @@ -9,8 +8,7 @@ This file is licensed under the MIT License: https://opensource.org/licenses/MIT #include "STM32WLx.h" #if !defined(RADIOLIB_EXCLUDE_STM32WLX) -STM32WLx::STM32WLx(STM32WLx_Module* mod) : SX1262(mod) { -} +STM32WLx::STM32WLx(STM32WLx_Module* mod) : SX1262(mod) { } int16_t STM32WLx::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { // Execute common part @@ -47,18 +45,18 @@ int16_t STM32WLx::setOutputPower(int8_t power) { RADIOLIB_ASSERT(state); // Use HP only if available and needed for the requested power - bool hp_supported = _mod->findRfSwitchMode(MODE_TX_HP); + bool hp_supported = this->mod->findRfSwitchMode(MODE_TX_HP); bool use_hp = power > 14 && hp_supported; // set PA config. if(use_hp) { RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER); state = SX126x::setPaConfig(0x04, 0x00, 0x07); // HP output up to 22dBm - _tx_mode = MODE_TX_HP; + this->txMode = MODE_TX_HP; } else { RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER); state = SX126x::setPaConfig(0x04, 0x01, 0x00); // LP output up to 14dBm - _tx_mode = MODE_TX_LP; + this->txMode = MODE_TX_LP; } RADIOLIB_ASSERT(state); diff --git a/src/modules/SX126x/STM32WLx.h b/src/modules/SX126x/STM32WLx.h index 0618dd43..742d8c8c 100644 --- a/src/modules/SX126x/STM32WLx.h +++ b/src/modules/SX126x/STM32WLx.h @@ -1,5 +1,4 @@ /* - Copyright (c) 2018 Jan Gromeš Copyright (c) 2022 STMicroelectronics @@ -38,18 +37,17 @@ class STM32WLx : public SX1262 { public: /*! \brief Default constructor. - \param mod Instance of STM32WLx_Module that will be used to communicate with the radio. */ STM32WLx(STM32WLx_Module* mod); /*! - * \brief Custom operation modes for STMWLx. - * - * This splits the TX mode into two modes: Low-power and high-power. - * These constants can be used with the setRfSwitchTable() method, - * instead of the Module::OpMode_t constants. - */ + \brief Custom operation modes for STMWLx. + + This splits the TX mode into two modes: Low-power and high-power. + These constants can be used with the setRfSwitchTable() method, + instead of the Module::OpMode_t constants. + */ enum OpMode_t { /*! End of table marker, use \ref END_OF_MODE_TABLE constant instead */ MODE_END_OF_TABLE = Module::MODE_END_OF_TABLE, @@ -112,7 +110,6 @@ class STM32WLx : public SX1262 { /*! \brief Sets interrupt service routine to call when DIO1/2/3 activates. - \param func ISR to call. */ void setDio1Action(void (*func)(void)); diff --git a/src/modules/SX126x/SX1261.cpp b/src/modules/SX126x/SX1261.cpp index 41237b67..999f4f9f 100644 --- a/src/modules/SX126x/SX1261.cpp +++ b/src/modules/SX126x/SX1261.cpp @@ -2,7 +2,7 @@ #if !defined(RADIOLIB_EXCLUDE_SX126X) SX1261::SX1261(Module* mod): SX1262(mod) { - _chipType = RADIOLIB_SX1261_CHIP_TYPE; + chipType = RADIOLIB_SX1261_CHIP_TYPE; } int16_t SX1261::setOutputPower(int8_t power) { diff --git a/src/modules/SX126x/SX1261.h b/src/modules/SX126x/SX1261.h index 13c5ff7d..8d7663e5 100644 --- a/src/modules/SX126x/SX1261.h +++ b/src/modules/SX126x/SX1261.h @@ -10,30 +10,26 @@ #include "SX1262.h" //RADIOLIB_SX126X_CMD_SET_PA_CONFIG -#define RADIOLIB_SX126X_PA_CONFIG_SX1261 0x01 +#define RADIOLIB_SX126X_PA_CONFIG_SX1261 0x01 //RADIOLIB_SX126X_REG_VERSION_STRING -#define RADIOLIB_SX1261_CHIP_TYPE "SX1261" +#define RADIOLIB_SX1261_CHIP_TYPE "SX1261" /*! \class SX1261 - \brief Derived class for %SX1261 modules. */ class SX1261 : public SX1262 { public: /*! \brief Default constructor. - \param mod Instance of Module that will be used to communicate with the radio. */ SX1261(Module* mod); /*! \brief Sets output power. Allowed values are in range from -17 to 14 dBm. - \param power Output power to be set in dBm. - \returns \ref status_codes */ int16_t setOutputPower(int8_t power); diff --git a/src/modules/SX126x/SX1262.cpp b/src/modules/SX126x/SX1262.cpp index 4cd8b9a9..baa27ae8 100644 --- a/src/modules/SX126x/SX1262.cpp +++ b/src/modules/SX126x/SX1262.cpp @@ -2,7 +2,7 @@ #if !defined(RADIOLIB_EXCLUDE_SX126X) SX1262::SX1262(Module* mod) : SX126x(mod) { - _chipType = RADIOLIB_SX1262_CHIP_TYPE; + chipType = RADIOLIB_SX1262_CHIP_TYPE; } int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { diff --git a/src/modules/SX126x/SX1262.h b/src/modules/SX126x/SX1262.h index e9919b83..32fd565c 100644 --- a/src/modules/SX126x/SX1262.h +++ b/src/modules/SX126x/SX1262.h @@ -9,22 +9,20 @@ #include "SX126x.h" //RADIOLIB_SX126X_CMD_SET_PA_CONFIG -#define RADIOLIB_SX126X_PA_CONFIG_SX1262 0x00 +#define RADIOLIB_SX126X_PA_CONFIG_SX1262 0x00 //RADIOLIB_SX126X_REG_VERSION_STRING // Note: this should really be "2", however, it seems that all SX1262 devices report as SX1261 -#define RADIOLIB_SX1262_CHIP_TYPE "SX1261" +#define RADIOLIB_SX1262_CHIP_TYPE "SX1261" /*! \class SX1262 - \brief Derived class for %SX1262 modules. */ class SX1262: public SX126x { public: /*! \brief Default constructor. - \param mod Instance of Module that will be used to communicate with the radio. */ SX1262(Module* mod); @@ -33,72 +31,46 @@ class SX1262: public SX126x { /*! \brief Initialization method for LoRa modem. - \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. - \param bw LoRa bandwidth in kHz. Defaults to 125.0 kHz. - \param sf LoRa spreading factor. Defaults to 9. - \param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7). - \param syncWord 1-byte LoRa sync word. Defaults to RADIOLIB_SX126X_SYNC_WORD_PRIVATE (0x12). - \param power Output power in dBm. Defaults to 10 dBm. - \param preambleLength LoRa preamble length in symbols. Defaults to 8 symbols. - \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. - \param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false. - \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_SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); /*! \brief Initialization method for FSK modem. - \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. - \param br FSK bit rate in kbps. Defaults to 4.8 kbps. - \param freqDev Frequency deviation from carrier frequency in kHz. Defaults to 5.0 kHz. - \param rxBw Receiver bandwidth in kHz. Defaults to 156.2 kHz. - \param power Output power in dBm. Defaults to 10 dBm. - \param preambleLength FSK preamble length in bits. Defaults to 16 bits. - \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. - \param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false. - \returns \ref status_codes */ int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); - - int16_t beginLRFHSS(float freq = 434.0, float tcxoVoltage = 0, bool useRegulatorLDO = false); // configuration methods /*! \brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz. - \param freq Carrier frequency to be set in MHz. - \returns \ref status_codes */ int16_t setFrequency(float freq); /*! \brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz. - \param freq Carrier frequency to be set in MHz. - \param calibrate Run image calibration. - \returns \ref status_codes */ int16_t setFrequency(float freq, bool calibrate); @@ -106,9 +78,7 @@ class SX1262: public SX126x { /*! \brief Sets output power. Allowed values are in range from -9 to 22 dBm. This method is virtual to allow override from the SX1261 class. - \param power Output power to be set in dBm. - \returns \ref status_codes */ virtual int16_t setOutputPower(int8_t power); diff --git a/src/modules/SX126x/SX1268.cpp b/src/modules/SX126x/SX1268.cpp index db60aef9..a2f60f23 100644 --- a/src/modules/SX126x/SX1268.cpp +++ b/src/modules/SX126x/SX1268.cpp @@ -2,7 +2,7 @@ #if !defined(RADIOLIB_EXCLUDE_SX126X) SX1268::SX1268(Module* mod) : SX126x(mod) { - _chipType = RADIOLIB_SX1268_CHIP_TYPE; + chipType = RADIOLIB_SX1268_CHIP_TYPE; } int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { diff --git a/src/modules/SX126x/SX1268.h b/src/modules/SX126x/SX1268.h index ab1bd222..8c5225b1 100644 --- a/src/modules/SX126x/SX1268.h +++ b/src/modules/SX126x/SX1268.h @@ -9,21 +9,19 @@ #include "SX126x.h" //RADIOLIB_SX126X_CMD_SET_PA_CONFIG -#define RADIOLIB_SX126X_PA_CONFIG_SX1268 0x00 +#define RADIOLIB_SX126X_PA_CONFIG_SX1268 0x00 //RADIOLIB_SX126X_REG_VERSION_STRING -#define RADIOLIB_SX1268_CHIP_TYPE "SX1268" +#define RADIOLIB_SX1268_CHIP_TYPE "SX1268" /*! \class SX1268 - \brief Derived class for %SX1268 modules. */ class SX1268: public SX126x { public: /*! \brief Default constructor. - \param mod Instance of Module that will be used to communicate with the radio. */ SX1268(Module* mod); @@ -32,48 +30,29 @@ class SX1268: public SX126x { /*! \brief Initialization method for LoRa modem. - \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. - \param bw LoRa bandwidth in kHz. Defaults to 125.0 kHz. - \param sf LoRa spreading factor. Defaults to 9. - \param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7). - \param syncWord 1-byte LoRa sync word. Defaults to RADIOLIB_SX126X_SYNC_WORD_PRIVATE (0x12). - \param power Output power in dBm. Defaults to 10 dBm. - \param preambleLength LoRa preamble length in symbols. Defaults to 8 symbols. - \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. - \param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false. - \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_SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); /*! \brief Initialization method for FSK modem. - \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. - \param br FSK bit rate in kbps. Defaults to 4.8 kbps. - \param freqDev Frequency deviation from carrier frequency in kHz. Defaults to 5.0 kHz. - \param rxBw Receiver bandwidth in kHz. Defaults to 156.2 kHz. - \param power Output power in dBm. Defaults to 10 dBm. - \param preambleLength FSK preamble length in bits. Defaults to 16 bits. - \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. - \param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false. - \returns \ref status_codes */ int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); @@ -82,29 +61,22 @@ class SX1268: public SX126x { /*! \brief Sets carrier frequency. Allowed values are in range from 410.0 to 810.0 MHz. - \param freq Carrier frequency to be set in MHz. - \returns \ref status_codes */ int16_t setFrequency(float freq); /*! \brief Sets carrier frequency. Allowed values are in range from 410.0 to 810.0 MHz. - \param freq Carrier frequency to be set in MHz. - \param calibrate Run image calibration. - \returns \ref status_codes */ int16_t setFrequency(float freq, bool calibrate); /*! \brief Sets output power. Allowed values are in range from -9 to 22 dBm. - \param power Output power to be set in dBm. - \returns \ref status_codes */ int16_t setOutputPower(int8_t power); diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index fc94f1a0..00e3d1af 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -4,48 +4,48 @@ #if !defined(RADIOLIB_EXCLUDE_SX126X) SX126x::SX126x(Module* mod) : PhysicalLayer(RADIOLIB_SX126X_FREQUENCY_STEP_SIZE, RADIOLIB_SX126X_MAX_PACKET_LENGTH) { - _mod = mod; + this->mod = mod; this->XTAL = false; } Module* SX126x::getMod() { - return(_mod); + return(this->mod); } int16_t SX126x::begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { // set module properties - _mod->init(); - _mod->hal->pinMode(_mod->getIrq(), _mod->hal->GpioModeInput); - _mod->hal->pinMode(_mod->getGpio(), _mod->hal->GpioModeInput); - _mod->SPIreadCommand = RADIOLIB_SX126X_CMD_READ_REGISTER; - _mod->SPIwriteCommand = RADIOLIB_SX126X_CMD_WRITE_REGISTER; - _mod->SPInopCommand = RADIOLIB_SX126X_CMD_NOP; - _mod->SPIstatusCommand = RADIOLIB_SX126X_CMD_GET_STATUS; - _mod->SPIstreamType = true; - _mod->SPIparseStatusCb = SPIparseStatus; + 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); + this->mod->SPIreadCommand = RADIOLIB_SX126X_CMD_READ_REGISTER; + this->mod->SPIwriteCommand = RADIOLIB_SX126X_CMD_WRITE_REGISTER; + this->mod->SPInopCommand = RADIOLIB_SX126X_CMD_NOP; + this->mod->SPIstatusCommand = RADIOLIB_SX126X_CMD_GET_STATUS; + this->mod->SPIstreamType = true; + this->mod->SPIparseStatusCb = SPIparseStatus; // try to find the SX126x chip - if(!SX126x::findChip(_chipType)) { + if(!SX126x::findChip(this->chipType)) { RADIOLIB_DEBUG_PRINTLN("No SX126x found!"); - _mod->term(); + this->mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } RADIOLIB_DEBUG_PRINTLN("M\tSX126x"); // BW in kHz and SF are required in order to calculate LDRO for setModulationParams // set the defaults, this will get overwritten later anyway - _bwKhz = 500.0; - _sf = 9; + this->bandwidthKhz = 500.0; + this->spreadingFactor = 9; // initialize configuration variables (will be overwritten during public settings configuration) - _bw = RADIOLIB_SX126X_LORA_BW_500_0; // initialized to 500 kHz, since lower valeus will interfere with LLCC68 - _cr = RADIOLIB_SX126X_LORA_CR_4_7; - _ldro = 0x00; - _crcType = RADIOLIB_SX126X_LORA_CRC_ON; - _preambleLength = preambleLength; - _tcxoDelay = 0; - _headerType = RADIOLIB_SX126X_LORA_HEADER_EXPLICIT; - _implicitLen = 0xFF; + this->bandwidth = RADIOLIB_SX126X_LORA_BW_500_0; // initialized to 500 kHz, since lower valeus will interfere with LLCC68 + this->codingRate = RADIOLIB_SX126X_LORA_CR_4_7; + this->ldrOptimize = 0x00; + this->crcTypeLoRa = RADIOLIB_SX126X_LORA_CRC_ON; + this->preambleLengthLoRa = preambleLength; + this->tcxoDelay = 0; + this->headerType = RADIOLIB_SX126X_LORA_HEADER_EXPLICIT; + this->implicitLen = 0xFF; // reset the module and verify startup int16_t state = reset(); @@ -96,33 +96,33 @@ int16_t SX126x::begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, flo int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { // set module properties - _mod->init(); - _mod->hal->pinMode(_mod->getIrq(), _mod->hal->GpioModeInput); - _mod->hal->pinMode(_mod->getGpio(), _mod->hal->GpioModeInput); - _mod->SPIreadCommand = RADIOLIB_SX126X_CMD_READ_REGISTER; - _mod->SPIwriteCommand = RADIOLIB_SX126X_CMD_WRITE_REGISTER; - _mod->SPInopCommand = RADIOLIB_SX126X_CMD_NOP; - _mod->SPIstatusCommand = RADIOLIB_SX126X_CMD_GET_STATUS; - _mod->SPIstreamType = true; - _mod->SPIparseStatusCb = SPIparseStatus; + 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); + this->mod->SPIreadCommand = RADIOLIB_SX126X_CMD_READ_REGISTER; + this->mod->SPIwriteCommand = RADIOLIB_SX126X_CMD_WRITE_REGISTER; + this->mod->SPInopCommand = RADIOLIB_SX126X_CMD_NOP; + this->mod->SPIstatusCommand = RADIOLIB_SX126X_CMD_GET_STATUS; + this->mod->SPIstreamType = true; + this->mod->SPIparseStatusCb = SPIparseStatus; // try to find the SX126x chip - if(!SX126x::findChip(_chipType)) { + if(!SX126x::findChip(this->chipType)) { RADIOLIB_DEBUG_PRINTLN("No SX126x found!"); - _mod->term(); + this->mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } RADIOLIB_DEBUG_PRINTLN("M\tSX126x"); // initialize configuration variables (will be overwritten during public settings configuration) - _br = 21333; // 48.0 kbps - _freqDev = 52428; // 50.0 kHz - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_156_2; - _rxBwKhz = 156.2; - _pulseShape = RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_5; - _crcTypeFSK = RADIOLIB_SX126X_GFSK_CRC_2_BYTE_INV; // CCIT CRC configuration - _preambleLengthFSK = preambleLength; - _addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF; + this->bitRate = 21333; // 48.0 kbps + this->freqencyDev = 52428; // 50.0 kHz + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_156_2; + this->rxBandwidthKhz = 156.2; + this->pulseShape = RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_5; + this->crcTypeFSK = RADIOLIB_SX126X_GFSK_CRC_2_BYTE_INV; // CCIT CRC configuration + this->preambleLengthFSK = preambleLength; + this->addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF; // reset the module and verify startup int16_t state = reset(); @@ -190,10 +190,10 @@ int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, uint16_t preambleL int16_t SX126x::reset(bool verify) { // run the reset sequence - _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); + 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); // return immediately when verification is disabled if(!verify) { @@ -201,7 +201,7 @@ int16_t SX126x::reset(bool verify) { } // set mode to standby - SX126x often refuses first few commands after reset - uint32_t start = _mod->hal->millis(); + uint32_t start = this->mod->hal->millis(); while(true) { // try to set mode to standby int16_t state = standby(); @@ -211,13 +211,13 @@ int16_t SX126x::reset(bool verify) { } // standby command failed, check timeout and try again - if(_mod->hal->millis() - start >= 1000) { + if(this->mod->hal->millis() - start >= 1000) { // timed out, possibly incorrect wiring return(state); } // wait a bit to not spam the module - _mod->hal->delay(100); + this->mod->hal->delay(100); } } @@ -254,18 +254,18 @@ int16_t SX126x::transmit(uint8_t* data, size_t len, uint8_t addr) { RADIOLIB_ASSERT(state); // wait for packet transmission 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) { finishTransmit(); return(RADIOLIB_ERR_TX_TIMEOUT); } } - uint32_t elapsed = _mod->hal->micros() - start; + uint32_t elapsed = this->mod->hal->micros() - start; // update data rate - _dataRate = (len*8.0)/((float)elapsed/1000000.0); + this->dataRateMeasured = (len*8.0)/((float)elapsed/1000000.0); return(finishTransmit()); } @@ -281,7 +281,7 @@ int16_t SX126x::receive(uint8_t* data, size_t len) { uint8_t modem = getPacketType(); if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) { // calculate timeout (100 LoRa symbols, the default for SX127x series) - float symbolLength = (float)(uint32_t(1) << _sf) / (float)_bwKhz; + float symbolLength = (float)(uint32_t(1) << this->spreadingFactor) / (float)this->bandwidthKhz; timeout = (uint32_t)(symbolLength * 100.0 * 1000.0); } else if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) { // calculate timeout (500 % of expected time-one-air) @@ -289,7 +289,7 @@ int16_t SX126x::receive(uint8_t* data, size_t len) { if(len == 0) { maxLen = 0xFF; } - float brBps = ((float)(RADIOLIB_SX126X_CRYSTAL_FREQ) * 1000000.0 * 32.0) / (float)_br; + float brBps = ((float)(RADIOLIB_SX126X_CRYSTAL_FREQ) * 1000000.0 * 32.0) / (float)this->bitRate; timeout = (uint32_t)(((maxLen * 8.0) / brBps) * 1000000.0 * 5.0); } else { @@ -304,10 +304,10 @@ int16_t SX126x::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) { fixImplicitTimeout(); clearIrqStatus(); standby(); @@ -316,7 +316,7 @@ int16_t SX126x::receive(uint8_t* data, size_t len) { } // fix timeout in implicit LoRa mode - if(((_headerType == RADIOLIB_SX126X_LORA_HEADER_IMPLICIT) && (getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_LORA))) { + if(((this->headerType == RADIOLIB_SX126X_LORA_HEADER_IMPLICIT) && (getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_LORA))) { state = fixImplicitTimeout(); RADIOLIB_ASSERT(state); } @@ -327,7 +327,7 @@ int16_t SX126x::receive(uint8_t* data, size_t len) { int16_t SX126x::transmitDirect(uint32_t frf) { // set RF switch (if present) - _mod->setRfSwitchState(_tx_mode); + this->mod->setRfSwitchState(this->txMode); // user requested to start transmitting immediately (required for RTTY) int16_t state = RADIOLIB_ERR_NONE; @@ -338,12 +338,12 @@ int16_t SX126x::transmitDirect(uint32_t frf) { // start transmitting uint8_t data[] = {RADIOLIB_SX126X_CMD_NOP}; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_TX_CONTINUOUS_WAVE, data, 1)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_TX_CONTINUOUS_WAVE, data, 1)); } int16_t SX126x::receiveDirect() { // set RF switch (if present) - _mod->setRfSwitchState(Module::MODE_RX); + this->mod->setRfSwitchState(Module::MODE_RX); // SX126x is unable to output received data directly return(RADIOLIB_ERR_UNKNOWN); @@ -365,13 +365,13 @@ int16_t SX126x::directMode() { // set DIO2 to clock output and DIO3 to data input // this is done exclusively by writing magic values to even more magic registers - state = _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_1, RADIOLIB_SX126X_TX_BITBANG_1_ENABLED, 6, 4); + state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_1, RADIOLIB_SX126X_TX_BITBANG_1_ENABLED, 6, 4); RADIOLIB_ASSERT(state); - state = _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_0, RADIOLIB_SX126X_TX_BITBANG_0_ENABLED, 3, 0); + state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_0, RADIOLIB_SX126X_TX_BITBANG_0_ENABLED, 3, 0); RADIOLIB_ASSERT(state); - state = _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_DIOX_OUT_ENABLE, RADIOLIB_SX126X_DIO3_OUT_DISABLED, 3, 3); + state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_DIOX_OUT_ENABLE, RADIOLIB_SX126X_DIO3_OUT_DISABLED, 3, 3); RADIOLIB_ASSERT(state); - state = _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_DIOX_IN_ENABLE, RADIOLIB_SX126X_DIO3_IN_ENABLED, 3, 3); + state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_DIOX_IN_ENABLE, RADIOLIB_SX126X_DIO3_IN_ENABLED, 3, 3); RADIOLIB_ASSERT(state); // enable TxDone interrupt @@ -399,13 +399,13 @@ int16_t SX126x::packetMode() { RADIOLIB_ASSERT(state); // restore the magic registers - state = _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_DIOX_IN_ENABLE, RADIOLIB_SX126X_DIO3_IN_DISABLED, 3, 3); + state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_DIOX_IN_ENABLE, RADIOLIB_SX126X_DIO3_IN_DISABLED, 3, 3); RADIOLIB_ASSERT(state); - state = _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_DIOX_OUT_ENABLE, RADIOLIB_SX126X_DIO3_OUT_ENABLED, 3, 3); + state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_DIOX_OUT_ENABLE, RADIOLIB_SX126X_DIO3_OUT_ENABLED, 3, 3); RADIOLIB_ASSERT(state); - state = _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_0, RADIOLIB_SX126X_TX_BITBANG_0_DISABLED, 3, 0); + state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_0, RADIOLIB_SX126X_TX_BITBANG_0_DISABLED, 3, 0); RADIOLIB_ASSERT(state); - state = _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_1, RADIOLIB_SX126X_TX_BITBANG_1_DISABLED, 6, 4); + state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_1, RADIOLIB_SX126X_TX_BITBANG_1_DISABLED, 6, 4); RADIOLIB_ASSERT(state); // enable DIO2 RF switch @@ -421,8 +421,8 @@ int16_t SX126x::scanChannel(uint8_t symbolNum, uint8_t detPeak, uint8_t detMin) RADIOLIB_ASSERT(state); // wait for channel activity detected or timeout - while(!_mod->hal->digitalRead(_mod->getIrq())) { - _mod->hal->yield(); + while(!this->mod->hal->digitalRead(this->mod->getIrq())) { + this->mod->hal->yield(); } // check CAD result @@ -431,16 +431,16 @@ int16_t SX126x::scanChannel(uint8_t symbolNum, uint8_t detPeak, uint8_t detMin) int16_t SX126x::sleep(bool retainConfig) { // set RF switch (if present) - _mod->setRfSwitchState(Module::MODE_IDLE); + this->mod->setRfSwitchState(Module::MODE_IDLE); uint8_t sleepMode = RADIOLIB_SX126X_SLEEP_START_WARM | RADIOLIB_SX126X_SLEEP_RTC_OFF; if(!retainConfig) { sleepMode = RADIOLIB_SX126X_SLEEP_START_COLD | RADIOLIB_SX126X_SLEEP_RTC_OFF; } - int16_t state = _mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_SLEEP, &sleepMode, 1, false, false); + int16_t state = this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_SLEEP, &sleepMode, 1, false, false); // wait for SX126x to safely enter sleep mode - _mod->hal->delay(1); + this->mod->hal->delay(1); return(state); } @@ -451,18 +451,18 @@ int16_t SX126x::standby() { int16_t SX126x::standby(uint8_t mode) { // set RF switch (if present) - _mod->setRfSwitchState(Module::MODE_IDLE); + this->mod->setRfSwitchState(Module::MODE_IDLE); uint8_t data[] = {mode}; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_STANDBY, data, 1)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_STANDBY, data, 1)); } void SX126x::setDio1Action(void (*func)(void)) { - _mod->hal->attachInterrupt(_mod->hal->pinToInterrupt(_mod->getIrq()), func, _mod->hal->GpioInterruptRising); + this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()), func, this->mod->hal->GpioInterruptRising); } void SX126x::clearDio1Action() { - _mod->hal->detachInterrupt(_mod->hal->pinToInterrupt(_mod->getIrq())); + this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq())); } int16_t SX126x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { @@ -475,7 +475,7 @@ int16_t SX126x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { } // maximum packet length is decreased by 1 when address filtering is active - if((_addrComp != RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF) && (len > RADIOLIB_SX126X_MAX_PACKET_LENGTH - 1)) { + if((this->addrComp != RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF) && (len > RADIOLIB_SX126X_MAX_PACKET_LENGTH - 1)) { return(RADIOLIB_ERR_PACKET_TOO_LONG); } @@ -483,9 +483,9 @@ int16_t SX126x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { int16_t state = RADIOLIB_ERR_NONE; uint8_t modem = getPacketType(); if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) { - state = setPacketParams(_preambleLength, _crcType, len, _headerType, _invertIQ); + state = setPacketParams(this->preambleLengthLoRa, this->crcTypeLoRa, len, this->headerType, this->invertIQEnabled); } else if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) { - state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening, _packetType, len); + state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType, len); } else { return(RADIOLIB_ERR_UNKNOWN); } @@ -512,15 +512,15 @@ int16_t SX126x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { RADIOLIB_ASSERT(state); // set RF switch (if present) - _mod->setRfSwitchState(_tx_mode); + this->mod->setRfSwitchState(this->txMode); // start transmission state = setTx(RADIOLIB_SX126X_TX_TIMEOUT_NONE); RADIOLIB_ASSERT(state); // wait for BUSY to go low (= PA ramp up done) - while(_mod->hal->digitalRead(_mod->getGpio())) { - _mod->hal->yield(); + while(this->mod->hal->digitalRead(this->mod->getGpio())) { + this->mod->hal->yield(); } return(state); @@ -540,7 +540,7 @@ int16_t SX126x::startReceive(uint32_t timeout, uint16_t irqFlags, uint16_t irqMa RADIOLIB_ASSERT(state); // set RF switch (if present) - _mod->setRfSwitchState(Module::MODE_RX); + this->mod->setRfSwitchState(Module::MODE_RX); // set mode to receive state = setRx(timeout); @@ -550,7 +550,7 @@ int16_t SX126x::startReceive(uint32_t timeout, uint16_t irqFlags, uint16_t irqMa int16_t SX126x::startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod, uint16_t irqFlags, uint16_t irqMask) { // datasheet claims time to go to sleep is ~500us, same to wake up, compensate for that with 1 ms + TCXO delay - uint32_t transitionTime = _tcxoDelay + 1000; + uint32_t transitionTime = this->tcxoDelay + 1000; sleepPeriod -= transitionTime; // divide by 15.625 @@ -572,12 +572,12 @@ int16_t SX126x::startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod, u uint8_t data[6] = {(uint8_t)((rxPeriodRaw >> 16) & 0xFF), (uint8_t)((rxPeriodRaw >> 8) & 0xFF), (uint8_t)(rxPeriodRaw & 0xFF), (uint8_t)((sleepPeriodRaw >> 16) & 0xFF), (uint8_t)((sleepPeriodRaw >> 8) & 0xFF), (uint8_t)(sleepPeriodRaw & 0xFF)}; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_RX_DUTY_CYCLE, data, 6)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_RX_DUTY_CYCLE, data, 6)); } int16_t SX126x::startReceiveDutyCycleAuto(uint16_t senderPreambleLength, uint16_t minSymbols, uint16_t irqFlags, uint16_t irqMask) { if(senderPreambleLength == 0) { - senderPreambleLength = _preambleLength; + senderPreambleLength = this->preambleLengthLoRa; } // worst case is that the sender starts transmitting when we're just less than minSymbols from going back to sleep. @@ -590,7 +590,7 @@ int16_t SX126x::startReceiveDutyCycleAuto(uint16_t senderPreambleLength, uint16_ return(startReceive(RADIOLIB_SX126X_RX_TIMEOUT_INF, irqFlags, irqMask)); } - uint32_t symbolLength = ((uint32_t)(10 * 1000) << _sf) / (10 * _bwKhz); + uint32_t symbolLength = ((uint32_t)(10 * 1000) << this->spreadingFactor) / (10 * this->bandwidthKhz); uint32_t sleepPeriod = symbolLength * sleepSymbols; RADIOLIB_DEBUG_PRINTLN("Auto sleep period: %d", sleepPeriod); @@ -606,7 +606,7 @@ int16_t SX126x::startReceiveDutyCycleAuto(uint16_t senderPreambleLength, uint16_ RADIOLIB_DEBUG_PRINTLN("Auto wake period: ", wakePeriod); // If our sleep period is shorter than our transition time, just use the standard startReceive - if(sleepPeriod < _tcxoDelay + 1016) { + if(sleepPeriod < this->tcxoDelay + 1016) { return(startReceive(RADIOLIB_SX126X_RX_TIMEOUT_INF, irqFlags, irqMask)); } @@ -631,9 +631,9 @@ int16_t SX126x::startReceiveCommon(uint32_t timeout, uint16_t irqFlags, uint16_t // restore original packet length uint8_t modem = getPacketType(); if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) { - state = setPacketParams(_preambleLength, _crcType, _implicitLen, _headerType, _invertIQ); + state = setPacketParams(this->preambleLengthLoRa, this->crcTypeLoRa, this->implicitLen, this->headerType, this->invertIQEnabled); } else if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) { - state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening, _packetType); + state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType); } else { return(RADIOLIB_ERR_UNKNOWN); } @@ -645,7 +645,7 @@ int16_t SX126x::readData(uint8_t* data, size_t len) { // this method may get called from receive() after Rx timeout // if that's the case, the first call will return "SPI command timeout error" // check the IRQ to be sure this really originated from timeout event - int16_t state = _mod->SPIcheckStream(); + int16_t state = this->mod->SPIcheckStream(); if((state == RADIOLIB_ERR_SPI_CMD_TIMEOUT) && (getIrqStatus() & RADIOLIB_SX126X_IRQ_TIMEOUT)) { // this is definitely Rx timeout return(RADIOLIB_ERR_RX_TIMEOUT); @@ -694,7 +694,7 @@ int16_t SX126x::startChannelScan(uint8_t symbolNum, uint8_t detPeak, uint8_t det RADIOLIB_ASSERT(state); // set RF switch (if present) - _mod->setRfSwitchState(Module::MODE_RX); + this->mod->setRfSwitchState(Module::MODE_RX); // set DIO pin mapping state = setDioIrqParams(RADIOLIB_SX126X_IRQ_CAD_DETECTED | RADIOLIB_SX126X_IRQ_CAD_DONE, RADIOLIB_SX126X_IRQ_CAD_DETECTED | RADIOLIB_SX126X_IRQ_CAD_DONE); @@ -743,42 +743,42 @@ int16_t SX126x::setBandwidth(float bw) { uint8_t bw_div2 = bw / 2 + 0.01; switch (bw_div2) { case 3: // 7.8: - _bw = RADIOLIB_SX126X_LORA_BW_7_8; + this->bandwidth = RADIOLIB_SX126X_LORA_BW_7_8; break; case 5: // 10.4: - _bw = RADIOLIB_SX126X_LORA_BW_10_4; + this->bandwidth = RADIOLIB_SX126X_LORA_BW_10_4; break; case 7: // 15.6: - _bw = RADIOLIB_SX126X_LORA_BW_15_6; + this->bandwidth = RADIOLIB_SX126X_LORA_BW_15_6; break; case 10: // 20.8: - _bw = RADIOLIB_SX126X_LORA_BW_20_8; + this->bandwidth = RADIOLIB_SX126X_LORA_BW_20_8; break; case 15: // 31.25: - _bw = RADIOLIB_SX126X_LORA_BW_31_25; + this->bandwidth = RADIOLIB_SX126X_LORA_BW_31_25; break; case 20: // 41.7: - _bw = RADIOLIB_SX126X_LORA_BW_41_7; + this->bandwidth = RADIOLIB_SX126X_LORA_BW_41_7; break; case 31: // 62.5: - _bw = RADIOLIB_SX126X_LORA_BW_62_5; + this->bandwidth = RADIOLIB_SX126X_LORA_BW_62_5; break; case 62: // 125.0: - _bw = RADIOLIB_SX126X_LORA_BW_125_0; + this->bandwidth = RADIOLIB_SX126X_LORA_BW_125_0; break; case 125: // 250.0 - _bw = RADIOLIB_SX126X_LORA_BW_250_0; + this->bandwidth = RADIOLIB_SX126X_LORA_BW_250_0; break; case 250: // 500.0 - _bw = RADIOLIB_SX126X_LORA_BW_500_0; + this->bandwidth = RADIOLIB_SX126X_LORA_BW_500_0; break; default: return(RADIOLIB_ERR_INVALID_BANDWIDTH); } // update modulation parameters - _bwKhz = bw; - return(setModulationParams(_sf, _bw, _cr, _ldro)); + this->bandwidthKhz = bw; + return(setModulationParams(this->spreadingFactor, this->bandwidth, this->codingRate, this->ldrOptimize)); } int16_t SX126x::setSpreadingFactor(uint8_t sf) { @@ -790,8 +790,8 @@ int16_t SX126x::setSpreadingFactor(uint8_t sf) { RADIOLIB_CHECK_RANGE(sf, 5, 12, RADIOLIB_ERR_INVALID_SPREADING_FACTOR); // update modulation parameters - _sf = sf; - return(setModulationParams(_sf, _bw, _cr, _ldro)); + this->spreadingFactor = sf; + return(setModulationParams(this->spreadingFactor, this->bandwidth, this->codingRate, this->ldrOptimize)); } int16_t SX126x::setCodingRate(uint8_t cr) { @@ -803,8 +803,8 @@ int16_t SX126x::setCodingRate(uint8_t cr) { RADIOLIB_CHECK_RANGE(cr, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE); // update modulation parameters - _cr = cr - 4; - return(setModulationParams(_sf, _bw, _cr, _ldro)); + this->codingRate = cr - 4; + return(setModulationParams(this->spreadingFactor, this->bandwidth, this->codingRate, this->ldrOptimize)); } int16_t SX126x::setSyncWord(uint8_t syncWord, uint8_t controlBits) { @@ -843,11 +843,11 @@ float SX126x::getCurrentLimit() { int16_t SX126x::setPreambleLength(uint16_t preambleLength) { uint8_t modem = getPacketType(); if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) { - _preambleLength = preambleLength; - return(setPacketParams(_preambleLength, _crcType, _implicitLen, _headerType, _invertIQ)); + this->preambleLengthLoRa = preambleLength; + return(setPacketParams(this->preambleLengthLoRa, this->crcTypeLoRa, this->implicitLen, this->headerType, this->invertIQEnabled)); } else if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) { - _preambleLengthFSK = preambleLength; - return(setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening, _packetType)); + this->preambleLengthFSK = preambleLength; + return(setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType)); } return(RADIOLIB_ERR_UNKNOWN); @@ -871,28 +871,31 @@ int16_t SX126x::setFrequencyDeviation(float freqDev) { uint32_t freqDevRaw = (uint32_t)(((newFreqDev * 1000.0) * (float)((uint32_t)(1) << 25)) / (RADIOLIB_SX126X_CRYSTAL_FREQ * 1000000.0)); // check modulation parameters - _freqDev = freqDevRaw; + this->freqencyDev = freqDevRaw; // update modulation parameters - return(setModulationParamsFSK(_br, _pulseShape, _rxBw, _freqDev)); + return(setModulationParamsFSK(this->bitRate, this->pulseShape, this->rxBandwidth, this->freqencyDev)); } int16_t SX126x::setBitRate(float br) { // check active modem - if(getPacketType() != RADIOLIB_SX126X_PACKET_TYPE_GFSK) { + uint8_t modem = getPacketType(); + if((modem != RADIOLIB_SX126X_PACKET_TYPE_GFSK) && (modem != RADIOLIB_SX126X_PACKET_TYPE_LR_FHSS)) { return(RADIOLIB_ERR_WRONG_MODEM); } - RADIOLIB_CHECK_RANGE(br, 0.6, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE); + if(modem != RADIOLIB_SX126X_PACKET_TYPE_LR_FHSS) { + RADIOLIB_CHECK_RANGE(br, 0.6, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE); + } // calculate raw bit rate value uint32_t brRaw = (uint32_t)((RADIOLIB_SX126X_CRYSTAL_FREQ * 1000000.0 * 32.0) / (br * 1000.0)); // check modulation parameters - _br = brRaw; + this->bitRate = brRaw; // update modulation parameters - return(setModulationParamsFSK(_br, _pulseShape, _rxBw, _freqDev)); + return(setModulationParamsFSK(this->bitRate, this->pulseShape, this->rxBandwidth, this->freqencyDev)); } int16_t SX126x::setRxBandwidth(float rxBw) { @@ -902,60 +905,60 @@ int16_t SX126x::setRxBandwidth(float rxBw) { } // check modulation parameters - /*if(2 * _freqDev + _br > rxBw * 1000.0) { + /*if(2 * this->freqencyDev + this->bitRate > rxBw * 1000.0) { return(RADIOLIB_ERR_INVALID_MODULATION_PARAMETERS); }*/ - _rxBwKhz = rxBw; + this->rxBandwidthKhz = rxBw; // check allowed receiver bandwidth values if(fabs(rxBw - 4.8) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_4_8; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_4_8; } else if(fabs(rxBw - 5.8) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_5_8; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_5_8; } else if(fabs(rxBw - 7.3) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_7_3; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_7_3; } else if(fabs(rxBw - 9.7) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_9_7; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_9_7; } else if(fabs(rxBw - 11.7) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_11_7; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_11_7; } else if(fabs(rxBw - 14.6) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_14_6; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_14_6; } else if(fabs(rxBw - 19.5) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_19_5; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_19_5; } else if(fabs(rxBw - 23.4) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_23_4; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_23_4; } else if(fabs(rxBw - 29.3) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_29_3; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_29_3; } else if(fabs(rxBw - 39.0) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_39_0; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_39_0; } else if(fabs(rxBw - 46.9) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_46_9; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_46_9; } else if(fabs(rxBw - 58.6) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_58_6; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_58_6; } else if(fabs(rxBw - 78.2) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_78_2; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_78_2; } else if(fabs(rxBw - 93.8) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_93_8; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_93_8; } else if(fabs(rxBw - 117.3) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_117_3; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_117_3; } else if(fabs(rxBw - 156.2) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_156_2; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_156_2; } else if(fabs(rxBw - 187.2) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_187_2; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_187_2; } else if(fabs(rxBw - 234.3) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_234_3; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_234_3; } else if(fabs(rxBw - 312.0) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_312_0; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_312_0; } else if(fabs(rxBw - 373.6) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_373_6; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_373_6; } else if(fabs(rxBw - 467.0) <= 0.001) { - _rxBw = RADIOLIB_SX126X_GFSK_RX_BW_467_0; + this->rxBandwidth = RADIOLIB_SX126X_GFSK_RX_BW_467_0; } else { return(RADIOLIB_ERR_INVALID_RX_BANDWIDTH); } // update modulation parameters - return(setModulationParamsFSK(_br, _pulseShape, _rxBw, _freqDev)); + return(setModulationParamsFSK(this->bitRate, this->pulseShape, this->rxBandwidth, this->freqencyDev)); } int16_t SX126x::setRxBoostedGainMode(bool rxbgm, bool persist) { @@ -1004,26 +1007,26 @@ int16_t SX126x::setDataShaping(uint8_t sh) { // set data shaping switch(sh) { case RADIOLIB_SHAPING_NONE: - _pulseShape = RADIOLIB_SX126X_GFSK_FILTER_NONE; + this->pulseShape = RADIOLIB_SX126X_GFSK_FILTER_NONE; break; case RADIOLIB_SHAPING_0_3: - _pulseShape = RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_3; + this->pulseShape = RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_3; break; case RADIOLIB_SHAPING_0_5: - _pulseShape = RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_5; + this->pulseShape = RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_5; break; case RADIOLIB_SHAPING_0_7: - _pulseShape = RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_7; + this->pulseShape = RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_7; break; case RADIOLIB_SHAPING_1_0: - _pulseShape = RADIOLIB_SX126X_GFSK_FILTER_GAUSS_1; + this->pulseShape = RADIOLIB_SX126X_GFSK_FILTER_GAUSS_1; break; default: return(RADIOLIB_ERR_INVALID_DATA_SHAPING); } // update modulation parameters - return(setModulationParamsFSK(_br, _pulseShape, _rxBw, _freqDev)); + return(setModulationParamsFSK(this->bitRate, this->pulseShape, this->rxBandwidth, this->freqencyDev)); } int16_t SX126x::setSyncWord(uint8_t* syncWord, uint8_t len) { @@ -1042,8 +1045,8 @@ int16_t SX126x::setSyncWord(uint8_t* syncWord, uint8_t len) { RADIOLIB_ASSERT(state); // update packet parameters - _syncWordLength = len * 8; - state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening, _packetType); + this->syncWordLength = len * 8; + state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType); return(state); } @@ -1069,8 +1072,8 @@ int16_t SX126x::setSyncBits(uint8_t *syncWord, uint8_t bitsLen) { RADIOLIB_ASSERT(state); // update packet parameters - _syncWordLength = bitsLen; - state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening, _packetType); + this->syncWordLength = bitsLen; + state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType); return(state); } @@ -1082,8 +1085,8 @@ int16_t SX126x::setNodeAddress(uint8_t nodeAddr) { } // enable address filtering (node only) - _addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE; - int16_t state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening, _packetType); + this->addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE; + int16_t state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType); RADIOLIB_ASSERT(state); // set node address @@ -1099,8 +1102,8 @@ int16_t SX126x::setBroadcastAddress(uint8_t broadAddr) { } // enable address filtering (node and broadcast) - _addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE_BROADCAST; - int16_t state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening, _packetType); + this->addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE_BROADCAST; + int16_t state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType); RADIOLIB_ASSERT(state); // set broadcast address @@ -1116,8 +1119,8 @@ int16_t SX126x::disableAddressFiltering() { } // disable address filtering - _addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF; - return(setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening)); + this->addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF; + return(setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening)); } int16_t SX126x::setCRC(uint8_t len, uint16_t initial, uint16_t polynomial, bool inverted) { @@ -1128,27 +1131,27 @@ int16_t SX126x::setCRC(uint8_t len, uint16_t initial, uint16_t polynomial, bool // update packet parameters switch(len) { case 0: - _crcTypeFSK = RADIOLIB_SX126X_GFSK_CRC_OFF; + this->crcTypeFSK = RADIOLIB_SX126X_GFSK_CRC_OFF; break; case 1: if(inverted) { - _crcTypeFSK = RADIOLIB_SX126X_GFSK_CRC_1_BYTE_INV; + this->crcTypeFSK = RADIOLIB_SX126X_GFSK_CRC_1_BYTE_INV; } else { - _crcTypeFSK = RADIOLIB_SX126X_GFSK_CRC_1_BYTE; + this->crcTypeFSK = RADIOLIB_SX126X_GFSK_CRC_1_BYTE; } break; case 2: if(inverted) { - _crcTypeFSK = RADIOLIB_SX126X_GFSK_CRC_2_BYTE_INV; + this->crcTypeFSK = RADIOLIB_SX126X_GFSK_CRC_2_BYTE_INV; } else { - _crcTypeFSK = RADIOLIB_SX126X_GFSK_CRC_2_BYTE; + this->crcTypeFSK = RADIOLIB_SX126X_GFSK_CRC_2_BYTE; } break; default: return(RADIOLIB_ERR_INVALID_CRC_CONFIGURATION); } - int16_t state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening, _packetType); + int16_t state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType); RADIOLIB_ASSERT(state); // write initial CRC value @@ -1168,12 +1171,12 @@ int16_t SX126x::setCRC(uint8_t len, uint16_t initial, uint16_t polynomial, bool // update packet parameters if(len) { - _crcType = RADIOLIB_SX126X_LORA_CRC_ON; + this->crcTypeLoRa = RADIOLIB_SX126X_LORA_CRC_ON; } else { - _crcType = RADIOLIB_SX126X_LORA_CRC_OFF; + this->crcTypeLoRa = RADIOLIB_SX126X_LORA_CRC_OFF; } - return(setPacketParams(_preambleLength, _crcType, _implicitLen, _headerType, _invertIQ)); + return(setPacketParams(this->preambleLengthLoRa, this->crcTypeLoRa, this->implicitLen, this->headerType, this->invertIQEnabled)); } return(RADIOLIB_ERR_UNKNOWN); @@ -1188,14 +1191,14 @@ int16_t SX126x::setWhitening(bool enabled, uint16_t initial) { int16_t state = RADIOLIB_ERR_NONE; if(!enabled) { // disable whitening - _whitening = RADIOLIB_SX126X_GFSK_WHITENING_OFF; + this->whitening = RADIOLIB_SX126X_GFSK_WHITENING_OFF; - state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening, _packetType); + state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType); RADIOLIB_ASSERT(state); } else { // enable whitening - _whitening = RADIOLIB_SX126X_GFSK_WHITENING_ON; + this->whitening = RADIOLIB_SX126X_GFSK_WHITENING_ON; // write initial whitening value // as per note on pg. 65 of datasheet v1.2: "The user should not change the value of the 7 MSB's of this register" @@ -1210,14 +1213,14 @@ int16_t SX126x::setWhitening(bool enabled, uint16_t initial) { state = writeRegister(RADIOLIB_SX126X_REG_WHITENING_INITIAL_MSB, data, 2); RADIOLIB_ASSERT(state); - state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening, _packetType); + state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType); RADIOLIB_ASSERT(state); } return(state); } float SX126x::getDataRate() const { - return(_dataRate); + return(this->dataRateMeasured); } float SX126x::getRSSI(bool packet) { @@ -1229,7 +1232,7 @@ float SX126x::getRSSI(bool packet) { } else { // get instantaneous RSSI value uint8_t data[3] = {0, 0, 0}; // RssiInst, Status, RFU - _mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_RSSI_INST, data, 3); + this->mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_RSSI_INST, data, 3); return((float)data[0] / (-2.0)); } } @@ -1275,9 +1278,9 @@ float SX126x::getFrequencyError() { // frequency error is negative efe |= (uint32_t) 0xFFF00000; efe = ~efe + 1; - error = 1.55 * (float) efe / (1600.0 / (float) _bwKhz) * -1.0; + error = 1.55 * (float) efe / (1600.0 / (float) this->bandwidthKhz) * -1.0; } else { - error = 1.55 * (float) efe / (1600.0 / (float) _bwKhz); + error = 1.55 * (float) efe / (1600.0 / (float) this->bandwidthKhz); } return(error); @@ -1287,12 +1290,12 @@ size_t SX126x::getPacketLength(bool update) { (void)update; // in implicit mode, return the cached value - if((getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_LORA) && (_headerType == RADIOLIB_SX126X_LORA_HEADER_IMPLICIT)) { - return(_implicitLen); + if((getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_LORA) && (this->headerType == RADIOLIB_SX126X_LORA_HEADER_IMPLICIT)) { + return(this->implicitLen); } uint8_t rxBufStatus[2] = {0, 0}; - _mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_RX_BUFFER_STATUS, rxBufStatus, 2); + this->mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_RX_BUFFER_STATUS, rxBufStatus, 2); return((size_t)rxBufStatus[0]); } @@ -1308,22 +1311,22 @@ uint32_t SX126x::getTimeOnAir(size_t len) { // everything is in microseconds to allow integer arithmetic // some constants have .25, these are multiplied by 4, and have _x4 postfix to indicate that fact if(getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_LORA) { - uint32_t symbolLength_us = ((uint32_t)(1000 * 10) << _sf) / (_bwKhz * 10) ; + uint32_t symbolLength_us = ((uint32_t)(1000 * 10) << this->spreadingFactor) / (this->bandwidthKhz * 10) ; uint8_t sfCoeff1_x4 = 17; // (4.25 * 4) uint8_t sfCoeff2 = 8; - if(_sf == 5 || _sf == 6) { + if(this->spreadingFactor == 5 || this->spreadingFactor == 6) { sfCoeff1_x4 = 25; // 6.25 * 4 sfCoeff2 = 0; } - uint8_t sfDivisor = 4*_sf; + uint8_t sfDivisor = 4*this->spreadingFactor; if(symbolLength_us >= 16000) { - sfDivisor = 4*(_sf - 2); + sfDivisor = 4*(this->spreadingFactor - 2); } const int8_t bitsPerCrc = 16; - const int8_t N_symbol_header = _headerType == RADIOLIB_SX126X_LORA_HEADER_EXPLICIT ? 20 : 0; + const int8_t N_symbol_header = this->headerType == RADIOLIB_SX126X_LORA_HEADER_EXPLICIT ? 20 : 0; // numerator of equation in section 6.1.4 of SX1268 datasheet v1.1 (might not actually be bitcount, but it has len * 8) - int16_t bitCount = (int16_t) 8 * len + _crcType * bitsPerCrc - 4 * _sf + sfCoeff2 + N_symbol_header; + int16_t bitCount = (int16_t) 8 * len + this->crcTypeLoRa * bitsPerCrc - 4 * this->spreadingFactor + sfCoeff2 + N_symbol_header; if(bitCount < 0) { bitCount = 0; } @@ -1331,11 +1334,11 @@ uint32_t SX126x::getTimeOnAir(size_t len) { uint16_t nPreCodedSymbols = (bitCount + (sfDivisor - 1)) / (sfDivisor); // preamble can be 65k, therefore nSymbol_x4 needs to be 32 bit - uint32_t nSymbol_x4 = (_preambleLength + 8) * 4 + sfCoeff1_x4 + nPreCodedSymbols * (_cr + 4) * 4; + uint32_t nSymbol_x4 = (this->preambleLengthLoRa + 8) * 4 + sfCoeff1_x4 + nPreCodedSymbols * (this->codingRate + 4) * 4; return((symbolLength_us * nSymbol_x4) / 4); } else { - return((len * 8 * _br) / (RADIOLIB_SX126X_CRYSTAL_FREQ * 32)); + return((len * 8 * this->bitRate) / (RADIOLIB_SX126X_CRYSTAL_FREQ * 32)); } } @@ -1360,11 +1363,11 @@ int16_t SX126x::setEncoding(uint8_t encoding) { } void SX126x::setRfSwitchPins(uint32_t rxEn, uint32_t txEn) { - _mod->setRfSwitchPins(rxEn, txEn); + this->mod->setRfSwitchPins(rxEn, txEn); } void SX126x::setRfSwitchTable(const uint32_t (&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[]) { - _mod->setRfSwitchTable(pins, table); + this->mod->setRfSwitchTable(pins, table); } int16_t SX126x::forceLDRO(bool enable) { @@ -1374,9 +1377,9 @@ int16_t SX126x::forceLDRO(bool enable) { } // update modulation parameters - _ldroAuto = false; - _ldro = (uint8_t)enable; - return(setModulationParams(_sf, _bw, _cr, _ldro)); + this->ldroAuto = false; + this->ldrOptimize = (uint8_t)enable; + return(setModulationParams(this->spreadingFactor, this->bandwidth, this->codingRate, this->ldrOptimize)); } int16_t SX126x::autoLDRO() { @@ -1384,20 +1387,20 @@ int16_t SX126x::autoLDRO() { return(RADIOLIB_ERR_WRONG_MODEM); } - _ldroAuto = true; + this->ldroAuto = true; return(RADIOLIB_ERR_NONE); } uint8_t SX126x::randomByte() { // set some magic registers - _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_ANA_LNA, RADIOLIB_SX126X_LNA_RNG_ENABLED, 0, 0); - _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_ANA_MIXER, RADIOLIB_SX126X_MIXER_RNG_ENABLED, 0, 0); + this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_ANA_LNA, RADIOLIB_SX126X_LNA_RNG_ENABLED, 0, 0); + this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_ANA_MIXER, RADIOLIB_SX126X_MIXER_RNG_ENABLED, 0, 0); // set mode to Rx setRx(RADIOLIB_SX126X_RX_TIMEOUT_INF); // 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; @@ -1411,24 +1414,24 @@ uint8_t SX126x::randomByte() { standby(); // restore the magic registers - _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_ANA_LNA, RADIOLIB_SX126X_LNA_RNG_DISABLED, 0, 0); - _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_ANA_MIXER, RADIOLIB_SX126X_MIXER_RNG_DISABLED, 0, 0); + this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_ANA_LNA, RADIOLIB_SX126X_LNA_RNG_DISABLED, 0, 0); + this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_ANA_MIXER, RADIOLIB_SX126X_MIXER_RNG_DISABLED, 0, 0); return(randByte); } -int16_t SX126x::invertIQ(bool invertIQ) { +int16_t SX126x::invertIQ(bool enable) { if(getPacketType() != RADIOLIB_SX126X_PACKET_TYPE_LORA) { return(RADIOLIB_ERR_WRONG_MODEM); } - if(invertIQ) { - _invertIQ = RADIOLIB_SX126X_LORA_IQ_INVERTED; + if(enable) { + this->invertIQEnabled = RADIOLIB_SX126X_LORA_IQ_INVERTED; } else { - _invertIQ = RADIOLIB_SX126X_LORA_IQ_STANDARD; + this->invertIQEnabled = RADIOLIB_SX126X_LORA_IQ_STANDARD; } - return(setPacketParams(_preambleLength, _crcType, _implicitLen, _headerType, _invertIQ)); + return(setPacketParams(this->preambleLengthLoRa, this->crcTypeLoRa, this->implicitLen, this->headerType, this->invertIQEnabled)); } #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE) @@ -1437,7 +1440,7 @@ void SX126x::setDirectAction(void (*func)(void)) { } void SX126x::readBit(uint32_t pin) { - updateDirectBuffer((uint8_t)_mod->hal->digitalRead(pin)); + updateDirectBuffer((uint8_t)this->mod->hal->digitalRead(pin)); } #endif @@ -1449,12 +1452,12 @@ int16_t SX126x::uploadPatch(const uint32_t* patch, size_t len, bool nonvolatile) // check the version #if defined(RADIOLIB_DEBUG) char ver_pre[16]; - _mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)ver_pre); + this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)ver_pre); RADIOLIB_DEBUG_PRINTLN("Pre-update version string: %d", ver_pre); #endif // enable patch update - _mod->SPIwriteRegister(RADIOLIB_SX126X_REG_PATCH_UPDATE_ENABLE, RADIOLIB_SX126X_PATCH_UPDATE_ENABLED); + this->mod->SPIwriteRegister(RADIOLIB_SX126X_REG_PATCH_UPDATE_ENABLE, RADIOLIB_SX126X_PATCH_UPDATE_ENABLED); // upload the patch uint8_t data[4]; @@ -1469,19 +1472,19 @@ int16_t SX126x::uploadPatch(const uint32_t* patch, size_t len, bool nonvolatile) data[1] = (bin >> 16) & 0xFF; data[2] = (bin >> 8) & 0xFF; data[3] = bin & 0xFF; - _mod->SPIwriteRegisterBurst(RADIOLIB_SX126X_REG_PATCH_MEMORY_BASE + i*sizeof(uint32_t), data, sizeof(uint32_t)); + this->mod->SPIwriteRegisterBurst(RADIOLIB_SX126X_REG_PATCH_MEMORY_BASE + i*sizeof(uint32_t), data, sizeof(uint32_t)); } // disable patch update - _mod->SPIwriteRegister(RADIOLIB_SX126X_REG_PATCH_UPDATE_ENABLE, RADIOLIB_SX126X_PATCH_UPDATE_DISABLED); + this->mod->SPIwriteRegister(RADIOLIB_SX126X_REG_PATCH_UPDATE_ENABLE, RADIOLIB_SX126X_PATCH_UPDATE_DISABLED); // update - _mod->SPIwriteStream(RADIOLIB_SX126X_CMD_PRAM_UPDATE, NULL, 0); + this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_PRAM_UPDATE, NULL, 0); // check the version again #if defined(RADIOLIB_DEBUG) char ver_post[16]; - _mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)ver_post); + this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)ver_post); RADIOLIB_DEBUG_PRINTLN("Post-update version string: %d", ver_post); #endif @@ -1493,7 +1496,7 @@ int16_t SX126x::spectralScanStart(uint16_t numSamples, uint8_t window, uint8_t i spectralScanAbort(); // set the RSSI window size - _mod->SPIwriteRegister(RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW, window); + this->mod->SPIwriteRegister(RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW, window); // start Rx with infinite timeout int16_t state = setRx(RADIOLIB_SX126X_RX_TIMEOUT_INF); @@ -1501,15 +1504,15 @@ int16_t SX126x::spectralScanStart(uint16_t numSamples, uint8_t window, uint8_t i // now set the actual spectral scan parameters uint8_t data[3] = { (uint8_t)((numSamples >> 8) & 0xFF), (uint8_t)(numSamples & 0xFF), interval }; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_SPECTR_SCAN_PARAMS, data, 3)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_SPECTR_SCAN_PARAMS, data, 3)); } void SX126x::spectralScanAbort() { - _mod->SPIwriteRegister(RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW, 0x00); + this->mod->SPIwriteRegister(RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW, 0x00); } int16_t SX126x::spectralScanGetStatus() { - uint8_t status = _mod->SPIreadRegister(RADIOLIB_SX126X_REG_SPECTRAL_SCAN_STATUS); + uint8_t status = this->mod->SPIreadRegister(RADIOLIB_SX126X_REG_SPECTRAL_SCAN_STATUS); if(status == RADIOLIB_SX126X_SPECTRAL_SCAN_COMPLETED) { return(RADIOLIB_ERR_NONE); } @@ -1519,7 +1522,7 @@ int16_t SX126x::spectralScanGetStatus() { int16_t SX126x::spectralScanGetResult(uint16_t* results) { // read the raw results uint8_t data[2*RADIOLIB_SX126X_SPECTRAL_SCAN_RES_SIZE]; - _mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_SPECTRAL_SCAN_RESULT, 2*RADIOLIB_SX126X_SPECTRAL_SCAN_RES_SIZE, data); + this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_SPECTRAL_SCAN_RESULT, 2*RADIOLIB_SX126X_SPECTRAL_SCAN_RES_SIZE, data); // convert it for(uint8_t i = 0; i < RADIOLIB_SX126X_SPECTRAL_SCAN_RES_SIZE; i++) { @@ -1575,10 +1578,10 @@ int16_t SX126x::setTCXO(float voltage, uint32_t delay) { data[2] = (uint8_t)((delayValue >> 8) & 0xFF); data[3] = (uint8_t)(delayValue & 0xFF); - _tcxoDelay = delay; + this->tcxoDelay = delay; // enable TCXO control on DIO3 - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_DIO3_AS_TCXO_CTRL, data, 4)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_DIO3_AS_TCXO_CTRL, data, 4)); } int16_t SX126x::setDio2AsRfSwitch(bool enable) { @@ -1588,21 +1591,21 @@ int16_t SX126x::setDio2AsRfSwitch(bool enable) { } else { data = RADIOLIB_SX126X_DIO2_AS_IRQ; } - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL, &data, 1)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL, &data, 1)); } int16_t SX126x::setFs() { - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_FS, NULL, 0)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_FS, NULL, 0)); } int16_t SX126x::setTx(uint32_t timeout) { uint8_t data[] = { (uint8_t)((timeout >> 16) & 0xFF), (uint8_t)((timeout >> 8) & 0xFF), (uint8_t)(timeout & 0xFF)} ; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_TX, data, 3)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_TX, data, 3)); } int16_t SX126x::setRx(uint32_t timeout) { uint8_t data[] = { (uint8_t)((timeout >> 16) & 0xFF), (uint8_t)((timeout >> 8) & 0xFF), (uint8_t)(timeout & 0xFF) }; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_RX, data, 3, true, false)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_RX, data, 3, true, false)); } int16_t SX126x::setCad(uint8_t symbolNum, uint8_t detPeak, uint8_t detMin) { @@ -1618,8 +1621,8 @@ int16_t SX126x::setCad(uint8_t symbolNum, uint8_t detPeak, uint8_t detMin) { RADIOLIB_SX126X_CAD_ON_4_SYMB }; // build the packet uint8_t data[7]; - data[0] = symbolNumValues[_sf - 5]; - data[1] = detPeakValues[_sf - 5]; + data[0] = symbolNumValues[this->spreadingFactor - 5]; + data[1] = detPeakValues[this->spreadingFactor - 5]; data[2] = RADIOLIB_SX126X_CAD_PARAM_DET_MIN; data[3] = RADIOLIB_SX126X_CAD_GOTO_STDBY; data[4] = 0x00; @@ -1640,40 +1643,40 @@ int16_t SX126x::setCad(uint8_t symbolNum, uint8_t detPeak, uint8_t detMin) { } // configure paramaters - int16_t state = _mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_CAD_PARAMS, data, 7); + int16_t state = this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_CAD_PARAMS, data, 7); RADIOLIB_ASSERT(state); // start CAD - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_CAD, NULL, 0)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_CAD, NULL, 0)); } int16_t SX126x::setPaConfig(uint8_t paDutyCycle, uint8_t deviceSel, uint8_t hpMax, uint8_t paLut) { uint8_t data[] = { paDutyCycle, hpMax, deviceSel, paLut }; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_PA_CONFIG, data, 4)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_PA_CONFIG, data, 4)); } int16_t SX126x::writeRegister(uint16_t addr, uint8_t* data, uint8_t numBytes) { - _mod->SPIwriteRegisterBurst(addr, data, numBytes); + this->mod->SPIwriteRegisterBurst(addr, data, numBytes); return(RADIOLIB_ERR_NONE); } int16_t SX126x::readRegister(uint16_t addr, uint8_t* data, uint8_t numBytes) { // send the command - _mod->SPIreadRegisterBurst(addr, numBytes, data); + this->mod->SPIreadRegisterBurst(addr, numBytes, data); // check the status - int16_t state = _mod->SPIcheckStream(); + int16_t state = this->mod->SPIcheckStream(); return(state); } int16_t SX126x::writeBuffer(uint8_t* data, uint8_t numBytes, uint8_t offset) { uint8_t cmd[] = { RADIOLIB_SX126X_CMD_WRITE_BUFFER, offset }; - return(_mod->SPIwriteStream(cmd, 2, data, numBytes)); + return(this->mod->SPIwriteStream(cmd, 2, data, numBytes)); } int16_t SX126x::readBuffer(uint8_t* data, uint8_t numBytes, uint8_t offset) { uint8_t cmd[] = { RADIOLIB_SX126X_CMD_READ_BUFFER, offset }; - return(_mod->SPIreadStream(cmd, 2, data, numBytes)); + return(this->mod->SPIreadStream(cmd, 2, data, numBytes)); } int16_t SX126x::setDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask, uint16_t dio3Mask) { @@ -1681,27 +1684,27 @@ int16_t SX126x::setDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t di (uint8_t)((dio1Mask >> 8) & 0xFF), (uint8_t)(dio1Mask & 0xFF), (uint8_t)((dio2Mask >> 8) & 0xFF), (uint8_t)(dio2Mask & 0xFF), (uint8_t)((dio3Mask >> 8) & 0xFF), (uint8_t)(dio3Mask & 0xFF)}; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_DIO_IRQ_PARAMS, data, 8)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_DIO_IRQ_PARAMS, data, 8)); } uint16_t SX126x::getIrqStatus() { uint8_t data[] = { 0x00, 0x00 }; - _mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_IRQ_STATUS, data, 2); + this->mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_IRQ_STATUS, data, 2); return(((uint16_t)(data[0]) << 8) | data[1]); } int16_t SX126x::clearIrqStatus(uint16_t clearIrqParams) { uint8_t data[] = { (uint8_t)((clearIrqParams >> 8) & 0xFF), (uint8_t)(clearIrqParams & 0xFF) }; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_CLEAR_IRQ_STATUS, data, 2)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_CLEAR_IRQ_STATUS, data, 2)); } int16_t SX126x::setRfFrequency(uint32_t frf) { uint8_t data[] = { (uint8_t)((frf >> 24) & 0xFF), (uint8_t)((frf >> 16) & 0xFF), (uint8_t)((frf >> 8) & 0xFF), (uint8_t)(frf & 0xFF) }; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_RF_FREQUENCY, data, 4)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_RF_FREQUENCY, data, 4)); } int16_t SX126x::calibrateImage(uint8_t* data) { - int16_t state = _mod->SPIwriteStream(RADIOLIB_SX126X_CMD_CALIBRATE_IMAGE, data, 2); + int16_t state = this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_CALIBRATE_IMAGE, data, 2); // if something failed, show the device errors #if defined(RADIOLIB_DEBUG) @@ -1717,13 +1720,13 @@ int16_t SX126x::calibrateImage(uint8_t* data) { uint8_t SX126x::getPacketType() { uint8_t data = 0xFF; - _mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_PACKET_TYPE, &data, 1); + this->mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_PACKET_TYPE, &data, 1); return(data); } int16_t SX126x::setTxParams(uint8_t power, uint8_t rampTime) { uint8_t data[] = { power, rampTime }; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_TX_PARAMS, data, 2)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_TX_PARAMS, data, 2)); } int16_t SX126x::setPacketMode(uint8_t mode, uint8_t len) { @@ -1733,103 +1736,103 @@ int16_t SX126x::setPacketMode(uint8_t mode, uint8_t len) { } // set requested packet mode - int16_t state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening, mode, len); + int16_t state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, mode, len); RADIOLIB_ASSERT(state); // update cached value - _packetType = mode; + this->packetType = mode; return(state); } -int16_t SX126x::setHeaderType(uint8_t headerType, size_t len) { +int16_t SX126x::setHeaderType(uint8_t hdrType, size_t len) { // check active modem if(getPacketType() != RADIOLIB_SX126X_PACKET_TYPE_LORA) { return(RADIOLIB_ERR_WRONG_MODEM); } // set requested packet mode - int16_t state = setPacketParams(_preambleLength, _crcType, len, headerType, _invertIQ); + int16_t state = setPacketParams(this->preambleLengthLoRa, this->crcTypeLoRa, len, hdrType, this->invertIQEnabled); RADIOLIB_ASSERT(state); // update cached value - _headerType = headerType; - _implicitLen = len; + this->headerType = hdrType; + this->implicitLen = len; return(state); } int16_t SX126x::setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr, uint8_t ldro) { // calculate symbol length and enable low data rate optimization, if auto-configuration is enabled - if(_ldroAuto) { - float symbolLength = (float)(uint32_t(1) << _sf) / (float)_bwKhz; + if(this->ldroAuto) { + float symbolLength = (float)(uint32_t(1) << this->spreadingFactor) / (float)this->bandwidthKhz; RADIOLIB_DEBUG_PRINTLN("Symbol length: %d ms", symbolLength); if(symbolLength >= 16.0) { - _ldro = RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_ON; + this->ldrOptimize = RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_ON; } else { - _ldro = RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_OFF; + this->ldrOptimize = RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_OFF; } } else { - _ldro = ldro; + this->ldrOptimize = ldro; } // 500/9/8 - 0x09 0x04 0x03 0x00 - SF9, BW125, 4/8 // 500/11/8 - 0x0B 0x04 0x03 0x00 - SF11 BW125, 4/7 - uint8_t data[4] = {sf, bw, cr, _ldro}; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_MODULATION_PARAMS, data, 4)); + uint8_t data[4] = {sf, bw, cr, this->ldrOptimize}; + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_MODULATION_PARAMS, data, 4)); } int16_t SX126x::setModulationParamsFSK(uint32_t br, uint8_t pulseShape, uint8_t rxBw, uint32_t freqDev) { uint8_t data[8] = {(uint8_t)((br >> 16) & 0xFF), (uint8_t)((br >> 8) & 0xFF), (uint8_t)(br & 0xFF), pulseShape, rxBw, (uint8_t)((freqDev >> 16) & 0xFF), (uint8_t)((freqDev >> 8) & 0xFF), (uint8_t)(freqDev & 0xFF)}; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_MODULATION_PARAMS, data, 8)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_MODULATION_PARAMS, data, 8)); } -int16_t SX126x::setPacketParams(uint16_t preambleLength, uint8_t crcType, uint8_t payloadLength, uint8_t headerType, uint8_t invertIQ) { +int16_t SX126x::setPacketParams(uint16_t preambleLen, uint8_t crcType, uint8_t payloadLen, uint8_t hdrType, uint8_t invertIQ) { int16_t state = fixInvertedIQ(invertIQ); RADIOLIB_ASSERT(state); - uint8_t data[6] = {(uint8_t)((preambleLength >> 8) & 0xFF), (uint8_t)(preambleLength & 0xFF), headerType, payloadLength, crcType, invertIQ}; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_PACKET_PARAMS, data, 6)); + uint8_t data[6] = {(uint8_t)((preambleLen >> 8) & 0xFF), (uint8_t)(preambleLen & 0xFF), hdrType, payloadLen, crcType, invertIQ}; + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_PACKET_PARAMS, data, 6)); } -int16_t SX126x::setPacketParamsFSK(uint16_t preambleLength, uint8_t crcType, uint8_t syncWordLength, uint8_t addrComp, uint8_t whitening, uint8_t packetType, uint8_t payloadLength, uint8_t preambleDetectorLength) { - uint8_t data[9] = {(uint8_t)((preambleLength >> 8) & 0xFF), (uint8_t)(preambleLength & 0xFF), - preambleDetectorLength, syncWordLength, addrComp, - packetType, payloadLength, crcType, whitening}; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_PACKET_PARAMS, data, 9)); +int16_t SX126x::setPacketParamsFSK(uint16_t preambleLen, uint8_t crcType, uint8_t syncWordLen, uint8_t addrCmp, uint8_t whiten, uint8_t packType, uint8_t payloadLen, uint8_t preambleDetectorLen) { + uint8_t data[9] = {(uint8_t)((preambleLen >> 8) & 0xFF), (uint8_t)(preambleLen & 0xFF), + preambleDetectorLen, syncWordLen, addrCmp, + packType, payloadLen, crcType, whiten}; + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_PACKET_PARAMS, data, 9)); } int16_t SX126x::setBufferBaseAddress(uint8_t txBaseAddress, uint8_t rxBaseAddress) { uint8_t data[2] = {txBaseAddress, rxBaseAddress}; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_BUFFER_BASE_ADDRESS, data, 2)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_BUFFER_BASE_ADDRESS, data, 2)); } int16_t SX126x::setRegulatorMode(uint8_t mode) { uint8_t data[1] = {mode}; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_REGULATOR_MODE, data, 1)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_REGULATOR_MODE, data, 1)); } uint8_t SX126x::getStatus() { uint8_t data = 0; - _mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_STATUS, &data, 1); + this->mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_STATUS, &data, 1); return(data); } uint32_t SX126x::getPacketStatus() { uint8_t data[3] = {0, 0, 0}; - _mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_PACKET_STATUS, data, 3); + this->mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_PACKET_STATUS, data, 3); return((((uint32_t)data[0]) << 16) | (((uint32_t)data[1]) << 8) | (uint32_t)data[2]); } uint16_t SX126x::getDeviceErrors() { uint8_t data[2] = {0, 0}; - _mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_DEVICE_ERRORS, data, 2); + this->mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_DEVICE_ERRORS, data, 2); uint16_t opError = (((uint16_t)data[0] & 0xFF) << 8) | ((uint16_t)data[1]); return(opError); } int16_t SX126x::clearDeviceErrors() { uint8_t data[2] = {RADIOLIB_SX126X_CMD_NOP, RADIOLIB_SX126X_CMD_NOP}; - return(_mod->SPIwriteStream(RADIOLIB_SX126X_CMD_CLEAR_DEVICE_ERRORS, data, 2)); + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_CLEAR_DEVICE_ERRORS, data, 2)); } int16_t SX126x::setFrequencyRaw(float freq) { @@ -1848,7 +1851,7 @@ int16_t SX126x::fixSensitivity() { RADIOLIB_ASSERT(state); // fix the value for LoRa with 500 kHz bandwidth - if((getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_LORA) && (fabs(_bwKhz - 500.0) <= 0.001)) { + if((getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_LORA) && (fabs(this->bandwidthKhz - 500.0) <= 0.001)) { sensitivityConfig &= 0xFB; } else { sensitivityConfig |= 0x04; @@ -1879,7 +1882,7 @@ int16_t SX126x::fixImplicitTimeout() { // see SX1262/SX1268 datasheet, chapter 15 Known Limitations, section 15.3 for details //check if we're in implicit LoRa mode - if(!((_headerType == RADIOLIB_SX126X_LORA_HEADER_IMPLICIT) && (getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_LORA))) { + if(!((this->headerType == RADIOLIB_SX126X_LORA_HEADER_IMPLICIT) && (getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_LORA))) { return(RADIOLIB_ERR_WRONG_MODEM); } @@ -1926,23 +1929,23 @@ int16_t SX126x::config(uint8_t modem) { // set modem uint8_t data[7]; data[0] = modem; - state = _mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_PACKET_TYPE, data, 1); + state = this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_PACKET_TYPE, data, 1); RADIOLIB_ASSERT(state); // set Rx/Tx fallback mode to STDBY_RC data[0] = RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_RC; - state = _mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_RX_TX_FALLBACK_MODE, data, 1); + state = this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_RX_TX_FALLBACK_MODE, data, 1); RADIOLIB_ASSERT(state); // set some CAD parameters - will be overwritten whel calling CAD anyway data[0] = RADIOLIB_SX126X_CAD_ON_8_SYMB; - data[1] = _sf + 13; + data[1] = this->spreadingFactor + 13; data[2] = RADIOLIB_SX126X_CAD_PARAM_DET_MIN; data[3] = RADIOLIB_SX126X_CAD_GOTO_STDBY; data[4] = 0x00; data[5] = 0x00; data[6] = 0x00; - state = _mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_CAD_PARAMS, data, 7); + state = this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_CAD_PARAMS, data, 7); RADIOLIB_ASSERT(state); // clear IRQ @@ -1952,17 +1955,17 @@ int16_t SX126x::config(uint8_t modem) { // calibrate all blocks data[0] = RADIOLIB_SX126X_CALIBRATE_ALL; - state = _mod->SPIwriteStream(RADIOLIB_SX126X_CMD_CALIBRATE, data, 1, true, false); + state = this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_CALIBRATE, data, 1, true, false); RADIOLIB_ASSERT(state); // wait for calibration completion - _mod->hal->delay(5); - while(_mod->hal->digitalRead(_mod->getGpio())) { - _mod->hal->yield(); + this->mod->hal->delay(5); + while(this->mod->hal->digitalRead(this->mod->getGpio())) { + this->mod->hal->yield(); } // check calibration result - state = _mod->SPIcheckStream(); + state = this->mod->SPIcheckStream(); // if something failed, show the device errors #if defined(RADIOLIB_DEBUG) @@ -1999,21 +2002,21 @@ bool SX126x::findChip(const char* verStr) { // read the version string char version[16]; - _mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)version); + this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)version); // check version register if(strncmp(verStr, version, 6) == 0) { RADIOLIB_DEBUG_PRINTLN("Found SX126x: RADIOLIB_SX126X_REG_VERSION_STRING:"); - _mod->hexdump((uint8_t*)version, 16, RADIOLIB_SX126X_REG_VERSION_STRING); + this->mod->hexdump((uint8_t*)version, 16, RADIOLIB_SX126X_REG_VERSION_STRING); RADIOLIB_DEBUG_PRINTLN(); flagFound = true; } else { #if defined(RADIOLIB_DEBUG) RADIOLIB_DEBUG_PRINTLN("SX126x not found! (%d of 10 tries) RADIOLIB_SX126X_REG_VERSION_STRING:", i + 1); - _mod->hexdump((uint8_t*)version, 16, RADIOLIB_SX126X_REG_VERSION_STRING); + this->mod->hexdump((uint8_t*)version, 16, RADIOLIB_SX126X_REG_VERSION_STRING); RADIOLIB_DEBUG_PRINTLN("Expected string: %s", verStr); #endif - _mod->hal->delay(10); + this->mod->hal->delay(10); i++; } } diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index fd33c713..5f92024f 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -10,29 +10,29 @@ #include "../../protocols/PhysicalLayer/PhysicalLayer.h" // SX126X physical layer properties -#define RADIOLIB_SX126X_FREQUENCY_STEP_SIZE 0.9536743164 -#define RADIOLIB_SX126X_MAX_PACKET_LENGTH 255 -#define RADIOLIB_SX126X_CRYSTAL_FREQ 32.0 -#define RADIOLIB_SX126X_DIV_EXPONENT 25 +#define RADIOLIB_SX126X_FREQUENCY_STEP_SIZE 0.9536743164 +#define RADIOLIB_SX126X_MAX_PACKET_LENGTH 255 +#define RADIOLIB_SX126X_CRYSTAL_FREQ 32.0 +#define RADIOLIB_SX126X_DIV_EXPONENT 25 // SX126X SPI commands // operational modes commands -#define RADIOLIB_SX126X_CMD_NOP 0x00 -#define RADIOLIB_SX126X_CMD_SET_SLEEP 0x84 -#define RADIOLIB_SX126X_CMD_SET_STANDBY 0x80 -#define RADIOLIB_SX126X_CMD_SET_FS 0xC1 -#define RADIOLIB_SX126X_CMD_SET_TX 0x83 -#define RADIOLIB_SX126X_CMD_SET_RX 0x82 -#define RADIOLIB_SX126X_CMD_STOP_TIMER_ON_PREAMBLE 0x9F -#define RADIOLIB_SX126X_CMD_SET_RX_DUTY_CYCLE 0x94 -#define RADIOLIB_SX126X_CMD_SET_CAD 0xC5 -#define RADIOLIB_SX126X_CMD_SET_TX_CONTINUOUS_WAVE 0xD1 -#define RADIOLIB_SX126X_CMD_SET_TX_INFINITE_PREAMBLE 0xD2 -#define RADIOLIB_SX126X_CMD_SET_REGULATOR_MODE 0x96 -#define RADIOLIB_SX126X_CMD_CALIBRATE 0x89 -#define RADIOLIB_SX126X_CMD_CALIBRATE_IMAGE 0x98 -#define RADIOLIB_SX126X_CMD_SET_PA_CONFIG 0x95 -#define RADIOLIB_SX126X_CMD_SET_RX_TX_FALLBACK_MODE 0x93 +#define RADIOLIB_SX126X_CMD_NOP 0x00 +#define RADIOLIB_SX126X_CMD_SET_SLEEP 0x84 +#define RADIOLIB_SX126X_CMD_SET_STANDBY 0x80 +#define RADIOLIB_SX126X_CMD_SET_FS 0xC1 +#define RADIOLIB_SX126X_CMD_SET_TX 0x83 +#define RADIOLIB_SX126X_CMD_SET_RX 0x82 +#define RADIOLIB_SX126X_CMD_STOP_TIMER_ON_PREAMBLE 0x9F +#define RADIOLIB_SX126X_CMD_SET_RX_DUTY_CYCLE 0x94 +#define RADIOLIB_SX126X_CMD_SET_CAD 0xC5 +#define RADIOLIB_SX126X_CMD_SET_TX_CONTINUOUS_WAVE 0xD1 +#define RADIOLIB_SX126X_CMD_SET_TX_INFINITE_PREAMBLE 0xD2 +#define RADIOLIB_SX126X_CMD_SET_REGULATOR_MODE 0x96 +#define RADIOLIB_SX126X_CMD_CALIBRATE 0x89 +#define RADIOLIB_SX126X_CMD_CALIBRATE_IMAGE 0x98 +#define RADIOLIB_SX126X_CMD_SET_PA_CONFIG 0x95 +#define RADIOLIB_SX126X_CMD_SET_RX_TX_FALLBACK_MODE 0x93 // register and buffer access commands #define RADIOLIB_SX126X_CMD_WRITE_REGISTER 0x0D @@ -41,403 +41,402 @@ #define RADIOLIB_SX126X_CMD_READ_BUFFER 0x1E // DIO and IRQ control -#define RADIOLIB_SX126X_CMD_SET_DIO_IRQ_PARAMS 0x08 -#define RADIOLIB_SX126X_CMD_GET_IRQ_STATUS 0x12 -#define RADIOLIB_SX126X_CMD_CLEAR_IRQ_STATUS 0x02 -#define RADIOLIB_SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL 0x9D -#define RADIOLIB_SX126X_CMD_SET_DIO3_AS_TCXO_CTRL 0x97 +#define RADIOLIB_SX126X_CMD_SET_DIO_IRQ_PARAMS 0x08 +#define RADIOLIB_SX126X_CMD_GET_IRQ_STATUS 0x12 +#define RADIOLIB_SX126X_CMD_CLEAR_IRQ_STATUS 0x02 +#define RADIOLIB_SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL 0x9D +#define RADIOLIB_SX126X_CMD_SET_DIO3_AS_TCXO_CTRL 0x97 // RF, modulation and packet commands -#define RADIOLIB_SX126X_CMD_SET_RF_FREQUENCY 0x86 -#define RADIOLIB_SX126X_CMD_SET_PACKET_TYPE 0x8A -#define RADIOLIB_SX126X_CMD_GET_PACKET_TYPE 0x11 -#define RADIOLIB_SX126X_CMD_SET_TX_PARAMS 0x8E -#define RADIOLIB_SX126X_CMD_SET_MODULATION_PARAMS 0x8B -#define RADIOLIB_SX126X_CMD_SET_PACKET_PARAMS 0x8C -#define RADIOLIB_SX126X_CMD_SET_CAD_PARAMS 0x88 -#define RADIOLIB_SX126X_CMD_SET_BUFFER_BASE_ADDRESS 0x8F -#define RADIOLIB_SX126X_CMD_SET_LORA_SYMB_NUM_TIMEOUT 0x0A +#define RADIOLIB_SX126X_CMD_SET_RF_FREQUENCY 0x86 +#define RADIOLIB_SX126X_CMD_SET_PACKET_TYPE 0x8A +#define RADIOLIB_SX126X_CMD_GET_PACKET_TYPE 0x11 +#define RADIOLIB_SX126X_CMD_SET_TX_PARAMS 0x8E +#define RADIOLIB_SX126X_CMD_SET_MODULATION_PARAMS 0x8B +#define RADIOLIB_SX126X_CMD_SET_PACKET_PARAMS 0x8C +#define RADIOLIB_SX126X_CMD_SET_CAD_PARAMS 0x88 +#define RADIOLIB_SX126X_CMD_SET_BUFFER_BASE_ADDRESS 0x8F +#define RADIOLIB_SX126X_CMD_SET_LORA_SYMB_NUM_TIMEOUT 0x0A // status commands -#define RADIOLIB_SX126X_CMD_GET_STATUS 0xC0 -#define RADIOLIB_SX126X_CMD_GET_RSSI_INST 0x15 -#define RADIOLIB_SX126X_CMD_GET_RX_BUFFER_STATUS 0x13 -#define RADIOLIB_SX126X_CMD_GET_PACKET_STATUS 0x14 -#define RADIOLIB_SX126X_CMD_GET_DEVICE_ERRORS 0x17 -#define RADIOLIB_SX126X_CMD_CLEAR_DEVICE_ERRORS 0x07 -#define RADIOLIB_SX126X_CMD_GET_STATS 0x10 -#define RADIOLIB_SX126X_CMD_RESET_STATS 0x00 +#define RADIOLIB_SX126X_CMD_GET_STATUS 0xC0 +#define RADIOLIB_SX126X_CMD_GET_RSSI_INST 0x15 +#define RADIOLIB_SX126X_CMD_GET_RX_BUFFER_STATUS 0x13 +#define RADIOLIB_SX126X_CMD_GET_PACKET_STATUS 0x14 +#define RADIOLIB_SX126X_CMD_GET_DEVICE_ERRORS 0x17 +#define RADIOLIB_SX126X_CMD_CLEAR_DEVICE_ERRORS 0x07 +#define RADIOLIB_SX126X_CMD_GET_STATS 0x10 +#define RADIOLIB_SX126X_CMD_RESET_STATS 0x00 -#define RADIOLIB_SX126X_CMD_PRAM_UPDATE 0xD9 -#define RADIOLIB_SX126X_CMD_SET_LBT_SCAN_PARAMS 0x9A -#define RADIOLIB_SX126X_CMD_SET_SPECTR_SCAN_PARAMS 0x9B +#define RADIOLIB_SX126X_CMD_PRAM_UPDATE 0xD9 +#define RADIOLIB_SX126X_CMD_SET_LBT_SCAN_PARAMS 0x9A +#define RADIOLIB_SX126X_CMD_SET_SPECTR_SCAN_PARAMS 0x9B // SX126X register map -#define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_0 0x029F // SX1268 datasheet v1.1, section 9.6 -#define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_1 0x02A0 // SX1268 datasheet v1.1, section 9.6 -#define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_2 0x02A1 // SX1268 datasheet v1.1, section 9.6 -#define RADIOLIB_SX126X_REG_VERSION_STRING 0x0320 -#define RADIOLIB_SX126X_REG_HOPPING_ENABLE 0x0385 -#define RADIOLIB_SX126X_REG_LR_FHSS_PACKET_LENGTH 0x0386 -#define RADIOLIB_SX126X_REG_LR_FHSS_NUM_HOPPING_BLOCKS 0x0387 -#define RADIOLIB_SX126X_REG_LR_FHSS_NUM_SYMBOLS_FREQX_MSB(X) (0x0388 + (X)*6) -#define RADIOLIB_SX126X_REG_LR_FHSS_NUM_SYMBOLS_FREQX_LSB(X) (0x0389 + (X)*6) -#define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_0(X) (0x038A + (X)*6) -#define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_1(X) (0x038B + (X)*6) -#define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_2(X) (0x038C + (X)*6) -#define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_3(X) (0x038D + (X)*6) -#define RADIOLIB_SX126X_REG_SPECTRAL_SCAN_RESULT 0x0401 -#define RADIOLIB_SX126X_REG_DIOX_OUT_ENABLE 0x0580 -#define RADIOLIB_SX126X_REG_DIOX_DRIVE_STRENGTH 0x0582 -#define RADIOLIB_SX126X_REG_DIOX_IN_ENABLE 0x0583 -#define RADIOLIB_SX126X_REG_DIOX_PULL_UP_CTRL 0x0584 -#define RADIOLIB_SX126X_REG_DIOX_PULL_DOWN_CTRL 0x0585 -#define RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_0 0x0587 -#define RADIOLIB_SX126X_REG_PATCH_UPDATE_ENABLE 0x0610 -#define RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_1 0x0680 -#define RADIOLIB_SX126X_REG_WHITENING_INITIAL_MSB 0x06B8 -#define RADIOLIB_SX126X_REG_WHITENING_INITIAL_LSB 0x06B9 -#define RADIOLIB_SX126X_REG_RX_TX_PLD_LEN 0x06BB -#define RADIOLIB_SX126X_REG_CRC_INITIAL_MSB 0x06BC -#define RADIOLIB_SX126X_REG_CRC_INITIAL_LSB 0x06BD -#define RADIOLIB_SX126X_REG_CRC_POLYNOMIAL_MSB 0x06BE -#define RADIOLIB_SX126X_REG_CRC_POLYNOMIAL_LSB 0x06BF -#define RADIOLIB_SX126X_REG_SYNC_WORD_0 0x06C0 -#define RADIOLIB_SX126X_REG_SYNC_WORD_1 0x06C1 -#define RADIOLIB_SX126X_REG_SYNC_WORD_2 0x06C2 -#define RADIOLIB_SX126X_REG_SYNC_WORD_3 0x06C3 -#define RADIOLIB_SX126X_REG_SYNC_WORD_4 0x06C4 -#define RADIOLIB_SX126X_REG_SYNC_WORD_5 0x06C5 -#define RADIOLIB_SX126X_REG_SYNC_WORD_6 0x06C6 -#define RADIOLIB_SX126X_REG_SYNC_WORD_7 0x06C7 -#define RADIOLIB_SX126X_REG_NODE_ADDRESS 0x06CD -#define RADIOLIB_SX126X_REG_BROADCAST_ADDRESS 0x06CE -#define RADIOLIB_SX126X_REG_PAYLOAD_LENGTH 0x0702 -#define RADIOLIB_SX126X_REG_PACKET_PARAMS 0x0704 -#define RADIOLIB_SX126X_REG_LORA_SYNC_TIMEOUT 0x0706 -#define RADIOLIB_SX126X_REG_IQ_CONFIG 0x0736 -#define RADIOLIB_SX126X_REG_LORA_SYNC_WORD_MSB 0x0740 -#define RADIOLIB_SX126X_REG_LORA_SYNC_WORD_LSB 0x0741 -#define RADIOLIB_SX126X_REG_FREQ_ERROR 0x076B -#define RADIOLIB_SX126X_REG_SPECTRAL_SCAN_STATUS 0x07CD -#define RADIOLIB_SX126X_REG_RX_ADDR_PTR 0x0803 -#define RADIOLIB_SX126X_REG_RANDOM_NUMBER_0 0x0819 -#define RADIOLIB_SX126X_REG_RANDOM_NUMBER_1 0x081A -#define RADIOLIB_SX126X_REG_RANDOM_NUMBER_2 0x081B -#define RADIOLIB_SX126X_REG_RANDOM_NUMBER_3 0x081C -#define RADIOLIB_SX126X_REG_SENSITIVITY_CONFIG 0x0889 // SX1268 datasheet v1.1, section 15.1 -#define RADIOLIB_SX126X_REG_RF_FREQUENCY_0 0x088B -#define RADIOLIB_SX126X_REG_RF_FREQUENCY_1 0x088C -#define RADIOLIB_SX126X_REG_RF_FREQUENCY_2 0x088D -#define RADIOLIB_SX126X_REG_RF_FREQUENCY_3 0x088E -#define RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW 0x089B -#define RADIOLIB_SX126X_REG_RX_GAIN 0x08AC -#define RADIOLIB_SX126X_REG_TX_CLAMP_CONFIG 0x08D8 -#define RADIOLIB_SX126X_REG_ANA_LNA 0x08E2 -#define RADIOLIB_SX126X_REG_LNA_CAP_TUNE_N 0x08E3 -#define RADIOLIB_SX126X_REG_LNA_CAP_TUNE_P 0x08E4 -#define RADIOLIB_SX126X_REG_ANA_MIXER 0x08E5 -#define RADIOLIB_SX126X_REG_OCP_CONFIGURATION 0x08E7 -#define RADIOLIB_SX126X_REG_RTC_CTRL 0x0902 -#define RADIOLIB_SX126X_REG_XTA_TRIM 0x0911 -#define RADIOLIB_SX126X_REG_XTB_TRIM 0x0912 -#define RADIOLIB_SX126X_REG_DIO3_OUT_VOLTAGE_CTRL 0x0920 -#define RADIOLIB_SX126X_REG_EVENT_MASK 0x0944 -#define RADIOLIB_SX126X_REG_PATCH_MEMORY_BASE 0x8000 +#define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_0 0x029F // SX1268 datasheet v1.1, section 9.6 +#define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_1 0x02A0 // SX1268 datasheet v1.1, section 9.6 +#define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_2 0x02A1 // SX1268 datasheet v1.1, section 9.6 +#define RADIOLIB_SX126X_REG_VERSION_STRING 0x0320 +#define RADIOLIB_SX126X_REG_HOPPING_ENABLE 0x0385 +#define RADIOLIB_SX126X_REG_LR_FHSS_PACKET_LENGTH 0x0386 +#define RADIOLIB_SX126X_REG_LR_FHSS_NUM_HOPPING_BLOCKS 0x0387 +#define RADIOLIB_SX126X_REG_LR_FHSS_NUM_SYMBOLS_FREQX_MSB(X) (0x0388 + (X)*6) +#define RADIOLIB_SX126X_REG_LR_FHSS_NUM_SYMBOLS_FREQX_LSB(X) (0x0389 + (X)*6) +#define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_0(X) (0x038A + (X)*6) +#define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_1(X) (0x038B + (X)*6) +#define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_2(X) (0x038C + (X)*6) +#define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_3(X) (0x038D + (X)*6) +#define RADIOLIB_SX126X_REG_SPECTRAL_SCAN_RESULT 0x0401 +#define RADIOLIB_SX126X_REG_DIOX_OUT_ENABLE 0x0580 +#define RADIOLIB_SX126X_REG_DIOX_DRIVE_STRENGTH 0x0582 +#define RADIOLIB_SX126X_REG_DIOX_IN_ENABLE 0x0583 +#define RADIOLIB_SX126X_REG_DIOX_PULL_UP_CTRL 0x0584 +#define RADIOLIB_SX126X_REG_DIOX_PULL_DOWN_CTRL 0x0585 +#define RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_0 0x0587 +#define RADIOLIB_SX126X_REG_PATCH_UPDATE_ENABLE 0x0610 +#define RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_1 0x0680 +#define RADIOLIB_SX126X_REG_WHITENING_INITIAL_MSB 0x06B8 +#define RADIOLIB_SX126X_REG_WHITENING_INITIAL_LSB 0x06B9 +#define RADIOLIB_SX126X_REG_RX_TX_PLD_LEN 0x06BB +#define RADIOLIB_SX126X_REG_CRC_INITIAL_MSB 0x06BC +#define RADIOLIB_SX126X_REG_CRC_INITIAL_LSB 0x06BD +#define RADIOLIB_SX126X_REG_CRC_POLYNOMIAL_MSB 0x06BE +#define RADIOLIB_SX126X_REG_CRC_POLYNOMIAL_LSB 0x06BF +#define RADIOLIB_SX126X_REG_SYNC_WORD_0 0x06C0 +#define RADIOLIB_SX126X_REG_SYNC_WORD_1 0x06C1 +#define RADIOLIB_SX126X_REG_SYNC_WORD_2 0x06C2 +#define RADIOLIB_SX126X_REG_SYNC_WORD_3 0x06C3 +#define RADIOLIB_SX126X_REG_SYNC_WORD_4 0x06C4 +#define RADIOLIB_SX126X_REG_SYNC_WORD_5 0x06C5 +#define RADIOLIB_SX126X_REG_SYNC_WORD_6 0x06C6 +#define RADIOLIB_SX126X_REG_SYNC_WORD_7 0x06C7 +#define RADIOLIB_SX126X_REG_NODE_ADDRESS 0x06CD +#define RADIOLIB_SX126X_REG_BROADCAST_ADDRESS 0x06CE +#define RADIOLIB_SX126X_REG_PAYLOAD_LENGTH 0x0702 +#define RADIOLIB_SX126X_REG_PACKET_PARAMS 0x0704 +#define RADIOLIB_SX126X_REG_LORA_SYNC_TIMEOUT 0x0706 +#define RADIOLIB_SX126X_REG_IQ_CONFIG 0x0736 +#define RADIOLIB_SX126X_REG_LORA_SYNC_WORD_MSB 0x0740 +#define RADIOLIB_SX126X_REG_LORA_SYNC_WORD_LSB 0x0741 +#define RADIOLIB_SX126X_REG_FREQ_ERROR 0x076B +#define RADIOLIB_SX126X_REG_SPECTRAL_SCAN_STATUS 0x07CD +#define RADIOLIB_SX126X_REG_RX_ADDR_PTR 0x0803 +#define RADIOLIB_SX126X_REG_RANDOM_NUMBER_0 0x0819 +#define RADIOLIB_SX126X_REG_RANDOM_NUMBER_1 0x081A +#define RADIOLIB_SX126X_REG_RANDOM_NUMBER_2 0x081B +#define RADIOLIB_SX126X_REG_RANDOM_NUMBER_3 0x081C +#define RADIOLIB_SX126X_REG_SENSITIVITY_CONFIG 0x0889 // SX1268 datasheet v1.1, section 15.1 +#define RADIOLIB_SX126X_REG_RF_FREQUENCY_0 0x088B +#define RADIOLIB_SX126X_REG_RF_FREQUENCY_1 0x088C +#define RADIOLIB_SX126X_REG_RF_FREQUENCY_2 0x088D +#define RADIOLIB_SX126X_REG_RF_FREQUENCY_3 0x088E +#define RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW 0x089B +#define RADIOLIB_SX126X_REG_RX_GAIN 0x08AC +#define RADIOLIB_SX126X_REG_TX_CLAMP_CONFIG 0x08D8 +#define RADIOLIB_SX126X_REG_ANA_LNA 0x08E2 +#define RADIOLIB_SX126X_REG_LNA_CAP_TUNE_N 0x08E3 +#define RADIOLIB_SX126X_REG_LNA_CAP_TUNE_P 0x08E4 +#define RADIOLIB_SX126X_REG_ANA_MIXER 0x08E5 +#define RADIOLIB_SX126X_REG_OCP_CONFIGURATION 0x08E7 +#define RADIOLIB_SX126X_REG_RTC_CTRL 0x0902 +#define RADIOLIB_SX126X_REG_XTA_TRIM 0x0911 +#define RADIOLIB_SX126X_REG_XTB_TRIM 0x0912 +#define RADIOLIB_SX126X_REG_DIO3_OUT_VOLTAGE_CTRL 0x0920 +#define RADIOLIB_SX126X_REG_EVENT_MASK 0x0944 +#define RADIOLIB_SX126X_REG_PATCH_MEMORY_BASE 0x8000 // SX126X SPI command variables -//RADIOLIB_SX126X_CMD_SET_SLEEP MSB LSB DESCRIPTION -#define RADIOLIB_SX126X_SLEEP_START_COLD 0b00000000 // 2 2 sleep mode: cold start, configuration is lost (default) -#define RADIOLIB_SX126X_SLEEP_START_WARM 0b00000100 // 2 2 warm start, configuration is retained -#define RADIOLIB_SX126X_SLEEP_RTC_OFF 0b00000000 // 0 0 wake on RTC timeout: disabled -#define RADIOLIB_SX126X_SLEEP_RTC_ON 0b00000001 // 0 0 enabled +//RADIOLIB_SX126X_CMD_SET_SLEEP MSB LSB DESCRIPTION +#define RADIOLIB_SX126X_SLEEP_START_COLD 0b00000000 // 2 2 sleep mode: cold start, configuration is lost (default) +#define RADIOLIB_SX126X_SLEEP_START_WARM 0b00000100 // 2 2 warm start, configuration is retained +#define RADIOLIB_SX126X_SLEEP_RTC_OFF 0b00000000 // 0 0 wake on RTC timeout: disabled +#define RADIOLIB_SX126X_SLEEP_RTC_ON 0b00000001 // 0 0 enabled //RADIOLIB_SX126X_CMD_SET_STANDBY -#define RADIOLIB_SX126X_STANDBY_RC 0x00 // 7 0 standby mode: 13 MHz RC oscillator -#define RADIOLIB_SX126X_STANDBY_XOSC 0x01 // 7 0 32 MHz crystal oscillator +#define RADIOLIB_SX126X_STANDBY_RC 0x00 // 7 0 standby mode: 13 MHz RC oscillator +#define RADIOLIB_SX126X_STANDBY_XOSC 0x01 // 7 0 32 MHz crystal oscillator //RADIOLIB_SX126X_CMD_SET_RX -#define RADIOLIB_SX126X_RX_TIMEOUT_NONE 0x000000 // 23 0 Rx timeout duration: no timeout (Rx single mode) -#define RADIOLIB_SX126X_RX_TIMEOUT_INF 0xFFFFFF // 23 0 infinite (Rx continuous mode) +#define RADIOLIB_SX126X_RX_TIMEOUT_NONE 0x000000 // 23 0 Rx timeout duration: no timeout (Rx single mode) +#define RADIOLIB_SX126X_RX_TIMEOUT_INF 0xFFFFFF // 23 0 infinite (Rx continuous mode) //RADIOLIB_SX126X_CMD_SET_TX -#define RADIOLIB_SX126X_TX_TIMEOUT_NONE 0x000000 // 23 0 Tx timeout duration: no timeout (Tx single mode) +#define RADIOLIB_SX126X_TX_TIMEOUT_NONE 0x000000 // 23 0 Tx timeout duration: no timeout (Tx single mode) //RADIOLIB_SX126X_CMD_STOP_TIMER_ON_PREAMBLE -#define RADIOLIB_SX126X_STOP_ON_PREAMBLE_OFF 0x00 // 7 0 stop timer on: sync word or header (default) -#define RADIOLIB_SX126X_STOP_ON_PREAMBLE_ON 0x01 // 7 0 preamble detection +#define RADIOLIB_SX126X_STOP_ON_PREAMBLE_OFF 0x00 // 7 0 stop timer on: sync word or header (default) +#define RADIOLIB_SX126X_STOP_ON_PREAMBLE_ON 0x01 // 7 0 preamble detection //RADIOLIB_SX126X_CMD_SET_REGULATOR_MODE -#define RADIOLIB_SX126X_REGULATOR_LDO 0x00 // 7 0 set regulator mode: LDO (default) -#define RADIOLIB_SX126X_REGULATOR_DC_DC 0x01 // 7 0 DC-DC +#define RADIOLIB_SX126X_REGULATOR_LDO 0x00 // 7 0 set regulator mode: LDO (default) +#define RADIOLIB_SX126X_REGULATOR_DC_DC 0x01 // 7 0 DC-DC //RADIOLIB_SX126X_CMD_CALIBRATE -#define RADIOLIB_SX126X_CALIBRATE_IMAGE_OFF 0b00000000 // 6 6 image calibration: disabled -#define RADIOLIB_SX126X_CALIBRATE_IMAGE_ON 0b01000000 // 6 6 enabled -#define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_P_OFF 0b00000000 // 5 5 ADC bulk P calibration: disabled -#define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_P_ON 0b00100000 // 5 5 enabled -#define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_N_OFF 0b00000000 // 4 4 ADC bulk N calibration: disabled -#define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_N_ON 0b00010000 // 4 4 enabled -#define RADIOLIB_SX126X_CALIBRATE_ADC_PULSE_OFF 0b00000000 // 3 3 ADC pulse calibration: disabled -#define RADIOLIB_SX126X_CALIBRATE_ADC_PULSE_ON 0b00001000 // 3 3 enabled -#define RADIOLIB_SX126X_CALIBRATE_PLL_OFF 0b00000000 // 2 2 PLL calibration: disabled -#define RADIOLIB_SX126X_CALIBRATE_PLL_ON 0b00000100 // 2 2 enabled -#define RADIOLIB_SX126X_CALIBRATE_RC13M_OFF 0b00000000 // 1 1 13 MHz RC osc. calibration: disabled -#define RADIOLIB_SX126X_CALIBRATE_RC13M_ON 0b00000010 // 1 1 enabled -#define RADIOLIB_SX126X_CALIBRATE_RC64K_OFF 0b00000000 // 0 0 64 kHz RC osc. calibration: disabled -#define RADIOLIB_SX126X_CALIBRATE_RC64K_ON 0b00000001 // 0 0 enabled -#define RADIOLIB_SX126X_CALIBRATE_ALL 0b01111111 // 6 0 calibrate all blocks +#define RADIOLIB_SX126X_CALIBRATE_IMAGE_OFF 0b00000000 // 6 6 image calibration: disabled +#define RADIOLIB_SX126X_CALIBRATE_IMAGE_ON 0b01000000 // 6 6 enabled +#define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_P_OFF 0b00000000 // 5 5 ADC bulk P calibration: disabled +#define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_P_ON 0b00100000 // 5 5 enabled +#define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_N_OFF 0b00000000 // 4 4 ADC bulk N calibration: disabled +#define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_N_ON 0b00010000 // 4 4 enabled +#define RADIOLIB_SX126X_CALIBRATE_ADC_PULSE_OFF 0b00000000 // 3 3 ADC pulse calibration: disabled +#define RADIOLIB_SX126X_CALIBRATE_ADC_PULSE_ON 0b00001000 // 3 3 enabled +#define RADIOLIB_SX126X_CALIBRATE_PLL_OFF 0b00000000 // 2 2 PLL calibration: disabled +#define RADIOLIB_SX126X_CALIBRATE_PLL_ON 0b00000100 // 2 2 enabled +#define RADIOLIB_SX126X_CALIBRATE_RC13M_OFF 0b00000000 // 1 1 13 MHz RC osc. calibration: disabled +#define RADIOLIB_SX126X_CALIBRATE_RC13M_ON 0b00000010 // 1 1 enabled +#define RADIOLIB_SX126X_CALIBRATE_RC64K_OFF 0b00000000 // 0 0 64 kHz RC osc. calibration: disabled +#define RADIOLIB_SX126X_CALIBRATE_RC64K_ON 0b00000001 // 0 0 enabled +#define RADIOLIB_SX126X_CALIBRATE_ALL 0b01111111 // 6 0 calibrate all blocks //RADIOLIB_SX126X_CMD_CALIBRATE_IMAGE -#define RADIOLIB_SX126X_CAL_IMG_430_MHZ_1 0x6B -#define RADIOLIB_SX126X_CAL_IMG_430_MHZ_2 0x6F -#define RADIOLIB_SX126X_CAL_IMG_470_MHZ_1 0x75 -#define RADIOLIB_SX126X_CAL_IMG_470_MHZ_2 0x81 -#define RADIOLIB_SX126X_CAL_IMG_779_MHZ_1 0xC1 -#define RADIOLIB_SX126X_CAL_IMG_779_MHZ_2 0xC5 -#define RADIOLIB_SX126X_CAL_IMG_863_MHZ_1 0xD7 -#define RADIOLIB_SX126X_CAL_IMG_863_MHZ_2 0xDB -#define RADIOLIB_SX126X_CAL_IMG_902_MHZ_1 0xE1 -#define RADIOLIB_SX126X_CAL_IMG_902_MHZ_2 0xE9 +#define RADIOLIB_SX126X_CAL_IMG_430_MHZ_1 0x6B +#define RADIOLIB_SX126X_CAL_IMG_430_MHZ_2 0x6F +#define RADIOLIB_SX126X_CAL_IMG_470_MHZ_1 0x75 +#define RADIOLIB_SX126X_CAL_IMG_470_MHZ_2 0x81 +#define RADIOLIB_SX126X_CAL_IMG_779_MHZ_1 0xC1 +#define RADIOLIB_SX126X_CAL_IMG_779_MHZ_2 0xC5 +#define RADIOLIB_SX126X_CAL_IMG_863_MHZ_1 0xD7 +#define RADIOLIB_SX126X_CAL_IMG_863_MHZ_2 0xDB +#define RADIOLIB_SX126X_CAL_IMG_902_MHZ_1 0xE1 +#define RADIOLIB_SX126X_CAL_IMG_902_MHZ_2 0xE9 //RADIOLIB_SX126X_CMD_SET_PA_CONFIG -#define RADIOLIB_SX126X_PA_CONFIG_HP_MAX 0x07 -#define RADIOLIB_SX126X_PA_CONFIG_PA_LUT 0x01 -#define RADIOLIB_SX126X_PA_CONFIG_SX1262_8 0x00 +#define RADIOLIB_SX126X_PA_CONFIG_HP_MAX 0x07 +#define RADIOLIB_SX126X_PA_CONFIG_PA_LUT 0x01 +#define RADIOLIB_SX126X_PA_CONFIG_SX1262_8 0x00 //RADIOLIB_SX126X_CMD_SET_RX_TX_FALLBACK_MODE -#define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_FS 0x40 // 7 0 after Rx/Tx go to: FS mode -#define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_XOSC 0x30 // 7 0 standby with crystal oscillator -#define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_RC 0x20 // 7 0 standby with RC oscillator (default) +#define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_FS 0x40 // 7 0 after Rx/Tx go to: FS mode +#define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_XOSC 0x30 // 7 0 standby with crystal oscillator +#define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_RC 0x20 // 7 0 standby with RC oscillator (default) //RADIOLIB_SX126X_CMD_SET_DIO_IRQ_PARAMS -#define RADIOLIB_SX126X_IRQ_LR_FHSS_HOP 0b0100000000000000 // 14 14 PA ramped up during LR-FHSS hop -#define RADIOLIB_SX126X_IRQ_TIMEOUT 0b0000001000000000 // 9 9 Rx or Tx timeout -#define RADIOLIB_SX126X_IRQ_CAD_DETECTED 0b0000000100000000 // 8 8 channel activity detected -#define RADIOLIB_SX126X_IRQ_CAD_DONE 0b0000000010000000 // 7 7 channel activity detection finished -#define RADIOLIB_SX126X_IRQ_CRC_ERR 0b0000000001000000 // 6 6 wrong CRC received -#define RADIOLIB_SX126X_IRQ_HEADER_ERR 0b0000000000100000 // 5 5 LoRa header CRC error -#define RADIOLIB_SX126X_IRQ_HEADER_VALID 0b0000000000010000 // 4 4 valid LoRa header received -#define RADIOLIB_SX126X_IRQ_SYNC_WORD_VALID 0b0000000000001000 // 3 3 valid sync word detected -#define RADIOLIB_SX126X_IRQ_RADIOLIB_PREAMBLE_DETECTED 0b0000000000000100 // 2 2 preamble detected -#define RADIOLIB_SX126X_IRQ_RX_DONE 0b0000000000000010 // 1 1 packet received -#define RADIOLIB_SX126X_IRQ_TX_DONE 0b0000000000000001 // 0 0 packet transmission completed -#define RADIOLIB_SX126X_IRQ_RX_DEFAULT 0b0000001001100010 // 14 0 default for Rx (RX_DONE, TIMEOUT, CRC_ERR and HEADER_ERR) -#define RADIOLIB_SX126X_IRQ_ALL 0b0100001111111111 // 14 0 all interrupts -#define RADIOLIB_SX126X_IRQ_NONE 0b0000000000000000 // 14 0 no interrupts +#define RADIOLIB_SX126X_IRQ_LR_FHSS_HOP 0b0100000000000000 // 14 14 PA ramped up during LR-FHSS hop +#define RADIOLIB_SX126X_IRQ_TIMEOUT 0b0000001000000000 // 9 9 Rx or Tx timeout +#define RADIOLIB_SX126X_IRQ_CAD_DETECTED 0b0000000100000000 // 8 8 channel activity detected +#define RADIOLIB_SX126X_IRQ_CAD_DONE 0b0000000010000000 // 7 7 channel activity detection finished +#define RADIOLIB_SX126X_IRQ_CRC_ERR 0b0000000001000000 // 6 6 wrong CRC received +#define RADIOLIB_SX126X_IRQ_HEADER_ERR 0b0000000000100000 // 5 5 LoRa header CRC error +#define RADIOLIB_SX126X_IRQ_HEADER_VALID 0b0000000000010000 // 4 4 valid LoRa header received +#define RADIOLIB_SX126X_IRQ_SYNC_WORD_VALID 0b0000000000001000 // 3 3 valid sync word detected +#define RADIOLIB_SX126X_IRQ_RADIOLIB_PREAMBLE_DETECTED 0b0000000000000100 // 2 2 preamble detected +#define RADIOLIB_SX126X_IRQ_RX_DONE 0b0000000000000010 // 1 1 packet received +#define RADIOLIB_SX126X_IRQ_TX_DONE 0b0000000000000001 // 0 0 packet transmission completed +#define RADIOLIB_SX126X_IRQ_RX_DEFAULT 0b0000001001100010 // 14 0 default for Rx (RX_DONE, TIMEOUT, CRC_ERR and HEADER_ERR) +#define RADIOLIB_SX126X_IRQ_ALL 0b0100001111111111 // 14 0 all interrupts +#define RADIOLIB_SX126X_IRQ_NONE 0b0000000000000000 // 14 0 no interrupts //RADIOLIB_SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL -#define RADIOLIB_SX126X_DIO2_AS_IRQ 0x00 // 7 0 DIO2 configuration: IRQ -#define RADIOLIB_SX126X_DIO2_AS_RF_SWITCH 0x01 // 7 0 RF switch control +#define RADIOLIB_SX126X_DIO2_AS_IRQ 0x00 // 7 0 DIO2 configuration: IRQ +#define RADIOLIB_SX126X_DIO2_AS_RF_SWITCH 0x01 // 7 0 RF switch control //RADIOLIB_SX126X_CMD_SET_DIO3_AS_TCXO_CTRL -#define RADIOLIB_SX126X_DIO3_OUTPUT_1_6 0x00 // 7 0 DIO3 voltage output for TCXO: 1.6 V -#define RADIOLIB_SX126X_DIO3_OUTPUT_1_7 0x01 // 7 0 1.7 V -#define RADIOLIB_SX126X_DIO3_OUTPUT_1_8 0x02 // 7 0 1.8 V -#define RADIOLIB_SX126X_DIO3_OUTPUT_2_2 0x03 // 7 0 2.2 V -#define RADIOLIB_SX126X_DIO3_OUTPUT_2_4 0x04 // 7 0 2.4 V -#define RADIOLIB_SX126X_DIO3_OUTPUT_2_7 0x05 // 7 0 2.7 V -#define RADIOLIB_SX126X_DIO3_OUTPUT_3_0 0x06 // 7 0 3.0 V -#define RADIOLIB_SX126X_DIO3_OUTPUT_3_3 0x07 // 7 0 3.3 V +#define RADIOLIB_SX126X_DIO3_OUTPUT_1_6 0x00 // 7 0 DIO3 voltage output for TCXO: 1.6 V +#define RADIOLIB_SX126X_DIO3_OUTPUT_1_7 0x01 // 7 0 1.7 V +#define RADIOLIB_SX126X_DIO3_OUTPUT_1_8 0x02 // 7 0 1.8 V +#define RADIOLIB_SX126X_DIO3_OUTPUT_2_2 0x03 // 7 0 2.2 V +#define RADIOLIB_SX126X_DIO3_OUTPUT_2_4 0x04 // 7 0 2.4 V +#define RADIOLIB_SX126X_DIO3_OUTPUT_2_7 0x05 // 7 0 2.7 V +#define RADIOLIB_SX126X_DIO3_OUTPUT_3_0 0x06 // 7 0 3.0 V +#define RADIOLIB_SX126X_DIO3_OUTPUT_3_3 0x07 // 7 0 3.3 V //RADIOLIB_SX126X_CMD_SET_PACKET_TYPE -#define RADIOLIB_SX126X_PACKET_TYPE_GFSK 0x00 // 7 0 packet type: GFSK -#define RADIOLIB_SX126X_PACKET_TYPE_LORA 0x01 // 7 0 LoRa -#define RADIOLIB_SX126X_PACKET_TYPE_LR_FHSS 0x03 // 7 0 LR-FHSS +#define RADIOLIB_SX126X_PACKET_TYPE_GFSK 0x00 // 7 0 packet type: GFSK +#define RADIOLIB_SX126X_PACKET_TYPE_LORA 0x01 // 7 0 LoRa +#define RADIOLIB_SX126X_PACKET_TYPE_LR_FHSS 0x03 // 7 0 LR-FHSS //RADIOLIB_SX126X_CMD_SET_TX_PARAMS -#define RADIOLIB_SX126X_PA_RAMP_10U 0x00 // 7 0 ramp time: 10 us -#define RADIOLIB_SX126X_PA_RAMP_20U 0x01 // 7 0 20 us -#define RADIOLIB_SX126X_PA_RAMP_40U 0x02 // 7 0 40 us -#define RADIOLIB_SX126X_PA_RAMP_80U 0x03 // 7 0 80 us -#define RADIOLIB_SX126X_PA_RAMP_200U 0x04 // 7 0 200 us -#define RADIOLIB_SX126X_PA_RAMP_800U 0x05 // 7 0 800 us -#define RADIOLIB_SX126X_PA_RAMP_1700U 0x06 // 7 0 1700 us -#define RADIOLIB_SX126X_PA_RAMP_3400U 0x07 // 7 0 3400 us +#define RADIOLIB_SX126X_PA_RAMP_10U 0x00 // 7 0 ramp time: 10 us +#define RADIOLIB_SX126X_PA_RAMP_20U 0x01 // 7 0 20 us +#define RADIOLIB_SX126X_PA_RAMP_40U 0x02 // 7 0 40 us +#define RADIOLIB_SX126X_PA_RAMP_80U 0x03 // 7 0 80 us +#define RADIOLIB_SX126X_PA_RAMP_200U 0x04 // 7 0 200 us +#define RADIOLIB_SX126X_PA_RAMP_800U 0x05 // 7 0 800 us +#define RADIOLIB_SX126X_PA_RAMP_1700U 0x06 // 7 0 1700 us +#define RADIOLIB_SX126X_PA_RAMP_3400U 0x07 // 7 0 3400 us //RADIOLIB_SX126X_CMD_SET_MODULATION_PARAMS -#define RADIOLIB_SX126X_GFSK_FILTER_NONE 0x00 // 7 0 GFSK filter: none -#define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_3 0x08 // 7 0 Gaussian, BT = 0.3 -#define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_5 0x09 // 7 0 Gaussian, BT = 0.5 -#define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_7 0x0A // 7 0 Gaussian, BT = 0.7 -#define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_1 0x0B // 7 0 Gaussian, BT = 1 -#define RADIOLIB_SX126X_GFSK_RX_BW_4_8 0x1F // 7 0 GFSK Rx bandwidth: 4.8 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_5_8 0x17 // 7 0 5.8 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_7_3 0x0F // 7 0 7.3 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_9_7 0x1E // 7 0 9.7 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_11_7 0x16 // 7 0 11.7 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_14_6 0x0E // 7 0 14.6 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_19_5 0x1D // 7 0 19.5 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_23_4 0x15 // 7 0 23.4 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_29_3 0x0D // 7 0 29.3 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_39_0 0x1C // 7 0 39.0 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_46_9 0x14 // 7 0 46.9 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_58_6 0x0C // 7 0 58.6 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_78_2 0x1B // 7 0 78.2 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_93_8 0x13 // 7 0 93.8 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_117_3 0x0B // 7 0 117.3 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_156_2 0x1A // 7 0 156.2 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_187_2 0x12 // 7 0 187.2 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_234_3 0x0A // 7 0 234.3 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_312_0 0x19 // 7 0 312.0 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_373_6 0x11 // 7 0 373.6 kHz -#define RADIOLIB_SX126X_GFSK_RX_BW_467_0 0x09 // 7 0 467.0 kHz -#define RADIOLIB_SX126X_LORA_BW_7_8 0x00 // 7 0 LoRa bandwidth: 7.8 kHz -#define RADIOLIB_SX126X_LORA_BW_10_4 0x08 // 7 0 10.4 kHz -#define RADIOLIB_SX126X_LORA_BW_15_6 0x01 // 7 0 15.6 kHz -#define RADIOLIB_SX126X_LORA_BW_20_8 0x09 // 7 0 20.8 kHz -#define RADIOLIB_SX126X_LORA_BW_31_25 0x02 // 7 0 31.25 kHz -#define RADIOLIB_SX126X_LORA_BW_41_7 0x0A // 7 0 41.7 kHz -#define RADIOLIB_SX126X_LORA_BW_62_5 0x03 // 7 0 62.5 kHz -#define RADIOLIB_SX126X_LORA_BW_125_0 0x04 // 7 0 125.0 kHz -#define RADIOLIB_SX126X_LORA_BW_250_0 0x05 // 7 0 250.0 kHz -#define RADIOLIB_SX126X_LORA_BW_500_0 0x06 // 7 0 500.0 kHz -#define RADIOLIB_SX126X_LORA_CR_4_5 0x01 // 7 0 LoRa coding rate: 4/5 -#define RADIOLIB_SX126X_LORA_CR_4_6 0x02 // 7 0 4/6 -#define RADIOLIB_SX126X_LORA_CR_4_7 0x03 // 7 0 4/7 -#define RADIOLIB_SX126X_LORA_CR_4_8 0x04 // 7 0 4/8 -#define RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_OFF 0x00 // 7 0 LoRa low data rate optimization: disabled -#define RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_ON 0x01 // 7 0 enabled +#define RADIOLIB_SX126X_GFSK_FILTER_NONE 0x00 // 7 0 GFSK filter: none +#define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_3 0x08 // 7 0 Gaussian, BT = 0.3 +#define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_5 0x09 // 7 0 Gaussian, BT = 0.5 +#define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_7 0x0A // 7 0 Gaussian, BT = 0.7 +#define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_1 0x0B // 7 0 Gaussian, BT = 1 +#define RADIOLIB_SX126X_GFSK_RX_BW_4_8 0x1F // 7 0 GFSK Rx bandwidth: 4.8 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_5_8 0x17 // 7 0 5.8 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_7_3 0x0F // 7 0 7.3 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_9_7 0x1E // 7 0 9.7 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_11_7 0x16 // 7 0 11.7 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_14_6 0x0E // 7 0 14.6 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_19_5 0x1D // 7 0 19.5 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_23_4 0x15 // 7 0 23.4 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_29_3 0x0D // 7 0 29.3 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_39_0 0x1C // 7 0 39.0 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_46_9 0x14 // 7 0 46.9 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_58_6 0x0C // 7 0 58.6 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_78_2 0x1B // 7 0 78.2 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_93_8 0x13 // 7 0 93.8 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_117_3 0x0B // 7 0 117.3 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_156_2 0x1A // 7 0 156.2 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_187_2 0x12 // 7 0 187.2 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_234_3 0x0A // 7 0 234.3 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_312_0 0x19 // 7 0 312.0 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_373_6 0x11 // 7 0 373.6 kHz +#define RADIOLIB_SX126X_GFSK_RX_BW_467_0 0x09 // 7 0 467.0 kHz +#define RADIOLIB_SX126X_LORA_BW_7_8 0x00 // 7 0 LoRa bandwidth: 7.8 kHz +#define RADIOLIB_SX126X_LORA_BW_10_4 0x08 // 7 0 10.4 kHz +#define RADIOLIB_SX126X_LORA_BW_15_6 0x01 // 7 0 15.6 kHz +#define RADIOLIB_SX126X_LORA_BW_20_8 0x09 // 7 0 20.8 kHz +#define RADIOLIB_SX126X_LORA_BW_31_25 0x02 // 7 0 31.25 kHz +#define RADIOLIB_SX126X_LORA_BW_41_7 0x0A // 7 0 41.7 kHz +#define RADIOLIB_SX126X_LORA_BW_62_5 0x03 // 7 0 62.5 kHz +#define RADIOLIB_SX126X_LORA_BW_125_0 0x04 // 7 0 125.0 kHz +#define RADIOLIB_SX126X_LORA_BW_250_0 0x05 // 7 0 250.0 kHz +#define RADIOLIB_SX126X_LORA_BW_500_0 0x06 // 7 0 500.0 kHz +#define RADIOLIB_SX126X_LORA_CR_4_5 0x01 // 7 0 LoRa coding rate: 4/5 +#define RADIOLIB_SX126X_LORA_CR_4_6 0x02 // 7 0 4/6 +#define RADIOLIB_SX126X_LORA_CR_4_7 0x03 // 7 0 4/7 +#define RADIOLIB_SX126X_LORA_CR_4_8 0x04 // 7 0 4/8 +#define RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_OFF 0x00 // 7 0 LoRa low data rate optimization: disabled +#define RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_ON 0x01 // 7 0 enabled //RADIOLIB_SX126X_CMD_SET_PACKET_PARAMS -#define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_OFF 0x00 // 7 0 GFSK minimum preamble length before reception starts: detector disabled -#define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_8 0x04 // 7 0 8 bits -#define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16 0x05 // 7 0 16 bits -#define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_24 0x06 // 7 0 24 bits -#define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_32 0x07 // 7 0 32 bits -#define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF 0x00 // 7 0 GFSK address filtering: disabled -#define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE 0x01 // 7 0 node only -#define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE_BROADCAST 0x02 // 7 0 node and broadcast -#define RADIOLIB_SX126X_GFSK_PACKET_FIXED 0x00 // 7 0 GFSK packet type: fixed (payload length known in advance to both sides) -#define RADIOLIB_SX126X_GFSK_PACKET_VARIABLE 0x01 // 7 0 variable (payload length added to packet) -#define RADIOLIB_SX126X_GFSK_CRC_OFF 0x01 // 7 0 GFSK packet CRC: disabled -#define RADIOLIB_SX126X_GFSK_CRC_1_BYTE 0x00 // 7 0 1 byte -#define RADIOLIB_SX126X_GFSK_CRC_2_BYTE 0x02 // 7 0 2 byte -#define RADIOLIB_SX126X_GFSK_CRC_1_BYTE_INV 0x04 // 7 0 1 byte, inverted -#define RADIOLIB_SX126X_GFSK_CRC_2_BYTE_INV 0x06 // 7 0 2 byte, inverted -#define RADIOLIB_SX126X_GFSK_WHITENING_OFF 0x00 // 7 0 GFSK data whitening: disabled -#define RADIOLIB_SX126X_GFSK_WHITENING_ON 0x01 // 7 0 enabled -#define RADIOLIB_SX126X_LORA_HEADER_EXPLICIT 0x00 // 7 0 LoRa header mode: explicit -#define RADIOLIB_SX126X_LORA_HEADER_IMPLICIT 0x01 // 7 0 implicit -#define RADIOLIB_SX126X_LORA_CRC_OFF 0x00 // 7 0 LoRa CRC mode: disabled -#define RADIOLIB_SX126X_LORA_CRC_ON 0x01 // 7 0 enabled -#define RADIOLIB_SX126X_LORA_IQ_STANDARD 0x00 // 7 0 LoRa IQ setup: standard -#define RADIOLIB_SX126X_LORA_IQ_INVERTED 0x01 // 7 0 inverted +#define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_OFF 0x00 // 7 0 GFSK minimum preamble length before reception starts: detector disabled +#define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_8 0x04 // 7 0 8 bits +#define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16 0x05 // 7 0 16 bits +#define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_24 0x06 // 7 0 24 bits +#define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_32 0x07 // 7 0 32 bits +#define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF 0x00 // 7 0 GFSK address filtering: disabled +#define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE 0x01 // 7 0 node only +#define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE_BROADCAST 0x02 // 7 0 node and broadcast +#define RADIOLIB_SX126X_GFSK_PACKET_FIXED 0x00 // 7 0 GFSK packet type: fixed (payload length known in advance to both sides) +#define RADIOLIB_SX126X_GFSK_PACKET_VARIABLE 0x01 // 7 0 variable (payload length added to packet) +#define RADIOLIB_SX126X_GFSK_CRC_OFF 0x01 // 7 0 GFSK packet CRC: disabled +#define RADIOLIB_SX126X_GFSK_CRC_1_BYTE 0x00 // 7 0 1 byte +#define RADIOLIB_SX126X_GFSK_CRC_2_BYTE 0x02 // 7 0 2 byte +#define RADIOLIB_SX126X_GFSK_CRC_1_BYTE_INV 0x04 // 7 0 1 byte, inverted +#define RADIOLIB_SX126X_GFSK_CRC_2_BYTE_INV 0x06 // 7 0 2 byte, inverted +#define RADIOLIB_SX126X_GFSK_WHITENING_OFF 0x00 // 7 0 GFSK data whitening: disabled +#define RADIOLIB_SX126X_GFSK_WHITENING_ON 0x01 // 7 0 enabled +#define RADIOLIB_SX126X_LORA_HEADER_EXPLICIT 0x00 // 7 0 LoRa header mode: explicit +#define RADIOLIB_SX126X_LORA_HEADER_IMPLICIT 0x01 // 7 0 implicit +#define RADIOLIB_SX126X_LORA_CRC_OFF 0x00 // 7 0 LoRa CRC mode: disabled +#define RADIOLIB_SX126X_LORA_CRC_ON 0x01 // 7 0 enabled +#define RADIOLIB_SX126X_LORA_IQ_STANDARD 0x00 // 7 0 LoRa IQ setup: standard +#define RADIOLIB_SX126X_LORA_IQ_INVERTED 0x01 // 7 0 inverted //RADIOLIB_SX126X_CMD_SET_CAD_PARAMS -#define RADIOLIB_SX126X_CAD_ON_1_SYMB 0x00 // 7 0 number of symbols used for CAD: 1 -#define RADIOLIB_SX126X_CAD_ON_2_SYMB 0x01 // 7 0 2 -#define RADIOLIB_SX126X_CAD_ON_4_SYMB 0x02 // 7 0 4 -#define RADIOLIB_SX126X_CAD_ON_8_SYMB 0x03 // 7 0 8 -#define RADIOLIB_SX126X_CAD_ON_16_SYMB 0x04 // 7 0 16 -#define RADIOLIB_SX126X_CAD_GOTO_STDBY 0x00 // 7 0 after CAD is done, always go to STDBY_RC mode -#define RADIOLIB_SX126X_CAD_GOTO_RX 0x01 // 7 0 after CAD is done, go to Rx mode if activity is detected -#define RADIOLIB_SX126X_CAD_PARAM_DEFAULT 0xFF // 7 0 used by the CAD methods to specify default parameter value -#define RADIOLIB_SX126X_CAD_PARAM_DET_MIN 10 // 7 0 default detMin CAD parameter +#define RADIOLIB_SX126X_CAD_ON_1_SYMB 0x00 // 7 0 number of symbols used for CAD: 1 +#define RADIOLIB_SX126X_CAD_ON_2_SYMB 0x01 // 7 0 2 +#define RADIOLIB_SX126X_CAD_ON_4_SYMB 0x02 // 7 0 4 +#define RADIOLIB_SX126X_CAD_ON_8_SYMB 0x03 // 7 0 8 +#define RADIOLIB_SX126X_CAD_ON_16_SYMB 0x04 // 7 0 16 +#define RADIOLIB_SX126X_CAD_GOTO_STDBY 0x00 // 7 0 after CAD is done, always go to STDBY_RC mode +#define RADIOLIB_SX126X_CAD_GOTO_RX 0x01 // 7 0 after CAD is done, go to Rx mode if activity is detected +#define RADIOLIB_SX126X_CAD_PARAM_DEFAULT 0xFF // 7 0 used by the CAD methods to specify default parameter value +#define RADIOLIB_SX126X_CAD_PARAM_DET_MIN 10 // 7 0 default detMin CAD parameter //RADIOLIB_SX126X_CMD_GET_STATUS -#define RADIOLIB_SX126X_STATUS_MODE_STDBY_RC 0b00100000 // 6 4 current chip mode: STDBY_RC -#define RADIOLIB_SX126X_STATUS_MODE_STDBY_XOSC 0b00110000 // 6 4 STDBY_XOSC -#define RADIOLIB_SX126X_STATUS_MODE_FS 0b01000000 // 6 4 FS -#define RADIOLIB_SX126X_STATUS_MODE_RX 0b01010000 // 6 4 RX -#define RADIOLIB_SX126X_STATUS_MODE_TX 0b01100000 // 6 4 TX -#define RADIOLIB_SX126X_STATUS_DATA_AVAILABLE 0b00000100 // 3 1 command status: packet received and data can be retrieved -#define RADIOLIB_SX126X_STATUS_CMD_TIMEOUT 0b00000110 // 3 1 SPI command timed out -#define RADIOLIB_SX126X_STATUS_CMD_INVALID 0b00001000 // 3 1 invalid SPI command -#define RADIOLIB_SX126X_STATUS_CMD_FAILED 0b00001010 // 3 1 SPI command failed to execute -#define RADIOLIB_SX126X_STATUS_TX_DONE 0b00001100 // 3 1 packet transmission done -#define RADIOLIB_SX126X_STATUS_SPI_FAILED 0b11111111 // 7 0 SPI transaction failed +#define RADIOLIB_SX126X_STATUS_MODE_STDBY_RC 0b00100000 // 6 4 current chip mode: STDBY_RC +#define RADIOLIB_SX126X_STATUS_MODE_STDBY_XOSC 0b00110000 // 6 4 STDBY_XOSC +#define RADIOLIB_SX126X_STATUS_MODE_FS 0b01000000 // 6 4 FS +#define RADIOLIB_SX126X_STATUS_MODE_RX 0b01010000 // 6 4 RX +#define RADIOLIB_SX126X_STATUS_MODE_TX 0b01100000 // 6 4 TX +#define RADIOLIB_SX126X_STATUS_DATA_AVAILABLE 0b00000100 // 3 1 command status: packet received and data can be retrieved +#define RADIOLIB_SX126X_STATUS_CMD_TIMEOUT 0b00000110 // 3 1 SPI command timed out +#define RADIOLIB_SX126X_STATUS_CMD_INVALID 0b00001000 // 3 1 invalid SPI command +#define RADIOLIB_SX126X_STATUS_CMD_FAILED 0b00001010 // 3 1 SPI command failed to execute +#define RADIOLIB_SX126X_STATUS_TX_DONE 0b00001100 // 3 1 packet transmission done +#define RADIOLIB_SX126X_STATUS_SPI_FAILED 0b11111111 // 7 0 SPI transaction failed //RADIOLIB_SX126X_CMD_GET_PACKET_STATUS -#define RADIOLIB_SX126X_GFSK_RX_STATUS_PREAMBLE_ERR 0b10000000 // 7 7 GFSK Rx status: preamble error -#define RADIOLIB_SX126X_GFSK_RX_STATUS_SYNC_ERR 0b01000000 // 6 6 sync word error -#define RADIOLIB_SX126X_GFSK_RX_STATUS_ADRS_ERR 0b00100000 // 5 5 address error -#define RADIOLIB_SX126X_GFSK_RX_STATUS_CRC_ERR 0b00010000 // 4 4 CRC error -#define RADIOLIB_SX126X_GFSK_RX_STATUS_LENGTH_ERR 0b00001000 // 3 3 length error -#define RADIOLIB_SX126X_GFSK_RX_STATUS_ABORT_ERR 0b00000100 // 2 2 abort error -#define RADIOLIB_SX126X_GFSK_RX_STATUS_PACKET_RECEIVED 0b00000010 // 2 2 packet received -#define RADIOLIB_SX126X_GFSK_RX_STATUS_PACKET_SENT 0b00000001 // 2 2 packet sent +#define RADIOLIB_SX126X_GFSK_RX_STATUS_PREAMBLE_ERR 0b10000000 // 7 7 GFSK Rx status: preamble error +#define RADIOLIB_SX126X_GFSK_RX_STATUS_SYNC_ERR 0b01000000 // 6 6 sync word error +#define RADIOLIB_SX126X_GFSK_RX_STATUS_ADRS_ERR 0b00100000 // 5 5 address error +#define RADIOLIB_SX126X_GFSK_RX_STATUS_CRC_ERR 0b00010000 // 4 4 CRC error +#define RADIOLIB_SX126X_GFSK_RX_STATUS_LENGTH_ERR 0b00001000 // 3 3 length error +#define RADIOLIB_SX126X_GFSK_RX_STATUS_ABORT_ERR 0b00000100 // 2 2 abort error +#define RADIOLIB_SX126X_GFSK_RX_STATUS_PACKET_RECEIVED 0b00000010 // 2 2 packet received +#define RADIOLIB_SX126X_GFSK_RX_STATUS_PACKET_SENT 0b00000001 // 2 2 packet sent //RADIOLIB_SX126X_CMD_GET_DEVICE_ERRORS -#define RADIOLIB_SX126X_PA_RAMP_ERR 0b100000000 // 8 8 device errors: PA ramping failed -#define RADIOLIB_SX126X_PLL_LOCK_ERR 0b001000000 // 6 6 PLL failed to lock -#define RADIOLIB_SX126X_XOSC_START_ERR 0b000100000 // 5 5 crystal oscillator failed to start -#define RADIOLIB_SX126X_IMG_CALIB_ERR 0b000010000 // 4 4 image calibration failed -#define RADIOLIB_SX126X_ADC_CALIB_ERR 0b000001000 // 3 3 ADC calibration failed -#define RADIOLIB_SX126X_PLL_CALIB_ERR 0b000000100 // 2 2 PLL calibration failed -#define RADIOLIB_SX126X_RC13M_CALIB_ERR 0b000000010 // 1 1 RC13M calibration failed -#define RADIOLIB_SX126X_RC64K_CALIB_ERR 0b000000001 // 0 0 RC64K calibration failed +#define RADIOLIB_SX126X_PA_RAMP_ERR 0b100000000 // 8 8 device errors: PA ramping failed +#define RADIOLIB_SX126X_PLL_LOCK_ERR 0b001000000 // 6 6 PLL failed to lock +#define RADIOLIB_SX126X_XOSC_START_ERR 0b000100000 // 5 5 crystal oscillator failed to start +#define RADIOLIB_SX126X_IMG_CALIB_ERR 0b000010000 // 4 4 image calibration failed +#define RADIOLIB_SX126X_ADC_CALIB_ERR 0b000001000 // 3 3 ADC calibration failed +#define RADIOLIB_SX126X_PLL_CALIB_ERR 0b000000100 // 2 2 PLL calibration failed +#define RADIOLIB_SX126X_RC13M_CALIB_ERR 0b000000010 // 1 1 RC13M calibration failed +#define RADIOLIB_SX126X_RC64K_CALIB_ERR 0b000000001 // 0 0 RC64K calibration failed //RADIOLIB_SX126X_CMD_SET_LBT_SCAN_PARAMS + RADIOLIB_SX126X_CMD_SET_SPECTR_SCAN_PARAMS -#define RADIOLIB_SX126X_SCAN_INTERVAL_7_68_US 10 // 7 0 RSSI reading interval: 7.68 us -#define RADIOLIB_SX126X_SCAN_INTERVAL_8_20_US 11 // 7 0 8.20 us -#define RADIOLIB_SX126X_SCAN_INTERVAL_8_68_US 12 // 7 0 8.68 us +#define RADIOLIB_SX126X_SCAN_INTERVAL_7_68_US 10 // 7 0 RSSI reading interval: 7.68 us +#define RADIOLIB_SX126X_SCAN_INTERVAL_8_20_US 11 // 7 0 8.20 us +#define RADIOLIB_SX126X_SCAN_INTERVAL_8_68_US 12 // 7 0 8.68 us // SX126X SPI register variables //RADIOLIB_SX126X_REG_HOPPING_ENABLE -#define RADIOLIB_SX126X_HOPPING_ENABLED 0b00000001 // 0 0 intra-packet hopping for LR-FHSS: enabled -#define RADIOLIB_SX126X_HOPPING_DISABLED 0b00000000 // 0 0 (disabled) +#define RADIOLIB_SX126X_HOPPING_ENABLED 0b00000001 // 0 0 intra-packet hopping for LR-FHSS: enabled +#define RADIOLIB_SX126X_HOPPING_DISABLED 0b00000000 // 0 0 (disabled) //RADIOLIB_SX126X_REG_LORA_SYNC_WORD_MSB + LSB -#define RADIOLIB_SX126X_SYNC_WORD_PUBLIC 0x34 // actually 0x3444 NOTE: The low nibbles in each byte (0x_4_4) are masked out since apparently, they're reserved. -#define RADIOLIB_SX126X_SYNC_WORD_PRIVATE 0x12 // actually 0x1424 You couldn't make this up if you tried. +#define RADIOLIB_SX126X_SYNC_WORD_PUBLIC 0x34 // actually 0x3444 NOTE: The low nibbles in each byte (0x_4_4) are masked out since apparently, they're reserved. +#define RADIOLIB_SX126X_SYNC_WORD_PRIVATE 0x12 // actually 0x1424 You couldn't make this up if you tried. // RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_1 -#define RADIOLIB_SX126X_TX_BITBANG_1_DISABLED 0b00000000 // 6 4 Tx bitbang: disabled (default) -#define RADIOLIB_SX126X_TX_BITBANG_1_ENABLED 0b00010000 // 6 4 enabled +#define RADIOLIB_SX126X_TX_BITBANG_1_DISABLED 0b00000000 // 6 4 Tx bitbang: disabled (default) +#define RADIOLIB_SX126X_TX_BITBANG_1_ENABLED 0b00010000 // 6 4 enabled // RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_0 -#define RADIOLIB_SX126X_TX_BITBANG_0_DISABLED 0b00000000 // 3 0 Tx bitbang: disabled (default) -#define RADIOLIB_SX126X_TX_BITBANG_0_ENABLED 0b00001100 // 3 0 enabled +#define RADIOLIB_SX126X_TX_BITBANG_0_DISABLED 0b00000000 // 3 0 Tx bitbang: disabled (default) +#define RADIOLIB_SX126X_TX_BITBANG_0_ENABLED 0b00001100 // 3 0 enabled // RADIOLIB_SX126X_REG_DIOX_OUT_ENABLE -#define RADIOLIB_SX126X_DIO1_OUT_DISABLED 0b00000010 // 1 1 DIO1 output: disabled -#define RADIOLIB_SX126X_DIO1_OUT_ENABLED 0b00000000 // 1 1 enabled -#define RADIOLIB_SX126X_DIO2_OUT_DISABLED 0b00000100 // 2 2 DIO2 output: disabled -#define RADIOLIB_SX126X_DIO2_OUT_ENABLED 0b00000000 // 2 2 enabled -#define RADIOLIB_SX126X_DIO3_OUT_DISABLED 0b00001000 // 3 3 DIO3 output: disabled -#define RADIOLIB_SX126X_DIO3_OUT_ENABLED 0b00000000 // 3 3 enabled +#define RADIOLIB_SX126X_DIO1_OUT_DISABLED 0b00000010 // 1 1 DIO1 output: disabled +#define RADIOLIB_SX126X_DIO1_OUT_ENABLED 0b00000000 // 1 1 enabled +#define RADIOLIB_SX126X_DIO2_OUT_DISABLED 0b00000100 // 2 2 DIO2 output: disabled +#define RADIOLIB_SX126X_DIO2_OUT_ENABLED 0b00000000 // 2 2 enabled +#define RADIOLIB_SX126X_DIO3_OUT_DISABLED 0b00001000 // 3 3 DIO3 output: disabled +#define RADIOLIB_SX126X_DIO3_OUT_ENABLED 0b00000000 // 3 3 enabled // RADIOLIB_SX126X_REG_DIOX_IN_ENABLE -#define RADIOLIB_SX126X_DIO1_IN_DISABLED 0b00000000 // 1 1 DIO1 input: disabled -#define RADIOLIB_SX126X_DIO1_IN_ENABLED 0b00000010 // 1 1 enabled -#define RADIOLIB_SX126X_DIO2_IN_DISABLED 0b00000000 // 2 2 DIO2 input: disabled -#define RADIOLIB_SX126X_DIO2_IN_ENABLED 0b00000100 // 2 2 enabled -#define RADIOLIB_SX126X_DIO3_IN_DISABLED 0b00000000 // 3 3 DIO3 input: disabled -#define RADIOLIB_SX126X_DIO3_IN_ENABLED 0b00001000 // 3 3 enabled +#define RADIOLIB_SX126X_DIO1_IN_DISABLED 0b00000000 // 1 1 DIO1 input: disabled +#define RADIOLIB_SX126X_DIO1_IN_ENABLED 0b00000010 // 1 1 enabled +#define RADIOLIB_SX126X_DIO2_IN_DISABLED 0b00000000 // 2 2 DIO2 input: disabled +#define RADIOLIB_SX126X_DIO2_IN_ENABLED 0b00000100 // 2 2 enabled +#define RADIOLIB_SX126X_DIO3_IN_DISABLED 0b00000000 // 3 3 DIO3 input: disabled +#define RADIOLIB_SX126X_DIO3_IN_ENABLED 0b00001000 // 3 3 enabled // RADIOLIB_SX126X_REG_RX_GAIN -#define RADIOLIB_SX126X_RX_GAIN_BOOSTED 0x96 // 7 0 Rx gain: boosted -#define RADIOLIB_SX126X_RX_GAIN_POWER_SAVING 0x94 // 7 0 power saving -#define RADIOLIB_SX126X_RX_GAIN_SPECTRAL_SCAN 0xCB // 7 0 spectral scan +#define RADIOLIB_SX126X_RX_GAIN_BOOSTED 0x96 // 7 0 Rx gain: boosted +#define RADIOLIB_SX126X_RX_GAIN_POWER_SAVING 0x94 // 7 0 power saving +#define RADIOLIB_SX126X_RX_GAIN_SPECTRAL_SCAN 0xCB // 7 0 spectral scan // RADIOLIB_SX126X_REG_PATCH_UPDATE_ENABLE -#define RADIOLIB_SX126X_PATCH_UPDATE_DISABLED 0b00000000 // 4 4 patch update: disabled -#define RADIOLIB_SX126X_PATCH_UPDATE_ENABLED 0b00010000 // 4 4 enabled +#define RADIOLIB_SX126X_PATCH_UPDATE_DISABLED 0b00000000 // 4 4 patch update: disabled +#define RADIOLIB_SX126X_PATCH_UPDATE_ENABLED 0b00010000 // 4 4 enabled // RADIOLIB_SX126X_REG_SPECTRAL_SCAN_STATUS -#define RADIOLIB_SX126X_SPECTRAL_SCAN_NONE 0x00 // 7 0 spectral scan status: none -#define RADIOLIB_SX126X_SPECTRAL_SCAN_ONGOING 0x0F // 7 0 ongoing -#define RADIOLIB_SX126X_SPECTRAL_SCAN_ABORTED 0xF0 // 7 0 aborted -#define RADIOLIB_SX126X_SPECTRAL_SCAN_COMPLETED 0xFF // 7 0 completed +#define RADIOLIB_SX126X_SPECTRAL_SCAN_NONE 0x00 // 7 0 spectral scan status: none +#define RADIOLIB_SX126X_SPECTRAL_SCAN_ONGOING 0x0F // 7 0 ongoing +#define RADIOLIB_SX126X_SPECTRAL_SCAN_ABORTED 0xF0 // 7 0 aborted +#define RADIOLIB_SX126X_SPECTRAL_SCAN_COMPLETED 0xFF // 7 0 completed // RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW -#define RADIOLIB_SX126X_SPECTRAL_SCAN_WINDOW_DEFAULT (0x05 << 2) // 7 0 default RSSI average window +#define RADIOLIB_SX126X_SPECTRAL_SCAN_WINDOW_DEFAULT (0x05 << 2) // 7 0 default RSSI average window // RADIOLIB_SX126X_REG_ANA_LNA -#define RADIOLIB_SX126X_LNA_RNG_DISABLED 0b00000001 // 0 0 random number: disabled -#define RADIOLIB_SX126X_LNA_RNG_ENABLED 0b00000000 // 0 0 enabled +#define RADIOLIB_SX126X_LNA_RNG_DISABLED 0b00000001 // 0 0 random number: disabled +#define RADIOLIB_SX126X_LNA_RNG_ENABLED 0b00000000 // 0 0 enabled // RADIOLIB_SX126X_REG_ANA_MIXER -#define RADIOLIB_SX126X_MIXER_RNG_DISABLED 0b00000001 // 7 7 random number: disabled -#define RADIOLIB_SX126X_MIXER_RNG_ENABLED 0b00000000 // 7 7 enabled +#define RADIOLIB_SX126X_MIXER_RNG_DISABLED 0b00000001 // 7 7 random number: disabled +#define RADIOLIB_SX126X_MIXER_RNG_ENABLED 0b00000000 // 7 7 enabled // size of the spectral scan result -#define RADIOLIB_SX126X_SPECTRAL_SCAN_RES_SIZE (33) +#define RADIOLIB_SX126X_SPECTRAL_SCAN_RES_SIZE (33) /*! \class SX126x - \brief Base class for %SX126x series. All derived classes for %SX126x (e.g. SX1262 or SX1268) inherit from this base class. This class should not be instantiated directly from Arduino sketch, only from its derived classes. */ @@ -451,7 +450,6 @@ class SX126x: public PhysicalLayer { /*! \brief Default constructor. - \param mod Instance of Module that will be used to communicate with the radio. */ SX126x(Module* mod); @@ -467,46 +465,32 @@ class SX126x: public PhysicalLayer { /*! \brief Initialization method for LoRa modem. - \param cr LoRa coding rate denominator. Allowed values range from 5 to 8. - \param syncWord 1-byte LoRa sync word. - \param preambleLength LoRa preamble length in symbols. Allowed values range from 1 to 65535. - \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. - \param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false. - \returns \ref status_codes */ int16_t begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO = false); /*! \brief Initialization method for FSK modem. - \param br FSK bit rate in kbps. Allowed values range from 0.6 to 300.0 kbps. - \param freqDev Frequency deviation from carrier frequency in kHz. Allowed values range from 0.0 to 200.0 kHz. - - \param rxBw Receiver bandwidth in kHz. Allowed values are 4.8, 5.8, 7.3, 9.7, 11.7, 14.6, 19.5, 23.4, 29.3, 39.0, 46.9, 58.6, 78.2, 93.8, 117.3, 156.2, 187.2, 234.3, 312.0, 373.6 and 467.0 kHz. - + \param rxBw Receiver bandwidth in kHz. Allowed values are 4.8, 5.8, 7.3, 9.7, 11.7, 14.6, 19.5, 23.4, 29.3, 39.0, + 46.9, 58.6, 78.2, 93.8, 117.3, 156.2, 187.2, 234.3, 312.0, 373.6 and 467.0 kHz. \param preambleLength FSK preamble length in bits. Allowed values range from 0 to 65535. - \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. - \param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false. - \returns \ref status_codes */ int16_t beginFSK(float br, float freqDev, float rxBw, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO = false); /*! \brief Reset method. Will reset the chip to the default state using RST pin. - \param verify Whether correct module startup should be verified. When set to true, RadioLib will attempt to verify the module has started correctly by repeatedly issuing setStandby command. Enabled by default. - \returns \ref status_codes */ int16_t reset(bool verify = true); @@ -514,13 +498,9 @@ class SX126x: public PhysicalLayer { /*! \brief Blocking binary transmit method. Overloads for string-based transmissions are implemented in PhysicalLayer. - \param data Binary data to be sent. - \param len Number of bytes to send. - \param addr Address to send the data to. Will only be added if address filtering was enabled. - \returns \ref status_codes */ int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override; @@ -528,20 +508,15 @@ class SX126x: public PhysicalLayer { /*! \brief Blocking binary receive method. Overloads for string-based transmissions are implemented in PhysicalLayer. - \param data Binary data to be sent. - \param len Number of bytes to send. - \returns \ref status_codes */ int16_t receive(uint8_t* data, size_t len) override; /*! \brief Starts direct mode transmission. - \param frf Raw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY. - \returns \ref status_codes */ int16_t transmitDirect(uint32_t frf = 0) override; @@ -549,45 +524,37 @@ class SX126x: public PhysicalLayer { /*! \brief Starts direct mode reception. Only implemented for PhysicalLayer compatibility, as %SX126x series does not support direct mode reception. Will always return RADIOLIB_ERR_UNKNOWN. - \returns \ref status_codes */ int16_t receiveDirect() override; /*! \brief Performs scan for LoRa transmission in the current channel. Detects both preamble and payload. - \param symbolNum Number of symbols for CAD detection. Defaults to the value recommended by AN1200.48. - \param detPeak Peak value for CAD detection. Defaults to the value recommended by AN1200.48. - \param detMin Minimum value for CAD detection. Defaults to the value recommended by AN1200.48. - \returns \ref status_codes */ int16_t scanChannel(uint8_t symbolNum = RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detPeak = RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detMin = RADIOLIB_SX126X_CAD_PARAM_DEFAULT); /*! \brief Sets the module to sleep mode. - - \param retainConfig Set to true to retain configuration of the currently active modem ("warm start") or to false to discard current configuration ("cold start"). Defaults to true. - + \param retainConfig Set to true to retain configuration of the currently active modem ("warm start") + or to false to discard current configuration ("cold start"). Defaults to true. \returns \ref status_codes */ int16_t sleep(bool retainConfig = true); /*! \brief Sets the module to standby mode (overload for PhysicalLayer compatibility, uses 13 MHz RC oscillator). - \returns \ref status_codes */ int16_t standby() override; /*! \brief Sets the module to standby mode. - - \param mode Oscillator to be used in standby mode. Can be set to RADIOLIB_SX126X_STANDBY_RC (13 MHz RC oscillator) or RADIOLIB_SX126X_STANDBY_XOSC (32 MHz external crystal oscillator). - + \param mode Oscillator to be used in standby mode. Can be set to RADIOLIB_SX126X_STANDBY_RC (13 MHz RC oscillator) + or RADIOLIB_SX126X_STANDBY_XOSC (32 MHz external crystal oscillator). \returns \ref status_codes */ int16_t standby(uint8_t mode); @@ -596,7 +563,6 @@ class SX126x: public PhysicalLayer { /*! \brief Sets interrupt service routine to call when DIO1 activates. - \param func ISR to call. */ void setDio1Action(void (*func)(void)); @@ -609,110 +575,91 @@ class SX126x: public PhysicalLayer { /*! \brief Interrupt-driven binary transmit method. Overloads for string-based transmissions are implemented in PhysicalLayer. - \param data Binary data to be sent. - \param len Number of bytes to send. - \param addr Address to send the data to. Will only be added if address filtering was enabled. - \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. DIO1 will be activated when full packet is received. - \param timeout Receive mode type and/or raw timeout value, expressed as multiples of 15.625 us. - When set to RADIOLIB_SX126X_RX_TIMEOUT_INF, the timeout will be infinite and the device will remain in Rx mode until explicitly commanded to stop (Rx continuous mode). - When set to RADIOLIB_SX126X_RX_TIMEOUT_NONE, there will be no timeout and the device will return to standby when a packet is received (Rx single mode). - For any other value, timeout will be applied and signal will be generated on DIO1 for conditions defined by irqFlags and irqMask. + When set to RADIOLIB_SX126X_RX_TIMEOUT_INF, the timeout will be infinite and the device will remain + in Rx mode until explicitly commanded to stop (Rx continuous mode). + When set to RADIOLIB_SX126X_RX_TIMEOUT_NONE, there will be no timeout and the device will return + to standby when a packet is received (Rx single mode). + For any other value, timeout will be applied and signal will be generated on DIO1 for conditions + defined by irqFlags and irqMask. \param irqFlags Sets the IRQ flags, defaults to RADIOLIB_SX126X_IRQ_RX_DEFAULT. - \param irqMask Sets the mask of IRQ flags that will trigger DIO1, defaults to RADIOLIB_SX126X_IRQ_RX_DONE. - \param len Only for PhysicalLayer compatibility, not used. - \returns \ref status_codes */ int16_t startReceive(uint32_t timeout = RADIOLIB_SX126X_RX_TIMEOUT_INF, uint16_t irqFlags = RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask = RADIOLIB_SX126X_IRQ_RX_DONE, size_t len = 0); /*! \brief Interrupt-driven receive method where the device mostly sleeps and periodically wakes to listen. - Note that this function assumes the unit will take 500us + TCXO_delay to change state. See datasheet section 13.1.7, version 1.2. - + Note that this function assumes the unit will take 500us + TCXO_delay to change state. + See datasheet section 13.1.7, version 1.2. \param rxPeriod The duration the receiver will be in Rx mode, in microseconds. - \param sleepPeriod The duration the receiver will not be in Rx mode, in microseconds. - \param irqFlags Sets the IRQ flags, defaults to RADIOLIB_SX126X_IRQ_RX_DEFAULT. - \param irqMask Sets the mask of IRQ flags that will trigger DIO1, defaults to RADIOLIB_SX126X_IRQ_RX_DONE. - \returns \ref status_codes */ int16_t startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod, uint16_t irqFlags = RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask = RADIOLIB_SX126X_IRQ_RX_DONE); /*! \brief Calls \ref startReceiveDutyCycle with rxPeriod and sleepPeriod set so the unit shouldn't miss any messages. - \param senderPreambleLength Expected preamble length of the messages to receive. If set to zero, the currently configured preamble length will be used. Defaults to zero. - \param minSymbols Parameters will be chosen to ensure that the unit will catch at least this many symbols of any preamble of the specified length. Defaults to 8. - According to Semtech, receiver requires 8 symbols to reliably latch a preamble. This makes this method redundant when transmitter preamble length is less than 17 (2*minSymbols + 1). + \param minSymbols Parameters will be chosen to ensure that the unit will catch at least this many symbols + of any preamble of the specified length. Defaults to 8. + According to Semtech, receiver requires 8 symbols to reliably latch a preamble. + This makes this method redundant when transmitter preamble length is less than 17 (2*minSymbols + 1). \param irqFlags Sets the IRQ flags, defaults to RADIOLIB_SX126X_IRQ_RX_DEFAULT. - \param irqMask Sets the mask of IRQ flags that will trigger DIO1, defaults to RADIOLIB_SX126X_IRQ_RX_DONE. - \returns \ref status_codes */ int16_t startReceiveDutyCycleAuto(uint16_t senderPreambleLength = 0, uint16_t minSymbols = 8, uint16_t irqFlags = RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask = RADIOLIB_SX126X_IRQ_RX_DONE); /*! \brief Reads the current IRQ status. - \returns IRQ status bits */ uint16_t getIrqStatus(); /*! \brief Reads data received after calling startReceive method. - \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; /*! - \brief Interrupt-driven channel activity detection method. DIO0 will be activated when LoRa preamble is detected, or upon timeout. - + \brief Interrupt-driven channel activity detection method. DIO0 will be activated + when LoRa preamble is detected, or upon timeout. \param symbolNum Number of symbols for CAD detection. Defaults to the value recommended by AN1200.48. - \param detPeak Peak value for CAD detection. Defaults to the value recommended by AN1200.48. - \param detMin Minimum value for CAD detection. Defaults to the value recommended by AN1200.48. - \returns \ref status_codes */ int16_t startChannelScan(uint8_t symbolNum = RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detPeak = RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detMin = RADIOLIB_SX126X_CAD_PARAM_DEFAULT); /*! \brief Read the channel scan result - \returns \ref status_codes */ int16_t getChannelScanResult(); @@ -721,101 +668,81 @@ class SX126x: public PhysicalLayer { /*! \brief Sets LoRa bandwidth. Allowed values are 7.8, 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125.0, 250.0 and 500.0 kHz. - \param bw LoRa bandwidth to be set in kHz. - \returns \ref status_codes */ int16_t setBandwidth(float bw); /*! \brief Sets LoRa spreading factor. Allowed values range from 5 to 12. - \param sf LoRa spreading factor to be set. - \returns \ref status_codes */ int16_t setSpreadingFactor(uint8_t sf); /*! \brief Sets LoRa coding rate denominator. Allowed values range from 5 to 8. - \param cr LoRa coding rate denominator to be set. - \returns \ref status_codes */ int16_t setCodingRate(uint8_t cr); /*! \brief Sets LoRa sync word. - \param syncWord LoRa sync word to be set. - \param controlBits Undocumented control bits, required for compatibility purposes. - \returns \ref status_codes */ int16_t setSyncWord(uint8_t syncWord, uint8_t controlBits = 0x44); /*! \brief Sets current protection limit. Can be set in 2.5 mA steps. - \param currentLimit current protection limit to be set in mA. Allowed values range from 0 to 140. - \returns \ref status_codes */ int16_t setCurrentLimit(float currentLimit); /*! \brief Reads current protection limit. - \returns Currently configured overcurrent protection limit in mA. */ float getCurrentLimit(); /*! \brief Sets preamble length for LoRa or FSK modem. Allowed values range from 1 to 65535. - \param preambleLength Preamble length to be set in symbols (LoRa) or bits (FSK). - \returns \ref status_codes */ int16_t setPreambleLength(uint16_t preambleLength); /*! \brief Sets FSK frequency deviation. Allowed values range from 0.0 to 200.0 kHz. - \param freqDev FSK frequency deviation to be set in kHz. - \returns \ref status_codes */ int16_t setFrequencyDeviation(float freqDev) override; /*! \brief Sets FSK bit rate. Allowed values range from 0.6 to 300.0 kbps. - \param br FSK bit rate to be set in kbps. - \returns \ref status_codes */ int16_t setBitRate(float br); /*! - \brief Sets FSK receiver bandwidth. Allowed values are 4.8, 5.8, 7.3, 9.7, 11.7, 14.6, 19.5, 23.4, 29.3, 39.0, 46.9, 58.6, 78.2, 93.8, 117.3, 156.2, 187.2, 234.3, 312.0, 373.6 and 467.0 kHz. - - \param FSK receiver bandwidth to be set in kHz. - + \brief Sets FSK receiver bandwidth. Allowed values are 4.8, 5.8, 7.3, 9.7, 11.7, 14.6, 19.5, + 23.4, 29.3, 39.0, 46.9, 58.6, 78.2, 93.8, 117.3, 156.2, 187.2, 234.3, 312.0, 373.6 and 467.0 kHz. + \param rxBw FSK receiver bandwidth to be set in kHz. \returns \ref status_codes */ int16_t setRxBandwidth(float rxBw); /*! - \brief Enables or disables Rx Boosted Gain mode as described in SX126x datasheet section 9.6 (SX1261/2 v2.1, SX1268 v1.1) - + \brief Enables or disables Rx Boosted Gain mode as described in SX126x datasheet + section 9.6 (SX1261/2 v2.1, SX1268 v1.1) \param rxbgm True for Rx Boosted Gain, false for Rx Power Saving Gain - - \param persist True to persist Rx gain setting when waking up from warm-start mode (e.g. when using Rx duty cycle mode) - + \param persist True to persist Rx gain setting when waking up from warm-start mode + (e.g. when using Rx duty cycle mode). \returns \ref status_codes */ int16_t setRxBoostedGainMode(bool rxbgm, bool persist = true); @@ -824,124 +751,100 @@ class SX126x: public PhysicalLayer { \brief Sets time-bandwidth product of Gaussian filter applied for shaping. Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5, RADIOLIB_SHAPING_0_7 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping. - \param sh Time-bandwidth product of Gaussian filter to be set. - \returns \ref status_codes */ int16_t setDataShaping(uint8_t sh) override; /*! \brief Sets FSK sync word in the form of array of up to 8 bytes. - \param syncWord FSK sync word to be set. - \param len FSK sync word length in bytes. - \returns \ref status_codes */ int16_t setSyncWord(uint8_t* syncWord, uint8_t len); /*! \brief Sets FSK sync word in the form of array of up to 8 bytes. - \param syncWord FSK sync word to be set. - - \param bitsLen FSK sync word length in bits. If length is not divisible by 8, least significant bits of syncWord will be ignored. - + \param bitsLen FSK sync word length in bits. If length is not divisible by 8, + least significant bits of syncWord will be ignored. \returns \ref status_codes */ int16_t setSyncBits(uint8_t *syncWord, uint8_t bitsLen); /*! \brief Sets node address. Calling this method will also enable address filtering for node address only. - \param nodeAddr Node address to be set. - \returns \ref status_codes */ int16_t setNodeAddress(uint8_t nodeAddr); /*! - \brief Sets broadcast address. Calling this method will also enable address filtering for node and broadcast address. - + \brief Sets broadcast address. Calling this method will also enable address + filtering for node and broadcast address. \param broadAddr Node address to be set. - \returns \ref status_codes */ int16_t setBroadcastAddress(uint8_t broadAddr); /*! \brief Disables address filtering. Calling this method will also erase previously set addresses. - \returns \ref status_codes */ int16_t disableAddressFiltering(); /*! \brief Sets CRC configuration. - \param len CRC length in bytes, Allowed values are 1 or 2, set to 0 to disable CRC. - \param initial Initial CRC value. FSK only. Defaults to 0x1D0F (CCIT CRC). - \param polynomial Polynomial for CRC calculation. FSK only. Defaults to 0x1021 (CCIT CRC). - \param inverted Invert CRC bytes. FSK only. Defaults to true (CCIT CRC). - \returns \ref status_codes */ int16_t setCRC(uint8_t len, uint16_t initial = 0x1D0F, uint16_t polynomial = 0x1021, bool inverted = true); /*! \brief Sets FSK whitening parameters. - \param enabled True = Whitening enabled - - \param initial Initial value used for the whitening LFSR in FSK mode. Defaults to 0x0100, use 0x01FF for SX127x compatibility. - + \param initial Initial value used for the whitening LFSR in FSK mode. Defaults to 0x0100, + use 0x01FF for SX127x compatibility. \returns \ref status_codes */ int16_t setWhitening(bool enabled, uint16_t initial = 0x0100); /*! \brief Sets TCXO (Temperature Compensated Crystal Oscillator) configuration. - - \param TCXO reference voltage in volts. Allowed values are 1.6, 1.7, 1.8, 2.2. 2.4, 2.7, 3.0 and 3.3 V. Set to 0 to disable TCXO. + \param voltage TCXO reference voltage in volts. Allowed values are 1.6, 1.7, 1.8, 2.2. 2.4, 2.7, 3.0 and 3.3 V. + Set to 0 to disable TCXO. NOTE: After setting this parameter to 0, the module will be reset (since there's no other way to disable TCXO). - \param TCXO timeout in us. Defaults to 5000 us. - + \param delay TCXO timeout in us. Defaults to 5000 us. \returns \ref status_codes */ int16_t setTCXO(float voltage, uint32_t delay = 5000); /*! \brief Set DIO2 to function as RF switch (default in Semtech example designs). - \returns \ref status_codes */ int16_t setDio2AsRfSwitch(bool enable = true); /*! \brief Gets effective data rate for the last transmitted packet. The value is calculated only for payload bytes. - \returns Effective data rate in bps. */ float getDataRate() const; /*! \brief GetsRSSI (Recorded Signal Strength Indicator). - \param packet Whether to read last packet RSSI, or the current value. - \returns RSSI value in dBm. */ float getRSSI(bool packet = true); /*! \brief Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem. - \returns SNR of the last received packet in dB. */ float getSNR(); @@ -957,75 +860,60 @@ class SX126x: public PhysicalLayer { /*! \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_SX126X_MAX_PACKET_LENGTH); /*! \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_SX126X_MAX_PACKET_LENGTH); /*! \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 Set implicit header mode for future reception/transmission. - \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(); /*! \brief Set regulator mode to LDO. - \returns \ref status_codes */ int16_t setRegulatorLDO(); /*! \brief Set regulator mode to DC-DC. - \returns \ref status_codes */ int16_t setRegulatorDCDC(); /*! \brief Sets transmission encoding. Available in FSK mode only. Serves only as alias for PhysicalLayer compatibility. - \param encoding Encoding to be used. Set to 0 for NRZ, and 2 for whitening. - \returns \ref status_codes */ int16_t setEncoding(uint8_t encoding) override; @@ -1037,18 +925,18 @@ class SX126x: public PhysicalLayer { void setRfSwitchTable(const uint32_t (&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[]); /*! - \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 SX126x::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 SX126x::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 */ @@ -1056,31 +944,26 @@ class SX126x: public PhysicalLayer { /*! \brief Get one truly random byte from RSSI noise. - \returns TRNG byte. */ uint8_t randomByte(); /*! \brief Enable/disable inversion of the I and Q signals - - \param invertIQ QI inversion enabled (true) or disabled (false); - + \param enable QI inversion enabled (true) or disabled (false); \returns \ref status_codes */ - int16_t invertIQ(bool invertIQ); + int16_t invertIQ(bool enable); #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); @@ -1089,27 +972,19 @@ class SX126x: public PhysicalLayer { /*! \brief Upload binary patch into the SX126x device RAM. Patch is needed to e.g., enable spectral scan and must be uploaded again on every power cycle. - \param patch Binary patch to upload. - \param len Length of the binary patch in 4-byte words. - \param nonvolatile Set to true when the patch is saved in non-volatile memory of the host processor, or to false when the patch is in its RAM. - \returns \ref status_codes */ int16_t uploadPatch(const uint32_t* patch, size_t len, bool nonvolatile = true); /*! \brief Start spectral scan. Requires binary path to be uploaded. - \param numSamples Number of samples for each scan. Fewer samples = better temporal resolution. - \param window RSSI averaging window size. - \param interval Scan interval length, one of RADIOLIB_SX126X_SCAN_INTERVAL_* macros. - \returns \ref status_codes */ int16_t spectralScanStart(uint16_t numSamples, uint8_t window = RADIOLIB_SX126X_SPECTRAL_SCAN_WINDOW_DEFAULT, uint8_t interval = RADIOLIB_SX126X_SCAN_INTERVAL_8_20_US); @@ -1121,16 +996,13 @@ class SX126x: public PhysicalLayer { /*! \brief Read the status of spectral scan. - \returns \ref status_codes */ int16_t spectralScanGetStatus(); /*! \brief Read the result of spectral scan. - \param results Array to which the results will be saved, must be RADIOLIB_SX126X_SPECTRAL_SCAN_RES_SIZE long. - \returns \ref status_codes */ int16_t spectralScanGetResult(uint16_t* results); @@ -1156,8 +1028,8 @@ class SX126x: public PhysicalLayer { int16_t setTxParams(uint8_t power, uint8_t rampTime = RADIOLIB_SX126X_PA_RAMP_200U); int16_t setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr, uint8_t ldro); int16_t setModulationParamsFSK(uint32_t br, uint8_t pulseShape, uint8_t rxBw, uint32_t freqDev); - int16_t setPacketParams(uint16_t preambleLength, uint8_t crcType, uint8_t payloadLength, uint8_t headerType, uint8_t invertIQ); - int16_t setPacketParamsFSK(uint16_t preambleLength, uint8_t crcType, uint8_t syncWordLength, uint8_t addrComp, uint8_t whitening, uint8_t packetType = RADIOLIB_SX126X_GFSK_PACKET_VARIABLE, uint8_t payloadLength = 0xFF, uint8_t preambleDetectorLength = RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16); + int16_t setPacketParams(uint16_t preambleLen, uint8_t crcType, uint8_t payloadLen, uint8_t hdrType, uint8_t invertIQ); + int16_t setPacketParamsFSK(uint16_t preambleLen, uint8_t crcType, uint8_t syncWordLen, uint8_t addrCmp, uint8_t whiten, uint8_t packType = RADIOLIB_SX126X_GFSK_PACKET_VARIABLE, uint8_t payloadLen = 0xFF, uint8_t preambleDetectorLen = RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16); int16_t setBufferBaseAddress(uint8_t txBaseAddress = 0x00, uint8_t rxBaseAddress = 0x00); int16_t setRegulatorMode(uint8_t mode); uint8_t getStatus(); @@ -1168,7 +1040,7 @@ class SX126x: public PhysicalLayer { int16_t startReceiveCommon(uint32_t timeout = RADIOLIB_SX126X_RX_TIMEOUT_INF, uint16_t irqFlags = RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask = RADIOLIB_SX126X_IRQ_RX_DONE); int16_t setFrequencyRaw(float freq); int16_t setPacketMode(uint8_t mode, uint8_t len); - int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF); + int16_t setHeaderType(uint8_t hdrType, size_t len = 0xFF); int16_t directMode(); int16_t packetMode(); @@ -1181,7 +1053,7 @@ class SX126x: public PhysicalLayer { #if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL) protected: #endif - Module* _mod; + Module* mod; // common low-level SPI interface static int16_t SPIparseStatus(uint8_t in); @@ -1190,26 +1062,26 @@ class SX126x: public PhysicalLayer { protected: #endif - uint8_t _bw = 0, _sf = 0, _cr = 0, _ldro = 0, _crcType = 0, _headerType = 0; - uint16_t _preambleLength = 0; - float _bwKhz = 0; - bool _ldroAuto = true; + uint8_t bandwidth = 0, spreadingFactor = 0, codingRate = 0, ldrOptimize = 0, crcTypeLoRa = 0, headerType = 0; + uint16_t preambleLengthLoRa = 0; + float bandwidthKhz = 0; + bool ldroAuto = true; - uint32_t _br = 0, _freqDev = 0; - uint8_t _rxBw = 0, _pulseShape = 0, _crcTypeFSK = 0, _syncWordLength = 0, _addrComp = 0, _whitening = 0, _packetType = 0; - uint16_t _preambleLengthFSK = 0; - float _rxBwKhz = 0; + uint32_t bitRate = 0, freqencyDev = 0; + uint8_t rxBandwidth = 0, pulseShape = 0, crcTypeFSK = 0, syncWordLength = 0, addrComp = 0, whitening = 0, packetType = 0; + uint16_t preambleLengthFSK = 0; + float rxBandwidthKhz = 0; - float _dataRate = 0; + float dataRateMeasured = 0; - uint32_t _tcxoDelay = 0; + uint32_t tcxoDelay = 0; - size_t _implicitLen = 0; - uint8_t _invertIQ = RADIOLIB_SX126X_LORA_IQ_STANDARD; - const char* _chipType; + size_t implicitLen = 0; + uint8_t invertIQEnabled = RADIOLIB_SX126X_LORA_IQ_STANDARD; + const char* chipType; // Allow subclasses to define different TX modes - uint8_t _tx_mode = Module::MODE_TX; + uint8_t txMode = Module::MODE_TX; int16_t config(uint8_t modem); bool findChip(const char* verStr);