diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index 68bd6326a..8cd735da5 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -1,7 +1,7 @@ #include "SX126xInterface.h" -#include "mesh/NodeDB.h" #include "configuration.h" #include "error.h" +#include "mesh/NodeDB.h" // Particular boards might define a different max power based on what their hardware can do #ifndef SX126X_MAX_POWER @@ -26,15 +26,6 @@ template bool SX126xInterface::init() pinMode(SX126X_POWER_EN, OUTPUT); #endif -#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 -#if defined(SX126X_TXEN) && (SX126X_TXEN != RADIOLIB_NC) - digitalWrite(SX126X_TXEN, LOW); - pinMode(SX126X_TXEN, OUTPUT); -#endif - #ifndef SX126X_E22 float tcxoVoltage = 0; // None - we use an XTAL #else @@ -67,11 +58,6 @@ template bool SX126xInterface::init() LOG_DEBUG("Current limit set to %f\n", currentLimit); LOG_DEBUG("Current limit set result %d\n", res); -#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(false); -#endif #ifdef SX126X_E22 // E22 Emulation explicitly requires DIO2 as RF switch, so set it to TRUE again for good measure. In case somebody defines // SX126X_TX for an E22 Module @@ -79,13 +65,21 @@ template bool SX126xInterface::init() res = lora.setDio2AsRfSwitch(true); #endif -if (config.lora.sx126x_rx_boosted_gain) { - uint16_t result = lora.setRxBoostedGainMode(true); - LOG_INFO("Set Rx Boosted Gain mode; result: %d\n", result); -} else { - uint16_t result = lora.setRxBoostedGainMode(false); - LOG_INFO("Set Rx Power Saving Gain mode; result: %d\n", result); -} +#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(false); + lora.setRfSwitchPins(SX126X_RXEN, SX126X_TXEN); + } +#endif + + if (config.lora.sx126x_rx_boosted_gain) { + uint16_t result = lora.setRxBoostedGainMode(true); + LOG_INFO("Set Rx Boosted Gain mode; result: %d\n", result); + } else { + uint16_t result = lora.setRxBoostedGainMode(false); + LOG_INFO("Set Rx Power Saving Gain mode; result: %d\n", result); + } #if 0 // Read/write a register we are not using (only used for FSK mode) to test SPI comms @@ -185,13 +179,6 @@ template void SX126xInterface::setStandby() assert(err == RADIOLIB_ERR_NONE); -#if defined(SX126X_RXEN) && (SX126X_RXEN != RADIOLIB_NC) // we have RXEN/TXEN control - turn off RX and TX power - digitalWrite(SX126X_RXEN, LOW); -#endif -#if defined(SX126X_TXEN) && (SX126X_TXEN != RADIOLIB_NC) - digitalWrite(SX126X_TXEN, LOW); -#endif - isReceiving = false; // If we were receiving, not any more disableInterrupt(); completeSending(); // If we were sending, not anymore @@ -211,13 +198,6 @@ template void SX126xInterface::addReceiveMetadata(meshtastic_Mes */ template void SX126xInterface::configHardwareForSend() { -#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 -#if defined(SX126X_RXEN) && (SX126X_RXEN != RADIOLIB_NC) - digitalWrite(SX126X_RXEN, LOW); -#endif - RadioLibInterface::configHardwareForSend(); } @@ -232,13 +212,6 @@ template void SX126xInterface::startReceive() setStandby(); -#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 -#if defined(SX126X_TXEN) && (SX126X_TXEN != RADIOLIB_NC) - digitalWrite(SX126X_TXEN, LOW); -#endif - // 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/variants/diy/v1/variant.h b/variants/diy/v1/variant.h index 349ed8ff3..712a88091 100644 --- a/variants/diy/v1/variant.h +++ b/variants/diy/v1/variant.h @@ -44,6 +44,9 @@ #define RF95_RXEN 14 #define RF95_TXEN 13 +// Set lora.tx_power to 13 for Hydra or other E22 900M30S target due to PA +#define SX126X_MAX_POWER 22 + #ifdef EBYTE_E22 // Internally the TTGO module hooks the SX126x-DIO2 in to control the TX/RX switch // (which is the default for the sx1262interface code) diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index fe5540974..68b2b1172 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -206,6 +206,7 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG #define SX126X_RESET (38) // #define SX126X_TXEN (39) // #define SX126X_RXEN (37) +#define SX126X_POWER_EN (37) #define SX126X_E22 // DIO2 controlls an antenna switch and the TCXO voltage is controlled by DIO3 // enables 3.3V periphery like GPS or IO Module diff --git a/variants/rak4631_epaper/variant.h b/variants/rak4631_epaper/variant.h index 9961abfa1..3d597d3d1 100644 --- a/variants/rak4631_epaper/variant.h +++ b/variants/rak4631_epaper/variant.h @@ -136,7 +136,7 @@ static const uint8_t SCK = PIN_SPI_SCK; // Controls power for the eink display - Board power is enabled either by VBUS from USB or the CPU asserting PWR_ON // FIXME - I think this is actually just the board power enable - it enables power to the CPU also -//#define PIN_EINK_PWR_ON (-1) +// #define PIN_EINK_PWR_ON (-1) #define USE_EINK @@ -181,8 +181,9 @@ static const uint8_t SCK = PIN_SPI_SCK; #define SX126X_DIO1 (47) #define SX126X_BUSY (46) #define SX126X_RESET (38) -#define SX126X_TXEN (39) -#define SX126X_RXEN (37) +// #define SX126X_TXEN (39) +// #define SX126X_RXEN (37) +#define SX126X_POWER_EN (37) #define SX126X_E22 // DIO2 controlls an antenna switch and the TCXO voltage is controlled by DIO3 // enables 3.3V periphery like GPS or IO Module