Skip to content

Commit 01e3b36

Browse files
committed
add readme file
1 parent 5bb505c commit 01e3b36

File tree

4 files changed

+318
-25
lines changed

4 files changed

+318
-25
lines changed

README.md

+266
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
# VL53L0X TOF传感器驱动软件包
2+
3+
4+
5+
## 1 简介
6+
7+
vl53l0x软件包是基于RT-Thread sensor框架实现的一个驱动包。基于该软件包,RT-Thread应用程序可以使用标准的sensor接口访问vl53l0x,获取传感器数据。
8+
9+
10+
11+
### 1.1 目录结构
12+
13+
| 名称 | 说明 |
14+
| ---------- | ------------------------------ |
15+
| docs | 文档目录 |
16+
| vl53l0x | 官方库函数以及i2c platform对接 |
17+
| examples | 例子目录 |
18+
| inc | 头文件目录 |
19+
| src | 源代码目录 |
20+
| LICENSE | 许可证文件 |
21+
| SConscript | RT-Thread默认构建脚本 |
22+
23+
24+
25+
### 1.2 许可证
26+
27+
vl53l0x软件包遵循 Apache license v2.0 许可,详见 `LICENSE` 文件。
28+
29+
<br>
30+
31+
## 2 传感器介绍
32+
33+
vl53l0x是 STMicroelectronics(意法半导体)公司推出的新一代单点TOF(Time of Flight)传感器,具备体积小、测量精度高、测量距离远、无需增加外部光学器件、使用简单等优点;此外,vl53l0x采用940nm肉眼不可见光源,集成物理红外过滤器,提高对环境光的抗干扰特性,具备良好的鲁棒性和防光学串扰特性。
34+
35+
测量参数:
36+
37+
| 功能 | 量程 | 分辨率 | 精度 |
38+
| ---- | -------- | ------ | ---- |
39+
| 距离 | 0—2000mm | 1mm ||
40+
41+
应用场合:
42+
43+
* 相机对焦
44+
* 1D手势识别
45+
* 白色家电检测(额温枪、水龙头)
46+
* 机器人避障
47+
48+
<br>
49+
50+
## 3 支持情况
51+
52+
53+
54+
| 包含设备 | TOF |
55+
| ------------ | ---- |
56+
| **通信接口** | |
57+
| IIC ||
58+
| SPI | |
59+
| **工作模式** | |
60+
| 轮询 ||
61+
| 中断 | |
62+
| FIFO | |
63+
| **电源模式** | |
64+
| 掉电 ||
65+
| 低功耗 | |
66+
| 普通 ||
67+
68+
>注:
69+
>
70+
>目前暂时只支持单次测量模式;后续增加:
71+
>
72+
>* 连续测量模式
73+
>* 定时测量模式
74+
>* 测距校准功能
75+
76+
<br>
77+
78+
79+
80+
## 4 使用说明
81+
82+
### 4.1 依赖
83+
84+
- RT-Thread 4.0.0+
85+
86+
- sensor 框架组件
87+
88+
- I2C 驱动,vl53l0x使用 I2C 进行数据通讯,需要系统 I2C 驱动框架支持
89+
90+
- PIN驱动,用于vl53l0x开关机(复位)引脚控制
91+
92+
93+
94+
### 4.2 获取软件包
95+
96+
使用 vl53l0xpackage 需要在 RT-Thread 的包管理器中选择它,具体路径如下。然后让 RT-Thread 的包管理器自动更新,或者使用 `pkgs --update` 命令更新包到 BSP 中。如需使用示例程序,则使能<code>Enable vl53l0x sample</code>。
97+
98+
```
99+
RT-Thread online packages --->
100+
peripheral libraries and drivers --->
101+
sensors drivers --->
102+
[*] VL53L0X Time of flight(TOF) sensor.
103+
[*] Enable vl53l0x sample
104+
Version (latest) --->
105+
```
106+
107+
> **Version**:软件包版本选择,默认选择最新版本。
108+
109+
110+
111+
### 4.3 初始化
112+
113+
vl53l0x软件包初始化函数如下所示:
114+
115+
```c
116+
int rt_hw_vl53l0x_init(const char *name, struct rt_sensor_config *cfg,rt_base_t xsht_pin);
117+
```
118+
119+
| 参数 | 描述 |
120+
| --------- | -------------- |
121+
| name | 传感器名称 |
122+
| cfg | sensor配置信息 |
123+
| xsht | 电源控制GPIO |
124+
| **返回** | — |
125+
| RT_EOK | 初始化成功 |
126+
| -RT_ERROR | 初始化失败 |
127+
128+
129+
130+
该函数需要由用户调用,函数主要完成的功能有:
131+
132+
- 根据配置信息配置i2c名称、i2c地址等(可增加其他配置信息),然后初始化设备
133+
134+
- 选择电源控制GPIO
135+
136+
- 注册相应的传感器设备,完成 vl53l0x设备的注册
137+
138+
139+
140+
**参考示例:**
141+
142+
```c
143+
#include "vl53l0x.h"
144+
145+
static int rt_hw_vl53l0x_port(void)
146+
{
147+
struct rt_sensor_config cfg;
148+
149+
cfg.intf.dev_name = "i2c1"; /* i2c bus */
150+
cfg.intf.user_data = (void *)0x29; /* i2c slave addr */
151+
rt_hw_vl53l0x_init("vl53l0x", &cfg, 57);/* xshutdown ctrl pin */
152+
153+
return RT_EOK;
154+
}
155+
INIT_COMPONENT_EXPORT(rt_hw_vl53l0x_port);
156+
```
157+
158+
159+
160+
### 4.4 读取数据
161+
162+
vl53l0x软件包基于sensor框架,sensor框架继承于RT-Thread标准设备框架,可以使用RT-Thread标准设备接口"open/read"读取传感器数据。
163+
164+
165+
166+
**参考伪代码:**
167+
168+
```
169+
temp_dev = rt_device_find("tof_vl53l0x");
170+
rt_device_open(temp_dev, RT_DEVICE_FLAG_RDONLY);
171+
rt_device_read(temp_dev, 0, &sensor_data, 1);
172+
```
173+
174+
175+
176+
### 4.5 msh/finsh测试
177+
178+
#### 查看设备注册
179+
180+
```
181+
msh >list_device
182+
device type ref count
183+
-------- -------------------- ----------
184+
tof_vl53 Sensor Device 0
185+
i2c1 I2C Bus 0
186+
pin Miscellaneous Device 0
187+
uart2 Character Device 0
188+
uart1 Character Device 2
189+
```
190+
191+
>注:
192+
>
193+
>完整设备名称为“tof_vl53l0x”,终端显示有长度限制
194+
195+
196+
197+
#### 运行例程周期打印数据
198+
199+
```b
200+
\ | /
201+
- RT - Thread Operating System
202+
/ | \ 4.0.1 build Dec 17 2020
203+
2006 - 2019 Copyright by rt-thread team
204+
[I/sensor] rt_sensor init success
205+
[I/vl53l0x] vl53l0x info:
206+
Name[VL53L0X ES1 or later]
207+
Type[VL53L0X]
208+
ProductId[VL53L0CBV0DH/1$1]
209+
210+
msh >distance[153mm],timestamp[87]
211+
distance[161mm],timestamp[192]
212+
distance[154mm],timestamp[297]
213+
distance[152mm],timestamp[402]
214+
```
215+
216+
217+
218+
#### 使用RTT自带的测试命令
219+
220+
* 探测设备
221+
222+
```b
223+
msh >sensor probe tof_vl53l0x
224+
[I/sensor.cmd] device id: 0xee!
225+
```
226+
227+
228+
229+
* 获取传感器信息
230+
231+
```
232+
msh >sensor info
233+
vendor :STMicroelectronics
234+
model :vl53l0x
235+
unit :mm
236+
range_max :2000
237+
range_min :0
238+
period_min:100ms
239+
fifo_max :0
240+
```
241+
242+
> 注:
243+
>
244+
> sensor框架暂未提供tof传感器相关描述信息,已在RT-Thread源码上PR。
245+
246+
* 读取测距数据
247+
248+
```b
249+
msh >sensor read 3
250+
[I/sensor.cmd] num: 0, distance: 212, timestamp:131863
251+
[I/sensor.cmd] num: 1, distance: 213, timestamp:131878
252+
[I/sensor.cmd] num: 2, distance: 213, timestamp:131893
253+
```
254+
255+
<br>
256+
257+
## 5 注意事项
258+
259+
暂无
260+
261+
<br>
262+
263+
## 6 联系方式
264+
265+
- 维护:[Acuity](https://github.com/Prry)
266+
- 主页:<https://github.com/Prry/rtt-vl53l0x>

examples/vl53l0x_sample.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
#include "sensor.h"
1515
#include "vl53l0x.h"
1616

17-
static void read_temp_entry(void *parameter)
17+
static void read_distance_entry(void *parameter)
1818
{
1919
rt_device_t temp_dev = RT_NULL;
2020
struct rt_sensor_data temp_data;
2121
rt_size_t res = 0;
2222
rt_uint32_t index = 0;
2323

24-
temp_dev = rt_device_find("pr_vl53l0x");
24+
temp_dev = rt_device_find("tof_vl53l0x");
2525
if (temp_dev == RT_NULL)
2626
{
2727
rt_kprintf("not found tof_vl53l0x device\r\n");
@@ -45,7 +45,7 @@ static void read_temp_entry(void *parameter)
4545
}
4646
else
4747
{
48-
rt_kprintf("temp[%dmm],timestamp[%d]\r\n",temp_data.data.proximity,
48+
rt_kprintf("distance[%dmm],timestamp[%d]\r\n",temp_data.data.proximity,
4949
temp_data.timestamp);
5050
}
5151

@@ -58,32 +58,32 @@ static void read_temp_entry(void *parameter)
5858
}
5959
}
6060

61-
static int temp_read_sample(void)
61+
static int read_distance_sample(void)
6262
{
63-
rt_thread_t temp_thread;
63+
rt_thread_t distance_thread;
6464

65-
temp_thread = rt_thread_create("tof_r",
66-
read_temp_entry,
65+
distance_thread = rt_thread_create("tof_r",
66+
read_distance_entry,
6767
RT_NULL,
6868
1024,
6969
RT_THREAD_PRIORITY_MAX / 2,
7070
20);
71-
if (temp_thread != RT_NULL)
71+
if (distance_thread != RT_NULL)
7272
{
73-
rt_thread_startup(temp_thread);
73+
rt_thread_startup(distance_thread);
7474
}
7575

7676
return RT_EOK;
7777
}
78-
INIT_APP_EXPORT(temp_read_sample);
78+
INIT_APP_EXPORT(read_distance_sample);
7979

8080
static int rt_hw_vl53l0x_port(void)
8181
{
8282
struct rt_sensor_config cfg;
8383

8484
cfg.intf.dev_name = "i2c1"; /* i2c bus */
8585
cfg.intf.user_data = (void *)0x29; /* i2c slave addr */
86-
rt_hw_vl53l0x_init("vl53l0x", &cfg, 57);/* vl53l0x */
86+
rt_hw_vl53l0x_init("vl53l0x", &cfg, 57);/* xshutdown ctrl pin */
8787

8888
return RT_EOK;
8989
}

inc/vl53l0x.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
#include <rtthread.h>
66

7-
extern int rt_hw_vl53l0x_init(const char *name, struct rt_sensor_config *cfg, rt_base_t rst_pin);
7+
extern int rt_hw_vl53l0x_init(const char *name, struct rt_sensor_config *cfg, rt_base_t xsht_pin);
88

99
#endif

0 commit comments

Comments
 (0)