FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
|
I2C device driver for the VL53L0X ToF ranging chip. More...
#include <fastarduino/devices/vl53l0x.h>
Classes | |
class | GetGPIOSettingsFuture |
Future to get device current GPIO settings. More... | |
class | SetGPIOSettingsFuture |
Future to set device GPIO settings. More... | |
Public Types | |
using | GetRangeStatusFuture = TReadRegisterFuture< Register::RESULT_RANGE_STATUS, DeviceStatus > |
Future to get device range status. More... | |
using | GetInterruptStatusFuture = TReadRegisterFuture< Register::RESULT_INTERRUPT_STATUS, InterruptStatus > |
Future to get device current interrupt status. More... | |
using | ClearInterruptFuture = TWriteRegisterFuture< Register::SYSTEM_INTERRUPT_CLEAR > |
Future to clear device interrupt status. More... | |
using | GetDirectRangeFuture = TReadRegisterFuture< Register::RESULT_RANGE_MILLIMETER, uint16_t > |
Future to get device current range measure. More... | |
Public Types inherited from i2c::I2CDevice< MANAGER > | |
using | MANAGER = MANAGER |
the type of I2C Manager that can handle this device. More... | |
Public Member Functions | |
VL53L0X (MANAGER &manager) | |
Create a new device driver for a VL53L0X chip. More... | |
bool | set_address (uint8_t device_address) |
Change the I2C address of this VL53L0X device. More... | |
bool | begin (Profile profile) |
Fully initialize this VL53L0X device and configures it with provided profile . More... | |
template<board::Timer TIMER> | |
bool | await_single_range (timer::RTT< TIMER > &rtt, uint16_t &range_mm, uint16_t timeout_ms=DEFAULT_TIMEOUT_MS) |
Perform a single range action on VL53L0X device, and wait for the measurement result. More... | |
bool | start_continuous_ranging (uint16_t period_ms=0) |
Start continuous ranging on this VL53L0X device. More... | |
template<board::Timer TIMER> | |
bool | await_continuous_range (timer::RTT< TIMER > &rtt, uint16_t &range_mm, uint16_t timeout_ms=DEFAULT_TIMEOUT_MS) |
Wait for the next continuous ranging measure on VL53L0X device to be ready and return the result. More... | |
bool | stop_continuous_ranging () |
Stop continuous ranging on this VL53L0X device. More... | |
bool | reset_device () |
Reset VL53L0X device. More... | |
bool | init_data_first () |
Perform 1st stage initialization of this VL53L0X device. More... | |
bool | init_static_second (const GPIOSettings &settings, SequenceSteps steps=SequenceSteps::create().pre_range().final_range().dss()) |
Perform 2nd stage initialization of this VL53L0X device. More... | |
bool | perform_ref_calibration () |
Perform VL53L0X VHV and Phase calibration. More... | |
int | get_range_status (GetRangeStatusFuture &future) |
Get current DeviceStatus from this device. More... | |
bool | get_range_status (DeviceStatus &range_status) |
Get current DeviceStatus from this device. More... | |
int | get_GPIO_settings (GetGPIOSettingsFuture &future) |
Get current GPIOSettings from this device. More... | |
bool | get_GPIO_settings (GPIOSettings &settings) |
Get current GPIOSettings from this device. More... | |
int | set_GPIO_settings (SetGPIOSettingsFuture &future) |
Set new GPIOSettings for this device. More... | |
bool | set_GPIO_settings (const GPIOSettings &settings) |
Set new GPIOSettings for this device. More... | |
int | get_interrupt_status (GetInterruptStatusFuture &future) |
Get current InterruptStatus from this device. More... | |
bool | get_interrupt_status (InterruptStatus &status) |
Get current InterruptStatus from this device. More... | |
int | clear_interrupt (ClearInterruptFuture &future) |
Clear interrupt status from this device. More... | |
bool | clear_interrupt (uint8_t clear_mask=0x01) |
Clear interrupt status from this device. More... | |
template<board::Timer TIMER> | |
bool | await_interrupt (timer::RTT< TIMER > &rtt, uint16_t timeout_ms=DEFAULT_TIMEOUT_MS) |
Wait for an interrupt condition on VL53L0X device. More... | |
int | get_direct_range (GetDirectRangeFuture &future) |
Get range measured by this device. More... | |
bool | get_direct_range (uint16_t &range_mm) |
Get range measured by this device. More... | |
bool | set_measurement_timing_budget (uint32_t budget_us) |
Set new "measurement timing budget" for this device. More... | |
bool | get_measurement_timing_budget (uint32_t &budget_us) |
Get current "measurement timing budget" for this device. More... | |
bool | set_sequence_steps (SequenceSteps sequence_steps) |
Set measurement steps to be executed in sequence by the device during ranging. More... | |
bool | get_sequence_steps (SequenceSteps &sequence_steps) |
Get current measurement steps executed in sequence by the device during ranging. More... | |
template<VcselPeriodType TYPE> | |
bool | set_vcsel_pulse_period (uint8_t period) |
Set new pulse period of the VCSEL for pre-range or final-range step. More... | |
template<VcselPeriodType TYPE> | |
bool | get_vcsel_pulse_period (uint8_t &period) |
Get current pulse period of the VCSEL for pre-range or final-range step. More... | |
bool | set_signal_rate_limit (float signal_rate) |
Set new signal rate limit for ranging. More... | |
bool | get_signal_rate_limit (float &signal_rate) |
Get current signal rate limit for ranging. More... | |
bool | get_power_mode (PowerMode &power_mode) |
Get current power mode of this VL53L0X register. More... | |
bool | get_model (uint8_t &model) |
Get model of this VL53L0X register. More... | |
bool | get_revision (uint8_t &revision) |
Get revision of this VL53L0X register. More... | |
bool | await_interrupt (uint16_t loops=MAX_LOOP) |
Wait for an interrupt condition on VL53L0X device. More... | |
bool | await_continuous_range (uint16_t &range_mm, uint16_t loops=MAX_LOOP) |
Wait for the next continuous ranging measure on VL53L0X device to be ready and return the result. More... | |
bool | await_single_range (uint16_t &range_mm, uint16_t loops=MAX_LOOP) |
Perform a single range action on VL53L0X device, and wait for the measurement result. More... | |
bool | get_reference_SPADs (SPADReference &spad_ref) |
Get the reference SPADs status (enabled or not). More... | |
bool | set_reference_SPADs (const SPADReference &spad_ref) |
Set the reference SPADs status (enabled or not). More... | |
bool | get_SPAD_info (SPADInfo &info) |
Get current SPAD information (number of SPAD aperture or not). More... | |
bool | get_sequence_steps_timeout (SequenceStepsTimeout &timeouts) |
Get current timeouts associated to each ranging step. More... | |
template<Register REGISTER, typename T = uint8_t> | |
int | get_register (TReadRegisterFuture< REGISTER, T > &future) |
Directly get value of a VL53L0X register. More... | |
template<Register REGISTER, typename T = uint8_t> | |
int | set_register (TWriteRegisterFuture< REGISTER, T > &future) |
Directly set value of a VL53L0X register. More... | |
template<Register REGISTER, typename T = uint8_t> | |
bool | get_register (T &value) |
Directly get value of a VL53L0X register. More... | |
template<Register REGISTER, typename T = uint8_t> | |
bool | set_register (T value) |
Directly set value of a VL53L0X register. More... | |
Additional Inherited Members | |
Protected Types inherited from i2c::I2CDevice< MANAGER > | |
using | ABSTRACT_FUTURE = typename MANAGER::ABSTRACT_FUTURE |
The abstract base class of all futures to be defined for a device. More... | |
using | FUTURE = typename MANAGER::template FUTURE< OUT, IN > |
The template base class of all futures to be defined for a device. More... | |
Protected Member Functions inherited from i2c::I2CDevice< MANAGER > | |
I2CDevice (MANAGER &manager, uint8_t device, UNUSED Mode< MODE > mode, bool auto_stop) | |
Create a new I2C device. More... | |
I2CDevice (const I2CDevice &)=delete | |
I2CDevice & | operator= (const I2CDevice &)=delete |
void | set_device (uint8_t device) |
Change the I2C address of this device. More... | |
int | launch_commands (ABSTRACT_FUTURE &future, utils::range< I2CLightCommand > commands) |
Launch execution (asynchronously or synchronously, depending on MANAGER) of a chain of I2CLightCommand items (constructed with read() and write() methods). More... | |
int | async_read (F &future, bool stop=true) |
Helper method that asynchronously launches I2C commands for a simple Future performing one write followed by one read (typically for device register reading). More... | |
bool | sync_read (T &result) |
Helper method that launches I2C commands for a simple Future performing one write followed by one read (typically for device register reading); the method blocks until the end of the I2C transaction. More... | |
int | async_write (F &future, bool stop=true) |
Helper method that asynchronously launches I2C commands for a simple Future performing only one write (typically for device register writing). More... | |
int | async_multi_write (F &future, bool stop=true) |
Helper method that asynchronously launches I2C commands for a simple Future performing several register writes. More... | |
bool | sync_write (const T &value) |
Helper method that launches I2C commands for a simple Future performing only one write (typically for device register writing); the method blocks until the end of the I2C transaction. More... | |
bool | sync_write () |
Helper method that launches I2C commands for a simple Future performing only one write (typically for device register writing); the method blocks until the end of the I2C transaction. More... | |
Static Protected Member Functions inherited from i2c::I2CDevice< MANAGER > | |
static constexpr I2CLightCommand | read (uint8_t read_count=0, bool finish_future=false, bool stop=false) |
Build a read I2CLightCommand that can be later pushed to the I2C Manager for proper handling. More... | |
static constexpr I2CLightCommand | write (uint8_t write_count=0, bool finish_future=false, bool stop=false) |
Build a write I2CLightCommand that can be later pushed to the I2C Manager for proper handling. More... | |
I2C device driver for the VL53L0X ToF ranging chip.
This chip supports both standard and fast I2C modes.
Several levels of API are provided:
Most API comes in synchronous mode only, although it can of course work with an asynchronous I2C Manager. This is due to the highly complex protocol of VL53L0X device where I2C transactions can be long and would have required highly complex Future classes to be defined with little added value. Only API that were deemed useful in non-blocking mode were also made asynchronous. Synchronous API are blocking until completion and should never be called from an ISR! Asynchronous API can be called from anywhere, but you must await their completion through a Future.
REGISTER_FUTURE_STATUS_LISTENERS()
for the following classes:i2c::I2CSameFutureGroup<MANAGER>
: mandatoryVL53L0X::SetGPIOSettingsFuture
: mandatoryVL53L0X::GetGPIOSettingsFuture
: needed if you call API get_GPIO_settings()
MANAGER | one of FastArduino available I2C Manager |
using devices::vl53l0x::VL53L0X< MANAGER >::GetRangeStatusFuture = TReadRegisterFuture<Register::RESULT_RANGE_STATUS, DeviceStatus> |
Future to get device range status.
using devices::vl53l0x::VL53L0X< MANAGER >::GetInterruptStatusFuture = TReadRegisterFuture<Register::RESULT_INTERRUPT_STATUS, InterruptStatus> |
Future to get device current interrupt status.
using devices::vl53l0x::VL53L0X< MANAGER >::ClearInterruptFuture = TWriteRegisterFuture<Register::SYSTEM_INTERRUPT_CLEAR> |
Future to clear device interrupt status.
using devices::vl53l0x::VL53L0X< MANAGER >::GetDirectRangeFuture = TReadRegisterFuture<Register::RESULT_RANGE_MILLIMETER, uint16_t> |
Future to get device current range measure.
|
inlineexplicit |
|
inline |
Change the I2C address of this VL53L0X device.
For this to work, other I2C devices with the same address shall be shut down during this method call.
device_address | the new I2C address for this device; only 7 LSB are relevant. |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Fully initialize this VL53L0X device and configures it with provided profile
.
Once this method has been called successfully, you can start perform ranging (continuous or not). You may also want to set some GPIO interrupts before ranging.
profile | the pre-defined Profile to use on this sensor |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Perform a single range action on VL53L0X device, and wait for the measurement result.
This shall be used when no continuous ranging is in effect.
TIMER | the Timer used for rtt ; this template argument will be automatically deduced from rtt . |
rtt | the real-time timer to use to count elapsed time |
range_mm | a reference to a variable that will receive the measurement result (in mm) |
timeout_ms | the maximum amount of time to wait for a result; default is 100ms, but it should be higher than the measurement timing budget. |
true | if the operation succeeded |
false | if the operation failed or timed out |
|
inline |
Start continuous ranging on this VL53L0X device.
This method shall not be called before the device has been properly initialized, either with high-level API begin()
or mid-level API methods init_data_first()
, init_static_second()
and perform_ref_calibration()
. Once this method has been called, continuous ranging starts on the device, at the given period. You can check when a sample is ready to read by examining interrupt status or reange status, then you can read the range and clear the interrupt. Or you may prefer just await for new range which is easier to code but will block your program.
period_ms | the period, in ms, between 2 consecutive ranging measures; if 0 (the default), then consecutive measures will follow each other with no delay ("back-to-back" mode). |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Wait for the next continuous ranging measure on VL53L0X device to be ready and return the result.
This shall be used only when continuous ranging is in effect.
TIMER | the Timer used for rtt ; this template argument will be automatically deduced from rtt . |
rtt | the real-time timer to use to count elapsed time |
range_mm | a reference to a variable that will receive the measurement result (in mm) |
timeout_ms | the maximum amount of time to wait for a result; default is 100ms, but it should be higher than the measurement timing budget. |
true | if the operation succeeded |
false | if the operation failed or timed out |
|
inline |
|
inline |
Reset VL53L0X device.
After this method is called, the device is in the same state as after power-up, hence device must be reinitialized from scratch.
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Perform 1st stage initialization of this VL53L0X device.
VL53L0X initialization is made of 3 steps before it can perform any ranging:
After initalization, you may call methods changing all kinds of settings. Finally, you may then perform ranging, continuously or not.
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Perform 2nd stage initialization of this VL53L0X device.
This must be called once, or more, after init_data_first()
has been called. It allows you to select which ranging steps shall be used afterwards.
settings | intial GPIO settings to set on the device; these settings can be changed anytime later. |
steps | the ranging steps sequence |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Perform VL53L0X VHV and Phase calibration.
This must be called once before any measurement, but after data and static initalization.
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get current DeviceStatus
from this device.
future | a GetRangeStatusFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
|
inline |
Get current DeviceStatus
from this device.
range_status | a reference to a variable that will receive the device status |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get current GPIOSettings
from this device.
future | a GetGPIOSettingsFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
|
inline |
Get current GPIOSettings
from this device.
settings | a reference to a variable that will receive the current GPIO settings for this device |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Set new GPIOSettings
for this device.
future | a SetGPIOSettingsFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
|
inline |
Set new GPIOSettings
for this device.
settings | new GPIO settings to write to this device |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get current InterruptStatus
from this device.
future | a GetInterruptStatusFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
|
inline |
Get current InterruptStatus
from this device.
status | a reference to a variable that will receive the current interrupt status of this device |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Clear interrupt status from this device.
future | a ClearInterruptFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
|
inline |
Clear interrupt status from this device.
clear_mask | the mask of the interrupts to be cleared |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Wait for an interrupt condition on VL53L0X device.
TIMER | the Timer used for rtt ; this template argument will be automatically deduced from rtt . |
rtt | the real-time timer to use to count elapsed time |
timeout_ms | the maximum amount of time to wait for a result; default is 100ms, but it should be higher than the measurement timing budget. |
true | if the operation succeeded |
false | if the operation failed or timed out |
|
inline |
Get range measured by this device.
This method does not wait for anything, it just gets the current value in the range register. This is useful only when you know a range is ready to read. In general, this method shall be used only after device interrupt status != 0, then interrupt status should be cleared immediately after. You would probably prefer to use methods that first await for range measure to be ready before returning its value.
future | a GetDirectRangeFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
|
inline |
Get range measured by this device.
This method does not wait for anything, it just gets the current value in the range register. This is useful only when you know a range is ready to read. You would probably prefer to use methods that first await for range measure to be ready before returning its value.
range_mm | a reference to a variable that will receive the current range (in mm) stored in the device |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Set new "measurement timing budget" for this device.
This is the amount of time (in us) that is used to perform a range.
budget_us | the new measurement timing budget to use for ranging; it must be bigger than 20000us; the actual minimum value also depends on other device settings, in particular the SequenceSteps used for ranging. The bigger the budget, the higher the accuracy of measurements. |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get current "measurement timing budget" for this device.
This is the amount of time (in us) that is used to perform a range. This amount is calculated based on other settings of the device.
budget_us | a reference to a variable that will receive the current measurement timing budget for this device |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Set measurement steps to be executed in sequence by the device during ranging.
sequence_steps | the sequence steps to use for ranging |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get current measurement steps executed in sequence by the device during ranging.
sequence_steps | a reference to a variable that will receive the sequence steps |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Set new pulse period of the VCSEL for pre-range or final-range step.
Pulse period is expressed in PCLK, whatever that really means. Changing pulse periods has an impact on range distance.
TYPE | the type of pulse period we want to set (pre-range or final-range) |
period | the new pulse period to use for TYPE step; for pre-range, possible values are 12, 14, 16, 18; for final-range these are 8, 10, 12, 14. |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get current pulse period of the VCSEL for pre-range or final-range step.
Pulse period is expressed in PCLK, whatever that really means.
TYPE | the type of pulse period we want to read |
period | a reference to a variable that will receive the pulse period |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Set new signal rate limit for ranging.
This is a ratio between 0.0 and 1.0; lower values will allow ranging in long distance or in a noisy environment; default is normally 0.25.
signal_rate | the new signal rate limit to use for ranging; must be between 0.0 and 1.0. |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get current signal rate limit for ranging.
This is a ratio between 0.0 and 1.0; lower values will allow ranging in long distance or in a noisy environment; default is normally 0.25.
signal_rate | a reference to a variable that will receive the current signal rate limit |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
|
inline |
Get model of this VL53L0X register.
This is normally a constant (0xEE
).
model | a reference to a variable that will receive the model |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get revision of this VL53L0X register.
This is normally a constant (0x10
).
revision | a reference to a variable that will receive the revision |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Wait for an interrupt condition on VL53L0X device.
Wait is performed based on a maximum number of loops, not on actual time. This is more difficult to use than await_interrupt(timer::RTT<TIMER>&, uint16_t)
loops | the maximum number of waiting loops before timeout; default is 2000, but it may not be suitable in every situation. |
true | if the operation succeeded |
false | if the operation failed or timed out |
|
inline |
Wait for the next continuous ranging measure on VL53L0X device to be ready and return the result.
This shall be used only when continuous ranging is in effect. Wait is performed based on a maximum number of loops, not on actual time. This is more difficult to use than await_continuous_range(timer::RTT<TIMER>&, uint16_t&, uint16_t)
range_mm | a reference to a variable that will receive the measurement result (in mm) |
loops | the maximum number of waiting loops before timeout; default is 2000, but it may not be suitable in every situation. |
true | if the operation succeeded |
false | if the operation failed or timed out |
|
inline |
Perform a single range action on VL53L0X device, and wait for the measurement result.
This shall be used when no continuous ranging is in effect. Wait is performed based on a maximum number of loops, not on actual time. This is more difficult to use than await_single_range(timer::RTT<TIMER>&, uint16_t&, uint16_t)
range_mm | a reference to a variable that will receive the measurement result (in mm) |
loops | the maximum number of waiting loops before timeout; default is 2000, but it may not be suitable in every situation. |
true | if the operation succeeded |
false | if the operation failed or timed out |
|
inline |
Get the reference SPADs status (enabled or not).
spad_ref | a reference to a variable that will receive the current reference SPADs status |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Set the reference SPADs status (enabled or not).
spad_ref | the new reference SPADs status to set |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get current SPAD information (number of SPAD aperture or not).
info | a reference to a variable that will receive the current reference SPAD information |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get current timeouts associated to each ranging step.
timeouts | a reference to a variable that will receive the current timeouts associated to ranging steps |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Directly get value of a VL53L0X register.
REGISTER | the register to read from VL53l)X device |
T | the type of value stored in REGISTER |
future | a Future passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
|
inline |
Directly set value of a VL53L0X register.
REGISTER | the register to write to VL53l)X device |
T | the type of value stored in REGISTER |
future | a Future passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
|
inline |
Directly get value of a VL53L0X register.
REGISTER | the register to read from VL53l)X device |
T | the type of value stored in REGISTER |
value | a reference to a variable of type T , that will receive the value in register REGISTER |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Directly set value of a VL53L0X register.
REGISTER | the register to write to VL53l)X device |
T | the type of value stored in REGISTER |
value | a value of type T that will be written to register REGISTER |
true | if the operation succeeded |
false | if the operation failed |