optimise mavlink SS packet size (#3029)
[ExpressLRS.git] / src / lib / SX1280Driver / SX1280.h
blob88df5d46efe8e3a65026a88a89b8c75b7ea54ed6
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();
41 bool FrequencyErrorAvailable() const { return modeSupportsFei && (LastPacketSNRRaw > 0); }
43 void TXnb(uint8_t * data, uint8_t size, 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();
55 private:
56 // constant used for no power change pending
57 // must not be a valid power register value
58 static const uint8_t PWRPENDING_NONE = 0x7f;
60 SX1280_RadioOperatingModes_t currOpmode;
61 uint8_t packet_mode;
62 bool modeSupportsFei;
63 uint8_t pwrCurrent;
64 uint8_t pwrPending;
65 SX1280_RadioOperatingModes_t fallBackMode;
67 void SetMode(SX1280_RadioOperatingModes_t OPmode, SX12XX_Radio_Number_t radioNumber, uint32_t incomingTimeout = 0);
68 void SetFIFOaddr(uint8_t txBaseAddr, uint8_t rxBaseAddr);
70 // LoRa functions
71 void ConfigModParamsLoRa(uint8_t bw, uint8_t sf, uint8_t cr);
72 void SetPacketParamsLoRa(uint8_t PreambleLength, SX1280_RadioLoRaPacketLengthsModes_t HeaderType,
73 uint8_t PayloadLength, uint8_t InvertIQ);
74 // FLRC functions
75 void ConfigModParamsFLRC(uint8_t bw, uint8_t cr, uint8_t bt=SX1280_FLRC_BT_0_5);
76 void SetPacketParamsFLRC(uint8_t HeaderType,
77 uint8_t PreambleLength,
78 uint8_t PayloadLength,
79 uint32_t syncWord,
80 uint16_t crcSeed,
81 uint8_t cr);
83 void SetDioIrqParams(uint16_t irqMask,
84 uint16_t dio1Mask=SX1280_IRQ_RADIO_NONE,
85 uint16_t dio2Mask=SX1280_IRQ_RADIO_NONE,
86 uint16_t dio3Mask=SX1280_IRQ_RADIO_NONE);
88 static void IsrCallback_1();
89 static void IsrCallback_2();
90 static void IsrCallback(SX12XX_Radio_Number_t radioNumber);
91 bool RXnbISR(uint16_t irqStatus, SX12XX_Radio_Number_t radioNumber); // ISR for non-blocking RX routine
92 void TXnbISR(); // ISR for non-blocking TX routine
93 void CommitOutputPower();