Improve frame error detection
[betaflight.git] / src / main / rx / expresslrs_impl.h
blobdfcfeb9d80250ccfc022e945d0bc91feb74d47fe
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 // expresslrs packet header types
22 // 00 -> standard 4 channel data packet
23 // 01 -> switch data packet
24 // 11 -> tlm packet
25 // 10 -> sync packet with hop data
26 typedef enum {
27 ELRS_RC_DATA_PACKET = 0x00,
28 ELRS_MSP_DATA_PACKET = 0x01,
29 ELRS_SYNC_PACKET = 0x02,
30 ELRS_TLM_PACKET = 0x03,
31 } elrsPacketType_e;
33 typedef enum {
34 ELRS_DIO_UNKNOWN = 0,
35 ELRS_DIO_RX_DONE = 1,
36 ELRS_DIO_TX_DONE = 2,
37 ELRS_DIO_RX_AND_TX_DONE = 3,
38 } dioReason_e;
40 typedef enum {
41 ELRS_CONNECTED,
42 ELRS_TENTATIVE,
43 ELRS_DISCONNECTED,
44 ELRS_DISCONNECT_PENDING // used on modelmatch change to drop the connection
45 } connectionState_e;
47 typedef enum {
48 ELRS_TIM_DISCONNECTED = 0,
49 ELRS_TIM_TENTATIVE = 1,
50 ELRS_TIM_LOCKED = 2
51 } timerState_e;
53 typedef struct elrsReceiver_s {
55 IO_t resetPin;
56 IO_t busyPin;
58 int32_t freqOffset;
59 uint32_t currentFreq;
61 volatile uint8_t nonceRX; // nonce that we THINK we are up to.
63 elrsModSettings_t *modParams;
64 elrsRfPerfParams_t *rfPerfParams;
66 const uint8_t *UID;
68 int8_t rssi;
69 int8_t snr;
70 int8_t rssiFiltered;
72 uint8_t uplinkLQ;
74 bool alreadyFhss;
75 bool alreadyTelemResp;
76 bool lockRFmode;
77 bool started;
79 timerState_e timerState;
80 connectionState_e connectionState;
82 uint8_t rfModeCycleMultiplier;
83 uint16_t cycleIntervalMs;
84 uint32_t rfModeCycledAtMs;
85 uint8_t rateIndex;
86 uint8_t nextRateIndex;
88 uint32_t gotConnectionMs;
89 uint32_t lastSyncPacketMs;
90 uint32_t lastValidPacketMs;
92 uint32_t configCheckedAtMs;
93 bool configChanged;
95 bool inBindingMode;
96 volatile bool initializeReceiverPending;
97 volatile bool fhssRequired;
98 volatile bool didFhss;
100 uint32_t statsUpdatedAtMs;
102 elrsRxInitFnPtr init;
103 elrsRxConfigFnPtr config;
104 elrsRxStartReceivingFnPtr startReceiving;
105 elrsRxISRFnPtr rxISR;
106 elrsRxHandleFromTockFnPtr rxHandleFromTock;
107 elrsRxBusyTimeoutFnPtr rxHandleFromTick;
108 elrsRxgetRfLinkInfoFnPtr getRfLinkInfo;
109 elrsRxSetFrequencyFnPtr setFrequency;
110 elrsRxHandleFreqCorrectionFnPtr handleFreqCorrection;
112 timerOvrHandlerRec_t timerUpdateCb;
113 } elrsReceiver_t;