firmware
boards
airbourne
airbourne
include
rc_sbus.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2017, James Jackson
3
*
4
* All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions are met:
8
*
9
* * Redistributions of source code must retain the above copyright notice, this
10
* list of conditions and the following disclaimer.
11
*
12
* * Redistributions in binary form must reproduce the above copyright notice,
13
* this list of conditions and the following disclaimer in the documentation
14
* and/or other materials provided with the distribution.
15
*
16
* * Neither the name of the copyright holder nor the names of its
17
* contributors may be used to endorse or promote products derived from
18
* this software without specific prior written permission.
19
*
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
*/
31
32
#ifndef RC_SBUS_H
33
#define RC_SBUS_H
34
35
#include "
gpio.h
"
36
#include "
rc_base.h
"
37
#include "
system.h
"
38
#include "
uart.h
"
39
40
class
RC_SBUS
:
public
RC_BASE
41
{
42
private
:
43
enum
44
{
45
START_BYTE
= 0x0F,
46
END_BYTE
= 0x00
47
};
48
49
typedef
enum
50
{
51
SBUS_SIGNAL_OK
,
52
SBUS_SIGNAL_LOST
,
53
SBUS_SIGNAL_FAILSAFE
54
}
failsafe_state_t
;
55
56
struct
dataFrame_s
57
{
58
uint8_t
startByte
;
59
unsigned
int
chan0
: 11;
60
unsigned
int
chan1
: 11;
61
unsigned
int
chan2
: 11;
62
unsigned
int
chan3
: 11;
63
unsigned
int
chan4
: 11;
64
unsigned
int
chan5
: 11;
65
unsigned
int
chan6
: 11;
66
unsigned
int
chan7
: 11;
67
unsigned
int
chan8
: 11;
68
unsigned
int
chan9
: 11;
69
unsigned
int
chan10
: 11;
70
unsigned
int
chan11
: 11;
71
unsigned
int
chan12
: 11;
72
unsigned
int
chan13
: 11;
73
unsigned
int
chan14
: 11;
74
unsigned
int
chan15
: 11;
75
uint8_t
digichannels
;
76
uint8_t
endByte
;
77
}
__attribute__
((__packed__));
78
79
typedef
union
80
{
81
uint8_t data[25];
82
struct
dataFrame_s
frame;
83
}
SBUS_t
;
84
85
SBUS_t
sbus_union_
;
86
87
failsafe_state_t
failsafe_status_
;
88
89
GPIO
*
inv_pin_
;
90
UART
*
uart_
;
91
uint32_t
raw_
[18];
92
uint32_t
frame_start_ms_
= 0;
93
uint8_t
buffer_
[25];
94
uint8_t
buffer_pos_
= 0;
95
uint32_t
errors_
= 0;
96
uint8_t
prev_byte_
= 0;
97
bool
frame_started_
=
false
;
98
99
void
decode_buffer
();
100
101
public
:
102
void
init
(
GPIO
* inv_pin,
UART
* uart);
103
void
read_cb
(uint8_t byte);
104
float
read
(uint8_t channel);
105
bool
lost
();
106
inline
uint32_t
get_errors
() {
return
errors_
; }
107
};
108
109
#endif // RC_SBUS_H
RC_SBUS::__attribute__
typedef __attribute__
uart.h
RC_SBUS::dataFrame_s::chan2
unsigned int chan2
Definition:
rc_sbus.h:61
RC_SBUS::SBUS_SIGNAL_FAILSAFE
Definition:
rc_sbus.h:53
RC_SBUS::dataFrame_s::endByte
uint8_t endByte
Definition:
rc_sbus.h:76
RC_SBUS::inv_pin_
GPIO * inv_pin_
Definition:
rc_sbus.h:89
gpio.h
RC_SBUS::dataFrame_s::chan12
unsigned int chan12
Definition:
rc_sbus.h:71
RC_SBUS::lost
bool lost()
Definition:
rc_sbus.cpp:62
RC_SBUS::SBUS_SIGNAL_LOST
Definition:
rc_sbus.h:52
RC_SBUS::decode_buffer
void decode_buffer()
Definition:
rc_sbus.cpp:67
RC_SBUS::dataFrame_s::chan7
unsigned int chan7
Definition:
rc_sbus.h:66
rc_base.h
RC_SBUS::dataFrame_s::chan5
unsigned int chan5
Definition:
rc_sbus.h:64
RC_SBUS::dataFrame_s::chan0
unsigned int chan0
Definition:
rc_sbus.h:59
RC_SBUS::dataFrame_s::chan11
unsigned int chan11
Definition:
rc_sbus.h:70
RC_SBUS::frame_start_ms_
uint32_t frame_start_ms_
Definition:
rc_sbus.h:92
RC_SBUS
Definition:
rc_sbus.h:40
RC_SBUS::dataFrame_s::startByte
uint8_t startByte
Definition:
rc_sbus.h:58
RC_SBUS::get_errors
uint32_t get_errors()
Definition:
rc_sbus.h:106
RC_SBUS::errors_
uint32_t errors_
Definition:
rc_sbus.h:95
RC_SBUS::prev_byte_
uint8_t prev_byte_
Definition:
rc_sbus.h:96
RC_SBUS::dataFrame_s::chan3
unsigned int chan3
Definition:
rc_sbus.h:62
RC_SBUS::dataFrame_s::chan14
unsigned int chan14
Definition:
rc_sbus.h:73
RC_SBUS::read_cb
void read_cb(uint8_t byte)
Definition:
rc_sbus.cpp:109
RC_SBUS::dataFrame_s::chan1
unsigned int chan1
Definition:
rc_sbus.h:60
RC_SBUS::failsafe_status_
failsafe_state_t failsafe_status_
Definition:
rc_sbus.h:87
UART
Definition:
uart.h:42
RC_BASE
Definition:
rc_base.h:38
RC_SBUS::uart_
UART * uart_
Definition:
rc_sbus.h:90
RC_SBUS::SBUS_SIGNAL_OK
Definition:
rc_sbus.h:51
RC_SBUS::sbus_union_
SBUS_t sbus_union_
Definition:
rc_sbus.h:85
RC_SBUS::SBUS_t
Definition:
rc_sbus.h:79
GPIO
Definition:
gpio.h:37
system.h
RC_SBUS::raw_
uint32_t raw_[18]
Definition:
rc_sbus.h:91
RC_SBUS::failsafe_state_t
failsafe_state_t
Definition:
rc_sbus.h:49
RC_SBUS::dataFrame_s::chan4
unsigned int chan4
Definition:
rc_sbus.h:63
RC_SBUS::dataFrame_s
Definition:
rc_sbus.h:56
RC_SBUS::dataFrame_s::chan8
unsigned int chan8
Definition:
rc_sbus.h:67
RC_SBUS::init
void init(GPIO *inv_pin, UART *uart)
Definition:
rc_sbus.cpp:42
RC_SBUS::dataFrame_s::chan15
unsigned int chan15
Definition:
rc_sbus.h:74
RC_SBUS::END_BYTE
Definition:
rc_sbus.h:46
RC_SBUS::frame_started_
bool frame_started_
Definition:
rc_sbus.h:97
RC_SBUS::dataFrame_s::chan13
unsigned int chan13
Definition:
rc_sbus.h:72
RC_SBUS::buffer_pos_
uint8_t buffer_pos_
Definition:
rc_sbus.h:94
RC_SBUS::dataFrame_s::digichannels
uint8_t digichannels
Definition:
rc_sbus.h:75
RC_SBUS::dataFrame_s::chan6
unsigned int chan6
Definition:
rc_sbus.h:65
RC_SBUS::read
float read(uint8_t channel)
Definition:
rc_sbus.cpp:57
RC_SBUS::START_BYTE
Definition:
rc_sbus.h:45
RC_SBUS::dataFrame_s::chan9
unsigned int chan9
Definition:
rc_sbus.h:68
RC_SBUS::buffer_
uint8_t buffer_[25]
Definition:
rc_sbus.h:93
RC_SBUS::dataFrame_s::chan10
unsigned int chan10
Definition:
rc_sbus.h:69
rosflight_firmware
Author(s): Daniel Koch
, James Jackson
autogenerated on Mon Feb 28 2022 23:36:09