2021-09-12 00:35:16 +03:00
# include "SX126xInterface.h"
2023-01-21 14:34:29 +01:00
# include "configuration.h"
2021-09-12 00:35:16 +03:00
# include "error.h"
2023-01-25 14:59:12 -06:00
# include "mesh/NodeDB.h"
2024-01-12 02:00:31 -06:00
# ifdef ARCH_PORTDUINO
2023-11-18 08:12:34 -06:00
# include "PortduinoGlue.h"
# endif
2021-09-12 00:35:16 +03:00
2023-09-27 22:01:40 +01:00
// Particular boards might define a different max power based on what their hardware can do, default to max power output if not
// specified (may be dangerous if using external PA and SX126x power config forgotten)
2021-09-12 00:35:16 +03:00
# ifndef SX126X_MAX_POWER
# define SX126X_MAX_POWER 22
# endif
2023-01-21 14:34:29 +01:00
template < typename T >
2023-05-08 13:18:28 +02:00
SX126xInterface < T > : : SX126xInterface ( LockingArduinoHal * hal , RADIOLIB_PIN_TYPE cs , RADIOLIB_PIN_TYPE irq , RADIOLIB_PIN_TYPE rst ,
RADIOLIB_PIN_TYPE busy )
: RadioLibInterface ( hal , cs , irq , rst , busy , & lora ) , lora ( & module )
2021-09-12 00:35:16 +03:00
{
2024-03-21 20:45:48 -05:00
LOG_DEBUG ( " SX126xInterface(cs=%d, irq=%d, rst=%d, busy=%d) \n " , cs , irq , rst , busy ) ;
2021-09-12 00:35:16 +03:00
}
/// Initialise the Driver transport hardware and software.
/// Make sure the Driver is properly configured before calling init().
/// \return true if initialisation succeeded.
2023-01-25 14:59:12 -06:00
template < typename T > bool SX126xInterface < T > : : init ( )
2021-09-12 00:35:16 +03:00
{
2024-09-12 19:36:10 +01:00
// Typically, the RF switch on SX126x boards is controlled by two signals, which are negations of each other (switched RFIO paths). The negation is usually performed in hardware, or (suboptimal design) TXEN and RXEN are the two inputs to this style of RF switch. On some boards, there is no hardware negation between CTRL and ¬CTRL, but CTRL is internally connected to DIO2, and DIO2's switching is done by the SX126X itself, so the MCU can't control ¬CTRL at exactly the same time. One solution would be to set ¬CTRL as SX126X_TXEN or SX126X_RXEN, but they may already be used for another purpose, such as controlling another PA/LNA. Keeping ¬CTRL high seems to work, as long CTRL=1, ¬CTRL=1 has the opposite and stable RF path effect as CTRL=0 and ¬CTRL=1, this depends on the RF switch, but it seems this usually works. Better hardware design, which is done most the time, means this workaround is not necessary.
# ifdef SX126X_ANT_SW // Perhaps add RADIOLIB_NC check, and beforehand define as such if it is undefined, but it is not commonly used and not part of the 'default' set of pin definitions.
digitalWrite ( SX126X_ANT_SW , HIGH ) ;
pinMode ( SX126X_ANT_SW , OUTPUT ) ;
# endif
# ifdef SX126X_POWER_EN // Perhaps add RADIOLIB_NC check, and beforehand define as such if it is undefined, but it is not commonly used and not part of the 'default' set of pin definitions.
2023-12-02 13:40:31 +00:00
digitalWrite ( SX126X_POWER_EN , HIGH ) ;
2024-09-12 19:36:10 +01:00
pinMode ( SX126X_POWER_EN , OUTPUT ) ;
2021-09-12 00:35:16 +03:00
# endif
2024-01-12 02:00:31 -06:00
# if ARCH_PORTDUINO
float tcxoVoltage = 0 ;
if ( settingsMap [ dio3_tcxo_voltage ] )
tcxoVoltage = 1.8 ;
2023-09-27 22:01:40 +01:00
// FIXME: correct logic to default to not using TCXO if no voltage is specified for SX126X_DIO3_TCXO_VOLTAGE
2024-01-12 02:00:31 -06:00
# elif !defined(SX126X_DIO3_TCXO_VOLTAGE)
2023-09-27 22:01:40 +01:00
float tcxoVoltage =
0 ; // "TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip." per
// https://github.com/jgromes/RadioLib/blob/690a050ebb46e6097c5d00c371e961c1caa3b52e/src/modules/SX126x/SX126x.h#L471C26-L471C104
// (DIO3 is free to be used as an IRQ)
2024-08-20 12:54:18 +01:00
# elif !defined(TCXO_OPTIONAL)
2023-09-27 22:01:40 +01:00
float tcxoVoltage = SX126X_DIO3_TCXO_VOLTAGE ;
// (DIO3 is not free to be used as an IRQ)
2021-09-12 00:35:16 +03:00
# endif
2024-01-12 02:00:31 -06:00
if ( tcxoVoltage = = 0 )
LOG_DEBUG ( " SX126X_DIO3_TCXO_VOLTAGE not defined, not using DIO3 as TCXO reference voltage \n " ) ;
else
LOG_DEBUG ( " SX126X_DIO3_TCXO_VOLTAGE defined, using DIO3 as TCXO reference voltage at %f V \n " , tcxoVoltage ) ;
2023-09-27 22:01:40 +01:00
// FIXME: May want to set depending on a definition, currently all SX126x variant files use the DC-DC regulator option
2021-09-12 00:35:16 +03:00
bool useRegulatorLDO = false ; // Seems to depend on the connection to pin 9/DCC_SW - if an inductor DCDC?
RadioLibInterface : : init ( ) ;
2023-11-13 12:19:02 +00:00
2023-09-27 22:01:40 +01:00
if ( power > SX126X_MAX_POWER ) // Clamp power to maximum defined level
2021-09-12 00:35:16 +03:00
power = SX126X_MAX_POWER ;
limitPower ( ) ;
2021-09-13 22:13:51 +03:00
int res = lora . begin ( getFreq ( ) , bw , sf , cr , syncWord , power , preambleLength , tcxoVoltage , useRegulatorLDO ) ;
2021-09-12 00:35:16 +03:00
// \todo Display actual typename of the adapter, not just `SX126x`
2022-12-30 10:27:07 -06:00
LOG_INFO ( " SX126x init result %d \n " , res ) ;
2023-03-18 13:23:37 +01:00
if ( res = = RADIOLIB_ERR_CHIP_NOT_FOUND )
return false ;
2021-09-12 00:35:16 +03:00
2022-12-30 10:27:07 -06:00
LOG_INFO ( " Frequency set to %f \n " , getFreq ( ) ) ;
LOG_INFO ( " Bandwidth set to %f \n " , bw ) ;
LOG_INFO ( " Power output set to %d \n " , power ) ;
2022-06-21 21:51:45 -07:00
2023-09-27 22:01:40 +01:00
// Overriding current limit
// (https://github.com/jgromes/RadioLib/blob/690a050ebb46e6097c5d00c371e961c1caa3b52e/src/modules/SX126x/SX126x.cpp#L85) using
// value in SX126xInterface.h (currently 140 mA) It may or may not be neccessary, depending on how RadioLib functions, from
// SX1261/2 datasheet: OCP after setting DeviceSel with SetPaConfig(): SX1261 - 60 mA, SX1262 - 140 mA For the SX1268 the IC
// defaults to 140mA no matter the set power level, but RadioLib set it lower, this would need further checking Default values
// are: SX1262, SX1268: 0x38 (140 mA), SX1261: 0x18 (60 mA)
// FIXME: Not ideal to increase SX1261 current limit above 60mA as it can only transmit max 15dBm, should probably only do it
// if using SX1262 or SX1268
2021-09-12 00:35:16 +03:00
res = lora . setCurrentLimit ( currentLimit ) ;
2022-12-29 20:41:37 -06:00
LOG_DEBUG ( " Current limit set to %f \n " , currentLimit ) ;
LOG_DEBUG ( " Current limit set result %d \n " , res ) ;
2021-09-12 00:35:16 +03:00
2023-09-27 22:01:40 +01:00
# ifdef SX126X_DIO2_AS_RF_SWITCH
LOG_DEBUG ( " Setting DIO2 as RF switch \n " ) ;
bool dio2AsRfSwitch = true ;
2024-01-12 02:00:31 -06:00
# elif defined(ARCH_PORTDUINO)
2023-11-18 08:12:34 -06:00
bool dio2AsRfSwitch = false ;
2023-11-19 14:00:03 -06:00
if ( settingsMap [ dio2_as_rf_switch ] ) {
2023-11-18 08:12:34 -06:00
LOG_DEBUG ( " Setting DIO2 as RF switch \n " ) ;
dio2AsRfSwitch = true ;
}
2023-09-27 22:01:40 +01:00
# else
LOG_DEBUG ( " Setting DIO2 as not RF switch \n " ) ;
bool dio2AsRfSwitch = false ;
2023-05-11 20:09:34 -05:00
# endif
2023-01-25 14:59:12 -06:00
if ( res = = RADIOLIB_ERR_NONE ) {
2023-09-27 22:01:40 +01:00
res = lora . setDio2AsRfSwitch ( dio2AsRfSwitch ) ;
2023-01-25 14:58:50 -06:00
}
2023-09-27 22:01:40 +01:00
// If a pin isn't defined, we set it to RADIOLIB_NC, it is safe to always do external RF switching with RADIOLIB_NC as it has
// no effect
2024-01-12 02:00:31 -06:00
# if ARCH_PORTDUINO
if ( res = = RADIOLIB_ERR_NONE ) {
LOG_DEBUG ( " Using MCU pin %i as RXEN and pin %i as TXEN to control RF switching \n " , settingsMap [ rxen ] , settingsMap [ txen ] ) ;
lora . setRfSwitchPins ( settingsMap [ rxen ] , settingsMap [ txen ] ) ;
}
# else
2023-09-27 22:01:40 +01:00
# ifndef SX126X_RXEN
# define SX126X_RXEN RADIOLIB_NC
LOG_DEBUG ( " SX126X_RXEN not defined, defaulting to RADIOLIB_NC \n " ) ;
# endif
# ifndef SX126X_TXEN
# define SX126X_TXEN RADIOLIB_NC
LOG_DEBUG ( " SX126X_TXEN not defined, defaulting to RADIOLIB_NC \n " ) ;
# endif
2023-07-21 21:37:00 -04:00
if ( res = = RADIOLIB_ERR_NONE ) {
2023-09-27 22:01:40 +01:00
LOG_DEBUG ( " Using MCU pin %i as RXEN and pin %i as TXEN to control RF switching \n " , SX126X_RXEN , SX126X_TXEN ) ;
2023-07-21 21:37:00 -04:00
lora . setRfSwitchPins ( SX126X_RXEN , SX126X_TXEN ) ;
}
2024-01-12 02:00:31 -06:00
# endif
2023-01-25 14:59:12 -06:00
if ( config . lora . sx126x_rx_boosted_gain ) {
2023-01-25 14:58:50 -06:00
uint16_t result = lora . setRxBoostedGainMode ( true ) ;
2023-09-27 22:01:40 +01:00
LOG_INFO ( " Set RX gain to boosted mode; result: %d \n " , result ) ;
2023-01-25 14:59:12 -06:00
} else {
2023-01-25 14:58:50 -06:00
uint16_t result = lora . setRxBoostedGainMode ( false ) ;
2023-09-27 22:01:40 +01:00
LOG_INFO ( " Set RX gain to power saving mode (boosted mode off); result: %d \n " , result ) ;
2023-01-25 14:58:50 -06:00
}
2023-01-16 23:35:56 -05:00
2021-09-12 00:35:16 +03:00
#if 0
// Read/write a register we are not using (only used for FSK mode) to test SPI comms
uint8_t crcLSB = 0 ;
int err = lora . readRegister ( SX126X_REG_CRC_POLYNOMIAL_LSB , & crcLSB , 1 ) ;
2022-05-29 19:30:20 -05:00
if ( err ! = RADIOLIB_ERR_NONE )
2021-09-12 00:35:16 +03:00
RECORD_CRITICALERROR ( CriticalErrorCode_SX1262Failure ) ;
//if(crcLSB != 0x0f)
// RECORD_CRITICALERROR(CriticalErrorCode_SX1262Failure);
2022-11-25 15:17:24 +02:00
2021-09-12 00:35:16 +03:00
crcLSB = 0x5a ;
err = lora . writeRegister ( SX126X_REG_CRC_POLYNOMIAL_LSB , & crcLSB , 1 ) ;
2022-05-29 19:30:20 -05:00
if ( err ! = RADIOLIB_ERR_NONE )
2022-11-25 15:17:24 +02:00
RECORD_CRITICALERROR ( CriticalErrorCode_SX1262Failure ) ;
2021-09-12 00:35:16 +03:00
err = lora . readRegister ( SX126X_REG_CRC_POLYNOMIAL_LSB , & crcLSB , 1 ) ;
2022-05-29 19:30:20 -05:00
if ( err ! = RADIOLIB_ERR_NONE )
2021-09-12 00:35:16 +03:00
RECORD_CRITICALERROR ( CriticalErrorCode_SX1262Failure ) ;
if ( crcLSB ! = 0x5a )
RECORD_CRITICALERROR ( CriticalErrorCode_SX1262Failure ) ;
// If we got this far register accesses (and therefore SPI comms) are good
# endif
2022-05-29 19:30:20 -05:00
if ( res = = RADIOLIB_ERR_NONE )
res = lora . setCRC ( RADIOLIB_SX126X_LORA_CRC_ON ) ;
2021-09-12 00:35:16 +03:00
2022-05-29 19:30:20 -05:00
if ( res = = RADIOLIB_ERR_NONE )
2021-09-12 00:35:16 +03:00
startReceive ( ) ; // start receiving
2022-05-29 19:30:20 -05:00
return res = = RADIOLIB_ERR_NONE ;
2021-09-12 00:35:16 +03:00
}
2023-01-25 14:59:12 -06:00
template < typename T > bool SX126xInterface < T > : : reconfigure ( )
2021-09-12 00:35:16 +03:00
{
RadioLibInterface : : reconfigure ( ) ;
// set mode to standby
setStandby ( ) ;
// configure publicly accessible settings
int err = lora . setSpreadingFactor ( sf ) ;
2022-05-29 19:30:20 -05:00
if ( err ! = RADIOLIB_ERR_NONE )
2023-01-21 18:22:19 +01:00
RECORD_CRITICALERROR ( meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING ) ;
2021-09-12 00:35:16 +03:00
err = lora . setBandwidth ( bw ) ;
2022-05-29 19:30:20 -05:00
if ( err ! = RADIOLIB_ERR_NONE )
2023-01-21 18:22:19 +01:00
RECORD_CRITICALERROR ( meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING ) ;
2021-09-12 00:35:16 +03:00
err = lora . setCodingRate ( cr ) ;
2022-05-29 19:30:20 -05:00
if ( err ! = RADIOLIB_ERR_NONE )
2023-01-21 18:22:19 +01:00
RECORD_CRITICALERROR ( meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING ) ;
2021-09-12 00:35:16 +03:00
err = lora . setSyncWord ( syncWord ) ;
2024-04-14 00:29:42 -05:00
if ( err ! = RADIOLIB_ERR_NONE )
LOG_ERROR ( " Radiolib error %d when attempting SX126X setSyncWord! \n " , err ) ;
2022-05-29 19:30:20 -05:00
assert ( err = = RADIOLIB_ERR_NONE ) ;
2021-09-12 00:35:16 +03:00
err = lora . setCurrentLimit ( currentLimit ) ;
2024-04-14 00:29:42 -05:00
if ( err ! = RADIOLIB_ERR_NONE )
LOG_ERROR ( " Radiolib error %d when attempting SX126X setCurrentLimit! \n " , err ) ;
2022-05-29 19:30:20 -05:00
assert ( err = = RADIOLIB_ERR_NONE ) ;
2021-09-12 00:35:16 +03:00
err = lora . setPreambleLength ( preambleLength ) ;
2024-04-14 00:29:42 -05:00
if ( err ! = RADIOLIB_ERR_NONE )
LOG_ERROR ( " Radiolib error %d when attempting SX126X setPreambleLength! \n " , err ) ;
2022-05-29 19:30:20 -05:00
assert ( err = = RADIOLIB_ERR_NONE ) ;
2021-09-12 00:35:16 +03:00
2021-09-13 22:13:51 +03:00
err = lora . setFrequency ( getFreq ( ) ) ;
2022-05-29 19:30:20 -05:00
if ( err ! = RADIOLIB_ERR_NONE )
2023-01-21 18:22:19 +01:00
RECORD_CRITICALERROR ( meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING ) ;
2021-09-12 00:35:16 +03:00
2022-11-14 09:49:50 +01:00
if ( power > SX126X_MAX_POWER ) // This chip has lower power limits than some
power = SX126X_MAX_POWER ;
2022-11-25 15:17:24 +02:00
2021-09-12 00:35:16 +03:00
err = lora . setOutputPower ( power ) ;
2024-04-14 00:29:42 -05:00
if ( err ! = RADIOLIB_ERR_NONE )
LOG_ERROR ( " Radiolib error %d when attempting SX126X setOutputPower! \n " , err ) ;
2022-05-29 19:30:20 -05:00
assert ( err = = RADIOLIB_ERR_NONE ) ;
2021-09-12 00:35:16 +03:00
startReceive ( ) ; // restart receiving
2022-05-29 19:30:20 -05:00
return RADIOLIB_ERR_NONE ;
2021-09-12 00:35:16 +03:00
}
2023-01-25 14:59:12 -06:00
template < typename T > void INTERRUPT_ATTR SX126xInterface < T > : : disableInterrupt ( )
2021-09-12 00:35:16 +03:00
{
lora . clearDio1Action ( ) ;
}
2023-01-25 14:59:12 -06:00
template < typename T > void SX126xInterface < T > : : setStandby ( )
2021-09-12 00:35:16 +03:00
{
checkNotification ( ) ; // handle any pending interrupts before we force standby
2022-11-25 15:17:24 +02:00
2021-09-12 00:35:16 +03:00
int err = lora . standby ( ) ;
2022-11-15 21:55:27 +01:00
2024-04-14 00:29:42 -05:00
if ( err ! = RADIOLIB_ERR_NONE )
2022-12-29 20:41:37 -06:00
LOG_DEBUG ( " SX126x standby failed with error %d \n " , err ) ;
2022-05-29 19:30:20 -05:00
assert ( err = = RADIOLIB_ERR_NONE ) ;
2021-09-12 00:35:16 +03:00
isReceiving = false ; // If we were receiving, not any more
2023-03-11 19:59:29 +01:00
activeReceiveStart = 0 ;
2021-09-12 00:35:16 +03:00
disableInterrupt ( ) ;
completeSending ( ) ; // If we were sending, not anymore
2024-07-03 16:02:20 -07:00
RadioLibInterface : : setStandby ( ) ;
2021-09-12 00:35:16 +03:00
}
/**
* Add SNR data to received messages
*/
2023-01-25 14:59:12 -06:00
template < typename T > void SX126xInterface < T > : : addReceiveMetadata ( meshtastic_MeshPacket * mp )
2021-09-12 00:35:16 +03:00
{
2022-12-29 20:41:37 -06:00
// LOG_DEBUG("PacketStatus %x\n", lora.getPacketStatus());
2021-09-12 00:35:16 +03:00
mp - > rx_snr = lora . getSNR ( ) ;
mp - > rx_rssi = lround ( lora . getRSSI ( ) ) ;
}
/** We override to turn on transmitter power as needed.
*/
2023-01-25 14:59:12 -06:00
template < typename T > void SX126xInterface < T > : : configHardwareForSend ( )
2021-09-12 00:35:16 +03:00
{
RadioLibInterface : : configHardwareForSend ( ) ;
}
// For power draw measurements, helpful to force radio to stay sleeping
// #define SLEEP_ONLY
2023-01-25 14:59:12 -06:00
template < typename T > void SX126xInterface < T > : : startReceive ( )
2021-09-12 00:35:16 +03:00
{
# ifdef SLEEP_ONLY
sleep ( ) ;
# else
setStandby ( ) ;
2023-03-06 22:53:59 +01:00
// We use a 16 bit preamble so this should save some power by letting radio sit in standby mostly.
2023-03-11 19:59:29 +01:00
// Furthermore, we need the PREAMBLE_DETECTED and HEADER_VALID IRQ flag to detect whether we are actively receiving
2024-09-03 21:21:40 +02:00
int err = lora . startReceiveDutyCycleAuto ( preambleLength , 8 , RADIOLIB_IRQ_RX_DEFAULT_FLAGS | RADIOLIB_IRQ_PREAMBLE_DETECTED ) ;
2024-04-14 00:29:42 -05:00
if ( err ! = RADIOLIB_ERR_NONE )
LOG_ERROR ( " Radiolib error %d when attempting SX126X startReceiveDutyCycleAuto! \n " , err ) ;
2022-05-29 19:30:20 -05:00
assert ( err = = RADIOLIB_ERR_NONE ) ;
2021-09-12 00:35:16 +03:00
2024-07-03 16:02:20 -07:00
RadioLibInterface : : startReceive ( ) ;
2021-09-12 00:35:16 +03:00
// Must be done AFTER, starting transmit, because startTransmit clears (possibly stale) interrupt pending register bits
enableInterrupt ( isrRxLevel0 ) ;
# endif
}
2023-03-06 22:53:59 +01:00
/** Is the channel currently active? */
2023-01-25 14:59:12 -06:00
template < typename T > bool SX126xInterface < T > : : isChannelActive ( )
2022-04-20 20:04:44 +02:00
{
// check if we can detect a LoRa preamble on the current channel
int16_t result ;
2022-11-25 15:17:24 +02:00
setStandby ( ) ;
2022-04-20 20:04:44 +02:00
result = lora . scanChannel ( ) ;
2023-02-20 21:11:54 +01:00
if ( result = = RADIOLIB_LORA_DETECTED )
2022-04-20 20:04:44 +02:00
return true ;
2024-04-14 14:36:11 -05:00
if ( result ! = RADIOLIB_CHANNEL_FREE )
2024-04-14 00:29:42 -05:00
LOG_ERROR ( " Radiolib error %d when attempting SX126X scanChannel! \n " , result ) ;
2022-05-29 19:30:20 -05:00
assert ( result ! = RADIOLIB_ERR_WRONG_MODEM ) ;
2022-11-25 15:17:24 +02:00
2022-04-20 20:04:44 +02:00
return false ;
}
2023-07-14 17:25:20 -04:00
/** Could we send right now (i.e. either not actively receiving or transmitting)? */
2023-01-25 14:59:12 -06:00
template < typename T > bool SX126xInterface < T > : : isActivelyReceiving ( )
2021-09-12 00:35:16 +03:00
{
2023-09-27 22:01:40 +01:00
// The IRQ status will be cleared when we start our read operation. Check if we've started a header, but haven't yet
2021-09-12 00:35:16 +03:00
// received and handled the interrupt for reading the packet/handling errors.
2024-09-03 13:12:39 +02:00
uint16_t irq = lora . getIrqFlags ( ) ;
2023-11-30 10:59:01 +01:00
bool detected = ( irq & ( RADIOLIB_SX126X_IRQ_HEADER_VALID | RADIOLIB_SX126X_IRQ_PREAMBLE_DETECTED ) ) ;
2023-03-11 19:59:29 +01:00
// Handle false detections
if ( detected ) {
uint32_t now = millis ( ) ;
if ( ! activeReceiveStart ) {
activeReceiveStart = now ;
} else if ( ( now - activeReceiveStart > 2 * preambleTimeMsec ) & & ! ( irq & RADIOLIB_SX126X_IRQ_HEADER_VALID ) ) {
// The HEADER_VALID flag should be set by now if it was really a packet, so ignore PREAMBLE_DETECTED flag
activeReceiveStart = 0 ;
LOG_DEBUG ( " Ignore false preamble detection. \n " ) ;
return false ;
} else if ( now - activeReceiveStart > maxPacketTimeMsec ) {
// We should have gotten an RX_DONE IRQ by now if it was really a packet, so ignore HEADER_VALID flag
activeReceiveStart = 0 ;
LOG_DEBUG ( " Ignore false header detection. \n " ) ;
return false ;
}
}
2021-09-12 00:35:16 +03:00
2023-03-11 19:59:29 +01:00
// if (detected) LOG_DEBUG("rx detected\n");
return detected ;
2021-09-12 00:35:16 +03:00
}
2023-01-25 14:59:12 -06:00
template < typename T > bool SX126xInterface < T > : : sleep ( )
2021-09-12 00:35:16 +03:00
{
// Not keeping config is busted - next time nrf52 board boots lora sending fails tcxo related? - see datasheet
// \todo Display actual typename of the adapter, not just `SX126x`
2023-09-27 22:01:40 +01:00
LOG_DEBUG ( " SX126x entering sleep mode (FIXME, don't keep config) \n " ) ;
2021-09-12 00:35:16 +03:00
setStandby ( ) ; // Stop any pending operations
// turn off TCXO if it was powered
// FIXME - this isn't correct
// lora.setTCXO(0);
// put chipset into sleep mode (we've already disabled interrupts by now)
bool keepConfig = true ;
lora . sleep ( keepConfig ) ; // Note: we do not keep the config, full reinit will be needed
# ifdef SX126X_POWER_EN
digitalWrite ( SX126X_POWER_EN , LOW ) ;
# endif
return true ;
2024-08-20 12:54:18 +01:00
}