Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHY] Get/Set modem #1294

Merged
merged 15 commits into from
Oct 26, 2024
Prev Previous commit
Next Next commit
[SX127x] Added get/set modem
  • Loading branch information
jgromes committed Oct 26, 2024
commit 301654ead407ecd3da513e9df72afb9e3422cb1c
13 changes: 13 additions & 0 deletions src/modules/SX127x/SX1272.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,17 @@ void SX1272::errataFix(bool rx) {
mod->SPIsetRegValue(0x31, 0b10000000, 7, 7);
}

int16_t SX1272::setModem(ModemType_t modem) {
switch(modem) {
case(ModemType_t::LoRa): {
return(this->begin());
} break;
case(ModemType_t::FSK): {
return(this->beginFSK());
} break;
default:
return(RADIOLIB_ERR_WRONG_MODEM);
}
}

#endif
8 changes: 8 additions & 0 deletions src/modules/SX127x/SX1272.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ class SX1272: public SX127x {
\returns \ref status_codes
*/
int16_t explicitHeader();

/*!
\brief Set modem for the radio to use. Will perform full reset and reconfigure the radio
using its default parameters.
\param modem Modem type to set - FSK or LoRa.
\returns \ref status_codes
*/
int16_t setModem(ModemType_t modem) override;

#if !RADIOLIB_GODMODE
protected:
Expand Down
13 changes: 13 additions & 0 deletions src/modules/SX127x/SX1273.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,17 @@ int16_t SX1273::checkDataRate(DataRate_t dr) {
return(state);
}

int16_t SX1273::setModem(ModemType_t modem) {
switch(modem) {
case(ModemType_t::LoRa): {
return(this->begin());
} break;
case(ModemType_t::FSK): {
return(this->beginFSK());
} break;
default:
return(RADIOLIB_ERR_WRONG_MODEM);
}
}

#endif
8 changes: 8 additions & 0 deletions src/modules/SX127x/SX1273.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ class SX1273: public SX1272 {
\returns \ref status_codes
*/
int16_t checkDataRate(DataRate_t dr) override;

/*!
\brief Set modem for the radio to use. Will perform full reset and reconfigure the radio
using its default parameters.
\param modem Modem type to set - FSK or LoRa.
\returns \ref status_codes
*/
int16_t setModem(ModemType_t modem) override;

#if !RADIOLIB_GODMODE
private:
Expand Down
13 changes: 13 additions & 0 deletions src/modules/SX127x/SX1276.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,17 @@ int16_t SX1276::setFrequency(float freq) {
return(state);
}

int16_t SX1276::setModem(ModemType_t modem) {
switch(modem) {
case(ModemType_t::LoRa): {
return(this->begin());
} break;
case(ModemType_t::FSK): {
return(this->beginFSK());
} break;
default:
return(RADIOLIB_ERR_WRONG_MODEM);
}
}

#endif
8 changes: 8 additions & 0 deletions src/modules/SX127x/SX1276.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ class SX1276: public SX1278 {
\returns \ref status_codes
*/
int16_t setFrequency(float freq) override;

/*!
\brief Set modem for the radio to use. Will perform full reset and reconfigure the radio
using its default parameters.
\param modem Modem type to set - FSK or LoRa.
\returns \ref status_codes
*/
int16_t setModem(ModemType_t modem) override;

#if !RADIOLIB_GODMODE
private:
Expand Down
13 changes: 13 additions & 0 deletions src/modules/SX127x/SX1277.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,17 @@ int16_t SX1277::checkDataRate(DataRate_t dr) {
return(state);
}

int16_t SX1277::setModem(ModemType_t modem) {
switch(modem) {
case(ModemType_t::LoRa): {
return(this->begin());
} break;
case(ModemType_t::FSK): {
return(this->beginFSK());
} break;
default:
return(RADIOLIB_ERR_WRONG_MODEM);
}
}

#endif
8 changes: 8 additions & 0 deletions src/modules/SX127x/SX1277.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ class SX1277: public SX1278 {
\returns \ref status_codes
*/
int16_t checkDataRate(DataRate_t dr) override;

/*!
\brief Set modem for the radio to use. Will perform full reset and reconfigure the radio
using its default parameters.
\param modem Modem type to set - FSK or LoRa.
\returns \ref status_codes
*/
int16_t setModem(ModemType_t modem) override;

#if !RADIOLIB_GODMODE
private:
Expand Down
13 changes: 13 additions & 0 deletions src/modules/SX127x/SX1278.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,4 +705,17 @@ void SX1278::errataFix(bool rx) {
mod->SPIsetRegValue(0x30, fixedRegs[2]);
}

int16_t SX1278::setModem(ModemType_t modem) {
switch(modem) {
case(ModemType_t::LoRa): {
return(this->begin());
} break;
case(ModemType_t::FSK): {
return(this->beginFSK());
} break;
default:
return(RADIOLIB_ERR_WRONG_MODEM);
}
}

#endif
8 changes: 8 additions & 0 deletions src/modules/SX127x/SX1278.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ class SX1278: public SX127x {
\returns \ref status_codes
*/
int16_t explicitHeader();

/*!
\brief Set modem for the radio to use. Will perform full reset and reconfigure the radio
using its default parameters.
\param modem Modem type to set - FSK or LoRa.
\returns \ref status_codes
*/
int16_t setModem(ModemType_t modem) override;

#if !RADIOLIB_GODMODE
protected:
Expand Down
13 changes: 13 additions & 0 deletions src/modules/SX127x/SX1279.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,17 @@ int16_t SX1279::setFrequency(float freq) {
return(state);
}

int16_t SX1279::setModem(ModemType_t modem) {
switch(modem) {
case(ModemType_t::LoRa): {
return(this->begin());
} break;
case(ModemType_t::FSK): {
return(this->beginFSK());
} break;
default:
return(RADIOLIB_ERR_WRONG_MODEM);
}
}

#endif
8 changes: 8 additions & 0 deletions src/modules/SX127x/SX1279.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ class SX1279: public SX1278 {
\returns \ref status_codes
*/
int16_t setFrequency(float freq) override;

/*!
\brief Set modem for the radio to use. Will perform full reset and reconfigure the radio
using its default parameters.
\param modem Modem type to set - FSK or LoRa.
\returns \ref status_codes
*/
int16_t setModem(ModemType_t modem) override;

#if !RADIOLIB_GODMODE
private:
Expand Down
18 changes: 18 additions & 0 deletions src/modules/SX127x/SX127x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,24 @@ int16_t SX127x::invertIQ(bool enable) {
return(state);
}

int16_t SX127x::getModem(ModemType_t* modem) {
if(!modem) {
return(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED);
}

int16_t packetType = getActiveModem();
switch(packetType) {
case(RADIOLIB_SX127X_LORA):
*modem = ModemType_t::LoRa;
return(RADIOLIB_ERR_NONE);
case(RADIOLIB_SX127X_FSK_OOK):
*modem = ModemType_t::FSK;
return(RADIOLIB_ERR_NONE);
}

return(RADIOLIB_ERR_WRONG_MODEM);
}

#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
void SX127x::setDirectAction(void (*func)(void)) {
setDio1Action(func, this->mod->hal->GpioInterruptRising);
Expand Down
7 changes: 7 additions & 0 deletions src/modules/SX127x/SX127x.h
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,13 @@ class SX127x: public PhysicalLayer {
*/
int16_t invertIQ(bool enable) override;

/*!
\brief Get modem currently in use by the radio.
\param modem Pointer to a variable to save the retrieved configuration into.
\returns \ref status_codes
*/
int16_t getModem(ModemType_t* modem) override;

#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
/*!
\brief Set interrupt service routine function to call when data bit is received in direct mode.
Expand Down