From 286cecb2bf08c5538cfe13053246b0d8b78b2df4 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 16 Apr 2011 02:59:55 +0200 Subject: Test ppmsum decoding. --- board.h | 2 +- halconf.h | 2 ++ main.cpp | 32 ++++++++++++++++++++++++++++++++ mcuconf.h | 14 ++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/board.h b/board.h index c0b01d0..9034d20 100644 --- a/board.h +++ b/board.h @@ -47,7 +47,7 @@ * PB14 - Normal input (MMC SPI2 MISO). * PB15 - Alternate output (MMC SPI2 MOSI). */ -#define VAL_GPIOBCRL 0x88888888 /* PB7...PB0 */ +#define VAL_GPIOBCRL 0x84888888 /* PB7...PB0 */ #define VAL_GPIOBCRH 0xB4B84488 /* PB15...PB8 */ #define VAL_GPIOBODR 0xFFFFFFFF diff --git a/halconf.h b/halconf.h index d10e1fe..1b0e3dd 100644 --- a/halconf.h +++ b/halconf.h @@ -69,6 +69,8 @@ #define HAL_USE_I2C TRUE #endif +#define HAL_USE_ICU TRUE + /** * @brief Enables the MAC subsystem. */ diff --git a/main.cpp b/main.cpp index 27fab50..57d3d17 100644 --- a/main.cpp +++ b/main.cpp @@ -170,12 +170,44 @@ static PWMConfig pwmcfg = { 0 }; +icucnt_t last_width, last_period; + +int16_t ppm_input[4]; + +int ppm_n = 0; + +static void icuwidthcb(ICUDriver *icup) { + + last_width = icuGetWidthI(icup); + ppm_input[ppm_n] = last_width; +} + +static void icuperiodcb(ICUDriver *icup) { + + last_period = icuGetPeriodI(icup); + if(last_period > 5000) { + ppm_n = 0; + } else { + ppm_n = (ppm_n + 1) % 4; + } +} + +static ICUConfig icucfg = { + ICU_INPUT_ACTIVE_HIGH, + 1000000, + icuwidthcb, + icuperiodcb +}; + int main(void) { halInit(); chSysInit(); led_thread.start(); + icuStart(&ICUD4, &icucfg); + icuEnable(&ICUD4); + usbs.init(); i2c_thread.start(); diff --git a/mcuconf.h b/mcuconf.h index 74b6346..40be2cc 100644 --- a/mcuconf.h +++ b/mcuconf.h @@ -74,6 +74,20 @@ #define STM32_GPT_TIM4_IRQ_PRIORITY 7 #define STM32_GPT_TIM5_IRQ_PRIORITY 7 +/* + * ICU driver system settings. + */ +#define STM32_ICU_USE_TIM1 FALSE +#define STM32_ICU_USE_TIM2 FALSE +#define STM32_ICU_USE_TIM3 FALSE +#define STM32_ICU_USE_TIM4 TRUE +#define STM32_ICU_USE_TIM5 FALSE +#define STM32_ICU_TIM1_IRQ_PRIORITY 7 +#define STM32_ICU_TIM2_IRQ_PRIORITY 7 +#define STM32_ICU_TIM3_IRQ_PRIORITY 7 +#define STM32_ICU_TIM4_IRQ_PRIORITY 7 +#define STM32_ICU_TIM5_IRQ_PRIORITY 7 + /* * PWM driver system settings. */ -- cgit v1.2.3