Create release.yml
[betaflight.git] / src / main / rx / ghst_protocol.h
blobe06e2b3f55dc40b14863f9d4ecccf52f4f2ab57e
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 <stdint.h>
24 #include <stdbool.h>
26 #define GHST_RX_BAUDRATE 420000
28 #define GHST_TX_BAUDRATE_FAST 400000
29 #define GHST_TX_BAUDRATE_SLOW 115200
30 #define GHST_BYTE_TIME_FAST_US ((1000000/GHST_TX_BAUDRATE_FAST)*10) // 10 bit words (8 data, 1 start, 1 stop)
31 #define GHST_BYTE_TIME_SLOW_US ((1000000/GHST_TX_BAUDRATE_SLOW)*10)
32 #define GHST_UART_WORDLENGTH UART_WORDLENGTH_8B
34 typedef enum {
35 GHST_ADDR_RADIO = 0x80,
36 GHST_ADDR_TX_MODULE_SYM = 0x81, // symmetrical, 400k pulses, 400k telemetry
37 GHST_ADDR_TX_MODULE_ASYM = 0x88, // asymmetrical, 400k pulses, 115k telemetry
38 GHST_ADDR_FC = 0x82,
39 GHST_ADDR_GOGGLES = 0x83,
40 GHST_ADDR_QUANTUM_TEE1 = 0x84, // phase 2
41 GHST_ADDR_QUANTUM_TEE2 = 0x85,
42 GHST_ADDR_QUANTUM_GW1 = 0x86,
43 GHST_ADDR_5G_CLK = 0x87, // phase 3
44 GHST_ADDR_RX = 0x89
45 } ghstAddr_e;
47 typedef enum {
48 // frame types 0x10 - 0x1f always include 4 primary channels, plus either 4 aux channels,
49 // or other type-specific data. Expect types 0x14-0x1f to be added in the future, and even though
50 // not explicitly supported, the 4 primary channels should always be extracted.
51 GHST_UL_RC_CHANS_HS4_FIRST = 0x10, // First frame type including 4 primary channels
52 GHST_UL_RC_CHANS_HS4_5TO8 = 0x10, // primary 4 channel, plus CH5-8
53 GHST_UL_RC_CHANS_HS4_9TO12 = 0x11, // primary 4 channel, plus CH9-12
54 GHST_UL_RC_CHANS_HS4_13TO16 = 0x12, // primary 4 channel, plus CH13-16
55 GHST_UL_RC_CHANS_HS4_RSSI = 0x13, // primary 4 channel, plus RSSI, LQ, RF Mode, and Tx Power
56 GHST_UL_RC_CHANS_HS4_LAST = 0x1f // Last frame type including 4 primary channels
57 } ghstUl_e;
59 #define GHST_UL_RC_CHANS_SIZE 12 // 1 (type) + 10 (data) + 1 (crc)
61 typedef enum {
62 GHST_DL_OPENTX_SYNC = 0x20,
63 GHST_DL_LINK_STAT = 0x21,
64 GHST_DL_VTX_STAT = 0x22,
65 GHST_DL_PACK_STAT = 0x23, // Battery (Pack) Status
66 GHST_DL_GPS_PRIMARY = 0x25, // Primary GPS data (position)
67 GHST_DL_GPS_SECONDARY = 0x26,
68 GHST_DL_MAGBARO = 0x27
69 } ghstDl_e;
71 #define GHST_RC_CTR_VAL_12BIT 0x7C0 // servo center for 12 bit values (0x3e0 << 1)
72 #define GHST_RC_CTR_VAL_8BIT 0x7C // servo center for 8 bit values
74 #define GHST_FRAME_SIZE 14 // including addr, type, len, crc, and payload
76 #define GHST_PAYLOAD_SIZE_MAX 14
78 #define GHST_FRAME_SIZE_MAX 24
80 #define GPS_FLAGS_FIX 0x01
81 #define GPS_FLAGS_FIX_HOME 0x02
83 #define MISC_FLAGS_MAGHEAD 0x01
84 #define MISC_FLAGS_BAROALT 0x02
85 #define MISC_FLAGS_VARIO 0x04
87 typedef struct ghstFrameDef_s {
88 uint8_t addr;
89 uint8_t len;
90 uint8_t type;
91 uint8_t payload[GHST_PAYLOAD_SIZE_MAX + 1]; // CRC adds 1
92 } ghstFrameDef_t;
94 typedef union ghstFrame_u {
95 uint8_t bytes[GHST_FRAME_SIZE];
96 ghstFrameDef_t frame;
97 } ghstFrame_t;
100 /* Pulses payload (channel data), for 4x 12-bit channels */
101 typedef struct ghstPayloadServo4_s {
102 // 48 bits, or 6 bytes
103 unsigned int ch1: 12;
104 unsigned int ch2: 12;
105 unsigned int ch3: 12;
106 unsigned int ch4: 12;
107 } __attribute__ ((__packed__)) ghstPayloadServo4_t;
109 /* Pulses payload (channel data). Includes 4x high speed control channels, plus 4 channels from CH5-CH12 */
110 typedef struct ghstPayloadPulses_s {
111 // 80 bits, or 10 bytes
112 ghstPayloadServo4_t ch1to4;
114 unsigned int cha: 8;
115 unsigned int chb: 8;
116 unsigned int chc: 8;
117 unsigned int chd: 8;
118 } __attribute__ ((__packed__)) ghstPayloadPulses_t;
120 /* Pulses payload (channel data), with RSSI/LQ, and other related data */
121 typedef struct ghstPayloadPulsesRssi_s {
122 // 80 bits, or 10 bytes
123 ghstPayloadServo4_t ch1to4;
125 unsigned int lq: 8; // 0-100
126 unsigned int rssi: 8; // 0 - 128 sign inverted, dBm
127 unsigned int rfProtocol: 8;
128 signed int txPwrdBm: 8; // tx power in dBm, use lookup table to map to published mW values
129 } __attribute__ ((__packed__)) ghstPayloadPulsesRssi_t;