Moved setDio2AsRfSwitch()
from module to SX126x
Added new error code Removed memory leak Signed-off-by: Bernd Giesecke <bernd@giesecke.tk>
This commit is contained in:
parent
8fc323a900
commit
23b0b9b25a
5 changed files with 13 additions and 31 deletions
|
@ -79,10 +79,6 @@ void Module::term() {
|
|||
_spi->end();
|
||||
}
|
||||
|
||||
void Module::setDio2Func(bool enable) {
|
||||
_dio2RfSwitch = enable;
|
||||
}
|
||||
|
||||
void Module::ATemptyBuffer() {
|
||||
while(ModuleSerial->available() > 0) {
|
||||
ModuleSerial->read();
|
||||
|
|
15
src/Module.h
15
src/Module.h
|
@ -277,20 +277,6 @@ class Module {
|
|||
*/
|
||||
int getTx() const { return(_tx); }
|
||||
|
||||
/*!
|
||||
\brief Access method to get DIO2 RF switch flag.
|
||||
|
||||
\returns true if DIO2 is set as RF switch.
|
||||
*/
|
||||
int getDio2Func() const { return(_dio2RfSwitch); }
|
||||
|
||||
/*!
|
||||
\brief Access method to set/reset DIO2 RF switch flag.
|
||||
|
||||
\returns true if DIO2 is set as RF switch.
|
||||
*/
|
||||
void setDio2Func(bool enable);
|
||||
|
||||
/*!
|
||||
\brief Access method to get the SPI interface.
|
||||
|
||||
|
@ -311,7 +297,6 @@ class Module {
|
|||
int _rx;
|
||||
int _int0;
|
||||
int _int1;
|
||||
bool _dio2RfSwitch = false;
|
||||
SPIClass* _spi;
|
||||
SPISettings _spiSettings;
|
||||
|
||||
|
|
|
@ -461,6 +461,11 @@
|
|||
*/
|
||||
#define ERR_SPI_CMD_FAILED -707
|
||||
|
||||
/*!
|
||||
\brief SX126x scan channel not possible because DIO2 is used as RF antenna switch.
|
||||
*/
|
||||
#define ERR_DIO2_UNAVAIL_CAD_FAILED -708
|
||||
|
||||
/*!
|
||||
\}
|
||||
*/
|
||||
|
|
|
@ -274,9 +274,9 @@ int16_t SX126x::scanChannel() {
|
|||
return(ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
if (_mod->getDio2Func()) {
|
||||
if (_dio2RfSwitch) {
|
||||
// If DIO2 is used as RF switch this function does not work
|
||||
return(ERR_WRONG_MODEM);
|
||||
return(ERR_DIO2_UNAVAIL_CAD_FAILED);
|
||||
}
|
||||
|
||||
// set mode to standby
|
||||
|
@ -1064,14 +1064,7 @@ int16_t SX126x::setFrequencyRaw(float freq) {
|
|||
}
|
||||
|
||||
int16_t SX126x::setDio2AsRfSwitch(bool enable) {
|
||||
int dio2 = _mod->getInt1();
|
||||
if (dio2 == -1)
|
||||
{
|
||||
// DIO2 is not defined, return error
|
||||
_mod->setDio2Func(false);
|
||||
return ERR_WRONG_MODEM;
|
||||
}
|
||||
uint8_t* data = new uint8_t[1];
|
||||
uint8_t data[1];
|
||||
if (enable) {
|
||||
// set DIO2 as RF switch
|
||||
data[0] = SX126X_DIO2_AS_RF_SWITCH;
|
||||
|
@ -1081,13 +1074,14 @@ int16_t SX126x::setDio2AsRfSwitch(bool enable) {
|
|||
int16_t state = SPIwriteCommand(SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL, data, 1);
|
||||
|
||||
if (state == ERR_NONE) {
|
||||
_mod->setDio2Func(enable);
|
||||
_dio2RfSwitch = true;
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX126x::config(uint8_t modem) {
|
||||
// set DIO2 as IRQ
|
||||
_dio2RfSwitch = false;
|
||||
uint8_t* data = new uint8_t[1];
|
||||
data[0] = SX126X_DIO2_AS_IRQ;
|
||||
int16_t state = SPIwriteCommand(SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL, data, 1);
|
||||
|
|
|
@ -683,7 +683,7 @@ class SX126x: public PhysicalLayer {
|
|||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDio2AsRfSwitch(bool enable = false);
|
||||
int16_t setDio2AsRfSwitch(bool enable = true);
|
||||
|
||||
protected:
|
||||
// SX1276x SPI command implementations
|
||||
|
@ -727,6 +727,8 @@ class SX126x: public PhysicalLayer {
|
|||
|
||||
float _dataRate;
|
||||
|
||||
bool _dio2RfSwitch = false;
|
||||
|
||||
int16_t config(uint8_t modem);
|
||||
|
||||
// common low-level SPI interface
|
||||
|
|
Loading…
Add table
Reference in a new issue