@@ -434,6 +434,51 @@ template <typename T> bool SX126xInterface<T>::sleep()
434434 return true ;
435435}
436436
437+ template <typename T> void SX126xInterface<T>::resetAGC()
438+ {
439+ // Safety: don't reset mid-packet
440+ if (sendingPacket != NULL || (isReceiving && isActivelyReceiving ()))
441+ return ;
442+
443+ LOG_INFO (" SX126x AGC reset: warm sleep + Calibrate(0x7F)" );
444+
445+ // 1. Warm sleep — powers down the entire analog frontend, resetting AGC state.
446+ // A plain standby→startReceive cycle does NOT reset the AGC.
447+ lora.sleep (true );
448+
449+ // 2. Wake to RC standby for stable calibration
450+ lora.standby (RADIOLIB_SX126X_STANDBY_RC , true );
451+
452+ // 3. Calibrate all blocks (ADC, PLL, image, RC oscillators)
453+ uint8_t calData = RADIOLIB_SX126X_CALIBRATE_ALL ;
454+ module .SPIwriteStream (RADIOLIB_SX126X_CMD_CALIBRATE , &calData, 1 , true , false );
455+
456+ // 4. Wait for calibration to complete (BUSY pin goes low)
457+ module .hal ->delay (5 );
458+ uint32_t start = millis ();
459+ while (module .hal ->digitalRead (module .getGpio ())) {
460+ if (millis () - start > 50 )
461+ break ;
462+ module .hal ->yield ();
463+ }
464+
465+ // 5. Re-apply settings that calibration may have reset
466+
467+ // DIO2 as RF switch
468+ #ifdef SX126X_DIO2_AS_RF_SWITCH
469+ lora.setDio2AsRfSwitch (true );
470+ #elif defined(ARCH_PORTDUINO)
471+ if (portduino_config.dio2_as_rf_switch )
472+ lora.setDio2AsRfSwitch (true );
473+ #endif
474+
475+ // RX boosted gain mode
476+ lora.setRxBoostedGainMode (config.lora .sx126x_rx_boosted_gain );
477+
478+ // 6. Resume receiving
479+ startReceive ();
480+ }
481+
437482/* * Control PA mode for GC1109 FEM - CPS pin selects full PA (txon=true) or bypass mode (txon=false) */
438483template <typename T> void SX126xInterface<T>::setTransmitEnable(bool txon)
439484{
0 commit comments