6 #if defined(RADIO_SX127X)
7 #include "SX127xDriver.h"
8 #elif defined(RADIO_LR1121)
9 #include "LR1121Driver.h"
10 #elif defined(RADIO_SX128X)
11 #include "SX1280Driver.h"
13 #error "Radio configuration is not valid!"
18 // Used to XOR with OtaCrcInitializer and macSeed to reduce compatibility with previous versions.
19 // It should be incremented when the OTA packet structure is modified.
20 #define OTA_VERSION_ID 4
23 typedef enum : uint8_t
25 TLM_RATIO_STD
= 0, // Use suggested ratio from ModParams
34 TLM_RATIO_DISARMED
, // TLM_RATIO_STD when disarmed, TLM_RATIO_NO_TLM when armed
35 } expresslrs_tlm_ratio_e
;
41 awaitingModelId
, // TX only
44 // States below here are special mode states
47 NO_CONFIG_SAVE_STATES
,
50 // Failure states go below here to display immediately
57 * On the TX, tracks what to do when the Tock timer fires
61 ttrpTransmitting
, // Transmitting RC channels as normal
62 ttrpPreReceiveGap
, // Has switched to Receive mode for telemetry, but in the gap between TX done and Tock
63 ttrpExpectingTelem
// Still in Receive mode, Tock has fired, receiving telem as far as we know
77 RF_AIRMODE_PARAMETERS
= 2
78 } expresslrs_tlm_header_e
;
80 typedef enum : uint8_t
82 // RATE_MODULATION_BAND_RATE_MODE
84 RATE_LORA_900_25HZ
= 0,
87 RATE_LORA_900_100HZ_8CH
,
90 RATE_LORA_900_200HZ_8CH
,
92 RATE_LORA_900_333HZ_8CH
,
94 RATE_LORA_900_50HZ_DVDA
,
95 RATE_FSK_900_1000HZ_8CH
,
97 RATE_LORA_2G4_25HZ
= 20,
100 RATE_LORA_2G4_100HZ_8CH
,
103 RATE_LORA_2G4_200HZ_8CH
,
105 RATE_LORA_2G4_333HZ_8CH
,
107 RATE_FLRC_2G4_250HZ_DVDA
,
108 RATE_FLRC_2G4_500HZ_DVDA
,
110 RATE_FLRC_2G4_1000HZ
,
111 RATE_FSK_2G4_250HZ_DVDA
,
112 RATE_FSK_2G4_500HZ_DVDA
,
115 RATE_LORA_DUAL_100HZ_8CH
= 100,
116 RATE_LORA_DUAL_150HZ
,
117 } expresslrs_RFrates_e
;
120 RADIO_TYPE_SX127x_LORA
,
121 RADIO_TYPE_LR1121_LORA_900
,
122 RADIO_TYPE_LR1121_LORA_2G4
,
123 RADIO_TYPE_LR1121_GFSK_900
,
124 RADIO_TYPE_LR1121_GFSK_2G4
,
125 RADIO_TYPE_LR1121_LORA_DUAL
,
126 RADIO_TYPE_SX128x_LORA
,
127 RADIO_TYPE_SX128x_FLRC
,
130 typedef enum : uint8_t
132 TX_RADIO_MODE_GEMINI
= 0,
133 TX_RADIO_MODE_ANT_1
= 1,
134 TX_RADIO_MODE_ANT_2
= 2,
135 TX_RADIO_MODE_SWITCH
= 3
138 typedef enum : uint8_t
142 } tx_transmission_mode_e
;
144 // Value used for expresslrs_rf_pref_params_s.DynpowerUpThresholdSnr if SNR should not be used
145 #define DYNPOWER_SNR_THRESH_NONE -127
146 #define SNR_SCALE(snr) ((int8_t)((float)snr * RADIO_SNR_SCALE))
147 #define SNR_DESCALE(snrScaled) (snrScaled / RADIO_SNR_SCALE)
148 // Bound is any of the last 4 bytes nonzero (unbound is all zeroes)
149 #define UID_IS_BOUND(uid) (uid[2] != 0 || uid[3] != 0 || uid[4] != 0 || uid[5] != 0)
151 typedef struct expresslrs_rf_pref_params_s
154 int16_t RXsensitivity
; // expected min RF sensitivity
155 uint16_t TOA
; // time on air in microseconds
156 uint16_t DisconnectTimeoutMs
; // Time without a packet before receiver goes to disconnected (ms)
157 uint16_t RxLockTimeoutMs
; // Max time to go from tentative -> connected state on receiver (ms)
158 uint16_t SyncPktIntervalDisconnected
; // how often to send the PACKET_TYPE_SYNC (ms) when there is no response from RX
159 uint16_t SyncPktIntervalConnected
; // how often to send the PACKET_TYPE_SYNC (ms) when there we have a connection
160 int8_t DynpowerSnrThreshUp
; // Request a raise in power if the reported (average) SNR is at or below this
161 // or DYNPOWER_UPTHRESH_SNR_NONE to use RSSI
162 int8_t DynpowerSnrThreshDn
; // Like DynpowerSnrUpThreshold except to lower power
164 } expresslrs_rf_pref_params_s
;
166 typedef struct expresslrs_mod_settings_s
170 expresslrs_RFrates_e enum_rate
;
175 #if defined(RADIO_LR1121)
179 uint8_t PreambleLen2
;
181 expresslrs_tlm_ratio_e TLMinterval
; // every X packets is a response TLM packet, should be a power of 2
182 uint8_t FHSShopInterval
; // every X packets we hop to a new frequency. Max value of 16 since only 4 bits have been assigned in the sync package.
183 int32_t interval
; // interval in us seconds that corresponds to that frequency
184 uint8_t PayloadLength
; // Number of OTA bytes to be sent.
185 uint8_t numOfSends
; // Number of packets to send.
186 } expresslrs_mod_settings_t
;
188 // Limited to 16 possible ACTIONs by config storage currently
189 typedef enum : uint8_t {
191 ACTION_INCREASE_POWER
,
192 ACTION_GOTO_VTX_BAND
,
193 ACTION_GOTO_VTX_CHANNEL
,
203 enum eServoOutputMode
: uint8_t
205 som50Hz
= 0, // 0: 50 Hz | modes are "Servo PWM" where the signal is 988-2012us
206 som60Hz
, // 1: 60 Hz | and the mode sets the refresh interval
207 som100Hz
, // 2: 100 Hz | must be mode=0 for default in config
208 som160Hz
, // 3: 160Hz
209 som333Hz
, // 4: 333Hz
210 som400Hz
, // 5: 400Hz
211 som10KHzDuty
, // 6: 10kHz duty
212 somOnOff
, // 7: Digital 0/1 mode
213 somDShot
, // 8: DShot300
214 somSerial
, // 9: primary Serial
215 somSCL
, // 10: I2C clock signal
216 somSDA
, // 11: I2C data line
217 somPwm
, // 12: true PWM mode (NOT SUPPORTED)
218 #if defined(PLATFORM_ESP32)
219 somSerial1RX
, // 13: secondary Serial RX
220 somSerial1TX
, // 14: secondary Serial TX
224 enum eServoOutputFailsafeMode
: uint8_t
226 PWMFAILSAFE_SET_POSITION
, // user customizable pulse value
227 PWMFAILSAFE_NO_PULSES
, // stop pulsing
228 PWMFAILSAFE_LAST_POSITION
, // continue to pulse last used value
231 enum eSerialProtocol
: uint8_t
234 PROTOCOL_INVERTED_CRSF
,
236 PROTOCOL_INVERTED_SBUS
,
241 PROTOCOL_MSP_DISPLAYPORT
,
244 #if defined(PLATFORM_ESP32)
245 enum eSerial1Protocol
: uint8_t
247 PROTOCOL_SERIAL1_OFF
,
248 PROTOCOL_SERIAL1_CRSF
,
249 PROTOCOL_SERIAL1_INVERTED_CRSF
,
250 PROTOCOL_SERIAL1_SBUS
,
251 PROTOCOL_SERIAL1_INVERTED_SBUS
,
252 PROTOCOL_SERIAL1_SUMD
,
253 PROTOCOL_SERIAL1_DJI_RS_PRO
,
254 PROTOCOL_SERIAL1_HOTT_TLM
,
255 PROTOCOL_SERIAL1_TRAMP
,
256 PROTOCOL_SERIAL1_SMARTAUDIO
,
257 PROTOCOL_SERIAL1_MSP_DISPLAYPORT
,
261 enum eFailsafeMode
: uint8_t
264 FAILSAFE_LAST_POSITION
,
265 FAILSAFE_SET_POSITION
268 enum eAuxChannels
: uint8_t
282 CRSF_NUM_CHANNELS
= 16
285 //ELRS SPECIFIC OTA CRC
286 //Koopman formatting https://users.ece.cmu.edu/~koopman/crc/
287 #define ELRS_CRC_POLY 0x07 // 0x83
288 #define ELRS_CRC14_POLY 0x2E57 // 0x372B
291 #if defined(RADIO_SX127X)
293 #define RATE_BINDING RATE_LORA_900_50HZ
295 extern SX127xDriver Radio
;
297 #elif defined(RADIO_LR1121)
299 #define RATE_BINDING RATE_LORA_900_50HZ
300 #define RATE_DUALBAND_BINDING RATE_LORA_2G4_50HZ
302 extern LR1121Driver Radio
;
304 #elif defined(RADIO_SX128X)
305 #define RATE_MAX 10 // 2xFLRC + 2xDVDA + 4xLoRa + 2xFullRes
306 #define RATE_BINDING RATE_LORA_2G4_50HZ
308 extern SX1280Driver Radio
;
312 expresslrs_mod_settings_s
*get_elrs_airRateConfig(uint8_t index
);
313 expresslrs_rf_pref_params_s
*get_elrs_RFperfParams(uint8_t index
);
314 uint8_t get_elrs_HandsetRate_max(uint8_t rateIndex
, uint32_t minInterval
);
316 uint8_t TLMratioEnumToValue(expresslrs_tlm_ratio_e
const enumval
);
317 uint8_t TLMBurstMaxForRateRatio(uint16_t const rateHz
, uint8_t const ratioDiv
);
318 uint8_t enumRatetoIndex(expresslrs_RFrates_e
const eRate
);
320 extern uint8_t UID
[UID_LEN
];
321 extern bool connectionHasModelMatch
;
322 extern bool teamraceHasModelMatch
;
323 extern bool InBindingMode
;
324 extern uint8_t ExpressLRS_currTlmDenom
;
325 extern connectionState_e connectionState
;
326 extern expresslrs_mod_settings_s
*ExpressLRS_currAirRate_Modparams
;
327 extern expresslrs_rf_pref_params_s
*ExpressLRS_currAirRate_RFperfParams
;
328 extern uint32_t ChannelData
[CRSF_NUM_CHANNELS
]; // Current state of channels, CRSF format
330 uint32_t uidMacSeedGet();
332 void EnterBindingModeSafely(); // defined in rx_main/tx_main
334 #if defined(RADIO_LR1121)
335 bool isSupportedRFRate(uint8_t index
);
337 inline bool isSupportedRFRate(uint8_t index
) { return true; };