Don't drop second package if it will be split
[ExpressLRS.git] / src / include / common.h
bloba406eb205c7dd7ca439a5db8e563d1775fd02421
1 #pragma once
3 #ifndef UNIT_TEST
4 #include "targets.h"
6 #if defined(Regulatory_Domain_AU_915) || defined(Regulatory_Domain_EU_868) || defined(Regulatory_Domain_IN_866) || defined(Regulatory_Domain_FCC_915) || defined(Regulatory_Domain_AU_433) || defined(Regulatory_Domain_EU_433)
7 #include "SX127xDriver.h"
8 #endif
10 #if defined(Regulatory_Domain_ISM_2400)
11 #include "SX1280Driver.h"
12 #endif
14 #endif // UNIT_TEST
16 extern uint8_t BindingUID[6];
17 extern uint8_t UID[6];
18 extern uint8_t MasterUID[6];
19 extern uint16_t CRCInitializer;
21 typedef enum
23 TLM_RATIO_NO_TLM = 0,
24 TLM_RATIO_1_128 = 1,
25 TLM_RATIO_1_64 = 2,
26 TLM_RATIO_1_32 = 3,
27 TLM_RATIO_1_16 = 4,
28 TLM_RATIO_1_8 = 5,
29 TLM_RATIO_1_4 = 6,
30 TLM_RATIO_1_2 = 7
32 } expresslrs_tlm_ratio_e;
34 typedef enum
36 connected,
37 tentative,
38 disconnected,
39 disconnectPending, // used on modelmatch change to drop the connection
40 MODE_STATES,
41 // States below here are special mode states
42 noCrossfire,
43 wifiUpdate,
44 bleJoystick,
45 // Failure states go below here to display immediately
46 FAILURE_STATES,
47 radioFailed
48 } connectionState_e;
50 /**
51 * On the TX, tracks what to do when the Tock timer fires
52 **/
53 typedef enum
55 ttrpTransmitting, // Transmitting RC channels as normal
56 ttrpInReceiveMode, // Has switched to Receive mode for telemetry on the next slot (set on TX done)
57 ttrpWindowInProgress // Tock has fired while in receive mode, receiving telemetry on this slot
58 // Next slot will go back to ttrsTransmitting
59 } TxTlmRcvPhase_e;
61 typedef enum
63 tim_disconnected = 0,
64 tim_tentative = 1,
65 tim_locked = 2
66 } RXtimerState_e;
68 extern connectionState_e connectionState;
69 extern connectionState_e connectionStatePrev;
71 typedef enum
73 RF_DOWNLINK_INFO = 0,
74 RF_UPLINK_INFO = 1,
75 RF_AIRMODE_PARAMETERS = 2
76 } expresslrs_tlm_header_e;
78 typedef enum
80 RATE_500HZ = 0,
81 RATE_250HZ = 1,
82 RATE_200HZ = 2,
83 RATE_150HZ = 3,
84 RATE_100HZ = 4,
85 RATE_50HZ = 5,
86 RATE_25HZ = 6,
87 RATE_4HZ = 7,
88 RATE_ENUM_MAX = 8
89 } expresslrs_RFrates_e; // Max value of 16 since only 4 bits have been assigned in the sync package.
91 typedef struct expresslrs_rf_pref_params_s
93 int8_t index;
94 expresslrs_RFrates_e enum_rate; // Max value of 16 since only 4 bits have been assigned in the sync package.
95 int32_t RXsensitivity; // expected RF sensitivity based on
96 uint32_t TOA; // time on air in microseconds
97 uint32_t DisconnectTimeoutMs; // Time without a packet before receiver goes to disconnected (ms)
98 uint32_t RxLockTimeoutMs; // Max time to go from tentative -> connected state on receiver (ms)
99 uint32_t SyncPktIntervalDisconnected; // how often to send the SYNC_PACKET packet (ms) when there is no response from RX
100 uint32_t SyncPktIntervalConnected; // how often to send the SYNC_PACKET packet (ms) when there we have a connection
102 } expresslrs_rf_pref_params_s;
104 #ifndef UNIT_TEST
105 #if defined(Regulatory_Domain_AU_915) || defined(Regulatory_Domain_EU_868) || defined(Regulatory_Domain_IN_866) || defined(Regulatory_Domain_FCC_915) || defined(Regulatory_Domain_AU_433) || defined(Regulatory_Domain_EU_433)
106 #define RATE_MAX 4
107 #define RATE_DEFAULT 0
108 #define RATE_BINDING 2 // 50Hz bind mode
109 typedef struct expresslrs_mod_settings_s
111 int8_t index;
112 expresslrs_RFrates_e enum_rate; // Max value of 16 since only 4 bits have been assigned in the sync package.
113 SX127x_Bandwidth bw;
114 SX127x_SpreadingFactor sf;
115 SX127x_CodingRate cr;
116 uint32_t interval; // interval in us seconds that corresponds to that frequency
117 expresslrs_tlm_ratio_e TLMinterval; // every X packets is a response TLM packet, should be a power of 2
118 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.
119 uint8_t PreambleLen;
120 uint8_t PayloadLength; // Number of OTA bytes to be sent.
121 } expresslrs_mod_settings_t;
123 #endif
125 #if defined(Regulatory_Domain_ISM_2400)
126 #define RATE_MAX 4
127 #define RATE_DEFAULT 0
128 #define RATE_BINDING 3 // 50Hz bind mode
129 typedef struct expresslrs_mod_settings_s
131 int8_t index;
132 expresslrs_RFrates_e enum_rate; // Max value of 16 since only 4 bits have been assigned in the sync package.
133 SX1280_RadioLoRaBandwidths_t bw;
134 SX1280_RadioLoRaSpreadingFactors_t sf;
135 SX1280_RadioLoRaCodingRates_t cr;
136 uint32_t interval; // interval in us seconds that corresponds to that frequency
137 expresslrs_tlm_ratio_e TLMinterval; // every X packets is a response TLM packet, should be a power of 2
138 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.
139 uint8_t PreambleLen;
140 uint8_t PayloadLength; // Number of OTA bytes to be sent.
141 } expresslrs_mod_settings_t;
143 #endif
146 expresslrs_mod_settings_s *get_elrs_airRateConfig(int8_t index);
147 expresslrs_rf_pref_params_s *get_elrs_RFperfParams(int8_t index);
149 uint8_t ICACHE_RAM_ATTR TLMratioEnumToValue(expresslrs_tlm_ratio_e enumval);
150 uint16_t RateEnumToHz(expresslrs_RFrates_e eRate);
152 extern expresslrs_mod_settings_s *ExpressLRS_currAirRate_Modparams;
153 extern expresslrs_rf_pref_params_s *ExpressLRS_currAirRate_RFperfParams;
154 extern uint8_t ExpressLRS_nextAirRateIndex;
155 //extern expresslrs_mod_settings_s *ExpressLRS_nextAirRate;
156 //extern expresslrs_mod_settings_s *ExpressLRS_prevAirRate;
157 uint8_t ICACHE_RAM_ATTR enumRatetoIndex(expresslrs_RFrates_e rate);
159 #endif // UNIT_TEST
161 uint32_t uidMacSeedGet(void);
163 #define AUX1 4
164 #define AUX2 5
165 #define AUX3 6
166 #define AUX4 7
167 #define AUX5 8
168 #define AUX6 9
169 #define AUX7 10
170 #define AUX8 11
171 #define AUX9 12
172 #define AUX10 13
173 #define AUX11 14
174 #define AUX12 15
176 //ELRS SPECIFIC OTA CRC
177 //Koopman formatting https://users.ece.cmu.edu/~koopman/crc/
178 #define ELRS_CRC_POLY 0x07 // 0x83
179 #define ELRS_CRC14_POLY 0x2E57 // 0x372B