Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
33 /* in case you want to override RADIO_CONTROL_NB_CHANNEL */
34 #include "generated/airframe.h"
35 
42 #define RC_PPM_TICKS_OF_USEC(_v) ((((_v) - 880) * 8) / 5)
43 #define RC_PPM_SIGNED_TICKS_OF_USEC(_v) (((_v) * 8) / 5)
44 #define USEC_OF_RC_PPM_TICKS(_v) ((((_v) * 5) / 8) + 880)
45 
50 #include "generated/radio.h"
51 
61 #define SBUS_BUF_LENGTH 24
62 #define SBUS_NB_CHANNEL 16
63 
67 #ifndef RADIO_CONTROL_NB_CHANNEL
68 #define RADIO_CONTROL_NB_CHANNEL SBUS_NB_CHANNEL
69 #endif
70 
71 #if RADIO_CONTROL_NB_CHANNEL > SBUS_NB_CHANNEL
72 #error "RADIO_CONTROL_NB_CHANNEL mustn't be higher than 16."
73 #endif
74 
78 struct Sbus {
85 };
86 
90 void sbus_common_init(struct Sbus *sbus, struct uart_periph *dev);
91 
95 void sbus_common_decode_event(struct Sbus *sbus, struct uart_periph *dev);
96 
97 
101 extern void radio_control_impl_event(void (* _received_frame_handler)(void));
102 
106 #define RadioControlEvent(_received_frame_handler) radio_control_impl_event(_received_frame_handler)
107 
108 
109 #endif /* RC_SBUS_H */
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint16_t pulses[SBUS_NB_CHANNEL]
decoded values
Definition: sbus_common.h:79
uint8_t status
decoder state machine status
Definition: sbus_common.h:84
uint8_t idx
input index
Definition: sbus_common.h:83
struct Sbus sbus
SBUS struct.
Definition: sbus.c:33
UART peripheral.
Definition: uart.h:70
#define SBUS_BUF_LENGTH
Generated code holding the description of a given transmitter.
Definition: sbus_common.h:61
void sbus_common_init(struct Sbus *sbus, struct uart_periph *dev)
Init function.
Definition: sbus_common.c:57
void radio_control_impl_event(void(*_received_frame_handler)(void))
RC event function with handler callback.
Definition: ppm.c:80
uint16_t ppm[SBUS_NB_CHANNEL]
decoded and converted values
Definition: sbus_common.h:80
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
unsigned char uint8_t
Definition: types.h:14
uint8_t buffer[SBUS_BUF_LENGTH]
input buffer
Definition: sbus_common.h:82
void sbus_common_decode_event(struct Sbus *sbus, struct uart_periph *dev)
Decoding event function.
Definition: sbus_common.c:115
bool frame_available
new frame available
Definition: sbus_common.h:81
#define SBUS_NB_CHANNEL
Definition: sbus_common.h:62
SBUS structure.
Definition: sbus_common.h:78