-
Notifications
You must be signed in to change notification settings - Fork 156
[driver] driver for ST vl53l5, vl53l7, vl53l8 #1296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hshose
wants to merge
6
commits into
modm-io:develop
Choose a base branch
from
hshose:feature/vl53
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3fc62e6
[driver] vl53l5, vl53l7, vl53l8 driver and examples
hshose 4e716a4
[driver] Added vl53 ext submodule
hshose a28ccd0
[driver] vl53 remove examples from lbuild
hshose ead0741
[driver] vl53 multiwrite with i2c eeprom
hshose 752496d
[driver] vl53 spi driver without tx buffer, fails with DMA
hshose 055c6f2
[driver] vl53 fixup
hshose File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Copyright (c) 2025, Henrik Hose | ||
| * | ||
| * This file is part of the modm project. | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| #include <modm/board.hpp> | ||
|
|
||
| // Tested with VL53L5CX-SATEL | ||
| extern "C" { | ||
| #include "../../../../ext/vl53/vl53/vl53l5cx/examples/Example_1_ranging_basic.h" | ||
| #include "../../../../ext/vl53/vl53/vl53l5cx/examples/Example_2_get_set_params.h" | ||
| #include "../../../../ext/vl53/vl53/vl53l5cx/examples/Example_3_ranging_modes.h" | ||
| #include "../../../../ext/vl53/vl53/vl53l5cx/examples/Example_5_multiple_targets_per_zone.h" | ||
| } | ||
|
|
||
| #include <modm/driver/vl53/vl53.hpp> | ||
| #include <modm/driver/vl53/vl53_transport.hpp> | ||
|
|
||
| using namespace Board; | ||
|
|
||
| using I2c = I2cMaster1; | ||
| using Scl = GpioB8; // D15 | ||
| using Sda = GpioB9; // D14 | ||
|
|
||
| using Int = GpioB5; | ||
| using Rst = GpioD14; | ||
| using PwrEn = GpioD15; | ||
| using LPn = GpioF3; | ||
|
|
||
| modm::Vl53I2cTransport<I2c, LPn> transport{VL53L5CX_DEFAULT_I2C_ADDRESS >> 1}; | ||
|
|
||
| int | ||
| main() | ||
| { | ||
| Board::initialize(); | ||
|
|
||
| Leds::setOutput(); | ||
|
|
||
| PwrEn::setOutput(true); | ||
|
|
||
| LPn::setOutput(false); | ||
| // Snc::setOutput(false); | ||
|
|
||
| transport.resetSensor(); | ||
|
|
||
| I2c::connect<Scl::Scl, Sda::Sda>(I2c::PullUps::External); | ||
| I2c::initialize<Board::SystemClock, 1_MHz, 10_pct>(); | ||
|
|
||
| uint8_t device_id, revision_id; | ||
|
|
||
| example1(&transport); | ||
| example2(&transport); | ||
| example3(&transport); | ||
| example5(&transport); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <library> | ||
| <extends>modm:nucleo-h723zg</extends> | ||
| <options> | ||
| <option name="modm:build:build.path">../../../../build/nucleo_h723zg/vl53l5cx_i2c</option> | ||
| <option name="modm:platform:cortex-m:main_stack_size">64Ki</option> | ||
| </options> | ||
| <modules> | ||
| <module>modm:build:scons</module> | ||
| <module>modm:platform:dma</module> | ||
| <module>modm:platform:exti</module> | ||
| <module>modm:platform:i2c:1</module> | ||
| <module>modm:vl53:vl53l5cx</module> | ||
| </modules> | ||
| </library> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Copyright (c) 2025, Henrik Hose | ||
| * | ||
| * This file is part of the modm project. | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| #include <modm/board.hpp> | ||
|
|
||
| // Tested with MIKROE LIGHTRANGER 12 CLICK Breakout | ||
| // with VL53L8CH variant, so histogram example 12 is supported | ||
| extern "C" { | ||
| #include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_12_cnh_data.h" | ||
| #include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_1_ranging_basic.h" | ||
| #include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_2_get_set_params.h" | ||
| #include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_3_ranging_modes.h" | ||
| #include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_5_multiple_targets_per_zone.h" | ||
| } | ||
|
|
||
| #include <modm/driver/vl53/vl53.hpp> | ||
| #include <modm/driver/vl53/vl53_transport.hpp> | ||
|
|
||
| using namespace Board; | ||
|
|
||
| using I2c = I2cMaster1; | ||
| using Scl = GpioB8; // D15 | ||
| using Sda = GpioB9; // D14 | ||
|
|
||
| using Rst = GpioD6; | ||
| using Snc = GpioB1; | ||
| using LPn = GpioA3; | ||
| using Int = GpioD7; | ||
|
|
||
| modm::Vl53I2cTransport<I2c, LPn> transport{VL53LMZ_DEFAULT_I2C_ADDRESS >> 1}; | ||
|
|
||
| int | ||
| main() | ||
| { | ||
| Board::initialize(); | ||
|
|
||
| Leds::setOutput(); | ||
|
|
||
| LPn::setOutput(false); | ||
| Snc::setOutput(false); | ||
|
|
||
| transport.resetSensor(); | ||
|
|
||
| I2c::connect<Scl::Scl, Sda::Sda>(I2c::PullUps::Internal); | ||
| I2c::initialize<Board::SystemClock, 1_MHz, 10_pct>(); | ||
|
|
||
| example1(&transport); | ||
| example2(&transport); | ||
| example3(&transport); | ||
| example5(&transport); | ||
| example12(&transport); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <library> | ||
| <extends>modm:nucleo-h723zg</extends> | ||
| <options> | ||
| <option name="modm:build:build.path">../../../../build/nucleo_h723zg/vl53l8_vl53l8_i2c</option> | ||
| <option name="modm:platform:cortex-m:main_stack_size">16Ki</option> | ||
| </options> | ||
| <modules> | ||
| <module>modm:build:scons</module> | ||
| <module>modm:platform:dma</module> | ||
| <module>modm:platform:exti</module> | ||
| <module>modm:platform:i2c:1</module> | ||
| <module>modm:vl53:vl53lmz</module> | ||
| </modules> | ||
| </library> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Copyright (c) 2025, Henrik Hose | ||
| * | ||
| * This file is part of the modm project. | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| #include <modm/board.hpp> | ||
|
|
||
| // Tested with MIKROE LIGHTRANGER 12 CLICK Breakout | ||
| // with VL53L8CH variant, so histogram example 12 is supported | ||
| extern "C" { | ||
| #include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_12_cnh_data.h" | ||
| #include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_1_ranging_basic.h" | ||
| #include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_2_get_set_params.h" | ||
| #include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_3_ranging_modes.h" | ||
| #include "../../../../ext/vl53/vl53/vl53lmz/examples/Example_5_multiple_targets_per_zone.h" | ||
| } | ||
|
|
||
| #include <modm/driver/vl53/vl53.hpp> | ||
| #include <modm/driver/vl53/vl53_transport.hpp> | ||
|
|
||
| using namespace Board; | ||
|
|
||
| using SpiMaster = SpiMaster2_Dma<Dma1::Channel0, Dma1::Channel1>; | ||
| using Cs = GpioC0; | ||
| using Mosi = GpioB15; | ||
| using Miso = GpioC2; | ||
| using Sck = GpioD3; | ||
|
|
||
| using Rst = GpioD6; | ||
| using Snc = GpioB1; | ||
| using LPn = GpioA3; | ||
| using Int = GpioD7; | ||
|
|
||
| modm::Vl53SpiTransport<SpiMaster, Cs, LPn> transport; | ||
|
|
||
| int | ||
| main() | ||
| { | ||
| Board::initialize(); | ||
|
|
||
| Dma1::enable(); | ||
| Leds::setOutput(); | ||
|
|
||
| LPn::setOutput(false); | ||
| Snc::setOutput(false); | ||
| Cs::setOutput(true); | ||
|
|
||
| transport.resetSensor(); | ||
|
|
||
| SpiMaster::connect<Sck::Sck, Mosi::Mosi, Miso::Miso>(); | ||
| SpiMaster::initialize<Board::SystemClock, 2.2_MHz, 10_pct>(); | ||
|
|
||
| example1(&transport); | ||
| example2(&transport); | ||
| example3(&transport); | ||
| example5(&transport); | ||
| example12(&transport); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <library> | ||
| <extends>modm:nucleo-h723zg</extends> | ||
| <options> | ||
| <option name="modm:build:build.path">../../../../build/nucleo_h723zg/vl53l8_spi</option> | ||
| <option name="modm:platform:cortex-m:main_stack_size">16Ki</option> | ||
| </options> | ||
| <modules> | ||
| <module>modm:build:scons</module> | ||
| <module>modm:platform:dma</module> | ||
| <module>modm:platform:exti</module> | ||
| <module>modm:platform:spi:2</module> | ||
| <module>modm:vl53:vl53lmz</module> | ||
| </modules> | ||
| </library> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Copyright (c) 2025, Henrik Hose | ||
| * | ||
| * This file is part of the modm project. | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| #include <modm/platform.hpp> | ||
|
|
||
| #include "vl53_transport.hpp" | ||
|
|
||
| extern "C" { | ||
| #include "vl53_platform.h" | ||
|
|
||
| uint8_t | ||
| VL53_RdByte(VL53_Platform *p_platform, uint16_t RegisterAddress, uint8_t *p_value) | ||
| { | ||
| auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport); | ||
| return iface->readByte(RegisterAddress, p_value); | ||
| } | ||
|
|
||
| uint8_t | ||
| VL53_WrByte(VL53_Platform *p_platform, uint16_t RegisterAddress, uint8_t value) | ||
| { | ||
| auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport); | ||
| return iface->writeByte(RegisterAddress, value); | ||
| } | ||
|
|
||
| uint8_t | ||
| VL53_WrMulti(VL53_Platform *p_platform, uint16_t RegisterAddress, uint8_t *p_values, uint32_t size) | ||
| { | ||
| auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport); | ||
| return iface->writeMulti(RegisterAddress, p_values, size); | ||
| } | ||
|
|
||
| uint8_t | ||
| VL53_RdMulti(VL53_Platform *p_platform, uint16_t RegisterAddress, uint8_t *p_values, uint32_t size) | ||
| { | ||
| auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport); | ||
| return iface->readMulti(RegisterAddress, p_values, size); | ||
| } | ||
|
|
||
| void | ||
| VL53_SwapBuffer(uint8_t *buffer, uint16_t size) | ||
| { | ||
| uint32_t i, tmp; | ||
|
|
||
| for (i = 0; i < size; i = i + 4) | ||
| { | ||
| tmp = (buffer[i] << 24) | (buffer[i + 1] << 16) | (buffer[i + 2] << 8) | (buffer[i + 3]); | ||
|
|
||
| memcpy(&(buffer[i]), &tmp, 4); | ||
| } | ||
| } | ||
|
|
||
| uint8_t | ||
| VL53_WaitMs(VL53_Platform *p_platform, uint32_t TimeMs) | ||
| { | ||
| modm::this_fiber::sleep_for(std::chrono::milliseconds(TimeMs)); | ||
| return 0; | ||
| } | ||
|
|
||
| uint8_t | ||
| VL53_Reset_Sensor(VL53_Platform *p_platform) | ||
| { | ||
| auto *iface = static_cast<modm::Vl53TransportBase *>(p_platform->transport); | ||
| return iface->resetSensor(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #!/usr/bin/env python3 | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (c) 2025, Henrik Hose | ||
| # | ||
| # This file is part of the modm project. | ||
| # | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
| class Vl53l5cx(Module): | ||
| def init(self, module): | ||
| module.name = "vl53l5cx" | ||
| module.description = "Driver for ST VL53L5CX Multi-Zone Time-of-Flight Sensor" | ||
|
|
||
| def prepare(self, module, options): | ||
| return True | ||
|
|
||
| def build(self, env): | ||
| env.outbasepath = "modm/ext" | ||
| env.copy("vl53/vl53l5cx/src") | ||
| env.copy("vl53/vl53l5cx/inc") | ||
| env.copy("vl53/vl53l5cx/LICENSE.txt") | ||
| env.collect(":build:path.include", "modm/src/modm/driver/vl53") | ||
| env.collect(":build:path.include", "modm/ext/vl53/vl53l5cx/inc") | ||
|
|
||
| class Vl53lmz(Module): | ||
| def init(self, module): | ||
| module.name = "vl53lmz" | ||
| module.description = "Driver for ST VL53L7 and VL53L8 Multi-Zone Time-of-Flight Sensors" | ||
|
|
||
| def prepare(self, module, options): | ||
| return True | ||
|
|
||
| def build(self, env): | ||
| env.outbasepath = "modm/ext" | ||
| env.copy("vl53/vl53lmz/src") | ||
| env.copy("vl53/vl53lmz/inc") | ||
| env.copy("vl53/vl53lmz/LICENSE.txt") | ||
| env.collect(":build:path.include", "modm/src/modm/driver/vl53") | ||
| env.collect(":build:path.include", "modm/ext/vl53/vl53lmz/inc") | ||
|
|
||
| def init(module): | ||
| module.name = ":vl53" | ||
| module.description = """\ | ||
| # ST's VL53 Time-of-Flight ULD Drivers | ||
|
|
||
| Currently supported sensors: | ||
| - With VL53LMZ driver: VL53L7CX, VL53L7CH, VL53L8CX, VL53L8CH | ||
| - VL53L5CX driver | ||
|
|
||
| """ | ||
|
|
||
| def prepare(module, options): | ||
| module.add_submodule(Vl53l5cx()) | ||
| module.add_submodule(Vl53lmz()) | ||
| module.depends(":architecture:spi.device") | ||
| module.depends(":architecture:i2c.device") | ||
| module.depends(":driver:i2c.eeprom") | ||
| return True | ||
|
|
||
| def build(env): | ||
| env.outbasepath = "modm/src/modm/driver/vl53" | ||
| env.copy("vl53.hpp") | ||
| env.copy("vl53_transport.hpp") | ||
| env.copy("vl53_transport_impl.hpp") | ||
| env.copy("vl53_platform.h") |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.