Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
SummerGao.
rt-thread
提交
f9bad31d
R
rt-thread
项目概览
SummerGao.
/
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,发现更多精彩内容 >>
提交
f9bad31d
编写于
8月 21, 2019
作者:
T
tangweikang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[components][drivers] change name: capture -> inputcapture
上级
e1587de6
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
264 addition
and
69 deletion
+264
-69
components/drivers/Kconfig
components/drivers/Kconfig
+5
-5
components/drivers/include/drivers/rt_capture.h
components/drivers/include/drivers/rt_capture.h
+0
-60
components/drivers/include/drivers/rt_inputcapture.h
components/drivers/include/drivers/rt_inputcapture.h
+60
-0
components/drivers/include/rtdevice.h
components/drivers/include/rtdevice.h
+2
-2
components/drivers/misc/SConscript
components/drivers/misc/SConscript
+2
-2
components/drivers/misc/rt_inputcapture.c
components/drivers/misc/rt_inputcapture.c
+195
-0
未找到文件。
components/drivers/Kconfig
浏览文件 @
f9bad31d
...
...
@@ -438,13 +438,13 @@ config RT_USING_ENCODER
bool "Using ENCODER device drivers"
default n
config RT_USING_CAPTURE
bool "Using CAPTURE device drivers"
config RT_USING_
INPUT_
CAPTURE
bool "Using
INPUT
CAPTURE device drivers"
default n
if RT_USING_CAPTURE
config RT_CAPTURE_RB_SIZE
int "Set capture ringbuffer size"
if RT_USING_
INPUT_
CAPTURE
config RT_
INPUT_
CAPTURE_RB_SIZE
int "Set
input
capture ringbuffer size"
default 100
endif
...
...
components/drivers/include/drivers/rt_capture.h
已删除
100644 → 0
浏览文件 @
e1587de6
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-08-13 balanceTWK first version.
*/
#ifndef __RT_CAPTURE_H__
#define __RT_CAPTURE_H__
#include <rtthread.h>
#include <rtdevice.h>
#ifdef __cplusplus
extern
"C"
{
#endif
/* capture control command */
#define CAPTURE_CMD_CLEAR_BUF (128 + 0)
/* clear capture buf */
#define CAPTURE_CMD_SET_WATERMARK (128 + 1)
/* Set the callback threshold */
struct
capture_data
{
rt_uint32_t
pulsewidth_us
;
rt_bool_t
is_high
;
};
struct
rt_capture_device
{
struct
rt_device
parent
;
const
struct
rt_capture_ops
*
ops
;
struct
rt_ringbuffer
*
ringbuff
;
rt_size_t
watermark
;
};
/**
* capture operators
*/
struct
rt_capture_ops
{
rt_err_t
(
*
init
)(
struct
rt_capture_device
*
capture
);
rt_err_t
(
*
open
)(
struct
rt_capture_device
*
capture
);
rt_err_t
(
*
close
)(
struct
rt_capture_device
*
capture
);
rt_err_t
(
*
get_pulsewidth
)(
struct
rt_capture_device
*
capture
,
rt_uint32_t
*
pulsewidth_us
);
};
void
rt_hw_capture_isr
(
struct
rt_capture_device
*
capture
,
rt_bool_t
level
);
rt_err_t
rt_device_capture_register
(
struct
rt_capture_device
*
capture
,
const
char
*
name
,
void
*
data
);
#ifdef __cplusplus
}
#endif
#endif
/* __RT_CAPTURE_H__ */
components/drivers/include/drivers/rt_inputcapture.h
0 → 100644
浏览文件 @
f9bad31d
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-08-13 balanceTWK first version.
*/
#ifndef __RT_INPUT_CAPTURE_H__
#define __RT_INPUT_CAPTURE_H__
#include <rtthread.h>
#include <rtdevice.h>
#ifdef __cplusplus
extern
"C"
{
#endif
/* capture control command */
#define INPUTCAPTURE_CMD_CLEAR_BUF (128 + 0)
/* clear capture buf */
#define INPUTCAPTURE_CMD_SET_WATERMARK (128 + 1)
/* Set the callback threshold */
struct
rt_inputcapture_data
{
rt_uint32_t
pulsewidth_us
;
rt_bool_t
is_high
;
};
struct
rt_inputcapture_device
{
struct
rt_device
parent
;
const
struct
rt_inputcapture_ops
*
ops
;
struct
rt_ringbuffer
*
ringbuff
;
rt_size_t
watermark
;
};
/**
* capture operators
*/
struct
rt_inputcapture_ops
{
rt_err_t
(
*
init
)(
struct
rt_inputcapture_device
*
inputcapture
);
rt_err_t
(
*
open
)(
struct
rt_inputcapture_device
*
inputcapture
);
rt_err_t
(
*
close
)(
struct
rt_inputcapture_device
*
inputcapture
);
rt_err_t
(
*
get_pulsewidth
)(
struct
rt_inputcapture_device
*
inputcapture
,
rt_uint32_t
*
pulsewidth_us
);
};
void
rt_hw_capture_isr
(
struct
rt_inputcapture_device
*
inputcapture
,
rt_bool_t
level
);
rt_err_t
rt_device_inputcapture_register
(
struct
rt_inputcapture_device
*
inputcapture
,
const
char
*
name
,
void
*
data
);
#ifdef __cplusplus
}
#endif
#endif
/* __RT_INPUT_CAPTURE_H__ */
components/drivers/include/rtdevice.h
浏览文件 @
f9bad31d
...
...
@@ -130,8 +130,8 @@ extern "C" {
#include "drivers/encoder.h"
#endif
#ifdef RT_USING_CAPTURE
#include "drivers/rt_capture.h"
#ifdef RT_USING_
INPUT_
CAPTURE
#include "drivers/rt_
input
capture.h"
#endif
#ifdef __cplusplus
...
...
components/drivers/misc/SConscript
浏览文件 @
f9bad31d
...
...
@@ -17,8 +17,8 @@ if GetDepend(['RT_USING_PWM']):
if
GetDepend
([
'RT_USING_ENCODER'
]):
src
=
src
+
[
'encoder.c'
]
if
GetDepend
([
'RT_USING_CAPTURE'
]):
src
=
src
+
[
'rt_capture.c'
]
if
GetDepend
([
'RT_USING_
INPUT_
CAPTURE'
]):
src
=
src
+
[
'rt_
input
capture.c'
]
if
len
(
src
):
group
=
DefineGroup
(
'DeviceDrivers'
,
src
,
depend
=
[
''
],
CPPPATH
=
CPPPATH
)
...
...
components/drivers/misc/rt_capture.c
→
components/drivers/misc/rt_
input
capture.c
浏览文件 @
f9bad31d
...
...
@@ -12,58 +12,58 @@
#include <rtdevice.h>
#include <rtdbg.h>
static
rt_err_t
rt_capture_init
(
struct
rt_device
*
dev
)
static
rt_err_t
rt_
input
capture_init
(
struct
rt_device
*
dev
)
{
rt_err_t
ret
;
struct
rt_
capture_device
*
capture
;
struct
rt_
inputcapture_device
*
input
capture
;
RT_ASSERT
(
dev
!=
RT_NULL
);
ret
=
RT_EOK
;
capture
=
(
struct
rt_
capture_device
*
)
dev
;
capture
->
watermark
=
R
T_CAPTURE_RB_SIZE
/
2
;
if
(
capture
->
ops
->
init
)
inputcapture
=
(
struct
rt_input
capture_device
*
)
dev
;
inputcapture
->
watermark
=
RT_INPU
T_CAPTURE_RB_SIZE
/
2
;
if
(
input
capture
->
ops
->
init
)
{
ret
=
capture
->
ops
->
init
(
capture
);
ret
=
inputcapture
->
ops
->
init
(
input
capture
);
}
return
ret
;
}
static
rt_err_t
rt_capture_open
(
struct
rt_device
*
dev
,
rt_uint16_t
oflag
)
static
rt_err_t
rt_
input
capture_open
(
struct
rt_device
*
dev
,
rt_uint16_t
oflag
)
{
rt_err_t
ret
;
struct
rt_
capture_device
*
capture
;
struct
rt_
inputcapture_device
*
input
capture
;
RT_ASSERT
(
dev
!=
RT_NULL
);
ret
=
RT_EOK
;
capture
=
(
struct
rt_
capture_device
*
)
dev
;
if
(
capture
->
ringbuff
==
RT_NULL
)
inputcapture
=
(
struct
rt_input
capture_device
*
)
dev
;
if
(
input
capture
->
ringbuff
==
RT_NULL
)
{
capture
->
ringbuff
=
rt_ringbuffer_create
(
sizeof
(
struct
capture_data
)
*
R
T_CAPTURE_RB_SIZE
);
inputcapture
->
ringbuff
=
rt_ringbuffer_create
(
sizeof
(
struct
rt_inputcapture_data
)
*
RT_INPU
T_CAPTURE_RB_SIZE
);
}
if
(
capture
->
ops
->
open
)
if
(
input
capture
->
ops
->
open
)
{
ret
=
capture
->
ops
->
open
(
capture
);
ret
=
inputcapture
->
ops
->
open
(
input
capture
);
}
return
ret
;
}
static
rt_err_t
rt_capture_close
(
struct
rt_device
*
dev
)
static
rt_err_t
rt_
input
capture_close
(
struct
rt_device
*
dev
)
{
rt_err_t
ret
;
struct
rt_
capture_device
*
capture
;
struct
rt_
inputcapture_device
*
input
capture
;
RT_ASSERT
(
dev
!=
RT_NULL
);
ret
=
-
RT_ERROR
;
capture
=
(
struct
rt_
capture_device
*
)
dev
;
inputcapture
=
(
struct
rt_input
capture_device
*
)
dev
;
if
(
capture
->
ops
->
close
)
if
(
input
capture
->
ops
->
close
)
{
ret
=
capture
->
ops
->
close
(
capture
);
ret
=
inputcapture
->
ops
->
close
(
input
capture
);
}
if
(
ret
!=
RT_EOK
)
...
...
@@ -71,49 +71,49 @@ static rt_err_t rt_capture_close(struct rt_device *dev)
return
ret
;
}
if
(
capture
->
ringbuff
)
if
(
input
capture
->
ringbuff
)
{
rt_ringbuffer_destroy
(
capture
->
ringbuff
);
capture
->
ringbuff
=
RT_NULL
;
rt_ringbuffer_destroy
(
input
capture
->
ringbuff
);
input
capture
->
ringbuff
=
RT_NULL
;
}
return
ret
;
}
static
rt_size_t
rt_capture_read
(
struct
rt_device
*
dev
,
static
rt_size_t
rt_
input
capture_read
(
struct
rt_device
*
dev
,
rt_off_t
pos
,
void
*
buffer
,
rt_size_t
size
)
{
rt_size_t
receive_size
;
struct
rt_
capture_device
*
capture
;
struct
rt_
inputcapture_device
*
input
capture
;
RT_ASSERT
(
dev
!=
RT_NULL
);
capture
=
(
struct
rt_
capture_device
*
)
dev
;
receive_size
=
rt_ringbuffer_get
(
capture
->
ringbuff
,
(
rt_uint8_t
*
)
buffer
,
sizeof
(
struct
capture_data
)
*
size
);
inputcapture
=
(
struct
rt_input
capture_device
*
)
dev
;
receive_size
=
rt_ringbuffer_get
(
inputcapture
->
ringbuff
,
(
rt_uint8_t
*
)
buffer
,
sizeof
(
struct
rt_input
capture_data
)
*
size
);
return
receive_size
/
sizeof
(
struct
capture_data
);
return
receive_size
/
sizeof
(
struct
rt_input
capture_data
);
}
static
rt_err_t
rt_capture_control
(
struct
rt_device
*
dev
,
int
cmd
,
void
*
args
)
static
rt_err_t
rt_
input
capture_control
(
struct
rt_device
*
dev
,
int
cmd
,
void
*
args
)
{
rt_err_t
result
;
struct
rt_
capture_device
*
capture
;
struct
rt_
inputcapture_device
*
input
capture
;
RT_ASSERT
(
dev
!=
RT_NULL
);
result
=
RT_EOK
;
capture
=
(
struct
rt_
capture_device
*
)
dev
;
inputcapture
=
(
struct
rt_input
capture_device
*
)
dev
;
switch
(
cmd
)
{
case
CAPTURE_CMD_CLEAR_BUF
:
if
(
capture
->
ringbuff
)
case
INPUT
CAPTURE_CMD_CLEAR_BUF
:
if
(
input
capture
->
ringbuff
)
{
rt_ringbuffer_reset
(
capture
->
ringbuff
);
rt_ringbuffer_reset
(
input
capture
->
ringbuff
);
}
break
;
case
CAPTURE_CMD_SET_WATERMARK
:
capture
->
watermark
=
*
(
rt_size_t
*
)
args
;
case
INPUT
CAPTURE_CMD_SET_WATERMARK
:
input
capture
->
watermark
=
*
(
rt_size_t
*
)
args
;
break
;
default:
result
=
-
RT_ENOSYS
;
...
...
@@ -124,41 +124,41 @@ static rt_err_t rt_capture_control(struct rt_device *dev, int cmd, void *args)
}
#ifdef RT_USING_DEVICE_OPS
const
static
struct
rt_device_ops
capture_ops
=
const
static
struct
rt_device_ops
input
capture_ops
=
{
rt_capture_init
,
rt_capture_open
,
rt_capture_close
,
rt_capture_read
,
rt_
input
capture_init
,
rt_
input
capture_open
,
rt_
input
capture_close
,
rt_
input
capture_read
,
RT_NULL
,
rt_capture_control
rt_
input
capture_control
};
#endif
rt_err_t
rt_device_
capture_register
(
struct
rt_capture_device
*
capture
,
const
char
*
name
,
void
*
user_data
)
rt_err_t
rt_device_
inputcapture_register
(
struct
rt_inputcapture_device
*
input
capture
,
const
char
*
name
,
void
*
user_data
)
{
struct
rt_device
*
device
;
RT_ASSERT
(
capture
!=
RT_NULL
);
RT_ASSERT
(
capture
->
ops
!=
RT_NULL
);
RT_ASSERT
(
capture
->
ops
->
get_pulsewidth
!=
RT_NULL
);
RT_ASSERT
(
input
capture
!=
RT_NULL
);
RT_ASSERT
(
input
capture
->
ops
!=
RT_NULL
);
RT_ASSERT
(
input
capture
->
ops
->
get_pulsewidth
!=
RT_NULL
);
device
=
&
(
capture
->
parent
);
device
=
&
(
input
capture
->
parent
);
device
->
type
=
RT_Device_Class_Miscellaneous
;
device
->
rx_indicate
=
RT_NULL
;
device
->
tx_complete
=
RT_NULL
;
capture
->
ringbuff
=
RT_NULL
;
input
capture
->
ringbuff
=
RT_NULL
;
#ifdef RT_USING_DEVICE_OPS
device
->
ops
=
&
capture_ops
;
device
->
ops
=
&
input
capture_ops
;
#else
device
->
init
=
rt_capture_init
;
device
->
open
=
rt_capture_open
;
device
->
close
=
rt_capture_close
;
device
->
read
=
rt_capture_read
;
device
->
init
=
rt_
input
capture_init
;
device
->
open
=
rt_
input
capture_open
;
device
->
close
=
rt_
input
capture_close
;
device
->
read
=
rt_
input
capture_read
;
device
->
write
=
RT_NULL
;
device
->
control
=
rt_capture_control
;
device
->
control
=
rt_
input
capture_control
;
#endif
device
->
user_data
=
user_data
;
...
...
@@ -166,30 +166,30 @@ rt_err_t rt_device_capture_register(struct rt_capture_device *capture, const cha
}
/**
* This function is ISR for capture interrupt.
* This function is ISR for
input
capture interrupt.
* level: RT_TRUE denotes high level pulse, and RT_FALSE denotes low level pulse.
*/
void
rt_hw_
capture_isr
(
struct
rt_capture_device
*
capture
,
rt_bool_t
level
)
void
rt_hw_
inputcapture_isr
(
struct
rt_inputcapture_device
*
input
capture
,
rt_bool_t
level
)
{
struct
capture_data
data
;
struct
rt_input
capture_data
data
;
rt_size_t
receive_size
;
if
(
capture
->
ops
->
get_pulsewidth
(
capture
,
&
data
.
pulsewidth_us
)
!=
RT_EOK
)
if
(
inputcapture
->
ops
->
get_pulsewidth
(
input
capture
,
&
data
.
pulsewidth_us
)
!=
RT_EOK
)
{
return
;
}
data
.
is_high
=
level
;
if
(
rt_ringbuffer_put
(
capture
->
ringbuff
,
(
rt_uint8_t
*
)
&
data
,
sizeof
(
struct
capture_data
))
==
0
)
if
(
rt_ringbuffer_put
(
inputcapture
->
ringbuff
,
(
rt_uint8_t
*
)
&
data
,
sizeof
(
struct
rt_input
capture_data
))
==
0
)
{
LOG_W
(
"capture ringbuffer doesn't have enough space."
);
LOG_W
(
"
input
capture ringbuffer doesn't have enough space."
);
}
receive_size
=
rt_ringbuffer_data_len
(
capture
->
ringbuff
)
/
sizeof
(
struct
capture_data
);
receive_size
=
rt_ringbuffer_data_len
(
inputcapture
->
ringbuff
)
/
sizeof
(
struct
rt_input
capture_data
);
if
(
receive_size
>=
capture
->
watermark
)
if
(
receive_size
>=
input
capture
->
watermark
)
{
/* indicate to upper layer application */
if
(
capture
->
parent
.
rx_indicate
!=
RT_NULL
)
capture
->
parent
.
rx_indicate
(
&
capture
->
parent
,
receive_size
);
if
(
input
capture
->
parent
.
rx_indicate
!=
RT_NULL
)
inputcapture
->
parent
.
rx_indicate
(
&
input
capture
->
parent
,
receive_size
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录