Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@
[submodule "ext/segger/rtt"]
path = ext/segger/rtt
url = https://github.com/modm-ext/segger-rtt.git
[submodule "ext/vl53/vl53"]
path = ext/vl53/vl53
url = https://github.com/modm-ext/vl53-partial.git
61 changes: 61 additions & 0 deletions examples/nucleo_h723zg/vl53/vl53l5cx_i2c/main.cpp
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);
}
14 changes: 14 additions & 0 deletions examples/nucleo_h723zg/vl53/vl53l5cx_i2c/project.xml
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>
60 changes: 60 additions & 0 deletions examples/nucleo_h723zg/vl53/vl53l7_vl53l8_i2c/main.cpp
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);
}
14 changes: 14 additions & 0 deletions examples/nucleo_h723zg/vl53/vl53l7_vl53l8_i2c/project.xml
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>
64 changes: 64 additions & 0 deletions examples/nucleo_h723zg/vl53/vl53l8_spi/main.cpp
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);
}
14 changes: 14 additions & 0 deletions examples/nucleo_h723zg/vl53/vl53l8_spi/project.xml
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>
1 change: 1 addition & 0 deletions ext/vl53/vl53
Submodule vl53 added at e41b85
73 changes: 73 additions & 0 deletions ext/vl53/vl53.hpp
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();
}
}
69 changes: 69 additions & 0 deletions ext/vl53/vl53.lb
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")
Loading
Loading