mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
OP-22 PIOS/Spektrum: Made spektrum input driver, NOT YET TESTED!!!, also preliminary support for CC, sync/supv timer not yet fixed.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2602 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
df0b5f9b6c
commit
195b63b6bb
@ -41,6 +41,7 @@
|
||||
#define PIOS_INCLUDE_I2C
|
||||
#define PIOS_INCLUDE_IRQ
|
||||
#define PIOS_INCLUDE_LED
|
||||
#define PIOS_INCLUDE_GPS
|
||||
//#define PIOS_INCLUDE_SPEKTRUM
|
||||
//#define PIOS_INCLUDE_PPM
|
||||
#define PIOS_INCLUDE_PWM
|
||||
|
@ -302,6 +302,7 @@ const struct pios_usart_cfg pios_usart_telem_cfg = {
|
||||
},
|
||||
};
|
||||
|
||||
#ifdef PIOS_COM_GPS
|
||||
/*
|
||||
* GPS USART
|
||||
*/
|
||||
@ -347,53 +348,88 @@ const struct pios_usart_cfg pios_usart_gps_cfg = {
|
||||
},
|
||||
},
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef PIOS_COM_SPEKTRUM
|
||||
/*
|
||||
* SPEKTRUM USART
|
||||
*/
|
||||
#include <pios_spektrum_priv.h>
|
||||
void PIOS_USART_spektrum_irq_handler(void);
|
||||
void USART1_IRQHandler() __attribute__ ((alias ("PIOS_USART_spektrum_irq_handler")));
|
||||
const struct pios_usart_cfg pios_usart_spektrum_cfg = {
|
||||
.regs = USART1,
|
||||
.init = {
|
||||
#if defined (PIOS_COM_SPEKTRUM_BAUDRATE)
|
||||
.USART_BaudRate = PIOS_COM_SPEKTRUM_BAUDRATE,
|
||||
#else
|
||||
.USART_BaudRate = 115200,
|
||||
#endif
|
||||
.USART_WordLength = USART_WordLength_8b,
|
||||
.USART_Parity = USART_Parity_No,
|
||||
.USART_StopBits = USART_StopBits_1,
|
||||
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
|
||||
.USART_Mode = USART_Mode_Rx,
|
||||
},
|
||||
.irq = {
|
||||
.handler = PIOS_USART_spektrum_irq_handler,
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USART1_IRQn,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.rx = {
|
||||
.gpio = GPIOA,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_10,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IPU,
|
||||
},
|
||||
},
|
||||
.tx = {
|
||||
.gpio = GPIOA,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_9,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
||||
},
|
||||
},
|
||||
void USART3_IRQHandler() __attribute__ ((alias ("PIOS_USART_spektrum_irq_handler")));
|
||||
void TIM6_IRQHandler();
|
||||
void TIM6_IRQHandler() __attribute__ ((alias ("PIOS_TIM6_irq_handler")));
|
||||
const struct pios_spektrum_cfg pios_spektrum_cfg = {
|
||||
.pios_usart_spektrum_cfg = {
|
||||
.regs = USART3,
|
||||
.init = {
|
||||
#if defined (PIOS_COM_SPEKTRUM_BAUDRATE)
|
||||
.USART_BaudRate = PIOS_COM_SPEKTRUM_BAUDRATE,
|
||||
#else
|
||||
.USART_BaudRate = 115200,
|
||||
#endif
|
||||
.USART_WordLength = USART_WordLength_8b,
|
||||
.USART_Parity = USART_Parity_No,
|
||||
.USART_StopBits = USART_StopBits_1,
|
||||
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
|
||||
.USART_Mode = USART_Mode_Rx,
|
||||
},
|
||||
.irq = {
|
||||
.handler = PIOS_USART_spektrum_irq_handler,
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USART3_IRQn,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.rx = {
|
||||
.gpio = GPIOB,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_11,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IPU,
|
||||
},
|
||||
},
|
||||
.tx = {
|
||||
.gpio = GPIOB,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_10,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
||||
},
|
||||
},
|
||||
},
|
||||
.tim_base_init = {
|
||||
.TIM_Prescaler = (PIOS_MASTER_CLOCK / 1000000) - 1, /* For 1 uS accuracy */
|
||||
.TIM_ClockDivision = TIM_CKD_DIV1,
|
||||
.TIM_CounterMode = TIM_CounterMode_Up,
|
||||
.TIM_Period = ((1000000 / 60) - 1), //60hz
|
||||
.TIM_RepetitionCounter = 0x0000,
|
||||
},
|
||||
.gpio_init = { //used for bind feature
|
||||
.GPIO_Mode = GPIO_Mode_Out_PP,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
},
|
||||
.remap = 0,
|
||||
.irq = {
|
||||
.handler = TIM6_IRQHandler,
|
||||
.init = {
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.timer = TIM6,
|
||||
.port = GPIOB,
|
||||
.ccr = TIM_IT_Update,
|
||||
.pin = GPIO_Pin_11,
|
||||
};
|
||||
|
||||
void PIOS_TIM6_irq_handler()
|
||||
{
|
||||
PIOS_SPEKTRUM_irq_handler();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -404,14 +440,16 @@ struct pios_usart_dev pios_usart_devs[] = {
|
||||
{
|
||||
.cfg = &pios_usart_telem_cfg,
|
||||
},
|
||||
#ifdef PIOS_COM_GPS
|
||||
#define PIOS_USART_GPS 1
|
||||
{
|
||||
.cfg = &pios_usart_gps_cfg,
|
||||
},
|
||||
#endif
|
||||
#ifdef PIOS_COM_SPEKTRUM
|
||||
#define PIOS_USART_AUX 2
|
||||
{
|
||||
.cfg = &pios_usart_spektrum_cfg,
|
||||
.cfg = &pios_spektrum_cfg.pios_usart_spektrum_cfg,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
@ -423,10 +461,12 @@ void PIOS_USART_telem_irq_handler(void)
|
||||
PIOS_USART_IRQ_Handler(PIOS_USART_TELEM);
|
||||
}
|
||||
|
||||
#ifdef PIOS_COM_GPS
|
||||
void PIOS_USART_gps_irq_handler(void)
|
||||
{
|
||||
PIOS_USART_IRQ_Handler(PIOS_USART_GPS);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PIOS_COM_SPEKTRUM
|
||||
void PIOS_USART_spektrum_irq_handler(void)
|
||||
@ -450,10 +490,12 @@ struct pios_com_dev pios_com_devs[] = {
|
||||
.id = PIOS_USART_TELEM,
|
||||
.driver = &pios_usart_com_driver,
|
||||
},
|
||||
#ifdef PIOS_COM_GPS
|
||||
{
|
||||
.id = PIOS_USART_GPS,
|
||||
.driver = &pios_usart_com_driver,
|
||||
},
|
||||
#endif
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
{
|
||||
.id = 0,
|
||||
|
@ -509,48 +509,82 @@ const struct pios_usart_cfg pios_usart_aux_cfg = {
|
||||
/*
|
||||
* SPEKTRUM USART
|
||||
*/
|
||||
#include <pios_spektrum_priv.h>
|
||||
void PIOS_USART_spektrum_irq_handler(void);
|
||||
void USART1_IRQHandler() __attribute__ ((alias ("PIOS_USART_spektrum_irq_handler")));
|
||||
const struct pios_usart_cfg pios_usart_spektrum_cfg = {
|
||||
.regs = USART1,
|
||||
.init = {
|
||||
#if defined (PIOS_COM_SPEKTRUM_BAUDRATE)
|
||||
.USART_BaudRate = PIOS_COM_SPEKTRUM_BAUDRATE,
|
||||
#else
|
||||
.USART_BaudRate = 115200,
|
||||
#endif
|
||||
.USART_WordLength = USART_WordLength_8b,
|
||||
.USART_Parity = USART_Parity_No,
|
||||
.USART_StopBits = USART_StopBits_1,
|
||||
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
|
||||
.USART_Mode = USART_Mode_Rx,
|
||||
},
|
||||
.irq = {
|
||||
.handler = PIOS_USART_spektrum_irq_handler,
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USART1_IRQn,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.rx = {
|
||||
.gpio = GPIOA,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_10,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IPU,
|
||||
},
|
||||
},
|
||||
.tx = {
|
||||
.gpio = GPIOA,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_9,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
||||
},
|
||||
},
|
||||
void TIM6_IRQHandler();
|
||||
void TIM6_IRQHandler() __attribute__ ((alias ("PIOS_TIM6_irq_handler")));
|
||||
const struct pios_spektrum_cfg pios_spektrum_cfg = {
|
||||
.pios_usart_spektrum_cfg = {
|
||||
.regs = USART1,
|
||||
.init = {
|
||||
#if defined (PIOS_COM_SPEKTRUM_BAUDRATE)
|
||||
.USART_BaudRate = PIOS_COM_SPEKTRUM_BAUDRATE,
|
||||
#else
|
||||
.USART_BaudRate = 115200,
|
||||
#endif
|
||||
.USART_WordLength = USART_WordLength_8b,
|
||||
.USART_Parity = USART_Parity_No,
|
||||
.USART_StopBits = USART_StopBits_1,
|
||||
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
|
||||
.USART_Mode = USART_Mode_Rx,
|
||||
},
|
||||
.irq = {
|
||||
.handler = PIOS_USART_spektrum_irq_handler,
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USART1_IRQn,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.rx = {
|
||||
.gpio = GPIOA,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_10,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IPU,
|
||||
},
|
||||
},
|
||||
.tx = {
|
||||
.gpio = GPIOA,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_9,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
|
||||
},
|
||||
},
|
||||
},
|
||||
.tim_base_init = {
|
||||
.TIM_Prescaler = (PIOS_MASTER_CLOCK / 1000000) - 1, /* For 1 uS accuracy */
|
||||
.TIM_ClockDivision = TIM_CKD_DIV1,
|
||||
.TIM_CounterMode = TIM_CounterMode_Up,
|
||||
.TIM_Period = ((1000000 / 60) - 1), //60hz
|
||||
.TIM_RepetitionCounter = 0x0000,
|
||||
},
|
||||
.gpio_init = { //used for bind feature
|
||||
.GPIO_Mode = GPIO_Mode_Out_PP,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
},
|
||||
.remap = 0,
|
||||
.irq = {
|
||||
.handler = TIM6_IRQHandler,
|
||||
.init = {
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.timer = TIM6,
|
||||
.port = GPIOA,
|
||||
.ccr = TIM_IT_Update,
|
||||
.pin = GPIO_Pin_10,
|
||||
};
|
||||
|
||||
void PIOS_TIM6_irq_handler()
|
||||
{
|
||||
PIOS_SPEKTRUM_irq_handler();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -574,7 +608,7 @@ struct pios_usart_dev pios_usart_devs[] = {
|
||||
#ifdef PIOS_COM_SPEKTRUM
|
||||
#define PIOS_USART_AUX 2
|
||||
{
|
||||
.cfg = &pios_usart_spektrum_cfg,
|
||||
.cfg = &pios_spektrum_cfg.pios_usart_spektrum_cfg,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
@ -148,12 +148,19 @@ TIM4 | RC In 1 | Servo 3 | Servo 2 | Servo 1
|
||||
#define PIOS_USART_RX_BUFFER_SIZE 256
|
||||
#define PIOS_USART_TX_BUFFER_SIZE 256
|
||||
#define PIOS_USART_BAUDRATE 57600
|
||||
#define PIOS_COM_DEBUG PIOS_COM_GPS
|
||||
#define PIOS_COM_DEBUG PIOS_COM_TELEM_RF
|
||||
|
||||
#define PIOS_COM_TELEM_RF 0
|
||||
#define PIOS_COM_GPS 1
|
||||
#ifdef PIOS_INCLUDE_GPS
|
||||
#define PIOS_COM_GPS 1
|
||||
#endif
|
||||
#define PIOS_COM_TELEM_USB 2
|
||||
|
||||
#ifdef PIOS_INCLUDE_SPEKTRUM
|
||||
#define PIOS_COM_SPEKTRUM_BAUDRATE 115200
|
||||
#define PIOS_COM_SPEKTRUM 1
|
||||
#endif
|
||||
|
||||
//-------------------------
|
||||
// ADC
|
||||
// PIOS_ADC_PinGet(0) = Gyro Z
|
||||
|
@ -230,12 +230,12 @@ TIM8 | Servo 5 | Servo 6 | Servo 7 | Servo 8
|
||||
//-------------------------
|
||||
// SPEKTRUM input
|
||||
//-------------------------
|
||||
#define PIOS_SPEKTRUM_SUPV_ENABLED 1
|
||||
#define PIOS_SPEKTRUM_SUPV_TIMER TIM6
|
||||
#define PIOS_SPEKTRUM_SUPV_TIMER_RCC_FUNC RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE)
|
||||
#define PIOS_SPEKTRUM_SUPV_HZ 60 // 1/22ms
|
||||
#define PIOS_SPEKTRUM_SUPV_IRQ_CHANNEL TIM6_IRQn
|
||||
#define PIOS_SPEKTRUM_SUPV_IRQ_FUNC void TIM6_IRQHandler(void)
|
||||
//#define PIOS_SPEKTRUM_SUPV_ENABLED 1
|
||||
//#define PIOS_SPEKTRUM_SUPV_TIMER TIM6
|
||||
//#define PIOS_SPEKTRUM_SUPV_TIMER_RCC_FUNC RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE)
|
||||
//#define PIOS_SPEKTRUM_SUPV_HZ 60 // 1/22ms
|
||||
//#define PIOS_SPEKTRUM_SUPV_IRQ_CHANNEL TIM6_IRQn
|
||||
//#define PIOS_SPEKTRUM_SUPV_IRQ_FUNC void TIM6_IRQHandler(void)
|
||||
|
||||
//-------------------------
|
||||
// Servo outputs
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
/* Project Includes */
|
||||
#include "pios.h"
|
||||
#include "pios_spektrum_priv.h"
|
||||
|
||||
#if defined(PIOS_INCLUDE_SPEKTRUM)
|
||||
#if defined(PIOS_INCLUDE_PWM)
|
||||
@ -58,6 +59,68 @@ void PIOS_SPEKTRUM_Init(void)
|
||||
PIOS_SPEKTRUM_Bind();
|
||||
}
|
||||
|
||||
///////////////////////
|
||||
|
||||
NVIC_InitTypeDef NVIC_InitStructure = pios_spektrum_cfg.irq.init;
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure = pios_spektrum_cfg.tim_base_init;
|
||||
|
||||
|
||||
/* Enable appropriate clock to timer module */
|
||||
switch((int32_t) pios_spektrum_cfg.timer) {
|
||||
case (int32_t)TIM1:
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
|
||||
break;
|
||||
case (int32_t)TIM2:
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
||||
break;
|
||||
case (int32_t)TIM3:
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
|
||||
break;
|
||||
case (int32_t)TIM4:
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
|
||||
break;
|
||||
#ifdef STM32F10X_HD
|
||||
|
||||
case (int32_t)TIM5:
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
|
||||
break;
|
||||
case (int32_t)TIM6:
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
|
||||
break;
|
||||
case (int32_t)TIM7:
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM7_IRQn;
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
|
||||
break;
|
||||
case (int32_t)TIM8:
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM8_CC_IRQn;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
/* Configure timer clocks */
|
||||
TIM_InternalClockConfig(pios_spektrum_cfg.timer);
|
||||
TIM_TimeBaseInit(pios_spektrum_cfg.timer, &TIM_TimeBaseStructure);
|
||||
|
||||
/* Enable the Capture Compare Interrupt Request */
|
||||
TIM_ITConfig(pios_spektrum_cfg.timer, pios_spektrum_cfg.ccr, ENABLE);
|
||||
|
||||
/* Clear update pending flag */
|
||||
TIM_ClearFlag(pios_spektrum_cfg.timer, TIM_FLAG_Update);
|
||||
|
||||
/* Enable timers */
|
||||
TIM_Cmd(pios_spektrum_cfg.timer, ENABLE);
|
||||
|
||||
/////////////////////////////
|
||||
|
||||
#if 0
|
||||
/* spektrum "watchdog" timer */
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
||||
@ -83,10 +146,11 @@ void PIOS_SPEKTRUM_Init(void)
|
||||
TIM_ITConfig(PIOS_SPEKTRUM_SUPV_TIMER, TIM_IT_Update, ENABLE);
|
||||
|
||||
/* Clear update pending flag */
|
||||
TIM_ClearFlag(TIM6, TIM_FLAG_Update);
|
||||
TIM_ClearFlag(PIOS_SPEKTRUM_SUPV_TIMER, TIM_FLAG_Update);
|
||||
|
||||
/* Enable counter */
|
||||
TIM_Cmd(PIOS_SPEKTRUM_SUPV_TIMER, ENABLE);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,6 +176,43 @@ int16_t PIOS_SPEKTRUM_Get(int8_t Channel)
|
||||
*/
|
||||
uint8_t PIOS_SPEKTRUM_Bind(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure = pios_spektrum_cfg.gpio_init;
|
||||
GPIO_InitStructure.GPIO_Pin = pios_spektrum_cfg.pin;
|
||||
GPIO_Init(pios_spektrum_cfg.port, &GPIO_InitStructure);
|
||||
|
||||
pios_spektrum_cfg.port->BRR = pios_spektrum_cfg.pin;
|
||||
//PIOS_DELAY_WaitmS(75);
|
||||
/* RX line, drive high for 10us */
|
||||
pios_spektrum_cfg.port->BSRR = pios_spektrum_cfg.pin;
|
||||
PIOS_DELAY_WaituS(10);
|
||||
/* RX line, drive low for 120us */
|
||||
pios_spektrum_cfg.port->BRR = pios_spektrum_cfg.pin;
|
||||
PIOS_DELAY_WaituS(120);
|
||||
/* RX line, drive high for 120us */
|
||||
pios_spektrum_cfg.port->BSRR = pios_spektrum_cfg.pin;
|
||||
PIOS_DELAY_WaituS(120);
|
||||
/* RX line, drive low for 120us */
|
||||
pios_spektrum_cfg.port->BRR = pios_spektrum_cfg.pin;
|
||||
PIOS_DELAY_WaituS(120);
|
||||
/* RX line, drive high for 120us */
|
||||
pios_spektrum_cfg.port->BSRR = pios_spektrum_cfg.pin;
|
||||
PIOS_DELAY_WaituS(120);
|
||||
/* RX line, drive low for 120us */
|
||||
pios_spektrum_cfg.port->BRR = pios_spektrum_cfg.pin;
|
||||
PIOS_DELAY_WaituS(120);
|
||||
/* RX line, drive high for 120us */
|
||||
pios_spektrum_cfg.port->BSRR = pios_spektrum_cfg.pin;
|
||||
PIOS_DELAY_WaituS(120);
|
||||
/* RX line, drive low for 120us */
|
||||
pios_spektrum_cfg.port->BRR = pios_spektrum_cfg.pin;
|
||||
PIOS_DELAY_WaituS(120);
|
||||
/* RX line, drive high for 120us */
|
||||
pios_spektrum_cfg.port->BSRR = pios_spektrum_cfg.pin;
|
||||
PIOS_DELAY_WaituS(120);
|
||||
/* RX line, set input and wait for data, PIOS_SPEKTRUM_Init */
|
||||
|
||||
#if 0
|
||||
|
||||
#define PIOS_USART3_GPIO_PORT GPIOA
|
||||
#define PIOS_USART3_RX_PIN GPIO_Pin_10
|
||||
|
||||
@ -155,6 +256,7 @@ uint8_t PIOS_SPEKTRUM_Bind(void)
|
||||
PIOS_USART3_GPIO_PORT->BSRR = PIOS_USART3_RX_PIN;
|
||||
PIOS_DELAY_WaituS(120);
|
||||
/* RX line, set input and wait for data, PIOS_SPEKTRUM_Init */
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -214,31 +316,32 @@ int32_t PIOS_SPEKTRUM_Decode(uint8_t b)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Interrupt handler for USART3 */
|
||||
/* Interrupt handler for USART */
|
||||
void SPEKTRUM_IRQHandler(void)
|
||||
{
|
||||
/* check if RXNE flag is set */
|
||||
if (USART1->SR & (1 << 5)) {
|
||||
uint8_t b = USART1->DR;
|
||||
if (pios_spektrum_cfg.pios_usart_spektrum_cfg.regs->SR & (1 << 5)) {
|
||||
uint8_t b = pios_spektrum_cfg.pios_usart_spektrum_cfg.regs->DR;
|
||||
if (PIOS_SPEKTRUM_Decode(b) < 0) {
|
||||
/* Here we could add some error handling */
|
||||
}
|
||||
}
|
||||
|
||||
if (USART1->SR & (1 << 7)) { // check if TXE flag is set
|
||||
if (pios_spektrum_cfg.pios_usart_spektrum_cfg.regs->SR & (1 << 7)) { // check if TXE flag is set
|
||||
/* Disable TXE interrupt (TXEIE=0) */
|
||||
USART1->CR1 &= ~(1 << 7);
|
||||
pios_spektrum_cfg.pios_usart_spektrum_cfg.regs->CR1 &= ~(1 << 7);
|
||||
}
|
||||
/* clear "watchdog" timer */
|
||||
TIM_SetCounter(PIOS_SPEKTRUM_SUPV_TIMER, 0);
|
||||
TIM_SetCounter(pios_spektrum_cfg.timer, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function handles TIM6 global interrupt request.
|
||||
*/
|
||||
PIOS_SPEKTRUM_SUPV_IRQ_FUNC {
|
||||
void PIOS_SPEKTRUM_irq_handler() {
|
||||
//PIOS_SPEKTRUM_SUPV_IRQ_FUNC {
|
||||
/* Clear timer interrupt pending bit */
|
||||
TIM_ClearITPendingBit(PIOS_SPEKTRUM_SUPV_TIMER, TIM_IT_Update);
|
||||
TIM_ClearITPendingBit(pios_spektrum_cfg.timer, TIM_IT_Update);
|
||||
|
||||
/* sync between frames, TODO! DX7SE */
|
||||
sync = 0;
|
||||
|
60
flight/PiOS/inc/pios_spektrum_priv.h
Normal file
60
flight/PiOS/inc/pios_spektrum_priv.h
Normal file
@ -0,0 +1,60 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @addtogroup PIOS_SPEKTRUM SPEKTRUM Functions
|
||||
* @brief PIOS interface to read and write from spektrum port
|
||||
* @{
|
||||
*
|
||||
* @file pios_spektrum_priv.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Servo 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_SPEKTRUM_PRIV_H
|
||||
#define PIOS_SPEKTRUM_PRIV_H
|
||||
|
||||
#include <pios.h>
|
||||
#include <pios_stm32.h>
|
||||
#include <pios_usart_priv.h>
|
||||
|
||||
struct pios_spektrum_cfg {
|
||||
struct pios_usart_cfg pios_usart_spektrum_cfg;
|
||||
TIM_TimeBaseInitTypeDef tim_base_init;
|
||||
GPIO_InitTypeDef gpio_init;
|
||||
uint32_t remap; /* GPIO_Remap_* */
|
||||
struct stm32_irq irq;
|
||||
TIM_TypeDef * timer;
|
||||
GPIO_TypeDef * port;
|
||||
uint16_t ccr;
|
||||
uint16_t pin;
|
||||
};
|
||||
|
||||
extern void PIOS_SPEKTRUM_irq_handler();
|
||||
|
||||
extern uint8_t pios_spektrum_num_channels;
|
||||
extern const struct pios_spektrum_cfg pios_spektrum_cfg;
|
||||
|
||||
#endif /* PIOS_PWM_PRIV_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
Loading…
Reference in New Issue
Block a user