vtx: fix VTX_SETTINGS_POWER_COUNT and add dummy entries to saPowerNames
[inav.git] / src / main / rx / crsf.h
blob69777a0390c298f9f902498ea6a4c6ae0d4da201
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #pragma once
20 #define CRSF_BAUDRATE 420000
21 #define CRSF_PORT_OPTIONS (SERIAL_STOPBITS_1 | SERIAL_PARITY_NO)
22 #define CRSF_PORT_MODE MODE_RXTX
24 #define CRSF_MAX_CHANNEL 17
26 enum { CRSF_SYNC_BYTE = 0xC8 };
28 enum { CRSF_FRAME_SIZE_MAX = 64 }; // 62 bytes frame plus 2 bytes frame header(<length><type>)
29 enum { CRSF_PAYLOAD_SIZE_MAX = CRSF_FRAME_SIZE_MAX - 6 };
31 enum {
32 CRSF_DISPLAYPORT_SUBCMD_UPDATE = 0x01, // transmit displayport buffer to remote
33 CRSF_DISPLAYPORT_SUBCMD_CLEAR = 0X02, // clear client screen
34 CRSF_DISPLAYPORT_SUBCMD_OPEN = 0x03, // client request to open cms menu
35 CRSF_DISPLAYPORT_SUBCMD_CLOSE = 0x04, // client request to close cms menu
36 CRSF_DISPLAYPORT_SUBCMD_POLL = 0x05, // client request to poll/refresh cms menu
39 enum {
40 CRSF_DISPLAYPORT_OPEN_ROWS_OFFSET = 1,
41 CRSF_DISPLAYPORT_OPEN_COLS_OFFSET = 2,
44 enum {
45 CRSF_FRAME_GPS_PAYLOAD_SIZE = 15,
46 CRSF_FRAME_VARIO_SENSOR_PAYLOAD_SIZE = 2,
47 CRSF_FRAME_BATTERY_SENSOR_PAYLOAD_SIZE = 8,
48 CRSF_FRAME_LINK_STATISTICS_PAYLOAD_SIZE = 10,
49 CRSF_FRAME_RC_CHANNELS_PAYLOAD_SIZE = 22, // 11 bits per channel * 16 channels = 22 bytes.
50 CRSF_FRAME_ATTITUDE_PAYLOAD_SIZE = 6,
51 CRSF_FRAME_LENGTH_ADDRESS = 1, // length of ADDRESS field
52 CRSF_FRAME_LENGTH_FRAMELENGTH = 1, // length of FRAMELENGTH field
53 CRSF_FRAME_LENGTH_TYPE = 1, // length of TYPE field
54 CRSF_FRAME_LENGTH_CRC = 1, // length of CRC field
55 CRSF_FRAME_LENGTH_TYPE_CRC = 2, // length of TYPE and CRC fields combined
56 CRSF_FRAME_LENGTH_EXT_TYPE_CRC = 4, // length of Extended Dest/Origin, TYPE and CRC fields combined
57 CRSF_FRAME_LENGTH_NON_PAYLOAD = 4, // combined length of all fields except payload
60 enum {
61 CRSF_FRAME_TX_MSP_FRAME_SIZE = 58,
62 CRSF_FRAME_RX_MSP_FRAME_SIZE = 8,
63 CRSF_FRAME_ORIGIN_DEST_SIZE = 2,
66 // Clashes with CRSF_ADDRESS_FLIGHT_CONTROLLER
67 #define CRSF_TELEMETRY_SYNC_BYTE 0XC8
69 typedef enum {
70 CRSF_ADDRESS_BROADCAST = 0x00,
71 CRSF_ADDRESS_USB = 0x10,
72 CRSF_ADDRESS_TBS_CORE_PNP_PRO = 0x80,
73 CRSF_ADDRESS_RESERVED1 = 0x8A,
74 CRSF_ADDRESS_CURRENT_SENSOR = 0xC0,
75 CRSF_ADDRESS_GPS = 0xC2,
76 CRSF_ADDRESS_TBS_BLACKBOX = 0xC4,
77 CRSF_ADDRESS_FLIGHT_CONTROLLER = 0xC8,
78 CRSF_ADDRESS_RESERVED2 = 0xCA,
79 CRSF_ADDRESS_RACE_TAG = 0xCC,
80 CRSF_ADDRESS_RADIO_TRANSMITTER = 0xEA,
81 CRSF_ADDRESS_CRSF_RECEIVER = 0xEC,
82 CRSF_ADDRESS_CRSF_TRANSMITTER = 0xEE
83 } crsfAddress_e;
85 typedef enum {
86 CRSF_FRAMETYPE_GPS = 0x02,
87 CRSF_FRAMETYPE_VARIO_SENSOR = 0x07,
88 CRSF_FRAMETYPE_BATTERY_SENSOR = 0x08,
89 CRSF_FRAMETYPE_LINK_STATISTICS = 0x14,
90 CRSF_FRAMETYPE_RC_CHANNELS_PACKED = 0x16,
91 CRSF_FRAMETYPE_ATTITUDE = 0x1E,
92 CRSF_FRAMETYPE_FLIGHT_MODE = 0x21,
93 // Extended Header Frames, range: 0x28 to 0x96
94 CRSF_FRAMETYPE_DEVICE_PING = 0x28,
95 CRSF_FRAMETYPE_DEVICE_INFO = 0x29,
96 CRSF_FRAMETYPE_PARAMETER_SETTINGS_ENTRY = 0x2B,
97 CRSF_FRAMETYPE_PARAMETER_READ = 0x2C,
98 CRSF_FRAMETYPE_PARAMETER_WRITE = 0x2D,
99 CRSF_FRAMETYPE_COMMAND = 0x32,
100 // MSP commands
101 CRSF_FRAMETYPE_MSP_REQ = 0x7A, // response request using msp sequence as command
102 CRSF_FRAMETYPE_MSP_RESP = 0x7B, // reply with 58 byte chunked binary
103 CRSF_FRAMETYPE_MSP_WRITE = 0x7C, // write with 8 byte chunked binary (OpenTX outbound telemetry buffer limit)
104 CRSF_FRAMETYPE_DISPLAYPORT_CMD = 0x7D, // displayport control command
105 } crsfFrameType_e;
107 enum {
108 CRSF_COMMAND_SUBCMD_RX = 0x10, // receiver command
109 CRSF_COMMAND_SUBCMD_GENERAL = 0x0A, // general command
112 enum {
113 CRSF_COMMAND_SUBCMD_RX_BIND = 0x01, // bind command
116 typedef struct crsfFrameDef_s {
117 uint8_t deviceAddress;
118 uint8_t frameLength;
119 uint8_t type;
120 uint8_t payload[CRSF_PAYLOAD_SIZE_MAX + 1]; // +1 for CRC at end of payload
121 } crsfFrameDef_t;
123 typedef union crsfFrame_u {
124 uint8_t bytes[CRSF_FRAME_SIZE_MAX];
125 crsfFrameDef_t frame;
126 } crsfFrame_t;
129 void crsfRxWriteTelemetryData(const void *data, int len);
130 void crsfRxSendTelemetryData(void);
132 struct rxConfig_s;
133 struct rxRuntimeConfig_s;
134 bool crsfRxInit(const struct rxConfig_s *initialRxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig);
135 bool crsfRxIsActive(void);
137 void crsfBind(void);