4 #include "SX1280_Regs.h"
5 #include "SX1280_hal.h"
10 ///////Callback Function Pointers/////
11 static void ICACHE_RAM_ATTR
nullCallback(void);
13 void (*RXdoneCallback
)() = &nullCallback
; //function pointer for callback
14 void (*TXdoneCallback
)() = &nullCallback
; //function pointer for callback
16 static void (*TXtimeout
)(); //function pointer for callback
17 static void (*RXtimeout
)(); //function pointer for callback
19 ///////////Radio Variables////////
20 #define TXRXBuffSize 16
21 volatile uint8_t TXdataBuffer
[TXRXBuffSize
];
22 volatile uint8_t RXdataBuffer
[TXRXBuffSize
];
24 uint8_t PayloadLength
= 8; // Dummy default value which is overwritten during setup.
26 static uint8_t _syncWord
;
28 SX1280_RadioLoRaBandwidths_t currBW
= SX1280_LORA_BW_0800
;
29 SX1280_RadioLoRaSpreadingFactors_t currSF
= SX1280_LORA_SF6
;
30 SX1280_RadioLoRaCodingRates_t currCR
= SX1280_LORA_CR_4_7
;
31 uint32_t currFreq
= 2400000000;
32 SX1280_RadioOperatingModes_t currOpmode
= SX1280_MODE_SLEEP
;
33 bool IQinverted
= false;
35 // static uint8_t currPWR;
36 // static uint8_t maxPWR;
38 ///////////////////////////////////
40 /////////////Packet Stats//////////
41 int8_t LastPacketRSSI
= 0;
42 int8_t LastPacketSNR
= 0;
43 volatile uint8_t NonceTX
= 0;
44 volatile uint8_t NonceRX
= 0;
45 static uint32_t TotalTime
;
46 static uint32_t TimeOnAir
;
47 static uint32_t TXstartMicros
;
48 static uint32_t TXspiTime
;
49 static uint32_t HeadRoom
;
50 static uint32_t TXdoneMicros
;
51 /////////////////////////////////
53 //// Local Variables //// Copy of values for SPI speed optimisation
54 static uint8_t CURR_REG_PAYLOAD_LENGTH
;
55 static uint8_t CURR_REG_DIO_MAPPING_1
;
56 static uint8_t CURR_REG_FIFO_ADDR_PTR
;
58 ////////////////Configuration Functions/////////////
60 static SX1280Driver
*instance
;
63 void SetMode(SX1280_RadioOperatingModes_t OPmode
);
64 void SetTxIdleMode() { SetMode(SX1280_MODE_FS
); }; // set Idle mode used when switching from RX to TX
65 void Config(SX1280_RadioLoRaBandwidths_t bw
, SX1280_RadioLoRaSpreadingFactors_t sf
, SX1280_RadioLoRaCodingRates_t cr
, uint32_t freq
, uint8_t PreambleLength
, bool InvertIQ
, uint8_t PayloadLength
);
66 void ConfigLoRaModParams(SX1280_RadioLoRaBandwidths_t bw
, SX1280_RadioLoRaSpreadingFactors_t sf
, SX1280_RadioLoRaCodingRates_t cr
);
67 void SetPacketParams(uint8_t PreambleLength
, SX1280_RadioLoRaPacketLengthsModes_t HeaderType
, uint8_t PayloadLength
, SX1280_RadioLoRaCrcModes_t crc
, SX1280_RadioLoRaIQModes_t InvertIQ
);
68 void ICACHE_RAM_ATTR
SetFrequencyHz(uint32_t freq
);
69 void ICACHE_RAM_ATTR
SetFrequencyReg(uint32_t freq
);
70 void ICACHE_RAM_ATTR
SetFIFOaddr(uint8_t txBaseAddr
, uint8_t rxBaseAddr
);
71 void SetOutputPower(int8_t power
);
72 void SetOutputPowerMax() { SetOutputPower(13); };
74 int32_t ICACHE_RAM_ATTR
GetFrequencyError();
79 uint16_t GetIrqStatus();
80 void ClearIrqStatus(uint16_t irqMask
);
84 void SetDioIrqParams(uint16_t irqMask
, uint16_t dio1Mask
, uint16_t dio2Mask
, uint16_t dio3Mask
);
86 bool GetFrequencyErrorbool();
87 uint8_t GetRxBufferAddr();
88 void GetLastPacketStats();
91 static void ICACHE_RAM_ATTR
IsrCallback();
92 void RXnbISR(); // ISR for non-blocking RX routine
93 void TXnbISR(); // ISR for non-blocking TX routine