Skip to content

Commit b2b4199

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

File tree

12 files changed

+930
-1
lines changed

12 files changed

+930
-1
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
// Tested with VL53L5CX-SATEL
17+
extern "C" {
18+
#include <vl53/vl53l5cx/examples/Example_1_ranging_basic.h>
19+
#include <vl53/vl53l5cx/examples/Example_2_get_set_params.h>
20+
#include <vl53/vl53l5cx/examples/Example_3_ranging_modes.h>
21+
#include <vl53/vl53l5cx/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 Int = GpioB5;
31+
using Rst = GpioD14;
32+
using PwrEn = GpioD15;
33+
using LPn = GpioF3;
34+
35+
modm::Vl53I2cTransport<I2c, LPn> transport{VL53L5CX_DEFAULT_I2C_ADDRESS >> 1};
36+
37+
int
38+
main()
39+
{
40+
Board::initialize();
41+
42+
Leds::setOutput();
43+
44+
PwrEn::setOutput(true);
45+
46+
LPn::setOutput(false);
47+
// Snc::setOutput(false);
48+
49+
transport.resetSensor();
50+
51+
I2c::connect<Scl::Scl, Sda::Sda>(I2c::PullUps::External);
52+
I2c::initialize<Board::SystemClock, 1_MHz, 10_pct>();
53+
54+
uint8_t device_id, revision_id;
55+
56+
example1(&transport);
57+
example2(&transport);
58+
example3(&transport);
59+
example5(&transport);
60+
}
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/vl53l5cx_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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
// Tested with MIKROE LIGHTRANGER 12 CLICK Breakout
17+
// with VL53L8CH variant, so histogram example 12 is supported
18+
extern "C" {
19+
#include <vl53/vl53lmz/examples/Example_12_cnh_data.h>
20+
#include <vl53/vl53lmz/examples/Example_1_ranging_basic.h>
21+
#include <vl53/vl53lmz/examples/Example_2_get_set_params.h>
22+
#include <vl53/vl53lmz/examples/Example_3_ranging_modes.h>
23+
#include <vl53/vl53lmz/examples/Example_5_multiple_targets_per_zone.h>
24+
}
25+
26+
using namespace Board;
27+
28+
using I2c = I2cMaster1;
29+
using Scl = GpioB8; // D15
30+
using Sda = GpioB9; // D14
31+
32+
using Snc = GpioA6;
33+
using Int = GpioB5;
34+
using Rst = GpioD14;
35+
using PwrEn = GpioD15;
36+
using LPn = GpioF3;
37+
38+
modm::Vl53I2cTransport<I2c, LPn> transport{VL53LMZ_DEFAULT_I2C_ADDRESS >> 1};
39+
40+
int
41+
main()
42+
{
43+
Board::initialize();
44+
45+
Leds::setOutput();
46+
47+
LPn::setOutput(false);
48+
Snc::setOutput(false);
49+
50+
transport.resetSensor();
51+
52+
I2c::connect<Scl::Scl, Sda::Sda>(I2c::PullUps::Internal);
53+
I2c::initialize<Board::SystemClock, 1_MHz, 10_pct>();
54+
55+
example1(&transport);
56+
example2(&transport);
57+
example3(&transport);
58+
example5(&transport);
59+
example12(&transport);
60+
}
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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
// Tested with MIKROE LIGHTRANGER 12 CLICK Breakout
15+
// with VL53L8CH variant, so histogram example 12 is supported
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+
#include <modm/ext/vl53/vl53.hpp>
25+
#include <modm/ext/vl53/vl53_transport.hpp>
26+
27+
using namespace Board;
28+
29+
using SpiMaster = SpiMaster2_Dma<Dma1::Channel0, Dma1::Channel1>;
30+
using Cs = GpioC0;
31+
using Mosi = GpioB15;
32+
using Miso = GpioC2;
33+
using Sck = GpioD3;
34+
35+
using Rst = GpioD6;
36+
using Snc = GpioB1;
37+
using LPn = GpioA3;
38+
using Int = GpioD7;
39+
40+
modm::Vl53SpiTransport<SpiMaster, Cs, LPn> transport;
41+
42+
int
43+
main()
44+
{
45+
Board::initialize();
46+
47+
Dma1::enable();
48+
Leds::setOutput();
49+
50+
LPn::setOutput(false);
51+
Snc::setOutput(false);
52+
Cs::setOutput(true);
53+
54+
transport.resetSensor();
55+
56+
SpiMaster::connect<Sck::Sck, Mosi::Mosi, Miso::Miso>();
57+
SpiMaster::initialize<Board::SystemClock, 2.2_MHz, 10_pct>();
58+
59+
example1(&transport);
60+
example2(&transport);
61+
example3(&transport);
62+
example5(&transport);
63+
example12(&transport);
64+
}
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+
}

0 commit comments

Comments
 (0)