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/>.
23 #define SBUS_MAX_CHANNEL 18
25 #define SBUS_FLAG_CHANNEL_17 (1 << 0)
26 #define SBUS_FLAG_CHANNEL_18 (1 << 1)
27 #define SBUS_FLAG_SIGNAL_LOSS (1 << 2)
28 #define SBUS_FLAG_FAILSAFE_ACTIVE (1 << 3)
30 #define SBUS_CHANNEL_DATA_LENGTH sizeof(sbusChannels_t)
31 #define SBUS_FRAME_SIZE (SBUS_CHANNEL_DATA_LENGTH + 2)
33 #define SBUS_FRAME_BEGIN_BYTE 0x0F
35 #define SBUS_BAUDRATE 100000
36 #define SBUS_BAUDRATE_FAST 200000
38 #if !defined(SBUS_PORT_OPTIONS)
39 #define SBUS_PORT_OPTIONS (SERIAL_STOPBITS_2 | SERIAL_PARITY_EVEN)
42 typedef struct sbusChannels_s
{
43 // 176 bits of data (11 bits per channel * 16 channels) = 22 bytes.
44 unsigned int chan0
: 11;
45 unsigned int chan1
: 11;
46 unsigned int chan2
: 11;
47 unsigned int chan3
: 11;
48 unsigned int chan4
: 11;
49 unsigned int chan5
: 11;
50 unsigned int chan6
: 11;
51 unsigned int chan7
: 11;
52 unsigned int chan8
: 11;
53 unsigned int chan9
: 11;
54 unsigned int chan10
: 11;
55 unsigned int chan11
: 11;
56 unsigned int chan12
: 11;
57 unsigned int chan13
: 11;
58 unsigned int chan14
: 11;
59 unsigned int chan15
: 11;
61 } __attribute__((__packed__
)) sbusChannels_t
;
63 typedef struct sbusFrame_s
{
65 sbusChannels_t channels
;
67 * The endByte is 0x00 on FrSky and some futaba RX's, on Some SBUS2 RX's the value indicates the telemetry byte that is sent after every 4th sbus frame.
69 * See https://github.com/cleanflight/cleanflight/issues/590#issuecomment-101027349
71 * https://github.com/cleanflight/cleanflight/issues/590#issuecomment-101706023
74 } __attribute__ ((__packed__
)) sbusFrame_t
;
77 uint16_t sbusDecodeChannelValue(uint16_t sbusValue
, bool safeValuesOnly
);
78 uint16_t sbusEncodeChannelValue(uint16_t rcValue
);
80 uint8_t sbusChannelsDecode(rxRuntimeConfig_t
*rxRuntimeConfig
, const sbusChannels_t
*channels
);
82 void sbusChannelsInit(rxRuntimeConfig_t
*rxRuntimeConfig
);