[SX126x] Add workaround for GFSK

pull/1642/head
jgromes 2025-10-24 16:12:39 +01:00
rodzic 1de98370eb
commit f73398533e
4 zmienionych plików z 54 dodań i 2 usunięć

Wyświetl plik

@ -1386,6 +1386,48 @@ int16_t SX126x::fixInvertedIQ(uint8_t iqConfig) {
return(writeRegister(RADIOLIB_SX126X_REG_IQ_CONFIG, &iqConfigCurrent, 1));
}
int16_t SX126x::fixGFSK() {
// method that applies some magic workaround for specific bitrate, frequency deviation,
// receiver bandwidth and carrier frequencies for GFSK (and resets it in all other cases)
// this is not documented in the datasheet, only in Semtech repositories for SX126x and LR11xx
// first, check we are using GFSK modem
if(getPacketType() != RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
// not in GFSK, nothing to do here
return(RADIOLIB_ERR_NONE);
}
// next, decide what to change based on modulation properties
int16_t state = RADIOLIB_ERR_UNKNOWN;
if(this->bitRate == 1200) {
// workaround for 1.2 kbps
state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_GFSK_FIX_3, 0x00, 4, 4);
} else if(this->bitRate == 600) {
// workaround for 0.6 kbps
state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_GFSK_FIX_1, 0x18, 4, 3);
RADIOLIB_ASSERT(state);
state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW, 0x04, 4, 2);
RADIOLIB_ASSERT(state);
state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_GFSK_FIX_3, 0x00, 4, 4);
RADIOLIB_ASSERT(state);
state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_GFSK_FIX_4, 0x50, 6, 4);
} else {
// reset
state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_GFSK_FIX_1, 0x08, 4, 3);
RADIOLIB_ASSERT(state);
state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW, 0x00, 4, 2);
RADIOLIB_ASSERT(state);
state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_GFSK_FIX_3, 0x10, 4, 4);
RADIOLIB_ASSERT(state);
state = this->mod->SPIsetRegValue(RADIOLIB_SX126X_REG_GFSK_FIX_4, 0x00, 6, 4);
}
return(state);
}
Module* SX126x::getMod() {
return(this->mod);
}

Wyświetl plik

@ -905,6 +905,7 @@ class SX126x: public PhysicalLayer {
int16_t fixSensitivity();
int16_t fixImplicitTimeout();
int16_t fixInvertedIQ(uint8_t iqConfig);
int16_t fixGFSK();
// LR-FHSS utilities
int16_t buildLRFHSSPacket(const uint8_t* in, size_t in_len, uint8_t* out, size_t* out_len, size_t* out_bits, size_t* out_hops);

Wyświetl plik

@ -238,10 +238,16 @@ int16_t SX126x::setBitRate(float br) {
this->bitRate = brRaw;
// update modulation parameters
int16_t state = RADIOLIB_ERR_UNKNOWN;
if(modem == RADIOLIB_SX126X_PACKET_TYPE_BPSK) {
return(setModulationParamsBPSK(this->bitRate));
state = setModulationParamsBPSK(this->bitRate);
} else {
state = setModulationParamsFSK(this->bitRate, this->pulseShape, this->rxBandwidth, this->frequencyDev);
}
return(setModulationParamsFSK(this->bitRate, this->pulseShape, this->rxBandwidth, this->frequencyDev));
RADIOLIB_ASSERT(state);
// apply workaround or reset it, as needed
return(fixGFSK());
}
int16_t SX126x::setDataRate(DataRate_t dr, ModemType_t modem) {

Wyświetl plik

@ -29,6 +29,7 @@
#define RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_0 0x0587
#define RADIOLIB_SX126X_REG_PATCH_UPDATE_ENABLE 0x0610
#define RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_1 0x0680
#define RADIOLIB_SX126X_REG_GFSK_FIX_4 0x06AC
#define RADIOLIB_SX126X_REG_WHITENING_INITIAL_MSB 0x06B8
#define RADIOLIB_SX126X_REG_WHITENING_INITIAL_LSB 0x06B9
#define RADIOLIB_SX126X_REG_RX_TX_PLD_LEN 0x06BB
@ -46,6 +47,7 @@
#define RADIOLIB_SX126X_REG_SYNC_WORD_7 0x06C7
#define RADIOLIB_SX126X_REG_NODE_ADDRESS 0x06CD
#define RADIOLIB_SX126X_REG_BROADCAST_ADDRESS 0x06CE
#define RADIOLIB_SX126X_REG_GFSK_FIX_1 0x06D1
#define RADIOLIB_SX126X_REG_PAYLOAD_LENGTH 0x0702
#define RADIOLIB_SX126X_REG_PACKET_PARAMS 0x0704
#define RADIOLIB_SX126X_REG_LORA_SYNC_TIMEOUT 0x0706
@ -67,6 +69,7 @@
#define RADIOLIB_SX126X_REG_RF_FREQUENCY_3 0x088E
#define RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW 0x089B
#define RADIOLIB_SX126X_REG_RX_GAIN 0x08AC
#define RADIOLIB_SX126X_REG_GFSK_FIX_3 0x08B8
#define RADIOLIB_SX126X_REG_TX_CLAMP_CONFIG 0x08D8
#define RADIOLIB_SX126X_REG_ANA_LNA 0x08E2
#define RADIOLIB_SX126X_REG_LNA_CAP_TUNE_N 0x08E3