Skip to content

Commit eb855f2

Browse files
Wessel Nieboerweebl2000
authored andcommitted
Address PR comments & implement for LR11x0 too
1 parent e36bd33 commit eb855f2

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/mesh/LR11x0Interface.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,32 @@ template <typename T> bool LR11x0Interface<T>::isActivelyReceiving()
299299
RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED);
300300
}
301301

302+
template <typename T> void LR11x0Interface<T>::resetAGC()
303+
{
304+
// Safety: don't reset mid-packet
305+
if (sendingPacket != NULL || (isReceiving && isActivelyReceiving()))
306+
return;
307+
308+
LOG_DEBUG("LR11x0 AGC reset: warm sleep + Calibrate(0x3F)");
309+
310+
// 1. Warm sleep — powers down the analog frontend, resetting AGC state
311+
lora.sleep(true, 0);
312+
313+
// 2. Wake to RC standby for stable calibration
314+
lora.standby(RADIOLIB_LR11X0_STANDBY_RC, true);
315+
316+
// 3. Calibrate all blocks (PLL, ADC, image, RC oscillators)
317+
// calibrate() is protected on LR11x0, so use raw SPI (same as internal implementation)
318+
uint8_t calData = RADIOLIB_LR11X0_CALIBRATE_ALL;
319+
module.SPIwriteStream(RADIOLIB_LR11X0_CMD_CALIBRATE, &calData, 1, true, true);
320+
321+
// 4. Re-apply RX boosted gain mode
322+
lora.setRxBoostedGainMode(config.lora.sx126x_rx_boosted_gain);
323+
324+
// 5. Resume receiving
325+
startReceive();
326+
}
327+
302328
template <typename T> bool LR11x0Interface<T>::sleep()
303329
{
304330
// \todo Display actual typename of the adapter, not just `LR11x0`

src/mesh/LR11x0Interface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ template <class T> class LR11x0Interface : public RadioLibInterface
2727

2828
bool isIRQPending() override { return lora.getIrqFlags() != 0; }
2929

30+
void resetAGC() override;
31+
3032
protected:
3133
/**
3234
* Specific module instance

src/mesh/SX126xInterface.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ template <typename T> void SX126xInterface<T>::resetAGC()
440440
if (sendingPacket != NULL || (isReceiving && isActivelyReceiving()))
441441
return;
442442

443-
LOG_INFO("SX126x AGC reset: warm sleep + Calibrate(0x7F)");
443+
LOG_DEBUG("SX126x AGC reset: warm sleep + Calibrate(0x7F)");
444444

445445
// 1. Warm sleep — powers down the entire analog frontend, resetting AGC state.
446446
// A plain standby→startReceive cycle does NOT reset the AGC.
@@ -462,6 +462,12 @@ template <typename T> void SX126xInterface<T>::resetAGC()
462462
module.hal->yield();
463463
}
464464

465+
if (module.hal->digitalRead(module.getGpio())) {
466+
LOG_WARN("SX126x AGC reset: calibration did not complete within 50ms");
467+
startReceive();
468+
return;
469+
}
470+
465471
// 5. Re-apply settings that calibration may have reset
466472

467473
// DIO2 as RF switch

0 commit comments

Comments
 (0)