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

This commit is contained in:
tangweikang
2019-08-30 15:58:52 +08:00
parent 05b1dff094
commit b76d3dac8a
19 changed files with 522 additions and 522 deletions
+2 -2
View File
@@ -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
@@ -1,58 +0,0 @@
/*
* 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__ */
@@ -0,0 +1,58 @@
/*
* 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__ */
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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']
-136
View File
@@ -1,136 +0,0 @@
/*
* 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
*/
#include <rtthread.h>
#include <rtdevice.h>
static rt_err_t rt_encoder_init(struct rt_device *dev)
{
struct rt_encoder_device *encoder;
encoder = (struct rt_encoder_device *)dev;
if (encoder->ops->init)
{
return encoder->ops->init(encoder);
}
else
{
return -RT_ENOSYS;
}
}
static rt_err_t rt_encoder_open(struct rt_device *dev, rt_uint16_t oflag)
{
struct rt_encoder_device *encoder;
encoder = (struct rt_encoder_device *)dev;
if (encoder->ops->control)
{
return encoder->ops->control(encoder, ENCODER_CMD_ENABLE, RT_NULL);
}
else
{
return -RT_ENOSYS;
}
}
static rt_err_t rt_encoder_close(struct rt_device *dev)
{
struct rt_encoder_device *encoder;
encoder = (struct rt_encoder_device *)dev;
if (encoder->ops->control)
{
return encoder->ops->control(encoder, ENCODER_CMD_DISABLE, RT_NULL);
}
else
{
return -RT_ENOSYS;
}
}
static rt_size_t rt_encoder_read(struct rt_device *dev, rt_off_t pos, void *buffer, rt_size_t size)
{
struct rt_encoder_device *encoder;
encoder = (struct rt_encoder_device *)dev;
if (encoder->ops->get_count)
{
*(rt_int32_t *)buffer = encoder->ops->get_count(encoder);
}
return 1;
}
static rt_err_t rt_encoder_control(struct rt_device *dev, int cmd, void *args)
{
rt_err_t result;
struct rt_encoder_device *encoder;
result = RT_EOK;
encoder = (struct rt_encoder_device *)dev;
switch (cmd)
{
case ENCODER_CMD_CLEAR_COUNT:
result = encoder->ops->clear_count(encoder);
break;
case ENCODER_CMD_GET_TYPE:
*(enum rt_encoder_type *)args = encoder->type;
break;
case ENCODER_CMD_ENABLE:
case ENCODER_CMD_DISABLE:
result = encoder->ops->control(encoder, cmd, args);
break;
default:
result = -RT_ENOSYS;
break;
}
return result;
}
#ifdef RT_USING_DEVICE_OPS
const static struct rt_device_ops encoder_ops =
{
rt_encoder_init,
rt_encoder_open,
rt_encoder_close,
rt_encoder_read,
RT_NULL,
rt_encoder_control
};
#endif
rt_err_t rt_device_encoder_register(struct rt_encoder_device *encoder, const char *name, void *user_data)
{
struct rt_device *device;
RT_ASSERT(encoder != RT_NULL);
RT_ASSERT(encoder->ops != RT_NULL);
device = &(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;
#else
device->init = rt_encoder_init;
device->open = rt_encoder_open;
device->close = rt_encoder_close;
device->read = rt_encoder_read;
device->write = RT_NULL;
device->control = rt_encoder_control;
#endif
device->user_data = user_data;
return rt_device_register(device, name, RT_DEVICE_FLAG_RDONLY | RT_DEVICE_FLAG_STANDALONE);
}
+136
View File
@@ -0,0 +1,136 @@
/*
* 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
*/
#include <rtthread.h>
#include <rtdevice.h>
static rt_err_t rt_pulse_encoder_init(struct rt_device *dev)
{
struct rt_pulse_encoder_device *pulse_encoder;
pulse_encoder = (struct rt_pulse_encoder_device *)dev;
if (pulse_encoder->ops->init)
{
return pulse_encoder->ops->init(pulse_encoder);
}
else
{
return -RT_ENOSYS;
}
}
static rt_err_t rt_pulse_encoder_open(struct rt_device *dev, rt_uint16_t oflag)
{
struct rt_pulse_encoder_device *pulse_encoder;
pulse_encoder = (struct rt_pulse_encoder_device *)dev;
if (pulse_encoder->ops->control)
{
return pulse_encoder->ops->control(pulse_encoder, PULSE_ENCODER_CMD_ENABLE, RT_NULL);
}
else
{
return -RT_ENOSYS;
}
}
static rt_err_t rt_pulse_encoder_close(struct rt_device *dev)
{
struct rt_pulse_encoder_device *pulse_encoder;
pulse_encoder = (struct rt_pulse_encoder_device *)dev;
if (pulse_encoder->ops->control)
{
return pulse_encoder->ops->control(pulse_encoder, PULSE_ENCODER_CMD_DISABLE, RT_NULL);
}
else
{
return -RT_ENOSYS;
}
}
static rt_size_t rt_pulse_encoder_read(struct rt_device *dev, rt_off_t pos, void *buffer, rt_size_t size)
{
struct rt_pulse_encoder_device *pulse_encoder;
pulse_encoder = (struct rt_pulse_encoder_device *)dev;
if (pulse_encoder->ops->get_count)
{
*(rt_int32_t *)buffer = pulse_encoder->ops->get_count(pulse_encoder);
}
return 1;
}
static rt_err_t rt_pulse_encoder_control(struct rt_device *dev, int cmd, void *args)
{
rt_err_t result;
struct rt_pulse_encoder_device *pulse_encoder;
result = RT_EOK;
pulse_encoder = (struct rt_pulse_encoder_device *)dev;
switch (cmd)
{
case PULSE_ENCODER_CMD_CLEAR_COUNT:
result = pulse_encoder->ops->clear_count(pulse_encoder);
break;
case PULSE_ENCODER_CMD_GET_TYPE:
*(enum rt_pulse_encoder_type *)args = pulse_encoder->type;
break;
case PULSE_ENCODER_CMD_ENABLE:
case PULSE_ENCODER_CMD_DISABLE:
result = pulse_encoder->ops->control(pulse_encoder, cmd, args);
break;
default:
result = -RT_ENOSYS;
break;
}
return result;
}
#ifdef RT_USING_DEVICE_OPS
const static struct rt_device_ops pulse_encoder_ops =
{
rt_pulse_encoder_init,
rt_pulse_encoder_open,
rt_pulse_encoder_close,
rt_pulse_encoder_read,
RT_NULL,
rt_pulse_encoder_control
};
#endif
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(pulse_encoder != RT_NULL);
RT_ASSERT(pulse_encoder->ops != RT_NULL);
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 = &pulse_encoder_ops;
#else
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_pulse_encoder_control;
#endif
device->user_data = user_data;
return rt_device_register(device, name, RT_DEVICE_FLAG_RDONLY | RT_DEVICE_FLAG_STANDALONE);
}