mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-31 16:52:10 +01:00
OP-22 Flight/PiOS: Spektrum reworked, input is mapped to old aux in receiver connector, works nicely with calibration plugin. Also bind works, just needs config flag to bind on powerup
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1189 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
c4a986ae1a
commit
7f6336d324
@ -127,6 +127,10 @@ TIM8 | Servo 5 | Servo 6 | Servo 7 | Servo 8
|
||||
#define PIOS_COM_DEBUG PIOS_COM_AUX
|
||||
#endif
|
||||
|
||||
#ifdef PIOS_INCLUDE_SPEKTRUM
|
||||
#define PIOS_COM_SPEKTRUM 3
|
||||
#endif
|
||||
|
||||
//-------------------------
|
||||
// SPI
|
||||
//
|
||||
|
@ -50,7 +50,10 @@ void PIOS_Board_Init(void) {
|
||||
/* Enable and mount the SDCard */
|
||||
PIOS_SDCARD_Init();
|
||||
PIOS_SDCARD_MountFS(0);
|
||||
|
||||
#if defined(PIOS_INCLUDE_SPEKTRUM)
|
||||
/* SPEKTRUM init must come before comms */
|
||||
PIOS_SPEKTRUM_Init();
|
||||
#endif
|
||||
/* Initialize UAVObject libraries */
|
||||
EventDispatcherInitialize();
|
||||
UAVObjInitialize();
|
||||
@ -64,9 +67,7 @@ void PIOS_Board_Init(void) {
|
||||
PIOS_Servo_Init();
|
||||
PIOS_ADC_Init();
|
||||
PIOS_GPIO_Init();
|
||||
#if defined(PIOS_INCLUDE_SPEKTRUM)
|
||||
PIOS_SPEKTRUM_Init();
|
||||
#endif
|
||||
|
||||
#if defined(PIOS_INCLUDE_PWM)
|
||||
PIOS_PWM_Init();
|
||||
#endif
|
||||
@ -76,7 +77,7 @@ void PIOS_Board_Init(void) {
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
PIOS_USB_HID_Init(0);
|
||||
#endif
|
||||
//PIOS_I2C_Init();
|
||||
PIOS_I2C_Init();
|
||||
|
||||
WWDG_SetPrescaler(WWDG_Prescaler_8);
|
||||
WWDG_SetWindowValue(0xff);
|
||||
@ -437,6 +438,50 @@ const struct pios_usart_cfg pios_usart_aux_cfg = {
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef PIOS_COM_SPEKTRUM
|
||||
/*
|
||||
* SPEKTRUM USART
|
||||
*/
|
||||
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 = {
|
||||
.USART_BaudRate = 115200,
|
||||
.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,
|
||||
},
|
||||
},
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Board specific number of devices.
|
||||
*/
|
||||
@ -455,6 +500,12 @@ struct pios_usart_dev pios_usart_devs[] = {
|
||||
.cfg = &pios_usart_aux_cfg,
|
||||
},
|
||||
#endif
|
||||
#ifdef PIOS_COM_SPEKTRUM
|
||||
#define PIOS_USART_AUX 2
|
||||
{
|
||||
.cfg = &pios_usart_spektrum_cfg,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
uint8_t pios_usart_num_devices = NELEMENTS(pios_usart_devs);
|
||||
@ -476,6 +527,13 @@ void PIOS_USART_aux_irq_handler(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PIOS_COM_SPEKTRUM
|
||||
void PIOS_USART_spektrum_irq_handler(void)
|
||||
{
|
||||
SPEKTRUM_IRQHandler();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* COM devices
|
||||
*/
|
||||
@ -507,6 +565,12 @@ struct pios_com_dev pios_com_devs[] = {
|
||||
.driver = &pios_usart_com_driver,
|
||||
},
|
||||
#endif
|
||||
#ifdef PIOS_COM_SPEKTRUM
|
||||
{
|
||||
.id = PIOS_USART_AUX,
|
||||
.driver = &pios_usart_com_driver,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
const uint8_t pios_com_num_devices = NELEMENTS(pios_com_devs);
|
||||
|
@ -83,7 +83,7 @@ static void TaskTesting(void *pvParameters)
|
||||
temp = PIOS_BMP085_GetTemperature();
|
||||
pressure = PIOS_BMP085_GetPressure();
|
||||
|
||||
PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART, "%3u,%4u\r", temp, pressure);
|
||||
PIOS_COM_SendFormattedStringNonBlocking(PIOS_COM_TELEM_RF, "%3u,%4u\r", temp, pressure);
|
||||
|
||||
vTaskDelay(xDelay);
|
||||
}
|
||||
|
@ -37,6 +37,9 @@
|
||||
#if defined(PIOS_INCLUDE_PWM)
|
||||
#error "Both PWM and SPEKTRUM input defined, choose only one"
|
||||
#endif
|
||||
#if defined(PIOS_COM_AUX)
|
||||
#error "AUX com cannot be used with SPEKTRUM"
|
||||
#endif
|
||||
|
||||
/* Global Variables */
|
||||
|
||||
@ -50,55 +53,11 @@ static uint16_t CaptureValue[12];
|
||||
*/
|
||||
void PIOS_SPEKTRUM_Init(void)
|
||||
{
|
||||
// need setting flag for bind on next powerup
|
||||
if(1)
|
||||
// TODO: need setting flag for bind on next powerup
|
||||
if(0)
|
||||
{
|
||||
PIOS_SPEKTRUM_Bind();
|
||||
}
|
||||
/* Configure USART Pins */
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_StructInit(&GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
|
||||
/* Configure and Init USARTs */
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Rx;
|
||||
|
||||
/* Configure the USART Interrupts */
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
|
||||
/* Enable the USART Pins Software Remapping */
|
||||
PIOS_USART3_REMAP_FUNC;
|
||||
|
||||
/* Configure and Init USART Rx input with internal pull-ups */
|
||||
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_InitStructure.GPIO_Pin = PIOS_USART3_RX_PIN;
|
||||
GPIO_Init(PIOS_USART3_GPIO_PORT, &GPIO_InitStructure);
|
||||
|
||||
/* Enable USART clock */
|
||||
PIOS_USART3_CLK_FUNC;
|
||||
|
||||
/* Enable USART Receive interrupt */
|
||||
USART_InitStructure.USART_BaudRate = 115200;
|
||||
USART_Init(PIOS_USART3_USART, &USART_InitStructure);
|
||||
USART_ITConfig(PIOS_USART3_USART, USART_IT_RXNE, ENABLE);
|
||||
//USART_ITConfig(PIOS_USART3_USART, USART_IT_TXE, ENABLE);
|
||||
|
||||
/* Configure the USART Interrupts */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = PIOS_USART3_IRQ_CHANNEL;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PIOS_USART3_NVIC_PRIO;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
USART_ITConfig(PIOS_USART3_USART, USART_IT_RXNE, ENABLE);
|
||||
|
||||
/* Enable USART */
|
||||
USART_Cmd(PIOS_USART3_USART, ENABLE);
|
||||
}
|
||||
|
||||
|
||||
@ -125,6 +84,9 @@ int16_t PIOS_SPEKTRUM_Get(int8_t Channel)
|
||||
*/
|
||||
uint8_t PIOS_SPEKTRUM_Bind(void)
|
||||
{
|
||||
#define PIOS_USART3_GPIO_PORT GPIOA
|
||||
#define PIOS_USART3_RX_PIN GPIO_Pin_10
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_StructInit(&GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
@ -132,7 +94,7 @@ uint8_t PIOS_SPEKTRUM_Bind(void)
|
||||
GPIO_InitStructure.GPIO_Pin = PIOS_USART3_RX_PIN;
|
||||
GPIO_Init(PIOS_USART3_GPIO_PORT, &GPIO_InitStructure);
|
||||
/* GPIO's Off */
|
||||
/* powerup, RX line stay low for 75ms */
|
||||
/* TODO: powerup, RX line stay low for 75ms */
|
||||
/* system init takes longer!!! */
|
||||
/* I have no idea how long the powerup init window for satellite is but works with this */
|
||||
PIOS_USART3_GPIO_PORT->BRR = PIOS_USART3_RX_PIN;
|
||||
@ -211,7 +173,7 @@ int32_t PIOS_SPEKTRUM_Decode(uint8_t b)
|
||||
}
|
||||
if(bytecount==16)
|
||||
{
|
||||
//PIOS_COM_SendBufferNonBlocking(COM_DEBUG_USART,byte_array,16);
|
||||
//PIOS_COM_SendBufferNonBlocking(PIOS_COM_TELEM_RF,byte_array,16);
|
||||
bytecount=0;
|
||||
sync=0;
|
||||
}
|
||||
@ -220,20 +182,19 @@ int32_t PIOS_SPEKTRUM_Decode(uint8_t b)
|
||||
}
|
||||
|
||||
/* Interrupt handler for USART3 */
|
||||
PIOS_USART3_IRQHANDLER_FUNC
|
||||
void SPEKTRUM_IRQHandler(void)
|
||||
{
|
||||
/* check if RXNE flag is set */
|
||||
if(PIOS_USART3_USART->SR & (1 << 5)) {
|
||||
uint8_t b = PIOS_USART3_USART->DR;
|
||||
|
||||
if(USART1->SR & (1 << 5)) {
|
||||
uint8_t b = USART1->DR;
|
||||
if(PIOS_SPEKTRUM_Decode(b) < 0) {
|
||||
/* Here we could add some error handling */
|
||||
}
|
||||
}
|
||||
|
||||
if(PIOS_USART3_USART->SR & (1 << 7)) { // check if TXE flag is set
|
||||
if(USART1->SR & (1 << 7)) { // check if TXE flag is set
|
||||
/* Disable TXE interrupt (TXEIE=0) */
|
||||
PIOS_USART3_USART->CR1 &= ~(1 << 7);
|
||||
USART1->CR1 &= ~(1 << 7);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ extern void PIOS_SPEKTRUM_Init(void);
|
||||
extern uint8_t PIOS_SPEKTRUM_Bind(void);
|
||||
extern int32_t PIOS_SPEKTRUM_Decode(uint8_t b);
|
||||
extern int16_t PIOS_SPEKTRUM_Get(int8_t Channel);
|
||||
extern void SPEKTRUM_IRQHandler(void);
|
||||
|
||||
#endif /* PIOS_SPEKTRUM_H */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user