From 78022ce6add50f50ce81bda59c374410e879597b Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 18 Jun 2020 16:31:38 +0200 Subject: [PATCH] Added external RF switch control base --- keywords.txt | 1 + src/Module.cpp | 24 ++++++++++++++++++++++++ src/Module.h | 20 ++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/keywords.txt b/keywords.txt index d7aa3950..f55c7fbf 100644 --- a/keywords.txt +++ b/keywords.txt @@ -127,6 +127,7 @@ setEncoding KEYWORD2 getIRQFlags KEYWORD2 getModemStatus KEYWORD2 getTempRaw KEYWORD2 +setRfSwitchPins KEYWORD2 # RF69-specific setAESKey KEYWORD2 diff --git a/src/Module.cpp b/src/Module.cpp index b4db0504..af6415bb 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -314,3 +314,27 @@ void Module::noTone(RADIOLIB_PIN_TYPE pin) { } #endif } + +void Module::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { + _useRfSwitch = true; + _rxEn = rxEn; + _txEn = txEn; + Module::pinMode(rxEn, OUTPUT); + Module::pinMode(txEn, OUTPUT); +} + +void Module::setRfSwitchState(bool tx) { + // check RF switch control is enabled + if(!_useRfSwitch) { + return; + } + + // set pins + if(tx) { + Module::digitalWrite(_rxEn, LOW); + Module::digitalWrite(_txEn, HIGH); + } else { + Module::digitalWrite(_rxEn, HIGH); + Module::digitalWrite(_txEn, LOW); + } +} diff --git a/src/Module.h b/src/Module.h index a77d1a7e..41e25299 100644 --- a/src/Module.h +++ b/src/Module.h @@ -386,6 +386,23 @@ class Module { */ static void noTone(RADIOLIB_PIN_TYPE pin); + /*! + \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. + When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch! + + \param rxEn RX enable pin. + + \param txEn TX enable pin. + */ + void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn); + + /*! + \brief Set RF switch state. + + \param tx True to set RF switch to Tx, false to set switch to Rx. + */ + void setRfSwitchState(bool tx); + #ifndef RADIOLIB_GODMODE private: #endif @@ -399,6 +416,9 @@ class Module { SPIClass* _spi; SPISettings _spiSettings; + bool _useRfSwitch = false; + RADIOLIB_PIN_TYPE _rxEn, _txEn; + uint32_t _ATtimeout = 15000; };