Skip to content

Commit 98e11c8

Browse files
committed
[driver] Add vl53l5, vl53l7, vl53l8 drivers
1 parent 7aafb63 commit 98e11c8

File tree

7 files changed

+614
-0
lines changed

7 files changed

+614
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@
5252
[submodule "ext/segger/rtt"]
5353
path = ext/segger/rtt
5454
url = https://github.com/modm-ext/segger-rtt.git
55+
[submodule "ext/vl53/vl53"]
56+
path = ext/vl53/vl53
57+
url = https://github.com/modm-ext/vl53-partial.git

ext/vl53/vl53

Submodule vl53 added at e41b856

ext/vl53/vl53.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2025, Henrik Hose
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
// ----------------------------------------------------------------------------
11+
12+
#include "vl53_transport.hpp"
13+
14+
extern "C" {
15+
#include "vl53_platform.h"
16+
17+
uint8_t
18+
VL53_RdByte(VL53_Platform *p_platform, uint16_t RegisterAddress, uint8_t *p_value)
19+
{
20+
auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport);
21+
return iface->readByte(RegisterAddress, p_value);
22+
}
23+
24+
uint8_t
25+
VL53_WrByte(VL53_Platform *p_platform, uint16_t RegisterAddress, uint8_t value)
26+
{
27+
auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport);
28+
return iface->writeByte(RegisterAddress, value);
29+
}
30+
31+
uint8_t
32+
VL53_WrMulti(VL53_Platform *p_platform, uint16_t RegisterAddress, uint8_t *p_values, uint32_t size)
33+
{
34+
auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport);
35+
return iface->writeMulti(RegisterAddress, p_values, size);
36+
}
37+
38+
uint8_t
39+
VL53_RdMulti(VL53_Platform *p_platform, uint16_t RegisterAddress, uint8_t *p_values, uint32_t size)
40+
{
41+
auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport);
42+
return iface->readMulti(RegisterAddress, p_values, size);
43+
}
44+
45+
void
46+
VL53_SwapBuffer(uint8_t *buffer, uint16_t size)
47+
{
48+
uint32_t i, tmp;
49+
50+
for (i = 0; i < size; i = i + 4)
51+
{
52+
tmp = (buffer[i] << 24) | (buffer[i + 1] << 16) | (buffer[i + 2] << 8) | (buffer[i + 3]);
53+
memcpy(&(buffer[i]), &tmp, 4);
54+
}
55+
}
56+
57+
uint8_t
58+
VL53_WaitMs(VL53_Platform*, uint32_t TimeMs)
59+
{
60+
modm::this_fiber::sleep_for(std::chrono::milliseconds(TimeMs));
61+
return 0;
62+
}
63+
64+
uint8_t
65+
VL53_Reset_Sensor(VL53_Platform *p_platform)
66+
{
67+
auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport);
68+
return iface->resetSensor();
69+
}
70+
}

ext/vl53/vl53.lb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2025, Henrik Hose
5+
#
6+
# This file is part of the modm project.
7+
#
8+
# This Source Code Form is subject to the terms of the Mozilla Public
9+
# License, v. 2.0. If a copy of the MPL was not distributed with this
10+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
11+
# -----------------------------------------------------------------------------
12+
13+
class Vl53l5cx(Module):
14+
def init(self, module):
15+
module.name = "vl53l5cx"
16+
module.description = "Driver for ST VL53L5CX Multi-Zone Time-of-Flight Sensor"
17+
18+
def prepare(self, module, options):
19+
return True
20+
21+
def build(self, env):
22+
env.outbasepath = "modm/ext"
23+
env.copy("vl53/vl53l5cx/src")
24+
env.copy("vl53/vl53l5cx/inc")
25+
env.copy("vl53/vl53l5cx/LICENSE.txt")
26+
env.collect(":build:path.include", "modm/ext/vl53/vl53l5cx/inc")
27+
28+
class Vl53lmz(Module):
29+
def init(self, module):
30+
module.name = "vl53lmz"
31+
module.description = "Driver for ST VL53L7 and VL53L8 Multi-Zone Time-of-Flight Sensors"
32+
33+
def prepare(self, module, options):
34+
return True
35+
36+
def build(self, env):
37+
env.outbasepath = "modm/ext"
38+
env.copy("vl53/vl53lmz/src")
39+
env.copy("vl53/vl53lmz/inc")
40+
env.copy("vl53/vl53lmz/LICENSE.txt")
41+
env.collect(":build:path.include", "modm/ext/vl53/vl53lmz/inc")
42+
43+
def init(module):
44+
module.name = ":vl53"
45+
module.description = """\
46+
# ST's VL53 Time-of-Flight ULD Drivers
47+
48+
Currently supported sensors:
49+
- With VL53LMZ driver: VL53L7CX, VL53L7CH, VL53L8CX, VL53L8CH
50+
- VL53L5CX driver
51+
52+
"""
53+
54+
def prepare(module, options):
55+
module.add_submodule(Vl53l5cx())
56+
module.add_submodule(Vl53lmz())
57+
module.depends(
58+
":architecture:spi.device",
59+
":architecture:i2c.device",
60+
":architecture:fiber",
61+
":driver:i2c.eeprom")
62+
return True
63+
64+
def build(env):
65+
env.outbasepath = "modm/src/modm/driver/vl53"
66+
env.copy("vl53.cpp")
67+
env.copy("vl53_transport.hpp")
68+
env.copy("vl53_transport_impl.hpp")
69+
70+
env.outbasepath = "modm/ext/vl53"
71+
env.collect(":build:path.include", "modm/ext/vl53")
72+
env.copy("vl53_platform.h")

ext/vl53/vl53_platform.h

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
/**
2+
*
3+
* Copyright (c) 2021 STMicroelectronics.
4+
* All rights reserved.
5+
*
6+
*
7+
* This software component is provided to you as part of a software package and
8+
* applicable license terms are in the Package_license file. If you received this
9+
* software component outside of a package or without applicable license terms,
10+
* the terms of the BSD-3-Clause license shall apply.
11+
* You may obtain a copy of the BSD-3-Clause at:
12+
* https://opensource.org/licenses/BSD-3-Clause
13+
*
14+
******************************************************************************
15+
*/
16+
17+
#ifndef VL53_PLATFORM_H_
18+
#define VL53_PLATFORM_H_
19+
#pragma once
20+
21+
#if __has_include("modm_config_vl53.h")
22+
#include "modm_config_vl53.h"
23+
#endif
24+
25+
#include <stdint.h>
26+
#include <string.h>
27+
28+
/*
29+
* @brief The macro below is used to define the number of target per zone sent
30+
* through I2C. This value can be changed by user, in order to tune I2C
31+
* transaction, and also the total memory size (a lower number of target per
32+
* zone means a lower RAM). The value must be between 1 and 4.
33+
*/
34+
35+
#define VL53L5CX_NB_TARGET_PER_ZONE 1U
36+
37+
/*
38+
* @brief The macro below can be used to avoid data conversion into the driver.
39+
* By default there is a conversion between firmware and user data. Using this macro
40+
* allows to use the firmware format instead of user format. The firmware format allows
41+
* an increased precision.
42+
*/
43+
44+
// #define VL53L5CX_USE_RAW_FORMAT
45+
46+
/*
47+
* @brief All macro below are used to configure the sensor output. User can
48+
* define some macros if he wants to disable selected output, in order to reduce
49+
* I2C access.
50+
*/
51+
52+
// #define VL53L5CX_DISABLE_AMBIENT_PER_SPAD
53+
// #define VL53L5CX_DISABLE_NB_SPADS_ENABLED
54+
// #define VL53L5CX_DISABLE_NB_TARGET_DETECTED
55+
// #define VL53L5CX_DISABLE_SIGNAL_PER_SPAD
56+
// #define VL53L5CX_DISABLE_RANGE_SIGMA_MM
57+
// #define VL53L5CX_DISABLE_DISTANCE_MM
58+
// #define VL53L5CX_DISABLE_REFLECTANCE_PERCENT
59+
// #define VL53L5CX_DISABLE_TARGET_STATUS
60+
// #define VL53L5CX_DISABLE_MOTION_INDICATOR
61+
62+
/*
63+
* @brief The macro below is used to define the number of target per zone sent
64+
* through I2C. This value can be changed by user, in order to tune I2C
65+
* transaction, and also the total memory size (a lower number of target per
66+
* zone means a lower RAM usage).
67+
*/
68+
69+
#define VL53LMZ_NB_TARGET_PER_ZONE 1
70+
71+
/*
72+
* @brief All macro below are used to configure the sensor output. User can
73+
* define some macros if he wants to disable selected output, in order to reduce
74+
* I2C access.
75+
*/
76+
77+
// #define VL53LMZ_DISABLE_AMBIENT_PER_SPAD
78+
// #define VL53LMZ_DISABLE_NB_SPADS_ENABLED
79+
// #define VL53LMZ_DISABLE_NB_TARGET_DETECTED
80+
// #define VL53LMZ_DISABLE_SIGNAL_PER_SPAD
81+
// #define VL53LMZ_DISABLE_RANGE_SIGMA_MM
82+
// #define VL53LMZ_DISABLE_DISTANCE_MM
83+
// #define VL53LMZ_DISABLE_REFLECTANCE_PERCENT
84+
// #define VL53LMZ_DISABLE_TARGET_STATUS
85+
// #define VL53LMZ_DISABLE_SCI
86+
87+
/**
88+
* @brief Structure VL53_Platform needs to be filled by the customer,
89+
* depending on his platform. At least, it contains the VL53 I2C address.
90+
* Some additional fields can be added, as descriptors, or platform
91+
* dependencies. Anything added into this structure is visible into the platform
92+
* layer.
93+
*/
94+
95+
typedef struct
96+
{
97+
/* To be filled with customer's platform. At least an I2C address/descriptor
98+
* needs to be added */
99+
/* Example for most standard platform : I2C address of sensor */
100+
uint16_t address;
101+
102+
void *transport;
103+
104+
} VL53_Platform;
105+
106+
/*
107+
* @brief The macro below is used to define the number of target per zone sent
108+
* through I2C. This value can be changed by user, in order to tune I2C
109+
* transaction, and also the total memory size (a lower number of target per
110+
* zone means a lower RAM). The value must be between 1 and 4.
111+
*/
112+
113+
#define VL53_NB_TARGET_PER_ZONE 1U
114+
115+
/*
116+
* @brief The macro below can be used to avoid data conversion into the driver.
117+
* By default there is a conversion between firmware and user data. Using this macro
118+
* allows to use the firmware format instead of user format. The firmware format allows
119+
* an increased precision.
120+
*/
121+
122+
// #define VL53_USE_RAW_FORMAT
123+
124+
/*
125+
* @brief All macro below are used to configure the sensor output. User can
126+
* define some macros if he wants to disable selected output, in order to reduce
127+
* I2C access.
128+
*/
129+
130+
// #define VL53_DISABLE_AMBIENT_PER_SPAD
131+
// #define VL53_DISABLE_NB_SPADS_ENABLED
132+
// #define VL53_DISABLE_NB_TARGET_DETECTED
133+
// #define VL53_DISABLE_SIGNAL_PER_SPAD
134+
// #define VL53_DISABLE_RANGE_SIGMA_MM
135+
// #define VL53_DISABLE_DISTANCE_MM
136+
// #define VL53_DISABLE_REFLECTANCE_PERCENT
137+
// #define VL53_DISABLE_TARGET_STATUS
138+
// #define VL53_DISABLE_MOTION_INDICATOR
139+
140+
/**
141+
* @param (VL53_Platform*) p_platform : Pointer of VL53 platform
142+
* structure.
143+
* @param (uint16_t) Address : I2C location of value to read.
144+
* @param (uint8_t) *p_values : Pointer of value to read.
145+
* @return (uint8_t) status : 0 if OK
146+
*/
147+
148+
uint8_t
149+
VL53_RdByte(VL53_Platform *p_platform, uint16_t RegisterAdress, uint8_t *p_value);
150+
151+
/**
152+
* @brief Mandatory function used to write one single byte.
153+
* @param (VL53_Platform*) p_platform : Pointer of VL53 platform
154+
* structure.
155+
* @param (uint16_t) Address : I2C location of value to read.
156+
* @param (uint8_t) value : Pointer of value to write.
157+
* @return (uint8_t) status : 0 if OK
158+
*/
159+
160+
uint8_t
161+
VL53_WrByte(VL53_Platform *p_platform, uint16_t RegisterAdress, uint8_t value);
162+
163+
/**
164+
* @brief Mandatory function used to read multiples bytes.
165+
* @param (VL53_Platform*) p_platform : Pointer of VL53 platform
166+
* structure.
167+
* @param (uint16_t) Address : I2C location of values to read.
168+
* @param (uint8_t) *p_values : Buffer of bytes to read.
169+
* @param (uint32_t) size : Size of *p_values buffer.
170+
* @return (uint8_t) status : 0 if OK
171+
*/
172+
173+
uint8_t
174+
VL53_RdMulti(VL53_Platform *p_platform, uint16_t RegisterAdress, uint8_t *p_values, uint32_t size);
175+
176+
/**
177+
* @brief Mandatory function used to write multiples bytes.
178+
* @param (VL53_Platform*) p_platform : Pointer of VL53 platform
179+
* structure.
180+
* @param (uint16_t) Address : I2C location of values to write.
181+
* @param (uint8_t) *p_values : Buffer of bytes to write.
182+
* @param (uint32_t) size : Size of *p_values buffer.
183+
* @return (uint8_t) status : 0 if OK
184+
*/
185+
186+
uint8_t
187+
VL53_WrMulti(VL53_Platform *p_platform, uint16_t RegisterAdress, uint8_t *p_values, uint32_t size);
188+
189+
/**
190+
* @brief Optional function, only used to perform an hardware reset of the
191+
* sensor. This function is not used in the API, but it can be used by the host.
192+
* This function is not mandatory to fill if user don't want to reset the
193+
* sensor.
194+
* @param (VL53_Platform*) p_platform : Pointer of VL53 platform
195+
* structure.
196+
* @return (uint8_t) status : 0 if OK
197+
*/
198+
199+
uint8_t
200+
VL53_Reset_Sensor(VL53_Platform *p_platform);
201+
202+
/**
203+
* @brief Mandatory function, used to swap a buffer. The buffer size is always a
204+
* multiple of 4 (4, 8, 12, 16, ...).
205+
* @param (uint8_t*) buffer : Buffer to swap, generally uint32_t
206+
* @param (uint16_t) size : Buffer size to swap
207+
*/
208+
209+
void
210+
VL53_SwapBuffer(uint8_t *buffer, uint16_t size);
211+
/**
212+
* @brief Mandatory function, used to wait during an amount of time. It must be
213+
* filled as it's used into the API.
214+
* @param (VL53_Platform*) p_platform : Pointer of VL53 platform
215+
* structure.
216+
* @param (uint32_t) TimeMs : Time to wait in ms.
217+
* @return (uint8_t) status : 0 if wait is finished.
218+
*/
219+
220+
uint8_t
221+
VL53_WaitMs(VL53_Platform *p_platform, uint32_t TimeMs);
222+
223+
#endif // _PLATFORM_H_

0 commit comments

Comments
 (0)