Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Mozi
rt-thread
提交
1bb425e8
R
rt-thread
项目概览
Mozi
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
0
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,发现更多精彩内容 >>
提交
1bb425e8
编写于
1月 19, 2015
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[DeviceDrivers] code cleanup for hardware pin
上级
765ac35e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
30 deletion
+30
-30
components/drivers/include/drivers/pin.h
components/drivers/include/drivers/pin.h
+5
-5
components/drivers/misc/pin.c
components/drivers/misc/pin.c
+25
-25
未找到文件。
components/drivers/include/drivers/pin.h
浏览文件 @
1bb425e8
...
...
@@ -59,18 +59,18 @@ struct rt_device_pin_status
struct
rt_pin_ops
{
void
(
*
pin_mode
)
(
struct
rt_device
*
device
,
rt_base_t
pin
,
rt_base_t
mode
);
void
(
*
pin_write
)(
struct
rt_device
*
device
,
rt_base_t
pin
,
rt_base_t
value
);
int
(
*
pin_read
)
(
struct
rt_device
*
device
,
rt_base_t
pin
);
void
(
*
pin_mode
)
(
struct
rt_device
*
device
,
rt_base_t
pin
,
rt_base_t
mode
);
void
(
*
pin_write
)(
struct
rt_device
*
device
,
rt_base_t
pin
,
rt_base_t
value
);
int
(
*
pin_read
)(
struct
rt_device
*
device
,
rt_base_t
pin
);
/* TODO: add GPIO interrupt */
};
int
rt_device_pin_register
(
const
char
*
name
,
const
struct
rt_pin_ops
*
ops
,
void
*
user_data
);
int
rt_device_pin_register
(
const
char
*
name
,
const
struct
rt_pin_ops
*
ops
,
void
*
user_data
);
void
rt_pin_mode
(
rt_base_t
pin
,
rt_base_t
mode
);
void
rt_pin_write
(
rt_base_t
pin
,
rt_base_t
value
);
int
rt_pin_read
(
rt_base_t
pin
);
int
rt_pin_read
(
rt_base_t
pin
);
#ifdef __cplusplus
}
...
...
components/drivers/misc/pin.c
浏览文件 @
1bb425e8
...
...
@@ -29,30 +29,30 @@
#endif
static
struct
rt_device_pin
_hw_pin
;
static
rt_size_t
_pin_read
(
rt_device_t
dev
,
rt_off_t
pos
,
void
*
buffer
,
rt_size_t
size
)
static
rt_size_t
_pin_read
(
rt_device_t
dev
,
rt_off_t
pos
,
void
*
buffer
,
rt_size_t
size
)
{
struct
rt_device_pin_status
*
status
;
struct
rt_device_pin
*
pin
=
(
struct
rt_device_pin
*
)
dev
;
struct
rt_device_pin_status
*
status
;
struct
rt_device_pin
*
pin
=
(
struct
rt_device_pin
*
)
dev
;
/* check parameters */
RT_ASSERT
(
pin
!=
RT_NULL
);
status
=
(
struct
rt_device_pin_status
*
)
buffer
;
status
=
(
struct
rt_device_pin_status
*
)
buffer
;
if
(
status
==
RT_NULL
||
size
!=
sizeof
(
*
status
))
return
0
;
status
->
status
=
pin
->
ops
->
pin_read
(
dev
,
status
->
pin
);
return
size
;
}
static
rt_size_t
_pin_write
(
rt_device_t
dev
,
rt_off_t
pos
,
const
void
*
buffer
,
rt_size_t
size
)
static
rt_size_t
_pin_write
(
rt_device_t
dev
,
rt_off_t
pos
,
const
void
*
buffer
,
rt_size_t
size
)
{
struct
rt_device_pin_status
*
status
;
struct
rt_device_pin
*
pin
=
(
struct
rt_device_pin
*
)
dev
;
struct
rt_device_pin_status
*
status
;
struct
rt_device_pin
*
pin
=
(
struct
rt_device_pin
*
)
dev
;
/* check parameters */
RT_ASSERT
(
pin
!=
RT_NULL
);
status
=
(
struct
rt_device_pin_status
*
)
buffer
;
status
=
(
struct
rt_device_pin_status
*
)
buffer
;
if
(
status
==
RT_NULL
||
size
!=
sizeof
(
*
status
))
return
0
;
pin
->
ops
->
pin_write
(
dev
,
(
rt_base_t
)
status
->
pin
,
(
rt_base_t
)
status
->
status
);
...
...
@@ -62,13 +62,13 @@ static rt_size_t _pin_write (rt_device_t dev, rt_off_t pos, const void *buffer,
static
rt_err_t
_pin_control
(
rt_device_t
dev
,
rt_uint8_t
cmd
,
void
*
args
)
{
struct
rt_device_pin_mode
*
mode
;
struct
rt_device_pin
*
pin
=
(
struct
rt_device_pin
*
)
dev
;
struct
rt_device_pin_mode
*
mode
;
struct
rt_device_pin
*
pin
=
(
struct
rt_device_pin
*
)
dev
;
/* check parameters */
RT_ASSERT
(
pin
!=
RT_NULL
);
mode
=
(
struct
rt_device_pin_mode
*
)
args
;
mode
=
(
struct
rt_device_pin_mode
*
)
args
;
if
(
mode
==
RT_NULL
)
return
-
RT_ERROR
;
pin
->
ops
->
pin_mode
(
dev
,
(
rt_base_t
)
mode
->
pin
,
(
rt_base_t
)
mode
->
mode
);
...
...
@@ -76,24 +76,24 @@ static rt_err_t _pin_control(rt_device_t dev, rt_uint8_t cmd, void *args)
return
0
;
}
int
rt_device_pin_register
(
const
char
*
name
,
const
struct
rt_pin_ops
*
ops
,
void
*
user_data
)
int
rt_device_pin_register
(
const
char
*
name
,
const
struct
rt_pin_ops
*
ops
,
void
*
user_data
)
{
_hw_pin
.
parent
.
type
=
RT_Device_Class_Miscellaneous
;
_hw_pin
.
parent
.
rx_indicate
=
RT_NULL
;
_hw_pin
.
parent
.
tx_complete
=
RT_NULL
;
_hw_pin
.
parent
.
type
=
RT_Device_Class_Miscellaneous
;
_hw_pin
.
parent
.
rx_indicate
=
RT_NULL
;
_hw_pin
.
parent
.
tx_complete
=
RT_NULL
;
_hw_pin
.
parent
.
init
=
RT_NULL
;
_hw_pin
.
parent
.
open
=
RT_NULL
;
_hw_pin
.
parent
.
close
=
RT_NULL
;
_hw_pin
.
parent
.
read
=
_pin_read
;
_hw_pin
.
parent
.
write
=
_pin_write
;
_hw_pin
.
parent
.
control
=
_pin_control
;
_hw_pin
.
parent
.
init
=
RT_NULL
;
_hw_pin
.
parent
.
open
=
RT_NULL
;
_hw_pin
.
parent
.
close
=
RT_NULL
;
_hw_pin
.
parent
.
read
=
_pin_read
;
_hw_pin
.
parent
.
write
=
_pin_write
;
_hw_pin
.
parent
.
control
=
_pin_control
;
_hw_pin
.
ops
=
ops
;
_hw_pin
.
parent
.
user_data
=
user_data
;
_hw_pin
.
parent
.
user_data
=
user_data
;
/* register a character device */
rt_device_register
(
&
_hw_pin
.
parent
,
"pin"
,
RT_DEVICE_FLAG_RDWR
);
/* register a character device */
rt_device_register
(
&
_hw_pin
.
parent
,
"pin"
,
RT_DEVICE_FLAG_RDWR
);
return
0
;
}
...
...
@@ -111,7 +111,7 @@ void rt_pin_write(rt_base_t pin, rt_base_t value)
}
FINSH_FUNCTION_EXPORT_ALIAS
(
rt_pin_write
,
pinWrite
,
write
value
to
hardware
pin
);
int
rt_pin_read
(
rt_base_t
pin
)
int
rt_pin_read
(
rt_base_t
pin
)
{
return
_hw_pin
.
ops
->
pin_read
(
&
_hw_pin
.
parent
,
pin
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录