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

+15 -1
View File
@@ -123,10 +123,12 @@ MeshCore-specific functionality uses the standard KISS SetHardware command. The
| GetAgcResetInterval | `0x1D` | - |
| SetFemState | `0x1E` | Apply mask (1) + Value mask (1) |
| GetFemState | `0x1F` | - |
| SetRxBoostedGain | `0x20` | Enable (1): 0x00=disable, nonzero=enable |
| GetRxBoostedGain | `0x21` | - |
### Response Sub-commands (TNC to Host)
Response codes use the high-bit convention: `response = command | 0x80`. Generic and unsolicited responses use the `0xF0`+ range. Set commands that report state (SetSignalReport, SetAgcResetInterval, SetFemState) reply with the matching Get response, so `0x9C` and `0x9E` are never sent.
Response codes use the high-bit convention: `response = command | 0x80`. Generic and unsolicited responses use the `0xF0`+ range. Set commands that report state (SetSignalReport, SetAgcResetInterval, SetFemState, SetRxBoostedGain) reply with the matching Get response, so `0x9C`, `0x9E` and `0xA0` are never sent.
| Sub-command | Value | Data |
|--------------|--------|-----------------------------------------|
@@ -155,6 +157,7 @@ Response codes use the high-bit convention: `response = command | 0x80`. Generic
| Capabilities | `0x9B` | Feature bits (4) |
| AgcResetInterval | `0x9D` | Effective seconds (2) |
| FemState | `0x9F` | Capability mask (1) + Value mask (1) |
| RxBoostedGain | `0xA1` | Status (1): 0x00=disabled, 0x01=enabled |
| OK | `0xF0` | - |
| Error | `0xF1` | Error code (1) |
| TxDone | `0xF8` | Result (1): 0x00=failed, 0x01=success |
@@ -239,6 +242,7 @@ All values little-endian. Hosts should probe capabilities rather than infer them
| 0 | `0x01` | AGC reset interval control (always set) |
| 1 | `0x02` | External FEM RX (LNA) gain control |
| 2 | `0x04` | External FEM TX (PA) gain control |
| 3 | `0x08` | Radio chip boosted RX gain control |
Remaining bits are reserved and sent as 0.
@@ -283,6 +287,16 @@ If any bit in the apply mask is not in the board's capability mask (including re
The setting is not persisted; the board's power-on default applies after reboot.
### RX Boosted Gain (SetRxBoostedGain / RxBoostedGain response)
Controls the radio chip's own boosted RX gain mode (SX1262, SX1268, LLCC68, LR11x0, LR2021), the equivalent of the MeshCore `radio.rxgain` setting. This is independent of the external FEM RX gain controlled by SetFemState; a board can support either, both or neither.
| Field | Size | Description |
|--------|--------|------------------------------------|
| Status | 1 byte | 0x00 = power-saving, 0x01 = boosted |
SetRxBoostedGain always replies with the RxBoostedGain response carrying the effective state read back from the radio; if it differs from the requested value, the change did not take effect. Some radios must drop to standby to apply it, so the modem replies `TxBusy` and changes nothing while a packet is on air or host output is backed up; retry later. Before applying, any completed received packet is delivered to the host first. A packet still being received at that moment can be lost. Radios whose driver has no boosted RX gain control (for example SX127x and STM32WLx) do not set capability bit 3 and reply `Unsupported` to both commands. The power-on default is the build's `SX126X_RX_BOOSTED_GAIN` setting; the value is not persisted, and periodic AGC resets preserve it.
### Stats (Stats response)
All values little-endian.