kiss_modem: add radio chip boosted RX gain control

Add SetRxBoostedGain (0x20) / GetRxBoostedGain (0x21, reply 0xA1) and
capability bit 3, the KISS equivalent of the radio.rxgain CLI setting.
It is separate from FEM RX gain; a board may support either or both.

- Support is declared by the driver via a new
  RadioLibWrapper::supportsRxBoostedGain() (SX1262, SX1268, LLCC68,
  LR1110, LR1121, LR2021), so nothing is written to the radio at boot.
- The set is refused with TxBusy during TX or while host output is
  backed up. Otherwise any completed RX packet is delivered first,
  because some drivers (LR2021) drop to standby to apply the gain.
- The reply always carries the state read back from the radio.

Driver fixes found along the way, which also affect the radio.rxgain
CLI in regular firmware:
- CustomLR2021 never updated its cached gain state, so the getter
  always reported off. It now tracks the applied level per RX path
  and rolls RadioLib's cached level back if a write fails.
- CustomLR1110/LR1121 cached the requested state even when the write
  failed.
- lr11x0ResetAGC only reapplied the gain when RX_BOOSTED_GAIN was
  defined, so a runtime setting was lost on the next AGC reset.
This commit is contained in:
agessaman committed 2026-09-23 16:59:39 -07:00
1 parent 0d648e4a18
commit 8cefda9612
16 files changed
+245 -16

No files matched your search

+45
View File
@@ -20,6 +20,9 @@ KissModem::KissModem(Stream& serial, mesh::LocalIdentity& identity, mesh::RNG& r
_setTxPowerCallback = nullptr;
_getCurrentRssiCallback = nullptr;
_getStatsCallback = nullptr;
_setRxBoostedGainCallback = nullptr;
_getRxBoostedGainCallback = nullptr;
_pollRxCallback = nullptr;
_config = {0, 0, 0, 0, 0};
_signal_report_enabled = true;
_agc_reset_interval_sec = KISS_AGC_RESET_DEFAULT_SEC;
@@ -422,6 +425,12 @@ void KissModem::handleHardwareCommand(uint8_t sub_cmd, const uint8_t* data, uint
case HW_CMD_GET_FEM_STATE:
handleGetFemState();
break;
case HW_CMD_SET_RX_BOOSTED_GAIN:
handleSetRxBoostedGain(data, len);
break;
case HW_CMD_GET_RX_BOOSTED_GAIN:
handleGetRxBoostedGain();
break;
default:
writeHardwareError(HW_ERR_UNKNOWN_CMD);
break;
@@ -778,6 +787,7 @@ void KissModem::handleGetCapabilities() {
uint32_t caps = HW_CAP_AGC_RESET;
if (_board.canControlLoRaFemLna()) caps |= HW_CAP_FEM_RX_GAIN;
if (_board.canControlLoRaFemPaGain()) caps |= HW_CAP_FEM_TX_GAIN;
if (_setRxBoostedGainCallback && _getRxBoostedGainCallback) caps |= HW_CAP_RX_BOOSTED_GAIN;
uint8_t buf[4] = { (uint8_t)caps, (uint8_t)(caps >> 8), (uint8_t)(caps >> 16), (uint8_t)(caps >> 24) };
writeHardwareFrame(HW_RESP(HW_CMD_GET_CAPABILITIES), buf, 4);
}
@@ -894,3 +904,38 @@ void KissModem::handleGetFemState() {
}
queueFemReply(true, true);
}
void KissModem::handleSetRxBoostedGain(const uint8_t* data, uint16_t len) {
if (len < 1) {
writeHardwareError(HW_ERR_INVALID_LENGTH);
return;
}
if (!_setRxBoostedGainCallback || !_getRxBoostedGainCallback) {
writeHardwareError(HW_ERR_UNSUPPORTED);
return;
}
// some drivers (LR2021) drop to standby to apply the gain, which would abort a TX and
// discard a completed RX packet; so never during TX, and only after draining RX
if (_tx_state == TX_SENDING || isHostOutputBackedUp()) {
writeHardwareError(HW_ERR_TX_BUSY);
return;
}
if (_pollRxCallback) _pollRxCallback();
tryFlushFrames();
if (_tx_frame_count >= KISS_TX_FRAME_QUEUE_DEPTH) {
writeHardwareError(HW_ERR_TX_BUSY); // no room left for the reply; change nothing
return;
}
// always reply with the state read back, so a failed or partial write is never misreported
_setRxBoostedGainCallback(data[0] != 0x00);
handleGetRxBoostedGain();
}
void KissModem::handleGetRxBoostedGain() {
if (!_getRxBoostedGainCallback) {
writeHardwareError(HW_ERR_UNSUPPORTED);
return;
}
uint8_t val = _getRxBoostedGainCallback() ? 0x01 : 0x00;
writeHardwareFrame(HW_RESP(HW_CMD_GET_RX_BOOSTED_GAIN), &val, 1);
}