dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_crossfire.h
Go to the documentation of this file.
1 
11 /*
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20  * for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, see <http://www.gnu.org/licenses/>
24  *
25  * Additional note on redistribution: The copyright and license notices above
26  * must be maintained in each individual source file that is a derivative work
27  * of this source file; otherwise redistribution is prohibited.
28  */
29 
30 #include "pios.h"
31 
32 #ifndef PIOS_CROSSFIRE_H
33 #define PIOS_CROSSFIRE_H
34 
35 #include "pios_rcvr.h"
36 
37 // There's 16 channels in the RC channel payload, the Crossfire currently
38 // only uses 12. Asked Perna a while ago to always send RSSI and LQ on
39 // 15 and 16, said was nice idea, but never showed up in change logs.
40 #define PIOS_CROSSFIRE_CHANNELS 16
41 
42 // Lengths of the type and CRC fields.
43 #define CRSF_ADDRESS_LEN 1
44 #define CRSF_LENGTH_LEN 1
45 #define CRSF_CRC_LEN 1
46 #define CRSF_TYPE_LEN 1
47 
48 // Maximum payload in the protocol can be 32 bytes.
49 // Should figure out whether that includes type and CRC, or not.
50 #define CRSF_MAX_PAYLOAD 32
51 
52 // Frame types.
53 #define CRSF_FRAME_GPS 0x02
54 #define CRSF_FRAME_BATTERY 0x08
55 #define CRSF_FRAME_RCCHANNELS 0x16
56 #define CRSF_FRAME_ATTITUDE 0x1e
57 
58 // Payload sizes
59 #define CRSF_PAYLOAD_GPS 15
60 #define CRSF_PAYLOAD_BATTERY 8
61 #define CRSF_PAYLOAD_RCCHANNELS 22
62 #define CRSF_PAYLOAD_ATTITUDE 6
63 // Maximum payload in the protocol can be 32 bytes.
64 // Should figure out whether that includes type and CRC, or not.
65 #define CRSF_MAX_PAYLOAD 32
66 
67 
68 #define CRSF_TIMING_MAXFRAME 1000
69 #define CRSF_TIMING_FRAMEDISTANCE 4000
70 
71 // We don't need those. Yet. More like a reference right now.
73 
74  int32_t latitude, longitude;
75  uint16_t groundspeed;
76  uint16_t heading;
77  uint16_t altitude;
78  uint8_t num_satellites;
79 
80 } __attribute__((packed));
81 
83 
84  uint16_t voltage;
85  uint16_t current;
86  uint8_t capacity[3];
87  uint8_t batt_remaining;
88 
89 } __attribute__((packed));
90 
92 
93  int16_t pitch;
94  int16_t roll;
95  int16_t yaw;
96 
97 } __attribute__((packed));
98 
104 };
105 
106 struct crsf_frame_t {
107  // Module address. Not sure what's the point, assuming provision for
108  // a bus type deal. Not used.
109  uint8_t dev_addr;
110 
111  // Length of the payload following this field. Length includes CRC and
112  // type field in addition to payload.
113  uint8_t length;
114 
115  // Frame type
116  uint8_t type;
117 
118  // The payload plus CRC appendix.
120 } __attribute__((packed));
121 
122 // Macro referring to the maximum frame size.
123 #define CRSF_MAX_FRAMELEN sizeof(struct crsf_frame_t)
124 
125 // Get formal payload length.
126 #define CRSF_PAYLOAD_LEN(x) (CRSF_TYPE_LEN+(x)+CRSF_CRC_LEN)
127 
128 extern const struct pios_rcvr_driver pios_crossfire_rcvr_driver;
129 
137 int PIOS_Crossfire_Init(uintptr_t *crsf_id, const struct pios_com_driver *driver,
138  uintptr_t uart_id);
139 
140 int PIOS_Crossfire_InitTelemetry(uintptr_t crsf_id);
141 
142 int PIOS_Crossfire_SendTelemetry(uintptr_t crsf_id, uint8_t *buf, uint8_t bytes);
143 
145 
146 #endif // PIOS_CROSSFIRE_H
147 
int PIOS_Crossfire_SendTelemetry(uintptr_t crsf_id, uint8_t *buf, uint8_t bytes)
Main PiOS header to include all the compiled in PiOS options.
uint8_t payload[CRSF_MAX_PAYLOAD+CRSF_CRC_LEN]
uint16_t groundspeed
#define CRSF_CRC_LEN
uint8_t bytes[2]
Definition: storm32bgc.c:156
uint8_t payload[CRSF_MAX_PAYLOAD+CRSF_CRC_LEN]
uint8_t num_satellites
int PIOS_Crossfire_InitTelemetry(uintptr_t crsf_id)
uint8_t dev_addr
#define CRSF_MAX_PAYLOAD
RCVR layer functions header.
int PIOS_Crossfire_Init(uintptr_t *crsf_id, const struct pios_com_driver *driver, uintptr_t uart_id)
Initialises the TBS Crossfire Rx driver with a serial port.
const struct pios_rcvr_driver pios_crossfire_rcvr_driver
struct crsf_payload_attitude attitude
struct crsf_payload_gps gps
union crsf_combo_payload __attribute__
bool PIOS_Crossfire_IsFailsafed()
struct crsf_payload_battery battery