sx126x-rx-gain-persist: add ability to persist Rx gain setting when calling SX126x::setRxBoostedGainMode

This commit is contained in:
Andrew Moroz 2023-01-28 17:46:01 -05:00
parent 18ff62890a
commit 5f3fb5fa0d
2 changed files with 21 additions and 2 deletions

View file

@ -870,7 +870,7 @@ int16_t SX126x::setRxBandwidth(float rxBw) {
return(setModulationParamsFSK(_br, _pulseShape, _rxBw, _freqDev)); 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 // read the current register value
uint8_t rxGain = 0; uint8_t rxGain = 0;
int16_t state = readRegister(RADIOLIB_SX126X_REG_RX_GAIN, &rxGain, 1); 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); state = writeRegister(RADIOLIB_SX126X_REG_RX_GAIN, &rxGain, 1);
RADIOLIB_ASSERT(state); 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); return(state);
} }

View file

@ -713,9 +713,11 @@ class SX126x: public PhysicalLayer {
\param rxbgm True for Rx Boosted Gain, false for Rx Power Saving Gain \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 \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. \brief Sets time-bandwidth product of Gaussian filter applied for shaping.