2025-01-13 14:07:48 +11:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "CustomSX1262.h"
|
|
|
|
|
#include "RadioLibWrappers.h"
|
2026-02-19 17:34:48 +01:00
|
|
|
#include "SX126xReset.h"
|
2025-01-13 14:07:48 +11:00
|
|
|
|
2026-02-10 14:56:20 +00:00
|
|
|
#ifndef USE_SX1262
|
|
|
|
|
#define USE_SX1262
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-01-13 14:07:48 +11:00
|
|
|
class CustomSX1262Wrapper : public RadioLibWrapper {
|
|
|
|
|
public:
|
|
|
|
|
CustomSX1262Wrapper(CustomSX1262& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { }
|
2026-05-01 14:47:07 +10:00
|
|
|
|
|
|
|
|
void setParams(float freq, float bw, uint8_t sf, uint8_t cr) override {
|
|
|
|
|
((CustomSX1262 *)_radio)->setFrequency(freq);
|
|
|
|
|
((CustomSX1262 *)_radio)->setSpreadingFactor(sf);
|
|
|
|
|
((CustomSX1262 *)_radio)->setBandwidth(bw);
|
|
|
|
|
((CustomSX1262 *)_radio)->setCodingRate(cr);
|
|
|
|
|
updatePreamble(sf);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-20 09:07:00 +02:00
|
|
|
// From RadioLib's SX1262::setFrequency(): RADIOLIB_CHECK_RANGE(freq, 150.0f, 960.0f, ...).
|
|
|
|
|
void getFreqBounds(float& min_mhz, float& max_mhz) const override { min_mhz = 150.0f; max_mhz = 960.0f; }
|
|
|
|
|
|
2025-05-24 20:42:00 +10:00
|
|
|
bool isReceivingPacket() override {
|
|
|
|
|
return ((CustomSX1262 *)_radio)->isReceiving();
|
2025-01-21 13:37:32 +11:00
|
|
|
}
|
2025-05-24 21:24:44 +10:00
|
|
|
float getCurrentRSSI() override {
|
|
|
|
|
return ((CustomSX1262 *)_radio)->getRSSI(false);
|
|
|
|
|
}
|
2025-01-13 14:07:48 +11:00
|
|
|
float getLastRSSI() const override { return ((CustomSX1262 *)_radio)->getRSSI(); }
|
|
|
|
|
float getLastSNR() const override { return ((CustomSX1262 *)_radio)->getSNR(); }
|
2025-02-04 12:35:53 +11:00
|
|
|
|
|
|
|
|
float packetScore(float snr, int packet_len) override {
|
|
|
|
|
int sf = ((CustomSX1262 *)_radio)->spreadingFactor;
|
2025-02-04 15:00:28 +11:00
|
|
|
return packetScoreInt(snr, sf, packet_len);
|
2025-02-04 12:35:53 +11:00
|
|
|
}
|
2026-03-05 22:14:22 +11:00
|
|
|
uint8_t getSpreadingFactor() const override { return ((CustomSX1262 *)_radio)->spreadingFactor; }
|
2025-11-22 02:06:44 +01:00
|
|
|
virtual void powerOff() override {
|
|
|
|
|
((CustomSX1262 *)_radio)->sleep(false);
|
|
|
|
|
}
|
2026-02-19 16:16:21 +01:00
|
|
|
|
2026-02-19 17:34:48 +01:00
|
|
|
void doResetAGC() override { sx126xResetAGC((SX126x *)_radio); }
|
2026-03-05 18:31:00 +00:00
|
|
|
|
2026-06-10 23:30:43 +02:00
|
|
|
// Power-save RX = hardware RX duty-cycle (SX126x SetRxDutyCycle, datasheet
|
|
|
|
|
// 13.1.7). The chip's sequencer cycles RX↔sleep on its own, latches a preamble
|
|
|
|
|
// of the configured length and then stays in RX to receive the packet, raising
|
|
|
|
|
// RX_DONE on DIO1 — handled by the normal recvRaw() path, no MCU polling.
|
|
|
|
|
// minSymbols=8 is the reliable preamble-latch count for SF7-12. If the
|
|
|
|
|
// configured preamble is too short for a real duty-cycle (senderPreamble <
|
|
|
|
|
// 2*minSymbols+1), RadioLib transparently falls back to a continuous receive.
|
|
|
|
|
int16_t startPowerSaveRecv() override {
|
|
|
|
|
return ((SX126x *)_radio)->startReceiveDutyCycleAuto(preambleLengthForSF(_preamble_sf), 8);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-05 18:31:00 +00:00
|
|
|
void setRxBoostedGainMode(bool en) override {
|
|
|
|
|
((CustomSX1262 *)_radio)->setRxBoostedGainMode(en);
|
|
|
|
|
}
|
|
|
|
|
bool getRxBoostedGainMode() const override {
|
|
|
|
|
return ((CustomSX1262 *)_radio)->getRxBoostedGainMode();
|
|
|
|
|
}
|
2025-01-13 14:07:48 +11:00
|
|
|
};
|