diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index 64758cd0d..cfb97e673 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -25,11 +25,11 @@ bool SX126xInterface::init() pinMode(SX126X_POWER_EN, OUTPUT); #endif -#ifdef SX126X_RXEN // set not rx or tx mode +#if defined(SX126X_RXEN) && (SX126X_RXEN != RADIOLIB_NC) // set not rx or tx mode digitalWrite(SX126X_RXEN, LOW); // Set low before becoming an output pinMode(SX126X_RXEN, OUTPUT); #endif -#ifdef SX126X_TXEN +#if defined(SX126X_TXEN) && (SX126X_TXEN != RADIOLIB_NC) digitalWrite(SX126X_TXEN, LOW); pinMode(SX126X_TXEN, OUTPUT); #endif @@ -66,7 +66,7 @@ bool SX126xInterface::init() DEBUG_MSG("Current limit set to %f\n", currentLimit); DEBUG_MSG("Current limit set result %d\n", res); -#ifdef SX126X_TXEN +#if defined(SX126X_TXEN) && (SX126X_TXEN != RADIOLIB_NC) // lora.begin sets Dio2 as RF switch control, which is not true if we are manually controlling RX and TX if (res == RADIOLIB_ERR_NONE) res = lora.setDio2AsRfSwitch(true); @@ -166,12 +166,16 @@ void SX126xInterface::setStandby() checkNotification(); // handle any pending interrupts before we force standby int err = lora.standby(); + + if (err != RADIOLIB_ERR_NONE) + DEBUG_MSG("SX126x standby failed with error %d\n", err); + assert(err == RADIOLIB_ERR_NONE); -#ifdef SX126X_RXEN // we have RXEN/TXEN control - turn off RX and TX power +#if defined(SX126X_RXEN) && (SX126X_RXEN != RADIOLIB_NC) // we have RXEN/TXEN control - turn off RX and TX power digitalWrite(SX126X_RXEN, LOW); #endif -#ifdef SX126X_TXEN +#if defined(SX126X_TXEN) && (SX126X_TXEN != RADIOLIB_NC) digitalWrite(SX126X_TXEN, LOW); #endif @@ -196,10 +200,10 @@ void SX126xInterface::addReceiveMetadata(MeshPacket *mp) template void SX126xInterface::configHardwareForSend() { -#ifdef SX126X_TXEN // we have RXEN/TXEN control - turn on TX power / off RX power +#if defined(SX126X_TXEN) && (SX126X_TXEN != RADIOLIB_NC) // we have RXEN/TXEN control - turn on TX power / off RX power digitalWrite(SX126X_TXEN, HIGH); #endif -#ifdef SX126X_RXEN +#if defined(SX126X_RXEN) && (SX126X_RXEN != RADIOLIB_NC) digitalWrite(SX126X_RXEN, LOW); #endif @@ -218,10 +222,10 @@ void SX126xInterface::startReceive() setStandby(); -#ifdef SX126X_RXEN // we have RXEN/TXEN control - turn on RX power / off TX power +#if defined(SX126X_RXEN) && (SX126X_RXEN != RADIOLIB_NC) // we have RXEN/TXEN control - turn on RX power / off TX power digitalWrite(SX126X_RXEN, HIGH); #endif -#ifdef SX126X_TXEN +#if defined(SX126X_TXEN) && (SX126X_TXEN != RADIOLIB_NC) digitalWrite(SX126X_TXEN, LOW); #endif diff --git a/variants/rak11200/variant.h b/variants/rak11200/variant.h index 0962d4f45..569f8f9de 100644 --- a/variants/rak11200/variant.h +++ b/variants/rak11200/variant.h @@ -59,11 +59,11 @@ static const uint8_t SCK = 33; // https://docs.rakwireless.com/Product-Categories/WisBlock/RAK13300/ -#define LORA_DIO0 -1 // a No connect on the SX1262/SX1268 module -#define LORA_RESET WB_IO4 // RST for SX1276, and for SX1262/SX1268 -#define LORA_DIO1 WB_IO6 // IRQ for SX1262/SX1268 -#define LORA_DIO2 WB_IO5 // BUSY for SX1262/SX1268 -#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262/SX1268, if DIO3 is high the TXCO is enabled +#define LORA_DIO0 RADIOLIB_NC // a No connect on the SX1262/SX1268 module +#define LORA_RESET WB_IO4 // RST for SX1276, and for SX1262/SX1268 +#define LORA_DIO1 WB_IO6 // IRQ for SX1262/SX1268 +#define LORA_DIO2 WB_IO5 // BUSY for SX1262/SX1268 +#define LORA_DIO3 RADIOLIB_NC // Not connected on PCB, but internally on the TTGO SX1262/SX1268, if DIO3 is high the TXCO is enabled #undef RF95_SCK #define RF95_SCK SCK @@ -75,10 +75,9 @@ static const uint8_t SCK = 33; #define RF95_NSS SS #define USE_SX1262 -#define SX126X_CS (SS)// NSS for SX126X -#define SX126X_DIO1 (LORA_DIO1) -#define SX126X_BUSY (LORA_DIO2) -#define SX126X_RESET (LORA_RESET) -#define SX126X_TXEN (-1) -#define SX126X_RXEN (WB_IO3) +#define SX126X_CS SS// NSS for SX126X +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_DIO2 +#define SX126X_RESET LORA_RESET +#define SX126X_POWER_EN WB_IO3 #define SX126X_E22 // DIO2 controlls an antenna switch and the TCXO voltage is controlled by DIO3