Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
AdRainty
rt-thread
提交
cc565da5
R
rt-thread
项目概览
AdRainty
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cc565da5
编写于
8月 09, 2019
作者:
T
tangweikang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[components][drivers] add encoder driven framework
上级
532ad16b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
211 addition
and
0 deletion
+211
-0
components/drivers/Kconfig
components/drivers/Kconfig
+4
-0
components/drivers/include/drivers/encoder.h
components/drivers/include/drivers/encoder.h
+65
-0
components/drivers/include/rtdevice.h
components/drivers/include/rtdevice.h
+4
-0
components/drivers/misc/SConscript
components/drivers/misc/SConscript
+3
-0
components/drivers/misc/encoder.c
components/drivers/misc/encoder.c
+135
-0
未找到文件。
components/drivers/Kconfig
浏览文件 @
cc565da5
...
...
@@ -434,6 +434,10 @@ menuconfig RT_USING_HWCRYPTO
endif
endif
config RT_USING_ENCODER
bool "Using ENCODER device drivers"
default n
menuconfig RT_USING_WIFI
bool "Using Wi-Fi framework"
default n
...
...
components/drivers/include/drivers/encoder.h
0 → 100644
浏览文件 @
cc565da5
/*
* 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 */
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
;
/* encoder type */
typedef
enum
{
SINGLE_PHASE_ENCODER
=
0x01
,
/* single phase encoder */
AB_PHASE_ENCODER
/* two phase encoder */
}
rt_encoder_type_t
;
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
(
*
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_device
parent
;
const
struct
rt_encoder_ops
*
ops
;
const
struct
rt_encoder_info
*
info
;
}
rt_encoder_t
;
rt_err_t
rt_device_encoder_register
(
rt_encoder_t
*
encoder
,
const
char
*
name
,
void
*
user_data
);
#ifdef __cplusplus
}
#endif
#endif
/* __ENCODER_H__ */
components/drivers/include/rtdevice.h
浏览文件 @
cc565da5
...
...
@@ -126,6 +126,10 @@ extern "C" {
#include "drivers/crypto.h"
#endif
#ifdef RT_USING_ENCODER
#include "drivers/encoder.h"
#endif
#ifdef __cplusplus
}
#endif
...
...
components/drivers/misc/SConscript
浏览文件 @
cc565da5
...
...
@@ -13,6 +13,9 @@ 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
len
(
src
):
group
=
DefineGroup
(
'DeviceDrivers'
,
src
,
depend
=
[
''
],
CPPPATH
=
CPPPATH
)
...
...
components/drivers/misc/encoder.c
0 → 100644
浏览文件 @
cc565da5
/*
* 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
)
{
rt_encoder_t
*
encoder
;
encoder
=
(
rt_encoder_t
*
)
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
)
{
rt_encoder_t
*
encoder
;
encoder
=
(
rt_encoder_t
*
)
dev
;
if
(
encoder
->
ops
->
control
)
{
return
encoder
->
ops
->
control
(
encoder
,
ENCODER_SWITCH_ON
,
RT_NULL
);
}
else
{
return
-
RT_ENOSYS
;
}
}
static
rt_err_t
rt_encoder_close
(
struct
rt_device
*
dev
)
{
rt_encoder_t
*
encoder
;
encoder
=
(
rt_encoder_t
*
)
dev
;
if
(
encoder
->
ops
->
control
)
{
return
encoder
->
ops
->
control
(
encoder
,
ENCODER_SWITCH_OFF
,
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
)
{
rt_encoder_t
*
encoder
;
encoder
=
(
rt_encoder_t
*
)
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
;
rt_encoder_t
*
encoder
;
result
=
RT_EOK
;
encoder
=
(
rt_encoder_t
*
)
dev
;
switch
(
cmd
)
{
case
ENCODER_INFO_GET
:
*
(
struct
rt_encoder_info
*
)
args
=
*
encoder
->
info
;
break
;
case
ENCODER_SWITCH_ON
:
case
ENCODER_SWITCH_OFF
:
case
ENCODER_COUNT_CLEAR
:
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
(
rt_encoder_t
*
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
);
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
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录