mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
Merge branch 'master' into OP-423_Mathieu_Change_Init_To_Reduce_Memory_Footprint
This commit is contained in:
commit
0ff5e9a46f
@ -45,7 +45,10 @@ ENABLE_DEBUG_PINS ?= NO
|
||||
# Set to Yes to enable the AUX UART which is mapped on the S1 (Tx) and S2 (Rx) servo outputs
|
||||
ENABLE_AUX_UART ?= NO
|
||||
|
||||
USE_TELEMETRY ?= YES
|
||||
USE_GPS ?= NO
|
||||
USE_SPEKTRUM ?= NO
|
||||
USE_SBUS ?= NO
|
||||
|
||||
USE_I2C ?= NO
|
||||
|
||||
@ -182,6 +185,7 @@ SRC += $(PIOSSTM32F10X)/pios_spi.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_ppm.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_pwm.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_spektrum.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_sbus.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_debug.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_gpio.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_exti.c
|
||||
@ -376,15 +380,42 @@ endif
|
||||
ifeq ($(ERASE_FLASH), YES)
|
||||
CDEFS += -DERASE_FLASH
|
||||
endif
|
||||
ifeq ($(USE_SPEKTRUM), YES)
|
||||
|
||||
# USART port functions. NO means do not use this function.
|
||||
# YES means use with default USART port number (hardware-dependent).
|
||||
# Number means use with specified USART port number (this value).
|
||||
ifneq ($(USE_TELEMETRY), NO)
|
||||
CDEFS += -DUSE_TELEMETRY
|
||||
ifneq ($(USE_TELEMETRY), YES)
|
||||
CDEFS += -DPIOS_PORT_TELEMETRY=$(USE_TELEMETRY)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(USE_GPS), NO)
|
||||
CDEFS += -DUSE_GPS
|
||||
ifneq ($(USE_GPS), YES)
|
||||
CDEFS += -DPIOS_PORT_GPS=$(USE_GPS)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(USE_SPEKTRUM), NO)
|
||||
CDEFS += -DUSE_SPEKTRUM
|
||||
ifneq ($(USE_SPEKTRUM), YES)
|
||||
CDEFS += -DPIOS_PORT_SPEKTRUM=$(USE_SPEKTRUM)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(USE_SBUS), NO)
|
||||
CDEFS += -DUSE_SBUS
|
||||
ifneq ($(USE_SBUS), YES)
|
||||
CDEFS += -DPIOS_PORT_SBUS=$(USE_SBUS)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(USE_I2C), YES)
|
||||
CDEFS += -DUSE_I2C
|
||||
endif
|
||||
|
||||
|
||||
# Place project-specific -D and/or -U options for
|
||||
# Assembler with preprocessor here.
|
||||
#ADEFS = -DUSE_IRQ_ASM_WRAPPER
|
||||
|
@ -30,11 +30,9 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PIOS_CONFIG_H
|
||||
#define PIOS_CONFIG_H
|
||||
|
||||
|
||||
/* Enable/Disable PiOS Modules */
|
||||
#define PIOS_INCLUDE_ADC
|
||||
#define PIOS_INCLUDE_DELAY
|
||||
@ -45,14 +43,25 @@
|
||||
#define PIOS_INCLUDE_IRQ
|
||||
#define PIOS_INCLUDE_LED
|
||||
|
||||
#if defined(USE_SPEKTRUM)
|
||||
#define PIOS_INCLUDE_SPEKTRUM
|
||||
#else
|
||||
#define PIOS_INCLUDE_GPS
|
||||
/* Receiver interfaces - only one allowed */
|
||||
#if !defined(USE_SPEKTRUM) && !defined(USE_SBUS)
|
||||
//#define PIOS_INCLUDE_PPM
|
||||
#define PIOS_INCLUDE_PWM
|
||||
#endif
|
||||
|
||||
/* USART-based PIOS modules */
|
||||
#if defined(USE_TELEMETRY)
|
||||
#define PIOS_INCLUDE_TELEMETRY_RF
|
||||
#endif
|
||||
#if defined(USE_GPS)
|
||||
#define PIOS_INCLUDE_GPS
|
||||
#endif
|
||||
#if defined(USE_SPEKTRUM)
|
||||
#define PIOS_INCLUDE_SPEKTRUM
|
||||
#endif
|
||||
#if defined(USE_SBUS)
|
||||
#define PIOS_INCLUDE_SBUS
|
||||
#endif
|
||||
|
||||
#define PIOS_INCLUDE_SERVO
|
||||
#define PIOS_INCLUDE_SPI
|
||||
|
@ -33,7 +33,6 @@
|
||||
|
||||
#if defined(PIOS_INCLUDE_SPI)
|
||||
|
||||
|
||||
#include <pios_spi_priv.h>
|
||||
|
||||
/* Flash/Accel Interface
|
||||
@ -200,13 +199,141 @@ void PIOS_ADC_handler() {
|
||||
|
||||
#include "pios_usart_priv.h"
|
||||
|
||||
/*
|
||||
* Serial port configuration.
|
||||
* TODO: This should be dynamic in the future.
|
||||
* But for now define any compatile combination of:
|
||||
* USE_I2C (shared with USART3)
|
||||
* USE_TELEMETRY
|
||||
* USE_GPS
|
||||
* USE_SPEKTRUM
|
||||
* USE_SBUS (USART1 only, it needs an invertor)
|
||||
* and optionally define PIOS_PORT_* to USART port numbers
|
||||
*/
|
||||
|
||||
/* Serial telemetry: USART1 or USART3 */
|
||||
#if !defined(PIOS_PORT_TELEMETRY)
|
||||
#define PIOS_PORT_TELEMETRY 1
|
||||
#endif
|
||||
|
||||
/* GPS receiver: USART1 or USART3 */
|
||||
#if !defined(PIOS_PORT_GPS)
|
||||
#define PIOS_PORT_GPS 3
|
||||
#endif
|
||||
|
||||
/* Spektrum satellite receiver: USART1 or USART3 */
|
||||
#if !defined(PIOS_PORT_SPEKTRUM)
|
||||
#define PIOS_PORT_SPEKTRUM 3
|
||||
#endif
|
||||
|
||||
/* Futaba S.Bus receiver: USART1 only (needs invertor) */
|
||||
#if !defined(PIOS_PORT_SBUS)
|
||||
#define PIOS_PORT_SBUS 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Define USART port configurations and check for conflicts
|
||||
* making sure they do not conflict with each other and with I2C.
|
||||
*/
|
||||
#define USART_GPIO(port) (((port) == 1) ? GPIOA : GPIOB)
|
||||
#define USART_RXIO(port) (((port) == 1) ? GPIO_Pin_10 : GPIO_Pin_11)
|
||||
#define USART_TXIO(port) (((port) == 1) ? GPIO_Pin_9 : GPIO_Pin_10)
|
||||
|
||||
#if defined(USE_TELEMETRY)
|
||||
#if defined(USE_I2C) && (PIOS_PORT_TELEMETRY == 3)
|
||||
#error defined(USE_I2C) && (PIOS_PORT_TELEMETRY == 3)
|
||||
#endif
|
||||
#if (PIOS_PORT_TELEMETRY == 1)
|
||||
#define PIOS_USART_TELEMETRY USART1
|
||||
#define PIOS_IRQH_TELEMETRY USART1_IRQHandler
|
||||
#define PIOS_IRQC_TELEMETRY USART1_IRQn
|
||||
#else
|
||||
#define PIOS_USART_TELEMETRY USART3
|
||||
#define PIOS_IRQH_TELEMETRY USART3_IRQHandler
|
||||
#define PIOS_IRQC_TELEMETRY USART3_IRQn
|
||||
#endif
|
||||
#define PIOS_GPIO_TELEMETRY USART_GPIO(PIOS_PORT_TELEMETRY)
|
||||
#define PIOS_RXIO_TELEMETRY USART_RXIO(PIOS_PORT_TELEMETRY)
|
||||
#define PIOS_TXIO_TELEMETRY USART_TXIO(PIOS_PORT_TELEMETRY)
|
||||
#endif
|
||||
|
||||
#if defined(USE_GPS)
|
||||
#if defined(USE_I2C) && (PIOS_PORT_GPS == 3)
|
||||
#error defined(USE_I2C) && (PIOS_PORT_GPS == 3)
|
||||
#endif
|
||||
#if defined(USE_TELEMETRY) && (PIOS_PORT_TELEMETRY == PIOS_PORT_GPS)
|
||||
#error defined(USE_TELEMETRY) && (PIOS_PORT_TELEMETRY == PIOS_PORT_GPS)
|
||||
#endif
|
||||
#if (PIOS_PORT_GPS == 1)
|
||||
#define PIOS_USART_GPS USART1
|
||||
#define PIOS_IRQH_GPS USART1_IRQHandler
|
||||
#define PIOS_IRQC_GPS USART1_IRQn
|
||||
#else
|
||||
#define PIOS_USART_GPS USART3
|
||||
#define PIOS_IRQH_GPS USART3_IRQHandler
|
||||
#define PIOS_IRQC_GPS USART3_IRQn
|
||||
#endif
|
||||
#define PIOS_GPIO_GPS USART_GPIO(PIOS_PORT_GPS)
|
||||
#define PIOS_RXIO_GPS USART_RXIO(PIOS_PORT_GPS)
|
||||
#define PIOS_TXIO_GPS USART_TXIO(PIOS_PORT_GPS)
|
||||
#endif
|
||||
|
||||
#if defined(USE_SPEKTRUM)
|
||||
#if defined(USE_I2C) && (PIOS_PORT_SPEKTRUM == 3)
|
||||
#error defined(USE_I2C) && (PIOS_PORT_SPEKTRUM == 3)
|
||||
#endif
|
||||
#if defined(USE_TELEMETRY) && (PIOS_PORT_SPEKTRUM == PIOS_PORT_TELEMETRY)
|
||||
#error defined(USE_TELEMETRY) && (PIOS_PORT_SPEKTRUM == PIOS_PORT_TELEMETRY)
|
||||
#endif
|
||||
#if defined(USE_GPS) && (PIOS_PORT_SPEKTRUM == PIOS_PORT_GPS)
|
||||
#error defined(USE_GPS) && (PIOS_PORT_SPEKTRUM == PIOS_PORT_GPS)
|
||||
#endif
|
||||
#if defined(USE_SBUS)
|
||||
#error defined(USE_SPEKTRUM) && defined(USE_SBUS)
|
||||
#endif
|
||||
#if (PIOS_PORT_SPEKTRUM == 1)
|
||||
#define PIOS_USART_SPEKTRUM USART1
|
||||
#define PIOS_IRQH_SPEKTRUM USART1_IRQHandler
|
||||
#define PIOS_IRQC_SPEKTRUM USART1_IRQn
|
||||
#else
|
||||
#define PIOS_USART_SPEKTRUM USART3
|
||||
#define PIOS_IRQH_SPEKTRUM USART3_IRQHandler
|
||||
#define PIOS_IRQC_SPEKTRUM USART3_IRQn
|
||||
#endif
|
||||
#define PIOS_GPIO_SPEKTRUM USART_GPIO(PIOS_PORT_SPEKTRUM)
|
||||
#define PIOS_RXIO_SPEKTRUM USART_RXIO(PIOS_PORT_SPEKTRUM)
|
||||
#define PIOS_TXIO_SPEKTRUM USART_TXIO(PIOS_PORT_SPEKTRUM)
|
||||
#endif
|
||||
|
||||
#if defined(USE_SBUS)
|
||||
#if (PIOS_PORT_SBUS != 1)
|
||||
#error (PIOS_PORT_SBUS != 1)
|
||||
#endif
|
||||
#if defined(USE_TELEMETRY) && (PIOS_PORT_SBUS == PIOS_PORT_TELEMETRY)
|
||||
#error defined(USE_TELEMETRY) && (PIOS_PORT_SBUS == PIOS_PORT_TELEMETRY)
|
||||
#endif
|
||||
#if defined(USE_GPS) && (PIOS_PORT_SBUS == PIOS_PORT_GPS)
|
||||
#error defined(USE_GPS) && (PIOS_PORT_SBUS == PIOS_PORT_GPS)
|
||||
#endif
|
||||
#if defined(USE_SPEKTRUM)
|
||||
#error defined(USE_SPEKTRUM) && defined(USE_SBUS)
|
||||
#endif
|
||||
#define PIOS_USART_SBUS USART1
|
||||
#define PIOS_IRQH_SBUS USART1_IRQHandler
|
||||
#define PIOS_IRQC_SBUS USART1_IRQn
|
||||
#define PIOS_GPIO_SBUS USART_GPIO(PIOS_PORT_SBUS)
|
||||
#define PIOS_RXIO_SBUS USART_RXIO(PIOS_PORT_SBUS)
|
||||
#define PIOS_TXIO_SBUS USART_TXIO(PIOS_PORT_SBUS)
|
||||
#endif
|
||||
|
||||
#if defined(PIOS_INCLUDE_TELEMETRY_RF)
|
||||
/*
|
||||
* Telemetry USART
|
||||
*/
|
||||
void PIOS_USART_telem_irq_handler(void);
|
||||
void USART1_IRQHandler() __attribute__ ((alias ("PIOS_USART_telem_irq_handler")));
|
||||
void PIOS_IRQH_TELEMETRY() __attribute__ ((alias ("PIOS_USART_telem_irq_handler")));
|
||||
const struct pios_usart_cfg pios_usart_telem_cfg = {
|
||||
.regs = USART1,
|
||||
.regs = PIOS_USART_TELEMETRY,
|
||||
.init = {
|
||||
#if defined (PIOS_COM_TELEM_BAUDRATE)
|
||||
.USART_BaudRate = PIOS_COM_TELEM_BAUDRATE,
|
||||
@ -222,38 +349,39 @@ const struct pios_usart_cfg pios_usart_telem_cfg = {
|
||||
.irq = {
|
||||
.handler = PIOS_USART_telem_irq_handler,
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USART1_IRQn,
|
||||
.NVIC_IRQChannel = PIOS_IRQC_TELEMETRY,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.rx = {
|
||||
.gpio = GPIOA,
|
||||
.gpio = PIOS_GPIO_TELEMETRY,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_10,
|
||||
.GPIO_Pin = PIOS_RXIO_TELEMETRY,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IPU,
|
||||
},
|
||||
},
|
||||
.tx = {
|
||||
.gpio = GPIOA,
|
||||
.gpio = PIOS_GPIO_TELEMETRY,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_9,
|
||||
.GPIO_Pin = PIOS_TXIO_TELEMETRY,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||
},
|
||||
},
|
||||
};
|
||||
#endif /* PIOS_INCLUDE_TELEMETRY_RF */
|
||||
|
||||
#if defined(PIOS_INCLUDE_GPS)
|
||||
/*
|
||||
* GPS USART
|
||||
*/
|
||||
void PIOS_USART_gps_irq_handler(void);
|
||||
void USART3_IRQHandler() __attribute__ ((alias ("PIOS_USART_gps_irq_handler")));
|
||||
void PIOS_IRQH_GPS() __attribute__ ((alias ("PIOS_USART_gps_irq_handler")));
|
||||
const struct pios_usart_cfg pios_usart_gps_cfg = {
|
||||
.regs = USART3,
|
||||
.regs = PIOS_USART_GPS,
|
||||
.init = {
|
||||
#if defined (PIOS_COM_GPS_BAUDRATE)
|
||||
.USART_BaudRate = PIOS_COM_GPS_BAUDRATE,
|
||||
@ -269,24 +397,24 @@ const struct pios_usart_cfg pios_usart_gps_cfg = {
|
||||
.irq = {
|
||||
.handler = PIOS_USART_gps_irq_handler,
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USART3_IRQn,
|
||||
.NVIC_IRQChannel = PIOS_IRQC_GPS,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.rx = {
|
||||
.gpio = GPIOB,
|
||||
.gpio = PIOS_GPIO_GPS,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_11,
|
||||
.GPIO_Pin = PIOS_RXIO_GPS,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IPU,
|
||||
},
|
||||
},
|
||||
.tx = {
|
||||
.gpio = GPIOB,
|
||||
.gpio = PIOS_GPIO_GPS,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_10,
|
||||
.GPIO_Pin = PIOS_TXIO_GPS,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||
},
|
||||
@ -299,9 +427,9 @@ const struct pios_usart_cfg pios_usart_gps_cfg = {
|
||||
* SPEKTRUM USART
|
||||
*/
|
||||
void PIOS_USART_spektrum_irq_handler(void);
|
||||
void USART3_IRQHandler() __attribute__ ((alias ("PIOS_USART_spektrum_irq_handler")));
|
||||
void PIOS_IRQH_SPEKTRUM() __attribute__ ((alias ("PIOS_USART_spektrum_irq_handler")));
|
||||
const struct pios_usart_cfg pios_usart_spektrum_cfg = {
|
||||
.regs = USART3,
|
||||
.regs = PIOS_USART_SPEKTRUM,
|
||||
.init = {
|
||||
#if defined (PIOS_COM_SPEKTRUM_BAUDRATE)
|
||||
.USART_BaudRate = PIOS_COM_SPEKTRUM_BAUDRATE,
|
||||
@ -317,24 +445,24 @@ const struct pios_usart_cfg pios_usart_spektrum_cfg = {
|
||||
.irq = {
|
||||
.handler = PIOS_USART_spektrum_irq_handler,
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USART3_IRQn,
|
||||
.NVIC_IRQChannel = PIOS_IRQC_SPEKTRUM,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.rx = {
|
||||
.gpio = GPIOB,
|
||||
.gpio = PIOS_GPIO_SPEKTRUM,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_11,
|
||||
.GPIO_Pin = PIOS_RXIO_SPEKTRUM,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IPU,
|
||||
},
|
||||
},
|
||||
.tx = {
|
||||
.gpio = GPIOB,
|
||||
.gpio = PIOS_GPIO_SPEKTRUM,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_10,
|
||||
.GPIO_Pin = PIOS_TXIO_SPEKTRUM,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
||||
},
|
||||
@ -365,8 +493,8 @@ const struct pios_spektrum_cfg pios_spektrum_cfg = {
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.port = GPIOB,
|
||||
.pin = GPIO_Pin_11,
|
||||
.port = PIOS_GPIO_SPEKTRUM,
|
||||
.pin = PIOS_RXIO_SPEKTRUM,
|
||||
};
|
||||
|
||||
void PIOS_SUPV_irq_handler() {
|
||||
@ -383,11 +511,99 @@ void PIOS_SUPV_irq_handler() {
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_SPEKTRUM */
|
||||
|
||||
#if defined(PIOS_INCLUDE_SBUS)
|
||||
/*
|
||||
* SBUS USART
|
||||
*/
|
||||
void PIOS_USART_sbus_irq_handler(void);
|
||||
void PIOS_IRQH_SBUS() __attribute__ ((alias ("PIOS_USART_sbus_irq_handler")));
|
||||
const struct pios_usart_cfg pios_usart_sbus_cfg = {
|
||||
.regs = PIOS_USART_SBUS,
|
||||
.init = {
|
||||
#if defined (PIOS_COM_SBUS_BAUDRATE)
|
||||
.USART_BaudRate = PIOS_COM_SBUS_BAUDRATE,
|
||||
#else
|
||||
.USART_BaudRate = 100000,
|
||||
#endif
|
||||
.USART_WordLength = USART_WordLength_8b,
|
||||
.USART_Parity = USART_Parity_Even,
|
||||
.USART_StopBits = USART_StopBits_2,
|
||||
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
|
||||
.USART_Mode = USART_Mode_Rx,
|
||||
},
|
||||
.irq = {
|
||||
.handler = PIOS_USART_sbus_irq_handler,
|
||||
.init = {
|
||||
.NVIC_IRQChannel = PIOS_IRQC_SBUS,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.rx = {
|
||||
.gpio = PIOS_GPIO_SBUS,
|
||||
.init = {
|
||||
.GPIO_Pin = PIOS_RXIO_SBUS,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IPU,
|
||||
},
|
||||
},
|
||||
.tx = {
|
||||
.gpio = PIOS_GPIO_SBUS,
|
||||
.init = {
|
||||
.GPIO_Pin = PIOS_TXIO_SBUS,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static uint32_t pios_usart_sbus_id;
|
||||
void PIOS_USART_sbus_irq_handler(void)
|
||||
{
|
||||
SBUS_IRQHandler(pios_usart_sbus_id);
|
||||
}
|
||||
|
||||
#include <pios_sbus_priv.h>
|
||||
void RTC_IRQHandler();
|
||||
void RTC_IRQHandler() __attribute__ ((alias ("PIOS_SUPV_irq_handler")));
|
||||
const struct pios_sbus_cfg pios_sbus_cfg = {
|
||||
/* USART configuration structure */
|
||||
.pios_usart_sbus_cfg = &pios_usart_sbus_cfg,
|
||||
|
||||
/* Invertor configuration */
|
||||
.gpio_clk_func = RCC_APB2PeriphClockCmd,
|
||||
.gpio_clk_periph = RCC_APB2Periph_GPIOB,
|
||||
.gpio_inv_port = GPIOB,
|
||||
.gpio_inv_init = {
|
||||
.GPIO_Pin = GPIO_Pin_2,
|
||||
.GPIO_Mode = GPIO_Mode_Out_PP,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
},
|
||||
.gpio_inv_enable = Bit_SET,
|
||||
};
|
||||
|
||||
void PIOS_SUPV_irq_handler() {
|
||||
if (RTC_GetITStatus(RTC_IT_SEC))
|
||||
{
|
||||
/* Call the right handler */
|
||||
PIOS_SBUS_irq_handler(pios_usart_sbus_id);
|
||||
|
||||
/* Wait until last write operation on RTC registers has finished */
|
||||
RTC_WaitForLastTask();
|
||||
/* Clear the RTC Second interrupt */
|
||||
RTC_ClearITPendingBit(RTC_IT_SEC);
|
||||
}
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_SBUS */
|
||||
|
||||
#if defined(PIOS_INCLUDE_TELEMETRY_RF)
|
||||
static uint32_t pios_usart_telem_rf_id;
|
||||
void PIOS_USART_telem_irq_handler(void)
|
||||
{
|
||||
PIOS_USART_IRQ_Handler(pios_usart_telem_rf_id);
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_TELEMETRY_RF */
|
||||
|
||||
#if defined(PIOS_INCLUDE_GPS)
|
||||
static uint32_t pios_usart_gps_id;
|
||||
@ -659,6 +875,7 @@ uint32_t pios_com_telem_rf_id;
|
||||
uint32_t pios_com_telem_usb_id;
|
||||
uint32_t pios_com_gps_id;
|
||||
uint32_t pios_com_spektrum_id;
|
||||
uint32_t pios_com_sbus_id;
|
||||
|
||||
/**
|
||||
* PIOS_Board_Init()
|
||||
@ -691,6 +908,7 @@ void PIOS_Board_Init(void) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Initialize UAVObject libraries */
|
||||
EventDispatcherInitialize();
|
||||
UAVObjInitialize();
|
||||
@ -704,12 +922,14 @@ void PIOS_Board_Init(void) {
|
||||
|
||||
/* Initialize the PiOS library */
|
||||
#if defined(PIOS_INCLUDE_COM)
|
||||
#if defined(PIOS_INCLUDE_TELEMETRY_RF)
|
||||
if (PIOS_USART_Init(&pios_usart_telem_rf_id, &pios_usart_telem_cfg)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
if (PIOS_COM_Init(&pios_com_telem_rf_id, &pios_usart_com_driver, pios_usart_telem_rf_id)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_TELEMETRY_RF */
|
||||
#if defined(PIOS_INCLUDE_GPS)
|
||||
if (PIOS_USART_Init(&pios_usart_gps_id, &pios_usart_gps_cfg)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
@ -718,6 +938,16 @@ void PIOS_Board_Init(void) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_GPS */
|
||||
#if defined(PIOS_INCLUDE_SBUS)
|
||||
PIOS_SBUS_Init();
|
||||
|
||||
if (PIOS_USART_Init(&pios_usart_sbus_id, &pios_usart_sbus_cfg)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
if (PIOS_COM_Init(&pios_com_sbus_id, &pios_usart_com_driver, pios_usart_sbus_id)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_SBUS */
|
||||
#endif /* PIOS_INCLUDE_COM */
|
||||
|
||||
/* Remap AFIO pin */
|
||||
|
@ -233,6 +233,8 @@ static void manualControlTask(void *parameters)
|
||||
cmd.Channel[n] = PIOS_PPM_Get(n);
|
||||
#elif defined(PIOS_INCLUDE_SPEKTRUM)
|
||||
cmd.Channel[n] = PIOS_SPEKTRUM_Get(n);
|
||||
#elif defined(PIOS_INCLUDE_SBUS)
|
||||
cmd.Channel[n] = PIOS_SBUS_Get(n);
|
||||
#endif
|
||||
scaledChannel[n] = scaleChannel(cmd.Channel[n], settings.ChannelMax[n], settings.ChannelMin[n], settings.ChannelNeutral[n]);
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ ENABLE_DEBUG_PINS ?= NO
|
||||
ENABLE_AUX_UART ?= NO
|
||||
|
||||
USE_SPEKTRUM ?= NO
|
||||
USE_SBUS ?= NO
|
||||
|
||||
|
||||
# Set to YES when using Code Sourcery toolchain
|
||||
@ -167,6 +168,7 @@ SRC += $(PIOSSTM32F10X)/pios_spi.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_ppm.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_pwm.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_spektrum.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_sbus.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_debug.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_gpio.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_exti.c
|
||||
@ -363,6 +365,9 @@ endif
|
||||
ifeq ($(USE_SPEKTRUM), YES)
|
||||
CDEFS += -DUSE_SPEKTRUM
|
||||
endif
|
||||
ifeq ($(USE_SBUS), YES)
|
||||
CDEFS += -DUSE_SBUS
|
||||
endif
|
||||
|
||||
|
||||
# Place project-specific -D and/or -U options for
|
||||
|
@ -44,6 +44,8 @@
|
||||
|
||||
#if defined(USE_SPEKTRUM)
|
||||
#define PIOS_INCLUDE_SPEKTRUM
|
||||
#elif defined(USE_SBUS)
|
||||
#define PIOS_INCLUDE_SBUS
|
||||
#else
|
||||
//#define PIOS_INCLUDE_PPM
|
||||
#define PIOS_INCLUDE_PWM
|
||||
|
@ -157,6 +157,9 @@ static void TaskTesting(void *pvParameters)
|
||||
#if defined(PIOS_INCLUDE_SPEKTRUM)
|
||||
PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART, "%u,%u,%u,%u,%u,%u,%u,%u\r", PIOS_SPEKTRUM_Get(0), PIOS_SPEKTRUM_Get(1), PIOS_SPEKTRUM_Get(2), PIOS_SPEKTRUM_Get(3), PIOS_SPEKTRUM_Get(4), PIOS_SPEKTRUM_Get(5), PIOS_SPEKTRUM_Get(6), PIOS_SPEKTRUM_Get(7));
|
||||
#endif
|
||||
#if defined(PIOS_INCLUDE_SBUS)
|
||||
PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART, "%u,%u,%u,%u,%u,%u,%u,%u\r", PIOS_SBUS_Get(0), PIOS_SBUS_Get(1), PIOS_SBUS_Get(2), PIOS_SBUS_Get(3), PIOS_SBUS_Get(4), PIOS_SBUS_Get(5), PIOS_SBUS_Get(6), PIOS_SBUS_Get(7));
|
||||
#endif
|
||||
#if defined(PIOS_INCLUDE_PWM)
|
||||
PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART, "%u,%u,%u,%u,%u,%u,%u,%u uS\r", PIOS_PWM_Get(0), PIOS_PWM_Get(1), PIOS_PWM_Get(2), PIOS_PWM_Get(3), PIOS_PWM_Get(4), PIOS_PWM_Get(5), PIOS_PWM_Get(6), PIOS_PWM_Get(7));
|
||||
#endif
|
||||
|
@ -539,6 +539,10 @@ void PIOS_SUPV_irq_handler() {
|
||||
}
|
||||
#endif /* PIOS_COM_SPEKTRUM */
|
||||
|
||||
#if defined(PIOS_INCLUDE_SBUS)
|
||||
#error PIOS_INCLUDE_SBUS not implemented
|
||||
#endif /* PIOS_INCLUDE_SBUS */
|
||||
|
||||
static uint32_t pios_usart_telem_rf_id;
|
||||
void PIOS_USART_telem_irq_handler(void)
|
||||
{
|
||||
|
@ -161,6 +161,12 @@ extern uint32_t pios_com_spektrum_id;
|
||||
#define PIOS_COM_SPEKTRUM (pios_com_spektrum_id)
|
||||
#endif
|
||||
|
||||
#ifdef PIOS_INCLUDE_SBUS
|
||||
#define PIOS_COM_SBUS_BAUDRATE 100000
|
||||
extern uint32_t pios_com_sbus_id;
|
||||
#define PIOS_COM_SBUS (pios_com_sbus_id)
|
||||
#endif
|
||||
|
||||
//-------------------------
|
||||
// ADC
|
||||
// PIOS_ADC_PinGet(0) = Gyro Z
|
||||
|
@ -173,6 +173,12 @@ extern uint32_t pios_com_spektrum_id;
|
||||
#define PIOS_COM_SPEKTRUM (pios_com_spektrum_id)
|
||||
#endif
|
||||
|
||||
#ifdef PIOS_INCLUDE_SBUS
|
||||
#define PIOS_COM_SBUS_BAUDRATE 100000
|
||||
extern uint32_t pios_com_sbus_id;
|
||||
#define PIOS_COM_SBUS (pios_com_sbus_id)
|
||||
#endif
|
||||
|
||||
//-------------------------
|
||||
// Delay Timer
|
||||
//-------------------------
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
static bool PIOS_COM_validate(struct pios_com_dev * com_dev)
|
||||
{
|
||||
return (com_dev->magic == PIOS_COM_DEV_MAGIC);
|
||||
return (com_dev && (com_dev->magic == PIOS_COM_DEV_MAGIC));
|
||||
}
|
||||
|
||||
#if defined(PIOS_INCLUDE_FREERTOS) && 0
|
||||
@ -298,7 +298,9 @@ int32_t PIOS_COM_ReceiveBufferUsed(uint32_t com_id)
|
||||
|
||||
if (!PIOS_COM_validate(com_dev)) {
|
||||
/* Undefined COM port for this board (see pios_board.c) */
|
||||
PIOS_DEBUG_Assert(0);
|
||||
/* This is commented out so com_id=NULL can be used to disable telemetry */
|
||||
//PIOS_DEBUG_Assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!com_dev->driver->rx_avail) {
|
||||
|
@ -32,8 +32,8 @@
|
||||
#include "pios.h"
|
||||
|
||||
#if defined(PIOS_INCLUDE_HCSR04)
|
||||
#if !defined(PIOS_INCLUDE_SPEKTRUM)
|
||||
#error Only supported with spektrum interface!
|
||||
#if !(defined(PIOS_INCLUDE_SPEKTRUM) || defined(PIOS_INCLUDE_SBUS))
|
||||
#error Only supported with Spektrum or S.Bus interface!
|
||||
#endif
|
||||
|
||||
/* Local Variables */
|
||||
|
@ -49,7 +49,7 @@ void PIOS_RTC_Init()
|
||||
RTC_WaitForSynchro();
|
||||
RTC_WaitForLastTask();
|
||||
|
||||
#if defined(PIOS_INCLUDE_SPEKTRUM)
|
||||
#if defined(PIOS_INCLUDE_SPEKTRUM) || defined(PIOS_INCLUDE_SBUS)
|
||||
/* Enable the RTC Second interrupt */
|
||||
RTC_ITConfig( RTC_IT_SEC, ENABLE );
|
||||
/* Wait until last write operation on RTC registers has finished */
|
||||
|
221
flight/PiOS/STM32F10x/pios_sbus.c
Normal file
221
flight/PiOS/STM32F10x/pios_sbus.c
Normal file
@ -0,0 +1,221 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @addtogroup PIOS_SBUS Futaba S.Bus receiver functions
|
||||
* @brief Code to read Futaba S.Bus input
|
||||
* @{
|
||||
*
|
||||
* @file pios_sbus.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2011.
|
||||
* @brief USART commands. Inits USARTs, controls USARTs & Interrupt handlers. (STM32 dependent)
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* Project Includes */
|
||||
#include "pios.h"
|
||||
#include "pios_sbus_priv.h"
|
||||
|
||||
#if defined(PIOS_INCLUDE_SBUS)
|
||||
|
||||
/* Global Variables */
|
||||
|
||||
/* Local Variables */
|
||||
static uint16_t channel_data[SBUS_NUMBER_OF_CHANNELS];
|
||||
static uint8_t received_data[SBUS_FRAME_LENGTH - 2];
|
||||
static uint8_t receive_timer;
|
||||
static uint8_t failsafe_timer;
|
||||
static uint8_t frame_found;
|
||||
|
||||
/**
|
||||
* reset_channels() function clears all channel data in case of
|
||||
* lost signal or explicit failsafe flag from the S.Bus data stream
|
||||
*/
|
||||
static void reset_channels(void)
|
||||
{
|
||||
for (int i = 0; i < SBUS_NUMBER_OF_CHANNELS; i++) {
|
||||
channel_data[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* unroll_channels() function computes channel_data[] from received_data[]
|
||||
* For efficiency it unrolls first 8 channels without loops. If other
|
||||
* 8 channels are needed they can be unrolled using the same code
|
||||
* starting from s[11] instead of s[0]. Two extra digital channels are
|
||||
* accessible using (s[22] & SBUS_FLAG_DGx) logical expressions.
|
||||
*/
|
||||
static void unroll_channels(void)
|
||||
{
|
||||
uint8_t *s = received_data;
|
||||
uint16_t *d = channel_data;
|
||||
|
||||
#if (SBUS_NUMBER_OF_CHANNELS != 8)
|
||||
#error Current S.Bus code unrolls only first 8 channels
|
||||
#endif
|
||||
|
||||
#define F(v,s) ((v) >> s) & 0x7ff
|
||||
*d++ = F(s[0] | s[1] << 8, 0);
|
||||
*d++ = F(s[1] | s[2] << 8, 3);
|
||||
*d++ = F(s[2] | s[3] << 8 | s[4] << 16, 6);
|
||||
*d++ = F(s[4] | s[5] << 8, 1);
|
||||
*d++ = F(s[5] | s[6] << 8, 4);
|
||||
*d++ = F(s[6] | s[7] << 8 | s[8] << 16, 7);
|
||||
*d++ = F(s[8] | s[9] << 8, 2);
|
||||
*d++ = F(s[9] | s[10] << 8, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* process_byte() function processes incoming byte from S.Bus stream
|
||||
*/
|
||||
static void process_byte(uint8_t b)
|
||||
{
|
||||
static uint8_t byte_count;
|
||||
|
||||
if (frame_found == 0) {
|
||||
/* no frame found yet, waiting for start byte */
|
||||
if (b == SBUS_SOF_BYTE) {
|
||||
byte_count = 0;
|
||||
frame_found = 1;
|
||||
}
|
||||
} else {
|
||||
/* do not store start and end of frame bytes */
|
||||
if (byte_count < SBUS_FRAME_LENGTH - 2) {
|
||||
/* store next byte */
|
||||
received_data[byte_count++] = b;
|
||||
} else {
|
||||
if (b == SBUS_EOF_BYTE) {
|
||||
/* full frame received */
|
||||
uint8_t flags = received_data[SBUS_FRAME_LENGTH - 3];
|
||||
if (flags & SBUS_FLAG_FL) {
|
||||
/* frame lost, do not update */
|
||||
} else if (flags & SBUS_FLAG_FS) {
|
||||
/* failsafe flag active */
|
||||
reset_channels();
|
||||
} else {
|
||||
/* data looking good */
|
||||
unroll_channels();
|
||||
failsafe_timer = 0;
|
||||
}
|
||||
} else {
|
||||
/* discard whole frame */
|
||||
}
|
||||
|
||||
/* prepare for the next frame */
|
||||
frame_found = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise S.Bus receiver interface
|
||||
*/
|
||||
void PIOS_SBUS_Init(void)
|
||||
{
|
||||
/* Enable USART input invertor clock and enable the invertor */
|
||||
(*pios_sbus_cfg.gpio_clk_func)(pios_sbus_cfg.gpio_clk_periph, ENABLE);
|
||||
GPIO_Init(pios_sbus_cfg.gpio_inv_port, &pios_sbus_cfg.gpio_inv_init);
|
||||
GPIO_WriteBit(pios_sbus_cfg.gpio_inv_port,
|
||||
pios_sbus_cfg.gpio_inv_init.GPIO_Pin,
|
||||
pios_sbus_cfg.gpio_inv_enable);
|
||||
|
||||
/* Init RTC supervisor timer interrupt */
|
||||
static const NVIC_InitTypeDef NVIC_InitStructure = {
|
||||
.NVIC_IRQChannel = RTC_IRQn,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
};
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
/* Init RTC clock */
|
||||
PIOS_RTC_Init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of an input channel
|
||||
* \param[in] channel Number of the channel desired (zero based)
|
||||
* \output -1 channel not available
|
||||
* \output >0 channel value
|
||||
*/
|
||||
int16_t PIOS_SBUS_Get(int8_t channel)
|
||||
{
|
||||
/* return error if channel is not available */
|
||||
if (channel >= SBUS_NUMBER_OF_CHANNELS) {
|
||||
return -1;
|
||||
}
|
||||
return channel_data[channel];
|
||||
}
|
||||
|
||||
/**
|
||||
* Interrupt handler for USART
|
||||
*/
|
||||
void SBUS_IRQHandler(uint32_t usart_id)
|
||||
{
|
||||
/* by always reading DR after SR make sure to clear any error interrupts */
|
||||
volatile uint16_t sr = pios_sbus_cfg.pios_usart_sbus_cfg->regs->SR;
|
||||
volatile uint8_t b = pios_sbus_cfg.pios_usart_sbus_cfg->regs->DR;
|
||||
|
||||
/* process received byte if one has arrived */
|
||||
if (sr & USART_SR_RXNE) {
|
||||
/* process byte and clear receive timer */
|
||||
process_byte(b);
|
||||
receive_timer = 0;
|
||||
}
|
||||
|
||||
/* ignore TXE interrupts */
|
||||
if (sr & USART_SR_TXE) {
|
||||
/* disable TXE interrupt (TXEIE=0) */
|
||||
USART_ITConfig(pios_sbus_cfg.pios_usart_sbus_cfg->regs, USART_IT_TXE, DISABLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Input data supervisor is called periodically and provides
|
||||
* two functions: frame syncing and failsafe triggering.
|
||||
*
|
||||
* S.Bus frames come at 7ms (HS) or 14ms (FS) rate at 100000bps. RTC
|
||||
* timer is running at 625Hz (1.6ms). So with divider 2 it gives
|
||||
* 3.2ms pause between frames which is good for both S.Bus data rates.
|
||||
*
|
||||
* Data receive function must clear the receive_timer to confirm new
|
||||
* data reception. If no new data received in 100ms, we must call the
|
||||
* failsafe function which clears all channels.
|
||||
*/
|
||||
void PIOS_SBUS_irq_handler()
|
||||
{
|
||||
/* waiting for new frame if no bytes were received in 3.2ms */
|
||||
if (++receive_timer > 2) {
|
||||
receive_timer = 0;
|
||||
frame_found = 0;
|
||||
}
|
||||
|
||||
/* activate failsafe if no frames have arrived in 102.4ms */
|
||||
if (++failsafe_timer > 64) {
|
||||
reset_channels();
|
||||
failsafe_timer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -34,8 +34,8 @@
|
||||
#include "pios_spektrum_priv.h"
|
||||
|
||||
#if defined(PIOS_INCLUDE_SPEKTRUM)
|
||||
#if defined(PIOS_INCLUDE_PWM)
|
||||
#error "Both PWM and SPEKTRUM input defined, choose only one"
|
||||
#if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_SBUS)
|
||||
#error "Both SPEKTRUM and either of PWM or SBUS inputs defined, choose only one"
|
||||
#endif
|
||||
#if defined(PIOS_COM_AUX)
|
||||
#error "AUX com cannot be used with SPEKTRUM"
|
||||
|
45
flight/PiOS/inc/pios_sbus.h
Normal file
45
flight/PiOS/inc/pios_sbus.h
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @addtogroup PIOS_SBUS Futaba S.Bus receiver functions
|
||||
* @{
|
||||
*
|
||||
* @file pios_sbus.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2011.
|
||||
* @brief Futaba S.Bus functions header.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef PIOS_SBUS_H
|
||||
#define PIOS_SBUS_H
|
||||
|
||||
/* Global Types */
|
||||
|
||||
/* Public Functions */
|
||||
extern void PIOS_SBUS_Init(void);
|
||||
extern int16_t PIOS_SBUS_Get(int8_t Channel);
|
||||
extern void SBUS_IRQHandler(uint32_t usart_id);
|
||||
|
||||
#endif /* PIOS_SBUS_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
88
flight/PiOS/inc/pios_sbus_priv.h
Normal file
88
flight/PiOS/inc/pios_sbus_priv.h
Normal file
@ -0,0 +1,88 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @addtogroup PIOS_SBUS S.Bus Functions
|
||||
* @brief PIOS interface to read and write from Futaba S.Bus port
|
||||
* @{
|
||||
*
|
||||
* @file pios_sbus_priv.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2011.
|
||||
* @brief Futaba S.Bus Private structures.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef PIOS_SBUS_PRIV_H
|
||||
#define PIOS_SBUS_PRIV_H
|
||||
|
||||
#include <pios.h>
|
||||
#include <pios_stm32.h>
|
||||
#include <pios_usart_priv.h>
|
||||
|
||||
/*
|
||||
* S.Bus serial port settings:
|
||||
* 100000bps inverted serial stream, 8 bits, even parity, 2 stop bits
|
||||
* frame period is 7ms (HS) or 14ms (FS)
|
||||
*
|
||||
* Frame structure:
|
||||
* 1 byte - 0x0f (start of frame byte)
|
||||
* 22 bytes - channel data (11 bit/channel, 16 channels, LSB first)
|
||||
* 1 byte - bit flags:
|
||||
* 0x01 - digital channel 1,
|
||||
* 0x02 - digital channel 2,
|
||||
* 0x04 - lost frame flag,
|
||||
* 0x08 - failsafe flag,
|
||||
* 0xf0 - reserved
|
||||
* 1 byte - 0x00 (end of frame byte)
|
||||
*/
|
||||
#define SBUS_FRAME_LENGTH (1+22+1+1)
|
||||
#define SBUS_SOF_BYTE 0x0f
|
||||
#define SBUS_EOF_BYTE 0x00
|
||||
#define SBUS_FLAG_DG1 0x01
|
||||
#define SBUS_FLAG_DG2 0x02
|
||||
#define SBUS_FLAG_FL 0x04
|
||||
#define SBUS_FLAG_FS 0x08
|
||||
|
||||
/*
|
||||
* S.Bus protocol provides up to 16 analog and 2 digital channels.
|
||||
* Only 8 channels are currently supported by the OpenPilot.
|
||||
*/
|
||||
#define SBUS_NUMBER_OF_CHANNELS 8
|
||||
|
||||
/*
|
||||
* S.Bus configuration includes USART and programmable invertor
|
||||
*/
|
||||
struct pios_sbus_cfg {
|
||||
const struct pios_usart_cfg *pios_usart_sbus_cfg;
|
||||
void (*gpio_clk_func)(uint32_t periph, FunctionalState state);
|
||||
uint32_t gpio_clk_periph;
|
||||
GPIO_TypeDef* gpio_inv_port;
|
||||
GPIO_InitTypeDef gpio_inv_init;
|
||||
BitAction gpio_inv_enable;
|
||||
};
|
||||
extern const struct pios_sbus_cfg pios_sbus_cfg;
|
||||
|
||||
extern void PIOS_SBUS_irq_handler();
|
||||
|
||||
#endif /* PIOS_SBUS_PRIV_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -79,6 +79,7 @@
|
||||
#include <pios_ppm.h>
|
||||
#include <pios_pwm.h>
|
||||
#include <pios_spektrum.h>
|
||||
#include <pios_sbus.h>
|
||||
#include <pios_usb_hid.h>
|
||||
#include <pios_debug.h>
|
||||
#include <pios_gpio.h>
|
||||
|
@ -33,16 +33,15 @@ CLEAN_GROUND := YES
|
||||
CLEAN_FLIGHT := YES
|
||||
endif
|
||||
|
||||
# Set up targets
|
||||
FW_STEMS_COMMON := ahrs pipxtreme
|
||||
FW_STEMS_INPUT := coptercontrol openpilot
|
||||
FW_STEMS_TOOLS := coptercontrol
|
||||
FW_STEMS_ALL := $(FW_STEMS_COMMON) $(FW_STEMS_INPUT)
|
||||
FW_TARGETS_COMMON := $(addprefix fw_, $(FW_STEMS_COMMON))
|
||||
FW_TARGETS_INPUT := $(addprefix fw_, $(FW_STEMS_INPUT))
|
||||
FW_TARGETS_TOOLS := $(addprefix fw_, $(FW_STEMS_TOOLS))
|
||||
BL_TARGETS := $(addprefix bl_, $(FW_STEMS_ALL))
|
||||
BU_TARGETS := $(addprefix bu_, $(FW_STEMS_ALL))
|
||||
# Set up targets (PPM target seems to be broken at the moment)
|
||||
FW_TARGETS_COMMON := $(addprefix fw_, ahrs pipxtreme)
|
||||
FW_TARGETS_PWM := $(addprefix fw_, coptercontrol openpilot)
|
||||
FW_TARGETS_DSM2 := $(addprefix fw_, coptercontrol openpilot)
|
||||
FW_TARGETS_SBUS := $(addprefix fw_, coptercontrol)
|
||||
FW_TARGETS_PPM := $(addprefix fw_, openpilot)
|
||||
FW_TARGETS_TOOLS := $(addprefix fw_, coptercontrol)
|
||||
BL_TARGETS := $(addprefix bl_, coptercontrol openpilot ahrs pipxtreme)
|
||||
BU_TARGETS := $(addprefix bu_, coptercontrol openpilot ahrs pipxtreme)
|
||||
|
||||
help:
|
||||
@echo
|
||||
@ -102,9 +101,10 @@ endef
|
||||
|
||||
# Firmware for different input drivers
|
||||
$(eval $(call INSTALL_TEMPLATE,fw_common,uavobjects,$(FW_DIR),,-$(PACKAGE_LBL),,,$(FW_TARGETS_COMMON),install))
|
||||
$(eval $(call INSTALL_TEMPLATE,fw_pwm,uavobjects,$(FW_DIR),,-pwm-$(PACKAGE_LBL),,clean,$(FW_TARGETS_INPUT),install))
|
||||
$(eval $(call INSTALL_TEMPLATE,fw_spektrum,uavobjects,$(FW_DIR),,-dsm2sat-$(PACKAGE_LBL),USE_SPEKTRUM=YES,clean,$(FW_TARGETS_INPUT),install))
|
||||
$(eval $(call INSTALL_TEMPLATE,fw_ppm,uavobjects,$(FW_DIR),,-ppm-$(PACKAGE_LBL),USE_PPM=YES,clean,$(FW_TARGETS_INPUT),install))
|
||||
$(eval $(call INSTALL_TEMPLATE,fw_pwm,uavobjects,$(FW_DIR),,-pwm-$(PACKAGE_LBL),,clean,$(FW_TARGETS_PWM),install))
|
||||
$(eval $(call INSTALL_TEMPLATE,fw_dsm2,uavobjects,$(FW_DIR),,-dsm2sat-$(PACKAGE_LBL),USE_SPEKTRUM=YES,clean,$(FW_TARGETS_DSM2),install))
|
||||
$(eval $(call INSTALL_TEMPLATE,fw_sbus,uavobjects,$(FW_DIR),,-sbus-$(PACKAGE_LBL),USE_SBUS=YES USE_TELEMETRY=3,clean,$(FW_TARGETS_SBUS),install))
|
||||
$(eval $(call INSTALL_TEMPLATE,fw_ppm,uavobjects,$(FW_DIR),,-ppm-$(PACKAGE_LBL),USE_PPM=YES,clean,$(FW_TARGETS_PPM),install))
|
||||
|
||||
# Bootloaders (change 'install' to 'bin' if you don't want to install bootloaders)
|
||||
$(eval $(call INSTALL_TEMPLATE,all_bl,uavobjects,$(BL_DIR),,-$(PACKAGE_LBL),,,$(BL_TARGETS),install))
|
||||
@ -121,13 +121,15 @@ $(eval $(call INSTALL_TEMPLATE,fw_tools,uavobjects,$(FE_DIR),,-flash-erase-$(PAC
|
||||
|
||||
fw_pwm: | # default dependencies, will be built first
|
||||
|
||||
fw_spektrum: | fw_pwm # ordered build
|
||||
fw_dsm2: | fw_pwm # ordered build
|
||||
|
||||
fw_ppm: | fw_spektrum # ordered build
|
||||
fw_sbus: | fw_dsm2 # ordered build
|
||||
|
||||
fw_tools: | fw_spektrum # ordered build, replace fw_spektrum by fw_ppm if uncommented below
|
||||
fw_ppm: | fw_sbus # ordered build
|
||||
|
||||
package_fw: | fw_common fw_pwm fw_spektrum # fw_ppm
|
||||
fw_tools: | fw_ppm # ordered build
|
||||
|
||||
package_fw: | fw_common fw_pwm fw_dsm2 fw_sbus fw_ppm
|
||||
|
||||
package_bu: | all_bu
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user