mirror of
https://github.com/apache/nuttx.git
synced 2026-06-08 01:42:58 +08:00
The examples/qencoder app was trying to init the encoder by a direct call into the board, cheating in a local header to declare the normally unavailable function prototype.
This commit is contained in:
committed by
Gregory Nutt
parent
ef1fc550b7
commit
dfa2d107b2
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************************************
|
||||
* configs/mikroe-stm32f4/src/mikroe-stm32f4.h
|
||||
*
|
||||
* Copyright (C) 2011-2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2011-2013, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -240,6 +240,18 @@ void weak_function stm32_usbinitialize(void);
|
||||
# error "The Mikroe-STM32F4 board does not support HOST OTG, only device!"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_qencoder_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register a qencoder
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_QENCODER
|
||||
int stm32_qencoder_initialize(FAR const char *devpath, int timer);
|
||||
#endif
|
||||
|
||||
/****************************************************************************************************
|
||||
* Name: stm32_lcdinitialize
|
||||
*
|
||||
|
||||
@@ -180,11 +180,7 @@ int board_app_initialize(uintptr_t arg)
|
||||
FAR struct spi_dev_s *spi;
|
||||
FAR struct mtd_dev_s *mtd;
|
||||
#endif
|
||||
#if defined(NSH_HAVEMMCSD) || defined(HAVE_USBHOST) || \
|
||||
defined(HAVE_USBMONITOR) || defined(CONFIG_LCD_MIO283QT2) || \
|
||||
defined(CONFIG_LCD_MIO283QT9A)
|
||||
int ret;
|
||||
#endif
|
||||
int ret = OK;
|
||||
|
||||
/* Configure SPI-based devices */
|
||||
|
||||
@@ -367,13 +363,24 @@ int board_app_initialize(uintptr_t arg)
|
||||
|
||||
#endif
|
||||
|
||||
/* Configure the Audio sub-system if enabled and bind it to SPI 3 */
|
||||
|
||||
#ifdef CONFIG_AUDIO
|
||||
|
||||
up_vs1053initialize(spi);
|
||||
#ifdef CONFIG_QENCODER
|
||||
/* Initialize and register the qencoder driver */
|
||||
|
||||
ret = stm32_qencoder_initialize("/dev/qe0", 3);
|
||||
if (ret != OK)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Failed to register the qencoder: %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
#ifdef CONFIG_AUDIO
|
||||
/* Configure the Audio sub-system if enabled and bind it to SPI 3 */
|
||||
|
||||
up_vs1053initialize(spi);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/************************************************************************************
|
||||
* configs/mikroe_stm32f4/src/stm32_qencoder.c
|
||||
*
|
||||
* Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2012-2013, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -50,83 +50,12 @@
|
||||
#include "stm32_qencoder.h"
|
||||
#include "mikroe-stm32f4.h"
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
/* Configuration *******************************************************************/
|
||||
/* Check if we have a timer configured for quadrature encoder -- assume YES. */
|
||||
|
||||
#define HAVE_QENCODER 1
|
||||
|
||||
/* 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
|
||||
|
||||
/* 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
|
||||
|
||||
#ifdef HAVE_QENCODER
|
||||
|
||||
/************************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: qe_devinit
|
||||
* Name: stm32_qencoder_initialize
|
||||
*
|
||||
* Description:
|
||||
* All STM32 architectures must provide the following interface to work with
|
||||
@@ -134,29 +63,20 @@
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int qe_devinit(void)
|
||||
int stm32_qencoder_initialize(FAR const char *devpath, int timer)
|
||||
{
|
||||
static bool initialized = false;
|
||||
int ret;
|
||||
|
||||
/* Check if we are already initialized */
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
if (!initialized)
|
||||
sninfo("Initializing the quadrature encoder using TIM%d\n", timer);
|
||||
ret = stm32_qeinitialize(devpath, timer);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
sninfo("Initializing the quadrature encoder using TIM%d\n", TIMID);
|
||||
ret = stm32_qeinitialize("/dev/qe0", TIMID);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* HAVE_QENCODER */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/************************************************************************************
|
||||
* configs/nucleo-f4x1re/src/nucleo-f4x1re.h
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
|
||||
* Authors: Frank Bennett
|
||||
* Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
@@ -320,6 +320,18 @@ void stm32_usbinitialize(void);
|
||||
int board_adc_initialize(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_qencoder_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register a qencoder
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_QENCODER
|
||||
int stm32_qencoder_initialize(FAR const char *devpath, int timer);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_ajoy_initialize
|
||||
*
|
||||
|
||||
@@ -55,18 +55,6 @@
|
||||
|
||||
#include "nucleo-f4x1re.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@@ -112,9 +100,7 @@ void up_netinitialize(void)
|
||||
|
||||
int board_app_initialize(uintptr_t arg)
|
||||
{
|
||||
#if defined(HAVE_MMCSD) || defined(CONFIG_AJOYSTICK)
|
||||
int ret;
|
||||
#endif
|
||||
int ret = OK;
|
||||
|
||||
/* Configure CPU load estimation */
|
||||
|
||||
@@ -153,6 +139,19 @@ int board_app_initialize(uintptr_t arg)
|
||||
syslog(LOG_INFO, "[boot] Initialized SDIO\n");
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_QENCODER
|
||||
/* Initialize and register the qencoder driver */
|
||||
|
||||
ret = stm32_qencoder_initialize("/dev/qe0", 3);
|
||||
if (ret != OK)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Failed to register the qencoder: %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_AJOYSTICK
|
||||
/* Initialize and register the joystick driver */
|
||||
|
||||
@@ -166,5 +165,5 @@ int board_app_initialize(uintptr_t arg)
|
||||
}
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/************************************************************************************
|
||||
* configs/stm32f4discovery/src/stm32_qencoder.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -50,79 +50,12 @@
|
||||
#include "stm32_qencoder.h"
|
||||
#include "nucleo-f4x1re.h"
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
/* Configuration *******************************************************************/
|
||||
/* Check if we have a timer configured for quadrature encoder -- assume YES. */
|
||||
|
||||
#define HAVE_QENCODER 1
|
||||
|
||||
/* 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
|
||||
|
||||
/* 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
|
||||
|
||||
#ifdef HAVE_QENCODER
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: qe_devinit
|
||||
* Name: stm32_qencoder_initialize
|
||||
*
|
||||
* Description:
|
||||
* All STM32 architectures must provide the following interface to work with
|
||||
@@ -130,29 +63,20 @@
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int qe_devinit(void)
|
||||
int stm32_qencoder_initialize(FAR const char *devpath, int timer)
|
||||
{
|
||||
static bool initialized = false;
|
||||
int ret;
|
||||
|
||||
/* Check if we are already initialized */
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
if (!initialized)
|
||||
sninfo("Initializing the quadrature encoder using TIM%d\n", timer);
|
||||
ret = stm32_qeinitialize(devpath, timer);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
sninfo("Initializing the quadrature encoder using TIM%d\n", TIMID);
|
||||
ret = stm32_qeinitialize("/dev/qe0", TIMID);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* HAVE_QENCODER */
|
||||
|
||||
@@ -363,4 +363,16 @@ int board_ajoy_initialize(void);
|
||||
int board_timer_driver_initialize(FAR const char *devpath, int timer);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32l4_qencoder_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register a qencoder
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_QENCODER
|
||||
int stm32l4_qencoder_initialize(FAR const char *devpath, int timer);
|
||||
#endif
|
||||
|
||||
#endif /* __CONFIGS_NUCLEO_L476RG_SRC_NUCLEO_L476RG_H */
|
||||
|
||||
@@ -218,6 +218,19 @@ int board_app_initialize(uintptr_t arg)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_QENCODER
|
||||
/* Initialize and register the qencoder driver */
|
||||
|
||||
ret = stm32l4_qencoder_initialize("/dev/qe0", 3);
|
||||
if (ret != OK)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Failed to register the qencoder: %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,73 +53,6 @@
|
||||
#include "stm32l4_qencoder.h"
|
||||
#include "nucleo-l476rg.h"
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
/* Configuration *******************************************************************/
|
||||
/* Check if we have a timer configured for quadrature encoder -- assume YES. */
|
||||
|
||||
#define HAVE_QENCODER 1
|
||||
|
||||
/* If TIMn is not enabled (via CONFIG_STM32L4_TIMn), then the configuration cannot
|
||||
* specify TIMn as a quadrature encoder (via CONFIG_STM32L4_TIMn_QE).
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_STM32L4_TIM1
|
||||
# undef CONFIG_STM32L4_TIM1_QE
|
||||
#endif
|
||||
#ifndef CONFIG_STM32L4_TIM2
|
||||
# undef CONFIG_STM32L4_TIM2_QE
|
||||
#endif
|
||||
#ifndef CONFIG_STM32L4_TIM3
|
||||
# undef CONFIG_STM32L4_TIM3_QE
|
||||
#endif
|
||||
#ifndef CONFIG_STM32L4_TIM4
|
||||
# undef CONFIG_STM32L4_TIM4_QE
|
||||
#endif
|
||||
#ifndef CONFIG_STM32L4_TIM5
|
||||
# undef CONFIG_STM32L4_TIM5_QE
|
||||
#endif
|
||||
#ifndef CONFIG_STM32L4_TIM8
|
||||
# undef CONFIG_STM32L4_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
|
||||
|
||||
/* 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_STM32L4_TIMn_QE
|
||||
* is defined, then the correspdonding TIMn is also enabled.
|
||||
*/
|
||||
|
||||
#if defined CONFIG_STM32L4_TIM1_QE
|
||||
# define TIMID 1
|
||||
#elif defined CONFIG_STM32L4_TIM2_QE
|
||||
# define TIMID 2
|
||||
#elif defined CONFIG_STM32L4_TIM3_QE
|
||||
# define TIMID 3
|
||||
#elif defined CONFIG_STM32L4_TIM4_QE
|
||||
# define TIMID 4
|
||||
#elif defined CONFIG_STM32L4_TIM5_QE
|
||||
# define TIMID 5
|
||||
#elif defined CONFIG_STM32L4_TIM8_QE
|
||||
# define TIMID 8
|
||||
#else
|
||||
# undef HAVE_QENCODER
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_QENCODER
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
@@ -133,29 +66,18 @@
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int qe_devinit(void)
|
||||
int stm32l4_qencoder_initialize(FAR const char *devpath, int timer)
|
||||
{
|
||||
static bool initialized = false;
|
||||
int ret;
|
||||
|
||||
/* Check if we are already initialized */
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
if (!initialized)
|
||||
sninfo("Initializing the quadrature encoder using TIM%d\n", timer);
|
||||
ret = stm32l4_qeinitialize(devpath, timer);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
sninfo("Initializing the quadrature encoder using TIM%d\n", TIMID);
|
||||
ret = stm32l4_qeinitialize("/dev/qe0", TIMID);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
snerr("ERROR: stm32l4_qeinitialize failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* HAVE_QENCODER */
|
||||
|
||||
@@ -115,9 +115,9 @@
|
||||
|
||||
int board_app_initialize(uintptr_t arg)
|
||||
{
|
||||
#ifdef HAVE_USBMONITOR
|
||||
int ret;
|
||||
int ret = OK;
|
||||
|
||||
#ifdef HAVE_USBMONITOR
|
||||
/* Start the USB Monitor */
|
||||
|
||||
ret = usbmonitor_start();
|
||||
@@ -127,5 +127,18 @@ int board_app_initialize(uintptr_t arg)
|
||||
}
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
#ifdef CONFIG_QENCODER
|
||||
/* Initialize and register the qencoder driver */
|
||||
|
||||
ret = stm32_qencoder_initialize("/dev/qe0", 3);
|
||||
if (ret != OK)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Failed to register the qencoder: %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/************************************************************************************
|
||||
* configs/stm32f3discovery/src/stm32_qencoder.c
|
||||
*
|
||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -50,83 +50,12 @@
|
||||
#include "stm32_qencoder.h"
|
||||
#include "stm32f3discovery.h"
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
/* Configuration *******************************************************************/
|
||||
/* Check if we have a timer configured for quadrature encoder -- assume YES. */
|
||||
|
||||
#define HAVE_QENCODER 1
|
||||
|
||||
/* 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
|
||||
|
||||
/* 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
|
||||
|
||||
#ifdef HAVE_QENCODER
|
||||
|
||||
/************************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: qe_devinit
|
||||
* Name: stm32_qencoder_initialize
|
||||
*
|
||||
* Description:
|
||||
* All STM32 architectures must provide the following interface to work with
|
||||
@@ -134,29 +63,20 @@
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int qe_devinit(void)
|
||||
int stm32_qencoder_initialize(FAR const char *devpath, int timer)
|
||||
{
|
||||
static bool initialized = false;
|
||||
int ret;
|
||||
|
||||
/* Check if we are already initialized */
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
if (!initialized)
|
||||
sninfo("Initializing the quadrature encoder using TIM%d\n", timer);
|
||||
ret = stm32_qeinitialize(devpath, timer);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
sninfo("Initializing the quadrature encoder using TIM%d\n", TIMID);
|
||||
ret = stm32_qeinitialize("/dev/qe0", TIMID);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* HAVE_QENCODER */
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* configs/stm32f3discovery/src/stm32f3discovery.h
|
||||
* arch/arm/src/board/stm32f3discovery.n
|
||||
*
|
||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -162,6 +162,18 @@ void weak_function stm32_spidev_initialize(void);
|
||||
void weak_function stm32_usbinitialize(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_qencoder_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register a qencoder
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_QENCODER
|
||||
int stm32_qencoder_initialize(FAR const char *devpath, int timer);
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __CONFIGS_STM32F3DISCOVERY_SRC_STM32F3DISCOVERY_H */
|
||||
|
||||
|
||||
@@ -159,6 +159,19 @@ int stm32_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_QENCODER
|
||||
/* Initialize and register the qencoder driver */
|
||||
|
||||
ret = stm32_qencoder_initialize("/dev/qe0", 3);
|
||||
if (ret != OK)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Failed to register the qencoder: %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RTC_DRIVER
|
||||
/* Instantiate the STM32 lower-half RTC driver */
|
||||
|
||||
|
||||
@@ -50,79 +50,12 @@
|
||||
#include "stm32_qencoder.h"
|
||||
#include "stm32f4discovery.h"
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
/* Configuration *******************************************************************/
|
||||
/* Check if we have a timer configured for quadrature encoder -- assume YES. */
|
||||
|
||||
#define HAVE_QENCODER 1
|
||||
|
||||
/* 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
|
||||
|
||||
/* 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
|
||||
|
||||
#ifdef HAVE_QENCODER
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: qe_devinit
|
||||
* Name: stm32_qencoder_initialize
|
||||
*
|
||||
* Description:
|
||||
* All STM32 architectures must provide the following interface to work with
|
||||
@@ -130,29 +63,20 @@
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int qe_devinit(void)
|
||||
int stm32_qencoder_initialize(FAR const char *devpath, int timer)
|
||||
{
|
||||
static bool initialized = false;
|
||||
int ret;
|
||||
|
||||
/* Check if we are already initialized */
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
if (!initialized)
|
||||
sninfo("Initializing the quadrature encoder using TIM%d\n", timer);
|
||||
ret = stm32_qeinitialize(devpath, timer);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
sninfo("Initializing the quadrature encoder using TIM%d\n", TIMID);
|
||||
ret = stm32_qeinitialize("/dev/qe0", TIMID);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* HAVE_QENCODER */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* configs/stm32f4discovery/src/stm32f4discovery.h
|
||||
*
|
||||
* Copyright (C) 2011-2012, 2015 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2011-2012, 2015-2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -564,6 +564,18 @@ int stm32_sdio_initialize(void);
|
||||
void weak_function stm32_netinitialize(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_qencoder_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register a qencoder
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_QENCODER
|
||||
int stm32_qencoder_initialize(FAR const char *devpath, int timer);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_zerocross_initialize
|
||||
*
|
||||
|
||||
@@ -47,10 +47,6 @@
|
||||
|
||||
#include "stm32ldiscovery.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@@ -82,11 +78,30 @@
|
||||
|
||||
int board_app_initialize(uintptr_t arg)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
#ifdef CONFIG_STM32_LCD
|
||||
/* Initialize the SLCD and register the SLCD device as /dev/slcd */
|
||||
|
||||
return stm32_slcd_initialize();
|
||||
#else
|
||||
return OK;
|
||||
ret = stm32_slcd_initialize();
|
||||
if (ret != OK)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: stm32_slcd_initialize failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_QENCODER
|
||||
/* Initialize and register the qencoder driver */
|
||||
|
||||
ret = stm32_qencoder_initialize("/dev/qe0", 3);
|
||||
if (ret != OK)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Failed to register the qencoder: %d\n",
|
||||
ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/************************************************************************************
|
||||
* configs/stm32ldiscovery/src/up_qencoder.c
|
||||
* arch/arm/src/board/up_qencoder.c
|
||||
*
|
||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -51,79 +50,12 @@
|
||||
#include "stm32_qencoder.h"
|
||||
#include "stm32ldiscovery.h"
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
/* Configuration *******************************************************************/
|
||||
/* Check if we have a timer configured for quadrature encoder -- assume YES. */
|
||||
|
||||
#define HAVE_QENCODER 1
|
||||
|
||||
/* 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
|
||||
|
||||
/* 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
|
||||
|
||||
#ifdef HAVE_QENCODER
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: qe_devinit
|
||||
* Name: stm32_qencoder_initialize
|
||||
*
|
||||
* Description:
|
||||
* All STM32 architectures must provide the following interface to work with
|
||||
@@ -131,29 +63,20 @@
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int qe_devinit(void)
|
||||
int stm32_qencoder_initialize(FAR const char *devpath, int timer)
|
||||
{
|
||||
static bool initialized = false;
|
||||
int ret;
|
||||
|
||||
/* Check if we are already initialized */
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
if (!initialized)
|
||||
sninfo("Initializing the quadrature encoder using TIM%d\n", timer);
|
||||
ret = stm32_qeinitialize(devpath, timer);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
sninfo("Initializing the quadrature encoder using TIM%d\n", TIMID);
|
||||
ret = stm32_qeinitialize("/dev/qe0", TIMID);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* HAVE_QENCODER */
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* configs/stm32ldiscovery/src/stm32ldiscovery.h
|
||||
* arch/arm/src/board/stm32ldiscovery.h
|
||||
*
|
||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -243,6 +243,18 @@
|
||||
|
||||
void weak_function stm32_spidev_initialize(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_qencoder_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register a qencoder
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_QENCODER
|
||||
int stm32_qencoder_initialize(FAR const char *devpath, int timer);
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __CONFIGS_STM32F3DISCOVERY_SRC_STM32F3DISCOVERY_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user