From a3112b231ca7d65b08e0758c400e3edb739b0a19 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 22 Nov 2016 07:49:04 -0600 Subject: [PATCH] nucleo-l476rg: Add better selection of timer. --- configs/nucleo-l476rg/Kconfig | 5 -- configs/nucleo-l476rg/src/stm32_appinit.c | 72 ++++++++++++++++++++++- 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/configs/nucleo-l476rg/Kconfig b/configs/nucleo-l476rg/Kconfig index 8edd703e42..7361b3f490 100644 --- a/configs/nucleo-l476rg/Kconfig +++ b/configs/nucleo-l476rg/Kconfig @@ -5,11 +5,6 @@ if ARCH_BOARD_NUCLEO_L476RG -config NUCLEO_L476RG_QETIMER - int "Timer to use with QE encoder" - default 3 - depends on QENCODER - config NUCLEO_L476RG_AJOY_MINBUTTONS bool "Minimal Joystick Buttons" default n if !STM32_USART1 diff --git a/configs/nucleo-l476rg/src/stm32_appinit.c b/configs/nucleo-l476rg/src/stm32_appinit.c index ceeca0eff3..ab2665bc73 100644 --- a/configs/nucleo-l476rg/src/stm32_appinit.c +++ b/configs/nucleo-l476rg/src/stm32_appinit.c @@ -111,6 +111,10 @@ int board_app_initialize(uintptr_t arg) { #ifdef HAVE_RTC_DRIVER FAR struct rtc_lowerhalf_s *rtclower; +#endif +#ifdef CONFIG_QENCODER + int index; + char buf[9]; #endif int ret; @@ -219,9 +223,14 @@ int board_app_initialize(uintptr_t arg) #endif #ifdef CONFIG_QENCODER + /* Initialize and register the qencoder driver */ - ret = stm32l4_qencoder_initialize("/dev/qe0", CONFIG_NUCLEO_L476RG_QETIMER); + index = 0; + +#ifdef CONFIG_STM32L4_TIM1_QE + sprintf(buf, "/dev/qe%d", index++); + ret = stm32l4_qencoder_initialize(buf, 1); if (ret != OK) { syslog(LOG_ERR, @@ -231,6 +240,67 @@ int board_app_initialize(uintptr_t arg) } #endif +#ifdef CONFIG_STM32L4_TIM2_QE + sprintf(buf, "/dev/qe%d", index++); + ret = stm32l4_qencoder_initialize(buf, 2); + if (ret != OK) + { + syslog(LOG_ERR, + "ERROR: Failed to register the qencoder: %d\n", + ret); + return ret; + } +#endif + +#ifdef CONFIG_STM32L4_TIM3_QE + sprintf(buf, "/dev/qe%d", index++); + ret = stm32l4_qencoder_initialize(buf, 3); + if (ret != OK) + { + syslog(LOG_ERR, + "ERROR: Failed to register the qencoder: %d\n", + ret); + return ret; + } +#endif + +#ifdef CONFIG_STM32L4_TIM4_QE + sprintf(buf, "/dev/qe%d", index++); + ret = stm32l4_qencoder_initialize(buf, 4); + if (ret != OK) + { + syslog(LOG_ERR, + "ERROR: Failed to register the qencoder: %d\n", + ret); + return ret; + } +#endif + +#ifdef CONFIG_STM32L4_TIM5_QE + sprintf(buf, "/dev/qe%d", index++); + ret = stm32l4_qencoder_initialize(buf, 5); + if (ret != OK) + { + syslog(LOG_ERR, + "ERROR: Failed to register the qencoder: %d\n", + ret); + return ret; + } +#endif + +#ifdef CONFIG_STM32L4_TIM8_QE + sprintf(buf, "/dev/qe%d", index++); + ret = stm32l4_qencoder_initialize(buf, 8); + if (ret != OK) + { + syslog(LOG_ERR, + "ERROR: Failed to register the qencoder: %d\n", + ret); + return ret; + } +#endif + +#endif return OK; }