Update Radiolib version to 7.1.0

This commit is contained in:
lewisxhe
2024-12-20 10:30:28 +08:00
parent ec34aea9f7
commit 7f7f0022fe
185 changed files with 5193 additions and 2116 deletions
+64 -6
View File
@@ -421,7 +421,7 @@ int16_t SX128x::receiveDirect() {
}
int16_t SX128x::scanChannel() {
ChannelScanConfig_t config = {
ChannelScanConfig_t cfg = {
.cad = {
.symNum = RADIOLIB_SX128X_CAD_PARAM_DEFAULT,
.detPeak = 0,
@@ -432,7 +432,7 @@ int16_t SX128x::scanChannel() {
.irqMask = RADIOLIB_IRQ_CAD_DEFAULT_MASK,
},
};
return(this->scanChannel(config));
return(this->scanChannel(cfg));
}
int16_t SX128x::scanChannel(const ChannelScanConfig_t &config) {
@@ -461,7 +461,9 @@ int16_t SX128x::sleep(bool retainConfig) {
if(!retainConfig) {
sleepConfig = RADIOLIB_SX128X_SLEEP_DATA_BUFFER_FLUSH | RADIOLIB_SX128X_SLEEP_DATA_RAM_FLUSH;
}
int16_t state = this->mod->SPIwriteStream(RADIOLIB_SX128X_CMD_SET_SLEEP, &sleepConfig, 1, false, false);
int16_t state = this->mod->SPIwriteStream(RADIOLIB_SX128X_CMD_SAVE_CONTEXT, 0, 1, false, false);
RADIOLIB_ASSERT(state);
state = this->mod->SPIwriteStream(RADIOLIB_SX128X_CMD_SET_SLEEP, &sleepConfig, 1, false, false);
// wait for SX128x to safely enter sleep mode
this->mod->hal->delay(1);
@@ -677,7 +679,7 @@ int16_t SX128x::clearIrqFlags(uint32_t irq) {
}
int16_t SX128x::startChannelScan() {
ChannelScanConfig_t config = {
ChannelScanConfig_t cfg = {
.cad = {
.symNum = RADIOLIB_SX128X_CAD_PARAM_DEFAULT,
.detPeak = 0,
@@ -688,7 +690,7 @@ int16_t SX128x::startChannelScan() {
.irqMask = RADIOLIB_IRQ_CAD_DEFAULT_MASK,
},
};
return(this->startChannelScan(config));
return(this->startChannelScan(cfg));
}
int16_t SX128x::startChannelScan(const ChannelScanConfig_t &config) {
@@ -854,6 +856,35 @@ int16_t SX128x::checkOutputPower(int8_t pwr, int8_t* clipped) {
return(RADIOLIB_ERR_NONE);
}
int16_t SX128x::setModem(ModemType_t modem) {
switch(modem) {
case(ModemType_t::LoRa): {
return(this->begin());
} break;
case(ModemType_t::FSK): {
return(this->beginGFSK());
} break;
default:
return(RADIOLIB_ERR_WRONG_MODEM);
}
}
int16_t SX128x::getModem(ModemType_t* modem) {
RADIOLIB_ASSERT_PTR(modem);
uint8_t packetType = getPacketType();
switch(packetType) {
case(RADIOLIB_SX128X_PACKET_TYPE_LORA):
*modem = ModemType_t::LoRa;
return(RADIOLIB_ERR_NONE);
case(RADIOLIB_SX128X_PACKET_TYPE_GFSK):
*modem = ModemType_t::FSK;
return(RADIOLIB_ERR_NONE);
}
return(RADIOLIB_ERR_WRONG_MODEM);
}
int16_t SX128x::setPreambleLength(uint32_t preambleLength) {
uint8_t modem = getPacketType();
if((modem == RADIOLIB_SX128X_PACKET_TYPE_LORA) || (modem == RADIOLIB_SX128X_PACKET_TYPE_RANGING)) {
@@ -870,7 +901,7 @@ int16_t SX128x::setPreambleLength(uint32_t preambleLength) {
uint8_t m = 1;
uint32_t len = 0;
for(; e <= 15; e++) {
for(; m <= 15; m++) {
for(m = 1; m <= 15; m++) {
len = m * (uint32_t(1) << e);
if(len >= preambleLength) {
break;
@@ -902,6 +933,22 @@ int16_t SX128x::setPreambleLength(uint32_t preambleLength) {
return(RADIOLIB_ERR_WRONG_MODEM);
}
int16_t SX128x::setDataRate(DataRate_t dr) {
// check active modem
uint8_t modem = getPacketType();
int16_t state = RADIOLIB_ERR_NONE;
if (modem == RADIOLIB_SX128X_PACKET_TYPE_LORA) {
state = this->setBandwidth(dr.lora.bandwidth);
RADIOLIB_ASSERT(state);
state = this->setSpreadingFactor(dr.lora.spreadingFactor);
RADIOLIB_ASSERT(state);
state = this->setCodingRate(dr.lora.codingRate);
} else {
return(RADIOLIB_ERR_WRONG_MODEM);
}
return(state);
}
int16_t SX128x::setBitRate(float br) {
// check active modem
uint8_t modem = getPacketType();
@@ -1253,6 +1300,17 @@ float SX128x::getRSSI() {
}
}
float SX128x::getRSSI(bool packet) {
if (!packet) {
// get instantaneous RSSI value
uint8_t data[3] = {0, 0, 0}; // RssiInst, Status, RFU
this->mod->SPIreadStream(RADIOLIB_SX128X_CMD_GET_RSSI_INST, data, 3);
return ((float)data[0] / (-2.0));
} else {
return this->getRSSI();
}
}
float SX128x::getSNR() {
// check active modem
uint8_t modem = getPacketType();
+30
View File
@@ -22,6 +22,7 @@
#define RADIOLIB_SX128X_CMD_READ_REGISTER 0x19
#define RADIOLIB_SX128X_CMD_WRITE_BUFFER 0x1A
#define RADIOLIB_SX128X_CMD_READ_BUFFER 0x1B
#define RADIOLIB_SX128X_CMD_SAVE_CONTEXT 0xD5
#define RADIOLIB_SX128X_CMD_SET_SLEEP 0x84
#define RADIOLIB_SX128X_CMD_SET_STANDBY 0x80
#define RADIOLIB_SX128X_CMD_SET_FS 0xC1
@@ -670,6 +671,21 @@ class SX128x: public PhysicalLayer {
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t pwr, int8_t* clipped) override;
/*!
\brief Set modem for the radio to use. Will perform full reset and reconfigure the radio
using its default parameters.
\param modem Modem type to set - FSK, LoRa or LR-FHSS.
\returns \ref status_codes
*/
int16_t setModem(ModemType_t modem) override;
/*!
\brief Get modem currently in use by the radio.
\param modem Pointer to a variable to save the retrieved configuration into.
\returns \ref status_codes
*/
int16_t getModem(ModemType_t* modem) override;
/*!
\brief Sets preamble length for currently active modem. Allowed values range from 1 to 65535.
@@ -678,6 +694,13 @@ class SX128x: public PhysicalLayer {
*/
int16_t setPreambleLength(uint32_t preambleLength);
/*!
\brief Set data rate.
\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 Sets FSK or FLRC bit rate. Allowed values are 125, 250, 400, 500, 800, 1000,
1600 and 2000 kbps (for FSK modem) or 260, 325, 520, 650, 1000 and 1300 (for FLRC modem).
@@ -761,6 +784,13 @@ class SX128x: public PhysicalLayer {
*/
float getRSSI() override;
/*!
\brief Gets RSSI (Recorded Signal Strength Indicator).
\param packet Whether to read last packet RSSI, or the current value.
\returns RSSI value in dBm.
*/
float getRSSI(bool packet);
/*!
\brief Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa or ranging modem.
\returns SNR of the last received packet in dB.