fix(radiolib): keep LR1121 tx power valid across sub-GHz and 2.4 GHz

- Clip requested power to the active PA's range instead of failing. A
  stored 22 dBm was rejected at 2.4 GHz (HF PA max 13 dBm), and since
  setTxPower ignores errors the sub-GHz PA stayed configured.
- Re-apply the requested power after every successful retune: PA choice
  depends on the band, and set radio / tempradio only call setParams.
This commit is contained in:
agessaman committed 2026-10-11 21:07:05 -07:00
1 parent 3d1a5d4c64
commit eac6e66b1b
1 file changed
+26 -4
+26 -4
View File
@@ -9,6 +9,8 @@ class CustomLR1121 : public LR1121 {
uint32_t _activityAt = 0;
bool _headerSeen = false;
bool _rx_boosted = false;
int8_t _txPower = 0;
bool _txPowerSet = false;
public:
CustomLR1121(Module *mod) : LR1121(mod) { }
@@ -36,12 +38,32 @@ class CustomLR1121 : public LR1121 {
return len;
}
#ifdef LR1121_FORCE_HP_PA
// boards with only RFO_HP_LF wired: stop RadioLib switching to the LP PA at <= 14 dBm (2.4 GHz still uses the HF PA)
using LR1121::setOutputPower;
using LR1121::setFrequency;
int16_t setOutputPower(int8_t power) override {
return LR1121::setOutputPower(power, true);
}
#ifdef LR1121_FORCE_HP_PA
const bool force_hp = true; // boards with only RFO_HP_LF wired: never select the LP PA
#else
const bool force_hp = false;
#endif
// clip to the active PA's range (HF PA tops out at 13 dBm) rather than fail and keep the other band's PA
int8_t clipped = power;
checkOutputPower(power, &clipped, force_hp);
int16_t state = LR1121::setOutputPower(clipped, force_hp);
if (state == RADIOLIB_ERR_NONE) {
_txPower = power;
_txPowerSet = true;
}
return state;
}
int16_t setFrequency(float freq) override {
int16_t state = LR1121::setFrequency(freq);
// PA selection depends on the band, and set radio / tempradio don't call setTxPower
if (state == RADIOLIB_ERR_NONE && _txPowerSet) state = setOutputPower(_txPower);
return state;
}
float getFreqMHz() const { return freqMHz; }