Skip to content

Commit d1f5f72

Browse files
committed
an update of RadioLib library
1 parent f05f7c2 commit d1f5f72

File tree

10 files changed

+98
-137
lines changed

10 files changed

+98
-137
lines changed

software/firmware/source/libraries/RadioLib/src/modules/LR11x0/LR11x0.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,9 @@ int16_t LR11x0::standby(uint8_t mode, bool wakeup) {
356356
this->mod->setRfSwitchState(Module::MODE_IDLE);
357357

358358
if(wakeup) {
359-
// pull NSS low for a while to wake up
360-
this->mod->hal->digitalWrite(this->mod->getCs(), this->mod->hal->GpioLevelLow);
361-
this->mod->hal->delay(1);
362-
this->mod->hal->digitalWrite(this->mod->getCs(), this->mod->hal->GpioLevelHigh);
359+
// send a NOP command - this pulls the NSS low to exit the sleep mode,
360+
// while preventing interference with possible other SPI transactions
361+
(void)this->mod->SPIwriteStream(RADIOLIB_LR11X0_CMD_NOP, NULL, 0, false, false);
363362
}
364363

365364
uint8_t buff[] = { mode };

software/firmware/source/libraries/RadioLib/src/modules/SX126x/SX126x.cpp

Lines changed: 37 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, uint16_t preambleL
7474
this->pulseShape = RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_5;
7575
this->crcTypeFSK = RADIOLIB_SX126X_GFSK_CRC_2_BYTE_INV; // CCITT CRC configuration
7676
this->preambleLengthFSK = preambleLength;
77-
this->addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF;
7877

7978
// set module properties and perform initial setup
8079
int16_t state = this->modSetup(tcxoVoltage, useRegulatorLDO, RADIOLIB_SX126X_PACKET_TYPE_GFSK);
@@ -468,8 +467,10 @@ int16_t SX126x::standby(uint8_t mode, bool wakeup) {
468467
this->mod->setRfSwitchState(Module::MODE_IDLE);
469468

470469
if(wakeup) {
471-
// pull NSS low to wake up
472-
this->mod->hal->digitalWrite(this->mod->getCs(), this->mod->hal->GpioLevelLow);
470+
// send a NOP command - this pulls the NSS low to exit the sleep mode,
471+
// while preventing interference with possible other SPI transactions
472+
// see https://github.com/jgromes/RadioLib/discussions/1364
473+
(void)this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_NOP, NULL, 0, false, false);
473474
}
474475

475476
uint8_t data[] = { mode };
@@ -515,13 +516,15 @@ void SX126x::clearChannelScanAction() {
515516
static unsigned long MAX_BUSY_TIME = 5000;
516517

517518
int16_t SX126x::startTransmit(const uint8_t* data, size_t len, uint8_t addr) {
519+
(void)addr;
520+
518521
// check packet length
519522
if(len > RADIOLIB_SX126X_MAX_PACKET_LENGTH) {
520523
return(RADIOLIB_ERR_PACKET_TOO_LONG);
521524
}
522525

523526
// maximum packet length is decreased by 1 when address filtering is active
524-
if((this->addrComp != RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF) && (len > RADIOLIB_SX126X_MAX_PACKET_LENGTH - 1)) {
527+
if((RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF != RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF) && (len > RADIOLIB_SX126X_MAX_PACKET_LENGTH - 1)) {
525528
return(RADIOLIB_ERR_PACKET_TOO_LONG);
526529
}
527530

@@ -532,13 +535,7 @@ int16_t SX126x::startTransmit(const uint8_t* data, size_t len, uint8_t addr) {
532535
state = setPacketParams(this->preambleLengthLoRa, this->crcTypeLoRa, len, this->headerType, this->invertIQEnabled);
533536

534537
} else if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
535-
state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType, len);
536-
537-
// address is taken from the register
538-
if(this->addrComp != RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF) {
539-
RADIOLIB_ASSERT(state);
540-
state = writeRegister(RADIOLIB_SX126X_REG_NODE_ADDRESS, &addr, 1);
541-
}
538+
state = setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF, this->whitening, this->packetType, len);
542539

543540
} else if(modem != RADIOLIB_SX126X_PACKET_TYPE_LR_FHSS) {
544541
return(RADIOLIB_ERR_UNKNOWN);
@@ -642,12 +639,6 @@ int16_t SX126x::finishTransmit() {
642639
int16_t state = clearIrqStatus();
643640
RADIOLIB_ASSERT(state);
644641

645-
// restore the original node address
646-
if(getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
647-
state = writeRegister(RADIOLIB_SX126X_REG_NODE_ADDRESS, &this->nodeAddr, 1);
648-
RADIOLIB_ASSERT(state);
649-
}
650-
651642
// set mode to standby to disable transmitter/RF switch
652643
return(standby());
653644
}
@@ -657,7 +648,12 @@ int16_t SX126x::startReceive() {
657648
}
658649

659650
int16_t SX126x::startReceive(uint32_t timeout, RadioLibIrqFlags_t irqFlags, RadioLibIrqFlags_t irqMask, size_t len) {
660-
(void)len;
651+
// in implicit header mode, use the provided length if it is nonzero
652+
// otherwise we trust the user has previously set the payload length manually
653+
if((this->headerType == RADIOLIB_SX126X_LORA_HEADER_IMPLICIT) && (len != 0)) {
654+
this->implicitLen = len;
655+
}
656+
661657
int16_t state = startReceiveCommon(timeout, irqFlags, irqMask);
662658
RADIOLIB_ASSERT(state);
663659

@@ -759,7 +755,7 @@ int16_t SX126x::startReceiveCommon(uint32_t timeout, RadioLibIrqFlags_t irqFlags
759755
if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) {
760756
state = setPacketParams(this->preambleLengthLoRa, this->crcTypeLoRa, this->implicitLen, this->headerType, this->invertIQEnabled);
761757
} else if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
762-
state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType);
758+
state = setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF, this->whitening, this->packetType);
763759
} else {
764760
return(RADIOLIB_ERR_UNKNOWN);
765761
}
@@ -984,12 +980,15 @@ int16_t SX126x::setPreambleLength(size_t preambleLength) {
984980
return(setPacketParams(this->preambleLengthLoRa, this->crcTypeLoRa, this->implicitLen, this->headerType, this->invertIQEnabled));
985981
} else if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
986982
this->preambleLengthFSK = preambleLength;
987-
this->preambleDetLength = preambleLength >= 32 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_32 :
988-
preambleLength >= 24 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_24 :
989-
preambleLength >= 16 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16 :
990-
preambleLength > 0 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_8 :
983+
// maximum preamble detector length is limited by sync word length
984+
// for details, see the note in SX1261 datasheet, Rev 2.1, section 6.2.2.1, page 45
985+
uint8_t maxDetLen = RADIOLIB_MIN(this->syncWordLength, this->preambleLengthFSK);
986+
this->preambleDetLength = maxDetLen >= 32 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_32 :
987+
maxDetLen >= 24 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_24 :
988+
maxDetLen >= 16 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16 :
989+
maxDetLen > 0 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_8 :
991990
RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_OFF;
992-
return(setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType));
991+
return(setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF, this->whitening, this->packetType));
993992
}
994993

995994
return(RADIOLIB_ERR_UNKNOWN);
@@ -1225,7 +1224,16 @@ int16_t SX126x::setSyncWord(uint8_t* syncWord, size_t len) {
12251224

12261225
// update packet parameters
12271226
this->syncWordLength = len * 8;
1228-
state = setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType);
1227+
1228+
// maximum preamble detector length is limited by sync word length
1229+
// for details, see the note in SX1261 datasheet, Rev 2.1, section 6.2.2.1, page 45
1230+
uint8_t maxDetLen = RADIOLIB_MIN(this->syncWordLength, this->preambleLengthFSK);
1231+
this->preambleDetLength = maxDetLen >= 32 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_32 :
1232+
maxDetLen >= 24 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_24 :
1233+
maxDetLen >= 16 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16 :
1234+
maxDetLen > 0 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_8 :
1235+
RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_OFF;
1236+
state = setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF, this->whitening, this->packetType);
12291237

12301238
return(state);
12311239

@@ -1267,52 +1275,6 @@ int16_t SX126x::setSyncBits(uint8_t *syncWord, uint8_t bitsLen) {
12671275
return(setSyncWord(syncWord, bytesLen));
12681276
}
12691277

1270-
int16_t SX126x::setNodeAddress(uint8_t addr) {
1271-
// check active modem
1272-
if(getPacketType() != RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
1273-
return(RADIOLIB_ERR_WRONG_MODEM);
1274-
}
1275-
1276-
// enable address filtering (node only)
1277-
this->addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE;
1278-
int16_t state = setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType);
1279-
RADIOLIB_ASSERT(state);
1280-
1281-
// set node address
1282-
this->nodeAddr = addr;
1283-
state = writeRegister(RADIOLIB_SX126X_REG_NODE_ADDRESS, &addr, 1);
1284-
1285-
return(state);
1286-
}
1287-
1288-
int16_t SX126x::setBroadcastAddress(uint8_t broadAddr) {
1289-
// check active modem
1290-
if(getPacketType() != RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
1291-
return(RADIOLIB_ERR_WRONG_MODEM);
1292-
}
1293-
1294-
// enable address filtering (node and broadcast)
1295-
this->addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE_BROADCAST;
1296-
int16_t state = setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType);
1297-
RADIOLIB_ASSERT(state);
1298-
1299-
// set broadcast address
1300-
state = writeRegister(RADIOLIB_SX126X_REG_BROADCAST_ADDRESS, &broadAddr, 1);
1301-
1302-
return(state);
1303-
}
1304-
1305-
int16_t SX126x::disableAddressFiltering() {
1306-
// check active modem
1307-
if(getPacketType() != RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
1308-
return(RADIOLIB_ERR_WRONG_MODEM);
1309-
}
1310-
1311-
// disable address filtering
1312-
this->addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF;
1313-
return(setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening));
1314-
}
1315-
13161278
int16_t SX126x::setCRC(uint8_t len, uint16_t initial, uint16_t polynomial, bool inverted) {
13171279
// check active modem
13181280
uint8_t modem = getPacketType();
@@ -1341,7 +1303,7 @@ int16_t SX126x::setCRC(uint8_t len, uint16_t initial, uint16_t polynomial, bool
13411303
return(RADIOLIB_ERR_INVALID_CRC_CONFIGURATION);
13421304
}
13431305

1344-
int16_t state = setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType);
1306+
int16_t state = setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF, this->whitening, this->packetType);
13451307
RADIOLIB_ASSERT(state);
13461308

13471309
// write initial CRC value
@@ -1383,7 +1345,7 @@ int16_t SX126x::setWhitening(bool enabled, uint16_t initial) {
13831345
// disable whitening
13841346
this->whitening = RADIOLIB_SX126X_GFSK_WHITENING_OFF;
13851347

1386-
state = setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType);
1348+
state = setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF, this->whitening, this->packetType);
13871349
RADIOLIB_ASSERT(state);
13881350

13891351
} else {
@@ -1403,7 +1365,7 @@ int16_t SX126x::setWhitening(bool enabled, uint16_t initial) {
14031365
state = writeRegister(RADIOLIB_SX126X_REG_WHITENING_INITIAL_MSB, data, 2);
14041366
RADIOLIB_ASSERT(state);
14051367

1406-
state = setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType);
1368+
state = setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF, this->whitening, this->packetType);
14071369
RADIOLIB_ASSERT(state);
14081370
}
14091371
return(state);
@@ -2065,7 +2027,7 @@ int16_t SX126x::setPacketMode(uint8_t mode, uint8_t len) {
20652027
}
20662028

20672029
// set requested packet mode
2068-
int16_t state = setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, mode, len);
2030+
int16_t state = setPacketParamsFSK(this->preambleLengthFSK, this->preambleDetLength, this->crcTypeFSK, this->syncWordLength, RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF, this->whitening, mode, len);
20692031
RADIOLIB_ASSERT(state);
20702032

20712033
// update cached value

software/firmware/source/libraries/RadioLib/src/modules/SX126x/SX126x.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,10 @@ class SX126x: public PhysicalLayer {
823823
/*!
824824
\brief Sets preamble length for LoRa or FSK modem. Allowed values range from 1 to 65535.
825825
\param preambleLength Preamble length to be set in symbols (LoRa) or bits (FSK).
826+
NOTE: In FSK mode, sync word length limits the preamble detector length
827+
(the number of preamble bits that must be detected to start receiving packet).
828+
For details, see the note in SX1261 datasheet, Rev 2.1, section 6.2.2.1, page 45.
829+
Preamble detector length is adjusted automatically each time this method is called.
826830
\returns \ref status_codes
827831
*/
828832
int16_t setPreambleLength(size_t preambleLength) override;
@@ -887,6 +891,10 @@ class SX126x: public PhysicalLayer {
887891
Can also set LR-FHSS sync word, but its length must be 4 bytes.
888892
\param syncWord FSK sync word to be set.
889893
\param len FSK sync word length in bytes.
894+
NOTE: In FSK mode, sync word length limits the preamble detector length
895+
(the number of preamble bits that must be detected to start receiving packet).
896+
For details, see the note in SX1261 datasheet, Rev 2.1, section 6.2.2.1, page 45.
897+
Preamble detector length is adjusted automatically each time this method is called.
890898
\returns \ref status_codes
891899
*/
892900
int16_t setSyncWord(uint8_t* syncWord, size_t len) override;
@@ -1278,10 +1286,9 @@ class SX126x: public PhysicalLayer {
12781286
bool ldroAuto = true;
12791287

12801288
uint32_t bitRate = 0, frequencyDev = 0;
1281-
uint8_t preambleDetLength = 0, rxBandwidth = 0, pulseShape = 0, crcTypeFSK = 0, syncWordLength = 0, addrComp = 0, whitening = 0, packetType = 0;
1289+
uint8_t preambleDetLength = 0, rxBandwidth = 0, pulseShape = 0, crcTypeFSK = 0, syncWordLength = 0, whitening = 0, packetType = 0;
12821290
uint16_t preambleLengthFSK = 0;
12831291
float rxBandwidthKhz = 0;
1284-
uint8_t nodeAddr = 0;
12851292

12861293
float dataRateMeasured = 0;
12871294

software/firmware/source/libraries/RadioLib/src/modules/SX127x/SX1272.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -497,11 +497,13 @@ int16_t SX1272::autoLDRO() {
497497
}
498498

499499
int16_t SX1272::implicitHeader(size_t len) {
500-
return(setHeaderType(RADIOLIB_SX1272_HEADER_IMPL_MODE, len));
500+
this->implicitHdr = true;
501+
return(setHeaderType(RADIOLIB_SX1272_HEADER_IMPL_MODE, 2, len));
501502
}
502503

503504
int16_t SX1272::explicitHeader() {
504-
return(setHeaderType(RADIOLIB_SX1272_HEADER_EXPL_MODE));
505+
this->implicitHdr = false;
506+
return(setHeaderType(RADIOLIB_SX1272_HEADER_EXPL_MODE, 2));
505507
}
506508

507509
int16_t SX1272::setBandwidthRaw(uint8_t newBandwidth) {
@@ -521,11 +523,13 @@ int16_t SX1272::setSpreadingFactorRaw(uint8_t newSpreadingFactor) {
521523
// write registers
522524
Module* mod = this->getMod();
523525
if(newSpreadingFactor == RADIOLIB_SX127X_SF_6) {
526+
this->implicitHdr = true;
524527
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);
525528
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
526529
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0);
527530
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6);
528531
} else {
532+
this->implicitHdr = false;
529533
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);
530534
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
531535
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0);
@@ -544,27 +548,6 @@ int16_t SX1272::setCodingRateRaw(uint8_t newCodingRate) {
544548
return(state);
545549
}
546550

547-
int16_t SX1272::setHeaderType(uint8_t headerType, size_t len) {
548-
// check active modem
549-
if(getActiveModem() != RADIOLIB_SX127X_LORA) {
550-
return(RADIOLIB_ERR_WRONG_MODEM);
551-
}
552-
553-
// set requested packet mode
554-
Module* mod = this->getMod();
555-
int16_t state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 2, 2);
556-
RADIOLIB_ASSERT(state);
557-
558-
// set length to register
559-
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len);
560-
RADIOLIB_ASSERT(state);
561-
562-
// update cached value
563-
SX127x::packetLength = len;
564-
565-
return(state);
566-
}
567-
568551
int16_t SX1272::configFSK() {
569552
// configure common registers
570553
int16_t state = SX127x::configFSK();

software/firmware/source/libraries/RadioLib/src/modules/SX127x/SX1272.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ class SX1272: public SX127x {
316316
int16_t setBandwidthRaw(uint8_t newBandwidth);
317317
int16_t setSpreadingFactorRaw(uint8_t newSpreadingFactor);
318318
int16_t setCodingRateRaw(uint8_t newCodingRate);
319-
int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);
320319

321320
int16_t configFSK();
322321
void errataFix(bool rx) override;

software/firmware/source/libraries/RadioLib/src/modules/SX127x/SX1278.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,13 @@ int16_t SX1278::autoLDRO() {
535535
}
536536

537537
int16_t SX1278::implicitHeader(size_t len) {
538-
return(setHeaderType(RADIOLIB_SX1278_HEADER_IMPL_MODE, len));
538+
this->implicitHdr = true;
539+
return(setHeaderType(RADIOLIB_SX1278_HEADER_IMPL_MODE, 0, len));
539540
}
540541

541542
int16_t SX1278::explicitHeader() {
542-
return(setHeaderType(RADIOLIB_SX1278_HEADER_EXPL_MODE));
543+
this->implicitHdr = false;
544+
return(setHeaderType(RADIOLIB_SX1278_HEADER_EXPL_MODE, 0));
543545
}
544546

545547
int16_t SX1278::setBandwidthRaw(uint8_t newBandwidth) {
@@ -559,11 +561,13 @@ int16_t SX1278::setSpreadingFactorRaw(uint8_t newSpreadingFactor) {
559561
// write registers
560562
Module* mod = this->getMod();
561563
if(newSpreadingFactor == RADIOLIB_SX127X_SF_6) {
564+
this->implicitHdr = true;
562565
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_IMPL_MODE, 0, 0);
563566
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
564567
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0);
565568
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6);
566569
} else {
570+
this->implicitHdr = false;
567571
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_EXPL_MODE, 0, 0);
568572
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
569573
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0);
@@ -582,27 +586,6 @@ int16_t SX1278::setCodingRateRaw(uint8_t newCodingRate) {
582586
return(state);
583587
}
584588

585-
int16_t SX1278::setHeaderType(uint8_t headerType, size_t len) {
586-
// check active modem
587-
if(getActiveModem() != RADIOLIB_SX127X_LORA) {
588-
return(RADIOLIB_ERR_WRONG_MODEM);
589-
}
590-
591-
// set requested packet mode
592-
Module* mod = this->getMod();
593-
int16_t state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 0, 0);
594-
RADIOLIB_ASSERT(state);
595-
596-
// set length to register
597-
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len);
598-
RADIOLIB_ASSERT(state);
599-
600-
// update cached value
601-
SX127x::packetLength = len;
602-
603-
return(state);
604-
}
605-
606589
int16_t SX1278::configFSK() {
607590
// configure common registers
608591
int16_t state = SX127x::configFSK();

software/firmware/source/libraries/RadioLib/src/modules/SX127x/SX1278.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ class SX1278: public SX127x {
328328
int16_t setBandwidthRaw(uint8_t newBandwidth);
329329
int16_t setSpreadingFactorRaw(uint8_t newSpreadingFactor);
330330
int16_t setCodingRateRaw(uint8_t newCodingRate);
331-
int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);
332331

333332
int16_t configFSK();
334333
void errataFix(bool rx) override;

0 commit comments

Comments
 (0)