Merge pull request #11299 from daleckystepan/vtx-start-bit
[betaflight.git] / src / main / rx / expresslrs_impl.h
blob2655cf2c99fb63a14386df97d3a8fe32ee88c9c0
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 } dioReason_e;
39 typedef enum {
40 ELRS_CONNECTED,
41 ELRS_TENTATIVE,
42 ELRS_DISCONNECTED,
43 ELRS_DISCONNECT_PENDING // used on modelmatch change to drop the connection
44 } connectionState_e;
46 typedef enum {
47 ELRS_TIM_DISCONNECTED = 0,
48 ELRS_TIM_TENTATIVE = 1,
49 ELRS_TIM_LOCKED = 2
50 } timerState_e;
52 typedef struct elrsReceiver_s {
54 IO_t resetPin;
55 IO_t busyPin;
57 int32_t freqOffset;
58 uint32_t currentFreq;
60 volatile uint8_t nonceRX; // nonce that we THINK we are up to.
62 elrsModSettings_t *modParams;
63 elrsRfPerfParams_t *rfPerfParams;
65 const uint8_t *UID;
67 int8_t rssi;
68 int8_t snr;
69 int8_t rssiFiltered;
71 uint8_t uplinkLQ;
73 bool alreadyFHSS;
74 bool alreadyTLMresp;
75 bool lockRFmode;
76 bool started;
78 timerState_e timerState;
79 connectionState_e connectionState;
81 uint8_t rfModeCycleMultiplier;
82 uint16_t cycleIntervalMs;
83 uint32_t rfModeCycledAtMs;
84 uint8_t rateIndex;
85 uint8_t nextRateIndex;
87 uint32_t gotConnectionMs;
88 uint32_t lastSyncPacketMs;
89 uint32_t lastValidPacketMs;
91 uint32_t configCheckedAtMs;
92 bool configChanged;
94 bool inBindingMode;
95 volatile bool fhssRequired;
97 uint32_t statsUpdatedAtMs;
99 elrsRxInitFnPtr init;
100 elrsRxConfigFnPtr config;
101 elrsRxStartReceivingFnPtr startReceiving;
102 elrsRxISRFnPtr rxISR;
103 elrsRxTransmitDataFnPtr transmitData;
104 elrsRxReceiveDataFnPtr receiveData;
105 elrsRxGetRFlinkInfoFnPtr getRFlinkInfo;
106 elrsRxSetFrequencyFnPtr setFrequency;
107 elrsRxHandleFreqCorrectionFnPtr handleFreqCorrection;
109 timerOvrHandlerRec_t timerUpdateCb;
110 } elrsReceiver_t;