From 60ad1793e410f2a3ff690c39f82a4bce90b2c57d Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 16 Jun 2020 06:26:21 -0700 Subject: [PATCH] sx1262 improvements attn @dafeman --- src/mesh/RadioLibInterface.cpp | 2 ++ src/mesh/RadioLibInterface.h | 11 +++++++---- src/mesh/SX1262Interface.cpp | 19 ++++++++++--------- src/mesh/SX1262Interface.h | 5 ++--- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 8fb1ce78..f0451079 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -304,6 +304,8 @@ void RadioLibInterface::startSend(MeshPacket *txp) printPacket("Starting low level send", txp); setStandby(); // Cancel any already in process receives + configHardwareForSend(); // must be after setStandby + size_t numbytes = beginSending(txp); int res = iface->startTransmit(radiobuf, numbytes); diff --git a/src/mesh/RadioLibInterface.h b/src/mesh/RadioLibInterface.h index 5f70d027..706fcdf0 100644 --- a/src/mesh/RadioLibInterface.h +++ b/src/mesh/RadioLibInterface.h @@ -105,16 +105,19 @@ class RadioLibInterface : public RadioInterface, private PeriodicTask virtual void doTask(); + /** start an immediate transmit + * This method is virtual so subclasses can hook as needed, subclasses should not call directly + */ + virtual void startSend(MeshPacket *txp); + protected: /// Initialise the Driver transport hardware and software. /// 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); + /** Do any hardware setup needed on entry into send configuration for the radio. Subclasses can customize */ + virtual void configHardwareForSend() {} /** * Convert our modemConfig enum into wf, sf, etc... diff --git a/src/mesh/SX1262Interface.cpp b/src/mesh/SX1262Interface.cpp index 628ec995..3fe4afa3 100644 --- a/src/mesh/SX1262Interface.cpp +++ b/src/mesh/SX1262Interface.cpp @@ -16,9 +16,9 @@ bool SX1262Interface::init() #ifdef SX1262_RXEN // set not rx or tx mode pinMode(SX1262_RXEN, OUTPUT); +#endif +#ifdef SX1262_TXEN pinMode(SX1262_TXEN, OUTPUT); - digitalWrite(SX1262_RXEN, LOW); - digitalWrite(SX1262_TXEN, LOW); #endif #ifndef SX1262_E22 @@ -36,7 +36,7 @@ bool SX1262Interface::init() 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 + // lora.begin sets Dio2 as RF switch control, which is not true if we are manually controlling RX and TX if (res == ERR_NONE) res = lora.setDio2AsRfSwitch(false); #endif @@ -101,6 +101,8 @@ void SX1262Interface::setStandby() #ifdef SX1262_RXEN // we have RXEN/TXEN control - turn off RX and TX power digitalWrite(SX1262_RXEN, LOW); +#endif +#ifdef SX1262_TXEN digitalWrite(SX1262_TXEN, LOW); #endif @@ -120,14 +122,13 @@ void SX1262Interface::addReceiveMetadata(MeshPacket *mp) /** start an immediate transmit * We override to turn on transmitter power as needed. */ -void SX1262Interface::startSend(MeshPacket *txp) +void SX1262Interface::configHardwareForSend() { -#ifdef SX1262_RXEN // we have RXEN/TXEN control - turn on TX power / off RX power - digitalWrite(SX1262_RXEN, LOW); +#ifdef SX1262_TXEN // we have RXEN/TXEN control - turn on TX power / off RX power digitalWrite(SX1262_TXEN, HIGH); #endif - RadioLibInterface::startSend(txp); + RadioLibInterface::configHardwareForSend(); } // For power draw measurements, helpful to force radio to stay sleeping @@ -139,12 +140,12 @@ void SX1262Interface::startReceive() sleep(); #else + setStandby(); + #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 // standby mostly. diff --git a/src/mesh/SX1262Interface.h b/src/mesh/SX1262Interface.h index 1eee86a6..30167bc2 100644 --- a/src/mesh/SX1262Interface.h +++ b/src/mesh/SX1262Interface.h @@ -44,10 +44,10 @@ class SX1262Interface : public RadioLibInterface */ virtual void startReceive(); - /** start an immediate transmit + /** * We override to turn on transmitter power as needed. */ - virtual void startSend(MeshPacket *txp); + virtual void configHardwareForSend(); /** * Add SNR data to received messages @@ -57,5 +57,4 @@ class SX1262Interface : public RadioLibInterface virtual void setStandby(); private: - }; \ No newline at end of file