10#ifndef M5_UNIT_TOF_UNIT_VL53L1X_HPP
11#define M5_UNIT_TOF_UNIT_VL53L1X_HPP
13#include <M5UnitComponent.hpp>
14#include <m5_utility/container/circular_buffer.hpp>
15#include <m5_utility/types.hpp>
68 RangeValidMinRangeClipped,
111 std::array<uint8_t, 17>
raw{};
131 return valid() ? m5::types::big_uint16_t(
raw[13],
raw[14]).get() : -1;
141class UnitVL53L1X :
public Component,
public PeriodicMeasurementAdapter<UnitVL53L1X, vl53l1x::Data> {
164 explicit UnitVL53L1X(
const uint8_t addr = DEFAULT_ADDRESS)
165 : Component(addr), _data{new
m5::container::CircularBuffer<vl53l1x::Data>(1)}
167 auto ccfg = component_config();
168 ccfg.clock = 400 * 1000U;
169 component_config(ccfg);
171 virtual ~UnitVL53L1X()
175 virtual bool begin()
override;
176 virtual void update(
const bool force =
false)
override;
200 return !empty() ? oldest().range() : -1;
205 return !empty() && oldest().valid();
210 return !empty() ? oldest().range_status() : vl53l1x::RangeStatus::Unknown255;
242 return PeriodicMeasurementAdapter<UnitVL53L1X, vl53l1x::Data>::startPeriodicMeasurement();
253 return PeriodicMeasurementAdapter<UnitVL53L1X, vl53l1x::Data>::startPeriodicMeasurement(dist, tb);
261 return PeriodicMeasurementAdapter<UnitVL53L1X, vl53l1x::Data>::stopPeriodicMeasurement();
325 bool calibrateXtalk(uint16_t& xtalk,
const uint16_t targetmm = 100);
441 bool readROI(uint8_t& wid, uint8_t& hgt);
456 bool writeROI(
const uint8_t wid,
const uint8_t hgt);
484 bool start_periodic_measurement();
486 bool stop_periodic_measurement();
491 bool read_data_ready_status();
495 bool write_default_values();
502 vl53l1x::Timing _tb{vl53l1x::Timing::BudgetUnknown};
504 std::unique_ptr<m5::container::CircularBuffer<vl53l1x::Data>> _data{};
512constexpr uint16_t SOFT_RESET {0x0000};
513constexpr uint16_t I2C_SLAVE_DEVICE_ADDRESS {0x0001};
514constexpr uint16_t OSC_MEASURED_FAST_OSC_FREQUENCY {0x0006};
515constexpr uint16_t VHV_CONFIG_TIMEOUT_MACROP_LOOP_BOUND {0x0008};
516constexpr uint16_t VHV_CONFIG_INIT {0x000B};
517constexpr uint16_t ALGO_CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS {0x0016};
518constexpr uint16_t ALGO_CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS {0x0018};
519constexpr uint16_t ALGO_CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS {0x001A};
520constexpr uint16_t ALGO_PART_TO_PART_RANGE_OFFSET_MM {0x001E};
521constexpr uint16_t MM_CONFIG_INNER_OFFSET_MM {0x0020};
522constexpr uint16_t MM_CONFIG_OUTER_OFFSET_MM {0x0022};
523constexpr uint16_t DSS_CONFIG_TARGET_TOTAL_RATE_MCPS {0x0024};
524constexpr uint16_t EXTSUP_CONFIG {0x002E};
525constexpr uint16_t GPIO_HV_MUX_CTRL {0x0030};
526constexpr uint16_t GPIO_TIO_HV_STATUS {0x0031};
527constexpr uint16_t SIGMA_ESTIMATOR_EFFECTIVE_PULSE_WIDTH_NS {0x0036};
528constexpr uint16_t SIGMA_ESTIMATOR_EFFECTIVE_AMBIENT_WIDTH_NS {0x0037};
529constexpr uint16_t ALGO_CROSSTALK_COMPENSATION_VALID_HEIGHT_MM {0x0039};
530constexpr uint16_t ALGO_RANGE_IGNORE_VALID_HEIGHT_MM {0x003E};
531constexpr uint16_t ALGO_RANGE_MIN_CLIP {0x003F};
532constexpr uint16_t ALGO_CONSISTENCY_CHECK_TOLERANCE {0x0040};
533constexpr uint16_t SYSTEM_INTERRUPT_CONFIG_GPIO {0x0046};
534constexpr uint16_t CAL_CONFIG_VCSEL_START {0x0047};
535constexpr uint16_t PHASECAL_CONFIG_TIMEOUT_MACROP {0x004B};
536constexpr uint16_t PHASECAL_CONFIG_OVERRIDE {0x004D};
537constexpr uint16_t DSS_CONFIG_ROI_MODE_CONTROL {0x004F};
538constexpr uint16_t SYSTEM_THRESH_RATE_HIGH {0x0050};
539constexpr uint16_t SYSTEM_THRESH_RATE_LOW {0x0052};
540constexpr uint16_t DSS_CONFIG_MANUAL_EFFECTIVE_SPADS_SELECT {0x0054};
541constexpr uint16_t DSS_CONFIG_APERTURE_ATTENUATION {0x0057};
542constexpr uint16_t MM_CONFIG_TIMEOUT_MACROP_A {0x005A};
543constexpr uint16_t MM_CONFIG_TIMEOUT_MACROP_B {0x005C};
544constexpr uint16_t RANGE_CONFIG_TIMEOUT_MACROP_A {0x005E};
545constexpr uint16_t RANGE_CONFIG_TIMEOUT_MACROP_A_HI {0x005E};
546constexpr uint16_t RANGE_CONFIG_VCSEL_PERIOD_A {0x0060};
547constexpr uint16_t RANGE_CONFIG_TIMEOUT_MACROP_B {0x0061};
548constexpr uint16_t RANGE_CONFIG_TIMEOUT_MACROP_B_HI {0x0061};
549constexpr uint16_t RANGE_CONFIG_VCSEL_PERIOD_B {0x0063};
550constexpr uint16_t RANGE_CONFIG_SIGMA_THRESH {0x0064};
551constexpr uint16_t RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT_MCPS {0x0066};
552constexpr uint16_t RANGE_CONFIG_VALID_PHASE_HIGH {0x0069};
553constexpr uint16_t SYSTEM_INTERMEASUREMENT_PERIOD {0x006C};
554constexpr uint16_t SYSTEM_GROUPED_PARAMETER_HOLD_0 {0x0071};
555constexpr uint16_t SYSTEM_THRESH_HIGH {0x0072};
556constexpr uint16_t SYSTEM_THRESH_LOW {0x0074};
557constexpr uint16_t SYSTEM_SEED_CONFIG {0x0077};
558constexpr uint16_t SD_CONFIG_WOI_SD0 {0x0078};
559constexpr uint16_t SD_CONFIG_WOI_SD1 {0x0079};
560constexpr uint16_t SD_CONFIG_INITIAL_PHASE_SD0 {0x007A};
561constexpr uint16_t SD_CONFIG_INITIAL_PHASE_SD1 {0x007B};
562constexpr uint16_t SYSTEM_GROUPED_PARAMETER_HOLD_1 {0x007C};
563constexpr uint16_t SD_CONFIG_QUANTIFIER {0x007E};
564constexpr uint16_t ROI_CONFIG_USER_ROI_CENTRE_SPAD {0x007F};
565constexpr uint16_t ROI_CONFIG_USER_ROI_REQUESTED_GLOBAL_XY_SIZE {0x0080};
566constexpr uint16_t SYSTEM_SEQUENCE_CONFIG {0x0081};
567constexpr uint16_t SYSTEM_GROUPED_PARAMETER_HOLD {0x0082};
568constexpr uint16_t SYSTEM_INTERRUPT_CLEAR {0x0086};
569constexpr uint16_t SYSTEM_MODE_START {0x0087};
570constexpr uint16_t RESULT_RANGE_STATUS {0x0089};
571constexpr uint16_t RESULT_DSS_ACTUAL_EFFECTIVE_SPADS_SD0 {0x008C};
572constexpr uint16_t RESULT_FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0 {0x0096};
573constexpr uint16_t RESULT_PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0 {0x0098};
574constexpr uint16_t PHASECAL_RESULT_VCSEL_START {0x00D8};
575constexpr uint16_t RESULT_OSC_CALIBRATE_VAL {0x00DE};
576constexpr uint16_t FIRMWARE_SYSTEM_STATUS {0x00E5};
578constexpr uint16_t MODEL_ID {0x010F};
579constexpr uint16_t MODULE_TYPE {0x0110};
580constexpr uint16_t MASK_REVISION {0x0111};
ToF4M unit.
Definition unit_VL53L1X.hpp:141
bool clearDistanceThreshold()
Go back to the regular ranging mode.
Definition unit_VL53L1X.hpp:405
bool writeROICenter(const uint8_t center)
Write the center of the ROI.
Definition unit_VL53L1X.cpp:751
bool startPeriodicMeasurement()
Start periodic measurement in the current settings.
Definition unit_VL53L1X.hpp:240
bool readDistanceThresholdWindow(vl53l1x::Window &window)
Read the window detection mode.
Definition unit_VL53L1X.cpp:672
int16_t range() const
Oldest measured range(mm)
Definition unit_VL53L1X.hpp:198
bool writeDistanceMode(const vl53l1x::Distance d)
Write the distance mode.
Definition unit_VL53L1X.cpp:390
bool readDistanceThresholdHigh(uint16_t &mm)
Read the higher distance threshould.
Definition unit_VL53L1X.cpp:690
bool readTimingBudget(vl53l1x::Timing &tb)
Read the timing budget.
Definition unit_VL53L1X.cpp:579
bool writeROI(const uint8_t wid, const uint8_t hgt)
Write the ROI width and height.
Definition unit_VL53L1X.cpp:731
bool readDistanceThresholdLow(uint16_t &mm)
Read the lower distance threshould.
Definition unit_VL53L1X.cpp:686
bool readXtalk(uint16_t &xtalk)
Read the crosstalk.
Definition unit_VL53L1X.cpp:559
vl53l1x::RangeStatus range_status() const
Oldest measured range status.
Definition unit_VL53L1X.hpp:208
bool readDistanceMode(vl53l1x::Distance &d)
Read the distance mode.
Definition unit_VL53L1X.cpp:380
vl53l1x::Timing timingBudget() const
Gets the inner timing budget.
Definition unit_VL53L1X.hpp:228
bool writeDistanceThreshold(const vl53l1x::Window window, const uint16_t low, const uint16_t high)
Write the threshold and window detection mode.
Definition unit_VL53L1X.cpp:695
bool readInterMeasurementPeriod(uint16_t &ms)
Read the inter-measurement period(IMP)
Definition unit_VL53L1X.cpp:642
bool readROI(uint8_t &wid, uint8_t &hgt)
Read the ROI width and height.
Definition unit_VL53L1X.cpp:715
bool startPeriodicMeasurement(const vl53l1x::Distance dist, const vl53l1x::Timing tb=vl53l1x::Timing::Budget50ms)
Start periodic measurement.
Definition unit_VL53L1X.hpp:250
bool writeOffset(const int16_t offset)
Write the offset.
Definition unit_VL53L1X.cpp:478
bool writeXtalk(const uint16_t xtalk)
Write the crosstalk.
Definition unit_VL53L1X.cpp:571
vl53l1x::Distance distanceMode() const
Gets the inner distance mode.
Definition unit_VL53L1X.hpp:220
bool changeI2CAddress(const uint8_t i2c_address)
Change unit I2C address.
Definition unit_VL53L1X.cpp:337
bool calibrateOffset(int16_t &offset, const uint16_t targetmm=100)
Calculate and write calibration offsets for a given target value.
Definition unit_VL53L1X.cpp:423
void config(const config_t &cfg)
Set the configration.
Definition unit_VL53L1X.hpp:186
bool readI2CAddress(uint8_t &i2c_address)
Read the I2C address.
Definition unit_VL53L1X.cpp:331
bool calibrateXtalk(uint16_t &xtalk, const uint16_t targetmm=100)
Calculate and write calibration crosstalk for a given target value.
Definition unit_VL53L1X.cpp:491
bool writeInterMeasurementPeriod(const uint16_t ms)
Write the inter-measurement period(IMP)
Definition unit_VL53L1X.cpp:656
bool writeTimingBudget(const vl53l1x::Timing tb)
Write the timing budget.
Definition unit_VL53L1X.hpp:354
bool valid() const
Is valid oldest data?
Definition unit_VL53L1X.hpp:203
bool measureSingleshot(vl53l1x::Data &d)
Measurement single shot in the current settings.
Definition unit_VL53L1X.cpp:277
bool softReset()
Software reset.
Definition unit_VL53L1X.cpp:298
bool stopPeriodicMeasurement()
Stop periodic measurement.
Definition unit_VL53L1X.hpp:259
bool readOffset(int16_t &offset)
Read the offset.
Definition unit_VL53L1X.cpp:463
config_t config() const
Gets the configration.
Definition unit_VL53L1X.hpp:181
bool readROICenter(uint8_t ¢er)
Read the center of the ROI.
Definition unit_VL53L1X.cpp:726
Top level namespace of M5stack.
Settings for begin.
Definition unit_VL53L1X.hpp:149
bool calibrate_xtalk
Caliblate crosstalk if start on begin.
Definition unit_VL53L1X.hpp:161
bool start_periodic
Start periodic measurement on begin?
Definition unit_VL53L1X.hpp:157
bool calibrate_offset
Caliblate offset if start on begin.
Definition unit_VL53L1X.hpp:159
vl53l1x::Timing timing_budget
Timing budget.
Definition unit_VL53L1X.hpp:155
vl53l1x::Operating operating
Operatiing condition.
Definition unit_VL53L1X.hpp:151
vl53l1x::Distance distance
Distance mode.
Definition unit_VL53L1X.hpp:153
Measurement data group.
Definition unit_VL53L1X.hpp:110
bool valid() const
Is data valid?
Definition unit_VL53L1X.hpp:120
RangeStatus range_status() const
Range status.
Definition unit_VL53L1X.cpp:92
std::array< uint8_t, 17 > raw
RAW data.
Definition unit_VL53L1X.hpp:111
int16_t range() const
range (mm)
Definition unit_VL53L1X.hpp:129
Window
Window detection mode.
Definition unit_VL53L1X.hpp:98
@ Beyond
Beyond a certain distance.
@ Out
Out of distance range (min/max), "out of Window".
@ Regular
Regular ranging (without window)
@ Below
Below a certain distance.
@ In
Within the distance range (min/max), "inside Window".
RangeStatus
Range status interpretation.
Definition unit_VL53L1X.hpp:64
Operating
Operating condition.
Definition unit_VL53L1X.hpp:28
Timing
Timeing budget for ranging.
Definition unit_VL53L1X.hpp:49
@ Budget15ms
15 ms (Only possible when Short mode)
Distance
Distance mode.
Definition unit_VL53L1X.hpp:37
@ Short
Short (limited to 1.3m)
@ Long
Long (limited to 4.0m)