Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sbus_dual.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Christophe De Wagter
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 
29 #include BOARD_CONFIG
30 #include "mcu_periph/uart.h"
31 #include <string.h>
32 
33 #ifndef RC_POLARITY_GPIO_PORT
34 #define RC_POLARITY_GPIO_PORT 0
35 #endif
36 #ifndef RC_POLARITY_GPIO_PIN
37 #define RC_POLARITY_GPIO_PIN 0
38 #endif
39 
40 #ifndef RC2_POLARITY_GPIO_PORT
41 #define RC2_POLARITY_GPIO_PORT RC_POLARITY_GPIO_PORT
42 #endif
43 #ifndef RC2_POLARITY_GPIO_PIN
44 #define RC2_POLARITY_GPIO_PIN RC_POLARITY_GPIO_PIN
45 #endif
46 
48 struct Sbus sbus1, sbus2;
49 
50 // Telemetry function
51 #if PERIODIC_TELEMETRY
53 
54 static void send_sbus(struct transport_tx *trans, struct link_device *dev)
55 {
56  // Using PPM message
57  pprz_msg_send_PPM(trans, dev, AC_ID,
59 }
60 #endif
61 
62 // Init function
64 {
67 
68  // Register telemetry message
69 #if PERIODIC_TELEMETRY
71 #endif
72 }
73 
74 static inline void sbus_dual_decode_event(void)
75 {
76  sbus_common_decode_event(&sbus1, &SBUS1_UART_DEV);
77  sbus_common_decode_event(&sbus2, &SBUS2_UART_DEV);
78 }
79 
80 void radio_control_impl_event(void (* _received_frame_handler)(void))
81 {
83  if (sbus2.frame_available) {
86  if (radio_control.radio_ok_cpt > 0) {
88  } else {
90  NormalizePpmIIR(sbus2.pulses, radio_control);
91  _received_frame_handler();
92  }
93  sbus2.frame_available = false;
94  }
95  if (sbus1.frame_available) {
98  if (radio_control.radio_ok_cpt > 0) {
100  } else {
102  NormalizePpmIIR(sbus1.pulses, radio_control);
103  _received_frame_handler();
104  }
105  sbus1.frame_available = false;
106  }
107 }
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void sbus_common_decode_event(struct Sbus *sbus_p, struct uart_periph *dev)
Decoding event function.
Definition: sbus_common.c:135
void radio_control_impl_event(void(*_received_frame_handler)(void))
RC event function with handler callback.
Definition: sbus_dual.c:80
Periodic telemetry system header (includes downlink utility and generated code).
uint8_t radio_ok_cpt
Definition: radio_control.h:66
uint8_t status
Definition: radio_control.h:64
uint16_t pulses[SBUS_NB_CHANNEL]
Decoded values.
Definition: sbus_common.h:80
void radio_control_impl_init(void)
Definition: sbus_dual.c:63
Radio control via two SBUS receivers.
#define RC2_POLARITY_GPIO_PORT
Definition: sbus_dual.c:41
#define RC_POLARITY_GPIO_PORT
Definition: sbus_dual.c:34
void sbus_common_init(struct Sbus *sbus_p, struct uart_periph *dev, gpio_port_t gpio_polarity_port, uint16_t gpio_polarity_pin)
Init function.
Definition: sbus_common.c:70
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
struct RadioControl radio_control
Definition: radio_control.c:30
struct Sbus sbus1 sbus2
SBUS struct.
Definition: sbus_dual.c:48
#define RC_OK
Definition: radio_control.h:56
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
#define RC_POLARITY_GPIO_PIN
Definition: sbus_dual.c:37
static void send_sbus(struct transport_tx *trans, struct link_device *dev)
Definition: sbus_dual.c:54
uint8_t time_since_last_frame
Definition: radio_control.h:65
bool frame_available
A data frame is available.
Definition: sbus_common.h:82
#define SBUS_NB_CHANNEL
Definition: sbus_common.h:63
SBUS structure.
Definition: sbus_common.h:79
static void sbus_dual_decode_event(void)
Definition: sbus_dual.c:74
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
uint8_t frame_cpt
Definition: radio_control.h:68
uint8_t frame_rate
Definition: radio_control.h:67
#define RC2_POLARITY_GPIO_PIN
Definition: sbus_dual.c:44