Macros | Functions
vl53l1_core.c File Reference

EwokPlus25 core function definition. More...

#include "vl53l1_ll_def.h"
#include "vl53l1_ll_device.h"
#include "vl53l1_platform.h"
#include "vl53l1_register_map.h"
#include "vl53l1_register_funcs.h"
#include "vl53l1_register_settings.h"
#include "vl53l1_api_preset_modes.h"
#include "vl53l1_core.h"
#include "vl53l1_tuning_parm_defaults.h"
Include dependency graph for vl53l1_core.c:

Go to the source code of this file.

Macros

#define LOG_FUNCTION_END(status, ...)   _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
 
#define LOG_FUNCTION_END_FMT(status, fmt, ...)
 
#define LOG_FUNCTION_START(fmt, ...)   _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
 
#define trace_print(level, ...)
 

Functions

uint32_t VL53L1_calc_crosstalk_plane_offset_with_margin (uint32_t plane_offset_kcps, int16_t margin_offset_kcps)
 Function to add signed margin to the xtalk plane offset value, dealing with signed and unsigned value mixing. More...
 
uint32_t VL53L1_calc_decoded_timeout_us (uint16_t timeout_encoded, uint32_t macro_period_us)
 Calculates the decoded timeout in us based on the input encoded timeout register value and the macro period in us. More...
 
uint16_t VL53L1_calc_encoded_timeout (uint32_t timeout_us, uint32_t macro_period_us)
 Calculates the encoded timeout register value based on the input timeout period in milliseconds and the macro period in us. More...
 
uint32_t VL53L1_calc_macro_period_us (uint16_t fast_osc_frequency, uint8_t vcsel_period)
 Forces shadow stream count to zero. More...
 
void VL53L1_calc_mm_effective_spads (uint8_t encoded_mm_roi_centre, uint8_t encoded_mm_roi_size, uint8_t encoded_zone_centre, uint8_t encoded_zone_size, uint8_t *pgood_spads, uint16_t aperture_attenuation, uint16_t *pmm_inner_effective_spads, uint16_t *pmm_outer_effective_spads)
 Calculates the effective SPAD counts for the MM inner and outer regions based on the input MM ROI, Zone info and return good SPAD map. More...
 
uint16_t VL53L1_calc_range_ignore_threshold (uint32_t central_rate, int16_t x_gradient, int16_t y_gradient, uint8_t rate_mult)
 Calculates the Xtalk Range Ignore Threshold rate per spad in 3.13Mcps. More...
 
uint32_t VL53L1_calc_timeout_mclks (uint32_t timeout_us, uint32_t macro_period_us)
 Calculates the timeout value in macro period based on the input timeout period in milliseconds and the macro period in us. More...
 
VL53L1_Error VL53L1_calc_timeout_register_values (uint32_t phasecal_config_timeout_us, uint32_t mm_config_timeout_us, uint32_t range_config_timeout_us, uint16_t fast_osc_frequency, VL53L1_general_config_t *pgeneral, VL53L1_timing_config_t *ptiming)
 Converts the input MM and range timeouts in [us] into the appropriate register values. More...
 
uint32_t VL53L1_calc_timeout_us (uint32_t timeout_mclks, uint32_t macro_period_us)
 Calculates the timeout in us based on the input timeout im macro periods value and the macro period in us. More...
 
VL53L1_Error VL53L1_check_ll_driver_rd_state (VL53L1_DEV Dev)
 Checks if the LL Driver Read state and expected stream count matches the state and stream count received from the device. More...
 
VL53L1_Error VL53L1_clear_interrupt (VL53L1_DEV Dev)
 Clears Ranging Interrupt. More...
 
VL53L1_Error VL53L1_config_low_power_auto_mode (VL53L1_general_config_t *pgeneral, VL53L1_dynamic_config_t *pdynamic, VL53L1_low_power_auto_data_t *plpadata)
 Initialize the config strcutures when low power auto preset modes are selected. More...
 
void VL53L1_copy_rtn_good_spads_to_buffer (VL53L1_nvm_copy_data_t *pdata, uint8_t *pbuffer)
 Convenience function to copy return SPAD enables to buffer. More...
 
VL53L1_GPIO_interrupt_config_t VL53L1_decode_GPIO_interrupt_config (uint8_t system__interrupt_config)
 Decodes FW register to VL53L1_GPIO_interrupt_config_t structure. More...
 
uint32_t VL53L1_decode_timeout (uint16_t encoded_timeout)
 Decode 16-bit timeout register value. More...
 
uint32_t VL53L1_decode_unsigned_integer (uint8_t *pbuffer, uint8_t no_of_bytes)
 Decodes an unsigned integer from a uint8_t buffer 16-bit, 24-bit or 32-bit integers. More...
 
void VL53L1_decode_zone_limits (uint8_t encoded_xy_centre, uint8_t encoded_xy_size, int16_t *px_ll, int16_t *py_ll, int16_t *px_ur, int16_t *py_ur)
 Decodes encoded zone info into min/max limits. More...
 
void VL53L1_decode_zone_size (uint8_t encoded_xy_size, uint8_t *pwidth, uint8_t *pheight)
 Decodes encoded zone size format into width and height values. More...
 
VL53L1_Error VL53L1_disable_firmware (VL53L1_DEV Dev)
 Disables MCU firmware. More...
 
VL53L1_Error VL53L1_disable_powerforce (VL53L1_DEV Dev)
 Disables power force. More...
 
VL53L1_Error VL53L1_enable_firmware (VL53L1_DEV Dev)
 Enables MCU firmware. More...
 
VL53L1_Error VL53L1_enable_powerforce (VL53L1_DEV Dev)
 Enables power force. More...
 
uint8_t VL53L1_encode_GPIO_interrupt_config (VL53L1_GPIO_interrupt_config_t *pintconf)
 Encodes VL53L1_GPIO_interrupt_config_t structure to FW register format. More...
 
void VL53L1_encode_row_col (uint8_t row, uint8_t col, uint8_t *pspad_number)
 Encodes a (col,row) coord value into ByteIndex.BitIndex format. More...
 
uint16_t VL53L1_encode_timeout (uint32_t timeout_mclks)
 Encode timeout in (LSByte * 2^MSByte) + 1 register format. More...
 
void VL53L1_encode_unsigned_integer (uint32_t ip_value, uint8_t no_of_bytes, uint8_t *pbuffer)
 Encodes an unsigned integer into a uint8_t buffer MS byte first. More...
 
uint8_t VL53L1_encode_vcsel_period (uint8_t vcsel_period_pclks)
 Encodes the real period in PLL clocks into the register value. More...
 
void VL53L1_encode_zone_size (uint8_t width, uint8_t height, uint8_t *pencoded_xy_size)
 Encodes a zone width & height into encoded size format. More...
 
VL53L1_Error VL53L1_get_spad_rate_data (VL53L1_DEV Dev, VL53L1_spad_rate_data_t *pspad_rates)
 Gets the 256 return array SSC rates from the Patch RAM. More...
 
int16_t VL53L1_i2c_decode_int16_t (uint16_t count, uint8_t *pbuffer)
 Decodes a int16_t register value from an I2C read buffer. More...
 
int32_t VL53L1_i2c_decode_int32_t (uint16_t count, uint8_t *pbuffer)
 Decodes a int32_t register value from an I2C read buffer. More...
 
uint16_t VL53L1_i2c_decode_uint16_t (uint16_t count, uint8_t *pbuffer)
 Decodes a uint16_t register value from an I2C read buffer. More...
 
uint32_t VL53L1_i2c_decode_uint32_t (uint16_t count, uint8_t *pbuffer)
 Decodes a uint32_t register value from an I2C read buffer. More...
 
uint32_t VL53L1_i2c_decode_with_mask (uint16_t count, uint8_t *pbuffer, uint32_t bit_mask, uint32_t down_shift, uint32_t offset)
 Decodes an integer register value from an I2C read buffer. More...
 
void VL53L1_i2c_encode_int16_t (int16_t ip_value, uint16_t count, uint8_t *pbuffer)
 Encodes a int16_t register value into an I2C write buffer. More...
 
void VL53L1_i2c_encode_int32_t (int32_t ip_value, uint16_t count, uint8_t *pbuffer)
 Encodes a int32_t register value into an I2C write buffer. More...
 
void VL53L1_i2c_encode_uint16_t (uint16_t ip_value, uint16_t count, uint8_t *pbuffer)
 Encodes a uint16_t register value into an I2C write buffer. More...
 
void VL53L1_i2c_encode_uint32_t (uint32_t ip_value, uint16_t count, uint8_t *pbuffer)
 Encodes a uint32_t register value into an I2C write buffer. More...
 
void VL53L1_init_ll_driver_state (VL53L1_DEV Dev, VL53L1_DeviceState device_state)
 Initialise LL Driver State. More...
 
void VL53L1_init_system_results (VL53L1_system_results_t *pdata)
 Initialise system results structure to all ones. More...
 
void VL53L1_init_version (VL53L1_DEV Dev)
 Initialise version info in pdev. More...
 
uint8_t VL53L1_is_aperture_location (uint8_t row, uint8_t col)
 Returns > 0 if input (row,col) location is an apertured SPAD. More...
 
VL53L1_Error VL53L1_low_power_auto_data_init (VL53L1_DEV Dev)
 Initialize the Low Power Auto data structure. More...
 
VL53L1_Error VL53L1_low_power_auto_data_stop_range (VL53L1_DEV Dev)
 Reset internal state but leave low_power_auto mode intact. More...
 
VL53L1_Error VL53L1_low_power_auto_setup_manual_calibration (VL53L1_DEV Dev)
 Setup ranges after the first one in low power auto mode by turning off FW calibration steps and programming static values. More...
 
VL53L1_Error VL53L1_low_power_auto_update_DSS (VL53L1_DEV Dev)
 Do a DSS calculation and update manual config. More...
 
VL53L1_Error VL53L1_set_firmware_enable_register (VL53L1_DEV Dev, uint8_t value)
 Set firmware enable register. More...
 
VL53L1_Error VL53L1_set_GPIO_distance_threshold (VL53L1_DEV Dev, uint16_t threshold_high, uint16_t threshold_low)
 SET GPIO distance threshold. More...
 
VL53L1_Error VL53L1_set_GPIO_rate_threshold (VL53L1_DEV Dev, uint16_t threshold_high, uint16_t threshold_low)
 SET GPIO rate threshold. More...
 
VL53L1_Error VL53L1_set_GPIO_thresholds_from_struct (VL53L1_DEV Dev, VL53L1_GPIO_interrupt_config_t *pintconf)
 SET GPIO thresholds from structure. Sets both rate and distance thresholds. More...
 
VL53L1_Error VL53L1_set_powerforce_register (VL53L1_DEV Dev, uint8_t value)
 Set power force register. More...
 
VL53L1_Error VL53L1_set_ref_spad_char_config (VL53L1_DEV Dev, uint8_t vcsel_period_a, uint32_t phasecal_timeout_us, uint16_t total_rate_target_mcps, uint16_t max_count_rate_rtn_limit_mcps, uint16_t min_count_rate_rtn_limit_mcps, uint16_t fast_osc_frequency)
 Set Ref SPAD Characterisation Config. More...
 
VL53L1_Error VL53L1_set_ssc_config (VL53L1_DEV Dev, VL53L1_ssc_config_t *pssc_cfg, uint16_t fast_osc_frequency)
 Applies SSC (SPAD Self Check) configuration to device. More...
 
void VL53L1_spad_number_to_byte_bit_index (uint8_t spad_number, uint8_t *pbyte_index, uint8_t *pbit_index, uint8_t *pbit_mask)
 Get the SPAD number, byte index (0-31) and bit index (0-7) for. More...
 
VL53L1_Error VL53L1_start_test (VL53L1_DEV Dev, uint8_t test_mode__ctrl)
 Triggers the start of the provided test_mode. More...
 
VL53L1_Error VL53L1_update_ll_driver_cfg_state (VL53L1_DEV Dev)
 Update LL Driver Configuration State. More...
 
VL53L1_Error VL53L1_update_ll_driver_rd_state (VL53L1_DEV Dev)
 Update LL Driver Read State. More...
 

Detailed Description

EwokPlus25 core function definition.

Definition in file vl53l1_core.c.

Macro Definition Documentation

◆ LOG_FUNCTION_END

#define LOG_FUNCTION_END (   status,
  ... 
)    _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)

Definition at line 87 of file vl53l1_core.c.

◆ LOG_FUNCTION_END_FMT

#define LOG_FUNCTION_END_FMT (   status,
  fmt,
  ... 
)
Value:
_LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, \
status, fmt, ##__VA_ARGS__)

Definition at line 89 of file vl53l1_core.c.

◆ LOG_FUNCTION_START

#define LOG_FUNCTION_START (   fmt,
  ... 
)    _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)

Definition at line 85 of file vl53l1_core.c.

◆ trace_print

#define trace_print (   level,
  ... 
)
Value:
_LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_CORE, \
level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)

Definition at line 93 of file vl53l1_core.c.

Function Documentation

◆ VL53L1_calc_crosstalk_plane_offset_with_margin()

uint32_t VL53L1_calc_crosstalk_plane_offset_with_margin ( uint32_t  plane_offset_kcps,
int16_t  margin_offset_kcps 
)

Function to add signed margin to the xtalk plane offset value, dealing with signed and unsigned value mixing.

Clips output to 0 if negative Clips to max possible value of 9.9 Kcps if exceeds this limitation

Parameters
[in]plane_offset_kcps: xtalk plane offset (9.9 format) Kcps
[in]margin_offset_kcps: margin offset signed (6.9 format) Kcps
Returns
plane_offset_with_margin in Kcps (7.9 format)

Definition at line 1172 of file vl53l1_core.c.

◆ VL53L1_calc_decoded_timeout_us()

uint32_t VL53L1_calc_decoded_timeout_us ( uint16_t  timeout_encoded,
uint32_t  macro_period_us 
)

Calculates the decoded timeout in us based on the input encoded timeout register value and the macro period in us.

Parameters
[in]timeout_encoded: encoded timeout register value
[in]macro_period_us: macro period in microseconds 12.12
Returns
timeout_us : encoded timeout register value

Definition at line 1201 of file vl53l1_core.c.

◆ VL53L1_calc_encoded_timeout()

uint16_t VL53L1_calc_encoded_timeout ( uint32_t  timeout_us,
uint32_t  macro_period_us 
)

Calculates the encoded timeout register value based on the input timeout period in milliseconds and the macro period in us.

Parameters
[in]timeout_us: timeout period in microseconds
[in]macro_period_us: macro period in microseconds 12.12
Returns
timeout_encoded : encoded timeout register value

Definition at line 1094 of file vl53l1_core.c.

◆ VL53L1_calc_macro_period_us()

uint32_t VL53L1_calc_macro_period_us ( uint16_t  fast_osc_frequency,
uint8_t  vcsel_period 
)

Forces shadow stream count to zero.

Parameters
[in]Dev: Device handle
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Calculates the macro period in [us] for the input fast_osc_frequency and VCSEL period register value

Processing steps:

  1. PLL period from fast_osc_frequency
  2. VCSEL period
  3. Macro period
Parameters
[in]fast_osc_frequency: fast oscillator frequency in 4.12 MHz format
[in]vcsel_period: VCSEL period register value
Returns
macro_period_us : macro period in [us] 12.12 format

Definition at line 920 of file vl53l1_core.c.

◆ VL53L1_calc_mm_effective_spads()

void VL53L1_calc_mm_effective_spads ( uint8_t  encoded_mm_roi_centre,
uint8_t  encoded_mm_roi_size,
uint8_t  encoded_zone_centre,
uint8_t  encoded_zone_size,
uint8_t pgood_spads,
uint16_t  aperture_attenuation,
uint16_t pmm_inner_effective_spads,
uint16_t pmm_outer_effective_spads 
)

Calculates the effective SPAD counts for the MM inner and outer regions based on the input MM ROI, Zone info and return good SPAD map.

Parameters
[in]encoded_mm_roi_centre: Encoded MM ROI centre - spad number
[in]encoded_mm_roi_size: Encoded MM ROI size
[in]encoded_zone_centre: Encoded Zone centre - spad number
[in]encoded_zone_size: Encoded Zone size
[in]pgood_spads: Return array good SPAD map (32 bytes)
[in]aperture_attenuation: Aperture attenuation value, Format 8.8
[out]pmm_inner_effective_spads: MM Inner effective SPADs, Format 8.8
[out]pmm_outer_effective_spads: MM Outer effective SPADs, Format 8.8

Definition at line 1583 of file vl53l1_core.c.

◆ VL53L1_calc_range_ignore_threshold()

uint16_t VL53L1_calc_range_ignore_threshold ( uint32_t  central_rate,
int16_t  x_gradient,
int16_t  y_gradient,
uint8_t  rate_mult 
)

Calculates the Xtalk Range Ignore Threshold rate per spad in 3.13Mcps.

This is done by calculating the worst case xtalk seen on the array and applying a user specified fractional multiplier.

Parameters
[in]central_rate: xtalk central rate in 9.9u Kcps format
[in]x_gradient: xtalk xgradient rate in 4.11s Kcps format
[in]y_gradient: xtalk ygradient rate in 4.11s Kcps format
[in]rate_mult: rate multiplier in 2.5 fractional format
Returns
range_ignore_threshold_kcps : rate per spad in mcps 3.13

Definition at line 987 of file vl53l1_core.c.

◆ VL53L1_calc_timeout_mclks()

uint32_t VL53L1_calc_timeout_mclks ( uint32_t  timeout_us,
uint32_t  macro_period_us 
)

Calculates the timeout value in macro period based on the input timeout period in milliseconds and the macro period in us.

Parameters
[in]timeout_us: timeout period in microseconds
[in]macro_period_us: macro period in microseconds 12.12
Returns
timeout_mclks : timeout in macro periods

Definition at line 1067 of file vl53l1_core.c.

◆ VL53L1_calc_timeout_register_values()

VL53L1_Error VL53L1_calc_timeout_register_values ( uint32_t  phasecal_config_timeout_us,
uint32_t  mm_config_timeout_us,
uint32_t  range_config_timeout_us,
uint16_t  fast_osc_frequency,
VL53L1_general_config_t pgeneral,
VL53L1_timing_config_t ptiming 
)

Converts the input MM and range timeouts in [us] into the appropriate register values.

Must also be run after the VCSEL period settings are changed

Parameters
[in]phasecal_config_timeout_us: requested Phase Cal Timeout e.g. 1000us
[in]mm_config_timeout_us: requested MM Timeout e.g. 2000us
[in]range_config_timeout_us: requested Ranging Timeout e.g 10000us
[in]fast_osc_frequency: fast oscillator frequency in 4.12 MHz format
[out]pgeneral: general data struct
[out]ptiming: timing data struct with input vcsel period data
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 1273 of file vl53l1_core.c.

◆ VL53L1_calc_timeout_us()

uint32_t VL53L1_calc_timeout_us ( uint32_t  timeout_mclks,
uint32_t  macro_period_us 
)

Calculates the timeout in us based on the input timeout im macro periods value and the macro period in us.

Parameters
[in]timeout_mclks: timeout im macro periods
[in]macro_period_us: macro period in microseconds 12.12
Returns
timeout_us : encoded timeout register value

Definition at line 1133 of file vl53l1_core.c.

◆ VL53L1_check_ll_driver_rd_state()

VL53L1_Error VL53L1_check_ll_driver_rd_state ( VL53L1_DEV  Dev)

Checks if the LL Driver Read state and expected stream count matches the state and stream count received from the device.

Parameters
[out]Dev: Device handle
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 255 of file vl53l1_core.c.

◆ VL53L1_clear_interrupt()

VL53L1_Error VL53L1_clear_interrupt ( VL53L1_DEV  Dev)

Clears Ranging Interrupt.

Parameters
[in]Dev: Device handle
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 866 of file vl53l1_core.c.

◆ VL53L1_config_low_power_auto_mode()

VL53L1_Error VL53L1_config_low_power_auto_mode ( VL53L1_general_config_t pgeneral,
VL53L1_dynamic_config_t pdynamic,
VL53L1_low_power_auto_data_t plpadata 
)

Initialize the config strcutures when low power auto preset modes are selected.

Patch_LowPowerAutoMode

Parameters
[in]pgeneral: pointer to the general config structure
[in]pdynamic: pointer to the dynamic config structure
[in]plpadata: pointer to the low power auto config structure
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 2174 of file vl53l1_core.c.

◆ VL53L1_copy_rtn_good_spads_to_buffer()

void VL53L1_copy_rtn_good_spads_to_buffer ( VL53L1_nvm_copy_data_t pdata,
uint8_t pbuffer 
)

Convenience function to copy return SPAD enables to buffer.

Parameters
[in]pdata: pointer to VL53L1_nvm_copy_data_t
[out]pbuffer: pointer to buffer

Definition at line 437 of file vl53l1_core.c.

◆ VL53L1_decode_GPIO_interrupt_config()

VL53L1_GPIO_interrupt_config_t VL53L1_decode_GPIO_interrupt_config ( uint8_t  system__interrupt_config)

Decodes FW register to VL53L1_GPIO_interrupt_config_t structure.

Parameters
[in]system__interrupt_config: interrupt config register byte
Returns
The decoded structure

Definition at line 1724 of file vl53l1_core.c.

◆ VL53L1_decode_timeout()

uint32_t VL53L1_decode_timeout ( uint16_t  encoded_timeout)

Decode 16-bit timeout register value.

Parameters
[in]encoded_timeout: 16-bit timeout register value
Returns
timeout_macro_clks : uint32_t decoded value

Definition at line 1257 of file vl53l1_core.c.

◆ VL53L1_decode_unsigned_integer()

uint32_t VL53L1_decode_unsigned_integer ( uint8_t pbuffer,
uint8_t  no_of_bytes 
)

Decodes an unsigned integer from a uint8_t buffer 16-bit, 24-bit or 32-bit integers.

Assumes MS Byte first

Parameters
[in]pbuffer: pointer to start of integer uint8_t data
[in]no_of_bytes: size of integer in bytes
Returns
decoded_value : decoded integer value

Definition at line 1390 of file vl53l1_core.c.

◆ VL53L1_decode_zone_limits()

void VL53L1_decode_zone_limits ( uint8_t  encoded_xy_centre,
uint8_t  encoded_xy_size,
int16_t px_ll,
int16_t py_ll,
int16_t px_ur,
int16_t py_ur 
)

Decodes encoded zone info into min/max limits.

Note both the lower left and upper right coordinated lie within the zone (inclusive)

Parameters
[in]encoded_xy_centre: Encoded zone centre (spad number)
[in]encoded_xy_size: Encoded zone size
[out]px_ll: Decoded zone lower left x coord
[out]py_ll: Decoded zone lower left y coord
[out]px_ur: Decoded zone upper right x coord
[out]py_ur: Decoded zone upper right y coord

Definition at line 1508 of file vl53l1_core.c.

◆ VL53L1_decode_zone_size()

void VL53L1_decode_zone_size ( uint8_t  encoded_xy_size,
uint8_t pwidth,
uint8_t pheight 
)

Decodes encoded zone size format into width and height values.

Parameters
[in]encoded_xy_size: Encoded zone size
[out]pwidth: Decoded zone width
[out]pheight: Decoded zone height

Definition at line 1468 of file vl53l1_core.c.

◆ VL53L1_disable_firmware()

VL53L1_Error VL53L1_disable_firmware ( VL53L1_DEV  Dev)

Disables MCU firmware.

This required to write to MCU G02, G01 registers and access the patch RAM

Parameters
[in]Dev: Device handle
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 787 of file vl53l1_core.c.

◆ VL53L1_disable_powerforce()

VL53L1_Error VL53L1_disable_powerforce ( VL53L1_DEV  Dev)

Disables power force.

Parameters
[in]Dev: Device handle

Disable power force

Calls VL53L1_set_powerforce_register()

Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 847 of file vl53l1_core.c.

◆ VL53L1_enable_firmware()

VL53L1_Error VL53L1_enable_firmware ( VL53L1_DEV  Dev)

Enables MCU firmware.

Parameters
[in]Dev: Device handle
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 768 of file vl53l1_core.c.

◆ VL53L1_enable_powerforce()

VL53L1_Error VL53L1_enable_powerforce ( VL53L1_DEV  Dev)

Enables power force.

This prevents the G01 and patch RAM from powering down between ranges to enable reading of G01 and patch RAM data

Calls VL53L1_set_powerforce_register()

Parameters
[in]Dev: Device handle
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 828 of file vl53l1_core.c.

◆ VL53L1_encode_GPIO_interrupt_config()

uint8_t VL53L1_encode_GPIO_interrupt_config ( VL53L1_GPIO_interrupt_config_t pintconf)

Encodes VL53L1_GPIO_interrupt_config_t structure to FW register format.

Parameters
[in]pintconf: pointer to gpio interrupt config structure
Returns
The encoded system__interrupt_config_gpio byte

Definition at line 1706 of file vl53l1_core.c.

◆ VL53L1_encode_row_col()

void VL53L1_encode_row_col ( uint8_t  row,
uint8_t  col,
uint8_t pspad_number 
)

Encodes a (col,row) coord value into ByteIndex.BitIndex format.

Parameters
[in]row: Row
[in]col: Column
[out]pspad_number: Encoded Coord in Byte.Bit format

Encodes the input array(row,col) location as SPAD number.

Definition at line 1451 of file vl53l1_core.c.

◆ VL53L1_encode_timeout()

uint16_t VL53L1_encode_timeout ( uint32_t  timeout_mclks)

Encode timeout in (LSByte * 2^MSByte) + 1 register format.

Parameters
[in]timeout_mclks: uint32_t timeout value (macro periods)
Returns
encoded_timeout : 16-bit encoded value

Definition at line 1231 of file vl53l1_core.c.

◆ VL53L1_encode_unsigned_integer()

void VL53L1_encode_unsigned_integer ( uint32_t  ip_value,
uint8_t  no_of_bytes,
uint8_t pbuffer 
)

Encodes an unsigned integer into a uint8_t buffer MS byte first.

Parameters
[in]ip_value: input unsigned integer
[in]no_of_bytes: size of integer storage in bytes
[out]pbuffer: pointer to output buffer

Definition at line 1409 of file vl53l1_core.c.

◆ VL53L1_encode_vcsel_period()

uint8_t VL53L1_encode_vcsel_period ( uint8_t  vcsel_period_pclks)

Encodes the real period in PLL clocks into the register value.

Parameters
[in]vcsel_period_pclks: 8-bit value
Returns
vcsel_period_reg : 8-bit encoded value

Definition at line 1375 of file vl53l1_core.c.

◆ VL53L1_encode_zone_size()

void VL53L1_encode_zone_size ( uint8_t  width,
uint8_t  height,
uint8_t pencoded_xy_size 
)

Encodes a zone width & height into encoded size format.

Parameters
[in]width: Zone Width
[in]height: Zone height
[out]pencoded_xy_size: Encoded zone size

Definition at line 1489 of file vl53l1_core.c.

◆ VL53L1_get_spad_rate_data()

VL53L1_Error VL53L1_get_spad_rate_data ( VL53L1_DEV  Dev,
VL53L1_spad_rate_data_t pspad_rates 
)

Gets the 256 return array SSC rates from the Patch RAM.

Each SSC rate is 1.15 or 9.7 dependent on test run. Total of 512 bytes to read!

ssc_rate_mcps buffer format:

  • 1.15 for DCR/LCR test modes with VCSEL off (ambient)
  • 9.7 LCR test mode with VCSEL on (which rate?)

Assumes that power force has already been enabled

Function disables firmware at start to allow patch RAM to be read and then enables the firmware before returning

The order of the rates is in SPAD number order (increasing)

Parameters
[in]Dev: Device handle
[out]pspad_rates: pointer to VL53L1_spad_rate_data_t
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Gets the SSC rate map output

Definition at line 2039 of file vl53l1_core.c.

◆ VL53L1_i2c_decode_int16_t()

int16_t VL53L1_i2c_decode_int16_t ( uint16_t  count,
uint8_t pbuffer 
)

Decodes a int16_t register value from an I2C read buffer.

The I2C read buffer is assumed to be MS byte first i.e. matching the device register map

Parameters
[in]count: register size of in bytes (1, 2, 3 or 4)
[in]pbuffer: uint8_t pointer to the I2C read buffer
Returns
value : decoded int16_t value

Definition at line 580 of file vl53l1_core.c.

◆ VL53L1_i2c_decode_int32_t()

int32_t VL53L1_i2c_decode_int32_t ( uint16_t  count,
uint8_t pbuffer 
)

Decodes a int32_t register value from an I2C read buffer.

The I2C read buffer is assumed to be MS byte first i.e. matching the device register map

Parameters
[in]count: register size of in bytes (1, 2, 3 or 4)
[in]pbuffer: uint8_t pointer to the I2C read buffer
Returns
value : decoded int32_t value

Definition at line 696 of file vl53l1_core.c.

◆ VL53L1_i2c_decode_uint16_t()

uint16_t VL53L1_i2c_decode_uint16_t ( uint16_t  count,
uint8_t pbuffer 
)

Decodes a uint16_t register value from an I2C read buffer.

The I2C read buffer is assumed to be MS byte first i.e. matching the device register map

Parameters
[in]count: register size of in bytes (1, 2, 3 or 4)
[in]pbuffer: uint8_t pointer to the I2C read buffer
Returns
value : decoded uint16_t value

Definition at line 540 of file vl53l1_core.c.

◆ VL53L1_i2c_decode_uint32_t()

uint32_t VL53L1_i2c_decode_uint32_t ( uint16_t  count,
uint8_t pbuffer 
)

Decodes a uint32_t register value from an I2C read buffer.

The I2C read buffer is assumed to be MS byte first i.e. matching the device register map

Parameters
[in]count: register size of in bytes (1, 2, 3 or 4)
[in]pbuffer: uint8_t pointer to the I2C read buffer
Returns
value : decoded uint32_t value

Definition at line 624 of file vl53l1_core.c.

◆ VL53L1_i2c_decode_with_mask()

uint32_t VL53L1_i2c_decode_with_mask ( uint16_t  count,
uint8_t pbuffer,
uint32_t  bit_mask,
uint32_t  down_shift,
uint32_t  offset 
)

Decodes an integer register value from an I2C read buffer.

The I2C read buffer is assumed to be MS byte first i.e. matching the device register map

Parameters
[in]count: integer size of in bytes (1, 2, 3 or 4)
[in]pbuffer: uint8_t pointer to the I2C read buffer
[in]bit_mask: bit mask to apply
[in]down_shift: down shift to apply
[in]offset: offset to apply after the down shift
Returns
value : decoded integer value

Definition at line 643 of file vl53l1_core.c.

◆ VL53L1_i2c_encode_int16_t()

void VL53L1_i2c_encode_int16_t ( int16_t  ip_value,
uint16_t  count,
uint8_t pbuffer 
)

Encodes a int16_t register value into an I2C write buffer.

The register is encoded MS byte first is the buffer i.e as per the device register map

Parameters
[in]ip_value: input int16_t value
[in]count: register size of in bytes (1, 2, 3 or 4)
[out]pbuffer: uint8_t pointer to the I2C write buffer

Definition at line 559 of file vl53l1_core.c.

◆ VL53L1_i2c_encode_int32_t()

void VL53L1_i2c_encode_int32_t ( int32_t  ip_value,
uint16_t  count,
uint8_t pbuffer 
)

Encodes a int32_t register value into an I2C write buffer.

The register is encoded MS byte first is the buffer i.e as per the device register map

Parameters
[in]ip_value: input int32_t value
[in]count: register size of in bytes (1, 2, 3 or 4)
[out]pbuffer: uint8_t pointer to the I2C write buffer

Definition at line 675 of file vl53l1_core.c.

◆ VL53L1_i2c_encode_uint16_t()

void VL53L1_i2c_encode_uint16_t ( uint16_t  ip_value,
uint16_t  count,
uint8_t pbuffer 
)

Encodes a uint16_t register value into an I2C write buffer.

The register is encoded MS byte first is the buffer i.e as per the device register map

Parameters
[in]ip_value: input uint16_t value
[in]count: register size of in bytes (1, 2, 3 or 4)
[out]pbuffer: uint8_t pointer to the I2C write buffer

Definition at line 519 of file vl53l1_core.c.

◆ VL53L1_i2c_encode_uint32_t()

void VL53L1_i2c_encode_uint32_t ( uint32_t  ip_value,
uint16_t  count,
uint8_t pbuffer 
)

Encodes a uint32_t register value into an I2C write buffer.

The register is encoded MS byte first is the buffer i.e as per the device register map

Parameters
[in]ip_value: input uint32_t value
[in]count: register size of in bytes (1, 2, 3 or 4)
[out]pbuffer: uint8_t pointer to the I2C write buffer

Definition at line 603 of file vl53l1_core.c.

◆ VL53L1_init_ll_driver_state()

void VL53L1_init_ll_driver_state ( VL53L1_DEV  Dev,
VL53L1_DeviceState  ll_state 
)

Initialise LL Driver State.

Parameters
[out]Dev: Device handle
[in]ll_state: Device state

Initialise LL Driver state variables

Definition at line 114 of file vl53l1_core.c.

◆ VL53L1_init_system_results()

void VL53L1_init_system_results ( VL53L1_system_results_t pdata)

Initialise system results structure to all ones.

This mimics what the device firmware does the the results registers at the start of each range

Parameters
[out]pdata: pointer to VL53L1_system_results_t

Definition at line 480 of file vl53l1_core.c.

◆ VL53L1_init_version()

void VL53L1_init_version ( VL53L1_DEV  Dev)

Initialise version info in pdev.

Parameters
[out]Dev: Device handle

Initialise version structure

Definition at line 98 of file vl53l1_core.c.

◆ VL53L1_is_aperture_location()

uint8_t VL53L1_is_aperture_location ( uint8_t  row,
uint8_t  col 
)

Returns > 0 if input (row,col) location is an apertured SPAD.

Parameters
[in]row: Row
[in]col: Column
Returns
is_aperture : if > 0 the location is an apertured SPAD

Definition at line 1561 of file vl53l1_core.c.

◆ VL53L1_low_power_auto_data_init()

VL53L1_Error VL53L1_low_power_auto_data_init ( VL53L1_DEV  Dev)

Initialize the Low Power Auto data structure.

Patch_LowPowerAutoMode

Parameters
[in]Dev: Device Handle
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 2101 of file vl53l1_core.c.

◆ VL53L1_low_power_auto_data_stop_range()

VL53L1_Error VL53L1_low_power_auto_data_stop_range ( VL53L1_DEV  Dev)

Reset internal state but leave low_power_auto mode intact.

Patch_LowPowerAutoMode

Parameters
[in]Dev: Device Handle
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 2133 of file vl53l1_core.c.

◆ VL53L1_low_power_auto_setup_manual_calibration()

VL53L1_Error VL53L1_low_power_auto_setup_manual_calibration ( VL53L1_DEV  Dev)

Setup ranges after the first one in low power auto mode by turning off FW calibration steps and programming static values.

Patch_LowPowerAutoMode

Parameters
[out]Dev: Device handle
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 2216 of file vl53l1_core.c.

◆ VL53L1_low_power_auto_update_DSS()

VL53L1_Error VL53L1_low_power_auto_update_DSS ( VL53L1_DEV  Dev)

Do a DSS calculation and update manual config.

Patch_LowPowerAutoMode

Parameters
[out]Dev: Device handle
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 2256 of file vl53l1_core.c.

◆ VL53L1_set_firmware_enable_register()

VL53L1_Error VL53L1_set_firmware_enable_register ( VL53L1_DEV  Dev,
uint8_t  value 
)

Set firmware enable register.

Wrapper for setting power force register state Also updates pdev->sys_ctrl.firmware__enable

Parameters
[in]Dev: Device handle
[in]value: register value
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 747 of file vl53l1_core.c.

◆ VL53L1_set_GPIO_distance_threshold()

VL53L1_Error VL53L1_set_GPIO_distance_threshold ( VL53L1_DEV  Dev,
uint16_t  threshold_high,
uint16_t  threshold_low 
)

SET GPIO distance threshold.

Parameters
[in]Dev: Device Handle
[in]threshold_high: High distance threshold in mm
[in]threshold_low: Low distance threshold in mm

Definition at line 1748 of file vl53l1_core.c.

◆ VL53L1_set_GPIO_rate_threshold()

VL53L1_Error VL53L1_set_GPIO_rate_threshold ( VL53L1_DEV  Dev,
uint16_t  threshold_high,
uint16_t  threshold_low 
)

SET GPIO rate threshold.

Parameters
[in]Dev: Device Handle
[in]threshold_high: High rate threshold in 9.7 Mcps
[in]threshold_low: Low rate threshold in 9.7 Mcps

Definition at line 1770 of file vl53l1_core.c.

◆ VL53L1_set_GPIO_thresholds_from_struct()

VL53L1_Error VL53L1_set_GPIO_thresholds_from_struct ( VL53L1_DEV  Dev,
VL53L1_GPIO_interrupt_config_t pintconf 
)

SET GPIO thresholds from structure. Sets both rate and distance thresholds.

Parameters
[in]Dev: Device Handle
[in]pintconf: Pointer to structure

Definition at line 1792 of file vl53l1_core.c.

◆ VL53L1_set_powerforce_register()

VL53L1_Error VL53L1_set_powerforce_register ( VL53L1_DEV  Dev,
uint8_t  value 
)

Set power force register.

Wrapper for setting power force register state Also updates pdev->sys_ctrl.power_management__go1_power_force

Parameters
[in]Dev: Device handle
[in]value: register value
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 806 of file vl53l1_core.c.

◆ VL53L1_set_ref_spad_char_config()

VL53L1_Error VL53L1_set_ref_spad_char_config ( VL53L1_DEV  Dev,
uint8_t  vcsel_period_a,
uint32_t  phasecal_timeout_us,
uint16_t  total_rate_target_mcps,
uint16_t  max_count_rate_rtn_limit_mcps,
uint16_t  min_count_rate_rtn_limit_mcps,
uint16_t  fast_osc_frequency 
)

Set Ref SPAD Characterisation Config.

Initialises the timeout and VCSEL period for the Reference SPAD Characterisation test mode.

Register Mapping:

  • timeout -> VL53L1_PHASECAL_CONFIG__TIMEOUT_MACROP
  • vcsel_period -> VL53L1_RANGE_CONFIG__VCSEL_PERIOD_A
    -> VL53L1_SD_CONFIG__WOI_SD0
    -> VL53L1_SD_CONFIG__WOI_SD1
  • total_rate_target_mcps -> VL53L1_REF_SPAD_CHAR__TOTAL_RATE_TARGET_MCPS
  • max_count_rate_rtn_limit_mcps -> VL53L1_RANGE_CONFIG__SIGMA_THRESH
  • min_count_rate_rtn_limit_mcps -> VL53L1_SRANGE_CONFIG__SIGMA_THRESH
Parameters
[in]Dev: Device handle
[in]vcsel_period_a: VCSEL period A register value
[in]phasecal_timeout_us: requested PhaseCal Timeout in [us] e.g 1000us
[in]total_rate_target_mcps: Target reference rate [Mcps] 9.7 format
[in]max_count_rate_rtn_limit_mcps: Max rate final check limit [Mcps] 9.7 format
[in]min_count_rate_rtn_limit_mcps: Min rate final check limit [Mcps] 9.7 format
[in]fast_osc_frequency: Fast Osc Frequency (4.12) format
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 1819 of file vl53l1_core.c.

◆ VL53L1_set_ssc_config()

VL53L1_Error VL53L1_set_ssc_config ( VL53L1_DEV  Dev,
VL53L1_ssc_config_t pssc_cfg,
uint16_t  fast_osc_frequency 
)

Applies SSC (SPAD Self Check) configuration to device.

Prior to calling this function it is assumed both the Fast Osc and VCSEL have already been trimmed and the register values set.

Internally the required timeout in macro periods is calculated from the input VCSEL period, fast_osc_frequency and requested timeout in microseconds.

Register Mapping:

  • rate_select -> VL53L1_NVM_BIST__CTRL
  • timeout -> VL53L1_RANGE_CONFIG__TIMEOUT_MACROP_ B_HI & _LO
  • vcsel_period -> VL53L1_RANGE_CONFIG__VCSEL_PERIOD_B
    -> VL53L1_SD_CONFIG__WOI_SD0
    -> VL53L1_SD_CONFIG__WOI_SD1
  • vcsel_start -> VL53L1_CAL_CONFIG__VCSEL_START
  • vcsel_width -> VL53L1_GLOBAL_CONFIG__VCSEL_WIDTH
  • ssc_limit_mcps -> VL53L1_RANGE_CONFIG__SIGMA_THRESH

ssc_rate_limit_mcps format:

  • 1.15 for DCR/LCR test modes with VCSEL off
  • 9.7 LCR test mode with VCSEL on

The configuration is set to the device via a 5-byte multi byte write.

Parameters
[in]Dev: Device handle
[in]pssc_cfg: pointer to VL53L1_ssc_config_t
[in]fast_osc_frequency: Fast Osc Frequency (4.12) format
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Builds and sends a single I2C multiple byte transaction to initialize the device for SSC.

The function also sets the WOI registers based on the input vcsel period register value.

Definition at line 1935 of file vl53l1_core.c.

◆ VL53L1_spad_number_to_byte_bit_index()

void VL53L1_spad_number_to_byte_bit_index ( uint8_t  spad_number,
uint8_t pbyte_index,
uint8_t pbit_index,
uint8_t pbit_mask 
)

Get the SPAD number, byte index (0-31) and bit index (0-7) for.

Takes the map index (0 - 255) and calculated the SPAD number, byte index within the SPAD enable byte array and but position within the SPAD enable byte

Parameters
[in]spad_number: spad number
[out]pbyte_index: pointer to output 0-31 byte index for SPAD enables
[out]pbit_index: pointer to output 0-7 bit index
[out]pbit_mask: pointer to output bit mask for the byte

Converts the input SPAD number into the SPAD Enable byte index, bit index and bit mask

byte_index = (spad_no >> 3) bit_index = spad_no & 0x07 bit_mask = 0x01 << bit_index

Definition at line 1429 of file vl53l1_core.c.

◆ VL53L1_start_test()

VL53L1_Error VL53L1_start_test ( VL53L1_DEV  Dev,
uint8_t  test_mode__ctrl 
)

Triggers the start of the provided test_mode.

Parameters
[in]Dev: Device handle
[in]test_mode__ctrl: VL53L1_TEST_MODE__CTRL register value
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

Definition at line 721 of file vl53l1_core.c.

◆ VL53L1_update_ll_driver_cfg_state()

VL53L1_Error VL53L1_update_ll_driver_cfg_state ( VL53L1_DEV  Dev)

Update LL Driver Configuration State.

Parameters
[out]Dev: Device handle
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

State machine for configuration device state

Definition at line 349 of file vl53l1_core.c.

◆ VL53L1_update_ll_driver_rd_state()

VL53L1_Error VL53L1_update_ll_driver_rd_state ( VL53L1_DEV  Dev)

Update LL Driver Read State.

Parameters
[out]Dev: Device handle
Returns
VL53L1_ERROR_NONE Success
"Other error code" See VL53L1_Error

State machine for read device state

VL53L1_DEVICESTATE_SW_STANDBY VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC VL53L1_DEVICESTATE_RANGING_GATHER_DATA VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA

Definition at line 138 of file vl53l1_core.c.

_LOG_FUNCTION_END_FMT
#define _LOG_FUNCTION_END_FMT(module, status, fmt,...)
Definition: vl53l1_platform_log.h:250
_LOG_TRACE_PRINT
#define _LOG_TRACE_PRINT(module, level, function,...)
Definition: vl53l1_platform_log.h:247


vl53l1x
Author(s):
autogenerated on Fri Aug 2 2024 08:35:54