DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
vl53l0x.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file vl53l0x.h
6 * @brief ST VL53L0X / VL53L1X optical time-of-flight ranging codec (DETWS_ENABLE_VL53L0X).
7 *
8 * The VL53L0X emits an infrared pulse and times the round-trip to a target, reporting distance in
9 * millimeters - contactless ranging and gesture, bridged to the same telemetry sink as the other field
10 * sensors. Its documented register interface is small: check IDENTIFICATION_MODEL_ID (0xC0 == 0xEE),
11 * start ranging via SYSRANGE_START, poll RESULT_INTERRUPT_STATUS for data-ready, read the 16-bit range
12 * from RESULT_RANGE_STATUS + 10, then clear the interrupt.
13 *
14 * This codec is pure and host-tested: ::vl53l0x_range_mm combines the range register pair,
15 * ::vl53l0x_data_ready decodes the interrupt-status byte, and ::vl53l0x_range_valid checks the device
16 * range-status field. On an ESP32 the binding runs the ranging loop over I2C (Wire); only that touches
17 * hardware. Note: ST's optional tuning blob (for best accuracy) is not applied - default-settings
18 * ranging via the documented registers.
19 */
20
21#ifndef DETERMINISTICESPASYNCWEBSERVER_VL53L0X_H
22#define DETERMINISTICESPASYNCWEBSERVER_VL53L0X_H
23
24#include <stdint.h>
25
26#define VL53L0X_REG_SYSRANGE_START 0x00
27#define VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR 0x0B
28#define VL53L0X_REG_RESULT_INTERRUPT_STATUS 0x13
29#define VL53L0X_REG_RESULT_RANGE_STATUS 0x14
30#define VL53L0X_REG_IDENTIFICATION_MODEL_ID 0xC0
31
32#define VL53L0X_MODEL_ID 0xEE ///< IDENTIFICATION_MODEL_ID for the VL53L0X.
33#define VL53L0X_RANGE_VALID 11 ///< DeviceRangeStatus value that means a valid measurement.
34
35/** @brief Combine the range high/low bytes (RESULT_RANGE_STATUS+10 / +11) into millimeters. */
36uint16_t vl53l0x_range_mm(uint8_t hi, uint8_t lo);
37
38/** @brief True if a new measurement is ready (any of the low 3 interrupt-status bits set). */
39bool vl53l0x_data_ready(uint8_t interrupt_status);
40
41/** @brief The DeviceRangeStatus field (bits 6:3) of the RESULT_RANGE_STATUS register. */
42uint8_t vl53l0x_range_status(uint8_t range_status_reg);
43
44/** @brief True if the range-status field reports a valid measurement (== VL53L0X_RANGE_VALID). */
45bool vl53l0x_range_valid(uint8_t range_status_reg);
46
47// --- ESP32 binding (I2C via Wire; no-ops on a host build) ------------------------------------
48
49/** @brief Verify the model id and start continuous back-to-back ranging at @p addr. @return present + ack. */
50bool vl53l0x_begin(uint8_t addr);
51
52/**
53 * @brief If a measurement is ready, read the distance into @p mm and clear the interrupt.
54 * @return true on a fresh, valid reading; false if not ready / invalid / I2C error.
55 */
56bool vl53l0x_read_mm(uint16_t *mm);
57
58#endif // DETERMINISTICESPASYNCWEBSERVER_VL53L0X_H
bool vl53l0x_begin(uint8_t addr)
Verify the model id and start continuous back-to-back ranging at addr.
bool vl53l0x_data_ready(uint8_t interrupt_status)
True if a new measurement is ready (any of the low 3 interrupt-status bits set).
bool vl53l0x_range_valid(uint8_t range_status_reg)
True if the range-status field reports a valid measurement (== VL53L0X_RANGE_VALID).
bool vl53l0x_read_mm(uint16_t *mm)
If a measurement is ready, read the distance into mm and clear the interrupt.
uint8_t vl53l0x_range_status(uint8_t range_status_reg)
The DeviceRangeStatus field (bits 6:3) of the RESULT_RANGE_STATUS register.
uint16_t vl53l0x_range_mm(uint8_t hi, uint8_t lo)
Combine the range high/low bytes (RESULT_RANGE_STATUS+10 / +11) into millimeters.