diff --git a/src/mesh/RadioLibInterface.h b/src/mesh/RadioLibInterface.h index 6619337b..5f70d027 100644 --- a/src/mesh/RadioLibInterface.h +++ b/src/mesh/RadioLibInterface.h @@ -91,9 +91,6 @@ class RadioLibInterface : public RadioInterface, private PeriodicTask virtual void startReceive() = 0; private: - /** start an immediate transmit */ - void startSend(MeshPacket *txp); - /** if we have something waiting to send, start a short random timer so we can come check for collision before actually doing * the transmit * @@ -113,7 +110,12 @@ class RadioLibInterface : public RadioInterface, private PeriodicTask /// Make sure the Driver is properly configured before calling init(). /// \return true if initialisation succeeded. virtual bool init(); - + + /** start an immediate transmit + * This method is virtual so subclasses can hook as needed, subclasses should not call directly + */ + virtual void startSend(MeshPacket *txp); + /** * Convert our modemConfig enum into wf, sf, etc... * diff --git a/src/mesh/SX1262Interface.cpp b/src/mesh/SX1262Interface.cpp index 69e7f8ee..628ec995 100644 --- a/src/mesh/SX1262Interface.cpp +++ b/src/mesh/SX1262Interface.cpp @@ -14,7 +14,19 @@ bool SX1262Interface::init() { RadioLibInterface::init(); - float tcxoVoltage = 0; // None - we use an XTAL +#ifdef SX1262_RXEN // set not rx or tx mode + pinMode(SX1262_RXEN, OUTPUT); + pinMode(SX1262_TXEN, OUTPUT); + digitalWrite(SX1262_RXEN, LOW); + digitalWrite(SX1262_TXEN, LOW); +#endif + +#ifndef SX1262_E22 + float tcxoVoltage = 0; // None - we use an XTAL +#else + float tcxoVoltage = + 2.4; // E22 uses DIO3 to power tcxo per https://github.com/jgromes/RadioLib/issues/12#issuecomment-520695575 +#endif bool useRegulatorLDO = false; // Seems to depend on the connection to pin 9/DCC_SW - if an inductor DCDC? applyModemConfig(); @@ -23,6 +35,12 @@ bool SX1262Interface::init() int res = lora.begin(freq, bw, sf, cr, syncWord, power, currentLimit, preambleLength, tcxoVoltage, useRegulatorLDO); DEBUG_MSG("LORA init result %d\n", res); +#ifdef SX1262_RXEN + // lora.begin assumes Dio2 is RF switch control, which is not true if we are manually controlling RX and TX + if (res == ERR_NONE) + res = lora.setDio2AsRfSwitch(false); +#endif + if (res == ERR_NONE) res = lora.setCRC(SX126X_LORA_CRC_ON); @@ -81,6 +99,11 @@ void SX1262Interface::setStandby() int err = lora.standby(); assert(err == ERR_NONE); +#ifdef SX1262_RXEN // we have RXEN/TXEN control - turn off RX and TX power + digitalWrite(SX1262_RXEN, LOW); + digitalWrite(SX1262_TXEN, LOW); +#endif + isReceiving = false; // If we were receiving, not any more disableInterrupt(); completeSending(); // If we were sending, not anymore @@ -94,6 +117,19 @@ void SX1262Interface::addReceiveMetadata(MeshPacket *mp) mp->rx_snr = lora.getSNR(); } +/** start an immediate transmit + * We override to turn on transmitter power as needed. + */ +void SX1262Interface::startSend(MeshPacket *txp) +{ +#ifdef SX1262_RXEN // we have RXEN/TXEN control - turn on TX power / off RX power + digitalWrite(SX1262_RXEN, LOW); + digitalWrite(SX1262_TXEN, HIGH); +#endif + + RadioLibInterface::startSend(txp); +} + // For power draw measurements, helpful to force radio to stay sleeping // #define SLEEP_ONLY @@ -102,6 +138,12 @@ void SX1262Interface::startReceive() #ifdef SLEEP_ONLY sleep(); #else + +#ifdef SX1262_RXEN // we have RXEN/TXEN control - turn on RX power / off TX power + digitalWrite(SX1262_RXEN, HIGH); + digitalWrite(SX1262_TXEN, LOW); +#endif + setStandby(); // int err = lora.startReceive(); int err = lora.startReceiveDutyCycleAuto(); // We use a 32 bit preamble so this should save some power by letting radio sit in diff --git a/src/mesh/SX1262Interface.h b/src/mesh/SX1262Interface.h index 92b301bf..1eee86a6 100644 --- a/src/mesh/SX1262Interface.h +++ b/src/mesh/SX1262Interface.h @@ -43,6 +43,12 @@ class SX1262Interface : public RadioLibInterface * Start waiting to receive a message */ virtual void startReceive(); + + /** start an immediate transmit + * We override to turn on transmitter power as needed. + */ + virtual void startSend(MeshPacket *txp); + /** * Add SNR data to received messages */ diff --git a/variants/ppr/variant.h b/variants/ppr/variant.h index 95b2803b..bbdda306 100644 --- a/variants/ppr/variant.h +++ b/variants/ppr/variant.h @@ -137,6 +137,7 @@ static const uint8_t SCK = PIN_SPI_SCK; // #define SX1262_ANT_SW (32 + 10) #define SX1262_RXEN (22) #define SX1262_TXEN (24) +#define SX1262_E22 // Indicates this SX1262 is inside of an ebyte E22 module and special config should be done for that // ERC12864-10 LCD #define ERC12864_CS (32 + 4)