Skip to content

Commit d5c4350

Browse files
committed
[driver] vl53l5, vl53l7, vl53l8 driver and examples
1 parent 5a98b45 commit d5c4350

File tree

12 files changed

+930
-1
lines changed

12 files changed

+930
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 <modm/board.hpp>
13+
#include <modm/ext/vl53/vl53.hpp>
14+
#include <modm/ext/vl53/vl53_transport.hpp>
15+
16+
extern "C" {
17+
#include <vl53/vl53l5cx/examples/Example_1_ranging_basic.h>
18+
#include <vl53/vl53l5cx/examples/Example_2_get_set_params.h>
19+
#include <vl53/vl53l5cx/examples/Example_3_ranging_modes.h>
20+
#include <vl53/vl53l5cx/examples/Example_5_multiple_targets_per_zone.h>
21+
}
22+
23+
using namespace Board;
24+
25+
using I2c = I2cMaster1;
26+
using Scl = GpioB8; // D15
27+
using Sda = GpioB9; // D14
28+
29+
using Rst = GpioD6;
30+
using Snc = GpioB1;
31+
using LPn = GpioA3;
32+
using Int = GpioD7;
33+
34+
modm::Vl53I2cTransport<I2c, LPn> transport{VL53L5CX_DEFAULT_I2C_ADDRESS};
35+
36+
int
37+
main()
38+
{
39+
Board::initialize();
40+
41+
Leds::setOutput();
42+
43+
LPn::setOutput(false);
44+
Snc::setOutput(false);
45+
46+
transport.resetSensor();
47+
48+
I2c::connect<Scl::Scl, Sda::Sda>(I2c::PullUps::Internal);
49+
I2c::initialize<Board::SystemClock, 100_kHz, 10_pct>();
50+
51+
example1(&transport);
52+
example2(&transport);
53+
example3(&transport);
54+
example5(&transport);
55+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<library>
2+
<extends>modm:nucleo-h723zg</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../../build/nucleo_h723zg/vl53l8_vl53l8_i2c</option>
5+
<option name="modm:vl53:vl53l5cx:examples">yes</option>
6+
<option name="modm:platform:cortex-m:main_stack_size">64Ki</option>
7+
</options>
8+
<modules>
9+
<module>modm:build:scons</module>
10+
<module>modm:platform:dma</module>
11+
<module>modm:platform:exti</module>
12+
<module>modm:platform:i2c:1</module>
13+
<module>modm:vl53:vl53l5cx</module>
14+
</modules>
15+
</library>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 <modm/board.hpp>
13+
#include <modm/ext/vl53/vl53.hpp>
14+
#include <modm/ext/vl53/vl53_transport.hpp>
15+
16+
extern "C" {
17+
#include <vl53/vl53lmz/examples/Example_12_cnh_data.h>
18+
#include <vl53/vl53lmz/examples/Example_1_ranging_basic.h>
19+
#include <vl53/vl53lmz/examples/Example_2_get_set_params.h>
20+
#include <vl53/vl53lmz/examples/Example_3_ranging_modes.h>
21+
#include <vl53/vl53lmz/examples/Example_5_multiple_targets_per_zone.h>
22+
}
23+
24+
using namespace Board;
25+
26+
using I2c = I2cMaster1;
27+
using Scl = GpioB8; // D15
28+
using Sda = GpioB9; // D14
29+
30+
using Rst = GpioD6;
31+
using Snc = GpioB1;
32+
using LPn = GpioA3;
33+
using Int = GpioD7;
34+
35+
modm::Vl53I2cTransport<I2c, LPn> transport{VL53LMZ_DEFAULT_I2C_ADDRESS};
36+
37+
int
38+
main()
39+
{
40+
Board::initialize();
41+
42+
Leds::setOutput();
43+
44+
LPn::setOutput(false);
45+
Snc::setOutput(false);
46+
47+
transport.resetSensor();
48+
49+
I2c::connect<Scl::Scl, Sda::Sda>(I2c::PullUps::Internal);
50+
I2c::initialize<Board::SystemClock, 100_kHz, 10_pct>();
51+
52+
example1(&transport);
53+
example2(&transport);
54+
example3(&transport);
55+
example5(&transport);
56+
example12(&transport);
57+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<library>
2+
<extends>modm:nucleo-h723zg</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../../build/nucleo_h723zg/vl53l8_vl53l8_i2c</option>
5+
<option name="modm:vl53:vl53lmz:examples">yes</option>
6+
<option name="modm:platform:cortex-m:main_stack_size">64Ki</option>
7+
</options>
8+
<modules>
9+
<module>modm:build:scons</module>
10+
<module>modm:platform:dma</module>
11+
<module>modm:platform:exti</module>
12+
<module>modm:platform:i2c:1</module>
13+
<module>modm:vl53:vl53lmz</module>
14+
</modules>
15+
</library>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 <modm/board.hpp>
13+
14+
extern "C" {
15+
#include <vl53/vl53lmz/examples/Example_12_cnh_data.h>
16+
#include <vl53/vl53lmz/examples/Example_1_ranging_basic.h>
17+
#include <vl53/vl53lmz/examples/Example_2_get_set_params.h>
18+
#include <vl53/vl53lmz/examples/Example_3_ranging_modes.h>
19+
#include <vl53/vl53lmz/examples/Example_5_multiple_targets_per_zone.h>
20+
}
21+
22+
#include <modm/ext/vl53/vl53.hpp>
23+
#include <modm/ext/vl53/vl53_transport.hpp>
24+
25+
using namespace Board;
26+
27+
using SpiMaster = SpiMaster2_Dma<Dma1::Channel0, Dma1::Channel1>;
28+
// using SpiMaster = SpiMaster2;
29+
using Cs = GpioC0;
30+
using Mosi = GpioB15;
31+
using Miso = GpioC2;
32+
using Sck = GpioD3;
33+
34+
using Rst = GpioD6;
35+
using Snc = GpioB1;
36+
using LPn = GpioA3;
37+
using Int = GpioD7;
38+
39+
modm::Vl53SpiTransport<SpiMaster, Cs, LPn> transport;
40+
41+
int
42+
main()
43+
{
44+
Board::initialize();
45+
46+
Dma1::enable();
47+
Leds::setOutput();
48+
49+
LPn::setOutput(false);
50+
Snc::setOutput(false);
51+
Cs::setOutput(true);
52+
53+
transport.resetSensor();
54+
55+
SpiMaster::connect<Sck::Sck, Mosi::Mosi, Miso::Miso>();
56+
SpiMaster::initialize<Board::SystemClock, 2.2_MHz, 10_pct>();
57+
58+
example1(&transport);
59+
example2(&transport);
60+
example3(&transport);
61+
example5(&transport);
62+
example12(&transport);
63+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<library>
2+
<extends>modm:nucleo-h723zg</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../../build/nucleo_h723zg/vl53l8_spi</option>
5+
<option name="modm:vl53:vl53lmz:examples">yes</option>
6+
<option name="modm:platform:cortex-m:main_stack_size">64Ki</option>
7+
</options>
8+
<modules>
9+
<module>modm:build:scons</module>
10+
<module>modm:platform:dma</module>
11+
<module>modm:platform:exti</module>
12+
<module>modm:platform:spi:2</module>
13+
<module>modm:vl53:vl53lmz</module>
14+
</modules>
15+
</library>

ext/vl53/vl53.hpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 <modm/platform.hpp>
13+
14+
#include "vl53_transport.hpp"
15+
16+
extern "C" {
17+
#include "vl53_platform.h"
18+
19+
uint8_t
20+
VL53_RdByte(VL53_Platform *p_platform, uint16_t RegisterAddress, uint8_t *p_value)
21+
{
22+
auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport);
23+
return iface->readByte(RegisterAddress, p_value);
24+
}
25+
26+
uint8_t
27+
VL53_WrByte(VL53_Platform *p_platform, uint16_t RegisterAddress, uint8_t value)
28+
{
29+
auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport);
30+
return iface->writeByte(RegisterAddress, value);
31+
}
32+
33+
uint8_t
34+
VL53_WrMulti(VL53_Platform *p_platform, uint16_t RegisterAddress, uint8_t *p_values, uint32_t size)
35+
{
36+
auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport);
37+
return iface->writeMulti(RegisterAddress, p_values, size);
38+
}
39+
40+
uint8_t
41+
VL53_RdMulti(VL53_Platform *p_platform, uint16_t RegisterAddress, uint8_t *p_values, uint32_t size)
42+
{
43+
auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport);
44+
return iface->readMulti(RegisterAddress, p_values, size);
45+
}
46+
47+
void
48+
VL53_SwapBuffer(uint8_t *buffer, uint16_t size)
49+
{
50+
uint32_t i, tmp;
51+
52+
for (i = 0; i < size; i = i + 4)
53+
{
54+
tmp = (buffer[i] << 24) | (buffer[i + 1] << 16) | (buffer[i + 2] << 8) | (buffer[i + 3]);
55+
56+
memcpy(&(buffer[i]), &tmp, 4);
57+
}
58+
}
59+
60+
uint8_t
61+
VL53_WaitMs(VL53_Platform *p_platform, uint32_t TimeMs)
62+
{
63+
modm::delay_ms(TimeMs);
64+
return 0;
65+
}
66+
67+
uint8_t
68+
VL53_Reset_Sensor(VL53_Platform *p_platform)
69+
{
70+
auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport);
71+
return iface->resetSensor();
72+
}
73+
}

ext/vl53/vl53.lb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
module.add_option(
20+
BooleanOption(
21+
name="examples",
22+
description="",
23+
default=False
24+
)
25+
)
26+
return True
27+
28+
def build(self, env):
29+
env.outbasepath = "modm/ext"
30+
env.copy("vl53/vl53l5cx/src")
31+
env.copy("vl53/vl53l5cx/inc")
32+
env.copy("vl53/vl53l5cx/LICENSE.txt")
33+
if env[":vl53:vl53l5cx:examples"]:
34+
env.copy("vl53/vl53l5cx/examples")
35+
env.collect(":build:path.include", "modm/ext/vl53/")
36+
env.collect(":build:path.include", "modm/ext/vl53/vl53l5cx/inc")
37+
38+
class Vl53lmz(Module):
39+
def init(self, module):
40+
module.name = "vl53lmz"
41+
module.description = "Driver for ST VL53L7 and VL53L8 Multi-Zone Time-of-Flight Sensors"
42+
43+
def prepare(self, module, options):
44+
module.add_option(
45+
BooleanOption(
46+
name="examples",
47+
description="",
48+
default=False
49+
)
50+
)
51+
return True
52+
53+
def build(self, env):
54+
env.outbasepath = "modm/ext"
55+
env.copy("vl53/vl53lmz/src")
56+
env.copy("vl53/vl53lmz/inc")
57+
env.copy("vl53/vl53lmz/LICENSE.txt")
58+
if env[":vl53:vl53lmz:examples"]:
59+
env.copy("vl53/vl53lmz/examples")
60+
env.collect(":build:path.include", "modm/ext/vl53/")
61+
env.collect(":build:path.include", "modm/ext/vl53/vl53lmz/inc")
62+
63+
def init(module):
64+
module.name = ":vl53"
65+
module.description = """\
66+
# ST's VL53 Time-of-Flight ULD Drivers
67+
68+
Currently supported sensors:
69+
- With VL53LMZ driver: VL53L7CX, VL53L7CH, VL53L8CX, VL53L8CH
70+
- VL53L5CX driver
71+
72+
"""
73+
74+
def prepare(module, options):
75+
module.add_submodule(Vl53l5cx())
76+
module.add_submodule(Vl53lmz())
77+
module.depends(":architecture:spi.device")
78+
module.depends(":architecture:i2c.device")
79+
return True
80+
81+
def build(env):
82+
env.outbasepath = "modm/ext/vl53"
83+
env.copy("vl53.hpp")
84+
env.copy("vl53_transport.hpp")
85+
env.copy("vl53_transport_impl.hpp")
86+
env.copy("vl53_platform.h")

0 commit comments

Comments
 (0)