Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Richard 祝发兴 - -IT
rt-thread
提交
e5dc60e3
R
rt-thread
项目概览
Richard 祝发兴 - -IT
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e5dc60e3
编写于
8月 11, 2019
作者:
T
tangweikang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[components][drivers] update encoder driven framework
上级
cc565da5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
39 deletion
+30
-39
components/drivers/include/drivers/encoder.h
components/drivers/include/drivers/encoder.h
+12
-20
components/drivers/misc/encoder.c
components/drivers/misc/encoder.c
+18
-19
未找到文件。
components/drivers/include/drivers/encoder.h
浏览文件 @
e5dc60e3
...
...
@@ -19,20 +19,18 @@ extern "C" {
#endif
/* encoder control command */
typedef
enum
{
ENCODER_INFO_GET
=
0x01
,
/* get a encoder feature information */
ENCODER_SWITCH_ON
,
/* switch on encoder */
ENCODER_SWITCH_OFF
,
/* switch off encoder */
ENCODER_COUNT_CLEAR
,
/* clear encoder count */
}
rt_encoder_ctrl_t
;
#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 */
typedef
enum
enum
rt_encoder_type
{
SINGLE_PHASE_ENCODER
=
0x01
,
/* single phase encoder */
UNKNOWN_ENCODER_TYPE
=
0x00
,
/* Unknown encoder type */
SINGLE_PHASE_ENCODER
,
/* single phase encoder */
AB_PHASE_ENCODER
/* two phase encoder */
}
rt_encoder_type_t
;
};
struct
rt_encoder_device
;
...
...
@@ -43,20 +41,14 @@ struct rt_encoder_ops
rt_err_t
(
*
control
)(
struct
rt_encoder_device
*
encoder
,
rt_uint32_t
cmd
,
void
*
args
);
};
/* Encoder feature information */
struct
rt_encoder_info
{
rt_encoder_type_t
type
;
/* the type of encoder */
};
typedef
struct
rt_encoder_device
struct
rt_encoder_device
{
struct
rt_device
parent
;
const
struct
rt_encoder_ops
*
ops
;
const
struct
rt_encoder_info
*
info
;
}
rt_encoder_t
;
enum
rt_encoder_type
type
;
};
rt_err_t
rt_device_encoder_register
(
rt_encoder_t
*
encoder
,
const
char
*
name
,
void
*
user_data
);
rt_err_t
rt_device_encoder_register
(
struct
rt_encoder_device
*
encoder
,
const
char
*
name
,
void
*
user_data
);
#ifdef __cplusplus
}
...
...
components/drivers/misc/encoder.c
浏览文件 @
e5dc60e3
...
...
@@ -13,9 +13,9 @@
static
rt_err_t
rt_encoder_init
(
struct
rt_device
*
dev
)
{
rt_encoder_t
*
encoder
;
struct
rt_encoder_device
*
encoder
;
encoder
=
(
rt_encoder_t
*
)
dev
;
encoder
=
(
struct
rt_encoder_device
*
)
dev
;
if
(
encoder
->
ops
->
init
)
{
return
encoder
->
ops
->
init
(
encoder
);
...
...
@@ -28,12 +28,12 @@ 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
)
{
rt_encoder_t
*
encoder
;
struct
rt_encoder_device
*
encoder
;
encoder
=
(
rt_encoder_t
*
)
dev
;
encoder
=
(
struct
rt_encoder_device
*
)
dev
;
if
(
encoder
->
ops
->
control
)
{
return
encoder
->
ops
->
control
(
encoder
,
ENCODER_
SWITCH_ON
,
RT_NULL
);
return
encoder
->
ops
->
control
(
encoder
,
ENCODER_
CMD_ENABLE
,
RT_NULL
);
}
else
{
...
...
@@ -43,12 +43,12 @@ 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
)
{
rt_encoder_t
*
encoder
;
struct
rt_encoder_device
*
encoder
;
encoder
=
(
rt_encoder_t
*
)
dev
;
encoder
=
(
struct
rt_encoder_device
*
)
dev
;
if
(
encoder
->
ops
->
control
)
{
return
encoder
->
ops
->
control
(
encoder
,
ENCODER_
SWITCH_OFF
,
RT_NULL
);
return
encoder
->
ops
->
control
(
encoder
,
ENCODER_
CMD_DISABLE
,
RT_NULL
);
}
else
{
...
...
@@ -58,9 +58,9 @@ 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
)
{
rt_encoder_t
*
encoder
;
struct
rt_encoder_device
*
encoder
;
encoder
=
(
rt_encoder_t
*
)
dev
;
encoder
=
(
struct
rt_encoder_device
*
)
dev
;
if
(
encoder
->
ops
->
get_count
)
{
*
(
rt_int32_t
*
)
buffer
=
encoder
->
ops
->
get_count
(
encoder
);
...
...
@@ -71,18 +71,18 @@ static rt_size_t rt_encoder_read(struct rt_device *dev, rt_off_t pos, void *buff
static
rt_err_t
rt_encoder_control
(
struct
rt_device
*
dev
,
int
cmd
,
void
*
args
)
{
rt_err_t
result
;
rt_encoder_t
*
encoder
;
struct
rt_encoder_device
*
encoder
;
result
=
RT_EOK
;
encoder
=
(
rt_encoder_t
*
)
dev
;
encoder
=
(
struct
rt_encoder_device
*
)
dev
;
switch
(
cmd
)
{
case
ENCODER_
INFO_GET
:
*
(
struct
rt_encoder_info
*
)
args
=
*
encoder
->
info
;
case
ENCODER_
CMD_GET_TYPE
:
*
(
enum
rt_encoder_type
*
)
args
=
encoder
->
type
;
break
;
case
ENCODER_
SWITCH_ON
:
case
ENCODER_
SWITCH_OFF
:
case
ENCODER_C
OUNT_CLEAR
:
case
ENCODER_
CMD_ENABLE
:
case
ENCODER_
CMD_DISABLE
:
case
ENCODER_C
MD_CLEAR_COUNT
:
result
=
encoder
->
ops
->
control
(
encoder
,
cmd
,
args
);
break
;
default:
...
...
@@ -105,13 +105,12 @@ const static struct rt_device_ops encoder_ops =
};
#endif
rt_err_t
rt_device_encoder_register
(
rt_encoder_t
*
encoder
,
const
char
*
name
,
void
*
user_data
)
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
);
RT_ASSERT
(
encoder
->
info
!=
RT_NULL
);
device
=
&
(
encoder
->
parent
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录