From c2910d0ce008e6eb85c1886e6c2fb8fe9520cd5c Mon Sep 17 00:00:00 2001 From: a*morale Date: Sun, 30 Sep 2012 20:54:10 +0200 Subject: [PATCH] Receiver input working for both PPM/PWM mode for rm2 --- flight/RevoMini/System/pios_board.c | 31 ++++- flight/board_hw_defs/revomini/board_hw_defs.c | 110 +++++++++++------- 2 files changed, 95 insertions(+), 46 deletions(-) diff --git a/flight/RevoMini/System/pios_board.c b/flight/RevoMini/System/pios_board.c index 4ca193b0b..ab072eba4 100644 --- a/flight/RevoMini/System/pios_board.c +++ b/flight/RevoMini/System/pios_board.c @@ -341,10 +341,11 @@ void PIOS_Board_Init(void) { PIOS_TIM_InitClock(&tim_3_cfg); PIOS_TIM_InitClock(&tim_4_cfg); PIOS_TIM_InitClock(&tim_5_cfg); + PIOS_TIM_InitClock(&tim_8_cfg); PIOS_TIM_InitClock(&tim_9_cfg); PIOS_TIM_InitClock(&tim_10_cfg); PIOS_TIM_InitClock(&tim_11_cfg); - + PIOS_TIM_InitClock(&tim_12_cfg); /* IAP System Setup */ PIOS_IAP_Init(); uint16_t boot_count = PIOS_IAP_ReadBootCount(); @@ -356,8 +357,8 @@ void PIOS_Board_Init(void) { HwSettingsSetDefaults(HwSettingsHandle(), 0); AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL); } - - + + //PIOS_IAP_Init(); #if defined(PIOS_INCLUDE_USB) @@ -470,8 +471,26 @@ void PIOS_Board_Init(void) { PIOS_Board_configure_com(&pios_usart_main_cfg, PIOS_COM_GPS_RX_BUF_LEN, -1, &pios_usart_com_driver, &pios_com_gps_id); break; case HWSETTINGS_CC_MAINPORT_SBUS: - // TODO - break; +#if defined(PIOS_INCLUDE_SBUS) + { + uint32_t pios_usart_sbus_id; + if (PIOS_USART_Init(&pios_usart_sbus_id, &pios_usart_sbus_main_cfg)) { + PIOS_Assert(0); + } + + uint32_t pios_sbus_id; + if (PIOS_SBus_Init(&pios_sbus_id, &pios_sbus_cfg, &pios_usart_com_driver, pios_usart_sbus_id)) { + PIOS_Assert(0); + } + + uint32_t pios_sbus_rcvr_id; + if (PIOS_RCVR_Init(&pios_sbus_rcvr_id, &pios_sbus_rcvr_driver, pios_sbus_id)) { + PIOS_Assert(0); + } + pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_SBUS] = pios_sbus_rcvr_id; + } +#endif + break; case HWSETTINGS_CC_MAINPORT_DSM2: case HWSETTINGS_CC_MAINPORT_DSMX10BIT: case HWSETTINGS_CC_MAINPORT_DSMX11BIT: @@ -618,7 +637,7 @@ void PIOS_Board_Init(void) { } pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_GCS] = pios_gcsrcvr_rcvr_id; #endif /* PIOS_INCLUDE_GCSRCVR */ - + #ifndef PIOS_DEBUG_ENABLE_DEBUG_PINS switch (hwsettings_rcvrport) { case HWSETTINGS_RV_RCVRPORT_DISABLED: diff --git a/flight/board_hw_defs/revomini/board_hw_defs.c b/flight/board_hw_defs/revomini/board_hw_defs.c index c2b33347a..d2958f2ad 100644 --- a/flight/board_hw_defs/revomini/board_hw_defs.c +++ b/flight/board_hw_defs/revomini/board_hw_defs.c @@ -962,17 +962,21 @@ static const struct pios_tim_clock_cfg tim_11_cfg = { }, }; -// Set up timers that only have inputs on APB2 -static const TIM_TimeBaseInitTypeDef tim_1_time_base = { - .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_CLOCK / 1000000) - 1, +// Set up timers that only have inputs on APB1 +// TIM2,3,4,5,6,7,12,13,14 +static const TIM_TimeBaseInitTypeDef tim_apb1_time_base = { + .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_CLOCK / 1000000) - 1, .TIM_ClockDivision = TIM_CKD_DIV1, .TIM_CounterMode = TIM_CounterMode_Up, .TIM_Period = 0xFFFF, .TIM_RepetitionCounter = 0x0000, }; + + // Set up timers that only have inputs on APB2 -static const TIM_TimeBaseInitTypeDef tim_4_time_base = { - .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_CLOCK / 1000000) - 1, +// TIM1,8,9,10,11 +static const TIM_TimeBaseInitTypeDef tim_apb2_time_base = { + .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_CLOCK / 1000000) - 1, .TIM_ClockDivision = TIM_CKD_DIV1, .TIM_CounterMode = TIM_CounterMode_Up, .TIM_Period = 0xFFFF, @@ -981,7 +985,7 @@ static const TIM_TimeBaseInitTypeDef tim_4_time_base = { static const struct pios_tim_clock_cfg tim_1_cfg = { .timer = TIM1, - .time_base_init = &tim_1_time_base, + .time_base_init = &tim_apb2_time_base, .irq = { .init = { .NVIC_IRQChannel = TIM1_CC_IRQn, @@ -994,7 +998,7 @@ static const struct pios_tim_clock_cfg tim_1_cfg = { static const struct pios_tim_clock_cfg tim_4_cfg = { .timer = TIM4, - .time_base_init = &tim_4_time_base, + .time_base_init = &tim_apb1_time_base, .irq = { .init = { .NVIC_IRQChannel = TIM4_IRQn, @@ -1004,6 +1008,32 @@ static const struct pios_tim_clock_cfg tim_4_cfg = { }, }, }; +static const struct pios_tim_clock_cfg tim_8_cfg = { + .timer = TIM8, + .time_base_init = &tim_apb2_time_base, + .irq = { + .init = { + .NVIC_IRQChannel = TIM8_CC_IRQn, + .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID, + .NVIC_IRQChannelSubPriority = 0, + .NVIC_IRQChannelCmd = ENABLE, + }, + }, +}; + +static const struct pios_tim_clock_cfg tim_12_cfg = { + .timer = TIM12, + .time_base_init = &tim_apb1_time_base, + .irq = { + .init = { + .NVIC_IRQChannel = TIM8_BRK_TIM12_IRQn, + .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID, + .NVIC_IRQChannelSubPriority = 0, + .NVIC_IRQChannelCmd = ENABLE, + }, + }, +}; + /** * Pios servo configuration structures @@ -1133,50 +1163,50 @@ const struct pios_servo_cfg pios_servo_cfg = { #include static const struct pios_tim_channel pios_tim_rcvrport_all_channels[] = { { - .timer = TIM1, + .timer = TIM12, .timer_chan = TIM_Channel_1, .pin = { - .gpio = GPIOA, + .gpio = GPIOB, .init = { - .GPIO_Pin = GPIO_Pin_8, + .GPIO_Pin = GPIO_Pin_14, .GPIO_Speed = GPIO_Speed_2MHz, .GPIO_Mode = GPIO_Mode_AF, .GPIO_OType = GPIO_OType_PP, .GPIO_PuPd = GPIO_PuPd_UP }, - .pin_source = GPIO_PinSource8, + .pin_source = GPIO_PinSource14, }, - .remap = GPIO_AF_TIM1, + .remap = GPIO_AF_TIM12, + }, + { + .timer = TIM12, + .timer_chan = TIM_Channel_2, + .pin = { + .gpio = GPIOB, + .init = { + .GPIO_Pin = GPIO_Pin_15, + .GPIO_Speed = GPIO_Speed_2MHz, + .GPIO_Mode = GPIO_Mode_AF, + .GPIO_OType = GPIO_OType_PP, + .GPIO_PuPd = GPIO_PuPd_UP + }, + .pin_source = GPIO_PinSource15, + }, + .remap = GPIO_AF_TIM12, }, { .timer = TIM8, - .timer_chan = TIM_Channel_4, + .timer_chan = TIM_Channel_1, .pin = { .gpio = GPIOC, .init = { - .GPIO_Pin = GPIO_Pin_9, + .GPIO_Pin = GPIO_Pin_6, .GPIO_Speed = GPIO_Speed_2MHz, .GPIO_Mode = GPIO_Mode_AF, .GPIO_OType = GPIO_OType_PP, .GPIO_PuPd = GPIO_PuPd_UP }, - .pin_source = GPIO_PinSource9, - }, - .remap = GPIO_AF_TIM8, - }, - { - .timer = TIM8, - .timer_chan = TIM_Channel_3, - .pin = { - .gpio = GPIOC, - .init = { - .GPIO_Pin = GPIO_Pin_8, - .GPIO_Speed = GPIO_Speed_2MHz, - .GPIO_Mode = GPIO_Mode_AF, - .GPIO_OType = GPIO_OType_PP, - .GPIO_PuPd = GPIO_PuPd_UP - }, - .pin_source = GPIO_PinSource8, + .pin_source = GPIO_PinSource6, }, .remap = GPIO_AF_TIM8, }, @@ -1198,35 +1228,35 @@ static const struct pios_tim_channel pios_tim_rcvrport_all_channels[] = { }, { .timer = TIM8, - .timer_chan = TIM_Channel_1, + .timer_chan = TIM_Channel_3, .pin = { .gpio = GPIOC, .init = { - .GPIO_Pin = GPIO_Pin_6, + .GPIO_Pin = GPIO_Pin_8, .GPIO_Speed = GPIO_Speed_2MHz, .GPIO_Mode = GPIO_Mode_AF, .GPIO_OType = GPIO_OType_PP, .GPIO_PuPd = GPIO_PuPd_UP }, - .pin_source = GPIO_PinSource6, + .pin_source = GPIO_PinSource8, }, .remap = GPIO_AF_TIM8, }, { - .timer = TIM12, - .timer_chan = TIM_Channel_2, + .timer = TIM8, + .timer_chan = TIM_Channel_4, .pin = { - .gpio = GPIOB, + .gpio = GPIOC, .init = { - .GPIO_Pin = GPIO_Pin_15, + .GPIO_Pin = GPIO_Pin_9, .GPIO_Speed = GPIO_Speed_2MHz, .GPIO_Mode = GPIO_Mode_AF, .GPIO_OType = GPIO_OType_PP, .GPIO_PuPd = GPIO_PuPd_UP }, - .pin_source = GPIO_PinSource15, + .pin_source = GPIO_PinSource9, }, - .remap = GPIO_AF_TIM12, + .remap = GPIO_AF_TIM8, }, };