Merge pull request #11198 from SteveCEvans/sce_rc2
[betaflight.git] / src / main / rx / expresslrs_impl.h
blobeb480c4a60fbc5ac53153c05a35487ee30e22136
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;
77 timerState_e timerState;
78 connectionState_e connectionState;
80 uint8_t rfModeCycleMultiplier;
81 uint16_t cycleIntervalMs;
82 uint32_t rfModeCycledAtMs;
83 uint8_t rateIndex;
84 uint8_t nextRateIndex;
86 uint32_t gotConnectionMs;
87 uint32_t lastSyncPacketMs;
88 uint32_t lastValidPacketMs;
90 uint32_t configCheckedAtMs;
91 bool configChanged;
93 bool inBindingMode;
94 volatile bool fhssRequired;
96 uint32_t statsUpdatedAtMs;
98 elrsRxInitFnPtr init;
99 elrsRxConfigFnPtr config;
100 elrsRxStartReceivingFnPtr startReceiving;
101 elrsRxISRFnPtr rxISR;
102 elrsRxTransmitDataFnPtr transmitData;
103 elrsRxReceiveDataFnPtr receiveData;
104 elrsRxGetRFlinkInfoFnPtr getRFlinkInfo;
105 elrsRxSetFrequencyFnPtr setFrequency;
106 elrsRxHandleFreqCorrectionFnPtr handleFreqCorrection;
108 timerOvrHandlerRec_t timerUpdateCb;
109 } elrsReceiver_t;