3 #include "SX127xRegs.h"
6 #ifdef PLATFORM_ESP8266
14 static SX127xDriver
*instance
;
16 ///////Callback Function Pointers/////
17 static void inline nullCallback(void);
19 static void (*RXdoneCallback
)(); //function pointer for callback
20 static void (*TXdoneCallback
)(); //function pointer for callback
22 static void (*TXtimeout
)(); //function pointer for callback
23 static void (*RXtimeout
)(); //function pointer for callback
25 ///////////Radio Variables////////
26 #define TXRXBuffSize 16
27 const uint8_t TXbuffLen
= TXRXBuffSize
;
28 const uint8_t RXbuffLen
= TXRXBuffSize
;
30 static volatile WORD_ALIGNED_ATTR
uint8_t TXdataBuffer
[TXRXBuffSize
];
31 static volatile WORD_ALIGNED_ATTR
uint8_t RXdataBuffer
[TXRXBuffSize
];
33 bool headerExplMode
= false;
34 bool crcEnabled
= false;
37 uint8_t PayloadLength
= 8; // Dummy default value which is overwritten during setup.
38 uint32_t currFreq
= 0; // leave as 0 to ensure that it gets set
39 uint8_t currSyncWord
= SX127X_SYNC_WORD
;
40 uint8_t currPreambleLen
= 0;
41 SX127x_Bandwidth currBW
= SX127x_BW_125_00_KHZ
; //default values from datasheet
42 SX127x_SpreadingFactor currSF
= SX127x_SF_7
;
43 SX127x_CodingRate currCR
= SX127x_CR_4_5
;
44 SX127x_RadioOPmodes currOpmode
= SX127x_OPMODE_SLEEP
;
45 uint8_t currPWR
= 0b0000;
46 SX127x_ModulationModes ModFSKorLoRa
= SX127x_OPMODE_LORA
;
47 bool IQinverted
= false;
48 ///////////////////////////////////
50 /////////////Packet Stats//////////
51 int8_t LastPacketRSSI
;
54 uint32_t TXstartMicros
;
57 uint32_t LastTXdoneMicros
;
58 uint32_t TXdoneMicros
;
59 /////////////////////////////////
61 ////////////////Configuration Functions/////////////
65 void Config(SX127x_Bandwidth bw
, SX127x_SpreadingFactor sf
, SX127x_CodingRate cr
, uint32_t freq
, uint8_t preambleLen
, uint8_t syncWord
, bool InvertIQ
, uint8_t PayloadLength
);
66 void Config(SX127x_Bandwidth bw
, SX127x_SpreadingFactor sf
, SX127x_CodingRate cr
, uint32_t freq
, uint8_t preambleLen
, bool InvertIQ
, uint8_t PayloadLength
);
67 void SetMode(SX127x_RadioOPmodes mode
);
68 void SetTxIdleMode() { SetMode(SX127x_OPMODE_STANDBY
); } // set Idle mode used when switching from RX to TX
69 void ConfigLoraDefaults();
71 void SetBandwidthCodingRate(SX127x_Bandwidth bw
, SX127x_CodingRate cr
);
72 void SetSyncWord(uint8_t syncWord
);
73 void SetOutputPower(uint8_t Power
);
74 void SetOutputPowerMax() { SetOutputPower(0b1111); };
75 void SetPreambleLength(uint8_t PreambleLen
);
76 void SetSpreadingFactor(SX127x_SpreadingFactor sf
);
78 uint32_t GetCurrBandwidth();
79 uint32_t GetCurrBandwidthNormalisedShifted();
81 #define FREQ_STEP 61.03515625
82 void SetFrequencyHz(uint32_t freq
);
83 void SetFrequencyReg(uint32_t freq
);
84 int32_t GetFrequencyError();
85 bool GetFrequencyErrorbool();
86 void SetPPMoffsetReg(int32_t offset
);
88 ////////////////////////////////////////////////////
90 /////////////////Utility Funcitons//////////////////
91 uint8_t GetIrqFlags();
94 //////////////RX related Functions/////////////////
98 uint8_t UnsignedGetLastPacketRSSI();
99 int8_t GetLastPacketRSSI();
100 int8_t GetLastPacketSNR();
101 int8_t GetCurrRSSI();
103 ////////////Non-blocking TX related Functions/////////////////
105 /////////////Non-blocking RX related Functions///////////////
109 static void ICACHE_RAM_ATTR
IsrCallback();
110 void RXnbISR(); // ISR for non-blocking RX routine
111 void TXnbISR(); // ISR for non-blocking TX routine