diff options
Diffstat (limited to 'nuttx/configs')
-rwxr-xr-x | nuttx/configs/stm32f4discovery/include/board.h | 5 | ||||
-rw-r--r-- | nuttx/configs/stm32f4discovery/src/up_qencoder.c | 59 |
2 files changed, 55 insertions, 9 deletions
diff --git a/nuttx/configs/stm32f4discovery/include/board.h b/nuttx/configs/stm32f4discovery/include/board.h index a34f22109..414c78a64 100755 --- a/nuttx/configs/stm32f4discovery/include/board.h +++ b/nuttx/configs/stm32f4discovery/include/board.h @@ -2,7 +2,7 @@ * configs/stm32f4discovery/include/board.h * include/arch/board/board.h * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -233,6 +233,9 @@ #define GPIO_TIM2_CH1IN GPIO_TIM2_CH1IN_2 #define GPIO_TIM2_CH2IN GPIO_TIM2_CH2IN_1 +#define GPIO_TIM8_CH1IN GPIO_TIM8_CH1IN_1 +#define GPIO_TIM8_CH2IN GPIO_TIM8_CH2IN_1 + /************************************************************************************ * Public Data ************************************************************************************/ diff --git a/nuttx/configs/stm32f4discovery/src/up_qencoder.c b/nuttx/configs/stm32f4discovery/src/up_qencoder.c index 60d4d760e..4963dadb7 100644 --- a/nuttx/configs/stm32f4discovery/src/up_qencoder.c +++ b/nuttx/configs/stm32f4discovery/src/up_qencoder.c @@ -55,21 +55,64 @@ * Definitions ************************************************************************************/ /* Configuration *******************************************************************/ -/* The following checks assum that the quadrature encoder is on TIM2. Make the - * appropriate changes if your configuration differes. - */ +/* Check if we have a timer configured for quadrature encoder -- assume YES. */ #define HAVE_QENCODER 1 -#ifndef CONFIG_QENCODER -# undef HAVE_QENCODER -#endif +/* If TIMn is not enabled (via CONFIG_STM32_TIMn), then the configuration cannot + * specify TIMn as a quadrature encoder (via CONFIG_STM32_TIMn_QE). + */ +#ifndef CONFIG_STM32_TIM1 +# undef CONFIG_STM32_TIM1_QE +#endif #ifndef CONFIG_STM32_TIM2 +# undef CONFIG_STM32_TIM2_QE +#endif +#ifndef CONFIG_STM32_TIM3 +# undef CONFIG_STM32_TIM3_QE +#endif +#ifndef CONFIG_STM32_TIM4 +# undef CONFIG_STM32_TIM4_QE +#endif +#ifndef CONFIG_STM32_TIM5 +# undef CONFIG_STM32_TIM5_QE +#endif +#ifndef CONFIG_STM32_TIM8 +# undef CONFIG_STM32_TIM8_QE +#endif + +/* If the upper-half quadrature encoder driver is not enabled, then we cannot + * support the quadrature encoder. + */ + +#ifndef CONFIG_QENCODER # undef HAVE_QENCODER #endif -#ifndef CONFIG_STM32_TIM2_QE +/* Which Timer should we use, TIMID={1,2,3,4,5,8}. If multiple timers are + * configured as quadrature encoders, this logic will arbitrarily select + * the lowest numbered timer. + * + * At least one TIMn, n={1,2,3,4,5,8}, must be both enabled and configured + * as a quadrature encoder in order to support the lower half quadrature + * encoder driver. The above check assures that if CONFIG_STM32_TIMn_QE + * is defined, then the correspdonding TIMn is also enabled. + */ + +#if defined CONFIG_STM32_TIM1_QE +# define TIMID 1 +#elif defined CONFIG_STM32_TIM2_QE +# define TIMID 2 +#elif defined CONFIG_STM32_TIM3_QE +# define TIMID 3 +#elif defined CONFIG_STM32_TIM4_QE +# define TIMID 4 +#elif defined CONFIG_STM32_TIM5_QE +# define TIMID 5 +#elif defined CONFIG_STM32_TIM8_QE +# define TIMID 8 +#else # undef HAVE_QENCODER #endif @@ -128,7 +171,7 @@ int qe_devinit(void) /* Initialize a quadrature encoder interface. */ qevdbg("Initializing the quadrature encoder\n"); - ret = stm32_qeinitialize("/dev/qe0", 2); + ret = stm32_qeinitialize("/dev/qe0", TIMID); if (ret < 0) { qedbg("stm32_qeinitialize failed: %d\n", ret); |