Double MSP (TLM and MAVLink) throughput for Gemini hardware (#3037)
[ExpressLRS.git] / src / lib / SX1280Driver / SX1280.h
blob3d09a9c86f7f7fe6fae4a4aba5375b467d015073
1 #pragma once
3 #include "targets.h"
4 #include "SX1280_Regs.h"
5 #include "SX1280_hal.h"
6 #include "SX12xxDriverCommon.h"
8 #ifdef PLATFORM_ESP8266
9 #include <cstdint>
10 #endif
12 #define RADIO_SNR_SCALE 4 // Units for LastPacketSNRRaw
14 class SX1280Driver: public SX12xxDriverCommon
16 public:
17 static SX1280Driver *instance;
20 ///////////Radio Variables////////
21 uint16_t timeout;
23 ///////////////////////////////////
25 ////////////////Configuration Functions/////////////
26 SX1280Driver();
27 bool Begin(uint32_t minimumFrequency, uint32_t maximumFrequency);
28 void End();
29 void SetTxIdleMode() { SetMode(SX1280_MODE_FS, SX12XX_Radio_All); }; // set Idle mode used when switching from RX to TX
30 void Config(uint8_t bw, uint8_t sf, uint8_t cr, uint32_t freq,
31 uint8_t PreambleLength, bool InvertIQ, uint8_t PayloadLength, uint32_t interval,
32 uint32_t flrcSyncWord=0, uint16_t flrcCrcSeed=0, uint8_t flrc=0);
33 void SetFrequencyHz(uint32_t freq, SX12XX_Radio_Number_t radioNumber);
34 void SetFrequencyReg(uint32_t freq, SX12XX_Radio_Number_t radioNumber = SX12XX_Radio_All);
35 void SetRxTimeoutUs(uint32_t interval);
36 void SetOutputPower(int8_t power);
37 void startCWTest(uint32_t freq, SX12XX_Radio_Number_t radioNumber);
40 bool GetFrequencyErrorbool(SX12XX_Radio_Number_t radioNumber);
41 bool FrequencyErrorAvailable() const { return modeSupportsFei && (LastPacketSNRRaw > 0); }
43 void TXnb(uint8_t * data, uint8_t size, bool sendGeminiBuffer, uint8_t * dataGemini, SX12XX_Radio_Number_t radioNumber);
44 void RXnb(SX1280_RadioOperatingModes_t rxMode = SX1280_MODE_RX, uint32_t incomingTimeout = 0);
46 uint16_t GetIrqStatus(SX12XX_Radio_Number_t radioNumber);
47 void ClearIrqStatus(uint16_t irqMask, SX12XX_Radio_Number_t radioNumber);
49 void GetStatus(SX12XX_Radio_Number_t radioNumber);
51 uint8_t GetRxBufferAddr(SX12XX_Radio_Number_t radioNumber);
52 int8_t GetRssiInst(SX12XX_Radio_Number_t radioNumber);
53 void GetLastPacketStats();
54 void CheckForSecondPacket();
56 private:
57 // constant used for no power change pending
58 // must not be a valid power register value
59 static const uint8_t PWRPENDING_NONE = 0x7f;
61 SX1280_RadioOperatingModes_t currOpmode;
62 uint8_t packet_mode;
63 bool modeSupportsFei;
64 uint8_t pwrCurrent;
65 uint8_t pwrPending;
66 SX1280_RadioOperatingModes_t fallBackMode;
68 void SetMode(SX1280_RadioOperatingModes_t OPmode, SX12XX_Radio_Number_t radioNumber, uint32_t incomingTimeout = 0);
69 void SetFIFOaddr(uint8_t txBaseAddr, uint8_t rxBaseAddr);
71 // LoRa functions
72 void ConfigModParamsLoRa(uint8_t bw, uint8_t sf, uint8_t cr);
73 void SetPacketParamsLoRa(uint8_t PreambleLength, SX1280_RadioLoRaPacketLengthsModes_t HeaderType,
74 uint8_t PayloadLength, uint8_t InvertIQ);
75 // FLRC functions
76 void ConfigModParamsFLRC(uint8_t bw, uint8_t cr, uint8_t bt=SX1280_FLRC_BT_0_5);
77 void SetPacketParamsFLRC(uint8_t HeaderType,
78 uint8_t PreambleLength,
79 uint8_t PayloadLength,
80 uint32_t syncWord,
81 uint16_t crcSeed,
82 uint8_t cr);
84 void SetDioIrqParams(uint16_t irqMask,
85 uint16_t dio1Mask=SX1280_IRQ_RADIO_NONE,
86 uint16_t dio2Mask=SX1280_IRQ_RADIO_NONE,
87 uint16_t dio3Mask=SX1280_IRQ_RADIO_NONE);
89 static void IsrCallback_1();
90 static void IsrCallback_2();
91 static void IsrCallback(SX12XX_Radio_Number_t radioNumber);
92 bool RXnbISR(uint16_t irqStatus, SX12XX_Radio_Number_t radioNumber); // ISR for non-blocking RX routine
93 void TXnbISR(); // ISR for non-blocking TX routine
94 void CommitOutputPower();