Plugin some of the telemetry functions.
[inav.git] / src / main / telemetry / sbus2.h
blobdce16c48441bc4098bca7355f41002fb7235b0b2
1 /*
2 * This file is part of INAV.
4 * INAV 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 * INAV 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 INAV. If not, see <http://www.gnu.org/licenses/>.
19 #pragma once
21 #include <stdint.h>
23 #include "platform.h"
25 #define SBUS2_TELEMETRY_PAYLOAD_SIZE 3
27 #define SBUS2_TELEMETRY_ITEM_SIZE 3
28 #define SBUS2_TELEMETRY_SLOTS 8
29 #define SBUS2_TELEMETRY_PAGES 4
30 #define SBUS2_SLOT_COUNT (SBUS2_TELEMETRY_PAGES * SBUS2_TELEMETRY_SLOTS)
32 #if defined(USE_TELEMETRY) && defined(USE_SBUS2_TELEMETRY)
34 // Information on SBUS2 sensors from: https://github.com/BrushlessPower/SBUS2-Telemetry/tree/master
35 // Temperature:
36 // Max 125C
37 // value | 0x4000
38 typedef struct sbus2_telemetry_temp_payload_s {
39 uint8_t tempHigh; // temp | 0x4000; // 125c
40 uint8_t tempLow;
41 } __attribute__((packed)) sbsu2_telemetry_temp_payload_t;
43 // Temperature:
44 // Max 200C
45 // temp | 0x8000
46 typedef struct sbus2_telemetry_temp200_payload_s {
47 uint8_t tempLow; // temp | 0x8000; // 200c
48 uint8_t tempHigh;
49 } __attribute__((packed)) sbsu2_telemetry_temp200_payload_t;
51 // RPM:
52 // (RPM / 6) max: 0xFFFF
53 typedef struct sbus2_telemetry_rpm_payload_s {
54 uint8_t rpmHigh; // RPM / 6, capped at 0xFFFF
55 uint8_t rpmLow;
56 } __attribute__((packed)) sbsu2_telemetry_rpm_payload_t;
58 // Voltage: 1 or 2 slots
59 // 0x8000 = rx voltage?
60 // max input: 0x1FFF
61 typedef struct sbus2_telemetry_voltage_payload_s {
62 uint8_t voltageHigh; // 2 slots // Voltage 1: value | 0x8000
63 uint8_t voltageLow; // max input value: 0x1FFF
64 } __attribute__((packed)) sbsu2_telemetry_voltage_payload_t;
66 // Current
67 // 3 frames
68 // 1: current
69 // Max input: 0x3FFF
70 // input |= 0x4000
71 // input &= 0x7FFF
72 // 2: voltage
73 // same as voltage frame. may not need ot be capped.
74 // 3: Capacity
75 typedef struct sbus2_telemetry_current_payload_s {
76 uint8_t currentHigh;
77 uint8_t currentLow;
78 } __attribute__((packed)) sbsu2_telemetry_current_payload_t;
80 typedef struct sbus2_telemetry_capacity_payload_s {
81 uint8_t capacityHigh;
82 uint8_t capacityLow;
83 } __attribute__((packed)) sbsu2_telemetry_capacity_payload_t;
85 // GPS
86 // frames:
87 // 1: Speed
88 // 2: Altitude
89 // 3: Vario
90 // 4,5: LAT
91 // 5,6: LON
93 typedef struct sbus2_telemetry_frame_s {
94 uint8_t slotId;
95 union
97 uint8_t data[2];
98 sbsu2_telemetry_temp_payload_t temp125;
99 sbsu2_telemetry_temp200_payload_t temp200;
100 sbsu2_telemetry_rpm_payload_t rpm;
101 sbsu2_telemetry_voltage_payload_t voltage;
102 sbsu2_telemetry_current_payload_t current;
103 sbsu2_telemetry_capacity_payload_t capacity;
104 } payload;
105 } __attribute__((packed)) sbus2_telemetry_frame_t;
107 extern const uint8_t Slot_ID[SBUS2_SLOT_COUNT];
108 extern sbus2_telemetry_frame_t sbusTelemetryData[SBUS2_TELEMETRY_PAGES][SBUS2_TELEMETRY_SLOTS];
109 extern uint8_t sbusTelemetryDataStatus[SBUS2_TELEMETRY_PAGES][SBUS2_TELEMETRY_SLOTS];
111 void handleSbus2Telemetry(timeUs_t currentTimeUs);
112 #endif