mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-05 15:30:08 +08:00
@@ -23,10 +23,10 @@
|
|||||||
<define name="USE_GYRO_PITCH_RATE"/>
|
<define name="USE_GYRO_PITCH_RATE"/>
|
||||||
|
|
||||||
<target name="sim" board="pc"/>
|
<target name="sim" board="pc"/>
|
||||||
<target name="ap" board="apogee_0.99"/>
|
<target name="ap" board="apogee_1.0"/>
|
||||||
<configure name="FLASH_MODE" value="SWD"/>
|
<!--configure name="FLASH_MODE" value="SWD"/-->
|
||||||
|
|
||||||
<subsystem name="radio_control" type="ppm"/>
|
<subsystem name="radio_control" type="sbus"/>
|
||||||
|
|
||||||
<!-- Communication -->
|
<!-- Communication -->
|
||||||
<subsystem name="telemetry" type="transparent"/>
|
<subsystem name="telemetry" type="transparent"/>
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#
|
||||||
|
# Makefile for shared radio_control SBUS subsystem
|
||||||
|
#
|
||||||
|
|
||||||
|
$(TARGET).CFLAGS += -DRADIO_CONTROL
|
||||||
|
ifneq ($(RADIO_CONTROL_LED),none)
|
||||||
|
ap.CFLAGS += -DRADIO_CONTROL_LED=$(RADIO_CONTROL_LED)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# convert SBUS_PORT to upper and lower case strings:
|
||||||
|
SBUS_PORT_UPPER=$(shell echo $(SBUS_PORT) | tr a-z A-Z)
|
||||||
|
SBUS_PORT_LOWER=$(shell echo $(SBUS_PORT) | tr A-Z a-z)
|
||||||
|
|
||||||
|
$(TARGET).CFLAGS += -DUSE_$(SBUS_PORT_UPPER) -D$(SBUS_PORT_UPPER)_BAUD=B100000
|
||||||
|
$(TARGET).CFLAGS += -DSBUS_UART_DEV=$(SBUS_PORT_LOWER)
|
||||||
|
$(TARGET).CFLAGS += -DRADIO_CONTROL_TYPE_H=\"subsystems/radio_control/sbus.h\"
|
||||||
|
$(TARGET).CFLAGS += -DRADIO_CONTROL_TYPE_SBUS
|
||||||
|
$(TARGET).srcs += $(SRC_SUBSYSTEMS)/radio_control.c
|
||||||
|
$(TARGET).srcs += $(SRC_SUBSYSTEMS)/radio_control/sbus.c
|
||||||
|
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- $Id$
|
||||||
|
--
|
||||||
|
-- (c) 2013 Gautier Hattenberger
|
||||||
|
--
|
||||||
|
-- This file is part of paparazzi.
|
||||||
|
--
|
||||||
|
-- paparazzi is free software; you can redistribute it and/or modify
|
||||||
|
-- it under the terms of the GNU General Public License as published by
|
||||||
|
-- the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
-- any later version.
|
||||||
|
--
|
||||||
|
-- paparazzi is distributed in the hope that it will be useful,
|
||||||
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
-- GNU General Public License for more details.
|
||||||
|
--
|
||||||
|
-- You should have received a copy of the GNU General Public License
|
||||||
|
-- along with paparazzi; see the file COPYING. If not, write to
|
||||||
|
-- the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||||
|
-- Boston, MA 02111-1307, USA.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
-- Attributes of root (Radio) tag :
|
||||||
|
-- name: name of RC
|
||||||
|
-- data_min: min width of a pulse to be considered as a data pulse
|
||||||
|
-- data_max: max width of a pulse to be considered as a data pulse
|
||||||
|
-- sync_min: min width of a pulse to be considered as a synchro pulse
|
||||||
|
-- sync_max: max width of a pulse to be considered as a synchro pulse
|
||||||
|
-- pulse_type: POSITIVE ( Futaba and others) | NEGATIVE (JR)
|
||||||
|
-- min, max and sync are expressed in micro-seconds
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
-- Attributes of channel tag :
|
||||||
|
-- ctl: name of the command on the transmitter - only for displaying
|
||||||
|
-- function: logical command
|
||||||
|
-- average: (boolean) channel filtered through several frames (for discrete commands)
|
||||||
|
-- min: minimum pulse length (micro-seconds)
|
||||||
|
-- max: maximum pulse length (micro-seconds)
|
||||||
|
-- neutral: neutral pulse length (micro-seconds)
|
||||||
|
-- Note: a command may be reversed by exchanging min and max values
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!DOCTYPE radio SYSTEM "radio.dtd">
|
||||||
|
<radio name="Futaba T10CG with SBUS" data_min="900" data_max="2100" sync_min ="5000" sync_max ="15000" pulse_type="POSITIVE">
|
||||||
|
<channel ctl="A" function="ROLL" min="363" neutral="1024" max="1683" average="0"/>
|
||||||
|
<channel ctl="B" function="PITCH" min="363" neutral="1024" max="1683" average="0"/>
|
||||||
|
<channel ctl="C" function="THROTTLE" min="1683" neutral="1683" max="363" average="0"/>
|
||||||
|
<channel ctl="D" function="YAW" min="363" neutral="1024" max="1683" average="0"/>
|
||||||
|
<channel ctl="E" function="MODE" max="137" neutral="1024" min="1908" average="1"/>
|
||||||
|
<channel ctl="F" function="GAIN1" min="137" neutral="1024" max="1908" average="0"/>
|
||||||
|
<channel ctl="G" function="GAIN2" min="137" neutral="1024" max="1908" average="0"/>
|
||||||
|
</radio>
|
||||||
@@ -68,6 +68,10 @@ void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud) {
|
|||||||
uart_enable_interrupts(p);
|
uart_enable_interrupts(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uart_periph_set_bits_stop_parity(struct uart_periph* p, uint8_t __attribute__((unused)) bits, uint8_t __attribute__((unused)) stop, uint8_t __attribute__((unused)) parity) {
|
||||||
|
// TBD
|
||||||
|
}
|
||||||
|
|
||||||
void uart_transmit(struct uart_periph* p, uint8_t data ) {
|
void uart_transmit(struct uart_periph* p, uint8_t data ) {
|
||||||
uint16_t temp;
|
uint16_t temp;
|
||||||
unsigned cpsr;
|
unsigned cpsr;
|
||||||
|
|||||||
@@ -41,11 +41,8 @@
|
|||||||
|
|
||||||
void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud) {
|
void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud) {
|
||||||
|
|
||||||
/* Configure USART */
|
/* Configure USART baudrate */
|
||||||
usart_set_baudrate((uint32_t)p->reg_addr, baud);
|
usart_set_baudrate((uint32_t)p->reg_addr, baud);
|
||||||
usart_set_databits((uint32_t)p->reg_addr, 8);
|
|
||||||
usart_set_stopbits((uint32_t)p->reg_addr, USART_STOPBITS_1);
|
|
||||||
usart_set_parity((uint32_t)p->reg_addr, USART_PARITY_NONE);
|
|
||||||
|
|
||||||
/* Disable Idle Line interrupt */
|
/* Disable Idle Line interrupt */
|
||||||
USART_CR1((uint32_t)p->reg_addr) &= ~USART_CR1_IDLEIE;
|
USART_CR1((uint32_t)p->reg_addr) &= ~USART_CR1_IDLEIE;
|
||||||
@@ -61,6 +58,33 @@ void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uart_periph_set_bits_stop_parity(struct uart_periph* p, uint8_t bits, uint8_t stop, uint8_t parity) {
|
||||||
|
/* Configure USART parity and data bits */
|
||||||
|
if (parity == UPARITY_EVEN) {
|
||||||
|
usart_set_parity((uint32_t)p->reg_addr, USART_PARITY_EVEN);
|
||||||
|
if (bits == UBITS_7)
|
||||||
|
usart_set_databits((uint32_t)p->reg_addr, 8);
|
||||||
|
else // 8 data bits by default
|
||||||
|
usart_set_databits((uint32_t)p->reg_addr, 9);
|
||||||
|
}
|
||||||
|
else if (parity == USART_PARITY_ODD) {
|
||||||
|
usart_set_parity((uint32_t)p->reg_addr, USART_PARITY_ODD);
|
||||||
|
if (bits == UBITS_7)
|
||||||
|
usart_set_databits((uint32_t)p->reg_addr, 8);
|
||||||
|
else // 8 data bits by default
|
||||||
|
usart_set_databits((uint32_t)p->reg_addr, 9);
|
||||||
|
}
|
||||||
|
else { // 8 data bist, NO_PARITY by default
|
||||||
|
usart_set_parity((uint32_t)p->reg_addr, USART_PARITY_NONE);
|
||||||
|
usart_set_databits((uint32_t)p->reg_addr, 8); // is 7bits without parity possible ?
|
||||||
|
}
|
||||||
|
/* Configure USART stop bits */
|
||||||
|
if (stop == USTOP_2)
|
||||||
|
usart_set_stopbits((uint32_t)p->reg_addr, USART_STOPBITS_2);
|
||||||
|
else // 1 stop bit by default
|
||||||
|
usart_set_stopbits((uint32_t)p->reg_addr, USART_STOPBITS_1);
|
||||||
|
}
|
||||||
|
|
||||||
void uart_periph_set_mode(struct uart_periph* p, bool_t tx_enabled, bool_t rx_enabled, bool_t hw_flow_control) {
|
void uart_periph_set_mode(struct uart_periph* p, bool_t tx_enabled, bool_t rx_enabled, bool_t hw_flow_control) {
|
||||||
uint32_t mode = 0;
|
uint32_t mode = 0;
|
||||||
if (tx_enabled)
|
if (tx_enabled)
|
||||||
@@ -173,6 +197,18 @@ static inline void usart_enable_irq(uint8_t IRQn) {
|
|||||||
#define UART1_HW_FLOW_CONTROL FALSE
|
#define UART1_HW_FLOW_CONTROL FALSE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART1_BITS
|
||||||
|
#define UART1_BITS UBITS_8
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART1_STOP
|
||||||
|
#define UART1_STOP USTOP_1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART1_PARITY
|
||||||
|
#define UART1_PARITY UPARITY_NO
|
||||||
|
#endif
|
||||||
|
|
||||||
void uart1_init( void ) {
|
void uart1_init( void ) {
|
||||||
|
|
||||||
uart_periph_init(&uart1);
|
uart_periph_init(&uart1);
|
||||||
@@ -201,7 +237,8 @@ void uart1_init( void ) {
|
|||||||
/* Configure USART1, enable hardware flow control*/
|
/* Configure USART1, enable hardware flow control*/
|
||||||
uart_periph_set_mode(&uart1, USE_UART1_TX, USE_UART1_RX, UART1_HW_FLOW_CONTROL);
|
uart_periph_set_mode(&uart1, USE_UART1_TX, USE_UART1_RX, UART1_HW_FLOW_CONTROL);
|
||||||
|
|
||||||
/* Set USART1 baudrate and enable interrupt */
|
/* Set USART1 parameters and enable interrupt */
|
||||||
|
uart_periph_set_bits_stop_parity(&uart1, UART1_BITS, UART1_STOP, UART1_PARITY);
|
||||||
uart_periph_set_baudrate(&uart1, UART1_BAUD);
|
uart_periph_set_baudrate(&uart1, UART1_BAUD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,6 +261,18 @@ void usart1_isr(void) { usart_isr(&uart1); }
|
|||||||
#define UART2_HW_FLOW_CONTROL FALSE
|
#define UART2_HW_FLOW_CONTROL FALSE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART2_BITS
|
||||||
|
#define UART2_BITS UBITS_8
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART2_STOP
|
||||||
|
#define UART2_STOP USTOP_1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART2_PARITY
|
||||||
|
#define UART2_PARITY UPARITY_NO
|
||||||
|
#endif
|
||||||
|
|
||||||
void uart2_init( void ) {
|
void uart2_init( void ) {
|
||||||
|
|
||||||
uart_periph_init(&uart2);
|
uart_periph_init(&uart2);
|
||||||
@@ -253,6 +302,7 @@ void uart2_init( void ) {
|
|||||||
uart_periph_set_mode(&uart2, USE_UART2_TX, USE_UART2_RX, UART2_HW_FLOW_CONTROL);
|
uart_periph_set_mode(&uart2, USE_UART2_TX, USE_UART2_RX, UART2_HW_FLOW_CONTROL);
|
||||||
|
|
||||||
/* Configure USART */
|
/* Configure USART */
|
||||||
|
uart_periph_set_bits_stop_parity(&uart2, UART2_BITS, UART2_STOP, UART2_PARITY);
|
||||||
uart_periph_set_baudrate(&uart2, UART2_BAUD);
|
uart_periph_set_baudrate(&uart2, UART2_BAUD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,6 +325,18 @@ void usart2_isr(void) { usart_isr(&uart2); }
|
|||||||
#define UART3_HW_FLOW_CONTROL FALSE
|
#define UART3_HW_FLOW_CONTROL FALSE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART3_BITS
|
||||||
|
#define UART3_BITS UBITS_8
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART3_STOP
|
||||||
|
#define UART3_STOP USTOP_1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART3_PARITY
|
||||||
|
#define UART3_PARITY UPARITY_NO
|
||||||
|
#endif
|
||||||
|
|
||||||
void uart3_init( void ) {
|
void uart3_init( void ) {
|
||||||
|
|
||||||
uart_periph_init(&uart3);
|
uart_periph_init(&uart3);
|
||||||
@@ -304,6 +366,7 @@ void uart3_init( void ) {
|
|||||||
uart_periph_set_mode(&uart3, USE_UART3_TX, USE_UART3_RX, UART3_HW_FLOW_CONTROL);
|
uart_periph_set_mode(&uart3, USE_UART3_TX, USE_UART3_RX, UART3_HW_FLOW_CONTROL);
|
||||||
|
|
||||||
/* Configure USART */
|
/* Configure USART */
|
||||||
|
uart_periph_set_bits_stop_parity(&uart3, UART3_BITS, UART3_STOP, UART3_PARITY);
|
||||||
uart_periph_set_baudrate(&uart3, UART3_BAUD);
|
uart_periph_set_baudrate(&uart3, UART3_BAUD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,6 +385,18 @@ void usart3_isr(void) { usart_isr(&uart3); }
|
|||||||
#define USE_UART4_RX TRUE
|
#define USE_UART4_RX TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART4_BITS
|
||||||
|
#define UART4_BITS UBITS_8
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART4_STOP
|
||||||
|
#define UART4_STOP USTOP_1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART4_PARITY
|
||||||
|
#define UART4_PARITY UPARITY_NO
|
||||||
|
#endif
|
||||||
|
|
||||||
void uart4_init( void ) {
|
void uart4_init( void ) {
|
||||||
|
|
||||||
uart_periph_init(&uart4);
|
uart_periph_init(&uart4);
|
||||||
@@ -342,6 +417,7 @@ void uart4_init( void ) {
|
|||||||
|
|
||||||
/* Configure USART */
|
/* Configure USART */
|
||||||
uart_periph_set_mode(&uart4, USE_UART4_TX, USE_UART4_RX, FALSE);
|
uart_periph_set_mode(&uart4, USE_UART4_TX, USE_UART4_RX, FALSE);
|
||||||
|
uart_periph_set_bits_stop_parity(&uart4, UART4_BITS, UART4_STOP, UART4_PARITY);
|
||||||
uart_periph_set_baudrate(&uart4, UART4_BAUD);
|
uart_periph_set_baudrate(&uart4, UART4_BAUD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,6 +436,18 @@ void uart4_isr(void) { usart_isr(&uart4); }
|
|||||||
#define USE_UART5_RX TRUE
|
#define USE_UART5_RX TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART5_BITS
|
||||||
|
#define UART5_BITS UBITS_8
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART5_STOP
|
||||||
|
#define UART5_STOP USTOP_1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART5_PARITY
|
||||||
|
#define UART5_PARITY UPARITY_NO
|
||||||
|
#endif
|
||||||
|
|
||||||
void uart5_init( void ) {
|
void uart5_init( void ) {
|
||||||
|
|
||||||
uart_periph_init(&uart5);
|
uart_periph_init(&uart5);
|
||||||
@@ -380,6 +468,7 @@ void uart5_init( void ) {
|
|||||||
|
|
||||||
/* Configure USART */
|
/* Configure USART */
|
||||||
uart_periph_set_mode(&uart5, USE_UART5_TX, USE_UART5_RX, FALSE);
|
uart_periph_set_mode(&uart5, USE_UART5_TX, USE_UART5_RX, FALSE);
|
||||||
|
uart_periph_set_bits_stop_parity(&uart5, UART5_BITS, UART5_STOP, UART5_PARITY);
|
||||||
uart_periph_set_baudrate(&uart5, UART5_BAUD);
|
uart_periph_set_baudrate(&uart5, UART5_BAUD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,6 +491,18 @@ void uart5_isr(void) { usart_isr(&uart5); }
|
|||||||
#define UART6_HW_FLOW_CONTROL FALSE
|
#define UART6_HW_FLOW_CONTROL FALSE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART6_BITS
|
||||||
|
#define UART6_BITS UBITS_8
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART6_STOP
|
||||||
|
#define UART6_STOP USTOP_1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART6_PARITY
|
||||||
|
#define UART6_PARITY UPARITY_NO
|
||||||
|
#endif
|
||||||
|
|
||||||
void uart6_init( void ) {
|
void uart6_init( void ) {
|
||||||
|
|
||||||
uart_periph_init(&uart6);
|
uart_periph_init(&uart6);
|
||||||
@@ -430,7 +531,7 @@ void uart6_init( void ) {
|
|||||||
|
|
||||||
/* Configure USART Tx,Rx and hardware flow control*/
|
/* Configure USART Tx,Rx and hardware flow control*/
|
||||||
uart_periph_set_mode(&uart6, USE_UART6_TX, USE_UART6_RX, UART6_HW_FLOW_CONTROL);
|
uart_periph_set_mode(&uart6, USE_UART6_TX, USE_UART6_RX, UART6_HW_FLOW_CONTROL);
|
||||||
|
uart_periph_set_bits_stop_parity(&uart6, UART6_BITS, UART6_STOP, UART6_PARITY);
|
||||||
uart_periph_set_baudrate(&uart6, UART6_BAUD);
|
uart_periph_set_baudrate(&uart6, UART6_BAUD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,18 +112,11 @@
|
|||||||
|
|
||||||
#define POWER_SWITCH_LED 9
|
#define POWER_SWITCH_LED 9
|
||||||
|
|
||||||
/* Uart2 RX polarity, on PB13, 1 on LED_ON, 0 on LED_OFF */
|
|
||||||
#ifndef USE_LED_10
|
|
||||||
#define USE_LED_10 1
|
|
||||||
#endif
|
|
||||||
#define LED_10_GPIO GPIOB
|
|
||||||
#define LED_10_GPIO_CLK RCC_AHB1ENR_IOPBEN
|
|
||||||
#define LED_10_GPIO_PIN GPIO13
|
|
||||||
#define LED_10_GPIO_ON gpio_set
|
|
||||||
#define LED_10_GPIO_OFF gpio_clear
|
|
||||||
#define LED_10_AFIO_REMAP ((void)0)
|
|
||||||
|
|
||||||
#define RC_POLARITY_LED 10
|
/* Pint to set Uart2 RX polarity, on PB13, output high inverts, low doesn't */
|
||||||
|
#define RC_POLARITY_GPIO_PORT GPIOB
|
||||||
|
#define RC_POLARITY_GPIO_PIN GPIO13
|
||||||
|
|
||||||
|
|
||||||
/* Default actuators driver */
|
/* Default actuators driver */
|
||||||
#define DEFAULT_ACTUATORS "subsystems/actuators/actuators_pwm.h"
|
#define DEFAULT_ACTUATORS "subsystems/actuators/actuators_pwm.h"
|
||||||
|
|||||||
@@ -66,6 +66,14 @@
|
|||||||
PPM_NB_CHANNEL, \
|
PPM_NB_CHANNEL, \
|
||||||
ppm_pulses_usec); \
|
ppm_pulses_usec); \
|
||||||
}
|
}
|
||||||
|
#elif defined RADIO_CONTROL_TYPE_SBUS
|
||||||
|
#include "subsystems/radio_control/sbus.h"
|
||||||
|
#define PERIODIC_SEND_PPM(_trans, _dev) { \
|
||||||
|
DOWNLINK_SEND_PPM(_trans, _dev, \
|
||||||
|
&radio_control.frame_rate, \
|
||||||
|
SBUS_NB_CHANNEL, \
|
||||||
|
sbus.pulses); \
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#define PERIODIC_SEND_PPM(_trans, _dev) {}
|
#define PERIODIC_SEND_PPM(_trans, _dev) {}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -74,6 +74,16 @@ static inline void led_init ( void ) {
|
|||||||
LED_OFF(8);
|
LED_OFF(8);
|
||||||
#endif /* LED_8 */
|
#endif /* LED_8 */
|
||||||
|
|
||||||
|
#if USE_LED_9
|
||||||
|
LED_INIT(9);
|
||||||
|
LED_OFF(9);
|
||||||
|
#endif /* LED_9 */
|
||||||
|
|
||||||
|
#if USE_LED_10
|
||||||
|
LED_INIT(10);
|
||||||
|
LED_OFF(10);
|
||||||
|
#endif /* LED_10 */
|
||||||
|
|
||||||
#ifdef USE_LED_BODY
|
#ifdef USE_LED_BODY
|
||||||
LED_INIT(BODY);
|
LED_INIT(BODY);
|
||||||
LED_OFF(BODY);
|
LED_OFF(BODY);
|
||||||
|
|||||||
@@ -46,10 +46,21 @@
|
|||||||
#define B19200 19200
|
#define B19200 19200
|
||||||
#define B38400 38400
|
#define B38400 38400
|
||||||
#define B57600 57600
|
#define B57600 57600
|
||||||
|
#define B100000 100000
|
||||||
#define B115200 115200
|
#define B115200 115200
|
||||||
#define B230400 230400
|
#define B230400 230400
|
||||||
#define B921600 921600
|
#define B921600 921600
|
||||||
|
|
||||||
|
#define UBITS_7 7
|
||||||
|
#define UBITS_8 8
|
||||||
|
|
||||||
|
#define USTOP_1 1
|
||||||
|
#define USTOP_2 2
|
||||||
|
|
||||||
|
#define UPARITY_NO 0
|
||||||
|
#define UPARITY_ODD 1
|
||||||
|
#define UPARITY_EVEN 2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UART peripheral
|
* UART peripheral
|
||||||
*/
|
*/
|
||||||
@@ -75,6 +86,7 @@ struct uart_periph {
|
|||||||
|
|
||||||
extern void uart_periph_init(struct uart_periph* p);
|
extern void uart_periph_init(struct uart_periph* p);
|
||||||
extern void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud);
|
extern void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud);
|
||||||
|
extern void uart_periph_set_bits_stop_parity(struct uart_periph* p, uint8_t bits, uint8_t stop, uint8_t parity);
|
||||||
extern void uart_periph_set_mode(struct uart_periph* p, bool_t tx_enabled, bool_t rx_enabled, bool_t hw_flow_control);
|
extern void uart_periph_set_mode(struct uart_periph* p, bool_t tx_enabled, bool_t rx_enabled, bool_t hw_flow_control);
|
||||||
extern void uart_transmit(struct uart_periph* p, uint8_t data);
|
extern void uart_transmit(struct uart_periph* p, uint8_t data);
|
||||||
extern bool_t uart_check_free_space(struct uart_periph* p, uint8_t len);
|
extern bool_t uart_check_free_space(struct uart_periph* p, uint8_t len);
|
||||||
@@ -97,6 +109,7 @@ extern void uart0_init(void);
|
|||||||
#define UART0Getch() uart_getch(&uart0)
|
#define UART0Getch() uart_getch(&uart0)
|
||||||
#define UART0TxRunning uart0.tx_running
|
#define UART0TxRunning uart0.tx_running
|
||||||
#define UART0SetBaudrate(_b) uart_periph_set_baudrate(&uart0, _b)
|
#define UART0SetBaudrate(_b) uart_periph_set_baudrate(&uart0, _b)
|
||||||
|
#define UART0SetBitsStopParity(_b, _s, _p) uart_periph_set_bits_stop_parity(&uart0, _b, _s, _p)
|
||||||
|
|
||||||
#endif // USE_UART0
|
#endif // USE_UART0
|
||||||
|
|
||||||
@@ -112,6 +125,7 @@ extern void uart1_init(void);
|
|||||||
#define UART1Getch() uart_getch(&uart1)
|
#define UART1Getch() uart_getch(&uart1)
|
||||||
#define UART1TxRunning uart1.tx_running
|
#define UART1TxRunning uart1.tx_running
|
||||||
#define UART1SetBaudrate(_b) uart_periph_set_baudrate(&uart1, _b)
|
#define UART1SetBaudrate(_b) uart_periph_set_baudrate(&uart1, _b)
|
||||||
|
#define UART1SetBitsStopParity(_b, _s, _p) uart_periph_set_bits_stop_parity(&uart1, _b, _s, _p)
|
||||||
|
|
||||||
#endif // USE_UART1
|
#endif // USE_UART1
|
||||||
|
|
||||||
@@ -127,6 +141,7 @@ extern void uart2_init(void);
|
|||||||
#define UART2Getch() uart_getch(&uart2)
|
#define UART2Getch() uart_getch(&uart2)
|
||||||
#define UART2TxRunning uart2.tx_running
|
#define UART2TxRunning uart2.tx_running
|
||||||
#define UART2SetBaudrate(_b) uart_periph_set_baudrate(&uart2, _b)
|
#define UART2SetBaudrate(_b) uart_periph_set_baudrate(&uart2, _b)
|
||||||
|
#define UART2SetBitsStopParity(_b, _s, _p) uart_periph_set_bits_stop_parity(&uart2, _b, _s, _p)
|
||||||
|
|
||||||
#endif // USE_UART2
|
#endif // USE_UART2
|
||||||
|
|
||||||
@@ -142,6 +157,7 @@ extern void uart3_init(void);
|
|||||||
#define UART3Getch() uart_getch(&uart3)
|
#define UART3Getch() uart_getch(&uart3)
|
||||||
#define UART3TxRunning uart3.tx_running
|
#define UART3TxRunning uart3.tx_running
|
||||||
#define UART3SetBaudrate(_b) uart_periph_set_baudrate(&uart3, _b)
|
#define UART3SetBaudrate(_b) uart_periph_set_baudrate(&uart3, _b)
|
||||||
|
#define UART3SetBitsStopParity(_b, _s, _p) uart_periph_set_bits_stop_parity(&uart3, _b, _s, _p)
|
||||||
|
|
||||||
#endif // USE_UART3
|
#endif // USE_UART3
|
||||||
|
|
||||||
@@ -157,6 +173,7 @@ extern void uart4_init(void);
|
|||||||
#define UART4Getch() uart_getch(&uart4)
|
#define UART4Getch() uart_getch(&uart4)
|
||||||
#define UART4TxRunning uart4.tx_running
|
#define UART4TxRunning uart4.tx_running
|
||||||
#define UART4SetBaudrate(_b) uart_periph_set_baudrate(&uart4, _b)
|
#define UART4SetBaudrate(_b) uart_periph_set_baudrate(&uart4, _b)
|
||||||
|
#define UART4SetBitsStopParity(_b, _s, _p) uart_periph_set_bits_stop_parity(&uart4, _b, _s, _p)
|
||||||
|
|
||||||
#endif // USE_UART4
|
#endif // USE_UART4
|
||||||
|
|
||||||
@@ -172,6 +189,7 @@ extern void uart5_init(void);
|
|||||||
#define UART5Getch() uart_getch(&uart5)
|
#define UART5Getch() uart_getch(&uart5)
|
||||||
#define UART5TxRunning uart5.tx_running
|
#define UART5TxRunning uart5.tx_running
|
||||||
#define UART5SetBaudrate(_b) uart_periph_set_baudrate(&uart5, _b)
|
#define UART5SetBaudrate(_b) uart_periph_set_baudrate(&uart5, _b)
|
||||||
|
#define UART5SetBitsStopParity(_b, _s, _p) uart_periph_set_bits_stop_parity(&uart5, _b, _s, _p)
|
||||||
|
|
||||||
#endif // USE_UART5
|
#endif // USE_UART5
|
||||||
|
|
||||||
@@ -187,6 +205,7 @@ extern void uart6_init(void);
|
|||||||
#define UART6Getch() uart_getch(&uart6)
|
#define UART6Getch() uart_getch(&uart6)
|
||||||
#define UART6TxRunning uart6.tx_running
|
#define UART6TxRunning uart6.tx_running
|
||||||
#define UART6SetBaudrate(_b) uart_periph_set_baudrate(&uart6, _b)
|
#define UART6SetBaudrate(_b) uart_periph_set_baudrate(&uart6, _b)
|
||||||
|
#define UART6SetBitsStopParity(_b, _s, _p) uart_periph_set_bits_stop_parity(&uart6, _b, _s, _p)
|
||||||
|
|
||||||
#endif // USE_UART6
|
#endif // USE_UART6
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,145 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Alexandre Bustico, Gautier Hattenberger
|
||||||
|
*
|
||||||
|
* This file is part of paparazzi.
|
||||||
|
*
|
||||||
|
* paparazzi is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* paparazzi is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with paparazzi; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file subsystems/radio_control/sbus.c
|
||||||
|
*
|
||||||
|
* Futaba SBUS decoder
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "subsystems/radio_control.h"
|
||||||
|
#include "subsystems/radio_control/sbus.h"
|
||||||
|
#include BOARD_CONFIG
|
||||||
|
#include "mcu_periph/uart.h"
|
||||||
|
#include "mcu_periph/gpio.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SBUS protocol and state machine status
|
||||||
|
*/
|
||||||
|
#define SBUS_START_BYTE 0x0f
|
||||||
|
#define SBUS_END_BYTE 0x00
|
||||||
|
#define SBUS_BIT_PER_CHANNEL 11
|
||||||
|
#define SBUS_BIT_PER_BYTE 8
|
||||||
|
#define SBUS_FLAGS_BYTE 22
|
||||||
|
#define SBUS_FRAME_LOST_BIT 2
|
||||||
|
|
||||||
|
#define SBUS_STATUS_UNINIT 0
|
||||||
|
#define SBUS_STATUS_GOT_START 1
|
||||||
|
|
||||||
|
/** Set polarity using RC_POLARITY_GPIO.
|
||||||
|
* SBUS signal has a reversed polarity compared to normal UART
|
||||||
|
* this allows to using hardware UART peripheral by changing
|
||||||
|
* the input signal polarity.
|
||||||
|
* Setting this gpio ouput high inverts the signal,
|
||||||
|
* output low sets it to normal polarity.
|
||||||
|
*/
|
||||||
|
#ifndef RC_SET_POLARITY
|
||||||
|
#define RC_SET_POLARITY gpio_output_high
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/** SBUS struct */
|
||||||
|
struct _sbus sbus;
|
||||||
|
|
||||||
|
// Init function
|
||||||
|
void radio_control_impl_init(void) {
|
||||||
|
sbus.frame_available = FALSE;
|
||||||
|
sbus.status = SBUS_STATUS_UNINIT;
|
||||||
|
|
||||||
|
// Set UART parameters (100K, 8 bits, 2 stops, even parity)
|
||||||
|
uart_periph_set_bits_stop_parity(&SBUS_UART_DEV, UBITS_8, USTOP_2, UPARITY_EVEN);
|
||||||
|
uart_periph_set_baudrate(&SBUS_UART_DEV, B100000);
|
||||||
|
|
||||||
|
// Set polarity
|
||||||
|
#ifdef RC_POLARITY_GPIO_PORT
|
||||||
|
gpio_setup_output(RC_POLARITY_GPIO_PORT, RC_POLARITY_GPIO_PIN);
|
||||||
|
RC_SET_POLARITY(RC_POLARITY_GPIO_PORT, RC_POLARITY_GPIO_PIN);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Decode the raw buffer */
|
||||||
|
static void decode_sbus_buffer (const uint8_t *src, uint16_t *dst, bool_t *available)
|
||||||
|
{
|
||||||
|
// reset counters
|
||||||
|
uint8_t byteInRawBuf = 0;
|
||||||
|
uint8_t bitInRawBuf = 0;
|
||||||
|
uint8_t channel = 0;
|
||||||
|
uint8_t bitInChannel = 0;
|
||||||
|
|
||||||
|
// clear bits
|
||||||
|
memset (dst, 0, SBUS_NB_CHANNEL*sizeof(uint16_t));
|
||||||
|
|
||||||
|
// decode sbus data
|
||||||
|
for (uint8_t i=0; i< (SBUS_NB_CHANNEL*SBUS_BIT_PER_CHANNEL); i++) {
|
||||||
|
if (src[byteInRawBuf] & (1<<bitInRawBuf))
|
||||||
|
dst[channel] |= (1<<bitInChannel);
|
||||||
|
|
||||||
|
bitInRawBuf++;
|
||||||
|
bitInChannel++;
|
||||||
|
|
||||||
|
if (bitInRawBuf == SBUS_BIT_PER_BYTE) {
|
||||||
|
bitInRawBuf = 0;
|
||||||
|
byteInRawBuf++;
|
||||||
|
}
|
||||||
|
if (bitInChannel == SBUS_BIT_PER_CHANNEL) {
|
||||||
|
bitInChannel = 0;
|
||||||
|
channel++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// test frame lost flag
|
||||||
|
*available = !bit_is_set(src[SBUS_FLAGS_BYTE], SBUS_FRAME_LOST_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decoding event function
|
||||||
|
// Reading from UART
|
||||||
|
void sbus_decode_event(void) {
|
||||||
|
uint8_t rbyte;
|
||||||
|
if (uart_char_available(&SBUS_UART_DEV)) {
|
||||||
|
do {
|
||||||
|
rbyte = uart_getch(&SBUS_UART_DEV);
|
||||||
|
switch (sbus.status) {
|
||||||
|
case SBUS_STATUS_UNINIT:
|
||||||
|
// Wait for the start byte
|
||||||
|
if (rbyte == SBUS_START_BYTE) {
|
||||||
|
sbus.status++;
|
||||||
|
sbus.idx = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SBUS_STATUS_GOT_START:
|
||||||
|
// Store buffer
|
||||||
|
sbus.buffer[sbus.idx] = rbyte;
|
||||||
|
sbus.idx++;
|
||||||
|
if (sbus.idx == SBUS_BUF_LENGTH) {
|
||||||
|
// Decode if last byte is the correct end byte
|
||||||
|
if (rbyte == SBUS_END_BYTE) {
|
||||||
|
decode_sbus_buffer(sbus.buffer, sbus.pulses, &sbus.frame_available);
|
||||||
|
}
|
||||||
|
sbus.status = SBUS_STATUS_UNINIT;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (uart_char_available(&SBUS_UART_DEV));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Alexandre Bustico, Gautier Hattenberger
|
||||||
|
*
|
||||||
|
* This file is part of paparazzi.
|
||||||
|
*
|
||||||
|
* paparazzi is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* paparazzi is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with paparazzi; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RC_SBUS_H
|
||||||
|
#define RC_SBUS_H
|
||||||
|
|
||||||
|
/** @file subsystems/radio_control/sbus.h
|
||||||
|
*
|
||||||
|
* Futaba SBUS decoder
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "std.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dummy macro to use radio.h file
|
||||||
|
*/
|
||||||
|
#define RC_PPM_TICKS_OF_USEC(_v) (_v)
|
||||||
|
#define RC_PPM_SIGNED_TICKS_OF_USEC(_v) (_v)
|
||||||
|
#define USEC_OF_RC_PPM_TICKS(_v) (_v)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generated code holding the description of a given
|
||||||
|
* transmitter
|
||||||
|
*/
|
||||||
|
#include "generated/radio.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define number of channels.
|
||||||
|
*
|
||||||
|
* SBUS frame always have 16 channels
|
||||||
|
* but only the X first one will be available
|
||||||
|
* depending of the RC transmitter.
|
||||||
|
* The radio XML file is used to assign the
|
||||||
|
* input values to RC channels.
|
||||||
|
*/
|
||||||
|
#define SBUS_BUF_LENGTH 24
|
||||||
|
#define SBUS_NB_CHANNEL 16
|
||||||
|
#define RADIO_CONTROL_NB_CHANNEL SBUS_NB_CHANNEL
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SBUS structure
|
||||||
|
*/
|
||||||
|
struct _sbus {
|
||||||
|
uint16_t pulses[SBUS_NB_CHANNEL]; ///< decoded values
|
||||||
|
bool_t frame_available; ///< new frame available
|
||||||
|
uint8_t buffer[SBUS_BUF_LENGTH]; ///< input buffer
|
||||||
|
uint8_t idx; ///< input index
|
||||||
|
uint8_t status; ///< decoder state machine status
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct _sbus sbus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decoding event function
|
||||||
|
*/
|
||||||
|
extern void sbus_decode_event(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event macro with handler callback
|
||||||
|
*/
|
||||||
|
#define RadioControlEvent(_received_frame_handler) { \
|
||||||
|
sbus_decode_event(); \
|
||||||
|
if (sbus.frame_available) { \
|
||||||
|
radio_control.frame_cpt++; \
|
||||||
|
radio_control.time_since_last_frame = 0; \
|
||||||
|
if (radio_control.radio_ok_cpt > 0) { \
|
||||||
|
radio_control.radio_ok_cpt--; \
|
||||||
|
} else { \
|
||||||
|
radio_control.status = RC_OK; \
|
||||||
|
NormalizePpmIIR(sbus.pulses,radio_control); \
|
||||||
|
_received_frame_handler(); \
|
||||||
|
} \
|
||||||
|
sbus.frame_available = FALSE; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* RC_SBUS_H */
|
||||||
Reference in New Issue
Block a user