Skip to content

feat(vl53l1x): Implement Arduino driver. #9#191

Merged
Charly-sketch merged 7 commits into
mainfrom
feat/vl53l1x-driver
Jun 22, 2026
Merged

feat(vl53l1x): Implement Arduino driver. #9#191
Charly-sketch merged 7 commits into
mainfrom
feat/vl53l1x-driver

Conversation

@DumontALINE

@DumontALINE DumontALINE commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a full driver for the ST VL53L1X Time-of-Flight distance sensor, including native mock tests, hardware validation tests, and complete documentation.

Close #9
Close #41
close #29

Changes

  • Add VL53L1X.h, VL53L1X.cpp, and VL53L1X_const.h implementing the full driver API
  • Add sensor initialization and device ID validation (0xEACC)
  • Add distance measurement support (distanceMm, read)
  • Add ranging control (startRanging, stopRanging)
  • Add data-ready polling and interrupt clearing support
  • Add software reset and power management (reset, powerOn, powerOff)
  • Add low-level 8-bit/16-bit register helpers and bulk configuration writes
  • Add ST default configuration upload during begin()
  • Add complete README.md with setup, API, examples, and testing documentation
  • Add hardware test suite validating device detection and plausible distance measurements on real hardware
  • Add native mock test suite covering device detection, reset logic, power management, ranging control, interrupt polarity handling, distance decoding, and interrupt clearing

Checklist

  • make lint passes (clang-format)
  • make build passes (PlatformIO)
  • make test-native passes (if native tests exist)
  • make test-hardware passes on a connected STeaMi (if hardware tests exist)
  • README updated (if adding/changing public API)
  • Examples added/updated (if applicable)
  • Commit messages follow conventional commits format

Copilot AI review requested due to automatic review settings June 2, 2026 09:35
@github-actions github-actions Bot added this to the Phase 3 — Drivers simples milestone Jun 2, 2026
@github-actions github-actions Bot added the enhancement New feature or request label Jun 2, 2026
@DumontALINE DumontALINE requested a review from nedseb June 2, 2026 09:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Arduino/C++ driver for the ST VL53L1X Time-of-Flight sensor to the STeaMi driver collection, along with native (mocked I2C) and on-device hardware validation tests plus updated documentation.

Changes:

  • Introduces a new VL53L1X driver (register constants, I2C helpers, begin/reset/ranging/data-ready/distance read API).
  • Adds native mock tests and hardware integration tests for device detection and plausible distance reads.
  • Replaces the placeholder vl53l1x README with usage/API/testing documentation.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/native/test_vl53l1x/test_main.cpp Adds native MockWire unit tests for the new VL53L1X driver API.
tests/native/helpers/Wire.h Extends the MockWire helper to support VL53L1X-style 16-bit register addressing.
tests/hardware/test_vl53l1x/test_main.cpp Adds on-hardware Unity tests for begin/device ID/plausible distance reads.
lib/vl53l1x/src/VL53L1X.h Declares the public VL53L1X driver API.
lib/vl53l1x/src/VL53L1X.cpp Implements the VL53L1X driver, including default-config upload and distance reads.
lib/vl53l1x/src/VL53L1X_const.h Defines VL53L1X register addresses, bit masks, and offsets used by the driver/tests.
lib/vl53l1x/README.md Documents setup, API surface, behavior, and testing for the driver.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +46 to +51
void test_device_id_returns_who_am_i() {
preloadWhoAmI(true);
VL53L1X testSensor; // ← Créé ici
testSensor.begin();
check_who_am_i(sensor, VL53L1X_DEVICE_ID);
}
Comment on lines +58 to +61
void test_reset_writes_assert_then_release(void) {
preloadDataReady(false);
TEST_ASSERT_FALSE(sensor.dataReady());
}
Comment thread tests/native/helpers/Wire.h Outdated
Comment on lines 37 to 60
bool is16bit =
(txBuffer_.size() >= 2) && (txBuffer_[0] <= 0x03) && (currentAddress_ == 0x29);

if (is16bit && txBuffer_.size() == 2) {
uint16_t regAddr = (static_cast<uint16_t>(txBuffer_[0]) << 8) | txBuffer_[1];
currentRegisterByAddr_[currentAddress_] = regAddr;
} else if (is16bit) {
uint16_t regAddr = (static_cast<uint16_t>(txBuffer_[0]) << 8) | txBuffer_[1];
for (size_t i = 2; i < txBuffer_.size(); ++i) {
uint8_t targetReg = static_cast<uint8_t>(regAddr + (i - 2));
uint8_t val = txBuffer_[i];
registers_[makeKey(currentAddress_, targetReg)] = val;
writes_.push_back({currentAddress_, targetReg, val});
}
currentRegisterByAddr_[currentAddress_] = regAddr;
} else {
for (size_t i = 1; i < txBuffer_.size(); ++i) {
uint8_t targetReg = static_cast<uint8_t>(reg + (i - 1));
uint8_t val = txBuffer_[i];
registers_[makeKey(currentAddress_, targetReg)] = val;
writes_.push_back({currentAddress_, targetReg, val});
}
currentRegisterByAddr_[currentAddress_] = reg;
}
Comment on lines +113 to 119
void setRegister(uint8_t address, uint16_t reg, uint8_t value) {
registers_[makeKey(address, reg)] = value;
}

uint8_t getRegister(uint8_t address, uint8_t reg) const {
uint8_t getRegister(uint8_t address, uint16_t reg) const {
auto it = registers_.find(makeKey(address, reg));
return (it != registers_.end()) ? it->second : 0x00;
}
Comment on lines +160 to +168
void VL53L1X::writeRegBytes(uint16_t reg, const uint8_t* data, size_t len) {
_wire->beginTransmission(_address);
_wire->write((reg >> 8) & 0xFF);
_wire->write(reg & 0xFF);
for (size_t i = 0; i < len; i++) {
_wire->write(data[i]);
}
_wire->endTransmission();
}
Comment on lines +221 to +236
uint16_t VL53L1X::distanceMm() {
ensureData();
uint8_t data[RESULT_BLOCK_SIZE] = {};
_wire->beginTransmission(_address);
_wire->write((REG_RESULT_RANGE_STATUS >> 8) & 0xFF);
_wire->write(REG_RESULT_RANGE_STATUS & 0xFF);
_wire->endTransmission(false);
_wire->requestFrom(_address, static_cast<uint8_t>(RESULT_BLOCK_SIZE));
for (uint8_t i = 0; i < RESULT_BLOCK_SIZE && _wire->available(); i++) {
data[i] = static_cast<uint8_t>(_wire->read());
}
uint16_t distance = static_cast<uint16_t>(data[RESULT_DISTANCE_MSB_OFFSET] << 8) +
data[RESULT_DISTANCE_LSB_OFFSET];
clearInterrupt();
return distance;
}
Comment thread lib/vl53l1x/README.md
Comment on lines +48 to +59
See [examples/read_distance/](examples/read_distance/) for the complete
example sketch.

## Examples

| Example | What it does |
|---------|--------------|
| [`read_distance`](examples/read_distance/) | Continuously reads and prints the measured distance in millimeters. |
| [`distance_alarm`](examples/distance_alarm/) | Triggers an alert when an object comes closer than a configurable threshold. |
| [`power_cycle`](examples/power_cycle/) | Demonstrates sensor power control using `powerOff()` and `powerOn()`. |
| [`continuous_ranging`](examples/continuous_ranging/) | Runs continuous ranging and prints measurements as soon as data becomes available. |

Comment on lines +63 to +67
void test_power_off_writes_assert(void) {
sensor.powerOff();
preloadDataReady(false);
TEST_ASSERT_FALSE(sensor.dataReady());
}
@Charly-sketch

Copy link
Copy Markdown
Contributor

Thanks for the update and for addressing the Copilot comments.

I checked the fixes and the major issues reported by Copilot seem resolved.

I only have a few remaining points before merge:

  • Can you confirm that the native tests cover the timeout path (ensureData() never becoming ready and distanceMm() returning an error value)?
  • The hardware issue mentions a full power cycle test. Is powerOff()powerOn() → measurement explicitly covered by the hardware test suite?
  • Please verify that every example referenced in the README actually exists in the repository.

Also, when replying to review comments, please indicate which Copilot comment each change addresses so the review history is easier to follow.

Apart from these points, the implementation looks good.

@Charly-sketch Charly-sketch merged commit d78c4a3 into main Jun 22, 2026
12 checks passed
@Charly-sketch Charly-sketch deleted the feat/vl53l1x-driver branch June 22, 2026 09:04
semantic-release-updater Bot pushed a commit that referenced this pull request Jun 22, 2026
# [0.21.0](v0.20.0...v0.21.0) (2026-06-22)

### Features

* **vl53l1x:** Implement Arduino driver.  [#9](#9) ([#191](#191)) ([d78c4a3](d78c4a3))
@semantic-release-updater

Copy link
Copy Markdown

🎉 This PR is included in version 0.21.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(vl53l1x): Add hardware integration tests. test(vl53l1x): Add mock unit tests. feat(vl53l1x): Implement Arduino driver.

4 participants