Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaobo07
rt-thread
提交
7d6fa238
R
rt-thread
项目概览
Xiaobo07
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
2
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,发现更多精彩内容 >>
提交
7d6fa238
编写于
6月 13, 2019
作者:
G
guozhanxin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[sensor] To streamline the code.| 精简代码,去除冗余的代码。
上级
2600f82e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
21 addition
and
52 deletion
+21
-52
components/drivers/sensors/sensor.c
components/drivers/sensors/sensor.c
+21
-52
未找到文件。
components/drivers/sensors/sensor.c
浏览文件 @
7d6fa238
...
...
@@ -116,24 +116,6 @@ static rt_err_t rt_sensor_irq_init(rt_sensor_t sensor)
return
0
;
}
/* Sensor interrupt enable */
static
void
rt_sensor_irq_enable
(
rt_sensor_t
sensor
)
{
if
(
sensor
->
config
.
irq_pin
.
pin
!=
RT_PIN_NONE
)
{
rt_pin_irq_enable
(
sensor
->
config
.
irq_pin
.
pin
,
RT_TRUE
);
}
}
/* Sensor interrupt disable */
static
void
rt_sensor_irq_disable
(
rt_sensor_t
sensor
)
{
if
(
sensor
->
config
.
irq_pin
.
pin
!=
RT_PIN_NONE
)
{
rt_pin_irq_enable
(
sensor
->
config
.
irq_pin
.
pin
,
RT_FALSE
);
}
}
/* RT-Thread Device Interface */
static
rt_err_t
rt_sensor_open
(
rt_device_t
dev
,
rt_uint16_t
oflag
)
{
...
...
@@ -160,31 +142,34 @@ static rt_err_t rt_sensor_open(rt_device_t dev, rt_uint16_t oflag)
if
(
oflag
&
RT_DEVICE_FLAG_RDONLY
&&
dev
->
flag
&
RT_DEVICE_FLAG_RDONLY
)
{
/* If polling mode is supported, configure it to polling mode */
if
(
sensor
->
ops
->
control
(
sensor
,
RT_SENSOR_CTRL_SET_MODE
,
(
void
*
)
RT_SENSOR_MODE_POLLING
)
==
RT_EOK
)
if
(
sensor
->
ops
->
control
!=
RT_NULL
)
{
sensor
->
config
.
mode
=
RT_SENSOR_MODE_POLLING
;
/* If polling mode is supported, configure it to polling mode */
sensor
->
ops
->
control
(
sensor
,
RT_SENSOR_CTRL_SET_MODE
,
(
void
*
)
RT_SENSOR_MODE_POLLING
);
}
sensor
->
config
.
mode
=
RT_SENSOR_MODE_POLLING
;
}
else
if
(
oflag
&
RT_DEVICE_FLAG_INT_RX
&&
dev
->
flag
&
RT_DEVICE_FLAG_INT_RX
)
{
/* If interrupt mode is supported, configure it to interrupt mode */
if
(
sensor
->
ops
->
control
(
sensor
,
RT_SENSOR_CTRL_SET_MODE
,
(
void
*
)
RT_SENSOR_MODE_INT
)
==
RT_EOK
)
if
(
sensor
->
ops
->
control
!=
RT_NULL
)
{
sensor
->
config
.
mode
=
RT_SENSOR_MODE_INT
;
/* Initialization sensor interrupt */
rt_sensor_irq_init
(
sensor
);
/* If interrupt mode is supported, configure it to interrupt mode */
sensor
->
ops
->
control
(
sensor
,
RT_SENSOR_CTRL_SET_MODE
,
(
void
*
)
RT_SENSOR_MODE_INT
);
}
/* Initialization sensor interrupt */
rt_sensor_irq_init
(
sensor
);
sensor
->
config
.
mode
=
RT_SENSOR_MODE_INT
;
}
else
if
(
oflag
&
RT_DEVICE_FLAG_FIFO_RX
&&
dev
->
flag
&
RT_DEVICE_FLAG_FIFO_RX
)
{
/* If fifo mode is supported, configure it to fifo mode */
if
(
sensor
->
ops
->
control
(
sensor
,
RT_SENSOR_CTRL_SET_MODE
,
(
void
*
)
RT_SENSOR_MODE_FIFO
)
==
RT_EOK
)
if
(
sensor
->
ops
->
control
!=
RT_NULL
)
{
sensor
->
config
.
mode
=
RT_SENSOR_MODE_FIFO
;
/* Initialization sensor interrupt */
rt_sensor_irq_init
(
sensor
);
/* If fifo mode is supported, configure it to fifo mode */
sensor
->
ops
->
control
(
sensor
,
RT_SENSOR_CTRL_SET_MODE
,
(
void
*
)
RT_SENSOR_MODE_FIFO
);
}
/* Initialization sensor interrupt */
rt_sensor_irq_init
(
sensor
);
sensor
->
config
.
mode
=
RT_SENSOR_MODE_FIFO
;
}
else
{
...
...
@@ -208,7 +193,7 @@ __exit:
return
res
;
}
static
rt_err_t
rt_sensor_close
(
rt_device_t
dev
)
static
rt_err_t
rt_sensor_close
(
rt_device_t
dev
)
{
rt_sensor_t
sensor
=
(
rt_sensor_t
)
dev
;
int
i
;
...
...
@@ -227,7 +212,10 @@ static rt_err_t rt_sensor_close(rt_device_t dev)
}
/* Sensor disable interrupt */
rt_sensor_irq_disable
(
sensor
);
if
(
sensor
->
config
.
irq_pin
.
pin
!=
RT_PIN_NONE
)
{
rt_pin_irq_enable
(
sensor
->
config
.
irq_pin
.
pin
,
RT_FALSE
);
}
if
(
sensor
->
module
!=
RT_NULL
&&
sensor
->
info
.
fifo_max
>
0
&&
sensor
->
data_buf
!=
RT_NULL
)
{
...
...
@@ -346,25 +334,6 @@ static rt_err_t rt_sensor_control(rt_device_t dev, int cmd, void *args)
LOG_D
(
"set odr %d"
,
sensor
->
config
.
odr
);
}
break
;
case
RT_SENSOR_CTRL_SET_MODE
:
/* Configuration sensor work mode */
result
=
sensor
->
ops
->
control
(
sensor
,
RT_SENSOR_CTRL_SET_MODE
,
args
);
if
(
result
==
RT_EOK
)
{
sensor
->
config
.
mode
=
(
rt_uint32_t
)
args
&
0xFF
;
LOG_D
(
"set work mode code:"
,
sensor
->
config
.
mode
);
if
(
sensor
->
config
.
mode
==
RT_SENSOR_MODE_POLLING
)
{
rt_sensor_irq_disable
(
sensor
);
}
else
if
(
sensor
->
config
.
mode
==
RT_SENSOR_MODE_INT
||
sensor
->
config
.
mode
==
RT_SENSOR_MODE_FIFO
)
{
rt_sensor_irq_enable
(
sensor
);
}
}
break
;
case
RT_SENSOR_CTRL_SET_POWER
:
/* Configuration sensor power mode */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录