Merge pull request #2993 from balanceTWK/encoder_perfect

[components][drivers][encoder] update
This commit is contained in:
Bernard Xiong 2019-08-26 13:45:27 +08:00 committed by GitHub
commit 4652480b64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 15 deletions

View File

@ -13,47 +13,47 @@
static rt_err_t rt_encoder_init(struct rt_device *dev) static rt_err_t rt_encoder_init(struct rt_device *dev)
{ {
rt_err_t ret;
struct rt_encoder_device *encoder; struct rt_encoder_device *encoder;
ret = RT_EOK;
encoder = (struct rt_encoder_device *)dev; encoder = (struct rt_encoder_device *)dev;
if (encoder->ops->init) if (encoder->ops->init)
{ {
return encoder->ops->init(encoder); ret = encoder->ops->init(encoder);
}
else
{
return -RT_ENOSYS;
} }
return ret;
} }
static rt_err_t rt_encoder_open(struct rt_device *dev, rt_uint16_t oflag) static rt_err_t rt_encoder_open(struct rt_device *dev, rt_uint16_t oflag)
{ {
rt_err_t ret;
struct rt_encoder_device *encoder; struct rt_encoder_device *encoder;
ret = RT_EOK;
encoder = (struct rt_encoder_device *)dev; encoder = (struct rt_encoder_device *)dev;
if (encoder->ops->control) if (encoder->ops->control)
{ {
return encoder->ops->control(encoder, ENCODER_CMD_ENABLE, RT_NULL); ret = encoder->ops->control(encoder, ENCODER_CMD_ENABLE, RT_NULL);
}
else
{
return -RT_ENOSYS;
} }
return ret;
} }
static rt_err_t rt_encoder_close(struct rt_device *dev) static rt_err_t rt_encoder_close(struct rt_device *dev)
{ {
rt_err_t ret;
struct rt_encoder_device *encoder; struct rt_encoder_device *encoder;
ret = RT_EOK;
encoder = (struct rt_encoder_device *)dev; encoder = (struct rt_encoder_device *)dev;
if (encoder->ops->control) if (encoder->ops->control)
{ {
return encoder->ops->control(encoder, ENCODER_CMD_DISABLE, RT_NULL); ret = encoder->ops->control(encoder, ENCODER_CMD_DISABLE, RT_NULL);
}
else
{
return -RT_ENOSYS;
} }
return ret;
} }
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_encoder_read(struct rt_device *dev, rt_off_t pos, void *buffer, rt_size_t size)
@ -113,6 +113,7 @@ rt_err_t rt_device_encoder_register(struct rt_encoder_device *encoder, const cha
RT_ASSERT(encoder != RT_NULL); RT_ASSERT(encoder != RT_NULL);
RT_ASSERT(encoder->ops != RT_NULL); RT_ASSERT(encoder->ops != RT_NULL);
RT_ASSERT(encoder->ops->get_count != RT_NULL);
device = &(encoder->parent); device = &(encoder->parent);