kopia lustrzana https://github.com/jgromes/RadioLib
Add function to set DIO2 of SX126x chips to be used as RF antenna switch (based on example design of Semtech and used in many modules).
This breaks the CAD function as DIO2 cannot be used as IRQ output. Signed-off-by: Bernd Giesecke <bernd@giesecke.tk>pull/17/head
rodzic
5c2bd2bc32
commit
8fc323a900
|
@ -79,6 +79,10 @@ void Module::term() {
|
|||
_spi->end();
|
||||
}
|
||||
|
||||
void Module::setDio2Func(bool enable) {
|
||||
_dio2RfSwitch = enable;
|
||||
}
|
||||
|
||||
void Module::ATemptyBuffer() {
|
||||
while(ModuleSerial->available() > 0) {
|
||||
ModuleSerial->read();
|
||||
|
|
16
src/Module.h
16
src/Module.h
|
@ -277,6 +277,20 @@ 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.
|
||||
|
||||
|
@ -297,7 +311,7 @@ class Module {
|
|||
int _rx;
|
||||
int _int0;
|
||||
int _int1;
|
||||
|
||||
bool _dio2RfSwitch = false;
|
||||
SPIClass* _spi;
|
||||
SPISettings _spiSettings;
|
||||
|
||||
|
|
|
@ -274,6 +274,11 @@ int16_t SX126x::scanChannel() {
|
|||
return(ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
if (_mod->getDio2Func()) {
|
||||
// If DIO2 is used as RF switch this function does not work
|
||||
return(ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
// set mode to standby
|
||||
int16_t state = standby();
|
||||
if(state != ERR_NONE) {
|
||||
|
@ -1058,6 +1063,29 @@ int16_t SX126x::setFrequencyRaw(float freq) {
|
|||
return(ERR_NONE);
|
||||
}
|
||||
|
||||
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];
|
||||
if (enable) {
|
||||
// set DIO2 as RF switch
|
||||
data[0] = SX126X_DIO2_AS_RF_SWITCH;
|
||||
} else {
|
||||
data[0] = SX126X_DIO2_AS_IRQ;
|
||||
}
|
||||
int16_t state = SPIwriteCommand(SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL, data, 1);
|
||||
|
||||
if (state == ERR_NONE) {
|
||||
_mod->setDio2Func(enable);
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX126x::config(uint8_t modem) {
|
||||
// set DIO2 as IRQ
|
||||
uint8_t* data = new uint8_t[1];
|
||||
|
|
|
@ -678,6 +678,13 @@ class SX126x: public PhysicalLayer {
|
|||
*/
|
||||
float getSNR();
|
||||
|
||||
/*!
|
||||
\brief Set DIO2 to function as RF switch (default in Semtech example designs).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDio2AsRfSwitch(bool enable = false);
|
||||
|
||||
protected:
|
||||
// SX1276x SPI command implementations
|
||||
int16_t setTx(uint32_t timeout = 0);
|
||||
|
|
Ładowanie…
Reference in New Issue