[SX127x] Implemented new common PHY methods

This commit is contained in:
jgromes 2023-07-06 11:17:29 +02:00
parent d561d41e95
commit d5ce384bda
10 changed files with 184 additions and 23 deletions

View file

@ -220,6 +220,35 @@ 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);
}
return(state);
}
int16_t SX1272::setOutputPower(int8_t power) {
return(this->setOutputPower(power, false));
}
int16_t SX1272::setOutputPower(int8_t power, bool useRfo) {
// check allowed power range
if(useRfo) {

View file

@ -176,14 +176,29 @@ class SX1272: public SX127x {
\returns \ref status_codes
*/
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 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. Defaults to PA_BOOST.
\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 = false);
int16_t setOutputPower(int8_t power, 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.

View file

@ -66,4 +66,29 @@ int16_t SX1273::setSpreadingFactor(uint8_t 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);
}
#endif

View file

@ -49,6 +49,13 @@ class SX1273: public SX1272 {
*/
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;
#if !defined(RADIOLIB_GODMODE)
private:
#endif

View file

@ -107,4 +107,29 @@ int16_t SX1277::setSpreadingFactor(uint8_t 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);
}
#endif

View file

@ -69,6 +69,13 @@ class SX1277: public SX1278 {
\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;
#if !defined(RADIOLIB_GODMODE)
private:

View file

@ -234,6 +234,35 @@ 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);
}
return(state);
}
int16_t SX1278::setOutputPower(int8_t power) {
return(this->setOutputPower(power, false));
}
int16_t SX1278::setOutputPower(int8_t power, bool useRfo) {
// check allowed power range
if(useRfo) {

View file

@ -184,15 +184,30 @@ class SX1278: public SX127x {
\returns \ref status_codes
*/
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 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. Defaults to PA_BOOST.
\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 = false);
int16_t setOutputPower(int8_t power, 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.

View file

@ -729,7 +729,7 @@ int16_t SX127x::setCurrentLimit(uint8_t currentLimit) {
return(state);
}
int16_t SX127x::setPreambleLength(uint16_t preambleLength) {
int16_t SX127x::setPreambleLength(size_t preambleLength) {
// set mode to standby
int16_t state = setMode(RADIOLIB_SX127X_STANDBY);
RADIOLIB_ASSERT(state);
@ -973,27 +973,36 @@ int16_t SX127x::setAFCAGCTrigger(uint8_t trigger) {
int16_t SX127x::setSyncWord(uint8_t* syncWord, size_t len) {
// check active modem
if(getActiveModem() != RADIOLIB_SX127X_FSK_OOK) {
return(RADIOLIB_ERR_WRONG_MODEM);
}
uint8_t modem = getActiveModem();
if(modem == RADIOLIB_SX127X_FSK_OOK) {
RADIOLIB_CHECK_RANGE(len, 1, 8, RADIOLIB_ERR_INVALID_SYNC_WORD);
RADIOLIB_CHECK_RANGE(len, 1, 8, RADIOLIB_ERR_INVALID_SYNC_WORD);
// sync word must not contain value 0x00
for(size_t i = 0; i < len; i++) {
if(syncWord[i] == 0x00) {
return(RADIOLIB_ERR_INVALID_SYNC_WORD);
}
}
// sync word must not contain value 0x00
for(size_t i = 0; i < len; i++) {
if(syncWord[i] == 0x00) {
// enable sync word recognition
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, RADIOLIB_SX127X_SYNC_ON, 4, 4);
state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, len - 1, 2, 0);
RADIOLIB_ASSERT(state);
// set sync word
this->mod->SPIwriteRegisterBurst(RADIOLIB_SX127X_REG_SYNC_VALUE_1, syncWord, len);
return(RADIOLIB_ERR_NONE);
} else if(modem == RADIOLIB_SX127X_LORA) {
// with length set to 1 and LoRa modem active, assume it is the LoRa sync word
if(len > 1) {
return(RADIOLIB_ERR_INVALID_SYNC_WORD);
}
return(this->setSyncWord(syncWord[0]));
}
// enable sync word recognition
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, RADIOLIB_SX127X_SYNC_ON, 4, 4);
state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, len - 1, 2, 0);
RADIOLIB_ASSERT(state);
// set sync word
this->mod->SPIwriteRegisterBurst(RADIOLIB_SX127X_REG_SYNC_VALUE_1, syncWord, len);
return(RADIOLIB_ERR_NONE);
return(RADIOLIB_ERR_WRONG_MODEM);
}
int16_t SX127x::setNodeAddress(uint8_t nodeAddr) {

View file

@ -856,7 +856,7 @@ class SX127x: public PhysicalLayer {
\param preambleLength Preamble length to be set (in symbols when in LoRa mode or bits in FSK mode).
\returns \ref status_codes
*/
int16_t setPreambleLength(uint16_t preambleLength);
int16_t setPreambleLength(size_t preambleLength) override;
/*!
\brief Gets frequency error of the latest received packet.
@ -924,7 +924,7 @@ class SX127x: public PhysicalLayer {
\param len Sync word length (in bytes).
\returns \ref status_codes
*/
int16_t setSyncWord(uint8_t* syncWord, size_t len);
int16_t setSyncWord(uint8_t* syncWord, size_t len) override;
/*!
\brief Sets FSK node address. Calling this method will enable address filtering. Only available in FSK mode.
@ -1089,7 +1089,7 @@ class SX127x: public PhysicalLayer {
\param enable QI inversion enabled (true) or disabled (false);
\returns \ref status_codes
*/
int16_t invertIQ(bool enable);
int16_t invertIQ(bool enable) override;
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
/*!