Make negotiated baud configurable for CRSF
[betaflight.git] / src / main / rx / crsf.h
bloba1ae3c80be5063533d4800feff741031a413bc99
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 #pragma once
23 #include "rx/crsf_protocol.h"
26 #define CRSF_PORT_OPTIONS (SERIAL_STOPBITS_1 | SERIAL_PARITY_NO)
27 #define CRSF_PORT_MODE MODE_RXTX
29 #define CRSF_MAX_CHANNEL 16
30 #define CRSFV3_MAX_CHANNEL 24
32 #define CRSF_SUBSET_RC_STARTING_CHANNEL_BITS 5
33 #define CRSF_SUBSET_RC_STARTING_CHANNEL_MASK 0x1F
34 #define CRSF_SUBSET_RC_RES_CONFIGURATION_BITS 2
35 #define CRSF_SUBSET_RC_RES_CONFIGURATION_MASK 0x03
36 #define CRSF_SUBSET_RC_RESERVED_CONFIGURATION_BITS 1
38 #define CRSF_RC_CHANNEL_SCALE_LEGACY 0.62477120195241f
39 #define CRSF_SUBSET_RC_RES_CONF_10B 0
40 #define CRSF_SUBSET_RC_RES_BITS_10B 10
41 #define CRSF_SUBSET_RC_RES_MASK_10B 0x03FF
42 #define CRSF_SUBSET_RC_CHANNEL_SCALE_10B 1.0f
43 #define CRSF_SUBSET_RC_RES_CONF_11B 1
44 #define CRSF_SUBSET_RC_RES_BITS_11B 11
45 #define CRSF_SUBSET_RC_RES_MASK_11B 0x07FF
46 #define CRSF_SUBSET_RC_CHANNEL_SCALE_11B 0.5f
47 #define CRSF_SUBSET_RC_RES_CONF_12B 2
48 #define CRSF_SUBSET_RC_RES_BITS_12B 12
49 #define CRSF_SUBSET_RC_RES_MASK_12B 0x0FFF
50 #define CRSF_SUBSET_RC_CHANNEL_SCALE_12B 0.25f
51 #define CRSF_SUBSET_RC_RES_CONF_13B 3
52 #define CRSF_SUBSET_RC_RES_BITS_13B 13
53 #define CRSF_SUBSET_RC_RES_MASK_13B 0x1FFF
54 #define CRSF_SUBSET_RC_CHANNEL_SCALE_13B 0.125f
56 #define CRSF_RSSI_MIN (-130)
57 #define CRSF_RSSI_MAX 0
58 #define CRSF_SNR_MIN (-30)
59 #define CRSF_SNR_MAX 20
61 /* For documentation purposes
62 typedef enum {
63 CRSF_RF_MODE_4_FPS = 0,
64 CRSF_RF_MODE_50_FPS,
65 CRSF_RF_MODE_150_FPS,
66 } crsfRfMode_e;
69 typedef struct crsfFrameDef_s {
70 uint8_t deviceAddress;
71 uint8_t frameLength;
72 uint8_t type;
73 uint8_t payload[CRSF_PAYLOAD_SIZE_MAX + 1]; // +1 for CRC at end of payload
74 } crsfFrameDef_t;
76 typedef union crsfFrame_u {
77 uint8_t bytes[CRSF_FRAME_SIZE_MAX];
78 crsfFrameDef_t frame;
79 } crsfFrame_t;
81 void crsfRxWriteTelemetryData(const void *data, int len);
82 void crsfRxSendTelemetryData(void);
83 bool crsfRxIsTelemetryBufEmpty(void); // check this function before using crsfRxWriteTelemetryData()
85 struct rxConfig_s;
86 struct rxRuntimeState_s;
87 bool crsfRxInit(const struct rxConfig_s *initialRxConfig, struct rxRuntimeState_s *rxRuntimeState);
88 void crsfRxUpdateBaudrate(uint32_t baudrate);
89 bool crsfRxUseNegotiatedBaud(void);
90 bool crsfRxIsActive(void);