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.
51 lines
1.8 KiB
C++
51 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include "CustomSX1268.h"
|
|
#include "RadioLibWrappers.h"
|
|
#include "SX126xReset.h"
|
|
|
|
#ifndef USE_SX1268
|
|
#define USE_SX1268
|
|
#endif
|
|
|
|
class CustomSX1268Wrapper : public RadioLibWrapper {
|
|
public:
|
|
CustomSX1268Wrapper(CustomSX1268& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { }
|
|
|
|
void setParams(float freq, float bw, uint8_t sf, uint8_t cr) override {
|
|
((CustomSX1268 *)_radio)->setFrequency(freq);
|
|
((CustomSX1268 *)_radio)->setSpreadingFactor(sf);
|
|
((CustomSX1268 *)_radio)->setBandwidth(bw);
|
|
((CustomSX1268 *)_radio)->setCodingRate(cr);
|
|
updatePreamble(sf);
|
|
PacketMillis pm = calcMaxPacketMillis(sf, bw, cr, preambleLengthForSF(sf));
|
|
((CustomSX1268 *)_radio)->setPreambleMillis(pm.preambleMillis);
|
|
((CustomSX1268 *)_radio)->setMaxPayloadMillis(pm.payloadMillis);
|
|
}
|
|
|
|
bool isReceivingPacket() override {
|
|
return ((CustomSX1268 *)_radio)->isReceiving();
|
|
}
|
|
float getCurrentRSSI() override {
|
|
return ((CustomSX1268 *)_radio)->getRSSI(false);
|
|
}
|
|
float getLastRSSI() const override { return ((CustomSX1268 *)_radio)->getRSSI(); }
|
|
float getLastSNR() const override { return ((CustomSX1268 *)_radio)->getSNR(); }
|
|
|
|
float packetScore(float snr, int packet_len) override {
|
|
int sf = ((CustomSX1268 *)_radio)->spreadingFactor;
|
|
return packetScoreInt(snr, sf, packet_len);
|
|
}
|
|
uint8_t getSpreadingFactor() const override { return ((CustomSX1268 *)_radio)->spreadingFactor; }
|
|
|
|
bool supportsRxBoostedGain() const override { return true; }
|
|
bool setRxBoostedGainMode(bool en) override {
|
|
return ((CustomSX1268 *)_radio)->setRxBoostedGainMode(en) == RADIOLIB_ERR_NONE;
|
|
}
|
|
bool getRxBoostedGainMode() const override {
|
|
return ((CustomSX1268 *)_radio)->getRxBoostedGainMode();
|
|
}
|
|
|
|
void doResetAGC() override { sx126xResetAGC((SX126x *)_radio, getRxBoostedGainMode()); }
|
|
};
|