Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
sbus_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Alexandre Bustico, Gautier Hattenberger
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
27 #ifndef RC_SBUS_COMMON_H
28 #define RC_SBUS_COMMON_H
29 
30 #include "std.h"
31 #include "mcu_periph/uart.h"
32 #include "mcu_periph/gpio.h"
33 
34 /* in case you want to override RADIO_CONTROL_NB_CHANNEL */
35 #include "generated/airframe.h"
36 
43 #define RC_PPM_TICKS_OF_USEC(_v) ((((_v) - 880) * 8) / 5)
44 #define RC_PPM_SIGNED_TICKS_OF_USEC(_v) (((_v) * 8) / 5)
45 #define USEC_OF_RC_PPM_TICKS(_v) ((((_v) * 5) / 8) + 880)
46 
51 #include "generated/radio.h"
52 
62 #define SBUS_BUF_LENGTH 24
63 #define SBUS_NB_CHANNEL 16
64 
68 #ifndef RADIO_CONTROL_NB_CHANNEL
69 #define RADIO_CONTROL_NB_CHANNEL SBUS_NB_CHANNEL
70 #endif
71 
72 #if RADIO_CONTROL_NB_CHANNEL > SBUS_NB_CHANNEL
73 #error "RADIO_CONTROL_NB_CHANNEL mustn't be higher than 16."
74 #endif
75 
79 struct Sbus {
83  bool rc_failsafe;
84  bool rc_lost;
89 };
90 
94 void sbus_common_init(struct Sbus *sbus, struct uart_periph *dev,
95  gpio_port_t gpio_polarity_port, uint16_t gpio_polarity_pin);
96 
100 void sbus_common_decode_event(struct Sbus *sbus, struct uart_periph *dev);
101 
102 
106 extern void radio_control_impl_event(void (* _received_frame_handler)(void));
107 
111 #define RadioControlEvent(_received_frame_handler) radio_control_impl_event(_received_frame_handler)
112 
113 
114 #endif /* RC_SBUS_H */
uint16_t
unsigned short uint16_t
Definition: types.h:16
Sbus::buffer
uint8_t buffer[SBUS_BUF_LENGTH]
Input buffer.
Definition: sbus_common.h:85
Sbus::start_time
uint32_t start_time
Decoder start time.
Definition: sbus_common.h:88
uint32_t
unsigned long uint32_t
Definition: types.h:18
Sbus::status
uint8_t status
Decoder state-machine status.
Definition: sbus_common.h:87
Sbus::pulses
uint16_t pulses[SBUS_NB_CHANNEL]
Decoded values.
Definition: sbus_common.h:80
std.h
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
SBUS_NB_CHANNEL
#define SBUS_NB_CHANNEL
Definition: sbus_common.h:63
dev
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
uint8_t
unsigned char uint8_t
Definition: types.h:14
sbus_common_decode_event
void sbus_common_decode_event(struct Sbus *sbus, struct uart_periph *dev)
Decoding event function.
Definition: sbus_common.c:135
sbus_common_init
void sbus_common_init(struct Sbus *sbus, struct uart_periph *dev, gpio_port_t gpio_polarity_port, uint16_t gpio_polarity_pin)
Init function.
Definition: sbus_common.c:70
Sbus::rc_failsafe
bool rc_failsafe
Receiver set to in failsafe mode.
Definition: sbus_common.h:83
sbus
struct Sbus sbus
SBUS struct.
Definition: sbus.c:39
gpio.h
uart_periph
UART peripheral.
Definition: uart.h:70
SBUS_BUF_LENGTH
#define SBUS_BUF_LENGTH
Generated code holding the description of a given transmitter.
Definition: sbus_common.h:62
Sbus::idx
uint8_t idx
Input index.
Definition: sbus_common.h:86
Sbus::rc_lost
bool rc_lost
RC reception is lost.
Definition: sbus_common.h:84
Sbus::ppm
uint16_t ppm[SBUS_NB_CHANNEL]
Decoded and converted to ppm values.
Definition: sbus_common.h:81
Sbus
SBUS structure.
Definition: sbus_common.h:79
gpio_port_t
ioportid_t gpio_port_t
Abstract gpio port type for hardware independent part.
Definition: gpio_arch.h:39
radio_control_impl_event
void radio_control_impl_event(void(*_received_frame_handler)(void))
RC event function with handler callback.
Definition: cc2500_paparazzi.c:61
Sbus::frame_available
bool frame_available
A data frame is available.
Definition: sbus_common.h:82