From 5f3fb5fa0db26d0f4a5fad18d6c7c454a44966e0 Mon Sep 17 00:00:00 2001 From: Andrew Moroz Date: Sat, 28 Jan 2023 17:46:01 -0500 Subject: [PATCH] sx126x-rx-gain-persist: add ability to persist Rx gain setting when calling SX126x::setRxBoostedGainMode --- src/modules/SX126x/SX126x.cpp | 19 ++++++++++++++++++- src/modules/SX126x/SX126x.h | 4 +++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 1e23dda2..d6fe884d 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -870,7 +870,7 @@ int16_t SX126x::setRxBandwidth(float rxBw) { return(setModulationParamsFSK(_br, _pulseShape, _rxBw, _freqDev)); } -int16_t SX126x::setRxBoostedGainMode(bool rxbgm) { +int16_t SX126x::setRxBoostedGainMode(bool rxbgm, bool persist) { // read the current register value uint8_t rxGain = 0; int16_t state = readRegister(RADIOLIB_SX126X_REG_RX_GAIN, &rxGain, 1); @@ -887,6 +887,23 @@ int16_t SX126x::setRxBoostedGainMode(bool rxbgm) { state = writeRegister(RADIOLIB_SX126X_REG_RX_GAIN, &rxGain, 1); RADIOLIB_ASSERT(state); + // add Rx Gain register to retention memory if requested + if(persist) { + // values and registers below are specified in SX126x datasheet v2.1 section 9.6, just below table 9-3 + uint8_t value0 = 0x01; + uint8_t value1 = 0x08; + uint8_t value2 = 0xAC; + + state = writeRegister(RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_0, &value0, 1); + RADIOLIB_ASSERT(state); + + state = writeRegister(RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_1, &value1, 1); + RADIOLIB_ASSERT(state); + + state = writeRegister(RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_2, &value2, 1); + RADIOLIB_ASSERT(state); + } + return(state); } diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index 12a737f9..57dcb7cb 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -713,9 +713,11 @@ class SX126x: public PhysicalLayer { \param rxbgm True for Rx Boosted Gain, false for Rx Power Saving Gain + \param persist True to persist Rx gain setting when waking up from warm-start mode (e.g. when using Rx duty cycle mode) + \returns \ref status_codes */ - int16_t setRxBoostedGainMode(bool rxbgm); + int16_t setRxBoostedGainMode(bool rxbgm, bool persist = true); /*! \brief Sets time-bandwidth product of Gaussian filter applied for shaping.