提交 b76d3dac 编写于 作者: T tangweikang

[components][drivers] change name: encoder -> pulse_encoder

上级 05b1dff0
......@@ -85,8 +85,8 @@ if GetDepend(['BSP_USING_SDIO']):
if GetDepend(['BSP_USING_USBD_FS']):
src += ['drv_usbd_fs.c']
if GetDepend(['BSP_USING_ENCODER']):
src += ['drv_encoder.c']
if GetDepend(['BSP_USING_PULSE_ENCODER']):
src += ['drv_pulse_encoder.c']
src += ['drv_common.c']
......
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-08-23 balanceTWK first version
*/
#ifndef __ENCODER_CONFIG_H__
#define __ENCODER_CONFIG_H__
#include <rtthread.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef BSP_USING_ENCODER1
#ifndef ENCODER1_CONFIG
#define ENCODER1_CONFIG \
{ \
.tim_handler.Instance = TIM1, \
.name = "encoder1" \
}
#endif /* ENCODER1_CONFIG */
#endif /* BSP_USING_ENCODER1 */
#ifdef BSP_USING_ENCODER2
#ifndef ENCODER2_CONFIG
#define ENCODER2_CONFIG \
{ \
.tim_handler.Instance = TIM2, \
.name = "encoder2" \
}
#endif /* ENCODER2_CONFIG */
#endif /* BSP_USING_ENCODER2 */
#ifdef BSP_USING_ENCODER3
#ifndef ENCODER3_CONFIG
#define ENCODER3_CONFIG \
{ \
.tim_handler.Instance = TIM3, \
.name = "encoder3" \
}
#endif /* ENCODER3_CONFIG */
#endif /* BSP_USING_ENCODER3 */
#ifdef BSP_USING_ENCODER4
#ifndef ENCODER4_CONFIG
#define ENCODER4_CONFIG \
{ \
.tim_handler.Instance = TIM4, \
.name = "encoder4" \
}
#endif /* ENCODER4_CONFIG */
#endif /* BSP_USING_ENCODER4 */
#ifdef __cplusplus
}
#endif
#endif /* __ENCODER_CONFIG_H__ */
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-08-23 balanceTWK first version
*/
#ifndef __PULSE_ENCODER_CONFIG_H__
#define __PULSE_ENCODER_CONFIG_H__
#include <rtthread.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef BSP_USING_PULSE_ENCODER1
#ifndef PULSE_ENCODER1_CONFIG
#define PULSE_ENCODER1_CONFIG \
{ \
.tim_handler.Instance = TIM1, \
.name = "pulse1" \
}
#endif /* PULSE_ENCODER1_CONFIG */
#endif /* BSP_USING_PULSE_ENCODER1 */
#ifdef BSP_USING_PULSE_ENCODER2
#ifndef PULSE_ENCODER2_CONFIG
#define PULSE_ENCODER2_CONFIG \
{ \
.tim_handler.Instance = TIM2, \
.name = "pulse2" \
}
#endif /* PULSE_ENCODER2_CONFIG */
#endif /* BSP_USING_PULSE_ENCODER2 */
#ifdef BSP_USING_PULSE_ENCODER3
#ifndef PULSE_ENCODER3_CONFIG
#define PULSE_ENCODER3_CONFIG \
{ \
.tim_handler.Instance = TIM3, \
.name = "pulse3" \
}
#endif /* PULSE_ENCODER3_CONFIG */
#endif /* BSP_USING_PULSE_ENCODER3 */
#ifdef BSP_USING_PULSE_ENCODER4
#ifndef PULSE_ENCODER4_CONFIG
#define PULSE_ENCODER4_CONFIG \
{ \
.tim_handler.Instance = TIM4, \
.name = "pulse4" \
}
#endif /* PULSE_ENCODER4_CONFIG */
#endif /* BSP_USING_PULSE_ENCODER4 */
#ifdef __cplusplus
}
#endif
#endif /* __PULSE_ENCODER_CONFIG_H__ */
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-08-23 balanceTWK first version
*/
#ifndef __ENCODER_CONFIG_H__
#define __ENCODER_CONFIG_H__
#include <rtthread.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef BSP_USING_ENCODER1
#ifndef ENCODER1_CONFIG
#define ENCODER1_CONFIG \
{ \
.tim_handler.Instance = TIM1, \
.name = "encoder1" \
}
#endif /* ENCODER1_CONFIG */
#endif /* BSP_USING_ENCODER1 */
#ifdef BSP_USING_ENCODER2
#ifndef ENCODER2_CONFIG
#define ENCODER2_CONFIG \
{ \
.tim_handler.Instance = TIM2, \
.name = "encoder2" \
}
#endif /* ENCODER2_CONFIG */
#endif /* BSP_USING_ENCODER2 */
#ifdef BSP_USING_ENCODER3
#ifndef ENCODER3_CONFIG
#define ENCODER3_CONFIG \
{ \
.tim_handler.Instance = TIM3, \
.name = "encoder3" \
}
#endif /* ENCODER3_CONFIG */
#endif /* BSP_USING_ENCODER3 */
#ifdef BSP_USING_ENCODER4
#ifndef ENCODER4_CONFIG
#define ENCODER4_CONFIG \
{ \
.tim_handler.Instance = TIM4, \
.name = "encoder4" \
}
#endif /* ENCODER4_CONFIG */
#endif /* BSP_USING_ENCODER4 */
#ifdef __cplusplus
}
#endif
#endif /* __ENCODER_CONFIG_H__ */
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-08-23 balanceTWK first version
*/
#ifndef __PULSE_ENCODER_CONFIG_H__
#define __PULSE_ENCODER_CONFIG_H__
#include <rtthread.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef BSP_USING_PULSE_ENCODER1
#ifndef PULSE_ENCODER1_CONFIG
#define PULSE_ENCODER1_CONFIG \
{ \
.tim_handler.Instance = TIM1, \
.name = "pulse1" \
}
#endif /* PULSE_ENCODER1_CONFIG */
#endif /* BSP_USING_PULSE_ENCODER1 */
#ifdef BSP_USING_PULSE_ENCODER2
#ifndef PULSE_ENCODER2_CONFIG
#define PULSE_ENCODER2_CONFIG \
{ \
.tim_handler.Instance = TIM2, \
.name = "pulse2" \
}
#endif /* PULSE_ENCODER2_CONFIG */
#endif /* BSP_USING_PULSE_ENCODER2 */
#ifdef BSP_USING_PULSE_ENCODER3
#ifndef PULSE_ENCODER3_CONFIG
#define PULSE_ENCODER3_CONFIG \
{ \
.tim_handler.Instance = TIM3, \
.name = "pulse3" \
}
#endif /* PULSE_ENCODER3_CONFIG */
#endif /* BSP_USING_PULSE_ENCODER3 */
#ifdef BSP_USING_PULSE_ENCODER4
#ifndef PULSE_ENCODER4_CONFIG
#define PULSE_ENCODER4_CONFIG \
{ \
.tim_handler.Instance = TIM4, \
.name = "pulse4" \
}
#endif /* PULSE_ENCODER4_CONFIG */
#endif /* BSP_USING_PULSE_ENCODER4 */
#ifdef __cplusplus
}
#endif
#endif /* __PULSE_ENCODER_CONFIG_H__ */
......@@ -34,7 +34,7 @@ extern "C" {
#include "f1/sdio_config.h"
#include "f1/pwm_config.h"
#include "f1/usbd_fs_config.h"
#include "f1/encoder_config.h"
#include "f1/pulse_encoder_config.h"
#elif defined(SOC_SERIES_STM32F2)
#include "f2/dma_config.h"
#include "f2/uart_config.h"
......@@ -53,7 +53,7 @@ extern "C" {
#include "f4/tim_config.h"
#include "f4/sdio_config.h"
#include "f4/pwm_config.h"
#include "f4/encoder_config.h"
#include "f4/pulse_encoder_config.h"
#elif defined(SOC_SERIES_STM32F7)
#include "f7/dma_config.h"
#include "f7/uart_config.h"
......
......@@ -10,74 +10,74 @@
#include "board.h"
#include "drv_config.h"
#ifdef RT_USING_ENCODER
#ifdef RT_USING_PULSE_ENCODER
//#define DRV_DEBUG
#define LOG_TAG "drv.encoder"
#define LOG_TAG "drv.pulse_encoder"
#include <drv_log.h>
#if !defined(BSP_USING_ENCODER1) && !defined(BSP_USING_ENCODER2) && !defined(BSP_USING_ENCODER3) \
&& !defined(BSP_USING_ENCODER4) && !defined(BSP_USING_ENCODER5) && !defined(BSP_USING_ENCODER6) && !defined(BSP_USING_LPENCODER1)
#error "Please define at least one BSP_USING_ENCODERx"
#if !defined(BSP_USING_PULSE_ENCODER1) && !defined(BSP_USING_PULSE_ENCODER2) && !defined(BSP_USING_PULSE_ENCODER3) \
&& !defined(BSP_USING_PULSE_ENCODER4) && !defined(BSP_USING_PULSE_ENCODER5) && !defined(BSP_USING_PULSE_ENCODER6)
#error "Please define at least one BSP_USING_PULSE_ENCODERx"
/* this driver can be disabled at menuconfig → RT-Thread Components → Device Drivers */
#endif
enum
{
#ifdef BSP_USING_ENCODER1
ENCODER1_INDEX,
#ifdef BSP_USING_PULSE_ENCODER1
PULSE_ENCODER1_INDEX,
#endif
#ifdef BSP_USING_ENCODER2
ENCODER2_INDEX,
#ifdef BSP_USING_PULSE_ENCODER2
PULSE_ENCODER2_INDEX,
#endif
#ifdef BSP_USING_ENCODER3
ENCODER3_INDEX,
#ifdef BSP_USING_PULSE_ENCODER3
PULSE_ENCODER3_INDEX,
#endif
#ifdef BSP_USING_ENCODER4
ENCODER4_INDEX,
#ifdef BSP_USING_PULSE_ENCODER4
PULSE_ENCODER4_INDEX,
#endif
#ifdef BSP_USING_ENCODER5
ENCODER5_INDEX,
#ifdef BSP_USING_PULSE_ENCODER5
PULSE_ENCODER5_INDEX,
#endif
#ifdef BSP_USING_ENCODER6
ENCODER6_INDEX,
#ifdef BSP_USING_PULSE_ENCODER6
PULSE_ENCODER6_INDEX,
#endif
};
struct stm32_encoder_device
struct stm32_pulse_encoder_device
{
struct rt_encoder_device encoder;
struct rt_pulse_encoder_device pulse_encoder;
TIM_HandleTypeDef tim_handler;
char *name;
};
static struct stm32_encoder_device stm32_encoder_obj[] =
static struct stm32_pulse_encoder_device stm32_pulse_encoder_obj[] =
{
#ifdef BSP_USING_ENCODER1
ENCODER1_CONFIG,
#ifdef BSP_USING_PULSE_ENCODER1
PULSE_ENCODER1_CONFIG,
#endif
#ifdef BSP_USING_ENCODER2
ENCODER2_CONFIG,
#ifdef BSP_USING_PULSE_ENCODER2
PULSE_ENCODER2_CONFIG,
#endif
#ifdef BSP_USING_ENCODER3
ENCODER3_CONFIG,
#ifdef BSP_USING_PULSE_ENCODER3
PULSE_ENCODER3_CONFIG,
#endif
#ifdef BSP_USING_ENCODER4
ENCODER4_CONFIG,
#ifdef BSP_USING_PULSE_ENCODER4
PULSE_ENCODER4_CONFIG,
#endif
#ifdef BSP_USING_ENCODER5
ENCODER5_CONFIG,
#ifdef BSP_USING_PULSE_ENCODER5
PULSE_ENCODER5_CONFIG,
#endif
#ifdef BSP_USING_ENCODER6
ENCODER6_CONFIG,
#ifdef BSP_USING_PULSE_ENCODER6
PULSE_ENCODER6_CONFIG,
#endif
};
rt_err_t encoder_init(struct rt_encoder_device *encoder)
rt_err_t pulse_encoder_init(struct rt_pulse_encoder_device *pulse_encoder)
{
TIM_Encoder_InitTypeDef sConfig;
TIM_MasterConfigTypeDef sMasterConfig;
TIM_HandleTypeDef *tim_handler = (TIM_HandleTypeDef *)encoder->parent.user_data;
TIM_HandleTypeDef *tim_handler = (TIM_HandleTypeDef *)pulse_encoder->parent.user_data;
tim_handler->Init.Prescaler = 0;
tim_handler->Init.CounterMode = TIM_COUNTERMODE_UP;
......@@ -96,7 +96,7 @@ rt_err_t encoder_init(struct rt_encoder_device *encoder)
if (HAL_TIM_Encoder_Init(tim_handler, &sConfig) != HAL_OK)
{
LOG_E("encoder init failed");
LOG_E("pulse_encoder init failed");
return -RT_ERROR;
}
......@@ -112,28 +112,28 @@ rt_err_t encoder_init(struct rt_encoder_device *encoder)
return RT_EOK;
}
rt_int32_t encoder_get_count(struct rt_encoder_device *encoder)
rt_int32_t pulse_encoder_get_count(struct rt_pulse_encoder_device *pulse_encoder)
{
TIM_HandleTypeDef *tim_handler = (TIM_HandleTypeDef *)encoder->parent.user_data;
TIM_HandleTypeDef *tim_handler = (TIM_HandleTypeDef *)pulse_encoder->parent.user_data;
return (rt_int16_t)__HAL_TIM_GET_COUNTER(tim_handler);
}
rt_err_t encoder_control(struct rt_encoder_device *encoder, rt_uint32_t cmd, void *args)
rt_err_t pulse_encoder_control(struct rt_pulse_encoder_device *pulse_encoder, rt_uint32_t cmd, void *args)
{
rt_err_t result;
TIM_HandleTypeDef *tim_handler = (TIM_HandleTypeDef *)encoder->parent.user_data;
TIM_HandleTypeDef *tim_handler = (TIM_HandleTypeDef *)pulse_encoder->parent.user_data;
result = RT_EOK;
switch (cmd)
{
case ENCODER_CMD_ENABLE:
case PULSE_ENCODER_CMD_ENABLE:
HAL_TIM_Encoder_Start(tim_handler, TIM_CHANNEL_ALL);
break;
case ENCODER_CMD_DISABLE:
case PULSE_ENCODER_CMD_DISABLE:
HAL_TIM_Encoder_Stop(tim_handler, TIM_CHANNEL_ALL);
break;
case ENCODER_CMD_CLEAR_COUNT:
case PULSE_ENCODER_CMD_CLEAR_COUNT:
__HAL_TIM_SET_COUNTER(tim_handler, 0);
break;
default:
......@@ -144,33 +144,33 @@ rt_err_t encoder_control(struct rt_encoder_device *encoder, rt_uint32_t cmd, voi
return result;
}
static const struct rt_encoder_ops _ops =
static const struct rt_pulse_encoder_ops _ops =
{
.init = encoder_init,
.get_count = encoder_get_count,
.control = encoder_control,
.init = pulse_encoder_init,
.get_count = pulse_encoder_get_count,
.control = pulse_encoder_control,
};
int hw_encoder_init(void)
int hw_pulse_encoder_init(void)
{
int i;
int result;
result = RT_EOK;
for (i = 0; i < sizeof(stm32_encoder_obj) / sizeof(stm32_encoder_obj[0]); i++)
for (i = 0; i < sizeof(stm32_pulse_encoder_obj) / sizeof(stm32_pulse_encoder_obj[0]); i++)
{
stm32_encoder_obj[i].encoder.type = AB_PHASE_ENCODER;
stm32_encoder_obj[i].encoder.ops = &_ops;
stm32_pulse_encoder_obj[i].pulse_encoder.type = AB_PHASE_PULSE_ENCODER;
stm32_pulse_encoder_obj[i].pulse_encoder.ops = &_ops;
if (rt_device_encoder_register(&stm32_encoder_obj[i].encoder, stm32_encoder_obj[i].name, &stm32_encoder_obj[i].tim_handler) != RT_EOK)
if (rt_device_pulse_encoder_register(&stm32_pulse_encoder_obj[i].pulse_encoder, stm32_pulse_encoder_obj[i].name, &stm32_pulse_encoder_obj[i].tim_handler) != RT_EOK)
{
LOG_E("%s register failed", stm32_encoder_obj[i].name);
LOG_E("%s register failed", stm32_pulse_encoder_obj[i].name);
result = -RT_ERROR;
}
}
return result;
}
INIT_BOARD_EXPORT(hw_encoder_init);
INIT_BOARD_EXPORT(hw_pulse_encoder_init);
#endif
......@@ -44,7 +44,7 @@ if GetDepend(['RT_USING_USB_HOST']) or GetDepend(['RT_USING_USB_DEVICE']):
if GetDepend(['RT_USING_CAN']):
src += ['STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_can.c']
if GetDepend(['RT_USING_HWTIMER']) or GetDepend(['RT_USING_PWM']) or GetDepend(['RT_USING_ENCODER']):
if GetDepend(['RT_USING_HWTIMER']) or GetDepend(['RT_USING_PWM']) or GetDepend(['RT_USING_PULSE_ENCODER']):
src += ['STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c']
src += ['STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c']
......
......@@ -46,7 +46,7 @@ if GetDepend(['RT_USING_USB_HOST']) or GetDepend(['RT_USING_USB_DEVICE']):
if GetDepend(['RT_USING_CAN']):
src += ['STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c']
if GetDepend(['RT_USING_HWTIMER']) or GetDepend(['RT_USING_PWM']) or GetDepend(['RT_USING_ENCODER']):
if GetDepend(['RT_USING_HWTIMER']) or GetDepend(['RT_USING_PWM']) or GetDepend(['RT_USING_PULSE_ENCODER']):
src += ['STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c']
src += ['STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c']
src += ['STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_lptim.c']
......
......@@ -201,13 +201,13 @@ menu "On-chip Peripheral Drivers"
select RT_USING_WDT
default n
menuconfig BSP_USING_ENCODER
bool "Enable Encoder"
menuconfig BSP_USING_PULSE_ENCODER
bool "Enable Pulse Encoder"
default n
select RT_USING_ENCODER
if BSP_USING_ENCODER
config BSP_USING_ENCODER3
bool "Enable Encoder3"
select RT_USING_PULSE_ENCODER
if BSP_USING_PULSE_ENCODER
config BSP_USING_PULSE_ENCODER3
bool "Enable Pulse Encoder3"
default n
endif
......
......@@ -294,13 +294,13 @@ menu "On-chip Peripheral Drivers"
select RT_USING_DFS
default n
menuconfig BSP_USING_ENCODER
bool "Enable Encoder"
menuconfig BSP_USING_PULSE_ENCODER
bool "Enable Pulse Encoder"
default n
select RT_USING_ENCODER
if BSP_USING_ENCODER
config BSP_USING_ENCODER4
bool "Enable Encoder4"
select RT_USING_PULSE_ENCODER
if BSP_USING_PULSE_ENCODER
config BSP_USING_PULSE_ENCODER4
bool "Enable Pulse Encoder4"
default n
endif
......
......@@ -434,8 +434,8 @@ menuconfig RT_USING_HWCRYPTO
endif
endif
config RT_USING_ENCODER
bool "Using ENCODER device drivers"
config RT_USING_PULSE_ENCODER
bool "Using PULSE ENCODER device drivers"
default n
config RT_USING_INPUT_CAPTURE
......
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-08-08 balanceTWK the first version
*/
#ifndef __ENCODER_H__
#define __ENCODER_H__
#include <rtthread.h>
#include <rtdevice.h>
#ifdef __cplusplus
extern "C" {
#endif
/* encoder control command */
#define ENCODER_CMD_GET_TYPE (128 + 0) /* get a encoder type information */
#define ENCODER_CMD_ENABLE (128 + 1) /* enable encoder */
#define ENCODER_CMD_DISABLE (128 + 2) /* disable encoder */
#define ENCODER_CMD_CLEAR_COUNT (128 + 3) /* clear encoder count */
/* encoder type */
enum rt_encoder_type
{
UNKNOWN_ENCODER_TYPE = 0x00, /* Unknown encoder type */
SINGLE_PHASE_ENCODER, /* single phase encoder */
AB_PHASE_ENCODER /* two phase encoder */
};
struct rt_encoder_device;
struct rt_encoder_ops
{
rt_err_t (*init)(struct rt_encoder_device *encoder);
rt_int32_t (*get_count)(struct rt_encoder_device *encoder);
rt_err_t (*clear_count)(struct rt_encoder_device *encoder);
rt_err_t (*control)(struct rt_encoder_device *encoder, rt_uint32_t cmd, void *args);
};
struct rt_encoder_device
{
struct rt_device parent;
const struct rt_encoder_ops *ops;
enum rt_encoder_type type;
};
rt_err_t rt_device_encoder_register(struct rt_encoder_device *encoder, const char *name, void *user_data);
#ifdef __cplusplus
}
#endif
#endif /* __ENCODER_H__ */
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-08-08 balanceTWK the first version
*/
#ifndef __PULSE_ENCODER_H__
#define __PULSE_ENCODER_H__
#include <rtthread.h>
#include <rtdevice.h>
#ifdef __cplusplus
extern "C" {
#endif
/* pulse_encoder control command */
#define PULSE_ENCODER_CMD_GET_TYPE (128 + 0) /* get a pulse_encoder type information */
#define PULSE_ENCODER_CMD_ENABLE (128 + 1) /* enable pulse_encoder */
#define PULSE_ENCODER_CMD_DISABLE (128 + 2) /* disable pulse_encoder */
#define PULSE_ENCODER_CMD_CLEAR_COUNT (128 + 3) /* clear pulse_encoder count */
/* pulse_encoder type */
enum rt_pulse_encoder_type
{
UNKNOWN_PULSE_ENCODER_TYPE = 0x00, /* Unknown pulse_encoder type */
SINGLE_PHASE_PULSE_ENCODER, /* single phase pulse_encoder */
AB_PHASE_PULSE_ENCODER /* two phase pulse_encoder */
};
struct rt_pulse_encoder_device;
struct rt_pulse_encoder_ops
{
rt_err_t (*init)(struct rt_pulse_encoder_device *pulse_encoder);
rt_int32_t (*get_count)(struct rt_pulse_encoder_device *pulse_encoder);
rt_err_t (*clear_count)(struct rt_pulse_encoder_device *pulse_encoder);
rt_err_t (*control)(struct rt_pulse_encoder_device *pulse_encoder, rt_uint32_t cmd, void *args);
};
struct rt_pulse_encoder_device
{
struct rt_device parent;
const struct rt_pulse_encoder_ops *ops;
enum rt_pulse_encoder_type type;
};
rt_err_t rt_device_pulse_encoder_register(struct rt_pulse_encoder_device *pulse_encoder, const char *name, void *user_data);
#ifdef __cplusplus
}
#endif
#endif /* __PULSE_ENCODER_H__ */
......@@ -126,8 +126,8 @@ extern "C" {
#include "drivers/crypto.h"
#endif
#ifdef RT_USING_ENCODER
#include "drivers/encoder.h"
#ifdef RT_USING_PULSE_ENCODER
#include "drivers/pulse_encoder.h"
#endif
#ifdef RT_USING_INPUT_CAPTURE
......
......@@ -14,8 +14,8 @@ if GetDepend(['RT_USING_ADC']):
if GetDepend(['RT_USING_PWM']):
src = src + ['rt_drv_pwm.c']
if GetDepend(['RT_USING_ENCODER']):
src = src + ['encoder.c']
if GetDepend(['RT_USING_PULSE_ENCODER']):
src = src + ['pulse_encoder.c']
if GetDepend(['RT_USING_INPUT_CAPTURE']):
src = src + ['rt_inputcapture.c']
......
......@@ -11,14 +11,14 @@
#include <rtthread.h>
#include <rtdevice.h>
static rt_err_t rt_encoder_init(struct rt_device *dev)
static rt_err_t rt_pulse_encoder_init(struct rt_device *dev)
{
struct rt_encoder_device *encoder;
struct rt_pulse_encoder_device *pulse_encoder;
encoder = (struct rt_encoder_device *)dev;
if (encoder->ops->init)
pulse_encoder = (struct rt_pulse_encoder_device *)dev;
if (pulse_encoder->ops->init)
{
return encoder->ops->init(encoder);
return pulse_encoder->ops->init(pulse_encoder);
}
else
{
......@@ -26,14 +26,14 @@ static rt_err_t rt_encoder_init(struct rt_device *dev)
}
}
static rt_err_t rt_encoder_open(struct rt_device *dev, rt_uint16_t oflag)
static rt_err_t rt_pulse_encoder_open(struct rt_device *dev, rt_uint16_t oflag)
{
struct rt_encoder_device *encoder;
struct rt_pulse_encoder_device *pulse_encoder;
encoder = (struct rt_encoder_device *)dev;
if (encoder->ops->control)
pulse_encoder = (struct rt_pulse_encoder_device *)dev;
if (pulse_encoder->ops->control)
{
return encoder->ops->control(encoder, ENCODER_CMD_ENABLE, RT_NULL);
return pulse_encoder->ops->control(pulse_encoder, PULSE_ENCODER_CMD_ENABLE, RT_NULL);
}
else
{
......@@ -41,14 +41,14 @@ static rt_err_t rt_encoder_open(struct rt_device *dev, rt_uint16_t oflag)
}
}
static rt_err_t rt_encoder_close(struct rt_device *dev)
static rt_err_t rt_pulse_encoder_close(struct rt_device *dev)
{
struct rt_encoder_device *encoder;
struct rt_pulse_encoder_device *pulse_encoder;
encoder = (struct rt_encoder_device *)dev;
if (encoder->ops->control)
pulse_encoder = (struct rt_pulse_encoder_device *)dev;
if (pulse_encoder->ops->control)
{
return encoder->ops->control(encoder, ENCODER_CMD_DISABLE, RT_NULL);
return pulse_encoder->ops->control(pulse_encoder, PULSE_ENCODER_CMD_DISABLE, RT_NULL);
}
else
{
......@@ -56,36 +56,36 @@ static rt_err_t rt_encoder_close(struct rt_device *dev)
}
}
static rt_size_t rt_encoder_read(struct rt_device *dev, rt_off_t pos, void *buffer, rt_size_t size)
static rt_size_t rt_pulse_encoder_read(struct rt_device *dev, rt_off_t pos, void *buffer, rt_size_t size)
{
struct rt_encoder_device *encoder;
struct rt_pulse_encoder_device *pulse_encoder;
encoder = (struct rt_encoder_device *)dev;
if (encoder->ops->get_count)
pulse_encoder = (struct rt_pulse_encoder_device *)dev;
if (pulse_encoder->ops->get_count)
{
*(rt_int32_t *)buffer = encoder->ops->get_count(encoder);
*(rt_int32_t *)buffer = pulse_encoder->ops->get_count(pulse_encoder);
}
return 1;
}
static rt_err_t rt_encoder_control(struct rt_device *dev, int cmd, void *args)
static rt_err_t rt_pulse_encoder_control(struct rt_device *dev, int cmd, void *args)
{
rt_err_t result;
struct rt_encoder_device *encoder;
struct rt_pulse_encoder_device *pulse_encoder;
result = RT_EOK;
encoder = (struct rt_encoder_device *)dev;
pulse_encoder = (struct rt_pulse_encoder_device *)dev;
switch (cmd)
{
case ENCODER_CMD_CLEAR_COUNT:
result = encoder->ops->clear_count(encoder);
case PULSE_ENCODER_CMD_CLEAR_COUNT:
result = pulse_encoder->ops->clear_count(pulse_encoder);
break;
case ENCODER_CMD_GET_TYPE:
*(enum rt_encoder_type *)args = encoder->type;
case PULSE_ENCODER_CMD_GET_TYPE:
*(enum rt_pulse_encoder_type *)args = pulse_encoder->type;
break;
case ENCODER_CMD_ENABLE:
case ENCODER_CMD_DISABLE:
result = encoder->ops->control(encoder, cmd, args);
case PULSE_ENCODER_CMD_ENABLE:
case PULSE_ENCODER_CMD_DISABLE:
result = pulse_encoder->ops->control(pulse_encoder, cmd, args);
break;
default:
result = -RT_ENOSYS;
......@@ -96,39 +96,39 @@ static rt_err_t rt_encoder_control(struct rt_device *dev, int cmd, void *args)
}
#ifdef RT_USING_DEVICE_OPS
const static struct rt_device_ops encoder_ops =
const static struct rt_device_ops pulse_encoder_ops =
{
rt_encoder_init,
rt_encoder_open,
rt_encoder_close,
rt_encoder_read,
rt_pulse_encoder_init,
rt_pulse_encoder_open,
rt_pulse_encoder_close,
rt_pulse_encoder_read,
RT_NULL,
rt_encoder_control
rt_pulse_encoder_control
};
#endif
rt_err_t rt_device_encoder_register(struct rt_encoder_device *encoder, const char *name, void *user_data)
rt_err_t rt_device_pulse_encoder_register(struct rt_pulse_encoder_device *pulse_encoder, const char *name, void *user_data)
{
struct rt_device *device;
RT_ASSERT(encoder != RT_NULL);
RT_ASSERT(encoder->ops != RT_NULL);
RT_ASSERT(pulse_encoder != RT_NULL);
RT_ASSERT(pulse_encoder->ops != RT_NULL);
device = &(encoder->parent);
device = &(pulse_encoder->parent);
device->type = RT_Device_Class_Miscellaneous;
device->rx_indicate = RT_NULL;
device->tx_complete = RT_NULL;
#ifdef RT_USING_DEVICE_OPS
device->ops = &encoder_ops;
device->ops = &pulse_encoder_ops;
#else
device->init = rt_encoder_init;
device->open = rt_encoder_open;
device->close = rt_encoder_close;
device->read = rt_encoder_read;
device->init = rt_pulse_encoder_init;
device->open = rt_pulse_encoder_open;
device->close = rt_pulse_encoder_close;
device->read = rt_pulse_encoder_read;
device->write = RT_NULL;
device->control = rt_encoder_control;
device->control = rt_pulse_encoder_control;
#endif
device->user_data = user_data;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册