Skip to content

Commit 7810f2f

Browse files
committed
[examples] Add VL53x examples for I2C and SPI
1 parent 98e11c8 commit 7810f2f

File tree

6 files changed

+217
-0
lines changed

6 files changed

+217
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 VL53L5CX-SATEL
15+
extern "C" {
16+
#include "../../../../ext/vl53/vl53/vl53l5cx/examples/Example_1_ranging_basic.h"
17+
#include "../../../../ext/vl53/vl53/vl53l5cx/examples/Example_2_get_set_params.h"
18+
#include "../../../../ext/vl53/vl53/vl53l5cx/examples/Example_3_ranging_modes.h"
19+
#include "../../../../ext/vl53/vl53/vl53l5cx/examples/Example_5_multiple_targets_per_zone.h"
20+
}
21+
22+
#include <modm/driver/vl53/vl53_transport.hpp>
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>();
53+
54+
example1(&transport);
55+
example2(&transport);
56+
example3(&transport);
57+
example5(&transport);
58+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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:platform:cortex-m:main_stack_size">8Ki</option>
6+
</options>
7+
<modules>
8+
<module>modm:build:scons</module>
9+
<module>modm:platform:i2c:1</module>
10+
<module>modm:vl53:vl53l5cx</module>
11+
</modules>
12+
</library>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 "../../../../ext/vl53/vl53/vl53lmz/examples/Example_12_cnh_data.h"
18+
#include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_1_ranging_basic.h"
19+
#include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_2_get_set_params.h"
20+
#include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_3_ranging_modes.h"
21+
#include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_5_multiple_targets_per_zone.h"
22+
}
23+
24+
#include <modm/driver/vl53/vl53_transport.hpp>
25+
26+
using namespace Board;
27+
28+
using I2c = I2cMaster1;
29+
using Scl = GpioB8; // D15
30+
using Sda = GpioB9; // D14
31+
32+
using Rst = GpioD6;
33+
using Snc = GpioB1;
34+
using LPn = GpioA3;
35+
using Int = GpioD7;
36+
37+
modm::Vl53I2cTransport<I2c, LPn> transport{VL53LMZ_DEFAULT_I2C_ADDRESS >> 1};
38+
39+
int
40+
main()
41+
{
42+
Board::initialize();
43+
44+
Leds::setOutput();
45+
46+
LPn::setOutput(false);
47+
Snc::setOutput(false);
48+
49+
transport.resetSensor();
50+
51+
I2c::connect<Scl::Scl, Sda::Sda>(I2c::PullUps::Internal);
52+
I2c::initialize<Board::SystemClock, 1_MHz>();
53+
54+
example1(&transport);
55+
example2(&transport);
56+
example3(&transport);
57+
example5(&transport);
58+
example12(&transport);
59+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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:platform:cortex-m:main_stack_size">12Ki</option>
6+
</options>
7+
<modules>
8+
<module>modm:build:scons</module>
9+
<module>modm:platform:i2c:1</module>
10+
<module>modm:vl53:vl53lmz</module>
11+
</modules>
12+
</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+
// Tested with MIKROE LIGHTRANGER 12 CLICK Breakout
15+
// with VL53L8CH variant, so histogram example 12 is supported
16+
extern "C" {
17+
#include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_12_cnh_data.h"
18+
#include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_1_ranging_basic.h"
19+
#include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_2_get_set_params.h"
20+
#include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_3_ranging_modes.h"
21+
#include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_5_multiple_targets_per_zone.h"
22+
}
23+
24+
#include <modm/driver/vl53/vl53_transport.hpp>
25+
26+
using namespace Board;
27+
28+
using SpiMaster = SpiMaster2_Dma<Dma1::Channel0, Dma1::Channel1>;
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>();
57+
58+
example1(&transport);
59+
example2(&transport);
60+
example3(&transport);
61+
example5(&transport);
62+
example12(&transport);
63+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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:platform:cortex-m:main_stack_size">12Ki</option>
6+
</options>
7+
<modules>
8+
<module>modm:build:scons</module>
9+
<module>modm:platform:dma</module>
10+
<module>modm:platform:spi:2</module>
11+
<module>modm:vl53:vl53lmz</module>
12+
</modules>
13+
</library>

0 commit comments

Comments
 (0)