[SX128x] Implemented RF switch control

This commit is contained in:
jgromes 2020-06-18 16:36:02 +02:00
parent d1527b0d8c
commit 5a3d7a7173
3 changed files with 30 additions and 0 deletions

View file

@ -47,6 +47,16 @@ void setup() {
Serial.println(state);
while (true);
}
// some modules have an external RF switch
// controlled via two pins (RX enable, TX enable)
// to enable automatic control of the switch,
// call the following method
// RX enable: 4
// TX enable: 5
/*
lora.setRfSwitchPins(4, 5);
*/
}
void loop() {

View file

@ -477,6 +477,9 @@ int16_t SX128x::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
state = clearIrqStatus();
RADIOLIB_ASSERT(state);
// set RF switch (if present)
_mod->setRfSwitchState(true);
// start transmission
state = setTx(SX128X_TX_TIMEOUT_NONE);
RADIOLIB_ASSERT(state);
@ -513,6 +516,9 @@ int16_t SX128x::startReceive(uint16_t timeout) {
RADIOLIB_ASSERT(state);
}
// set RF switch (if present)
_mod->setRfSwitchState(false);
// set mode to receive
state = setRx(timeout);
@ -1090,6 +1096,10 @@ int16_t SX128x::setEncoding(uint8_t encoding) {
return(setWhitening(encoding));
}
void SX128x::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) {
_mod->setRfSwitchPins(rxEn, txEn);
}
uint8_t SX128x::getStatus() {
uint8_t data = 0;
SPIreadCommand(SX128X_CMD_GET_STATUS, &data, 1);

View file

@ -741,6 +741,16 @@ class SX128x: public PhysicalLayer {
*/
int16_t setEncoding(uint8_t encoding);
/*!
\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);
#ifndef RADIOLIB_GODMODE
protected:
#endif