Update RadioLib

This commit is contained in:
lewisxhe
2024-09-19 11:12:36 +08:00
parent 210367a171
commit 5794daa8aa
301 changed files with 115546 additions and 12703 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+69 -5
View File
@@ -1,11 +1,12 @@
#include "LLCC68.h"
#if !defined(RADIOLIB_EXCLUDE_SX126X)
#if !RADIOLIB_EXCLUDE_SX126X
LLCC68::LLCC68(Module* mod) : SX1262(mod) {
chipType = RADIOLIB_LLCC68_CHIP_TYPE;
this->XTAL = true;
}
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) {
int16_t LLCC68::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t pwr, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) {
// execute common part
int16_t state = SX126x::begin(cr, syncWord, preambleLength, tcxoVoltage, useRegulatorLDO);
RADIOLIB_ASSERT(state);
@@ -20,7 +21,7 @@ int16_t LLCC68::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
state = setSpreadingFactor(sf);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
state = setOutputPower(pwr);
RADIOLIB_ASSERT(state);
state = SX126x::fixPaClamping();
@@ -35,7 +36,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;
@@ -52,4 +53,67 @@ int16_t LLCC68::setSpreadingFactor(uint8_t sf) {
return(SX1262::setSpreadingFactor(sf));
}
int16_t LLCC68::setDataRate(DataRate_t dr) {
int16_t state = RADIOLIB_ERR_UNKNOWN;
// select interpretation based on active modem
uint8_t modem = this->getPacketType();
if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
// set the bit rate
state = this->setBitRate(dr.fsk.bitRate);
RADIOLIB_ASSERT(state);
// set the frequency deviation
state = this->setFrequencyDeviation(dr.fsk.freqDev);
} else if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) {
// set the spreading factor
state = this->setSpreadingFactor(dr.lora.spreadingFactor);
RADIOLIB_ASSERT(state);
// set the bandwidth
state = this->setBandwidth(dr.lora.bandwidth);
RADIOLIB_ASSERT(state);
// set the coding rate
state = this->setCodingRate(dr.lora.codingRate);
}
return(state);
}
int16_t LLCC68::checkDataRate(DataRate_t dr) {
int16_t state = RADIOLIB_ERR_UNKNOWN;
// select interpretation based on active modem
uint8_t modem = this->getPacketType();
if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.6, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
RADIOLIB_CHECK_RANGE(dr.fsk.freqDev, 0.6, 200.0, RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
return(RADIOLIB_ERR_NONE);
} else if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) {
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 100.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
uint8_t bw_div2 = dr.lora.bandwidth / 2 + 0.01;
switch (bw_div2) {
case 62: // 125.0:
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 5, 9, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
break;
case 125: // 250.0
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 5, 10, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
break;
case 250: // 500.0
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 5, 11, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
break;
default:
return(RADIOLIB_ERR_INVALID_BANDWIDTH);
}
return(RADIOLIB_ERR_NONE);
}
return(state);
}
#endif
+27 -22
View File
@@ -3,69 +3,74 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX126X)
#if !RADIOLIB_EXCLUDE_SX126X
#include "../../Module.h"
#include "../SX126x/SX1262.h"
//RADIOLIB_SX126X_REG_VERSION_STRING
#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);
LLCC68(Module* mod); // cppcheck-suppress noExplicitConstructor
/*!
\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 2-byte LoRa sync word. Defaults to RADIOLIB_SX126X_SYNC_WORD_PRIVATE (0x12).
\param power Output power in dBm. Defaults to 10 dBm.
\param syncWord 1-byte LoRa sync word. Defaults to RADIOLIB_SX126X_SYNC_WORD_PRIVATE (0x12).
\param pwr 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 tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 0 V (XTAL).
If you are seeing -706/-707 error codes, it likely means you are using a module with TCXO.
To use TCXO, either set this value to its reference voltage, or set SX126x::XTAL to false.
\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);
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 pwr = 10, uint16_t preambleLength = 8, float tcxoVoltage = 0, bool useRegulatorLDO = false);
// configuration methods
/*!
\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);
#if !defined(RADIOLIB_GODMODE)
/*!
\brief Set data.
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
\returns \ref status_codes
*/
int16_t setDataRate(DataRate_t dr) override;
/*!
\brief Check the data rate can be configured by this module.
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
\returns \ref status_codes
*/
int16_t checkDataRate(DataRate_t dr) override;
#if !RADIOLIB_GODMODE
private:
#endif
+108
View File
@@ -0,0 +1,108 @@
#include "LR1110.h"
#if !RADIOLIB_EXCLUDE_LR11X0
LR1110::LR1110(Module* mod) : LR11x0(mod) {
chipType = RADIOLIB_LR11X0_DEVICE_LR1110;
}
int16_t LR1110::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage) {
// execute common part
int16_t state = LR11x0::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage);
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
return(state);
}
int16_t LR1110::beginGFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, float tcxoVoltage) {
// execute common part
int16_t state = LR11x0::beginGFSK(br, freqDev, rxBw, preambleLength, tcxoVoltage);
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
return(state);
}
int16_t LR1110::beginLRFHSS(float freq, uint8_t bw, uint8_t cr, int8_t power, float tcxoVoltage) {
// execute common part
int16_t state = LR11x0::beginLRFHSS(bw, cr, tcxoVoltage);
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
return(state);
}
int16_t LR1110::setFrequency(float freq) {
return(this->setFrequency(freq, true));
}
int16_t LR1110::setFrequency(float freq, bool calibrate, float band) {
RADIOLIB_CHECK_RANGE(freq, 150.0, 960.0, RADIOLIB_ERR_INVALID_FREQUENCY);
// calibrate image rejection
if(calibrate) {
int16_t state = LR11x0::calibImage(freq - band, freq + band);
RADIOLIB_ASSERT(state);
}
// set frequency
return(LR11x0::setRfFrequency((uint32_t)(freq*1000000.0f)));
}
int16_t LR1110::setOutputPower(int8_t power) {
return(this->setOutputPower(power, false));
}
int16_t LR1110::setOutputPower(int8_t power, bool forceHighPower) {
// check if power value is configurable
int16_t state = this->checkOutputPower(power, NULL, forceHighPower);
RADIOLIB_ASSERT(state);
// determine whether to use HP or LP PA and check range accordingly
bool useHp = forceHighPower || (power > 14);
// TODO how and when to configure OCP?
// update PA config - always use VBAT for high-power PA
state = setPaConfig((uint8_t)useHp, (uint8_t)useHp, 0x04, 0x07);
RADIOLIB_ASSERT(state);
// set output power
state = setTxParams(power, RADIOLIB_LR11X0_PA_RAMP_48U);
return(state);
}
int16_t LR1110::checkOutputPower(int8_t power, int8_t* clipped) {
return(checkOutputPower(power, clipped, false));
}
int16_t LR1110::checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPower) {
if(forceHighPower || (power > 14)) {
if(clipped) {
*clipped = RADIOLIB_MAX(-9, RADIOLIB_MIN(22, power));
}
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
} else {
if(clipped) {
*clipped = RADIOLIB_MAX(-17, RADIOLIB_MIN(14, power));
}
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
}
return(RADIOLIB_ERR_NONE);
}
#endif
+133
View File
@@ -0,0 +1,133 @@
#if !defined(_RADIOLIB_LR1110_H)
#define _RADIOLIB_LR1110_H
#include "../../TypeDef.h"
#if !RADIOLIB_EXCLUDE_LR11X0
#include "../../Module.h"
#include "LR11x0.h"
/*!
\class LR1110
\brief Derived class for %LR1110 modules.
*/
class LR1110: public LR11x0 {
public:
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
LR1110(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
/*!
\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_LR11X0_LORA_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. Defaults to 1.6 V.
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
To use XTAL, either set this value to 0, or set LR11x0::XTAL to true.
\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_LR11X0_LORA_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6);
/*!
\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. Defaults to 1.6 V.
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
To use XTAL, either set this value to 0, or set LR11x0::XTAL to true.
\returns \ref status_codes
*/
int16_t beginGFSK(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);
/*!
\brief Initialization method for LR-FHSS modem.
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
\param bw LR-FHSS bandwidth, one of RADIOLIB_LR11X0_LR_FHSS_BW_* values. Defaults to 722.66 kHz.
\param cr LR-FHSS coding rate, one of RADIOLIB_LR11X0_LR_FHSS_CR_* values. Defaults to 2/3 coding rate.
\param power Output power in dBm. Defaults to 10 dBm.
\param tcxoVoltage TCXO reference voltage to be set. Defaults to 1.6 V.
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
To use XTAL, either set this value to 0, or set LR11x0::XTAL to true.
\returns \ref status_codes
*/
int16_t beginLRFHSS(float freq = 434.0, uint8_t bw = RADIOLIB_LR11X0_LR_FHSS_BW_722_66, uint8_t cr = RADIOLIB_LR11X0_LR_FHSS_CR_2_3, int8_t power = 10, float tcxoVoltage = 1.6);
// configuration methods
/*!
\brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz.
Will also perform calibrations.
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq) override;
/*!
\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.
\param band Half bandwidth for image calibration. For example,
if carrier is 434 MHz and band is set to 4 MHz, then the image will be calibrate
for band 430 - 438 MHz. Unused if calibrate is set to false, defaults to 4 MHz
\returns \ref status_codes
*/
int16_t setFrequency(float freq, bool calibrate, float band = 4);
/*!
\brief Sets output power. Allowed values are in range from -9 to 22 dBm (high-power PA) or -17 to 14 dBm (low-power PA).
\param power Output power to be set in dBm, output PA is determined automatically preferring the low-power PA.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power) override;
/*!
\brief Sets output power. Allowed values are in range from -9 to 22 dBm (high-power PA) or -17 to 14 dBm (low-power PA).
\param power Output power to be set in dBm.
\param forceHighPower Force using the high-power PA. If set to false, PA will be determined automatically
based on configured output power, preferring the low-power PA. If set to true, only high-power PA will be used.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power, bool forceHighPower);
/*!
\brief Check if output power is configurable.
This method is needed for compatibility with PhysicalLayer::checkOutputPower.
\param power Output power in dBm, PA will be determined automatically.
\param clipped Clipped output power value to what is possible within the module's range.
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
/*!
\brief Check if output power is configurable.
\param power Output power in dBm.
\param clipped Clipped output power value to what is possible within the module's range.
\param forceHighPower Force using the high-power PA. If set to false, PA will be determined automatically
based on configured output power, preferring the low-power PA. If set to true, only high-power PA will be used.
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPower);
#if !RADIOLIB_GODMODE
private:
#endif
};
#endif
#endif
+131
View File
@@ -0,0 +1,131 @@
#include "LR1120.h"
#if !RADIOLIB_EXCLUDE_LR11X0
LR1120::LR1120(Module* mod) : LR11x0(mod) {
chipType = RADIOLIB_LR11X0_DEVICE_LR1120;
}
int16_t LR1120::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage) {
// execute common part
int16_t state = LR11x0::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage);
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
return(state);
}
int16_t LR1120::beginGFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, float tcxoVoltage) {
// execute common part
int16_t state = LR11x0::beginGFSK(br, freqDev, rxBw, preambleLength, tcxoVoltage);
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
return(state);
}
int16_t LR1120::beginLRFHSS(float freq, uint8_t bw, uint8_t cr, int8_t power, float tcxoVoltage) {
// execute common part
int16_t state = LR11x0::beginLRFHSS(bw, cr, tcxoVoltage);
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
return(state);
}
int16_t LR1120::setFrequency(float freq) {
return(this->setFrequency(freq, true));
}
int16_t LR1120::setFrequency(float freq, bool calibrate, float band) {
if(!(((freq >= 150.0) && (freq <= 960.0)) ||
((freq >= 1900.0) && (freq <= 2200.0)) ||
((freq >= 2400.0) && (freq <= 2500.0)))) {
return(RADIOLIB_ERR_INVALID_FREQUENCY);
}
// calibrate image rejection
int16_t state;
if(calibrate) {
state = LR11x0::calibImage(freq - band, freq + band);
RADIOLIB_ASSERT(state);
}
// set frequency
state = LR11x0::setRfFrequency((uint32_t)(freq*1000000.0f));
RADIOLIB_ASSERT(state);
this->highFreq = (freq > 1000.0);
return(RADIOLIB_ERR_NONE);
}
int16_t LR1120::setOutputPower(int8_t power) {
return(this->setOutputPower(power, false));
}
int16_t LR1120::setOutputPower(int8_t power, bool forceHighPower) {
// check if power value is configurable
int16_t state = this->checkOutputPower(power, NULL, forceHighPower);
RADIOLIB_ASSERT(state);
// determine whether to use HP or LP PA and check range accordingly
uint8_t paSel = 0;
uint8_t paSupply = 0;
if(this->highFreq) {
paSel = 2;
} else if(forceHighPower || (power > 14)) {
paSel = 1;
paSupply = 1;
}
// TODO how and when to configure OCP?
// update PA config - always use VBAT for high-power PA
state = setPaConfig(paSel, paSupply, 0x04, 0x07);
RADIOLIB_ASSERT(state);
// set output power
state = setTxParams(power, RADIOLIB_LR11X0_PA_RAMP_48U);
return(state);
}
int16_t LR1120::checkOutputPower(int8_t power, int8_t* clipped) {
return(checkOutputPower(power, clipped, false));
}
int16_t LR1120::checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPower) {
if(this->highFreq) {
if(clipped) {
*clipped = RADIOLIB_MAX(-18, RADIOLIB_MIN(13, power));
}
RADIOLIB_CHECK_RANGE(power, -18, 13, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
return(RADIOLIB_ERR_NONE);
}
if(forceHighPower || (power > 14)) {
if(clipped) {
*clipped = RADIOLIB_MAX(-9, RADIOLIB_MIN(22, power));
}
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
} else {
if(clipped) {
*clipped = RADIOLIB_MAX(-17, RADIOLIB_MIN(14, power));
}
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
}
return(RADIOLIB_ERR_NONE);
}
#endif
+145
View File
@@ -0,0 +1,145 @@
#if !defined(_RADIOLIB_LR1120_H)
#define _RADIOLIB_LR1120_H
#include "../../TypeDef.h"
#if !RADIOLIB_EXCLUDE_LR11X0
#include "../../Module.h"
#include "LR11x0.h"
/*!
\class LR1120
\brief Derived class for %LR1120 modules.
*/
class LR1120: public LR11x0 {
public:
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
LR1120(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
/*!
\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_LR11X0_LORA_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. Defaults to 1.6 V.
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
To use XTAL, either set this value to 0, or set LR11x0::XTAL to true.
\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_LR11X0_LORA_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6);
/*!
\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. Defaults to 1.6 V.
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
To use XTAL, either set this value to 0, or set LR11x0::XTAL to true.
\returns \ref status_codes
*/
int16_t beginGFSK(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);
/*!
\brief Initialization method for LR-FHSS modem.
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
\param bw LR-FHSS bandwidth, one of RADIOLIB_LR11X0_LR_FHSS_BW_* values. Defaults to 722.66 kHz.
\param cr LR-FHSS coding rate, one of RADIOLIB_LR11X0_LR_FHSS_CR_* values. Defaults to 2/3 coding rate.
\param power Output power in dBm. Defaults to 10 dBm.
\param tcxoVoltage TCXO reference voltage to be set. Defaults to 1.6 V.
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
To use XTAL, either set this value to 0, or set LR11x0::XTAL to true.
\returns \ref status_codes
*/
int16_t beginLRFHSS(float freq = 434.0, uint8_t bw = RADIOLIB_LR11X0_LR_FHSS_BW_722_66, uint8_t cr = RADIOLIB_LR11X0_LR_FHSS_CR_2_3, int8_t power = 10, float tcxoVoltage = 1.6);
// configuration methods
/*!
\brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz,
1900 - 2200 MHz and 2400 - 2500 MHz. Will also perform calibrations.
NOTE: When switching between sub-GHz and high-frequency bands, after changing the frequency,
setOutputPower() must be called in order to set the correct power amplifier!
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq) override;
/*!
\brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz,
1900 - 2200 MHz and 2400 - 2500 MHz. Will also perform calibrations.
NOTE: When switching between sub-GHz and high-frequency bands, after changing the frequency,
setOutputPower() must be called in order to set the correct power amplifier!
\param freq Carrier frequency to be set in MHz.
\param calibrate Run image calibration.
\param band Half bandwidth for image calibration. For example,
if carrier is 434 MHz and band is set to 4 MHz, then the image will be calibrate
for band 430 - 438 MHz. Unused if calibrate is set to false, defaults to 4 MHz
\returns \ref status_codes
*/
int16_t setFrequency(float freq, bool calibrate, float band = 4);
/*!
\brief Sets output power. Allowed values are in range from -9 to 22 dBm (high-power PA) or -17 to 14 dBm (low-power PA).
\param power Output power to be set in dBm, output PA is determined automatically preferring the low-power PA.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power) override;
/*!
\brief Sets output power. Allowed values are in range from -9 to 22 dBm (high-power PA), -17 to 14 dBm (low-power PA)
or -18 to 13 dBm (high-frequency PA).
\param power Output power to be set in dBm.
\param forceHighPower Force using the high-power PA in sub-GHz bands, or high-frequency PA in 2.4 GHz band.
If set to false, PA will be determined automatically based on configured output power and frequency,
preferring the low-power PA but always using high-frequency PA in 2.4 GHz band.
Ignored when operating in 2.4 GHz band.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power, bool forceHighPower);
/*!
\brief Check if output power is configurable.
This method is needed for compatibility with PhysicalLayer::checkOutputPower.
\param power Output power in dBm, PA will be determined automatically.
\param clipped Clipped output power value to what is possible within the module's range.
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
/*!
\brief Check if output power is configurable.
\param power Output power in dBm.
\param clipped Clipped output power value to what is possible within the module's range.
\param forceHighPower Force using the high-power PA. If set to false, PA will be determined automatically
based on configured output power, preferring the low-power PA. If set to true, only high-power PA will be used.
Ignored when operating in 2.4 GHz band.
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPower);
#if !RADIOLIB_GODMODE
private:
#endif
// flag to determine whether we are in the sub-GHz or 2.4 GHz range
// this is needed to automatically detect which PA to use
bool highFreq = false;
};
#endif
#endif
@@ -0,0 +1,8 @@
#include "LR1121.h"
#if !RADIOLIB_EXCLUDE_LR11X0
LR1121::LR1121(Module* mod) : LR1120(mod) {
chipType = RADIOLIB_LR11X0_DEVICE_LR1121;
}
#endif
+35
View File
@@ -0,0 +1,35 @@
#if !defined(_RADIOLIB_LR1121_H)
#define _RADIOLIB_LR1121_H
#include "../../TypeDef.h"
#if !RADIOLIB_EXCLUDE_LR11X0
#include "../../Module.h"
#include "LR11x0.h"
#include "LR1120.h"
/*!
\class LR1121
\brief Derived class for %LR1121 modules.
*/
class LR1121: public LR1120 {
public:
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
LR1121(Module* mod); // cppcheck-suppress noExplicitConstructor
// TODO this is where overrides to disable GNSS+WiFi scanning methods on LR1121
// will be put once those are implemented
#if !RADIOLIB_GODMODE
private:
#endif
};
#endif
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,38 @@
#if !defined(_RADIOLIB_LR11X0_FIRMWARE_H)
#define _RADIOLIB_LR11X0_FIRMWARE_H
#if defined(RADIOLIB_LR1110_FIRMWARE_IN_RAM)
#define RADIOLIB_LR1110_FIRMWARE_ATTR
#else
#define RADIOLIB_LR1110_FIRMWARE_ATTR RADIOLIB_NONVOLATILE
#endif
#define RADIOLIB_LR11X0_FIRMWARE_IMAGE_SIZE LR11XX_FIRMWARE_IMAGE_SIZE
#if defined(RADIOLIB_LR1110_FIRMWARE_0303)
#include "firmware/lr1110_transceiver_0303.h"
#elif defined(RADIOLIB_LR1110_FIRMWARE_0304)
#include "firmware/lr1110_transceiver_0304.h"
#elif defined(RADIOLIB_LR1110_FIRMWARE_0305)
#include "firmware/lr1110_transceiver_0305.h"
#elif defined(RADIOLIB_LR1110_FIRMWARE_0306)
#include "firmware/lr1110_transceiver_0306.h"
#elif defined(RADIOLIB_LR1110_FIRMWARE_0307)
#include "firmware/lr1110_transceiver_0307.h"
#elif defined(RADIOLIB_LR1110_FIRMWARE_0401)
#include "firmware/lr1110_transceiver_0401.h"
#elif defined(RADIOLIB_LR1120_FIRMWARE_0101)
#include "firmware/lr1120_transceiver_0101.h"
#elif defined(RADIOLIB_LR1120_FIRMWARE_0102)
#include "firmware/lr1120_transceiver_0102.h"
#elif defined(RADIOLIB_LR1120_FIRMWARE_0201)
#include "firmware/lr1120_transceiver_0201.h"
#elif defined(RADIOLIB_LR1121_FIRMWARE_0102)
#include "firmware/lr1121_transceiver_0102.h"
#elif defined(RADIOLIB_LR1121_FIRMWARE_0103)
#include "firmware/lr1121_transceiver_0103.h"
#else
#error "No LR11x0 firmware image selected!"
#endif
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+2 -3
View File
@@ -3,7 +3,7 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_RFM2X)
#if !RADIOLIB_EXCLUDE_RFM2X
#include "../../Module.h"
#include "../Si443x/Si443x.h"
@@ -11,10 +11,9 @@
/*!
\class RFM22
\brief Only exists as alias for Si4432, since there seems to be no difference between %RFM22 and %Si4432 modules.
*/
RADIOLIB_TYPE_ALIAS(Si4432, RFM22);
RADIOLIB_TYPE_ALIAS(Si4432, RFM22)
#endif
+2 -3
View File
@@ -3,7 +3,7 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_RFM2X)
#if !RADIOLIB_EXCLUDE_RFM2X
#include "../../Module.h"
#include "../Si443x/Si443x.h"
@@ -11,10 +11,9 @@
/*!
\class RFM23
\brief Only exists as alias for Si4431, since there seems to be no difference between %RFM23 and %Si4431 modules.
*/
RADIOLIB_TYPE_ALIAS(Si4431, RFM23);
RADIOLIB_TYPE_ALIAS(Si4431, RFM23)
#endif
-90
View File
@@ -1,90 +0,0 @@
#include "RFM95.h"
#if !defined(RADIOLIB_EXCLUDE_RFM9X)
RFM95::RFM95(Module* mod) : SX1278(mod) {
}
int16_t RFM95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
// execute common part
int16_t state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, syncWord, preambleLength);
if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) {
// SX127X_REG_VERSION might be set 0x12
state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, preambleLength);
RADIOLIB_ASSERT(state);
} else if(state != RADIOLIB_ERR_NONE) {
// some other error
return(state);
}
RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278"));
RADIOLIB_DEBUG_PRINTLN(F("M\tRFM95"));
// configure publicly accessible settings
state = setBandwidth(bw);
RADIOLIB_ASSERT(state);
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setSpreadingFactor(sf);
RADIOLIB_ASSERT(state);
state = setCodingRate(cr);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
state = setGain(gain);
return(state);
}
int16_t RFM95::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
// execute common part
int16_t state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, br, freqDev, rxBw, preambleLength, enableOOK);
if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) {
// SX127X_REG_VERSION might be set 0x12
state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, br, freqDev, rxBw, preambleLength, enableOOK);
RADIOLIB_ASSERT(state);
} else if(state != RADIOLIB_ERR_NONE) {
// some other error
return(state);
}
RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278"));
RADIOLIB_DEBUG_PRINTLN(F("M\tRFM95"));
// configure settings not accessible by API
state = configFSK();
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
if(enableOOK) {
state = setDataShapingOOK(RADIOLIB_SHAPING_NONE);
RADIOLIB_ASSERT(state);
} else {
state = setDataShaping(RADIOLIB_SHAPING_NONE);
RADIOLIB_ASSERT(state);
}
return(state);
}
int16_t RFM95::setFrequency(float freq) {
RADIOLIB_CHECK_RANGE(freq, 862.0, 1020.0, RADIOLIB_ERR_INVALID_FREQUENCY);
// set frequency and if successful, save the new setting
int16_t state = SX127x::setFrequencyRaw(freq);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_freq = freq;
}
return(state);
}
#endif
-101
View File
@@ -1,101 +0,0 @@
#if !defined(_RADIOLIB_RFM95_H)
#define _RADIOLIB_RFM95_H
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_RFM9X)
#include "../../Module.h"
#include "../SX127x/SX127x.h"
#include "../SX127x/SX1278.h"
// SX127X_REG_VERSION
#define RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL 0x11
#define RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL 0x12 // according to datasheet, only 0x11 should be possible, but some modules seem to have 0x12
/*!
\class RFM95
\brief Derived class for %RFM95 modules. Overrides some methods from SX1278 due to different parameter ranges.
*/
class RFM95: public SX1278 {
public:
// constructor
/*!
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/
RFM95(Module* mod);
// basic methods
/*!
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 868.0 MHz to 915.0 MHz.
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
Allowed values range from 6 to 65535.
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
Set to 0 to enable automatic gain control (recommended).
\returns \ref status_codes
*/
int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
/*!
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of FSK preamble in bits.
\param enableOOK Use OOK modulation instead of FSK.
\returns \ref status_codes
*/
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
// configuration methods
/*!
\brief Sets carrier frequency. Allowed values range from 868.0 MHz to 915.0 MHz.
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq);
#if !defined(RADIOLIB_GODMODE)
private:
#endif
};
#endif
#endif
-91
View File
@@ -1,91 +0,0 @@
#include "RFM96.h"
#if !defined(RADIOLIB_EXCLUDE_RFM9X)
RFM96::RFM96(Module* mod) : SX1278(mod) {
}
int16_t RFM96::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
// execute common part
int16_t state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, syncWord, preambleLength);
if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) {
// SX127X_REG_VERSION might be set 0x12
state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, preambleLength);
RADIOLIB_ASSERT(state);
} else if(state != RADIOLIB_ERR_NONE) {
// some other error
return(state);
}
RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278"));
RADIOLIB_DEBUG_PRINTLN(F("M\tRFM96"));
// configure publicly accessible settings
state = setBandwidth(bw);
RADIOLIB_ASSERT(state);
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setSpreadingFactor(sf);
RADIOLIB_ASSERT(state);
state = setCodingRate(cr);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
state = setGain(gain);
RADIOLIB_ASSERT(state);
return(state);
}
int16_t RFM96::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
// execute common part
int16_t state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, br, freqDev, rxBw, preambleLength, enableOOK);
if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) {
// SX127X_REG_VERSION might be set 0x12
state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, br, freqDev, rxBw, preambleLength, enableOOK);
RADIOLIB_ASSERT(state);
} else if(state != RADIOLIB_ERR_NONE) {
// some other error
return(state);
}
RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278"));
RADIOLIB_DEBUG_PRINTLN(F("M\tRFM96"));
// configure settings not accessible by API
state = configFSK();
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
if(enableOOK) {
state = setDataShapingOOK(RADIOLIB_SHAPING_NONE);
RADIOLIB_ASSERT(state);
} else {
state = setDataShaping(RADIOLIB_SHAPING_NONE);
RADIOLIB_ASSERT(state);
}
return(state);
}
int16_t RFM96::setFrequency(float freq) {
RADIOLIB_CHECK_RANGE(freq, 410.0, 525.0, RADIOLIB_ERR_INVALID_FREQUENCY);
// set frequency and if successful, save the new setting
int16_t state = SX127x::setFrequencyRaw(freq);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_freq = freq;
}
return(state);
}
#endif
-108
View File
@@ -1,108 +0,0 @@
#if !defined(_RADIOLIB_RFM96_H)
#define _RADIOLIB_RFM96_H
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_RFM9X)
#include "../../Module.h"
#include "../SX127x/SX127x.h"
#include "../SX127x/SX1278.h"
// SX127X_REG_VERSION
#define RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL 0x11
#define RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL 0x12 // according to datasheet, only 0x11 should be possible, but some modules seem to have 0x12
/*!
\class RFM96
\brief Derived class for %RFM96 modules. Overrides some methods from SX1278 due to different parameter ranges.
*/
class RFM96: public SX1278 {
public:
// constructor
/*!
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/
RFM96(Module* mod);
// basic methods
/*!
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 433.0 MHz to 470.0 MHz.
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
Allowed values range from 6 to 65535.
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
Set to 0 to enable automatic gain control (recommended).
\returns \ref status_codes
*/
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
/*!
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of FSK preamble in bits.
\param enableOOK Use OOK modulation instead of FSK.
\returns \ref status_codes
*/
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
// configuration methods
/*!
\brief Sets carrier frequency. Allowed values range from 433.0 MHz to 470.0 MHz.
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq);
#if !defined(RADIOLIB_GODMODE)
private:
#endif
};
/*!
\class RFM98
\brief Only exists as alias for RFM96, since there seems to be no difference between %RFM96 and %RFM98 modules.
*/
RADIOLIB_TYPE_ALIAS(RFM96, RFM98);
#endif
#endif
-42
View File
@@ -1,42 +0,0 @@
#include "RFM97.h"
#if !defined(RADIOLIB_EXCLUDE_RFM9X)
RFM97::RFM97(Module* mod) : RFM95(mod) {
};
int16_t RFM97::setSpreadingFactor(uint8_t sf) {
// check active modem
if(getActiveModem() != RADIOLIB_SX127X_LORA) {
return(RADIOLIB_ERR_WRONG_MODEM);
}
uint8_t newSpreadingFactor;
// check allowed spreading factor values
switch(sf) {
case 6:
newSpreadingFactor = RADIOLIB_SX127X_SF_6;
break;
case 7:
newSpreadingFactor = RADIOLIB_SX127X_SF_7;
break;
case 8:
newSpreadingFactor = RADIOLIB_SX127X_SF_8;
break;
case 9:
newSpreadingFactor = RADIOLIB_SX127X_SF_9;
break;
default:
return(RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
}
// set spreading factor and if successful, save the new setting
int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_sf = sf;
}
return(state);
}
#endif
-49
View File
@@ -1,49 +0,0 @@
#if !defined(_RADIOLIB_RFM97_H)
#define _RADIOLIB_RFM97_H
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_RFM9X)
#include "../../Module.h"
#include "../SX127x/SX127x.h"
#include "../SX127x/SX1278.h"
#include "RFM95.h"
/*!
\class RFM97
\brief Derived class for %RFM97 modules. Overrides some methods from RFM95 due to different parameter ranges.
*/
class RFM97: public RFM95 {
public:
// constructor
/*!
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/
RFM97(Module* mod);
// configuration methods
/*!
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 9. Only available in %LoRa mode.
\param sf %LoRa link spreading factor to be set.
\returns \ref status_codes
*/
int16_t setSpreadingFactor(uint8_t sf);
#if !defined(RADIOLIB_GODMODE)
private:
#endif
};
#endif
#endif
@@ -1,5 +1,5 @@
#include "SX1231.h"
#if !defined(RADIOLIB_EXCLUDE_SX1231)
#if !RADIOLIB_EXCLUDE_SX1231
SX1231::SX1231(Module* mod) : RF69(mod) {
@@ -7,53 +7,44 @@ SX1231::SX1231(Module* mod) : RF69(mod) {
int16_t SX1231::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) {
// set module properties
_mod->init();
_mod->pinMode(_mod->getIrq(), INPUT);
_mod->pinMode(_mod->getRst(), OUTPUT);
Module* mod = this->getMod();
mod->init();
mod->hal->pinMode(mod->getIrq(), mod->hal->GpioModeInput);
mod->hal->pinMode(mod->getRst(), mod->hal->GpioModeOutput);
// try to find the SX1231 chip
uint8_t i = 0;
bool flagFound = false;
while((i < 10) && !flagFound) {
int16_t version = getChipVersion();
if((version == 0x21) || (version == 0x22) || (version == 0x23)) {
if((version == RADIOLIB_SX123X_CHIP_REVISION_2_A) || (version == RADIOLIB_SX123X_CHIP_REVISION_2_B) || (version == RADIOLIB_SX123X_CHIP_REVISION_2_C)) {
flagFound = true;
_chipRevision = version;
this->chipRevision = version;
} else {
#if defined(RADIOLIB_DEBUG)
RADIOLIB_DEBUG_PRINT(F("SX1231 not found! ("));
RADIOLIB_DEBUG_PRINT(i + 1);
RADIOLIB_DEBUG_PRINT(F(" of 10 tries) RF69_REG_VERSION == "));
char buffHex[12];
sprintf(buffHex, "0x%04X", version);
RADIOLIB_DEBUG_PRINT(buffHex);
RADIOLIB_DEBUG_PRINT(F(", expected 0x0021 / 0x0022 / 0x0023"));
RADIOLIB_DEBUG_PRINTLN();
#endif
_mod->delay(10);
RADIOLIB_DEBUG_BASIC_PRINTLN("SX1231 not found! (%d of 10 tries) RF69_REG_VERSION == 0x%04X, expected 0x0021 / 0x0022 / 0x0023", i + 1, version);
mod->hal->delay(10);
i++;
}
}
if(!flagFound) {
RADIOLIB_DEBUG_PRINTLN(F("No SX1231 found!"));
_mod->term();
RADIOLIB_DEBUG_BASIC_PRINTLN("No SX1231 found!");
mod->term();
return(RADIOLIB_ERR_CHIP_NOT_FOUND);
}
RADIOLIB_DEBUG_PRINTLN(F("M\tSX1231"));
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSX1231");
// configure settings not accessible by API
int16_t state = config();
RADIOLIB_ASSERT(state);
RADIOLIB_DEBUG_PRINTLN(F("M\tRF69"));
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tRF69");
// configure publicly accessible settings
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
// configure bitrate
_rxBw = 125.0;
this->rxBandwidth = 125.0;
state = setBitRate(br);
RADIOLIB_ASSERT(state);
@@ -84,14 +75,14 @@ int16_t SX1231::begin(float freq, float br, float freqDev, float rxBw, int8_t po
return(state);
}
// SX1231 V2a only
if(_chipRevision == RADIOLIB_SX1231_CHIP_REVISION_2_A) {
// SX123x V2a only
if(this->chipRevision == RADIOLIB_SX123X_CHIP_REVISION_2_A) {
// modify default OOK threshold value
state = _mod->SPIsetRegValue(RADIOLIB_SX1231_REG_TEST_OOK, RADIOLIB_SX1231_OOK_DELTA_THRESHOLD);
state = mod->SPIsetRegValue(RADIOLIB_SX1231_REG_TEST_OOK, RADIOLIB_SX1231_OOK_DELTA_THRESHOLD);
RADIOLIB_ASSERT(state);
// enable OCP with 95 mA limit
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM, 4, 0);
state = mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM, 4, 0);
RADIOLIB_ASSERT(state);
}
@@ -3,126 +3,117 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX1231)
#if !RADIOLIB_EXCLUDE_SX1231
#include "../../Module.h"
#include "../RF69/RF69.h"
#define RADIOLIB_SX1231_CHIP_REVISION_2_A 0x21
#define RADIOLIB_SX1231_CHIP_REVISION_2_B 0x22
#define RADIOLIB_SX1231_CHIP_REVISION_2_C 0x23
#define RADIOLIB_SX123X_CHIP_REVISION_2_A 0x21
#define RADIOLIB_SX123X_CHIP_REVISION_2_B 0x22
#define RADIOLIB_SX123X_CHIP_REVISION_2_C 0x23
//SX1231 specific register map
#define RADIOLIB_SX1231_REG_TEST_OOK 0x6E
// RADIOLIB_SX1231 specific register map
#define RADIOLIB_SX1231_REG_TEST_OOK 0x6E
//SX1231_REG_TEST_OOK
#define RADIOLIB_SX1231_OOK_DELTA_THRESHOLD 0x0C
// RADIOLIB_SX1231_REG_TEST_OOK
#define RADIOLIB_SX1231_OOK_DELTA_THRESHOLD 0x0C
// SX1231_REG_DIO_MAPPING_1
#define RADIOLIB_SX1231_DIO0_CONT_LOW_BAT 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO0_CONT_MODE_READY 0b11000000 // 7 6
#define RADIOLIB_SX1231_DIO0_CONT_PLL_LOCK 0b00000000 // 7 6
#define RADIOLIB_SX1231_DIO0_CONT_SYNC_ADDRESS 0b00000000 // 7 6
#define RADIOLIB_SX1231_DIO0_CONT_TIMEOUT 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO0_CONT_RSSI 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO0_CONT_MODE_READY 0b11000000 // 7 6
#define RADIOLIB_SX1231_DIO0_CONT_TX_READY 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_LOW_BAT 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_PLL_LOCK 0b11000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_CRC_OK 0b00000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_PAYLOAD_READY 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_SYNC_ADDRESS 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_RSSI 0b11000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_PACKET_SENT 0b00000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_TX_READY 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO1_CONT_LOW_BAT 0b00100000 // 5 4
#define RADIOLIB_SX1231_DIO1_CONT_PLL_LOCK 0b00110000 // 5 4
#define RADIOLIB_SX1231_DIO1_CONT_DCLK 0b00000000 // 5 4
#define RADIOLIB_SX1231_DIO1_CONT_RX_READY 0b00010000 // 5 4
#define RADIOLIB_SX1231_DIO1_CONT_SYNC_ADDRESS 0b00110000 // 5 4
#define RADIOLIB_SX1231_DIO1_CONT_TX_READY 0b00010000 // 5 4
#define RADIOLIB_SX1231_DIO1_PACK_FIFO_LEVEL 0b00000000 // 5 4
#define RADIOLIB_SX1231_DIO1_PACK_FIFO_FULL 0b00010000 // 5 4
#define RADIOLIB_SX1231_DIO1_PACK_FIFO_NOT_EMPTY 0b00100000 // 5 4
#define RADIOLIB_SX1231_DIO1_PACK_PLL_LOCK 0b00110000 // 5 4
#define RADIOLIB_SX1231_DIO1_PACK_TIMEOUT 0b00110000 // 5 4
#define RADIOLIB_SX1231_DIO2_CONT_DATA 0b00000000 // 3 2
#define RADIOLIB_SX1231_DIO2_PACK_FIFO_NOT_EMPTY 0b00000000 // 3 2
#define RADIOLIB_SX1231_DIO2_PACK_LOW_BAT 0b00001000 // 3 2
#define RADIOLIB_SX1231_DIO2_PACK_AUTO_MODE 0b00001100 // 3 2
#define RADIOLIB_SX1231_DIO2_PACK_DATA 0b00000100 // 3 2
#define RADIOLIB_SX1231_DIO3_CONT_AUTO_MODE 0b00000010 // 0 1
#define RADIOLIB_SX1231_DIO3_CONT_RSSI 0b00000000 // 0 1
#define RADIOLIB_SX1231_DIO3_CONT_RX_READY 0b00000001 // 0 1
#define RADIOLIB_SX1231_DIO3_CONT_TIMEOUT 0b00000011 // 0 1
#define RADIOLIB_SX1231_DIO3_CONT_TX_READY 0b00000001 // 0 1
#define RADIOLIB_SX1231_DIO3_PACK_FIFO_FULL 0b00000000 // 0 1
#define RADIOLIB_SX1231_DIO3_PACK_LOW_BAT 0b00000010 // 0 1
#define RADIOLIB_SX1231_DIO3_PACK_PLL_LOCK 0b00000011 // 0 1
#define RADIOLIB_SX1231_DIO3_PACK_RSSI 0b00000001 // 0 1
#define RADIOLIB_SX1231_DIO3_PACK_SYNC_ADDRESSS 0b00000010 // 0 1
#define RADIOLIB_SX1231_DIO3_PACK_TX_READY 0b00000001 // 0 1
// RADIOLIB_SX1231_REG_DIO_MAPPING_1
#define RADIOLIB_SX1231_DIO0_CONT_LOW_BAT 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO0_CONT_MODE_READY 0b11000000 // 7 6
#define RADIOLIB_SX1231_DIO0_CONT_PLL_LOCK 0b00000000 // 7 6
#define RADIOLIB_SX1231_DIO0_CONT_SYNC_ADDRESS 0b00000000 // 7 6
#define RADIOLIB_SX1231_DIO0_CONT_TIMEOUT 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO0_CONT_RSSI 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO0_CONT_MODE_READY 0b11000000 // 7 6
#define RADIOLIB_SX1231_DIO0_CONT_TX_READY 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_LOW_BAT 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_PLL_LOCK 0b11000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_CRC_OK 0b00000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_PAYLOAD_READY 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_SYNC_ADDRESS 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_RSSI 0b11000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_PACKET_SENT 0b00000000 // 7 6
#define RADIOLIB_SX1231_DIO0_PACK_TX_READY 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO1_CONT_LOW_BAT 0b00100000 // 5 4
#define RADIOLIB_SX1231_DIO1_CONT_PLL_LOCK 0b00110000 // 5 4
#define RADIOLIB_SX1231_DIO1_CONT_DCLK 0b00000000 // 5 4
#define RADIOLIB_SX1231_DIO1_CONT_RX_READY 0b00010000 // 5 4
#define RADIOLIB_SX1231_DIO1_CONT_SYNC_ADDRESS 0b00110000 // 5 4
#define RADIOLIB_SX1231_DIO1_CONT_TX_READY 0b00010000 // 5 4
#define RADIOLIB_SX1231_DIO1_PACK_FIFO_LEVEL 0b00000000 // 5 4
#define RADIOLIB_SX1231_DIO1_PACK_FIFO_FULL 0b00010000 // 5 4
#define RADIOLIB_SX1231_DIO1_PACK_FIFO_NOT_EMPTY 0b00100000 // 5 4
#define RADIOLIB_SX1231_DIO1_PACK_PLL_LOCK 0b00110000 // 5 4
#define RADIOLIB_SX1231_DIO1_PACK_TIMEOUT 0b00110000 // 5 4
#define RADIOLIB_SX1231_DIO2_CONT_DATA 0b00000000 // 3 2
#define RADIOLIB_SX1231_DIO2_PACK_FIFO_NOT_EMPTY 0b00000000 // 3 2
#define RADIOLIB_SX1231_DIO2_PACK_LOW_BAT 0b00001000 // 3 2
#define RADIOLIB_SX1231_DIO2_PACK_AUTO_MODE 0b00001100 // 3 2
#define RADIOLIB_SX1231_DIO2_PACK_DATA 0b00000100 // 3 2
#define RADIOLIB_SX1231_DIO3_CONT_AUTO_MODE 0b00000010 // 0 1
#define RADIOLIB_SX1231_DIO3_CONT_RSSI 0b00000000 // 0 1
#define RADIOLIB_SX1231_DIO3_CONT_RX_READY 0b00000001 // 0 1
#define RADIOLIB_SX1231_DIO3_CONT_TIMEOUT 0b00000011 // 0 1
#define RADIOLIB_SX1231_DIO3_CONT_TX_READY 0b00000001 // 0 1
#define RADIOLIB_SX1231_DIO3_PACK_FIFO_FULL 0b00000000 // 0 1
#define RADIOLIB_SX1231_DIO3_PACK_LOW_BAT 0b00000010 // 0 1
#define RADIOLIB_SX1231_DIO3_PACK_PLL_LOCK 0b00000011 // 0 1
#define RADIOLIB_SX1231_DIO3_PACK_RSSI 0b00000001 // 0 1
#define RADIOLIB_SX1231_DIO3_PACK_SYNC_ADDRESSS 0b00000010 // 0 1
#define RADIOLIB_SX1231_DIO3_PACK_TX_READY 0b00000001 // 0 1
// SX1231_REG_DIO_MAPPING_2
#define RADIOLIB_SX1231_DIO4_CONT_LOW_BAT 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO4_CONT_PLL_LOCK 0b11000000 // 7 6
#define RADIOLIB_SX1231_DIO4_CONT_TIMEOUT 0b00000000 // 7 6
#define RADIOLIB_SX1231_DIO4_CONT_RX_READY 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO4_CONT_SYNC_ADDRESS 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO4_CONT_TX_READY 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO4_PACK_LOW_BAT 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO4_PACK_PLL_LOCK 0b11000000 // 7 6
#define RADIOLIB_SX1231_DIO4_PACK_TIMEOUT 0b00000000 // 7 6
#define RADIOLIB_SX1231_DIO4_PACK_RSSI 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO4_PACK_RX_READY 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO4_PACK_MODE_READY 0b00000000 // 7 6
#define RADIOLIB_SX1231_DIO4_PACK_TX_READY 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO5_CONT_LOW_BAT 0b00100000 // 5 4
#define RADIOLIB_SX1231_DIO5_CONT_MODE_READY 0b00110000 // 5 4
#define RADIOLIB_SX1231_DIO5_CONT_CLK_OUT 0b00000000 // 5 4
#define RADIOLIB_SX1231_DIO5_CONT_RSSI 0b00010000 // 5 4
#define RADIOLIB_SX1231_DIO5_PACK_LOW_BAT 0b00100000 // 5 4
#define RADIOLIB_SX1231_DIO5_PACK_MODE_READY 0b00110000 // 5 4
#define RADIOLIB_SX1231_DIO5_PACK_CLK_OUT 0b00000000 // 5 4
#define RADIOLIB_SX1231_DIO5_PACK_DATA 0b00010000 // 5 4
// RADIOLIB_SX1231_REG_DIO_MAPPING_2
#define RADIOLIB_SX1231_DIO4_CONT_LOW_BAT 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO4_CONT_PLL_LOCK 0b11000000 // 7 6
#define RADIOLIB_SX1231_DIO4_CONT_TIMEOUT 0b00000000 // 7 6
#define RADIOLIB_SX1231_DIO4_CONT_RX_READY 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO4_CONT_SYNC_ADDRESS 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO4_CONT_TX_READY 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO4_PACK_LOW_BAT 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO4_PACK_PLL_LOCK 0b11000000 // 7 6
#define RADIOLIB_SX1231_DIO4_PACK_TIMEOUT 0b00000000 // 7 6
#define RADIOLIB_SX1231_DIO4_PACK_RSSI 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO4_PACK_RX_READY 0b10000000 // 7 6
#define RADIOLIB_SX1231_DIO4_PACK_MODE_READY 0b00000000 // 7 6
#define RADIOLIB_SX1231_DIO4_PACK_TX_READY 0b01000000 // 7 6
#define RADIOLIB_SX1231_DIO5_CONT_LOW_BAT 0b00100000 // 5 4
#define RADIOLIB_SX1231_DIO5_CONT_MODE_READY 0b00110000 // 5 4
#define RADIOLIB_SX1231_DIO5_CONT_CLK_OUT 0b00000000 // 5 4
#define RADIOLIB_SX1231_DIO5_CONT_RSSI 0b00010000 // 5 4
#define RADIOLIB_SX1231_DIO5_PACK_LOW_BAT 0b00100000 // 5 4
#define RADIOLIB_SX1231_DIO5_PACK_MODE_READY 0b00110000 // 5 4
#define RADIOLIB_SX1231_DIO5_PACK_CLK_OUT 0b00000000 // 5 4
#define RADIOLIB_SX1231_DIO5_PACK_DATA 0b00010000 // 5 4
/*!
\class SX1231
\brief Control class for %SX1231 module. Overrides some methods from RF69 due to different register values.
*/
class SX1231: public RF69 {
public:
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
SX1231(Module* mod);
SX1231(Module* mod); // cppcheck-suppress noExplicitConstructor
/*!
\brief Initialization method.
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
\param br Bit rate to be used 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 125.0 kHz.
\param power Output power in dBm. Defaults to 10 dBm.
\param preambleLen Preamble Length in bits. Defaults to 16 bits.
\returns \ref status_codes
*/
int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint8_t preambleLen = 16);
#if !defined(RADIOLIB_GODMODE)
private:
#if !RADIOLIB_GODMODE
protected:
#endif
uint8_t _chipRevision = 0;
uint8_t chipRevision = 0;
};
#endif
+127
View File
@@ -0,0 +1,127 @@
#include "SX1233.h"
#include <math.h>
#if !RADIOLIB_EXCLUDE_SX1231
SX1233::SX1233(Module* mod) : SX1231(mod) {
}
int16_t SX1233::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) {
// set module properties
Module* mod = this->getMod();
mod->init();
mod->hal->pinMode(mod->getIrq(), mod->hal->GpioModeInput);
mod->hal->pinMode(mod->getRst(), mod->hal->GpioModeOutput);
// try to find the SX1233 chip
uint8_t i = 0;
bool flagFound = false;
while((i < 10) && !flagFound) {
int16_t version = getChipVersion();
if((version == RADIOLIB_SX123X_CHIP_REVISION_2_A) || (version == RADIOLIB_SX123X_CHIP_REVISION_2_B) || (version == RADIOLIB_SX123X_CHIP_REVISION_2_C)) {
flagFound = true;
this->chipRevision = version;
} else {
RADIOLIB_DEBUG_BASIC_PRINTLN("SX1231 not found! (%d of 10 tries) RF69_REG_VERSION == 0x%04X, expected 0x0021 / 0x0022 / 0x0023", i + 1, version);
mod->hal->delay(10);
i++;
}
}
if(!flagFound) {
RADIOLIB_DEBUG_BASIC_PRINTLN("No SX1233 found!");
mod->term();
return(RADIOLIB_ERR_CHIP_NOT_FOUND);
}
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSX1233");
// configure settings not accessible by API
int16_t state = config();
RADIOLIB_ASSERT(state);
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tRF69");
// configure publicly accessible settings
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
// configure bitrate
this->rxBandwidth = 125.0;
state = setBitRate(br);
RADIOLIB_ASSERT(state);
// configure default RX bandwidth
state = setRxBandwidth(rxBw);
RADIOLIB_ASSERT(state);
// configure default frequency deviation
state = setFrequencyDeviation(freqDev);
RADIOLIB_ASSERT(state);
// configure default TX output power
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
// configure default preamble length
state = setPreambleLength(preambleLen);
RADIOLIB_ASSERT(state);
// default sync word values 0x2D01 is the same as the default in LowPowerLab RFM69 library
uint8_t syncWord[] = {0x2D, 0x01};
state = setSyncWord(syncWord, 2);
RADIOLIB_ASSERT(state);
// set default packet length mode
state = variablePacketLengthMode();
if (state != RADIOLIB_ERR_NONE) {
return(state);
}
// SX123x V2a only
if(this->chipRevision == RADIOLIB_SX123X_CHIP_REVISION_2_A) {
// modify default OOK threshold value
state = mod->SPIsetRegValue(RADIOLIB_SX1231_REG_TEST_OOK, RADIOLIB_SX1231_OOK_DELTA_THRESHOLD);
RADIOLIB_ASSERT(state);
// enable OCP with 95 mA limit
state = mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM, 4, 0);
RADIOLIB_ASSERT(state);
}
return(RADIOLIB_ERR_NONE);
}
int16_t SX1233::setBitRate(float br) {
// check high bit-rate operation
uint8_t pllBandwidth = RADIOLIB_SX1233_PLL_BW_LOW_BIT_RATE;
if((fabsf(br - 500.0f) < 0.1) || (fabsf(br - 600.0f) < 0.1)) {
pllBandwidth = RADIOLIB_SX1233_PLL_BW_HIGH_BIT_RATE;
} else {
// datasheet says 1.2 kbps should be the smallest possible, but 0.512 works fine
RADIOLIB_CHECK_RANGE(br, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
}
// check bitrate-bandwidth ratio
if(!(br < 2000 * this->rxBandwidth)) {
return(RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO);
}
// set mode to standby
setMode(RADIOLIB_RF69_STANDBY);
// set PLL bandwidth
Module* mod = this->getMod();
int16_t state = mod->SPIsetRegValue(RADIOLIB_SX1233_REG_TEST_PLL, pllBandwidth, 7, 0);
RADIOLIB_ASSERT(state);
// set bit rate
uint16_t bitRate = 32000 / br;
state = mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0);
state |= mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0);
if(state == RADIOLIB_ERR_NONE) {
this->bitRate = br;
}
return(state);
}
#endif
+61
View File
@@ -0,0 +1,61 @@
#if !defined(_RADIOLIB_SX1233_H)
#define _RADIOLIB_SX1233_H
#include "../../TypeDef.h"
#if !RADIOLIB_EXCLUDE_SX1231
#include "../../Module.h"
#include "../RF69/RF69.h"
#include "SX1231.h"
// RADIOLIB_SX1233 specific register map
#define RADIOLIB_SX1233_REG_TEST_PLL 0x5F
// RADIOLIB_SX1233_REG_TEST_PLL
#define RADIOLIB_SX1233_PLL_BW_HIGH_BIT_RATE 0x0C
#define RADIOLIB_SX1233_PLL_BW_LOW_BIT_RATE 0x08
/*!
\class SX1233
\brief Control class for %SX1233 module. Overrides some methods from SX1231/RF69 due to different register values.
*/
class SX1233: public SX1231 {
public:
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
SX1233(Module* mod); // cppcheck-suppress noExplicitConstructor
/*!
\brief Initialization method.
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
\param br Bit rate to be used 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 125.0 kHz.
\param power Output power in dBm. Defaults to 10 dBm.
\param preambleLen Preamble Length in bits. Defaults to 16 bits.
\returns \ref status_codes
*/
int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint8_t preambleLen = 16);
/*!
\brief Sets bit rate. Allowed values range from 0.5 to 300.0 kbps.
SX1233 also allows 500 kbps and 600 kbps operation.
NOTE: For 500 kbps rate, the receiver frequency should be offset by 50 kHz from the transmitter.
For 600 kbps rate, the receiver frequency should be offset by 40 kHz from the transmitter.
\param br Bit rate to be set in kbps.
\returns \ref status_codes
*/
int16_t setBitRate(float br) override;
#if !RADIOLIB_GODMODE
private:
#endif
};
#endif
#endif
@@ -0,0 +1,154 @@
/*
Copyright (c) 2018 Jan Gromeš
Copyright (c) 2022 STMicroelectronics
This file is licensed under the MIT License: https://opensource.org/licenses/MIT
*/
#include "STM32WLx.h"
#if !RADIOLIB_EXCLUDE_STM32WLX
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
int16_t state = SX1262::begin(freq, bw, sf, cr, syncWord, power, preambleLength, tcxoVoltage, useRegulatorLDO);
RADIOLIB_ASSERT(state);
// This overrides the value in SX126x::begin()
// On STM32WL, DIO2 is hardwired to the radio IRQ on the MCU, so it
// should really not be used as RfSwitch control output.
state = setDio2AsRfSwitch(false);
RADIOLIB_ASSERT(state);
return(state);
}
int16_t STM32WLx::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) {
// Execute common part
int16_t state = SX1262::beginFSK(freq, br, freqDev, rxBw, power, preambleLength, tcxoVoltage, useRegulatorLDO);
RADIOLIB_ASSERT(state);
// This overrides the value in SX126x::beginFSK()
// On STM32WL, DIO2 is hardwired to the radio IRQ on the MCU, so it
// should really not be used as RfSwitch control output.
state = setDio2AsRfSwitch(false);
RADIOLIB_ASSERT(state);
return(state);
}
int16_t STM32WLx::setOutputPower(int8_t power) {
// get current OCP configuration
uint8_t ocp = 0;
int16_t state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
RADIOLIB_ASSERT(state);
// check the user did not request power output that is not possible
Module* mod = this->getMod();
bool hp_supported = mod->findRfSwitchMode(MODE_TX_HP);
bool lp_supported = mod->findRfSwitchMode(MODE_TX_LP);
if((!lp_supported && (power < -9)) || (!hp_supported && (power > 14))) {
// LP not supported but requested power is below HP low bound or
// HP not supported but requested power is above LP high bound
return(RADIOLIB_ERR_INVALID_OUTPUT_POWER);
}
// set PA config based on which PAs are supported
bool use_hp = false;
if(hp_supported && lp_supported) {
// both PAs supported, use HP when above 14 dBm
if(power > 14) {
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
state = SX126x::setPaConfig(0x04, 0x00, 0x07); // HP output up to 22dBm
this->txMode = MODE_TX_HP;
use_hp = true;
} else {
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
state = SX126x::setPaConfig(0x04, 0x01, 0x00); // LP output up to 14dBm
this->txMode = MODE_TX_LP;
}
} else if(!hp_supported && lp_supported) {
// only LP supported
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
state = SX126x::setPaConfig(0x04, 0x01, 0x00);
this->txMode = MODE_TX_LP;
} else if(hp_supported && !lp_supported) {
// only HP supported
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
state = SX126x::setPaConfig(0x04, 0x00, 0x07);
this->txMode = MODE_TX_HP;
use_hp = true;
} else {
// neither PA is supported
return(RADIOLIB_ERR_INVALID_OUTPUT_POWER);
}
RADIOLIB_ASSERT(state);
// Apply workaround for HP only
state = SX126x::fixPaClamping(use_hp);
RADIOLIB_ASSERT(state);
// set output power with default 200us ramp
state = SX126x::setTxParams(power, RADIOLIB_SX126X_PA_RAMP_200U);
RADIOLIB_ASSERT(state);
// restore OCP configuration
return(writeRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1));
}
int16_t STM32WLx::clearIrqStatus(uint16_t clearIrqParams) {
int16_t res = SX126x::clearIrqStatus(clearIrqParams);
// The NVIC interrupt is level-sensitive, so clear away any pending
// flag that is only set because the radio IRQ status was not cleared
// in the interrupt (to prevent each IRQ triggering twice and allow
// reading the irq status through the pending flag).
SubGhz.clearPendingInterrupt();
if(SubGhz.hasInterrupt())
SubGhz.enableInterrupt();
return(res);
}
void STM32WLx::setDio1Action(void (*func)(void)) {
SubGhz.attachInterrupt([func]() {
// Because the interrupt is level-triggered, we disable it in the
// NVIC (otherwise we would need an SPI command to clear the IRQ in
// the radio, or it would trigger over and over again).
SubGhz.disableInterrupt();
func();
});
}
void STM32WLx::clearDio1Action() {
SubGhz.detachInterrupt();
}
void STM32WLx::setPacketReceivedAction(void (*func)(void)) {
this->setDio1Action(func);
}
void STM32WLx::clearPacketReceivedAction() {
this->clearDio1Action();
}
void STM32WLx::setPacketSentAction(void (*func)(void)) {
this->setDio1Action(func);
}
void STM32WLx::clearPacketSentAction() {
this->clearDio1Action();
}
void STM32WLx::setChannelScanAction(void (*func)(void)) {
this->setDio1Action(func);
}
void STM32WLx::clearChannelScanAction() {
this->clearDio1Action();
}
#endif
+168
View File
@@ -0,0 +1,168 @@
/*
Copyright (c) 2018 Jan Gromeš
Copyright (c) 2022 STMicroelectronics
This file is licensed under the MIT License: https://opensource.org/licenses/MIT
*/
#if !defined(_RADIOLIB_STM32WLx_H)
#define _RADIOLIB_STM32WLx_H
#include "../../TypeDef.h"
#if !RADIOLIB_EXCLUDE_STM32WLX
#include "../../Module.h"
#include "SX1262.h"
#include "STM32WLx_Module.h"
/*!
\class STM32WLx
\brief Derived class for STM32WL modules.
The radio integrated into these modules is essentially the same as the
Semtech %SX126x external radio chips, so most of the documentation for
those also applies here.
One notable difference with the %SX126x radios is that this radio
essentially combines the %SX1261 and %SX1262 by integrating both the
low-power (LP) and high-power (HP) amplifier. See setOutputPower() and
setRfSwitchTable() for details on how this is handled.
*/
class STM32WLx : public SX1262 {
// NOTE: This class could not be named STM32WL (or STM32WLxx), since
// those are macros defined by
// system/Drivers/CMSIS/Device/ST/STM32WLxxx/Include/stm32wlxx.h
public:
/*!
\brief Default constructor.
\param mod Instance of STM32WLx_Module that will be used to communicate with the radio.
*/
STM32WLx(STM32WLx_Module* mod); // cppcheck-suppress noExplicitConstructor
/*!
\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,
/*! Idle mode */
MODE_IDLE = Module::MODE_IDLE,
/*! Receive mode */
MODE_RX = Module::MODE_RX,
/*! Low power transmission mode */
MODE_TX_LP = Module::MODE_TX,
/*! High power transmission mode */
MODE_TX_HP,
};
// basic methods
/*!
\copydoc SX1262::begin
*/
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);
/*!
\copydoc SX1262::beginFSK
*/
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);
// configuration methods
/*!
\brief Sets output power. Allowed values are in range from -17 to 22 dBm.
This automatically switches between the low-power (LP) and high-power (HP) amplifier.
LP is preferred and supports -17 to +14dBm. When a higher power is
requested (or the LP amplifier is marked as unavailable using
setRfSwitchTable()), HP is used, which supports -9 to +22dBm. If the LP is marked as unavailable,
HP output will be used instead.
\param power Output power to be set in dBm.
\returns \ref status_codes
*/
virtual int16_t setOutputPower(int8_t power) override;
/*!
\copybrief Module::setRfSwitchTable
This method works like Module::setRfSwitchTable(), except that you
should use STM32WLx::OpMode_t constants for modes, which
distinguishes between a low-power (LP) and high-power (HP) TX mode.
For boards that do not support both modes, just omit the
unsupported mode from the table and it will not be used (and the
valid power range is adjusted by setOutputPower() accordingly).
Note that the setRfSwitchTable() method should be called *before* the
begin() method, to ensure the radio knows which modes are supported
during initialization.
*/
// Note: This explicitly inherits this method only to override docs
using SX126x::setRfSwitchTable;
/*!
\brief Sets interrupt service routine to call when DIO1/2/3 activates.
\param func ISR to call.
*/
void setDio1Action(void (*func)(void));
/*!
\brief Clears interrupt service routine to call when DIO1/2/3 activates.
*/
void clearDio1Action();
/*!
\brief Sets interrupt service routine to call when a packet is received.
\param func ISR to call.
*/
void setPacketReceivedAction(void (*func)(void)) override;
/*!
\brief Clears interrupt service routine to call when a packet is received.
*/
void clearPacketReceivedAction() override;
/*!
\brief Sets interrupt service routine to call when a packet is sent.
\param func ISR to call.
*/
void setPacketSentAction(void (*func)(void)) override;
/*!
\brief Clears interrupt service routine to call when a packet is sent.
*/
void clearPacketSentAction() override;
/*!
\brief Sets interrupt service routine to call when a channel scan is finished.
\param func ISR to call.
*/
void setChannelScanAction(void (*func)(void)) override;
/*!
\brief Clears interrupt service routine to call when a channel scan is finished.
*/
void clearChannelScanAction() override;
#if !RADIOLIB_GODMODE
protected:
#endif
virtual int16_t clearIrqStatus(uint16_t clearIrqParams) override;
#if !RADIOLIB_GODMODE
private:
#endif
};
#endif
#endif
@@ -0,0 +1,125 @@
/*
Copyright (c) 2022 STMicroelectronics
This file is licensed under the MIT License: https://opensource.org/licenses/MIT
*/
#include "STM32WLx_Module.h"
#if !RADIOLIB_EXCLUDE_STM32WLX
#include "../../ArduinoHal.h"
// This defines some dummy pin numbers (starting at NUM_DIGITAL_PINS to
// guarantee these are not valid regular pin numbers) that can be passed
// to the parent Module class, to be stored here and then passed back to
// the overridden callbacks when these are used.
enum {
RADIOLIB_STM32WLx_VIRTUAL_PIN_NSS = NUM_DIGITAL_PINS,
RADIOLIB_STM32WLx_VIRTUAL_PIN_BUSY,
RADIOLIB_STM32WLx_VIRTUAL_PIN_IRQ,
RADIOLIB_STM32WLx_VIRTUAL_PIN_RESET,
};
/*!
\class Stm32wlxHal
\brief Hardware Abstraction Layer for STM32WL.
*/
class Stm32wlxHal : public ArduinoHal {
public:
Stm32wlxHal(): ArduinoHal(SubGhz.SPI, SubGhz.spi_settings) {}
/*!
\brief Pin mode override to handle STM32WL virtual pins.
\param dwPin Pin to set.
\param dwMode Mode to set.
*/
void pinMode(uint32_t dwPin, uint32_t dwMode) {
switch(dwPin) {
case RADIOLIB_STM32WLx_VIRTUAL_PIN_NSS:
case RADIOLIB_STM32WLx_VIRTUAL_PIN_BUSY:
case RADIOLIB_STM32WLx_VIRTUAL_PIN_IRQ:
case RADIOLIB_STM32WLx_VIRTUAL_PIN_RESET:
// Nothing to do
break;
default:
::pinMode(dwPin, dwMode);
break;
}
}
/*!
\brief Digital write override to handle STM32WL virtual pins.
\param dwPin Pin to set.
\param dwVal Value to set.
*/
void digitalWrite(uint32_t dwPin, uint32_t dwVal) {
switch (dwPin) {
case RADIOLIB_STM32WLx_VIRTUAL_PIN_NSS:
SubGhz.setNssActive(dwVal == LOW);
break;
case RADIOLIB_STM32WLx_VIRTUAL_PIN_RESET:
SubGhz.setResetActive(dwVal == LOW);
break;
case RADIOLIB_STM32WLx_VIRTUAL_PIN_BUSY:
case RADIOLIB_STM32WLx_VIRTUAL_PIN_IRQ:
// Should not (and cannot) be written, just ignore
break;
default:
::digitalWrite(dwPin, dwVal);
break;
}
}
/*!
\brief Digital read override to handle STM32WL virtual pins.
\param ulPin Pin to read.
\returns Value read on the pin.
*/
uint32_t digitalRead(uint32_t ulPin) {
switch (ulPin) {
case RADIOLIB_STM32WLx_VIRTUAL_PIN_BUSY:
return(SubGhz.isBusy() ? HIGH : LOW);
case RADIOLIB_STM32WLx_VIRTUAL_PIN_IRQ:
// We cannot use the radio IRQ output directly, but since:
// - the pending flag will be set whenever the IRQ output is set,
// and
// - the pending flag will be cleared (by
// STM32WLx::clearIrqStatus()) whenever the radio IRQ output is
// cleared,
// the pending flag should always reflect the current radio IRQ
// output. There is one exception: when the ISR starts the pending
// flag is cleared by hardware and not set again until after the
// ISR finishes, so the value is incorrect *inside* the ISR, but
// running RadioLib code inside the ISR (especially code that
// polls the IRQ flag) is not supported and probably broken in
// other ways too.
return(SubGhz.isInterruptPending() ? HIGH : LOW);
case RADIOLIB_STM32WLx_VIRTUAL_PIN_NSS:
return(SubGhz.isNssActive() ? LOW : HIGH);
case RADIOLIB_STM32WLx_VIRTUAL_PIN_RESET:
return(SubGhz.isResetActive() ? LOW : HIGH);
default:
return(::digitalRead(ulPin));
}
}
};
STM32WLx_Module::STM32WLx_Module():
Module(
new Stm32wlxHal,
RADIOLIB_STM32WLx_VIRTUAL_PIN_NSS,
RADIOLIB_STM32WLx_VIRTUAL_PIN_IRQ,
RADIOLIB_STM32WLx_VIRTUAL_PIN_RESET,
RADIOLIB_STM32WLx_VIRTUAL_PIN_BUSY
) {}
#endif
@@ -0,0 +1,38 @@
/*
Copyright (c) 2022 STMicroelectronics
This file is licensed under the MIT License: https://opensource.org/licenses/MIT
*/
#if !defined(_RADIOLIB_STM32WLX_MODULE_H)
#define _RADIOLIB_STM32WLX_MODULE_H
#include "../../TypeDef.h"
#if !RADIOLIB_EXCLUDE_STM32WLX
#include "../../Module.h"
/*!
* \class STM32WLx_Module
*
* This is a subclass of Module to be used with the STM32WLx driver.
*
* It is used to override some callbacks, allowing access to some of the
* radio control signals that are wired to internal registers instead of
* actual GPIO pins.
*/
class STM32WLx_Module : public Module {
// Note: We cannot easily override any methods here, since most calls
// are non-virtual and made through a Module*, so they would not be
// calling any overridden methods. This means this class works by
// overriding some of the callbacks in its constructor.
public:
STM32WLx_Module();
};
#endif
#endif
+16 -7
View File
@@ -1,29 +1,38 @@
#include "SX1261.h"
#if !defined(RADIOLIB_EXCLUDE_SX126X)
#if !RADIOLIB_EXCLUDE_SX126X
SX1261::SX1261(Module* mod): SX1262(mod) {
chipType = RADIOLIB_SX1261_CHIP_TYPE;
}
int16_t SX1261::setOutputPower(int8_t power) {
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
// check if power value is configurable
int16_t state = checkOutputPower(power, NULL);
RADIOLIB_ASSERT(state);
// get current OCP configuration
uint8_t ocp = 0;
int16_t state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
RADIOLIB_ASSERT(state);
// set PA config
state = SX126x::setPaConfig(0x04, RADIOLIB_SX126X_PA_CONFIG_SX1261, 0x00);
RADIOLIB_ASSERT(state);
// set output power
/// \todo power ramp time configuration
state = SX126x::setTxParams(power);
// set output power with default 200us ramp
state = SX126x::setTxParams(power, RADIOLIB_SX126X_PA_RAMP_200U);
RADIOLIB_ASSERT(state);
// restore OCP configuration
return(writeRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1));
}
int16_t SX1261::checkOutputPower(int8_t power, int8_t* clipped) {
if(clipped) {
*clipped = RADIOLIB_MAX(-17, RADIOLIB_MIN(14, power));
}
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
return(RADIOLIB_ERR_NONE);
}
#endif
+16 -9
View File
@@ -3,39 +3,46 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX126X)
#if !RADIOLIB_EXCLUDE_SX126X
#include "../../Module.h"
#include "SX126x.h"
#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"
/*!
\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);
SX1261(Module* mod); // cppcheck-suppress noExplicitConstructor
/*!
\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);
int16_t setOutputPower(int8_t power) override;
#if !defined(RADIOLIB_GODMODE)
/*!
\brief Check if output power is configurable.
\param power Output power in dBm.
\param clipped Clipped output power value to what is possible within the module's range.
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
#if !RADIOLIB_GODMODE
private:
#endif
+48 -19
View File
@@ -1,8 +1,8 @@
#include "SX1262.h"
#if !defined(RADIOLIB_EXCLUDE_SX126X)
#if !RADIOLIB_EXCLUDE_SX126X
SX1262::SX1262(Module* mod) : SX126x(mod) {
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) {
@@ -20,10 +20,10 @@ int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
state = SX126x::fixPaClamping();
RADIOLIB_ASSERT(state);
state = SX126x::fixPaClamping();
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
return(state);
@@ -38,39 +38,59 @@ int16_t SX1262::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
state = SX126x::fixPaClamping();
RADIOLIB_ASSERT(state);
state = SX126x::fixPaClamping();
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
return(state);
}
int16_t SX1262::setFrequency(float freq) {
return(setFrequency(freq, true));
}
int16_t SX1262::setFrequency(float freq, bool calibrate) {
RADIOLIB_CHECK_RANGE(freq, 150.0, 960.0, RADIOLIB_ERR_INVALID_FREQUENCY);
// calibrate image
// calibrate image rejection
if(calibrate) {
uint8_t data[2];
if(freq > 900.0) {
uint8_t data[2] = { 0, 0 };
// try to match the frequency ranges
int freqBand = (int)freq;
if((freqBand >= 902) && (freqBand <= 928)) {
data[0] = RADIOLIB_SX126X_CAL_IMG_902_MHZ_1;
data[1] = RADIOLIB_SX126X_CAL_IMG_902_MHZ_2;
} else if(freq > 850.0) {
} else if((freqBand >= 863) && (freqBand <= 870)) {
data[0] = RADIOLIB_SX126X_CAL_IMG_863_MHZ_1;
data[1] = RADIOLIB_SX126X_CAL_IMG_863_MHZ_2;
} else if(freq > 770.0) {
} else if((freqBand >= 779) && (freqBand <= 787)) {
data[0] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_1;
data[1] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_2;
} else if(freq > 460.0) {
} else if((freqBand >= 470) && (freqBand <= 510)) {
data[0] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_1;
data[1] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_2;
} else {
} else if((freqBand >= 430) && (freqBand <= 440)) {
data[0] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_1;
data[1] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_2;
}
int16_t state = SX126x::calibrateImage(data);
int16_t state;
if(data[0]) {
// matched with predefined ranges, do the calibration
state = SX126x::calibrateImage(data);
} else {
// if nothing matched, try custom calibration - the may or may not work
RADIOLIB_DEBUG_BASIC_PRINTLN("Failed to match predefined frequency range, trying custom");
state = SX126x::calibrateImageRejection(freq - 4.0f, freq + 4.0f);
}
RADIOLIB_ASSERT(state);
}
// set frequency
@@ -78,24 +98,33 @@ int16_t SX1262::setFrequency(float freq, bool calibrate) {
}
int16_t SX1262::setOutputPower(int8_t power) {
RADIOLIB_CHECK_RANGE(power, -17, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
// check if power value is configurable
int16_t state = checkOutputPower(power, NULL);
RADIOLIB_ASSERT(state);
// get current OCP configuration
uint8_t ocp = 0;
int16_t state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
RADIOLIB_ASSERT(state);
// set PA config
state = SX126x::setPaConfig(0x04, RADIOLIB_SX126X_PA_CONFIG_SX1262);
RADIOLIB_ASSERT(state);
// set output power
/// \todo power ramp time configuration
state = SX126x::setTxParams(power);
// set output power with default 200us ramp
state = SX126x::setTxParams(power, RADIOLIB_SX126X_PA_RAMP_200U);
RADIOLIB_ASSERT(state);
// restore OCP configuration
return(writeRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1));
}
int16_t SX1262::checkOutputPower(int8_t power, int8_t* clipped) {
if(clipped) {
*clipped = RADIOLIB_MAX(-9, RADIOLIB_MIN(22, power));
}
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
return(RADIOLIB_ERR_NONE);
}
#endif
+39 -39
View File
@@ -3,99 +3,99 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX126X)
#if !RADIOLIB_EXCLUDE_SX126X
#include "../../Module.h"
#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"
/*!
\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);
SX1262(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
/*!
\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 2-byte LoRa sync word. Defaults to RADIOLIB_SX126X_SYNC_WORD_PRIVATE (0x12).
\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 tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V.
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
To use XTAL, either set this value to 0, or set SX126x::XTAL to true.
\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.
\parma 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 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.
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
To use XTAL, either set this value to 0, or set SX126x::XTAL to true.
\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);
// 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.
\param calibrate Run image calibration.
\returns \ref status_codes
*/
int16_t setFrequency(float freq, bool calibrate = true);
int16_t setFrequency(float freq) override;
/*!
\brief Sets output power. Allowed values are in range from -17 to 22 dBm.
\param power Output power to be set in dBm.
\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 setOutputPower(int8_t power);
int16_t setFrequency(float freq, bool calibrate);
#if !defined(RADIOLIB_GODMODE)
/*!
\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) override;
/*!
\brief Check if output power is configurable.
\param power Output power in dBm.
\param clipped Clipped output power value to what is possible within the module's range.
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
#if !RADIOLIB_GODMODE
private:
#endif
+42 -13
View File
@@ -1,8 +1,8 @@
#include "SX1268.h"
#if !defined(RADIOLIB_EXCLUDE_SX126X)
#if !RADIOLIB_EXCLUDE_SX126X
SX1268::SX1268(Module* mod) : SX126x(mod) {
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) {
@@ -47,25 +47,45 @@ int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
return(state);
}
int16_t SX1268::setFrequency(float freq) {
return(setFrequency(freq, true));
}
/// \todo integers only (all modules - frequency, data rate, bandwidth etc.)
int16_t SX1268::setFrequency(float freq, bool calibrate) {
RADIOLIB_CHECK_RANGE(freq, 410.0, 810.0, RADIOLIB_ERR_INVALID_FREQUENCY);
// calibrate image
// calibrate image rejection
if(calibrate) {
uint8_t data[2];
if(freq > 770.0) {
uint8_t data[2] = { 0, 0 };
// try to match the frequency ranges
int freqBand = (int)freq;
if((freqBand >= 779) && (freqBand <= 787)) {
data[0] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_1;
data[1] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_2;
} else if(freq > 460.0) {
} else if((freqBand >= 470) && (freqBand <= 510)) {
data[0] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_1;
data[1] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_2;
} else {
} else if((freqBand >= 430) && (freqBand <= 440)) {
data[0] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_1;
data[1] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_2;
}
int16_t state = SX126x::calibrateImage(data);
int16_t state;
if(data[0]) {
// matched with predefined ranges, do the calibration
state = SX126x::calibrateImage(data);
} else {
// if nothing matched, try custom calibration - the may or may not work
RADIOLIB_DEBUG_BASIC_PRINTLN("Failed to match predefined frequency range, trying custom");
state = SX126x::calibrateImageRejection(freq - 4.0f, freq + 4.0f);
}
RADIOLIB_ASSERT(state);
}
// set frequency
@@ -73,24 +93,33 @@ int16_t SX1268::setFrequency(float freq, bool calibrate) {
}
int16_t SX1268::setOutputPower(int8_t power) {
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
// check if power value is configurable
int16_t state = checkOutputPower(power, NULL);
RADIOLIB_ASSERT(state);
// get current OCP configuration
uint8_t ocp = 0;
int16_t state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
RADIOLIB_ASSERT(state);
// set PA config
state = SX126x::setPaConfig(0x04, RADIOLIB_SX126X_PA_CONFIG_SX1268);
RADIOLIB_ASSERT(state);
// set output power
/// \todo power ramp time configuration
state = SX126x::setTxParams(power);
// set output power with default 200us ramp
state = SX126x::setTxParams(power, RADIOLIB_SX126X_PA_RAMP_200U);
RADIOLIB_ASSERT(state);
// restore OCP configuration
return(writeRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1));
}
int16_t SX1268::checkOutputPower(int8_t power, int8_t* clipped) {
if(clipped) {
*clipped = RADIOLIB_MAX(-9, RADIOLIB_MIN(22, power));
}
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
return(RADIOLIB_ERR_NONE);
}
#endif
+34 -36
View File
@@ -3,72 +3,60 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX126X)
#if !RADIOLIB_EXCLUDE_SX126X
#include "../../Module.h"
#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"
/*!
\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);
SX1268(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
/*!
\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 2-byte LoRa sync word. Defaults to RADIOLIB_SX126X_SYNC_WORD_PRIVATE (0x12).
\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 tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V.
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
To use XTAL, either set this value to 0, or set SX126x::XTAL to true.
\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.
\parma 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 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.
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
To use XTAL, either set this value to 0, or set SX126x::XTAL to true.
\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);
@@ -77,25 +65,35 @@ 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.
\param calibrate Run image calibration.
\returns \ref status_codes
*/
int16_t setFrequency(float freq, bool calibrate = true);
int16_t setFrequency(float freq) override;
/*!
\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);
/*!
\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);
int16_t setOutputPower(int8_t power) override;
#if !defined(RADIOLIB_GODMODE)
/*!
\brief Check if output power is configurable.
\param power Output power in dBm.
\param clipped Clipped output power value to what is possible within the module's range.
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
#if !RADIOLIB_GODMODE
private:
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,110 @@
/*
Binary in this file originates from https://github.com/Lora-net/sx1302_hal/tree/master
As such, license of the above repository is reproduced here.
Copyright (c) 2019, SEMTECH S.A.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Semtech corporation nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if !defined(_RADIOLIB_SX126X_PATCH_SCAN_H)
#define _RADIOLIB_SX126X_PATCH_SCAN_H
#include "../../../TypeDef.h"
#if !RADIOLIB_EXCLUDE_SX126X
// the following is a binary patch to the SX1262
// this patch is needed to enable spectral scan functionality
const uint32_t sx126x_patch_scan[] RADIOLIB_NONVOLATILE = {
0x337fe1, 0x337fdb, 0x337fd5, 0x337fcf, 0x3a7fc8, 0x3f3fff,
0x0378ff, 0x0379ff, 0x3a7fb7, 0x16a901, 0x16a801, 0x23ffff,
0x0378ff, 0x0379ff, 0x3a7faf, 0x16a901, 0x16a801, 0x23ffff,
0x0378ff, 0x0379ff, 0x3a7f34, 0x16a901, 0x16a801, 0x23ffff,
0x0378ff, 0x0379ff, 0x3a7e80, 0x16a901, 0x16a801, 0x23ffff,
0x0378ff, 0x0379ff, 0x3a7fc3, 0x16a901, 0x16a801, 0x337fc9,
0x0378ff, 0x0379ff, 0x3a7fc0, 0x16a901, 0x16a801, 0x337fc9,
0x0378ff, 0x0379ff, 0x3a7fbd, 0x16a901, 0x16a801, 0x337fc9,
0x0378ff, 0x0379ff, 0x3a7fba, 0x16a901, 0x16a801, 0x337fc9,
0x23ffff, 0x0ea1fc, 0x0ea0df, 0x0eafc9, 0x02cf0e, 0x23ffff,
0x0eacff, 0x0eabff, 0x23ffff, 0x0eacff, 0x0eabff, 0x23ffff,
0x0eacff, 0x0eabff, 0x23ffff, 0x0eacff, 0x0eabff, 0x23ffff,
0x0378ff, 0x0379ff, 0x3a7fc8, 0x0eacfd, 0x0eabff, 0x16a901,
0x16a801, 0x23ffff, 0x0374ff, 0x0375ff, 0x0378ff, 0x0379ff,
0x16affe, 0x0ea5ff, 0x0ea465, 0x1dbb04, 0x0e1bfd, 0x307fa3,
0x1caf00, 0x327fa0, 0x0eacf7, 0x0eabff, 0x337f3a, 0x1cad04,
0x0eacfe, 0x0eabff, 0x0dbfdd, 0x307f97, 0x0dafcc, 0x0defbb,
0x0dbfdd, 0x347f9b, 0x0eecef, 0x0caffc, 0x04ade8, 0x0cbdcd,
0x01bde8, 0x04abe8, 0x0ebbbf, 0x01bbe8, 0x04abe8, 0x0ebbdf,
0x01bbe8, 0x1ca800, 0x0ea9ff, 0x04abe3, 0x0e2b01, 0x01bbe3,
0x04abee, 0x0e2b01, 0x01bbee, 0x1ca202, 0x1ca301, 0x02f300,
0x02f201, 0x0ea064, 0x0ea1f7, 0x18ab00, 0x367f58, 0x0ea041,
0x0ea1f7, 0x18ab00, 0x1c1b03, 0x317f3f, 0x1ea201, 0x1ea300,
0x0cb23f, 0x327f4a, 0x1cab04, 0x0eaefe, 0x0dbfbb, 0x307f6c,
0x0dafee, 0x0dbfbb, 0x347f6f, 0x04abee, 0x0cbbeb, 0x01bbee,
0x0eacff, 0x0eabff, 0x0c1b9f, 0x327f64, 0x0c1c8f, 0x317f5c,
0x3fffff, 0x0d1fcc, 0x0d5fbb, 0x0c1b9f, 0x327f5d, 0x0c1c8f,
0x357f63, 0x0ea064, 0x0ea1f7, 0x18ab00, 0x327f7c, 0x1cad04,
0x0eacfe, 0x0dbfdd, 0x307f51, 0x0dafcc, 0x0dbfdd, 0x347f54,
0x0d8fcb, 0x04acee, 0x0c2bcb, 0x01bbee, 0x0eacfd, 0x0eabff,
0x337f3a, 0x1cad04, 0x0eacfe, 0x0dbfdd, 0x307f43, 0x0dafcc,
0x0dbfdd, 0x347f46, 0x0d8fcb, 0x04acee, 0x0c2bcb, 0x337f6a,
0x0cb23f, 0x367f75, 0x0dbf22, 0x0dff33, 0x337f75, 0x16af02,
0x16a901, 0x16a801, 0x16a501, 0x16a401, 0x23ffff, 0x0374ff,
0x0375ff, 0x0378ff, 0x0379ff, 0x16afe0, 0x0ea5ff, 0x0ea465,
0x1ca802, 0x0ea9ff, 0x0eafff, 0x02ff00, 0x0eaff7, 0x02ff01,
0x0eafef, 0x02ff02, 0x0eafe7, 0x02ff03, 0x0eafdf, 0x02ff04,
0x0eafd7, 0x02ff05, 0x0eafcf, 0x02ff06, 0x0eafc7, 0x02ff07,
0x0eafbf, 0x02ff08, 0x0eafb7, 0x02ff09, 0x0eafaf, 0x02ff0a,
0x0eafa7, 0x02ff0b, 0x0eaf9f, 0x02ff0c, 0x0eaf97, 0x02ff0d,
0x0eaf8f, 0x02ff0e, 0x0eaf87, 0x02ff0f, 0x0eaf7f, 0x02ff10,
0x0eaf77, 0x02ff11, 0x0eaf6f, 0x02ff12, 0x0eaf67, 0x02ff13,
0x0eaf5f, 0x02ff14, 0x0eaf57, 0x02ff15, 0x0eaf4f, 0x02ff16,
0x0eaf47, 0x02ff17, 0x0eaf3f, 0x02ff18, 0x0eaf37, 0x02ff19,
0x0eaf2f, 0x02ff1a, 0x0eaf27, 0x02ff1b, 0x0eaf1f, 0x02ff1c,
0x0eaf17, 0x02ff1d, 0x0eaf0f, 0x02ff1e, 0x0eaf07, 0x02ff1f,
0x04abee, 0x0e2b01, 0x01bbee, 0x0eacff, 0x0eabff, 0x0cafc0,
0x0ec0ff, 0x0cafb1, 0x0ed1fb, 0x0eafff, 0x02cf00, 0x0d1fcc,
0x0d5fbb, 0x0e1bff, 0x327edb, 0x0e1c00, 0x347ee6, 0x0ea2ff,
0x0ea3ff, 0x0ea032, 0x0ea1f8, 0x0eaff0, 0x02cf00, 0x0ea064,
0x0ea1f7, 0x18ad00, 0x1c1300, 0x327ece, 0x1c1201, 0x317e9b,
0x0e1dff, 0x367e9b, 0x0ea041, 0x0ea1f7, 0x18ab00, 0x0eebdf,
0x0cafbc, 0x0eabff, 0x0ccccc, 0x0cdbbb, 0x0cafc0, 0x0ec0ff,
0x0cafb1, 0x0ed1fb, 0x18ab01, 0x0eacff, 0x18ae02, 0x0eadff,
0x0ccecc, 0x0cddbb, 0x0d1fcc, 0x0d5fbb, 0x0cafbe, 0x0eadff,
0x02ce01, 0x02cc02, 0x0d1f22, 0x0d5f33, 0x0ea064, 0x0ea1f7,
0x18ad00, 0x0eacff, 0x0eabff, 0x0c1b9f, 0x327ea9, 0x0c1c8f,
0x317ea1, 0x3fffff, 0x0d1fcc, 0x0d5fbb, 0x0c1b9f, 0x327ea2,
0x0c1c8f, 0x357ea8, 0x1c1300, 0x327e9e, 0x1c1201, 0x317e9b,
0x0e1dff, 0x327ecb, 0x0e1dff, 0x367e90, 0x0ea032, 0x0ea1f8,
0x0eaf00, 0x02cf00, 0x0ea1fb, 0x0ea0ff, 0x0eaf00, 0x02cf00,
0x337e88, 0x0ea032, 0x0ea1f8, 0x0eaf0f, 0x02cf00, 0x0ea1fb,
0x0ea0ff, 0x0eaf0f, 0x02cf00, 0x0eacfd, 0x0eabff, 0x16af20,
0x16a901, 0x16a801, 0x16a501, 0x16a401, 0x23ffff, 0x0eacf7,
0x0eabff, 0x23ffff
};
#endif
#endif
+192 -117
View File
@@ -1,5 +1,6 @@
#include "SX1272.h"
#if !defined(RADIOLIB_EXCLUDE_SX127X)
#include <math.h>
#if !RADIOLIB_EXCLUDE_SX127X
SX1272::SX1272(Module* mod) : SX127x(mod) {
@@ -7,7 +8,8 @@ SX1272::SX1272(Module* mod) : SX127x(mod) {
int16_t SX1272::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
// execute common part
int16_t state = SX127x::begin(RADIOLIB_SX1272_CHIP_VERSION, syncWord, preambleLength);
uint8_t version = RADIOLIB_SX1272_CHIP_VERSION;
int16_t state = SX127x::begin(&version, 1, syncWord, preambleLength);
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
@@ -29,12 +31,17 @@ int16_t SX1272::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
state = setGain(gain);
RADIOLIB_ASSERT(state);
// set publicly accessible settings that are not a part of begin method
state = setCRC(true);
RADIOLIB_ASSERT(state);
return(state);
}
int16_t SX1272::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
// execute common part
int16_t state = SX127x::beginFSK(RADIOLIB_SX1272_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK);
uint8_t version = RADIOLIB_SX1272_CHIP_VERSION;
int16_t state = SX127x::beginFSK(&version, 1, freqDev, rxBw, preambleLength, enableOOK);
RADIOLIB_ASSERT(state);
// configure settings not accessible by API
@@ -45,6 +52,9 @@ int16_t SX1272::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setBitRate(br);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
@@ -56,15 +66,20 @@ int16_t SX1272::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
RADIOLIB_ASSERT(state);
}
// set publicly accessible settings that are not a part of begin method
state = setCRC(true);
RADIOLIB_ASSERT(state);
return(state);
}
void SX1272::reset() {
_mod->pinMode(_mod->getRst(), OUTPUT);
_mod->digitalWrite(_mod->getRst(), HIGH);
_mod->delay(1);
_mod->digitalWrite(_mod->getRst(), LOW);
_mod->delay(5);
Module* mod = this->getMod();
mod->hal->pinMode(mod->getRst(), mod->hal->GpioModeOutput);
mod->hal->digitalWrite(mod->getRst(), mod->hal->GpioLevelHigh);
mod->hal->delay(1);
mod->hal->digitalWrite(mod->getRst(), mod->hal->GpioLevelLow);
mod->hal->delay(5);
}
int16_t SX1272::setFrequency(float freq) {
@@ -73,7 +88,7 @@ int16_t SX1272::setFrequency(float freq) {
// set frequency and if successful, save the new setting
int16_t state = SX127x::setFrequencyRaw(freq);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_freq = freq;
SX127x::frequency = freq;
}
return(state);
}
@@ -87,11 +102,11 @@ int16_t SX1272::setBandwidth(float bw) {
uint8_t newBandwidth;
// check allowed bandwidth values
if(fabs(bw - 125.0) <= 0.001) {
if(fabsf(bw - 125.0) <= 0.001) {
newBandwidth = RADIOLIB_SX1272_BW_125_00_KHZ;
} else if(fabs(bw - 250.0) <= 0.001) {
} else if(fabsf(bw - 250.0) <= 0.001) {
newBandwidth = RADIOLIB_SX1272_BW_250_00_KHZ;
} else if(fabs(bw - 500.0) <= 0.001) {
} else if(fabsf(bw - 500.0) <= 0.001) {
newBandwidth = RADIOLIB_SX1272_BW_500_00_KHZ;
} else {
return(RADIOLIB_ERR_INVALID_BANDWIDTH);
@@ -100,18 +115,16 @@ int16_t SX1272::setBandwidth(float bw) {
// set bandwidth and if successful, save the new setting
int16_t state = SX1272::setBandwidthRaw(newBandwidth);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_bw = bw;
SX127x::bandwidth = bw;
// calculate symbol length and set low data rate optimization, if auto-configuration is enabled
if(_ldroAuto) {
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
RADIOLIB_DEBUG_PRINT("Symbol length: ");
RADIOLIB_DEBUG_PRINT(symbolLength);
RADIOLIB_DEBUG_PRINTLN(" ms");
if(this->ldroAuto) {
float symbolLength = (float)(uint32_t(1) << SX127x::spreadingFactor) / (float)SX127x::bandwidth;
Module* mod = this->getMod();
if(symbolLength >= 16.0) {
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0);
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0);
} else {
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0);
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0);
}
}
}
@@ -156,18 +169,16 @@ int16_t SX1272::setSpreadingFactor(uint8_t sf) {
// set spreading factor and if successful, save the new setting
int16_t state = SX1272::setSpreadingFactorRaw(newSpreadingFactor);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_sf = sf;
SX127x::spreadingFactor = sf;
// calculate symbol length and set low data rate optimization, if auto-configuration is enabled
if(_ldroAuto) {
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
RADIOLIB_DEBUG_PRINT("Symbol length: ");
RADIOLIB_DEBUG_PRINT(symbolLength);
RADIOLIB_DEBUG_PRINTLN(" ms");
if(this->ldroAuto) {
float symbolLength = (float)(uint32_t(1) << SX127x::spreadingFactor) / (float)SX127x::bandwidth;
Module* mod = this->getMod();
if(symbolLength >= 16.0) {
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0);
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0);
} else {
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0);
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0);
}
}
}
@@ -203,40 +214,98 @@ int16_t SX1272::setCodingRate(uint8_t cr) {
// set coding rate and if successful, save the new setting
int16_t state = SX1272::setCodingRateRaw(newCodingRate);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_cr = cr;
SX127x::codingRate = cr;
}
return(state);
}
int16_t SX1272::setOutputPower(int8_t power, bool useRfo) {
// check allowed power range
if(useRfo) {
RADIOLIB_CHECK_RANGE(power, -1, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
} else {
RADIOLIB_CHECK_RANGE(power, 2, 20, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
int16_t SX1272::setBitRate(float br) {
return(SX127x::setBitRateCommon(br, RADIOLIB_SX1272_REG_BIT_RATE_FRAC));
}
int16_t SX1272::setDataRate(DataRate_t dr) {
int16_t state = RADIOLIB_ERR_UNKNOWN;
// select interpretation based on active modem
uint8_t modem = this->getActiveModem();
if(modem == RADIOLIB_SX127X_FSK_OOK) {
// set the bit rate
state = this->setBitRate(dr.fsk.bitRate);
RADIOLIB_ASSERT(state);
// set the frequency deviation
state = this->setFrequencyDeviation(dr.fsk.freqDev);
} else if(modem == RADIOLIB_SX127X_LORA) {
// set the spreading factor
state = this->setSpreadingFactor(dr.lora.spreadingFactor);
RADIOLIB_ASSERT(state);
// set the bandwidth
state = this->setBandwidth(dr.lora.bandwidth);
RADIOLIB_ASSERT(state);
// set the coding rate
state = this->setCodingRate(dr.lora.codingRate);
}
return(state);
}
int16_t SX1272::checkDataRate(DataRate_t dr) {
int16_t state = RADIOLIB_ERR_UNKNOWN;
// select interpretation based on active modem
int16_t modem = getActiveModem();
if(modem == RADIOLIB_SX127X_FSK_OOK) {
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
if(!((dr.fsk.freqDev + dr.fsk.bitRate/2.0 <= 250.0) && (dr.fsk.freqDev <= 200.0))) {
return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
}
return(RADIOLIB_ERR_NONE);
} else if(modem == RADIOLIB_SX127X_LORA) {
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 12, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 100.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
return(RADIOLIB_ERR_NONE);
}
return(state);
}
int16_t SX1272::setOutputPower(int8_t power) {
return(this->setOutputPower(power, false));
}
int16_t SX1272::setOutputPower(int8_t power, bool useRfo) {
// check if power value is configurable
int16_t state = checkOutputPower(power, NULL, useRfo);
RADIOLIB_ASSERT(state);
// set mode to standby
int16_t state = SX127x::standby();
state = SX127x::standby();
Module* mod = this->getMod();
if(useRfo) {
// RFO output
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_RFO, 7, 7);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power + 1), 3, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_RFO, 7, 7);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power + 1), 3, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
} else {
if(power <= 17) {
// power is 2 - 17 dBm, enable PA1 + PA2 on PA_BOOST
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power - 2), 3, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power - 2), 3, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
} else {
// power is 18 - 20 dBm, enable PA1 + PA2 on PA_BOOST and enable high power control
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power - 5), 3, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_ON, 2, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power - 5), 3, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_ON, 2, 0);
}
@@ -245,6 +314,26 @@ int16_t SX1272::setOutputPower(int8_t power, bool useRfo) {
return(state);
}
int16_t SX1272::checkOutputPower(int8_t power, int8_t* clipped) {
return(checkOutputPower(power, clipped, false));
}
int16_t SX1272::checkOutputPower(int8_t power, int8_t* clipped, bool useRfo) {
// check allowed power range
if(useRfo) {
if(clipped) {
*clipped = RADIOLIB_MAX(-1, RADIOLIB_MIN(14, power));
}
RADIOLIB_CHECK_RANGE(power, -1, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
} else {
if(clipped) {
*clipped = RADIOLIB_MAX(2, RADIOLIB_MIN(20, power));
}
RADIOLIB_CHECK_RANGE(power, 2, 20, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
}
return(RADIOLIB_ERR_NONE);
}
int16_t SX1272::setGain(uint8_t gain) {
// check allowed range
if(gain > 6) {
@@ -253,27 +342,28 @@ int16_t SX1272::setGain(uint8_t gain) {
// set mode to standby
int16_t state = SX127x::standby();
Module* mod = this->getMod();
// get modem
int16_t modem = getActiveModem();
if(modem == RADIOLIB_SX127X_LORA){
if(modem == RADIOLIB_SX127X_LORA) {
// set gain
if(gain == 0) {
// gain set to 0, enable AGC loop
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_AGC_AUTO_ON, 2, 2);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_AGC_AUTO_ON, 2, 2);
} else {
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_AGC_AUTO_OFF, 2, 2);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_AGC_AUTO_OFF, 2, 2);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
}
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
// set gain
if(gain == 0) {
// gain set to 0, enable AGC loop
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3);
} else {
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
}
}
@@ -288,7 +378,7 @@ int16_t SX1272::setDataShaping(uint8_t sh) {
}
// check modulation
if(SX127x::_ook) {
if(SX127x::ookEnabled) {
return(RADIOLIB_ERR_INVALID_MODULATION);
}
@@ -297,15 +387,16 @@ int16_t SX1272::setDataShaping(uint8_t sh) {
RADIOLIB_ASSERT(state);
// set data shaping
Module* mod = this->getMod();
switch(sh) {
case RADIOLIB_SHAPING_NONE:
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_NO_SHAPING, 4, 3));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_NO_SHAPING, 4, 3));
case RADIOLIB_SHAPING_0_3:
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_0_3, 4, 3));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_0_3, 4, 3));
case RADIOLIB_SHAPING_0_5:
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_0_5, 4, 3));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_0_5, 4, 3));
case RADIOLIB_SHAPING_1_0:
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_1_0, 4, 3));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_1_0, 4, 3));
default:
return(RADIOLIB_ERR_INVALID_DATA_SHAPING);
}
@@ -318,7 +409,7 @@ int16_t SX1272::setDataShapingOOK(uint8_t sh) {
}
// check modulation
if(!SX127x::_ook) {
if(!SX127x::ookEnabled) {
return(RADIOLIB_ERR_INVALID_MODULATION);
}
@@ -326,15 +417,16 @@ int16_t SX1272::setDataShapingOOK(uint8_t sh) {
int16_t state = SX127x::standby();
// set data shaping
Module* mod = this->getMod();
switch(sh) {
case 0:
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_NO_SHAPING, 4, 3);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_NO_SHAPING, 4, 3);
break;
case 1:
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_OOK_FILTER_BR, 4, 3);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_OOK_FILTER_BR, 4, 3);
break;
case 2:
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_OOK_FILTER_2BR, 4, 3);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_OOK_FILTER_2BR, 4, 3);
break;
default:
state = RADIOLIB_ERR_INVALID_DATA_SHAPING;
@@ -344,63 +436,39 @@ int16_t SX1272::setDataShapingOOK(uint8_t sh) {
return(state);
}
float SX1272::getRSSI(bool skipReceive) {
if(getActiveModem() == RADIOLIB_SX127X_LORA) {
// RSSI calculation uses different constant for low-frequency and high-frequency ports
float lastPacketRSSI = -139 + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PKT_RSSI_VALUE);
float SX1272::getRSSI() {
return(SX1272::getRSSI(true, false));
}
// spread-spectrum modulation signal can be received below noise floor
// check last packet SNR and if it's less than 0, add it to reported RSSI to get the correct value
float lastPacketSNR = SX127x::getSNR();
if(lastPacketSNR < 0.0) {
lastPacketRSSI += lastPacketSNR;
}
return(lastPacketRSSI);
} else {
// enable listen mode
if(!skipReceive) {
startReceive();
}
// read the value for FSK
float rssi = (float)_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE_FSK) / -2.0;
// set mode back to standby
if(!skipReceive) {
standby();
}
// return the value
return(rssi);
}
float SX1272::getRSSI(bool packet, bool skipReceive) {
return(SX127x::getRSSI(packet, skipReceive, -139));
}
int16_t SX1272::setCRC(bool enable, bool mode) {
Module* mod = this->getMod();
if(getActiveModem() == RADIOLIB_SX127X_LORA) {
// set LoRa CRC
SX127x::_crcEnabled = enable;
SX127x::crcEnabled = enable;
if(enable) {
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_RX_CRC_MODE_ON, 2, 2));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_RX_CRC_MODE_ON, 1, 1));
} else {
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_RX_CRC_MODE_OFF, 2, 2));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_RX_CRC_MODE_OFF, 1, 1));
}
} else {
// set FSK CRC
int16_t state = RADIOLIB_ERR_NONE;
if(enable) {
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_ON, 4, 4);
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_ON, 4, 4);
} else {
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_OFF, 4, 4);
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_OFF, 4, 4);
}
RADIOLIB_ASSERT(state);
// set FSK CRC mode
if(mode) {
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM, 0, 0));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM, 0, 0));
} else {
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT, 0, 0));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT, 0, 0));
}
}
}
@@ -410,11 +478,12 @@ int16_t SX1272::forceLDRO(bool enable) {
return(RADIOLIB_ERR_WRONG_MODEM);
}
_ldroAuto = false;
this->ldroAuto = false;
Module* mod = this->getMod();
if(enable) {
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0));
} else {
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0));
}
}
@@ -423,7 +492,7 @@ int16_t SX1272::autoLDRO() {
return(RADIOLIB_ERR_WRONG_MODEM);
}
_ldroAuto = true;
this->ldroAuto = true;
return(RADIOLIB_ERR_NONE);
}
@@ -440,7 +509,8 @@ int16_t SX1272::setBandwidthRaw(uint8_t newBandwidth) {
int16_t state = SX127x::standby();
// write register
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newBandwidth, 7, 6);
Module* mod = this->getMod();
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newBandwidth, 7, 6);
return(state);
}
@@ -449,16 +519,17 @@ int16_t SX1272::setSpreadingFactorRaw(uint8_t newSpreadingFactor) {
int16_t state = SX127x::standby();
// write registers
Module* mod = this->getMod();
if(newSpreadingFactor == RADIOLIB_SX127X_SF_6) {
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_HEADER_IMPL_MODE | (SX127x::_crcEnabled ? RADIOLIB_SX1272_RX_CRC_MODE_ON : RADIOLIB_SX1272_RX_CRC_MODE_OFF), 2, 1);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_HEADER_IMPL_MODE | (SX127x::crcEnabled ? RADIOLIB_SX1272_RX_CRC_MODE_ON : RADIOLIB_SX1272_RX_CRC_MODE_OFF), 2, 1);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6);
} else {
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_HEADER_EXPL_MODE | (SX127x::_crcEnabled ? RADIOLIB_SX1272_RX_CRC_MODE_ON : RADIOLIB_SX1272_RX_CRC_MODE_OFF), 2, 1);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_HEADER_EXPL_MODE | (SX127x::crcEnabled ? RADIOLIB_SX1272_RX_CRC_MODE_ON : RADIOLIB_SX1272_RX_CRC_MODE_OFF), 2, 1);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12);
}
return(state);
}
@@ -468,7 +539,8 @@ int16_t SX1272::setCodingRateRaw(uint8_t newCodingRate) {
int16_t state = SX127x::standby();
// write register
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newCodingRate, 5, 3);
Module* mod = this->getMod();
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newCodingRate, 5, 3);
return(state);
}
@@ -479,15 +551,16 @@ int16_t SX1272::setHeaderType(uint8_t headerType, size_t len) {
}
// set requested packet mode
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 2, 2);
Module* mod = this->getMod();
int16_t state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 2, 2);
RADIOLIB_ASSERT(state);
// set length to register
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len);
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len);
RADIOLIB_ASSERT(state);
// update cached value
_packetLength = len;
SX127x::packetLength = len;
return(state);
}
@@ -498,7 +571,8 @@ int16_t SX1272::configFSK() {
RADIOLIB_ASSERT(state);
// set fast PLL hop
state = _mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PLL_HOP, RADIOLIB_SX127X_FAST_HOP_ON, 7, 7);
Module* mod = this->getMod();
state = mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PLL_HOP, RADIOLIB_SX127X_FAST_HOP_ON, 7, 7);
return(state);
}
@@ -507,7 +581,8 @@ void SX1272::errataFix(bool rx) {
// mitigation of receiver spurious response
// see SX1272/73 Errata, section 2.2 for details
_mod->SPIsetRegValue(0x31, 0b10000000, 7, 7);
Module* mod = this->getMod();
mod->SPIsetRegValue(0x31, 0b10000000, 7, 7);
}
#endif
+127 -118
View File
@@ -3,92 +3,91 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX127X)
#if !RADIOLIB_EXCLUDE_SX127X
#include "../../Module.h"
#include "SX127x.h"
// SX1272 specific register map
#define RADIOLIB_SX1272_REG_AGC_REF 0x43
#define RADIOLIB_SX1272_REG_AGC_THRESH_1 0x44
#define RADIOLIB_SX1272_REG_AGC_THRESH_2 0x45
#define RADIOLIB_SX1272_REG_AGC_THRESH_3 0x46
#define RADIOLIB_SX1272_REG_PLL_HOP 0x4B
#define RADIOLIB_SX1272_REG_TCXO 0x58
#define RADIOLIB_SX1272_REG_PA_DAC 0x5A
#define RADIOLIB_SX1272_REG_PLL 0x5C
#define RADIOLIB_SX1272_REG_PLL_LOW_PN 0x5E
#define RADIOLIB_SX1272_REG_FORMER_TEMP 0x6C
#define RADIOLIB_SX1272_REG_BIT_RATE_FRAC 0x70
#define RADIOLIB_SX1272_REG_AGC_REF 0x43
#define RADIOLIB_SX1272_REG_AGC_THRESH_1 0x44
#define RADIOLIB_SX1272_REG_AGC_THRESH_2 0x45
#define RADIOLIB_SX1272_REG_AGC_THRESH_3 0x46
#define RADIOLIB_SX1272_REG_PLL_HOP 0x4B
#define RADIOLIB_SX1272_REG_TCXO 0x58
#define RADIOLIB_SX1272_REG_PA_DAC 0x5A
#define RADIOLIB_SX1272_REG_PLL 0x5C
#define RADIOLIB_SX1272_REG_PLL_LOW_PN 0x5E
#define RADIOLIB_SX1272_REG_FORMER_TEMP 0x6C
#define RADIOLIB_SX1272_REG_BIT_RATE_FRAC 0x70
// SX1272 LoRa modem settings
// RADIOLIB_SX1272_REG_FRF_MSB + REG_FRF_MID + REG_FRF_LSB
#define RADIOLIB_SX1272_FRF_MSB 0xE4 // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19
#define RADIOLIB_SX1272_FRF_MID 0xC0 // 7 0 where F(XOSC) = 32 MHz
#define RADIOLIB_SX1272_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers
#define RADIOLIB_SX1272_FRF_MSB 0xE4 // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19
#define RADIOLIB_SX1272_FRF_MID 0xC0 // 7 0 where F(XOSC) = 32 MHz
#define RADIOLIB_SX1272_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers
// RADIOLIB_SX127X_REG_MODEM_CONFIG_1
#define RADIOLIB_SX1272_BW_125_00_KHZ 0b00000000 // 7 6 bandwidth: 125 kHz
#define RADIOLIB_SX1272_BW_250_00_KHZ 0b01000000 // 7 6 250 kHz
#define RADIOLIB_SX1272_BW_500_00_KHZ 0b10000000 // 7 6 500 kHz
#define RADIOLIB_SX1272_CR_4_5 0b00001000 // 5 3 error coding rate: 4/5
#define RADIOLIB_SX1272_CR_4_6 0b00010000 // 5 3 4/6
#define RADIOLIB_SX1272_CR_4_7 0b00011000 // 5 3 4/7
#define RADIOLIB_SX1272_CR_4_8 0b00100000 // 5 3 4/8
#define RADIOLIB_SX1272_HEADER_EXPL_MODE 0b00000000 // 2 2 explicit header mode
#define RADIOLIB_SX1272_HEADER_IMPL_MODE 0b00000100 // 2 2 implicit header mode
#define RADIOLIB_SX1272_RX_CRC_MODE_OFF 0b00000000 // 1 1 CRC disabled
#define RADIOLIB_SX1272_RX_CRC_MODE_ON 0b00000010 // 1 1 CRC enabled
#define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF 0b00000000 // 0 0 low data rate optimization disabled
#define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON 0b00000001 // 0 0 low data rate optimization enabled, mandatory for SF 11 and 12 with BW 125 kHz
#define RADIOLIB_SX1272_BW_125_00_KHZ 0b00000000 // 7 6 bandwidth: 125 kHz
#define RADIOLIB_SX1272_BW_250_00_KHZ 0b01000000 // 7 6 250 kHz
#define RADIOLIB_SX1272_BW_500_00_KHZ 0b10000000 // 7 6 500 kHz
#define RADIOLIB_SX1272_CR_4_5 0b00001000 // 5 3 error coding rate: 4/5
#define RADIOLIB_SX1272_CR_4_6 0b00010000 // 5 3 4/6
#define RADIOLIB_SX1272_CR_4_7 0b00011000 // 5 3 4/7
#define RADIOLIB_SX1272_CR_4_8 0b00100000 // 5 3 4/8
#define RADIOLIB_SX1272_HEADER_EXPL_MODE 0b00000000 // 2 2 explicit header mode
#define RADIOLIB_SX1272_HEADER_IMPL_MODE 0b00000100 // 2 2 implicit header mode
#define RADIOLIB_SX1272_RX_CRC_MODE_OFF 0b00000000 // 1 1 CRC disabled
#define RADIOLIB_SX1272_RX_CRC_MODE_ON 0b00000010 // 1 1 CRC enabled
#define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF 0b00000000 // 0 0 low data rate optimization disabled
#define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON 0b00000001 // 0 0 low data rate optimization enabled, mandatory for SF 11 and 12 with BW 125 kHz
// RADIOLIB_SX127X_REG_MODEM_CONFIG_2
#define RADIOLIB_SX1272_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA
#define RADIOLIB_SX1272_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop
#define RADIOLIB_SX1272_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA
#define RADIOLIB_SX1272_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop
// RADIOLIB_SX127X_REG_VERSION
#define RADIOLIB_SX1272_CHIP_VERSION 0x22
#define RADIOLIB_SX1272_CHIP_VERSION 0x22
// SX1272 FSK modem settings
// RADIOLIB_SX127X_REG_OP_MODE
#define RADIOLIB_SX1272_NO_SHAPING 0b00000000 // 4 3 data shaping: no shaping (default)
#define RADIOLIB_SX1272_FSK_GAUSSIAN_1_0 0b00001000 // 4 3 FSK modulation Gaussian filter, BT = 1.0
#define RADIOLIB_SX1272_FSK_GAUSSIAN_0_5 0b00010000 // 4 3 FSK modulation Gaussian filter, BT = 0.5
#define RADIOLIB_SX1272_FSK_GAUSSIAN_0_3 0b00011000 // 4 3 FSK modulation Gaussian filter, BT = 0.3
#define RADIOLIB_SX1272_OOK_FILTER_BR 0b00001000 // 4 3 OOK modulation filter, f_cutoff = BR
#define RADIOLIB_SX1272_OOK_FILTER_2BR 0b00010000 // 4 3 OOK modulation filter, f_cutoff = 2*BR
#define RADIOLIB_SX1272_NO_SHAPING 0b00000000 // 4 3 data shaping: no shaping (default)
#define RADIOLIB_SX1272_FSK_GAUSSIAN_1_0 0b00001000 // 4 3 FSK modulation Gaussian filter, BT = 1.0
#define RADIOLIB_SX1272_FSK_GAUSSIAN_0_5 0b00010000 // 4 3 FSK modulation Gaussian filter, BT = 0.5
#define RADIOLIB_SX1272_FSK_GAUSSIAN_0_3 0b00011000 // 4 3 FSK modulation Gaussian filter, BT = 0.3
#define RADIOLIB_SX1272_OOK_FILTER_BR 0b00001000 // 4 3 OOK modulation filter, f_cutoff = BR
#define RADIOLIB_SX1272_OOK_FILTER_2BR 0b00010000 // 4 3 OOK modulation filter, f_cutoff = 2*BR
// RADIOLIB_SX127X_REG_PA_RAMP
#define RADIOLIB_SX1272_LOW_PN_TX_PLL_OFF 0b00010000 // 4 4 use standard PLL in transmit mode (default)
#define RADIOLIB_SX1272_LOW_PN_TX_PLL_ON 0b00000000 // 4 4 use lower phase noise PLL in transmit mode
#define RADIOLIB_SX1272_LOW_PN_TX_PLL_OFF 0b00010000 // 4 4 use standard PLL in transmit mode (default)
#define RADIOLIB_SX1272_LOW_PN_TX_PLL_ON 0b00000000 // 4 4 use lower phase noise PLL in transmit mode
// RADIOLIB_SX127X_REG_SYNC_CONFIG
#define RADIOLIB_SX1272_FIFO_FILL_CONDITION_SYNC_ADDRESS 0b00000000 // 3 3 FIFO will be filled when sync address interrupt occurs (default)
#define RADIOLIB_SX1272_FIFO_FILL_CONDITION_ALWAYS 0b00001000 // 3 3 FIFO will be filled as long as this bit is set
#define RADIOLIB_SX1272_FIFO_FILL_CONDITION_SYNC_ADDRESS 0b00000000 // 3 3 FIFO will be filled when sync address interrupt occurs (default)
#define RADIOLIB_SX1272_FIFO_FILL_CONDITION_ALWAYS 0b00001000 // 3 3 FIFO will be filled as long as this bit is set
// RADIOLIB_SX1272_REG_AGC_REF
#define RADIOLIB_SX1272_AGC_REFERENCE_LEVEL 0x13 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm]
#define RADIOLIB_SX1272_AGC_REFERENCE_LEVEL 0x13 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm]
// RADIOLIB_SX1272_REG_AGC_THRESH_1
#define RADIOLIB_SX1272_AGC_STEP_1 0x0E // 4 0 1st AGC threshold
#define RADIOLIB_SX1272_AGC_STEP_1 0x0E // 4 0 1st AGC threshold
// RADIOLIB_SX1272_REG_AGC_THRESH_2
#define RADIOLIB_SX1272_AGC_STEP_2 0x50 // 7 4 2nd AGC threshold
#define RADIOLIB_SX1272_AGC_STEP_3 0x0B // 4 0 3rd AGC threshold
#define RADIOLIB_SX1272_AGC_STEP_2 0x50 // 7 4 2nd AGC threshold
#define RADIOLIB_SX1272_AGC_STEP_3 0x0B // 4 0 3rd AGC threshold
// RADIOLIB_SX1272_REG_AGC_THRESH_3
#define RADIOLIB_SX1272_AGC_STEP_4 0xD0 // 7 4 4th AGC threshold
#define RADIOLIB_SX1272_AGC_STEP_5 0x0B // 4 0 5th AGC threshold
#define RADIOLIB_SX1272_AGC_STEP_4 0xD0 // 7 4 4th AGC threshold
#define RADIOLIB_SX1272_AGC_STEP_5 0x0B // 4 0 5th AGC threshold
// RADIOLIB_SX1272_REG_PLL_LOW_PN
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_75_KHZ 0b00000000 // 7 6 low phase noise PLL bandwidth: 75 kHz
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_150_KHZ 0b01000000 // 7 6 150 kHz
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_225_KHZ 0b10000000 // 7 6 225 kHz
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_300_KHZ 0b11000000 // 7 6 300 kHz (default)
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_75_KHZ 0b00000000 // 7 6 low phase noise PLL bandwidth: 75 kHz
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_150_KHZ 0b01000000 // 7 6 150 kHz
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_225_KHZ 0b10000000 // 7 6 225 kHz
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_300_KHZ 0b11000000 // 7 6 300 kHz (default)
/*!
\class SX1272
\brief Derived class for %SX1272 modules. Also used as base class for SX1273.
Both modules use the same basic hardware and only differ in parameter ranges.
*/
@@ -99,57 +98,38 @@ class SX1272: public SX127x {
/*!
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/
SX1272(Module* mod);
SX1272(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
/*!
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz.
\param bw %LoRa link bandwidth in kHz. Allowed values are 125, 250 and 500 kHz.
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
\param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA.
Set to 0 to disable OCP (not recommended).
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
Allowed values range from 6 to 65535.
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
Set to 0 to enable automatic gain control (recommended).
\returns \ref status_codes
*/
int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
/*!
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz.
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of FSK preamble in bits.
\param enableOOK Use OOK modulation instead of FSK.
\returns \ref status_codes
*/
int16_t beginFSK(float freq = 915.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
@@ -163,57 +143,91 @@ class SX1272: public SX127x {
/*!
\brief Sets carrier frequency. Allowed values range from 860.0 MHz to 1020.0 MHz.
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq);
int16_t setFrequency(float freq) override;
/*!
\brief Sets %LoRa link bandwidth. Allowed values are 125, 250 and 500 kHz. Only available in %LoRa mode.
\param bw %LoRa link bandwidth to be set in kHz.
\returns \ref status_codes
*/
int16_t setBandwidth(float bw);
/*!
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 12. Only available in %LoRa mode.
\param sf %LoRa link spreading factor to be set.
\returns \ref status_codes
*/
int16_t setSpreadingFactor(uint8_t sf);
/*!
\brief Sets %LoRa link coding rate denominator. Allowed values range from 5 to 8. Only available in %LoRa mode.
\param cr %LoRa link coding rate denominator to be set.
\returns \ref status_codes
*/
int16_t setCodingRate(uint8_t cr);
/*!
\brief Sets transmission output power. Allowed values range from -1 to 14 dBm (RFO pin) or +2 to +20 dBm (PA_BOOST pin).
\param power Transmission output power in dBm.
\param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output. Defaults to PA_BOOST.
\brief Sets FSK bit rate. Allowed values range from 0.5 to 300 kbps. Only available in FSK mode.
\param br Bit rate to be set (in kbps).
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power, bool useRfo = false);
int16_t setBitRate(float br) override;
/*!
\brief Set data.
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
\returns \ref status_codes
*/
int16_t setDataRate(DataRate_t dr) override;
/*!
\brief Check the data rate can be configured by this module.
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
\returns \ref status_codes
*/
int16_t checkDataRate(DataRate_t dr) override;
/*!
\brief Sets transmission output power. Allowed values range from -1 to 14 dBm (RFO pin) or +2 to +20 dBm (PA_BOOST pin).
High power +20 dBm operation is also supported, on the PA_BOOST pin. Defaults to PA_BOOST.
\param power Transmission output power in dBm.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power) override;
/*!
\brief Sets transmission output power. Allowed values range from -1 to 14 dBm (RFO pin) or +2 to +20 dBm (PA_BOOST pin).
\param power Transmission output power in dBm.
\param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power, bool useRfo);
/*!
\brief Check if output power is configurable.
This method is needed for compatibility with PhysicalLayer::checkOutputPower.
\param power Output power in dBm, assumes PA_BOOST pin.
\param clipped Clipped output power value to what is possible within the module's range.
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
/*!
\brief Check if output power is configurable.
\param power Output power in dBm.
\param clipped Clipped output power value to what is possible within the module's range.
\param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output.
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t power, int8_t* clipped, bool useRfo);
/*!
\brief Sets gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
Set to 0 to enable automatic gain control (recommended). Only available in %LoRa mode.
Set to 0 to enable automatic gain control (recommended).
\param gain Gain of receiver LNA (low-noise amplifier) to be set.
\returns \ref status_codes
*/
int16_t setGain(uint8_t gain);
@@ -221,9 +235,7 @@ class SX1272: public SX127x {
/*!
\brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. Only available in FSK mode with FSK modulation.
Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping.
\param sh Gaussian shaping bandwidth-time product that will be used for data shaping
\returns \ref status_codes
*/
int16_t setDataShaping(uint8_t sh) override;
@@ -232,29 +244,32 @@ class SX1272: public SX127x {
\brief Sets filter cutoff frequency that will be used for data shaping.
Allowed values are 1 for frequency equal to bit rate and 2 for frequency equal to 2x bit rate. Set to 0 to disable data shaping.
Only available in FSK mode with OOK modulation.
\param sh Cutoff frequency that will be used for data shaping
\returns \ref status_codes
*/
int16_t setDataShapingOOK(uint8_t sh);
/*!
\brief Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem.
\param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FKS/OOK mode.
\returns Last packet RSSI for LoRa modem, or current RSSI level for FSK modem.
\brief Gets recorded signal strength indicator.
Overload with packet mode enabled for PhysicalLayer compatibility.
\returns RSSI value in dBm.
*/
float getRSSI(bool skipReceive = false);
float getRSSI() override;
/*!
\brief Gets recorded signal strength indicator.
\param packet Whether to read last packet RSSI, or the current value. LoRa mode only, ignored for FSK.
\param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FSK/OOK mode.
\returns RSSI value in dBm.
*/
float getRSSI(bool packet, bool skipReceive = false);
/*!
\brief Enables/disables CRC check of received packets.
\param enable Enable (true) or disable (false) CRC.
\param mode Set CRC mode to RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT for CCITT, polynomial X16 + X12 + X5 + 1 (false) or RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM for IBM, polynomial X16 + X15 + X2 + 1 (true). Only valid in FSK mode.
\param mode Set CRC mode to RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT for CCITT,
polynomial X16 + X12 + X5 + 1 (false) or RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM for IBM,
polynomial X16 + X15 + X2 + 1 (true). Only valid in FSK mode.
\returns \ref status_codes
*/
int16_t setCRC(bool enable, bool mode = false);
@@ -262,9 +277,7 @@ class SX1272: public SX127x {
/*!
\brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method, LDRO will always be set to
the provided value, regardless of symbol length. To re-enable automatic LDRO configuration, call SX1278::autoLDRO()
\param enable Force LDRO to be always enabled (true) or disabled (false).
\returns \ref status_codes
*/
int16_t forceLDRO(bool enable);
@@ -272,28 +285,24 @@ class SX1272: public SX127x {
/*!
\brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method, LDRO will be enabled automatically
when symbol length exceeds 16 ms.
\returns \ref status_codes
*/
int16_t autoLDRO();
/*!
\brief Set implicit header mode for future reception/transmission. Required for spreading factor 6.
\brief Set implicit header mode for future reception/transmission. Required for spreading factor 6.
\param len Payload length in bytes.
\returns \ref status_codes
*/
int16_t implicitHeader(size_t len);
/*!
\brief Set explicit header mode for future reception/transmission.
\returns \ref status_codes
*/
int16_t explicitHeader();
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
protected:
#endif
int16_t setBandwidthRaw(uint8_t newBandwidth);
@@ -302,13 +311,13 @@ class SX1272: public SX127x {
int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);
int16_t configFSK();
void errataFix(bool rx);
void errataFix(bool rx) override;
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
private:
#endif
bool _ldroAuto = true;
bool _ldroEnabled = false;
bool ldroAuto = true;
bool ldroEnabled = false;
};
+56 -3
View File
@@ -1,5 +1,5 @@
#include "SX1273.h"
#if !defined(RADIOLIB_EXCLUDE_SX127X)
#if !RADIOLIB_EXCLUDE_SX127X
SX1273::SX1273(Module* mod) : SX1272(mod) {
@@ -7,7 +7,8 @@ SX1273::SX1273(Module* mod) : SX1272(mod) {
int16_t SX1273::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
// execute common part
int16_t state = SX127x::begin(RADIOLIB_SX1272_CHIP_VERSION, syncWord, preambleLength);
uint8_t version = RADIOLIB_SX1272_CHIP_VERSION;
int16_t state = SX127x::begin(&version, 1, syncWord, preambleLength);
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
@@ -29,6 +30,10 @@ int16_t SX1273::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
state = setGain(gain);
RADIOLIB_ASSERT(state);
// set publicly accessible settings that are not a part of begin method
state = setCRC(true);
RADIOLIB_ASSERT(state);
return(state);
}
@@ -56,7 +61,55 @@ int16_t SX1273::setSpreadingFactor(uint8_t sf) {
// set spreading factor and if successful, save the new setting
int16_t state = setSpreadingFactorRaw(newSpreadingFactor);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_sf = sf;
SX127x::spreadingFactor = sf;
}
return(state);
}
int16_t SX1273::setDataRate(DataRate_t dr) {
int16_t state = RADIOLIB_ERR_UNKNOWN;
// select interpretation based on active modem
uint8_t modem = this->getActiveModem();
if(modem == RADIOLIB_SX127X_FSK_OOK) {
// set the bit rate
state = this->setBitRate(dr.fsk.bitRate);
RADIOLIB_ASSERT(state);
// set the frequency deviation
state = this->setFrequencyDeviation(dr.fsk.freqDev);
} else if(modem == RADIOLIB_SX127X_LORA) {
// set the spreading factor
state = this->setSpreadingFactor(dr.lora.spreadingFactor);
RADIOLIB_ASSERT(state);
// set the bandwidth
state = this->setBandwidth(dr.lora.bandwidth);
}
return(state);
}
int16_t SX1273::checkDataRate(DataRate_t dr) {
int16_t state = RADIOLIB_ERR_UNKNOWN;
// select interpretation based on active modem
int16_t modem = getActiveModem();
if(modem == RADIOLIB_SX127X_FSK_OOK) {
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
if(!((dr.fsk.freqDev + dr.fsk.bitRate/2.0 <= 250.0) && (dr.fsk.freqDev <= 200.0))) {
return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
}
return(RADIOLIB_ERR_NONE);
} else if(modem == RADIOLIB_SX127X_LORA) {
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 9, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 100.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
return(RADIOLIB_ERR_NONE);
}
return(state);
+17 -16
View File
@@ -3,13 +3,12 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX127X)
#if !RADIOLIB_EXCLUDE_SX127X
#include "SX1272.h"
/*!
\class SX1273
\brief Derived class for %SX1273 modules. Overrides some methods from SX1272 due to different parameter ranges.
*/
class SX1273: public SX1272 {
@@ -19,34 +18,24 @@ class SX1273: public SX1272 {
/*!
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/
SX1273(Module* mod);
SX1273(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
/*!
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz.
\param bw %LoRa link bandwidth in kHz. Allowed values are 125, 250 and 500 kHz.
\param sf %LoRa link spreading factor. Allowed values range from 6 to 9.
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
Allowed values range from 6 to 65535.
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
Set to 0 to enable automatic gain control (recommended).
\returns \ref status_codes
*/
int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
@@ -55,14 +44,26 @@ class SX1273: public SX1272 {
/*!
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 9. Only available in %LoRa mode.
\param sf %LoRa link spreading factor to be set.
\returns \ref status_codes
*/
int16_t setSpreadingFactor(uint8_t sf);
#if !defined(RADIOLIB_GODMODE)
/*!
\brief Set data.
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
\returns \ref status_codes
*/
int16_t setDataRate(DataRate_t dr) override;
/*!
\brief Check the data rate can be configured by this module.
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
\returns \ref status_codes
*/
int16_t checkDataRate(DataRate_t dr) override;
#if !RADIOLIB_GODMODE
private:
#endif
+13 -4
View File
@@ -1,5 +1,5 @@
#include "SX1276.h"
#if !defined(RADIOLIB_EXCLUDE_SX127X)
#if !RADIOLIB_EXCLUDE_SX127X
SX1276::SX1276(Module* mod) : SX1278(mod) {
@@ -7,7 +7,8 @@ SX1276::SX1276(Module* mod) : SX1278(mod) {
int16_t SX1276::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
// execute common part
int16_t state = SX127x::begin(RADIOLIB_SX1278_CHIP_VERSION, syncWord, preambleLength);
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
int16_t state = SX127x::begin(versions, 3, syncWord, preambleLength);
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
@@ -29,12 +30,17 @@ int16_t SX1276::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
state = setGain(gain);
RADIOLIB_ASSERT(state);
// set publicly accessible settings that are not a part of begin method
state = setCRC(true);
RADIOLIB_ASSERT(state);
return(state);
}
int16_t SX1276::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
// execute common part
int16_t state = SX127x::beginFSK(RADIOLIB_SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK);
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
int16_t state = SX127x::beginFSK(versions, 3, freqDev, rxBw, preambleLength, enableOOK);
RADIOLIB_ASSERT(state);
// configure settings not accessible by API
@@ -45,6 +51,9 @@ int16_t SX1276::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setBitRate(br);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
@@ -65,7 +74,7 @@ int16_t SX1276::setFrequency(float freq) {
// set frequency and if successful, save the new setting
int16_t state = SX127x::setFrequencyRaw(freq);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_freq = freq;
SX127x::frequency = freq;
}
return(state);
}
+16 -25
View File
@@ -3,13 +3,12 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX127X)
#if !RADIOLIB_EXCLUDE_SX127X
#include "SX1278.h"
/*!
\class SX1276
\brief Derived class for %SX1276 modules. Overrides some methods from SX1278 due to different parameter ranges.
*/
class SX1276: public SX1278 {
@@ -19,56 +18,38 @@ class SX1276: public SX1278 {
/*!
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/
SX1276(Module* mod);
SX1276(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
/*!
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 1020.0 MHz.
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
Allowed values range from 6 to 65535.
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
Set to 0 to enable automatic gain control (recommended).
\returns \ref status_codes
*/
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
/*!
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 1020.0 MHz.
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of FSK preamble in bits.
\param enableOOK Use OOK modulation instead of FSK.
\returns \ref status_codes
*/
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
@@ -77,19 +58,29 @@ class SX1276: public SX1278 {
/*!
\brief Sets carrier frequency. Allowed values range from 137.0 MHz to 1020.0 MHz.
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq);
int16_t setFrequency(float freq) override;
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
private:
#endif
};
/*!
\class RFM95
\brief Only exists as alias for SX1276, since there seems to be no difference between %RFM95 and %SX1276 modules.
*/
RADIOLIB_TYPE_ALIAS(SX1276, RFM95)
/*!
\class RFM96
\brief Only exists as alias for SX1276, since there seems to be no difference between %RFM96 and %SX1276 modules.
*/
RADIOLIB_TYPE_ALIAS(SX1276, RFM96)
#endif
#endif
+62 -5
View File
@@ -1,5 +1,5 @@
#include "SX1277.h"
#if !defined(RADIOLIB_EXCLUDE_SX127X)
#if !RADIOLIB_EXCLUDE_SX127X
SX1277::SX1277(Module* mod) : SX1278(mod) {
@@ -7,7 +7,8 @@ SX1277::SX1277(Module* mod) : SX1278(mod) {
int16_t SX1277::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
// execute common part
int16_t state = SX127x::begin(RADIOLIB_SX1278_CHIP_VERSION, syncWord, preambleLength);
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
int16_t state = SX127x::begin(versions, 3, syncWord, preambleLength);
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
@@ -29,12 +30,17 @@ int16_t SX1277::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
state = setGain(gain);
RADIOLIB_ASSERT(state);
// set publicly accessible settings that are not a part of begin method
state = setCRC(true);
RADIOLIB_ASSERT(state);
return(state);
}
int16_t SX1277::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
// execute common part
int16_t state = SX127x::beginFSK(RADIOLIB_SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK);
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
int16_t state = SX127x::beginFSK(versions, 3, freqDev, rxBw, preambleLength, enableOOK);
RADIOLIB_ASSERT(state);
// configure settings not accessible by API
@@ -45,6 +51,9 @@ int16_t SX1277::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setBitRate(br);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
@@ -65,7 +74,7 @@ int16_t SX1277::setFrequency(float freq) {
// set frequency and if successful, save the new setting
int16_t state = SX127x::setFrequencyRaw(freq);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_freq = freq;
SX127x::frequency = freq;
}
return(state);
}
@@ -94,7 +103,55 @@ int16_t SX1277::setSpreadingFactor(uint8_t sf) {
// set spreading factor and if successful, save the new setting
int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_sf = sf;
SX127x::spreadingFactor = sf;
}
return(state);
}
int16_t SX1277::setDataRate(DataRate_t dr) {
int16_t state = RADIOLIB_ERR_UNKNOWN;
// select interpretation based on active modem
uint8_t modem = this->getActiveModem();
if(modem == RADIOLIB_SX127X_FSK_OOK) {
// set the bit rate
state = this->setBitRate(dr.fsk.bitRate);
RADIOLIB_ASSERT(state);
// set the frequency deviation
state = this->setFrequencyDeviation(dr.fsk.freqDev);
} else if(modem == RADIOLIB_SX127X_LORA) {
// set the spreading factor
state = this->setSpreadingFactor(dr.lora.spreadingFactor);
RADIOLIB_ASSERT(state);
// set the bandwidth
state = this->setBandwidth(dr.lora.bandwidth);
}
return(state);
}
int16_t SX1277::checkDataRate(DataRate_t dr) {
int16_t state = RADIOLIB_ERR_UNKNOWN;
// select interpretation based on active modem
int16_t modem = getActiveModem();
if(modem == RADIOLIB_SX127X_FSK_OOK) {
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
if(!((dr.fsk.freqDev + dr.fsk.bitRate/2.0 <= 250.0) && (dr.fsk.freqDev <= 200.0))) {
return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
}
return(RADIOLIB_ERR_NONE);
} else if(modem == RADIOLIB_SX127X_LORA) {
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 9, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 0.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
return(RADIOLIB_ERR_NONE);
}
return(state);
+24 -27
View File
@@ -3,13 +3,12 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX127X)
#if !RADIOLIB_EXCLUDE_SX127X
#include "SX1278.h"
/*!
\class SX1277
\brief Derived class for %SX1277 modules. Overrides some methods from SX1278 due to different parameter ranges.
*/
class SX1277: public SX1278 {
@@ -19,56 +18,38 @@ class SX1277: public SX1278 {
/*!
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/
SX1277(Module* mod);
SX1277(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
/*!
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 1020.0 MHz.
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
\param sf %LoRa link spreading factor. Allowed values range from 6 to 9.
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
Allowed values range from 6 to 65535.
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
Set to 0 to enable automatic gain control (recommended).
\returns \ref status_codes
*/
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
/*!
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of FSK preamble in bits.
\param enableOOK Use OOK modulation instead of FSK.
\returns \ref status_codes
*/
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
@@ -77,28 +58,44 @@ class SX1277: public SX1278 {
/*!
\brief Sets carrier frequency. Allowed values range from 137.0 MHz to 1020.0 MHz.
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq);
int16_t setFrequency(float freq) override;
/*!
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 9. Only available in %LoRa mode.
\param sf %LoRa link spreading factor to be set.
\returns \ref status_codes
*/
int16_t setSpreadingFactor(uint8_t sf);
/*!
\brief Set data.
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
\returns \ref status_codes
*/
int16_t setDataRate(DataRate_t dr) override;
/*!
\brief Check the data rate can be configured by this module.
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
\returns \ref status_codes
*/
int16_t checkDataRate(DataRate_t dr) override;
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
private:
#endif
};
/*!
\class RFM97
\brief Only exists as alias for SX1277, since there seems to be no difference between %RFM97 and %SX1277 modules.
*/
RADIOLIB_TYPE_ALIAS(SX1277, RFM97)
#endif
#endif
+243 -166
View File
@@ -1,5 +1,6 @@
#include "SX1278.h"
#if !defined(RADIOLIB_EXCLUDE_SX127X)
#include <math.h>
#if !RADIOLIB_EXCLUDE_SX127X
SX1278::SX1278(Module* mod) : SX127x(mod) {
@@ -7,7 +8,8 @@ SX1278::SX1278(Module* mod) : SX127x(mod) {
int16_t SX1278::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
// execute common part
int16_t state = SX127x::begin(RADIOLIB_SX1278_CHIP_VERSION, syncWord, preambleLength);
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
int16_t state = SX127x::begin(versions, 3, syncWord, preambleLength);
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
@@ -29,12 +31,17 @@ int16_t SX1278::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
state = setGain(gain);
RADIOLIB_ASSERT(state);
// set publicly accessible settings that are not a part of begin method
state = setCRC(true);
RADIOLIB_ASSERT(state);
return(state);
}
int16_t SX1278::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
// execute common part
int16_t state = SX127x::beginFSK(RADIOLIB_SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK);
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
int16_t state = SX127x::beginFSK(versions, 3, freqDev, rxBw, preambleLength, enableOOK);
RADIOLIB_ASSERT(state);
// configure settings not accessible by API
@@ -45,6 +52,9 @@ int16_t SX1278::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setBitRate(br);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
@@ -56,15 +66,20 @@ int16_t SX1278::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
RADIOLIB_ASSERT(state);
}
// set publicly accessible settings that are not a part of begin method
state = setCRC(true);
RADIOLIB_ASSERT(state);
return(state);
}
void SX1278::reset() {
_mod->pinMode(_mod->getRst(), OUTPUT);
_mod->digitalWrite(_mod->getRst(), LOW);
_mod->delay(1);
_mod->digitalWrite(_mod->getRst(), HIGH);
_mod->delay(5);
Module* mod = this->getMod();
mod->hal->pinMode(mod->getRst(), mod->hal->GpioModeOutput);
mod->hal->digitalWrite(mod->getRst(), mod->hal->GpioLevelLow);
mod->hal->delay(1);
mod->hal->digitalWrite(mod->getRst(), mod->hal->GpioLevelHigh);
mod->hal->delay(5);
}
int16_t SX1278::setFrequency(float freq) {
@@ -73,7 +88,7 @@ int16_t SX1278::setFrequency(float freq) {
// set frequency and if successful, save the new setting
int16_t state = SX127x::setFrequencyRaw(freq);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_freq = freq;
SX127x::frequency = freq;
}
return(state);
}
@@ -87,25 +102,25 @@ int16_t SX1278::setBandwidth(float bw) {
uint8_t newBandwidth;
// check allowed bandwidth values
if(fabs(bw - 7.8) <= 0.001) {
if(fabsf(bw - 7.8) <= 0.001) {
newBandwidth = RADIOLIB_SX1278_BW_7_80_KHZ;
} else if(fabs(bw - 10.4) <= 0.001) {
} else if(fabsf(bw - 10.4) <= 0.001) {
newBandwidth = RADIOLIB_SX1278_BW_10_40_KHZ;
} else if(fabs(bw - 15.6) <= 0.001) {
} else if(fabsf(bw - 15.6) <= 0.001) {
newBandwidth = RADIOLIB_SX1278_BW_15_60_KHZ;
} else if(fabs(bw - 20.8) <= 0.001) {
} else if(fabsf(bw - 20.8) <= 0.001) {
newBandwidth = RADIOLIB_SX1278_BW_20_80_KHZ;
} else if(fabs(bw - 31.25) <= 0.001) {
} else if(fabsf(bw - 31.25) <= 0.001) {
newBandwidth = RADIOLIB_SX1278_BW_31_25_KHZ;
} else if(fabs(bw - 41.7) <= 0.001) {
} else if(fabsf(bw - 41.7) <= 0.001) {
newBandwidth = RADIOLIB_SX1278_BW_41_70_KHZ;
} else if(fabs(bw - 62.5) <= 0.001) {
} else if(fabsf(bw - 62.5) <= 0.001) {
newBandwidth = RADIOLIB_SX1278_BW_62_50_KHZ;
} else if(fabs(bw - 125.0) <= 0.001) {
} else if(fabsf(bw - 125.0) <= 0.001) {
newBandwidth = RADIOLIB_SX1278_BW_125_00_KHZ;
} else if(fabs(bw - 250.0) <= 0.001) {
} else if(fabsf(bw - 250.0) <= 0.001) {
newBandwidth = RADIOLIB_SX1278_BW_250_00_KHZ;
} else if(fabs(bw - 500.0) <= 0.001) {
} else if(fabsf(bw - 500.0) <= 0.001) {
newBandwidth = RADIOLIB_SX1278_BW_500_00_KHZ;
} else {
return(RADIOLIB_ERR_INVALID_BANDWIDTH);
@@ -114,18 +129,16 @@ int16_t SX1278::setBandwidth(float bw) {
// set bandwidth and if successful, save the new setting
int16_t state = SX1278::setBandwidthRaw(newBandwidth);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_bw = bw;
SX127x::bandwidth = bw;
// calculate symbol length and set low data rate optimization, if auto-configuration is enabled
if(_ldroAuto) {
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
RADIOLIB_DEBUG_PRINT("Symbol length: ");
RADIOLIB_DEBUG_PRINT(symbolLength);
RADIOLIB_DEBUG_PRINTLN(" ms");
if(this->ldroAuto) {
float symbolLength = (float)(uint32_t(1) << SX127x::spreadingFactor) / (float)SX127x::bandwidth;
Module* mod = this->getMod();
if(symbolLength >= 16.0) {
state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3);
state = mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3);
} else {
state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3);
state = mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3);
}
}
}
@@ -170,18 +183,16 @@ int16_t SX1278::setSpreadingFactor(uint8_t sf) {
// set spreading factor and if successful, save the new setting
int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_sf = sf;
SX127x::spreadingFactor = sf;
// calculate symbol length and set low data rate optimization, if auto-configuration is enabled
if(_ldroAuto) {
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
RADIOLIB_DEBUG_PRINT("Symbol length: ");
RADIOLIB_DEBUG_PRINT(symbolLength);
RADIOLIB_DEBUG_PRINTLN(" ms");
if(this->ldroAuto) {
float symbolLength = (float)(uint32_t(1) << SX127x::spreadingFactor) / (float)SX127x::bandwidth;
Module* mod = this->getMod();
if(symbolLength >= 16.0) {
state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3);
state = mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3);
} else {
state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3);
state = mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3);
}
}
}
@@ -217,25 +228,79 @@ int16_t SX1278::setCodingRate(uint8_t cr) {
// set coding rate and if successful, save the new setting
int16_t state = SX1278::setCodingRateRaw(newCodingRate);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_cr = cr;
SX127x::codingRate = cr;
}
return(state);
}
int16_t SX1278::setOutputPower(int8_t power, bool useRfo) {
// check allowed power range
if(useRfo) {
// RFO output
RADIOLIB_CHECK_RANGE(power, -3, 15, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
} else {
// PA_BOOST output, check high-power operation
if(power != 20) {
RADIOLIB_CHECK_RANGE(power, 2, 17, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
}
int16_t SX1278::setBitRate(float br) {
return(SX127x::setBitRateCommon(br, RADIOLIB_SX1278_REG_BIT_RATE_FRAC));
}
int16_t SX1278::setDataRate(DataRate_t dr) {
int16_t state = RADIOLIB_ERR_UNKNOWN;
// select interpretation based on active modem
uint8_t modem = this->getActiveModem();
if(modem == RADIOLIB_SX127X_FSK_OOK) {
// set the bit rate
state = this->setBitRate(dr.fsk.bitRate);
RADIOLIB_ASSERT(state);
// set the frequency deviation
state = this->setFrequencyDeviation(dr.fsk.freqDev);
} else if(modem == RADIOLIB_SX127X_LORA) {
// set the spreading factor
state = this->setSpreadingFactor(dr.lora.spreadingFactor);
RADIOLIB_ASSERT(state);
// set the bandwidth
state = this->setBandwidth(dr.lora.bandwidth);
RADIOLIB_ASSERT(state);
// set the coding rate
state = this->setCodingRate(dr.lora.codingRate);
}
return(state);
}
int16_t SX1278::checkDataRate(DataRate_t dr) {
int16_t state = RADIOLIB_ERR_UNKNOWN;
// select interpretation based on active modem
int16_t modem = getActiveModem();
if(modem == RADIOLIB_SX127X_FSK_OOK) {
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
if(!((dr.fsk.freqDev + dr.fsk.bitRate/2.0 <= 250.0) && (dr.fsk.freqDev <= 200.0))) {
return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
}
return(RADIOLIB_ERR_NONE);
} else if(modem == RADIOLIB_SX127X_LORA) {
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 12, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 0.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
return(RADIOLIB_ERR_NONE);
}
return(state);
}
int16_t SX1278::setOutputPower(int8_t power) {
return(this->setOutputPower(power, false));
}
int16_t SX1278::setOutputPower(int8_t power, bool useRfo) {
// check if power value is configurable
int16_t state = checkOutputPower(power, NULL, useRfo);
RADIOLIB_ASSERT(state);
// set mode to standby
int16_t state = SX127x::standby();
state = SX127x::standby();
Module* mod = this->getMod();
if(useRfo) {
uint8_t paCfg = 0;
@@ -247,22 +312,22 @@ int16_t SX1278::setOutputPower(int8_t power, bool useRfo) {
paCfg = RADIOLIB_SX1278_MAX_POWER | power;
}
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_RFO, 7, 7);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, paCfg, 6, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_RFO, 7, 7);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, paCfg, 6, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
} else {
if(power != 20) {
// power is 2 - 17 dBm, enable PA1 + PA2 on PA_BOOST
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX1278_MAX_POWER | (power - 2), 6, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX1278_MAX_POWER | (power - 2), 6, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
} else {
// power is 20 dBm, enable PA1 + PA2 on PA_BOOST and enable high power control
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX1278_MAX_POWER | 0x0F, 6, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_ON, 2, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX1278_MAX_POWER | 0x0F, 6, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_ON, 2, 0);
}
}
@@ -270,6 +335,34 @@ int16_t SX1278::setOutputPower(int8_t power, bool useRfo) {
return(state);
}
int16_t SX1278::checkOutputPower(int8_t power, int8_t* clipped) {
return(checkOutputPower(power, clipped, false));
}
int16_t SX1278::checkOutputPower(int8_t power, int8_t* clipped, bool useRfo) {
// check allowed power range
if(useRfo) {
// RFO output
if(clipped) {
*clipped = RADIOLIB_MAX(-3, RADIOLIB_MIN(15, power));
}
RADIOLIB_CHECK_RANGE(power, -3, 15, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
} else {
// PA_BOOST output, check high-power operation
if(clipped) {
if(power != 20) {
*clipped = RADIOLIB_MAX(2, RADIOLIB_MIN(17, power));
} else {
*clipped = 20;
}
}
if(power != 20) {
RADIOLIB_CHECK_RANGE(power, 2, 17, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
}
}
return(RADIOLIB_ERR_NONE);
}
int16_t SX1278::setGain(uint8_t gain) {
// check allowed range
if(gain > 6) {
@@ -278,6 +371,7 @@ int16_t SX1278::setGain(uint8_t gain) {
// set mode to standby
int16_t state = SX127x::standby();
Module* mod = this->getMod();
// get modem
int16_t modem = getActiveModem();
@@ -285,20 +379,21 @@ int16_t SX1278::setGain(uint8_t gain) {
// set gain
if(gain == 0) {
// gain set to 0, enable AGC loop
state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_AGC_AUTO_ON, 2, 2);
state |= mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_AGC_AUTO_ON, 2, 2);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, RADIOLIB_SX127X_LNA_BOOST_ON, 1, 0);
} else {
state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_AGC_AUTO_OFF, 2, 2);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
state |= mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_AGC_AUTO_OFF, 2, 2);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
}
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
// set gain
if(gain == 0) {
// gain set to 0, enable AGC loop
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3);
} else {
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX1278_AGC_AUTO_OFF, 3, 3);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX1278_AGC_AUTO_OFF, 3, 3);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
}
}
@@ -313,7 +408,7 @@ int16_t SX1278::setDataShaping(uint8_t sh) {
}
// check modulation
if(SX127x::_ook) {
if(SX127x::ookEnabled) {
// we're in OOK mode, the only thing we can do is disable
if(sh == RADIOLIB_SHAPING_NONE) {
return(setDataShapingOOK(0));
@@ -327,15 +422,16 @@ int16_t SX1278::setDataShaping(uint8_t sh) {
RADIOLIB_ASSERT(state);
// set data shaping
Module* mod = this->getMod();
switch(sh) {
case RADIOLIB_SHAPING_NONE:
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_NO_SHAPING, 6, 5));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_NO_SHAPING, 6, 5));
case RADIOLIB_SHAPING_0_3:
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_0_3, 6, 5));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_0_3, 6, 5));
case RADIOLIB_SHAPING_0_5:
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_0_5, 6, 5));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_0_5, 6, 5));
case RADIOLIB_SHAPING_1_0:
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_1_0, 6, 5));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_1_0, 6, 5));
default:
return(RADIOLIB_ERR_INVALID_DATA_SHAPING);
}
@@ -348,7 +444,7 @@ int16_t SX1278::setDataShapingOOK(uint8_t sh) {
}
// check modulation
if(!SX127x::_ook) {
if(!SX127x::ookEnabled) {
return(RADIOLIB_ERR_INVALID_MODULATION);
}
@@ -356,15 +452,16 @@ int16_t SX1278::setDataShapingOOK(uint8_t sh) {
int16_t state = SX127x::standby();
// set data shaping
Module* mod = this->getMod();
switch(sh) {
case 0:
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_NO_SHAPING, 6, 5);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_NO_SHAPING, 6, 5);
break;
case 1:
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_OOK_FILTER_BR, 6, 5);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_OOK_FILTER_BR, 6, 5);
break;
case 2:
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_OOK_FILTER_2BR, 6, 5);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_OOK_FILTER_2BR, 6, 5);
break;
default:
return(RADIOLIB_ERR_INVALID_DATA_SHAPING);
@@ -373,70 +470,43 @@ int16_t SX1278::setDataShapingOOK(uint8_t sh) {
return(state);
}
float SX1278::getRSSI(bool skipReceive) {
if(getActiveModem() == RADIOLIB_SX127X_LORA) {
// for LoRa, get RSSI of the last packet
float lastPacketRSSI;
float SX1278::getRSSI() {
return(SX1278::getRSSI(true, false));
}
// RSSI calculation uses different constant for low-frequency and high-frequency ports
if(_freq < 868.0) {
lastPacketRSSI = -164 + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PKT_RSSI_VALUE);
} else {
lastPacketRSSI = -157 + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PKT_RSSI_VALUE);
}
// spread-spectrum modulation signal can be received below noise floor
// check last packet SNR and if it's less than 0, add it to reported RSSI to get the correct value
float lastPacketSNR = SX127x::getSNR();
if(lastPacketSNR < 0.0) {
lastPacketRSSI += lastPacketSNR;
}
return(lastPacketRSSI);
} else {
// enable listen mode
if(!skipReceive) {
startReceive();
}
// read the value for FSK
float rssi = (float)_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE_FSK) / -2.0;
// set mode back to standby
if(!skipReceive) {
standby();
}
// return the value
return(rssi);
float SX1278::getRSSI(bool packet, bool skipReceive) {
int16_t offset = -157;
if(frequency < 868.0) {
offset = -164;
}
return(SX127x::getRSSI(packet, skipReceive, offset));
}
int16_t SX1278::setCRC(bool enable, bool mode) {
Module* mod = this->getMod();
if(getActiveModem() == RADIOLIB_SX127X_LORA) {
// set LoRa CRC
SX127x::_crcEnabled = enable;
SX127x::crcEnabled = enable;
if(enable) {
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1278_RX_CRC_MODE_ON, 2, 2));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1278_RX_CRC_MODE_ON, 2, 2));
} else {
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1278_RX_CRC_MODE_OFF, 2, 2));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1278_RX_CRC_MODE_OFF, 2, 2));
}
} else {
// set FSK CRC
int16_t state = RADIOLIB_ERR_NONE;
if(enable) {
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_ON, 4, 4);
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_ON, 4, 4);
} else {
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_OFF, 4, 4);
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_OFF, 4, 4);
}
RADIOLIB_ASSERT(state);
// set FSK CRC mode
if(mode) {
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM, 0, 0));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM, 0, 0));
} else {
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT, 0, 0));
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT, 0, 0));
}
}
}
@@ -446,11 +516,12 @@ int16_t SX1278::forceLDRO(bool enable) {
return(RADIOLIB_ERR_WRONG_MODEM);
}
_ldroAuto = false;
Module* mod = this->getMod();
this->ldroAuto = false;
if(enable) {
return(_mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3));
return(mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3));
} else {
return(_mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3));
return(mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3));
}
}
@@ -459,7 +530,7 @@ int16_t SX1278::autoLDRO() {
return(RADIOLIB_ERR_WRONG_MODEM);
}
_ldroAuto = true;
this->ldroAuto = true;
return(RADIOLIB_ERR_NONE);
}
@@ -476,7 +547,8 @@ int16_t SX1278::setBandwidthRaw(uint8_t newBandwidth) {
int16_t state = SX127x::standby();
// write register
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newBandwidth, 7, 4);
Module* mod = this->getMod();
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newBandwidth, 7, 4);
return(state);
}
@@ -485,16 +557,17 @@ int16_t SX1278::setSpreadingFactorRaw(uint8_t newSpreadingFactor) {
int16_t state = SX127x::standby();
// write registers
Module* mod = this->getMod();
if(newSpreadingFactor == RADIOLIB_SX127X_SF_6) {
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_IMPL_MODE, 0, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE | (SX127x::_crcEnabled ? RADIOLIB_SX1278_RX_CRC_MODE_ON : RADIOLIB_SX1278_RX_CRC_MODE_OFF), 7, 2);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_IMPL_MODE, 0, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6);
} else {
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_EXPL_MODE, 0, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE | (SX127x::_crcEnabled ? RADIOLIB_SX1278_RX_CRC_MODE_ON : RADIOLIB_SX1278_RX_CRC_MODE_OFF), 7, 2);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_EXPL_MODE, 0, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0);
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12);
}
return(state);
}
@@ -504,7 +577,8 @@ int16_t SX1278::setCodingRateRaw(uint8_t newCodingRate) {
int16_t state = SX127x::standby();
// write register
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newCodingRate, 3, 1);
Module* mod = this->getMod();
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newCodingRate, 3, 1);
return(state);
}
@@ -515,15 +589,16 @@ int16_t SX1278::setHeaderType(uint8_t headerType, size_t len) {
}
// set requested packet mode
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 0, 0);
Module* mod = this->getMod();
int16_t state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 0, 0);
RADIOLIB_ASSERT(state);
// set length to register
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len);
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len);
RADIOLIB_ASSERT(state);
// update cached value
_packetLength = len;
SX127x::packetLength = len;
return(state);
}
@@ -534,7 +609,8 @@ int16_t SX1278::configFSK() {
RADIOLIB_ASSERT(state);
// set fast PLL hop
state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PLL_HOP, RADIOLIB_SX127X_FAST_HOP_ON, 7, 7);
Module* mod = this->getMod();
state = mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PLL_HOP, RADIOLIB_SX127X_FAST_HOP_ON, 7, 7);
return(state);
}
@@ -546,13 +622,14 @@ void SX1278::errataFix(bool rx) {
// sensitivity optimization for 500kHz bandwidth
// see SX1276/77/78 Errata, section 2.1 for details
if(fabs(_bw - 500.0) <= 0.001) {
if((_freq >= 862.0) && (_freq <= 1020.0)) {
_mod->SPIwriteRegister(0x36, 0x02);
_mod->SPIwriteRegister(0x3a, 0x64);
} else if((_freq >= 410.0) && (_freq <= 525.0)) {
_mod->SPIwriteRegister(0x36, 0x02);
_mod->SPIwriteRegister(0x3a, 0x7F);
Module* mod = this->getMod();
if(fabsf(SX127x::bandwidth - 500.0) <= 0.001) {
if((frequency >= 862.0) && (frequency <= 1020.0)) {
mod->SPIwriteRegister(0x36, 0x02);
mod->SPIwriteRegister(0x3a, 0x64);
} else if((frequency >= 410.0) && (frequency <= 525.0)) {
mod->SPIwriteRegister(0x36, 0x02);
mod->SPIwriteRegister(0x3a, 0x7F);
}
}
@@ -561,53 +638,53 @@ void SX1278::errataFix(bool rx) {
// figure out what we need to set
uint8_t fixedRegs[3] = { 0x00, 0x00, 0x00 };
float rxFreq = _freq;
if(fabs(_bw - 7.8) <= 0.001) {
fixedRegs[0] = 0b0000000;
float rxFreq = frequency;
if(fabsf(SX127x::bandwidth - 7.8) <= 0.001) {
fixedRegs[0] = 0b00000000;
fixedRegs[1] = 0x48;
fixedRegs[2] = 0x00;
rxFreq += 0.00781;
} else if(fabs(_bw - 10.4) <= 0.001) {
fixedRegs[0] = 0b0000000;
} else if(fabsf(SX127x::bandwidth - 10.4) <= 0.001) {
fixedRegs[0] = 0b00000000;
fixedRegs[1] = 0x44;
fixedRegs[2] = 0x00;
rxFreq += 0.01042;
} else if(fabs(_bw - 15.6) <= 0.001) {
fixedRegs[0] = 0b0000000;
} else if(fabsf(SX127x::bandwidth - 15.6) <= 0.001) {
fixedRegs[0] = 0b00000000;
fixedRegs[1] = 0x44;
fixedRegs[2] = 0x00;
rxFreq += 0.01562;
} else if(fabs(_bw - 20.8) <= 0.001) {
fixedRegs[0] = 0b0000000;
} else if(fabsf(SX127x::bandwidth - 20.8) <= 0.001) {
fixedRegs[0] = 0b00000000;
fixedRegs[1] = 0x44;
fixedRegs[2] = 0x00;
rxFreq += 0.02083;
} else if(fabs(_bw - 31.25) <= 0.001) {
fixedRegs[0] = 0b0000000;
} else if(fabsf(SX127x::bandwidth - 31.25) <= 0.001) {
fixedRegs[0] = 0b00000000;
fixedRegs[1] = 0x44;
fixedRegs[2] = 0x00;
rxFreq += 0.03125;
} else if(fabs(_bw - 41.7) <= 0.001) {
fixedRegs[0] = 0b0000000;
} else if(fabsf(SX127x::bandwidth - 41.7) <= 0.001) {
fixedRegs[0] = 0b00000000;
fixedRegs[1] = 0x44;
fixedRegs[2] = 0x00;
rxFreq += 0.04167;
} else if(fabs(_bw - 62.5) <= 0.001) {
fixedRegs[0] = 0b0000000;
} else if(fabsf(SX127x::bandwidth - 62.5) <= 0.001) {
fixedRegs[0] = 0b00000000;
fixedRegs[1] = 0x40;
fixedRegs[2] = 0x00;
} else if(fabs(_bw - 125.0) <= 0.001) {
fixedRegs[0] = 0b0000000;
} else if(fabsf(SX127x::bandwidth - 125.0) <= 0.001) {
fixedRegs[0] = 0b00000000;
fixedRegs[1] = 0x40;
fixedRegs[2] = 0x00;
} else if(fabs(_bw - 250.0) <= 0.001) {
fixedRegs[0] = 0b0000000;
} else if(fabsf(SX127x::bandwidth - 250.0) <= 0.001) {
fixedRegs[0] = 0b00000000;
fixedRegs[1] = 0x40;
fixedRegs[2] = 0x00;
} else if(fabs(_bw - 500.0) <= 0.001) {
fixedRegs[0] = 0b1000000;
fixedRegs[1] = _mod->SPIreadRegister(0x2F);
fixedRegs[2] = _mod->SPIreadRegister(0x30);
} else if(fabsf(SX127x::bandwidth - 500.0) <= 0.001) {
fixedRegs[0] = 0b10000000;
fixedRegs[1] = mod->SPIreadRegister(0x2F);
fixedRegs[2] = mod->SPIreadRegister(0x30);
} else {
return;
}
@@ -619,13 +696,13 @@ void SX1278::errataFix(bool rx) {
if(rx) {
SX127x::setFrequencyRaw(rxFreq);
} else {
SX127x::setFrequencyRaw(_freq);
SX127x::setFrequencyRaw(frequency);
}
// finally, apply errata fixes
_mod->SPIsetRegValue(0x31, fixedRegs[0], 7, 7);
_mod->SPIsetRegValue(0x2F, fixedRegs[1]);
_mod->SPIsetRegValue(0x30, fixedRegs[2]);
mod->SPIsetRegValue(0x31, fixedRegs[0], 7, 7);
mod->SPIsetRegValue(0x2F, fixedRegs[1]);
mod->SPIsetRegValue(0x30, fixedRegs[2]);
}
#endif
+147 -129
View File
@@ -3,101 +3,102 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX127X)
#if !RADIOLIB_EXCLUDE_SX127X
#include "../../Module.h"
#include "SX127x.h"
// SX1278 specific register map
#define RADIOLIB_SX1278_REG_MODEM_CONFIG_3 0x26
#define RADIOLIB_SX1278_REG_PLL_HOP 0x44
#define RADIOLIB_SX1278_REG_TCXO 0x4B
#define RADIOLIB_SX1278_REG_PA_DAC 0x4D
#define RADIOLIB_SX1278_REG_FORMER_TEMP 0x5B
#define RADIOLIB_SX1278_REG_REG_BIT_RATE_FRAC 0x5D
#define RADIOLIB_SX1278_REG_AGC_REF 0x61
#define RADIOLIB_SX1278_REG_AGC_THRESH_1 0x62
#define RADIOLIB_SX1278_REG_AGC_THRESH_2 0x63
#define RADIOLIB_SX1278_REG_AGC_THRESH_3 0x64
#define RADIOLIB_SX1278_REG_PLL 0x70
#define RADIOLIB_SX1278_REG_MODEM_CONFIG_3 0x26
#define RADIOLIB_SX1278_REG_PLL_HOP 0x44
#define RADIOLIB_SX1278_REG_TCXO 0x4B
#define RADIOLIB_SX1278_REG_PA_DAC 0x4D
#define RADIOLIB_SX1278_REG_FORMER_TEMP 0x5B
#define RADIOLIB_SX1278_REG_BIT_RATE_FRAC 0x5D
#define RADIOLIB_SX1278_REG_AGC_REF 0x61
#define RADIOLIB_SX1278_REG_AGC_THRESH_1 0x62
#define RADIOLIB_SX1278_REG_AGC_THRESH_2 0x63
#define RADIOLIB_SX1278_REG_AGC_THRESH_3 0x64
#define RADIOLIB_SX1278_REG_PLL 0x70
// SX1278 LoRa modem settings
// RADIOLIB_SX1278_REG_OP_MODE MSB LSB DESCRIPTION
#define RADIOLIB_SX1278_HIGH_FREQ 0b00000000 // 3 3 access HF test registers
#define RADIOLIB_SX1278_LOW_FREQ 0b00001000 // 3 3 access LF test registers
// RADIOLIB_SX1278_REG_OP_MODE MSB LSB DESCRIPTION
#define RADIOLIB_SX1278_HIGH_FREQ 0b00000000 // 3 3 access HF test registers
#define RADIOLIB_SX1278_LOW_FREQ 0b00001000 // 3 3 access LF test registers
// RADIOLIB_SX1278_REG_FRF_MSB + REG_FRF_MID + REG_FRF_LSB
#define RADIOLIB_SX1278_FRF_MSB 0x6C // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19
#define RADIOLIB_SX1278_FRF_MID 0x80 // 7 0 where F(XOSC) = 32 MHz
#define RADIOLIB_SX1278_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers
#define RADIOLIB_SX1278_FRF_MSB 0x6C // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19
#define RADIOLIB_SX1278_FRF_MID 0x80 // 7 0 where F(XOSC) = 32 MHz
#define RADIOLIB_SX1278_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers
// RADIOLIB_SX1278_REG_PA_CONFIG
#define RADIOLIB_SX1278_MAX_POWER 0b01110000 // 6 4 max power: P_max = 10.8 + 0.6*MAX_POWER [dBm]; P_max(MAX_POWER = 0b111) = 15 dBm
#define RADIOLIB_SX1278_LOW_POWER 0b00100000 // 6 4
#define RADIOLIB_SX1278_MAX_POWER 0b01110000 // 6 4 max power: P_max = 10.8 + 0.6*MAX_POWER [dBm]; P_max(MAX_POWER = 0b111) = 15 dBm
#define RADIOLIB_SX1278_LOW_POWER 0b00100000 // 6 4
// RADIOLIB_SX1278_REG_LNA
#define RADIOLIB_SX1278_LNA_BOOST_LF_OFF 0b00000000 // 4 3 default LNA current
#define RADIOLIB_SX1278_LNA_BOOST_LF_OFF 0b00000000 // 4 3 default LNA current
// SX127X_REG_MODEM_CONFIG_1
#define RADIOLIB_SX1278_BW_7_80_KHZ 0b00000000 // 7 4 bandwidth: 7.80 kHz
#define RADIOLIB_SX1278_BW_10_40_KHZ 0b00010000 // 7 4 10.40 kHz
#define RADIOLIB_SX1278_BW_15_60_KHZ 0b00100000 // 7 4 15.60 kHz
#define RADIOLIB_SX1278_BW_20_80_KHZ 0b00110000 // 7 4 20.80 kHz
#define RADIOLIB_SX1278_BW_31_25_KHZ 0b01000000 // 7 4 31.25 kHz
#define RADIOLIB_SX1278_BW_41_70_KHZ 0b01010000 // 7 4 41.70 kHz
#define RADIOLIB_SX1278_BW_62_50_KHZ 0b01100000 // 7 4 62.50 kHz
#define RADIOLIB_SX1278_BW_125_00_KHZ 0b01110000 // 7 4 125.00 kHz
#define RADIOLIB_SX1278_BW_250_00_KHZ 0b10000000 // 7 4 250.00 kHz
#define RADIOLIB_SX1278_BW_500_00_KHZ 0b10010000 // 7 4 500.00 kHz
#define RADIOLIB_SX1278_CR_4_5 0b00000010 // 3 1 error coding rate: 4/5
#define RADIOLIB_SX1278_CR_4_6 0b00000100 // 3 1 4/6
#define RADIOLIB_SX1278_CR_4_7 0b00000110 // 3 1 4/7
#define RADIOLIB_SX1278_CR_4_8 0b00001000 // 3 1 4/8
#define RADIOLIB_SX1278_HEADER_EXPL_MODE 0b00000000 // 0 0 explicit header mode
#define RADIOLIB_SX1278_HEADER_IMPL_MODE 0b00000001 // 0 0 implicit header mode
#define RADIOLIB_SX1278_BW_7_80_KHZ 0b00000000 // 7 4 bandwidth: 7.80 kHz
#define RADIOLIB_SX1278_BW_10_40_KHZ 0b00010000 // 7 4 10.40 kHz
#define RADIOLIB_SX1278_BW_15_60_KHZ 0b00100000 // 7 4 15.60 kHz
#define RADIOLIB_SX1278_BW_20_80_KHZ 0b00110000 // 7 4 20.80 kHz
#define RADIOLIB_SX1278_BW_31_25_KHZ 0b01000000 // 7 4 31.25 kHz
#define RADIOLIB_SX1278_BW_41_70_KHZ 0b01010000 // 7 4 41.70 kHz
#define RADIOLIB_SX1278_BW_62_50_KHZ 0b01100000 // 7 4 62.50 kHz
#define RADIOLIB_SX1278_BW_125_00_KHZ 0b01110000 // 7 4 125.00 kHz
#define RADIOLIB_SX1278_BW_250_00_KHZ 0b10000000 // 7 4 250.00 kHz
#define RADIOLIB_SX1278_BW_500_00_KHZ 0b10010000 // 7 4 500.00 kHz
#define RADIOLIB_SX1278_CR_4_5 0b00000010 // 3 1 error coding rate: 4/5
#define RADIOLIB_SX1278_CR_4_6 0b00000100 // 3 1 4/6
#define RADIOLIB_SX1278_CR_4_7 0b00000110 // 3 1 4/7
#define RADIOLIB_SX1278_CR_4_8 0b00001000 // 3 1 4/8
#define RADIOLIB_SX1278_HEADER_EXPL_MODE 0b00000000 // 0 0 explicit header mode
#define RADIOLIB_SX1278_HEADER_IMPL_MODE 0b00000001 // 0 0 implicit header mode
// SX127X_REG_MODEM_CONFIG_2
#define RADIOLIB_SX1278_RX_CRC_MODE_OFF 0b00000000 // 2 2 CRC disabled
#define RADIOLIB_SX1278_RX_CRC_MODE_ON 0b00000100 // 2 2 CRC enabled
#define RADIOLIB_SX1278_RX_CRC_MODE_OFF 0b00000000 // 2 2 CRC disabled
#define RADIOLIB_SX1278_RX_CRC_MODE_ON 0b00000100 // 2 2 CRC enabled
// RADIOLIB_SX1278_REG_MODEM_CONFIG_3
#define RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF 0b00000000 // 3 3 low data rate optimization disabled
#define RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON 0b00001000 // 3 3 low data rate optimization enabled
#define RADIOLIB_SX1278_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA
#define RADIOLIB_SX1278_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop
#define RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF 0b00000000 // 3 3 low data rate optimization disabled
#define RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON 0b00001000 // 3 3 low data rate optimization enabled
#define RADIOLIB_SX1278_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA
#define RADIOLIB_SX1278_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop
// SX127X_REG_VERSION
#define RADIOLIB_SX1278_CHIP_VERSION 0x12
#define RADIOLIB_SX1278_CHIP_VERSION 0x12 // this is the "official" version listed in datasheet
#define RADIOLIB_SX1278_CHIP_VERSION_ALT 0x13 // appears sometimes
#define RADIOLIB_SX1278_CHIP_VERSION_RFM9X 0x11 // this value is used for the RFM9x
// SX1278 FSK modem settings
// SX127X_REG_PA_RAMP
#define RADIOLIB_SX1278_NO_SHAPING 0b00000000 // 6 5 data shaping: no shaping (default)
#define RADIOLIB_SX1278_FSK_GAUSSIAN_1_0 0b00100000 // 6 5 FSK modulation Gaussian filter, BT = 1.0
#define RADIOLIB_SX1278_FSK_GAUSSIAN_0_5 0b01000000 // 6 5 FSK modulation Gaussian filter, BT = 0.5
#define RADIOLIB_SX1278_FSK_GAUSSIAN_0_3 0b01100000 // 6 5 FSK modulation Gaussian filter, BT = 0.3
#define RADIOLIB_SX1278_OOK_FILTER_BR 0b00100000 // 6 5 OOK modulation filter, f_cutoff = BR
#define RADIOLIB_SX1278_OOK_FILTER_2BR 0b01000000 // 6 5 OOK modulation filter, f_cutoff = 2*BR
#define RADIOLIB_SX1278_NO_SHAPING 0b00000000 // 6 5 data shaping: no shaping (default)
#define RADIOLIB_SX1278_FSK_GAUSSIAN_1_0 0b00100000 // 6 5 FSK modulation Gaussian filter, BT = 1.0
#define RADIOLIB_SX1278_FSK_GAUSSIAN_0_5 0b01000000 // 6 5 FSK modulation Gaussian filter, BT = 0.5
#define RADIOLIB_SX1278_FSK_GAUSSIAN_0_3 0b01100000 // 6 5 FSK modulation Gaussian filter, BT = 0.3
#define RADIOLIB_SX1278_OOK_FILTER_BR 0b00100000 // 6 5 OOK modulation filter, f_cutoff = BR
#define RADIOLIB_SX1278_OOK_FILTER_2BR 0b01000000 // 6 5 OOK modulation filter, f_cutoff = 2*BR
// RADIOLIB_SX1278_REG_AGC_REF
#define RADIOLIB_SX1278_AGC_REFERENCE_LEVEL_LF 0x19 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm]: below 525 MHz
#define RADIOLIB_SX1278_AGC_REFERENCE_LEVEL_HF 0x1C // 5 0 above 779 MHz
#define RADIOLIB_SX1278_AGC_REFERENCE_LEVEL_LF 0x19 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm]: below 525 MHz
#define RADIOLIB_SX1278_AGC_REFERENCE_LEVEL_HF 0x1C // 5 0 above 779 MHz
// RADIOLIB_SX1278_REG_AGC_THRESH_1
#define RADIOLIB_SX1278_AGC_STEP_1_LF 0x0C // 4 0 1st AGC threshold: below 525 MHz
#define RADIOLIB_SX1278_AGC_STEP_1_HF 0x0E // 4 0 above 779 MHz
#define RADIOLIB_SX1278_AGC_STEP_1_LF 0x0C // 4 0 1st AGC threshold: below 525 MHz
#define RADIOLIB_SX1278_AGC_STEP_1_HF 0x0E // 4 0 above 779 MHz
// RADIOLIB_SX1278_REG_AGC_THRESH_2
#define RADIOLIB_SX1278_AGC_STEP_2_LF 0x40 // 7 4 2nd AGC threshold: below 525 MHz
#define RADIOLIB_SX1278_AGC_STEP_2_HF 0x50 // 7 4 above 779 MHz
#define RADIOLIB_SX1278_AGC_STEP_3 0x0B // 3 0 3rd AGC threshold
#define RADIOLIB_SX1278_AGC_STEP_2_LF 0x40 // 7 4 2nd AGC threshold: below 525 MHz
#define RADIOLIB_SX1278_AGC_STEP_2_HF 0x50 // 7 4 above 779 MHz
#define RADIOLIB_SX1278_AGC_STEP_3 0x0B // 3 0 3rd AGC threshold
// RADIOLIB_SX1278_REG_AGC_THRESH_3
#define RADIOLIB_SX1278_AGC_STEP_4 0xC0 // 7 4 4th AGC threshold
#define RADIOLIB_SX1278_AGC_STEP_5 0x0C // 4 0 5th AGC threshold
#define RADIOLIB_SX1278_AGC_STEP_4 0xC0 // 7 4 4th AGC threshold
#define RADIOLIB_SX1278_AGC_STEP_5 0x0C // 4 0 5th AGC threshold
/*!
\class SX1278
\brief Derived class for %SX1278 modules. Also used as base class for SX1276, SX1277, SX1279, RFM95 and RFM96.
All of these modules use the same basic hardware and only differ in parameter ranges (and names).
*/
@@ -108,56 +109,38 @@ class SX1278: public SX127x {
/*!
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/
SX1278(Module* mod);
SX1278(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
/*!
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
Allowed values range from 6 to 65535.
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
Set to 0 to enable automatic gain control (recommended).
\returns \ref status_codes
*/
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
/*!
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of FSK preamble in bits.
\param enableOOK Use OOK modulation instead of FSK.
\returns \ref status_codes
*/
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
@@ -171,58 +154,92 @@ class SX1278: public SX127x {
/*!
\brief Sets carrier frequency. Allowed values range from 137.0 MHz to 525.0 MHz.
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq);
int16_t setFrequency(float freq) override;
/*!
\brief Sets %LoRa link bandwidth. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. Only available in %LoRa mode.
\param bw %LoRa link bandwidth to be set in kHz.
\returns \ref status_codes
*/
int16_t setBandwidth(float bw);
/*!
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 12. Only available in %LoRa mode.
\param sf %LoRa link spreading factor to be set.
\returns \ref status_codes
*/
int16_t setSpreadingFactor(uint8_t sf);
/*!
\brief Sets %LoRa link coding rate denominator. Allowed values range from 5 to 8. Only available in %LoRa mode.
\param cr %LoRa link coding rate denominator to be set.
\returns \ref status_codes
*/
int16_t setCodingRate(uint8_t cr);
/*!
\brief Sets transmission output power. Allowed values range from -3 to 15 dBm (RFO pin) or +2 to +17 dBm (PA_BOOST pin).
High power +20 dBm operation is also supported, on the PA_BOOST pin.
\param power Transmission output power in dBm.
\param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output. Defaults to PA_BOOST.
\brief Sets FSK bit rate. Allowed values range from 0.5 to 300 kbps. Only available in FSK mode.
\param br Bit rate to be set (in kbps).
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power, bool useRfo = false);
int16_t setBitRate(float br) override;
/*!
\brief Set data.
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
\returns \ref status_codes
*/
int16_t setDataRate(DataRate_t dr) override;
/*!
\brief Check the data rate can be configured by this module.
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
\returns \ref status_codes
*/
int16_t checkDataRate(DataRate_t dr) override;
/*!
\brief Sets transmission output power. Allowed values range from -3 to 15 dBm (RFO pin) or +2 to +17 dBm (PA_BOOST pin).
High power +20 dBm operation is also supported, on the PA_BOOST pin. Defaults to PA_BOOST.
\param power Transmission output power in dBm.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power) override;
/*!
\brief Sets transmission output power. Allowed values range from -3 to 15 dBm (RFO pin) or +2 to +17 dBm (PA_BOOST pin).
High power +20 dBm operation is also supported, on the PA_BOOST pin.
\param power Transmission output power in dBm.
\param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power, bool useRfo);
/*!
\brief Check if output power is configurable.
This method is needed for compatibility with PhysicalLayer::checkOutputPower.
\param power Output power in dBm, assumes PA_BOOST pin.
\param clipped Clipped output power value to what is possible within the module's range.
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
/*!
\brief Check if output power is configurable.
\param power Output power in dBm.
\param clipped Clipped output power value to what is possible within the module's range.
\param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output.
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t power, int8_t* clipped, bool useRfo);
/*!
\brief Sets gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
Set to 0 to enable automatic gain control (recommended). Only available in %LoRa mode.
Set to 0 to enable automatic gain control (recommended).
\param gain Gain of receiver LNA (low-noise amplifier) to be set.
\returns \ref status_codes
*/
int16_t setGain(uint8_t gain);
@@ -230,9 +247,7 @@ class SX1278: public SX127x {
/*!
\brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. Only available in FSK mode with FSK modulation.
Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping.
\param sh Gaussian shaping bandwidth-time product that will be used for data shaping
\returns \ref status_codes
*/
int16_t setDataShaping(uint8_t sh) override;
@@ -241,68 +256,65 @@ class SX1278: public SX127x {
\brief Sets filter cutoff frequency that will be used for data shaping.
Allowed values are 1 for frequency equal to bit rate and 2 for frequency equal to 2x bit rate. Set to 0 to disable data shaping.
Only available in FSK mode with OOK modulation.
\param sh Cutoff frequency that will be used for data shaping
\returns \ref status_codes
*/
int16_t setDataShapingOOK(uint8_t sh);
/*!
\brief Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem.
\param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FKS/OOK mode.
\returns Last packet RSSI for LoRa modem, or current RSSI level for FSK modem.
\brief Gets recorded signal strength indicator.
Overload with packet mode enabled for PhysicalLayer compatibility.
\returns RSSI value in dBm.
*/
float getRSSI(bool skipReceive = false);
float getRSSI() override;
/*!
\brief Gets recorded signal strength indicator.
\param packet Whether to read last packet RSSI, or the current value. LoRa mode only, ignored for FSK.
\param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FSK/OOK mode.
\returns RSSI value in dBm.
*/
float getRSSI(bool packet, bool skipReceive = false);
/*!
\brief Enables/disables CRC check of received packets.
\param enable Enable (true) or disable (false) CRC.
\param mode Set CRC mode to SX127X_CRC_WHITENING_TYPE_CCITT for CCITT, polynomial X16 + X12 + X5 + 1 (false) or SX127X_CRC_WHITENING_TYPE_IBM for IBM, polynomial X16 + X15 + X2 + 1 (true). Only valid in FSK mode.
\param mode Set CRC mode to SX127X_CRC_WHITENING_TYPE_CCITT for CCITT, polynomial X16 + X12 + X5 + 1 (false)
or SX127X_CRC_WHITENING_TYPE_IBM for IBM, polynomial X16 + X15 + X2 + 1 (true). Only valid in FSK mode.
\returns \ref status_codes
*/
int16_t setCRC(bool enable, bool mode = false);
/*!
\brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method, LDRO will always be set to
the provided value, regardless of symbol length. To re-enable automatic LDRO configuration, call SX1278::autoLDRO()
\brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method,
LDRO will always be set to the provided value, regardless of symbol length.
To re-enable automatic LDRO configuration, call SX1278::autoLDRO()
\param enable Force LDRO to be always enabled (true) or disabled (false).
\returns \ref status_codes
*/
int16_t forceLDRO(bool enable);
/*!
\brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method, LDRO will be enabled automatically
when symbol length exceeds 16 ms.
\brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method,
LDRO will be enabled automatically when symbol length exceeds 16 ms.
\returns \ref status_codes
*/
int16_t autoLDRO();
/*!
\brief Set implicit header mode for future reception/transmission. Required for spreading factor 6.
\brief Set implicit header mode for future reception/transmission. Required for spreading factor 6.
\param len Payload length in bytes.
\returns \ref status_codes
*/
int16_t implicitHeader(size_t len);
/*!
\brief Set explicit header mode for future reception/transmission.
\returns \ref status_codes
*/
int16_t explicitHeader();
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
protected:
#endif
int16_t setBandwidthRaw(uint8_t newBandwidth);
@@ -311,16 +323,22 @@ class SX1278: public SX127x {
int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);
int16_t configFSK();
void errataFix(bool rx);
void errataFix(bool rx) override;
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
private:
#endif
bool _ldroAuto = true;
bool _ldroEnabled = false;
bool ldroAuto = true;
bool ldroEnabled = false;
};
/*!
\class RFM98
\brief Only exists as alias for SX1278, since there seems to be no difference between %RFM98 and %SX1278 modules.
*/
RADIOLIB_TYPE_ALIAS(SX1278, RFM98)
#endif
#endif
+13 -4
View File
@@ -1,5 +1,5 @@
#include "SX1279.h"
#if !defined(RADIOLIB_EXCLUDE_SX127X)
#if !RADIOLIB_EXCLUDE_SX127X
SX1279::SX1279(Module* mod) : SX1278(mod) {
@@ -7,7 +7,8 @@ SX1279::SX1279(Module* mod) : SX1278(mod) {
int16_t SX1279::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
// execute common part
int16_t state = SX127x::begin(RADIOLIB_SX1278_CHIP_VERSION, syncWord, preambleLength);
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
int16_t state = SX127x::begin(versions, 3, syncWord, preambleLength);
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
@@ -29,12 +30,17 @@ int16_t SX1279::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
state = setGain(gain);
RADIOLIB_ASSERT(state);
// set publicly accessible settings that are not a part of begin method
state = setCRC(true);
RADIOLIB_ASSERT(state);
return(state);
}
int16_t SX1279::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
// execute common part
int16_t state = SX127x::beginFSK(RADIOLIB_SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK);
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
int16_t state = SX127x::beginFSK(versions, 3, freqDev, rxBw, preambleLength, enableOOK);
RADIOLIB_ASSERT(state);
// configure settings not accessible by API
@@ -45,6 +51,9 @@ int16_t SX1279::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setBitRate(br);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
@@ -65,7 +74,7 @@ int16_t SX1279::setFrequency(float freq) {
// set frequency and if successful, save the new setting
int16_t state = SX127x::setFrequencyRaw(freq);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_freq = freq;
SX127x::frequency = freq;
}
return(state);
}
+4 -25
View File
@@ -3,13 +3,12 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX127X)
#if !RADIOLIB_EXCLUDE_SX127X
#include "SX1278.h"
/*!
\class SX1279
\brief Derived class for %SX1279 modules. Overrides some methods from SX1278 due to different parameter ranges.
*/
class SX1279: public SX1278 {
@@ -19,56 +18,38 @@ class SX1279: public SX1278 {
/*!
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/
SX1279(Module* mod);
SX1279(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
/*!
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 960.0 MHz.
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
Allowed values range from 6 to 65535.
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
Set to 0 to enable automatic gain control (recommended).
\returns \ref status_codes
*/
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
/*!
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of FSK preamble in bits.
\param enableOOK Use OOK modulation instead of FSK.
\returns \ref status_codes
*/
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
@@ -77,14 +58,12 @@ class SX1279: public SX1278 {
/*!
\brief Sets carrier frequency. Allowed values range from 137.0 MHz to 960.0 MHz.
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq);
int16_t setFrequency(float freq) override;
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
private:
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+38 -26
View File
@@ -1,20 +1,22 @@
#include "SX1280.h"
#if !defined(RADIOLIB_EXCLUDE_SX128X)
#include <string.h>
#if !RADIOLIB_EXCLUDE_SX128X
SX1280::SX1280(Module* mod) : SX1281(mod) {
}
int16_t SX1280::range(bool master, uint32_t addr) {
int16_t SX1280::range(bool master, uint32_t addr, uint16_t calTable[3][6]) {
// start ranging
int16_t state = startRanging(master, addr);
int16_t state = startRanging(master, addr, calTable);
RADIOLIB_ASSERT(state);
// wait until ranging is finished
uint32_t start = _mod->millis();
while(!_mod->digitalRead(_mod->getIrq())) {
_mod->yield();
if(_mod->millis() - start > 10000) {
Module* mod = this->getMod();
RadioLibTime_t start = mod->hal->millis();
while(!mod->hal->digitalRead(mod->getIrq())) {
mod->hal->yield();
if(mod->hal->millis() - start > 10000) {
clearIrqStatus();
standby();
return(RADIOLIB_ERR_RANGING_TIMEOUT);
@@ -31,7 +33,7 @@ int16_t SX1280::range(bool master, uint32_t addr) {
return(state);
}
int16_t SX1280::startRanging(bool master, uint32_t addr) {
int16_t SX1280::startRanging(bool master, uint32_t addr, uint16_t calTable[3][6]) {
// check active modem
uint8_t modem = getPacketType();
if(!((modem == RADIOLIB_SX128X_PACKET_TYPE_LORA) || (modem == RADIOLIB_SX128X_PACKET_TYPE_RANGING))) {
@@ -49,21 +51,23 @@ int16_t SX1280::startRanging(bool master, uint32_t addr) {
}
// set modulation parameters
state = setModulationParams(_sf, _bw, _cr);
state = setModulationParams(this->spreadingFactor, this->bandwidth, this->codingRateLoRa);
RADIOLIB_ASSERT(state);
// set packet parameters
state = setPacketParamsLoRa(_preambleLengthLoRa, _headerType, _payloadLen, _crcLoRa);
state = setPacketParamsLoRa(this->preambleLengthLoRa, this->headerType, this->payloadLen, this->crcLoRa);
RADIOLIB_ASSERT(state);
// check all address bits
uint8_t regValue;
state = readRegister(RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_WIDTH, &regValue, 1);
RADIOLIB_ASSERT(state);
regValue &= 0b00111111;
regValue |= 0b11000000;
state = writeRegister(RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_WIDTH, &regValue, 1);
RADIOLIB_ASSERT(state);
if(!master) {
uint8_t regValue;
state = readRegister(RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_WIDTH, &regValue, 1);
RADIOLIB_ASSERT(state);
regValue &= 0b00111111;
regValue |= 0b11000000;
state = writeRegister(RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_WIDTH, &regValue, 1);
RADIOLIB_ASSERT(state);
}
// set remaining parameter values
uint32_t addrReg = RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_3;
@@ -84,23 +88,30 @@ int16_t SX1280::startRanging(bool master, uint32_t addr) {
state = setDioIrqParams(irqMask, irqDio1);
RADIOLIB_ASSERT(state);
// set calibration values
uint8_t index = (_sf >> 4) - 5;
static const uint16_t calTable[3][6] = {
// this is the default calibration from AN1200.29
uint16_t calTbl[3][6] = {
{ 10299, 10271, 10244, 10242, 10230, 10246 },
{ 11486, 11474, 11453, 11426, 11417, 11401 },
{ 13308, 13493, 13528, 13515, 13430, 13376 }
};
// check if user provided some custom calibration
if(calTable != NULL) {
memcpy(calTbl, calTable, sizeof(calTbl));
}
// set calibration values
uint8_t index = (this->spreadingFactor >> 4) - 5;
uint16_t val = 0;
switch(_bw) {
switch(this->bandwidth) {
case(RADIOLIB_SX128X_LORA_BW_406_25):
val = calTable[0][index];
val = calTbl[0][index];
break;
case(RADIOLIB_SX128X_LORA_BW_812_50):
val = calTable[1][index];
val = calTbl[1][index];
break;
case(RADIOLIB_SX128X_LORA_BW_1625_00):
val = calTable[2][index];
val = calTbl[2][index];
break;
default:
return(RADIOLIB_ERR_INVALID_BANDWIDTH);
@@ -165,8 +176,9 @@ float SX1280::getRangingResult() {
RADIOLIB_ASSERT(state);
// calculate the real result
uint32_t raw = ((uint32_t)data[0] << 16) | ((uint32_t)data[1] << 8) | data[2];
return((float)raw * 150.0 / (4.096 * _bwKhz));
uint32_t uraw = ((uint32_t)data[0] << 16) | ((uint32_t)data[1] << 8) | data[2];
int32_t raw = (uraw & ((1UL << 23) - 1)) | (uraw >> 23 << 31);
return((float)raw * 150.0 / (4.096 * this->bandwidthKhz));
}
#endif
+7 -14
View File
@@ -3,7 +3,7 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX128X)
#if !RADIOLIB_EXCLUDE_SX128X
#include "../../Module.h"
#include "SX128x.h"
@@ -11,48 +11,41 @@
/*!
\class SX1280
\brief Derived class for %SX1280 modules.
*/
class SX1280: public SX1281 {
public:
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
SX1280(Module* mod);
SX1280(Module* mod); // cppcheck-suppress noExplicitConstructor
/*!
\brief Blocking ranging method.
\param master Whether to execute ranging in master mode (true) or slave mode (false).
\param addr Ranging address to be used.
\param calTable Ranging calibration table - set to NULL to use the default.
\returns \ref status_codes
*/
int16_t range(bool master, uint32_t addr);
int16_t range(bool master, uint32_t addr, uint16_t calTable[3][6] = NULL);
/*!
\brief Interrupt-driven ranging method.
\param master Whether to execute ranging in master mode (true) or slave mode (false).
\param addr Ranging address to be used.
\param calTable Ranging calibration table - set to NULL to use the default.
\returns \ref status_codes
*/
int16_t startRanging(bool master, uint32_t addr);
int16_t startRanging(bool master, uint32_t addr, uint16_t calTable[3][6] = NULL);
/*!
\brief Gets ranging result of the last ranging exchange.
\returns Ranging result in meters.
*/
float getRangingResult();
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
private:
#endif
+1 -1
View File
@@ -1,5 +1,5 @@
#include "SX1281.h"
#if !defined(RADIOLIB_EXCLUDE_SX128X)
#if !RADIOLIB_EXCLUDE_SX128X
SX1281::SX1281(Module* mod) : SX128x(mod) {
+3 -5
View File
@@ -3,26 +3,24 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX128X)
#if !RADIOLIB_EXCLUDE_SX128X
#include "../../Module.h"
#include "SX128x.h"
/*!
\class SX1281
\brief Derived class for %SX1281 modules.
*/
class SX1281: public SX128x {
public:
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
SX1281(Module* mod);
SX1281(Module* mod); // cppcheck-suppress noExplicitConstructor
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
private:
#endif
+1 -1
View File
@@ -1,5 +1,5 @@
#include "SX1282.h"
#if !defined(RADIOLIB_EXCLUDE_SX128X)
#if !RADIOLIB_EXCLUDE_SX128X
/// \todo implement advanced ranging
SX1282::SX1282(Module* mod) : SX1280(mod) {
+3 -5
View File
@@ -3,7 +3,7 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX128X)
#if !RADIOLIB_EXCLUDE_SX128X
#include "../../Module.h"
#include "SX128x.h"
@@ -11,19 +11,17 @@
/*!
\class SX1282
\brief Derived class for %SX1282 modules.
*/
class SX1282: public SX1280 {
public:
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
SX1282(Module* mod);
SX1282(Module* mod); // cppcheck-suppress noExplicitConstructor
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
private:
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+4 -3
View File
@@ -1,5 +1,5 @@
#include "Si4430.h"
#if !defined(RADIOLIB_EXCLUDE_SI443X)
#if !RADIOLIB_EXCLUDE_SI443X
Si4430::Si4430(Module* mod) : Si4432(mod) {
@@ -9,7 +9,7 @@ int16_t Si4430::begin(float freq, float br, float freqDev, float rxBw, int8_t po
// execute common part
int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen);
RADIOLIB_ASSERT(state);
RADIOLIB_DEBUG_PRINTLN(F("M\tSi4430"));
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSi4430");
// configure publicly accessible settings
state = setFrequency(freq);
@@ -32,7 +32,8 @@ int16_t Si4430::setOutputPower(int8_t power) {
RADIOLIB_CHECK_RANGE(power, -8, 13, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
// set output power
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TX_POWER, (uint8_t)((power + 8) / 3), 2, 0));
Module* mod = this->getMod();
return(mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TX_POWER, (uint8_t)((power + 8) / 3), 2, 0));
}
#endif
+6 -20
View File
@@ -3,14 +3,13 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SI443X)
#if !RADIOLIB_EXCLUDE_SI443X
#include "../../Module.h"
#include "Si4432.h"
/*!
\class Si4430
\brief Derived class for %Si4430 modules.
*/
class Si4430: public Si4432 {
@@ -20,28 +19,20 @@ class Si4430: public Si4432 {
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio chip.
*/
Si4430(Module* mod);
Si4430(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
/*!
\brief Initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 900.0 MHz to 960.0 MHz.
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 0.123 to 256.0 kbps.
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.625 to 320.0 kbps.
\param rxBw Receiver bandwidth in kHz. Allowed values range from 2.6 to 620.7 kHz.
\param power Transmission output power in dBm. Allowed values range from -8 to 13 dBm in 3 dBm steps.
\param preambleLen Preamble Length in bits. Defaults to 16 bits.
\returns \ref status_codes
*/
int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 181.1, int8_t power = 10, uint8_t preambleLen = 16);
@@ -50,28 +41,23 @@ class Si4430: public Si4432 {
/*!
\brief Sets carrier frequency. Allowed values range from 900.0 MHz to 960.0 MHz.
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq);
int16_t setFrequency(float freq) override;
/*!
\brief Sets output power. Allowed values range from -8 to 13 dBm in 3 dBm steps.
\param power Output power to be set in dBm.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power);
int16_t setOutputPower(int8_t power) override;
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
protected:
#endif
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
private:
#endif
};
+4 -3
View File
@@ -1,5 +1,5 @@
#include "Si4431.h"
#if !defined(RADIOLIB_EXCLUDE_SI443X)
#if !RADIOLIB_EXCLUDE_SI443X
Si4431::Si4431(Module* mod) : Si4432(mod) {
@@ -9,7 +9,7 @@ int16_t Si4431::begin(float freq, float br, float freqDev, float rxBw, int8_t po
// execute common part
int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen);
RADIOLIB_ASSERT(state);
RADIOLIB_DEBUG_PRINTLN(F("M\tSi4431"));
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSi4431");
// configure publicly accessible settings
state = setFrequency(freq);
@@ -25,7 +25,8 @@ int16_t Si4431::setOutputPower(int8_t power) {
RADIOLIB_CHECK_RANGE(power, -8, 13, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
// set output power
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TX_POWER, (uint8_t)((power + 8) / 3), 2, 0));
Module* mod = this->getMod();
return(mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TX_POWER, (uint8_t)((power + 8) / 3), 2, 0));
}
#endif
+5 -17
View File
@@ -3,14 +3,13 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SI443X)
#if !RADIOLIB_EXCLUDE_SI443X
#include "../../Module.h"
#include "Si4432.h"
/*!
\class Si4431
\brief Derived class for %Si4431 modules.
*/
class Si4431: public Si4432 {
@@ -20,28 +19,20 @@ class Si4431: public Si4432 {
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio chip.
*/
Si4431(Module* mod);
Si4431(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
/*!
\brief Initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 240.0 MHz to 930.0 MHz.
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 0.123 to 256.0 kbps.
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.625 to 320.0 kbps.
\param rxBw Receiver bandwidth in kHz. Allowed values range from 2.6 to 620.7 kHz.
\param power Transmission output power in dBm. Allowed values range from -8 to 13 dBm in 3 dBm steps.
\param preambleLen Preamble Length in bits. Defaults to 16 bits.
\returns \ref status_codes
*/
int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 181.1, int8_t power = 10, uint8_t preambleLen = 16);
@@ -50,19 +41,16 @@ class Si4431: public Si4432 {
/*!
\brief Sets output power. Allowed values range from -8 to 13 dBm in 3 dBm steps.
\param power Output power to be set in dBm.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power);
int16_t setOutputPower(int8_t power) override;
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
protected:
#endif
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
private:
#endif
};
+4 -3
View File
@@ -1,5 +1,5 @@
#include "Si4432.h"
#if !defined(RADIOLIB_EXCLUDE_SI443X)
#if !RADIOLIB_EXCLUDE_SI443X
Si4432::Si4432(Module* mod) : Si443x(mod) {
@@ -9,7 +9,7 @@ int16_t Si4432::begin(float freq, float br, float freqDev, float rxBw, int8_t po
// execute common part
int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen);
RADIOLIB_ASSERT(state);
RADIOLIB_DEBUG_PRINTLN(F("M\tSi4432"));
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSi4432");
// configure publicly accessible settings
state = setFrequency(freq);
@@ -32,7 +32,8 @@ int16_t Si4432::setOutputPower(int8_t power) {
RADIOLIB_CHECK_RANGE(power, -1, 20, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
// set output power
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TX_POWER, (uint8_t)((power + 1) / 3), 2, 0));
Module* mod = this->getMod();
return(mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TX_POWER, (uint8_t)((power + 1) / 3), 2, 0));
}
#endif
+6 -20
View File
@@ -3,14 +3,13 @@
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SI443X)
#if !RADIOLIB_EXCLUDE_SI443X
#include "../../Module.h"
#include "Si443x.h"
/*!
\class Si4432
\brief Derived class for %Si4432 modules.
*/
class Si4432: public Si443x {
@@ -20,28 +19,20 @@ class Si4432: public Si443x {
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio chip.
*/
Si4432(Module* mod);
Si4432(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
/*!
\brief Initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 240.0 MHz to 930.0 MHz.
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 0.123 to 256.0 kbps.
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.625 to 320.0 kbps.
\param rxBw Receiver bandwidth in kHz. Allowed values range from 2.6 to 620.7 kHz.
\param power Transmission output power in dBm. Allowed values range from -1 to 20 dBm in 3 dBm steps.
\param preambleLen Preamble Length in bits. Defaults to 16 bits.
\returns \ref status_codes
*/
int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 181.1, int8_t power = 10, uint8_t preambleLen = 16);
@@ -50,28 +41,23 @@ class Si4432: public Si443x {
/*!
\brief Sets carrier frequency. Allowed values range from 240.0 MHz to 930.0 MHz.
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq);
int16_t setFrequency(float freq) override;
/*!
\brief Sets output power. Allowed values range from -1 to 20 dBm in 3 dBm steps.
\param power Output power to be set in dBm.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power);
int16_t setOutputPower(int8_t power) override;
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
protected:
#endif
#if !defined(RADIOLIB_GODMODE)
#if !RADIOLIB_GODMODE
private:
#endif
};
+194 -185
View File
@@ -1,32 +1,29 @@
#include "Si443x.h"
#if !defined(RADIOLIB_EXCLUDE_SI443X)
#include <math.h>
#if !RADIOLIB_EXCLUDE_SI443X
Si443x::Si443x(Module* mod) : PhysicalLayer(RADIOLIB_SI443X_FREQUENCY_STEP_SIZE, RADIOLIB_SI443X_MAX_PACKET_LENGTH) {
_mod = mod;
}
Module* Si443x::getMod() {
return(_mod);
this->mod = mod;
}
int16_t Si443x::begin(float br, float freqDev, float rxBw, uint8_t preambleLen) {
// set module properties
_mod->init();
_mod->pinMode(_mod->getIrq(), INPUT);
_mod->pinMode(_mod->getRst(), OUTPUT);
_mod->digitalWrite(_mod->getRst(), LOW);
this->mod->init();
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
this->mod->hal->pinMode(this->mod->getRst(), this->mod->hal->GpioModeOutput);
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
// try to find the Si443x chip
if(!Si443x::findChip()) {
RADIOLIB_DEBUG_PRINTLN(F("No Si443x found!"));
_mod->term();
RADIOLIB_DEBUG_BASIC_PRINTLN("No Si443x found!");
this->mod->term();
return(RADIOLIB_ERR_CHIP_NOT_FOUND);
} else {
RADIOLIB_DEBUG_PRINTLN(F("M\tSi443x"));
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSi443x");
}
// reset the device
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_SOFTWARE_RESET);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_SOFTWARE_RESET);
// clear POR interrupt
clearIRQFlags();
@@ -67,53 +64,46 @@ int16_t Si443x::begin(float br, float freqDev, float rxBw, uint8_t preambleLen)
}
void Si443x::reset() {
_mod->pinMode(_mod->getRst(), OUTPUT);
_mod->digitalWrite(_mod->getRst(), HIGH);
_mod->delay(1);
_mod->digitalWrite(_mod->getRst(), LOW);
_mod->delay(100);
this->mod->hal->pinMode(this->mod->getRst(), this->mod->hal->GpioModeOutput);
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh);
this->mod->hal->delay(1);
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
this->mod->hal->delay(100);
}
int16_t Si443x::transmit(uint8_t* data, size_t len, uint8_t addr) {
int16_t Si443x::transmit(const uint8_t* data, size_t len, uint8_t addr) {
// calculate timeout (5ms + 500 % of expected time-on-air)
uint32_t timeout = 5000000 + (uint32_t)((((float)(len * 8)) / (_br * 1000.0)) * 5000000.0);
RadioLibTime_t timeout = 5 + (uint32_t)((((float)(len * 8)) / this->bitRate) * 5);
// start transmission
int16_t state = startTransmit(data, len, addr);
RADIOLIB_ASSERT(state);
// wait for transmission end or timeout
uint32_t start = _mod->micros();
while(_mod->digitalRead(_mod->getIrq())) {
_mod->yield();
if(_mod->micros() - start > timeout) {
standby();
clearIRQFlags();
RadioLibTime_t start = this->mod->hal->millis();
while(this->mod->hal->digitalRead(this->mod->getIrq())) {
this->mod->hal->yield();
if(this->mod->hal->millis() - start > timeout) {
finishTransmit();
return(RADIOLIB_ERR_TX_TIMEOUT);
}
}
// clear interrupt flags
clearIRQFlags();
// set mode to standby
standby();
return(state);
return(finishTransmit());
}
int16_t Si443x::receive(uint8_t* data, size_t len) {
// calculate timeout (500 ms + 400 full 64-byte packets at current bit rate)
uint32_t timeout = 500000 + (1.0/(_br*1000.0))*(RADIOLIB_SI443X_MAX_PACKET_LENGTH*400.0);
RadioLibTime_t timeout = 500 + (1.0/(this->bitRate))*(RADIOLIB_SI443X_MAX_PACKET_LENGTH*400.0);
// start reception
int16_t state = startReceive();
RADIOLIB_ASSERT(state);
// wait for packet reception or timeout
uint32_t start = _mod->micros();
while(_mod->digitalRead(_mod->getIrq())) {
if(_mod->micros() - start > timeout) {
RadioLibTime_t start = this->mod->hal->millis();
while(this->mod->hal->digitalRead(this->mod->getIrq())) {
if(this->mod->hal->millis() - start > timeout) {
standby();
clearIRQFlags();
return(RADIOLIB_ERR_RX_TIMEOUT);
@@ -126,30 +116,33 @@ int16_t Si443x::receive(uint8_t* data, size_t len) {
int16_t Si443x::sleep() {
// set RF switch (if present)
_mod->setRfSwitchState(LOW, LOW);
this->mod->setRfSwitchState(Module::MODE_IDLE);
// disable wakeup timer interrupt
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_1, 0x00);
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_1, 0x00);
RADIOLIB_ASSERT(state);
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
RADIOLIB_ASSERT(state);
// enable wakeup timer to set mode to sleep
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_ENABLE_WAKEUP_TIMER);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_ENABLE_WAKEUP_TIMER);
return(state);
}
int16_t Si443x::standby() {
// set RF switch (if present)
_mod->setRfSwitchState(LOW, LOW);
return(standby(RADIOLIB_SI443X_XTAL_ON));
}
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_XTAL_ON, 7, 0, 10));
int16_t Si443x::standby(uint8_t mode) {
// set RF switch (if present)
this->mod->setRfSwitchState(Module::MODE_IDLE);
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, mode, 7, 0, 10));
}
int16_t Si443x::transmitDirect(uint32_t frf) {
// set RF switch (if present)
_mod->setRfSwitchState(LOW, HIGH);
this->mod->setRfSwitchState(Module::MODE_TX);
// user requested to start transmitting immediately (required for RTTY)
if(frf != 0) {
@@ -169,13 +162,13 @@ int16_t Si443x::transmitDirect(uint32_t frf) {
uint16_t freqCarrier = ((newFreq / (10 * ((bandSelect >> 5) + 1))) - freqBand - 24) * (uint32_t)64000;
// update registers
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_FREQUENCY_BAND_SELECT, RADIOLIB_SI443X_SIDE_BAND_SELECT_LOW | bandSelect | freqBand);
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_1, (uint8_t)((freqCarrier & 0xFF00) >> 8));
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_0, (uint8_t)(freqCarrier & 0xFF));
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_FREQUENCY_BAND_SELECT, RADIOLIB_SI443X_SIDE_BAND_SELECT_LOW | bandSelect | freqBand);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_1, (uint8_t)((freqCarrier & 0xFF00) >> 8));
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_0, (uint8_t)(freqCarrier & 0xFF));
// start direct transmission
directMode();
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_TX_ON | RADIOLIB_SI443X_XTAL_ON);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_TX_ON | RADIOLIB_SI443X_XTAL_ON);
return(RADIOLIB_ERR_NONE);
}
@@ -185,39 +178,55 @@ int16_t Si443x::transmitDirect(uint32_t frf) {
RADIOLIB_ASSERT(state);
// start transmitting
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_TX_ON | RADIOLIB_SI443X_XTAL_ON);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_TX_ON | RADIOLIB_SI443X_XTAL_ON);
return(state);
}
int16_t Si443x::receiveDirect() {
// set RF switch (if present)
_mod->setRfSwitchState(HIGH, LOW);
this->mod->setRfSwitchState(Module::MODE_RX);
// activate direct mode
int16_t state = directMode();
RADIOLIB_ASSERT(state);
// start receiving
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_RX_ON | RADIOLIB_SI443X_XTAL_ON);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_RX_ON | RADIOLIB_SI443X_XTAL_ON);
return(state);
}
int16_t Si443x::packetMode() {
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_MODULATION_FSK, 1, 0);
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_MODULATION_FSK, 1, 0);
RADIOLIB_ASSERT(state);
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_TX_DATA_SOURCE_FIFO, 5, 4));
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_TX_DATA_SOURCE_FIFO, 5, 4));
}
void Si443x::setIrqAction(void (*func)(void)) {
_mod->attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()), func, FALLING);
this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()), func, this->mod->hal->GpioInterruptFalling);
}
void Si443x::clearIrqAction() {
_mod->detachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()));
this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()));
}
int16_t Si443x::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
void Si443x::setPacketReceivedAction(void (*func)(void)) {
this->setIrqAction(func);
}
void Si443x::clearPacketReceivedAction() {
this->clearIrqAction();
}
void Si443x::setPacketSentAction(void (*func)(void)) {
this->setIrqAction(func);
}
void Si443x::clearPacketSentAction() {
this->clearIrqAction();
}
int16_t Si443x::startTransmit(const uint8_t* data, size_t len, uint8_t addr) {
// check packet length
if(len > RADIOLIB_SI443X_MAX_PACKET_LENGTH) {
return(RADIOLIB_ERR_PACKET_TOO_LONG);
@@ -228,61 +237,77 @@ int16_t Si443x::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
RADIOLIB_ASSERT(state);
// clear Tx FIFO
_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_TX_FIFO_RESET, 0, 0);
_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_TX_FIFO_CLEAR, 0, 0);
this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_TX_FIFO_RESET, 0, 0);
this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_TX_FIFO_CLEAR, 0, 0);
// clear interrupt flags
clearIRQFlags();
// set packet length
if (_packetLengthConfig == RADIOLIB_SI443X_FIXED_PACKET_LENGTH_OFF) {
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH, len);
if (this->packetLengthConfig == RADIOLIB_SI443X_FIXED_PACKET_LENGTH_OFF) {
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH, len);
}
/// \todo use header as address field?
(void)addr;
// write packet to FIFO
_mod->SPIwriteRegisterBurst(RADIOLIB_SI443X_REG_FIFO_ACCESS, data, len);
this->mod->SPIwriteRegisterBurst(RADIOLIB_SI443X_REG_FIFO_ACCESS, const_cast<uint8_t*>(data), len);
// set RF switch (if present)
_mod->setRfSwitchState(LOW, HIGH);
this->mod->setRfSwitchState(Module::MODE_TX);
// set interrupt mapping
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_1, RADIOLIB_SI443X_PACKET_SENT_ENABLED);
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_1, RADIOLIB_SI443X_PACKET_SENT_ENABLED);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
// set mode to transmit
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_TX_ON | RADIOLIB_SI443X_XTAL_ON);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_TX_ON | RADIOLIB_SI443X_XTAL_ON);
return(state);
}
int16_t Si443x::finishTransmit() {
// clear interrupt flags
clearIRQFlags();
// set mode to standby to disable transmitter/RF switch
return(standby());
}
int16_t Si443x::startReceive() {
// set mode to standby
int16_t state = standby();
RADIOLIB_ASSERT(state);
// clear Rx FIFO
_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_RX_FIFO_RESET, 1, 1);
_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_RX_FIFO_CLEAR, 1, 1);
this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_RX_FIFO_RESET, 1, 1);
this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_RX_FIFO_CLEAR, 1, 1);
// clear interrupt flags
clearIRQFlags();
// set RF switch (if present)
_mod->setRfSwitchState(HIGH, LOW);
this->mod->setRfSwitchState(Module::MODE_RX);
// set interrupt mapping
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_1, RADIOLIB_SI443X_VALID_PACKET_RECEIVED_ENABLED | RADIOLIB_SI443X_CRC_ERROR_ENABLED);
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_1, RADIOLIB_SI443X_VALID_PACKET_RECEIVED_ENABLED | RADIOLIB_SI443X_CRC_ERROR_ENABLED);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
// set mode to receive
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_RX_ON | RADIOLIB_SI443X_XTAL_ON);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_RX_ON | RADIOLIB_SI443X_XTAL_ON);
return(state);
}
int16_t Si443x::startReceive(uint32_t timeout, uint32_t irqFlags, uint32_t irqMask, size_t len) {
(void)timeout;
(void)irqFlags;
(void)irqMask;
(void)len;
return(startReceive());
}
int16_t Si443x::readData(uint8_t* data, size_t len) {
// clear interrupt flags
clearIRQFlags();
@@ -297,7 +322,7 @@ int16_t Si443x::readData(uint8_t* data, size_t len) {
}
// read packet data
_mod->SPIreadRegisterBurst(RADIOLIB_SI443X_REG_FIFO_ACCESS, length, data);
this->mod->SPIreadRegisterBurst(RADIOLIB_SI443X_REG_FIFO_ACCESS, length, data);
// dump the bytes that weren't requested
if(dumpLen != 0) {
@@ -305,7 +330,7 @@ int16_t Si443x::readData(uint8_t* data, size_t len) {
}
// clear internal flag so getPacketLength can return the new packet length
_packetLengthQueried = false;
this->packetLengthQueried = false;
// set mode to standby
int16_t state = standby();
@@ -333,12 +358,12 @@ int16_t Si443x::setBitRate(float br) {
uint16_t txDr = (br * ((uint32_t)1 << exp)) / 1000.0;
// update registers
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, dataRateMode, 5, 5);
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_TX_DATA_RATE_1, (uint8_t)((txDr & 0xFF00) >> 8));
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_TX_DATA_RATE_0, (uint8_t)(txDr & 0xFF));
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, dataRateMode, 5, 5);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_TX_DATA_RATE_1, (uint8_t)((txDr & 0xFF00) >> 8));
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_TX_DATA_RATE_0, (uint8_t)(txDr & 0xFF));
if(state == RADIOLIB_ERR_NONE) {
_br = br;
this->bitRate = br;
}
RADIOLIB_ASSERT(state);
@@ -361,11 +386,11 @@ int16_t Si443x::setFrequencyDeviation(float freqDev) {
uint16_t fdev = (uint16_t)(newFreqDev / 0.625);
// update registers
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, (uint8_t)((fdev & 0x0100) >> 6), 2, 2);
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_FREQUENCY_DEVIATION, (uint8_t)(fdev & 0xFF));
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, (uint8_t)((fdev & 0x0100) >> 6), 2, 2);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_FREQUENCY_DEVIATION, (uint8_t)(fdev & 0xFF));
if(state == RADIOLIB_ERR_NONE) {
_freqDev = newFreqDev;
this->frequencyDev = newFreqDev;
}
return(state);
@@ -401,63 +426,63 @@ int16_t Si443x::setRxBandwidth(float rxBw) {
// this is the "Lord help thee who tread 'ere" section - no way to approximate this mess
/// \todo float tolerance equality as macro?
} else if(fabs(rxBw - 142.8) <= 0.001) {
} else if(fabsf(rxBw - 142.8) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 1;
filterSet = 4;
} else if(fabs(rxBw - 167.8) <= 0.001) {
} else if(fabsf(rxBw - 167.8) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 1;
filterSet = 5;
} else if(fabs(rxBw - 181.1) <= 0.001) {
} else if(fabsf(rxBw - 181.1) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 1;
filterSet = 6;
} else if(fabs(rxBw - 191.5) <= 0.001) {
} else if(fabsf(rxBw - 191.5) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0;
filterSet = 15;
} else if(fabs(rxBw - 225.1) <= 0.001) {
} else if(fabsf(rxBw - 225.1) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0;
filterSet = 1;
} else if(fabs(rxBw - 248.8) <= 0.001) {
} else if(fabsf(rxBw - 248.8) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0;
filterSet = 2;
} else if(fabs(rxBw - 269.3) <= 0.001) {
} else if(fabsf(rxBw - 269.3) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0;
filterSet = 3;
} else if(fabs(rxBw - 284.8) <= 0.001) {
} else if(fabsf(rxBw - 284.8) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0;
filterSet = 4;
} else if(fabs(rxBw -335.5) <= 0.001) {
} else if(fabsf(rxBw -335.5) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0;
filterSet = 8;
} else if(fabs(rxBw - 391.8) <= 0.001) {
} else if(fabsf(rxBw - 391.8) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0;
filterSet = 9;
} else if(fabs(rxBw - 420.2) <= 0.001) {
} else if(fabsf(rxBw - 420.2) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0;
filterSet = 10;
} else if(fabs(rxBw - 468.4) <= 0.001) {
} else if(fabsf(rxBw - 468.4) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0;
filterSet = 11;
} else if(fabs(rxBw - 518.8) <= 0.001) {
} else if(fabsf(rxBw - 518.8) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0;
filterSet = 12;
} else if(fabs(rxBw - 577.0) <= 0.001) {
} else if(fabsf(rxBw - 577.0) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0;
filterSet = 13;
} else if(fabs(rxBw - 620.7) <= 0.001) {
} else if(fabsf(rxBw - 620.7) <= 0.001) {
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0;
filterSet = 14;
@@ -469,7 +494,7 @@ int16_t Si443x::setRxBandwidth(float rxBw) {
decRate <<= 4;
// update register
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_IF_FILTER_BANDWIDTH, bypass | decRate | filterSet);
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_IF_FILTER_BANDWIDTH, bypass | decRate | filterSet);
RADIOLIB_ASSERT(state);
// update clock recovery
@@ -486,11 +511,11 @@ int16_t Si443x::setSyncWord(uint8_t* syncWord, size_t len) {
RADIOLIB_ASSERT(state);
// set sync word length
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_2, (uint8_t)(len - 1) << 1, 2, 1);
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_2, (uint8_t)(len - 1) << 1, 2, 1);
RADIOLIB_ASSERT(state);
// set sync word bytes
_mod->SPIwriteRegisterBurst(RADIOLIB_SI443X_REG_SYNC_WORD_3, syncWord, len);
this->mod->SPIwriteRegisterBurst(RADIOLIB_SI443X_REG_SYNC_WORD_3, syncWord, len);
return(state);
}
@@ -503,25 +528,25 @@ int16_t Si443x::setPreambleLength(uint8_t preambleLen) {
// set default preamble length
uint8_t preLenNibbles = preambleLen / 4;
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_PREAMBLE_LENGTH, preLenNibbles);
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_PREAMBLE_LENGTH, preLenNibbles);
RADIOLIB_ASSERT(state);
// set default preamble detection threshold to 5/8 of preamble length (in units of 4 bits)
uint8_t preThreshold = 5*preLenNibbles / 8;
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_PREAMBLE_DET_CONTROL, preThreshold << 3, 7, 3));
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_PREAMBLE_DET_CONTROL, preThreshold << 3, 7, 3));
}
size_t Si443x::getPacketLength(bool update) {
if(!_packetLengthQueried && update) {
if (_packetLengthConfig == RADIOLIB_SI443X_FIXED_PACKET_LENGTH_ON) {
_packetLength = _mod->SPIreadRegister(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH);
if(!this->packetLengthQueried && update) {
if (this->packetLengthConfig == RADIOLIB_SI443X_FIXED_PACKET_LENGTH_ON) {
this->packetLength = this->mod->SPIreadRegister(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH);
} else {
_packetLength = _mod->SPIreadRegister(RADIOLIB_SI443X_REG_RECEIVED_PACKET_LENGTH);
this->packetLength = this->mod->SPIreadRegister(RADIOLIB_SI443X_REG_RECEIVED_PACKET_LENGTH);
}
_packetLengthQueried = true;
this->packetLengthQueried = true;
}
return(_packetLength);
return(this->packetLength);
}
int16_t Si443x::setEncoding(uint8_t encoding) {
@@ -533,11 +558,11 @@ int16_t Si443x::setEncoding(uint8_t encoding) {
/// \todo - add inverted Manchester?
switch(encoding) {
case RADIOLIB_ENCODING_NRZ:
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_INVERTED_OFF | RADIOLIB_SI443X_MANCHESTER_OFF | RADIOLIB_SI443X_WHITENING_OFF, 2, 0));
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_OFF | RADIOLIB_SI443X_WHITENING_OFF, 2, 0));
case RADIOLIB_ENCODING_MANCHESTER:
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_INVERTED_OFF | RADIOLIB_SI443X_MANCHESTER_ON | RADIOLIB_SI443X_WHITENING_OFF, 2, 0));
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_ON | RADIOLIB_SI443X_WHITENING_OFF, 2, 0));
case RADIOLIB_ENCODING_WHITENING:
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_INVERTED_OFF | RADIOLIB_SI443X_MANCHESTER_OFF | RADIOLIB_SI443X_WHITENING_ON, 2, 0));
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_OFF | RADIOLIB_SI443X_WHITENING_ON, 2, 0));
default:
return(RADIOLIB_ERR_INVALID_ENCODING);
}
@@ -551,32 +576,33 @@ int16_t Si443x::setDataShaping(uint8_t sh) {
// set data shaping
switch(sh) {
case RADIOLIB_SHAPING_NONE:
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_INVERTED_OFF | RADIOLIB_SI443X_MANCHESTER_OFF | RADIOLIB_SI443X_WHITENING_OFF, 2, 0));
case RADIOLIB_SHAPING_0_3:
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_INVERTED_OFF | RADIOLIB_SI443X_MANCHESTER_OFF | RADIOLIB_SI443X_WHITENING_OFF, 2, 0));
case RADIOLIB_SHAPING_0_5:
case RADIOLIB_SHAPING_1_0:
/// \todo implement fiter configuration - docs claim this should be possible, but seems undocumented
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_INVERTED_OFF | RADIOLIB_SI443X_MANCHESTER_OFF | RADIOLIB_SI443X_WHITENING_ON, 2, 0));
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_MODULATION_GFSK, 1, 0));
default:
return(RADIOLIB_ERR_INVALID_ENCODING);
}
}
void Si443x::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) {
_mod->setRfSwitchPins(rxEn, txEn);
void Si443x::setRfSwitchPins(uint32_t rxEn, uint32_t txEn) {
this->mod->setRfSwitchPins(rxEn, txEn);
}
void Si443x::setRfSwitchTable(const uint32_t (&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[]) {
this->mod->setRfSwitchTable(pins, table);
}
uint8_t Si443x::randomByte() {
// set mode to Rx
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_RX_ON | RADIOLIB_SI443X_XTAL_ON);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_RX_ON | RADIOLIB_SI443X_XTAL_ON);
// wait a bit for the RSSI reading to stabilise
_mod->delay(10);
this->mod->hal->delay(10);
// read RSSI value 8 times, always keep just the least significant bit
uint8_t randByte = 0x00;
for(uint8_t i = 0; i < 8; i++) {
randByte |= ((_mod->SPIreadRegister(RADIOLIB_SI443X_REG_RSSI) & 0x01) << i);
randByte |= ((this->mod->SPIreadRegister(RADIOLIB_SI443X_REG_RSSI) & 0x01) << i);
}
// set mode to standby
@@ -586,16 +612,16 @@ uint8_t Si443x::randomByte() {
}
int16_t Si443x::getChipVersion() {
return(_mod->SPIgetRegValue(RADIOLIB_SI443X_REG_DEVICE_VERSION));
return(this->mod->SPIgetRegValue(RADIOLIB_SI443X_REG_DEVICE_VERSION));
}
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
void Si443x::setDirectAction(void (*func)(void)) {
setIrqAction(func);
}
void Si443x::readBit(RADIOLIB_PIN_TYPE pin) {
updateDirectBuffer((uint8_t)digitalRead(pin));
void Si443x::readBit(uint32_t pin) {
updateDirectBuffer((uint8_t)this->mod->hal->digitalRead(pin));
}
#endif
@@ -607,6 +633,10 @@ int16_t Si443x::variablePacketLengthMode(uint8_t maxLen) {
return(Si443x::setPacketMode(RADIOLIB_SI443X_FIXED_PACKET_LENGTH_OFF, maxLen));
}
Module* Si443x::getMod() {
return(this->mod);
}
int16_t Si443x::setFrequencyRaw(float newFreq) {
// set mode to standby
int16_t state = standby();
@@ -616,7 +646,7 @@ int16_t Si443x::setFrequencyRaw(float newFreq) {
uint8_t bandSelect = RADIOLIB_SI443X_BAND_SELECT_LOW;
uint8_t freqBand = (newFreq / 10) - 24;
uint8_t afcLimiter = 80;
_freq = newFreq;
this->frequency = newFreq;
if(newFreq >= 480.0) {
bandSelect = RADIOLIB_SI443X_BAND_SELECT_HIGH;
freqBand = (newFreq / 20) - 24;
@@ -627,10 +657,10 @@ int16_t Si443x::setFrequencyRaw(float newFreq) {
uint16_t freqCarrier = ((newFreq / (10 * ((bandSelect >> 5) + 1))) - freqBand - 24) * (uint32_t)64000;
// update registers
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_FREQUENCY_BAND_SELECT, bandSelect | freqBand, 5, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_1, (uint8_t)((freqCarrier & 0xFF00) >> 8));
state |= _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_0, (uint8_t)(freqCarrier & 0xFF));
state |= _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_AFC_LIMITER, afcLimiter);
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_FREQUENCY_BAND_SELECT, bandSelect | freqBand, 5, 0);
state |= this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_1, (uint8_t)((freqCarrier & 0xFF00) >> 8));
state |= this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_0, (uint8_t)(freqCarrier & 0xFF));
state |= this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_AFC_LIMITER, afcLimiter);
return(state);
}
@@ -642,15 +672,15 @@ int16_t Si443x::setPacketMode(uint8_t mode, uint8_t len) {
}
// set to fixed packet length
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_2, mode, 3, 3);
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_2, mode, 3, 3);
RADIOLIB_ASSERT(state);
// set length to register
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH, len);
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH, len);
RADIOLIB_ASSERT(state);
// update cached value
_packetLengthConfig = mode;
this->packetLengthConfig = mode;
return(state);
}
@@ -662,22 +692,12 @@ bool Si443x::findChip() {
reset();
// check version register
uint8_t version = _mod->SPIreadRegister(RADIOLIB_SI443X_REG_DEVICE_VERSION);
uint8_t version = this->mod->SPIreadRegister(RADIOLIB_SI443X_REG_DEVICE_VERSION);
if(version == RADIOLIB_SI443X_DEVICE_VERSION) {
flagFound = true;
} else {
#if defined(RADIOLIB_DEBUG)
RADIOLIB_DEBUG_PRINT(F("Si443x not found! ("));
RADIOLIB_DEBUG_PRINT(i + 1);
RADIOLIB_DEBUG_PRINT(F(" of 10 tries) RADIOLIB_SI443X_REG_DEVICE_VERSION == "));
char buffHex[5];
sprintf(buffHex, "0x%02X", version);
RADIOLIB_DEBUG_PRINT(buffHex);
RADIOLIB_DEBUG_PRINT(F(", expected 0x00"));
RADIOLIB_DEBUG_PRINTLN(RADIOLIB_SI443X_DEVICE_VERSION, HEX);
#endif
_mod->delay(10);
RADIOLIB_DEBUG_BASIC_PRINTLN("Si443x not found! (%d of 10 tries) RADIOLIB_SI443X_REG_DEVICE_VERSION == 0x%02X, expected 0x0%X", i + 1, version, RADIOLIB_SI443X_DEVICE_VERSION);
this->mod->hal->delay(10);
i++;
}
}
@@ -687,12 +707,12 @@ bool Si443x::findChip() {
void Si443x::clearIRQFlags() {
uint8_t buff[2];
_mod->SPIreadRegisterBurst(RADIOLIB_SI443X_REG_INTERRUPT_STATUS_1, 2, buff);
this->mod->SPIreadRegisterBurst(RADIOLIB_SI443X_REG_INTERRUPT_STATUS_1, 2, buff);
}
void Si443x::clearFIFO(size_t count) {
while(count) {
_mod->SPIreadRegister(RADIOLIB_SI443X_REG_FIFO_ACCESS);
this->mod->SPIreadRegister(RADIOLIB_SI443X_REG_FIFO_ACCESS);
count--;
}
}
@@ -703,22 +723,22 @@ int16_t Si443x::config() {
RADIOLIB_ASSERT(state);
// disable POR and chip ready interrupts
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
// enable AGC
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_AGC_OVERRIDE_1, RADIOLIB_SI443X_AGC_GAIN_INCREASE_ON | RADIOLIB_SI443X_AGC_ON, 6, 5);
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_AGC_OVERRIDE_1, RADIOLIB_SI443X_AGC_GAIN_INCREASE_ON | RADIOLIB_SI443X_AGC_ON, 6, 5);
RADIOLIB_ASSERT(state);
// disable packet header
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_2, RADIOLIB_SI443X_SYNC_WORD_TIMEOUT_OFF | RADIOLIB_SI443X_HEADER_LENGTH_HEADER_NONE, 7, 4);
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_2, RADIOLIB_SI443X_SYNC_WORD_TIMEOUT_OFF | RADIOLIB_SI443X_HEADER_LENGTH_HEADER_NONE, 7, 4);
RADIOLIB_ASSERT(state);
// set antenna switching
_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO0_CONFIG, RADIOLIB_SI443X_GPIOX_TX_STATE_OUT, 4, 0);
_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO1_CONFIG, RADIOLIB_SI443X_GPIOX_RX_STATE_OUT, 4, 0);
this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO0_CONFIG, RADIOLIB_SI443X_GPIOX_TX_STATE_OUT, 4, 0);
this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO1_CONFIG, RADIOLIB_SI443X_GPIOX_RX_STATE_OUT, 4, 0);
// disable packet header checking
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_1, RADIOLIB_SI443X_BROADCAST_ADDR_CHECK_NONE | RADIOLIB_SI443X_RECEIVED_HEADER_CHECK_NONE);
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_1, RADIOLIB_SI443X_BROADCAST_ADDR_CHECK_NONE | RADIOLIB_SI443X_RECEIVED_HEADER_CHECK_NONE);
RADIOLIB_ASSERT(state);
return(state);
@@ -726,9 +746,9 @@ int16_t Si443x::config() {
int16_t Si443x::updateClockRecovery() {
// get the parameters
uint8_t bypass = _mod->SPIgetRegValue(RADIOLIB_SI443X_REG_IF_FILTER_BANDWIDTH, 7, 7) >> 7;
uint8_t decRate = _mod->SPIgetRegValue(RADIOLIB_SI443X_REG_IF_FILTER_BANDWIDTH, 6, 4) >> 4;
uint8_t manch = _mod->SPIgetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, 1, 1) >> 1;
uint8_t bypass = this->mod->SPIgetRegValue(RADIOLIB_SI443X_REG_IF_FILTER_BANDWIDTH, 7, 7) >> 7;
uint8_t decRate = this->mod->SPIgetRegValue(RADIOLIB_SI443X_REG_IF_FILTER_BANDWIDTH, 6, 4) >> 4;
uint8_t manch = this->mod->SPIgetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, 1, 1) >> 1;
// calculate oversampling ratio, NCO offset and clock recovery gain
int8_t ndecExp = (int8_t)decRate - 3;
@@ -739,61 +759,50 @@ int16_t Si443x::updateClockRecovery() {
ndecExp *= -1;
ndec = 1.0/(float)((uint16_t)1 << ndecExp);
}
float rxOsr = ((float)(500 * (1 + 2*bypass))) / (ndec * _br * ((float)(1 + manch)));
uint32_t ncoOff = (_br * (1 + manch) * ((uint32_t)(1) << (20 + decRate))) / (500 * (1 + 2*bypass));
uint16_t crGain = 2 + (((float)(65536.0 * (1 + manch)) * _br) / (rxOsr * (_freqDev / 0.625)));
float rxOsr = ((float)(500 * (1 + 2*bypass))) / (ndec * this->bitRate * ((float)(1 + manch)));
uint32_t ncoOff = (this->bitRate * (1 + manch) * ((uint32_t)(1) << (20 + decRate))) / (500 * (1 + 2*bypass));
uint16_t crGain = 2 + (((float)(65536.0 * (1 + manch)) * this->bitRate) / (rxOsr * (this->frequencyDev / 0.625)));
uint16_t rxOsr_fixed = (uint16_t)rxOsr;
// print that whole mess
RADIOLIB_DEBUG_PRINTLN(bypass, HEX);
RADIOLIB_DEBUG_PRINTLN(decRate, HEX);
RADIOLIB_DEBUG_PRINTLN(manch, HEX);
RADIOLIB_DEBUG_PRINT(rxOsr, 3);
RADIOLIB_DEBUG_PRINT('\t');
RADIOLIB_DEBUG_PRINT(rxOsr_fixed);
RADIOLIB_DEBUG_PRINT('\t');
RADIOLIB_DEBUG_PRINTLN(rxOsr_fixed, HEX);
RADIOLIB_DEBUG_PRINT(ncoOff);
RADIOLIB_DEBUG_PRINT('\t');
RADIOLIB_DEBUG_PRINTLN(ncoOff, HEX);
RADIOLIB_DEBUG_PRINT(crGain);
RADIOLIB_DEBUG_PRINT('\t');
RADIOLIB_DEBUG_PRINTLN(crGain, HEX);
RADIOLIB_DEBUG_BASIC_PRINTLN("%X\n%X\n%X", bypass, decRate, manch);
RADIOLIB_DEBUG_BASIC_PRINT_FLOAT(rxOsr, 2);
RADIOLIB_DEBUG_BASIC_PRINTLN("\t%d\t%X\n%lu\t%lX\n%d\t%X", rxOsr_fixed, rxOsr_fixed, (long unsigned int)ncoOff, (long unsigned int)ncoOff, crGain, crGain);
// update oversampling ratio
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_2, (uint8_t)((rxOsr_fixed & 0x0700) >> 3), 7, 5);
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_2, (uint8_t)((rxOsr_fixed & 0x0700) >> 3), 7, 5);
RADIOLIB_ASSERT(state);
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OVERSAMP_RATIO, (uint8_t)(rxOsr_fixed & 0x00FF));
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OVERSAMP_RATIO, (uint8_t)(rxOsr_fixed & 0x00FF));
RADIOLIB_ASSERT(state);
// update NCO offset
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_2, (uint8_t)((ncoOff & 0x0F0000) >> 16), 3, 0);
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_2, (uint8_t)((ncoOff & 0x0F0000) >> 16), 3, 0);
RADIOLIB_ASSERT(state);
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_1, (uint8_t)((ncoOff & 0x00FF00) >> 8));
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_1, (uint8_t)((ncoOff & 0x00FF00) >> 8));
RADIOLIB_ASSERT(state);
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_0, (uint8_t)(ncoOff & 0x0000FF));
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_0, (uint8_t)(ncoOff & 0x0000FF));
RADIOLIB_ASSERT(state);
// update clock recovery loop gain
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_TIMING_LOOP_GAIN_1, (uint8_t)((crGain & 0x0700) >> 8), 2, 0);
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_TIMING_LOOP_GAIN_1, (uint8_t)((crGain & 0x0700) >> 8), 2, 0);
RADIOLIB_ASSERT(state);
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_TIMING_LOOP_GAIN_0, (uint8_t)(crGain & 0x00FF));
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_TIMING_LOOP_GAIN_0, (uint8_t)(crGain & 0x00FF));
RADIOLIB_ASSERT(state);
return(state);
}
int16_t Si443x::directMode() {
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_TX_DATA_SOURCE_GPIO, 5, 4);
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_TX_DATA_SOURCE_GPIO, 5, 4);
RADIOLIB_ASSERT(state);
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO1_CONFIG, RADIOLIB_SI443X_GPIOX_TX_RX_DATA_CLK_OUT, 4, 0);
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO1_CONFIG, RADIOLIB_SI443X_GPIOX_TX_RX_DATA_CLK_OUT, 4, 0);
RADIOLIB_ASSERT(state);
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO2_CONFIG, RADIOLIB_SI443X_GPIOX_TX_DATA_IN, 4, 0);
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO2_CONFIG, RADIOLIB_SI443X_GPIOX_TX_DATA_IN, 4, 0);
RADIOLIB_ASSERT(state);
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_MODULATION_FSK, 1, 0);
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_MODULATION_FSK, 1, 0);
return(state);
}
File diff suppressed because it is too large Load Diff
+220 -169
View File
@@ -1,36 +1,33 @@
#include "nRF24.h"
#if !defined(RADIOLIB_EXCLUDE_NRF24)
#include <string.h>
#if !RADIOLIB_EXCLUDE_NRF24
nRF24::nRF24(Module* mod) : PhysicalLayer(RADIOLIB_NRF24_FREQUENCY_STEP_SIZE, RADIOLIB_NRF24_MAX_PACKET_LENGTH) {
_mod = mod;
this->mod = mod;
}
Module* nRF24::getMod() {
return(_mod);
}
int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrWidth) {
int16_t nRF24::begin(int16_t freq, int16_t dr, int8_t pwr, uint8_t addrWidth) {
// set module properties
_mod->SPIreadCommand = RADIOLIB_NRF24_CMD_READ;
_mod->SPIwriteCommand = RADIOLIB_NRF24_CMD_WRITE;
_mod->init();
_mod->pinMode(_mod->getIrq(), INPUT);
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] = RADIOLIB_NRF24_CMD_READ;
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] = RADIOLIB_NRF24_CMD_WRITE;
this->mod->init();
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
// set pin mode on RST (connected to nRF24 CE pin)
_mod->pinMode(_mod->getRst(), OUTPUT);
_mod->digitalWrite(_mod->getRst(), LOW);
this->mod->hal->pinMode(this->mod->getRst(), this->mod->hal->GpioModeOutput);
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
// wait for minimum power-on reset duration
_mod->delay(100);
this->mod->hal->delay(100);
// check SPI connection
int16_t val = _mod->SPIgetRegValue(RADIOLIB_NRF24_REG_SETUP_AW);
int16_t val = this->mod->SPIgetRegValue(RADIOLIB_NRF24_REG_SETUP_AW);
if(!((val >= 0) && (val <= 3))) {
RADIOLIB_DEBUG_PRINTLN(F("No nRF24 found!"));
_mod->term();
RADIOLIB_DEBUG_BASIC_PRINTLN("No nRF24 found!");
this->mod->term();
return(RADIOLIB_ERR_CHIP_NOT_FOUND);
}
RADIOLIB_DEBUG_PRINTLN(F("M\tnRF24"));
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tnRF24");
// configure settings inaccessible by public API
int16_t state = config();
@@ -45,11 +42,11 @@ int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrW
RADIOLIB_ASSERT(state);
// set data rate
state = setDataRate(dataRate);
state = setBitRate(dr);
RADIOLIB_ASSERT(state);
// set output power
state = setOutputPower(power);
state = setOutputPower(pwr);
RADIOLIB_ASSERT(state);
// set address width
@@ -68,48 +65,47 @@ int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrW
}
int16_t nRF24::sleep() {
return(_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_POWER_DOWN, 1, 1));
return(this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_POWER_DOWN, 1, 1));
}
int16_t nRF24::standby() {
// make sure carrier output is disabled
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_CONT_WAVE_OFF, 7, 7);
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_PLL_LOCK_OFF, 4, 4);
_mod->digitalWrite(_mod->getRst(), LOW);
// use standby-1 mode
return(_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_POWER_UP, 1, 1));
return(standby(RADIOLIB_NRF24_POWER_UP));
}
int16_t nRF24::transmit(uint8_t* data, size_t len, uint8_t addr) {
int16_t nRF24::standby(uint8_t mode) {
// make sure carrier output is disabled
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_CONT_WAVE_OFF, 7, 7);
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_PLL_LOCK_OFF, 4, 4);
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
// use standby-1 mode
return(this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, mode, 1, 1));
}
int16_t nRF24::transmit(const uint8_t* data, size_t len, uint8_t addr) {
// start transmission
int16_t state = startTransmit(data, len, addr);
RADIOLIB_ASSERT(state);
// wait until transmission is finished
uint32_t start = _mod->micros();
while(_mod->digitalRead(_mod->getIrq())) {
_mod->yield();
uint32_t start = this->mod->hal->millis();
while(this->mod->hal->digitalRead(this->mod->getIrq())) {
this->mod->hal->yield();
// check maximum number of retransmits
if(getStatus(RADIOLIB_NRF24_MAX_RT)) {
standby();
clearIRQ();
finishTransmit();
return(RADIOLIB_ERR_ACK_NOT_RECEIVED);
}
// check timeout: 15 retries * 4ms (max Tx time as per datasheet)
if(_mod->micros() - start >= 60000) {
standby();
clearIRQ();
// check timeout: 15 retries * 4ms (max Tx time as per datasheet) + 10 ms
if(this->mod->hal->millis() - start >= ((15 * 4) + 10)) {
finishTransmit();
return(RADIOLIB_ERR_TX_TIMEOUT);
}
}
// clear interrupts
clearIRQ();
return(state);
return(finishTransmit());
}
int16_t nRF24::receive(uint8_t* data, size_t len) {
@@ -118,12 +114,12 @@ int16_t nRF24::receive(uint8_t* data, size_t len) {
RADIOLIB_ASSERT(state);
// wait for Rx_DataReady or timeout
uint32_t start = _mod->micros();
while(_mod->digitalRead(_mod->getIrq())) {
_mod->yield();
uint32_t start = this->mod->hal->millis();
while(this->mod->hal->digitalRead(this->mod->getIrq())) {
this->mod->hal->yield();
// check timeout: 15 retries * 4ms (max Tx time as per datasheet)
if(_mod->micros() - start >= 60000) {
// check timeout: 15 retries * 4ms (max Tx time as per datasheet) + 10 ms
if(this->mod->hal->millis() - start >= ((15 * 4) + 10)) {
standby();
clearIRQ();
return(RADIOLIB_ERR_RX_TIMEOUT);
@@ -138,14 +134,14 @@ int16_t nRF24::transmitDirect(uint32_t frf) {
// set raw frequency value
if(frf != 0) {
uint8_t freqRaw = frf - 2400;
_mod->SPIwriteRegister(RADIOLIB_NRF24_REG_RF_CH, freqRaw & 0b01111111);
this->mod->SPIwriteRegister(RADIOLIB_NRF24_REG_RF_CH, freqRaw & 0b01111111);
}
// output carrier
int16_t state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PTX, 0, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_CONT_WAVE_ON, 7, 7);
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_PLL_LOCK_ON, 4, 4);
_mod->digitalWrite(_mod->getRst(), HIGH);
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PTX, 0, 0);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_CONT_WAVE_ON, 7, 7);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_PLL_LOCK_ON, 4, 4);
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh);
return(state);
}
@@ -156,10 +152,30 @@ int16_t nRF24::receiveDirect() {
}
void nRF24::setIrqAction(void (*func)(void)) {
_mod->attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()), func, FALLING);
this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()), func, this->mod->hal->GpioInterruptFalling);
}
int16_t nRF24::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
void nRF24::clearIrqAction() {
this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()));
}
void nRF24::setPacketReceivedAction(void (*func)(void)) {
this->setIrqAction(func);
}
void nRF24::clearPacketReceivedAction() {
this->clearIrqAction();
}
void nRF24::setPacketSentAction(void (*func)(void)) {
this->setIrqAction(func);
}
void nRF24::clearPacketSentAction() {
this->clearIrqAction();
}
int16_t nRF24::startTransmit(const uint8_t* data, size_t len, uint8_t addr) {
// suppress unused variable warning
(void)addr;
@@ -173,13 +189,13 @@ int16_t nRF24::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
RADIOLIB_ASSERT(state);
// enable primary Tx mode
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PTX, 0, 0);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PTX, 0, 0);
// clear interrupts
clearIRQ();
// enable Tx_DataSent interrupt
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_TX_DS_IRQ_ON, 5, 5);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_TX_DS_IRQ_ON, 5, 5);
RADIOLIB_ASSERT(state);
// flush Tx FIFO
@@ -189,42 +205,58 @@ int16_t nRF24::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
uint8_t buff[32];
memset(buff, 0x00, 32);
memcpy(buff, data, len);
SPIwriteTxPayload(data, len);
SPIwriteTxPayload(const_cast<uint8_t*>(data), len);
// CE high to start transmitting
_mod->digitalWrite(_mod->getRst(), HIGH);
_mod->delay(1);
_mod->digitalWrite(_mod->getRst(), LOW);
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh);
this->mod->hal->delay(1);
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
return(state);
}
int16_t nRF24::finishTransmit() {
// clear interrupt flags
clearIRQ();
// set mode to standby to disable transmitter/RF switch
return(standby());
}
int16_t nRF24::startReceive() {
// set mode to standby
int16_t state = standby();
RADIOLIB_ASSERT(state);
// enable primary Rx mode
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PRX, 0, 0);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PRX, 0, 0);
RADIOLIB_ASSERT(state);
// enable Rx_DataReady interrupt
clearIRQ();
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_RX_DR_IRQ_ON, 6, 6);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_RX_DR_IRQ_ON, 6, 6);
RADIOLIB_ASSERT(state);
// flush Rx FIFO
SPItransfer(RADIOLIB_NRF24_CMD_FLUSH_RX);
// CE high to start receiving
_mod->digitalWrite(_mod->getRst(), HIGH);
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh);
// wait to enter Rx state
_mod->delay(1);
this->mod->hal->delay(1);
return(state);
}
int16_t nRF24::startReceive(uint32_t timeout, uint32_t irqFlags, uint32_t irqMask, size_t len) {
(void)timeout;
(void)irqFlags;
(void)irqMask;
(void)len;
return(startReceive());
}
int16_t nRF24::readData(uint8_t* data, size_t len) {
// set mode to standby
int16_t state = standby();
@@ -246,44 +278,56 @@ int16_t nRF24::readData(uint8_t* data, size_t len) {
return(RADIOLIB_ERR_NONE);
}
int16_t nRF24::setFrequency(int16_t freq) {
RADIOLIB_CHECK_RANGE(freq, 2400, 2525, RADIOLIB_ERR_INVALID_FREQUENCY);
int16_t nRF24::setFrequency(float freq) {
RADIOLIB_CHECK_RANGE((uint16_t)freq, 2400, 2525, RADIOLIB_ERR_INVALID_FREQUENCY);
// set frequency
uint8_t freqRaw = freq - 2400;
return(_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_CH, freqRaw, 6, 0));
}
uint8_t freqRaw = (uint16_t)freq - 2400;
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_CH, freqRaw, 6, 0);
int16_t nRF24::setDataRate(int16_t dataRate) {
// set mode to standby
int16_t state = standby();
RADIOLIB_ASSERT(state);
// set data rate
if(dataRate == 250) {
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 5, 5);
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 3, 3);
} else if(dataRate == 1000) {
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 5, 5);
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 3, 3);
} else if(dataRate == 2000) {
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 5, 5);
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 3, 3);
} else {
return(RADIOLIB_ERR_INVALID_DATA_RATE);
if(state == RADIOLIB_ERR_NONE) {
this->frequency = freq;
}
return(state);
}
int16_t nRF24::setOutputPower(int8_t power) {
int16_t nRF24::setBitRate(float br) {
// set mode to standby
int16_t state = standby();
RADIOLIB_ASSERT(state);
// set data rate
uint16_t bitRate = (uint16_t)br;
if(bitRate == 250) {
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 5, 5);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 3, 3);
} else if(bitRate == 1000) {
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 5, 5);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 3, 3);
} else if(bitRate == 2000) {
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 5, 5);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 3, 3);
} else {
return(RADIOLIB_ERR_INVALID_DATA_RATE);
}
if(state == RADIOLIB_ERR_NONE) {
this->dataRate = bitRate;
}
return(state);
}
int16_t nRF24::setOutputPower(int8_t pwr) {
// set mode to standby
int16_t state = standby();
RADIOLIB_ASSERT(state);
// check allowed values
uint8_t powerRaw = 0;
switch(power) {
switch(pwr) {
case -18:
powerRaw = RADIOLIB_NRF24_RF_PWR_18_DBM;
break;
@@ -301,7 +345,12 @@ int16_t nRF24::setOutputPower(int8_t power) {
}
// write new register value
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, powerRaw, 2, 1);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, powerRaw, 2, 1);
if(state == RADIOLIB_ERR_NONE) {
this->power = pwr;
}
return(state);
}
@@ -315,23 +364,25 @@ int16_t nRF24::setAddressWidth(uint8_t addrWidth) {
case 2:
// Even if marked as 'Illegal' on the datasheet this will work:
// http://travisgoodspeed.blogspot.com/2011/02/promiscuity-is-nrf24l01s-duty.html
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_2_BYTES, 1, 0);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_2_BYTES, 1, 0);
break;
case 3:
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_3_BYTES, 1, 0);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_3_BYTES, 1, 0);
break;
case 4:
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_4_BYTES, 1, 0);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_4_BYTES, 1, 0);
break;
case 5:
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_5_BYTES, 1, 0);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_5_BYTES, 1, 0);
break;
default:
return(RADIOLIB_ERR_INVALID_ADDRESS_WIDTH);
}
// save address width
_addrWidth = addrWidth;
if(state == RADIOLIB_ERR_NONE) {
this->addressWidth = addrWidth;
}
return(state);
}
@@ -342,11 +393,11 @@ int16_t nRF24::setTransmitPipe(uint8_t* addr) {
RADIOLIB_ASSERT(state);
// set transmit address
_mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_TX_ADDR, addr, _addrWidth);
this->mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_TX_ADDR, addr, this->addressWidth);
// set Rx pipe 0 address (for ACK)
_mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P0, addr, _addrWidth);
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_ON, 0, 0);
this->mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P0, addr, this->addressWidth);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_ON, 0, 0);
return(state);
}
@@ -359,12 +410,12 @@ int16_t nRF24::setReceivePipe(uint8_t pipeNum, uint8_t* addr) {
// write full pipe 0 - 1 address and enable the pipe
switch(pipeNum) {
case 0:
_mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P0, addr, _addrWidth);
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_ON, 0, 0);
this->mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P0, addr, this->addressWidth);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_ON, 0, 0);
break;
case 1:
_mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P1, addr, _addrWidth);
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P1_ON, 1, 1);
this->mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P1, addr, this->addressWidth);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P1_ON, 1, 1);
break;
default:
return(RADIOLIB_ERR_INVALID_PIPE_NUMBER);
@@ -381,20 +432,20 @@ int16_t nRF24::setReceivePipe(uint8_t pipeNum, uint8_t addrByte) {
// write unique pipe 2 - 5 address and enable the pipe
switch(pipeNum) {
case 2:
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P2, addrByte);
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P2_ON, 2, 2);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P2, addrByte);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P2_ON, 2, 2);
break;
case 3:
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P3, addrByte);
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P3_ON, 3, 3);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P3, addrByte);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P3_ON, 3, 3);
break;
case 4:
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P4, addrByte);
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P4_ON, 4, 4);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P4, addrByte);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P4_ON, 4, 4);
break;
case 5:
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P5, addrByte);
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P5_ON, 5, 5);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P5, addrByte);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P5_ON, 5, 5);
break;
default:
return(RADIOLIB_ERR_INVALID_PIPE_NUMBER);
@@ -410,22 +461,22 @@ int16_t nRF24::disablePipe(uint8_t pipeNum) {
switch(pipeNum) {
case 0:
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_OFF, 0, 0);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_OFF, 0, 0);
break;
case 1:
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P1_OFF, 1, 1);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P1_OFF, 1, 1);
break;
case 2:
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P2_OFF, 2, 2);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P2_OFF, 2, 2);
break;
case 3:
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P3_OFF, 3, 3);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P3_OFF, 3, 3);
break;
case 4:
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P4_OFF, 4, 4);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P4_OFF, 4, 4);
break;
case 5:
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P5_OFF, 5, 5);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P5_OFF, 5, 5);
break;
default:
return(RADIOLIB_ERR_INVALID_PIPE_NUMBER);
@@ -435,11 +486,11 @@ int16_t nRF24::disablePipe(uint8_t pipeNum) {
}
int16_t nRF24::getStatus(uint8_t mask) {
return(_mod->SPIgetRegValue(RADIOLIB_NRF24_REG_STATUS) & mask);
return(this->mod->SPIgetRegValue(RADIOLIB_NRF24_REG_STATUS) & mask);
}
bool nRF24::isCarrierDetected() {
return(_mod->SPIgetRegValue(RADIOLIB_NRF24_REG_RPD, 0, 0) == 1);
return(this->mod->SPIgetRegValue(RADIOLIB_NRF24_REG_RPD, 0, 0) == 1);
}
int16_t nRF24::setFrequencyDeviation(float freqDev) {
@@ -464,32 +515,32 @@ int16_t nRF24::setCrcFiltering(bool crcOn) {
}
// Disable CRC
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, (crcOn ? RADIOLIB_NRF24_CRC_ON : RADIOLIB_NRF24_CRC_OFF), 3, 3);
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, (crcOn ? RADIOLIB_NRF24_CRC_ON : RADIOLIB_NRF24_CRC_OFF), 3, 3);
}
int16_t nRF24::setAutoAck(bool autoAckOn){
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_ALL_ON : RADIOLIB_NRF24_AA_ALL_OFF), 5, 0);
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_ALL_ON : RADIOLIB_NRF24_AA_ALL_OFF), 5, 0);
}
int16_t nRF24::setAutoAck(uint8_t pipeNum, bool autoAckOn){
switch(pipeNum) {
case 0:
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P0_ON : RADIOLIB_NRF24_AA_P0_OFF), 0, 0);
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P0_ON : RADIOLIB_NRF24_AA_P0_OFF), 0, 0);
break;
case 1:
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P1_ON : RADIOLIB_NRF24_AA_P1_OFF), 1, 1);
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P1_ON : RADIOLIB_NRF24_AA_P1_OFF), 1, 1);
break;
case 2:
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P2_ON : RADIOLIB_NRF24_AA_P2_OFF), 2, 2);
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P2_ON : RADIOLIB_NRF24_AA_P2_OFF), 2, 2);
break;
case 3:
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P3_ON : RADIOLIB_NRF24_AA_P3_OFF), 3, 3);
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P3_ON : RADIOLIB_NRF24_AA_P3_OFF), 3, 3);
break;
case 4:
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P4_ON : RADIOLIB_NRF24_AA_P4_OFF), 4, 4);
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P4_ON : RADIOLIB_NRF24_AA_P4_OFF), 4, 4);
break;
case 5:
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P5_ON : RADIOLIB_NRF24_AA_P5_OFF), 5, 5);
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P5_ON : RADIOLIB_NRF24_AA_P5_OFF), 5, 5);
break;
default:
return (RADIOLIB_ERR_INVALID_PIPE_NUMBER);
@@ -510,67 +561,51 @@ int16_t nRF24::setEncoding(uint8_t encoding) {
return(RADIOLIB_ERR_NONE);
}
uint8_t nRF24::randomByte() {
// nRF24 is unable to measure RSSI, hence no TRNG
// this method is implemented only for PhysicalLayer compatibility
return(0);
}
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
void nRF24::setDirectAction(void (*func)(void)) {
// nRF24 is unable to perform direct mode actions
// this method is implemented only for PhysicalLayer compatibility
(void)func;
}
void nRF24::readBit(RADIOLIB_PIN_TYPE pin) {
// nRF24 is unable to perform direct mode actions
// this method is implemented only for PhysicalLayer compatibility
(void)pin;
}
#endif
void nRF24::clearIRQ() {
// clear status bits
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_STATUS, RADIOLIB_NRF24_RX_DR | RADIOLIB_NRF24_TX_DS | RADIOLIB_NRF24_MAX_RT, 6, 4);
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_STATUS, RADIOLIB_NRF24_RX_DR | RADIOLIB_NRF24_TX_DS | RADIOLIB_NRF24_MAX_RT, 6, 4);
// disable interrupts
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_RX_DR_IRQ_OFF | RADIOLIB_NRF24_MASK_TX_DS_IRQ_OFF | RADIOLIB_NRF24_MASK_MAX_RT_IRQ_OFF, 6, 4);
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_RX_DR_IRQ_OFF | RADIOLIB_NRF24_MASK_TX_DS_IRQ_OFF | RADIOLIB_NRF24_MASK_MAX_RT_IRQ_OFF, 6, 4);
}
int16_t nRF24::config() {
// enable 16-bit CRC
int16_t state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_CRC_ON | RADIOLIB_NRF24_CRC_16, 3, 2);
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_CRC_ON | RADIOLIB_NRF24_CRC_16, 3, 2);
RADIOLIB_ASSERT(state);
// set 15 retries and delay 1500 (5*250) us
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_RETR, (5 << 4) | 5);
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_RETR, (5 << 4) | 5);
// set features: dynamic payload on, payload with ACK packets off, dynamic ACK off
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_FEATURE, RADIOLIB_NRF24_DPL_ON | RADIOLIB_NRF24_ACK_PAY_OFF | RADIOLIB_NRF24_DYN_ACK_OFF, 2, 0);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_FEATURE, RADIOLIB_NRF24_DPL_ON | RADIOLIB_NRF24_ACK_PAY_OFF | RADIOLIB_NRF24_DYN_ACK_OFF, 2, 0);
RADIOLIB_ASSERT(state);
// enable dynamic payloads
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_DYNPD, RADIOLIB_NRF24_DPL_ALL_ON, 5, 0);
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_DYNPD, RADIOLIB_NRF24_DPL_ALL_ON, 5, 0);
RADIOLIB_ASSERT(state);
// reset IRQ
clearIRQ();
// clear status
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_STATUS, RADIOLIB_NRF24_RX_DR | RADIOLIB_NRF24_TX_DS | RADIOLIB_NRF24_MAX_RT, 6, 4);
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_STATUS, RADIOLIB_NRF24_RX_DR | RADIOLIB_NRF24_TX_DS | RADIOLIB_NRF24_MAX_RT, 6, 4);
// flush FIFOs
SPItransfer(RADIOLIB_NRF24_CMD_FLUSH_TX);
SPItransfer(RADIOLIB_NRF24_CMD_FLUSH_RX);
// power up
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_POWER_UP, 1, 1);
_mod->delay(5);
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_POWER_UP, 1, 1);
this->mod->hal->delay(5);
return(state);
}
Module* nRF24::getMod() {
return(this->mod);
}
void nRF24::SPIreadRxPayload(uint8_t* data, uint8_t numBytes) {
SPItransfer(RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD, false, NULL, data, numBytes);
}
@@ -580,27 +615,43 @@ void nRF24::SPIwriteTxPayload(uint8_t* data, uint8_t numBytes) {
}
void nRF24::SPItransfer(uint8_t cmd, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes) {
// start transfer
_mod->digitalWrite(_mod->getCs(), LOW);
_mod->SPIbeginTransaction();
// prepare the buffers
size_t buffLen = 1 + numBytes;
#if RADIOLIB_STATIC_ONLY
uint8_t buffOut[RADIOLIB_STATIC_ARRAY_SIZE];
uint8_t buffIn[RADIOLIB_STATIC_ARRAY_SIZE];
#else
uint8_t* buffOut = new uint8_t[buffLen];
uint8_t* buffIn = new uint8_t[buffLen];
#endif
uint8_t* buffOutPtr = buffOut;
// send command
_mod->SPItransfer(cmd);
// copy the command
*(buffOutPtr++) = cmd;
// send data
// copy the data
if(write) {
for(uint8_t i = 0; i < numBytes; i++) {
_mod->SPItransfer(dataOut[i]);
}
memcpy(buffOutPtr, dataOut, numBytes);
} else {
for(uint8_t i = 0; i < numBytes; i++) {
dataIn[i] = _mod->SPItransfer(0x00);
}
memset(buffOutPtr, 0x00, numBytes);
}
// stop transfer
_mod->SPIendTransaction();
_mod->digitalWrite(_mod->getCs(), HIGH);
// do the transfer
this->mod->hal->digitalWrite(this->mod->getCs(), this->mod->hal->GpioLevelLow);
this->mod->hal->spiBeginTransaction();
this->mod->hal->spiTransfer(buffOut, buffLen, buffIn);
this->mod->hal->spiEndTransaction();
this->mod->hal->digitalWrite(this->mod->getCs(), this->mod->hal->GpioLevelHigh);
// copy the data
if(!write) {
memcpy(dataIn, &buffIn[1], numBytes);
}
#if !RADIOLIB_STATIC_ONLY
delete[] buffOut;
delete[] buffIn;
#endif
}
#endif
+246 -266
View File
@@ -1,4 +1,4 @@
#if !defined(_RADIOLIB_NRF24_H) && !defined(RADIOLIB_EXCLUDE_NRF24)
#if !defined(_RADIOLIB_NRF24_H) && !RADIOLIB_EXCLUDE_NRF24
#define _RADIOLIB_NRF24_H
#include "../../Module.h"
@@ -7,173 +7,178 @@
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
// nRF24 physical layer properties
#define RADIOLIB_NRF24_FREQUENCY_STEP_SIZE 1000000.0
#define RADIOLIB_NRF24_MAX_PACKET_LENGTH 32
#define RADIOLIB_NRF24_FREQUENCY_STEP_SIZE 1000000.0
#define RADIOLIB_NRF24_MAX_PACKET_LENGTH 32
// nRF24 SPI commands
#define RADIOLIB_NRF24_CMD_READ 0b00000000
#define RADIOLIB_NRF24_CMD_WRITE 0b00100000
#define RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD 0b01100001
#define RADIOLIB_NRF24_CMD_WRITE_TX_PAYLOAD 0b10100000
#define RADIOLIB_NRF24_CMD_FLUSH_TX 0b11100001
#define RADIOLIB_NRF24_CMD_FLUSH_RX 0b11100010
#define RADIOLIB_NRF24_CMD_REUSE_TX_PAXLOAD 0b11100011
#define RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD_WIDTH 0b01100000
#define RADIOLIB_NRF24_CMD_WRITE_ACK_PAYLOAD 0b10101000
#define RADIOLIB_NRF24_CMD_WRITE_TX_PAYLOAD_NOACK 0b10110000
#define RADIOLIB_NRF24_CMD_NOP 0b11111111
#define RADIOLIB_NRF24_CMD_READ 0b00000000
#define RADIOLIB_NRF24_CMD_WRITE 0b00100000
#define RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD 0b01100001
#define RADIOLIB_NRF24_CMD_WRITE_TX_PAYLOAD 0b10100000
#define RADIOLIB_NRF24_CMD_FLUSH_TX 0b11100001
#define RADIOLIB_NRF24_CMD_FLUSH_RX 0b11100010
#define RADIOLIB_NRF24_CMD_REUSE_TX_PAXLOAD 0b11100011
#define RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD_WIDTH 0b01100000
#define RADIOLIB_NRF24_CMD_WRITE_ACK_PAYLOAD 0b10101000
#define RADIOLIB_NRF24_CMD_WRITE_TX_PAYLOAD_NOACK 0b10110000
#define RADIOLIB_NRF24_CMD_NOP 0b11111111
// nRF24 register map
#define RADIOLIB_NRF24_REG_CONFIG 0x00
#define RADIOLIB_NRF24_REG_EN_AA 0x01
#define RADIOLIB_NRF24_REG_EN_RXADDR 0x02
#define RADIOLIB_NRF24_REG_SETUP_AW 0x03
#define RADIOLIB_NRF24_REG_SETUP_RETR 0x04
#define RADIOLIB_NRF24_REG_RF_CH 0x05
#define RADIOLIB_NRF24_REG_RF_SETUP 0x06
#define RADIOLIB_NRF24_REG_STATUS 0x07
#define RADIOLIB_NRF24_REG_OBSERVE_TX 0x08
#define RADIOLIB_NRF24_REG_RPD 0x09
#define RADIOLIB_NRF24_REG_RX_ADDR_P0 0x0A
#define RADIOLIB_NRF24_REG_RX_ADDR_P1 0x0B
#define RADIOLIB_NRF24_REG_RX_ADDR_P2 0x0C
#define RADIOLIB_NRF24_REG_RX_ADDR_P3 0x0D
#define RADIOLIB_NRF24_REG_RX_ADDR_P4 0x0E
#define RADIOLIB_NRF24_REG_RX_ADDR_P5 0x0F
#define RADIOLIB_NRF24_REG_TX_ADDR 0x10
#define RADIOLIB_NRF24_REG_RX_PW_P0 0x11
#define RADIOLIB_NRF24_REG_RX_PW_P1 0x12
#define RADIOLIB_NRF24_REG_RX_PW_P2 0x13
#define RADIOLIB_NRF24_REG_RX_PW_P3 0x14
#define RADIOLIB_NRF24_REG_RX_PW_P4 0x15
#define RADIOLIB_NRF24_REG_RX_PW_P5 0x16
#define RADIOLIB_NRF24_REG_FIFO_STATUS 0x17
#define RADIOLIB_NRF24_REG_DYNPD 0x1C
#define RADIOLIB_NRF24_REG_FEATURE 0x1D
#define RADIOLIB_NRF24_REG_CONFIG 0x00
#define RADIOLIB_NRF24_REG_EN_AA 0x01
#define RADIOLIB_NRF24_REG_EN_RXADDR 0x02
#define RADIOLIB_NRF24_REG_SETUP_AW 0x03
#define RADIOLIB_NRF24_REG_SETUP_RETR 0x04
#define RADIOLIB_NRF24_REG_RF_CH 0x05
#define RADIOLIB_NRF24_REG_RF_SETUP 0x06
#define RADIOLIB_NRF24_REG_STATUS 0x07
#define RADIOLIB_NRF24_REG_OBSERVE_TX 0x08
#define RADIOLIB_NRF24_REG_RPD 0x09
#define RADIOLIB_NRF24_REG_RX_ADDR_P0 0x0A
#define RADIOLIB_NRF24_REG_RX_ADDR_P1 0x0B
#define RADIOLIB_NRF24_REG_RX_ADDR_P2 0x0C
#define RADIOLIB_NRF24_REG_RX_ADDR_P3 0x0D
#define RADIOLIB_NRF24_REG_RX_ADDR_P4 0x0E
#define RADIOLIB_NRF24_REG_RX_ADDR_P5 0x0F
#define RADIOLIB_NRF24_REG_TX_ADDR 0x10
#define RADIOLIB_NRF24_REG_RX_PW_P0 0x11
#define RADIOLIB_NRF24_REG_RX_PW_P1 0x12
#define RADIOLIB_NRF24_REG_RX_PW_P2 0x13
#define RADIOLIB_NRF24_REG_RX_PW_P3 0x14
#define RADIOLIB_NRF24_REG_RX_PW_P4 0x15
#define RADIOLIB_NRF24_REG_RX_PW_P5 0x16
#define RADIOLIB_NRF24_REG_FIFO_STATUS 0x17
#define RADIOLIB_NRF24_REG_DYNPD 0x1C
#define RADIOLIB_NRF24_REG_FEATURE 0x1D
// NRF24_REG_CONFIG MSB LSB DESCRIPTION
#define RADIOLIB_NRF24_MASK_RX_DR_IRQ_OFF 0b01000000 // 6 6 RX_DR will not be reflected on IRQ pin
#define RADIOLIB_NRF24_MASK_RX_DR_IRQ_ON 0b00000000 // 6 6 RX_DR will be reflected on IRQ pin as active low (default)
#define RADIOLIB_NRF24_MASK_TX_DS_IRQ_OFF 0b00100000 // 5 5 TX_DS will not be reflected on IRQ pin
#define RADIOLIB_NRF24_MASK_TX_DS_IRQ_ON 0b00000000 // 5 5 TX_DS will be reflected on IRQ pin as active low (default)
#define RADIOLIB_NRF24_MASK_MAX_RT_IRQ_OFF 0b00010000 // 4 4 MAX_RT will not be reflected on IRQ pin
#define RADIOLIB_NRF24_MASK_MAX_RT_IRQ_ON 0b00000000 // 4 4 MAX_RT will be reflected on IRQ pin as active low (default)
#define RADIOLIB_NRF24_CRC_OFF 0b00000000 // 3 3 CRC calculation: disabled
#define RADIOLIB_NRF24_CRC_ON 0b00001000 // 3 3 enabled (default)
#define RADIOLIB_NRF24_CRC_8 0b00000000 // 2 2 CRC scheme: CRC8 (default)
#define RADIOLIB_NRF24_CRC_16 0b00000100 // 2 2 CRC16
#define RADIOLIB_NRF24_POWER_UP 0b00000010 // 1 1 power up
#define RADIOLIB_NRF24_POWER_DOWN 0b00000000 // 1 1 power down
#define RADIOLIB_NRF24_PTX 0b00000000 // 0 0 enable primary Tx
#define RADIOLIB_NRF24_PRX 0b00000001 // 0 0 enable primary Rx
// RADIOLIB_NRF24_REG_CONFIG MSB LSB DESCRIPTION
#define RADIOLIB_NRF24_MASK_RX_DR_IRQ_OFF 0b01000000 // 6 6 RX_DR will not be reflected on IRQ pin
#define RADIOLIB_NRF24_MASK_RX_DR_IRQ_ON 0b00000000 // 6 6 RX_DR will be reflected on IRQ pin as active low (default)
#define RADIOLIB_NRF24_MASK_TX_DS_IRQ_OFF 0b00100000 // 5 5 TX_DS will not be reflected on IRQ pin
#define RADIOLIB_NRF24_MASK_TX_DS_IRQ_ON 0b00000000 // 5 5 TX_DS will be reflected on IRQ pin as active low (default)
#define RADIOLIB_NRF24_MASK_MAX_RT_IRQ_OFF 0b00010000 // 4 4 MAX_RT will not be reflected on IRQ pin
#define RADIOLIB_NRF24_MASK_MAX_RT_IRQ_ON 0b00000000 // 4 4 MAX_RT will be reflected on IRQ pin as active low (default)
#define RADIOLIB_NRF24_CRC_OFF 0b00000000 // 3 3 CRC calculation: disabled
#define RADIOLIB_NRF24_CRC_ON 0b00001000 // 3 3 enabled (default)
#define RADIOLIB_NRF24_CRC_8 0b00000000 // 2 2 CRC scheme: CRC8 (default)
#define RADIOLIB_NRF24_CRC_16 0b00000100 // 2 2 CRC16
#define RADIOLIB_NRF24_POWER_UP 0b00000010 // 1 1 power up
#define RADIOLIB_NRF24_POWER_DOWN 0b00000000 // 1 1 power down
#define RADIOLIB_NRF24_PTX 0b00000000 // 0 0 enable primary Tx
#define RADIOLIB_NRF24_PRX 0b00000001 // 0 0 enable primary Rx
// NRF24_REG_EN_AA
#define RADIOLIB_NRF24_AA_ALL_OFF 0b00000000 // 5 0 auto-ACK on all pipes: disabled
#define RADIOLIB_NRF24_AA_ALL_ON 0b00111111 // 5 0 enabled (default)
#define RADIOLIB_NRF24_AA_P5_OFF 0b00000000 // 5 5 auto-ACK on pipe 5: disabled
#define RADIOLIB_NRF24_AA_P5_ON 0b00100000 // 5 5 enabled (default)
#define RADIOLIB_NRF24_AA_P4_OFF 0b00000000 // 4 4 auto-ACK on pipe 4: disabled
#define RADIOLIB_NRF24_AA_P4_ON 0b00010000 // 4 4 enabled (default)
#define RADIOLIB_NRF24_AA_P3_OFF 0b00000000 // 3 3 auto-ACK on pipe 3: disabled
#define RADIOLIB_NRF24_AA_P3_ON 0b00001000 // 3 3 enabled (default)
#define RADIOLIB_NRF24_AA_P2_OFF 0b00000000 // 2 2 auto-ACK on pipe 2: disabled
#define RADIOLIB_NRF24_AA_P2_ON 0b00000100 // 2 2 enabled (default)
#define RADIOLIB_NRF24_AA_P1_OFF 0b00000000 // 1 1 auto-ACK on pipe 1: disabled
#define RADIOLIB_NRF24_AA_P1_ON 0b00000010 // 1 1 enabled (default)
#define RADIOLIB_NRF24_AA_P0_OFF 0b00000000 // 0 0 auto-ACK on pipe 0: disabled
#define RADIOLIB_NRF24_AA_P0_ON 0b00000001 // 0 0 enabled (default)
// RADIOLIB_NRF24_REG_EN_AA
#define RADIOLIB_NRF24_AA_ALL_OFF 0b00000000 // 5 0 auto-ACK on all pipes: disabled
#define RADIOLIB_NRF24_AA_ALL_ON 0b00111111 // 5 0 enabled (default)
#define RADIOLIB_NRF24_AA_P5_OFF 0b00000000 // 5 5 auto-ACK on pipe 5: disabled
#define RADIOLIB_NRF24_AA_P5_ON 0b00100000 // 5 5 enabled (default)
#define RADIOLIB_NRF24_AA_P4_OFF 0b00000000 // 4 4 auto-ACK on pipe 4: disabled
#define RADIOLIB_NRF24_AA_P4_ON 0b00010000 // 4 4 enabled (default)
#define RADIOLIB_NRF24_AA_P3_OFF 0b00000000 // 3 3 auto-ACK on pipe 3: disabled
#define RADIOLIB_NRF24_AA_P3_ON 0b00001000 // 3 3 enabled (default)
#define RADIOLIB_NRF24_AA_P2_OFF 0b00000000 // 2 2 auto-ACK on pipe 2: disabled
#define RADIOLIB_NRF24_AA_P2_ON 0b00000100 // 2 2 enabled (default)
#define RADIOLIB_NRF24_AA_P1_OFF 0b00000000 // 1 1 auto-ACK on pipe 1: disabled
#define RADIOLIB_NRF24_AA_P1_ON 0b00000010 // 1 1 enabled (default)
#define RADIOLIB_NRF24_AA_P0_OFF 0b00000000 // 0 0 auto-ACK on pipe 0: disabled
#define RADIOLIB_NRF24_AA_P0_ON 0b00000001 // 0 0 enabled (default)
// NRF24_REG_EN_RXADDR
#define RADIOLIB_NRF24_P5_OFF 0b00000000 // 5 5 receive pipe 5: disabled (default)
#define RADIOLIB_NRF24_P5_ON 0b00100000 // 5 5 enabled
#define RADIOLIB_NRF24_P4_OFF 0b00000000 // 4 4 receive pipe 4: disabled (default)
#define RADIOLIB_NRF24_P4_ON 0b00010000 // 4 4 enabled
#define RADIOLIB_NRF24_P3_OFF 0b00000000 // 3 3 receive pipe 3: disabled (default)
#define RADIOLIB_NRF24_P3_ON 0b00001000 // 3 3 enabled
#define RADIOLIB_NRF24_P2_OFF 0b00000000 // 2 2 receive pipe 2: disabled (default)
#define RADIOLIB_NRF24_P2_ON 0b00000100 // 2 2 enabled
#define RADIOLIB_NRF24_P1_OFF 0b00000000 // 1 1 receive pipe 1: disabled
#define RADIOLIB_NRF24_P1_ON 0b00000010 // 1 1 enabled (default)
#define RADIOLIB_NRF24_P0_OFF 0b00000000 // 0 0 receive pipe 0: disabled
#define RADIOLIB_NRF24_P0_ON 0b00000001 // 0 0 enabled (default)
// RADIOLIB_NRF24_REG_EN_RXADDR
#define RADIOLIB_NRF24_P5_OFF 0b00000000 // 5 5 receive pipe 5: disabled (default)
#define RADIOLIB_NRF24_P5_ON 0b00100000 // 5 5 enabled
#define RADIOLIB_NRF24_P4_OFF 0b00000000 // 4 4 receive pipe 4: disabled (default)
#define RADIOLIB_NRF24_P4_ON 0b00010000 // 4 4 enabled
#define RADIOLIB_NRF24_P3_OFF 0b00000000 // 3 3 receive pipe 3: disabled (default)
#define RADIOLIB_NRF24_P3_ON 0b00001000 // 3 3 enabled
#define RADIOLIB_NRF24_P2_OFF 0b00000000 // 2 2 receive pipe 2: disabled (default)
#define RADIOLIB_NRF24_P2_ON 0b00000100 // 2 2 enabled
#define RADIOLIB_NRF24_P1_OFF 0b00000000 // 1 1 receive pipe 1: disabled
#define RADIOLIB_NRF24_P1_ON 0b00000010 // 1 1 enabled (default)
#define RADIOLIB_NRF24_P0_OFF 0b00000000 // 0 0 receive pipe 0: disabled
#define RADIOLIB_NRF24_P0_ON 0b00000001 // 0 0 enabled (default)
// NRF24_REG_SETUP_AW
#define RADIOLIB_NRF24_ADDRESS_2_BYTES 0b00000000 // 1 0 address width: 2 bytes
#define RADIOLIB_NRF24_ADDRESS_3_BYTES 0b00000001 // 1 0 3 bytes
#define RADIOLIB_NRF24_ADDRESS_4_BYTES 0b00000010 // 1 0 4 bytes
#define RADIOLIB_NRF24_ADDRESS_5_BYTES 0b00000011 // 1 0 5 bytes (default)
// RADIOLIB_NRF24_REG_SETUP_AW
#define RADIOLIB_NRF24_ADDRESS_2_BYTES 0b00000000 // 1 0 address width: 2 bytes
#define RADIOLIB_NRF24_ADDRESS_3_BYTES 0b00000001 // 1 0 3 bytes
#define RADIOLIB_NRF24_ADDRESS_4_BYTES 0b00000010 // 1 0 4 bytes
#define RADIOLIB_NRF24_ADDRESS_5_BYTES 0b00000011 // 1 0 5 bytes (default)
// NRF24_REG_SETUP_RETR
#define RADIOLIB_NRF24_ARD 0b00000000 // 7 4 auto retransmit delay: t[us] = (NRF24_ARD + 1) * 250 us
#define RADIOLIB_NRF24_ARC_OFF 0b00000000 // 3 0 auto retransmit count: auto retransmit disabled
#define RADIOLIB_NRF24_ARC 0b00000011 // 3 0 up to 3 retransmits on AA fail (default)
// RADIOLIB_NRF24_REG_SETUP_RETR
#define RADIOLIB_NRF24_ARD 0b00000000 // 7 4 auto retransmit delay: t[us] = (NRF24_ARD + 1) * 250 us
#define RADIOLIB_NRF24_ARC_OFF 0b00000000 // 3 0 auto retransmit count: auto retransmit disabled
#define RADIOLIB_NRF24_ARC 0b00000011 // 3 0 up to 3 retransmits on AA fail (default)
// NRF24_REG_RF_CH
#define RADIOLIB_NRF24_RF_CH 0b00000010 // 6 0 RF channel: f_CH[MHz] = 2400 MHz + NRF24_RF_CH
// RADIOLIB_NRF24_REG_RF_CH
#define RADIOLIB_NRF24_RF_CH 0b00000010 // 6 0 RF channel: f_CH[MHz] = 2400 MHz + NRF24_RF_CH
// NRF24_REG_RF_SETUP
#define RADIOLIB_NRF24_CONT_WAVE_OFF 0b00000000 // 7 7 continuous carrier transmit: disabled (default)
#define RADIOLIB_NRF24_CONT_WAVE_ON 0b10000000 // 7 7 enabled
#define RADIOLIB_NRF24_DR_250_KBPS 0b00100000 // 5 5 data rate: 250 kbps
#define RADIOLIB_NRF24_DR_1_MBPS 0b00000000 // 3 3 1 Mbps (default)
#define RADIOLIB_NRF24_DR_2_MBPS 0b00001000 // 3 3 2 Mbps
#define RADIOLIB_NRF24_PLL_LOCK_ON 0b00010000 // 4 4 force PLL lock: enabled
#define RADIOLIB_NRF24_PLL_LOCK_OFF 0b00000000 // 4 4 disabled (default)
#define RADIOLIB_NRF24_RF_PWR_18_DBM 0b00000000 // 2 1 output power: -18 dBm
#define RADIOLIB_NRF24_RF_PWR_12_DBM 0b00000010 // 2 1 -12 dBm
#define RADIOLIB_NRF24_RF_PWR_6_DBM 0b00000100 // 2 1 -6 dBm
#define RADIOLIB_NRF24_RF_PWR_0_DBM 0b00000110 // 2 1 0 dBm (default)
// RADIOLIB_NRF24_REG_RF_SETUP
#define RADIOLIB_NRF24_CONT_WAVE_OFF 0b00000000 // 7 7 continuous carrier transmit: disabled (default)
#define RADIOLIB_NRF24_CONT_WAVE_ON 0b10000000 // 7 7 enabled
#define RADIOLIB_NRF24_DR_250_KBPS 0b00100000 // 5 5 data rate: 250 kbps
#define RADIOLIB_NRF24_DR_1_MBPS 0b00000000 // 3 3 1 Mbps (default)
#define RADIOLIB_NRF24_DR_2_MBPS 0b00001000 // 3 3 2 Mbps
#define RADIOLIB_NRF24_PLL_LOCK_ON 0b00010000 // 4 4 force PLL lock: enabled
#define RADIOLIB_NRF24_PLL_LOCK_OFF 0b00000000 // 4 4 disabled (default)
#define RADIOLIB_NRF24_RF_PWR_18_DBM 0b00000000 // 2 1 output power: -18 dBm
#define RADIOLIB_NRF24_RF_PWR_12_DBM 0b00000010 // 2 1 -12 dBm
#define RADIOLIB_NRF24_RF_PWR_6_DBM 0b00000100 // 2 1 -6 dBm
#define RADIOLIB_NRF24_RF_PWR_0_DBM 0b00000110 // 2 1 0 dBm (default)
// NRF24_REG_STATUS
#define RADIOLIB_NRF24_RX_DR 0b01000000 // 6 6 Rx data ready
#define RADIOLIB_NRF24_TX_DS 0b00100000 // 5 5 Tx data sent
#define RADIOLIB_NRF24_MAX_RT 0b00010000 // 4 4 maximum number of retransmits reached (must be cleared to continue)
#define RADIOLIB_NRF24_RX_FIFO_EMPTY 0b00001110 // 3 1 Rx FIFO is empty
#define RADIOLIB_NRF24_RX_P_NO 0b00000000 // 3 1 number of data pipe that received data
#define RADIOLIB_NRF24_TX_FIFO_FULL 0b00000001 // 0 0 Tx FIFO is full
// RADIOLIB_NRF24_REG_STATUS
#define RADIOLIB_NRF24_RX_DR 0b01000000 // 6 6 Rx data ready
#define RADIOLIB_NRF24_TX_DS 0b00100000 // 5 5 Tx data sent
#define RADIOLIB_NRF24_MAX_RT 0b00010000 // 4 4 maximum number of retransmits reached (must be cleared to continue)
#define RADIOLIB_NRF24_RX_FIFO_EMPTY 0b00001110 // 3 1 Rx FIFO is empty
#define RADIOLIB_NRF24_RX_P_NO 0b00000000 // 3 1 number of data pipe that received data
#define RADIOLIB_NRF24_TX_FIFO_FULL 0b00000001 // 0 0 Tx FIFO is full
// NRF24_REG_OBSERVE_TX
#define RADIOLIB_NRF24_PLOS_CNT 0b00000000 // 7 4 number of lost packets
#define RADIOLIB_NRF24_ARC_CNT 0b00000000 // 3 0 number of retransmitted packets
// RADIOLIB_NRF24_REG_OBSERVE_TX
#define RADIOLIB_NRF24_PLOS_CNT 0b00000000 // 7 4 number of lost packets
#define RADIOLIB_NRF24_ARC_CNT 0b00000000 // 3 0 number of retransmitted packets
// NRF24_REG_RPD
#define RADIOLIB_NRF24_RP_BELOW_64_DBM 0b00000000 // 0 0 received power in the current channel: less than -64 dBm
#define RADIOLIB_NRF24_RP_ABOVE_64_DBM 0b00000001 // 0 0 more than -64 dBm
// RADIOLIB_NRF24_REG_RPD
#define RADIOLIB_NRF24_RP_BELOW_64_DBM 0b00000000 // 0 0 received power in the current channel: less than -64 dBm
#define RADIOLIB_NRF24_RP_ABOVE_64_DBM 0b00000001 // 0 0 more than -64 dBm
// NRF24_REG_FIFO_STATUS
#define RADIOLIB_NRF24_TX_REUSE 0b01000000 // 6 6 reusing last transmitted payload
#define RADIOLIB_NRF24_TX_FIFO_FULL_FLAG 0b00100000 // 5 5 Tx FIFO is full
#define RADIOLIB_NRF24_TX_FIFO_EMPTY_FLAG 0b00010000 // 4 4 Tx FIFO is empty
#define RADIOLIB_NRF24_RX_FIFO_FULL_FLAG 0b00000010 // 1 1 Rx FIFO is full
#define RADIOLIB_NRF24_RX_FIFO_EMPTY_FLAG 0b00000001 // 0 0 Rx FIFO is empty
// RADIOLIB_NRF24_REG_FIFO_STATUS
#define RADIOLIB_NRF24_TX_REUSE 0b01000000 // 6 6 reusing last transmitted payload
#define RADIOLIB_NRF24_TX_FIFO_FULL_FLAG 0b00100000 // 5 5 Tx FIFO is full
#define RADIOLIB_NRF24_TX_FIFO_EMPTY_FLAG 0b00010000 // 4 4 Tx FIFO is empty
#define RADIOLIB_NRF24_RX_FIFO_FULL_FLAG 0b00000010 // 1 1 Rx FIFO is full
#define RADIOLIB_NRF24_RX_FIFO_EMPTY_FLAG 0b00000001 // 0 0 Rx FIFO is empty
// NRF24_REG_DYNPD
#define RADIOLIB_NRF24_DPL_P5_OFF 0b00000000 // 5 5 dynamic payload length on pipe 5: disabled (default)
#define RADIOLIB_NRF24_DPL_P5_ON 0b00100000 // 5 5 enabled
#define RADIOLIB_NRF24_DPL_P4_OFF 0b00000000 // 4 4 dynamic payload length on pipe 4: disabled (default)
#define RADIOLIB_NRF24_DPL_P4_ON 0b00010000 // 4 4 enabled
#define RADIOLIB_NRF24_DPL_P3_OFF 0b00000000 // 3 3 dynamic payload length on pipe 3: disabled (default)
#define RADIOLIB_NRF24_DPL_P3_ON 0b00001000 // 3 3 enabled
#define RADIOLIB_NRF24_DPL_P2_OFF 0b00000000 // 2 2 dynamic payload length on pipe 2: disabled (default)
#define RADIOLIB_NRF24_DPL_P2_ON 0b00000100 // 2 2 enabled
#define RADIOLIB_NRF24_DPL_P1_OFF 0b00000000 // 1 1 dynamic payload length on pipe 1: disabled (default)
#define RADIOLIB_NRF24_DPL_P1_ON 0b00000010 // 1 1 enabled
#define RADIOLIB_NRF24_DPL_P0_OFF 0b00000000 // 0 0 dynamic payload length on pipe 0: disabled (default)
#define RADIOLIB_NRF24_DPL_P0_ON 0b00000001 // 0 0 enabled
#define RADIOLIB_NRF24_DPL_ALL_OFF 0b00000000 // 5 0 disable all dynamic payloads
#define RADIOLIB_NRF24_DPL_ALL_ON 0b00111111 // 5 0 enable all dynamic payloads
// RADIOLIB_NRF24_REG_DYNPD
#define RADIOLIB_NRF24_DPL_P5_OFF 0b00000000 // 5 5 dynamic payload length on pipe 5: disabled (default)
#define RADIOLIB_NRF24_DPL_P5_ON 0b00100000 // 5 5 enabled
#define RADIOLIB_NRF24_DPL_P4_OFF 0b00000000 // 4 4 dynamic payload length on pipe 4: disabled (default)
#define RADIOLIB_NRF24_DPL_P4_ON 0b00010000 // 4 4 enabled
#define RADIOLIB_NRF24_DPL_P3_OFF 0b00000000 // 3 3 dynamic payload length on pipe 3: disabled (default)
#define RADIOLIB_NRF24_DPL_P3_ON 0b00001000 // 3 3 enabled
#define RADIOLIB_NRF24_DPL_P2_OFF 0b00000000 // 2 2 dynamic payload length on pipe 2: disabled (default)
#define RADIOLIB_NRF24_DPL_P2_ON 0b00000100 // 2 2 enabled
#define RADIOLIB_NRF24_DPL_P1_OFF 0b00000000 // 1 1 dynamic payload length on pipe 1: disabled (default)
#define RADIOLIB_NRF24_DPL_P1_ON 0b00000010 // 1 1 enabled
#define RADIOLIB_NRF24_DPL_P0_OFF 0b00000000 // 0 0 dynamic payload length on pipe 0: disabled (default)
#define RADIOLIB_NRF24_DPL_P0_ON 0b00000001 // 0 0 enabled
#define RADIOLIB_NRF24_DPL_ALL_OFF 0b00000000 // 5 0 disable all dynamic payloads
#define RADIOLIB_NRF24_DPL_ALL_ON 0b00111111 // 5 0 enable all dynamic payloads
// NRF24_REG_FEATURE
#define RADIOLIB_NRF24_DPL_OFF 0b00000000 // 2 2 dynamic payload length: disabled (default)
#define RADIOLIB_NRF24_DPL_ON 0b00000100 // 2 2 enabled
#define RADIOLIB_NRF24_ACK_PAY_OFF 0b00000000 // 1 1 payload with ACK packets: disabled (default)
#define RADIOLIB_NRF24_ACK_PAY_ON 0b00000010 // 1 1 enabled
#define RADIOLIB_NRF24_DYN_ACK_OFF 0b00000000 // 0 0 payloads without ACK: disabled (default)
#define RADIOLIB_NRF24_DYN_ACK_ON 0b00000001 // 0 0 enabled
// RADIOLIB_NRF24_REG_FEATURE
#define RADIOLIB_NRF24_DPL_OFF 0b00000000 // 2 2 dynamic payload length: disabled (default)
#define RADIOLIB_NRF24_DPL_ON 0b00000100 // 2 2 enabled
#define RADIOLIB_NRF24_ACK_PAY_OFF 0b00000000 // 1 1 payload with ACK packets: disabled (default)
#define RADIOLIB_NRF24_ACK_PAY_ON 0b00000010 // 1 1 enabled
#define RADIOLIB_NRF24_DYN_ACK_OFF 0b00000000 // 0 0 payloads without ACK: disabled (default)
#define RADIOLIB_NRF24_DYN_ACK_ON 0b00000001 // 0 0 enabled
// RadioLib defaults
#define RADIOLIB_NRF24_DEFAULT_FREQ 2400
#define RADIOLIB_NRF24_DEFAULT_DR 1000
#define RADIOLIB_NRF24_DEFAULT_POWER -12
#define RADIOLIB_NRF24_DEFAULT_ADDRWIDTH 5
/*!
\class nRF24
\brief Control class for %nRF24 module.
*/
class nRF24: public PhysicalLayer {
@@ -186,82 +191,73 @@ class nRF24: public PhysicalLayer {
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
nRF24(Module* mod);
Module* getMod();
nRF24(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
/*!
\brief Initialization method.
\param freq Carrier frequency in MHz. Defaults to 2400 MHz.
\param dataRate Data rate to be used in kbps. Defaults to 1000 kbps.
\param power Output power in dBm. Defaults to -12 dBm.
\param dr Data rate to be used in kbps. Defaults to 1000 kbps.
\param pwr Output power in dBm. Defaults to -12 dBm.
\param addrWidth Address width in bytes. Defaults to 5 bytes.
\returns \ref status_codes
*/
int16_t begin(int16_t freq = 2400, int16_t dataRate = 1000, int8_t power = -12, uint8_t addrWidth = 5);
int16_t begin(
int16_t freq = RADIOLIB_NRF24_DEFAULT_FREQ,
int16_t dr = RADIOLIB_NRF24_DEFAULT_DR,
int8_t pwr = RADIOLIB_NRF24_DEFAULT_POWER,
uint8_t addrWidth = RADIOLIB_NRF24_DEFAULT_ADDRWIDTH);
/*!
\brief Sets the module to sleep mode.
\returns \ref status_codes
*/
int16_t sleep();
int16_t sleep() override;
/*!
\brief Sets the module to standby mode.
\returns \ref status_codes
*/
int16_t standby() override;
/*!
\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 Dummy address parameter, to ensure PhysicalLayer compatibility.
\brief Sets the module to standby.
\param mode Standby mode to be used.
\returns \ref status_codes
*/
int16_t transmit(uint8_t* data, size_t len, uint8_t addr) override;
int16_t standby(uint8_t mode) override;
/*!
\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 Dummy address parameter, to ensure PhysicalLayer compatibility.
\returns \ref status_codes
*/
int16_t transmit(const uint8_t* data, size_t len, uint8_t addr) override;
/*!
\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;
/*!
\brief Dummy direct mode reception method, to ensure PhysicalLayer compatibility.
\returns \ref status_codes
*/
int16_t receiveDirect() override;
@@ -270,39 +266,74 @@ class nRF24: public PhysicalLayer {
/*!
\brief Sets interrupt service routine to call when IRQ activates.
\param func ISR to call.
*/
void setIrqAction(void (*func)(void));
/*!
\brief Clears interrupt service routine .
*/
void clearIrqAction();
/*!
\brief Sets interrupt service routine to call when a packet is received.
\param func ISR to call.
*/
void setPacketReceivedAction(void (*func)(void)) override;
/*!
\brief Clears interrupt service routine to call when a packet is received.
*/
void clearPacketReceivedAction() override;
/*!
\brief Sets interrupt service routine to call when a packet is sent.
\param func ISR to call.
*/
void setPacketSentAction(void (*func)(void)) override;
/*!
\brief Clears interrupt service routine to call when a packet is sent.
*/
void clearPacketSentAction() override;
/*!
\brief Interrupt-driven binary transmit method. IRQ will be activated when full packet is transmitted.
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 Dummy address parameter, to ensure PhysicalLayer compatibility.
\returns \ref status_codes
*/
int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr) override;
int16_t startTransmit(const uint8_t* data, size_t len, uint8_t addr) override;
/*!
\brief Clean up after transmission is done.
\returns \ref status_codes
*/
int16_t finishTransmit() override;
/*!
\brief Interrupt-driven receive method. IRQ will be activated when full packet is received.
\returns \ref status_codes
*/
int16_t startReceive();
int16_t startReceive() override;
/*!
\brief Reads data received after calling startReceive method.
\brief Interrupt-driven receive method, implemented for compatibility with PhysicalLayer.
\param timeout Ignored.
\param irqFlags Ignored.
\param irqMask Ignored.
\param len Ignored.
\returns \ref status_codes
*/
int16_t startReceive(uint32_t timeout, uint32_t irqFlags, uint32_t irqMask, size_t len) override;
/*!
\brief Reads data received after calling startReceive method. When the packet length is not known in advance,
getPacketLength method must be called BEFORE calling readData!
\param data Pointer to array to save the received binary data.
\param len Number of bytes that will be received. Must be known in advance for binary transmissions.
\returns \ref status_codes
*/
int16_t readData(uint8_t* data, size_t len) override;
@@ -311,198 +342,147 @@ class nRF24: public PhysicalLayer {
/*!
\brief Sets carrier frequency. Allowed values range from 2400 MHz to 2525 MHz.
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(int16_t freq);
int16_t setFrequency(float freq) override;
/*!
\brief Sets data rate. Allowed values are 2000, 1000 or 250 kbps.
\param dataRate Data rate to be set in kbps.
\brief Sets bit rate. Allowed values are 2000, 1000 or 250 kbps.
\param br Bit rate to be set in kbps.
\returns \ref status_codes
*/
int16_t setDataRate(int16_t dataRate);
int16_t setBitRate(float br) override;
/*!
\brief Sets output power. Allowed values are -18, -12, -6 or 0 dBm.
\param power Output power to be set in dBm.
\param pwr Output power to be set in dBm.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power);
int16_t setOutputPower(int8_t pwr) override;
/*!
\brief Sets address width of transmit and receive pipes in bytes. Allowed values are 3, 4 or 5 bytes.
\param addrWidth Address width to be set in bytes.
\returns \ref status_codes
*/
int16_t setAddressWidth(uint8_t addrWidth);
/*!
\brief Sets address of transmit pipe. The address width must be the same as the same as the configured in setAddressWidth.
\brief Sets address of transmit pipe. The address width must be the same as the same
as the configured in setAddressWidth.
\param addr Address to which the next packet shall be transmitted.
\returns \ref status_codes
*/
int16_t setTransmitPipe(uint8_t* addr);
/*!
\brief Sets address of receive pipes 0 or 1. The address width must be the same as the same as the configured in setAddressWidth.
\param pipeNum Number of pipe to which the address shall be set. Either 0 or 1, other pipes are handled using overloaded method.
\brief Sets address of receive pipes 0 or 1. The address width must be the same as the same
as the configured in setAddressWidth.
\param pipeNum Number of pipe to which the address shall be set. Either 0 or 1,
other pipes are handled using overloaded method.
\param addr Address from which %nRF24 shall receive new packets on the specified pipe.
\returns \ref status_codes
*/
int16_t setReceivePipe(uint8_t pipeNum, uint8_t* addr);
/*!
\brief Sets address of receive pipes 2 - 5. The first 2 - 4 address bytes for these pipes are the same as for address pipe 1, only the last byte can be set.
\brief Sets address of receive pipes 2 - 5. The first 2 - 4 address bytes for these pipes
are the same as for address pipe 1, only the last byte can be set.
\param pipeNum Number of pipe to which the address shall be set. Allowed values range from 2 to 5.
\param addrByte LSB of address from which %nRF24 shall receive new packets on the specified pipe.
\returns \ref status_codes
*/
int16_t setReceivePipe(uint8_t pipeNum, uint8_t addrByte);
/*!
\brief Disables specified receive pipe.
\param pipeNum Receive pipe to be disabled.
\returns \ref status_codes
*/
int16_t disablePipe(uint8_t pipeNum);
/*!
\brief Gets nRF24 status register.
\param mask Bit mask to be used on the returned register value.
\returns Status register value or \ref status_codes
*/
int16_t getStatus(uint8_t mask = 0xFF);
/*!
\brief Checks if carrier was detected during last RX
\returns Whatever the carrier was above threshold.
*/
bool isCarrierDetected();
/*!
\brief Dummy configuration method, to ensure PhysicalLayer compatibility.
\param freqDev Dummy frequency deviation parameter, no configuration will be changed.
\returns \ref status_codes
*/
int16_t setFrequencyDeviation(float freqDev) override;
/*!
\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 Enable CRC filtering and generation.
\param crcOn Set or unset CRC check.
\returns \ref status_codes
*/
int16_t setCrcFiltering(bool crcOn = true);
/*!
\brief Enable or disable auto-acknowledge packets on all pipes
\brief Enable or disable auto-acknowledge packets on all pipes.
\param autoAckOn Enable (true) or disable (false) auto-acks.
\returns \ref status_codes
*/
int16_t setAutoAck(bool autoAckOn = true);
/*!
\brief Enable or disable auto-acknowledge packets on given pipe.
\param pipeNum Number of pipe to which enable / disable auto-acks.
\param autoAckOn Enable (true) or disable (false) auto-acks.
\returns \ref status_codes
*/
int16_t setAutoAck(uint8_t pipeNum, bool autoAckOn);
/*!
\brief Dummy data shaping configuration method, to ensure PhysicalLayer compatibility.
\param sh Ignored.
\returns \ref status_codes
*/
int16_t setDataShaping(uint8_t sh) override;
/*!
\brief Dummy encoding configuration method, to ensure PhysicalLayer compatibility.
\param sh Ignored.
\param encoding Ignored.
\returns \ref status_codes
*/
int16_t setEncoding(uint8_t encoding) override;
/*!
\brief Dummy random method, to ensure PhysicalLayer compatibility.
\returns Always returns 0.
*/
uint8_t randomByte();
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
/*!
\brief Dummy method, to ensure PhysicalLayer compatibility.
\param func Ignored.
*/
void setDirectAction(void (*func)(void));
/*!
\brief Dummy method, to ensure PhysicalLayer compatibility.
\param pin Ignored.
*/
void readBit(RADIOLIB_PIN_TYPE pin);
#endif
#if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL)
#if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL
protected:
#endif
Module* _mod;
Module* getMod() override;
void SPIreadRxPayload(uint8_t* data, uint8_t numBytes);
void SPIwriteTxPayload(uint8_t* data, uint8_t numBytes);
void SPItransfer(uint8_t cmd, bool write = false, uint8_t* dataOut = NULL, uint8_t* dataIn = NULL, uint8_t numBytes = 0);
#if !defined(RADIOLIB_GODMODE)
protected:
#if !RADIOLIB_GODMODE
private:
#endif
Module* mod;
uint8_t _addrWidth = 0;
int16_t frequency = RADIOLIB_NRF24_DEFAULT_FREQ;
int16_t dataRate = RADIOLIB_NRF24_DEFAULT_DR;
int8_t power = RADIOLIB_NRF24_DEFAULT_POWER;
uint8_t addressWidth = RADIOLIB_NRF24_DEFAULT_ADDRWIDTH;
int16_t config();
void clearIRQ();