Add helper functions for SX1277, SX1278, SX1279

This commit is contained in:
Nathan Seidle 2022-01-17 11:35:19 -07:00
parent 3cc299d17b
commit 20e1ab23df
7 changed files with 156 additions and 5 deletions

View file

@ -100,4 +100,24 @@ int16_t SX1277::setSpreadingFactor(uint8_t sf) {
return(state);
}
int16_t SX1277::setFHSSHoppingPeriod(uint8_t freqHoppingPeriod) {
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD, freqHoppingPeriod));
}
uint8_t SX1277::getFHSSHoppingPeriod(void) {
return(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD));
}
uint8_t SX1277::getFHSSChannel(void) {
return(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_CHANNEL, 5, 0));
}
void SX1277::clearFHSSInt(void) {
int16_t modem = getActiveModem();
if(modem == RADIOLIB_SX127X_LORA) {
_mod->SPIwriteRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS, getIRQFlags() | RADIOLIB_SX127X_CLEAR_IRQ_FLAG_FHSS_CHANGE_CHANNEL);
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
return; //These are not the interrupts you are looking for
}
}
#endif

View file

@ -93,6 +93,34 @@ class SX1277: public SX1278 {
*/
int16_t setSpreadingFactor(uint8_t sf);
/*!
\brief Sets the hopping period and enables FHSS
\param freqHoppingPeriod Integer multiple of symbol periods between hops
\returns \ref status_codes
*/
int16_t setFHSSHoppingPeriod(uint8_t freqHoppingPeriod);
/*!
\brief Gets FHSS hopping period
\returns 8 bit period
*/
uint8_t getFHSSHoppingPeriod(void);
/*!
\brief Gets the FHSS channel in use
\returns 6 bit channel number
*/
uint8_t getFHSSChannel(void);
/*!
\brief Clear the FHSS interrupt
*/
void clearFHSSInt(void);
#if !defined(RADIOLIB_GODMODE)
private:
#endif

View file

@ -623,4 +623,25 @@ void SX1278::errataFix(bool rx) {
_mod->SPIsetRegValue(0x30, fixedRegs[2]);
}
int16_t SX1278::setFHSSHoppingPeriod(uint8_t freqHoppingPeriod) {
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD, freqHoppingPeriod));
}
uint8_t SX1278::getFHSSHoppingPeriod(void) {
return(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD));
}
uint8_t SX1278::getFHSSChannel(void) {
return(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_CHANNEL, 5, 0));
}
void SX1278::clearFHSSInt(void) {
int16_t modem = getActiveModem();
if(modem == RADIOLIB_SX127X_LORA) {
_mod->SPIwriteRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS, getIRQFlags() | RADIOLIB_SX127X_CLEAR_IRQ_FLAG_FHSS_CHANGE_CHANNEL);
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
return; //These are not the interrupts you are looking for
}
}
#endif

View file

@ -302,6 +302,34 @@ class SX1278: public SX127x {
*/
int16_t explicitHeader();
/*!
\brief Sets the hopping period and enables FHSS
\param freqHoppingPeriod Integer multiple of symbol periods between hops
\returns \ref status_codes
*/
int16_t setFHSSHoppingPeriod(uint8_t freqHoppingPeriod);
/*!
\brief Gets FHSS hopping period
\returns 8 bit period
*/
uint8_t getFHSSHoppingPeriod(void);
/*!
\brief Gets the FHSS channel in use
\returns 6 bit channel number
*/
uint8_t getFHSSChannel(void);
/*!
\brief Clear the FHSS interrupt
*/
void clearFHSSInt(void);
#if !defined(RADIOLIB_GODMODE)
protected:
#endif

View file

@ -70,4 +70,25 @@ int16_t SX1279::setFrequency(float freq) {
return(state);
}
int16_t SX1279::setFHSSHoppingPeriod(uint8_t freqHoppingPeriod) {
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD, freqHoppingPeriod));
}
uint8_t SX1279::getFHSSHoppingPeriod(void) {
return(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD));
}
uint8_t SX1279::getFHSSChannel(void) {
return(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_CHANNEL, 5, 0));
}
void SX1279::clearFHSSInt(void) {
int16_t modem = getActiveModem();
if(modem == RADIOLIB_SX127X_LORA) {
_mod->SPIwriteRegister(RADIOLIB_SX127X_REG_IRQ_FLAGS, getIRQFlags() | RADIOLIB_SX127X_CLEAR_IRQ_FLAG_FHSS_CHANGE_CHANNEL);
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
return; //These are not the interrupts you are looking for
}
}
#endif

View file

@ -84,6 +84,34 @@ class SX1279: public SX1278 {
*/
int16_t setFrequency(float freq);
/*!
\brief Sets the hopping period and enables FHSS
\param freqHoppingPeriod Integer multiple of symbol periods between hops
\returns \ref status_codes
*/
int16_t setFHSSHoppingPeriod(uint8_t freqHoppingPeriod);
/*!
\brief Gets FHSS hopping period
\returns 8 bit period
*/
uint8_t getFHSSHoppingPeriod(void);
/*!
\brief Gets the FHSS channel in use
\returns 6 bit channel number
*/
uint8_t getFHSSChannel(void);
/*!
\brief Clear the FHSS interrupt
*/
void clearFHSSInt(void);
#if !defined(RADIOLIB_GODMODE)
private:
#endif

View file

@ -375,10 +375,12 @@ int16_t SX127x::startReceive(uint8_t len, uint8_t mode) {
int16_t modem = getActiveModem();
if(modem == RADIOLIB_SX127X_LORA) {
// set DIO pin mapping
if(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD) > RADIOLIB_SX127X_HOP_PERIOD_OFF)
if(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD) > RADIOLIB_SX127X_HOP_PERIOD_OFF) {
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_RX_DONE | RADIOLIB_SX127X_DIO1_FHSS_CHANGE_CHANNEL, 7, 4);
else
}
else {
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_RX_DONE | RADIOLIB_SX127X_DIO1_RX_TIMEOUT, 7, 4);
}
// set expected packet length for SF6
if(_sf == 6) {
@ -451,10 +453,12 @@ int16_t SX127x::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
}
// set DIO mapping
if(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD) > RADIOLIB_SX127X_HOP_PERIOD_OFF)
if(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD) > RADIOLIB_SX127X_HOP_PERIOD_OFF) {
_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_TX_DONE | RADIOLIB_SX127X_DIO1_FHSS_CHANGE_CHANNEL, 7, 4);
else
}
else {
_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_TX_DONE, 7, 6);
}
// apply fixes to errata
RADIOLIB_ERRATA_SX127X(false);
@ -996,8 +1000,9 @@ int16_t SX127x::setFrequencyRaw(float newFreq) {
int16_t state = RADIOLIB_ERR_NONE;
// set mode to standby if not FHSS
if(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD) == RADIOLIB_SX127X_HOP_PERIOD_OFF)
if(_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_PERIOD) == RADIOLIB_SX127X_HOP_PERIOD_OFF) {
state = setMode(RADIOLIB_SX127X_STANDBY);
}
// calculate register values
uint32_t FRF = (newFreq * (uint32_t(1) << RADIOLIB_SX127X_DIV_EXPONENT)) / RADIOLIB_SX127X_CRYSTAL_FREQ;