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
+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