From f90880f2f85d9e9451f78f28cbc47a0adff3bf22 Mon Sep 17 00:00:00 2001
From: guocx4
Date: Tue, 10 Apr 2018 17:22:05 +0800
Subject: [PATCH] Add stm laser modules
1. Add vl53L0
2. Add vl53L1
Change-Id: Ib98cbddb95f1ec2ba2aaee79e215d0a5e0b7ffb4
Signed-off-by: guocx4
Reviewed-on: https://gerrit.mot.com/1160804
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Haichao Li
Reviewed-by: Dawei Wang
Reviewed-by: Zilong Zhang
Reviewed-by: Zhenxin Xi
Submit-Approved: Jira Key
---
drivers/input/misc/vl53L0/Android.mk | 8 +
drivers/input/misc/vl53L0/Kbuild | 26 +
drivers/input/misc/vl53L0/Makefile | 10 +
drivers/input/misc/vl53L0/inc/vl53l010_api.h | 1423 ++
.../input/misc/vl53L0/inc/vl53l010_device.h | 231 +
.../input/misc/vl53L0/inc/vl53l010_strings.h | 134 +
.../input/misc/vl53L0/inc/vl53l010_tuning.h | 58 +
drivers/input/misc/vl53L0/inc/vl53l0_api.h | 1930 +++
.../misc/vl53L0/inc/vl53l0_api_calibration.h | 85 +
.../input/misc/vl53L0/inc/vl53l0_api_core.h | 108 +
.../misc/vl53L0/inc/vl53l0_api_histogram.h | 70 +
.../misc/vl53L0/inc/vl53l0_api_ranging.h | 47 +
.../misc/vl53L0/inc/vl53l0_api_strings.h | 271 +
drivers/input/misc/vl53L0/inc/vl53l0_def.h | 637 +
drivers/input/misc/vl53L0/inc/vl53l0_device.h | 255 +
.../misc/vl53L0/inc/vl53l0_i2c_platform.h | 402 +
.../input/misc/vl53L0/inc/vl53l0_platform.h | 228 +
.../misc/vl53L0/inc/vl53l0_platform_log.h | 125 +
.../input/misc/vl53L0/inc/vl53l0_strings.h | 211 +
drivers/input/misc/vl53L0/inc/vl53l0_tuning.h | 145 +
drivers/input/misc/vl53L0/inc/vl53l0_types.h | 68 +
drivers/input/misc/vl53L0/src/vl53l010_api.c | 4127 +++++
.../input/misc/vl53L0/src/vl53l010_tuning.c | 138 +
drivers/input/misc/vl53L0/src/vl53l0_api.c | 2845 ++++
.../misc/vl53L0/src/vl53l0_api_calibration.c | 1275 ++
.../input/misc/vl53L0/src/vl53l0_api_core.c | 2234 +++
.../misc/vl53L0/src/vl53l0_api_histogram.c | 746 +
.../misc/vl53L0/src/vl53l0_api_ranging.c | 42 +
.../misc/vl53L0/src/vl53l0_api_strings.c | 448 +
.../misc/vl53L0/src/vl53l0_i2c_platform.c | 379 +
.../input/misc/vl53L0/src/vl53l0_platform.c | 242 +
.../input/misc/vl53L0/src/vl53l0_port_i2c.c | 150 +
drivers/input/misc/vl53L0/src/vl53l0_tuning.c | 137 +
drivers/input/misc/vl53L0/stmvl53l0-cci.h | 65 +
drivers/input/misc/vl53L0/stmvl53l0-i2c.h | 47 +
drivers/input/misc/vl53L0/stmvl53l0.h | 201 +
.../input/misc/vl53L0/stmvl53l0_module-cci.c | 475 +
.../input/misc/vl53L0/stmvl53l0_module-i2c.c | 422 +
drivers/input/misc/vl53L0/stmvl53l0_module.c | 2804 ++++
drivers/input/misc/vl53L1/Android.mk | 8 +
drivers/input/misc/vl53L1/Kbuild | 26 +
drivers/input/misc/vl53L1/Makefile | 10 +
drivers/input/misc/vl53L1/inc/vl53l1_api.h | 1264 ++
.../misc/vl53L1/inc/vl53l1_api_calibration.h | 569 +
.../input/misc/vl53L1/inc/vl53l1_api_core.h | 1579 ++
.../input/misc/vl53L1/inc/vl53l1_api_debug.h | 649 +
.../misc/vl53L1/inc/vl53l1_api_preset_modes.h | 1191 ++
.../misc/vl53L1/inc/vl53l1_api_strings.h | 210 +
drivers/input/misc/vl53L1/inc/vl53l1_core.h | 1513 ++
.../misc/vl53L1/inc/vl53l1_core_support.h | 410 +
drivers/input/misc/vl53L1/inc/vl53l1_def.h | 704 +
.../misc/vl53L1/inc/vl53l1_dmax_structs.h | 205 +
.../misc/vl53L1/inc/vl53l1_error_codes.h | 323 +
.../misc/vl53L1/inc/vl53l1_error_exceptions.h | 125 +
.../misc/vl53L1/inc/vl53l1_error_strings.h | 243 +
.../input/misc/vl53L1/inc/vl53l1_fpga_core.h | 134 +
.../input/misc/vl53L1/inc/vl53l1_hist_char.h | 175 +
.../input/misc/vl53L1/inc/vl53l1_hist_map.h | 154 +
.../misc/vl53L1/inc/vl53l1_hist_structs.h | 477 +
drivers/input/misc/vl53L1/inc/vl53l1_ll_def.h | 1625 ++
.../input/misc/vl53L1/inc/vl53l1_ll_device.h | 843 +
drivers/input/misc/vl53L1/inc/vl53l1_nvm.h | 422 +
.../input/misc/vl53L1/inc/vl53l1_nvm_debug.h | 201 +
.../input/misc/vl53L1/inc/vl53l1_nvm_map.h | 3246 ++++
.../misc/vl53L1/inc/vl53l1_nvm_structs.h | 804 +
.../misc/vl53L1/inc/vl53l1_register_funcs.h | 1693 ++
.../misc/vl53L1/inc/vl53l1_register_map.h | 13113 ++++++++++++++++
.../vl53L1/inc/vl53l1_register_settings.h | 273 +
.../misc/vl53L1/inc/vl53l1_register_structs.h | 4848 ++++++
.../misc/vl53L1/inc/vl53l1_silicon_core.h | 133 +
drivers/input/misc/vl53L1/inc/vl53l1_wait.h | 318 +
.../misc/vl53L1/inc/vl53l1_zone_presets.h | 182 +
drivers/input/misc/vl53L1/ipp/ipp_linux.c | 343 +
drivers/input/misc/vl53L1/src/vl53l1_api.c | 2809 ++++
.../misc/vl53L1/src/vl53l1_api_calibration.c | 2617 +++
.../input/misc/vl53L1/src/vl53l1_api_core.c | 4790 ++++++
.../input/misc/vl53L1/src/vl53l1_api_debug.c | 3184 ++++
.../misc/vl53L1/src/vl53l1_api_preset_modes.c | 4086 +++++
.../misc/vl53L1/src/vl53l1_api_strings.c | 333 +
drivers/input/misc/vl53L1/src/vl53l1_core.c | 3961 +++++
.../misc/vl53L1/src/vl53l1_core_support.c | 931 ++
.../misc/vl53L1/src/vl53l1_error_strings.c | 327 +
.../input/misc/vl53L1/src/vl53l1_fpga_core.c | 167 +
.../input/misc/vl53L1/src/vl53l1_hist_char.c | 282 +
drivers/input/misc/vl53L1/src/vl53l1_nvm.c | 1639 ++
.../input/misc/vl53L1/src/vl53l1_nvm_debug.c | 1103 ++
.../misc/vl53L1/src/vl53l1_register_funcs.c | 4594 ++++++
.../misc/vl53L1/src/vl53l1_silicon_core.c | 180 +
drivers/input/misc/vl53L1/src/vl53l1_wait.c | 627 +
.../misc/vl53L1/src/vl53l1_zone_presets.c | 253 +
drivers/input/misc/vl53L1/stmvl53l1-i2c.h | 109 +
drivers/input/misc/vl53L1/stmvl53l1.h | 379 +
drivers/input/misc/vl53L1/stmvl53l1_i2c.c | 366 +
drivers/input/misc/vl53L1/stmvl53l1_if.h | 564 +
.../input/misc/vl53L1/stmvl53l1_internal_if.h | 75 +
drivers/input/misc/vl53L1/stmvl53l1_ipp.h | 386 +
drivers/input/misc/vl53L1/stmvl53l1_ipp_nl.c | 378 +
drivers/input/misc/vl53L1/stmvl53l1_log.c | 78 +
.../input/misc/vl53L1/stmvl53l1_module-i2c.c | 890 ++
drivers/input/misc/vl53L1/stmvl53l1_module.c | 3636 +++++
drivers/input/misc/vl53L1/vl53l1_platform.h | 447 +
.../input/misc/vl53L1/vl53l1_platform_ipp.h | 188 +
.../misc/vl53L1/vl53l1_platform_ipp_imports.h | 36 +
.../input/misc/vl53L1/vl53l1_platform_log.h | 176 +
.../misc/vl53L1/vl53l1_platform_user_config.h | 100 +
.../misc/vl53L1/vl53l1_platform_user_data.h | 62 +
.../vl53L1/vl53l1_platform_user_defines.h | 92 +
drivers/input/misc/vl53L1/vl53l1_types.h | 46 +
108 files changed, 101153 insertions(+)
create mode 100644 drivers/input/misc/vl53L0/Android.mk
create mode 100644 drivers/input/misc/vl53L0/Kbuild
create mode 100644 drivers/input/misc/vl53L0/Makefile
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l010_api.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l010_device.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l010_strings.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l010_tuning.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l0_api.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l0_api_calibration.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l0_api_core.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l0_api_histogram.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l0_api_ranging.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l0_api_strings.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l0_def.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l0_device.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l0_i2c_platform.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l0_platform.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l0_platform_log.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l0_strings.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l0_tuning.h
create mode 100644 drivers/input/misc/vl53L0/inc/vl53l0_types.h
create mode 100644 drivers/input/misc/vl53L0/src/vl53l010_api.c
create mode 100644 drivers/input/misc/vl53L0/src/vl53l010_tuning.c
create mode 100644 drivers/input/misc/vl53L0/src/vl53l0_api.c
create mode 100644 drivers/input/misc/vl53L0/src/vl53l0_api_calibration.c
create mode 100644 drivers/input/misc/vl53L0/src/vl53l0_api_core.c
create mode 100644 drivers/input/misc/vl53L0/src/vl53l0_api_histogram.c
create mode 100644 drivers/input/misc/vl53L0/src/vl53l0_api_ranging.c
create mode 100644 drivers/input/misc/vl53L0/src/vl53l0_api_strings.c
create mode 100644 drivers/input/misc/vl53L0/src/vl53l0_i2c_platform.c
create mode 100644 drivers/input/misc/vl53L0/src/vl53l0_platform.c
create mode 100644 drivers/input/misc/vl53L0/src/vl53l0_port_i2c.c
create mode 100644 drivers/input/misc/vl53L0/src/vl53l0_tuning.c
create mode 100644 drivers/input/misc/vl53L0/stmvl53l0-cci.h
create mode 100644 drivers/input/misc/vl53L0/stmvl53l0-i2c.h
create mode 100644 drivers/input/misc/vl53L0/stmvl53l0.h
create mode 100644 drivers/input/misc/vl53L0/stmvl53l0_module-cci.c
create mode 100644 drivers/input/misc/vl53L0/stmvl53l0_module-i2c.c
create mode 100644 drivers/input/misc/vl53L0/stmvl53l0_module.c
create mode 100644 drivers/input/misc/vl53L1/Android.mk
create mode 100644 drivers/input/misc/vl53L1/Kbuild
create mode 100644 drivers/input/misc/vl53L1/Makefile
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_api.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_api_calibration.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_api_core.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_api_debug.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_api_preset_modes.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_api_strings.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_core.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_core_support.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_def.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_dmax_structs.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_error_codes.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_error_exceptions.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_error_strings.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_fpga_core.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_hist_char.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_hist_map.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_hist_structs.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_ll_def.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_ll_device.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_nvm.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_nvm_debug.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_nvm_map.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_nvm_structs.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_register_funcs.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_register_map.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_register_settings.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_register_structs.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_silicon_core.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_wait.h
create mode 100644 drivers/input/misc/vl53L1/inc/vl53l1_zone_presets.h
create mode 100644 drivers/input/misc/vl53L1/ipp/ipp_linux.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_api.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_api_calibration.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_api_core.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_api_debug.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_api_preset_modes.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_api_strings.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_core.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_core_support.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_error_strings.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_fpga_core.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_hist_char.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_nvm.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_nvm_debug.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_register_funcs.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_silicon_core.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_wait.c
create mode 100644 drivers/input/misc/vl53L1/src/vl53l1_zone_presets.c
create mode 100644 drivers/input/misc/vl53L1/stmvl53l1-i2c.h
create mode 100644 drivers/input/misc/vl53L1/stmvl53l1.h
create mode 100644 drivers/input/misc/vl53L1/stmvl53l1_i2c.c
create mode 100644 drivers/input/misc/vl53L1/stmvl53l1_if.h
create mode 100644 drivers/input/misc/vl53L1/stmvl53l1_internal_if.h
create mode 100644 drivers/input/misc/vl53L1/stmvl53l1_ipp.h
create mode 100644 drivers/input/misc/vl53L1/stmvl53l1_ipp_nl.c
create mode 100644 drivers/input/misc/vl53L1/stmvl53l1_log.c
create mode 100644 drivers/input/misc/vl53L1/stmvl53l1_module-i2c.c
create mode 100644 drivers/input/misc/vl53L1/stmvl53l1_module.c
create mode 100644 drivers/input/misc/vl53L1/vl53l1_platform.h
create mode 100644 drivers/input/misc/vl53L1/vl53l1_platform_ipp.h
create mode 100644 drivers/input/misc/vl53L1/vl53l1_platform_ipp_imports.h
create mode 100644 drivers/input/misc/vl53L1/vl53l1_platform_log.h
create mode 100644 drivers/input/misc/vl53L1/vl53l1_platform_user_config.h
create mode 100644 drivers/input/misc/vl53L1/vl53l1_platform_user_data.h
create mode 100644 drivers/input/misc/vl53L1/vl53l1_platform_user_defines.h
create mode 100644 drivers/input/misc/vl53L1/vl53l1_types.h
diff --git a/drivers/input/misc/vl53L0/Android.mk b/drivers/input/misc/vl53L0/Android.mk
new file mode 100644
index 000000000000..fb4f59171eae
--- /dev/null
+++ b/drivers/input/misc/vl53L0/Android.mk
@@ -0,0 +1,8 @@
+DLKM_DIR := motorola/kernel/modules
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := stmvl53l0.ko
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_PATH := $(KERNEL_MODULES_OUT)
+include $(DLKM_DIR)/AndroidKernelModule.mk
diff --git a/drivers/input/misc/vl53L0/Kbuild b/drivers/input/misc/vl53L0/Kbuild
new file mode 100644
index 000000000000..a1272a5c661f
--- /dev/null
+++ b/drivers/input/misc/vl53L0/Kbuild
@@ -0,0 +1,26 @@
+#
+# Makefile for the vl53L0 drivers.
+#
+
+# Each configuration option enables a list of files.
+FEATURE_USE_CCI := true
+
+ifeq ($(FEATURE_USE_CCI), true)
+ccflags-y += -Idrivers/input/misc/vl53L0/inc -DCAMERA_CCI
+else
+ccflags-y += -Idrivers/input/misc/vl53L0/inc -DSTM_TEST
+endif
+
+ccflags-$(CONFIG_MSMB_CAMERA) += -Idrivers/media/platform/msm/camera_v2/sensor/io
+ccflags-$(CONFIG_MSMB_CAMERA) += -Idrivers/media/platform/msm/camera_v2
+ccflags-$(CONFIG_MSMB_CAMERA) += -Idrivers/media/platform/msm/camera_v2/sensor/cci
+ccflags-$(CONFIG_MSMB_CAMERA) += -Idrivers/media/platform/msm/camera_v2/common
+
+ccflags-$(CONFIG_MSMB_CAMERA_2016) += -Idrivers/media/platform/msm/camera_v2_2016/sensor/io
+ccflags-$(CONFIG_MSMB_CAMERA_2016) += -Idrivers/media/platform/msm/camera_v2_2016
+ccflags-$(CONFIG_MSMB_CAMERA_2016) += -Idrivers/media/platform/msm/camera_v2_2016/sensor/cci
+ccflags-$(CONFIG_MSMB_CAMERA_2016) += -Idrivers/media/platform/msm/camera_v2_2016/common
+
+obj-m += stmvl53l0.o
+stmvl53l0-objs := stmvl53l0_module.o stmvl53l0_module-i2c.o stmvl53l0_module-cci.o src/vl53l0_api_calibration.o src/vl53l0_api_core.o src/vl53l0_api_histogram.o src/vl53l0_api_ranging.o src/vl53l0_api_strings.o src/vl53l0_api.o src/vl53l0_platform.o src/vl53l0_i2c_platform.o src/vl53l0_port_i2c.o src/vl53l010_api.o src/vl53l010_tuning.o
+
diff --git a/drivers/input/misc/vl53L0/Makefile b/drivers/input/misc/vl53L0/Makefile
new file mode 100644
index 000000000000..4191dea22679
--- /dev/null
+++ b/drivers/input/misc/vl53L0/Makefile
@@ -0,0 +1,10 @@
+KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build
+
+all:
+ $(MAKE) -C $(KERNEL_SRC) M=$(shell pwd) modules $(KBUILD_OPTIONS)
+
+modules_install:
+ $(MAKE) INSTALL_MOD_STRIP=1 -C $(KERNEL_SRC) M=$(shell pwd) modules_install
+
+clean:
+ $(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean
diff --git a/drivers/input/misc/vl53L0/inc/vl53l010_api.h b/drivers/input/misc/vl53L0/inc/vl53l010_api.h
new file mode 100644
index 000000000000..6054e4eff719
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l010_api.h
@@ -0,0 +1,1423 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+/*
+ * @file vl53l0_api.h
+ * $Date: 2014-12-04 16:15:06 +0100 (Thu, 04 Dec 2014) $
+ * $Revision: 1906 $
+ */
+
+
+
+#ifndef _VL53L010_API_H_
+#define _VL53L010_API_H_
+
+#include "vl53l010_device.h"
+#include "vl53l010_strings.h"
+#include "vl53l0_def.h"
+#include "vl53l0_platform.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#ifdef _MSC_VER
+# ifdef VL53L0_API_EXPORTS
+# define VL53L010_API __declspec(dllexport)
+# else
+# define VL53L010_API
+# endif
+#else
+# define VL53L010_API
+#endif
+
+
+/** @defgroup VL53L010_cut10_group VL53L010 cut1.0 Function Definition
+ * @brief VL53L010 cut1.0 Function Definition
+ * @{
+ */
+
+/** @defgroup VL53L010_general_group VL53L010 General Functions
+ * @brief VL53L010 General functions and definitions
+ * @{
+ */
+
+/**
+ * @brief Return the VL53L0 PAL Implementation Version
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param pVersion Pointer to current PAL Implementation Version
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetVersion(VL53L0_Version_t *pVersion);
+
+/**
+ * @brief Return the PAL Specification Version used for the current
+ * implementation.
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param pPalSpecVersion Pointer to current PAL Specification Version
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetPalSpecVersion(
+ VL53L0_Version_t *pPalSpecVersion);
+
+
+/**
+ * @brief Reads the Device information for given Device
+ *
+ * @note This function Access to the device.\n
+ * Use ProductRevisionMajor and ProductRevisionMinor to know the cut
+ * of the device used.
+ *
+ * @param Dev Device Handle
+ * @param pVL53L0_DeviceInfo Pointer to current device info for a given
+ * Device
+ *
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetDeviceInfo(VL53L0_DEV Dev,
+ VL53L0_DeviceInfo_t *pVL53L0_DeviceInfo);
+
+
+/**
+ * @brief Read current status of the error register for the selected device
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pDeviceErrorStatus Pointer to current error code of the device
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetDeviceErrorStatus(VL53L0_DEV Dev,
+ VL53L010_DeviceError *pDeviceErrorStatus);
+
+/**
+ * @brief Human readable error string for a given Error Code
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param ErrorCode The error code as stored on
+ * ::VL53L0_DeviceError
+ * @param pDeviceErrorString The error string corresponding to the
+ * ErrorCode
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetDeviceErrorString(
+ VL53L010_DeviceError ErrorCode, char *pDeviceErrorString);
+
+
+/**
+ * @brief Human readable error string for current PAL error status
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param PalErrorCode The error code as stored on @a VL53L0_Error
+ * @param pPalErrorString The error string corresponding to the
+ * PalErrorCode
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetPalErrorString(VL53L0_Error PalErrorCode,
+ char *pPalErrorString);
+
+
+/**
+ * @brief Reads the internal state of the PAL for a given Device
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param Dev Device Handle
+ * @param pPalState Pointer to current state of the PAL for a
+ * given Device
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetPalState(VL53L0_DEV Dev,
+ VL53L0_State *pPalState);
+
+
+/**
+ * @brief Set the power mode for a given Device
+ * The power mode can be Standby or Idle. Different level of both Standby and
+ * Idle can exists.
+ * This function should not be used when device is in Ranging state.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param PowerMode The value of the power mode to set.
+ * see ::VL53L0_PowerModes Valid values are:
+ * VL53L0_POWERMODE_STANDBY_LEVEL1, VL53L0_POWERMODE_IDLE_LEVEL1
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_MODE_NOT_SUPPORTED This error occurs when PowerMode
+ * is not in the supported list
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetPowerMode(VL53L0_DEV Dev,
+ VL53L0_PowerModes PowerMode);
+
+/**
+ * @brief Get the power mode for a given Device
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pPowerMode Pointer to the current value of the power
+ * mode. see ::VL53L0_PowerModes. Valid values are:
+ * VL53L0_POWERMODE_STANDBY_LEVEL1, VL53L0_POWERMODE_IDLE_LEVEL1
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetPowerMode(VL53L0_DEV Dev,
+ VL53L0_PowerModes *pPowerMode);
+
+
+/**
+ * Set or over-hide part to part calibration offset
+ * \sa VL53L0_DataInit() VL53L0_GetOffsetCalibrationDataMicroMeter()
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param OffsetCalibrationDataMicroMeter Offset (in micrometer)
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetOffsetCalibrationDataMicroMeter(
+ VL53L0_DEV Dev,
+ int32_t OffsetCalibrationDataMicroMeter);
+
+/**
+ * @brief Get part to part calibration offset
+ *
+ * @par Function Description
+ * Should only be used after a successful call to @a VL53L0_DataInit to backup
+ * device NVM value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pOffsetCalibrationDataMicroMeter Return part to part calibration
+ * offset from device (in micro meter)
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetOffsetCalibrationDataMicroMeter(
+ VL53L0_DEV Dev,
+ int32_t *pOffsetCalibrationDataMicroMeter);
+
+/**
+ * Set Group parameter Hold state
+ *
+ * @par Function Description
+ * Set or remove device internal group parameter hold
+ *
+ * @note This function is not Implemented
+ *
+ * @param Dev Device Handle
+ * @param GroupParamHold Group parameter Hold state to be set (on/off)
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+VL53L010_API VL53L0_Error VL53L010_SetGroupParamHold(VL53L0_DEV Dev,
+ uint8_t GroupParamHold);
+
+/**
+ * @brief Get the maximal distance for actual setup
+ * @par Function Description
+ * Device must be initialized through @a VL53L0_SetParameters() prior calling
+ * this function.
+ *
+ * Any range value more than the value returned is to be considered as "no
+ * target detected"
+ * or "no target in detectable range"\n
+ * @warning The maximal distance depends on the setup
+ *
+ * @note This function is not Implemented
+ *
+ * @param Dev Device Handle
+ * @param pUpperLimitMilliMeter The maximal range limit for actual setup
+ * (in millimeter)
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+VL53L010_API VL53L0_Error VL53L010_GetUpperLimitMilliMeter(VL53L0_DEV Dev,
+ uint16_t *pUpperLimitMilliMeter);
+
+/** @} VL53L010_general_group */
+
+
+/** @defgroup VL53L010_init_group VL53L010 Init Functions
+ * @brief VL53L010 Init Functions
+ * @{
+ */
+
+/**
+ * @brief Set new device address
+ *
+ * After completion the device will answer to the new address programmed. This
+ * function should be called when several devices are used in parallel
+ * before start programming the sensor.
+ * When a single device us used, there is no need to call this function.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param DeviceAddress The new Device address
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetDeviceAddress(VL53L0_DEV Dev,
+ uint8_t DeviceAddress);
+
+/**
+ *
+ * @brief One time device initialization
+ *
+ * To be called once and only once after device is brought out of reset (Chip
+ * enable) and booted see @a VL53L0_WaitDeviceBooted()
+ *
+ * @par Function Description
+ * When not used after a fresh device "power up" or reset, it may return @a
+ * #VL53L0_ERROR_CALIBRATION_WARNING
+ * meaning wrong calibration data may have been fetched from device that can
+ * result in ranging offset error\n
+ * If application cannot execute device reset or need to run VL53L0_DataInit
+ * multiple time
+ * then it must ensure proper offset calibration saving and restore on its own
+ * by using @a VL53L0_GetOffsetCalibrationData() on first power up and then @a
+ * VL53L0_SetOffsetCalibrationData() in all subsequent init
+ * This function will change the VL53L0_State from VL53L0_STATE_POWERDOWN to
+ * VL53L0_STATE_WAIT_STATICINIT.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_DataInit(VL53L0_DEV Dev);
+
+/**
+ * @brief Do basic device init (and eventually patch loading)
+ * This function will change the VL53L0_State from VL53L0_STATE_WAIT_STATICINIT
+ * to VL53L0_STATE_IDLE.
+ * In this stage all defalut setting will be applied.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_StaticInit(VL53L0_DEV Dev);
+
+/**
+ * @brief Wait for device booted after chip enable (hardware standby)
+ * This function can be run only when VL53L0_State is VL53L0_STATE_POWERDOWN.
+ *
+ * @note This function is not Implemented
+ *
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ *
+ */
+VL53L010_API VL53L0_Error VL53L010_WaitDeviceBooted(VL53L0_DEV Dev);
+
+/**
+ * @brief Do an hard reset or soft reset (depending on implementation) of the
+ * device \n
+ * After call of this function, device must be in same state as right after a
+ * power-up sequence.
+ * This function will change the VL53L0_State to VL53L0_STATE_POWERDOWN.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_ResetDevice(VL53L0_DEV Dev);
+
+/** @} VL53L010_init_group */
+
+
+/** @defgroup VL53L010_parameters_group VL53L010 Parameters Functions
+ * @brief VL53L010 Functions used to prepare and setup the device
+ * @{
+ */
+
+/**
+ * @brief Prepare device for operation
+ * @par Function Description
+ * Update device with provided parameters
+ * @li Then start ranging operation.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pDeviceParameters Pointer to store current device parameters.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetDeviceParameters(VL53L0_DEV Dev,
+ const VL53L0_DeviceParameters_t *pDeviceParameters);
+
+/**
+ * @brief Retrieve current device parameters
+ * @par Function Description
+ * Get actual parameters of the device
+ * @li Then start ranging operation.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pDeviceParameters Pointer to store current device parameters.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetDeviceParameters(VL53L0_DEV Dev,
+ VL53L0_DeviceParameters_t *pDeviceParameters);
+
+/**
+ * @brief Set a new device mode
+ * @par Function Description
+ * Set device to a new mode (ranging, histogram ...)
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param DeviceMode New device mode to apply
+ * Valid values are:
+ * VL53L0_DEVICEMODE_SINGLE_RANGING
+ * VL53L0_DEVICEMODE_CONTINUOUS_RANGING
+ * VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING
+ * VL53L0_DEVICEMODE_SINGLE_HISTOGRAM
+ * (functionality not available)
+ *
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_MODE_NOT_SUPPORTED This error occurs when
+ * DeviceMode is not in the supported list
+ */
+VL53L010_API VL53L0_Error VL53L010_SetDeviceMode(VL53L0_DEV Dev,
+ VL53L0_DeviceModes DeviceMode);
+
+/**
+ * @brief Get current new device mode
+ * @par Function Description
+ * Get actual mode of the device(ranging, histogram ...)
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pDeviceMode Pointer to current apply mode value
+ * Valid values are:
+ * VL53L0_DEVICEMODE_SINGLE_RANGING
+ * VL53L0_DEVICEMODE_CONTINUOUS_RANGING
+ * VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING
+ * VL53L0_DEVICEMODE_SINGLE_HISTOGRAM
+ * (functionality not available)
+ *
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_MODE_NOT_SUPPORTED This error occurs when
+ * DeviceMode is not in the supported list
+ */
+VL53L010_API VL53L0_Error VL53L010_GetDeviceMode(VL53L0_DEV Dev,
+ VL53L0_DeviceModes *pDeviceMode);
+
+/**
+ * @brief Set a new Histogram mode
+ * @par Function Description
+ * Set device to a new Histogram mode
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param HistogramMode New device mode to apply
+ * Valid values are:
+ * VL53L0_HISTOGRAMMODE_DISABLED
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_MODE_NOT_SUPPORTED This error occurs when
+ * HistogramMode is not in the supported list
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetHistogramMode(VL53L0_DEV Dev,
+ VL53L0_HistogramModes HistogramMode);
+
+/**
+ * @brief Get current new device mode
+ * @par Function Description
+ * Get current Histogram mode of a Device
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pHistogramMode Pointer to current Histogram Mode value
+ * Valid values are:
+ * VL53L0_HISTOGRAMMODE_DISABLED
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetHistogramMode(VL53L0_DEV Dev,
+ VL53L0_HistogramModes *pHistogramMode);
+
+/**
+ * @brief Set Ranging Timing Budget in microseconds
+ *
+ * @par Function Description
+ * Defines the maximum time allowed by the user to the device to run a full
+ * ranging sequence
+ * for the current mode (ranging, histogram, ASL ...)
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param MeasurementTimingBudgetMicroSeconds Max measurement time in
+ * microseconds.
+ * Valid values are:
+ * >= 17000 microseconds when
+ * wraparound is enabled
+ * >= 12000 microseconds when
+ * wraparound is disabled
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned if
+ * MeasurementTimingBudgetMicroSeconds is out of range
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetMeasurementTimingBudgetMicroSeconds(
+ VL53L0_DEV Dev,
+ uint32_t MeasurementTimingBudgetMicroSeconds);
+
+/**
+ * @brief Get Ranging Timing Budget in microseconds
+ *
+ * @par Function Description
+ * Returns the programmed the maximum time allowed by the user to the device to
+ * run a full ranging sequence
+ * for the current mode (ranging, histogram, ASL ...)
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pMeasurementTimingBudgetMicroSeconds Max measurement time in
+ * microseconds.
+ * Valid values are:
+ * >= 17000 microseconds when
+ * wraparound is enabled
+ * >= 12000 microseconds when
+ * wraparound is disabled
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetMeasurementTimingBudgetMicroSeconds(
+ VL53L0_DEV Dev,
+ uint32_t *pMeasurementTimingBudgetMicroSeconds);
+
+/**
+ * Program continuous mode Inter-Measurement period in milliseconds
+ *
+ * @par Function Description
+ * When trying to set too short time return INVALID_PARAMS minimal value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param InterMeasurementPeriodMilliSeconds Requires Inter-Measurement
+ * Period in milliseconds.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetInterMeasurementPeriodMilliSeconds(
+ VL53L0_DEV Dev,
+ uint32_t InterMeasurementPeriodMilliSeconds);
+
+/**
+ * Get continuous mode Inter-Measurement period in milliseconds
+ *
+ * @par Function Description
+ * When trying to set too short time return INVALID_PARAMS minimal value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pInterMeasurementPeriodMilliSeconds Pointer to programmed
+ * Inter-Measurement Period in milliseconds.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetInterMeasurementPeriodMilliSeconds(
+ VL53L0_DEV Dev,
+ uint32_t *pInterMeasurementPeriodMilliSeconds);
+
+/**
+ * @brief Enable/Disable Cross talk compensation feature
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param XTalkCompensationEnable Cross talk compensation to be set
+ * 0=disabled else = enabled
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetXTalkCompensationEnable(
+ VL53L0_DEV Dev, uint8_t XTalkCompensationEnable);
+
+/**
+ * @brief Get Cross talk compensation rate
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pXTalkCompensationEnable Pointer to the Cross talk compensation
+ * state 0=disabled or 1 = enabled
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetXTalkCompensationEnable(
+ VL53L0_DEV Dev, uint8_t *pXTalkCompensationEnable);
+
+/**
+ * @brief Set Cross talk compensation rate
+ *
+ * @par Function Description
+ * Set Cross talk compensation rate.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param XTalkCompensationRateMegaCps Compensation rate in Mega counts per
+ * second (16.16 fix point) see datasheet for details
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetXTalkCompensationRateMegaCps(
+ VL53L0_DEV Dev,
+ FixPoint1616_t XTalkCompensationRateMegaCps);
+
+/**
+ * @brief Get Cross talk compensation rate
+ *
+ * @par Function Description
+ * Get Cross talk compensation rate.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pXTalkCompensationRateMegaCps Pointer to Compensation rate in Mega
+ * counts per second (16.16 fix point) see datasheet for details
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetXTalkCompensationRateMegaCps(
+ VL53L0_DEV Dev,
+ FixPoint1616_t *pXTalkCompensationRateMegaCps);
+
+
+/**
+ * @brief Get the number of the check limit managed by a given Device
+ *
+ * @par Function Description
+ * This function give the number of the check limit managed by the Device
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param pNumberOfLimitCheck Pointer to the number of check limit.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetNumberOfLimitCheck(
+ uint16_t *pNumberOfLimitCheck);
+
+/**
+ * @brief Return a description string for a given limit check number
+ *
+ * @par Function Description
+ * This function returns a description string for a given limit check number.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID (0<= LimitCheckId <
+ * VL53L0_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckString Pointer to the description string of
+ * the given check limit.
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned when
+ * LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetLimitCheckInfo(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, char *pLimitCheckString);
+
+
+/**
+ * @brief Enable/Disable a specific limit check
+ *
+ * @par Function Description
+ * This function Enable/Disable a specific limit check.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID (0<= LimitCheckId <
+ * VL53L0_GetNumberOfLimitCheck() ).
+ * @param LimitCheckEnable if 1 the check limit corresponding to
+ * LimitCheckId is Enabled
+ * if 0 the check limit corresponding to
+ * LimitCheckId is disabled
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned when
+ * LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetLimitCheckEnable(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, uint8_t LimitCheckEnable);
+
+
+/**
+ * @brief Get specific limit check enable state
+ *
+ * @par Function Description
+ * This function get the enable state of a specific limit check.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID (0<= LimitCheckId <
+ * VL53L0_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckEnable Pointer to the check limit enable
+ * value.
+ * if 1 the check limit corresponding to
+ * LimitCheckId is Enabled
+ * if 0 the check limit corresponding to
+ * LimitCheckId is disabled
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned when
+ * LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetLimitCheckEnable(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, uint8_t *pLimitCheckEnable);
+
+/**
+ * @brief Set a specific limit check value
+ *
+ * @par Function Description
+ * This function set a specific limit check value.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID (0<= LimitCheckId <
+ * VL53L0_GetNumberOfLimitCheck() ).
+ * @param LimitCheckValue Limit check Value for a given
+ * LimitCheckId
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned when either
+ * LimitCheckId or LimitCheckValue value is out of range.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetLimitCheckValue(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t LimitCheckValue);
+
+/**
+ * @brief Get a specific limit check value
+ *
+ * @par Function Description
+ * This function get a specific limit check value from device then it updates
+ * internal values and check enables.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID (0<= LimitCheckId <
+ * VL53L0_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckValue Pointer to Limit check Value for a
+ * given LimitCheckId.
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned when
+ * LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetLimitCheckValue(VL53L0_DEV Dev,
+ uint16_t LimitCheckId,
+ FixPoint1616_t *pLimitCheckValue);
+
+
+/**
+ * @brief Get the current value of the signal used for the limit check
+ *
+ * @par Function Description
+ * This function get a the current value of the signal used for the limit check.
+ * To obtain the latest value you should run a ranging before.
+ * The value reported is linked to the limit check identified with the
+ * LimitCheckId.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID (0<= LimitCheckId <
+ * VL53L0_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckCurrent Pointer to current Value for a
+ * given LimitCheckId.
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned when
+ * LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetLimitCheckCurrent(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t *pLimitCheckCurrent);
+
+/**
+ * @brief Enable (or disable) Wrap around Check
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param WrapAroundCheckEnable Wrap around Check to be set 0=disabled,
+ * other = enabled
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetWrapAroundCheckEnable(VL53L0_DEV Dev,
+ uint8_t WrapAroundCheckEnable);
+
+/**
+ * @brief Get setup of Wrap around Check
+ *
+ * @par Function Description
+ * This function get the wrapAround check enable parameters
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pWrapAroundCheckEnable Pointer to the Wrap around Check state
+ * 0=disabled or 1 = enabled
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetWrapAroundCheckEnable(VL53L0_DEV Dev,
+ uint8_t *pWrapAroundCheckEnable);
+
+/** @} VL53L010_parameters_group */
+
+
+/** @defgroup VL53L010_measurement_group VL53L010 Measurement Functions
+ * @brief VL53L010 Functions used for the measurements
+ * @{
+ */
+
+/**
+ * @brief Single shot measurement.
+ *
+ * @par Function Description
+ * Perform simple measurement sequence (Start measure, Wait measure to end, and
+ * returns when measurement is done).
+ * Once function returns, user can get valid data by calling
+ * VL53L0_GetRangingMeasurement or VL53L0_GetHistogramMeasurement depending on
+ * defined measurement mode
+ * User should Clear the interrupt in case this are enabled by using the
+ * function VL53L0_ClearInterruptMask().
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_PerformSingleMeasurement(VL53L0_DEV Dev);
+
+/**
+ * @brief Perform Reference Calibration
+ *
+ * @details Perform a reference calibration of the Device.
+ * This function should be run from time to time before doing a ranging
+ * measurement.
+ * This function will launch a special ranging measurement, so if interrupt are
+ * enable an interrupt will be done.
+ * This function will clear the interrupt generated automatically.
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_PerformRefCalibration(VL53L0_DEV Dev);
+
+/**
+ * @brief Perform XTalk Calibration
+ *
+ * @details Perform a XTalk calibration of the Device.
+ * This function will launch a ranging measurement, if interrupts are enabled
+ * an interrupt will be done.
+ * This function will clear the interrupt generated automatically.
+ * This function will program a new value for the XTalk compensation and it
+ * will enable the cross talk before exit.
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @note This function change the device mode to
+ * VL53L0_DEVICEMODE_SINGLE_RANGING
+ *
+ * @param Dev Device Handle
+ * @param XTalkCalDistance XTalkCalDistance value used for the
+ * XTalk computation.
+ * @param pXTalkCompensationRateMegaCps Pointer to new XTalkCompensation
+ * value.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_PerformXTalkCalibration(VL53L0_DEV Dev,
+ FixPoint1616_t XTalkCalDistance,
+ FixPoint1616_t *pXTalkCompensationRateMegaCps);
+
+/**
+ * @brief Perform Offset Calibration
+ *
+ * @details Perform a Offset calibration of the Device.
+ * This function will launch a ranging measurement, if interrupts are
+ * enabled an interrupt will be done.
+ * This function will clear the interrupt generated automatically.
+ * This function will program a new value for the Offset calibration value and
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @note This function does not change the device mode.
+ *
+ * @param Dev Device Handle
+ * @param CalDistanceMilliMeter Calibration distance value used for the
+ * offset compensation.
+ * @param pOffsetMicroMeter Pointer to new Offset value computed by the
+ * function.
+ *
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_PerformOffsetCalibration(VL53L0_DEV Dev,
+ FixPoint1616_t CalDistanceMilliMeter, int32_t* pOffsetMicroMeter);
+
+/**
+ * @brief Start device measurement
+ *
+ * @details Started measurement will depend on device parameters set through @a
+ * VL53L0_SetParameters()
+ * This is a non-blocking function
+ * This function will change the VL53L0_State from VL53L0_STATE_IDLE to
+ * VL53L0_STATE_RUNNING.
+ *
+ * @note This function Access to the device
+ *
+
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_MODE_NOT_SUPPORTED This error occurs when
+ * DeviceMode programmed with @a VL53L0_SetDeviceMode is not in the supported
+ * list:
+ * Supported mode are:
+ * VL53L0_DEVICEMODE_SINGLE_RANGING, VL53L0_DEVICEMODE_CONTINUOUS_RANGING,
+ * VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING
+ * @return VL53L0_ERROR_TIME_OUT Time out on start measurement
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_StartMeasurement(VL53L0_DEV Dev);
+
+/**
+ * @brief Stop device measurement
+ *
+ * @details Will set the device in standby mode at end of current measurement \n
+ * Not necessary in single mode as device shall return automatically
+ * in standby mode at end of measurement.
+ * This function will change the VL53L0_State from
+ * VL53L0_STATE_RUNNING to VL53L0_STATE_IDLE.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_StopMeasurement(VL53L0_DEV Dev);
+
+/**
+ * @brief Return Measurement Data Ready
+ *
+ * @par Function Description
+ * This function indicate that a measurement data is ready.
+ * This function check if interrupt mode is used then check is done accordingly.
+ * If perform function clear the interrupt, this function will not work, like
+ * in case of @a VL53L0_PerformSingleRangingMeasurement().
+ * The previous function is blocking function, VL53L0_GetMeasurementDataReady
+ * is used for non-blocking capture.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pMeasurementDataReady Pointer to Measurement Data Ready. 0=data
+ * not ready, 1 = data ready
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetMeasurementDataReady(VL53L0_DEV Dev,
+ uint8_t *pMeasurementDataReady);
+
+/**
+ * @brief Wait for device ready for a new measurement command. Blocking
+ * function.
+ *
+ * @note This function is not Implemented
+ *
+ * @param Dev Device Handle
+ * @param MaxLoop Max Number of polling loop (timeout).
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+VL53L010_API VL53L0_Error VL53L010_WaitDeviceReadyForNewMeasurement(VL53L0_DEV Dev,
+ uint32_t MaxLoop);
+
+
+/**
+ * @brief Retrieve the measurements from device for a given setup
+ *
+ * @par Function Description
+ * Get data from last successful Ranging measurement
+ * @warning USER should take care about @a VL53L0_GetNumberOfROIZones() before
+ * get data.
+ * PAL will fill a NumberOfROIZones times the corresponding data structure used
+ * in the measurement function.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pRangingMeasurementData Pointer to the data structure to fill up.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetRangingMeasurementData(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData);
+
+/**
+ * @brief Retrieve the measurements from device for a given setup
+ *
+ * @par Function Description
+ * Get data from last successful Histogram measurement
+ * @warning USER should take care about @a VL53L0_GetNumberOfROIZones() before
+ * get data.
+ * PAL will fill a NumberOfROIZones times the corresponding data structure used
+ * in the measurement function.
+ * @note This function is not Implemented
+ * @param Dev Device Handle
+ * @param pHistogramMeasurementData Pointer to the data structure to fill
+ * up.
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+VL53L010_API VL53L0_Error VL53L010_GetHistogramMeasurementData(VL53L0_DEV Dev,
+ VL53L0_HistogramMeasurementData_t *pHistogramMeasurementData);
+
+/**
+ * @brief Performs a single ranging measurement and retrieve the ranging
+ * measurement data
+ *
+ * @par Function Description
+ * This function will change the device mode to
+ * VL53L0_DEVICEMODE_SINGLE_RANGING with @a VL53L0_SetDeviceMode(),
+ * It performs measurement with @a VL53L0_PerformSingleMeasurement()
+ * It get data from last successful Ranging measurement with @a
+ * VL53L0_GetRangingMeasurementData.
+ * Finally it clear the interrupt with @a VL53L0_ClearInterruptMask().
+ * @note This function Access to the device
+ *
+ * @note This function change the device mode to
+ * VL53L0_DEVICEMODE_SINGLE_RANGING
+ *
+ * @param Dev Device Handle
+ * @param pRangingMeasurementData Pointer to the data structure to fill up.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_PerformSingleRangingMeasurement(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData);
+
+/**
+ * @brief Performs a single histogram measurement and retrieve the histogram
+ * measurement data
+ * Is equivalent to VL53L0_PerformSingleMeasurement +
+ * VL53L0_GetHistogramMeasurementData
+ *
+ * @par Function Description
+ * Get data from last successful Ranging measurement.
+ * This function will clear the interrupt in case of these are enabled.
+ *
+ * @note This function is not Implemented
+ *
+ * @param Dev Device Handle
+ * @param pHistogramMeasurementData Pointer to the data structure to fill
+ * up.
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+VL53L010_API VL53L0_Error VL53L010_PerformSingleHistogramMeasurement(
+ VL53L0_DEV Dev,
+ VL53L0_HistogramMeasurementData_t *pHistogramMeasurementData);
+
+
+
+/**
+ * @brief Set the number of ROI Zones to be used for a specific Device
+ *
+ * @par Function Description
+ * Set the number of ROI Zones to be used for a specific Device.
+ * The programmed value should be less than the max number of ROI Zones given
+ * with @a VL53L0_GetMaxNumberOfROIZones().
+ * This version of API manage only one zone.
+ *
+ * @param Dev Device Handle
+ * @param NumberOfROIZones Number of ROI Zones to be used for a
+ * specific Device.
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned if
+ * NumberOfROIZones != 1
+ */
+VL53L010_API VL53L0_Error VL53L010_SetNumberOfROIZones(VL53L0_DEV Dev,
+ uint8_t NumberOfROIZones);
+
+/**
+ * @brief Get the number of ROI Zones managed by the Device
+ *
+ * @par Function Description
+ * Get number of ROI Zones managed by the Device
+ * USER should take care about @a VL53L0_GetNumberOfROIZones() before get data
+ * after a perform measurement.
+ * PAL will fill a NumberOfROIZones times the corresponding data structure used
+ * in the measurement function.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pNumberOfROIZones Pointer to the Number of ROI Zones
+ * value.
+ * @return VL53L0_ERROR_NONE Success
+ */
+VL53L010_API VL53L0_Error VL53L010_GetNumberOfROIZones(VL53L0_DEV Dev,
+ uint8_t *pNumberOfROIZones);
+
+/**
+ * @brief Get the Maximum number of ROI Zones managed by the Device
+ *
+ * @par Function Description
+ * Get Maximum number of ROI Zones managed by the Device.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pMaxNumberOfROIZones Pointer to the Maximum Number of ROI
+ * Zones value.
+ * @return VL53L0_ERROR_NONE Success
+ */
+VL53L010_API VL53L0_Error VL53L010_GetMaxNumberOfROIZones(VL53L0_DEV Dev,
+ uint8_t *pMaxNumberOfROIZones);
+
+
+/** @} VL53L010_measurement_group */
+
+
+/** @defgroup VL53L010_interrupt_group VL53L010 Interrupt Functions
+ * @brief VL53L010 Functions used for interrupt managements
+ * @{
+ */
+
+/**
+ * @brief Set the configuration of GPIO pin for a given device
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param Pin ID of the GPIO Pin
+ * @param Functionality Select Pin functionality. Refer to
+ * ::VL53L0_GpioFunctionality
+ * @param DeviceMode Device Mode associated to the Gpio.
+ * @param Polarity Set interrupt polarity. Active high or active
+ * low see ::VL53L0_InterruptPolarity
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_GPIO_NOT_EXISTING Only Pin=0 is
+ * accepted.
+ * @return VL53L0_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED This error occurs
+ * when Functionality programmed is not in the supported list:
+ * Supported value
+ * are:
+ *
+ * VL53L0_GPIOFUNCTIONALITY_OFF, VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW,
+ * VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH,
+ * VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT,
+ *
+ * VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetGpioConfig(VL53L0_DEV Dev, uint8_t Pin,
+ VL53L0_DeviceModes DeviceMode,
+ VL53L0_GpioFunctionality Functionality,
+ VL53L0_InterruptPolarity Polarity);
+
+
+/**
+ * @brief Get current configuration for GPIO pin for a given device
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param Pin ID of the GPIO Pin
+ * @param pDeviceMode Pointer to Device Mode associated to the Gpio.
+ * @param pFunctionality Pointer to Pin functionality.
+ * Refer to ::VL53L0_GpioFunctionality
+ * @param pPolarity Pointer to interrupt polarity. Active high or
+ * active low see ::VL53L0_InterruptPolarity
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_GPIO_NOT_EXISTING Only Pin=0 is accepted.
+ * @return VL53L0_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED This error occurs
+ * when Functionality programmed is not in the supported list:
+ * Supported value are:
+ * VL53L0_GPIOFUNCTIONALITY_OFF, VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW,
+ * VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH,
+ * VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT,
+ * VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetGpioConfig(VL53L0_DEV Dev, uint8_t Pin,
+ VL53L0_DeviceModes *pDeviceMode,
+ VL53L0_GpioFunctionality *pFunctionality,
+ VL53L0_InterruptPolarity *pPolarity);
+
+/**
+ * @brief Set low and high Interrupt thresholds for a given mode (ranging, ALS,
+ * ...) for a given device
+ *
+ * @par Function Description
+ * Set low and high Interrupt thresholds for a given mode (ranging, ALS, ...)
+ * for a given device
+ *
+ * @note This function Access to the device
+ *
+ * @note DeviceMode is ignored for the current device
+ *
+ * @param Dev Device Handle
+ * @param DeviceMode Device Mode for which change thresholds
+ * @param ThresholdLow Low threshold (mm, lux ..., depending on the
+ * mode)
+ * @param ThresholdHigh High threshold (mm, lux ..., depending on the
+ * mode)
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetInterruptThresholds(VL53L0_DEV Dev,
+ VL53L0_DeviceModes DeviceMode,
+ FixPoint1616_t ThresholdLow,
+ FixPoint1616_t ThresholdHigh);
+
+/**
+ * @brief Get high and low Interrupt thresholds for a given mode (ranging,
+ * ALS, ...) for a given device
+ *
+ * @par Function Description
+ * Get high and low Interrupt thresholds for a given mode (ranging, ALS, ...)
+ * for a given device
+ *
+ * @note This function Access to the device
+ *
+ * @note DeviceMode is ignored for the current device
+ *
+ * @param Dev Device Handle
+ * @param DeviceMode Device Mode from which read thresholds
+ * @param pThresholdLow Low threshold (mm, lux ..., depending on the
+ * mode)
+ * @param pThresholdHigh High threshold (mm, lux ..., depending on the
+ * mode)
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetInterruptThresholds(VL53L0_DEV Dev,
+ VL53L0_DeviceModes DeviceMode,
+ FixPoint1616_t *pThresholdLow,
+ FixPoint1616_t *pThresholdHigh);
+
+/**
+ * @brief Clear given system interrupt condition
+ *
+ * @par Function Description
+ * Clear given interrupt(s).
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param InterruptMask Mask of interrupts to clear
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_ClearInterruptMask(VL53L0_DEV Dev,
+ uint32_t InterruptMask);
+
+/**
+ * @brief Return device interrupt status
+ *
+ * @par Function Description
+ * Returns currently raised interrupts by the device.
+ * User shall be able to activate/deactivate interrupts through
+ * @a VL53L0_SetGpioConfig()
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pInterruptMaskStatus Pointer to status variable to update
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetInterruptMaskStatus(VL53L0_DEV Dev,
+ uint32_t *pInterruptMaskStatus);
+
+
+/**
+ * @brief Configure ranging interrupt reported to system
+ *
+ * @note This function is not Implemented
+ *
+ * @param Dev Device Handle
+ * @param InterruptMask Mask of interrupt to Enable/disable
+ * (0:interrupt disabled or 1: interrupt enabled)
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+VL53L010_API VL53L0_Error VL53L010_EnableInterruptMask(VL53L0_DEV Dev,
+ uint32_t InterruptMask);
+
+
+/** @} VL53L010_interrupt_group */
+
+
+/** @defgroup VL53L010_SPADfunctions_group VL53L010 SPAD Functions
+ * @brief VL53L010 Functions used for SPAD managements
+ * @{
+ */
+
+
+
+/**
+ * @brief Set the SPAD Ambient Damper Threshold value
+ *
+ * @par Function Description
+ * This function set the SPAD Ambient Damper Threshold value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param SpadAmbientDamperThreshold SPAD Ambient Damper Threshold value
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetSpadAmbientDamperThreshold(VL53L0_DEV Dev,
+ uint16_t SpadAmbientDamperThreshold);
+
+/**
+ * @brief Get the current SPAD Ambient Damper Threshold value
+ *
+ * @par Function Description
+ * This function get the SPAD Ambient Damper Threshold value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pSpadAmbientDamperThreshold Pointer to programmed SPAD Ambient
+ * Damper Threshold value
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetSpadAmbientDamperThreshold(VL53L0_DEV Dev,
+ uint16_t *pSpadAmbientDamperThreshold);
+
+
+/**
+ * @brief Set the SPAD Ambient Damper Factor value
+ *
+ * @par Function Description
+ * This function set the SPAD Ambient Damper Factor value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param SpadAmbientDamperFactor SPAD Ambient Damper Factor value
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_SetSpadAmbientDamperFactor(VL53L0_DEV Dev,
+ uint16_t SpadAmbientDamperFactor);
+
+/**
+ * @brief Get the current SPAD Ambient Damper Factor value
+ *
+ * @par Function Description
+ * This function get the SPAD Ambient Damper Factor value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pSpadAmbientDamperFactor Pointer to programmed SPAD Ambient
+ * Damper Factor value
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L010_API VL53L0_Error VL53L010_GetSpadAmbientDamperFactor(VL53L0_DEV Dev,
+ uint16_t *pSpadAmbientDamperFactor);
+
+
+/** @} VL53L010_SPADfunctions_group */
+
+/** @} VL53L010_cut10_group */
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VL53L010_API_H_ */
diff --git a/drivers/input/misc/vl53L0/inc/vl53l010_device.h b/drivers/input/misc/vl53L0/inc/vl53l010_device.h
new file mode 100644
index 000000000000..a94b552c1b44
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l010_device.h
@@ -0,0 +1,231 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+/**
+ * Device specific defines. To be adapted by implementer for the targeted
+ * device.
+ */
+
+#ifndef _VL53L010_DEVICE_H_
+#define _VL53L010_DEVICE_H_
+
+#include "vl53l0_types.h"
+
+/** @defgroup VL53L010_SpecDefines_group VL53L010 cut1.0 Device Specific Defines
+ * @brief VL53L010 cut1.0 Device Specific Defines
+ * @{
+ */
+
+
+/** @defgroup VL53L010_DeviceError_group Device Error
+ * @brief Device Error code
+ *
+ * This enum is Device specific it should be updated in the implementation
+ * Use @a VL53L010_GetStatusErrorString() to get the string.
+ * It is related to Status Register of the Device.
+ * @{
+ */
+typedef uint8_t VL53L010_DeviceError;
+
+#define VL53L010_DEVICEERROR_NONE ((VL53L010_DeviceError) 0)
+#define VL53L010_DEVICEERROR_VCSELCONTINUITYTESTFAILURE ((VL53L010_DeviceError) 1)
+#define VL53L010_DEVICEERROR_VCSELWATCHDOGTESTFAILURE ((VL53L010_DeviceError) 2)
+#define VL53L010_DEVICEERROR_NOVHVVALUEFOUND ((VL53L010_DeviceError) 3)
+#define VL53L010_DEVICEERROR_MSRCNOTARGET ((VL53L010_DeviceError) 4)
+#define VL53L010_DEVICEERROR_MSRCMINIMUMSNR ((VL53L010_DeviceError) 5)
+#define VL53L010_DEVICEERROR_MSRCWRAPAROUND ((VL53L010_DeviceError) 6)
+#define VL53L010_DEVICEERROR_TCC ((VL53L010_DeviceError) 7)
+#define VL53L010_DEVICEERROR_RANGEAWRAPAROUND ((VL53L010_DeviceError) 8)
+#define VL53L010_DEVICEERROR_RANGEBWRAPAROUND ((VL53L010_DeviceError) 9)
+#define VL53L010_DEVICEERROR_MINCLIP ((VL53L010_DeviceError) 10)
+#define VL53L010_DEVICEERROR_RANGECOMPLETE ((VL53L010_DeviceError) 11)
+#define VL53L010_DEVICEERROR_ALGOUNDERFLOW ((VL53L010_DeviceError) 12)
+#define VL53L010_DEVICEERROR_ALGOOVERFLOW ((VL53L010_DeviceError) 13)
+#define VL53L010_DEVICEERROR_FINALSNRLIMIT ((VL53L010_DeviceError) 14)
+#define VL53L010_DEVICEERROR_NOTARGETIGNORE ((VL53L010_DeviceError) 15)
+
+/** @} VL53L010_DeviceError_group */
+
+/** @defgroup VL53L010_CheckEnable_group Check Enable list
+ * @brief Check Enable code
+ *
+ * Define used to specify the LimitCheckId.
+ * Use @a VL53L010_GetLimitCheckInfo() to get the string.
+ * @{
+ */
+
+#define VL53L010_CHECKENABLE_SIGMA_FINAL_RANGE 0
+#define VL53L010_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE 1
+#define VL53L010_CHECKENABLE_NUMBER_OF_CHECKS 2
+
+/** @} VL53L010_CheckEnable_group */
+
+
+/** @defgroup VL53L010_GpioFunctionality_group Gpio Functionality
+ * @brief Defines the different functionalities for the device GPIO(s)
+ * @{
+ */
+typedef uint8_t VL53L010_GpioFunctionality;
+
+#define VL53L010_GPIOFUNCTIONALITY_OFF ((VL53L010_GpioFunctionality) 0) /*!< NO Interrupt */
+#define VL53L010_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW ((VL53L010_GpioFunctionality) 1) /*!< Level Low (value < thresh_low) */
+#define VL53L010_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH ((VL53L010_GpioFunctionality) 2) /*!< Level High (value > thresh_high) */
+#define VL53L010_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT ((VL53L010_GpioFunctionality) 3) /*!< Out Of Window (value < thresh_low OR value > thresh_high) */
+#define VL53L010_GPIOFUNCTIONALITY_NEW_MEASURE_READY ((VL53L010_GpioFunctionality) 4) /*!< New Sample Ready */
+
+/** @} VL53L010_GpioFunctionality_group */
+
+
+
+/* Device register map */
+
+/** @defgroup VL53L010_DefineRegisters_group Define Registers
+ * @brief List of all the defined registers
+ * @{
+ */
+#define VL53L010_REG_SYSRANGE_START 0x000
+ /** mask existing bit in #VL53L010_REG_SYSRANGE_START*/
+ #define VL53L010_REG_SYSRANGE_MODE_MASK 0x0F
+ /** bit 0 in #VL53L010_REG_SYSRANGE_START write 1 toggle state in
+ continuous mode and arm next shot in single shot mode */
+ #define VL53L010_REG_SYSRANGE_MODE_START_STOP 0x01
+ /** bit 1 write 0 in #VL53L010_REG_SYSRANGE_START set single shot mode */
+ #define VL53L010_REG_SYSRANGE_MODE_SINGLESHOT 0x00
+ /** bit 1 write 1 in #VL53L010_REG_SYSRANGE_START set back-to-back
+ operation mode */
+ #define VL53L010_REG_SYSRANGE_MODE_BACKTOBACK 0x02
+ /** bit 2 write 1 in #VL53L010_REG_SYSRANGE_START set timed operation
+ mode */
+ #define VL53L010_REG_SYSRANGE_MODE_TIMED 0x04
+ /** bit 3 write 1 in #VL53L010_REG_SYSRANGE_START set histogram
+ operation mode */
+ #define VL53L010_REG_SYSRANGE_MODE_HISTOGRAM 0x08
+
+
+#define VL53L010_REG_SYSTEM_THRESH_HIGH 0x000C /* NOSLC 2 bytes */
+#define VL53L010_REG_SYSTEM_THRESH_LOW 0x000E /* NOSLC 2 bytes */
+
+
+/* FPGA bitstream */
+#define VL53L010_REG_SYSTEM_SEQUENCE_CONFIG 0x0001
+#define VL53L010_REG_SYSTEM_INTERMEASUREMENT_PERIOD 0x0004
+
+#define VL53L010_REG_SYSTEM_REPORT_REQUEST 0x0009
+ #define VL53L010_REG_SYSTEM_RANGEA_DATA 0x04
+ #define VL53L010_REG_SYSTEM_RANGEB_DATA 0x05
+
+#define VL53L010_REG_SYSTEM_INTERRUPT_CONFIG_GPIO 0x000A
+ #define VL53L010_REG_SYSTEM_INTERRUPT_GPIO_DISABLED 0x00
+ #define VL53L010_REG_SYSTEM_INTERRUPT_GPIO_LEVEL_LOW 0x01
+ #define VL53L010_REG_SYSTEM_INTERRUPT_GPIO_LEVEL_HIGH 0x02
+ #define VL53L010_REG_SYSTEM_INTERRUPT_GPIO_OUT_OF_WINDOW 0x03
+ #define VL53L010_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY 0x04
+
+#define VL53L010_REG_GPIO_HV_MUX_ACTIVE_HIGH 0x0084
+
+#define VL53L010_REG_SYSTEM_INTERRUPT_CLEAR 0x000B
+
+/* Result registers */
+#define VL53L010_REG_RESULT_INTERRUPT_STATUS 0x0013
+#define VL53L010_REG_RESULT_RANGE_STATUS 0x0014
+
+#define VL53L010_REG_RESULT_SIGNAL_COUNT_RATE_RET 0x001A
+#define VL53L010_REG_RESULT_AMBIENT_COUNT_RATE_RET 0x001C
+#define VL53L010_REG_RESULT_FINAL_RANGE 0x001E
+
+/* Algo register */
+#define VL53L010_REG_ALGO_CROSSTALK_COMPENSATION_RATE 0x0020
+#define VL53L010_REG_ALGO_RANGE_IGNORE_VALID_HEIGHT 0x0025
+#define VL53L010_REG_ALGO_RANGE_IGNORE_THRESHOLD 0x0026
+#define VL53L010_REG_ALGO_SNR_RATIO 0x0027
+#define VL53L010_REG_ALGO_RANGE_CHECK_ENABLES 0x0028
+
+#define VL53L010_REG_ALGO_PART_TO_PART_RANGE_OFFSET 0x0029
+
+#define VL53L010_REG_I2C_SLAVE_DEVICE_ADDRESS 0x008a
+
+/* MSRC registers */
+#define VL53L010_REG_MSRC_CONFIG_COUNT 0x0044
+#define VL53L010_REG_MSRC_CONFIG_TIMEOUT 0x0046
+#define VL53L010_REG_MSRC_CONFIG_MIN_SNR 0x0055
+#define VL53L010_REG_MSRC_CONFIG_VALID_PHASE_LOW 0x0047
+#define VL53L010_REG_MSRC_CONFIG_VALID_PHASE_HIGH 0x0048
+
+/* RANGE A registers */
+#define VL53L010_REG_RNGA_CONFIG_VCSEL_PERIOD 0x0050
+#define VL53L010_REG_RNGA_TIMEOUT_MSB 0x0051
+#define VL53L010_REG_RNGA_TIMEOUT_LSB 0x0052
+#define VL53L010_REG_RNGA_CONFIG_VALID_PHASE_LOW 0x0056
+#define VL53L010_REG_RNGA_CONFIG_VALID_PHASE_HIGH 0x0057
+
+/* RANGE B1 registers */
+#define VL53L010_REG_RNGB1_CONFIG_VCSEL_PERIOD 0x0060
+#define VL53L010_REG_RNGB1_TIMEOUT_MSB 0x0061
+#define VL53L010_REG_RNGB1_TIMEOUT_LSB 0x0062
+#define VL53L010_REG_RNGB1_CONFIG_VALID_PHASE_LOW 0x0066
+#define VL53L010_REG_RNGB1_CONFIG_VALID_PHASE_HIGH 0x0067
+
+/* RANGE B2 registers */
+#define VL53L010_REG_RNGB2_CONFIG_VCSEL_PERIOD 0x0070
+#define VL53L010_REG_RNGB2_TIMEOUT_MSB 0x0071
+#define VL53L010_REG_RNGB2_TIMEOUT_LSB 0x0072
+#define VL53L010_REG_RNGB2_CONFIG_VALID_PHASE_LOW 0x0076
+#define VL53L010_REG_RNGB2_CONFIG_VALID_PHASE_HIGH 0x0077
+
+
+#define VL53L010_REG_SOFT_RESET_GO2_SOFT_RESET_N 0x00bf
+#define VL53L010_REG_IDENTIFICATION_MODEL_ID 0x00c0
+#define VL53L010_REG_IDENTIFICATION_REVISION_ID 0x00c2
+#define VL53L010_REG_IDENTIFICATION_MODULE_ID 0x00c3
+
+#define VL53L010_REG_OSC_CALIBRATE_VAL 0x00f8
+
+#define VL53L010_REG_FIRMWARE_MODE_STATUS 0x00C5
+
+#define VL53L010_REG_DYNAMIC_SPAD_ACTUAL_RTN_SPADS_INT 0x0016
+
+#define VL53L010_SIGMA_ESTIMATE_MAX_VALUE 65535
+/*equivalent to a range sigma of 655.35mm */
+
+/*
+ * Speed of light in um per 1E-10 Seconds
+ */
+
+#define VL53L010_SPEED_OF_LIGHT_IN_AIR 2997
+
+
+/** @} VL53L010_DefineRegisters_group */
+
+/** @} VL53L010_SpecDefines_group */
+
+
+#endif
+
+/* _VL53L010_DEVICE_H_ */
+
+
diff --git a/drivers/input/misc/vl53L0/inc/vl53l010_strings.h b/drivers/input/misc/vl53L0/inc/vl53l010_strings.h
new file mode 100644
index 000000000000..cd632abc5728
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l010_strings.h
@@ -0,0 +1,134 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+#ifndef VL53L010_STRINGS_H_
+#define VL53L010_STRINGS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ #define VL53L010_STRING_DEVICE_INFO_NAME \
+ "VL53L0 cut1.0"
+ #define VL53L010_STRING_DEVICE_INFO_NAME_TS0 \
+ "VL53L0 TS0"
+ #define VL53L010_STRING_DEVICE_INFO_NAME_TS1 \
+ "VL53L0 TS1"
+ #define VL53L010_STRING_DEVICE_INFO_NAME_TS2 \
+ "VL53L0 TS2"
+ #define VL53L010_STRING_DEVICE_INFO_NAME_ES1 \
+ "VL53L0 ES1 or later"
+ #define VL53L010_STRING_DEVICE_INFO_TYPE \
+ "VL53L0"
+
+ /* PAL ERROR strings */
+ #define VL53L010_STRING_ERROR_NONE \
+ "No Error"
+ #define VL53L010_STRING_ERROR_CALIBRATION_WARNING \
+ "Calibration Warning Error"
+ #define VL53L010_STRING_ERROR_MIN_CLIPPED \
+ "Min clipped error"
+ #define VL53L010_STRING_ERROR_UNDEFINED \
+ "Undefined error"
+ #define VL53L010_STRING_ERROR_INVALID_PARAMS \
+ "Invalid parameters error"
+ #define VL53L010_STRING_ERROR_NOT_SUPPORTED \
+ "Not supported error"
+ #define VL53L010_STRING_ERROR_RANGE_ERROR \
+ "Range error"
+ #define VL53L010_STRING_ERROR_TIME_OUT \
+ "Time out error"
+ #define VL53L010_STRING_ERROR_MODE_NOT_SUPPORTED \
+ "Mode not supported error"
+ #define VL53L010_STRING_ERROR_NOT_IMPLEMENTED \
+ "Not implemented error"
+
+ #define VL53L010_STRING_UNKNOW_ERROR_CODE \
+ "Unknow Error Code"
+ #define VL53L010_STRING_ERROR_BUFFER_TOO_SMALL \
+ "Buffer too small"
+
+ #define VL53L010_STRING_ERROR_GPIO_NOT_EXISTING \
+ "GPIO not existing"
+ #define VL53L010_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED \
+ "GPIO functionality not supported"
+ #define VL53L010_STRING_ERROR_CONTROL_INTERFACE \
+ "Control Interface Error"
+
+
+ /* Device Specific */
+ #define VL53L010_STRING_DEVICEERROR_NONE \
+ "No Update"
+ #define VL53L010_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE \
+ "VCSEL Continuity Test Failure"
+ #define VL53L010_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE \
+ "VCSEL Watchdog Test Failure"
+ #define VL53L010_STRING_DEVICEERROR_NOVHVVALUEFOUND \
+ "No VHV Value found"
+ #define VL53L010_STRING_DEVICEERROR_MSRCNOTARGET \
+ "MSRC No Target Error"
+ #define VL53L010_STRING_DEVICEERROR_MSRCMINIMUMSNR \
+ "MSRC Minimum SNR Error"
+ #define VL53L010_STRING_DEVICEERROR_MSRCWRAPAROUND \
+ "MSRC Wraparound Error"
+ #define VL53L010_STRING_DEVICEERROR_TCC \
+ "TCC Error"
+ #define VL53L010_STRING_DEVICEERROR_RANGEAWRAPAROUND \
+ "Range A Wraparound Error"
+ #define VL53L010_STRING_DEVICEERROR_RANGEBWRAPAROUND \
+ "Range B Wraparound Error"
+ #define VL53L010_STRING_DEVICEERROR_MINCLIP \
+ "Min Clip Error"
+ #define VL53L010_STRING_DEVICEERROR_RANGECOMPLETE \
+ "Range Complete"
+ #define VL53L010_STRING_DEVICEERROR_ALGOUNDERFLOW \
+ "Range Algo Underflow Error"
+ #define VL53L010_STRING_DEVICEERROR_ALGOOVERFLOW \
+ "Range Algo Overlow Error"
+ #define VL53L010_STRING_DEVICEERROR_FINALSNRLIMIT \
+ "Final Minimum SNR Error"
+ #define VL53L010_STRING_DEVICEERROR_NOTARGETIGNORE \
+ "No Target Ignore Error"
+ #define VL53L010_STRING_DEVICEERROR_UNKNOWN \
+ "Unknown error code"
+
+
+ /* Check Enable */
+ #define VL53L010_STRING_CHECKENABLE_SIGMA \
+ "SIGMA"
+ #define VL53L010_STRING_CHECKENABLE_SIGNAL_RATE \
+ "SIGNAL RATE"
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L0/inc/vl53l010_tuning.h b/drivers/input/misc/vl53L0/inc/vl53l010_tuning.h
new file mode 100644
index 000000000000..8128e65d8f6c
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l010_tuning.h
@@ -0,0 +1,58 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+#ifndef _VL53L010_TUNING_H_
+#define _VL53L010_TUNING_H_
+
+#include "vl53l0_def.h"
+#include "vl53l0_platform.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @brief Internal function used to Program the default tuning settings
+ *
+ * @ingroup VL53L0_general_group
+ * @note This function access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_Error VL53L010_load_tuning_settings(VL53L0_DEV Dev);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VL53L010_TUNING_H_ */
diff --git a/drivers/input/misc/vl53L0/inc/vl53l0_api.h b/drivers/input/misc/vl53L0/inc/vl53l0_api.h
new file mode 100644
index 000000000000..f56603853b45
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l0_api.h
@@ -0,0 +1,1930 @@
+/*******************************************************************************
+ Copyright © 2016, STMicroelectronics International N.V.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+ NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+ IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *****************************************************************************/
+
+#ifndef _VL53L0_API_H_
+#define _VL53L0_API_H_
+
+#include "vl53l0_api_strings.h"
+#include "vl53l0_def.h"
+#include "vl53l0_platform.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef _MSC_VER
+# ifdef VL53L0_API_EXPORTS
+# define VL53L0_API __declspec(dllexport)
+# else
+# define VL53L0_API
+# endif
+#else
+# define VL53L0_API
+#endif
+
+/** @defgroup VL53L0_cut11_group VL53L0 cut1.1 Function Definition
+ * @brief VL53L0 cut1.1 Function Definition
+ * @{
+ */
+
+/** @defgroup VL53L0_general_group VL53L0 General Functions
+ * @brief General functions and definitions
+ * @{
+ */
+
+/**
+ * @brief Return the VL53L0 PAL Implementation Version
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param pVersion Pointer to current PAL Implementation Version
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetVersion(VL53L0_Version_t *pVersion);
+
+/**
+ * @brief Return the PAL Specification Version used for the current
+ * implementation.
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param pPalSpecVersion Pointer to current PAL Specification Version
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetPalSpecVersion(
+ VL53L0_Version_t *pPalSpecVersion);
+
+/**
+ * @brief Reads the Product Revision for a for given Device
+ * This function can be used to distinguish cut1.0 from cut1.1.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pProductRevisionMajor Pointer to Product Revision Major
+ * for a given Device
+ * @param pProductRevisionMinor Pointer to Product Revision Minor
+ * for a given Device
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetProductRevision(VL53L0_DEV Dev,
+ uint8_t *pProductRevisionMajor, uint8_t *pProductRevisionMinor);
+
+/**
+ * @brief Reads the Device information for given Device
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pVL53L0_DeviceInfo Pointer to current device info for a given
+ * Device
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetDeviceInfo(VL53L0_DEV Dev,
+ VL53L0_DeviceInfo_t *pVL53L0_DeviceInfo);
+
+/**
+ * @brief Read current status of the error register for the selected device
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pDeviceErrorStatus Pointer to current error code of the device
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetDeviceErrorStatus(VL53L0_DEV Dev,
+ VL53L0_DeviceError *pDeviceErrorStatus);
+
+/**
+ * @brief Human readable Range Status string for a given RangeStatus
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param RangeStatus The RangeStatus code as stored on
+ * @a VL53L0_RangingMeasurementData_t
+ * @param pRangeStatusString The returned RangeStatus string.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetRangeStatusString(uint8_t RangeStatus,
+ char *pRangeStatusString);
+
+/**
+ * @brief Human readable error string for a given Error Code
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param ErrorCode The error code as stored on ::VL53L0_DeviceError
+ * @param pDeviceErrorString The error string corresponding to the ErrorCode
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetDeviceErrorString(
+ VL53L0_DeviceError ErrorCode, char *pDeviceErrorString);
+
+/**
+ * @brief Human readable error string for current PAL error status
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param PalErrorCode The error code as stored on @a VL53L0_Error
+ * @param pPalErrorString The error string corresponding to the
+ * PalErrorCode
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetPalErrorString(VL53L0_Error PalErrorCode,
+ char *pPalErrorString);
+
+/**
+ * @brief Human readable PAL State string
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param PalStateCode The State code as stored on @a VL53L0_State
+ * @param pPalStateString The State string corresponding to the
+ * PalStateCode
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetPalStateString(VL53L0_State PalStateCode,
+ char *pPalStateString);
+
+/**
+ * @brief Reads the internal state of the PAL for a given Device
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param Dev Device Handle
+ * @param pPalState Pointer to current state of the PAL for a
+ * given Device
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetPalState(VL53L0_DEV Dev,
+ VL53L0_State *pPalState);
+
+/**
+ * @brief Set the power mode for a given Device
+ * The power mode can be Standby or Idle. Different level of both Standby and
+ * Idle can exists.
+ * This function should not be used when device is in Ranging state.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param PowerMode The value of the power mode to set.
+ * see ::VL53L0_PowerModes
+ * Valid values are:
+ * VL53L0_POWERMODE_STANDBY_LEVEL1,
+ * VL53L0_POWERMODE_IDLE_LEVEL1
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_MODE_NOT_SUPPORTED This error occurs when PowerMode
+ * is not in the supported list
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetPowerMode(VL53L0_DEV Dev,
+ VL53L0_PowerModes PowerMode);
+
+/**
+ * @brief Get the power mode for a given Device
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pPowerMode Pointer to the current value of the power
+ * mode. see ::VL53L0_PowerModes
+ * Valid values are:
+ * VL53L0_POWERMODE_STANDBY_LEVEL1,
+ * VL53L0_POWERMODE_IDLE_LEVEL1
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetPowerMode(VL53L0_DEV Dev,
+ VL53L0_PowerModes *pPowerMode);
+
+/**
+ * Set or over-hide part to part calibration offset
+ * \sa VL53L0_DataInit() VL53L0_GetOffsetCalibrationDataMicroMeter()
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param OffsetCalibrationDataMicroMeter Offset (microns)
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetOffsetCalibrationDataMicroMeter(
+ VL53L0_DEV Dev, int32_t OffsetCalibrationDataMicroMeter);
+
+/**
+ * @brief Get part to part calibration offset
+ *
+ * @par Function Description
+ * Should only be used after a successful call to @a VL53L0_DataInit to backup
+ * device NVM value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pOffsetCalibrationDataMicroMeter Return part to part
+ * calibration offset from device (microns)
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetOffsetCalibrationDataMicroMeter(
+ VL53L0_DEV Dev, int32_t *pOffsetCalibrationDataMicroMeter);
+
+/**
+ * Set the linearity corrective gain
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LinearityCorrectiveGain Linearity corrective
+ * gain in x1000
+ * if value is 1000 then no modification is applied.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetLinearityCorrectiveGain(VL53L0_DEV Dev,
+ int16_t LinearityCorrectiveGain);
+
+/**
+ * @brief Get the linearity corrective gain
+ *
+ * @par Function Description
+ * Should only be used after a successful call to @a VL53L0_DataInit to backup
+ * device NVM value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pLinearityCorrectiveGain Pointer to the linearity
+ * corrective gain in x1000
+ * if value is 1000 then no modification is applied.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetLinearityCorrectiveGain(VL53L0_DEV Dev,
+ uint16_t *pLinearityCorrectiveGain);
+
+/**
+ * Set Group parameter Hold state
+ *
+ * @par Function Description
+ * Set or remove device internal group parameter hold
+ *
+ * @note This function is not Implemented
+ *
+ * @param Dev Device Handle
+ * @param GroupParamHold Group parameter Hold state to be set (on/off)
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+VL53L0_API VL53L0_Error VL53L0_SetGroupParamHold(VL53L0_DEV Dev,
+ uint8_t GroupParamHold);
+
+/**
+ * @brief Get the maximal distance for actual setup
+ * @par Function Description
+ * Device must be initialized through @a VL53L0_SetParameters() prior calling
+ * this function.
+ *
+ * Any range value more than the value returned is to be considered as
+ * "no target detected" or
+ * "no target in detectable range"\n
+ * @warning The maximal distance depends on the setup
+ *
+ * @note This function is not Implemented
+ *
+ * @param Dev Device Handle
+ * @param pUpperLimitMilliMeter The maximal range limit for actual setup
+ * (in millimeter)
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+VL53L0_API VL53L0_Error VL53L0_GetUpperLimitMilliMeter(VL53L0_DEV Dev,
+ uint16_t *pUpperLimitMilliMeter);
+
+
+/**
+ * @brief Get the Total Signal Rate
+ * @par Function Description
+ * This function will return the Total Signal Rate after a good ranging is done.
+ *
+ * @note This function access to Device
+ *
+ * @param Dev Device Handle
+ * @param pTotalSignalRate Total Signal Rate value in Mega count per second
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_Error VL53L0_GetTotalSignalRate(VL53L0_DEV Dev,
+ FixPoint1616_t *pTotalSignalRate);
+
+/** @} VL53L0_general_group */
+
+/** @defgroup VL53L0_init_group VL53L0 Init Functions
+ * @brief VL53L0 Init Functions
+ * @{
+ */
+
+/**
+ * @brief Set new device address
+ *
+ * After completion the device will answer to the new address programmed.
+ * This function should be called when several devices are used in parallel
+ * before start programming the sensor.
+ * When a single device us used, there is no need to call this function.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param DeviceAddress The new Device address
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetDeviceAddress(VL53L0_DEV Dev,
+ uint8_t DeviceAddress);
+
+/**
+ *
+ * @brief One time device initialization
+ *
+ * To be called once and only once after device is brought out of reset
+ * (Chip enable) and booted see @a VL53L0_WaitDeviceBooted()
+ *
+ * @par Function Description
+ * When not used after a fresh device "power up" or reset, it may return
+ * @a #VL53L0_ERROR_CALIBRATION_WARNING meaning wrong calibration data
+ * may have been fetched from device that can result in ranging offset error\n
+ * If application cannot execute device reset or need to run VL53L0_DataInit
+ * multiple time then it must ensure proper offset calibration saving and
+ * restore on its own by using @a VL53L0_GetOffsetCalibrationData() on first
+ * power up and then @a VL53L0_SetOffsetCalibrationData() in all subsequent init
+ * This function will change the VL53L0_State from VL53L0_STATE_POWERDOWN to
+ * VL53L0_STATE_WAIT_STATICINIT.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_DataInit(VL53L0_DEV Dev);
+
+/**
+ * @brief Set the tuning settings pointer
+ *
+ * This function is used to specify the Tuning settings buffer to be used
+ * for a given device. The buffer contains all the necessary data to permit
+ * the API to write tuning settings.
+ * This function permit to force the usage of either external or internal
+ * tuning settings.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pTuningSettingBuffer Pointer to tuning settings buffer.
+ * @param UseInternalTuningSettings Use internal tuning settings value.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetTuningSettingBuffer(VL53L0_DEV Dev,
+ uint8_t *pTuningSettingBuffer, uint8_t UseInternalTuningSettings);
+
+/**
+ * @brief Get the tuning settings pointer and the internal external switch
+ * value.
+ *
+ * This function is used to get the Tuning settings buffer pointer and the
+ * value.
+ * of the switch to select either external or internal tuning settings.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param ppTuningSettingBuffer Pointer to tuning settings buffer.
+ * @param pUseInternalTuningSettings Pointer to store Use internal tuning
+ * settings value.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetTuningSettingBuffer(VL53L0_DEV Dev,
+ uint8_t **ppTuningSettingBuffer, uint8_t *pUseInternalTuningSettings);
+
+/**
+ * @brief Do basic device init (and eventually patch loading)
+ * This function will change the VL53L0_State from
+ * VL53L0_STATE_WAIT_STATICINIT to VL53L0_STATE_IDLE.
+ * In this stage all default setting will be applied.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_StaticInit(VL53L0_DEV Dev);
+
+/**
+ * @brief Wait for device booted after chip enable (hardware standby)
+ * This function can be run only when VL53L0_State is VL53L0_STATE_POWERDOWN.
+ *
+ * @note This function is not Implemented
+ *
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ *
+ */
+VL53L0_API VL53L0_Error VL53L0_WaitDeviceBooted(VL53L0_DEV Dev);
+
+/**
+ * @brief Do an hard reset or soft reset (depending on implementation) of the
+ * device \nAfter call of this function, device must be in same state as right
+ * after a power-up sequence.This function will change the VL53L0_State to
+ * VL53L0_STATE_POWERDOWN.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_ResetDevice(VL53L0_DEV Dev);
+
+/** @} VL53L0_init_group */
+
+/** @defgroup VL53L0_parameters_group VL53L0 Parameters Functions
+ * @brief Functions used to prepare and setup the device
+ * @{
+ */
+
+/**
+ * @brief Prepare device for operation
+ * @par Function Description
+ * Update device with provided parameters
+ * @li Then start ranging operation.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pDeviceParameters Pointer to store current device parameters.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetDeviceParameters(VL53L0_DEV Dev,
+ const VL53L0_DeviceParameters_t *pDeviceParameters);
+
+/**
+ * @brief Retrieve current device parameters
+ * @par Function Description
+ * Get actual parameters of the device
+ * @li Then start ranging operation.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pDeviceParameters Pointer to store current device parameters.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetDeviceParameters(VL53L0_DEV Dev,
+ VL53L0_DeviceParameters_t *pDeviceParameters);
+
+/**
+ * @brief Set a new device mode
+ * @par Function Description
+ * Set device to a new mode (ranging, histogram ...)
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param DeviceMode New device mode to apply
+ * Valid values are:
+ * VL53L0_DEVICEMODE_SINGLE_RANGING
+ * VL53L0_DEVICEMODE_CONTINUOUS_RANGING
+ * VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING
+ * VL53L0_DEVICEMODE_SINGLE_HISTOGRAM
+ * VL53L0_HISTOGRAMMODE_REFERENCE_ONLY
+ * VL53L0_HISTOGRAMMODE_RETURN_ONLY
+ * VL53L0_HISTOGRAMMODE_BOTH
+ *
+ *
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_MODE_NOT_SUPPORTED This error occurs when DeviceMode is
+ * not in the supported list
+ */
+VL53L0_API VL53L0_Error VL53L0_SetDeviceMode(VL53L0_DEV Dev,
+ VL53L0_DeviceModes DeviceMode);
+
+/**
+ * @brief Get current new device mode
+ * @par Function Description
+ * Get actual mode of the device(ranging, histogram ...)
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pDeviceMode Pointer to current apply mode value
+ * Valid values are:
+ * VL53L0_DEVICEMODE_SINGLE_RANGING
+ * VL53L0_DEVICEMODE_CONTINUOUS_RANGING
+ * VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING
+ * VL53L0_DEVICEMODE_SINGLE_HISTOGRAM
+ * VL53L0_HISTOGRAMMODE_REFERENCE_ONLY
+ * VL53L0_HISTOGRAMMODE_RETURN_ONLY
+ * VL53L0_HISTOGRAMMODE_BOTH
+ *
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_MODE_NOT_SUPPORTED This error occurs when
+ * DeviceMode is not in the supported list
+ */
+VL53L0_API VL53L0_Error VL53L0_GetDeviceMode(VL53L0_DEV Dev,
+ VL53L0_DeviceModes *pDeviceMode);
+
+/**
+ * @brief Sets the resolution of range measurements.
+ * @par Function Description
+ * Set resolution of range measurements to either 0.25mm if
+ * fraction enabled or 1mm if not enabled.
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param Enable Enable high resolution
+ *
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetRangeFractionEnable(VL53L0_DEV Dev,
+ uint8_t Enable);
+
+/**
+ * @brief Gets the fraction enable parameter indicating the resolution of
+ * range measurements.
+ *
+ * @par Function Description
+ * Gets the fraction enable state, which translates to the resolution of
+ * range measurements as follows :Enabled:=0.25mm resolution,
+ * Not Enabled:=1mm resolution.
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param pEnable Output Parameter reporting the fraction enable state.
+ *
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetFractionEnable(VL53L0_DEV Dev,
+ uint8_t *pEnable);
+
+/**
+ * @brief Set a new Histogram mode
+ * @par Function Description
+ * Set device to a new Histogram mode
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param HistogramMode New device mode to apply
+ * Valid values are:
+ * VL53L0_HISTOGRAMMODE_DISABLED
+ * VL53L0_DEVICEMODE_SINGLE_HISTOGRAM
+ * VL53L0_HISTOGRAMMODE_REFERENCE_ONLY
+ * VL53L0_HISTOGRAMMODE_RETURN_ONLY
+ * VL53L0_HISTOGRAMMODE_BOTH
+ *
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_MODE_NOT_SUPPORTED This error occurs when
+ * HistogramMode is not in the supported list
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetHistogramMode(VL53L0_DEV Dev,
+ VL53L0_HistogramModes HistogramMode);
+
+/**
+ * @brief Get current new device mode
+ * @par Function Description
+ * Get current Histogram mode of a Device
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pHistogramMode Pointer to current Histogram Mode value
+ * Valid values are:
+ * VL53L0_HISTOGRAMMODE_DISABLED
+ * VL53L0_DEVICEMODE_SINGLE_HISTOGRAM
+ * VL53L0_HISTOGRAMMODE_REFERENCE_ONLY
+ * VL53L0_HISTOGRAMMODE_RETURN_ONLY
+ * VL53L0_HISTOGRAMMODE_BOTH
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetHistogramMode(VL53L0_DEV Dev,
+ VL53L0_HistogramModes *pHistogramMode);
+
+/**
+ * @brief Set Ranging Timing Budget in microseconds
+ *
+ * @par Function Description
+ * Defines the maximum time allowed by the user to the device to run a
+ * full ranging sequence for the current mode (ranging, histogram, ASL ...)
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param MeasurementTimingBudgetMicroSeconds Max measurement time in
+ * microseconds.
+ * Valid values are:
+ * >= 17000 microsecs when wraparound enabled
+ * >= 12000 microsecs when wraparound disabled
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned if
+ MeasurementTimingBudgetMicroSeconds out of range
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetMeasurementTimingBudgetMicroSeconds(
+ VL53L0_DEV Dev, uint32_t MeasurementTimingBudgetMicroSeconds);
+
+/**
+ * @brief Get Ranging Timing Budget in microseconds
+ *
+ * @par Function Description
+ * Returns the programmed the maximum time allowed by the user to the
+ * device to run a full ranging sequence for the current mode
+ * (ranging, histogram, ASL ...)
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pMeasurementTimingBudgetMicroSeconds Max measurement time in
+ * microseconds.
+ * Valid values are:
+ * >= 17000 microsecs when wraparound enabled
+ * >= 12000 microsecs when wraparound disabled
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetMeasurementTimingBudgetMicroSeconds(
+ VL53L0_DEV Dev, uint32_t *pMeasurementTimingBudgetMicroSeconds);
+
+/**
+ * @brief Gets the VCSEL pulse period.
+ *
+ * @par Function Description
+ * This function retrieves the VCSEL pulse period for the given period type.
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param VcselPeriodType VCSEL period identifier (pre-range|final).
+ * @param pVCSELPulsePeriod Pointer to VCSEL period value.
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS Error VcselPeriodType parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetVcselPulsePeriod(VL53L0_DEV Dev,
+ VL53L0_VcselPeriod VcselPeriodType, uint8_t *pVCSELPulsePeriod);
+
+/**
+ * @brief Sets the VCSEL pulse period.
+ *
+ * @par Function Description
+ * This function retrieves the VCSEL pulse period for the given period type.
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param VcselPeriodType VCSEL period identifier (pre-range|final).
+ * @param VCSELPulsePeriod VCSEL period value
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS Error VcselPeriodType parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetVcselPulsePeriod(VL53L0_DEV Dev,
+ VL53L0_VcselPeriod VcselPeriodType, uint8_t VCSELPulsePeriod);
+
+/**
+ * @brief Sets the (on/off) state of a requested sequence step.
+ *
+ * @par Function Description
+ * This function enables/disables a requested sequence step.
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param SequenceStepId Sequence step identifier.
+ * @param SequenceStepEnabled Demanded state {0=Off,1=On}
+ * is enabled.
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS Error SequenceStepId parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetSequenceStepEnable(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId, uint8_t SequenceStepEnabled);
+
+/**
+ * @brief Gets the (on/off) state of a requested sequence step.
+ *
+ * @par Function Description
+ * This function retrieves the state of a requested sequence step, i.e. on/off.
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param SequenceStepId Sequence step identifier.
+ * @param pSequenceStepEnabled Out parameter reporting if the sequence step
+ * is enabled {0=Off,1=On}.
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS Error SequenceStepId parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetSequenceStepEnable(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId, uint8_t *pSequenceStepEnabled);
+
+/**
+ * @brief Gets the (on/off) state of all sequence steps.
+ *
+ * @par Function Description
+ * This function retrieves the state of all sequence step in the scheduler.
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param pSchedulerSequenceSteps Pointer to struct containing result.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetSequenceStepEnables(VL53L0_DEV Dev,
+ VL53L0_SchedulerSequenceSteps_t *pSchedulerSequenceSteps);
+
+/**
+ * @brief Sets the timeout of a requested sequence step.
+ *
+ * @par Function Description
+ * This function sets the timeout of a requested sequence step.
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param SequenceStepId Sequence step identifier.
+ * @param TimeOutMilliSecs Demanded timeout
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS Error SequenceStepId parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetSequenceStepTimeout(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId, FixPoint1616_t TimeOutMilliSecs);
+
+/**
+ * @brief Gets the timeout of a requested sequence step.
+ *
+ * @par Function Description
+ * This function retrieves the timeout of a requested sequence step.
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param SequenceStepId Sequence step identifier.
+ * @param pTimeOutMilliSecs Timeout value.
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS Error SequenceStepId parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetSequenceStepTimeout(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId,
+ FixPoint1616_t *pTimeOutMilliSecs);
+
+/**
+ * @brief Gets number of sequence steps managed by the API.
+ *
+ * @par Function Description
+ * This function retrieves the number of sequence steps currently managed
+ * by the API
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param pNumberOfSequenceSteps Out parameter reporting the number of
+ * sequence steps.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetNumberOfSequenceSteps(VL53L0_DEV Dev,
+ uint8_t *pNumberOfSequenceSteps);
+
+/**
+ * @brief Gets the name of a given sequence step.
+ *
+ * @par Function Description
+ * This function retrieves the name of sequence steps corresponding to
+ * SequenceStepId.
+ *
+ * @note This function doesn't Accesses the device
+ *
+ * @param SequenceStepId Sequence step identifier.
+ * @param pSequenceStepsString Pointer to Info string
+ *
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetSequenceStepsInfo(
+ VL53L0_SequenceStepId SequenceStepId, char *pSequenceStepsString);
+
+/**
+ * Program continuous mode Inter-Measurement period in milliseconds
+ *
+ * @par Function Description
+ * When trying to set too short time return INVALID_PARAMS minimal value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param InterMeasurementPeriodMilliSeconds Inter-Measurement Period in ms.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetInterMeasurementPeriodMilliSeconds(
+ VL53L0_DEV Dev, uint32_t InterMeasurementPeriodMilliSeconds);
+
+/**
+ * Get continuous mode Inter-Measurement period in milliseconds
+ *
+ * @par Function Description
+ * When trying to set too short time return INVALID_PARAMS minimal value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pInterMeasurementPeriodMilliSeconds Pointer to programmed
+ * Inter-Measurement Period in milliseconds.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetInterMeasurementPeriodMilliSeconds(
+ VL53L0_DEV Dev, uint32_t *pInterMeasurementPeriodMilliSeconds);
+
+/**
+ * @brief Enable/Disable Cross talk compensation feature
+ *
+ * @note This function is not Implemented.
+ * Enable/Disable Cross Talk by set to zero the Cross Talk value
+ * by using @a VL53L0_SetXTalkCompensationRateMegaCps().
+ *
+ * @param Dev Device Handle
+ * @param XTalkCompensationEnable Cross talk compensation
+ * to be set 0=disabled else = enabled
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+VL53L0_API VL53L0_Error VL53L0_SetXTalkCompensationEnable(VL53L0_DEV Dev,
+ uint8_t XTalkCompensationEnable);
+
+/**
+ * @brief Get Cross talk compensation rate
+ *
+ * @note This function is not Implemented.
+ * Enable/Disable Cross Talk by set to zero the Cross Talk value by
+ * using @a VL53L0_SetXTalkCompensationRateMegaCps().
+ *
+ * @param Dev Device Handle
+ * @param pXTalkCompensationEnable Pointer to the Cross talk compensation
+ * state 0=disabled or 1 = enabled
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+VL53L0_API VL53L0_Error VL53L0_GetXTalkCompensationEnable(VL53L0_DEV Dev,
+ uint8_t *pXTalkCompensationEnable);
+
+/**
+ * @brief Set Cross talk compensation rate
+ *
+ * @par Function Description
+ * Set Cross talk compensation rate.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param XTalkCompensationRateMegaCps Compensation rate in
+ * Mega counts per second (16.16 fix point) see datasheet for details
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetXTalkCompensationRateMegaCps(VL53L0_DEV Dev,
+ FixPoint1616_t XTalkCompensationRateMegaCps);
+
+/**
+ * @brief Get Cross talk compensation rate
+ *
+ * @par Function Description
+ * Get Cross talk compensation rate.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pXTalkCompensationRateMegaCps Pointer to Compensation rate
+ in Mega counts per second (16.16 fix point) see datasheet for details
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetXTalkCompensationRateMegaCps(VL53L0_DEV Dev,
+ FixPoint1616_t *pXTalkCompensationRateMegaCps);
+
+/**
+ * @brief Set Reference Calibration Parameters
+ *
+ * @par Function Description
+ * Set Reference Calibration Parameters.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param VhvSettings Parameter for VHV
+ * @param PhaseCal Parameter for PhaseCal
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetRefCalibration(VL53L0_DEV Dev,
+ uint8_t VhvSettings, uint8_t PhaseCal);
+
+/**
+ * @brief Get Reference Calibration Parameters
+ *
+ * @par Function Description
+ * Get Reference Calibration Parameters.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pVhvSettings Pointer to VHV parameter
+ * @param pPhaseCal Pointer to PhaseCal Parameter
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetRefCalibration(VL53L0_DEV Dev,
+ uint8_t *pVhvSettings, uint8_t *pPhaseCal);
+
+/**
+ * @brief Get the number of the check limit managed by a given Device
+ *
+ * @par Function Description
+ * This function give the number of the check limit managed by the Device
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param pNumberOfLimitCheck Pointer to the number of check limit.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetNumberOfLimitCheck(
+ uint16_t *pNumberOfLimitCheck);
+
+/**
+ * @brief Return a description string for a given limit check number
+ *
+ * @par Function Description
+ * This function returns a description string for a given limit check number.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ (0<= LimitCheckId < VL53L0_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckString Pointer to the
+ description string of the given check limit.
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is
+ returned when LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetLimitCheckInfo(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, char *pLimitCheckString);
+
+/**
+ * @brief Return a the Status of the specified check limit
+ *
+ * @par Function Description
+ * This function returns the Status of the specified check limit.
+ * The value indicate if the check is fail or not.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ (0<= LimitCheckId < VL53L0_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckStatus Pointer to the
+ Limit Check Status of the given check limit.
+ * LimitCheckStatus :
+ * 0 the check is not fail
+ * 1 the check if fail or not enabled
+ *
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is
+ returned when LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetLimitCheckStatus(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, uint8_t *pLimitCheckStatus);
+
+/**
+ * @brief Enable/Disable a specific limit check
+ *
+ * @par Function Description
+ * This function Enable/Disable a specific limit check.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L0_GetNumberOfLimitCheck() ).
+ * @param LimitCheckEnable if 1 the check limit
+ * corresponding to LimitCheckId is Enabled
+ * if 0 the check limit
+ * corresponding to LimitCheckId is disabled
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned
+ * when LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetLimitCheckEnable(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, uint8_t LimitCheckEnable);
+
+/**
+ * @brief Get specific limit check enable state
+ *
+ * @par Function Description
+ * This function get the enable state of a specific limit check.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L0_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckEnable Pointer to the check limit enable
+ * value.
+ * if 1 the check limit
+ * corresponding to LimitCheckId is Enabled
+ * if 0 the check limit
+ * corresponding to LimitCheckId is disabled
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned
+ * when LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetLimitCheckEnable(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, uint8_t *pLimitCheckEnable);
+
+/**
+ * @brief Set a specific limit check value
+ *
+ * @par Function Description
+ * This function set a specific limit check value.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L0_GetNumberOfLimitCheck() ).
+ * @param LimitCheckValue Limit check Value for a given
+ * LimitCheckId
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned when either
+ * LimitCheckId or LimitCheckValue value is out of range.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetLimitCheckValue(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t LimitCheckValue);
+
+/**
+ * @brief Get a specific limit check value
+ *
+ * @par Function Description
+ * This function get a specific limit check value from device then it updates
+ * internal values and check enables.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L0_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckValue Pointer to Limit
+ * check Value for a given LimitCheckId.
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned
+ * when LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetLimitCheckValue(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t *pLimitCheckValue);
+
+/**
+ * @brief Get the current value of the signal used for the limit check
+ *
+ * @par Function Description
+ * This function get a the current value of the signal used for the limit check.
+ * To obtain the latest value you should run a ranging before.
+ * The value reported is linked to the limit check identified with the
+ * LimitCheckId.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L0_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckCurrent Pointer to current Value for a
+ * given LimitCheckId.
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned when
+ * LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetLimitCheckCurrent(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t *pLimitCheckCurrent);
+
+/**
+ * @brief Enable (or disable) Wrap around Check
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param WrapAroundCheckEnable Wrap around Check to be set
+ * 0=disabled, other = enabled
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetWrapAroundCheckEnable(VL53L0_DEV Dev,
+ uint8_t WrapAroundCheckEnable);
+
+/**
+ * @brief Get setup of Wrap around Check
+ *
+ * @par Function Description
+ * This function get the wrapAround check enable parameters
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pWrapAroundCheckEnable Pointer to the Wrap around Check state
+ * 0=disabled or 1 = enabled
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetWrapAroundCheckEnable(VL53L0_DEV Dev,
+ uint8_t *pWrapAroundCheckEnable);
+
+/**
+ * @brief Set Dmax Calibration Parameters for a given device
+ * When one of the parameter is zero, this function will get parameter
+ * from NVM.
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param RangeMilliMeter Calibration Distance
+ * @param SignalRateRtnMegaCps Signal rate return read at CalDistance
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetDmaxCalParameters(VL53L0_DEV Dev,
+ uint16_t RangeMilliMeter, FixPoint1616_t SignalRateRtnMegaCps);
+
+/**
+ * @brief Get Dmax Calibration Parameters for a given device
+ *
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pRangeMilliMeter Pointer to Calibration Distance
+ * @param pSignalRateRtnMegaCps Pointer to Signal rate return
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetDmaxCalParameters(VL53L0_DEV Dev,
+ uint16_t *pRangeMilliMeter, FixPoint1616_t *pSignalRateRtnMegaCps);
+
+/** @} VL53L0_parameters_group */
+
+/** @defgroup VL53L0_measurement_group VL53L0 Measurement Functions
+ * @brief Functions used for the measurements
+ * @{
+ */
+
+/**
+ * @brief Single shot measurement.
+ *
+ * @par Function Description
+ * Perform simple measurement sequence (Start measure, Wait measure to end,
+ * and returns when measurement is done).
+ * Once function returns, user can get valid data by calling
+ * VL53L0_GetRangingMeasurement or VL53L0_GetHistogramMeasurement
+ * depending on defined measurement mode
+ * User should Clear the interrupt in case this are enabled by using the
+ * function VL53L0_ClearInterruptMask().
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_PerformSingleMeasurement(VL53L0_DEV Dev);
+
+/**
+ * @brief Perform Reference Calibration
+ *
+ * @details Perform a reference calibration of the Device.
+ * This function should be run from time to time before doing
+ * a ranging measurement.
+ * This function will launch a special ranging measurement, so
+ * if interrupt are enable an interrupt will be done.
+ * This function will clear the interrupt generated automatically.
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pVhvSettings Pointer to vhv settings parameter.
+ * @param pPhaseCal Pointer to PhaseCal parameter.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_PerformRefCalibration(VL53L0_DEV Dev,
+ uint8_t *pVhvSettings, uint8_t *pPhaseCal);
+
+/**
+ * @brief Perform XTalk Measurement
+ *
+ * @details Measures the current cross talk from glass in front
+ * of the sensor.
+ * This functions performs a histogram measurement and uses the results
+ * to measure the crosstalk. For the function to be successful, there
+ * must be no target in front of the sensor.
+ *
+ * @warning This function is a blocking function
+ *
+ * @warning This function is not supported when the final range
+ * vcsel clock period is set below 10 PCLKS.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param TimeoutMs Histogram measurement duration.
+ * @param pXtalkPerSpad Output parameter containing the crosstalk
+ * measurement result, in MCPS/Spad. Format fixpoint 16:16.
+ * @param pAmbientTooHigh Output parameter which indicate that
+ * pXtalkPerSpad is not good if the Ambient is too high.
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS vcsel clock period not supported
+ * for this operation. Must not be less than 10PCLKS.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_PerformXTalkMeasurement(VL53L0_DEV Dev,
+ uint32_t TimeoutMs, FixPoint1616_t *pXtalkPerSpad,
+ uint8_t *pAmbientTooHigh);
+
+/**
+ * @brief Perform XTalk Calibration
+ *
+ * @details Perform a XTalk calibration of the Device.
+ * This function will launch a ranging measurement, if interrupts
+ * are enabled an interrupt will be done.
+ * This function will clear the interrupt generated automatically.
+ * This function will program a new value for the XTalk compensation
+ * and it will enable the cross talk before exit.
+ * This function will disable the VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD.
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @note This function change the device mode to
+ * VL53L0_DEVICEMODE_SINGLE_RANGING
+ *
+ * @param Dev Device Handle
+ * @param XTalkCalDistance XTalkCalDistance value used for the XTalk
+ * computation.
+ * @param pXTalkCompensationRateMegaCps Pointer to new
+ * XTalkCompensation value.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_PerformXTalkCalibration(VL53L0_DEV Dev,
+ FixPoint1616_t XTalkCalDistance,
+ FixPoint1616_t *pXTalkCompensationRateMegaCps);
+
+/**
+ * @brief Perform Offset Calibration
+ *
+ * @details Perform a Offset calibration of the Device.
+ * This function will launch a ranging measurement, if interrupts are
+ * enabled an interrupt will be done.
+ * This function will clear the interrupt generated automatically.
+ * This function will program a new value for the Offset calibration value
+ * This function will disable the VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD.
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @note This function does not change the device mode.
+ *
+ * @param Dev Device Handle
+ * @param CalDistanceMilliMeter Calibration distance value used for the
+ * offset compensation.
+ * @param pOffsetMicroMeter Pointer to new Offset value computed by the
+ * function.
+ *
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_PerformOffsetCalibration(VL53L0_DEV Dev,
+ FixPoint1616_t CalDistanceMilliMeter, int32_t *pOffsetMicroMeter);
+
+/**
+ * @brief Start device measurement
+ *
+ * @details Started measurement will depend on device parameters set through
+ * @a VL53L0_SetParameters()
+ * This is a non-blocking function.
+ * This function will change the VL53L0_State from VL53L0_STATE_IDLE to
+ * VL53L0_STATE_RUNNING.
+ *
+ * @note This function Access to the device
+ *
+
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_MODE_NOT_SUPPORTED This error occurs when
+ * DeviceMode programmed with @a VL53L0_SetDeviceMode is not in the supported
+ * list:
+ * Supported mode are:
+ * VL53L0_DEVICEMODE_SINGLE_RANGING,
+ * VL53L0_DEVICEMODE_CONTINUOUS_RANGING,
+ * VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING
+ * @return VL53L0_ERROR_TIME_OUT Time out on start measurement
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_StartMeasurement(VL53L0_DEV Dev);
+
+/**
+ * @brief Stop device measurement
+ *
+ * @details Will set the device in standby mode at end of current measurement\n
+ * Not necessary in single mode as device shall return automatically
+ * in standby mode at end of measurement.
+ * This function will change the VL53L0_State from VL53L0_STATE_RUNNING
+ * to VL53L0_STATE_IDLE.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_StopMeasurement(VL53L0_DEV Dev);
+
+/**
+ * @brief Return Measurement Data Ready
+ *
+ * @par Function Description
+ * This function indicate that a measurement data is ready.
+ * This function check if interrupt mode is used then check is done accordingly.
+ * If perform function clear the interrupt, this function will not work,
+ * like in case of @a VL53L0_PerformSingleRangingMeasurement().
+ * The previous function is blocking function, VL53L0_GetMeasurementDataReady
+ * is used for non-blocking capture.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pMeasurementDataReady Pointer to Measurement Data Ready.
+ * 0=data not ready, 1 = data ready
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetMeasurementDataReady(VL53L0_DEV Dev,
+ uint8_t *pMeasurementDataReady);
+
+/**
+ * @brief Wait for device ready for a new measurement command.
+ * Blocking function.
+ *
+ * @note This function is not Implemented
+ *
+ * @param Dev Device Handle
+ * @param MaxLoop Max Number of polling loop (timeout).
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+VL53L0_API VL53L0_Error VL53L0_WaitDeviceReadyForNewMeasurement(VL53L0_DEV Dev,
+ uint32_t MaxLoop);
+
+/**
+ * @brief Retrieve the Reference Signal after a measurements
+ *
+ * @par Function Description
+ * Get Reference Signal from last successful Ranging measurement
+ * This function return a valid value after that you call the
+ * @a VL53L0_GetRangingMeasurementData().
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pMeasurementRefSignal Pointer to the Ref Signal to fill up.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetMeasurementRefSignal(VL53L0_DEV Dev,
+ FixPoint1616_t *pMeasurementRefSignal);
+
+/**
+ * @brief Retrieve the measurements from device for a given setup
+ *
+ * @par Function Description
+ * Get data from last successful Ranging measurement
+ * @warning USER should take care about @a VL53L0_GetNumberOfROIZones()
+ * before get data.
+ * PAL will fill a NumberOfROIZones times the corresponding data
+ * structure used in the measurement function.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pRangingMeasurementData Pointer to the data structure to fill up.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetRangingMeasurementData(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData);
+
+/**
+ * @brief Retrieve the measurements from device for a given setup
+ *
+ * @par Function Description
+ * Get data from last successful Histogram measurement
+ * @warning USER should take care about @a VL53L0_GetNumberOfROIZones()
+ * before get data.
+ * PAL will fill a NumberOfROIZones times the corresponding data structure
+ * used in the measurement function.
+ *
+ * @note This function is not Implemented
+ *
+ * @param Dev Device Handle
+ * @param pHistogramMeasurementData Pointer to the histogram data structure.
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+VL53L0_API VL53L0_Error VL53L0_GetHistogramMeasurementData(VL53L0_DEV Dev,
+ VL53L0_HistogramMeasurementData_t *pHistogramMeasurementData);
+
+/**
+ * @brief Performs a single ranging measurement and retrieve the ranging
+ * measurement data
+ *
+ * @par Function Description
+ * This function will change the device mode to VL53L0_DEVICEMODE_SINGLE_RANGING
+ * with @a VL53L0_SetDeviceMode(),
+ * It performs measurement with @a VL53L0_PerformSingleMeasurement()
+ * It get data from last successful Ranging measurement with
+ * @a VL53L0_GetRangingMeasurementData.
+ * Finally it clear the interrupt with @a VL53L0_ClearInterruptMask().
+ *
+ * @note This function Access to the device
+ *
+ * @note This function change the device mode to
+ * VL53L0_DEVICEMODE_SINGLE_RANGING
+ *
+ * @param Dev Device Handle
+ * @param pRangingMeasurementData Pointer to the data structure to fill up.
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_PerformSingleRangingMeasurement(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData);
+
+/**
+ * @brief Performs a single histogram measurement and retrieve the histogram
+ * measurement data
+ * Is equivalent to VL53L0_PerformSingleMeasurement +
+ * VL53L0_GetHistogramMeasurementData
+ *
+ * @par Function Description
+ * Get data from last successful Ranging measurement.
+ * This function will clear the interrupt in case of these are enabled.
+ *
+ * @note This function is not Implemented
+ *
+ * @param Dev Device Handle
+ * @param pHistogramMeasurementData Pointer to the data structure to fill up.
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+VL53L0_API VL53L0_Error VL53L0_PerformSingleHistogramMeasurement(VL53L0_DEV Dev,
+ VL53L0_HistogramMeasurementData_t *pHistogramMeasurementData);
+
+/**
+ * @brief Set the number of ROI Zones to be used for a specific Device
+ *
+ * @par Function Description
+ * Set the number of ROI Zones to be used for a specific Device.
+ * The programmed value should be less than the max number of ROI Zones given
+ * with @a VL53L0_GetMaxNumberOfROIZones().
+ * This version of API manage only one zone.
+ *
+ * @param Dev Device Handle
+ * @param NumberOfROIZones Number of ROI Zones to be used for a
+ * specific Device.
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_INVALID_PARAMS This error is returned if
+ * NumberOfROIZones != 1
+ */
+VL53L0_API VL53L0_Error VL53L0_SetNumberOfROIZones(VL53L0_DEV Dev,
+ uint8_t NumberOfROIZones);
+
+/**
+ * @brief Get the number of ROI Zones managed by the Device
+ *
+ * @par Function Description
+ * Get number of ROI Zones managed by the Device
+ * USER should take care about @a VL53L0_GetNumberOfROIZones()
+ * before get data after a perform measurement.
+ * PAL will fill a NumberOfROIZones times the corresponding data
+ * structure used in the measurement function.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pNumberOfROIZones Pointer to the Number of ROI Zones value.
+ * @return VL53L0_ERROR_NONE Success
+ */
+VL53L0_API VL53L0_Error VL53L0_GetNumberOfROIZones(VL53L0_DEV Dev,
+ uint8_t *pNumberOfROIZones);
+
+/**
+ * @brief Get the Maximum number of ROI Zones managed by the Device
+ *
+ * @par Function Description
+ * Get Maximum number of ROI Zones managed by the Device.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pMaxNumberOfROIZones Pointer to the Maximum Number
+ * of ROI Zones value.
+ * @return VL53L0_ERROR_NONE Success
+ */
+VL53L0_API VL53L0_Error VL53L0_GetMaxNumberOfROIZones(VL53L0_DEV Dev,
+ uint8_t *pMaxNumberOfROIZones);
+
+/** @} VL53L0_measurement_group */
+
+/** @defgroup VL53L0_interrupt_group VL53L0 Interrupt Functions
+ * @brief Functions used for interrupt managements
+ * @{
+ */
+
+/**
+ * @brief Set the configuration of GPIO pin for a given device
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param Pin ID of the GPIO Pin
+ * @param Functionality Select Pin functionality.
+ * Refer to ::VL53L0_GpioFunctionality
+ * @param DeviceMode Device Mode associated to the Gpio.
+ * @param Polarity Set interrupt polarity. Active high
+ * or active low see ::VL53L0_InterruptPolarity
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_GPIO_NOT_EXISTING Only Pin=0 is accepted.
+ * @return VL53L0_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED This error occurs
+ * when Functionality programmed is not in the supported list:
+ * Supported value are:
+ * VL53L0_GPIOFUNCTIONALITY_OFF,
+ * VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW,
+ * VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH,
+ VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT,
+ * VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetGpioConfig(VL53L0_DEV Dev, uint8_t Pin,
+ VL53L0_DeviceModes DeviceMode, VL53L0_GpioFunctionality Functionality,
+ VL53L0_InterruptPolarity Polarity);
+
+/**
+ * @brief Get current configuration for GPIO pin for a given device
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param Pin ID of the GPIO Pin
+ * @param pDeviceMode Pointer to Device Mode associated to the Gpio.
+ * @param pFunctionality Pointer to Pin functionality.
+ * Refer to ::VL53L0_GpioFunctionality
+ * @param pPolarity Pointer to interrupt polarity.
+ * Active high or active low see ::VL53L0_InterruptPolarity
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_GPIO_NOT_EXISTING Only Pin=0 is accepted.
+ * @return VL53L0_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED This error occurs
+ * when Functionality programmed is not in the supported list:
+ * Supported value are:
+ * VL53L0_GPIOFUNCTIONALITY_OFF,
+ * VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW,
+ * VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH,
+ * VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT,
+ * VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetGpioConfig(VL53L0_DEV Dev, uint8_t Pin,
+ VL53L0_DeviceModes *pDeviceMode,
+ VL53L0_GpioFunctionality *pFunctionality,
+ VL53L0_InterruptPolarity *pPolarity);
+
+/**
+ * @brief Set low and high Interrupt thresholds for a given mode
+ * (ranging, ALS, ...) for a given device
+ *
+ * @par Function Description
+ * Set low and high Interrupt thresholds for a given mode (ranging, ALS, ...)
+ * for a given device
+ *
+ * @note This function Access to the device
+ *
+ * @note DeviceMode is ignored for the current device
+ *
+ * @param Dev Device Handle
+ * @param DeviceMode Device Mode for which change thresholds
+ * @param ThresholdLow Low threshold (mm, lux ..., depending on the mode)
+ * @param ThresholdHigh High threshold (mm, lux ..., depending on the mode)
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetInterruptThresholds(VL53L0_DEV Dev,
+ VL53L0_DeviceModes DeviceMode, FixPoint1616_t ThresholdLow,
+ FixPoint1616_t ThresholdHigh);
+
+/**
+ * @brief Get high and low Interrupt thresholds for a given mode
+ * (ranging, ALS, ...) for a given device
+ *
+ * @par Function Description
+ * Get high and low Interrupt thresholds for a given mode (ranging, ALS, ...)
+ * for a given device
+ *
+ * @note This function Access to the device
+ *
+ * @note DeviceMode is ignored for the current device
+ *
+ * @param Dev Device Handle
+ * @param DeviceMode Device Mode from which read thresholds
+ * @param pThresholdLow Low threshold (mm, lux ..., depending on the mode)
+ * @param pThresholdHigh High threshold (mm, lux ..., depending on the mode)
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetInterruptThresholds(VL53L0_DEV Dev,
+ VL53L0_DeviceModes DeviceMode, FixPoint1616_t *pThresholdLow,
+ FixPoint1616_t *pThresholdHigh);
+
+/**
+ * @brief Clear given system interrupt condition
+ *
+ * @par Function Description
+ * Clear given interrupt(s).
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param InterruptMask Mask of interrupts to clear
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_ClearInterruptMask(VL53L0_DEV Dev,
+ uint32_t InterruptMask);
+
+/**
+ * @brief Return device interrupt status
+ *
+ * @par Function Description
+ * Returns currently raised interrupts by the device.
+ * User shall be able to activate/deactivate interrupts through
+ * @a VL53L0_SetGpioConfig()
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pInterruptMaskStatus Pointer to status variable to update
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetInterruptMaskStatus(VL53L0_DEV Dev,
+ uint32_t *pInterruptMaskStatus);
+
+/**
+ * @brief Configure ranging interrupt reported to system
+ *
+ * @note This function is not Implemented
+ *
+ * @param Dev Device Handle
+ * @param InterruptMask Mask of interrupt to Enable/disable
+ * (0:interrupt disabled or 1: interrupt enabled)
+ * @return VL53L0_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+VL53L0_API VL53L0_Error VL53L0_EnableInterruptMask(VL53L0_DEV Dev,
+ uint32_t InterruptMask);
+
+/** @} VL53L0_interrupt_group */
+
+/** @defgroup VL53L0_SPADfunctions_group VL53L0 SPAD Functions
+ * @brief Functions used for SPAD managements
+ * @{
+ */
+
+/**
+ * @brief Set the SPAD Ambient Damper Threshold value
+ *
+ * @par Function Description
+ * This function set the SPAD Ambient Damper Threshold value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param SpadAmbientDamperThreshold SPAD Ambient Damper Threshold value
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetSpadAmbientDamperThreshold(VL53L0_DEV Dev,
+ uint16_t SpadAmbientDamperThreshold);
+
+/**
+ * @brief Get the current SPAD Ambient Damper Threshold value
+ *
+ * @par Function Description
+ * This function get the SPAD Ambient Damper Threshold value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pSpadAmbientDamperThreshold Pointer to programmed
+ * SPAD Ambient Damper Threshold value
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetSpadAmbientDamperThreshold(VL53L0_DEV Dev,
+ uint16_t *pSpadAmbientDamperThreshold);
+
+/**
+ * @brief Set the SPAD Ambient Damper Factor value
+ *
+ * @par Function Description
+ * This function set the SPAD Ambient Damper Factor value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param SpadAmbientDamperFactor SPAD Ambient Damper Factor value
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetSpadAmbientDamperFactor(VL53L0_DEV Dev,
+ uint16_t SpadAmbientDamperFactor);
+
+/**
+ * @brief Get the current SPAD Ambient Damper Factor value
+ *
+ * @par Function Description
+ * This function get the SPAD Ambient Damper Factor value
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pSpadAmbientDamperFactor Pointer to programmed SPAD Ambient
+ * Damper Factor value
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetSpadAmbientDamperFactor(VL53L0_DEV Dev,
+ uint16_t *pSpadAmbientDamperFactor);
+
+/**
+ * @brief Performs Reference Spad Management
+ *
+ * @par Function Description
+ * The reference SPAD initialization procedure determines the minimum amount
+ * of reference spads to be enables to achieve a target reference signal rate
+ * and should be performed once during initialization.
+ *
+ * @note This function Access to the device
+ *
+ * @note This function change the device mode to
+ * VL53L0_DEVICEMODE_SINGLE_RANGING
+ *
+ * @param Dev Device Handle
+ * @param refSpadCount Reports ref Spad Count
+ * @param isApertureSpads Reports if spads are of type
+ * aperture or non-aperture.
+ * 1:=aperture, 0:=Non-Aperture
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_REF_SPAD_INIT Error in the Ref Spad procedure.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_PerformRefSpadManagement(VL53L0_DEV Dev,
+ uint32_t *refSpadCount, uint8_t *isApertureSpads);
+
+/**
+ * @brief Applies Reference SPAD configuration
+ *
+ * @par Function Description
+ * This function applies a given number of reference spads, identified as
+ * either Aperture or Non-Aperture.
+ * The requested spad count and type are stored within the device specific
+ * parameters data for access by the host.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param refSpadCount Number of ref spads.
+ * @param isApertureSpads Defines if spads are of type
+ * aperture or non-aperture.
+ * 1:=aperture, 0:=Non-Aperture
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_REF_SPAD_INIT Error in the in the reference
+ * spad configuration.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_SetReferenceSpads(VL53L0_DEV Dev,
+ uint32_t refSpadCount, uint8_t isApertureSpads);
+
+/**
+ * @brief Retrieves SPAD configuration
+ *
+ * @par Function Description
+ * This function retrieves the current number of applied reference spads
+ * and also their type : Aperture or Non-Aperture.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param refSpadCount Number ref Spad Count
+ * @param isApertureSpads Reports if spads are of type
+ * aperture or non-aperture.
+ * 1:=aperture, 0:=Non-Aperture
+ * @return VL53L0_ERROR_NONE Success
+ * @return VL53L0_ERROR_REF_SPAD_INIT Error in the in the reference
+ * spad configuration.
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_API VL53L0_Error VL53L0_GetReferenceSpads(VL53L0_DEV Dev,
+ uint32_t *refSpadCount, uint8_t *isApertureSpads);
+
+/** @} VL53L0_SPADfunctions_group */
+
+/** @} VL53L0_cut11_group */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VL53L0_API_H_ */
diff --git a/drivers/input/misc/vl53L0/inc/vl53l0_api_calibration.h b/drivers/input/misc/vl53L0/inc/vl53l0_api_calibration.h
new file mode 100644
index 000000000000..ff54e99263d9
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l0_api_calibration.h
@@ -0,0 +1,85 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+#ifndef _VL53L0_API_CALIBRATION_H_
+#define _VL53L0_API_CALIBRATION_H_
+
+#include "vl53l0_def.h"
+#include "vl53l0_platform.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+VL53L0_Error VL53L0_perform_xtalk_calibration(VL53L0_DEV Dev,
+ FixPoint1616_t XTalkCalDistance,
+ FixPoint1616_t *pXTalkCompensationRateMegaCps);
+
+VL53L0_Error VL53L0_perform_offset_calibration(VL53L0_DEV Dev,
+ FixPoint1616_t CalDistanceMilliMeter,
+ int32_t *pOffsetMicroMeter);
+
+VL53L0_Error VL53L0_set_offset_calibration_data_micro_meter(VL53L0_DEV Dev,
+ int32_t OffsetCalibrationDataMicroMeter);
+
+VL53L0_Error VL53L0_get_offset_calibration_data_micro_meter(VL53L0_DEV Dev,
+ int32_t *pOffsetCalibrationDataMicroMeter);
+
+VL53L0_Error VL53L0_apply_offset_adjustment(VL53L0_DEV Dev);
+
+VL53L0_Error VL53L0_perform_ref_spad_management(VL53L0_DEV Dev,
+ uint32_t *refSpadCount, uint8_t *isApertureSpads);
+
+VL53L0_Error VL53L0_set_reference_spads(VL53L0_DEV Dev,
+ uint32_t count, uint8_t isApertureSpads);
+
+VL53L0_Error VL53L0_get_reference_spads(VL53L0_DEV Dev,
+ uint32_t *pSpadCount, uint8_t *pIsApertureSpads);
+
+VL53L0_Error VL53L0_perform_phase_calibration(VL53L0_DEV Dev,
+ uint8_t *pPhaseCal, const uint8_t get_data_enable,
+ const uint8_t restore_config);
+
+VL53L0_Error VL53L0_perform_ref_calibration(VL53L0_DEV Dev,
+ uint8_t *pVhvSettings, uint8_t *pPhaseCal, uint8_t get_data_enable);
+
+VL53L0_Error VL53L0_set_ref_calibration(VL53L0_DEV Dev,
+ uint8_t VhvSettings, uint8_t PhaseCal);
+
+VL53L0_Error VL53L0_get_ref_calibration(VL53L0_DEV Dev,
+ uint8_t *pVhvSettings, uint8_t *pPhaseCal);
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VL53L0_API_CALIBRATION_H_ */
diff --git a/drivers/input/misc/vl53L0/inc/vl53l0_api_core.h b/drivers/input/misc/vl53L0/inc/vl53l0_api_core.h
new file mode 100644
index 000000000000..563017067528
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l0_api_core.h
@@ -0,0 +1,108 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+#ifndef _VL53L0_API_CORE_H_
+#define _VL53L0_API_CORE_H_
+
+#include "vl53l0_def.h"
+#include "vl53l0_platform.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+VL53L0_Error VL53L0_reverse_bytes(uint8_t *data, uint32_t size);
+
+VL53L0_Error VL53L0_measurement_poll_for_completion(VL53L0_DEV Dev);
+
+uint8_t VL53L0_encode_vcsel_period(uint8_t vcsel_period_pclks);
+
+uint8_t VL53L0_decode_vcsel_period(uint8_t vcsel_period_reg);
+
+uint32_t VL53L0_isqrt(uint32_t num);
+
+uint32_t VL53L0_quadrature_sum(uint32_t a, uint32_t b);
+
+VL53L0_Error VL53L0_get_info_from_device(VL53L0_DEV Dev, uint8_t option);
+
+VL53L0_Error VL53L0_set_vcsel_pulse_period(VL53L0_DEV Dev,
+ VL53L0_VcselPeriod VcselPeriodType, uint8_t VCSELPulsePeriodPCLK);
+
+VL53L0_Error VL53L0_get_vcsel_pulse_period(VL53L0_DEV Dev,
+ VL53L0_VcselPeriod VcselPeriodType, uint8_t *pVCSELPulsePeriodPCLK);
+
+uint32_t VL53L0_decode_timeout(uint16_t encoded_timeout);
+
+VL53L0_Error get_sequence_step_timeout(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId,
+ uint32_t *pTimeOutMicroSecs);
+
+VL53L0_Error set_sequence_step_timeout(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId,
+ uint32_t TimeOutMicroSecs);
+
+VL53L0_Error VL53L0_set_measurement_timing_budget_micro_seconds(VL53L0_DEV Dev,
+ uint32_t MeasurementTimingBudgetMicroSeconds);
+
+VL53L0_Error VL53L0_get_measurement_timing_budget_micro_seconds(VL53L0_DEV Dev,
+ uint32_t *pMeasurementTimingBudgetMicroSeconds);
+
+VL53L0_Error VL53L0_load_tuning_settings(VL53L0_DEV Dev,
+ uint8_t *pTuningSettingBuffer);
+
+VL53L0_Error VL53L0_calc_sigma_estimate(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData,
+ FixPoint1616_t *pSigmaEstimate, uint32_t *pDmax_mm);
+
+VL53L0_Error VL53L0_get_total_xtalk_rate(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData,
+ FixPoint1616_t *ptotal_xtalk_rate_mcps);
+
+VL53L0_Error VL53L0_get_total_signal_rate(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData,
+ FixPoint1616_t *ptotal_signal_rate_mcps);
+
+VL53L0_Error VL53L0_get_pal_range_status(VL53L0_DEV Dev,
+ uint8_t DeviceRangeStatus,
+ FixPoint1616_t SignalRate,
+ uint16_t EffectiveSpadRtnCount,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData,
+ uint8_t *pPalRangeStatus);
+
+uint32_t VL53L0_calc_timeout_mclks(VL53L0_DEV Dev,
+ uint32_t timeout_period_us, uint8_t vcsel_period_pclks);
+
+uint16_t VL53L0_encode_timeout(uint32_t timeout_macro_clks);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VL53L0_API_CORE_H_ */
diff --git a/drivers/input/misc/vl53L0/inc/vl53l0_api_histogram.h b/drivers/input/misc/vl53L0/inc/vl53l0_api_histogram.h
new file mode 100644
index 000000000000..b3e21442ca53
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l0_api_histogram.h
@@ -0,0 +1,70 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+#ifndef _VL53L0_API_HISTOGRAM_H_
+#define _VL53L0_API_HISTOGRAM_H_
+
+#include "vl53l0_def.h"
+#include "vl53l0_platform.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+VL53L0_Error VL53L0_confirm_measurement_start(VL53L0_DEV Dev);
+
+VL53L0_Error VL53L0_set_histogram_mode(VL53L0_DEV Dev,
+ VL53L0_HistogramModes HistogramMode);
+
+VL53L0_Error VL53L0_get_histogram_mode(VL53L0_DEV Dev,
+ VL53L0_HistogramModes *pHistogramMode);
+
+VL53L0_Error VL53L0_start_histogram_measurement(VL53L0_DEV Dev,
+ VL53L0_HistogramModes histoMode,
+ uint32_t count);
+
+VL53L0_Error VL53L0_perform_single_histogram_measurement(VL53L0_DEV Dev,
+ VL53L0_HistogramMeasurementData_t *pHistogramMeasurementData);
+
+VL53L0_Error VL53L0_get_histogram_measurement_data(VL53L0_DEV Dev,
+ VL53L0_HistogramMeasurementData_t *pHistogramMeasurementData);
+
+VL53L0_Error VL53L0_read_histo_measurement(VL53L0_DEV Dev,
+ uint32_t *histoData, uint32_t offset, VL53L0_HistogramModes histoMode);
+
+VL53L0_Error VL53L0_perform_xtalk_measurement(VL53L0_DEV dev,
+ uint32_t timeout_ms, FixPoint1616_t *pxtalk_per_spad,
+ uint8_t *pambient_too_high);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VL53L0_API_HISTOGRAM_H_ */
diff --git a/drivers/input/misc/vl53L0/inc/vl53l0_api_ranging.h b/drivers/input/misc/vl53L0/inc/vl53l0_api_ranging.h
new file mode 100644
index 000000000000..d2f90d34f3e4
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l0_api_ranging.h
@@ -0,0 +1,47 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+#ifndef _VL53L0_API_RANGING_H_
+#define _VL53L0_API_RANGING_H_
+
+#include "vl53l0_def.h"
+#include "vl53l0_platform.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VL53L0_API_RANGING_H_ */
diff --git a/drivers/input/misc/vl53L0/inc/vl53l0_api_strings.h b/drivers/input/misc/vl53L0/inc/vl53l0_api_strings.h
new file mode 100644
index 000000000000..72f290f19c3f
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l0_api_strings.h
@@ -0,0 +1,271 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+#ifndef VL53L0_API_STRINGS_H_
+#define VL53L0_API_STRINGS_H_
+
+#include "vl53l0_def.h"
+#include "vl53l0_platform.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+VL53L0_Error VL53L0_get_device_info(VL53L0_DEV Dev,
+ VL53L0_DeviceInfo_t *pVL53L0_DeviceInfo);
+
+VL53L0_Error VL53L0_get_device_error_string(VL53L0_DeviceError ErrorCode,
+ char *pDeviceErrorString);
+
+VL53L0_Error VL53L0_get_range_status_string(uint8_t RangeStatus,
+ char *pRangeStatusString);
+
+VL53L0_Error VL53L0_get_pal_error_string(VL53L0_Error PalErrorCode,
+ char *pPalErrorString);
+
+VL53L0_Error VL53L0_get_pal_state_string(VL53L0_State PalStateCode,
+ char *pPalStateString);
+
+VL53L0_Error VL53L0_get_sequence_steps_info(
+ VL53L0_SequenceStepId SequenceStepId,
+ char *pSequenceStepsString);
+
+VL53L0_Error VL53L0_get_limit_check_info(VL53L0_DEV Dev, uint16_t LimitCheckId,
+ char *pLimitCheckString);
+
+
+#ifdef USE_EMPTY_STRING
+ #define VL53L0_STRING_DEVICE_INFO_NAME ""
+ #define VL53L0_STRING_DEVICE_INFO_NAME_TS0 ""
+ #define VL53L0_STRING_DEVICE_INFO_NAME_TS1 ""
+ #define VL53L0_STRING_DEVICE_INFO_NAME_TS2 ""
+ #define VL53L0_STRING_DEVICE_INFO_NAME_ES1 ""
+ #define VL53L0_STRING_DEVICE_INFO_TYPE ""
+
+ /* PAL ERROR strings */
+ #define VL53L0_STRING_ERROR_NONE ""
+ #define VL53L0_STRING_ERROR_CALIBRATION_WARNING ""
+ #define VL53L0_STRING_ERROR_MIN_CLIPPED ""
+ #define VL53L0_STRING_ERROR_UNDEFINED ""
+ #define VL53L0_STRING_ERROR_INVALID_PARAMS ""
+ #define VL53L0_STRING_ERROR_NOT_SUPPORTED ""
+ #define VL53L0_STRING_ERROR_RANGE_ERROR ""
+ #define VL53L0_STRING_ERROR_TIME_OUT ""
+ #define VL53L0_STRING_ERROR_MODE_NOT_SUPPORTED ""
+ #define VL53L0_STRING_ERROR_BUFFER_TOO_SMALL ""
+ #define VL53L0_STRING_ERROR_GPIO_NOT_EXISTING ""
+ #define VL53L0_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED ""
+ #define VL53L0_STRING_ERROR_CONTROL_INTERFACE ""
+ #define VL53L0_STRING_ERROR_INVALID_COMMAND ""
+ #define VL53L0_STRING_ERROR_DIVISION_BY_ZERO ""
+ #define VL53L0_STRING_ERROR_REF_SPAD_INIT ""
+ #define VL53L0_STRING_ERROR_NOT_IMPLEMENTED ""
+
+ #define VL53L0_STRING_UNKNOW_ERROR_CODE ""
+
+
+
+ /* Range Status */
+ #define VL53L0_STRING_RANGESTATUS_NONE ""
+ #define VL53L0_STRING_RANGESTATUS_RANGEVALID ""
+ #define VL53L0_STRING_RANGESTATUS_SIGMA ""
+ #define VL53L0_STRING_RANGESTATUS_SIGNAL ""
+ #define VL53L0_STRING_RANGESTATUS_MINRANGE ""
+ #define VL53L0_STRING_RANGESTATUS_PHASE ""
+ #define VL53L0_STRING_RANGESTATUS_HW ""
+
+
+ /* Range Status */
+ #define VL53L0_STRING_STATE_POWERDOWN ""
+ #define VL53L0_STRING_STATE_WAIT_STATICINIT ""
+ #define VL53L0_STRING_STATE_STANDBY ""
+ #define VL53L0_STRING_STATE_IDLE ""
+ #define VL53L0_STRING_STATE_RUNNING ""
+ #define VL53L0_STRING_STATE_UNKNOWN ""
+ #define VL53L0_STRING_STATE_ERROR ""
+
+
+ /* Device Specific */
+ #define VL53L0_STRING_DEVICEERROR_NONE ""
+ #define VL53L0_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE ""
+ #define VL53L0_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE ""
+ #define VL53L0_STRING_DEVICEERROR_NOVHVVALUEFOUND ""
+ #define VL53L0_STRING_DEVICEERROR_MSRCNOTARGET ""
+ #define VL53L0_STRING_DEVICEERROR_SNRCHECK ""
+ #define VL53L0_STRING_DEVICEERROR_RANGEPHASECHECK ""
+ #define VL53L0_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK ""
+ #define VL53L0_STRING_DEVICEERROR_TCC ""
+ #define VL53L0_STRING_DEVICEERROR_PHASECONSISTENCY ""
+ #define VL53L0_STRING_DEVICEERROR_MINCLIP ""
+ #define VL53L0_STRING_DEVICEERROR_RANGECOMPLETE ""
+ #define VL53L0_STRING_DEVICEERROR_ALGOUNDERFLOW ""
+ #define VL53L0_STRING_DEVICEERROR_ALGOOVERFLOW ""
+ #define VL53L0_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD ""
+ #define VL53L0_STRING_DEVICEERROR_UNKNOWN ""
+
+ /* Check Enable */
+ #define VL53L0_STRING_CHECKENABLE_SIGMA_FINAL_RANGE ""
+ #define VL53L0_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE ""
+ #define VL53L0_STRING_CHECKENABLE_SIGNAL_REF_CLIP ""
+ #define VL53L0_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD ""
+
+ /* Sequence Step */
+ #define VL53L0_STRING_SEQUENCESTEP_TCC ""
+ #define VL53L0_STRING_SEQUENCESTEP_DSS ""
+ #define VL53L0_STRING_SEQUENCESTEP_MSRC ""
+ #define VL53L0_STRING_SEQUENCESTEP_PRE_RANGE ""
+ #define VL53L0_STRING_SEQUENCESTEP_FINAL_RANGE ""
+#else
+ #define VL53L0_STRING_DEVICE_INFO_NAME "VL53L0 cut1.0"
+ #define VL53L0_STRING_DEVICE_INFO_NAME_TS0 "VL53L0 TS0"
+ #define VL53L0_STRING_DEVICE_INFO_NAME_TS1 "VL53L0 TS1"
+ #define VL53L0_STRING_DEVICE_INFO_NAME_TS2 "VL53L0 TS2"
+ #define VL53L0_STRING_DEVICE_INFO_NAME_ES1 "VL53L0 ES1 or later"
+ #define VL53L0_STRING_DEVICE_INFO_TYPE "VL53L0"
+
+ /* PAL ERROR strings */
+ #define VL53L0_STRING_ERROR_NONE \
+ "No Error"
+ #define VL53L0_STRING_ERROR_CALIBRATION_WARNING \
+ "Calibration Warning Error"
+ #define VL53L0_STRING_ERROR_MIN_CLIPPED \
+ "Min clipped error"
+ #define VL53L0_STRING_ERROR_UNDEFINED \
+ "Undefined error"
+ #define VL53L0_STRING_ERROR_INVALID_PARAMS \
+ "Invalid parameters error"
+ #define VL53L0_STRING_ERROR_NOT_SUPPORTED \
+ "Not supported error"
+ #define VL53L0_STRING_ERROR_RANGE_ERROR \
+ "Range error"
+ #define VL53L0_STRING_ERROR_TIME_OUT \
+ "Time out error"
+ #define VL53L0_STRING_ERROR_MODE_NOT_SUPPORTED \
+ "Mode not supported error"
+ #define VL53L0_STRING_ERROR_BUFFER_TOO_SMALL \
+ "Buffer too small"
+ #define VL53L0_STRING_ERROR_GPIO_NOT_EXISTING \
+ "GPIO not existing"
+ #define VL53L0_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED \
+ "GPIO funct not supported"
+ #define VL53L0_STRING_ERROR_CONTROL_INTERFACE \
+ "Control Interface Error"
+ #define VL53L0_STRING_ERROR_INVALID_COMMAND \
+ "Invalid Command Error"
+ #define VL53L0_STRING_ERROR_DIVISION_BY_ZERO \
+ "Division by zero Error"
+ #define VL53L0_STRING_ERROR_REF_SPAD_INIT \
+ "Reference Spad Init Error"
+ #define VL53L0_STRING_ERROR_NOT_IMPLEMENTED \
+ "Not implemented error"
+
+ #define VL53L0_STRING_UNKNOW_ERROR_CODE \
+ "Unknown Error Code"
+
+
+
+ /* Range Status */
+ #define VL53L0_STRING_RANGESTATUS_NONE "No Update"
+ #define VL53L0_STRING_RANGESTATUS_RANGEVALID "Range Valid"
+ #define VL53L0_STRING_RANGESTATUS_SIGMA "Sigma Fail"
+ #define VL53L0_STRING_RANGESTATUS_SIGNAL "Signal Fail"
+ #define VL53L0_STRING_RANGESTATUS_MINRANGE "Min Range Fail"
+ #define VL53L0_STRING_RANGESTATUS_PHASE "Phase Fail"
+ #define VL53L0_STRING_RANGESTATUS_HW "Hardware Fail"
+
+
+ /* Range Status */
+ #define VL53L0_STRING_STATE_POWERDOWN "POWERDOWN State"
+ #define VL53L0_STRING_STATE_WAIT_STATICINIT \
+ "Wait for staticinit State"
+ #define VL53L0_STRING_STATE_STANDBY "STANDBY State"
+ #define VL53L0_STRING_STATE_IDLE "IDLE State"
+ #define VL53L0_STRING_STATE_RUNNING "RUNNING State"
+ #define VL53L0_STRING_STATE_UNKNOWN "UNKNOWN State"
+ #define VL53L0_STRING_STATE_ERROR "ERROR State"
+
+
+ /* Device Specific */
+ #define VL53L0_STRING_DEVICEERROR_NONE "No Update"
+ #define VL53L0_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE \
+ "VCSEL Continuity Test Failure"
+ #define VL53L0_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE \
+ "VCSEL Watchdog Test Failure"
+ #define VL53L0_STRING_DEVICEERROR_NOVHVVALUEFOUND \
+ "No VHV Value found"
+ #define VL53L0_STRING_DEVICEERROR_MSRCNOTARGET \
+ "MSRC No Target Error"
+ #define VL53L0_STRING_DEVICEERROR_SNRCHECK \
+ "SNR Check Exit"
+ #define VL53L0_STRING_DEVICEERROR_RANGEPHASECHECK \
+ "Range Phase Check Error"
+ #define VL53L0_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK \
+ "Sigma Threshold Check Error"
+ #define VL53L0_STRING_DEVICEERROR_TCC \
+ "TCC Error"
+ #define VL53L0_STRING_DEVICEERROR_PHASECONSISTENCY \
+ "Phase Consistency Error"
+ #define VL53L0_STRING_DEVICEERROR_MINCLIP \
+ "Min Clip Error"
+ #define VL53L0_STRING_DEVICEERROR_RANGECOMPLETE \
+ "Range Complete"
+ #define VL53L0_STRING_DEVICEERROR_ALGOUNDERFLOW \
+ "Range Algo Underflow Error"
+ #define VL53L0_STRING_DEVICEERROR_ALGOOVERFLOW \
+ "Range Algo Overlow Error"
+ #define VL53L0_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD \
+ "Range Ignore Threshold Error"
+ #define VL53L0_STRING_DEVICEERROR_UNKNOWN \
+ "Unknown error code"
+
+ /* Check Enable */
+ #define VL53L0_STRING_CHECKENABLE_SIGMA_FINAL_RANGE \
+ "SIGMA FINAL RANGE"
+ #define VL53L0_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE \
+ "SIGNAL RATE FINAL RANGE"
+ #define VL53L0_STRING_CHECKENABLE_SIGNAL_REF_CLIP \
+ "SIGNAL REF CLIP"
+ #define VL53L0_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD \
+ "RANGE IGNORE THRESHOLD"
+
+ /* Sequence Step */
+ #define VL53L0_STRING_SEQUENCESTEP_TCC "TCC"
+ #define VL53L0_STRING_SEQUENCESTEP_DSS "DSS"
+ #define VL53L0_STRING_SEQUENCESTEP_MSRC "MSRC"
+ #define VL53L0_STRING_SEQUENCESTEP_PRE_RANGE "PRE RANGE"
+ #define VL53L0_STRING_SEQUENCESTEP_FINAL_RANGE "FINAL RANGE"
+#endif /* USE_EMPTY_STRING */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L0/inc/vl53l0_def.h b/drivers/input/misc/vl53L0/inc/vl53l0_def.h
new file mode 100644
index 000000000000..2391242949ed
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l0_def.h
@@ -0,0 +1,637 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+/**
+ * @file VL53L0_def.h
+ *
+ * @brief Type definitions for VL53L0 API.
+ *
+ */
+
+
+#ifndef _VL53L0_DEF_H_
+#define _VL53L0_DEF_H_
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @defgroup VL53L0_globaldefine_group VL53L0 Defines
+ * @brief VL53L0 Defines
+ * @{
+ */
+
+
+/** PAL SPECIFICATION major version */
+#define VL53L010_SPECIFICATION_VER_MAJOR 1
+/** PAL SPECIFICATION minor version */
+#define VL53L010_SPECIFICATION_VER_MINOR 2
+/** PAL SPECIFICATION sub version */
+#define VL53L010_SPECIFICATION_VER_SUB 7
+/** PAL SPECIFICATION sub version */
+#define VL53L010_SPECIFICATION_VER_REVISION 1440
+
+/** VL53L0 PAL IMPLEMENTATION major version */
+#define VL53L010_IMPLEMENTATION_VER_MAJOR 1
+/** VL53L0 PAL IMPLEMENTATION minor version */
+#define VL53L010_IMPLEMENTATION_VER_MINOR 0
+/** VL53L0 PAL IMPLEMENTATION sub version */
+#define VL53L010_IMPLEMENTATION_VER_SUB 9
+/** VL53L0 PAL IMPLEMENTATION sub version */
+#define VL53L010_IMPLEMENTATION_VER_REVISION 3673
+
+/** PAL SPECIFICATION major version */
+#define VL53L0_SPECIFICATION_VER_MAJOR 1
+/** PAL SPECIFICATION minor version */
+#define VL53L0_SPECIFICATION_VER_MINOR 2
+/** PAL SPECIFICATION sub version */
+#define VL53L0_SPECIFICATION_VER_SUB 7
+/** PAL SPECIFICATION sub version */
+#define VL53L0_SPECIFICATION_VER_REVISION 1440
+
+/** VL53L0 PAL IMPLEMENTATION major version */
+#define VL53L0_IMPLEMENTATION_VER_MAJOR 1
+/** VL53L0 PAL IMPLEMENTATION minor version */
+#define VL53L0_IMPLEMENTATION_VER_MINOR 1
+/** VL53L0 PAL IMPLEMENTATION sub version */
+#define VL53L0_IMPLEMENTATION_VER_SUB 18
+/** VL53L0 PAL IMPLEMENTATION sub version */
+#define VL53L0_IMPLEMENTATION_VER_REVISION 4357
+#define VL53L0_DEFAULT_MAX_LOOP 200
+#define VL53L0_MAX_STRING_LENGTH 32
+
+
+#include "vl53l0_device.h"
+#include "vl53l0_types.h"
+
+
+/****************************************
+ * PRIVATE define do not edit
+ ****************************************/
+
+/** @brief Defines the parameters of the Get Version Functions
+ */
+typedef struct {
+ uint32_t revision; /*!< revision number */
+ uint8_t major; /*!< major number */
+ uint8_t minor; /*!< minor number */
+ uint8_t build; /*!< build number */
+} VL53L0_Version_t;
+
+
+/** @brief Defines the parameters of the Get Device Info Functions
+ */
+typedef struct {
+ char Name[VL53L0_MAX_STRING_LENGTH];
+ /*!< Name of the Device e.g. Left_Distance */
+ char Type[VL53L0_MAX_STRING_LENGTH];
+ /*!< Type of the Device e.g VL53L0 */
+ char ProductId[VL53L0_MAX_STRING_LENGTH];
+ /*!< Product Identifier String */
+ uint8_t ProductType;
+ /*!< Product Type, VL53L0 = 1, VL53L1 = 2 */
+ uint8_t ProductRevisionMajor;
+ /*!< Product revision major */
+ uint8_t ProductRevisionMinor;
+ /*!< Product revision minor */
+} VL53L0_DeviceInfo_t;
+
+
+/** @defgroup VL53L0_define_Error_group Error and Warning code returned by API
+ * The following DEFINE are used to identify the PAL ERROR
+ * @{
+ */
+
+typedef int8_t VL53L0_Error;
+
+#define VL53L0_ERROR_NONE ((VL53L0_Error) 0)
+#define VL53L0_ERROR_CALIBRATION_WARNING ((VL53L0_Error) - 1)
+ /*!< Warning invalid calibration data may be in used
+ \a VL53L0_InitData()
+ \a VL53L0_GetOffsetCalibrationData
+ \a VL53L0_SetOffsetCalibrationData */
+#define VL53L0_ERROR_MIN_CLIPPED ((VL53L0_Error) - 2)
+ /*!< Warning parameter passed was clipped to min before to be applied */
+
+#define VL53L0_ERROR_UNDEFINED ((VL53L0_Error) - 3)
+ /*!< Unqualified error */
+#define VL53L0_ERROR_INVALID_PARAMS ((VL53L0_Error) - 4)
+ /*!< Parameter passed is invalid or out of range */
+#define VL53L0_ERROR_NOT_SUPPORTED ((VL53L0_Error) - 5)
+ /*!< Function is not supported in current mode or configuration */
+#define VL53L0_ERROR_RANGE_ERROR ((VL53L0_Error) - 6)
+ /*!< Device report a ranging error interrupt status */
+#define VL53L0_ERROR_TIME_OUT ((VL53L0_Error) - 7)
+ /*!< Aborted due to time out */
+#define VL53L0_ERROR_MODE_NOT_SUPPORTED ((VL53L0_Error) - 8)
+ /*!< Asked mode is not supported by the device */
+#define VL53L0_ERROR_BUFFER_TOO_SMALL ((VL53L0_Error) - 9)
+ /*!< ... */
+#define VL53L0_ERROR_GPIO_NOT_EXISTING ((VL53L0_Error) - 10)
+ /*!< User tried to setup a non-existing GPIO pin */
+#define VL53L0_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED ((VL53L0_Error) - 11)
+ /*!< unsupported GPIO functionality */
+#define VL53L0_ERROR_CONTROL_INTERFACE ((VL53L0_Error) - 20)
+ /*!< error reported from IO functions */
+#define VL53L0_ERROR_INVALID_COMMAND ((VL53L0_Error) - 30)
+ /*!< The command is not allowed in the current device state
+ * (power down) */
+#define VL53L0_ERROR_DIVISION_BY_ZERO ((VL53L0_Error) - 40)
+ /*!< In the function a division by zero occurs */
+#define VL53L0_ERROR_REF_SPAD_INIT ((VL53L0_Error) - 50)
+ /*!< Error during reference SPAD initialization */
+#define VL53L0_ERROR_NOT_IMPLEMENTED ((VL53L0_Error) - 99)
+ /*!< Tells requested functionality has not been implemented yet or
+ * not compatible with the device */
+/** @} VL53L0_define_Error_group */
+
+
+/** @defgroup VL53L0_define_DeviceModes_group Defines Device modes
+ * Defines all possible modes for the device
+ * @{
+ */
+typedef uint8_t VL53L0_DeviceModes;
+
+#define VL53L0_DEVICEMODE_SINGLE_RANGING ((VL53L0_DeviceModes) 0)
+#define VL53L0_DEVICEMODE_CONTINUOUS_RANGING ((VL53L0_DeviceModes) 1)
+#define VL53L0_DEVICEMODE_SINGLE_HISTOGRAM ((VL53L0_DeviceModes) 2)
+#define VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING ((VL53L0_DeviceModes) 3)
+#define VL53L0_DEVICEMODE_SINGLE_ALS ((VL53L0_DeviceModes) 10)
+#define VL53L0_DEVICEMODE_GPIO_DRIVE ((VL53L0_DeviceModes) 20)
+#define VL53L0_DEVICEMODE_GPIO_OSC ((VL53L0_DeviceModes) 21)
+ /* ... Modes to be added depending on device */
+/** @} VL53L0_define_DeviceModes_group */
+
+
+
+/** @defgroup VL53L0_define_HistogramModes_group Defines Histogram modes
+ * Defines all possible Histogram modes for the device
+ * @{
+ */
+typedef uint8_t VL53L0_HistogramModes;
+
+#define VL53L0_HISTOGRAMMODE_DISABLED ((VL53L0_HistogramModes) 0)
+ /*!< Histogram Disabled */
+#define VL53L0_HISTOGRAMMODE_REFERENCE_ONLY ((VL53L0_HistogramModes) 1)
+ /*!< Histogram Reference array only */
+#define VL53L0_HISTOGRAMMODE_RETURN_ONLY ((VL53L0_HistogramModes) 2)
+ /*!< Histogram Return array only */
+#define VL53L0_HISTOGRAMMODE_BOTH ((VL53L0_HistogramModes) 3)
+ /*!< Histogram both Reference and Return Arrays */
+ /* ... Modes to be added depending on device */
+/** @} VL53L0_define_HistogramModes_group */
+
+
+/** @defgroup VL53L0_define_PowerModes_group List of available Power Modes
+ * List of available Power Modes
+ * @{
+ */
+
+typedef uint8_t VL53L0_PowerModes;
+
+#define VL53L0_POWERMODE_STANDBY_LEVEL1 ((VL53L0_PowerModes) 0)
+ /*!< Standby level 1 */
+#define VL53L0_POWERMODE_STANDBY_LEVEL2 ((VL53L0_PowerModes) 1)
+ /*!< Standby level 2 */
+#define VL53L0_POWERMODE_IDLE_LEVEL1 ((VL53L0_PowerModes) 2)
+ /*!< Idle level 1 */
+#define VL53L0_POWERMODE_IDLE_LEVEL2 ((VL53L0_PowerModes) 3)
+ /*!< Idle level 2 */
+
+/** @} VL53L0_define_PowerModes_group */
+
+
+/** @brief Defines all parameters for the device
+ */
+typedef struct {
+ VL53L0_DeviceModes DeviceMode;
+ /*!< Defines type of measurement to be done for the next measure */
+ VL53L0_HistogramModes HistogramMode;
+ /*!< Defines type of histogram measurement to be done for the next
+ * measure */
+ uint32_t MeasurementTimingBudgetMicroSeconds;
+ /*!< Defines the allowed total time for a single measurement */
+ uint32_t InterMeasurementPeriodMilliSeconds;
+ /*!< Defines time between two consecutive measurements (between two
+ * measurement starts). If set to 0 means back-to-back mode */
+ uint8_t XTalkCompensationEnable;
+ /*!< Tells if Crosstalk compensation shall be enable or not */
+ uint16_t XTalkCompensationRangeMilliMeter;
+ /*!< CrossTalk compensation range in millimeter */
+ FixPoint1616_t XTalkCompensationRateMegaCps;
+ /*!< CrossTalk compensation rate in Mega counts per seconds.
+ * Expressed in 16.16 fixed point format. */
+ int32_t RangeOffsetMicroMeters;
+ /*!< Range offset adjustment (mm). */
+
+ uint8_t LimitChecksEnable[VL53L0_CHECKENABLE_NUMBER_OF_CHECKS];
+ /*!< This Array store all the Limit Check enable for this device. */
+ uint8_t LimitChecksStatus[VL53L0_CHECKENABLE_NUMBER_OF_CHECKS];
+ /*!< This Array store all the Status of the check linked to last
+ * measurement. */
+ FixPoint1616_t LimitChecksValue[VL53L0_CHECKENABLE_NUMBER_OF_CHECKS];
+ /*!< This Array store all the Limit Check value for this device */
+
+ uint8_t WrapAroundCheckEnable;
+ /*!< Tells if Wrap Around Check shall be enable or not */
+} VL53L0_DeviceParameters_t;
+
+
+/** @defgroup VL53L0_define_State_group Defines the current status of the device
+ * Defines the current status of the device
+ * @{
+ */
+
+typedef uint8_t VL53L0_State;
+
+#define VL53L0_STATE_POWERDOWN ((VL53L0_State) 0)
+ /*!< Device is in HW reset */
+#define VL53L0_STATE_WAIT_STATICINIT ((VL53L0_State) 1)
+ /*!< Device is initialized and wait for static initialization */
+#define VL53L0_STATE_STANDBY ((VL53L0_State) 2)
+ /*!< Device is in Low power Standby mode */
+#define VL53L0_STATE_IDLE ((VL53L0_State) 3)
+ /*!< Device has been initialized and ready to do measurements */
+#define VL53L0_STATE_RUNNING ((VL53L0_State) 4)
+ /*!< Device is performing measurement */
+#define VL53L0_STATE_UNKNOWN ((VL53L0_State) 98)
+ /*!< Device is in unknown state and need to be rebooted */
+#define VL53L0_STATE_ERROR ((VL53L0_State) 99)
+ /*!< Device is in error state and need to be rebooted */
+
+/** @} VL53L0_define_State_group */
+
+
+/** @brief Structure containing the Dmax computation parameters and data
+ */
+typedef struct {
+ int32_t AmbTuningWindowFactor_K;
+ /*!< internal algo tuning (*1000) */
+ int32_t RetSignalAt0mm;
+ /*!< intermediate dmax computation value caching */
+} VL53L0_DMaxData_t;
+
+/**
+ * @struct VL53L0_RangeData_t
+ * @brief Range measurement data.
+ */
+typedef struct {
+ uint32_t TimeStamp; /*!< 32-bit time stamp. */
+ uint32_t MeasurementTimeUsec;
+ /*!< Give the Measurement time needed by the device to do the
+ * measurement.*/
+
+
+ uint16_t RangeMilliMeter; /*!< range distance in millimeter. */
+
+ uint16_t RangeDMaxMilliMeter;
+ /*!< Tells what is the maximum detection distance of the device
+ * in current setup and environment conditions (Filled when
+ * applicable) */
+
+ FixPoint1616_t SignalRateRtnMegaCps;
+ /*!< Return signal rate (MCPS)\n these is a 16.16 fix point
+ * value, which is effectively a measure of target
+ * reflectance.*/
+ FixPoint1616_t AmbientRateRtnMegaCps;
+ /*!< Return ambient rate (MCPS)\n these is a 16.16 fix point
+ * value, which is effectively a measure of the ambien
+ * t light.*/
+
+ uint16_t EffectiveSpadRtnCount;
+ /*!< Return the effective SPAD count for the return signal.
+ * To obtain Real value it should be divided by 256 */
+
+ uint8_t ZoneId;
+ /*!< Denotes which zone and range scheduler stage the range
+ * data relates to. */
+ uint8_t RangeFractionalPart;
+ /*!< Fractional part of range distance. Final value is a
+ * FixPoint168 value. */
+ uint8_t RangeStatus;
+ /*!< Range Status for the current measurement. This is device
+ * dependent. Value = 0 means value is valid.
+ * See \ref RangeStatusPage */
+ FixPoint1616_t SigmaEstimate;
+} VL53L0_RangingMeasurementData_t;
+
+
+#define VL53L0_HISTOGRAM_BUFFER_SIZE 24
+
+/**
+ * @struct VL53L0_HistogramData_t
+ * @brief Histogram measurement data.
+ */
+typedef struct {
+ /* Histogram Measurement data */
+ uint32_t HistogramData[VL53L0_HISTOGRAM_BUFFER_SIZE];
+ /*!< Histogram data */
+ uint8_t HistogramType; /*!< Indicate the types of histogram data :
+ Return only, Reference only, both Return and Reference */
+ uint8_t FirstBin; /*!< First Bin value */
+ uint8_t BufferSize; /*!< Buffer Size - Set by the user.*/
+ uint8_t NumberOfBins;
+ /*!< Number of bins filled by the histogram measurement */
+
+ VL53L0_DeviceError ErrorStatus;
+ /*!< Error status of the current measurement. \n
+ see @a ::VL53L0_DeviceError @a VL53L0_GetStatusErrorString() */
+} VL53L0_HistogramMeasurementData_t;
+
+#define VL53L0_REF_SPAD_BUFFER_SIZE 6
+
+/**
+ * @struct VL53L0_SpadData_t
+ * @brief Spad Configuration Data.
+ */
+typedef struct {
+ uint8_t RefSpadEnables[VL53L0_REF_SPAD_BUFFER_SIZE];
+ /*!< Reference Spad Enables */
+ uint8_t RefGoodSpadMap[VL53L0_REF_SPAD_BUFFER_SIZE];
+ /*!< Reference Spad Good Spad Map */
+} VL53L0_SpadData_t;
+
+typedef struct {
+ FixPoint1616_t OscFrequencyMHz; /* Frequency used */
+
+ uint16_t LastEncodedTimeout;
+ /* last encoded Time out used for timing budget*/
+
+ VL53L0_GpioFunctionality Pin0GpioFunctionality;
+ /* store the functionality of the GPIO: pin0 */
+
+ uint32_t FinalRangeTimeoutMicroSecs;
+ /*!< Execution time of the final range*/
+ uint8_t FinalRangeVcselPulsePeriod;
+ /*!< Vcsel pulse period (pll clocks) for the final range measurement*/
+ uint32_t PreRangeTimeoutMicroSecs;
+ /*!< Execution time of the final range*/
+ uint8_t PreRangeVcselPulsePeriod;
+ /*!< Vcsel pulse period (pll clocks) for the pre-range measurement*/
+
+ uint16_t SigmaEstRefArray;
+ /*!< Reference array sigma value in 1/100th of [mm] e.g. 100 = 1mm */
+ uint16_t SigmaEstEffPulseWidth;
+ /*!< Effective Pulse width for sigma estimate in 1/100th
+ * of ns e.g. 900 = 9.0ns */
+ uint16_t SigmaEstEffAmbWidth;
+ /*!< Effective Ambient width for sigma estimate in 1/100th of ns
+ * e.g. 500 = 5.0ns */
+
+
+ uint8_t ReadDataFromDeviceDone; /* Indicate if read from device has
+ been done (==1) or not (==0) */
+ uint8_t ModuleId; /* Module ID */
+ uint8_t Revision; /* test Revision */
+ char ProductId[VL53L0_MAX_STRING_LENGTH];
+ /* Product Identifier String */
+ uint8_t ReferenceSpadCount; /* used for ref spad management */
+ uint8_t ReferenceSpadType; /* used for ref spad management */
+ uint8_t RefSpadsInitialised; /* reports if ref spads are initialised. */
+ uint32_t PartUIDUpper; /*!< Unique Part ID Upper */
+ uint32_t PartUIDLower; /*!< Unique Part ID Lower */
+ FixPoint1616_t SignalRateMeasFixed400mm; /*!< Peek Signal rate
+ at 400 mm*/
+
+} VL53L0_DeviceSpecificParameters_t;
+
+/**
+ * @struct VL53L0_DevData_t
+ *
+ * @brief VL53L0 PAL device ST private data structure \n
+ * End user should never access any of these field directly
+ *
+ * These must never access directly but only via macro
+ */
+typedef struct {
+ VL53L0_DMaxData_t DMaxData;
+ /*!< Dmax Data */
+ int32_t Part2PartOffsetNVMMicroMeter;
+ /*!< backed up NVM value */
+ int32_t Part2PartOffsetAdjustmentNVMMicroMeter;
+ /*!< backed up NVM value representing additional offset adjustment */
+ VL53L0_DeviceParameters_t CurrentParameters;
+ /*!< Current Device Parameter */
+ VL53L0_RangingMeasurementData_t LastRangeMeasure;
+ /*!< Ranging Data */
+ VL53L0_HistogramMeasurementData_t LastHistogramMeasure;
+ /*!< Histogram Data */
+ VL53L0_DeviceSpecificParameters_t DeviceSpecificParameters;
+ /*!< Parameters specific to the device */
+ VL53L0_SpadData_t SpadData;
+ /*!< Spad Data */
+ uint8_t SequenceConfig;
+ /*!< Internal value for the sequence config */
+ uint8_t RangeFractionalEnable;
+ /*!< Enable/Disable fractional part of ranging data */
+ VL53L0_State PalState;
+ /*!< Current state of the PAL for this device */
+ VL53L0_PowerModes PowerMode;
+ /*!< Current Power Mode */
+ uint16_t SigmaEstRefArray;
+ /*!< Reference array sigma value in 1/100th of [mm] e.g. 100 = 1mm */
+ uint16_t SigmaEstEffPulseWidth;
+ /*!< Effective Pulse width for sigma estimate in 1/100th
+ * of ns e.g. 900 = 9.0ns */
+ uint16_t SigmaEstEffAmbWidth;
+ /*!< Effective Ambient width for sigma estimate in 1/100th of ns
+ * e.g. 500 = 5.0ns */
+ uint16_t targetRefRate;
+ /*!< Target Ambient Rate for Ref spad management */
+ FixPoint1616_t SigmaEstimate;
+ /*!< Sigma Estimate - based on ambient & VCSEL rates and
+ * signal_total_events */
+ FixPoint1616_t SignalEstimate;
+ /*!< Signal Estimate - based on ambient & VCSEL rates and cross talk */
+ FixPoint1616_t LastSignalRefMcps;
+ /*!< Latest Signal ref in Mcps */
+ uint8_t *pTuningSettingsPointer;
+ /*!< Pointer for Tuning Settings table */
+ uint8_t UseInternalTuningSettings;
+ /*!< Indicate if we use Tuning Settings table */
+ uint16_t LinearityCorrectiveGain;
+ /*!< Linearity Corrective Gain value in x1000 */
+ uint16_t DmaxCalRangeMilliMeter;
+ /*!< Dmax Calibration Range millimeter */
+ FixPoint1616_t DmaxCalSignalRateRtnMegaCps;
+ /*!< Dmax Calibration Signal Rate Return MegaCps */
+
+} VL53L0_DevData_t;
+
+
+/** @defgroup VL53L0_define_InterruptPolarity_group Defines the Polarity
+ * of the Interrupt
+ * Defines the Polarity of the Interrupt
+ * @{
+ */
+typedef uint8_t VL53L0_InterruptPolarity;
+
+#define VL53L0_INTERRUPTPOLARITY_LOW ((VL53L0_InterruptPolarity) 0)
+/*!< Set active low polarity best setup for falling edge. */
+#define VL53L0_INTERRUPTPOLARITY_HIGH ((VL53L0_InterruptPolarity) 1)
+/*!< Set active high polarity best setup for rising edge. */
+
+/** @} VL53L0_define_InterruptPolarity_group */
+
+
+/** @defgroup VL53L0_define_VcselPeriod_group Vcsel Period Defines
+ * Defines the range measurement for which to access the vcsel period.
+ * @{
+ */
+typedef uint8_t VL53L0_VcselPeriod;
+
+#define VL53L0_VCSEL_PERIOD_PRE_RANGE ((VL53L0_VcselPeriod) 0)
+/*!>9)&0xFFFF)
+#define VL53L0_FIXPOINT97TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<9)
+
+#define VL53L0_FIXPOINT1616TOFIXPOINT88(Value) \
+ (uint16_t)((Value>>8)&0xFFFF)
+#define VL53L0_FIXPOINT88TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<8)
+
+#define VL53L0_FIXPOINT1616TOFIXPOINT412(Value) \
+ (uint16_t)((Value>>4)&0xFFFF)
+#define VL53L0_FIXPOINT412TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<4)
+
+#define VL53L0_FIXPOINT1616TOFIXPOINT313(Value) \
+ (uint16_t)((Value>>3)&0xFFFF)
+#define VL53L0_FIXPOINT313TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<3)
+
+#define VL53L0_FIXPOINT1616TOFIXPOINT08(Value) \
+ (uint8_t)((Value>>8)&0x00FF)
+#define VL53L0_FIXPOINT08TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<8)
+
+#define VL53L0_FIXPOINT1616TOFIXPOINT53(Value) \
+ (uint8_t)((Value>>13)&0x00FF)
+#define VL53L0_FIXPOINT53TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<13)
+
+#define VL53L0_FIXPOINT1616TOFIXPOINT102(Value) \
+ (uint16_t)((Value>>14)&0x0FFF)
+#define VL53L0_FIXPOINT102TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<12)
+
+#define VL53L0_MAKEUINT16(lsb, msb) (uint16_t)((((uint16_t)msb)<<8) + \
+ (uint16_t)lsb)
+
+/** @} VL53L0_define_GeneralMacro_group */
+
+/** @} VL53L0_globaldefine_group */
+
+
+
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _VL53L0_DEF_H_ */
diff --git a/drivers/input/misc/vl53L0/inc/vl53l0_device.h b/drivers/input/misc/vl53L0/inc/vl53l0_device.h
new file mode 100644
index 000000000000..ee724a20e2ad
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l0_device.h
@@ -0,0 +1,255 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+/**
+ * Device specific defines. To be adapted by implementer for the targeted
+ * device.
+ */
+
+#ifndef _VL53L0_DEVICE_H_
+#define _VL53L0_DEVICE_H_
+
+#include "vl53l0_types.h"
+
+
+/** @defgroup VL53L0_DevSpecDefines_group VL53L0 cut1.1 Device Specific Defines
+ * @brief VL53L0 cut1.1 Device Specific Defines
+ * @{
+ */
+
+
+/** @defgroup VL53L0_DeviceError_group Device Error
+ * @brief Device Error code
+ *
+ * This enum is Device specific it should be updated in the implementation
+ * Use @a VL53L0_GetStatusErrorString() to get the string.
+ * It is related to Status Register of the Device.
+ * @{
+ */
+typedef uint8_t VL53L0_DeviceError;
+
+#define VL53L0_DEVICEERROR_NONE ((VL53L0_DeviceError) 0)
+ /*!< 0 NoError */
+#define VL53L0_DEVICEERROR_VCSELCONTINUITYTESTFAILURE ((VL53L0_DeviceError) 1)
+#define VL53L0_DEVICEERROR_VCSELWATCHDOGTESTFAILURE ((VL53L0_DeviceError) 2)
+#define VL53L0_DEVICEERROR_NOVHVVALUEFOUND ((VL53L0_DeviceError) 3)
+#define VL53L0_DEVICEERROR_MSRCNOTARGET ((VL53L0_DeviceError) 4)
+#define VL53L0_DEVICEERROR_SNRCHECK ((VL53L0_DeviceError) 5)
+#define VL53L0_DEVICEERROR_RANGEPHASECHECK ((VL53L0_DeviceError) 6)
+#define VL53L0_DEVICEERROR_SIGMATHRESHOLDCHECK ((VL53L0_DeviceError) 7)
+#define VL53L0_DEVICEERROR_TCC ((VL53L0_DeviceError) 8)
+#define VL53L0_DEVICEERROR_PHASECONSISTENCY ((VL53L0_DeviceError) 9)
+#define VL53L0_DEVICEERROR_MINCLIP ((VL53L0_DeviceError) 10)
+#define VL53L0_DEVICEERROR_RANGECOMPLETE ((VL53L0_DeviceError) 11)
+#define VL53L0_DEVICEERROR_ALGOUNDERFLOW ((VL53L0_DeviceError) 12)
+#define VL53L0_DEVICEERROR_ALGOOVERFLOW ((VL53L0_DeviceError) 13)
+#define VL53L0_DEVICEERROR_RANGEIGNORETHRESHOLD ((VL53L0_DeviceError) 14)
+
+/** @} end of VL53L0_DeviceError_group */
+
+
+/** @defgroup VL53L0_CheckEnable_group Check Enable list
+ * @brief Check Enable code
+ *
+ * Define used to specify the LimitCheckId.
+ * Use @a VL53L0_GetLimitCheckInfo() to get the string.
+ * @{
+ */
+
+#define VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE 0
+#define VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE 1
+#define VL53L0_CHECKENABLE_SIGNAL_REF_CLIP 2
+#define VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD 3
+
+#define VL53L0_CHECKENABLE_NUMBER_OF_CHECKS 4
+
+/** @} end of VL53L0_CheckEnable_group */
+
+
+/** @defgroup VL53L0_GpioFunctionality_group Gpio Functionality
+ * @brief Defines the different functionalities for the device GPIO(s)
+ * @{
+ */
+typedef uint8_t VL53L0_GpioFunctionality;
+
+#define VL53L0_GPIOFUNCTIONALITY_OFF \
+ ((VL53L0_GpioFunctionality) 0) /*!< NO Interrupt */
+#define VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW \
+ ((VL53L0_GpioFunctionality) 1) /*!< Level Low (value < thresh_low) */
+#define VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH \
+ ((VL53L0_GpioFunctionality) 2) /*!< Level High (value > thresh_high) */
+#define VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT \
+ ((VL53L0_GpioFunctionality) 3)
+ /*!< Out Of Window (value < thresh_low OR value > thresh_high) */
+#define VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY \
+ ((VL53L0_GpioFunctionality) 4) /*!< New Sample Ready */
+
+/** @} end of VL53L0_GpioFunctionality_group */
+
+
+/* Device register map */
+
+/** @defgroup VL53L0_DefineRegisters_group Define Registers
+ * @brief List of all the defined registers
+ * @{
+ */
+#define VL53L0_REG_SYSRANGE_START 0x000
+ /** mask existing bit in #VL53L0_REG_SYSRANGE_START*/
+ #define VL53L0_REG_SYSRANGE_MODE_MASK 0x0F
+ /** bit 0 in #VL53L0_REG_SYSRANGE_START write 1 toggle state in
+ * continuous mode and arm next shot in single shot mode */
+ #define VL53L0_REG_SYSRANGE_MODE_START_STOP 0x01
+ /** bit 1 write 0 in #VL53L0_REG_SYSRANGE_START set single shot mode */
+ #define VL53L0_REG_SYSRANGE_MODE_SINGLESHOT 0x00
+ /** bit 1 write 1 in #VL53L0_REG_SYSRANGE_START set back-to-back
+ * operation mode */
+ #define VL53L0_REG_SYSRANGE_MODE_BACKTOBACK 0x02
+ /** bit 2 write 1 in #VL53L0_REG_SYSRANGE_START set timed operation
+ * mode */
+ #define VL53L0_REG_SYSRANGE_MODE_TIMED 0x04
+ /** bit 3 write 1 in #VL53L0_REG_SYSRANGE_START set histogram operation
+ * mode */
+ #define VL53L0_REG_SYSRANGE_MODE_HISTOGRAM 0x08
+
+
+#define VL53L0_REG_SYSTEM_THRESH_HIGH 0x000C
+#define VL53L0_REG_SYSTEM_THRESH_LOW 0x000E
+
+
+#define VL53L0_REG_SYSTEM_SEQUENCE_CONFIG 0x0001
+#define VL53L0_REG_SYSTEM_RANGE_CONFIG 0x0009
+#define VL53L0_REG_SYSTEM_INTERMEASUREMENT_PERIOD 0x0004
+
+
+#define VL53L0_REG_SYSTEM_INTERRUPT_CONFIG_GPIO 0x000A
+ #define VL53L0_REG_SYSTEM_INTERRUPT_GPIO_DISABLED 0x00
+ #define VL53L0_REG_SYSTEM_INTERRUPT_GPIO_LEVEL_LOW 0x01
+ #define VL53L0_REG_SYSTEM_INTERRUPT_GPIO_LEVEL_HIGH 0x02
+ #define VL53L0_REG_SYSTEM_INTERRUPT_GPIO_OUT_OF_WINDOW 0x03
+ #define VL53L0_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY 0x04
+
+#define VL53L0_REG_GPIO_HV_MUX_ACTIVE_HIGH 0x0084
+
+
+#define VL53L0_REG_SYSTEM_INTERRUPT_CLEAR 0x000B
+
+/* Result registers */
+#define VL53L0_REG_RESULT_INTERRUPT_STATUS 0x0013
+#define VL53L0_REG_RESULT_RANGE_STATUS 0x0014
+
+#define VL53L0_REG_RESULT_CORE_PAGE 1
+#define VL53L0_REG_RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN 0x00BC
+#define VL53L0_REG_RESULT_CORE_RANGING_TOTAL_EVENTS_RTN 0x00C0
+#define VL53L0_REG_RESULT_CORE_AMBIENT_WINDOW_EVENTS_REF 0x00D0
+#define VL53L0_REG_RESULT_CORE_RANGING_TOTAL_EVENTS_REF 0x00D4
+#define VL53L0_REG_RESULT_PEAK_SIGNAL_RATE_REF 0x00B6
+
+/* Algo register */
+
+#define VL53L0_REG_ALGO_PART_TO_PART_RANGE_OFFSET_MM 0x0028
+
+#define VL53L0_REG_I2C_SLAVE_DEVICE_ADDRESS 0x008a
+
+/* Check Limit registers */
+#define VL53L0_REG_MSRC_CONFIG_CONTROL 0x0060
+
+#define VL53L0_REG_PRE_RANGE_CONFIG_MIN_SNR 0X0027
+#define VL53L0_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW 0x0056
+#define VL53L0_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH 0x0057
+#define VL53L0_REG_PRE_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT 0x0064
+
+#define VL53L0_REG_FINAL_RANGE_CONFIG_MIN_SNR 0X0067
+#define VL53L0_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW 0x0047
+#define VL53L0_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH 0x0048
+#define VL53L0_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT 0x0044
+
+
+#define VL53L0_REG_PRE_RANGE_CONFIG_SIGMA_THRESH_HI 0X0061
+#define VL53L0_REG_PRE_RANGE_CONFIG_SIGMA_THRESH_LO 0X0062
+
+/* PRE RANGE registers */
+#define VL53L0_REG_PRE_RANGE_CONFIG_VCSEL_PERIOD 0x0050
+#define VL53L0_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI 0x0051
+#define VL53L0_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_LO 0x0052
+
+#define VL53L0_REG_SYSTEM_HISTOGRAM_BIN 0x0081
+#define VL53L0_REG_HISTOGRAM_CONFIG_INITIAL_PHASE_SELECT 0x0033
+#define VL53L0_REG_HISTOGRAM_CONFIG_READOUT_CTRL 0x0055
+
+#define VL53L0_REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD 0x0070
+#define VL53L0_REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI 0x0071
+#define VL53L0_REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_LO 0x0072
+#define VL53L0_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MCPS 0x0020
+
+#define VL53L0_REG_MSRC_CONFIG_TIMEOUT_MACROP 0x0046
+
+
+#define VL53L0_REG_SOFT_RESET_GO2_SOFT_RESET_N 0x00bf
+#define VL53L0_REG_IDENTIFICATION_MODEL_ID 0x00c0
+#define VL53L0_REG_IDENTIFICATION_REVISION_ID 0x00c2
+
+#define VL53L0_REG_OSC_CALIBRATE_VAL 0x00f8
+
+
+#define VL53L0_SIGMA_ESTIMATE_MAX_VALUE 65535
+/* equivalent to a range sigma of 655.35mm */
+
+#define VL53L0_REG_GLOBAL_CONFIG_VCSEL_WIDTH 0x032
+#define VL53L0_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0 0x0B0
+#define VL53L0_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_1 0x0B1
+#define VL53L0_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_2 0x0B2
+#define VL53L0_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_3 0x0B3
+#define VL53L0_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_4 0x0B4
+#define VL53L0_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_5 0x0B5
+
+#define VL53L0_REG_GLOBAL_CONFIG_REF_EN_START_SELECT 0xB6
+#define VL53L0_REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD 0x4E /* 0x14E */
+#define VL53L0_REG_DYNAMIC_SPAD_REF_EN_START_OFFSET 0x4F /* 0x14F */
+#define VL53L0_REG_POWER_MANAGEMENT_GO1_POWER_FORCE 0x80
+
+/*
+ * Speed of light in um per 1E-10 Seconds
+ */
+
+#define VL53L0_SPEED_OF_LIGHT_IN_AIR 2997
+
+#define VL53L0_REG_VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV 0x0089
+
+#define VL53L0_REG_ALGO_PHASECAL_LIM 0x0030 /* 0x130 */
+#define VL53L0_REG_ALGO_PHASECAL_CONFIG_TIMEOUT 0x0030
+
+/** @} VL53L0_DefineRegisters_group */
+
+/** @} VL53L0_DevSpecDefines_group */
+
+
+#endif
+
+/* _VL53L0_DEVICE_H_ */
+
+
diff --git a/drivers/input/misc/vl53L0/inc/vl53l0_i2c_platform.h b/drivers/input/misc/vl53L0/inc/vl53l0_i2c_platform.h
new file mode 100644
index 000000000000..9b1bdd7f3c54
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l0_i2c_platform.h
@@ -0,0 +1,402 @@
+/*
+ * vl53l0_i2c_platform.h - Linux kernel modules for STM VL53L0 FlightSense TOF
+ * sensor
+ *
+ * Copyright (C) 2016 STMicroelectronics Imaging Division.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+/**
+ * @file VL53L0_i2c_platform.h
+ * @brief Function prototype definitions for EWOK Platform layer.
+ *
+ */
+
+
+#ifndef _VL53L0_I2C_PLATFORM_H_
+#define _VL53L0_I2C_PLATFORM_H_
+
+#include "vl53l0_def.h"
+
+
+/** Maximum buffer size to be used in i2c */
+#define VL53L0_MAX_I2C_XFER_SIZE 64
+
+/**
+ * @brief Typedef defining .\n
+ * The developer should modify this to suit the platform being deployed.
+ *
+ */
+
+/**
+ * @brief Typedef defining 8 bit unsigned char type.\n
+ * The developer should modify this to suit the platform being deployed.
+ *
+ */
+
+#ifndef bool_t
+typedef unsigned char bool_t;
+#endif
+
+
+#define I2C 0x01
+#define SPI 0x00
+
+#define COMMS_BUFFER_SIZE 64
+/*MUST be the same size as the SV task buffer */
+
+#define BYTES_PER_WORD 2
+#define BYTES_PER_DWORD 4
+
+#define VL53L0_MAX_STRING_LENGTH_PLT 256
+
+/**
+ * @brief Initialise platform comms.
+ *
+ * @param comms_type - selects between I2C and SPI
+ * @param comms_speed_khz - unsigned short containing the I2C speed in kHz
+ *
+ * @return status - status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_comms_initialise(uint8_t comms_type,
+ uint16_t comms_speed_khz);
+
+/**
+ * @brief Close platform comms.
+ *
+ * @return status - status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_comms_close(void);
+
+/**
+ * @brief Cycle Power to Device
+ *
+ * @return status - status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_cycle_power(void);
+
+int32_t VL53L0_set_page(VL53L0_DEV dev, uint8_t page_data);
+
+/**
+ * @brief Writes the supplied byte buffer to the device
+ *
+ * Wrapper for SystemVerilog Write Multi task
+ *
+ * @code
+ *
+ * Example:
+ *
+ * uint8_t *spad_enables;
+ *
+ * int status = VL53L0_write_multi(RET_SPAD_EN_0, spad_enables, 36);
+ *
+ * @endcode
+ *
+ * @param address - uint8_t device address value
+ * @param index - uint8_t register index value
+ * @param pdata - pointer to uint8_t buffer containing the data to be written
+ * @param count - number of bytes in the supplied byte buffer
+ *
+ * @return status - SystemVerilog status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_write_multi(VL53L0_DEV dev, uint8_t index, uint8_t *pdata,
+ int32_t count);
+
+
+/**
+ * @brief Reads the requested number of bytes from the device
+ *
+ * Wrapper for SystemVerilog Read Multi task
+ *
+ * @code
+ *
+ * Example:
+ *
+ * uint8_t buffer[COMMS_BUFFER_SIZE];
+ *
+ * int status = status = VL53L0_read_multi(DEVICE_ID, buffer, 2)
+ *
+ * @endcode
+ *
+ * @param address - uint8_t device address value
+ * @param index - uint8_t register index value
+ * @param pdata - pointer to the uint8_t buffer to store read data
+ * @param count - number of uint8_t's to read
+ *
+ * @return status - SystemVerilog status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_read_multi(VL53L0_DEV dev, uint8_t index, uint8_t *pdata,
+ int32_t count);
+
+
+/**
+ * @brief Writes a single byte to the device
+ *
+ * Wrapper for SystemVerilog Write Byte task
+ *
+ * @code
+ *
+ * Example:
+ *
+ * uint8_t page_number = MAIN_SELECT_PAGE;
+ *
+ * int status = VL53L0_write_byte(PAGE_SELECT, page_number);
+ *
+ * @endcode
+ *
+ * @param address - uint8_t device address value
+ * @param index - uint8_t register index value
+ * @param data - uint8_t data value to write
+ *
+ * @return status - SystemVerilog status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_write_byte(VL53L0_DEV dev, uint8_t index, uint8_t data);
+
+
+/**
+ * @brief Writes a single word (16-bit unsigned) to the device
+ *
+ * Manages the big-endian nature of the device (first byte written is the
+ * MS byte).
+ * Uses SystemVerilog Write Multi task.
+ *
+ * @code
+ *
+ * Example:
+ *
+ * uint16_t nvm_ctrl_pulse_width = 0x0004;
+ *
+ * int status = VL53L0_write_word(NVM_CTRL__PULSE_WIDTH_MSB,
+ * nvm_ctrl_pulse_width);
+ *
+ * @endcode
+ *
+ * @param address - uint8_t device address value
+ * @param index - uint8_t register index value
+ * @param data - uin16_t data value write
+ *
+ * @return status - SystemVerilog status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_write_word(VL53L0_DEV dev, uint8_t index, uint16_t data);
+
+
+/**
+ * @brief Writes a single dword (32-bit unsigned) to the device
+ *
+ * Manages the big-endian nature of the device (first byte written is the
+ * MS byte).
+ * Uses SystemVerilog Write Multi task.
+ *
+ * @code
+ *
+ * Example:
+ *
+ * uint32_t nvm_data = 0x0004;
+ *
+ * int status = VL53L0_write_dword(NVM_CTRL__DATAIN_MMM, nvm_data);
+ *
+ * @endcode
+ *
+ * @param address - uint8_t device address value
+ * @param index - uint8_t register index value
+ * @param data - uint32_t data value to write
+ *
+ * @return status - SystemVerilog status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_write_dword(VL53L0_DEV dev, uint8_t index, uint32_t data);
+
+
+
+/**
+ * @brief Reads a single byte from the device
+ *
+ * Uses SystemVerilog Read Byte task.
+ *
+ * @code
+ *
+ * Example:
+ *
+ * uint8_t device_status = 0;
+ *
+ * int status = VL53L0_read_byte(STATUS, &device_status);
+ *
+ * @endcode
+ *
+ * @param address - uint8_t device address value
+ * @param index - uint8_t register index value
+ * @param pdata - pointer to uint8_t data value
+ *
+ * @return status - SystemVerilog status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_read_byte(VL53L0_DEV dev, uint8_t index, uint8_t *pdata);
+
+
+/**
+ * @brief Reads a single word (16-bit unsigned) from the device
+ *
+ * Manages the big-endian nature of the device (first byte read is the MS byte).
+ * Uses SystemVerilog Read Multi task.
+ *
+ * @code
+ *
+ * Example:
+ *
+ * uint16_t timeout = 0;
+ *
+ * int status = VL53L0_read_word(TIMEOUT_OVERALL_PERIODS_MSB, &timeout);
+ *
+ * @endcode
+ *
+ * @param address - uint8_t device address value
+ * @param index - uint8_t register index value
+ * @param pdata - pointer to uint16_t data value
+ *
+ * @return status - SystemVerilog status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_read_word(VL53L0_DEV dev, uint8_t index, uint16_t *pdata);
+
+
+/**
+ * @brief Reads a single dword (32-bit unsigned) from the device
+ *
+ * Manages the big-endian nature of the device (first byte read is the MS byte).
+ * Uses SystemVerilog Read Multi task.
+ *
+ * @code
+ *
+ * Example:
+ *
+ * uint32_t range_1 = 0;
+ *
+ * int status = VL53L0_read_dword(RANGE_1_MMM, &range_1);
+ *
+ * @endcode
+ *
+ * @param address - uint8_t device address value
+ * @param index - uint8_t register index value
+ * @param pdata - pointer to uint32_t data value
+ *
+ * @return status - SystemVerilog status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_read_dword(VL53L0_DEV dev, uint8_t index, uint32_t *pdata);
+
+
+/**
+ * @brief Implements a programmable wait in us
+ *
+ * Wrapper for SystemVerilog Wait in micro seconds task
+ *
+ * @param wait_us - integer wait in micro seconds
+ *
+ * @return status - SystemVerilog status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_platform_wait_us(int32_t wait_us);
+
+
+/**
+ * @brief Implements a programmable wait in ms
+ *
+ * Wrapper for SystemVerilog Wait in milli seconds task
+ *
+ * @param wait_ms - integer wait in milli seconds
+ *
+ * @return status - SystemVerilog status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_wait_ms(int32_t wait_ms);
+
+
+/**
+ * @brief Set GPIO value
+ *
+ * @param level - input level - either 0 or 1
+ *
+ * @return status - SystemVerilog status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_set_gpio(uint8_t level);
+
+
+/**
+ * @brief Get GPIO value
+ *
+ * @param plevel - uint8_t pointer to store GPIO level (0 or 1)
+ *
+ * @return status - SystemVerilog status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_get_gpio(uint8_t *plevel);
+
+/**
+ * @brief Release force on GPIO
+ *
+ * @return status - SystemVerilog status 0 = ok, 1 = error
+ *
+ */
+
+int32_t VL53L0_release_gpio(void);
+
+
+/**
+* @brief Get the frequency of the timer used for ranging results time stamps
+*
+* @param[out] ptimer_freq_hz : pointer for timer frequency
+*
+* @return status : 0 = ok, 1 = error
+*
+*/
+
+int32_t VL53L0_get_timer_frequency(int32_t *ptimer_freq_hz);
+
+/**
+* @brief Get the timer value in units of timer_freq_hz
+* (see VL53L0_get_timestamp_frequency())
+*
+* @param[out] ptimer_count : pointer for timer count value
+*
+* @return status : 0 = ok, 1 = error
+*
+*/
+
+int32_t VL53L0_get_timer_value(int32_t *ptimer_count);
+int VL53L0_I2CWrite(VL53L0_DEV dev, uint8_t *buff, uint8_t len);
+int VL53L0_I2CRead(VL53L0_DEV dev, uint8_t *buff, uint8_t len);
+
+#endif /* _VL53L0_I2C_PLATFORM_H_ */
+
diff --git a/drivers/input/misc/vl53L0/inc/vl53l0_platform.h b/drivers/input/misc/vl53L0/inc/vl53l0_platform.h
new file mode 100644
index 000000000000..e38d65d5af14
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l0_platform.h
@@ -0,0 +1,228 @@
+/*******************************************************************************
+Copyright © 2015, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+
+#ifndef _VL53L0_PLATFORM_H_
+#define _VL53L0_PLATFORM_H_
+
+#include
+#include "vl53l0_def.h"
+#include "vl53l0_platform_log.h"
+
+#include "stmvl53l0-i2c.h"
+#include "stmvl53l0-cci.h"
+#include "stmvl53l0.h"
+
+/**
+ * @file vl53l0_platform.h
+ *
+ * @brief All end user OS/platform/application porting
+ */
+
+/**
+ * @defgroup VL53L0_platform_group VL53L0 Platform Functions
+ * @brief VL53L0 Platform Functions
+ * @{
+ */
+
+/**
+ * @struct VL53L0_Dev_t
+ * @brief Generic PAL device type that does link between API and platform abstraction layer
+ *
+ */
+typedef struct stmvl53l0_data *VL53L0_DEV;
+
+/**
+ * @def PALDevDataGet
+ * @brief Get ST private structure @a VL53L0_DevData_t data access
+ *
+ * @param Dev Device Handle
+ * @param field ST structure field name
+ * It maybe used and as real data "ref" not just as "get" for sub-structure item
+ * like PALDevDataGet(FilterData.field)[i] or
+ * PALDevDataGet(FilterData.MeasurementIndex)++
+ */
+#define PALDevDataGet(Dev, field) (Dev->Data.field)
+
+/**
+ * @def PALDevDataSet(Dev, field, data)
+ * @brief Set ST private structure @a VL53L0_DevData_t data field
+ * @param Dev Device Handle
+ * @param field ST structure field na*me
+ * @param data Data to be set
+ */
+#define PALDevDataSet(Dev, field, data) ((Dev->Data.field) = (data))
+
+
+/**
+ * @defgroup VL53L0_registerAccess_group PAL Register Access Functions
+ * @brief PAL Register Access Functions
+ * @{
+ */
+
+/**
+ * Lock comms interface to serialize all commands to a shared I2C interface for a specific device
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_Error VL53L0_LockSequenceAccess(VL53L0_DEV Dev);
+
+/**
+ * Unlock comms interface to serialize all commands to a shared I2C interface for a specific device
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_Error VL53L0_UnlockSequenceAccess(VL53L0_DEV Dev);
+
+
+/**
+ * Writes the supplied byte buffer to the device
+ * @param Dev Device Handle
+ * @param index The register index
+ * @param pdata Pointer to uint8_t buffer containing the data to be written
+ * @param count Number of bytes in the supplied byte buffer
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_Error VL53L0_WriteMulti(VL53L0_DEV Dev, uint8_t index,
+ uint8_t *pdata, uint32_t count);
+
+/**
+ * Reads the requested number of bytes from the device
+ * @param Dev Device Handle
+ * @param index The register index
+ * @param pdata Pointer to the uint8_t buffer to store read data
+ * @param count Number of uint8_t's to read
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_Error VL53L0_ReadMulti(VL53L0_DEV Dev, uint8_t index,
+ uint8_t *pdata, uint32_t count);
+
+/**
+ * Write single byte register
+ * @param Dev Device Handle
+ * @param index The register index
+ * @param data 8 bit register data
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_Error VL53L0_WrByte(VL53L0_DEV Dev, uint8_t index, uint8_t data);
+
+/**
+ * Write word register
+ * @param Dev Device Handle
+ * @param index The register index
+ * @param data 16 bit register data
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_Error VL53L0_WrWord(VL53L0_DEV Dev, uint8_t index, uint16_t data);
+
+/**
+ * Write double word (4 byte) register
+ * @param Dev Device Handle
+ * @param index The register index
+ * @param data 32 bit register data
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_Error VL53L0_WrDWord(VL53L0_DEV Dev, uint8_t index, uint32_t data);
+
+/**
+ * Read single byte register
+ * @param Dev Device Handle
+ * @param index The register index
+ * @param data pointer to 8 bit data
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_Error VL53L0_RdByte(VL53L0_DEV Dev, uint8_t index, uint8_t *data);
+
+/**
+ * Read word (2byte) register
+ * @param Dev Device Handle
+ * @param index The register index
+ * @param data pointer to 16 bit data
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_Error VL53L0_RdWord(VL53L0_DEV Dev, uint8_t index, uint16_t *data);
+
+/**
+ * Read dword (4byte) register
+ * @param Dev Device Handle
+ * @param index The register index
+ * @param data pointer to 32 bit data
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_Error VL53L0_RdDWord(VL53L0_DEV Dev, uint8_t index, uint32_t *data);
+
+/**
+ * Threat safe Update (read/modify/write) single byte register
+ *
+ * Final_reg = (Initial_reg & and_data) |or_data
+ *
+ * @param Dev Device Handle
+ * @param index The register index
+ * @param AndData 8 bit and data
+ * @param OrData 8 bit or data
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_Error VL53L0_UpdateByte(VL53L0_DEV Dev, uint8_t index,
+ uint8_t AndData, uint8_t OrData);
+
+/** @} end of VL53L0_registerAccess_group */
+
+
+/**
+ * @brief execute delay in all polling API call
+ *
+ * A typical multi-thread or RTOs implementation is to sleep the task for
+ * some 5ms (with 100Hz max rate faster polling is not needed)
+ * if nothing specific is need you can define it as an empty/void macro
+ * @code
+ * #define VL53L0_PollingDelay(...) (void)0
+ * @endcode
+ * @param Dev Device Handle
+ * @return VL53L0_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0_Error
+ */
+VL53L0_Error VL53L0_PollingDelay(VL53L0_DEV Dev);
+/* usually best implemented as a real function */
+
+/** @} end of VL53L0_platform_group */
+
+#endif /* _VL53L0_PLATFORM_H_ */
+
+
+
diff --git a/drivers/input/misc/vl53L0/inc/vl53l0_platform_log.h b/drivers/input/misc/vl53L0/inc/vl53l0_platform_log.h
new file mode 100644
index 000000000000..4c5bd51b2621
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l0_platform_log.h
@@ -0,0 +1,125 @@
+/*******************************************************************************
+Copyright © 2015, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+
+#ifndef _VL53L0_PLATFORM_LOG_H_
+#define _VL53L0_PLATFORM_LOG_H_
+
+#include
+/* LOG Functions */
+
+
+/**
+ * @file vl53l0_platform_log.h
+ *
+ * @brief platform log function definition
+ */
+
+/*#define VL53L0_LOG_ENABLE 0*/
+
+enum {
+ TRACE_LEVEL_NONE,
+ TRACE_LEVEL_ERRORS,
+ TRACE_LEVEL_WARNING,
+ TRACE_LEVEL_INFO,
+ TRACE_LEVEL_DEBUG,
+ TRACE_LEVEL_ALL,
+ TRACE_LEVEL_IGNORE
+};
+
+enum {
+ TRACE_FUNCTION_NONE = 0,
+ TRACE_FUNCTION_I2C = 1,
+ TRACE_FUNCTION_ALL = 0x7fffffff /* all bits except sign */
+};
+
+enum {
+ TRACE_MODULE_NONE = 0x0,
+ TRACE_MODULE_API = 0x1,
+ TRACE_MODULE_PLATFORM = 0x2,
+ TRACE_MODULE_ALL = 0x7fffffff /* all bits except sign */
+};
+
+
+#ifdef VL53L0_LOG_ENABLE
+
+#include
+
+
+extern uint32_t _trace_level;
+
+
+
+int32_t VL53L0_trace_config(char *filename, uint32_t modules,
+ uint32_t level, uint32_t functions);
+
+void trace_print_module_function(uint32_t module, uint32_t level,
+ uint32_t function, const char *format, ...);
+
+
+#define LOG_GET_TIME() (int)0
+/*
+#define _LOG_FUNCTION_START(module, fmt, ...) \
+ printk(KERN_INFO"beg %s start @%d\t" fmt "\n", \
+ __func__, LOG_GET_TIME(), ##__VA_ARGS__)
+
+#define _LOG_FUNCTION_END(module, status, ...)\
+ printk(KERN_INFO"end %s @%d %d\n", \
+ __func__, LOG_GET_TIME(), (int)status)
+
+#define _LOG_FUNCTION_END_FMT(module, status, fmt, ...)\
+ printk(KERN_INFO"End %s @%d %d\t"fmt"\n" , \
+ __func__, LOG_GET_TIME(), (int)status, ##__VA_ARGS__)
+*/
+#define _LOG_FUNCTION_START(module, fmt, ...) \
+ pr_err("beg %s start @%d\t" fmt "\n", \
+ __func__, LOG_GET_TIME(), ##__VA_ARGS__)
+
+#define _LOG_FUNCTION_END(module, status, ...)\
+ pr_err("end %s start @%d\t" fmt "\n", \
+ __func__, LOG_GET_TIME(), (int)status)
+
+#define _LOG_FUNCTION_END_FMT(module, status, fmt, ...)\
+ pr_err("End %s @%d %d\t"fmt"\n" , \
+ __func__, LOG_GET_TIME(), (int)status, ##__VA_ARGS__)
+
+
+#else /* VL53L0_LOG_ENABLE no logging */
+ #define VL53L0_ErrLog(...) (void)0
+ #define _LOG_FUNCTION_START(module, fmt, ...) (void)0
+ #define _LOG_FUNCTION_END(module, status, ...) (void)0
+ #define _LOG_FUNCTION_END_FMT(module, status, fmt, ...) (void)0
+#endif /* else */
+
+#define VL53L0_COPYSTRING(str, ...) strlcpy(str, ##__VA_ARGS__, sizeof(str))
+
+
+#endif /* _VL53L0_PLATFORM_LOG_H_ */
+
+
+
diff --git a/drivers/input/misc/vl53L0/inc/vl53l0_strings.h b/drivers/input/misc/vl53L0/inc/vl53l0_strings.h
new file mode 100644
index 000000000000..ec78899a25d9
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l0_strings.h
@@ -0,0 +1,211 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+********************************************************************************/
+/*
+ * @file vl53l0_string.h
+ * $Date: 2014-12-04 16:15:06 +0100 (Thu, 04 Dec 2014) $
+ * $Revision: 1906 $
+ */
+
+#ifndef VL53L0_STRINGS_H_
+#define VL53L0_STRINGS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef USE_EMPTY_STRING
+ #define VL53L0_STRING_DEVICE_INFO_NAME ""
+ #define VL53L0_STRING_DEVICE_INFO_NAME_TS0 ""
+ #define VL53L0_STRING_DEVICE_INFO_NAME_TS1 ""
+ #define VL53L0_STRING_DEVICE_INFO_NAME_TS2 ""
+ #define VL53L0_STRING_DEVICE_INFO_NAME_ES1 ""
+ #define VL53L0_STRING_DEVICE_INFO_TYPE ""
+
+ /* PAL ERROR strings */
+ #define VL53L0_STRING_ERROR_NONE ""
+ #define VL53L0_STRING_ERROR_CALIBRATION_WARNING ""
+ #define VL53L0_STRING_ERROR_MIN_CLIPPED ""
+ #define VL53L0_STRING_ERROR_UNDEFINED ""
+ #define VL53L0_STRING_ERROR_INVALID_PARAMS ""
+ #define VL53L0_STRING_ERROR_NOT_SUPPORTED ""
+ #define VL53L0_STRING_ERROR_RANGE_ERROR ""
+ #define VL53L0_STRING_ERROR_TIME_OUT ""
+ #define VL53L0_STRING_ERROR_MODE_NOT_SUPPORTED ""
+ #define VL53L0_STRING_ERROR_BUFFER_TOO_SMALL ""
+ #define VL53L0_STRING_ERROR_GPIO_NOT_EXISTING ""
+ #define VL53L0_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED ""
+ #define VL53L0_STRING_ERROR_CONTROL_INTERFACE ""
+ #define VL53L0_STRING_ERROR_INVALID_COMMAND ""
+ #define VL53L0_STRING_ERROR_DIVISION_BY_ZERO ""
+ #define VL53L0_STRING_ERROR_REF_SPAD_INIT ""
+ #define VL53L0_STRING_ERROR_NOT_IMPLEMENTED ""
+
+ #define VL53L0_STRING_UNKNOW_ERROR_CODE ""
+
+
+
+ /* Range Status */
+ #define VL53L0_STRING_RANGESTATUS_NONE ""
+ #define VL53L0_STRING_RANGESTATUS_RANGEVALID ""
+ #define VL53L0_STRING_RANGESTATUS_SIGMA ""
+ #define VL53L0_STRING_RANGESTATUS_SIGNAL ""
+ #define VL53L0_STRING_RANGESTATUS_MINRANGE ""
+ #define VL53L0_STRING_RANGESTATUS_PHASE ""
+ #define VL53L0_STRING_RANGESTATUS_HW ""
+
+
+ /* Range Status */
+ #define VL53L0_STRING_STATE_POWERDOWN ""
+ #define VL53L0_STRING_STATE_WAIT_STATICINIT ""
+ #define VL53L0_STRING_STATE_STANDBY ""
+ #define VL53L0_STRING_STATE_IDLE ""
+ #define VL53L0_STRING_STATE_RUNNING ""
+ #define VL53L0_STRING_STATE_UNKNOWN ""
+ #define VL53L0_STRING_STATE_ERROR ""
+
+
+ /* Device Specific */
+ #define VL53L0_STRING_DEVICEERROR_NONE ""
+ #define VL53L0_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE ""
+ #define VL53L0_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE ""
+ #define VL53L0_STRING_DEVICEERROR_NOVHVVALUEFOUND ""
+ #define VL53L0_STRING_DEVICEERROR_MSRCNOTARGET ""
+ #define VL53L0_STRING_DEVICEERROR_SNRCHECK ""
+ #define VL53L0_STRING_DEVICEERROR_RANGEPHASECHECK ""
+ #define VL53L0_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK ""
+ #define VL53L0_STRING_DEVICEERROR_TCC ""
+ #define VL53L0_STRING_DEVICEERROR_PHASECONSISTENCY ""
+ #define VL53L0_STRING_DEVICEERROR_MINCLIP ""
+ #define VL53L0_STRING_DEVICEERROR_RANGECOMPLETE ""
+ #define VL53L0_STRING_DEVICEERROR_ALGOUNDERFLOW ""
+ #define VL53L0_STRING_DEVICEERROR_ALGOOVERFLOW ""
+ #define VL53L0_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD ""
+ #define VL53L0_STRING_DEVICEERROR_UNKNOWN ""
+
+ /* Check Enable */
+ #define VL53L0_STRING_CHECKENABLE_SIGMA_FINAL_RANGE ""
+ #define VL53L0_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE ""
+ #define VL53L0_STRING_CHECKENABLE_SIGNAL_REF_CLIP ""
+ #define VL53L0_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD ""
+
+ /* Sequence Step */
+ #define VL53L0_STRING_SEQUENCESTEP_TCC ""
+ #define VL53L0_STRING_SEQUENCESTEP_DSS ""
+ #define VL53L0_STRING_SEQUENCESTEP_MSRC ""
+ #define VL53L0_STRING_SEQUENCESTEP_PRE_RANGE ""
+ #define VL53L0_STRING_SEQUENCESTEP_FINAL_RANGE ""
+#else
+ #define VL53L0_STRING_DEVICE_INFO_NAME "VL53L0 cut1.0"
+ #define VL53L0_STRING_DEVICE_INFO_NAME_TS0 "VL53L0 TS0"
+ #define VL53L0_STRING_DEVICE_INFO_NAME_TS1 "VL53L0 TS1"
+ #define VL53L0_STRING_DEVICE_INFO_NAME_TS2 "VL53L0 TS2"
+ #define VL53L0_STRING_DEVICE_INFO_NAME_ES1 "VL53L0 ES1 or later"
+ #define VL53L0_STRING_DEVICE_INFO_TYPE "VL53L0"
+
+ /* PAL ERROR strings */
+ #define VL53L0_STRING_ERROR_NONE "No Error"
+ #define VL53L0_STRING_ERROR_CALIBRATION_WARNING "Calibration Warning Error"
+ #define VL53L0_STRING_ERROR_MIN_CLIPPED "Min clipped error"
+ #define VL53L0_STRING_ERROR_UNDEFINED "Undefined error"
+ #define VL53L0_STRING_ERROR_INVALID_PARAMS "Invalid parameters error"
+ #define VL53L0_STRING_ERROR_NOT_SUPPORTED "Not supported error"
+ #define VL53L0_STRING_ERROR_RANGE_ERROR "Range error"
+ #define VL53L0_STRING_ERROR_TIME_OUT "Time out error"
+ #define VL53L0_STRING_ERROR_MODE_NOT_SUPPORTED "Mode not supported error"
+ #define VL53L0_STRING_ERROR_BUFFER_TOO_SMALL "Buffer too small"
+ #define VL53L0_STRING_ERROR_GPIO_NOT_EXISTING "GPIO not existing"
+ #define VL53L0_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED "GPIO funct not supported"
+ #define VL53L0_STRING_ERROR_CONTROL_INTERFACE "Control Interface Error"
+ #define VL53L0_STRING_ERROR_INVALID_COMMAND "Invalid Command Error"
+ #define VL53L0_STRING_ERROR_DIVISION_BY_ZERO "Division by zero Error"
+ #define VL53L0_STRING_ERROR_REF_SPAD_INIT "Reference Spad Init Error"
+ #define VL53L0_STRING_ERROR_NOT_IMPLEMENTED "Not implemented error"
+
+ #define VL53L0_STRING_UNKNOW_ERROR_CODE "Unknown Error Code"
+
+
+
+ /* Range Status */
+ #define VL53L0_STRING_RANGESTATUS_NONE "No Update"
+ #define VL53L0_STRING_RANGESTATUS_RANGEVALID "Range Valid"
+ #define VL53L0_STRING_RANGESTATUS_SIGMA "Sigma Fail"
+ #define VL53L0_STRING_RANGESTATUS_SIGNAL "Signal Fail"
+ #define VL53L0_STRING_RANGESTATUS_MINRANGE "Min Range Fail"
+ #define VL53L0_STRING_RANGESTATUS_PHASE "Phase Fail"
+ #define VL53L0_STRING_RANGESTATUS_HW "Hardware Fail"
+
+
+ /* Range Status */
+ #define VL53L0_STRING_STATE_POWERDOWN "POWERDOWN State"
+ #define VL53L0_STRING_STATE_WAIT_STATICINIT "Wait for staticinit State"
+ #define VL53L0_STRING_STATE_STANDBY "STANDBY State"
+ #define VL53L0_STRING_STATE_IDLE "IDLE State"
+ #define VL53L0_STRING_STATE_RUNNING "RUNNING State"
+ #define VL53L0_STRING_STATE_UNKNOWN "UNKNOWN State"
+ #define VL53L0_STRING_STATE_ERROR "ERROR State"
+
+
+ /* Device Specific */
+ #define VL53L0_STRING_DEVICEERROR_NONE "No Update"
+ #define VL53L0_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE "VCSEL Continuity Test Failure"
+ #define VL53L0_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE "VCSEL Watchdog Test Failure"
+ #define VL53L0_STRING_DEVICEERROR_NOVHVVALUEFOUND "No VHV Value found"
+ #define VL53L0_STRING_DEVICEERROR_MSRCNOTARGET "MSRC No Target Error"
+ #define VL53L0_STRING_DEVICEERROR_SNRCHECK "SNR Check Exit"
+ #define VL53L0_STRING_DEVICEERROR_RANGEPHASECHECK "Range Phase Check Error"
+ #define VL53L0_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK "Sigma Threshold Check Error"
+ #define VL53L0_STRING_DEVICEERROR_TCC "TCC Error"
+ #define VL53L0_STRING_DEVICEERROR_PHASECONSISTENCY "Phase Consistency Error"
+ #define VL53L0_STRING_DEVICEERROR_MINCLIP "Min Clip Error"
+ #define VL53L0_STRING_DEVICEERROR_RANGECOMPLETE "Range Complete"
+ #define VL53L0_STRING_DEVICEERROR_ALGOUNDERFLOW "Range Algo Underflow Error"
+ #define VL53L0_STRING_DEVICEERROR_ALGOOVERFLOW "Range Algo Overlow Error"
+ #define VL53L0_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD "Range Ignore Threshold Error"
+ #define VL53L0_STRING_DEVICEERROR_UNKNOWN "Unknown error code"
+
+ /* Check Enable */
+ #define VL53L0_STRING_CHECKENABLE_SIGMA_FINAL_RANGE "SIGMA FINAL RANGE"
+ #define VL53L0_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE "SIGNAL RATE FINAL RANGE"
+ #define VL53L0_STRING_CHECKENABLE_SIGNAL_REF_CLIP "SIGNAL REF CLIP"
+ #define VL53L0_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD "RANGE IGNORE THRESHOLD"
+
+ /* Sequence Step */
+ #define VL53L0_STRING_SEQUENCESTEP_TCC "TCC"
+ #define VL53L0_STRING_SEQUENCESTEP_DSS "DSS"
+ #define VL53L0_STRING_SEQUENCESTEP_MSRC "MSRC"
+ #define VL53L0_STRING_SEQUENCESTEP_PRE_RANGE "PRE RANGE"
+ #define VL53L0_STRING_SEQUENCESTEP_FINAL_RANGE "FINAL RANGE"
+#endif //USE_EMPTY_STRING
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L0/inc/vl53l0_tuning.h b/drivers/input/misc/vl53L0/inc/vl53l0_tuning.h
new file mode 100644
index 000000000000..2cffaab8e655
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l0_tuning.h
@@ -0,0 +1,145 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+
+#ifndef _VL53L0_TUNING_H_
+#define _VL53L0_TUNING_H_
+
+#include "vl53l0_def.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+uint8_t DefaultTuningSettings[] = {
+
+ /* update 02/11/2015_v36 */
+ 0x01, 0xFF, 0x01,
+ 0x01, 0x00, 0x00,
+
+ 0x01, 0xFF, 0x00,
+ 0x01, 0x09, 0x00,
+ 0x01, 0x10, 0x00,
+ 0x01, 0x11, 0x00,
+
+ 0x01, 0x24, 0x01,
+ 0x01, 0x25, 0xff,
+ 0x01, 0x75, 0x00,
+
+ 0x01, 0xFF, 0x01,
+ 0x01, 0x4e, 0x2c,
+ 0x01, 0x48, 0x00,
+ 0x01, 0x30, 0x20,
+
+ 0x01, 0xFF, 0x00,
+ 0x01, 0x30, 0x09, /* mja changed from 0x64. */
+ 0x01, 0x54, 0x00,
+ 0x01, 0x31, 0x04,
+ 0x01, 0x32, 0x03,
+ 0x01, 0x40, 0x83,
+ 0x01, 0x46, 0x25,
+ 0x01, 0x60, 0x00,
+ 0x01, 0x27, 0x00,
+ 0x01, 0x50, 0x06,
+ 0x01, 0x51, 0x00,
+ 0x01, 0x52, 0x96,
+ 0x01, 0x56, 0x08,
+ 0x01, 0x57, 0x30,
+ 0x01, 0x61, 0x00,
+ 0x01, 0x62, 0x00,
+ 0x01, 0x64, 0x00,
+ 0x01, 0x65, 0x00,
+ 0x01, 0x66, 0xa0,
+
+ 0x01, 0xFF, 0x01,
+ 0x01, 0x22, 0x32,
+ 0x01, 0x47, 0x14,
+ 0x01, 0x49, 0xff,
+ 0x01, 0x4a, 0x00,
+
+ 0x01, 0xFF, 0x00,
+ 0x01, 0x7a, 0x0a,
+ 0x01, 0x7b, 0x00,
+ 0x01, 0x78, 0x21,
+
+ 0x01, 0xFF, 0x01,
+ 0x01, 0x23, 0x34,
+ 0x01, 0x42, 0x00,
+ 0x01, 0x44, 0xff,
+ 0x01, 0x45, 0x26,
+ 0x01, 0x46, 0x05,
+ 0x01, 0x40, 0x40,
+ 0x01, 0x0E, 0x06,
+ 0x01, 0x20, 0x1a,
+ 0x01, 0x43, 0x40,
+
+ 0x01, 0xFF, 0x00,
+ 0x01, 0x34, 0x03,
+ 0x01, 0x35, 0x44,
+
+ 0x01, 0xFF, 0x01,
+ 0x01, 0x31, 0x04,
+ 0x01, 0x4b, 0x09,
+ 0x01, 0x4c, 0x05,
+ 0x01, 0x4d, 0x04,
+
+
+ 0x01, 0xFF, 0x00,
+ 0x01, 0x44, 0x00,
+ 0x01, 0x45, 0x20,
+ 0x01, 0x47, 0x08,
+ 0x01, 0x48, 0x28,
+ 0x01, 0x67, 0x00,
+ 0x01, 0x70, 0x04,
+ 0x01, 0x71, 0x01,
+ 0x01, 0x72, 0xfe,
+ 0x01, 0x76, 0x00,
+ 0x01, 0x77, 0x00,
+
+ 0x01, 0xFF, 0x01,
+ 0x01, 0x0d, 0x01,
+
+ 0x01, 0xFF, 0x00,
+ 0x01, 0x80, 0x01,
+ 0x01, 0x01, 0xF8,
+
+ 0x01, 0xFF, 0x01,
+ 0x01, 0x8e, 0x01,
+ 0x01, 0x00, 0x01,
+ 0x01, 0xFF, 0x00,
+
+ 0x00, 0x00, 0x00
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VL53L0_TUNING_H_ */
diff --git a/drivers/input/misc/vl53L0/inc/vl53l0_types.h b/drivers/input/misc/vl53L0/inc/vl53l0_types.h
new file mode 100644
index 000000000000..4085628b78a9
--- /dev/null
+++ b/drivers/input/misc/vl53L0/inc/vl53l0_types.h
@@ -0,0 +1,68 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+#ifndef VL53L0_TYPES_H_
+#define VL53L0_TYPES_H_
+
+#include
+
+#ifndef NULL
+#error "TODO review NULL definition or add required include "
+#define NULL 0
+#endif
+/** use where fractional values are expected
+ *
+ * Given a floating point value f it's .16 bit point is (int)(f*(1<<16))*/
+typedef unsigned int FixPoint1616_t;
+
+#if !defined(STDINT_H) && !defined(_GCC_STDINT_H) \
+ && !defined(_STDINT_H) && !defined(_LINUX_TYPES_H)
+
+#pragma message("Please review type definition of STDINT define for your \
+platform and add to list above ")
+
+/*
+* target platform do not provide stdint or use a different #define than above
+* to avoid seeing the message below addapt the #define list above or implement
+* all type and delete these pragma
+*/
+
+typedef unsigned int uint32_t;
+typedef int int32_t;
+
+typedef unsigned short uint16_t;
+typedef short int16_t;
+
+typedef unsigned char uint8_t;
+
+typedef signed char int8_t;
+
+
+#endif /* VL53L0_TYPES_H_ */
+
+#endif /* VL6180x_TYPES_H_ */
diff --git a/drivers/input/misc/vl53L0/src/vl53l010_api.c b/drivers/input/misc/vl53L0/src/vl53l010_api.c
new file mode 100644
index 000000000000..f86eb79cb553
--- /dev/null
+++ b/drivers/input/misc/vl53L0/src/vl53l010_api.c
@@ -0,0 +1,4127 @@
+/*******************************************************************************
+ Copyright © 2016, STMicroelectronics International N.V.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+ NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+ IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ******************************************************************************/
+
+#include "vl53l010_api.h"
+#include "vl53l010_device.h"
+#include "vl53l010_tuning.h"
+
+/* use macro for abs */
+#ifndef __KERNEL__
+#include
+#endif
+
+#ifdef VL53L0_EXTERNAL_USE
+#define VL53L010_EXTERNAL
+#else
+#define VL53L010_EXTERNAL static
+#endif
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(TRACE_MODULE_API, status, fmt, ##__VA_ARGS__)
+
+#ifdef VL53L0_LOG_ENABLE
+#define trace_print(level, ...) trace_print_module_function(TRACE_MODULE_API, \
+ level, TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+#endif
+
+
+/* Defines */
+#define VL53L010_SETPARAMETERFIELD(Dev, field, value) \
+ do { \
+ if (Status == VL53L0_ERROR_NONE) {\
+ CurrentParameters = \
+ PALDevDataGet(Dev, CurrentParameters); \
+ CurrentParameters.field = value; \
+ CurrentParameters = \
+ PALDevDataSet(Dev, CurrentParameters, \
+ CurrentParameters); \
+ } \
+ } while (0)
+#define VL53L010_SETARRAYPARAMETERFIELD(Dev, field, index, value) \
+ do { \
+ if (Status == VL53L0_ERROR_NONE) {\
+ CurrentParameters = \
+ PALDevDataGet(Dev, CurrentParameters); \
+ CurrentParameters.field[index] = value; \
+ CurrentParameters = \
+ PALDevDataSet(Dev, CurrentParameters, \
+ CurrentParameters); \
+ } \
+ } while (0)
+
+#define VL53L010_GETPARAMETERFIELD(Dev, field, variable) \
+ do { \
+ if (Status == VL53L0_ERROR_NONE) { \
+ CurrentParameters = \
+ PALDevDataGet(Dev, CurrentParameters); \
+ variable = CurrentParameters.field; \
+ } \
+ } while (0)
+
+#define VL53L010_GETARRAYPARAMETERFIELD(Dev, field, index, variable) \
+ do { \
+ if (Status == VL53L0_ERROR_NONE) { \
+ CurrentParameters = \
+ PALDevDataGet(Dev, CurrentParameters); \
+ variable = CurrentParameters.field[index]; \
+ } \
+ } while (0)
+
+#define VL53L010_SETDEVICESPECIFICPARAMETER(Dev, field, value) \
+ do { \
+ if (Status == VL53L0_ERROR_NONE) { \
+ DeviceSpecificParameters = \
+ PALDevDataGet(Dev, DeviceSpecificParameters); \
+ DeviceSpecificParameters.field = value; \
+ DeviceSpecificParameters = \
+ PALDevDataSet(Dev, DeviceSpecificParameters, \
+ DeviceSpecificParameters); \
+ } \
+ } while (0)
+
+#define VL53L010_GETDEVICESPECIFICPARAMETER(Dev, field) \
+ PALDevDataGet(Dev, DeviceSpecificParameters).field
+
+#define VL53L010_FIXPOINT1616TOFIXPOINT97(Value) \
+ (uint16_t)((Value >> 9) & 0xFFFF)
+#define VL53L010_FIXPOINT97TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value << 9)
+#define VL53L010_FIXPOINT1616TOFIXPOINT412(Value) \
+ (uint16_t)((Value >> 4) & 0xFFFF)
+#define VL53L010_FIXPOINT412TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value << 4)
+#define VL53L010_FIXPOINT1616TOFIXPOINT08(Value) \
+ (uint8_t)((Value >> 8) & 0x00FF)
+#define VL53L010_FIXPOINT08TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value << 8)
+#define VL53L010_MAKEUINT16(lsb, msb) \
+ (uint16_t)((((uint16_t)msb) << 8) + (uint16_t)lsb)
+
+/* Internal functions declaration */
+VL53L010_EXTERNAL VL53L0_Error VL53L010_get_vcsel_pulse_period(VL53L0_DEV Dev,
+ uint8_t *pVCSELPulsePeriod, uint8_t RangeIndex);
+VL53L010_EXTERNAL uint8_t VL53L010_encode_vcsel_period(uint8_t vcsel_period_pclks);
+VL53L010_EXTERNAL uint8_t VL53L010_decode_vcsel_period(uint8_t vcsel_period_reg);
+VL53L010_EXTERNAL uint16_t VL53L010_calc_encoded_timeout(VL53L0_DEV Dev,
+ uint32_t timeout_period_us, uint8_t vcsel_period);
+VL53L010_EXTERNAL uint32_t VL53L010_calc_ranging_wait_us(VL53L0_DEV Dev,
+ uint16_t timeout_overall_periods, uint8_t vcsel_period);
+VL53L010_EXTERNAL VL53L0_Error VL53L010_load_additional_settings1(VL53L0_DEV Dev);
+VL53L010_EXTERNAL VL53L0_Error VL53L010_load_additional_settings3(VL53L0_DEV Dev);
+VL53L010_EXTERNAL VL53L0_Error VL53L010_check_part_used(VL53L0_DEV Dev,
+ uint8_t *Revision, VL53L0_DeviceInfo_t *pVL53L0_DeviceInfo);
+VL53L010_EXTERNAL VL53L0_Error VL53L010_get_info_from_device(VL53L0_DEV Dev);
+VL53L010_EXTERNAL VL53L0_Error VL53L010_device_read_strobe(VL53L0_DEV Dev);
+VL53L010_EXTERNAL VL53L0_Error VL53L010_get_pal_range_status(VL53L0_DEV Dev,
+ uint8_t DeviceRangeStatus,
+ FixPoint1616_t SignalRate,
+ FixPoint1616_t CrosstalkCompensation,
+ uint16_t EffectiveSpadRtnCount,
+ VL53L0_RangingMeasurementData_t
+ *pRangingMeasurementData,
+ uint8_t *pPalRangeStatus);
+
+/* Group PAL General Functions */
+VL53L0_Error VL53L010_GetVersion(VL53L0_Version_t *pVersion)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ pVersion->major = VL53L010_IMPLEMENTATION_VER_MAJOR;
+ pVersion->minor = VL53L010_IMPLEMENTATION_VER_MINOR;
+ pVersion->build = VL53L010_IMPLEMENTATION_VER_SUB;
+
+ pVersion->revision = VL53L0_IMPLEMENTATION_VER_REVISION;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetPalSpecVersion(VL53L0_Version_t *pPalSpecVersion)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ pPalSpecVersion->major = VL53L010_SPECIFICATION_VER_MAJOR;
+ pPalSpecVersion->minor = VL53L010_SPECIFICATION_VER_MINOR;
+ pPalSpecVersion->build = VL53L010_SPECIFICATION_VER_SUB;
+
+ pPalSpecVersion->revision = VL53L010_SPECIFICATION_VER_REVISION;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetDeviceInfo(VL53L0_DEV Dev,
+ VL53L0_DeviceInfo_t *pVL53L0_DeviceInfo)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t model_id;
+ uint8_t Revision;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L010_check_part_used(Dev, &Revision, pVL53L0_DeviceInfo);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (Revision == 0) {
+ VL53L0_COPYSTRING(pVL53L0_DeviceInfo->Name,
+ VL53L010_STRING_DEVICE_INFO_NAME_TS0);
+ } else if ((Revision <= 34) && (Revision != 32)) {
+ VL53L0_COPYSTRING(pVL53L0_DeviceInfo->Name,
+ VL53L010_STRING_DEVICE_INFO_NAME_TS1);
+ } else if (Revision < 39) {
+ VL53L0_COPYSTRING(pVL53L0_DeviceInfo->Name,
+ VL53L010_STRING_DEVICE_INFO_NAME_TS2);
+ } else {
+ VL53L0_COPYSTRING(pVL53L0_DeviceInfo->Name,
+ VL53L010_STRING_DEVICE_INFO_NAME_ES1);
+ }
+
+ VL53L0_COPYSTRING(pVL53L0_DeviceInfo->Type,
+ VL53L010_STRING_DEVICE_INFO_TYPE);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdByte(Dev, VL53L010_REG_IDENTIFICATION_MODEL_ID,
+ &pVL53L0_DeviceInfo->ProductType);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdByte(Dev, VL53L010_REG_IDENTIFICATION_REVISION_ID,
+ &model_id);
+ pVL53L0_DeviceInfo->ProductRevisionMajor = 1;
+ pVL53L0_DeviceInfo->ProductRevisionMinor = (model_id & 0xF0) >> 4;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetDeviceErrorStatus(VL53L0_DEV Dev,
+ VL53L010_DeviceError *pDeviceErrorStatus)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t RangeStatus;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L010_REG_RESULT_RANGE_STATUS,
+ &RangeStatus);
+
+ *pDeviceErrorStatus = (VL53L0_DeviceError)((RangeStatus & 0x78) >> 3);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+#define VL53L010_BUILDSTATUSERRORSTRING(BUFFER, ERRORCODE, STRINGVALUE) \
+ case ERRORCODE: \
+ VL53L0_COPYSTRING(BUFFER, STRINGVALUE);\
+ break;\
+
+VL53L0_Error VL53L010_GetDeviceErrorString(VL53L0_DeviceError ErrorCode,
+ char *pDeviceErrorString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ switch (ErrorCode) {
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_NONE,
+ VL53L010_STRING_DEVICEERROR_NONE);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_VCSELCONTINUITYTESTFAILURE,
+ VL53L010_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_VCSELWATCHDOGTESTFAILURE,
+ VL53L010_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_NOVHVVALUEFOUND,
+ VL53L010_STRING_DEVICEERROR_NOVHVVALUEFOUND);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_MSRCNOTARGET,
+ VL53L010_STRING_DEVICEERROR_MSRCNOTARGET);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_MSRCMINIMUMSNR,
+ VL53L010_STRING_DEVICEERROR_MSRCMINIMUMSNR);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_MSRCWRAPAROUND,
+ VL53L010_STRING_DEVICEERROR_MSRCWRAPAROUND);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_TCC, VL53L010_STRING_DEVICEERROR_TCC);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_RANGEAWRAPAROUND,
+ VL53L010_STRING_DEVICEERROR_RANGEAWRAPAROUND);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_RANGEBWRAPAROUND,
+ VL53L010_STRING_DEVICEERROR_RANGEBWRAPAROUND);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_MINCLIP,
+ VL53L010_STRING_DEVICEERROR_MINCLIP);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_RANGECOMPLETE,
+ VL53L010_STRING_DEVICEERROR_RANGECOMPLETE);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_ALGOUNDERFLOW,
+ VL53L010_STRING_DEVICEERROR_ALGOUNDERFLOW);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_ALGOOVERFLOW,
+ VL53L010_STRING_DEVICEERROR_ALGOOVERFLOW);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_FINALSNRLIMIT,
+ VL53L010_STRING_DEVICEERROR_FINALSNRLIMIT);
+ VL53L010_BUILDSTATUSERRORSTRING(pDeviceErrorString,
+ VL53L010_DEVICEERROR_NOTARGETIGNORE,
+ VL53L010_STRING_DEVICEERROR_NOTARGETIGNORE);
+ default:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L010_STRING_UNKNOW_ERROR_CODE);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetPalErrorString(VL53L0_Error PalErrorCode,
+ char *pPalErrorString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ switch (PalErrorCode) {
+ VL53L010_BUILDSTATUSERRORSTRING(pPalErrorString,
+ VL53L0_ERROR_NONE, VL53L010_STRING_ERROR_NONE);
+ VL53L010_BUILDSTATUSERRORSTRING(pPalErrorString,
+ VL53L0_ERROR_CALIBRATION_WARNING,
+ VL53L010_STRING_ERROR_CALIBRATION_WARNING);
+ VL53L010_BUILDSTATUSERRORSTRING(pPalErrorString,
+ VL53L0_ERROR_MIN_CLIPPED,
+ VL53L010_STRING_ERROR_MIN_CLIPPED);
+ VL53L010_BUILDSTATUSERRORSTRING(pPalErrorString,
+ VL53L0_ERROR_UNDEFINED, VL53L010_STRING_ERROR_UNDEFINED);
+ VL53L010_BUILDSTATUSERRORSTRING(pPalErrorString,
+ VL53L0_ERROR_INVALID_PARAMS,
+ VL53L010_STRING_ERROR_INVALID_PARAMS);
+ VL53L010_BUILDSTATUSERRORSTRING(pPalErrorString,
+ VL53L0_ERROR_NOT_SUPPORTED,
+ VL53L010_STRING_ERROR_NOT_SUPPORTED);
+ VL53L010_BUILDSTATUSERRORSTRING(pPalErrorString,
+ VL53L0_ERROR_RANGE_ERROR,
+ VL53L010_STRING_ERROR_RANGE_ERROR);
+ VL53L010_BUILDSTATUSERRORSTRING(pPalErrorString,
+ VL53L0_ERROR_TIME_OUT,
+ VL53L010_STRING_ERROR_TIME_OUT);
+ VL53L010_BUILDSTATUSERRORSTRING(pPalErrorString,
+ VL53L0_ERROR_MODE_NOT_SUPPORTED,
+ VL53L010_STRING_ERROR_MODE_NOT_SUPPORTED);
+ VL53L010_BUILDSTATUSERRORSTRING(pPalErrorString,
+ VL53L0_ERROR_NOT_IMPLEMENTED,
+ VL53L010_STRING_ERROR_NOT_IMPLEMENTED);
+ VL53L010_BUILDSTATUSERRORSTRING(pPalErrorString,
+ VL53L0_ERROR_BUFFER_TOO_SMALL,
+ VL53L010_STRING_ERROR_BUFFER_TOO_SMALL);
+ VL53L010_BUILDSTATUSERRORSTRING(pPalErrorString,
+ VL53L0_ERROR_GPIO_NOT_EXISTING,
+ VL53L010_STRING_ERROR_GPIO_NOT_EXISTING);
+ VL53L010_BUILDSTATUSERRORSTRING(pPalErrorString,
+ VL53L0_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED,
+ VL53L010_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED);
+ VL53L010_BUILDSTATUSERRORSTRING(pPalErrorString,
+ VL53L0_ERROR_CONTROL_INTERFACE,
+ VL53L010_STRING_ERROR_CONTROL_INTERFACE);
+ default:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L010_STRING_UNKNOW_ERROR_CODE);
+ break;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L0_Error VL53L010_GetPalState(VL53L0_DEV Dev, VL53L0_State *pPalState)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pPalState = PALDevDataGet(Dev, PalState);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_SetPowerMode(VL53L0_DEV Dev, VL53L0_PowerModes PowerMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ /* Only level1 of Power mode exists */
+ if ((PowerMode != VL53L0_POWERMODE_STANDBY_LEVEL1) &&
+ (PowerMode != VL53L0_POWERMODE_IDLE_LEVEL1)) {
+ Status = VL53L0_ERROR_MODE_NOT_SUPPORTED;
+ } else if (PowerMode == VL53L0_POWERMODE_STANDBY_LEVEL1) {
+ /* set the standby level1 of power mode */
+ Status = VL53L0_WrByte(Dev, 0x80, 0x00);
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Set PAL State to standby */
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_STANDBY);
+ PALDevDataSet(Dev, PowerMode,
+ VL53L0_POWERMODE_STANDBY_LEVEL1);
+ }
+
+ } else {
+ /* VL53L0_POWERMODE_IDLE_LEVEL1 */
+ Status = VL53L0_WrByte(Dev, 0x80, 0x01);
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L010_StaticInit(Dev);
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, PowerMode,
+ VL53L0_POWERMODE_IDLE_LEVEL1);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetPowerMode(VL53L0_DEV Dev, VL53L0_PowerModes *pPowerMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Byte;
+
+ LOG_FUNCTION_START("");
+
+ /* Only level1 of Power mode exists */
+ Status = VL53L0_RdByte(Dev, 0x80, &Byte);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (Byte == 1)
+ PALDevDataSet(Dev, PowerMode,
+ VL53L0_POWERMODE_IDLE_LEVEL1);
+ else
+ PALDevDataSet(Dev, PowerMode,
+ VL53L0_POWERMODE_STANDBY_LEVEL1);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_SetOffsetCalibrationDataMicroMeter(VL53L0_DEV Dev,
+ int32_t OffsetCalibrationDataMicroMeter)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t OffsetCalibrationData;
+
+ LOG_FUNCTION_START("");
+
+ OffsetCalibrationData = (uint8_t) (OffsetCalibrationDataMicroMeter
+ / 1000);
+ Status = VL53L0_WrByte(Dev, VL53L010_REG_ALGO_PART_TO_PART_RANGE_OFFSET,
+ *(uint8_t *) &OffsetCalibrationData);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetOffsetCalibrationDataMicroMeter(VL53L0_DEV Dev,
+ int32_t *pOffsetCalibrationDataMicroMeter)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t RangeOffsetRegister;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L010_REG_ALGO_PART_TO_PART_RANGE_OFFSET,
+ &RangeOffsetRegister);
+ if (Status == VL53L0_ERROR_NONE) {
+ *pOffsetCalibrationDataMicroMeter =
+ (*((int8_t *) (&RangeOffsetRegister))) * 1000;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_SetGroupParamHold(VL53L0_DEV Dev, uint8_t GroupParamHold)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NOT_IMPLEMENTED;
+
+ LOG_FUNCTION_START("");
+
+ /* not implemented on VL53L0 */
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetUpperLimitMilliMeter(VL53L0_DEV Dev,
+ uint16_t *pUpperLimitMilliMeter)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NOT_IMPLEMENTED;
+
+ LOG_FUNCTION_START("");
+
+ /* not implemented on VL53L0 */
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+/* End Group PAL General Functions */
+
+/* Group PAL Init Functions */
+VL53L0_Error VL53L010_SetDeviceAddress(VL53L0_DEV Dev, uint8_t DeviceAddress)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_WrByte(Dev, VL53L010_REG_I2C_SLAVE_DEVICE_ADDRESS,
+ DeviceAddress / 2);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_DataInit(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+ VL53L0_DeviceSpecificParameters_t DeviceSpecificParameters;
+ int32_t OffsetCalibrationData;
+
+ LOG_FUNCTION_START("");
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* read device info */
+ VL53L010_SETDEVICESPECIFICPARAMETER(Dev, ReadDataFromDeviceDone, 0);
+
+ Status = VL53L010_get_info_from_device(Dev);
+ }
+
+ /* Set Default static parameters */
+ /* set first temporary values 11.3999MHz * 65536 = 748421 */
+ VL53L010_SETDEVICESPECIFICPARAMETER(Dev, OscFrequencyMHz, 748421);
+ /* 11.3999MHz * 65536 = 748421 */
+
+ /* Get default parameters */
+ Status = VL53L010_GetDeviceParameters(Dev, &CurrentParameters);
+ if (Status == VL53L0_ERROR_NONE) {
+ /* initialize PAL values */
+ CurrentParameters.DeviceMode = VL53L0_DEVICEMODE_SINGLE_RANGING;
+ CurrentParameters.HistogramMode = VL53L0_HISTOGRAMMODE_DISABLED;
+ PALDevDataSet(Dev, CurrentParameters, CurrentParameters);
+ }
+
+ /* Sigma estimator variable */
+ PALDevDataSet(Dev, SigmaEstRefArray, 100);
+ PALDevDataSet(Dev, SigmaEstEffPulseWidth, 900);
+ PALDevDataSet(Dev, SigmaEstEffAmbWidth, 500);
+
+ /* Set Signal and Sigma check */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_SetLimitCheckEnable(Dev,
+ VL53L010_CHECKENABLE_SIGMA_FINAL_RANGE, 0);
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_SetLimitCheckEnable(Dev,
+ VL53L010_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 0);
+ }
+ if(Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_SetLimitCheckValue(Dev,
+ VL53L010_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (FixPoint1616_t)(32<<16));
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_SetLimitCheckValue(Dev,
+ VL53L010_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (FixPoint1616_t)(25 * 65536 / 100));
+ /* 0.25 * 65538 */
+ }
+
+ /* Read back NVM offset */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_GetOffsetCalibrationDataMicroMeter(Dev,
+ &OffsetCalibrationData);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ PALDevDataSet(Dev, Part2PartOffsetNVMMicroMeter,
+ OffsetCalibrationData);
+
+ PALDevDataSet(Dev, SequenceConfig, 0xFF);
+
+ /* Set PAL state to tell that we are waiting for call
+ to VL53L010_StaticInit */
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_WAIT_STATICINIT);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L0_Error VL53L010_StaticInit(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceSpecificParameters_t DeviceSpecificParameters;
+ VL53L0_DeviceParameters_t CurrentParameters;
+ uint16_t TempWord;
+ uint8_t TempByte;
+ uint8_t localBuffer[32];
+ uint8_t i;
+ uint8_t Revision;
+
+ LOG_FUNCTION_START("");
+
+ /* Set I2C standard mode */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev, 0x88, 0x00);
+
+ /* this function do nothing if it has been called before */
+ Status = VL53L010_get_info_from_device(Dev);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Revision = VL53L010_GETDEVICESPECIFICPARAMETER(Dev, Revision);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (Revision == 0)
+ Status = VL53L010_load_additional_settings1(Dev);
+ }
+
+ /* update13_05_15 */
+ if (Status == VL53L0_ERROR_NONE) {
+ if ((Revision <= 34) && (Revision != 32)) {
+
+ for (i = 0; i < 32; i++)
+ localBuffer[i] = 0xff;
+
+ Status = VL53L0_WriteMulti(Dev, 0x90, localBuffer, 32);
+
+ Status |= VL53L0_WrByte(Dev, 0xb6, 16);
+ Status |= VL53L0_WrByte(Dev, 0xb0, 0x0);
+ Status |= VL53L0_WrByte(Dev, 0xb1, 0x0);
+ Status |= VL53L0_WrByte(Dev, 0xb2, 0xE0);
+ Status |= VL53L0_WrByte(Dev, 0xb3, 0xE0);
+ Status |= VL53L0_WrByte(Dev, 0xb4, 0xE0);
+ Status |= VL53L0_WrByte(Dev, 0xb5, 0xE0);
+ }
+ }
+
+ /* update 17_06_15_v10 */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L010_load_tuning_settings(Dev);
+
+ /* check if GO1 power is ON after load default tuning */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdByte(Dev, 0x80, &TempByte);
+ if ((TempByte != 0) && (Status == VL53L0_ERROR_NONE)) {
+ /* update 07_05_15 */
+ Status = VL53L010_load_additional_settings3(Dev);
+ }
+ }
+
+ /* Set interrupt config to new sample ready */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_SetGpioConfig(Dev, 0, 0,
+ VL53L010_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY,
+ VL53L0_INTERRUPTPOLARITY_LOW);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_RdWord(Dev, 0x84, &TempWord);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L010_SETDEVICESPECIFICPARAMETER(Dev, OscFrequencyMHz,
+ VL53L010_FIXPOINT412TOFIXPOINT1616(TempWord));
+ }
+
+ /* After static init, some device parameters may be changed,
+ so update them */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L010_GetDeviceParameters(Dev, &CurrentParameters);
+
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, CurrentParameters, CurrentParameters);
+
+
+ /* read the sequence config and save it */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdByte(Dev, VL53L010_REG_SYSTEM_SEQUENCE_CONFIG,
+ &TempByte);
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, SequenceConfig, TempByte);
+
+ }
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L010_PerformRefCalibration(Dev);
+
+ /* Set PAL State to standby */
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_IDLE);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_WaitDeviceBooted(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NOT_IMPLEMENTED;
+
+ LOG_FUNCTION_START("");
+
+ /* not implemented on VL53L0 */
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_ResetDevice(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Byte;
+
+ LOG_FUNCTION_START("");
+
+ /* Set reset bit */
+ Status = VL53L0_WrByte(Dev, VL53L010_REG_SOFT_RESET_GO2_SOFT_RESET_N,
+ 0x00);
+
+ /* Wait for some time */
+ if (Status == VL53L0_ERROR_NONE) {
+ do {
+ Status = VL53L0_RdByte(Dev,
+ VL53L010_REG_IDENTIFICATION_MODEL_ID, &Byte);
+ } while (Byte != 0x00);
+ }
+
+ /* Release reset */
+ Status = VL53L0_WrByte(Dev, VL53L010_REG_SOFT_RESET_GO2_SOFT_RESET_N,
+ 0x01);
+
+ /* Wait until correct boot-up of the device */
+ if (Status == VL53L0_ERROR_NONE) {
+ do {
+ Status = VL53L0_RdByte(Dev,
+ VL53L010_REG_IDENTIFICATION_MODEL_ID, &Byte);
+ } while (Byte == 0x00);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+/* End Group PAL Init Functions */
+
+/* Group PAL Parameters Functions */
+VL53L0_Error VL53L010_SetDeviceParameters(VL53L0_DEV Dev,
+ const VL53L0_DeviceParameters_t*
+ pDeviceParameters)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int i;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L010_SetDeviceMode(Dev, pDeviceParameters->DeviceMode);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_SetHistogramMode(Dev,
+ pDeviceParameters->HistogramMode);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_SetInterMeasurementPeriodMilliSeconds(Dev,
+
+ pDeviceParameters->InterMeasurementPeriodMilliSeconds);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_SetXTalkCompensationEnable(Dev,
+
+ pDeviceParameters->XTalkCompensationEnable);
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_SetXTalkCompensationRateMegaCps(Dev,
+
+ pDeviceParameters->XTalkCompensationRateMegaCps);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_SetOffsetCalibrationDataMicroMeter(Dev,
+ pDeviceParameters->RangeOffsetMicroMeters);
+ }
+
+ for (i = 0; i < VL53L010_CHECKENABLE_NUMBER_OF_CHECKS; i++) {
+ if (Status == VL53L0_ERROR_NONE) {
+ Status |= VL53L010_SetLimitCheckEnable(Dev, i,
+ pDeviceParameters->LimitChecksEnable[i]);
+ } else {
+ break;
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status |= VL53L010_SetLimitCheckValue(Dev, i,
+ pDeviceParameters->LimitChecksValue[i]);
+ } else {
+ break;
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_SetWrapAroundCheckEnable(Dev,
+
+ pDeviceParameters->WrapAroundCheckEnable);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_SetMeasurementTimingBudgetMicroSeconds(Dev,
+
+ pDeviceParameters->MeasurementTimingBudgetMicroSeconds);
+ }
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetDeviceParameters(VL53L0_DEV Dev,
+ VL53L0_DeviceParameters_t *pDeviceParameters)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int i;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L010_GetDeviceMode(Dev, &(pDeviceParameters->DeviceMode));
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_GetHistogramMode(Dev,
+ &(pDeviceParameters->HistogramMode));
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_GetInterMeasurementPeriodMilliSeconds(Dev,
+ &(pDeviceParameters->InterMeasurementPeriodMilliSeconds));
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_GetXTalkCompensationEnable(Dev,
+ &(pDeviceParameters->XTalkCompensationEnable));
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_GetXTalkCompensationRateMegaCps(Dev,
+
+ &(pDeviceParameters->XTalkCompensationRateMegaCps));
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_GetOffsetCalibrationDataMicroMeter(Dev,
+ &(pDeviceParameters->RangeOffsetMicroMeters));
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ for (i = 0; i < VL53L010_CHECKENABLE_NUMBER_OF_CHECKS; i++) {
+ // get first the values, then the enables.
+ // VL53L0_GetLimitCheckValue will modify the enable flags
+ if (Status == VL53L0_ERROR_NONE) {
+ Status |= VL53L010_GetLimitCheckValue(Dev, i,
+ &(pDeviceParameters->LimitChecksValue[i]));
+ } else {
+ break;
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status |= VL53L010_GetLimitCheckEnable(Dev, i,
+ &(pDeviceParameters->LimitChecksEnable[i]));
+ } else {
+ break;
+ }
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_GetWrapAroundCheckEnable(Dev,
+ &(pDeviceParameters->WrapAroundCheckEnable));
+ }
+
+ /* Need to be done at the end as it uses VCSELPulsePeriod */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_GetMeasurementTimingBudgetMicroSeconds(Dev,
+ &(pDeviceParameters->MeasurementTimingBudgetMicroSeconds));
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_SetDeviceMode(VL53L0_DEV Dev,
+ VL53L0_DeviceModes DeviceMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+
+ LOG_FUNCTION_START("%d", (int)DeviceMode);
+
+ switch (DeviceMode) {
+ case VL53L0_DEVICEMODE_SINGLE_RANGING:
+ case VL53L0_DEVICEMODE_CONTINUOUS_RANGING:
+ case VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING:
+ case VL53L0_DEVICEMODE_SINGLE_HISTOGRAM:
+ case VL53L0_DEVICEMODE_GPIO_DRIVE:
+ case VL53L0_DEVICEMODE_GPIO_OSC:
+ /* Supported mode */
+ VL53L010_SETPARAMETERFIELD(Dev, DeviceMode, DeviceMode);
+ break;
+ default:
+ /* Unsupported mode */
+ Status = VL53L0_ERROR_MODE_NOT_SUPPORTED;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetDeviceMode(VL53L0_DEV Dev,
+ VL53L0_DeviceModes *pDeviceMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+
+ LOG_FUNCTION_START("");
+
+ VL53L010_GETPARAMETERFIELD(Dev, DeviceMode, *pDeviceMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_SetHistogramMode(VL53L0_DEV Dev,
+ VL53L0_HistogramModes HistogramMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+
+ LOG_FUNCTION_START("%d", (int)HistogramMode);
+
+ switch (HistogramMode) {
+ case VL53L0_HISTOGRAMMODE_DISABLED:
+ /* Supported mode */
+ VL53L010_SETPARAMETERFIELD(Dev, HistogramMode,
+ HistogramMode);
+ break;
+ case VL53L0_HISTOGRAMMODE_REFERENCE_ONLY:
+ case VL53L0_HISTOGRAMMODE_RETURN_ONLY:
+ case VL53L0_HISTOGRAMMODE_BOTH:
+ default:
+ /* Unsupported mode */
+ Status = VL53L0_ERROR_MODE_NOT_SUPPORTED;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetHistogramMode(VL53L0_DEV Dev,
+ VL53L0_HistogramModes *pHistogramMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+
+ LOG_FUNCTION_START("");
+
+ VL53L010_GETPARAMETERFIELD(Dev, HistogramMode, *pHistogramMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_SetMeasurementTimingBudgetMicroSeconds(VL53L0_DEV Dev,
+ uint32_t MeasurementTimingBudgetMicroSeconds)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+ VL53L0_DeviceSpecificParameters_t DeviceSpecificParameters;
+ uint8_t CurrentVCSELPulsePeriod;
+ uint8_t CurrentVCSELPulsePeriodPClk;
+ uint8_t Byte;
+ uint32_t NewTimingBudgetMicroSeconds;
+ uint16_t encodedTimeOut;
+
+ LOG_FUNCTION_START("");
+
+ /* check if rangeB is done: */
+ Status = VL53L010_GetWrapAroundCheckEnable(Dev, &Byte);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (((Byte == 1) && (MeasurementTimingBudgetMicroSeconds <
+17000)) ||
+ ((Byte == 0) && (MeasurementTimingBudgetMicroSeconds <
+12000))) {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ NewTimingBudgetMicroSeconds =
+MeasurementTimingBudgetMicroSeconds -
+ 7000;
+ if (Byte == 1) {
+ NewTimingBudgetMicroSeconds =
+ (uint32_t)(NewTimingBudgetMicroSeconds >> 1);
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_get_vcsel_pulse_period(Dev,
+ &CurrentVCSELPulsePeriodPClk, 0);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ CurrentVCSELPulsePeriod = VL53L010_encode_vcsel_period(
+ CurrentVCSELPulsePeriodPClk);
+ encodedTimeOut = VL53L010_calc_encoded_timeout(Dev,
+ NewTimingBudgetMicroSeconds,
+ (uint8_t)
+ CurrentVCSELPulsePeriod);
+ VL53L010_SETPARAMETERFIELD(Dev,
+MeasurementTimingBudgetMicroSeconds,
+ MeasurementTimingBudgetMicroSeconds);
+ VL53L010_SETDEVICESPECIFICPARAMETER(Dev, LastEncodedTimeout,
+ encodedTimeOut);
+ }
+
+ /* Program in register */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_WrWord(Dev, VL53L010_REG_RNGA_TIMEOUT_MSB,
+ encodedTimeOut);
+ }
+
+ /* Temp: program same value for rangeB1 and rangeB2 */
+ /* Range B1 */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_get_vcsel_pulse_period(Dev,
+ &CurrentVCSELPulsePeriodPClk, 1);
+ if (Status == VL53L0_ERROR_NONE) {
+ CurrentVCSELPulsePeriod = VL53L010_encode_vcsel_period(
+ CurrentVCSELPulsePeriodPClk);
+ encodedTimeOut = VL53L010_calc_encoded_timeout(Dev,
+ NewTimingBudgetMicroSeconds,
+ (uint8_t)
+ CurrentVCSELPulsePeriod);
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_WrWord(Dev, VL53L010_REG_RNGB1_TIMEOUT_MSB,
+ encodedTimeOut);
+ }
+
+ /* Range B2 */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_get_vcsel_pulse_period(Dev,
+ &CurrentVCSELPulsePeriodPClk, 2);
+ if (Status == VL53L0_ERROR_NONE) {
+ CurrentVCSELPulsePeriod = VL53L010_encode_vcsel_period(
+ CurrentVCSELPulsePeriodPClk);
+ encodedTimeOut = VL53L010_calc_encoded_timeout(Dev,
+ NewTimingBudgetMicroSeconds,
+ (uint8_t)
+ CurrentVCSELPulsePeriod);
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_WrWord(Dev, VL53L010_REG_RNGB2_TIMEOUT_MSB,
+ encodedTimeOut);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetMeasurementTimingBudgetMicroSeconds(VL53L0_DEV Dev,
+ uint32_t *pMeasurementTimingBudgetMicroSeconds)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+ uint8_t CurrentVCSELPulsePeriod;
+ uint8_t CurrentVCSELPulsePeriodPClk;
+ uint16_t encodedTimeOut;
+ uint32_t RangATimingBudgetMicroSeconds = 0;
+ uint32_t RangBTimingBudgetMicroSeconds = 0;
+ uint8_t Byte;
+
+ LOG_FUNCTION_START("");
+
+ /* check if rangeB is done: */
+ Status = VL53L010_GetWrapAroundCheckEnable(Dev, &Byte);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L010_get_vcsel_pulse_period(Dev,
+ &CurrentVCSELPulsePeriodPClk, 0);
+ CurrentVCSELPulsePeriod = VL53L010_encode_vcsel_period(
+ CurrentVCSELPulsePeriodPClk);
+
+ /* Read from register */
+ Status = VL53L0_RdWord(Dev, VL53L010_REG_RNGA_TIMEOUT_MSB,
+ &encodedTimeOut);
+ if (Status == VL53L0_ERROR_NONE) {
+ RangATimingBudgetMicroSeconds =
+ VL53L010_calc_ranging_wait_us(Dev,
+ encodedTimeOut,
+ CurrentVCSELPulsePeriod);
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (Byte == 0) {
+ *pMeasurementTimingBudgetMicroSeconds =
+ RangATimingBudgetMicroSeconds + 7000;
+ VL53L010_SETPARAMETERFIELD(Dev,
+ MeasurementTimingBudgetMicroSeconds,
+ *pMeasurementTimingBudgetMicroSeconds);
+ } else {
+ VL53L010_get_vcsel_pulse_period(Dev,
+ &CurrentVCSELPulsePeriodPClk, 1);
+ CurrentVCSELPulsePeriod = VL53L010_encode_vcsel_period(
+ CurrentVCSELPulsePeriodPClk);
+
+ /* Read from register */
+ Status = VL53L0_RdWord(Dev,
+ VL53L010_REG_RNGB1_TIMEOUT_MSB,
+ &encodedTimeOut);
+ if (Status == VL53L0_ERROR_NONE) {
+ RangBTimingBudgetMicroSeconds =
+ VL53L010_calc_ranging_wait_us(
+ Dev, encodedTimeOut,
+ CurrentVCSELPulsePeriod);
+ }
+
+ *pMeasurementTimingBudgetMicroSeconds =
+ RangATimingBudgetMicroSeconds +
+ RangBTimingBudgetMicroSeconds +
+ 7000;
+ VL53L010_SETPARAMETERFIELD(Dev,
+ MeasurementTimingBudgetMicroSeconds,
+ *pMeasurementTimingBudgetMicroSeconds);
+ }
+ }
+
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_SetInterMeasurementPeriodMilliSeconds(VL53L0_DEV Dev,
+ uint32_t InterMeasurementPeriodMilliSeconds)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+ uint16_t osc_calibrate_val;
+ uint32_t IMPeriodMilliSeconds;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdWord(Dev, VL53L010_REG_OSC_CALIBRATE_VAL,
+ &osc_calibrate_val);
+
+ if (Status == VL53L0_ERROR_NONE) {
+
+ if (osc_calibrate_val != 0) {
+
+ IMPeriodMilliSeconds =
+ InterMeasurementPeriodMilliSeconds *
+ osc_calibrate_val;
+ } else {
+ IMPeriodMilliSeconds =
+ InterMeasurementPeriodMilliSeconds;
+ }
+ Status = VL53L0_WrDWord(Dev,
+ VL53L010_REG_SYSTEM_INTERMEASUREMENT_PERIOD,
+ IMPeriodMilliSeconds);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L010_SETPARAMETERFIELD(Dev,
+ InterMeasurementPeriodMilliSeconds,
+ InterMeasurementPeriodMilliSeconds);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetInterMeasurementPeriodMilliSeconds(VL53L0_DEV Dev,
+ uint32_t *pInterMeasurementPeriodMilliSeconds)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+ uint16_t osc_calibrate_val;
+ uint32_t IMPeriodMilliSeconds;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdWord(Dev, VL53L010_REG_OSC_CALIBRATE_VAL,
+ &osc_calibrate_val);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdDWord(Dev,
+ VL53L010_REG_SYSTEM_INTERMEASUREMENT_PERIOD,
+ &IMPeriodMilliSeconds);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (osc_calibrate_val != 0)
+ *pInterMeasurementPeriodMilliSeconds =
+ IMPeriodMilliSeconds /
+ osc_calibrate_val;
+
+ VL53L010_SETPARAMETERFIELD(Dev,
+ InterMeasurementPeriodMilliSeconds,
+ *pInterMeasurementPeriodMilliSeconds);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_SetXTalkCompensationEnable(VL53L0_DEV Dev,
+ uint8_t XTalkCompensationEnable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+ uint8_t XTalkCompensationEnableValue;
+
+ LOG_FUNCTION_START("");
+
+ if (XTalkCompensationEnable == 0) {
+ /* Disable the crosstalk compensation */
+ XTalkCompensationEnableValue = 0x00;
+ } else {
+ /* Enable the crosstalk compensation */
+ XTalkCompensationEnableValue = 0x01;
+ }
+ Status = VL53L0_UpdateByte(Dev, VL53L010_REG_ALGO_RANGE_CHECK_ENABLES,
+ 0xFE,
+ XTalkCompensationEnableValue);
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L010_SETPARAMETERFIELD(Dev, XTalkCompensationEnable,
+ XTalkCompensationEnableValue);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetXTalkCompensationEnable(VL53L0_DEV Dev, uint8_t*
+ pXTalkCompensationEnable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+ uint8_t data;
+ uint8_t Temp;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L010_REG_ALGO_RANGE_CHECK_ENABLES, &data);
+ if (Status == VL53L0_ERROR_NONE) {
+ if (data & 0x01)
+ Temp = 0x01;
+ else
+ Temp = 0x00;
+
+ *pXTalkCompensationEnable = Temp;
+ }
+ if (Status == VL53L0_ERROR_NONE)
+ VL53L010_SETPARAMETERFIELD(Dev, XTalkCompensationEnable, Temp);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_SetXTalkCompensationRateMegaCps(VL53L0_DEV Dev,
+ FixPoint1616_t XTalkCompensationRateMegaCps)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_WrWord(Dev, VL53L010_REG_ALGO_CROSSTALK_COMPENSATION_RATE,
+ VL53L010_FIXPOINT1616TOFIXPOINT412(XTalkCompensationRateMegaCps));
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L010_SETPARAMETERFIELD(Dev, XTalkCompensationRateMegaCps,
+ XTalkCompensationRateMegaCps);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetXTalkCompensationRateMegaCps(VL53L0_DEV Dev,
+ FixPoint1616_t *pXTalkCompensationRateMegaCps)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint16_t Value;
+ FixPoint1616_t TempFix1616;
+ VL53L0_DeviceParameters_t CurrentParameters;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdWord(Dev, VL53L010_REG_ALGO_CROSSTALK_COMPENSATION_RATE,
+ (uint16_t *) &Value);
+ if (Status == VL53L0_ERROR_NONE) {
+ TempFix1616 = VL53L010_FIXPOINT412TOFIXPOINT1616(Value);
+ *pXTalkCompensationRateMegaCps = TempFix1616;
+ VL53L010_SETPARAMETERFIELD(Dev, XTalkCompensationRateMegaCps,
+ TempFix1616);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+/*
+ * CHECK LIMIT FUNCTIONS
+ */
+
+VL53L0_Error VL53L010_GetNumberOfLimitCheck(uint16_t *pNumberOfLimitCheck)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pNumberOfLimitCheck = VL53L010_CHECKENABLE_NUMBER_OF_CHECKS;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+#define VL53L010_BUILDCASESTRING(BUFFER, CODE, STRINGVALUE) \
+ do { \
+ case CODE: \
+ VL53L0_COPYSTRING(BUFFER, STRINGVALUE); \
+ break; \
+ } while (0)
+
+VL53L0_Error VL53L010_GetLimitCheckInfo(VL53L0_DEV Dev, uint16_t LimitCheckId,
+ char *pLimitCheckString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ switch (LimitCheckId) {
+ VL53L010_BUILDCASESTRING(pLimitCheckString,
+ VL53L010_CHECKENABLE_SIGMA_FINAL_RANGE,
+ VL53L010_STRING_CHECKENABLE_SIGMA);
+ VL53L010_BUILDCASESTRING(pLimitCheckString,
+ VL53L010_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ VL53L010_STRING_CHECKENABLE_SIGNAL_RATE);
+
+ default:
+ VL53L0_COPYSTRING(pLimitCheckString,
+ VL53L010_STRING_UNKNOW_ERROR_CODE);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_SetLimitCheckEnable(VL53L0_DEV Dev, uint16_t LimitCheckId,
+ uint8_t LimitCheckEnable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L010_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ } else {
+ if (LimitCheckEnable == 0) {
+ VL53L010_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
+ LimitCheckId, 0);
+ } else {
+ VL53L010_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
+ LimitCheckId, 1);
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetLimitCheckEnable(VL53L0_DEV Dev, uint16_t LimitCheckId,
+ uint8_t *pLimitCheckEnable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+ uint8_t Temp8;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L010_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ } else {
+ VL53L010_GETARRAYPARAMETERFIELD(Dev, LimitChecksEnable, LimitCheckId, Temp8);
+ *pLimitCheckEnable = Temp8;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_SetLimitCheckValue(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t LimitCheckValue)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L010_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ } else {
+ VL53L010_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue, LimitCheckId,
+ LimitCheckValue);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetLimitCheckValue(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t *pLimitCheckValue)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L010_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ } else {
+ VL53L010_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
+ LimitCheckId, *pLimitCheckValue);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+VL53L0_Error VL53L010_GetLimitCheckCurrent(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t *pLimitCheckCurrent)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L010_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ } else {
+ switch (LimitCheckId) {
+ case VL53L010_CHECKENABLE_SIGMA_FINAL_RANGE:
+ /* Need to run a ranging to have the latest values */
+ *pLimitCheckCurrent = PALDevDataGet(Dev, SigmaEstimate);
+
+ break;
+
+ case VL53L010_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+ /* Need to run a ranging to have the latest values */
+ *pLimitCheckCurrent = PALDevDataGet(Dev, SignalEstimate);
+
+ break;
+ default:
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+/*
+ * WRAPAROUND LIMIT
+ */
+VL53L0_Error VL53L010_SetWrapAroundCheckEnable(VL53L0_DEV Dev, uint8_t
+ WrapAroundCheckEnable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Byte;
+ uint8_t WrapAroundCheckEnableInt;
+ VL53L0_DeviceParameters_t CurrentParameters;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L010_REG_SYSTEM_SEQUENCE_CONFIG, &Byte);
+ if (WrapAroundCheckEnable == 0) {
+ /* Disable wraparound */
+ Byte = Byte & 0x7F;
+ WrapAroundCheckEnableInt = 0;
+ } else {
+ /* Enable wraparound */
+ Byte = Byte | 0x80;
+ WrapAroundCheckEnableInt = 1;
+ }
+
+ Status = VL53L0_WrByte(Dev, VL53L010_REG_SYSTEM_SEQUENCE_CONFIG, Byte);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ PALDevDataSet(Dev, SequenceConfig, Byte);
+ VL53L010_SETPARAMETERFIELD(Dev, WrapAroundCheckEnable,
+ WrapAroundCheckEnableInt);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetWrapAroundCheckEnable(VL53L0_DEV Dev, uint8_t
+ *pWrapAroundCheckEnable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t data;
+ VL53L0_DeviceParameters_t CurrentParameters;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L010_REG_SYSTEM_SEQUENCE_CONFIG, &data);
+ if (Status == VL53L0_ERROR_NONE) {
+ PALDevDataSet(Dev, SequenceConfig, data);
+ if (data & (0x01 << 7))
+ *pWrapAroundCheckEnable = 0x01;
+ else
+ *pWrapAroundCheckEnable = 0x00;
+
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L010_SETPARAMETERFIELD(Dev, WrapAroundCheckEnable,
+ *pWrapAroundCheckEnable);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+/* End Group PAL Parameters Functions */
+
+/* Group PAL Measurement Functions */
+VL53L0_Error VL53L010_PerformSingleMeasurement(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceModes DeviceMode;
+ uint8_t NewDatReady = 0;
+ uint32_t LoopNb;
+
+ LOG_FUNCTION_START("");
+
+ /* Get Current DeviceMode */
+ Status = VL53L010_GetDeviceMode(Dev, &DeviceMode);
+
+ /* Start immediately to run a single ranging measurement in case of
+ single ranging or single histogram */
+ if ((Status == VL53L0_ERROR_NONE) &&
+ ((DeviceMode == VL53L0_DEVICEMODE_SINGLE_RANGING) ||
+ (DeviceMode ==
+ VL53L0_DEVICEMODE_SINGLE_HISTOGRAM))) {
+ Status = VL53L010_StartMeasurement(Dev);
+ }
+
+ /* Wait until it finished
+ use timeout to avoid deadlock
+ */
+ if (Status == VL53L0_ERROR_NONE) {
+ LoopNb = 0;
+ do {
+ Status = VL53L010_GetMeasurementDataReady(Dev,
+ &NewDatReady);
+ if ((NewDatReady == 0x01) || Status !=
+ VL53L0_ERROR_NONE) {
+ break;
+ }
+ LoopNb = LoopNb + 1;
+ VL53L0_PollingDelay(Dev);
+ } while (LoopNb < VL53L0_DEFAULT_MAX_LOOP);
+
+ if (LoopNb >= VL53L0_DEFAULT_MAX_LOOP)
+ Status = VL53L0_ERROR_TIME_OUT;
+
+ }
+
+ /* Change PAL State in case of single ranging or single histogram
+ */
+ if ((Status == VL53L0_ERROR_NONE) &&
+ ((DeviceMode == VL53L0_DEVICEMODE_SINGLE_RANGING) ||
+ (DeviceMode ==
+ VL53L0_DEVICEMODE_SINGLE_HISTOGRAM))) {
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_IDLE);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_PerformRefCalibration(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t NewDatReady = 0;
+ uint8_t Byte = 0;
+ uint8_t SequenceConfig = 0;
+ uint32_t LoopNb;
+
+ LOG_FUNCTION_START("");
+
+ /* store the value of the sequence config,
+ * this will be reset before the end of the function
+ */
+
+ SequenceConfig = PALDevDataGet(Dev, SequenceConfig);
+
+ Status = VL53L0_WrByte(Dev, VL53L010_REG_SYSTEM_SEQUENCE_CONFIG, 0x03);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ PALDevDataSet(Dev, SequenceConfig, 0x03);
+ Status = VL53L0_WrByte(Dev, VL53L010_REG_SYSRANGE_START,
+ VL53L010_REG_SYSRANGE_MODE_START_STOP);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Wait until start bit has been cleared */
+ LoopNb = 0;
+ do {
+ if (LoopNb > 0)
+ Status = VL53L0_RdByte(Dev,
+ VL53L010_REG_SYSRANGE_START, &Byte);
+ LoopNb = LoopNb + 1;
+ } while (((Byte & VL53L010_REG_SYSRANGE_MODE_START_STOP) ==
+ VL53L010_REG_SYSRANGE_MODE_START_STOP) &&
+ (Status == VL53L0_ERROR_NONE) &&
+ (LoopNb < VL53L0_DEFAULT_MAX_LOOP));
+ }
+
+ /* Wait until it finished
+ use timeout to avoid deadlock
+ */
+ if (Status == VL53L0_ERROR_NONE) {
+ LoopNb = 0;
+ do {
+ Status = VL53L010_GetMeasurementDataReady(Dev,
+ &NewDatReady);
+ if ((NewDatReady == 0x01) || Status !=
+ VL53L0_ERROR_NONE) {
+ break;
+ }
+ LoopNb = LoopNb + 1;
+ VL53L0_PollingDelay(Dev);
+ } while (LoopNb < VL53L0_DEFAULT_MAX_LOOP);
+
+ if (LoopNb >= VL53L0_DEFAULT_MAX_LOOP)
+ Status = VL53L0_ERROR_TIME_OUT;
+
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x04);
+ Status |= VL53L0_RdByte(Dev, 0x30, &Byte);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x31, Byte);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L010_ClearInterruptMask(Dev, 0);
+
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* restore the previous Sequence Config */
+ Status = VL53L0_WrByte(Dev, VL53L010_REG_SYSTEM_SEQUENCE_CONFIG,
+ SequenceConfig);
+ }
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, SequenceConfig, SequenceConfig);
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L010_API VL53L0_Error VL53L010_PerformXTalkCalibration(VL53L0_DEV Dev,
+ FixPoint1616_t XTalkCalDistance,
+ FixPoint1616_t *pXTalkCompensationRateMegaCps)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint16_t sum_ranging = 0;
+ uint16_t sum_spads = 0;
+ FixPoint1616_t sum_signalRate = 0;
+ FixPoint1616_t total_count = 0;
+ uint8_t xtalk_meas = 0;
+ VL53L0_RangingMeasurementData_t RangingMeasurementData;
+ FixPoint1616_t xTalkStoredMeanSignalRate;
+ FixPoint1616_t xTalkStoredMeanRange;
+ FixPoint1616_t xTalkStoredMeanRtnSpads;
+ uint32_t signalXTalkTotalPerSpad;
+ uint32_t xTalkStoredMeanRtnSpadsAsInt;
+ uint32_t xTalkCalDistanceAsInt;
+ FixPoint1616_t XTalkCompensationRateMegaCps;
+
+ LOG_FUNCTION_START("");
+
+ if (XTalkCalDistance <= 0)
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+
+
+ /* Disable the XTalk compensation */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L010_SetXTalkCompensationEnable(Dev, 0);
+
+
+ /* Perform 50 measurements and compute the averages */
+ if (Status == VL53L0_ERROR_NONE) {
+ sum_ranging = 0;
+ sum_spads = 0;
+ sum_signalRate = 0;
+ total_count = 0;
+ for (xtalk_meas = 0; xtalk_meas < 50; xtalk_meas++) {
+ Status = VL53L010_PerformSingleRangingMeasurement(Dev,
+ &RangingMeasurementData);
+
+ if (Status != VL53L0_ERROR_NONE)
+ break;
+
+ /* The range is valid when RangeStatus = 0 */
+ if (RangingMeasurementData.RangeStatus == 0) {
+ sum_ranging = sum_ranging +
+ RangingMeasurementData.RangeMilliMeter;
+ sum_signalRate = sum_signalRate +
+ RangingMeasurementData.SignalRateRtnMegaCps;
+ sum_spads = sum_spads +
+ RangingMeasurementData.EffectiveSpadRtnCount
+ / 32;
+ total_count = total_count + 1;
+ }
+ }
+
+ if (total_count == 0) {
+ /* no valid values found */
+ Status = VL53L0_ERROR_DIVISION_BY_ZERO;
+ }
+ }
+
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* FixPoint1616_t / uint16_t = FixPoint1616_t */
+ xTalkStoredMeanSignalRate = sum_signalRate / total_count;
+ xTalkStoredMeanRange =
+ (FixPoint1616_t)((uint32_t)(sum_ranging << 16) /
+ total_count);
+ xTalkStoredMeanRtnSpads =
+ (FixPoint1616_t)((uint32_t)(sum_spads<<16) /
+ total_count);
+
+ /* Round Mean Spads to Whole Number.
+ Typically the calculated mean SPAD count is a whole number or
+ very close to a whole
+ number, therefore any truncation will not result in a
+ significant loss in accuracy.
+ Also, for a grey target at a typical distance of around 400mm,
+ around 220 SPADs will
+ be enabled, therefore, any truncation will result in a loss of
+ accuracy of less than 0.5%.
+ */
+ xTalkStoredMeanRtnSpadsAsInt = (xTalkStoredMeanRtnSpads +
+ 0x8000) >> 16;
+
+ /* Round Cal Distance to Whole Number.
+ Note that the cal distance is in mm, therefore no resolution is
+ lost.
+ */
+ xTalkCalDistanceAsInt = (XTalkCalDistance + 0x8000) >> 16;
+
+ if (xTalkStoredMeanRtnSpadsAsInt == 0 || xTalkCalDistanceAsInt
+ == 0 ||
+ xTalkStoredMeanRange >= XTalkCalDistance) {
+ XTalkCompensationRateMegaCps = 0;
+ } else {
+ /* Round Cal Distance to Whole Number.
+ Note that the cal distance is in mm, therefore no
+ resolution is lost.
+ */
+ xTalkCalDistanceAsInt = (XTalkCalDistance + 0x8000) >>
+ 16;
+
+ /* Apply division by mean spad count early in the
+ calculation to keep the numbers small.
+ This ensures we can maintain a 32bit calculation.
+ Fixed1616 / int := Fixed1616
+ */
+ signalXTalkTotalPerSpad =
+ (xTalkStoredMeanSignalRate) /
+ xTalkStoredMeanRtnSpadsAsInt;
+
+ /* Complete the calculation for total Signal XTalk per
+ SPAD Fixed1616 * (Fixed1616 - Fixed1616/int)
+ := (2^16 * Fixed1616)
+ */
+ signalXTalkTotalPerSpad *= ((1<<16) -
+ (xTalkStoredMeanRange/xTalkCalDistanceAsInt));
+
+ /* Round from 2^16 * Fixed1616, to Fixed1616. */
+ XTalkCompensationRateMegaCps = (signalXTalkTotalPerSpad
+ + 0x8000) >> 16;
+ }
+
+ *pXTalkCompensationRateMegaCps = XTalkCompensationRateMegaCps;
+
+ /* Enable the XTalk compensation */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L010_SetXTalkCompensationEnable(Dev, 1);
+
+
+ /* Enable the XTalk compensation */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_SetXTalkCompensationRateMegaCps(Dev,
+ XTalkCompensationRateMegaCps);
+ }
+
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L010_API VL53L0_Error VL53L010_PerformOffsetCalibration(VL53L0_DEV Dev,
+ FixPoint1616_t CalDistanceMilliMeter,
+ int32_t* pOffsetMicroMeter) {
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint16_t sum_ranging = 0;
+ FixPoint1616_t total_count = 0;
+ VL53L0_RangingMeasurementData_t RangingMeasurementData;
+ FixPoint1616_t StoredMeanRange;
+ uint32_t StoredMeanRangeAsInt;
+ VL53L0_DeviceParameters_t CurrentParameters;
+ uint32_t CalDistanceAsInt_mm;
+ int meas = 0;
+ LOG_FUNCTION_START("");
+
+ if (CalDistanceMilliMeter<=0) {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L010_SetOffsetCalibrationDataMicroMeter(Dev, 0);
+ }
+
+ /* Perform 50 measurements and compute the averages */
+ if (Status == VL53L0_ERROR_NONE) {
+ sum_ranging = 0;
+ total_count = 0;
+ for(meas=0;meas<50;meas++)
+ {
+ Status = VL53L010_PerformSingleRangingMeasurement(Dev, &RangingMeasurementData);
+
+ if (Status != VL53L0_ERROR_NONE) {
+ break;
+ }
+
+ /* The range is valid when RangeStatus = 0 */
+ if (RangingMeasurementData.RangeStatus == 0) {
+ sum_ranging = sum_ranging + RangingMeasurementData.RangeMilliMeter;
+ total_count = total_count + 1;
+ }
+ }
+
+ if (total_count == 0) {
+ /* no valid values found */
+ Status = VL53L0_ERROR_RANGE_ERROR;
+ }
+ }
+
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* FixPoint1616_t / uint16_t = FixPoint1616_t */
+ StoredMeanRange = (FixPoint1616_t)((uint32_t)(sum_ranging<<16) / total_count);
+
+ StoredMeanRangeAsInt = (StoredMeanRange + 0x8000) >> 16;
+
+ /* Round Cal Distance to Whole Number.
+ * Note that the cal distance is in mm, therefore no resolution is lost.*/
+ CalDistanceAsInt_mm = (CalDistanceMilliMeter + 0x8000) >> 16;
+
+ *pOffsetMicroMeter = (CalDistanceAsInt_mm - StoredMeanRangeAsInt) * 1000;
+
+ /* Apply the calculated offset */
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L010_SETPARAMETERFIELD(Dev, RangeOffsetMicroMeters, *pOffsetMicroMeter);
+ Status = VL53L010_SetOffsetCalibrationDataMicroMeter(Dev, *pOffsetMicroMeter);
+ }
+
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_StartMeasurement(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceModes DeviceMode;
+ uint8_t Byte = 0;
+ uint32_t LoopNb;
+
+ LOG_FUNCTION_START("");
+
+ /* Get Current DeviceMode */
+ VL53L010_GetDeviceMode(Dev, &DeviceMode);
+
+ switch (DeviceMode) {
+ case VL53L0_DEVICEMODE_SINGLE_RANGING:
+ Status = VL53L0_WrByte(Dev, VL53L010_REG_SYSRANGE_START,
+ VL53L010_REG_SYSRANGE_MODE_SINGLESHOT |
+ VL53L010_REG_SYSRANGE_MODE_START_STOP);
+ break;
+ case VL53L0_DEVICEMODE_CONTINUOUS_RANGING:
+ /* Back-to-back mode */
+ Status = VL53L0_WrByte(Dev, VL53L010_REG_SYSRANGE_START,
+ VL53L010_REG_SYSRANGE_MODE_BACKTOBACK |
+ VL53L010_REG_SYSRANGE_MODE_START_STOP);
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Set PAL State to Running */
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_RUNNING);
+ }
+ break;
+ case VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING:
+ /* Continuous mode */
+ Status = VL53L0_WrByte(Dev, VL53L010_REG_SYSRANGE_START,
+ VL53L010_REG_SYSRANGE_MODE_TIMED |
+ VL53L010_REG_SYSRANGE_MODE_START_STOP);
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Set PAL State to Running */
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_RUNNING);
+ }
+ break;
+ default:
+ /* Selected mode not supported */
+ Status = VL53L0_ERROR_MODE_NOT_SUPPORTED;
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Wait until start bit has been cleared */
+ LoopNb = 0;
+ do {
+ if (LoopNb > 0)
+ Status = VL53L0_RdByte(Dev,
+ VL53L010_REG_SYSRANGE_START, &Byte);
+ LoopNb = LoopNb + 1;
+ } while (((Byte & VL53L010_REG_SYSRANGE_MODE_START_STOP) ==
+ VL53L010_REG_SYSRANGE_MODE_START_STOP) &&
+ (Status == VL53L0_ERROR_NONE) &&
+ (LoopNb < VL53L0_DEFAULT_MAX_LOOP));
+
+ if (LoopNb >= VL53L0_DEFAULT_MAX_LOOP)
+ Status = VL53L0_ERROR_TIME_OUT;
+
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_StopMeasurement(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_WrByte(Dev, VL53L010_REG_SYSRANGE_START,
+ VL53L010_REG_SYSRANGE_MODE_SINGLESHOT);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Set PAL State to Idle */
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_IDLE);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetMeasurementDataReady(VL53L0_DEV Dev, uint8_t
+ *pMeasurementDataReady)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t SysRangeStatusRegister;
+ uint8_t InterruptConfig;
+ uint32_t InterruptMask;
+
+ LOG_FUNCTION_START("");
+
+ InterruptConfig = VL53L010_GETDEVICESPECIFICPARAMETER(Dev,
+ Pin0GpioFunctionality);
+
+ if (InterruptConfig ==
+ VL53L010_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY) {
+ VL53L010_GetInterruptMaskStatus(Dev, &InterruptMask);
+ if (InterruptMask ==
+ VL53L010_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY){
+ *pMeasurementDataReady = 1;
+ } else {
+ *pMeasurementDataReady = 0;
+ }
+ } else {
+ Status = VL53L0_RdByte(Dev, VL53L010_REG_RESULT_RANGE_STATUS,
+ &SysRangeStatusRegister);
+ if (Status == VL53L0_ERROR_NONE) {
+ if (SysRangeStatusRegister & 0x01)
+ *pMeasurementDataReady = 1;
+ else
+ *pMeasurementDataReady = 0;
+
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_WaitDeviceReadyForNewMeasurement(VL53L0_DEV Dev, uint32_t
+ MaxLoop)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NOT_IMPLEMENTED;
+
+ LOG_FUNCTION_START("");
+
+ /* not implemented for VL53L0 */
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetRangingMeasurementData(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t DeviceRangeStatus;
+ uint8_t PalRangeStatus;
+ uint16_t AmbientRate;
+ FixPoint1616_t SignalRate;
+ FixPoint1616_t CrosstalkCompensation;
+ uint16_t EffectiveSpadRtnCount;
+ uint8_t localBuffer[14];
+ VL53L0_RangingMeasurementData_t LastRangeDataBuffer;
+
+ LOG_FUNCTION_START("");
+
+ /* use multi read even if some registers are not useful, result will be
+ more efficient
+ start reading at 0x14 dec20
+ end reading at 0x21 dec33 total 14 bytes to read
+ */
+ Status = VL53L0_ReadMulti(Dev, 0x14, localBuffer, 14);
+
+ if (Status == VL53L0_ERROR_NONE) {
+
+ pRangingMeasurementData->ZoneId = 0; /* Only one zone */
+ pRangingMeasurementData->TimeStamp = 0; /* Not Implemented */
+
+ pRangingMeasurementData->RangeMilliMeter =
+ VL53L010_MAKEUINT16(localBuffer[11], localBuffer[10]);
+
+ pRangingMeasurementData->RangeDMaxMilliMeter = 0;
+ pRangingMeasurementData->RangeFractionalPart = 0;
+ pRangingMeasurementData->MeasurementTimeUsec = 0;
+
+ SignalRate =
+ VL53L010_FIXPOINT97TOFIXPOINT1616(
+ VL53L010_MAKEUINT16(localBuffer[7], localBuffer[6]));
+ pRangingMeasurementData->SignalRateRtnMegaCps = SignalRate;
+
+ AmbientRate = VL53L010_MAKEUINT16(localBuffer[9], localBuffer[8]);
+ pRangingMeasurementData->AmbientRateRtnMegaCps =
+ VL53L010_FIXPOINT97TOFIXPOINT1616(AmbientRate);
+
+ EffectiveSpadRtnCount = VL53L010_MAKEUINT16(localBuffer[3],
+ localBuffer[2]);
+ pRangingMeasurementData->EffectiveSpadRtnCount =
+ EffectiveSpadRtnCount;
+
+ DeviceRangeStatus = localBuffer[0];
+
+ /* initial format = 4.12, when pass to 16.16 from 9.7 we shift
+ 5 bit more this will be absorbed in the further computation
+ */
+ CrosstalkCompensation =
+ VL53L010_FIXPOINT97TOFIXPOINT1616(
+ VL53L010_MAKEUINT16(localBuffer[13], localBuffer[12]));
+
+ /*
+ * For a standard definition of RangeStatus, this should return
+ * 0 in case of good result after a ranging
+ * The range status depends on the device so call a device
+ * specific function to obtain the right Status.
+ */
+ Status = VL53L010_get_pal_range_status(Dev, DeviceRangeStatus,
+ SignalRate, CrosstalkCompensation,
+ EffectiveSpadRtnCount,
+ pRangingMeasurementData, &PalRangeStatus);
+
+ if (Status == VL53L0_ERROR_NONE)
+ pRangingMeasurementData->RangeStatus = PalRangeStatus;
+
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Copy last read data into Dev buffer */
+ LastRangeDataBuffer = PALDevDataGet(Dev, LastRangeMeasure);
+
+ LastRangeDataBuffer.RangeMilliMeter =
+ pRangingMeasurementData->RangeMilliMeter;
+ LastRangeDataBuffer.RangeFractionalPart =
+ pRangingMeasurementData->RangeFractionalPart;
+ LastRangeDataBuffer.RangeDMaxMilliMeter =
+ pRangingMeasurementData->RangeDMaxMilliMeter;
+ LastRangeDataBuffer.MeasurementTimeUsec =
+ pRangingMeasurementData->MeasurementTimeUsec;
+ LastRangeDataBuffer.SignalRateRtnMegaCps =
+ pRangingMeasurementData->SignalRateRtnMegaCps;
+ LastRangeDataBuffer.AmbientRateRtnMegaCps =
+ pRangingMeasurementData->AmbientRateRtnMegaCps;
+ LastRangeDataBuffer.EffectiveSpadRtnCount =
+ pRangingMeasurementData->EffectiveSpadRtnCount;
+ LastRangeDataBuffer.RangeStatus =
+ pRangingMeasurementData->RangeStatus;
+
+ PALDevDataSet(Dev, LastRangeMeasure, LastRangeDataBuffer);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetHistogramMeasurementData(VL53L0_DEV Dev,
+ VL53L0_HistogramMeasurementData_t *pHistogramMeasurementData)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NOT_IMPLEMENTED;
+
+ LOG_FUNCTION_START("");
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L0_Error VL53L010_PerformSingleRangingMeasurement(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ /* This function will do a complete single ranging
+ * Here we fix the mode!
+ */
+ Status = VL53L010_SetDeviceMode(Dev, VL53L0_DEVICEMODE_SINGLE_RANGING);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L010_PerformSingleMeasurement(Dev);
+
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_GetRangingMeasurementData(Dev,
+ pRangingMeasurementData);
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L010_ClearInterruptMask(Dev, 0);
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L0_Error VL53L010_PerformSingleHistogramMeasurement(VL53L0_DEV Dev,
+ VL53L0_HistogramMeasurementData_t *pHistogramMeasurementData)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NOT_IMPLEMENTED;
+
+ LOG_FUNCTION_START("");
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_SetNumberOfROIZones(VL53L0_DEV Dev, uint8_t
+ NumberOfROIZones)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (NumberOfROIZones != 1)
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetNumberOfROIZones(VL53L0_DEV Dev, uint8_t*
+ pNumberOfROIZones)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pNumberOfROIZones = 1;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetMaxNumberOfROIZones(VL53L0_DEV Dev, uint8_t
+ *pMaxNumberOfROIZones)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pMaxNumberOfROIZones = 1;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+/* End Group PAL Measurement Functions */
+
+
+VL53L0_Error VL53L010_SetGpioConfig(VL53L0_DEV Dev, uint8_t Pin,
+ VL53L0_DeviceModes DeviceMode, VL53L0_GpioFunctionality Functionality,
+ VL53L0_InterruptPolarity Polarity)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceSpecificParameters_t DeviceSpecificParameters;
+ uint8_t data;
+
+ LOG_FUNCTION_START("");
+
+ if (Pin != 0) {
+ Status = VL53L0_ERROR_GPIO_NOT_EXISTING;
+ } else if (DeviceMode == VL53L0_DEVICEMODE_GPIO_DRIVE) {
+ if (Polarity == VL53L0_INTERRUPTPOLARITY_LOW) {
+ data = 0x10;
+ } else {
+ data = 1;
+ }
+ Status = VL53L0_WrByte(Dev,
+ VL53L010_REG_GPIO_HV_MUX_ACTIVE_HIGH, data);
+
+ } else if (DeviceMode == VL53L0_DEVICEMODE_GPIO_OSC) {
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x80, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x85, 0x02);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0xcd, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xcc, 0x11);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x07);
+ Status |= VL53L0_WrByte(Dev, 0xbe, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x06);
+ Status |= VL53L0_WrByte(Dev, 0xcc, 0x09);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x00);
+
+ } else {
+
+ if (Status == VL53L0_ERROR_NONE) {
+ switch (Functionality) {
+ case VL53L010_GPIOFUNCTIONALITY_OFF:
+ data = 0x00;
+ break;
+ case VL53L010_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW:
+ data = 0x01;
+ break;
+ case VL53L010_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH:
+ data = 0x02;
+ break;
+ case VL53L010_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT:
+ data = 0x03;
+ break;
+ case VL53L010_GPIOFUNCTIONALITY_NEW_MEASURE_READY:
+ data = 0x04;
+ break;
+ default:
+ Status = VL53L0_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED;
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_WrByte(Dev,
+ VL53L010_REG_SYSTEM_INTERRUPT_CONFIG_GPIO,
+ data);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (Polarity == VL53L0_INTERRUPTPOLARITY_LOW)
+ data = 0;
+ else
+ data = (uint8_t)(1<<4);
+
+ Status = VL53L0_UpdateByte(Dev,
+ VL53L010_REG_GPIO_HV_MUX_ACTIVE_HIGH,
+ 0xEF, data);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L010_SETDEVICESPECIFICPARAMETER(Dev, Pin0GpioFunctionality,
+ Functionality);
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L010_ClearInterruptMask(Dev, 0);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetGpioConfig(VL53L0_DEV Dev, uint8_t Pin,
+ VL53L0_DeviceModes *DeviceMode,
+ VL53L0_GpioFunctionality *pFunctionality,
+ VL53L0_InterruptPolarity *pPolarity)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceSpecificParameters_t DeviceSpecificParameters;
+ VL53L0_GpioFunctionality GpioFunctionality;
+ uint8_t data;
+
+ LOG_FUNCTION_START("");
+
+ if (Pin != 0) {
+ Status = VL53L0_ERROR_GPIO_NOT_EXISTING;
+ } else {
+ Status = VL53L0_RdByte(Dev,
+ VL53L010_REG_SYSTEM_INTERRUPT_CONFIG_GPIO,
+ &data);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ switch (data&0x07) {
+ case 0x00:
+ GpioFunctionality = VL53L010_GPIOFUNCTIONALITY_OFF;
+ break;
+ case 0x01:
+ GpioFunctionality =
+ VL53L010_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW;
+ break;
+ case 0x02:
+ GpioFunctionality =
+ VL53L010_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH;
+ break;
+ case 0x03:
+ GpioFunctionality =
+ VL53L010_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT;
+ break;
+ case 0x04:
+ GpioFunctionality =
+ VL53L010_GPIOFUNCTIONALITY_NEW_MEASURE_READY;
+ break;
+ default:
+ Status = VL53L0_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED;
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_RdByte(Dev,
+ VL53L010_REG_GPIO_HV_MUX_ACTIVE_HIGH, &data);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if ((data & (uint8_t)(1<<4)) == 0)
+ *pPolarity = VL53L0_INTERRUPTPOLARITY_LOW;
+ else
+ *pPolarity = VL53L0_INTERRUPTPOLARITY_HIGH;
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ *pFunctionality = GpioFunctionality;
+ VL53L010_SETDEVICESPECIFICPARAMETER(Dev, Pin0GpioFunctionality,
+ GpioFunctionality);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_SetInterruptThresholds(VL53L0_DEV Dev, VL53L0_DeviceModes
+ DeviceMode, FixPoint1616_t ThresholdLow, FixPoint1616_t ThresholdHigh)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint16_t Threshold16;
+
+ LOG_FUNCTION_START("");
+
+ /* no dependency on DeviceMode for Ewok */
+ /* Need to divide by 2 because the FW will apply a x2 */
+ Threshold16 = (uint16_t)((ThresholdLow >> 17) & 0x00fff);
+ Status = VL53L0_WrWord(Dev, VL53L010_REG_SYSTEM_THRESH_LOW, Threshold16);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Need to divide by 2 because the FW will apply a x2 */
+ Threshold16 = (uint16_t)((ThresholdHigh >> 17) & 0x00fff);
+ Status = VL53L0_WrWord(Dev, VL53L010_REG_SYSTEM_THRESH_HIGH,
+ Threshold16);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetInterruptThresholds(VL53L0_DEV Dev, VL53L0_DeviceModes
+ DeviceMode, FixPoint1616_t *pThresholdLow,
+ FixPoint1616_t *pThresholdHigh)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint16_t Threshold16;
+
+ LOG_FUNCTION_START("");
+
+ /* no dependency on DeviceMode for Ewok */
+
+ Status = VL53L0_RdWord(Dev, VL53L010_REG_SYSTEM_THRESH_LOW, &Threshold16);
+ /* Need to multiply by 2 because the FW will apply a x2 */
+ *pThresholdLow = (FixPoint1616_t)((0x00fff & Threshold16)<<17);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdWord(Dev, VL53L010_REG_SYSTEM_THRESH_HIGH,
+ &Threshold16);
+ /* Need to multiply by 2 because the FW will apply a x2 */
+ *pThresholdHigh = (FixPoint1616_t)((0x00fff & Threshold16)<<17);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+/* Group PAL Interrupt Functions */
+VL53L0_Error VL53L010_ClearInterruptMask(VL53L0_DEV Dev, uint32_t InterruptMask)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t LoopCount;
+ uint8_t Byte;
+
+ LOG_FUNCTION_START("");
+
+ /* clear bit 0 range interrupt, bit 1 error interrupt */
+ Status = VL53L0_WrByte(Dev, VL53L010_REG_SYSTEM_INTERRUPT_CLEAR, 0x01);
+ LoopCount = 0;
+ do {
+ VL53L0_RdByte(Dev, VL53L010_REG_RESULT_INTERRUPT_STATUS, &Byte);
+ LoopCount++;
+ } while (((Byte & 0x07) != 0x00) && (LoopCount < 8));
+ Status = VL53L0_WrByte(Dev, VL53L010_REG_SYSTEM_INTERRUPT_CLEAR, 0x00);
+ /* clear all */
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetInterruptMaskStatus(VL53L0_DEV Dev, uint32_t
+ *pInterruptMaskStatus)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Byte;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L010_REG_RESULT_INTERRUPT_STATUS, &Byte);
+ *pInterruptMaskStatus = Byte & 0x07;
+
+ if (Byte & 0x18) {
+ Status = VL53L0_ERROR_RANGE_ERROR; /* check if some error
+ occurs */
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_EnableInterruptMask(VL53L0_DEV Dev, uint32_t InterruptMask)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NOT_IMPLEMENTED;
+
+ LOG_FUNCTION_START("");
+
+ /* not implemented for VL53L0 */
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+/* End Group PAL Interrupt Functions */
+
+/* Group SPAD functions */
+
+VL53L0_Error VL53L010_SetSpadAmbientDamperThreshold(VL53L0_DEV Dev, uint16_t
+ SpadAmbientDamperThreshold)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status = VL53L0_WrWord(Dev, 0x40, SpadAmbientDamperThreshold);
+ VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetSpadAmbientDamperThreshold(VL53L0_DEV Dev, uint16_t
+ *pSpadAmbientDamperThreshold)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status = VL53L0_RdWord(Dev, 0x40, pSpadAmbientDamperThreshold);
+ VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_SetSpadAmbientDamperFactor(VL53L0_DEV Dev, uint16_t
+ SpadAmbientDamperFactor)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Byte;
+
+ LOG_FUNCTION_START("");
+
+ Byte = (uint8_t) (SpadAmbientDamperFactor & 0x00FF);
+
+ VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status = VL53L0_WrByte(Dev, 0x42, Byte);
+ VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_GetSpadAmbientDamperFactor(VL53L0_DEV Dev, uint16_t
+ *pSpadAmbientDamperFactor)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Byte;
+
+ LOG_FUNCTION_START("");
+
+ VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status = VL53L0_RdByte(Dev, 0x42, &Byte);
+ VL53L0_WrByte(Dev, 0xFF, 0x00);
+ *pSpadAmbientDamperFactor = (uint16_t) Byte;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+/* END Group SPAD functions */
+
+/*//////////////////////////////////////////////////////////////////////////////
+//
+//////////////////////////////////
+// Internal functions
+////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////
+*/
+
+
+VL53L010_EXTERNAL uint32_t VL53L010_calc_macro_period_ps(VL53L0_DEV Dev,
+ uint8_t vcsel_period);
+VL53L010_EXTERNAL uint16_t VL53L010_encode_timeout(uint32_t timeout_mclks);
+VL53L010_EXTERNAL uint32_t VL53L010_decode_timeout(uint16_t encoded_timeout);
+
+VL53L010_EXTERNAL VL53L0_Error VL53L010_get_vcsel_pulse_period(VL53L0_DEV Dev, uint8_t
+ *pVCSELPulsePeriod, uint8_t RangeIndex)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t vcsel_period_reg;
+
+ LOG_FUNCTION_START("");
+
+ switch (RangeIndex) {
+ case 0:
+ Status = VL53L0_RdByte(Dev, VL53L010_REG_RNGA_CONFIG_VCSEL_PERIOD,
+ &vcsel_period_reg);
+ break;
+ case 1:
+ Status = VL53L0_RdByte(Dev,
+ VL53L010_REG_RNGB1_CONFIG_VCSEL_PERIOD,
+ &vcsel_period_reg);
+ break;
+ case 2:
+ Status = VL53L0_RdByte(Dev,
+ VL53L010_REG_RNGB2_CONFIG_VCSEL_PERIOD,
+ &vcsel_period_reg);
+ break;
+ default:
+ Status = VL53L0_RdByte(Dev, VL53L010_REG_RNGA_CONFIG_VCSEL_PERIOD,
+ &vcsel_period_reg);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ *pVCSELPulsePeriod =
+ VL53L010_decode_vcsel_period(vcsel_period_reg);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+/* To convert ms into register value */
+VL53L010_EXTERNAL uint16_t VL53L010_calc_encoded_timeout(VL53L0_DEV Dev, uint32_t
+ timeout_period_us, uint8_t vcsel_period)
+{
+ uint32_t macro_period_ps;
+ uint32_t macro_period_ns;
+ uint32_t timeout_period_mclks = 0;
+ uint16_t timeout_overall_periods = 0;
+
+ macro_period_ps = VL53L010_calc_macro_period_ps(Dev, vcsel_period);
+ macro_period_ns = macro_period_ps / 1000;
+
+ timeout_period_mclks = (uint32_t) (((timeout_period_us * 1000) +
+ (macro_period_ns / 2)) / macro_period_ns);
+ timeout_overall_periods = VL53L010_encode_timeout(timeout_period_mclks);
+
+ return timeout_overall_periods;
+}
+
+/* To convert register value into us */
+VL53L010_EXTERNAL uint32_t VL53L010_calc_ranging_wait_us(VL53L0_DEV Dev, uint16_t
+ timeout_overall_periods, uint8_t vcsel_period)
+{
+ uint32_t macro_period_ps;
+ uint32_t macro_period_ns;
+ uint32_t timeout_period_mclks = 0;
+ uint32_t actual_timeout_period_us = 0;
+
+ macro_period_ps = VL53L010_calc_macro_period_ps(Dev, vcsel_period);
+ macro_period_ns = macro_period_ps / 1000;
+
+ timeout_period_mclks = VL53L010_decode_timeout(timeout_overall_periods);
+ actual_timeout_period_us = ((timeout_period_mclks * macro_period_ns) +
+ (macro_period_ns / 2)) / 1000;
+
+ return actual_timeout_period_us;
+}
+
+VL53L010_EXTERNAL uint32_t VL53L010_calc_macro_period_ps(VL53L0_DEV Dev,
+ uint8_t vcsel_period)
+{
+ uint32_t PLL_multiplier;
+ uint64_t PLL_period_ps;
+ uint8_t vcsel_period_pclks;
+ uint32_t macro_period_vclks;
+ uint32_t macro_period_ps;
+ FixPoint1616_t OscFrequencyMHz;
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceSpecificParameters_t DeviceSpecificParameters;
+
+ LOG_FUNCTION_START("");
+
+ PLL_multiplier = 65536 / 64; /* PLL multiplier is 64 */
+
+ OscFrequencyMHz = VL53L010_GETDEVICESPECIFICPARAMETER(Dev,
+ OscFrequencyMHz);
+
+ if (OscFrequencyMHz == 0) {
+ /* Use default one */
+ VL53L010_SETDEVICESPECIFICPARAMETER(Dev, OscFrequencyMHz, 748421);
+ OscFrequencyMHz = 748421;
+ }
+ PLL_period_ps = (1000 * 1000 * PLL_multiplier) /
+ OscFrequencyMHz;
+
+ vcsel_period_pclks = VL53L010_decode_vcsel_period(vcsel_period);
+
+ macro_period_vclks = 2304;
+ macro_period_ps = (uint32_t)(macro_period_vclks * vcsel_period_pclks *
+ PLL_period_ps);
+
+ LOG_FUNCTION_END("");
+ return macro_period_ps;
+}
+
+VL53L010_EXTERNAL uint8_t VL53L010_decode_vcsel_period(uint8_t vcsel_period_reg)
+{
+
+ /*!
+ * Converts the encoded VCSEL period register value into the real
+ * period in PLL clocks
+ */
+
+ uint8_t vcsel_period_pclks = 0;
+
+ vcsel_period_pclks = (vcsel_period_reg + 1) << 1;
+
+ return vcsel_period_pclks;
+}
+
+VL53L010_EXTERNAL uint8_t VL53L010_encode_vcsel_period(uint8_t vcsel_period_pclks)
+{
+
+ /*!
+ * Converts the encoded VCSEL period register value into the real
+ * period in PLL clocks
+ */
+
+ uint8_t vcsel_period_reg = 0;
+
+ vcsel_period_reg = (vcsel_period_pclks >> 1) - 1;
+
+ return vcsel_period_reg;
+}
+
+VL53L010_EXTERNAL uint16_t VL53L010_encode_timeout(uint32_t timeout_mclks)
+{
+ /*!
+ * Encode timeout in macro periods in (LSByte * 2^MSByte) + 1 format
+ *
+ */
+
+ uint16_t encoded_timeout = 0;
+ uint32_t ls_byte = 0;
+ uint16_t ms_byte = 0;
+
+ if (timeout_mclks > 0) {
+ ls_byte = timeout_mclks - 1;
+
+ while ((ls_byte & 0xFFFFFF00) > 0) {
+ ls_byte = ls_byte >> 1;
+ ms_byte++;
+ }
+
+ encoded_timeout = (ms_byte << 8) + (uint16_t) (ls_byte &
+ 0x000000FF);
+
+ }
+
+ return encoded_timeout;
+
+}
+
+VL53L010_EXTERNAL uint32_t VL53L010_decode_timeout(uint16_t encoded_timeout)
+{
+ /*!
+ * Decode 16-bit timeout register value - format (LSByte * 2^MSByte) + 1
+ *
+ */
+
+ uint32_t timeout_mclks = 0;
+
+ timeout_mclks = ((uint32_t) (encoded_timeout & 0x00FF) << (uint32_t)
+ ((encoded_timeout & 0xFF00) >> 8)) + 1;
+
+ return timeout_mclks;
+
+}
+
+
+VL53L010_EXTERNAL VL53L0_Error VL53L010_load_additional_settings1(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ /* update 12_05_15_v6 */
+ /* OSCT */
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x80, 0x01);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x14, 0x01);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xCD, 0x6C);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x86, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x87, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ /* update 12_05_15_v6 */
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xcd, 0x6c);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x90, 0x07);
+ Status |= VL53L0_WrByte(Dev, 0x91, 0x3f);
+ Status |= VL53L0_WrByte(Dev, 0x92, 0x3f);
+ Status |= VL53L0_WrByte(Dev, 0x88, 0x2b);
+ Status |= VL53L0_WrByte(Dev, 0x89, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xcd, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ /* update 12_05_15 */
+ Status |= VL53L0_WrByte(Dev, 0xb0, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xb1, 0xfc);
+ Status |= VL53L0_WrByte(Dev, 0xb2, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xb3, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xb4, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xb5, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xb6, 0xb0);
+
+ Status |= VL53L0_WrByte(Dev, 0x32, 0x03);
+
+ Status |= VL53L0_WrByte(Dev, 0x41, 0xff);
+ Status |= VL53L0_WrByte(Dev, 0x42, 0x07);
+ Status |= VL53L0_WrByte(Dev, 0x43, 0x01);
+
+ Status |= VL53L0_WrByte(Dev, 0x01, 0x01);
+
+ if (Status != 0)
+ Status = VL53L0_ERROR_CONTROL_INTERFACE;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L010_EXTERNAL VL53L0_Error VL53L010_load_additional_settings3(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ /* update 150624_b */
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x80, 0x01);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x4f, 0x0B);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x0E);
+
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x0C);
+ Status |= VL53L0_WrByte(Dev, 0x01, 0x0C);
+ Status |= VL53L0_WrByte(Dev, 0x02, 0x0A);
+ Status |= VL53L0_WrByte(Dev, 0x03, 0x0D);
+ Status |= VL53L0_WrByte(Dev, 0x04, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x05, 0x60);
+ Status |= VL53L0_WrByte(Dev, 0x06, 0x06);
+ Status |= VL53L0_WrByte(Dev, 0x07, 0x47);
+ Status |= VL53L0_WrByte(Dev, 0x08, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x09, 0x20);
+ Status |= VL53L0_WrByte(Dev, 0x0A, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x0B, 0x49);
+ Status |= VL53L0_WrByte(Dev, 0x0C, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x0D, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x0E, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x0F, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x10, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x11, 0xA1);
+ Status |= VL53L0_WrByte(Dev, 0x12, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x13, 0xA0);
+ Status |= VL53L0_WrByte(Dev, 0x14, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x15, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x16, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x17, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x18, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x19, 0xA0);
+ Status |= VL53L0_WrByte(Dev, 0x1A, 0x11);
+ Status |= VL53L0_WrByte(Dev, 0x1B, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x1C, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x1D, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x1E, 0x11);
+ Status |= VL53L0_WrByte(Dev, 0x1F, 0x08);
+ Status |= VL53L0_WrByte(Dev, 0x20, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x21, 0x02);
+ Status |= VL53L0_WrByte(Dev, 0x22, 0x0C);
+ Status |= VL53L0_WrByte(Dev, 0x23, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x24, 0x0A);
+ Status |= VL53L0_WrByte(Dev, 0x25, 0x0D);
+ Status |= VL53L0_WrByte(Dev, 0x26, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x27, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x28, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x29, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x2A, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x2B, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x2C, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x2D, 0x60);
+ Status |= VL53L0_WrByte(Dev, 0x2E, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x2F, 0x92);
+ Status |= VL53L0_WrByte(Dev, 0x30, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x31, 0x64);
+ Status |= VL53L0_WrByte(Dev, 0x32, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x33, 0x8A);
+ Status |= VL53L0_WrByte(Dev, 0x34, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x35, 0xE0);
+ Status |= VL53L0_WrByte(Dev, 0x36, 0x0F);
+ Status |= VL53L0_WrByte(Dev, 0x37, 0xAA);
+ Status |= VL53L0_WrByte(Dev, 0x38, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x39, 0xE4);
+ Status |= VL53L0_WrByte(Dev, 0x3A, 0x0F);
+ Status |= VL53L0_WrByte(Dev, 0x3B, 0xAE);
+ Status |= VL53L0_WrByte(Dev, 0x3C, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x3D, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x3E, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x3F, 0x54);
+ Status |= VL53L0_WrByte(Dev, 0x40, 0x05);
+ Status |= VL53L0_WrByte(Dev, 0x41, 0x88);
+ Status |= VL53L0_WrByte(Dev, 0x42, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x43, 0x02);
+ Status |= VL53L0_WrByte(Dev, 0x44, 0x0C);
+ Status |= VL53L0_WrByte(Dev, 0x45, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x46, 0x06);
+ Status |= VL53L0_WrByte(Dev, 0x47, 0x87);
+ Status |= VL53L0_WrByte(Dev, 0x48, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x49, 0x38);
+ Status |= VL53L0_WrByte(Dev, 0x4A, 0x2B);
+ Status |= VL53L0_WrByte(Dev, 0x4B, 0x89);
+ Status |= VL53L0_WrByte(Dev, 0x4C, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x4D, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x4E, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x4F, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x50, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x51, 0xA1);
+ Status |= VL53L0_WrByte(Dev, 0x52, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x53, 0xA0);
+ Status |= VL53L0_WrByte(Dev, 0x54, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x55, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x56, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x57, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x58, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x59, 0x0D);
+ Status |= VL53L0_WrByte(Dev, 0x5A, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x5B, 0x02);
+ Status |= VL53L0_WrByte(Dev, 0x5C, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x5D, 0x60);
+ Status |= VL53L0_WrByte(Dev, 0x5E, 0x0D);
+ Status |= VL53L0_WrByte(Dev, 0x5F, 0x67);
+ Status |= VL53L0_WrByte(Dev, 0x60, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x61, 0x60);
+ Status |= VL53L0_WrByte(Dev, 0x62, 0x0D);
+ Status |= VL53L0_WrByte(Dev, 0x63, 0xB0);
+ Status |= VL53L0_WrByte(Dev, 0x64, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x65, 0x20);
+ Status |= VL53L0_WrByte(Dev, 0x66, 0x29);
+ Status |= VL53L0_WrByte(Dev, 0x67, 0xC1);
+ Status |= VL53L0_WrByte(Dev, 0x68, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x69, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x6A, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x6B, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x6C, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x6D, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x6E, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x6F, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x70, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x71, 0xA1);
+ Status |= VL53L0_WrByte(Dev, 0x72, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x73, 0xA0);
+ Status |= VL53L0_WrByte(Dev, 0x74, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x75, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x76, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x77, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x78, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x79, 0x0D);
+ Status |= VL53L0_WrByte(Dev, 0x7A, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x7B, 0x1B);
+ Status |= VL53L0_WrByte(Dev, 0x7C, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x7D, 0x82);
+ Status |= VL53L0_WrByte(Dev, 0x7E, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x7F, 0x24);
+ Status |= VL53L0_WrByte(Dev, 0x80, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x81, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x82, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x83, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x84, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x85, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x86, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x87, 0x21);
+ Status |= VL53L0_WrByte(Dev, 0x88, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x89, 0x58);
+ Status |= VL53L0_WrByte(Dev, 0x8A, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x8B, 0xCC);
+ Status |= VL53L0_WrByte(Dev, 0x8C, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x8D, 0xC3);
+ Status |= VL53L0_WrByte(Dev, 0x8E, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x8F, 0x94);
+ Status |= VL53L0_WrByte(Dev, 0x90, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x91, 0x53);
+ Status |= VL53L0_WrByte(Dev, 0x92, 0x1E);
+ Status |= VL53L0_WrByte(Dev, 0x93, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x95, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x96, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x97, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x98, 0x20);
+ Status |= VL53L0_WrByte(Dev, 0x99, 0x20);
+ Status |= VL53L0_WrByte(Dev, 0x9A, 0x08);
+ Status |= VL53L0_WrByte(Dev, 0x9B, 0x10);
+ Status |= VL53L0_WrByte(Dev, 0x9C, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x9D, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x9E, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x9F, 0x50);
+ Status |= VL53L0_WrByte(Dev, 0xA0, 0x2B);
+ Status |= VL53L0_WrByte(Dev, 0xA1, 0xB1);
+ Status |= VL53L0_WrByte(Dev, 0xA2, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0xA3, 0x02);
+ Status |= VL53L0_WrByte(Dev, 0xA4, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0xA5, 0x50);
+ Status |= VL53L0_WrByte(Dev, 0xA6, 0x2C);
+ Status |= VL53L0_WrByte(Dev, 0xA7, 0x11);
+ Status |= VL53L0_WrByte(Dev, 0xA8, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xA9, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0xAA, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xAB, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0xAC, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xAD, 0xA1);
+ Status |= VL53L0_WrByte(Dev, 0xAE, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xAF, 0xA0);
+ Status |= VL53L0_WrByte(Dev, 0xB0, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xB1, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0xB2, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0xB3, 0x4E);
+ Status |= VL53L0_WrByte(Dev, 0xB4, 0x2D);
+ Status |= VL53L0_WrByte(Dev, 0xB5, 0x47);
+ Status |= VL53L0_WrByte(Dev, 0xB6, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xB7, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0xB8, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xB9, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0xBA, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xBB, 0xA7);
+ Status |= VL53L0_WrByte(Dev, 0xBC, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xBD, 0xA6);
+ Status |= VL53L0_WrByte(Dev, 0xBE, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0xBF, 0x02);
+ Status |= VL53L0_WrByte(Dev, 0xC0, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0xC1, 0x30);
+ Status |= VL53L0_WrByte(Dev, 0xC2, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xC3, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0xC4, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0xC5, 0x60);
+ Status |= VL53L0_WrByte(Dev, 0xC6, 0x2D);
+ Status |= VL53L0_WrByte(Dev, 0xC7, 0x89);
+ Status |= VL53L0_WrByte(Dev, 0xC8, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xC9, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0xCA, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xCB, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0xCC, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xCD, 0xA1);
+ Status |= VL53L0_WrByte(Dev, 0xCE, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xCF, 0xA0);
+ Status |= VL53L0_WrByte(Dev, 0xD0, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xD1, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0xD2, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xD3, 0x25);
+ Status |= VL53L0_WrByte(Dev, 0xD4, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xD5, 0x2E);
+ Status |= VL53L0_WrByte(Dev, 0xD6, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xD7, 0x25);
+ Status |= VL53L0_WrByte(Dev, 0xD8, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xD9, 0x2E);
+ Status |= VL53L0_WrByte(Dev, 0xDA, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0xDB, 0xF3);
+ Status |= VL53L0_WrByte(Dev, 0xDC, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0xDD, 0xEA);
+ Status |= VL53L0_WrByte(Dev, 0xDE, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0xDF, 0x58);
+ Status |= VL53L0_WrByte(Dev, 0xE0, 0x2C);
+ Status |= VL53L0_WrByte(Dev, 0xE1, 0xD9);
+ Status |= VL53L0_WrByte(Dev, 0xE2, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xE3, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0xE4, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xE5, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0xE6, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xE7, 0xA1);
+ Status |= VL53L0_WrByte(Dev, 0xE8, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xE9, 0xA0);
+ Status |= VL53L0_WrByte(Dev, 0xEA, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xEB, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0xEC, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0xED, 0x26);
+ Status |= VL53L0_WrByte(Dev, 0xEE, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xEF, 0xDC);
+ Status |= VL53L0_WrByte(Dev, 0xF0, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0xF1, 0x58);
+ Status |= VL53L0_WrByte(Dev, 0xF2, 0x2F);
+ Status |= VL53L0_WrByte(Dev, 0xF3, 0x21);
+ Status |= VL53L0_WrByte(Dev, 0xF4, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xF5, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0xF6, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xF7, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0xF8, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xF9, 0xA1);
+ Status |= VL53L0_WrByte(Dev, 0xFA, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xFB, 0xA0);
+ Status |= VL53L0_WrByte(Dev, 0xFC, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xFD, 0x04);
+ Status |= VL53L0_WrWord(Dev, 0xFE, 0x01E3);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x0F);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x01, 0x48);
+ Status |= VL53L0_WrByte(Dev, 0x02, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x03, 0x60);
+ Status |= VL53L0_WrByte(Dev, 0x04, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x05, 0xA4);
+ Status |= VL53L0_WrByte(Dev, 0x06, 0x05);
+ Status |= VL53L0_WrByte(Dev, 0x07, 0xB8);
+ Status |= VL53L0_WrByte(Dev, 0x08, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x09, 0x07);
+ Status |= VL53L0_WrByte(Dev, 0x0A, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x0B, 0x60);
+ Status |= VL53L0_WrByte(Dev, 0x0C, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x0D, 0x6B);
+ Status |= VL53L0_WrByte(Dev, 0x0E, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x0F, 0x64);
+ Status |= VL53L0_WrByte(Dev, 0x10, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x11, 0x3C);
+ Status |= VL53L0_WrByte(Dev, 0x12, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x13, 0x60);
+ Status |= VL53L0_WrByte(Dev, 0x14, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x15, 0x74);
+ Status |= VL53L0_WrByte(Dev, 0x16, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x17, 0x02);
+ Status |= VL53L0_WrByte(Dev, 0x18, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x19, 0x02);
+ Status |= VL53L0_WrByte(Dev, 0x1A, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x1B, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x1C, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x1D, 0xA2);
+ Status |= VL53L0_WrByte(Dev, 0x1E, 0x07);
+ Status |= VL53L0_WrByte(Dev, 0x1F, 0x8E);
+ Status |= VL53L0_WrByte(Dev, 0x20, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x21, 0x50);
+ Status |= VL53L0_WrByte(Dev, 0x22, 0x2E);
+ Status |= VL53L0_WrByte(Dev, 0x23, 0xC9);
+ Status |= VL53L0_WrByte(Dev, 0x24, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x25, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x26, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x27, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x28, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x29, 0xA1);
+ Status |= VL53L0_WrByte(Dev, 0x2A, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x2B, 0xA0);
+ Status |= VL53L0_WrByte(Dev, 0x2C, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x2D, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x2E, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x2F, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x30, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x31, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x32, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x33, 0xA0);
+ Status |= VL53L0_WrByte(Dev, 0x34, 0x11);
+ Status |= VL53L0_WrByte(Dev, 0x35, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x36, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x37, 0x05);
+ Status |= VL53L0_WrByte(Dev, 0x38, 0x11);
+ Status |= VL53L0_WrByte(Dev, 0x39, 0x08);
+ Status |= VL53L0_WrByte(Dev, 0x3A, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x3B, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x3C, 0x11);
+ Status |= VL53L0_WrByte(Dev, 0x3D, 0x18);
+ Status |= VL53L0_WrByte(Dev, 0x3E, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x3F, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x40, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x41, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x42, 0x0C);
+ Status |= VL53L0_WrByte(Dev, 0x43, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x44, 0x0A);
+ Status |= VL53L0_WrByte(Dev, 0x45, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x46, 0x0C);
+ Status |= VL53L0_WrByte(Dev, 0x47, 0x08);
+ Status |= VL53L0_WrByte(Dev, 0x48, 0x0A);
+ Status |= VL53L0_WrByte(Dev, 0x49, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x4A, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x4B, 0x40);
+ Status |= VL53L0_WrByte(Dev, 0x4C, 0x2F);
+ Status |= VL53L0_WrByte(Dev, 0x4D, 0xD1);
+ Status |= VL53L0_WrByte(Dev, 0x4E, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x4F, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x50, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x51, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x52, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x53, 0xA1);
+ Status |= VL53L0_WrByte(Dev, 0x54, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x55, 0xA0);
+ Status |= VL53L0_WrByte(Dev, 0x56, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x57, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x58, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x59, 0x11);
+ Status |= VL53L0_WrByte(Dev, 0x5A, 0x05);
+ Status |= VL53L0_WrByte(Dev, 0x5B, 0x48);
+ Status |= VL53L0_WrByte(Dev, 0x5C, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x5D, 0x60);
+ Status |= VL53L0_WrByte(Dev, 0x5E, 0x0A);
+ Status |= VL53L0_WrByte(Dev, 0x5F, 0xA2);
+ Status |= VL53L0_WrByte(Dev, 0x60, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x61, 0x60);
+ Status |= VL53L0_WrByte(Dev, 0x62, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x63, 0x3E);
+ Status |= VL53L0_WrByte(Dev, 0x64, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x65, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x66, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x67, 0x54);
+ Status |= VL53L0_WrByte(Dev, 0x68, 0x05);
+ Status |= VL53L0_WrByte(Dev, 0x69, 0x80);
+ Status |= VL53L0_WrByte(Dev, 0x6A, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x6B, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x6C, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x6D, 0x38);
+ Status |= VL53L0_WrByte(Dev, 0x6E, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x6F, 0xE1);
+ Status |= VL53L0_WrByte(Dev, 0x70, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x71, 0x02);
+ Status |= VL53L0_WrByte(Dev, 0x72, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x73, 0x38);
+ Status |= VL53L0_WrByte(Dev, 0x74, 0x29);
+ Status |= VL53L0_WrByte(Dev, 0x75, 0x21);
+ Status |= VL53L0_WrByte(Dev, 0x76, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x77, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x78, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x79, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x7A, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x7B, 0xA1);
+ Status |= VL53L0_WrByte(Dev, 0x7C, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x7D, 0xA0);
+ Status |= VL53L0_WrByte(Dev, 0x7E, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x7F, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x80, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x81, 0x33);
+ Status |= VL53L0_WrByte(Dev, 0x82, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x83, 0x6A);
+ Status |= VL53L0_WrByte(Dev, 0x84, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x85, 0x61);
+ Status |= VL53L0_WrByte(Dev, 0x86, 0x05);
+ Status |= VL53L0_WrByte(Dev, 0x87, 0xF9);
+ Status |= VL53L0_WrByte(Dev, 0x88, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x89, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x8A, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x8B, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x8C, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x8D, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0x8E, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x8F, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x90, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x91, 0x66);
+ Status |= VL53L0_WrByte(Dev, 0x92, 0x2A);
+ Status |= VL53L0_WrByte(Dev, 0x93, 0x67);
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x95, 0x02);
+ Status |= VL53L0_WrByte(Dev, 0x96, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x97, 0x66);
+ Status |= VL53L0_WrByte(Dev, 0x98, 0x2A);
+ Status |= VL53L0_WrByte(Dev, 0x99, 0xAF);
+ Status |= VL53L0_WrByte(Dev, 0x9A, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x9B, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x9C, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x9D, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x9E, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x9F, 0xA7);
+ Status |= VL53L0_WrByte(Dev, 0xA0, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xA1, 0xA6);
+ Status |= VL53L0_WrByte(Dev, 0xA2, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xA3, 0x04);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x04);
+
+ Status |= VL53L0_WrByte(Dev, 0x79, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0x7B, 0x16);
+ Status |= VL53L0_WrByte(Dev, 0x7D, 0x2B);
+ Status |= VL53L0_WrByte(Dev, 0x7F, 0x3B);
+ Status |= VL53L0_WrByte(Dev, 0x81, 0x59);
+ Status |= VL53L0_WrByte(Dev, 0x83, 0x62);
+ Status |= VL53L0_WrByte(Dev, 0x85, 0x69);
+ Status |= VL53L0_WrByte(Dev, 0x87, 0x76);
+ Status |= VL53L0_WrByte(Dev, 0x89, 0x7F);
+ Status |= VL53L0_WrByte(Dev, 0x8B, 0x98);
+ Status |= VL53L0_WrByte(Dev, 0x8D, 0xAC);
+ Status |= VL53L0_WrByte(Dev, 0x8F, 0xC0);
+ Status |= VL53L0_WrByte(Dev, 0x90, 0x0C);
+ Status |= VL53L0_WrByte(Dev, 0x91, 0x30);
+ Status |= VL53L0_WrByte(Dev, 0x92, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0x93, 0x02);
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x37);
+ Status |= VL53L0_WrByte(Dev, 0x95, 0x62);
+
+ Status |= VL53L0_WrByte(Dev, 0x96, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x97, 0x08);
+ Status |= VL53L0_WrByte(Dev, 0x98, 0x07);
+ Status |= VL53L0_WrByte(Dev, 0x99, 0x18);
+ Status |= VL53L0_WrByte(Dev, 0x9A, 0x07);
+ Status |= VL53L0_WrByte(Dev, 0x9B, 0x6F);
+ Status |= VL53L0_WrByte(Dev, 0x9C, 0x05);
+ Status |= VL53L0_WrByte(Dev, 0x9D, 0xD4);
+ Status |= VL53L0_WrByte(Dev, 0x9E, 0x0A);
+ Status |= VL53L0_WrByte(Dev, 0x9F, 0x6E);
+ Status |= VL53L0_WrByte(Dev, 0xA0, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0xA1, 0xA2);
+ Status |= VL53L0_WrByte(Dev, 0xA2, 0x0C);
+ Status |= VL53L0_WrByte(Dev, 0xA3, 0xAA);
+ Status |= VL53L0_WrByte(Dev, 0xA4, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0xA5, 0x97);
+ Status |= VL53L0_WrByte(Dev, 0xA6, 0x0B);
+ Status |= VL53L0_WrByte(Dev, 0xA7, 0xD8);
+ Status |= VL53L0_WrByte(Dev, 0xA8, 0x0A);
+ Status |= VL53L0_WrByte(Dev, 0xA9, 0xD7);
+ Status |= VL53L0_WrByte(Dev, 0xAA, 0x08);
+ Status |= VL53L0_WrByte(Dev, 0xAB, 0xF6);
+ Status |= VL53L0_WrByte(Dev, 0xAC, 0x07);
+ Status |= VL53L0_WrByte(Dev, 0xAD, 0x1A);
+ Status |= VL53L0_WrByte(Dev, 0xAE, 0x0C);
+ Status |= VL53L0_WrByte(Dev, 0xAF, 0x49);
+ Status |= VL53L0_WrByte(Dev, 0xB0, 0x09);
+ Status |= VL53L0_WrByte(Dev, 0xB1, 0x17);
+ Status |= VL53L0_WrByte(Dev, 0xB2, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0xB3, 0xCD);
+ Status |= VL53L0_WrByte(Dev, 0xB4, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0xB5, 0x55);
+
+ Status |= VL53L0_WrByte(Dev, 0x72, 0xFF);
+ Status |= VL53L0_WrByte(Dev, 0x73, 0xFF);
+
+ Status |= VL53L0_WrByte(Dev, 0x74, 0xE0);
+
+ Status |= VL53L0_WrByte(Dev, 0x70, 0x01);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x00);
+
+ if (Status != 0)
+ Status = VL53L0_ERROR_CONTROL_INTERFACE;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L010_EXTERNAL VL53L0_Error VL53L010_check_part_used(VL53L0_DEV Dev,
+ uint8_t *Revision, VL53L0_DeviceInfo_t* pVL53L0_DeviceInfo)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t ModuleIdInt;
+ char *ProductId_tmp;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L010_get_info_from_device(Dev);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ ModuleIdInt = VL53L010_GETDEVICESPECIFICPARAMETER(Dev, ModuleId);
+
+ if (ModuleIdInt == 0) {
+ *Revision = 0;
+ VL53L0_COPYSTRING(pVL53L0_DeviceInfo->ProductId, "");
+ } else {
+ *Revision = VL53L010_GETDEVICESPECIFICPARAMETER(Dev, Revision);
+ ProductId_tmp = VL53L010_GETDEVICESPECIFICPARAMETER(Dev, ProductId);
+ VL53L0_COPYSTRING(pVL53L0_DeviceInfo->ProductId, ProductId_tmp);
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L010_EXTERNAL VL53L0_Error VL53L010_get_info_from_device(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t byte;
+ uint32_t TmpDWord;
+ VL53L0_DeviceSpecificParameters_t DeviceSpecificParameters;
+ uint8_t ModuleId;
+ uint8_t Revision;
+ uint8_t ReferenceSpadCount;
+ uint8_t ReferenceSpadType;
+ char ProductId[19];
+ char *ProductId_tmp;
+ uint8_t ReadDataFromDeviceDone;
+
+ LOG_FUNCTION_START("");
+
+ ReadDataFromDeviceDone = VL53L010_GETDEVICESPECIFICPARAMETER(Dev,
+ ReadDataFromDeviceDone);
+
+ /* This access is done only once after that a GetDeviceInfo or
+ * datainit is done*/
+ if (ReadDataFromDeviceDone == 0) {
+
+ Status |= VL53L0_WrByte(Dev, 0x80, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x06);
+ Status |= VL53L0_RdByte(Dev, 0x83, &byte);
+ Status |= VL53L0_WrByte(Dev, 0x83, byte|4);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x07);
+ Status |= VL53L0_WrByte(Dev, 0x81, 0x01);
+
+ Status |= VL53L0_PollingDelay(Dev);
+
+ Status |= VL53L0_WrByte(Dev, 0x80, 0x01);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x6b);
+ Status |= VL53L010_device_read_strobe(Dev);
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ ReferenceSpadCount = (uint8_t)((TmpDWord >> 8) & 0x07f);
+ ReferenceSpadType = (uint8_t)((TmpDWord >> 15) & 0x01);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x02);
+ Status |= VL53L010_device_read_strobe(Dev);
+ Status |= VL53L0_RdByte(Dev, 0x90, &ModuleId);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x7B);
+ Status |= VL53L010_device_read_strobe(Dev);
+ Status |= VL53L0_RdByte(Dev, 0x90, &Revision);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x77);
+ Status |= VL53L010_device_read_strobe(Dev);
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ ProductId[0] = (char)((TmpDWord >> 25) & 0x07f);
+ ProductId[1] = (char)((TmpDWord >> 18) & 0x07f);
+ ProductId[2] = (char)((TmpDWord >> 11) & 0x07f);
+ ProductId[3] = (char)((TmpDWord >> 4) & 0x07f);
+
+ byte = (uint8_t)((TmpDWord & 0x00f) << 3);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x78);
+ Status |= VL53L010_device_read_strobe(Dev);
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ ProductId[4] = (char)(byte +
+ ((TmpDWord >> 29) & 0x07f));
+ ProductId[5] = (char)((TmpDWord >> 22) & 0x07f);
+ ProductId[6] = (char)((TmpDWord >> 15) & 0x07f);
+ ProductId[7] = (char)((TmpDWord >> 8) & 0x07f);
+ ProductId[8] = (char)((TmpDWord >> 1) & 0x07f);
+
+ byte = (uint8_t)((TmpDWord & 0x001) << 6);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x79);
+
+ Status |= VL53L010_device_read_strobe(Dev);
+
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ ProductId[9] = (char)(byte +
+ ((TmpDWord >> 26) & 0x07f));
+ ProductId[10] = (char)((TmpDWord >> 19) & 0x07f);
+ ProductId[11] = (char)((TmpDWord >> 12) & 0x07f);
+ ProductId[12] = (char)((TmpDWord >> 5) & 0x07f);
+
+ byte = (uint8_t)((TmpDWord & 0x01f) << 2);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x80);
+
+ Status |= VL53L010_device_read_strobe(Dev);
+
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ ProductId[13] = (char)(byte +
+ ((TmpDWord >> 30) & 0x07f));
+ ProductId[14] = (char)((TmpDWord >> 23) & 0x07f);
+ ProductId[15] = (char)((TmpDWord >> 16) & 0x07f);
+ ProductId[16] = (char)((TmpDWord >> 9) & 0x07f);
+ ProductId[17] = (char)((TmpDWord >> 2) & 0x07f);
+ ProductId[18] = '\0';
+
+ Status |= VL53L0_WrByte(Dev, 0x81, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x06);
+ Status |= VL53L0_RdByte(Dev, 0x83, &byte);
+ Status |= VL53L0_WrByte(Dev, 0x83, byte&0xfb);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x01);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x80, 0x00);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L010_SETDEVICESPECIFICPARAMETER(Dev,
+ ModuleId, ModuleId);
+
+ VL53L010_SETDEVICESPECIFICPARAMETER(Dev,
+ Revision, Revision);
+
+ VL53L010_SETDEVICESPECIFICPARAMETER(Dev,
+ ReferenceSpadCount, ReferenceSpadCount);
+
+ VL53L010_SETDEVICESPECIFICPARAMETER(Dev,
+ ReferenceSpadType, ReferenceSpadType);
+
+ ProductId_tmp = VL53L010_GETDEVICESPECIFICPARAMETER(Dev,
+ ProductId);
+ VL53L0_COPYSTRING(ProductId_tmp, ProductId);
+
+ VL53L010_SETDEVICESPECIFICPARAMETER(Dev,
+ ReadDataFromDeviceDone, 1);
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+uint32_t VL53L010_isqrt(uint32_t num)
+{
+
+ /*
+ * Implements an integer square root
+ *
+ * From: http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
+ */
+
+ uint32_t res = 0;
+ uint32_t bit = 1 << 30;
+ /* The second-to-top bit is set: 1 << 14 for
+ 16-bits, 1 << 30 for 32 bits
+ */
+ /* "bit" starts at the highest power of four <= the argument.*/
+ while (bit > num)
+ bit >>= 2;
+
+
+ while (bit != 0) {
+ if (num >= res + bit) {
+ num -= res + bit;
+ res = (res >> 1) + bit;
+ } else
+ res >>= 1;
+
+ bit >>= 2;
+ }
+
+ return res;
+}
+
+
+VL53L0_Error VL53L010_device_read_strobe(VL53L0_DEV Dev) {
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t strobe;
+ uint32_t LoopNb;
+ LOG_FUNCTION_START("");
+
+ Status |= VL53L0_WrByte(Dev, 0x83, 0x00);
+
+ // polling
+ // use timeout to avoid deadlock
+ if (Status == VL53L0_ERROR_NONE) {
+ LoopNb = 0;
+ do {
+ Status =VL53L0_RdByte(Dev, 0x83, &strobe);
+ if ((strobe != 0x00) || Status != VL53L0_ERROR_NONE) {
+ break;
+ }
+ LoopNb = LoopNb + 1;
+ } while (LoopNb < VL53L0_DEFAULT_MAX_LOOP);
+
+ if (LoopNb >= VL53L0_DEFAULT_MAX_LOOP) {
+ Status = VL53L0_ERROR_TIME_OUT;
+ }
+ }
+
+ Status |= VL53L0_WrByte(Dev, 0x83, 0x01);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+uint32_t VL53L010_quadrature_sum(uint32_t a,
+ uint32_t b)
+{
+ /*
+ * Implements a quadrature sum
+ *
+ * rea = sqrt(a^2 + b^2)
+ *
+ * Trap overflow case max input value is 65535 (16-bit value)
+ * as internal calc are 32-bit wide
+ *
+ * If overflow then seta output to maximum
+ */
+ uint32_t res = 0;
+
+ if (a > 65535 || b > 65535)
+ res = 65535;
+ else
+ res = VL53L010_isqrt(a*a + b*b);
+
+
+ return res;
+}
+
+
+
+VL53L0_Error VL53L010_get_jmp_vcsel_ambient_rate(VL53L0_DEV Dev,
+ uint32_t *pAmbient_rate_kcps,
+ uint32_t *pVcsel_rate_kcps,
+ uint32_t *pSignalTotalEventsRtn)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint16_t encodedTimeOut;
+
+ uint32_t total_periods_elapsed_rtn__macrop = 0;
+ uint32_t result_core__total_periods_elapsed_rtn = 0;
+ uint32_t rngb1_config__timeout__macrop = 0;
+ uint32_t rngb2_config__timeout__macrop = 0;
+ uint32_t result_core__ambient_window_events_rtn = 0;
+ uint32_t result_core__signal_total_events_rtn = 0;
+ uint8_t last_woi_period;
+ uint8_t rnga_config__vcsel_period;
+ uint8_t rngb1_config__vcsel_period;
+ uint8_t rngb2_config__vcsel_period;
+ uint8_t global_config__vcsel_width;
+
+ uint32_t ambient_duration_us = 0;
+ uint32_t vcsel_duration_us = 0;
+
+ uint32_t pll_period_us = 0;
+
+ LOG_FUNCTION_START("");
+
+ /* read the following */
+ Status = VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_RdDWord(Dev, 0xC8,
+ &result_core__total_periods_elapsed_rtn);
+ Status |= VL53L0_RdDWord(Dev, 0xF0, &pll_period_us);
+ Status |= VL53L0_RdDWord(Dev, 0xbc,
+ &result_core__ambient_window_events_rtn);
+ Status |= VL53L0_RdDWord(Dev, 0xc4,
+ &result_core__signal_total_events_rtn);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+
+ if (Status == VL53L0_ERROR_NONE) {
+ result_core__total_periods_elapsed_rtn =
+ (int32_t)(result_core__total_periods_elapsed_rtn &
+ 0x00ffffff);
+ pll_period_us = (int32_t)(pll_period_us & 0x3ffff);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdWord(Dev, VL53L010_REG_RNGB1_TIMEOUT_MSB,
+ &encodedTimeOut);
+ if (Status == VL53L0_ERROR_NONE)
+ rngb1_config__timeout__macrop =
+ VL53L010_decode_timeout(encodedTimeOut) - 1;
+
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdByte(Dev, VL53L010_REG_RNGA_CONFIG_VCSEL_PERIOD,
+ &rnga_config__vcsel_period);
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdByte(Dev,
+ VL53L010_REG_RNGB1_CONFIG_VCSEL_PERIOD,
+ &rngb1_config__vcsel_period);
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdByte(Dev,
+ VL53L010_REG_RNGB2_CONFIG_VCSEL_PERIOD,
+ &rngb2_config__vcsel_period);
+ }
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_RdByte(Dev, 0x32, &global_config__vcsel_width);
+
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdWord(Dev, VL53L010_REG_RNGB2_TIMEOUT_MSB,
+ &encodedTimeOut);
+ if (Status == VL53L0_ERROR_NONE)
+ rngb2_config__timeout__macrop =
+ VL53L010_decode_timeout(encodedTimeOut) - 1;
+
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ total_periods_elapsed_rtn__macrop =
+ result_core__total_periods_elapsed_rtn + 1;
+
+ if (result_core__total_periods_elapsed_rtn ==
+ rngb1_config__timeout__macrop) {
+ last_woi_period = rngb1_config__vcsel_period;
+ } else if (result_core__total_periods_elapsed_rtn ==
+ rngb2_config__timeout__macrop) {
+ last_woi_period = rngb2_config__vcsel_period;
+ } else {
+ last_woi_period = rnga_config__vcsel_period;
+
+ }
+ /* 512 = 1<<9 ==> 24-9=15 */
+ ambient_duration_us = last_woi_period *
+ total_periods_elapsed_rtn__macrop * pll_period_us;
+ ambient_duration_us = ambient_duration_us / 1000;
+
+ if (ambient_duration_us != 0) {
+ *pAmbient_rate_kcps = ((1 << 15) *
+ result_core__ambient_window_events_rtn) /
+ ambient_duration_us;
+ } else {
+ Status = VL53L0_ERROR_DIVISION_BY_ZERO;
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+
+ /* 2048 = 1<<11 ==> 24-11=13 */
+ vcsel_duration_us =
+ (10 * global_config__vcsel_width + 4)
+ * total_periods_elapsed_rtn__macrop *
+ pll_period_us ;
+ vcsel_duration_us = vcsel_duration_us / 10000 ;
+
+
+ if (vcsel_duration_us != 0) {
+ *pVcsel_rate_kcps = ((1 << 13) *
+ result_core__signal_total_events_rtn) /
+ vcsel_duration_us;
+ *pSignalTotalEventsRtn =
+ result_core__signal_total_events_rtn;
+ } else {
+ Status = VL53L0_ERROR_DIVISION_BY_ZERO;
+ }
+
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+VL53L0_Error VL53L010_calc_sigma_estimate(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t
+ *pRangingMeasurementData,
+ FixPoint1616_t *pSigmaEstimate)
+{
+ /* Expressed in 100ths of a ns, i.e. centi-ns */
+ const uint32_t cPulseEffectiveWidth_centi_ns = 800;
+ /* Expressed in 100ths of a ns, i.e. centi-ns */
+ const uint32_t cAmbientEffectiveWidth_centi_ns = 600;
+ const FixPoint1616_t cSigmaEstRef = 0x00000042;
+ /* pico secs */
+ const uint32_t cVcselPulseWidth_ps = 4700;
+ const FixPoint1616_t cSigmaEstMax = 0x028F87AE;
+ /* Time Of Flight per mm (6.6 pico secs) */
+ const FixPoint1616_t cTOF_per_mm_ps = 0x0006999A;
+ const uint32_t c16BitRoundingParam = 0x00008000;
+ const FixPoint1616_t cMaxXTalk_kcps = 0x00320000;
+
+ uint32_t signalTotalEventsRtn;
+ FixPoint1616_t sigmaEstimateP1;
+ FixPoint1616_t sigmaEstimateP2;
+ FixPoint1616_t sigmaEstimateP3;
+ FixPoint1616_t deltaT_ps;
+ FixPoint1616_t pwMult;
+ FixPoint1616_t sigmaEstRtn;
+ FixPoint1616_t sigmaEstimate;
+ FixPoint1616_t xTalkCorrection;
+ uint32_t signalTotalEventsRtnRawVal;
+ FixPoint1616_t ambientRate_kcps;
+ FixPoint1616_t vcselRate_kcps;
+ FixPoint1616_t xTalkCompRate_mcps;
+ uint32_t xTalkCompRate_kcps;
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+ FixPoint1616_t diff1_mcps;
+ FixPoint1616_t diff2_mcps;
+ FixPoint1616_t sqr1;
+ FixPoint1616_t sqr2;
+ FixPoint1616_t sqrSum;
+ FixPoint1616_t sqrtResult_centi_ns;
+ FixPoint1616_t sqrtResult;
+
+ /*! \addtogroup calc_sigma_estimate
+ * @{
+ *
+ * Estimates the range sigma based on the
+ *
+ * - vcsel_rate_kcps
+ * - ambient_rate_kcps
+ * - signal_total_events
+ * - xtalk_rate
+ *
+ * and the following parameters
+ *
+ * - SigmaEstRefArray
+ * - SigmaEstEffPulseWidth
+ * - SigmaEstEffAmbWidth
+ */
+
+ LOG_FUNCTION_START("");
+
+ VL53L010_GETPARAMETERFIELD(Dev, XTalkCompensationRateMegaCps,
+ xTalkCompRate_mcps);
+ /*
+ * We work in kcps rather than mcps as this helps keep within the confines
+ * of the 32 Fix1616 type.
+ */
+
+ xTalkCompRate_kcps = xTalkCompRate_mcps * 1000;
+ if (xTalkCompRate_kcps > cMaxXTalk_kcps)
+ xTalkCompRate_kcps = cMaxXTalk_kcps;
+
+
+ Status = VL53L010_get_jmp_vcsel_ambient_rate(Dev,
+ &ambientRate_kcps,
+ &vcselRate_kcps,
+ &signalTotalEventsRtnRawVal);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (vcselRate_kcps == 0) {
+ Status = VL53L0_ERROR_DIVISION_BY_ZERO;
+ } else {
+ signalTotalEventsRtn = signalTotalEventsRtnRawVal;
+ if (signalTotalEventsRtn < 1)
+ signalTotalEventsRtn = 1;
+
+ /*
+ * Calculate individual components of the main
+ * equation - replicating the equation implemented in
+ * the script OpenAll_Ewok_ranging_data.jsl.
+ *
+ * sigmaEstimateP1 represents the effective pulse width,
+ * which is a tuning parameter, rather than a real
+ * value.
+ *
+ * sigmaEstimateP2 represents the ambient/signal rate
+ * ratio expressed as a multiple of the effective
+ * ambient width (tuning parameter).
+ *
+ * sigmaEstimateP3 provides the signal event component,
+ * with the knowledge that
+ * - Noise of a square pulse is 1/sqrt(12) of the
+ * pulse width.
+ * - at 0Lux, sigma is proportional to
+ * effectiveVcselPulseWidth /
+ * sqrt(12 * signalTotalEvents)
+ *
+ * deltaT_ps represents the time of flight in pico secs
+ * for the current range measurement, using the
+ * "TOF per mm" constant (in ps).
+ */
+
+ sigmaEstimateP1 = cPulseEffectiveWidth_centi_ns;
+
+ /*
+ ((FixPoint1616 << 16)* uint32)/FixPoint1616 =
+ FixPoint1616
+ */
+ sigmaEstimateP2 = (ambientRate_kcps << 16) /
+ vcselRate_kcps;
+ sigmaEstimateP2 *= cAmbientEffectiveWidth_centi_ns;
+
+ sigmaEstimateP3 = 2 *
+ VL53L010_isqrt(signalTotalEventsRtn * 12);
+
+ /* uint32 * FixPoint1616 = FixPoint1616 */
+ deltaT_ps =
+ pRangingMeasurementData->RangeMilliMeter *
+ cTOF_per_mm_ps;
+
+ /*
+ * vcselRate - xtalkCompRate
+ * (uint32 << 16) - FixPoint1616 = FixPoint1616.
+ * Divide result by 1000 to convert to mcps.
+ * 500 is added to ensure rounding when integer
+ * division truncates.
+ */
+ diff1_mcps = (((vcselRate_kcps << 16) -
+ xTalkCompRate_kcps) + 500)/1000;
+
+ /* vcselRate + xtalkCompRate */
+ diff2_mcps = (((vcselRate_kcps << 16) +
+ xTalkCompRate_kcps) + 500)/1000;
+
+ /* Shift by 12 bits to increase resolution prior to the
+ division */
+ diff1_mcps <<= 12;
+
+ /* FixPoint0428/FixPoint1616 = FixPoint2012 */
+ xTalkCorrection = abs(diff1_mcps/diff2_mcps);
+
+ /* FixPoint2012 << 4 = FixPoint1616 */
+ xTalkCorrection <<= 4;
+
+ /* FixPoint1616/uint32 = FixPoint1616 */
+ pwMult = deltaT_ps/cVcselPulseWidth_ps;
+ /* smaller than 1.0f */
+
+ /*
+ * FixPoint1616 * FixPoint1616 = FixPoint3232, however
+ * both values are small enough such that32 bits will
+ * not be exceeded.
+ */
+ pwMult *= ((1 << 16) - xTalkCorrection);
+
+ /* (FixPoint3232 >> 16) = FixPoint1616 */
+ pwMult = (pwMult + c16BitRoundingParam) >> 16;
+
+ /* FixPoint1616 + FixPoint1616 = FixPoint1616 */
+ pwMult += (1 << 16);
+
+ /*
+ * At this point the value will be 1.xx, therefore if we
+ * square the value this will exceed 32 bits. To address
+ * this perform a single shift to the right before the
+ * multiplication.
+ */
+ pwMult >>= 1;
+ /* FixPoint1715 * FixPoint1715 = FixPoint3430 */
+ pwMult = pwMult * pwMult;
+
+ /* (FixPoint3430 >> 14) = Fix1616 */
+ pwMult >>= 14;
+
+ /* FixPoint1616 * FixPoint1616 = FixPoint3232 */
+ sqr1 = pwMult * sigmaEstimateP1;
+
+ /* (FixPoint1616 >> 12) = FixPoint2804 */
+ sqr1 = (sqr1 + 0x800) >> 12;
+
+ /* FixPoint2804 * FixPoint2804 = FixPoint5608 */
+ sqr1 *= sqr1;
+
+ sqr2 = sigmaEstimateP2;
+
+ /* (FixPoint1616 >> 12) = FixPoint2804 */
+ sqr2 = (sqr2 + 0x800) >> 12;
+
+ /* FixPoint2804 * FixPoint2804 = FixPoint5608 */
+ sqr2 *= sqr2;
+
+ /* FixPoint5608 + FixPoint5608 = FixPoint5608 */
+ sqrSum = sqr1 + sqr2;
+
+ /* SQRT(FixPoint5608) = FixPoint2804 */
+ sqrtResult_centi_ns = VL53L010_isqrt(sqrSum);
+
+ /* (FixPoint2804 << 12) = FixPoint1616 */
+ sqrtResult_centi_ns <<= 12;
+
+ /*
+ * Note that the Speed Of Light is expressed in um
+ * per 1E-10 seconds (2997). Therefore to get mm/ns
+ * we have to divide by 10000
+ */
+ sigmaEstRtn =
+ ((sqrtResult_centi_ns + 50) / 100 *
+ VL53L010_SPEED_OF_LIGHT_IN_AIR);
+ sigmaEstRtn /= (sigmaEstimateP3);
+ /* Add 5000 before dividing by 10000 to ensure
+ rounding. */
+ sigmaEstRtn += 5000;
+ sigmaEstRtn /= 10000;
+
+ /* FixPoint1616 * FixPoint1616 = FixPoint3232 */
+ sqr1 = sigmaEstRtn * sigmaEstRtn;
+ /* FixPoint1616 * FixPoint1616 = FixPoint3232 */
+ sqr2 = cSigmaEstRef * cSigmaEstRef;
+
+ /* sqrt(FixPoint3232 << 12) = FixPoint1022 */
+ sqrtResult = VL53L010_isqrt((sqr1 + sqr2) << 12);
+ sqrtResult = (sqrtResult + 0x20) >> 6;
+ /*
+ * Note that the Shift by 12bits increases resolution
+ * prior to the sqrt, therefore the result must be
+ * shifted by 6bits to the right to revert back to the
+ * FixPoint1616 format.
+ */
+
+ sigmaEstimate = 1000 * sqrtResult;
+
+ if ((vcselRate_kcps < 1) ||
+ (signalTotalEventsRtn < 1) ||
+ (sigmaEstimate > cSigmaEstMax)) {
+ sigmaEstimate = cSigmaEstMax;
+ }
+
+ *pSigmaEstimate = (uint32_t)(sigmaEstimate);
+ PALDevDataSet(Dev, SigmaEstimate, *pSigmaEstimate);
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L010_get_pal_range_status(VL53L0_DEV Dev,
+ uint8_t DeviceRangeStatus,
+ FixPoint1616_t SignalRate,
+ FixPoint1616_t CrosstalkCompensation,
+ uint16_t EffectiveSpadRtnCount,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData,
+ uint8_t *pPalRangeStatus)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t tmpByte;
+ uint8_t SigmaLimitCheckEnable;
+ uint8_t SignalLimitCheckEnable;
+ FixPoint1616_t SigmaEstimate;
+ FixPoint1616_t SignalEstimate;
+ FixPoint1616_t SigmaLimitValue;
+ FixPoint1616_t SignalLimitValue;
+ uint8_t DeviceRangeStatusInternal = 0;
+
+ LOG_FUNCTION_START("");
+
+ /*
+ * VL53L0 has a good ranging when the value of the
+ * DeviceRangeStatus = 11. This function will replace
+ * the value 0 with the value 11 in the DeviceRangeStatus.
+ * In addition, the SigmaEstimator is not included in the
+ * VL53L0 DeviceRangeStatus, this will be added in the
+ * PalRangeStatus.
+ */
+
+ DeviceRangeStatusInternal = ((DeviceRangeStatus & 0x78) >> 3);
+
+ if (DeviceRangeStatusInternal == 11)
+ tmpByte = 0;
+ else if (DeviceRangeStatusInternal == 0)
+ tmpByte = 11;
+ else
+ tmpByte = DeviceRangeStatusInternal;
+
+
+ /*
+ * Check if Sigma limit is enabled, if yes then do comparison with
+ * limit value and put the result back into pPalRangeStatus.
+ */
+ Status = VL53L010_GetLimitCheckEnable(Dev,
+ VL53L010_CHECKENABLE_SIGMA_FINAL_RANGE,
+ &SigmaLimitCheckEnable);
+
+ if ((SigmaLimitCheckEnable != 0) && (Status == VL53L0_ERROR_NONE)) {
+ /*
+ * compute the Sigma and check with limit
+ */
+ Status = VL53L010_calc_sigma_estimate(Dev,
+ pRangingMeasurementData, &SigmaEstimate);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L010_GetLimitCheckValue(Dev,
+ VL53L010_CHECKENABLE_SIGMA_FINAL_RANGE,
+ &SigmaLimitValue);
+
+ if ((SigmaLimitValue > 0) &&
+ (SigmaEstimate > SigmaLimitValue)) {
+ /* Limit Fail add 2^4 to range status */
+ tmpByte += 16;
+ }
+ }
+ }
+
+ /*
+ * Check if Signal limit is enabled, if yes then do comparison with
+ * limit value and put the result back into pPalRangeStatus.
+ */
+ Status = VL53L010_GetLimitCheckEnable(Dev,
+ VL53L010_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ &SignalLimitCheckEnable);
+
+ if ((SignalLimitCheckEnable != 0) && (Status == VL53L0_ERROR_NONE)) {
+ /*
+ * compute the Signal and check with limit
+ */
+
+ SignalEstimate = (FixPoint1616_t)(SignalRate -
+ (FixPoint1616_t)((EffectiveSpadRtnCount *
+ CrosstalkCompensation) >> 1));
+
+ PALDevDataSet(Dev, SignalEstimate, SignalEstimate);
+
+ Status = VL53L010_GetLimitCheckValue(Dev,
+ VL53L010_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ &SignalLimitValue);
+
+ if ((SignalLimitValue > 0) && (SignalEstimate <
+ SignalLimitValue)) {
+ /* Limit Fail add 2^5 to range status */
+ tmpByte += 32;
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ *pPalRangeStatus = tmpByte;
+
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
diff --git a/drivers/input/misc/vl53L0/src/vl53l010_tuning.c b/drivers/input/misc/vl53L0/src/vl53l010_tuning.c
new file mode 100644
index 000000000000..0f5fd85bd878
--- /dev/null
+++ b/drivers/input/misc/vl53L0/src/vl53l010_tuning.c
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ Copyright © 2016, STMicroelectronics International N.V.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+ NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+ IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ******************************************************************************/
+
+#include "vl53l010_tuning.h"
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(TRACE_MODULE_API, status, fmt, ##__VA_ARGS__)
+
+#ifdef VL53L0_LOG_ENABLE
+#define trace_print(level, ...) \
+ trace_print_module_function(TRACE_MODULE_API,\
+ level, TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+#endif
+
+/*
+//////////////////////////////////////////////////////
+//// DEFAULT TUNING SETTINGS ////
+//////////////////////////////////////////////////////
+*/
+VL53L0_Error VL53L010_load_tuning_settings(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ /* update 14_12_15_v11 */
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x91, 0x3C);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x54, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x33, 0x05);
+ Status |= VL53L0_WrByte(Dev, 0x32, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x30, 0x05);
+ Status |= VL53L0_WrByte(Dev, 0x50, 0x05);
+ Status |= VL53L0_WrByte(Dev, 0x60, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x70, 0x06);
+
+ Status |= VL53L0_WrByte(Dev, 0x46, 0x1a);
+ Status |= VL53L0_WrWord(Dev, 0x51, 0x01a3);
+ Status |= VL53L0_WrWord(Dev, 0x61, 0x01c4);
+ Status |= VL53L0_WrWord(Dev, 0x71, 0x018c);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x31, 0x0f);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x66, 0x38);
+
+ Status |= VL53L0_WrByte(Dev, 0x47, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x48, 0xff);
+ Status |= VL53L0_WrByte(Dev, 0x57, 0x4c);
+ Status |= VL53L0_WrByte(Dev, 0x67, 0x3c);
+ Status |= VL53L0_WrByte(Dev, 0x77, 0x5c);
+
+ Status |= VL53L0_WrWord(Dev, 0x44, 0x0000);
+
+ Status |= VL53L0_WrByte(Dev, 0x27, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x55, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x30, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0x10, 0x0f);
+ Status |= VL53L0_WrByte(Dev, 0x11, 0xff);
+ Status |= VL53L0_WrByte(Dev, 0x40, 0x82);
+ Status |= VL53L0_WrByte(Dev, 0x41, 0xff);
+ Status |= VL53L0_WrByte(Dev, 0x42, 0x07);
+ Status |= VL53L0_WrByte(Dev, 0x43, 0x12);
+
+ Status |= VL53L0_WrByte(Dev, 0x20, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x21, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0x28, 0x06);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x48, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0x7a, 0x0a);
+ Status |= VL53L0_WrByte(Dev, 0x7b, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x78, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x44, 0xff);
+ Status |= VL53L0_WrByte(Dev, 0x45, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x46, 0x10);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0x04, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x05, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x06, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x07, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x0d, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x80, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x01, 0xF8);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x8e, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+
+ if (Status != 0)
+ Status = VL53L0_ERROR_CONTROL_INTERFACE;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
diff --git a/drivers/input/misc/vl53L0/src/vl53l0_api.c b/drivers/input/misc/vl53L0/src/vl53l0_api.c
new file mode 100644
index 000000000000..ccb446a15c4c
--- /dev/null
+++ b/drivers/input/misc/vl53L0/src/vl53l0_api.c
@@ -0,0 +1,2845 @@
+/*******************************************************************************
+ Copyright © 2016, STMicroelectronics International N.V.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+ NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+ IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ******************************************************************************/
+
+#include "vl53l0_api.h"
+#include "vl53l0_tuning.h"
+#include "vl53l0_api_core.h"
+#include "vl53l0_api_histogram.h"
+#include "vl53l0_api_calibration.h"
+#include "vl53l0_api_strings.h"
+
+#ifndef __KERNEL__
+#include
+#endif
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(TRACE_MODULE_API, status, fmt, ##__VA_ARGS__)
+
+#ifdef VL53L0_LOG_ENABLE
+#define trace_print(level, ...) trace_print_module_function(TRACE_MODULE_API, \
+ level, TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+#endif
+
+/* Group PAL General Functions */
+
+VL53L0_Error VL53L0_GetVersion(VL53L0_Version_t *pVersion)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ pVersion->major = VL53L0_IMPLEMENTATION_VER_MAJOR;
+ pVersion->minor = VL53L0_IMPLEMENTATION_VER_MINOR;
+ pVersion->build = VL53L0_IMPLEMENTATION_VER_SUB;
+
+ pVersion->revision = VL53L0_IMPLEMENTATION_VER_REVISION;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetPalSpecVersion(VL53L0_Version_t *pPalSpecVersion)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ pPalSpecVersion->major = VL53L0_SPECIFICATION_VER_MAJOR;
+ pPalSpecVersion->minor = VL53L0_SPECIFICATION_VER_MINOR;
+ pPalSpecVersion->build = VL53L0_SPECIFICATION_VER_SUB;
+
+ pPalSpecVersion->revision = VL53L0_SPECIFICATION_VER_REVISION;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetProductRevision(VL53L0_DEV Dev,
+ uint8_t *pProductRevisionMajor, uint8_t *pProductRevisionMinor)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t revision_id;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L0_REG_IDENTIFICATION_REVISION_ID,
+ &revision_id);
+ *pProductRevisionMajor = 1;
+ *pProductRevisionMinor = (revision_id & 0xF0) >> 4;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+VL53L0_Error VL53L0_GetDeviceInfo(VL53L0_DEV Dev,
+ VL53L0_DeviceInfo_t *pVL53L0_DeviceInfo)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_device_info(Dev, pVL53L0_DeviceInfo);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetDeviceErrorStatus(VL53L0_DEV Dev,
+ VL53L0_DeviceError *pDeviceErrorStatus)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t RangeStatus;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L0_REG_RESULT_RANGE_STATUS,
+ &RangeStatus);
+
+ *pDeviceErrorStatus = (VL53L0_DeviceError)((RangeStatus & 0x78) >> 3);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_GetDeviceErrorString(VL53L0_DeviceError ErrorCode,
+ char *pDeviceErrorString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_device_error_string(ErrorCode, pDeviceErrorString);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetRangeStatusString(uint8_t RangeStatus,
+ char *pRangeStatusString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_range_status_string(RangeStatus,
+ pRangeStatusString);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetPalErrorString(VL53L0_Error PalErrorCode,
+ char *pPalErrorString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_pal_error_string(PalErrorCode, pPalErrorString);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetPalStateString(VL53L0_State PalStateCode,
+ char *pPalStateString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_pal_state_string(PalStateCode, pPalStateString);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetPalState(VL53L0_DEV Dev, VL53L0_State *pPalState)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ *pPalState = PALDevDataGet(Dev, PalState);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetPowerMode(VL53L0_DEV Dev, VL53L0_PowerModes PowerMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ /* Only level1 of Power mode exists */
+ if ((PowerMode != VL53L0_POWERMODE_STANDBY_LEVEL1)
+ && (PowerMode != VL53L0_POWERMODE_IDLE_LEVEL1)) {
+ Status = VL53L0_ERROR_MODE_NOT_SUPPORTED;
+ } else if (PowerMode == VL53L0_POWERMODE_STANDBY_LEVEL1) {
+ /* set the standby level1 of power mode */
+ Status = VL53L0_WrByte(Dev, 0x80, 0x00);
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Set PAL State to standby */
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_STANDBY);
+ PALDevDataSet(Dev, PowerMode,
+ VL53L0_POWERMODE_STANDBY_LEVEL1);
+ }
+
+ } else {
+ /* VL53L0_POWERMODE_IDLE_LEVEL1 */
+ Status = VL53L0_WrByte(Dev, 0x80, 0x00);
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_StaticInit(Dev);
+
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, PowerMode,
+ VL53L0_POWERMODE_IDLE_LEVEL1);
+
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetPowerMode(VL53L0_DEV Dev, VL53L0_PowerModes *pPowerMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Byte;
+ LOG_FUNCTION_START("");
+
+ /* Only level1 of Power mode exists */
+ Status = VL53L0_RdByte(Dev, 0x80, &Byte);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (Byte == 1) {
+ PALDevDataSet(Dev, PowerMode,
+ VL53L0_POWERMODE_IDLE_LEVEL1);
+ } else {
+ PALDevDataSet(Dev, PowerMode,
+ VL53L0_POWERMODE_STANDBY_LEVEL1);
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetOffsetCalibrationDataMicroMeter(VL53L0_DEV Dev,
+ int32_t OffsetCalibrationDataMicroMeter)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_set_offset_calibration_data_micro_meter(Dev,
+ OffsetCalibrationDataMicroMeter);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetOffsetCalibrationDataMicroMeter(VL53L0_DEV Dev,
+ int32_t *pOffsetCalibrationDataMicroMeter)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_offset_calibration_data_micro_meter(Dev,
+ pOffsetCalibrationDataMicroMeter);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetLinearityCorrectiveGain(VL53L0_DEV Dev,
+ int16_t LinearityCorrectiveGain)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ if ((LinearityCorrectiveGain < 0) || (LinearityCorrectiveGain > 1000))
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ else {
+ PALDevDataSet(Dev, LinearityCorrectiveGain,
+ LinearityCorrectiveGain);
+
+ if (LinearityCorrectiveGain != 1000) {
+ /* Disable FW Xtalk */
+ Status = VL53L0_WrWord(Dev,
+ VL53L0_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MCPS, 0);
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetLinearityCorrectiveGain(VL53L0_DEV Dev,
+ uint16_t *pLinearityCorrectiveGain)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ *pLinearityCorrectiveGain = PALDevDataGet(Dev, LinearityCorrectiveGain);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetGroupParamHold(VL53L0_DEV Dev, uint8_t GroupParamHold)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NOT_IMPLEMENTED;
+ LOG_FUNCTION_START("");
+
+ /* not implemented on VL53L0 */
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetUpperLimitMilliMeter(VL53L0_DEV Dev,
+ uint16_t *pUpperLimitMilliMeter)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NOT_IMPLEMENTED;
+ LOG_FUNCTION_START("");
+
+ /* not implemented on VL53L0 */
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetTotalSignalRate(VL53L0_DEV Dev,
+ FixPoint1616_t *pTotalSignalRate)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_RangingMeasurementData_t LastRangeDataBuffer;
+
+ LOG_FUNCTION_START("");
+
+ LastRangeDataBuffer = PALDevDataGet(Dev, LastRangeMeasure);
+
+ Status = VL53L0_get_total_signal_rate(
+ Dev, &LastRangeDataBuffer, pTotalSignalRate);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+/* End Group PAL General Functions */
+
+/* Group PAL Init Functions */
+VL53L0_Error VL53L0_SetDeviceAddress(VL53L0_DEV Dev, uint8_t DeviceAddress)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_I2C_SLAVE_DEVICE_ADDRESS,
+ DeviceAddress / 2);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_DataInit(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters;
+ int i;
+
+ LOG_FUNCTION_START("");
+
+ /* by default the I2C is running at 1V8 if you want to change it you
+ * need to include this define at compilation level. */
+#ifdef USE_I2C_2V8
+ Status = VL53L0_UpdateByte(Dev,
+ VL53L0_REG_VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV,
+ 0xFE,
+ 0x01);
+#endif
+
+ /* Set I2C standard mode */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev, 0x88, 0x00);
+
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev, ReadDataFromDeviceDone, 0);
+
+#ifdef USE_IQC_STATION
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_apply_offset_adjustment(Dev);
+#endif
+
+ /* Default value is 1000 for Linearity Corrective Gain */
+ PALDevDataSet(Dev, LinearityCorrectiveGain, 1000);
+
+ /* Dmax default Parameter */
+ PALDevDataSet(Dev, DmaxCalRangeMilliMeter, 400);
+ PALDevDataSet(Dev, DmaxCalSignalRateRtnMegaCps,
+ (FixPoint1616_t)((0x00016B85))); /* 1.42 No Cover Glass*/
+
+ /* Set Default static parameters
+ *set first temporary values 9.44MHz * 65536 = 618660 */
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev, OscFrequencyMHz, 618660);
+
+ /* Set Default XTalkCompensationRateMegaCps to 0 */
+ VL53L0_SETPARAMETERFIELD(Dev, XTalkCompensationRateMegaCps, 0);
+
+ /* Get default parameters */
+ Status = VL53L0_GetDeviceParameters(Dev, &CurrentParameters);
+ if (Status == VL53L0_ERROR_NONE) {
+ /* initialize PAL values */
+ CurrentParameters.DeviceMode = VL53L0_DEVICEMODE_SINGLE_RANGING;
+ CurrentParameters.HistogramMode = VL53L0_HISTOGRAMMODE_DISABLED;
+ PALDevDataSet(Dev, CurrentParameters, CurrentParameters);
+ }
+
+ /* Sigma estimator variable */
+ PALDevDataSet(Dev, SigmaEstRefArray, 100);
+ PALDevDataSet(Dev, SigmaEstEffPulseWidth, 900);
+ PALDevDataSet(Dev, SigmaEstEffAmbWidth, 500);
+ PALDevDataSet(Dev, targetRefRate, 0x0A00); /* 20 MCPS in 9:7 format */
+
+ /* Use internal default settings */
+ PALDevDataSet(Dev, UseInternalTuningSettings, 1);
+
+ /* Enable all check */
+ for (i = 0; i < VL53L0_CHECKENABLE_NUMBER_OF_CHECKS; i++) {
+ if (Status == VL53L0_ERROR_NONE)
+ Status |= VL53L0_SetLimitCheckEnable(Dev, i, 1);
+ else
+ break;
+
+ }
+
+ /* Disable the following checks */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetLimitCheckEnable(Dev,
+ VL53L0_CHECKENABLE_SIGNAL_REF_CLIP, 0);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetLimitCheckEnable(Dev,
+ VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 0);
+
+ /* Limit default values */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_SetLimitCheckValue(Dev,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (FixPoint1616_t)(18 * 65536));
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_SetLimitCheckValue(Dev,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (FixPoint1616_t)(25 * 65536 / 100));
+ /* 0.25 * 65536 */
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_SetLimitCheckValue(Dev,
+ VL53L0_CHECKENABLE_SIGNAL_REF_CLIP,
+ (FixPoint1616_t)(35 * 65536));
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_SetLimitCheckValue(Dev,
+ VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
+ (FixPoint1616_t)(0 * 65536));
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+
+ PALDevDataSet(Dev, SequenceConfig, 0xFF);
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSTEM_SEQUENCE_CONFIG,
+ 0xFF);
+
+ /* Set PAL state to tell that we are waiting for call to
+ * VL53L0_StaticInit */
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_WAIT_STATICINIT);
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev, RefSpadsInitialised, 0);
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetTuningSettingBuffer(VL53L0_DEV Dev,
+ uint8_t *pTuningSettingBuffer, uint8_t UseInternalTuningSettings)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (UseInternalTuningSettings == 1) {
+ /* Force use internal settings */
+ PALDevDataSet(Dev, UseInternalTuningSettings, 1);
+ } else {
+
+ /* check that the first byte is not 0 */
+ if (*pTuningSettingBuffer != 0) {
+ PALDevDataSet(Dev, pTuningSettingsPointer,
+ pTuningSettingBuffer);
+ PALDevDataSet(Dev, UseInternalTuningSettings, 0);
+
+ } else {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetTuningSettingBuffer(VL53L0_DEV Dev,
+ uint8_t **ppTuningSettingBuffer, uint8_t *pUseInternalTuningSettings)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *ppTuningSettingBuffer = PALDevDataGet(Dev, pTuningSettingsPointer);
+ *pUseInternalTuningSettings = PALDevDataGet(Dev,
+ UseInternalTuningSettings);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_StaticInit(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceParameters_t CurrentParameters = {0};
+ uint8_t *pTuningSettingBuffer;
+ uint16_t tempword = 0;
+ uint8_t tempbyte = 0;
+ uint8_t UseInternalTuningSettings = 0;
+ uint32_t count = 0;
+ uint8_t isApertureSpads = 0;
+ uint32_t refSpadCount = 0;
+ uint8_t ApertureSpads = 0;
+ uint8_t vcselPulsePeriodPCLK;
+ FixPoint1616_t seqTimeoutMilliSecs;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_info_from_device(Dev, 1);
+
+ /* set the ref spad from NVM */
+ count = (uint32_t)VL53L0_GETDEVICESPECIFICPARAMETER(Dev,
+ ReferenceSpadCount);
+ ApertureSpads = VL53L0_GETDEVICESPECIFICPARAMETER(Dev,
+ ReferenceSpadType);
+
+ /* NVM value invalid */
+ if ((ApertureSpads > 1) ||
+ ((ApertureSpads == 1) && (count > 32)) ||
+ ((ApertureSpads == 0) && (count > 12)))
+ Status = VL53L0_perform_ref_spad_management(Dev, &refSpadCount,
+ &isApertureSpads);
+ else
+ Status = VL53L0_set_reference_spads(Dev, count, ApertureSpads);
+
+
+ /* Initialize tuning settings buffer to prevent compiler warning. */
+ pTuningSettingBuffer = DefaultTuningSettings;
+
+ if (Status == VL53L0_ERROR_NONE) {
+ UseInternalTuningSettings = PALDevDataGet(Dev,
+ UseInternalTuningSettings);
+
+ if (UseInternalTuningSettings == 0)
+ pTuningSettingBuffer = PALDevDataGet(Dev,
+ pTuningSettingsPointer);
+ else
+ pTuningSettingBuffer = DefaultTuningSettings;
+
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_load_tuning_settings(Dev, pTuningSettingBuffer);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev, 0x80, 0x00);
+
+
+ /* Set interrupt config to new sample ready */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_SetGpioConfig(Dev, 0, 0,
+ VL53L0_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY,
+ VL53L0_INTERRUPTPOLARITY_LOW);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_RdWord(Dev, 0x84, &tempword);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev, OscFrequencyMHz,
+ VL53L0_FIXPOINT412TOFIXPOINT1616(tempword));
+ }
+
+ /* After static init, some device parameters may be changed,
+ * so update them */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_GetDeviceParameters(Dev, &CurrentParameters);
+
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_GetFractionEnable(Dev, &tempbyte);
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, RangeFractionalEnable, tempbyte);
+
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, CurrentParameters, CurrentParameters);
+
+
+ /* read the sequence config and save it */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdByte(Dev,
+ VL53L0_REG_SYSTEM_SEQUENCE_CONFIG, &tempbyte);
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, SequenceConfig, tempbyte);
+
+ }
+
+ /* Disable MSRC and TCC by default */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetSequenceStepEnable(Dev,
+ VL53L0_SEQUENCESTEP_TCC, 0);
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetSequenceStepEnable(Dev,
+ VL53L0_SEQUENCESTEP_MSRC, 0);
+
+
+ /* Set PAL State to standby */
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_IDLE);
+
+
+
+ /* Store pre-range vcsel period */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_GetVcselPulsePeriod(
+ Dev,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE,
+ &vcselPulsePeriodPCLK);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETDEVICESPECIFICPARAMETER(
+ Dev,
+ PreRangeVcselPulsePeriod,
+ vcselPulsePeriodPCLK);
+ }
+
+ /* Store final-range vcsel period */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_GetVcselPulsePeriod(
+ Dev,
+ VL53L0_VCSEL_PERIOD_FINAL_RANGE,
+ &vcselPulsePeriodPCLK);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETDEVICESPECIFICPARAMETER(
+ Dev,
+ FinalRangeVcselPulsePeriod,
+ vcselPulsePeriodPCLK);
+ }
+
+ /* Store pre-range timeout */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_GetSequenceStepTimeout(
+ Dev,
+ VL53L0_SEQUENCESTEP_PRE_RANGE,
+ &seqTimeoutMilliSecs);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETDEVICESPECIFICPARAMETER(
+ Dev,
+ PreRangeTimeoutMicroSecs,
+ seqTimeoutMilliSecs);
+ }
+
+ /* Store final-range timeout */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_GetSequenceStepTimeout(
+ Dev,
+ VL53L0_SEQUENCESTEP_FINAL_RANGE,
+ &seqTimeoutMilliSecs);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETDEVICESPECIFICPARAMETER(
+ Dev,
+ FinalRangeTimeoutMicroSecs,
+ seqTimeoutMilliSecs);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_WaitDeviceBooted(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NOT_IMPLEMENTED;
+ LOG_FUNCTION_START("");
+
+ /* not implemented on VL53L0 */
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_ResetDevice(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Byte;
+ LOG_FUNCTION_START("");
+
+ /* Set reset bit */
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SOFT_RESET_GO2_SOFT_RESET_N,
+ 0x00);
+
+ /* Wait for some time */
+ if (Status == VL53L0_ERROR_NONE) {
+ do {
+ Status = VL53L0_RdByte(Dev,
+ VL53L0_REG_IDENTIFICATION_MODEL_ID, &Byte);
+ } while (Byte != 0x00);
+ }
+
+ /* Release reset */
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SOFT_RESET_GO2_SOFT_RESET_N,
+ 0x01);
+
+ /* Wait until correct boot-up of the device */
+ if (Status == VL53L0_ERROR_NONE) {
+ do {
+ Status = VL53L0_RdByte(Dev,
+ VL53L0_REG_IDENTIFICATION_MODEL_ID, &Byte);
+ } while (Byte == 0x00);
+ }
+
+ /* Set PAL State to VL53L0_STATE_POWERDOWN */
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_POWERDOWN);
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+/* End Group PAL Init Functions */
+
+/* Group PAL Parameters Functions */
+VL53L0_Error VL53L0_SetDeviceParameters(VL53L0_DEV Dev,
+ const VL53L0_DeviceParameters_t *pDeviceParameters)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int i;
+ LOG_FUNCTION_START("");
+ Status = VL53L0_SetDeviceMode(Dev, pDeviceParameters->DeviceMode);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetHistogramMode(Dev,
+ pDeviceParameters->HistogramMode);
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetInterMeasurementPeriodMilliSeconds(Dev,
+ pDeviceParameters->InterMeasurementPeriodMilliSeconds);
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetXTalkCompensationRateMegaCps(Dev,
+ pDeviceParameters->XTalkCompensationRateMegaCps);
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetOffsetCalibrationDataMicroMeter(Dev,
+ pDeviceParameters->RangeOffsetMicroMeters);
+
+
+ for (i = 0; i < VL53L0_CHECKENABLE_NUMBER_OF_CHECKS; i++) {
+ if (Status == VL53L0_ERROR_NONE)
+ Status |= VL53L0_SetLimitCheckEnable(Dev, i,
+ pDeviceParameters->LimitChecksEnable[i]);
+ else
+ break;
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status |= VL53L0_SetLimitCheckValue(Dev, i,
+ pDeviceParameters->LimitChecksValue[i]);
+ else
+ break;
+
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetWrapAroundCheckEnable(Dev,
+ pDeviceParameters->WrapAroundCheckEnable);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetMeasurementTimingBudgetMicroSeconds(Dev,
+ pDeviceParameters->MeasurementTimingBudgetMicroSeconds);
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetDeviceParameters(VL53L0_DEV Dev,
+ VL53L0_DeviceParameters_t *pDeviceParameters)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int i;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_GetDeviceMode(Dev, &(pDeviceParameters->DeviceMode));
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_GetHistogramMode(Dev,
+ &(pDeviceParameters->HistogramMode));
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_GetInterMeasurementPeriodMilliSeconds(Dev,
+ &(pDeviceParameters->InterMeasurementPeriodMilliSeconds));
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ pDeviceParameters->XTalkCompensationEnable = 0;
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_GetXTalkCompensationRateMegaCps(Dev,
+ &(pDeviceParameters->XTalkCompensationRateMegaCps));
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_GetOffsetCalibrationDataMicroMeter(Dev,
+ &(pDeviceParameters->RangeOffsetMicroMeters));
+
+
+ if (Status == VL53L0_ERROR_NONE) {
+ for (i = 0; i < VL53L0_CHECKENABLE_NUMBER_OF_CHECKS; i++) {
+ /* get first the values, then the enables.
+ * VL53L0_GetLimitCheckValue will modify the enable
+ * flags
+ */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status |= VL53L0_GetLimitCheckValue(Dev, i,
+ &(pDeviceParameters->LimitChecksValue[i]));
+ } else {
+ break;
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status |= VL53L0_GetLimitCheckEnable(Dev, i,
+ &(pDeviceParameters->LimitChecksEnable[i]));
+ } else {
+ break;
+ }
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_GetWrapAroundCheckEnable(Dev,
+ &(pDeviceParameters->WrapAroundCheckEnable));
+ }
+
+ /* Need to be done at the end as it uses VCSELPulsePeriod */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_GetMeasurementTimingBudgetMicroSeconds(Dev,
+ &(pDeviceParameters->MeasurementTimingBudgetMicroSeconds));
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetDeviceMode(VL53L0_DEV Dev, VL53L0_DeviceModes DeviceMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("%d", (int)DeviceMode);
+
+ switch (DeviceMode) {
+ case VL53L0_DEVICEMODE_SINGLE_RANGING:
+ case VL53L0_DEVICEMODE_CONTINUOUS_RANGING:
+ case VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING:
+ case VL53L0_DEVICEMODE_SINGLE_HISTOGRAM:
+ case VL53L0_DEVICEMODE_GPIO_DRIVE:
+ case VL53L0_DEVICEMODE_GPIO_OSC:
+ /* Supported modes */
+ VL53L0_SETPARAMETERFIELD(Dev, DeviceMode, DeviceMode);
+ break;
+ default:
+ /* Unsupported mode */
+ Status = VL53L0_ERROR_MODE_NOT_SUPPORTED;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetDeviceMode(VL53L0_DEV Dev,
+ VL53L0_DeviceModes *pDeviceMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ VL53L0_GETPARAMETERFIELD(Dev, DeviceMode, *pDeviceMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetRangeFractionEnable(VL53L0_DEV Dev, uint8_t Enable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("%d", (int)Enable);
+
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSTEM_RANGE_CONFIG, Enable);
+
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, RangeFractionalEnable, Enable);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetFractionEnable(VL53L0_DEV Dev, uint8_t *pEnabled)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L0_REG_SYSTEM_RANGE_CONFIG, pEnabled);
+
+ if (Status == VL53L0_ERROR_NONE)
+ *pEnabled = (*pEnabled & 1);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetHistogramMode(VL53L0_DEV Dev,
+ VL53L0_HistogramModes HistogramMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("%d", (int)HistogramMode);
+
+ Status = VL53L0_set_histogram_mode(Dev, HistogramMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetHistogramMode(VL53L0_DEV Dev,
+ VL53L0_HistogramModes *pHistogramMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_histogram_mode(Dev, pHistogramMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetMeasurementTimingBudgetMicroSeconds(VL53L0_DEV Dev,
+ uint32_t MeasurementTimingBudgetMicroSeconds)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_set_measurement_timing_budget_micro_seconds(Dev,
+ MeasurementTimingBudgetMicroSeconds);
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetMeasurementTimingBudgetMicroSeconds(VL53L0_DEV Dev,
+ uint32_t *pMeasurementTimingBudgetMicroSeconds)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_measurement_timing_budget_micro_seconds(Dev,
+ pMeasurementTimingBudgetMicroSeconds);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetVcselPulsePeriod(VL53L0_DEV Dev,
+ VL53L0_VcselPeriod VcselPeriodType, uint8_t VCSELPulsePeriodPCLK)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_set_vcsel_pulse_period(Dev, VcselPeriodType,
+ VCSELPulsePeriodPCLK);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetVcselPulsePeriod(VL53L0_DEV Dev,
+ VL53L0_VcselPeriod VcselPeriodType, uint8_t *pVCSELPulsePeriodPCLK)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_vcsel_pulse_period(Dev, VcselPeriodType,
+ pVCSELPulsePeriodPCLK);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetSequenceStepEnable(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId, uint8_t SequenceStepEnabled)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t SequenceConfig = 0;
+ uint8_t SequenceConfigNew = 0;
+ uint32_t MeasurementTimingBudgetMicroSeconds;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L0_REG_SYSTEM_SEQUENCE_CONFIG,
+ &SequenceConfig);
+
+ SequenceConfigNew = SequenceConfig;
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (SequenceStepEnabled == 1) {
+
+ /* Enable requested sequence step
+ */
+ switch (SequenceStepId) {
+ case VL53L0_SEQUENCESTEP_TCC:
+ SequenceConfigNew |= 0x10;
+ break;
+ case VL53L0_SEQUENCESTEP_DSS:
+ SequenceConfigNew |= 0x28;
+ break;
+ case VL53L0_SEQUENCESTEP_MSRC:
+ SequenceConfigNew |= 0x04;
+ break;
+ case VL53L0_SEQUENCESTEP_PRE_RANGE:
+ SequenceConfigNew |= 0x40;
+ break;
+ case VL53L0_SEQUENCESTEP_FINAL_RANGE:
+ SequenceConfigNew |= 0x80;
+ break;
+ default:
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+ } else {
+ /* Disable requested sequence step
+ */
+ switch (SequenceStepId) {
+ case VL53L0_SEQUENCESTEP_TCC:
+ SequenceConfigNew &= 0xef;
+ break;
+ case VL53L0_SEQUENCESTEP_DSS:
+ SequenceConfigNew &= 0xd7;
+ break;
+ case VL53L0_SEQUENCESTEP_MSRC:
+ SequenceConfigNew &= 0xfb;
+ break;
+ case VL53L0_SEQUENCESTEP_PRE_RANGE:
+ SequenceConfigNew &= 0xbf;
+ break;
+ case VL53L0_SEQUENCESTEP_FINAL_RANGE:
+ SequenceConfigNew &= 0x7f;
+ break;
+ default:
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+ }
+ }
+
+ if (SequenceConfigNew != SequenceConfig) {
+ /* Apply New Setting */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_SYSTEM_SEQUENCE_CONFIG, SequenceConfigNew);
+ }
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, SequenceConfig, SequenceConfigNew);
+
+
+ /* Recalculate timing budget */
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_GETPARAMETERFIELD(Dev,
+ MeasurementTimingBudgetMicroSeconds,
+ MeasurementTimingBudgetMicroSeconds);
+
+ VL53L0_SetMeasurementTimingBudgetMicroSeconds(Dev,
+ MeasurementTimingBudgetMicroSeconds);
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+VL53L0_Error sequence_step_enabled(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId, uint8_t SequenceConfig,
+ uint8_t *pSequenceStepEnabled)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ *pSequenceStepEnabled = 0;
+ LOG_FUNCTION_START("");
+
+ switch (SequenceStepId) {
+ case VL53L0_SEQUENCESTEP_TCC:
+ *pSequenceStepEnabled = (SequenceConfig & 0x10) >> 4;
+ break;
+ case VL53L0_SEQUENCESTEP_DSS:
+ *pSequenceStepEnabled = (SequenceConfig & 0x08) >> 3;
+ break;
+ case VL53L0_SEQUENCESTEP_MSRC:
+ *pSequenceStepEnabled = (SequenceConfig & 0x04) >> 2;
+ break;
+ case VL53L0_SEQUENCESTEP_PRE_RANGE:
+ *pSequenceStepEnabled = (SequenceConfig & 0x40) >> 6;
+ break;
+ case VL53L0_SEQUENCESTEP_FINAL_RANGE:
+ *pSequenceStepEnabled = (SequenceConfig & 0x80) >> 7;
+ break;
+ default:
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetSequenceStepEnable(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId, uint8_t *pSequenceStepEnabled)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t SequenceConfig = 0;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L0_REG_SYSTEM_SEQUENCE_CONFIG,
+ &SequenceConfig);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = sequence_step_enabled(Dev, SequenceStepId,
+ SequenceConfig, pSequenceStepEnabled);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetSequenceStepEnables(VL53L0_DEV Dev,
+ VL53L0_SchedulerSequenceSteps_t *pSchedulerSequenceSteps)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t SequenceConfig = 0;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L0_REG_SYSTEM_SEQUENCE_CONFIG,
+ &SequenceConfig);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = sequence_step_enabled(Dev,
+ VL53L0_SEQUENCESTEP_TCC, SequenceConfig,
+ &pSchedulerSequenceSteps->TccOn);
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = sequence_step_enabled(Dev,
+ VL53L0_SEQUENCESTEP_DSS, SequenceConfig,
+ &pSchedulerSequenceSteps->DssOn);
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = sequence_step_enabled(Dev,
+ VL53L0_SEQUENCESTEP_MSRC, SequenceConfig,
+ &pSchedulerSequenceSteps->MsrcOn);
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = sequence_step_enabled(Dev,
+ VL53L0_SEQUENCESTEP_PRE_RANGE, SequenceConfig,
+ &pSchedulerSequenceSteps->PreRangeOn);
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = sequence_step_enabled(Dev,
+ VL53L0_SEQUENCESTEP_FINAL_RANGE, SequenceConfig,
+ &pSchedulerSequenceSteps->FinalRangeOn);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetNumberOfSequenceSteps(VL53L0_DEV Dev,
+ uint8_t *pNumberOfSequenceSteps)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ *pNumberOfSequenceSteps = VL53L0_SEQUENCESTEP_NUMBER_OF_CHECKS;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetSequenceStepsInfo(VL53L0_SequenceStepId SequenceStepId,
+ char *pSequenceStepsString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_sequence_steps_info(
+ SequenceStepId,
+ pSequenceStepsString);
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetSequenceStepTimeout(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId, FixPoint1616_t TimeOutMilliSecs)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_Error Status1 = VL53L0_ERROR_NONE;
+ uint32_t TimeoutMicroSeconds = ((TimeOutMilliSecs * 1000) + 0x8000)
+ >> 16;
+ uint32_t MeasurementTimingBudgetMicroSeconds;
+ FixPoint1616_t OldTimeOutMicroSeconds;
+
+ LOG_FUNCTION_START("");
+
+ /* Read back the current value in case we need to revert back to this.
+ */
+ Status = get_sequence_step_timeout(Dev, SequenceStepId,
+ &OldTimeOutMicroSeconds);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = set_sequence_step_timeout(Dev, SequenceStepId,
+ TimeoutMicroSeconds);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_GETPARAMETERFIELD(Dev,
+ MeasurementTimingBudgetMicroSeconds,
+ MeasurementTimingBudgetMicroSeconds);
+
+ /* At this point we don't know if the requested value is valid,
+ therefore proceed to update the entire timing budget and
+ if this fails, revert back to the previous value.
+ */
+ Status = VL53L0_SetMeasurementTimingBudgetMicroSeconds(Dev,
+ MeasurementTimingBudgetMicroSeconds);
+
+ if (Status != VL53L0_ERROR_NONE) {
+ Status1 = set_sequence_step_timeout(Dev, SequenceStepId,
+ OldTimeOutMicroSeconds);
+
+ if (Status1 == VL53L0_ERROR_NONE) {
+ Status1 =
+ VL53L0_SetMeasurementTimingBudgetMicroSeconds(
+ Dev,
+ MeasurementTimingBudgetMicroSeconds);
+ }
+
+ Status = Status1;
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetSequenceStepTimeout(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId, FixPoint1616_t *pTimeOutMilliSecs)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint32_t TimeoutMicroSeconds;
+ uint32_t WholeNumber_ms = 0;
+ uint32_t Fraction_ms = 0;
+ LOG_FUNCTION_START("");
+
+ Status = get_sequence_step_timeout(Dev, SequenceStepId,
+ &TimeoutMicroSeconds);
+ if (Status == VL53L0_ERROR_NONE) {
+ WholeNumber_ms = TimeoutMicroSeconds / 1000;
+ Fraction_ms = TimeoutMicroSeconds - (WholeNumber_ms * 1000);
+ *pTimeOutMilliSecs = (WholeNumber_ms << 16)
+ + (((Fraction_ms * 0xffff) + 500) / 1000);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetInterMeasurementPeriodMilliSeconds(VL53L0_DEV Dev,
+ uint32_t InterMeasurementPeriodMilliSeconds)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint16_t osc_calibrate_val;
+ uint32_t IMPeriodMilliSeconds;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdWord(Dev, VL53L0_REG_OSC_CALIBRATE_VAL,
+ &osc_calibrate_val);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (osc_calibrate_val != 0) {
+ IMPeriodMilliSeconds =
+ InterMeasurementPeriodMilliSeconds
+ * osc_calibrate_val;
+ } else {
+ IMPeriodMilliSeconds =
+ InterMeasurementPeriodMilliSeconds;
+ }
+ Status = VL53L0_WrDWord(Dev,
+ VL53L0_REG_SYSTEM_INTERMEASUREMENT_PERIOD,
+ IMPeriodMilliSeconds);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETPARAMETERFIELD(Dev,
+ InterMeasurementPeriodMilliSeconds,
+ InterMeasurementPeriodMilliSeconds);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetInterMeasurementPeriodMilliSeconds(VL53L0_DEV Dev,
+ uint32_t *pInterMeasurementPeriodMilliSeconds)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint16_t osc_calibrate_val;
+ uint32_t IMPeriodMilliSeconds;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdWord(Dev, VL53L0_REG_OSC_CALIBRATE_VAL,
+ &osc_calibrate_val);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdDWord(Dev,
+ VL53L0_REG_SYSTEM_INTERMEASUREMENT_PERIOD,
+ &IMPeriodMilliSeconds);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (osc_calibrate_val != 0) {
+ *pInterMeasurementPeriodMilliSeconds =
+ IMPeriodMilliSeconds / osc_calibrate_val;
+ }
+ VL53L0_SETPARAMETERFIELD(Dev,
+ InterMeasurementPeriodMilliSeconds,
+ *pInterMeasurementPeriodMilliSeconds);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetXTalkCompensationEnable(VL53L0_DEV Dev,
+ uint8_t XTalkCompensationEnable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ FixPoint1616_t TempFix1616;
+ uint16_t LinearityCorrectiveGain;
+
+ LOG_FUNCTION_START("");
+
+ LinearityCorrectiveGain = PALDevDataGet(Dev, LinearityCorrectiveGain);
+
+ if ((XTalkCompensationEnable == 0)
+ || (LinearityCorrectiveGain != 1000)) {
+ TempFix1616 = 0;
+ } else {
+ VL53L0_GETPARAMETERFIELD(Dev, XTalkCompensationRateMegaCps,
+ TempFix1616);
+ }
+
+ /* the following register has a format 3.13 */
+ Status = VL53L0_WrWord(Dev,
+ VL53L0_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MCPS,
+ VL53L0_FIXPOINT1616TOFIXPOINT313(TempFix1616));
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (XTalkCompensationEnable == 0) {
+ VL53L0_SETPARAMETERFIELD(Dev, XTalkCompensationEnable,
+ 0);
+ } else {
+ VL53L0_SETPARAMETERFIELD(Dev, XTalkCompensationEnable,
+ 1);
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetXTalkCompensationEnable(VL53L0_DEV Dev,
+ uint8_t *pXTalkCompensationEnable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Temp8;
+ LOG_FUNCTION_START("");
+
+ VL53L0_GETPARAMETERFIELD(Dev, XTalkCompensationEnable, Temp8);
+ *pXTalkCompensationEnable = Temp8;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetXTalkCompensationRateMegaCps(VL53L0_DEV Dev,
+ FixPoint1616_t XTalkCompensationRateMegaCps)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Temp8;
+ uint16_t LinearityCorrectiveGain;
+ uint16_t data;
+ LOG_FUNCTION_START("");
+
+ VL53L0_GETPARAMETERFIELD(Dev, XTalkCompensationEnable, Temp8);
+ LinearityCorrectiveGain = PALDevDataGet(Dev, LinearityCorrectiveGain);
+
+ if (Temp8 == 0) { /* disabled write only internal value */
+ VL53L0_SETPARAMETERFIELD(Dev, XTalkCompensationRateMegaCps,
+ XTalkCompensationRateMegaCps);
+ } else {
+ /* the following register has a format 3.13 */
+ if (LinearityCorrectiveGain == 1000) {
+ data = VL53L0_FIXPOINT1616TOFIXPOINT313(
+ XTalkCompensationRateMegaCps);
+ } else {
+ data = 0;
+ }
+
+ Status = VL53L0_WrWord(Dev,
+ VL53L0_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MCPS, data);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETPARAMETERFIELD(Dev,
+ XTalkCompensationRateMegaCps,
+ XTalkCompensationRateMegaCps);
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetXTalkCompensationRateMegaCps(VL53L0_DEV Dev,
+ FixPoint1616_t *pXTalkCompensationRateMegaCps)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint16_t Value;
+ FixPoint1616_t TempFix1616;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdWord(Dev,
+ VL53L0_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MCPS, (uint16_t *)&Value);
+ if (Status == VL53L0_ERROR_NONE) {
+ if (Value == 0) {
+ /* the Xtalk is disabled return value from memory */
+ VL53L0_GETPARAMETERFIELD(Dev,
+ XTalkCompensationRateMegaCps, TempFix1616);
+ *pXTalkCompensationRateMegaCps = TempFix1616;
+ VL53L0_SETPARAMETERFIELD(Dev, XTalkCompensationEnable,
+ 0);
+ } else {
+ TempFix1616 = VL53L0_FIXPOINT313TOFIXPOINT1616(Value);
+ *pXTalkCompensationRateMegaCps = TempFix1616;
+ VL53L0_SETPARAMETERFIELD(Dev,
+ XTalkCompensationRateMegaCps, TempFix1616);
+ VL53L0_SETPARAMETERFIELD(Dev, XTalkCompensationEnable,
+ 1);
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetRefCalibration(VL53L0_DEV Dev, uint8_t VhvSettings,
+ uint8_t PhaseCal)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_set_ref_calibration(Dev, VhvSettings, PhaseCal);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetRefCalibration(VL53L0_DEV Dev, uint8_t *pVhvSettings,
+ uint8_t *pPhaseCal)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_ref_calibration(Dev, pVhvSettings, pPhaseCal);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+/*
+ * CHECK LIMIT FUNCTIONS
+ */
+
+VL53L0_Error VL53L0_GetNumberOfLimitCheck(uint16_t *pNumberOfLimitCheck)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ *pNumberOfLimitCheck = VL53L0_CHECKENABLE_NUMBER_OF_CHECKS;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetLimitCheckInfo(VL53L0_DEV Dev, uint16_t LimitCheckId,
+ char *pLimitCheckString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_limit_check_info(Dev, LimitCheckId,
+ pLimitCheckString);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetLimitCheckStatus(VL53L0_DEV Dev, uint16_t LimitCheckId,
+ uint8_t *pLimitCheckStatus)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Temp8;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L0_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ } else {
+
+ VL53L0_GETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
+ LimitCheckId, Temp8);
+
+ *pLimitCheckStatus = Temp8;
+
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetLimitCheckEnable(VL53L0_DEV Dev, uint16_t LimitCheckId,
+ uint8_t LimitCheckEnable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ FixPoint1616_t TempFix1616 = 0;
+ uint8_t LimitCheckEnableInt;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L0_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ } else {
+ if (LimitCheckEnable == 0) {
+ TempFix1616 = 0;
+ LimitCheckEnableInt = 0;
+ } else {
+ VL53L0_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
+ LimitCheckId, TempFix1616);
+ /* this to be sure to have either 0 or 1 */
+ LimitCheckEnableInt = 1;
+ }
+
+ switch (LimitCheckId) {
+
+ case VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE:
+ /* internal computation: */
+ VL53L0_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ LimitCheckEnableInt);
+
+ break;
+
+ case VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+
+ Status = VL53L0_WrWord(Dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,
+ VL53L0_FIXPOINT1616TOFIXPOINT97(TempFix1616));
+
+ break;
+
+ case VL53L0_CHECKENABLE_SIGNAL_REF_CLIP:
+
+ /* internal computation: */
+ VL53L0_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
+ VL53L0_CHECKENABLE_SIGNAL_REF_CLIP,
+ LimitCheckEnableInt);
+
+ break;
+
+ case VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
+
+ /* internal computation: */
+ VL53L0_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
+ VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
+ LimitCheckEnableInt);
+
+ break;
+
+ default:
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+
+ }
+
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (LimitCheckEnable == 0) {
+ VL53L0_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
+ LimitCheckId, 0);
+ } else {
+ VL53L0_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
+ LimitCheckId, 1);
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetLimitCheckEnable(VL53L0_DEV Dev, uint16_t LimitCheckId,
+ uint8_t *pLimitCheckEnable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Temp8;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L0_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ *pLimitCheckEnable = 0;
+ } else {
+ VL53L0_GETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
+ LimitCheckId, Temp8);
+ *pLimitCheckEnable = Temp8;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetLimitCheckValue(VL53L0_DEV Dev, uint16_t LimitCheckId,
+ FixPoint1616_t LimitCheckValue)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Temp8;
+
+ LOG_FUNCTION_START("");
+
+ VL53L0_GETARRAYPARAMETERFIELD(Dev, LimitChecksEnable, LimitCheckId,
+ Temp8);
+
+ if (Temp8 == 0) { /* disabled write only internal value */
+ VL53L0_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
+ LimitCheckId, LimitCheckValue);
+ } else {
+
+ switch (LimitCheckId) {
+
+ case VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE:
+ /* internal computation: */
+ VL53L0_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ LimitCheckValue);
+ break;
+
+ case VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+
+ Status = VL53L0_WrWord(Dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,
+ VL53L0_FIXPOINT1616TOFIXPOINT97(
+ LimitCheckValue));
+
+ break;
+
+ case VL53L0_CHECKENABLE_SIGNAL_REF_CLIP:
+
+ /* internal computation: */
+ VL53L0_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
+ VL53L0_CHECKENABLE_SIGNAL_REF_CLIP,
+ LimitCheckValue);
+
+ break;
+
+ case VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
+
+ /* internal computation: */
+ VL53L0_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
+ VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
+ LimitCheckValue);
+
+ break;
+
+ default:
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
+ LimitCheckId, LimitCheckValue);
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetLimitCheckValue(VL53L0_DEV Dev, uint16_t LimitCheckId,
+ FixPoint1616_t *pLimitCheckValue)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t EnableZeroValue = 0;
+ uint16_t Temp16;
+ FixPoint1616_t TempFix1616;
+
+ LOG_FUNCTION_START("");
+
+ switch (LimitCheckId) {
+
+ case VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE:
+ /* internal computation: */
+ VL53L0_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE, TempFix1616);
+ EnableZeroValue = 0;
+ break;
+
+ case VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+ Status = VL53L0_RdWord(Dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,
+ &Temp16);
+ if (Status == VL53L0_ERROR_NONE)
+ TempFix1616 = VL53L0_FIXPOINT97TOFIXPOINT1616(Temp16);
+
+
+ EnableZeroValue = 1;
+ break;
+
+ case VL53L0_CHECKENABLE_SIGNAL_REF_CLIP:
+ /* internal computation: */
+ VL53L0_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
+ VL53L0_CHECKENABLE_SIGNAL_REF_CLIP, TempFix1616);
+ EnableZeroValue = 0;
+ break;
+
+ case VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
+ /* internal computation: */
+ VL53L0_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
+ VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD, TempFix1616);
+ EnableZeroValue = 0;
+ break;
+
+ default:
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+
+ if (EnableZeroValue == 1) {
+
+ if (TempFix1616 == 0) {
+ /* disabled: return value from memory */
+ VL53L0_GETARRAYPARAMETERFIELD(Dev,
+ LimitChecksValue, LimitCheckId,
+ TempFix1616);
+ *pLimitCheckValue = TempFix1616;
+ VL53L0_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksEnable, LimitCheckId, 0);
+ } else {
+ *pLimitCheckValue = TempFix1616;
+ VL53L0_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksValue, LimitCheckId,
+ TempFix1616);
+ VL53L0_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksEnable, LimitCheckId, 1);
+ }
+ } else {
+ *pLimitCheckValue = TempFix1616;
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+VL53L0_Error VL53L0_GetLimitCheckCurrent(VL53L0_DEV Dev, uint16_t LimitCheckId,
+ FixPoint1616_t *pLimitCheckCurrent)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_RangingMeasurementData_t LastRangeDataBuffer;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L0_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ } else {
+ switch (LimitCheckId) {
+ case VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE:
+ /* Need to run a ranging to have the latest values */
+ *pLimitCheckCurrent = PALDevDataGet(Dev, SigmaEstimate);
+
+ break;
+
+ case VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+ /* Need to run a ranging to have the latest values */
+ LastRangeDataBuffer = PALDevDataGet(Dev,
+ LastRangeMeasure);
+ *pLimitCheckCurrent =
+ LastRangeDataBuffer.SignalRateRtnMegaCps;
+
+ break;
+
+ case VL53L0_CHECKENABLE_SIGNAL_REF_CLIP:
+ /* Need to run a ranging to have the latest values */
+ *pLimitCheckCurrent = PALDevDataGet(Dev,
+ LastSignalRefMcps);
+
+ break;
+
+ case VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
+ /* Need to run a ranging to have the latest values */
+ LastRangeDataBuffer = PALDevDataGet(Dev,
+ LastRangeMeasure);
+ *pLimitCheckCurrent =
+ LastRangeDataBuffer.SignalRateRtnMegaCps;
+
+ break;
+
+ default:
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+/*
+ * WRAPAROUND Check
+ */
+VL53L0_Error VL53L0_SetWrapAroundCheckEnable(VL53L0_DEV Dev,
+ uint8_t WrapAroundCheckEnable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Byte;
+ uint8_t WrapAroundCheckEnableInt;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L0_REG_SYSTEM_SEQUENCE_CONFIG, &Byte);
+ if (WrapAroundCheckEnable == 0) {
+ /* Disable wraparound */
+ Byte = Byte & 0x7F;
+ WrapAroundCheckEnableInt = 0;
+ } else {
+ /*Enable wraparound */
+ Byte = Byte | 0x80;
+ WrapAroundCheckEnableInt = 1;
+ }
+
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSTEM_SEQUENCE_CONFIG, Byte);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ PALDevDataSet(Dev, SequenceConfig, Byte);
+ VL53L0_SETPARAMETERFIELD(Dev, WrapAroundCheckEnable,
+ WrapAroundCheckEnableInt);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetWrapAroundCheckEnable(VL53L0_DEV Dev,
+ uint8_t *pWrapAroundCheckEnable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t data;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L0_REG_SYSTEM_SEQUENCE_CONFIG, &data);
+ if (Status == VL53L0_ERROR_NONE) {
+ PALDevDataSet(Dev, SequenceConfig, data);
+ if (data & (0x01 << 7))
+ *pWrapAroundCheckEnable = 0x01;
+ else
+ *pWrapAroundCheckEnable = 0x00;
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETPARAMETERFIELD(Dev, WrapAroundCheckEnable,
+ *pWrapAroundCheckEnable);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetDmaxCalParameters(VL53L0_DEV Dev,
+ uint16_t RangeMilliMeter, FixPoint1616_t SignalRateRtnMegaCps)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ FixPoint1616_t SignalRateRtnMegaCpsTemp = 0;
+
+ LOG_FUNCTION_START("");
+
+ /* Check if one of input parameter is zero, in that case the
+ * value are get from NVM */
+ if ((RangeMilliMeter == 0) || (SignalRateRtnMegaCps == 0)) {
+ /* NVM parameters */
+ /* Run VL53L0_get_info_from_device wit option 4 to get
+ * signal rate at 400 mm if the value have been already
+ * get this function will return with no access to device */
+ VL53L0_get_info_from_device(Dev, 4);
+
+ SignalRateRtnMegaCpsTemp = VL53L0_GETDEVICESPECIFICPARAMETER(
+ Dev, SignalRateMeasFixed400mm);
+
+ PALDevDataSet(Dev, DmaxCalRangeMilliMeter, 400);
+ PALDevDataSet(Dev, DmaxCalSignalRateRtnMegaCps,
+ SignalRateRtnMegaCpsTemp);
+ } else {
+ /* User parameters */
+ PALDevDataSet(Dev, DmaxCalRangeMilliMeter, RangeMilliMeter);
+ PALDevDataSet(Dev, DmaxCalSignalRateRtnMegaCps,
+ SignalRateRtnMegaCps);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetDmaxCalParameters(VL53L0_DEV Dev,
+ uint16_t *pRangeMilliMeter, FixPoint1616_t *pSignalRateRtnMegaCps)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pRangeMilliMeter = PALDevDataGet(Dev, DmaxCalRangeMilliMeter);
+ *pSignalRateRtnMegaCps = PALDevDataGet(Dev,
+ DmaxCalSignalRateRtnMegaCps);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+/* End Group PAL Parameters Functions */
+
+/* Group PAL Measurement Functions */
+VL53L0_Error VL53L0_PerformSingleMeasurement(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceModes DeviceMode;
+
+ LOG_FUNCTION_START("");
+
+ /* Get Current DeviceMode */
+ Status = VL53L0_GetDeviceMode(Dev, &DeviceMode);
+
+ /* Start immediately to run a single ranging measurement in case of
+ * single ranging or single histogram */
+ if (Status == VL53L0_ERROR_NONE
+ && DeviceMode == VL53L0_DEVICEMODE_SINGLE_RANGING)
+ Status = VL53L0_StartMeasurement(Dev);
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_measurement_poll_for_completion(Dev);
+
+
+ /* Change PAL State in case of single ranging or single histogram */
+ if (Status == VL53L0_ERROR_NONE
+ && DeviceMode == VL53L0_DEVICEMODE_SINGLE_RANGING)
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_IDLE);
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_PerformSingleHistogramMeasurement(VL53L0_DEV Dev,
+ VL53L0_HistogramMeasurementData_t *pHistogramMeasurementData)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_perform_single_histogram_measurement(Dev,
+ pHistogramMeasurementData);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_PerformRefCalibration(VL53L0_DEV Dev, uint8_t *pVhvSettings,
+ uint8_t *pPhaseCal)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_perform_ref_calibration(Dev, pVhvSettings,
+ pPhaseCal, 1);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_PerformXTalkMeasurement(VL53L0_DEV Dev,
+ uint32_t TimeoutMs, FixPoint1616_t *pXtalkPerSpad,
+ uint8_t *pAmbientTooHigh)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_perform_xtalk_measurement(Dev, TimeoutMs,
+ pXtalkPerSpad, pAmbientTooHigh);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_PerformXTalkCalibration(VL53L0_DEV Dev,
+ FixPoint1616_t XTalkCalDistance,
+ FixPoint1616_t *pXTalkCompensationRateMegaCps)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_perform_xtalk_calibration(Dev, XTalkCalDistance,
+ pXTalkCompensationRateMegaCps);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_PerformOffsetCalibration(VL53L0_DEV Dev,
+ FixPoint1616_t CalDistanceMilliMeter, int32_t *pOffsetMicroMeter)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_perform_offset_calibration(Dev, CalDistanceMilliMeter,
+ pOffsetMicroMeter);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_StartMeasurement(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceModes DeviceMode;
+ uint8_t Byte;
+ uint8_t StartStopByte = VL53L0_REG_SYSRANGE_MODE_START_STOP;
+ uint32_t LoopNb;
+ LOG_FUNCTION_START("");
+
+ /* Get Current DeviceMode */
+ VL53L0_GetDeviceMode(Dev, &DeviceMode);
+
+ switch (DeviceMode) {
+ case VL53L0_DEVICEMODE_SINGLE_RANGING:
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_SYSRANGE_START,
+ VL53L0_REG_SYSRANGE_MODE_SINGLESHOT | StartStopByte);
+ break;
+ case VL53L0_DEVICEMODE_CONTINUOUS_RANGING:
+ /* Back-to-back mode */
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_SYSRANGE_START,
+ VL53L0_REG_SYSRANGE_MODE_BACKTOBACK | StartStopByte);
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Set PAL State to Running */
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_RUNNING);
+ }
+ break;
+ case VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING:
+ /* Continuous mode */
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_SYSRANGE_START,
+ VL53L0_REG_SYSRANGE_MODE_TIMED | StartStopByte);
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Set PAL State to Running */
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_RUNNING);
+ }
+ break;
+ default:
+ /* Selected mode not supported */
+ Status = VL53L0_ERROR_MODE_NOT_SUPPORTED;
+ }
+
+ Byte = StartStopByte;
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Wait until start bit has been cleared */
+ LoopNb = 0;
+ do {
+ if (LoopNb > 0)
+ Status = VL53L0_RdByte(Dev,
+ VL53L0_REG_SYSRANGE_START, &Byte);
+ LoopNb = LoopNb + 1;
+ } while (((Byte & StartStopByte) == StartStopByte)
+ && (Status == VL53L0_ERROR_NONE)
+ && (LoopNb < VL53L0_DEFAULT_MAX_LOOP));
+
+ if (LoopNb >= VL53L0_DEFAULT_MAX_LOOP)
+ Status = VL53L0_ERROR_TIME_OUT;
+
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_StopMeasurement(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSRANGE_START,
+ VL53L0_REG_SYSRANGE_MODE_SINGLESHOT);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Set PAL State to Idle */
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_IDLE);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetMeasurementDataReady(VL53L0_DEV Dev,
+ uint8_t *pMeasurementDataReady)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t SysRangeStatusRegister;
+ uint8_t InterruptConfig;
+ uint32_t InterruptMask;
+ LOG_FUNCTION_START("");
+
+ InterruptConfig = VL53L0_GETDEVICESPECIFICPARAMETER(Dev,
+ Pin0GpioFunctionality);
+
+ if (InterruptConfig ==
+ VL53L0_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY) {
+ Status = VL53L0_GetInterruptMaskStatus(Dev, &InterruptMask);
+ if (InterruptMask ==
+ VL53L0_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY)
+ *pMeasurementDataReady = 1;
+ else
+ *pMeasurementDataReady = 0;
+ } else {
+ Status = VL53L0_RdByte(Dev, VL53L0_REG_RESULT_RANGE_STATUS,
+ &SysRangeStatusRegister);
+ if (Status == VL53L0_ERROR_NONE) {
+ if (SysRangeStatusRegister & 0x01)
+ *pMeasurementDataReady = 1;
+ else
+ *pMeasurementDataReady = 0;
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_WaitDeviceReadyForNewMeasurement(VL53L0_DEV Dev,
+ uint32_t MaxLoop)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NOT_IMPLEMENTED;
+ LOG_FUNCTION_START("");
+
+ /* not implemented for VL53L0 */
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_GetRangingMeasurementData(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t DeviceRangeStatus;
+ uint8_t RangeFractionalEnable;
+ uint8_t PalRangeStatus;
+ uint8_t XTalkCompensationEnable;
+ uint16_t AmbientRate;
+ FixPoint1616_t SignalRate;
+ uint16_t XTalkCompensationRateMegaCps;
+ uint16_t EffectiveSpadRtnCount;
+ uint16_t tmpuint16;
+ uint16_t XtalkRangeMilliMeter;
+ uint16_t LinearityCorrectiveGain;
+ uint8_t localBuffer[12];
+ VL53L0_RangingMeasurementData_t LastRangeDataBuffer;
+
+ LOG_FUNCTION_START("");
+
+ /*
+ * use multi read even if some registers are not useful, result will
+ * be more efficient
+ * start reading at 0x14 dec20
+ * end reading at 0x21 dec33 total 14 bytes to read
+ */
+ Status = VL53L0_ReadMulti(Dev, 0x14, localBuffer, 12);
+
+ if (Status == VL53L0_ERROR_NONE) {
+
+ pRangingMeasurementData->ZoneId = 0; /* Only one zone */
+ pRangingMeasurementData->TimeStamp = 0; /* Not Implemented */
+
+ tmpuint16 = VL53L0_MAKEUINT16(localBuffer[11], localBuffer[10]);
+ /* cut1.1 if SYSTEM__RANGE_CONFIG if 1 range is 2bits fractional
+ *(format 11.2) else no fractional
+ */
+
+ pRangingMeasurementData->MeasurementTimeUsec = 0;
+
+ SignalRate = VL53L0_FIXPOINT97TOFIXPOINT1616(
+ VL53L0_MAKEUINT16(localBuffer[7], localBuffer[6]));
+ /* peak_signal_count_rate_rtn_mcps */
+ pRangingMeasurementData->SignalRateRtnMegaCps = SignalRate;
+
+ AmbientRate = VL53L0_MAKEUINT16(localBuffer[9], localBuffer[8]);
+ pRangingMeasurementData->AmbientRateRtnMegaCps =
+ VL53L0_FIXPOINT97TOFIXPOINT1616(AmbientRate);
+
+ EffectiveSpadRtnCount = VL53L0_MAKEUINT16(localBuffer[3],
+ localBuffer[2]);
+ /* EffectiveSpadRtnCount is 8.8 format */
+ pRangingMeasurementData->EffectiveSpadRtnCount =
+ EffectiveSpadRtnCount;
+
+ DeviceRangeStatus = localBuffer[0];
+
+ /* Get Linearity Corrective Gain */
+ LinearityCorrectiveGain = PALDevDataGet(Dev,
+ LinearityCorrectiveGain);
+
+ /* Get ranging configuration */
+ RangeFractionalEnable = PALDevDataGet(Dev,
+ RangeFractionalEnable);
+
+ if (LinearityCorrectiveGain != 1000) {
+
+ tmpuint16 = (uint16_t)((LinearityCorrectiveGain
+ * tmpuint16 + 500) / 1000);
+
+ /* Implement Xtalk */
+ VL53L0_GETPARAMETERFIELD(Dev,
+ XTalkCompensationRateMegaCps,
+ XTalkCompensationRateMegaCps);
+ VL53L0_GETPARAMETERFIELD(Dev, XTalkCompensationEnable,
+ XTalkCompensationEnable);
+
+ if (XTalkCompensationEnable) {
+
+ if ((SignalRate
+ - ((XTalkCompensationRateMegaCps
+ * EffectiveSpadRtnCount) >> 8))
+ <= 0) {
+ if (RangeFractionalEnable)
+ XtalkRangeMilliMeter = 8888;
+ else
+ XtalkRangeMilliMeter = 8888
+ << 2;
+ } else {
+ XtalkRangeMilliMeter =
+ (tmpuint16 * SignalRate)
+ / (SignalRate
+ - ((XTalkCompensationRateMegaCps
+ * EffectiveSpadRtnCount)
+ >> 8));
+ }
+
+ tmpuint16 = XtalkRangeMilliMeter;
+ }
+
+ }
+
+ if (RangeFractionalEnable) {
+ pRangingMeasurementData->RangeMilliMeter =
+ (uint16_t)((tmpuint16) >> 2);
+ pRangingMeasurementData->RangeFractionalPart =
+ (uint8_t)((tmpuint16 & 0x03) << 6);
+ } else {
+ pRangingMeasurementData->RangeMilliMeter = tmpuint16;
+ pRangingMeasurementData->RangeFractionalPart = 0;
+ }
+
+ /*
+ * For a standard definition of RangeStatus, this should
+ * return 0 in case of good result after a ranging
+ * The range status depends on the device so call a device
+ * specific function to obtain the right Status.
+ */
+ Status |= VL53L0_get_pal_range_status(Dev, DeviceRangeStatus,
+ SignalRate, EffectiveSpadRtnCount,
+ pRangingMeasurementData, &PalRangeStatus);
+
+ if (Status == VL53L0_ERROR_NONE)
+ pRangingMeasurementData->RangeStatus = PalRangeStatus;
+
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Copy last read data into Dev buffer */
+ LastRangeDataBuffer = PALDevDataGet(Dev, LastRangeMeasure);
+
+ LastRangeDataBuffer.RangeMilliMeter =
+ pRangingMeasurementData->RangeMilliMeter;
+ LastRangeDataBuffer.RangeFractionalPart =
+ pRangingMeasurementData->RangeFractionalPart;
+ LastRangeDataBuffer.RangeDMaxMilliMeter =
+ pRangingMeasurementData->RangeDMaxMilliMeter;
+ LastRangeDataBuffer.MeasurementTimeUsec =
+ pRangingMeasurementData->MeasurementTimeUsec;
+ LastRangeDataBuffer.SignalRateRtnMegaCps =
+ pRangingMeasurementData->SignalRateRtnMegaCps;
+ LastRangeDataBuffer.AmbientRateRtnMegaCps =
+ pRangingMeasurementData->AmbientRateRtnMegaCps;
+ LastRangeDataBuffer.EffectiveSpadRtnCount =
+ pRangingMeasurementData->EffectiveSpadRtnCount;
+ LastRangeDataBuffer.RangeStatus =
+ pRangingMeasurementData->RangeStatus;
+
+ PALDevDataSet(Dev, LastRangeMeasure, LastRangeDataBuffer);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetMeasurementRefSignal(VL53L0_DEV Dev,
+ FixPoint1616_t *pMeasurementRefSignal)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ *pMeasurementRefSignal = PALDevDataGet(Dev, LastSignalRefMcps);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+VL53L0_Error VL53L0_GetHistogramMeasurementData(VL53L0_DEV Dev,
+ VL53L0_HistogramMeasurementData_t *pHistogramMeasurementData)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NOT_IMPLEMENTED;
+ LOG_FUNCTION_START("");
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_PerformSingleRangingMeasurement(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ /* This function will do a complete single ranging
+ * Here we fix the mode! */
+ Status = VL53L0_SetDeviceMode(Dev, VL53L0_DEVICEMODE_SINGLE_RANGING);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_PerformSingleMeasurement(Dev);
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_GetRangingMeasurementData(Dev,
+ pRangingMeasurementData);
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_ClearInterruptMask(Dev, 0);
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetNumberOfROIZones(VL53L0_DEV Dev,
+ uint8_t NumberOfROIZones)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (NumberOfROIZones != 1)
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetNumberOfROIZones(VL53L0_DEV Dev,
+ uint8_t *pNumberOfROIZones)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pNumberOfROIZones = 1;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetMaxNumberOfROIZones(VL53L0_DEV Dev,
+ uint8_t *pMaxNumberOfROIZones)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pMaxNumberOfROIZones = 1;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+/* End Group PAL Measurement Functions */
+
+VL53L0_Error VL53L0_SetGpioConfig(VL53L0_DEV Dev, uint8_t Pin,
+ VL53L0_DeviceModes DeviceMode, VL53L0_GpioFunctionality Functionality,
+ VL53L0_InterruptPolarity Polarity)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t data;
+
+ LOG_FUNCTION_START("");
+
+ if (Pin != 0) {
+ Status = VL53L0_ERROR_GPIO_NOT_EXISTING;
+ } else if (DeviceMode == VL53L0_DEVICEMODE_GPIO_DRIVE) {
+ if (Polarity == VL53L0_INTERRUPTPOLARITY_LOW)
+ data = 0x10;
+ else
+ data = 1;
+
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_GPIO_HV_MUX_ACTIVE_HIGH, data);
+
+ } else if (DeviceMode == VL53L0_DEVICEMODE_GPIO_OSC) {
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x80, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x85, 0x02);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0xcd, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xcc, 0x11);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x07);
+ Status |= VL53L0_WrByte(Dev, 0xbe, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x06);
+ Status |= VL53L0_WrByte(Dev, 0xcc, 0x09);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x00);
+
+ } else {
+
+ if (Status == VL53L0_ERROR_NONE) {
+ switch (Functionality) {
+ case VL53L0_GPIOFUNCTIONALITY_OFF:
+ data = 0x00;
+ break;
+ case VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW:
+ data = 0x01;
+ break;
+ case VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH:
+ data = 0x02;
+ break;
+ case VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT:
+ data = 0x03;
+ break;
+ case VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY:
+ data = 0x04;
+ break;
+ default:
+ Status =
+ VL53L0_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED;
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_SYSTEM_INTERRUPT_CONFIG_GPIO, data);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (Polarity == VL53L0_INTERRUPTPOLARITY_LOW)
+ data = 0;
+ else
+ data = (uint8_t)(1 << 4);
+
+ Status = VL53L0_UpdateByte(Dev,
+ VL53L0_REG_GPIO_HV_MUX_ACTIVE_HIGH, 0xEF, data);
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ Pin0GpioFunctionality, Functionality);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_ClearInterruptMask(Dev, 0);
+
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetGpioConfig(VL53L0_DEV Dev, uint8_t Pin,
+ VL53L0_DeviceModes *pDeviceMode,
+ VL53L0_GpioFunctionality *pFunctionality,
+ VL53L0_InterruptPolarity *pPolarity)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_GpioFunctionality GpioFunctionality;
+ uint8_t data;
+
+ LOG_FUNCTION_START("");
+
+ /* pDeviceMode not managed by Ewok it return the current mode */
+
+ Status = VL53L0_GetDeviceMode(Dev, pDeviceMode);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (Pin != 0) {
+ Status = VL53L0_ERROR_GPIO_NOT_EXISTING;
+ } else {
+ Status = VL53L0_RdByte(Dev,
+ VL53L0_REG_SYSTEM_INTERRUPT_CONFIG_GPIO, &data);
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ switch (data & 0x07) {
+ case 0x00:
+ GpioFunctionality = VL53L0_GPIOFUNCTIONALITY_OFF;
+ break;
+ case 0x01:
+ GpioFunctionality =
+ VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW;
+ break;
+ case 0x02:
+ GpioFunctionality =
+ VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH;
+ break;
+ case 0x03:
+ GpioFunctionality =
+ VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT;
+ break;
+ case 0x04:
+ GpioFunctionality =
+ VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY;
+ break;
+ default:
+ Status = VL53L0_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED;
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_RdByte(Dev, VL53L0_REG_GPIO_HV_MUX_ACTIVE_HIGH,
+ &data);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if ((data & (uint8_t)(1 << 4)) == 0)
+ *pPolarity = VL53L0_INTERRUPTPOLARITY_LOW;
+ else
+ *pPolarity = VL53L0_INTERRUPTPOLARITY_HIGH;
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ *pFunctionality = GpioFunctionality;
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev, Pin0GpioFunctionality,
+ GpioFunctionality);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetInterruptThresholds(VL53L0_DEV Dev,
+ VL53L0_DeviceModes DeviceMode, FixPoint1616_t ThresholdLow,
+ FixPoint1616_t ThresholdHigh)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint16_t Threshold16;
+ LOG_FUNCTION_START("");
+
+ /* no dependency on DeviceMode for Ewok */
+ /* Need to divide by 2 because the FW will apply a x2 */
+ Threshold16 = (uint16_t)((ThresholdLow >> 17) & 0x00fff);
+ Status = VL53L0_WrWord(Dev, VL53L0_REG_SYSTEM_THRESH_LOW, Threshold16);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Need to divide by 2 because the FW will apply a x2 */
+ Threshold16 = (uint16_t)((ThresholdHigh >> 17) & 0x00fff);
+ Status = VL53L0_WrWord(Dev, VL53L0_REG_SYSTEM_THRESH_HIGH,
+ Threshold16);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetInterruptThresholds(VL53L0_DEV Dev,
+ VL53L0_DeviceModes DeviceMode, FixPoint1616_t *pThresholdLow,
+ FixPoint1616_t *pThresholdHigh)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint16_t Threshold16;
+ LOG_FUNCTION_START("");
+
+ /* no dependency on DeviceMode for Ewok */
+
+ Status = VL53L0_RdWord(Dev, VL53L0_REG_SYSTEM_THRESH_LOW, &Threshold16);
+ /* Need to multiply by 2 because the FW will apply a x2 */
+ *pThresholdLow = (FixPoint1616_t)((0x00fff & Threshold16) << 17);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdWord(Dev, VL53L0_REG_SYSTEM_THRESH_HIGH,
+ &Threshold16);
+ /* Need to multiply by 2 because the FW will apply a x2 */
+ *pThresholdHigh =
+ (FixPoint1616_t)((0x00fff & Threshold16) << 17);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+/* Group PAL Interrupt Functions */
+VL53L0_Error VL53L0_ClearInterruptMask(VL53L0_DEV Dev, uint32_t InterruptMask)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t LoopCount;
+ uint8_t Byte;
+ LOG_FUNCTION_START("");
+
+ /* clear bit 0 range interrupt, bit 1 error interrupt */
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSTEM_INTERRUPT_CLEAR, 0x01);
+ LoopCount = 0;
+ do {
+ VL53L0_RdByte(Dev, VL53L0_REG_RESULT_INTERRUPT_STATUS, &Byte);
+ LoopCount++;
+ } while (((Byte & 0x07) != 0x00) && (LoopCount < 8));
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSTEM_INTERRUPT_CLEAR, 0x00);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetInterruptMaskStatus(VL53L0_DEV Dev,
+ uint32_t *pInterruptMaskStatus)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Byte;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_RdByte(Dev, VL53L0_REG_RESULT_INTERRUPT_STATUS, &Byte);
+ *pInterruptMaskStatus = Byte & 0x07;
+
+ if (Byte & 0x18)
+ Status = VL53L0_ERROR_RANGE_ERROR;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_EnableInterruptMask(VL53L0_DEV Dev, uint32_t InterruptMask)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NOT_IMPLEMENTED;
+ LOG_FUNCTION_START("");
+
+ /* not implemented for VL53L0 */
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+/* End Group PAL Interrupt Functions */
+
+/* Group SPAD functions */
+
+VL53L0_Error VL53L0_SetSpadAmbientDamperThreshold(VL53L0_DEV Dev,
+ uint16_t SpadAmbientDamperThreshold)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status = VL53L0_WrWord(Dev, 0x40, SpadAmbientDamperThreshold);
+ VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetSpadAmbientDamperThreshold(VL53L0_DEV Dev,
+ uint16_t *pSpadAmbientDamperThreshold)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status = VL53L0_RdWord(Dev, 0x40, pSpadAmbientDamperThreshold);
+ VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_SetSpadAmbientDamperFactor(VL53L0_DEV Dev,
+ uint16_t SpadAmbientDamperFactor)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Byte;
+ LOG_FUNCTION_START("");
+
+ Byte = (uint8_t)(SpadAmbientDamperFactor & 0x00FF);
+
+ VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status = VL53L0_WrByte(Dev, 0x42, Byte);
+ VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetSpadAmbientDamperFactor(VL53L0_DEV Dev,
+ uint16_t *pSpadAmbientDamperFactor)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t Byte;
+ LOG_FUNCTION_START("");
+
+ VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status = VL53L0_RdByte(Dev, 0x42, &Byte);
+ VL53L0_WrByte(Dev, 0xFF, 0x00);
+ *pSpadAmbientDamperFactor = (uint16_t)Byte;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+/* END Group SPAD functions */
+
+/*****************************************************************************
+ * Internal functions
+ *****************************************************************************/
+
+VL53L0_Error VL53L0_SetReferenceSpads(VL53L0_DEV Dev, uint32_t count,
+ uint8_t isApertureSpads)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_set_reference_spads(Dev, count, isApertureSpads);
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_GetReferenceSpads(VL53L0_DEV Dev, uint32_t *pSpadCount,
+ uint8_t *pIsApertureSpads)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_reference_spads(Dev, pSpadCount, pIsApertureSpads);
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_PerformRefSpadManagement(VL53L0_DEV Dev,
+ uint32_t *refSpadCount, uint8_t *isApertureSpads)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_perform_ref_spad_management(Dev, refSpadCount,
+ isApertureSpads);
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
diff --git a/drivers/input/misc/vl53L0/src/vl53l0_api_calibration.c b/drivers/input/misc/vl53L0/src/vl53l0_api_calibration.c
new file mode 100644
index 000000000000..596b07017ae0
--- /dev/null
+++ b/drivers/input/misc/vl53L0/src/vl53l0_api_calibration.c
@@ -0,0 +1,1275 @@
+/*******************************************************************************
+ Copyright © 2016, STMicroelectronics International N.V.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+ NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+ IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ******************************************************************************/
+
+#include "vl53l0_api.h"
+#include "vl53l0_api_core.h"
+#include "vl53l0_api_calibration.h"
+
+#ifndef __KERNEL__
+#include
+#endif
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(TRACE_MODULE_API, status, fmt, ##__VA_ARGS__)
+
+#define REF_ARRAY_SPAD_0 0
+#define REF_ARRAY_SPAD_5 5
+#define REF_ARRAY_SPAD_10 10
+
+uint32_t refArrayQuadrants[4] = {REF_ARRAY_SPAD_10, REF_ARRAY_SPAD_5,
+ REF_ARRAY_SPAD_0, REF_ARRAY_SPAD_5 };
+
+VL53L0_Error VL53L0_perform_xtalk_calibration(VL53L0_DEV Dev,
+ FixPoint1616_t XTalkCalDistance,
+ FixPoint1616_t *pXTalkCompensationRateMegaCps)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint16_t sum_ranging = 0;
+ uint16_t sum_spads = 0;
+ FixPoint1616_t sum_signalRate = 0;
+ FixPoint1616_t total_count = 0;
+ uint8_t xtalk_meas = 0;
+ VL53L0_RangingMeasurementData_t RangingMeasurementData;
+ FixPoint1616_t xTalkStoredMeanSignalRate;
+ FixPoint1616_t xTalkStoredMeanRange;
+ FixPoint1616_t xTalkStoredMeanRtnSpads;
+ uint32_t signalXTalkTotalPerSpad;
+ uint32_t xTalkStoredMeanRtnSpadsAsInt;
+ uint32_t xTalkCalDistanceAsInt;
+ FixPoint1616_t XTalkCompensationRateMegaCps;
+
+ if (XTalkCalDistance <= 0)
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+
+ /* Disable the XTalk compensation */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetXTalkCompensationEnable(Dev, 0);
+
+ /* Disable the RIT */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_SetLimitCheckEnable(Dev,
+ VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 0);
+ }
+
+ /* Perform 50 measurements and compute the averages */
+ if (Status == VL53L0_ERROR_NONE) {
+ sum_ranging = 0;
+ sum_spads = 0;
+ sum_signalRate = 0;
+ total_count = 0;
+ for (xtalk_meas = 0; xtalk_meas < 50; xtalk_meas++) {
+ Status = VL53L0_PerformSingleRangingMeasurement(Dev,
+ &RangingMeasurementData);
+
+ if (Status != VL53L0_ERROR_NONE)
+ break;
+
+ /* The range is valid when RangeStatus = 0 */
+ if (RangingMeasurementData.RangeStatus == 0) {
+ sum_ranging = sum_ranging +
+ RangingMeasurementData.RangeMilliMeter;
+ sum_signalRate = sum_signalRate +
+ RangingMeasurementData.SignalRateRtnMegaCps;
+ sum_spads = sum_spads +
+ RangingMeasurementData.EffectiveSpadRtnCount
+ / 256;
+ total_count = total_count + 1;
+ }
+ }
+
+ /* no valid values found */
+ if (total_count == 0)
+ Status = VL53L0_ERROR_RANGE_ERROR;
+
+ }
+
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* FixPoint1616_t / uint16_t = FixPoint1616_t */
+ xTalkStoredMeanSignalRate = sum_signalRate / total_count;
+ xTalkStoredMeanRange = (FixPoint1616_t)((uint32_t)(
+ sum_ranging << 16) / total_count);
+ xTalkStoredMeanRtnSpads = (FixPoint1616_t)((uint32_t)(
+ sum_spads << 16) / total_count);
+
+ /* Round Mean Spads to Whole Number.
+ * Typically the calculated mean SPAD count is a whole number
+ * or very close to a whole
+ * number, therefore any truncation will not result in a
+ * significant loss in accuracy.
+ * Also, for a grey target at a typical distance of around
+ * 400mm, around 220 SPADs will
+ * be enabled, therefore, any truncation will result in a loss
+ * of accuracy of less than
+ * 0.5%.
+ */
+ xTalkStoredMeanRtnSpadsAsInt = (xTalkStoredMeanRtnSpads +
+ 0x8000) >> 16;
+
+ /* Round Cal Distance to Whole Number.
+ * Note that the cal distance is in mm, therefore no resolution
+ * is lost.*/
+ xTalkCalDistanceAsInt = (XTalkCalDistance + 0x8000) >> 16;
+
+ if (xTalkStoredMeanRtnSpadsAsInt == 0 ||
+ xTalkCalDistanceAsInt == 0 ||
+ xTalkStoredMeanRange >= XTalkCalDistance) {
+ XTalkCompensationRateMegaCps = 0;
+ } else {
+ /* Round Cal Distance to Whole Number.
+ Note that the cal distance is in mm, therefore no
+ resolution is lost.*/
+ xTalkCalDistanceAsInt = (XTalkCalDistance +
+ 0x8000) >> 16;
+
+ /* Apply division by mean spad count early in the
+ * calculation to keep the numbers small.
+ * This ensures we can maintain a 32bit calculation.
+ * Fixed1616 / int := Fixed1616 */
+ signalXTalkTotalPerSpad = (xTalkStoredMeanSignalRate) /
+ xTalkStoredMeanRtnSpadsAsInt;
+
+ /* Complete the calculation for total Signal XTalk per
+ * SPAD
+ * Fixed1616 * (Fixed1616 - Fixed1616/int) :=
+ * (2^16 * Fixed1616)
+ */
+ signalXTalkTotalPerSpad *= ((1 << 16) -
+ (xTalkStoredMeanRange / xTalkCalDistanceAsInt));
+
+ /* Round from 2^16 * Fixed1616, to Fixed1616. */
+ XTalkCompensationRateMegaCps = (signalXTalkTotalPerSpad
+ + 0x8000) >> 16;
+
+ if (XTalkCompensationRateMegaCps < 0)
+ XTalkCompensationRateMegaCps = 0;
+ }
+
+ *pXTalkCompensationRateMegaCps = XTalkCompensationRateMegaCps;
+
+ /* Enable the XTalk compensation */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetXTalkCompensationEnable(Dev, 1);
+
+ /* Enable the XTalk compensation */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetXTalkCompensationRateMegaCps(Dev,
+ XTalkCompensationRateMegaCps);
+
+ }
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_perform_offset_calibration(VL53L0_DEV Dev,
+ FixPoint1616_t CalDistanceMilliMeter,
+ int32_t *pOffsetMicroMeter)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint16_t sum_ranging = 0;
+ FixPoint1616_t total_count = 0;
+ VL53L0_RangingMeasurementData_t RangingMeasurementData;
+ FixPoint1616_t StoredMeanRange;
+ uint32_t StoredMeanRangeAsInt;
+ uint32_t CalDistanceAsInt_mm;
+ uint8_t SequenceStepEnabled;
+ int meas = 0;
+
+ if (CalDistanceMilliMeter <= 0)
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetOffsetCalibrationDataMicroMeter(Dev, 0);
+
+
+ /* Get the value of the TCC */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_GetSequenceStepEnable(Dev,
+ VL53L0_SEQUENCESTEP_TCC, &SequenceStepEnabled);
+
+
+ /* Disable the TCC */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetSequenceStepEnable(Dev,
+ VL53L0_SEQUENCESTEP_TCC, 0);
+
+
+ /* Disable the RIT */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_SetLimitCheckEnable(Dev,
+ VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 0);
+
+ /* Perform 50 measurements and compute the averages */
+ if (Status == VL53L0_ERROR_NONE) {
+ sum_ranging = 0;
+ total_count = 0;
+ for (meas = 0; meas < 50; meas++) {
+ Status = VL53L0_PerformSingleRangingMeasurement(Dev,
+ &RangingMeasurementData);
+
+ if (Status != VL53L0_ERROR_NONE)
+ break;
+
+ /* The range is valid when RangeStatus = 0 */
+ if (RangingMeasurementData.RangeStatus == 0) {
+ sum_ranging = sum_ranging +
+ RangingMeasurementData.RangeMilliMeter;
+ total_count = total_count + 1;
+ }
+ }
+
+ /* no valid values found */
+ if (total_count == 0)
+ Status = VL53L0_ERROR_RANGE_ERROR;
+ }
+
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* FixPoint1616_t / uint16_t = FixPoint1616_t */
+ StoredMeanRange = (FixPoint1616_t)((uint32_t)(sum_ranging << 16)
+ / total_count);
+
+ StoredMeanRangeAsInt = (StoredMeanRange + 0x8000) >> 16;
+
+ /* Round Cal Distance to Whole Number.
+ * Note that the cal distance is in mm, therefore no resolution
+ * is lost.*/
+ CalDistanceAsInt_mm = (CalDistanceMilliMeter + 0x8000) >> 16;
+
+ *pOffsetMicroMeter = (CalDistanceAsInt_mm -
+ StoredMeanRangeAsInt) * 1000;
+
+ /* Apply the calculated offset */
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETPARAMETERFIELD(Dev, RangeOffsetMicroMeters,
+ *pOffsetMicroMeter);
+ Status = VL53L0_SetOffsetCalibrationDataMicroMeter(Dev,
+ *pOffsetMicroMeter);
+ }
+
+ }
+
+ /* Restore the TCC */
+ if (Status == VL53L0_ERROR_NONE) {
+ if (SequenceStepEnabled != 0)
+ Status = VL53L0_SetSequenceStepEnable(Dev,
+ VL53L0_SEQUENCESTEP_TCC, 1);
+ }
+
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_set_offset_calibration_data_micro_meter(VL53L0_DEV Dev,
+ int32_t OffsetCalibrationDataMicroMeter)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int32_t cMaxOffsetMicroMeter = 511000;
+ int32_t cMinOffsetMicroMeter = -512000;
+ int16_t cOffsetRange = 4096;
+ uint32_t encodedOffsetVal;
+
+ LOG_FUNCTION_START("");
+
+ if (OffsetCalibrationDataMicroMeter > cMaxOffsetMicroMeter)
+ OffsetCalibrationDataMicroMeter = cMaxOffsetMicroMeter;
+ else if (OffsetCalibrationDataMicroMeter < cMinOffsetMicroMeter)
+ OffsetCalibrationDataMicroMeter = cMinOffsetMicroMeter;
+
+ /* The offset register is 10.2 format and units are mm
+ * therefore conversion is applied by a division of
+ * 250.
+ */
+ if (OffsetCalibrationDataMicroMeter >= 0) {
+ encodedOffsetVal =
+ OffsetCalibrationDataMicroMeter/250;
+ } else {
+ encodedOffsetVal =
+ cOffsetRange +
+ OffsetCalibrationDataMicroMeter/250;
+ }
+
+ Status = VL53L0_WrWord(Dev,
+ VL53L0_REG_ALGO_PART_TO_PART_RANGE_OFFSET_MM,
+ encodedOffsetVal);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_get_offset_calibration_data_micro_meter(VL53L0_DEV Dev,
+ int32_t *pOffsetCalibrationDataMicroMeter)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint16_t RangeOffsetRegister;
+ int16_t cMaxOffset = 2047;
+ int16_t cOffsetRange = 4096;
+
+ /* Note that offset has 10.2 format */
+
+ Status = VL53L0_RdWord(Dev,
+ VL53L0_REG_ALGO_PART_TO_PART_RANGE_OFFSET_MM,
+ &RangeOffsetRegister);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ RangeOffsetRegister = (RangeOffsetRegister & 0x0fff);
+
+ /* Apply 12 bit 2's compliment conversion */
+ if (RangeOffsetRegister > cMaxOffset)
+ *pOffsetCalibrationDataMicroMeter =
+ (int16_t)(RangeOffsetRegister - cOffsetRange)
+ * 250;
+ else
+ *pOffsetCalibrationDataMicroMeter =
+ (int16_t)RangeOffsetRegister * 250;
+
+ }
+
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_apply_offset_adjustment(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int32_t CorrectedOffsetMicroMeters;
+ int32_t CurrentOffsetMicroMeters;
+
+ /* if we run on this function we can read all the NVM info
+ * used by the API */
+ Status = VL53L0_get_info_from_device(Dev, 7);
+
+ /* Read back current device offset */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_GetOffsetCalibrationDataMicroMeter(Dev,
+ &CurrentOffsetMicroMeters);
+ }
+
+ /* Apply Offset Adjustment derived from 400mm measurements */
+ if (Status == VL53L0_ERROR_NONE) {
+
+ /* Store initial device offset */
+ PALDevDataSet(Dev, Part2PartOffsetNVMMicroMeter,
+ CurrentOffsetMicroMeters);
+
+ CorrectedOffsetMicroMeters = CurrentOffsetMicroMeters +
+ (int32_t)PALDevDataGet(Dev,
+ Part2PartOffsetAdjustmentNVMMicroMeter);
+
+ Status = VL53L0_SetOffsetCalibrationDataMicroMeter(Dev,
+ CorrectedOffsetMicroMeters);
+
+ /* store current, adjusted offset */
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETPARAMETERFIELD(Dev, RangeOffsetMicroMeters,
+ CorrectedOffsetMicroMeters);
+ }
+ }
+
+ return Status;
+}
+
+void get_next_good_spad(uint8_t goodSpadArray[], uint32_t size,
+ uint32_t curr, int32_t *next)
+{
+ uint32_t startIndex;
+ uint32_t fineOffset;
+ uint32_t cSpadsPerByte = 8;
+ uint32_t coarseIndex;
+ uint32_t fineIndex;
+ uint8_t dataByte;
+ uint8_t success = 0;
+
+ /*
+ * Starting with the current good spad, loop through the array to find
+ * the next. i.e. the next bit set in the sequence.
+ *
+ * The coarse index is the byte index of the array and the fine index is
+ * the index of the bit within each byte.
+ */
+
+ *next = -1;
+
+ startIndex = curr / cSpadsPerByte;
+ fineOffset = curr % cSpadsPerByte;
+
+ for (coarseIndex = startIndex; ((coarseIndex < size) && !success);
+ coarseIndex++) {
+ fineIndex = 0;
+ dataByte = goodSpadArray[coarseIndex];
+
+ if (coarseIndex == startIndex) {
+ /* locate the bit position of the provided current
+ * spad bit before iterating */
+ dataByte >>= fineOffset;
+ fineIndex = fineOffset;
+ }
+
+ while (fineIndex < cSpadsPerByte) {
+ if ((dataByte & 0x1) == 1) {
+ success = 1;
+ *next = coarseIndex * cSpadsPerByte + fineIndex;
+ break;
+ }
+ dataByte >>= 1;
+ fineIndex++;
+ }
+ }
+}
+
+
+uint8_t is_aperture(uint32_t spadIndex)
+{
+ /*
+ * This function reports if a given spad index is an aperture SPAD by
+ * deriving the quadrant.
+ */
+ uint32_t quadrant;
+ uint8_t isAperture = 1;
+ quadrant = spadIndex >> 6;
+ if (refArrayQuadrants[quadrant] == REF_ARRAY_SPAD_0)
+ isAperture = 0;
+
+ return isAperture;
+}
+
+
+VL53L0_Error enable_spad_bit(uint8_t spadArray[], uint32_t size,
+ uint32_t spadIndex)
+{
+ VL53L0_Error status = VL53L0_ERROR_NONE;
+ uint32_t cSpadsPerByte = 8;
+ uint32_t coarseIndex;
+ uint32_t fineIndex;
+
+ coarseIndex = spadIndex / cSpadsPerByte;
+ fineIndex = spadIndex % cSpadsPerByte;
+ if (coarseIndex >= size)
+ status = VL53L0_ERROR_REF_SPAD_INIT;
+ else
+ spadArray[coarseIndex] |= (1 << fineIndex);
+
+ return status;
+}
+
+VL53L0_Error count_enabled_spads(uint8_t spadArray[],
+ uint32_t byteCount, uint32_t maxSpads,
+ uint32_t *pTotalSpadsEnabled, uint8_t *pIsAperture)
+{
+ VL53L0_Error status = VL53L0_ERROR_NONE;
+ uint32_t cSpadsPerByte = 8;
+ uint32_t lastByte;
+ uint32_t lastBit;
+ uint32_t byteIndex = 0;
+ uint32_t bitIndex = 0;
+ uint8_t tempByte;
+ uint8_t spadTypeIdentified = 0;
+
+ /* The entire array will not be used for spads, therefore the last
+ * byte and last bit is determined from the max spads value.
+ */
+
+ lastByte = maxSpads / cSpadsPerByte;
+ lastBit = maxSpads % cSpadsPerByte;
+
+ /* Check that the max spads value does not exceed the array bounds. */
+ if (lastByte >= byteCount)
+ status = VL53L0_ERROR_REF_SPAD_INIT;
+
+ *pTotalSpadsEnabled = 0;
+
+ /* Count the bits enabled in the whole bytes */
+ for (byteIndex = 0; byteIndex <= (lastByte - 1); byteIndex++) {
+ tempByte = spadArray[byteIndex];
+
+ for (bitIndex = 0; bitIndex <= cSpadsPerByte; bitIndex++) {
+ if ((tempByte & 0x01) == 1) {
+ (*pTotalSpadsEnabled)++;
+
+ if (!spadTypeIdentified) {
+ *pIsAperture = 1;
+ if ((byteIndex < 2) && (bitIndex < 4))
+ *pIsAperture = 0;
+ spadTypeIdentified = 1;
+ }
+ }
+ tempByte >>= 1;
+ }
+ }
+
+ /* Count the number of bits enabled in the last byte accounting
+ * for the fact that not all bits in the byte may be used.
+ */
+ tempByte = spadArray[lastByte];
+
+ for (bitIndex = 0; bitIndex <= lastBit; bitIndex++) {
+ if ((tempByte & 0x01) == 1)
+ (*pTotalSpadsEnabled)++;
+ }
+
+ return status;
+}
+
+VL53L0_Error set_ref_spad_map(VL53L0_DEV Dev, uint8_t *refSpadArray)
+{
+ VL53L0_Error status = VL53L0_WriteMulti(Dev,
+ VL53L0_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,
+ refSpadArray, 6);
+ return status;
+}
+
+VL53L0_Error get_ref_spad_map(VL53L0_DEV Dev, uint8_t *refSpadArray)
+{
+ VL53L0_Error status = VL53L0_ReadMulti(Dev,
+ VL53L0_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,
+ refSpadArray,
+ 6);
+ return status;
+}
+
+VL53L0_Error enable_ref_spads(VL53L0_DEV Dev,
+ uint8_t apertureSpads,
+ uint8_t goodSpadArray[],
+ uint8_t spadArray[],
+ uint32_t size,
+ uint32_t start,
+ uint32_t offset,
+ uint32_t spadCount,
+ uint32_t *lastSpad)
+{
+ VL53L0_Error status = VL53L0_ERROR_NONE;
+ uint32_t index;
+ uint32_t i;
+ int32_t nextGoodSpad = offset;
+ uint32_t currentSpad;
+ uint8_t checkSpadArray[6];
+
+ /*
+ * This function takes in a spad array which may or may not have SPADS
+ * already enabled and appends from a given offset a requested number
+ * of new SPAD enables. The 'good spad map' is applied to
+ * determine the next SPADs to enable.
+ *
+ * This function applies to only aperture or only non-aperture spads.
+ * Checks are performed to ensure this.
+ */
+
+ currentSpad = offset;
+ for (index = 0; index < spadCount; index++) {
+ get_next_good_spad(goodSpadArray, size, currentSpad,
+ &nextGoodSpad);
+
+ if (nextGoodSpad == -1) {
+ status = VL53L0_ERROR_REF_SPAD_INIT;
+ break;
+ }
+
+ /* Confirm that the next good SPAD is non-aperture */
+ if (is_aperture(start + nextGoodSpad) != apertureSpads) {
+ /* if we can't get the required number of good aperture
+ * spads from the current quadrant then this is an error
+ */
+ status = VL53L0_ERROR_REF_SPAD_INIT;
+ break;
+ }
+ currentSpad = (uint32_t)nextGoodSpad;
+ enable_spad_bit(spadArray, size, currentSpad);
+ currentSpad++;
+ }
+ *lastSpad = currentSpad;
+
+ if (status == VL53L0_ERROR_NONE)
+ status = set_ref_spad_map(Dev, spadArray);
+
+
+ if (status == VL53L0_ERROR_NONE) {
+ status = get_ref_spad_map(Dev, checkSpadArray);
+
+ i = 0;
+
+ /* Compare spad maps. If not equal report error. */
+ while (i < size) {
+ if (spadArray[i] != checkSpadArray[i]) {
+ status = VL53L0_ERROR_REF_SPAD_INIT;
+ break;
+ }
+ i++;
+ }
+ }
+ return status;
+}
+
+
+VL53L0_Error perform_ref_signal_measurement(VL53L0_DEV Dev,
+ uint16_t *refSignalRate)
+{
+ VL53L0_Error status = VL53L0_ERROR_NONE;
+ VL53L0_RangingMeasurementData_t rangingMeasurementData;
+
+ uint8_t SequenceConfig = 0;
+
+ /* store the value of the sequence config,
+ * this will be reset before the end of the function
+ */
+
+ SequenceConfig = PALDevDataGet(Dev, SequenceConfig);
+
+ /*
+ * This function performs a reference signal rate measurement.
+ */
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_WrByte(Dev,
+ VL53L0_REG_SYSTEM_SEQUENCE_CONFIG, 0xC0);
+
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_PerformSingleRangingMeasurement(Dev,
+ &rangingMeasurementData);
+
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_WrByte(Dev, 0xFF, 0x01);
+
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_RdWord(Dev,
+ VL53L0_REG_RESULT_PEAK_SIGNAL_RATE_REF,
+ refSignalRate);
+
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ if (status == VL53L0_ERROR_NONE) {
+ /* restore the previous Sequence Config */
+ status = VL53L0_WrByte(Dev, VL53L0_REG_SYSTEM_SEQUENCE_CONFIG,
+ SequenceConfig);
+ if (status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, SequenceConfig, SequenceConfig);
+ }
+
+ return status;
+}
+
+VL53L0_Error VL53L0_perform_ref_spad_management(VL53L0_DEV Dev,
+ uint32_t *refSpadCount,
+ uint8_t *isApertureSpads)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t lastSpadArray[6];
+ uint8_t startSelect = 0xB4;
+ uint32_t minimumSpadCount = 3;
+ uint32_t maxSpadCount = 44;
+ uint32_t currentSpadIndex = 0;
+ uint32_t lastSpadIndex = 0;
+ int32_t nextGoodSpad = 0;
+ uint16_t targetRefRate = 0x0A00; /* 20 MCPS in 9:7 format */
+ uint16_t peakSignalRateRef;
+ uint32_t needAptSpads = 0;
+ uint32_t index = 0;
+ uint32_t spadArraySize = 6;
+ uint32_t signalRateDiff = 0;
+ uint32_t lastSignalRateDiff = 0;
+ uint8_t complete = 0;
+ uint8_t VhvSettings = 0;
+ uint8_t PhaseCal = 0;
+ uint32_t refSpadCount_int = 0;
+ uint8_t isApertureSpads_int = 0;
+
+ /*
+ * The reference SPAD initialization procedure determines the minimum
+ * amount of reference spads to be enables to achieve a target reference
+ * signal rate and should be performed once during initialization.
+ *
+ * Either aperture or non-aperture spads are applied but never both.
+ * Firstly non-aperture spads are set, begining with 5 spads, and
+ * increased one spad at a time until the closest measurement to the
+ * target rate is achieved.
+ *
+ * If the target rate is exceeded when 5 non-aperture spads are enabled,
+ * initialization is performed instead with aperture spads.
+ *
+ * When setting spads, a 'Good Spad Map' is applied.
+ *
+ * This procedure operates within a SPAD window of interest of a maximum
+ * 44 spads.
+ * The start point is currently fixed to 180, which lies towards the end
+ * of the non-aperture quadrant and runs in to the adjacent aperture
+ * quadrant.
+ */
+
+
+ targetRefRate = PALDevDataGet(Dev, targetRefRate);
+
+ /*
+ * Initialize Spad arrays.
+ * Currently the good spad map is initialised to 'All good'.
+ * This is a short term implementation. The good spad map will be
+ * provided as an input.
+ * Note that there are 6 bytes. Only the first 44 bits will be used to
+ * represent spads.
+ */
+ for (index = 0; index < spadArraySize; index++) {
+ Dev->Data.SpadData.RefSpadEnables[index] = 0;
+ }
+
+ Status = VL53L0_WrByte(Dev, 0xFF, 0x01);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_DYNAMIC_SPAD_REF_EN_START_OFFSET, 0x00);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD, 0x2C);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_GLOBAL_CONFIG_REF_EN_START_SELECT,
+ startSelect);
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_POWER_MANAGEMENT_GO1_POWER_FORCE, 0);
+
+ /* Perform ref calibration */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_perform_ref_calibration(Dev, &VhvSettings,
+ &PhaseCal, 0);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Enable Minimum NON-APERTURE Spads */
+ currentSpadIndex = 0;
+ lastSpadIndex = currentSpadIndex;
+ needAptSpads = 0;
+ Status = enable_ref_spads(Dev,
+ needAptSpads,
+ Dev->Data.SpadData.RefGoodSpadMap,
+ Dev->Data.SpadData.RefSpadEnables,
+ spadArraySize,
+ startSelect,
+ currentSpadIndex,
+ minimumSpadCount,
+ &lastSpadIndex);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ currentSpadIndex = lastSpadIndex;
+
+ Status = perform_ref_signal_measurement(Dev,
+ &peakSignalRateRef);
+ if ((Status == VL53L0_ERROR_NONE) &&
+ (peakSignalRateRef > targetRefRate)) {
+ /* Signal rate measurement too high,
+ * switch to APERTURE SPADs */
+
+ for (index = 0; index < spadArraySize; index++)
+ Dev->Data.SpadData.RefSpadEnables[index] = 0;
+
+
+ /* Increment to the first APERTURE spad */
+ while ((is_aperture(startSelect + currentSpadIndex)
+ == 0) && (currentSpadIndex < maxSpadCount)) {
+ currentSpadIndex++;
+ }
+
+ needAptSpads = 1;
+
+ Status = enable_ref_spads(Dev,
+ needAptSpads,
+ Dev->Data.SpadData.RefGoodSpadMap,
+ Dev->Data.SpadData.RefSpadEnables,
+ spadArraySize,
+ startSelect,
+ currentSpadIndex,
+ minimumSpadCount,
+ &lastSpadIndex);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ currentSpadIndex = lastSpadIndex;
+ Status = perform_ref_signal_measurement(Dev,
+ &peakSignalRateRef);
+
+ if ((Status == VL53L0_ERROR_NONE) &&
+ (peakSignalRateRef > targetRefRate)) {
+ /* Signal rate still too high after
+ * setting the minimum number of
+ * APERTURE spads. Can do no more.
+ */
+ Status = VL53L0_ERROR_REF_SPAD_INIT;
+ needAptSpads = 0;
+ }
+ }
+ } else {
+ needAptSpads = 0;
+ }
+ }
+
+ if ((Status == VL53L0_ERROR_NONE) &&
+ (peakSignalRateRef < targetRefRate)) {
+ /* At this point, the minimum number of either aperture
+ * or non-aperture spads have been set. Proceed to add
+ * spads and perform measurements until the target
+ * reference is reached.
+ */
+ isApertureSpads_int = needAptSpads;
+ refSpadCount_int = minimumSpadCount;
+
+ memcpy(lastSpadArray, Dev->Data.SpadData.RefSpadEnables,
+ spadArraySize);
+ lastSignalRateDiff = abs(peakSignalRateRef -
+ targetRefRate);
+ complete = 0;
+
+ while (!complete) {
+ get_next_good_spad(
+ Dev->Data.SpadData.RefGoodSpadMap,
+ spadArraySize, currentSpadIndex,
+ &nextGoodSpad);
+
+ if (nextGoodSpad == -1) {
+ Status = VL53L0_ERROR_REF_SPAD_INIT;
+ break;
+ }
+
+ (refSpadCount_int)++;
+
+ /* Cannot combine Aperture and Non-Aperture spads, so
+ * ensure the current spad is of the correct type.
+ */
+ if (is_aperture((uint32_t)startSelect + nextGoodSpad) !=
+ needAptSpads) {
+ Status = VL53L0_ERROR_REF_SPAD_INIT;
+ break;
+ }
+
+ currentSpadIndex = nextGoodSpad;
+ Status = enable_spad_bit(
+ Dev->Data.SpadData.RefSpadEnables,
+ spadArraySize, currentSpadIndex);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ currentSpadIndex++;
+ /* Proceed to apply the additional spad and
+ * perform measurement. */
+ Status = set_ref_spad_map(Dev,
+ Dev->Data.SpadData.RefSpadEnables);
+ }
+
+ if (Status != VL53L0_ERROR_NONE)
+ break;
+
+ Status = perform_ref_signal_measurement(Dev,
+ &peakSignalRateRef);
+
+ if (Status != VL53L0_ERROR_NONE)
+ break;
+
+ signalRateDiff = abs(peakSignalRateRef - targetRefRate);
+
+ if (peakSignalRateRef > targetRefRate) {
+ /* Select the spad map that provides the
+ * measurement closest to the target rate,
+ * either above or below it.
+ */
+ if (signalRateDiff > lastSignalRateDiff) {
+ /* Previous spad map produced a closer
+ * measurement, so choose this. */
+ Status = set_ref_spad_map(Dev,
+ lastSpadArray);
+ memcpy(
+ Dev->Data.SpadData.RefSpadEnables,
+ lastSpadArray, spadArraySize);
+
+ (refSpadCount_int)--;
+ }
+ complete = 1;
+ } else {
+ /* Continue to add spads */
+ lastSignalRateDiff = signalRateDiff;
+ memcpy(lastSpadArray,
+ Dev->Data.SpadData.RefSpadEnables,
+ spadArraySize);
+ }
+
+ } /* while */
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ *refSpadCount = refSpadCount_int;
+ *isApertureSpads = isApertureSpads_int;
+
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev, RefSpadsInitialised, 1);
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ ReferenceSpadCount, (uint8_t)(*refSpadCount));
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ ReferenceSpadType, *isApertureSpads);
+ }
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_set_reference_spads(VL53L0_DEV Dev,
+ uint32_t count, uint8_t isApertureSpads)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint32_t currentSpadIndex = 0;
+ uint8_t startSelect = 0xB4;
+ uint32_t spadArraySize = 6;
+ uint32_t maxSpadCount = 44;
+ uint32_t lastSpadIndex;
+ uint32_t index;
+
+ /*
+ * This function applies a requested number of reference spads, either
+ * aperture or
+ * non-aperture, as requested.
+ * The good spad map will be applied.
+ */
+
+ Status = VL53L0_WrByte(Dev, 0xFF, 0x01);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_DYNAMIC_SPAD_REF_EN_START_OFFSET, 0x00);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD, 0x2C);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_GLOBAL_CONFIG_REF_EN_START_SELECT,
+ startSelect);
+
+ for (index = 0; index < spadArraySize; index++) {
+ Dev->Data.SpadData.RefSpadEnables[index] = 0;
+ }
+
+ if (isApertureSpads) {
+ /* Increment to the first APERTURE spad */
+ while ((is_aperture(startSelect + currentSpadIndex) == 0) &&
+ (currentSpadIndex < maxSpadCount)) {
+ currentSpadIndex++;
+ }
+ }
+ Status = enable_ref_spads(Dev,
+ isApertureSpads,
+ Dev->Data.SpadData.RefGoodSpadMap,
+ Dev->Data.SpadData.RefSpadEnables,
+ spadArraySize,
+ startSelect,
+ currentSpadIndex,
+ count,
+ &lastSpadIndex);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev, RefSpadsInitialised, 1);
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ ReferenceSpadCount, (uint8_t)(count));
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ ReferenceSpadType, isApertureSpads);
+ }
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_get_reference_spads(VL53L0_DEV Dev,
+ uint32_t *pSpadCount, uint8_t *pIsApertureSpads)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t refSpadsInitialised;
+ uint8_t refSpadArray[6];
+ uint32_t cMaxSpadCount = 44;
+ uint32_t cSpadArraySize = 6;
+ uint32_t spadsEnabled;
+ uint8_t isApertureSpads = 0;
+
+ refSpadsInitialised = VL53L0_GETDEVICESPECIFICPARAMETER(Dev,
+ RefSpadsInitialised);
+
+ if (refSpadsInitialised == 1) {
+
+ *pSpadCount = (uint32_t)VL53L0_GETDEVICESPECIFICPARAMETER(Dev,
+ ReferenceSpadCount);
+ *pIsApertureSpads = VL53L0_GETDEVICESPECIFICPARAMETER(Dev,
+ ReferenceSpadType);
+ } else {
+
+ /* obtain spad info from device.*/
+ Status = get_ref_spad_map(Dev, refSpadArray);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* count enabled spads within spad map array and
+ * determine if Aperture or Non-Aperture.
+ */
+ Status = count_enabled_spads(refSpadArray,
+ cSpadArraySize,
+ cMaxSpadCount,
+ &spadsEnabled,
+ &isApertureSpads);
+
+ if (Status == VL53L0_ERROR_NONE) {
+
+ *pSpadCount = spadsEnabled;
+ *pIsApertureSpads = isApertureSpads;
+
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ RefSpadsInitialised, 1);
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ ReferenceSpadCount,
+ (uint8_t)spadsEnabled);
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ ReferenceSpadType, isApertureSpads);
+ }
+ }
+ }
+
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_perform_single_ref_calibration(VL53L0_DEV Dev,
+ uint8_t vhv_init_byte)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSRANGE_START,
+ VL53L0_REG_SYSRANGE_MODE_START_STOP |
+ vhv_init_byte);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_measurement_poll_for_completion(Dev);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_ClearInterruptMask(Dev, 0);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSRANGE_START, 0x00);
+
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_ref_calibration_io(VL53L0_DEV Dev, uint8_t read_not_write,
+ uint8_t VhvSettings, uint8_t PhaseCal,
+ uint8_t *pVhvSettings, uint8_t *pPhaseCal,
+ const uint8_t vhv_enable, const uint8_t phase_enable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t PhaseCalint = 0;
+
+ /* Read VHV from device */
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ if (read_not_write) {
+ if (vhv_enable)
+ Status |= VL53L0_RdByte(Dev, 0xCB, pVhvSettings);
+ if (phase_enable)
+ Status |= VL53L0_RdByte(Dev, 0xEE, &PhaseCalint);
+ } else {
+ if (vhv_enable)
+ Status |= VL53L0_WrByte(Dev, 0xCB, VhvSettings);
+ if (phase_enable)
+ Status |= VL53L0_UpdateByte(Dev, 0xEE, 0x80, PhaseCal);
+ }
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ *pPhaseCal = (uint8_t)(PhaseCalint&0xEF);
+
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_perform_vhv_calibration(VL53L0_DEV Dev,
+ uint8_t *pVhvSettings, const uint8_t get_data_enable,
+ const uint8_t restore_config)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t SequenceConfig = 0;
+ uint8_t VhvSettings = 0;
+ uint8_t PhaseCal = 0;
+ uint8_t PhaseCalInt = 0;
+
+ /* store the value of the sequence config,
+ * this will be reset before the end of the function
+ */
+
+ if (restore_config)
+ SequenceConfig = PALDevDataGet(Dev, SequenceConfig);
+
+ /* Run VHV */
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSTEM_SEQUENCE_CONFIG, 0x01);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_perform_single_ref_calibration(Dev, 0x40);
+
+ /* Read VHV from device */
+ if ((Status == VL53L0_ERROR_NONE) && (get_data_enable == 1)) {
+ Status = VL53L0_ref_calibration_io(Dev, 1,
+ VhvSettings, PhaseCal, /* Not used here */
+ pVhvSettings, &PhaseCalInt,
+ 1, 0);
+ } else
+ *pVhvSettings = 0;
+
+
+ if ((Status == VL53L0_ERROR_NONE) && restore_config) {
+ /* restore the previous Sequence Config */
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSTEM_SEQUENCE_CONFIG,
+ SequenceConfig);
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, SequenceConfig, SequenceConfig);
+
+ }
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_perform_phase_calibration(VL53L0_DEV Dev,
+ uint8_t *pPhaseCal, const uint8_t get_data_enable,
+ const uint8_t restore_config)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t SequenceConfig = 0;
+ uint8_t VhvSettings = 0;
+ uint8_t PhaseCal = 0;
+ uint8_t VhvSettingsint;
+
+ /* store the value of the sequence config,
+ * this will be reset before the end of the function
+ */
+
+ if (restore_config)
+ SequenceConfig = PALDevDataGet(Dev, SequenceConfig);
+
+ /* Run PhaseCal */
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSTEM_SEQUENCE_CONFIG, 0x02);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_perform_single_ref_calibration(Dev, 0x0);
+
+ /* Read PhaseCal from device */
+ if ((Status == VL53L0_ERROR_NONE) && (get_data_enable == 1)) {
+ Status = VL53L0_ref_calibration_io(Dev, 1,
+ VhvSettings, PhaseCal, /* Not used here */
+ &VhvSettingsint, pPhaseCal,
+ 0, 1);
+ } else
+ *pPhaseCal = 0;
+
+
+ if ((Status == VL53L0_ERROR_NONE) && restore_config) {
+ /* restore the previous Sequence Config */
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSTEM_SEQUENCE_CONFIG,
+ SequenceConfig);
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, SequenceConfig, SequenceConfig);
+
+ }
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_perform_ref_calibration(VL53L0_DEV Dev,
+ uint8_t *pVhvSettings, uint8_t *pPhaseCal, uint8_t get_data_enable)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t SequenceConfig = 0;
+
+ /* store the value of the sequence config,
+ * this will be reset before the end of the function
+ */
+
+ SequenceConfig = PALDevDataGet(Dev, SequenceConfig);
+
+ /* In the following function we don't save the config to optimize
+ * writes on device. Config is saved and restored only once. */
+ Status = VL53L0_perform_vhv_calibration(
+ Dev, pVhvSettings, get_data_enable, 0);
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_perform_phase_calibration(
+ Dev, pPhaseCal, get_data_enable, 0);
+
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* restore the previous Sequence Config */
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSTEM_SEQUENCE_CONFIG,
+ SequenceConfig);
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, SequenceConfig, SequenceConfig);
+
+ }
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_set_ref_calibration(VL53L0_DEV Dev,
+ uint8_t VhvSettings, uint8_t PhaseCal)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t pVhvSettings;
+ uint8_t pPhaseCal;
+
+ Status = VL53L0_ref_calibration_io(Dev, 0,
+ VhvSettings, PhaseCal,
+ &pVhvSettings, &pPhaseCal,
+ 1, 1);
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_get_ref_calibration(VL53L0_DEV Dev,
+ uint8_t *pVhvSettings, uint8_t *pPhaseCal)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t VhvSettings = 0;
+ uint8_t PhaseCal = 0;
+
+ Status = VL53L0_ref_calibration_io(Dev, 1,
+ VhvSettings, PhaseCal,
+ pVhvSettings, pPhaseCal,
+ 1, 1);
+
+ return Status;
+}
diff --git a/drivers/input/misc/vl53L0/src/vl53l0_api_core.c b/drivers/input/misc/vl53L0/src/vl53l0_api_core.c
new file mode 100644
index 000000000000..ca3ec3e33bc3
--- /dev/null
+++ b/drivers/input/misc/vl53L0/src/vl53l0_api_core.c
@@ -0,0 +1,2234 @@
+/*******************************************************************************
+ Copyright © 2016, STMicroelectronics International N.V.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+ NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+ IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ******************************************************************************/
+
+#include "vl53l0_api.h"
+#include "vl53l0_api_core.h"
+#include "vl53l0_api_calibration.h"
+
+#ifndef __KERNEL__
+#include
+#endif
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(TRACE_MODULE_API, status, fmt, ##__VA_ARGS__)
+
+VL53L0_Error VL53L0_reverse_bytes(uint8_t *data, uint32_t size)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t tempData;
+ uint32_t mirrorIndex;
+ uint32_t middle = size/2;
+ uint32_t index;
+
+ for (index = 0; index < middle; index++) {
+ mirrorIndex = size - index - 1;
+ tempData = data[index];
+ data[index] = data[mirrorIndex];
+ data[mirrorIndex] = tempData;
+ }
+ return Status;
+}
+
+VL53L0_Error VL53L0_measurement_poll_for_completion(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t NewDataReady = 0;
+ uint32_t LoopNb;
+
+ LOG_FUNCTION_START("");
+
+ LoopNb = 0;
+
+ do {
+ Status = VL53L0_GetMeasurementDataReady(Dev, &NewDataReady);
+ if (Status != 0)
+ break; /* the error is set */
+
+ if (NewDataReady == 1)
+ break; /* done note that status == 0 */
+
+ LoopNb++;
+ if (LoopNb >= VL53L0_DEFAULT_MAX_LOOP) {
+ Status = VL53L0_ERROR_TIME_OUT;
+ break;
+ }
+
+ VL53L0_PollingDelay(Dev);
+ } while (1);
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+
+uint8_t VL53L0_decode_vcsel_period(uint8_t vcsel_period_reg)
+{
+ /*!
+ * Converts the encoded VCSEL period register value into the real
+ * period in PLL clocks
+ */
+
+ uint8_t vcsel_period_pclks = 0;
+
+ vcsel_period_pclks = (vcsel_period_reg + 1) << 1;
+
+ return vcsel_period_pclks;
+}
+
+uint8_t VL53L0_encode_vcsel_period(uint8_t vcsel_period_pclks)
+{
+ /*!
+ * Converts the encoded VCSEL period register value into the real period
+ * in PLL clocks
+ */
+
+ uint8_t vcsel_period_reg = 0;
+
+ vcsel_period_reg = (vcsel_period_pclks >> 1) - 1;
+
+ return vcsel_period_reg;
+}
+
+
+uint32_t VL53L0_isqrt(uint32_t num)
+{
+ /*
+ * Implements an integer square root
+ *
+ * From: http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
+ */
+
+ uint32_t res = 0;
+ uint32_t bit = 1 << 30;
+ /* The second-to-top bit is set:
+ * 1 << 14 for 16-bits, 1 << 30 for 32 bits */
+
+ /* "bit" starts at the highest power of four <= the argument. */
+ while (bit > num)
+ bit >>= 2;
+
+
+ while (bit != 0) {
+ if (num >= res + bit) {
+ num -= res + bit;
+ res = (res >> 1) + bit;
+ } else
+ res >>= 1;
+
+ bit >>= 2;
+ }
+
+ return res;
+}
+
+
+uint32_t VL53L0_quadrature_sum(uint32_t a, uint32_t b)
+{
+ /*
+ * Implements a quadrature sum
+ *
+ * rea = sqrt(a^2 + b^2)
+ *
+ * Trap overflow case max input value is 65535 (16-bit value)
+ * as internal calc are 32-bit wide
+ *
+ * If overflow then seta output to maximum
+ */
+ uint32_t res = 0;
+
+ if (a > 65535 || b > 65535)
+ res = 65535;
+ else
+ res = VL53L0_isqrt(a * a + b * b);
+
+ return res;
+}
+
+
+VL53L0_Error VL53L0_device_read_strobe(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t strobe;
+ uint32_t LoopNb;
+ LOG_FUNCTION_START("");
+
+ Status |= VL53L0_WrByte(Dev, 0x83, 0x00);
+
+ /* polling
+ * use timeout to avoid deadlock*/
+ if (Status == VL53L0_ERROR_NONE) {
+ LoopNb = 0;
+ do {
+ Status = VL53L0_RdByte(Dev, 0x83, &strobe);
+ if ((strobe != 0x00) || Status != VL53L0_ERROR_NONE)
+ break;
+
+ LoopNb = LoopNb + 1;
+ } while (LoopNb < VL53L0_DEFAULT_MAX_LOOP);
+
+ if (LoopNb >= VL53L0_DEFAULT_MAX_LOOP)
+ Status = VL53L0_ERROR_TIME_OUT;
+
+ }
+
+ Status |= VL53L0_WrByte(Dev, 0x83, 0x01);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+VL53L0_Error VL53L0_get_info_from_device(VL53L0_DEV Dev, uint8_t option)
+{
+
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t byte;
+ uint32_t TmpDWord;
+ uint8_t ModuleId;
+ uint8_t Revision;
+ uint8_t ReferenceSpadCount = 0;
+ uint8_t ReferenceSpadType = 0;
+ uint32_t PartUIDUpper = 0;
+ uint32_t PartUIDLower = 0;
+ uint32_t OffsetFixed1104_mm = 0;
+ int16_t OffsetMicroMeters = 0;
+ uint32_t DistMeasTgtFixed1104_mm = 400 << 4;
+ uint32_t DistMeasFixed1104_400_mm = 0;
+ uint32_t SignalRateMeasFixed1104_400_mm = 0;
+ char ProductId[19];
+ char *ProductId_tmp;
+ uint8_t ReadDataFromDeviceDone;
+ FixPoint1616_t SignalRateMeasFixed400mmFix = 0;
+ uint8_t NvmRefGoodSpadMap[VL53L0_REF_SPAD_BUFFER_SIZE];
+ int i;
+
+
+ LOG_FUNCTION_START("");
+
+ ReadDataFromDeviceDone = VL53L0_GETDEVICESPECIFICPARAMETER(Dev,
+ ReadDataFromDeviceDone);
+
+ /* This access is done only once after that a GetDeviceInfo or
+ * datainit is done*/
+ if (ReadDataFromDeviceDone != 7) {
+
+ Status |= VL53L0_WrByte(Dev, 0x80, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x06);
+ Status |= VL53L0_RdByte(Dev, 0x83, &byte);
+ Status |= VL53L0_WrByte(Dev, 0x83, byte|4);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x07);
+ Status |= VL53L0_WrByte(Dev, 0x81, 0x01);
+
+ Status |= VL53L0_PollingDelay(Dev);
+
+ Status |= VL53L0_WrByte(Dev, 0x80, 0x01);
+
+ if (((option & 1) == 1) &&
+ ((ReadDataFromDeviceDone & 1) == 0)) {
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x6b);
+ Status |= VL53L0_device_read_strobe(Dev);
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ ReferenceSpadCount = (uint8_t)((TmpDWord >> 8) & 0x07f);
+ ReferenceSpadType = (uint8_t)((TmpDWord >> 15) & 0x01);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x24);
+ Status |= VL53L0_device_read_strobe(Dev);
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+
+ NvmRefGoodSpadMap[0] = (uint8_t)((TmpDWord >> 24)
+ & 0xff);
+ NvmRefGoodSpadMap[1] = (uint8_t)((TmpDWord >> 16)
+ & 0xff);
+ NvmRefGoodSpadMap[2] = (uint8_t)((TmpDWord >> 8)
+ & 0xff);
+ NvmRefGoodSpadMap[3] = (uint8_t)(TmpDWord & 0xff);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x25);
+ Status |= VL53L0_device_read_strobe(Dev);
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ NvmRefGoodSpadMap[4] = (uint8_t)((TmpDWord >> 24)
+ & 0xff);
+ NvmRefGoodSpadMap[5] = (uint8_t)((TmpDWord >> 16)
+ & 0xff);
+ }
+
+ if (((option & 2) == 2) &&
+ ((ReadDataFromDeviceDone & 2) == 0)) {
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x02);
+ Status |= VL53L0_device_read_strobe(Dev);
+ Status |= VL53L0_RdByte(Dev, 0x90, &ModuleId);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x7B);
+ Status |= VL53L0_device_read_strobe(Dev);
+ Status |= VL53L0_RdByte(Dev, 0x90, &Revision);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x77);
+ Status |= VL53L0_device_read_strobe(Dev);
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ ProductId[0] = (char)((TmpDWord >> 25) & 0x07f);
+ ProductId[1] = (char)((TmpDWord >> 18) & 0x07f);
+ ProductId[2] = (char)((TmpDWord >> 11) & 0x07f);
+ ProductId[3] = (char)((TmpDWord >> 4) & 0x07f);
+
+ byte = (uint8_t)((TmpDWord & 0x00f) << 3);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x78);
+ Status |= VL53L0_device_read_strobe(Dev);
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ ProductId[4] = (char)(byte +
+ ((TmpDWord >> 29) & 0x07f));
+ ProductId[5] = (char)((TmpDWord >> 22) & 0x07f);
+ ProductId[6] = (char)((TmpDWord >> 15) & 0x07f);
+ ProductId[7] = (char)((TmpDWord >> 8) & 0x07f);
+ ProductId[8] = (char)((TmpDWord >> 1) & 0x07f);
+
+ byte = (uint8_t)((TmpDWord & 0x001) << 6);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x79);
+
+ Status |= VL53L0_device_read_strobe(Dev);
+
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ ProductId[9] = (char)(byte +
+ ((TmpDWord >> 26) & 0x07f));
+ ProductId[10] = (char)((TmpDWord >> 19) & 0x07f);
+ ProductId[11] = (char)((TmpDWord >> 12) & 0x07f);
+ ProductId[12] = (char)((TmpDWord >> 5) & 0x07f);
+
+ byte = (uint8_t)((TmpDWord & 0x01f) << 2);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x7A);
+
+ Status |= VL53L0_device_read_strobe(Dev);
+
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ ProductId[13] = (char)(byte +
+ ((TmpDWord >> 30) & 0x07f));
+ ProductId[14] = (char)((TmpDWord >> 23) & 0x07f);
+ ProductId[15] = (char)((TmpDWord >> 16) & 0x07f);
+ ProductId[16] = (char)((TmpDWord >> 9) & 0x07f);
+ ProductId[17] = (char)((TmpDWord >> 2) & 0x07f);
+ ProductId[18] = '\0';
+
+ }
+
+ if (((option & 4) == 4) &&
+ ((ReadDataFromDeviceDone & 4) == 0)) {
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x7B);
+ Status |= VL53L0_device_read_strobe(Dev);
+ Status |= VL53L0_RdDWord(Dev, 0x90, &PartUIDUpper);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x7C);
+ Status |= VL53L0_device_read_strobe(Dev);
+ Status |= VL53L0_RdDWord(Dev, 0x90, &PartUIDLower);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x73);
+ Status |= VL53L0_device_read_strobe(Dev);
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ SignalRateMeasFixed1104_400_mm = (TmpDWord &
+ 0x0000000ff) << 8;
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x74);
+ Status |= VL53L0_device_read_strobe(Dev);
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ SignalRateMeasFixed1104_400_mm |= ((TmpDWord &
+ 0xff000000) >> 24);
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x75);
+ Status |= VL53L0_device_read_strobe(Dev);
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ DistMeasFixed1104_400_mm = (TmpDWord & 0x0000000ff)
+ << 8;
+
+ Status |= VL53L0_WrByte(Dev, 0x94, 0x76);
+ Status |= VL53L0_device_read_strobe(Dev);
+ Status |= VL53L0_RdDWord(Dev, 0x90, &TmpDWord);
+
+ DistMeasFixed1104_400_mm |= ((TmpDWord & 0xff000000)
+ >> 24);
+ }
+
+ Status |= VL53L0_WrByte(Dev, 0x81, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x06);
+ Status |= VL53L0_RdByte(Dev, 0x83, &byte);
+ Status |= VL53L0_WrByte(Dev, 0x83, byte&0xfb);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x01);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x80, 0x00);
+ }
+
+ if ((Status == VL53L0_ERROR_NONE) &&
+ (ReadDataFromDeviceDone != 7)) {
+ /* Assign to variable if status is ok */
+ if (((option & 1) == 1) &&
+ ((ReadDataFromDeviceDone & 1) == 0)) {
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ ReferenceSpadCount, ReferenceSpadCount);
+
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ ReferenceSpadType, ReferenceSpadType);
+
+ for(i = 0; i < VL53L0_REF_SPAD_BUFFER_SIZE; i++){
+ Dev->Data.SpadData.RefGoodSpadMap[i] =
+ NvmRefGoodSpadMap[i];
+ }
+ }
+
+ if (((option & 2) == 2) &&
+ ((ReadDataFromDeviceDone & 2) == 0)) {
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ ModuleId, ModuleId);
+
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ Revision, Revision);
+
+ ProductId_tmp = VL53L0_GETDEVICESPECIFICPARAMETER(Dev,
+ ProductId);
+ VL53L0_COPYSTRING(ProductId_tmp, ProductId);
+
+ }
+
+ if (((option & 4) == 4) &&
+ ((ReadDataFromDeviceDone & 4) == 0)) {
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ PartUIDUpper, PartUIDUpper);
+
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ PartUIDLower, PartUIDLower);
+
+ SignalRateMeasFixed400mmFix =
+ VL53L0_FIXPOINT97TOFIXPOINT1616(
+ SignalRateMeasFixed1104_400_mm);
+
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ SignalRateMeasFixed400mm,
+ SignalRateMeasFixed400mmFix);
+
+ OffsetMicroMeters = 0;
+ if (DistMeasFixed1104_400_mm != 0) {
+ OffsetFixed1104_mm =
+ DistMeasFixed1104_400_mm -
+ DistMeasTgtFixed1104_mm;
+ OffsetMicroMeters = (OffsetFixed1104_mm
+ * 1000) >> 4;
+ OffsetMicroMeters *= -1;
+ }
+
+ PALDevDataSet(Dev,
+ Part2PartOffsetAdjustmentNVMMicroMeter,
+ OffsetMicroMeters);
+ }
+ byte = (uint8_t)(ReadDataFromDeviceDone|option);
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev, ReadDataFromDeviceDone,
+ byte);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+uint32_t VL53L0_calc_macro_period_ps(VL53L0_DEV Dev, uint8_t vcsel_period_pclks)
+{
+ uint64_t PLL_period_ps;
+ uint32_t macro_period_vclks;
+ uint32_t macro_period_ps;
+
+ LOG_FUNCTION_START("");
+
+ /* The above calculation will produce rounding errors,
+ therefore set fixed value
+ */
+ PLL_period_ps = 1655;
+
+ macro_period_vclks = 2304;
+ macro_period_ps = (uint32_t)(macro_period_vclks
+ * vcsel_period_pclks * PLL_period_ps);
+
+ LOG_FUNCTION_END("");
+ return macro_period_ps;
+}
+
+uint16_t VL53L0_encode_timeout(uint32_t timeout_macro_clks)
+{
+ /*!
+ * Encode timeout in macro periods in (LSByte * 2^MSByte) + 1 format
+ */
+
+ uint16_t encoded_timeout = 0;
+ uint32_t ls_byte = 0;
+ uint16_t ms_byte = 0;
+
+ if (timeout_macro_clks > 0) {
+ ls_byte = timeout_macro_clks - 1;
+
+ while ((ls_byte & 0xFFFFFF00) > 0) {
+ ls_byte = ls_byte >> 1;
+ ms_byte++;
+ }
+
+ encoded_timeout = (ms_byte << 8)
+ + (uint16_t) (ls_byte & 0x000000FF);
+ }
+
+ return encoded_timeout;
+
+}
+
+uint32_t VL53L0_decode_timeout(uint16_t encoded_timeout)
+{
+ /*!
+ * Decode 16-bit timeout register value - format (LSByte * 2^MSByte) + 1
+ */
+
+ uint32_t timeout_macro_clks = 0;
+
+ timeout_macro_clks = ((uint32_t) (encoded_timeout & 0x00FF)
+ << (uint32_t) ((encoded_timeout & 0xFF00) >> 8)) + 1;
+
+ return timeout_macro_clks;
+}
+
+
+/* To convert ms into register value */
+uint32_t VL53L0_calc_timeout_mclks(VL53L0_DEV Dev,
+ uint32_t timeout_period_us,
+ uint8_t vcsel_period_pclks)
+{
+ uint32_t macro_period_ps;
+ uint32_t macro_period_ns;
+ uint32_t timeout_period_mclks = 0;
+
+ macro_period_ps = VL53L0_calc_macro_period_ps(Dev, vcsel_period_pclks);
+ macro_period_ns = (macro_period_ps + 500) / 1000;
+
+ timeout_period_mclks =
+ (uint32_t) (((timeout_period_us * 1000)
+ + (macro_period_ns / 2)) / macro_period_ns);
+
+ return timeout_period_mclks;
+}
+
+/* To convert register value into us */
+uint32_t VL53L0_calc_timeout_us(VL53L0_DEV Dev,
+ uint16_t timeout_period_mclks,
+ uint8_t vcsel_period_pclks)
+{
+ uint32_t macro_period_ps;
+ uint32_t macro_period_ns;
+ uint32_t actual_timeout_period_us = 0;
+
+ macro_period_ps = VL53L0_calc_macro_period_ps(Dev, vcsel_period_pclks);
+ macro_period_ns = (macro_period_ps + 500) / 1000;
+
+ actual_timeout_period_us =
+ ((timeout_period_mclks * macro_period_ns)
+ + (macro_period_ns / 2)) / 1000;
+
+ return actual_timeout_period_us;
+}
+
+
+VL53L0_Error get_sequence_step_timeout(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId,
+ uint32_t *pTimeOutMicroSecs)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t CurrentVCSELPulsePeriodPClk;
+ uint8_t EncodedTimeOutByte = 0;
+ uint32_t TimeoutMicroSeconds = 0;
+ uint16_t PreRangeEncodedTimeOut = 0;
+ uint16_t MsrcTimeOutMClks;
+ uint16_t PreRangeTimeOutMClks;
+ uint16_t FinalRangeTimeOutMClks = 0;
+ uint16_t FinalRangeEncodedTimeOut;
+ VL53L0_SchedulerSequenceSteps_t SchedulerSequenceSteps;
+
+ if ((SequenceStepId == VL53L0_SEQUENCESTEP_TCC) ||
+ (SequenceStepId == VL53L0_SEQUENCESTEP_DSS) ||
+ (SequenceStepId == VL53L0_SEQUENCESTEP_MSRC)) {
+
+ Status = VL53L0_GetVcselPulsePeriod(Dev,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE,
+ &CurrentVCSELPulsePeriodPClk);
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdByte(Dev,
+ VL53L0_REG_MSRC_CONFIG_TIMEOUT_MACROP,
+ &EncodedTimeOutByte);
+ }
+ MsrcTimeOutMClks = VL53L0_decode_timeout(EncodedTimeOutByte);
+
+ TimeoutMicroSeconds = VL53L0_calc_timeout_us(Dev,
+ MsrcTimeOutMClks,
+ CurrentVCSELPulsePeriodPClk);
+ } else if (SequenceStepId == VL53L0_SEQUENCESTEP_PRE_RANGE) {
+ /* Retrieve PRE-RANGE VCSEL Period */
+ Status = VL53L0_GetVcselPulsePeriod(Dev,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE,
+ &CurrentVCSELPulsePeriodPClk);
+
+ /* Retrieve PRE-RANGE Timeout in Macro periods (MCLKS) */
+ if (Status == VL53L0_ERROR_NONE) {
+
+ /* Retrieve PRE-RANGE VCSEL Period */
+ Status = VL53L0_GetVcselPulsePeriod(Dev,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE,
+ &CurrentVCSELPulsePeriodPClk);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdWord(Dev,
+ VL53L0_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,
+ &PreRangeEncodedTimeOut);
+ }
+
+ PreRangeTimeOutMClks = VL53L0_decode_timeout(
+ PreRangeEncodedTimeOut);
+
+ TimeoutMicroSeconds = VL53L0_calc_timeout_us(Dev,
+ PreRangeTimeOutMClks,
+ CurrentVCSELPulsePeriodPClk);
+ }
+ } else if (SequenceStepId == VL53L0_SEQUENCESTEP_FINAL_RANGE) {
+
+ VL53L0_GetSequenceStepEnables(Dev, &SchedulerSequenceSteps);
+ PreRangeTimeOutMClks = 0;
+
+ if (SchedulerSequenceSteps.PreRangeOn) {
+ /* Retrieve PRE-RANGE VCSEL Period */
+ Status = VL53L0_GetVcselPulsePeriod(Dev,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE,
+ &CurrentVCSELPulsePeriodPClk);
+
+ /* Retrieve PRE-RANGE Timeout in Macro periods
+ * (MCLKS) */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdWord(Dev,
+ VL53L0_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,
+ &PreRangeEncodedTimeOut);
+ PreRangeTimeOutMClks = VL53L0_decode_timeout(
+ PreRangeEncodedTimeOut);
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Retrieve FINAL-RANGE VCSEL Period */
+ Status = VL53L0_GetVcselPulsePeriod(Dev,
+ VL53L0_VCSEL_PERIOD_FINAL_RANGE,
+ &CurrentVCSELPulsePeriodPClk);
+ }
+
+ /* Retrieve FINAL-RANGE Timeout in Macro periods (MCLKS) */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdWord(Dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI,
+ &FinalRangeEncodedTimeOut);
+ FinalRangeTimeOutMClks = VL53L0_decode_timeout(
+ FinalRangeEncodedTimeOut);
+ }
+
+ FinalRangeTimeOutMClks -= PreRangeTimeOutMClks;
+ TimeoutMicroSeconds = VL53L0_calc_timeout_us(Dev,
+ FinalRangeTimeOutMClks,
+ CurrentVCSELPulsePeriodPClk);
+ }
+
+ *pTimeOutMicroSecs = TimeoutMicroSeconds;
+
+ return Status;
+}
+
+
+VL53L0_Error set_sequence_step_timeout(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId,
+ uint32_t TimeOutMicroSecs)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t CurrentVCSELPulsePeriodPClk;
+ uint8_t MsrcEncodedTimeOut;
+ uint16_t PreRangeEncodedTimeOut;
+ uint16_t PreRangeTimeOutMClks;
+ uint16_t MsrcRangeTimeOutMClks;
+ uint16_t FinalRangeTimeOutMClks;
+ uint16_t FinalRangeEncodedTimeOut;
+ VL53L0_SchedulerSequenceSteps_t SchedulerSequenceSteps;
+
+ if ((SequenceStepId == VL53L0_SEQUENCESTEP_TCC) ||
+ (SequenceStepId == VL53L0_SEQUENCESTEP_DSS) ||
+ (SequenceStepId == VL53L0_SEQUENCESTEP_MSRC)) {
+
+ Status = VL53L0_GetVcselPulsePeriod(Dev,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE,
+ &CurrentVCSELPulsePeriodPClk);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ MsrcRangeTimeOutMClks = VL53L0_calc_timeout_mclks(Dev,
+ TimeOutMicroSecs,
+ (uint8_t)CurrentVCSELPulsePeriodPClk);
+
+ if (MsrcRangeTimeOutMClks > 256)
+ MsrcEncodedTimeOut = 255;
+ else
+ MsrcEncodedTimeOut =
+ (uint8_t)MsrcRangeTimeOutMClks - 1;
+
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ LastEncodedTimeout,
+ MsrcEncodedTimeOut);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_MSRC_CONFIG_TIMEOUT_MACROP,
+ MsrcEncodedTimeOut);
+ }
+ } else {
+
+ if (SequenceStepId == VL53L0_SEQUENCESTEP_PRE_RANGE) {
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_GetVcselPulsePeriod(Dev,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE,
+ &CurrentVCSELPulsePeriodPClk);
+ PreRangeTimeOutMClks =
+ VL53L0_calc_timeout_mclks(Dev,
+ TimeOutMicroSecs,
+ (uint8_t)CurrentVCSELPulsePeriodPClk);
+ PreRangeEncodedTimeOut = VL53L0_encode_timeout(
+ PreRangeTimeOutMClks);
+
+ VL53L0_SETDEVICESPECIFICPARAMETER(Dev,
+ LastEncodedTimeout,
+ PreRangeEncodedTimeOut);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_WrWord(Dev,
+ VL53L0_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,
+ PreRangeEncodedTimeOut);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETDEVICESPECIFICPARAMETER(
+ Dev,
+ PreRangeTimeoutMicroSecs,
+ TimeOutMicroSecs);
+ }
+ } else if (SequenceStepId == VL53L0_SEQUENCESTEP_FINAL_RANGE) {
+
+ /* For the final range timeout, the pre-range timeout
+ * must be added. To do this both final and pre-range
+ * timeouts must be expressed in macro periods MClks
+ * because they have different vcsel periods.
+ */
+
+ VL53L0_GetSequenceStepEnables(Dev,
+ &SchedulerSequenceSteps);
+ PreRangeTimeOutMClks = 0;
+ if (SchedulerSequenceSteps.PreRangeOn) {
+
+ /* Retrieve PRE-RANGE VCSEL Period */
+ Status = VL53L0_GetVcselPulsePeriod(Dev,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE,
+ &CurrentVCSELPulsePeriodPClk);
+
+ /* Retrieve PRE-RANGE Timeout in Macro periods
+ * (MCLKS) */
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdWord(Dev, 0x51,
+ &PreRangeEncodedTimeOut);
+ PreRangeTimeOutMClks =
+ VL53L0_decode_timeout(
+ PreRangeEncodedTimeOut);
+ }
+ }
+
+ /* Calculate FINAL RANGE Timeout in Macro Periods
+ * (MCLKS) and add PRE-RANGE value
+ */
+ if (Status == VL53L0_ERROR_NONE) {
+
+ Status = VL53L0_GetVcselPulsePeriod(Dev,
+ VL53L0_VCSEL_PERIOD_FINAL_RANGE,
+ &CurrentVCSELPulsePeriodPClk);
+ }
+ if (Status == VL53L0_ERROR_NONE) {
+
+ FinalRangeTimeOutMClks =
+ VL53L0_calc_timeout_mclks(Dev,
+ TimeOutMicroSecs,
+ (uint8_t) CurrentVCSELPulsePeriodPClk);
+
+ FinalRangeTimeOutMClks += PreRangeTimeOutMClks;
+
+ FinalRangeEncodedTimeOut =
+ VL53L0_encode_timeout(FinalRangeTimeOutMClks);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_WrWord(Dev, 0x71,
+ FinalRangeEncodedTimeOut);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETDEVICESPECIFICPARAMETER(
+ Dev,
+ FinalRangeTimeoutMicroSecs,
+ TimeOutMicroSecs);
+ }
+ }
+ } else
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+
+ }
+ return Status;
+}
+
+VL53L0_Error VL53L0_set_vcsel_pulse_period(VL53L0_DEV Dev,
+ VL53L0_VcselPeriod VcselPeriodType, uint8_t VCSELPulsePeriodPCLK)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t vcsel_period_reg;
+ uint8_t MinPreVcselPeriodPCLK = 12;
+ uint8_t MaxPreVcselPeriodPCLK = 18;
+ uint8_t MinFinalVcselPeriodPCLK = 8;
+ uint8_t MaxFinalVcselPeriodPCLK = 14;
+ uint32_t MeasurementTimingBudgetMicroSeconds;
+ uint32_t FinalRangeTimeoutMicroSeconds;
+ uint32_t PreRangeTimeoutMicroSeconds;
+ uint32_t MsrcTimeoutMicroSeconds;
+ uint8_t PhaseCalInt = 0;
+
+ /* Check if valid clock period requested */
+
+ if ((VCSELPulsePeriodPCLK % 2) != 0) {
+ /* Value must be an even number */
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ } else if (VcselPeriodType == VL53L0_VCSEL_PERIOD_PRE_RANGE &&
+ (VCSELPulsePeriodPCLK < MinPreVcselPeriodPCLK ||
+ VCSELPulsePeriodPCLK > MaxPreVcselPeriodPCLK)) {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ } else if (VcselPeriodType == VL53L0_VCSEL_PERIOD_FINAL_RANGE &&
+ (VCSELPulsePeriodPCLK < MinFinalVcselPeriodPCLK ||
+ VCSELPulsePeriodPCLK > MaxFinalVcselPeriodPCLK)) {
+
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+
+ /* Apply specific settings for the requested clock period */
+
+ if (Status != VL53L0_ERROR_NONE)
+ return Status;
+
+
+ if (VcselPeriodType == VL53L0_VCSEL_PERIOD_PRE_RANGE) {
+
+ /* Set phase check limits */
+ if (VCSELPulsePeriodPCLK == 12) {
+
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x18);
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+ } else if (VCSELPulsePeriodPCLK == 14) {
+
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x30);
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+ } else if (VCSELPulsePeriodPCLK == 16) {
+
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x40);
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+ } else if (VCSELPulsePeriodPCLK == 18) {
+
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x50);
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+ }
+ } else if (VcselPeriodType == VL53L0_VCSEL_PERIOD_FINAL_RANGE) {
+
+ if (VCSELPulsePeriodPCLK == 8) {
+
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x10);
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+
+ Status |= VL53L0_WrByte(Dev,
+ VL53L0_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x02);
+ Status |= VL53L0_WrByte(Dev,
+ VL53L0_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x0C);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x01);
+ Status |= VL53L0_WrByte(Dev,
+ VL53L0_REG_ALGO_PHASECAL_LIM,
+ 0x30);
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x00);
+ } else if (VCSELPulsePeriodPCLK == 10) {
+
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x28);
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+
+ Status |= VL53L0_WrByte(Dev,
+ VL53L0_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x03);
+ Status |= VL53L0_WrByte(Dev,
+ VL53L0_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x09);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x01);
+ Status |= VL53L0_WrByte(Dev,
+ VL53L0_REG_ALGO_PHASECAL_LIM,
+ 0x20);
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x00);
+ } else if (VCSELPulsePeriodPCLK == 12) {
+
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x38);
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+
+ Status |= VL53L0_WrByte(Dev,
+ VL53L0_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x03);
+ Status |= VL53L0_WrByte(Dev,
+ VL53L0_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x08);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x01);
+ Status |= VL53L0_WrByte(Dev,
+ VL53L0_REG_ALGO_PHASECAL_LIM,
+ 0x20);
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x00);
+ } else if (VCSELPulsePeriodPCLK == 14) {
+
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x048);
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+
+ Status |= VL53L0_WrByte(Dev,
+ VL53L0_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x03);
+ Status |= VL53L0_WrByte(Dev,
+ VL53L0_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x07);
+
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x01);
+ Status |= VL53L0_WrByte(Dev,
+ VL53L0_REG_ALGO_PHASECAL_LIM,
+ 0x20);
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x00);
+ }
+ }
+
+
+ /* Re-calculate and apply timeouts, in macro periods */
+
+ if (Status == VL53L0_ERROR_NONE) {
+ vcsel_period_reg = VL53L0_encode_vcsel_period((uint8_t)
+ VCSELPulsePeriodPCLK);
+
+ /* When the VCSEL period for the pre or final range is changed,
+ * the corresponding timeout must be read from the device using
+ * the current VCSEL period, then the new VCSEL period can be
+ * applied. The timeout then must be written back to the device
+ * using the new VCSEL period.
+ *
+ * For the MSRC timeout, the same applies - this timeout being
+ * dependant on the pre-range vcsel period.
+ */
+ switch (VcselPeriodType) {
+ case VL53L0_VCSEL_PERIOD_PRE_RANGE:
+ Status = get_sequence_step_timeout(Dev,
+ VL53L0_SEQUENCESTEP_PRE_RANGE,
+ &PreRangeTimeoutMicroSeconds);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = get_sequence_step_timeout(Dev,
+ VL53L0_SEQUENCESTEP_MSRC,
+ &MsrcTimeoutMicroSeconds);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_PRE_RANGE_CONFIG_VCSEL_PERIOD,
+ vcsel_period_reg);
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = set_sequence_step_timeout(Dev,
+ VL53L0_SEQUENCESTEP_PRE_RANGE,
+ PreRangeTimeoutMicroSeconds);
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = set_sequence_step_timeout(Dev,
+ VL53L0_SEQUENCESTEP_MSRC,
+ MsrcTimeoutMicroSeconds);
+
+ VL53L0_SETDEVICESPECIFICPARAMETER(
+ Dev,
+ PreRangeVcselPulsePeriod,
+ VCSELPulsePeriodPCLK);
+ break;
+ case VL53L0_VCSEL_PERIOD_FINAL_RANGE:
+ Status = get_sequence_step_timeout(Dev,
+ VL53L0_SEQUENCESTEP_FINAL_RANGE,
+ &FinalRangeTimeoutMicroSeconds);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD,
+ vcsel_period_reg);
+
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = set_sequence_step_timeout(Dev,
+ VL53L0_SEQUENCESTEP_FINAL_RANGE,
+ FinalRangeTimeoutMicroSeconds);
+
+ VL53L0_SETDEVICESPECIFICPARAMETER(
+ Dev,
+ FinalRangeVcselPulsePeriod,
+ VCSELPulsePeriodPCLK);
+ break;
+ default:
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+ }
+
+ /* Finally, the timing budget must be re-applied */
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_GETPARAMETERFIELD(Dev,
+ MeasurementTimingBudgetMicroSeconds,
+ MeasurementTimingBudgetMicroSeconds);
+
+ Status = VL53L0_SetMeasurementTimingBudgetMicroSeconds(Dev,
+ MeasurementTimingBudgetMicroSeconds);
+ }
+
+ /* Perform the phase calibration. This is needed after changing on
+ * vcsel period.
+ * get_data_enable = 0, restore_config = 1 */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_perform_phase_calibration(
+ Dev, &PhaseCalInt, 0, 1);
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_get_vcsel_pulse_period(VL53L0_DEV Dev,
+ VL53L0_VcselPeriod VcselPeriodType, uint8_t *pVCSELPulsePeriodPCLK)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t vcsel_period_reg;
+
+ switch (VcselPeriodType) {
+ case VL53L0_VCSEL_PERIOD_PRE_RANGE:
+ Status = VL53L0_RdByte(Dev,
+ VL53L0_REG_PRE_RANGE_CONFIG_VCSEL_PERIOD,
+ &vcsel_period_reg);
+ break;
+ case VL53L0_VCSEL_PERIOD_FINAL_RANGE:
+ Status = VL53L0_RdByte(Dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD,
+ &vcsel_period_reg);
+ break;
+ default:
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ *pVCSELPulsePeriodPCLK =
+ VL53L0_decode_vcsel_period(vcsel_period_reg);
+
+ return Status;
+}
+
+
+
+VL53L0_Error VL53L0_set_measurement_timing_budget_micro_seconds(VL53L0_DEV Dev,
+ uint32_t MeasurementTimingBudgetMicroSeconds)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint32_t FinalRangeTimingBudgetMicroSeconds;
+ VL53L0_SchedulerSequenceSteps_t SchedulerSequenceSteps;
+ uint32_t MsrcDccTccTimeoutMicroSeconds = 2000;
+ uint32_t StartOverheadMicroSeconds = 1320;
+ uint32_t EndOverheadMicroSeconds = 960;
+ uint32_t MsrcOverheadMicroSeconds = 660;
+ uint32_t TccOverheadMicroSeconds = 590;
+ uint32_t DssOverheadMicroSeconds = 690;
+ uint32_t PreRangeOverheadMicroSeconds = 660;
+ uint32_t FinalRangeOverheadMicroSeconds = 550;
+ uint32_t PreRangeTimeoutMicroSeconds = 0;
+ uint32_t cMinTimingBudgetMicroSeconds = 20000;
+ uint32_t SubTimeout = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (MeasurementTimingBudgetMicroSeconds
+ < cMinTimingBudgetMicroSeconds) {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ return Status;
+ }
+
+ FinalRangeTimingBudgetMicroSeconds =
+ MeasurementTimingBudgetMicroSeconds -
+ (StartOverheadMicroSeconds + EndOverheadMicroSeconds);
+
+ Status = VL53L0_GetSequenceStepEnables(Dev, &SchedulerSequenceSteps);
+
+ if (Status == VL53L0_ERROR_NONE &&
+ (SchedulerSequenceSteps.TccOn ||
+ SchedulerSequenceSteps.MsrcOn ||
+ SchedulerSequenceSteps.DssOn)) {
+
+ /* TCC, MSRC and DSS all share the same timeout */
+ Status = get_sequence_step_timeout(Dev,
+ VL53L0_SEQUENCESTEP_MSRC,
+ &MsrcDccTccTimeoutMicroSeconds);
+
+ /* Subtract the TCC, MSRC and DSS timeouts if they are
+ * enabled. */
+
+ if (Status != VL53L0_ERROR_NONE)
+ return Status;
+
+ /* TCC */
+ if (SchedulerSequenceSteps.TccOn) {
+
+ SubTimeout = MsrcDccTccTimeoutMicroSeconds
+ + TccOverheadMicroSeconds;
+
+ if (SubTimeout <
+ FinalRangeTimingBudgetMicroSeconds) {
+ FinalRangeTimingBudgetMicroSeconds -=
+ SubTimeout;
+ } else {
+ /* Requested timeout too big. */
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+ }
+
+ if (Status != VL53L0_ERROR_NONE) {
+ LOG_FUNCTION_END(Status);
+ return Status;
+ }
+
+ /* DSS */
+ if (SchedulerSequenceSteps.DssOn) {
+
+ SubTimeout = 2 * (MsrcDccTccTimeoutMicroSeconds +
+ DssOverheadMicroSeconds);
+
+ if (SubTimeout < FinalRangeTimingBudgetMicroSeconds) {
+ FinalRangeTimingBudgetMicroSeconds
+ -= SubTimeout;
+ } else {
+ /* Requested timeout too big. */
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+ } else if (SchedulerSequenceSteps.MsrcOn) {
+ /* MSRC */
+ SubTimeout = MsrcDccTccTimeoutMicroSeconds +
+ MsrcOverheadMicroSeconds;
+
+ if (SubTimeout < FinalRangeTimingBudgetMicroSeconds) {
+ FinalRangeTimingBudgetMicroSeconds
+ -= SubTimeout;
+ } else {
+ /* Requested timeout too big. */
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+ }
+
+ }
+
+ if (Status != VL53L0_ERROR_NONE) {
+ LOG_FUNCTION_END(Status);
+ return Status;
+ }
+
+ if (SchedulerSequenceSteps.PreRangeOn) {
+
+ /* Subtract the Pre-range timeout if enabled. */
+
+ Status = get_sequence_step_timeout(Dev,
+ VL53L0_SEQUENCESTEP_PRE_RANGE,
+ &PreRangeTimeoutMicroSeconds);
+
+ SubTimeout = PreRangeTimeoutMicroSeconds +
+ PreRangeOverheadMicroSeconds;
+
+ if (SubTimeout < FinalRangeTimingBudgetMicroSeconds) {
+ FinalRangeTimingBudgetMicroSeconds -= SubTimeout;
+ } else {
+ /* Requested timeout too big. */
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+ }
+
+
+ if (Status == VL53L0_ERROR_NONE &&
+ SchedulerSequenceSteps.FinalRangeOn) {
+
+ FinalRangeTimingBudgetMicroSeconds -=
+ FinalRangeOverheadMicroSeconds;
+
+ /* Final Range Timeout
+ * Note that the final range timeout is determined by the timing
+ * budget and the sum of all other timeouts within the sequence.
+ * If there is no room for the final range timeout, then an error
+ * will be set. Otherwise the remaining time will be applied to
+ * the final range.
+ */
+ Status = set_sequence_step_timeout(Dev,
+ VL53L0_SEQUENCESTEP_FINAL_RANGE,
+ FinalRangeTimingBudgetMicroSeconds);
+
+ VL53L0_SETPARAMETERFIELD(Dev,
+ MeasurementTimingBudgetMicroSeconds,
+ MeasurementTimingBudgetMicroSeconds);
+ }
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_get_measurement_timing_budget_micro_seconds(VL53L0_DEV Dev,
+ uint32_t *pMeasurementTimingBudgetMicroSeconds)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_SchedulerSequenceSteps_t SchedulerSequenceSteps;
+ uint32_t FinalRangeTimeoutMicroSeconds;
+ uint32_t MsrcDccTccTimeoutMicroSeconds = 2000;
+ uint32_t StartOverheadMicroSeconds = 1910;
+ uint32_t EndOverheadMicroSeconds = 960;
+ uint32_t MsrcOverheadMicroSeconds = 660;
+ uint32_t TccOverheadMicroSeconds = 590;
+ uint32_t DssOverheadMicroSeconds = 690;
+ uint32_t PreRangeOverheadMicroSeconds = 660;
+ uint32_t FinalRangeOverheadMicroSeconds = 550;
+ uint32_t PreRangeTimeoutMicroSeconds = 0;
+
+ LOG_FUNCTION_START("");
+
+ /* Start and end overhead times always present */
+ *pMeasurementTimingBudgetMicroSeconds
+ = StartOverheadMicroSeconds + EndOverheadMicroSeconds;
+
+ Status = VL53L0_GetSequenceStepEnables(Dev, &SchedulerSequenceSteps);
+
+ if (Status != VL53L0_ERROR_NONE) {
+ LOG_FUNCTION_END(Status);
+ return Status;
+ }
+
+
+ if (SchedulerSequenceSteps.TccOn ||
+ SchedulerSequenceSteps.MsrcOn ||
+ SchedulerSequenceSteps.DssOn) {
+
+ Status = get_sequence_step_timeout(Dev,
+ VL53L0_SEQUENCESTEP_MSRC,
+ &MsrcDccTccTimeoutMicroSeconds);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (SchedulerSequenceSteps.TccOn) {
+ *pMeasurementTimingBudgetMicroSeconds +=
+ MsrcDccTccTimeoutMicroSeconds +
+ TccOverheadMicroSeconds;
+ }
+
+ if (SchedulerSequenceSteps.DssOn) {
+ *pMeasurementTimingBudgetMicroSeconds +=
+ 2 * (MsrcDccTccTimeoutMicroSeconds +
+ DssOverheadMicroSeconds);
+ } else if (SchedulerSequenceSteps.MsrcOn) {
+ *pMeasurementTimingBudgetMicroSeconds +=
+ MsrcDccTccTimeoutMicroSeconds +
+ MsrcOverheadMicroSeconds;
+ }
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (SchedulerSequenceSteps.PreRangeOn) {
+ Status = get_sequence_step_timeout(Dev,
+ VL53L0_SEQUENCESTEP_PRE_RANGE,
+ &PreRangeTimeoutMicroSeconds);
+ *pMeasurementTimingBudgetMicroSeconds +=
+ PreRangeTimeoutMicroSeconds +
+ PreRangeOverheadMicroSeconds;
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (SchedulerSequenceSteps.FinalRangeOn) {
+ Status = get_sequence_step_timeout(Dev,
+ VL53L0_SEQUENCESTEP_FINAL_RANGE,
+ &FinalRangeTimeoutMicroSeconds);
+ *pMeasurementTimingBudgetMicroSeconds +=
+ (FinalRangeTimeoutMicroSeconds +
+ FinalRangeOverheadMicroSeconds);
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_SETPARAMETERFIELD(Dev,
+ MeasurementTimingBudgetMicroSeconds,
+ *pMeasurementTimingBudgetMicroSeconds);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+VL53L0_Error VL53L0_load_tuning_settings(VL53L0_DEV Dev,
+ uint8_t *pTuningSettingBuffer)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int i;
+ int Index;
+ uint8_t msb;
+ uint8_t lsb;
+ uint8_t SelectParam;
+ uint8_t NumberOfWrites;
+ uint8_t Address;
+ uint8_t localBuffer[4]; /* max */
+ uint16_t Temp16;
+
+ LOG_FUNCTION_START("");
+
+ Index = 0;
+
+ while ((*(pTuningSettingBuffer + Index) != 0) &&
+ (Status == VL53L0_ERROR_NONE)) {
+ NumberOfWrites = *(pTuningSettingBuffer + Index);
+ Index++;
+ if (NumberOfWrites == 0xFF) {
+ /* internal parameters */
+ SelectParam = *(pTuningSettingBuffer + Index);
+ Index++;
+ switch (SelectParam) {
+ case 0: /* uint16_t SigmaEstRefArray -> 2 bytes */
+ msb = *(pTuningSettingBuffer + Index);
+ Index++;
+ lsb = *(pTuningSettingBuffer + Index);
+ Index++;
+ Temp16 = VL53L0_MAKEUINT16(lsb, msb);
+ PALDevDataSet(Dev, SigmaEstRefArray, Temp16);
+ break;
+ case 1: /* uint16_t SigmaEstEffPulseWidth -> 2 bytes */
+ msb = *(pTuningSettingBuffer + Index);
+ Index++;
+ lsb = *(pTuningSettingBuffer + Index);
+ Index++;
+ Temp16 = VL53L0_MAKEUINT16(lsb, msb);
+ PALDevDataSet(Dev, SigmaEstEffPulseWidth,
+ Temp16);
+ break;
+ case 2: /* uint16_t SigmaEstEffAmbWidth -> 2 bytes */
+ msb = *(pTuningSettingBuffer + Index);
+ Index++;
+ lsb = *(pTuningSettingBuffer + Index);
+ Index++;
+ Temp16 = VL53L0_MAKEUINT16(lsb, msb);
+ PALDevDataSet(Dev, SigmaEstEffAmbWidth, Temp16);
+ break;
+ case 3: /* uint16_t targetRefRate -> 2 bytes */
+ msb = *(pTuningSettingBuffer + Index);
+ Index++;
+ lsb = *(pTuningSettingBuffer + Index);
+ Index++;
+ Temp16 = VL53L0_MAKEUINT16(lsb, msb);
+ PALDevDataSet(Dev, targetRefRate, Temp16);
+ break;
+ default: /* invalid parameter */
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+
+ } else if (NumberOfWrites <= 4) {
+ Address = *(pTuningSettingBuffer + Index);
+ Index++;
+
+ for (i = 0; i < NumberOfWrites; i++) {
+ localBuffer[i] = *(pTuningSettingBuffer +
+ Index);
+ Index++;
+ }
+
+ Status = VL53L0_WriteMulti(Dev, Address, localBuffer,
+ NumberOfWrites);
+
+ } else {
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+ }
+
+ /* Set Pulse Width Offset. This duplicates the previous setting
+ * applied in the tuning list, however is required because the
+ * register value appears to have not been set.
+ */
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x50, 0x06);
+ Status |= VL53L0_WrByte(Dev, 0xff, 0x00);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_get_total_xtalk_rate(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData,
+ FixPoint1616_t *ptotal_xtalk_rate_mcps)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ uint8_t xtalkCompEnable;
+ FixPoint1616_t totalXtalkMegaCps;
+ FixPoint1616_t xtalkPerSpadMegaCps;
+
+ *ptotal_xtalk_rate_mcps = 0;
+
+ Status = VL53L0_GetXTalkCompensationEnable(Dev, &xtalkCompEnable);
+ if(Status == VL53L0_ERROR_NONE) {
+
+ if(xtalkCompEnable) {
+
+ VL53L0_GETPARAMETERFIELD(
+ Dev,
+ XTalkCompensationRateMegaCps,
+ xtalkPerSpadMegaCps);
+
+ /* FixPoint1616 * FixPoint 8:8 = FixPoint0824 */
+ totalXtalkMegaCps =
+ pRangingMeasurementData->EffectiveSpadRtnCount *
+ xtalkPerSpadMegaCps;
+
+ /* FixPoint0824 >> 8 = FixPoint1616 */
+ *ptotal_xtalk_rate_mcps = (totalXtalkMegaCps + 0x80) >> 8;
+ }
+ }
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_get_total_signal_rate(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData,
+ FixPoint1616_t *ptotal_signal_rate_mcps)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ FixPoint1616_t totalXtalkMegaCps;
+
+ LOG_FUNCTION_START("");
+
+ *ptotal_signal_rate_mcps =
+ pRangingMeasurementData->SignalRateRtnMegaCps;
+
+ Status = VL53L0_get_total_xtalk_rate(
+ Dev, pRangingMeasurementData, &totalXtalkMegaCps);
+
+ if(Status == VL53L0_ERROR_NONE)
+ *ptotal_signal_rate_mcps += totalXtalkMegaCps;
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_calc_dmax(
+ VL53L0_DEV Dev,
+ FixPoint1616_t totalSignalRate_mcps,
+ FixPoint1616_t totalCorrSignalRate_mcps,
+ FixPoint1616_t pwMult,
+ uint32_t sigmaEstimateP1,
+ FixPoint1616_t sigmaEstimateP2,
+ uint32_t peakVcselDuration_us,
+ uint32_t *pdmax_mm)
+{
+ const uint32_t cSigmaLimit = 18;
+ const FixPoint1616_t cSignalLimit = 0x4000; /* 0.25 */
+ const FixPoint1616_t cSigmaEstRef = 0x00000042; /* 0.001 */
+ const uint32_t cAmbEffWidthSigmaEst_ns = 6;
+ const uint32_t cAmbEffWidthDMax_ns = 7;
+ uint32_t dmaxCalRange_mm;
+ FixPoint1616_t dmaxCalSignalRateRtn_mcps;
+ FixPoint1616_t minSignalNeeded;
+ FixPoint1616_t minSignalNeeded_p1;
+ FixPoint1616_t minSignalNeeded_p2;
+ FixPoint1616_t minSignalNeeded_p3;
+ FixPoint1616_t minSignalNeeded_p4;
+ FixPoint1616_t sigmaLimitTmp;
+ FixPoint1616_t sigmaEstSqTmp;
+ FixPoint1616_t signalLimitTmp;
+ FixPoint1616_t SignalAt0mm;
+ FixPoint1616_t dmaxDark;
+ FixPoint1616_t dmaxAmbient;
+ FixPoint1616_t dmaxDarkTmp;
+ uint32_t signalRateTemp_mcps;
+
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ dmaxCalRange_mm =
+ PALDevDataGet(Dev, DmaxCalRangeMilliMeter);
+
+ dmaxCalSignalRateRtn_mcps =
+ PALDevDataGet(Dev, DmaxCalSignalRateRtnMegaCps);
+
+ /* uint32 * FixPoint1616 = FixPoint1616 */
+ SignalAt0mm = dmaxCalRange_mm * dmaxCalSignalRateRtn_mcps;
+
+ /* FixPoint1616 >> 8 = FixPoint2408 */
+ SignalAt0mm = (SignalAt0mm + 0x80) >> 8;
+ SignalAt0mm *= dmaxCalRange_mm;
+
+ minSignalNeeded_p1 = 0;
+ if(totalCorrSignalRate_mcps > 0) {
+
+ /* Shift by 10 bits to increase resolution prior to the
+ * division */
+ signalRateTemp_mcps = totalSignalRate_mcps << 10;
+
+ /* Add rounding value prior to division */
+ minSignalNeeded_p1 = signalRateTemp_mcps +
+ (totalCorrSignalRate_mcps/2);
+
+ /* FixPoint0626/FixPoint1616 = FixPoint2210 */
+ minSignalNeeded_p1 /= totalCorrSignalRate_mcps;
+
+ /* Apply a factored version of the speed of light.
+ Correction to be applied at the end */
+ minSignalNeeded_p1 *= 3;
+
+ /* FixPoint2210 * FixPoint2210 = FixPoint1220 */
+ minSignalNeeded_p1 *= minSignalNeeded_p1;
+
+ /* FixPoint1220 >> 16 = FixPoint2804 */
+ minSignalNeeded_p1 = (minSignalNeeded_p1 + 0x8000) >> 16;
+ }
+
+ minSignalNeeded_p2 = pwMult * sigmaEstimateP1;
+
+ /* FixPoint1616 >> 16 = uint32 */
+ minSignalNeeded_p2 = (minSignalNeeded_p2 + 0x8000) >> 16;
+
+ /* uint32 * uint32 = uint32 */
+ minSignalNeeded_p2 *= minSignalNeeded_p2;
+
+ /* DMAX uses a different ambient width from sigma, so apply
+ * correction.
+ * Perform division before multiplication to prevent overflow.
+ */
+ sigmaEstimateP2 = (sigmaEstimateP2 + cAmbEffWidthSigmaEst_ns/2)/
+ cAmbEffWidthSigmaEst_ns;
+ sigmaEstimateP2 *= cAmbEffWidthDMax_ns;
+
+ /* FixPoint1616 >> 16 = uint32 */
+ minSignalNeeded_p3 = (sigmaEstimateP2 + 0x8000) >> 16;
+
+ minSignalNeeded_p3 *= minSignalNeeded_p3;
+
+ /* FixPoint2012 / uint32 = FixPoint2012 */
+ sigmaLimitTmp = ((cSigmaLimit << 12) + 500) / 1000;
+
+ /* FixPoint2012 * FixPoint2012 = FixPoint4420 := FixPoint0824 */
+ sigmaLimitTmp *= sigmaLimitTmp;
+
+ /* FixPoint1616 * FixPoint1616 = FixPoint3232 */
+ sigmaEstSqTmp = cSigmaEstRef * cSigmaEstRef;
+
+ /* FixPoint3232 >> 8 = FixPoint0824 */
+ sigmaEstSqTmp = (sigmaEstSqTmp + 0x80) >> 8;
+
+ /* FixPoint0824 - FixPoint0824 = FixPoint0824 */
+ sigmaLimitTmp -= sigmaEstSqTmp;
+
+ /* uint32_t * FixPoint0824 = FixPoint0824 */
+ minSignalNeeded_p4 = 4 * 12 * sigmaLimitTmp;
+
+ /* FixPoint0824 >> 12 = FixPoint2012 */
+ minSignalNeeded_p4 = (minSignalNeeded_p4 + 0x800) >> 12;
+
+ /* uint32 + uint32 = uint32 */
+ minSignalNeeded = (minSignalNeeded_p2 + minSignalNeeded_p3);
+
+ /* uint32 / uint32 = uint32 */
+ minSignalNeeded += (peakVcselDuration_us/2);
+ minSignalNeeded /= peakVcselDuration_us;
+
+ /* uint32 << 12 = FixPoint2012 */
+ minSignalNeeded <<= 12;
+
+ /* FixPoint2012 / FixPoint2012 = uint32 */
+ minSignalNeeded += (minSignalNeeded_p4/2);
+ minSignalNeeded /= minSignalNeeded_p4;
+
+ /* FixPoint3200 * FixPoint2804 := FixPoint2804*/
+ minSignalNeeded *= minSignalNeeded_p1;
+
+ /* Apply correction by dividing by 1000000.
+ * This assumes 10E16 on the numerator of the equation
+ * and 10E-22 on the denominator.
+ * We do this because 32bit fix point calculation can't
+ * handle the larger and smaller elements of this equation,
+ * i.e. speed of light and pulse widths.
+ */
+ minSignalNeeded = (minSignalNeeded + 500) / 1000;
+ minSignalNeeded <<= 4;
+
+ minSignalNeeded = (minSignalNeeded + 500) / 1000;
+
+ /* FixPoint1616 >> 8 = FixPoint2408 */
+ signalLimitTmp = (cSignalLimit + 0x80) >> 8;
+
+ /* FixPoint2408/FixPoint2408 = uint32 */
+ if (signalLimitTmp != 0)
+ dmaxDarkTmp = (SignalAt0mm + (signalLimitTmp / 2))
+ / signalLimitTmp;
+ else
+ dmaxDarkTmp = 0;
+
+ dmaxDark = VL53L0_isqrt(dmaxDarkTmp);
+
+ /* FixPoint2408/FixPoint2408 = uint32 */
+ if (minSignalNeeded != 0)
+ dmaxAmbient = (SignalAt0mm + minSignalNeeded/2)
+ / minSignalNeeded;
+ else
+ dmaxAmbient = 0;
+
+ dmaxAmbient = VL53L0_isqrt(dmaxAmbient);
+
+ *pdmax_mm = dmaxDark;
+ if(dmaxDark > dmaxAmbient)
+ *pdmax_mm = dmaxAmbient;
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_calc_sigma_estimate(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData,
+ FixPoint1616_t *pSigmaEstimate,
+ uint32_t *pDmax_mm)
+{
+ /* Expressed in 100ths of a ns, i.e. centi-ns */
+ const uint32_t cPulseEffectiveWidth_centi_ns = 800;
+ /* Expressed in 100ths of a ns, i.e. centi-ns */
+ const uint32_t cAmbientEffectiveWidth_centi_ns = 600;
+ const FixPoint1616_t cSigmaEstRef = 0x00000042; /* 0.001 */
+ const uint32_t cVcselPulseWidth_ps = 4700; /* pico secs */
+ const FixPoint1616_t cSigmaEstMax = 0x028F87AE;
+ /* Time Of Flight per mm (6.6 pico secs) */
+ const FixPoint1616_t cTOF_per_mm_ps = 0x0006999A;
+ const uint32_t c16BitRoundingParam = 0x00008000;
+ const FixPoint1616_t cMaxXTalk_kcps = 0x00320000;
+ const uint32_t cPllPeriod_ps = 1655;
+
+ uint32_t vcselTotalEventsRtn;
+ uint32_t finalRangeTimeoutMicroSecs;
+ uint32_t preRangeTimeoutMicroSecs;
+ FixPoint1616_t sigmaEstimateP1;
+ FixPoint1616_t sigmaEstimateP2;
+ FixPoint1616_t sigmaEstimateP3;
+ FixPoint1616_t deltaT_ps;
+ FixPoint1616_t pwMult;
+ FixPoint1616_t sigmaEstRtn;
+ FixPoint1616_t sigmaEstimate;
+ FixPoint1616_t xTalkCorrection;
+ FixPoint1616_t ambientRate_kcps;
+ FixPoint1616_t peakSignalRate_kcps;
+ FixPoint1616_t xTalkCompRate_mcps;
+ uint32_t xTalkCompRate_kcps;
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ FixPoint1616_t diff1_mcps;
+ FixPoint1616_t diff2_mcps;
+ FixPoint1616_t sqr1;
+ FixPoint1616_t sqr2;
+ FixPoint1616_t sqrSum;
+ FixPoint1616_t sqrtResult_centi_ns;
+ FixPoint1616_t sqrtResult;
+ FixPoint1616_t totalSignalRate_mcps;
+ FixPoint1616_t correctedSignalRate_mcps;
+ uint32_t vcselWidth;
+ uint32_t finalRangeMacroPCLKS;
+ uint32_t preRangeMacroPCLKS;
+ uint32_t peakVcselDuration_us;
+ uint8_t finalRangeVcselPCLKS;
+ uint8_t preRangeVcselPCLKS;
+ /*! \addtogroup calc_sigma_estimate
+ * @{
+ *
+ * Estimates the range sigma based on the
+ *
+ * - vcsel_rate_kcps
+ * - ambient_rate_kcps
+ * - signal_total_events
+ * - xtalk_rate
+ *
+ * and the following parameters
+ *
+ * - SigmaEstRefArray
+ * - SigmaEstEffPulseWidth
+ * - SigmaEstEffAmbWidth
+ */
+
+ LOG_FUNCTION_START("");
+
+ VL53L0_GETPARAMETERFIELD(Dev, XTalkCompensationRateMegaCps,
+ xTalkCompRate_mcps);
+
+ /*
+ * We work in kcps rather than mcps as this helps keep within the
+ * confines of the 32 Fix1616 type.
+ */
+
+ ambientRate_kcps =
+ (pRangingMeasurementData->AmbientRateRtnMegaCps * 1000) >> 16;
+
+ correctedSignalRate_mcps =
+ pRangingMeasurementData->SignalRateRtnMegaCps;
+
+
+ Status = VL53L0_get_total_signal_rate(
+ Dev, pRangingMeasurementData, &totalSignalRate_mcps);
+ Status = VL53L0_get_total_xtalk_rate(
+ Dev, pRangingMeasurementData, &xTalkCompRate_mcps);
+
+
+ /* Signal rate measurement provided by device is the
+ * peak signal rate, not average.
+ */
+ peakSignalRate_kcps = (totalSignalRate_mcps * 1000);
+ peakSignalRate_kcps = (peakSignalRate_kcps + 0x8000) >> 16;
+
+ xTalkCompRate_kcps = xTalkCompRate_mcps * 1000;
+
+ if (xTalkCompRate_kcps > cMaxXTalk_kcps)
+ xTalkCompRate_kcps = cMaxXTalk_kcps;
+
+ if(Status == VL53L0_ERROR_NONE){
+
+ /* Calculate final range macro periods */
+ finalRangeTimeoutMicroSecs = VL53L0_GETDEVICESPECIFICPARAMETER(
+ Dev, FinalRangeTimeoutMicroSecs);
+
+ finalRangeVcselPCLKS = VL53L0_GETDEVICESPECIFICPARAMETER(
+ Dev, FinalRangeVcselPulsePeriod);
+
+ finalRangeMacroPCLKS = VL53L0_calc_timeout_mclks(
+ Dev, finalRangeTimeoutMicroSecs, finalRangeVcselPCLKS);
+
+ /* Calculate pre-range macro periods */
+ preRangeTimeoutMicroSecs = VL53L0_GETDEVICESPECIFICPARAMETER(
+ Dev, PreRangeTimeoutMicroSecs);
+
+ preRangeVcselPCLKS = VL53L0_GETDEVICESPECIFICPARAMETER(
+ Dev, PreRangeVcselPulsePeriod);
+
+ preRangeMacroPCLKS = VL53L0_calc_timeout_mclks(
+ Dev, preRangeTimeoutMicroSecs, preRangeVcselPCLKS);
+
+ vcselWidth = 3;
+ if(finalRangeVcselPCLKS == 8) {
+ vcselWidth = 2;
+ }
+
+ peakVcselDuration_us = vcselWidth * 2048 *
+ (preRangeMacroPCLKS + finalRangeMacroPCLKS);
+ peakVcselDuration_us = (peakVcselDuration_us + 500)/1000;
+ peakVcselDuration_us *= cPllPeriod_ps;
+ peakVcselDuration_us = (peakVcselDuration_us + 500)/1000;
+
+ vcselTotalEventsRtn = totalSignalRate_mcps *
+ peakVcselDuration_us;
+ vcselTotalEventsRtn = (vcselTotalEventsRtn + 0x8000) >> 16;
+ }
+
+ if (Status != VL53L0_ERROR_NONE) {
+ LOG_FUNCTION_END(Status);
+ return Status;
+ }
+
+ if (peakSignalRate_kcps == 0) {
+ *pSigmaEstimate = 0;
+ PALDevDataSet(Dev, SigmaEstimate, 0);
+ *pDmax_mm = 0;
+ } else {
+ if (vcselTotalEventsRtn < 1)
+ vcselTotalEventsRtn = 1;
+
+ /*
+ * Calculate individual components of the main equation -
+ * replicating the equation implemented in the script
+ * OpenAll_Ewok_ranging_data.jsl.
+ *
+ * sigmaEstimateP1 represents the effective pulse width, which
+ * is a tuning parameter, rather than a real value.
+ *
+ * sigmaEstimateP2 represents the ambient/signal rate ratio
+ * expressed as a multiple of the effective ambient width
+ * (tuning parameter).
+ *
+ * sigmaEstimateP3 provides the signal event component, with the
+ * knowledge that
+ * - Noise of a square pulse is 1/sqrt(12) of the pulse
+ * width.
+ * - at 0Lux, sigma is proportional to
+ * effectiveVcselPulseWidth/sqrt(12 * signalTotalEvents)
+ *
+ * deltaT_ps represents the time of flight in pico secs for the
+ * current range measurement, using the "TOF per mm" constant
+ * (in ps).
+ */
+
+ sigmaEstimateP1 = cPulseEffectiveWidth_centi_ns;
+
+ /* ((FixPoint1616 << 16)* uint32)/uint32 = FixPoint1616 */
+ sigmaEstimateP2 = (ambientRate_kcps << 16)/peakSignalRate_kcps;
+ sigmaEstimateP2 *= cAmbientEffectiveWidth_centi_ns;
+
+ sigmaEstimateP3 = 2 * VL53L0_isqrt(vcselTotalEventsRtn * 12);
+
+ /* uint32 * FixPoint1616 = FixPoint1616 */
+ deltaT_ps = pRangingMeasurementData->RangeMilliMeter *
+ cTOF_per_mm_ps;
+
+ /*
+ * vcselRate - xtalkCompRate
+ * (uint32 << 16) - FixPoint1616 = FixPoint1616.
+ * Divide result by 1000 to convert to mcps.
+ * 500 is added to ensure rounding when integer division
+ * truncates.
+ */
+ diff1_mcps = (((peakSignalRate_kcps << 16) -
+ xTalkCompRate_kcps) + 500)/1000;
+
+ /* vcselRate + xtalkCompRate */
+ diff2_mcps = (((peakSignalRate_kcps << 16) +
+ xTalkCompRate_kcps) + 500)/1000;
+
+ /* Shift by 12 bits to increase resolution prior to the
+ * division */
+ diff1_mcps <<= 12;
+
+ /* FixPoint0428/FixPoint1616 = FixPoint2012 */
+ xTalkCorrection = abs(diff1_mcps/diff2_mcps);
+
+ /* FixPoint2012 << 4 = FixPoint1616 */
+ xTalkCorrection <<= 4;
+
+ /* FixPoint1616/uint32 = FixPoint1616 */
+ pwMult = deltaT_ps/cVcselPulseWidth_ps; /* smaller than 1.0f */
+
+ /*
+ * FixPoint1616 * FixPoint1616 = FixPoint3232, however both
+ * values are small enough such that32 bits will not be
+ * exceeded.
+ */
+ pwMult *= ((1 << 16) - xTalkCorrection);
+
+ /* (FixPoint3232 >> 16) = FixPoint1616 */
+ pwMult = (pwMult + c16BitRoundingParam) >> 16;
+
+ /* FixPoint1616 + FixPoint1616 = FixPoint1616 */
+ pwMult += (1 << 16);
+
+ /*
+ * At this point the value will be 1.xx, therefore if we square
+ * the value this will exceed 32 bits. To address this perform
+ * a single shift to the right before the multiplication.
+ */
+ pwMult >>= 1;
+ /* FixPoint1715 * FixPoint1715 = FixPoint3430 */
+ pwMult = pwMult * pwMult;
+
+ /* (FixPoint3430 >> 14) = Fix1616 */
+ pwMult >>= 14;
+
+ /* FixPoint1616 * uint32 = FixPoint1616 */
+ sqr1 = pwMult * sigmaEstimateP1;
+
+ /* (FixPoint1616 >> 12) = FixPoint2804 */
+ sqr1 = (sqr1 + 0x800) >> 12;
+
+ /* FixPoint2804 * FixPoint2804 = FixPoint5608 */
+ sqr1 *= sqr1;
+
+ sqr2 = sigmaEstimateP2;
+
+ /* (FixPoint1616 >> 12) = FixPoint2804 */
+ sqr2 = (sqr2 + 0x800) >> 12;
+
+ /* FixPoint2804 * FixPoint2804 = FixPoint5608 */
+ sqr2 *= sqr2;
+
+ /* FixPoint5608 + FixPoint5608 = FixPoint5608 */
+ sqrSum = sqr1 + sqr2;
+
+ /* SQRT(FixPoint5608) = FixPoint2804 */
+ sqrtResult_centi_ns = VL53L0_isqrt(sqrSum);
+
+ /* (FixPoint2804 << 12) = FixPoint1616 */
+ sqrtResult_centi_ns <<= 12;
+
+ /*
+ * Note that the Speed Of Light is expressed in um per 1E-10
+ * seconds (2997) Therefore to get mm/ns we have to divide by
+ * 10000
+ */
+ sigmaEstRtn = (((sqrtResult_centi_ns+50)/100) /
+ sigmaEstimateP3);
+ sigmaEstRtn *= VL53L0_SPEED_OF_LIGHT_IN_AIR;
+
+ /* Add 5000 before dividing by 10000 to ensure rounding. */
+ sigmaEstRtn += 5000;
+ sigmaEstRtn /= 10000;
+
+ /* FixPoint1616 * FixPoint1616 = FixPoint3232 */
+ sqr1 = sigmaEstRtn * sigmaEstRtn;
+ /* FixPoint1616 * FixPoint1616 = FixPoint3232 */
+ sqr2 = cSigmaEstRef * cSigmaEstRef;
+
+ /* sqrt(FixPoint3232 << 8) = sqrt(FixPoint4024) =FixPoint2012 */
+ sqrtResult = VL53L0_isqrt((sqr1 + sqr2) << 8);
+ sqrtResult = (sqrtResult + 0x08) >> 4;
+ /*
+ * Note that the Shift by 12bits increases resolution prior to
+ * the sqrt, therefore the result must be shifted by 6bits to
+ * the right to revert back to the FixPoint1616 format.
+ */
+
+ sigmaEstimate = 1000 * sqrtResult;
+
+ if ((peakSignalRate_kcps < 1) || (vcselTotalEventsRtn < 1) ||
+ (sigmaEstimate > cSigmaEstMax)) {
+ sigmaEstimate = cSigmaEstMax;
+ }
+
+ *pSigmaEstimate = (uint32_t)(sigmaEstimate);
+ PALDevDataSet(Dev, SigmaEstimate, *pSigmaEstimate);
+
+ Status = VL53L0_calc_dmax(
+ Dev,
+ totalSignalRate_mcps,
+ correctedSignalRate_mcps,
+ pwMult,
+ sigmaEstimateP1,
+ sigmaEstimateP2,
+ peakVcselDuration_us,
+ pDmax_mm);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_get_pal_range_status(VL53L0_DEV Dev,
+ uint8_t DeviceRangeStatus,
+ FixPoint1616_t SignalRate,
+ uint16_t EffectiveSpadRtnCount,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData,
+ uint8_t *pPalRangeStatus)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t NoneFlag;
+ uint8_t SigmaLimitflag = 0;
+ uint8_t SignalRefClipflag = 0;
+ uint8_t RangeIgnoreThresholdflag = 0;
+ uint8_t SigmaLimitCheckEnable = 0;
+ uint8_t SignalRateFinalRangeLimitCheckEnable = 0;
+ uint8_t SignalRefClipLimitCheckEnable = 0;
+ uint8_t RangeIgnoreThresholdLimitCheckEnable = 0;
+ FixPoint1616_t SigmaEstimate;
+ FixPoint1616_t SigmaLimitValue;
+ FixPoint1616_t SignalRefClipValue;
+ FixPoint1616_t RangeIgnoreThresholdValue;
+ FixPoint1616_t SignalRatePerSpad;
+ uint8_t DeviceRangeStatusInternal = 0;
+ uint16_t tmpWord = 0;
+ uint8_t Temp8;
+ uint32_t Dmax_mm = 0;
+ FixPoint1616_t LastSignalRefMcps;
+
+ LOG_FUNCTION_START("");
+
+
+ /*
+ * VL53L0 has a good ranging when the value of the
+ * DeviceRangeStatus = 11. This function will replace the value 0 with
+ * the value 11 in the DeviceRangeStatus.
+ * In addition, the SigmaEstimator is not included in the VL53L0
+ * DeviceRangeStatus, this will be added in the PalRangeStatus.
+ */
+
+ DeviceRangeStatusInternal = ((DeviceRangeStatus & 0x78) >> 3);
+
+ if (DeviceRangeStatusInternal == 0 ||
+ DeviceRangeStatusInternal == 5 ||
+ DeviceRangeStatusInternal == 7 ||
+ DeviceRangeStatusInternal == 12 ||
+ DeviceRangeStatusInternal == 13 ||
+ DeviceRangeStatusInternal == 14 ||
+ DeviceRangeStatusInternal == 15
+ ) {
+ NoneFlag = 1;
+ } else {
+ NoneFlag = 0;
+ }
+
+ /* LastSignalRefMcps */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev, 0xFF, 0x01);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_RdWord(Dev,
+ VL53L0_REG_RESULT_PEAK_SIGNAL_RATE_REF,
+ &tmpWord);
+
+ LastSignalRefMcps = VL53L0_FIXPOINT97TOFIXPOINT1616(tmpWord);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ PALDevDataSet(Dev, LastSignalRefMcps, LastSignalRefMcps);
+
+ /*
+ * Check if Sigma limit is enabled, if yes then do comparison with limit
+ * value and put the result back into pPalRangeStatus.
+ */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_GetLimitCheckEnable(Dev,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ &SigmaLimitCheckEnable);
+ /*
+ * compute the Sigma and check with limit
+ */
+ Status = VL53L0_calc_sigma_estimate(
+ Dev,
+ pRangingMeasurementData,
+ &SigmaEstimate,
+ &Dmax_mm);
+ pRangingMeasurementData->SigmaEstimate = SigmaEstimate;
+ if (Status == VL53L0_ERROR_NONE)
+ pRangingMeasurementData->RangeDMaxMilliMeter = Dmax_mm;
+
+ if ((SigmaLimitCheckEnable != 0) && (Status == VL53L0_ERROR_NONE)) {
+ /*
+ * compute the Sigma and check with limit
+ */
+ Status = VL53L0_calc_sigma_estimate(
+ Dev,
+ pRangingMeasurementData,
+ &SigmaEstimate,
+ &Dmax_mm);
+
+ if (Status == VL53L0_ERROR_NONE)
+ pRangingMeasurementData->RangeDMaxMilliMeter = Dmax_mm;
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_GetLimitCheckValue(Dev,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ &SigmaLimitValue);
+
+ if ((SigmaLimitValue > 0) &&
+ (SigmaEstimate > SigmaLimitValue))
+ /* Limit Fail */
+ SigmaLimitflag = 1;
+ }
+ }
+
+ /*
+ * Check if Signal ref clip limit is enabled, if yes then do comparison
+ * with limit value and put the result back into pPalRangeStatus.
+ */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_GetLimitCheckEnable(Dev,
+ VL53L0_CHECKENABLE_SIGNAL_REF_CLIP,
+ &SignalRefClipLimitCheckEnable);
+
+ if ((SignalRefClipLimitCheckEnable != 0) &&
+ (Status == VL53L0_ERROR_NONE)) {
+
+ Status = VL53L0_GetLimitCheckValue(Dev,
+ VL53L0_CHECKENABLE_SIGNAL_REF_CLIP,
+ &SignalRefClipValue);
+
+ if ((SignalRefClipValue > 0) &&
+ (LastSignalRefMcps > SignalRefClipValue)) {
+ /* Limit Fail */
+ SignalRefClipflag = 1;
+ }
+ }
+
+ /*
+ * Check if Signal ref clip limit is enabled, if yes then do comparison
+ * with limit value and put the result back into pPalRangeStatus.
+ * EffectiveSpadRtnCount has a format 8.8
+ * If (Return signal rate < (1.5 x Xtalk x number of Spads)) : FAIL
+ */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_GetLimitCheckEnable(Dev,
+ VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
+ &RangeIgnoreThresholdLimitCheckEnable);
+
+ if ((RangeIgnoreThresholdLimitCheckEnable != 0) &&
+ (Status == VL53L0_ERROR_NONE)) {
+
+ /* Compute the signal rate per spad */
+ if (EffectiveSpadRtnCount == 0) {
+ SignalRatePerSpad = 0;
+ } else {
+ SignalRatePerSpad = (FixPoint1616_t)((256 * SignalRate)
+ / EffectiveSpadRtnCount);
+ }
+
+ Status = VL53L0_GetLimitCheckValue(Dev,
+ VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
+ &RangeIgnoreThresholdValue);
+
+ if ((RangeIgnoreThresholdValue > 0) &&
+ (SignalRatePerSpad < RangeIgnoreThresholdValue)) {
+ /* Limit Fail add 2^6 to range status */
+ RangeIgnoreThresholdflag = 1;
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (NoneFlag == 1) {
+ *pPalRangeStatus = 255; /* NONE */
+ } else if (DeviceRangeStatusInternal == 1 ||
+ DeviceRangeStatusInternal == 2 ||
+ DeviceRangeStatusInternal == 3) {
+ *pPalRangeStatus = 5; /* HW fail */
+ } else if (DeviceRangeStatusInternal == 6 ||
+ DeviceRangeStatusInternal == 9) {
+ *pPalRangeStatus = 4; /* Phase fail */
+ } else if (DeviceRangeStatusInternal == 8 ||
+ DeviceRangeStatusInternal == 10 ||
+ SignalRefClipflag == 1) {
+ *pPalRangeStatus = 3; /* Min range */
+ } else if (DeviceRangeStatusInternal == 4 ||
+ RangeIgnoreThresholdflag == 1) {
+ *pPalRangeStatus = 2; /* Signal Fail */
+ } else if (SigmaLimitflag == 1) {
+ *pPalRangeStatus = 1; /* Sigma Fail */
+ } else {
+ *pPalRangeStatus = 0; /* Range Valid */
+ }
+ }
+
+ /* fill the Limit Check Status */
+
+ Status = VL53L0_GetLimitCheckEnable(Dev,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ &SignalRateFinalRangeLimitCheckEnable);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if ((SigmaLimitCheckEnable == 0) || (SigmaLimitflag == 1))
+ Temp8 = 1;
+ else
+ Temp8 = 0;
+ VL53L0_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE, Temp8);
+
+ if ((DeviceRangeStatusInternal == 4) ||
+ (SignalRateFinalRangeLimitCheckEnable == 0))
+ Temp8 = 1;
+ else
+ Temp8 = 0;
+ VL53L0_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ Temp8);
+
+ if ((SignalRefClipLimitCheckEnable == 0) ||
+ (SignalRefClipflag == 1))
+ Temp8 = 1;
+ else
+ Temp8 = 0;
+
+ VL53L0_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
+ VL53L0_CHECKENABLE_SIGNAL_REF_CLIP, Temp8);
+
+ if ((RangeIgnoreThresholdLimitCheckEnable == 0) ||
+ (RangeIgnoreThresholdflag == 1))
+ Temp8 = 1;
+ else
+ Temp8 = 0;
+
+ VL53L0_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
+ VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
+ Temp8);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
diff --git a/drivers/input/misc/vl53L0/src/vl53l0_api_histogram.c b/drivers/input/misc/vl53L0/src/vl53l0_api_histogram.c
new file mode 100644
index 000000000000..ef543bcf6bde
--- /dev/null
+++ b/drivers/input/misc/vl53L0/src/vl53l0_api_histogram.c
@@ -0,0 +1,746 @@
+/*******************************************************************************
+ Copyright © 2016, STMicroelectronics International N.V.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+ NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+ IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ******************************************************************************/
+
+#include "vl53l0_api.h"
+#include "vl53l0_api_core.h"
+#include "vl53l0_api_histogram.h"
+
+
+#ifndef __KERNEL__
+#include
+#endif
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(TRACE_MODULE_API, status, fmt, ##__VA_ARGS__)
+
+
+typedef uint32_t WindowSelection;
+#define VL53L0_AMBIENT_WINDOW_ONLY ((WindowSelection) 0)
+ /*!< Measure Ambient Signal only */
+#define VL53L0_AMBIENT_AND_SIGNAL_WINDOW ((WindowSelection) 1)
+ /*!< Measure Combined Ambient and Signal Rate. */
+
+
+VL53L0_Error VL53L0_start_histogram_measurement(VL53L0_DEV Dev,
+ VL53L0_HistogramModes histoMode,
+ uint32_t count)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t dataByte;
+ LOG_FUNCTION_START("");
+
+
+ dataByte = VL53L0_REG_SYSRANGE_MODE_SINGLESHOT |
+ VL53L0_REG_SYSRANGE_MODE_START_STOP;
+
+ /* First histogram measurement must have bit 5 set */
+ if (count == 0)
+ dataByte |= (1 << 5);
+
+ switch (histoMode) {
+ case VL53L0_HISTOGRAMMODE_DISABLED:
+ /* Selected mode not supported */
+ Status = VL53L0_ERROR_INVALID_COMMAND;
+ break;
+
+ case VL53L0_HISTOGRAMMODE_REFERENCE_ONLY:
+ case VL53L0_HISTOGRAMMODE_RETURN_ONLY:
+ case VL53L0_HISTOGRAMMODE_BOTH:
+ dataByte |= (histoMode << 3);
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSRANGE_START,
+ dataByte);
+ if (Status == VL53L0_ERROR_NONE) {
+ /* Set PAL State to Running */
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_RUNNING);
+ }
+ break;
+
+ default:
+ /* Selected mode not supported */
+ Status = VL53L0_ERROR_MODE_NOT_SUPPORTED;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_confirm_measurement_start(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t NewDataReady = 0;
+ uint32_t LoopNb;
+
+ LOG_FUNCTION_START("");
+
+ LoopNb = 0;
+ do {
+ Status = VL53L0_GetMeasurementDataReady(Dev, &NewDataReady);
+ if ((NewDataReady == 0x01) || Status != VL53L0_ERROR_NONE)
+ break;
+
+ LoopNb = LoopNb + 1;
+ VL53L0_PollingDelay(Dev);
+ } while (LoopNb < VL53L0_DEFAULT_MAX_LOOP);
+
+ if (LoopNb >= VL53L0_DEFAULT_MAX_LOOP)
+ Status = VL53L0_ERROR_TIME_OUT;
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_set_histogram_mode(VL53L0_DEV Dev,
+ VL53L0_HistogramModes HistogramMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ switch (HistogramMode) {
+ case VL53L0_HISTOGRAMMODE_DISABLED:
+ case VL53L0_HISTOGRAMMODE_REFERENCE_ONLY:
+ case VL53L0_HISTOGRAMMODE_RETURN_ONLY:
+ case VL53L0_HISTOGRAMMODE_BOTH:
+ /* Supported mode */
+ VL53L0_SETPARAMETERFIELD(Dev, HistogramMode, HistogramMode);
+ break;
+ default:
+ /* Unsupported mode */
+ Status = VL53L0_ERROR_MODE_NOT_SUPPORTED;
+ }
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_get_histogram_mode(VL53L0_DEV Dev,
+ VL53L0_HistogramModes *pHistogramMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ VL53L0_GETPARAMETERFIELD(Dev, HistogramMode, *pHistogramMode);
+
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_perform_single_histogram_measurement(VL53L0_DEV Dev,
+ VL53L0_HistogramMeasurementData_t *pHistogramMeasurementData)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceModes DeviceMode;
+ VL53L0_HistogramModes HistogramMode = VL53L0_HISTOGRAMMODE_DISABLED;
+ uint32_t MeasCount;
+ uint32_t Measurements;
+
+ /* Get Current DeviceMode */
+ Status = VL53L0_GetHistogramMode(Dev, &HistogramMode);
+
+
+ if (Status != VL53L0_ERROR_NONE)
+ return Status;
+
+
+ if (HistogramMode == VL53L0_HISTOGRAMMODE_BOTH) {
+ if (pHistogramMeasurementData->BufferSize <
+ VL53L0_HISTOGRAM_BUFFER_SIZE) {
+ Status = VL53L0_ERROR_BUFFER_TOO_SMALL;
+ }
+ } else {
+ if (pHistogramMeasurementData->BufferSize <
+ VL53L0_HISTOGRAM_BUFFER_SIZE/2) {
+ Status = VL53L0_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ pHistogramMeasurementData->HistogramType = (uint8_t)HistogramMode;
+ pHistogramMeasurementData->ErrorStatus = VL53L0_DEVICEERROR_NONE;
+ pHistogramMeasurementData->FirstBin = 0;
+ pHistogramMeasurementData->NumberOfBins = 0;
+
+
+ /* Get Current DeviceMode */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_GetDeviceMode(Dev, &DeviceMode);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev, VL53L0_REG_SYSTEM_HISTOGRAM_BIN,
+ 0x00);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_HISTOGRAM_CONFIG_INITIAL_PHASE_SELECT, 0x00);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_WrByte(Dev,
+ VL53L0_REG_HISTOGRAM_CONFIG_READOUT_CTRL, 0x01);
+
+ if (Status != VL53L0_ERROR_NONE)
+ return Status;
+
+ Measurements = 3;
+ if (HistogramMode == VL53L0_HISTOGRAMMODE_BOTH)
+ Measurements = 6;
+
+ if (DeviceMode != VL53L0_DEVICEMODE_SINGLE_HISTOGRAM) {
+ Status = VL53L0_ERROR_INVALID_COMMAND;
+ return Status;
+ }
+
+ /* DeviceMode == VL53L0_DEVICEMODE_SINGLE_HISTOGRAM */
+ MeasCount = 0;
+ while ((MeasCount < Measurements) && (Status == VL53L0_ERROR_NONE)) {
+ Status = VL53L0_start_histogram_measurement(Dev, HistogramMode,
+ MeasCount);
+
+ if (Status == VL53L0_ERROR_NONE)
+ VL53L0_confirm_measurement_start(Dev);
+
+ if (Status == VL53L0_ERROR_NONE)
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_RUNNING);
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_measurement_poll_for_completion(Dev);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_read_histo_measurement(Dev,
+ pHistogramMeasurementData->HistogramData,
+ MeasCount,
+ HistogramMode);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ /*
+ * When reading both rtn and ref arrays,
+ * histograms are read two bins at a time.
+ * For rtn or ref only, histograms are read four
+ * bins at a time.
+ */
+ if (HistogramMode == VL53L0_HISTOGRAMMODE_BOTH)
+ pHistogramMeasurementData->NumberOfBins
+ += 2;
+ else
+ pHistogramMeasurementData->NumberOfBins
+ += 4;
+
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_ClearInterruptMask(Dev, 0);
+
+ MeasCount++;
+ }
+
+ /* Change PAL State in case of single ranging or single histogram */
+ if (Status == VL53L0_ERROR_NONE) {
+ pHistogramMeasurementData->NumberOfBins = 12;
+ PALDevDataSet(Dev, PalState, VL53L0_STATE_IDLE);
+ }
+
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_get_histogram_measurement_data(VL53L0_DEV Dev,
+ VL53L0_HistogramMeasurementData_t *pHistogramMeasurementData)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NOT_IMPLEMENTED;
+ LOG_FUNCTION_START("");
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_read_histo_measurement(VL53L0_DEV Dev,
+ uint32_t *histoData,
+ uint32_t offset,
+ VL53L0_HistogramModes histoMode)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t localBuffer[28];
+ uint32_t cDataSize = 4;
+ uint32_t offset1;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_WrByte(Dev, 0xFF, VL53L0_REG_RESULT_CORE_PAGE);
+ Status = VL53L0_ReadMulti(Dev,
+ (uint8_t)VL53L0_REG_RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN,
+ localBuffer,
+ 28);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ VL53L0_reverse_bytes(&localBuffer[0], cDataSize);
+ VL53L0_reverse_bytes(&localBuffer[4], cDataSize);
+ VL53L0_reverse_bytes(&localBuffer[20], cDataSize);
+ VL53L0_reverse_bytes(&localBuffer[24], cDataSize);
+
+ offset1 = offset * cDataSize;
+ if (histoMode == VL53L0_HISTOGRAMMODE_BOTH) {
+ /*
+ * When reading both return and ref data, each
+ * measurement reads two ref values and two return
+ * values. Data is stored in an interleaved sequence,
+ * starting with the return histogram.
+ *
+ * Some result Core registers are reused for the
+ * histogram measurements
+ *
+ * The bin values are retrieved in the following order
+ * VL53L0_REG_RESULT_CORE_RANGING_TOTAL_EVENTS_RTN
+ * VL53L0_REG_RESULT_CORE_RANGING_TOTAL_EVENTS_REF
+ * VL53L0_REG_RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN
+ * VL53L0_REG_RESULT_CORE_AMBIENT_WINDOW_EVENTS_REF
+ */
+
+ memcpy(&histoData[offset1], &localBuffer[4],
+ cDataSize); /* rtn */
+ memcpy(&histoData[offset1 + 1], &localBuffer[24],
+ cDataSize); /* ref */
+ memcpy(&histoData[offset1 + 2], &localBuffer[0],
+ cDataSize); /* rtn */
+ memcpy(&histoData[offset1 + 3], &localBuffer[20],
+ cDataSize); /* ref */
+
+ } else {
+ /*
+ * When reading either return and ref data, each
+ * measurement reads four bin values.
+ *
+ * The bin values are retrieved in the following order
+ * VL53L0_REG_RESULT_CORE_RANGING_TOTAL_EVENTS_RTN
+ * VL53L0_REG_RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN
+ * VL53L0_REG_RESULT_CORE_RANGING_TOTAL_EVENTS_REF
+ * VL53L0_REG_RESULT_CORE_AMBIENT_WINDOW_EVENTS_REF
+ */
+
+ memcpy(&histoData[offset1], &localBuffer[24],
+ cDataSize);
+ memcpy(&histoData[offset1 + 1], &localBuffer[20],
+ cDataSize);
+ memcpy(&histoData[offset1 + 2], &localBuffer[4],
+ cDataSize);
+ memcpy(&histoData[offset1 + 3], &localBuffer[0],
+ cDataSize);
+
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_get_max_spads(VL53L0_DEV Dev,
+ uint32_t *pmax_spads, uint8_t *pambient_too_high)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t TCC_Enabled;
+ uint8_t MSRC_Enabled;
+ VL53L0_RangingMeasurementData_t RangingMeasurementData;
+ FixPoint1616_t ratio = 0;
+ uint32_t max_spads = 0;
+
+ /* Get the value of the TCC */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_GetSequenceStepEnable(Dev,
+ VL53L0_SEQUENCESTEP_TCC, &TCC_Enabled);
+
+ /* Get the value of the MSRC */
+ if (Status == VL53L0_ERROR_NONE)
+ Status = VL53L0_GetSequenceStepEnable(Dev,
+ VL53L0_SEQUENCESTEP_MSRC, &MSRC_Enabled);
+
+ /* Disable the TCC */
+ if ((Status == VL53L0_ERROR_NONE) && (TCC_Enabled != 0))
+ Status = VL53L0_SetSequenceStepEnable(Dev,
+ VL53L0_SEQUENCESTEP_TCC, 0);
+
+ /* Disable the MSRC */
+ if ((Status == VL53L0_ERROR_NONE) && (MSRC_Enabled != 0))
+ Status = VL53L0_SetSequenceStepEnable(Dev,
+ VL53L0_SEQUENCESTEP_MSRC, 0);
+
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_PerformSingleRangingMeasurement(Dev,
+ &RangingMeasurementData);
+ max_spads = (RangingMeasurementData.EffectiveSpadRtnCount +
+ 128)/256;
+ *pmax_spads = max_spads;
+ }
+
+ /* Check Ambient per spad > 10 Kcps */
+ if (Status == VL53L0_ERROR_NONE) {
+ if (max_spads <= 0) {
+ *pambient_too_high = 1;
+ return VL53L0_ERROR_DIVISION_BY_ZERO;
+ } else {
+ ratio = RangingMeasurementData.AmbientRateRtnMegaCps /
+ max_spads;
+
+ /* ratio is given in mega count per second and
+ * FixPoint1616_t */
+ if (ratio > 65536/100)
+ *pambient_too_high = 1;
+ else
+ *pambient_too_high = 0;
+
+ }
+ }
+
+
+ /* Restore the TCC */
+ if (Status == VL53L0_ERROR_NONE) {
+ if (TCC_Enabled != 0)
+ Status = VL53L0_SetSequenceStepEnable(Dev,
+ VL53L0_SEQUENCESTEP_TCC, 1);
+ }
+
+ /* Restore the MSRC */
+ if (Status == VL53L0_ERROR_NONE) {
+ if (MSRC_Enabled != 0)
+ Status = VL53L0_SetSequenceStepEnable(Dev,
+ VL53L0_SEQUENCESTEP_MSRC, 1);
+ }
+
+ return Status;
+
+}
+
+
+VL53L0_Error calc_xtalk_mcps_per_spad(
+ uint32_t rtn_signal_events,
+ uint32_t timeout_ms,
+ uint32_t max_spads,
+ uint8_t vcsel_pulse_period_pclk,
+ FixPoint1616_t *pxtalk_mcps_per_spad)
+{
+ /* Calculate the X-Talk per Spad based on given inputs.
+ *
+ * To calculate x-talk, only a portion of the vcsel pulse period is
+ * used, therefore we use the ratio between vcsel_width_pclk and
+ * vcsel_pulse_period_pclks to determine the integration time.
+ *
+ * With the rtn signal events, and the integration time,
+ * the x-talk rate per spad is then determined.
+ */
+
+ const FixPoint1616_t cmin_xtalk_per_spad = 8; /* 0.000122 */
+ const FixPoint1616_t ccompensation2 = 13;/* 0.0002 */
+ const FixPoint1616_t ccompensation1 = 7; /* 0.0001; */
+ const FixPoint1616_t ctalk_thresh = 66; /* 0.001 */
+ const uint32_t c16BitRoundingParam = 0x00008000;
+ VL53L0_Error status = VL53L0_ERROR_NONE;
+ FixPoint1616_t xtalk_mcps;
+ FixPoint1616_t vcsel_width_to_period_ratio;
+ FixPoint1616_t integration_time_us;
+ uint32_t integration_time_us_int;
+ uint8_t vcsel_width_pclk = 3;
+
+ LOG_FUNCTION_START("");
+
+ if (vcsel_pulse_period_pclk == 0 || timeout_ms == 0)
+ status = VL53L0_ERROR_DIVISION_BY_ZERO;
+
+
+ if (status == VL53L0_ERROR_NONE) {
+
+ /* (FixPoint1616 + uint32)/uint32 = FixPoint1616 */
+ vcsel_width_to_period_ratio =
+ ((vcsel_width_pclk << 16) +
+ (vcsel_pulse_period_pclk/2))/vcsel_pulse_period_pclk;
+
+ /* uint32_t * FixPoint1616 = FixPoint1616 */
+ integration_time_us = timeout_ms * vcsel_width_to_period_ratio
+ * 1000;
+
+ /*FixPoint1616 >>16 = uint32_t */
+ integration_time_us_int = (integration_time_us +
+ c16BitRoundingParam) >> 16;
+
+ /* (uint32_t << 16)/uint32_t = FixPoint1616 */
+ xtalk_mcps = rtn_signal_events << 16;
+ xtalk_mcps = (xtalk_mcps +
+ (integration_time_us_int/2))/integration_time_us_int;
+
+ /* (FixPoint1616 + uint32)/uint32 = FixPoint1616 */
+ *pxtalk_mcps_per_spad = (xtalk_mcps + (max_spads/2))/max_spads;
+
+ /* Apply compensation to prevent overshoot.
+ */
+ if (*pxtalk_mcps_per_spad < ctalk_thresh)
+ *pxtalk_mcps_per_spad = *pxtalk_mcps_per_spad
+ - ccompensation2;
+ else
+ *pxtalk_mcps_per_spad = *pxtalk_mcps_per_spad
+ - ccompensation1;
+
+ if (*pxtalk_mcps_per_spad < cmin_xtalk_per_spad)
+ *pxtalk_mcps_per_spad = cmin_xtalk_per_spad;
+
+ }
+ LOG_FUNCTION_END("");
+
+ return status;
+}
+
+
+uint32_t bytes_to_int(uint8_t *data_bytes)
+{
+ /* Convert an array of 4 bytes to an integer.
+ */
+ uint32_t data = (uint32_t)data_bytes[0] << 24;
+ data += ((uint32_t)data_bytes[1] << 16);
+ data += ((uint32_t)data_bytes[2] << 8);
+ data += ((uint32_t)data_bytes[3]);
+ return data;
+}
+
+VL53L0_Error perform_histo_signal_meas(VL53L0_DEV dev,
+ WindowSelection window_select,
+ uint32_t *psignal_events)
+{
+ VL53L0_Error status = VL53L0_ERROR_NONE;
+ uint8_t data[8];
+ uint8_t readout_ctrl_val;
+ uint32_t bin_width = 3;
+
+ LOG_FUNCTION_START("");
+
+ /* Select Ambient or Total Signal Measurement
+ */
+ if (status == VL53L0_ERROR_NONE) {
+ readout_ctrl_val = bin_width;
+ if (window_select == VL53L0_AMBIENT_WINDOW_ONLY)
+ readout_ctrl_val += 0x80;
+
+ status = VL53L0_WrByte(
+ dev, VL53L0_REG_HISTOGRAM_CONFIG_READOUT_CTRL,
+ readout_ctrl_val);
+ }
+
+ /* Perform Measurement.
+ */
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_start_histogram_measurement(
+ dev, VL53L0_HISTOGRAMMODE_RETURN_ONLY, 0);
+
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_measurement_poll_for_completion(dev);
+
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_ClearInterruptMask(dev, 0);
+
+ /* Read Measurement Data.
+ */
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_WrByte(dev, 0xFF, VL53L0_REG_RESULT_CORE_PAGE);
+
+
+ if (status == VL53L0_ERROR_NONE) {
+ status = VL53L0_ReadMulti(dev,
+ (uint8_t)VL53L0_REG_RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN,
+ data,
+ 8);
+ }
+
+ if (status == VL53L0_ERROR_NONE)
+ status |= VL53L0_WrByte(dev, 0xFF, 0x00);
+
+
+ /* Take the sum of the Ambient and Signal Window Event readings.
+ */
+ if (status == VL53L0_ERROR_NONE)
+ *psignal_events = bytes_to_int(data) +
+ bytes_to_int(&(data[4]));
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L0_Error set_final_range_timeout_us(
+ VL53L0_DEV dev, uint32_t timeout_microSecs,
+ uint16_t final_range_vcsel_period_pclks)
+{
+ VL53L0_Error status = VL53L0_ERROR_NONE;
+ uint16_t final_range_timeout_mclks;
+ uint16_t final_range_encoded_timeOut;
+
+ LOG_FUNCTION_START("");
+
+ /* Calculate FINAL RANGE Timeout in Macro Periods (MCLKS)
+ */
+
+ /* convert timeout to mclks. */
+ final_range_timeout_mclks = VL53L0_calc_timeout_mclks(dev,
+ timeout_microSecs, (uint8_t) final_range_vcsel_period_pclks);
+
+ /* Encode timeout */
+ final_range_encoded_timeOut = VL53L0_encode_timeout(
+ final_range_timeout_mclks);
+
+ /* Write to device */
+ status = VL53L0_WrWord(dev,
+ VL53L0_REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI,
+ final_range_encoded_timeOut);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L0_Error perform_histogram_config(VL53L0_DEV dev,
+ uint32_t timeout_ms, uint16_t final_range_vcsel_period_pclks)
+{
+ VL53L0_Error status = VL53L0_ERROR_NONE;
+ uint8_t phaseSelect = 1;
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L0_ERROR_NONE)
+ status = set_final_range_timeout_us(
+ dev, timeout_ms * 1000, final_range_vcsel_period_pclks);
+
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_SetDeviceMode(dev,
+ VL53L0_DEVICEMODE_SINGLE_HISTOGRAM);
+
+
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_SetHistogramMode(dev,
+ VL53L0_HISTOGRAMMODE_BOTH);
+
+
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_WrByte(dev, VL53L0_REG_SYSTEM_HISTOGRAM_BIN,
+ 0x00);
+
+
+ /* Apply specific phase select for x-talk measurement */
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_WrByte(dev,
+ VL53L0_REG_HISTOGRAM_CONFIG_INITIAL_PHASE_SELECT,
+ phaseSelect);
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L0_Error VL53L0_perform_xtalk_measurement(VL53L0_DEV dev,
+ uint32_t timeout_ms, FixPoint1616_t *pxtalk_per_spad,
+ uint8_t *pambient_too_high)
+{
+ VL53L0_Error status = VL53L0_ERROR_NONE;
+ uint32_t signal_events = 0;
+ uint32_t amb_events = 0;
+ uint32_t meas_timing_budget_us;
+ VL53L0_DeviceModes device_mode;
+ uint8_t final_range_vcsel_period_pclks;
+ uint32_t max_spads;
+
+ /* Get Current DeviceMode */
+ status = VL53L0_GetDeviceMode(dev, &device_mode);
+
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_get_max_spads(dev, &max_spads,
+ pambient_too_high);
+
+ if (status != VL53L0_ERROR_NONE)
+ return status;
+
+
+ if (status == VL53L0_ERROR_NONE) {
+ status = VL53L0_GetVcselPulsePeriod(
+ dev,
+ VL53L0_VCSEL_PERIOD_FINAL_RANGE,
+ &final_range_vcsel_period_pclks);
+ }
+
+ if (status == VL53L0_ERROR_NONE) {
+ if (final_range_vcsel_period_pclks < 10)
+ status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+
+ if (status == VL53L0_ERROR_NONE) {
+ perform_histogram_config(
+ dev, timeout_ms, final_range_vcsel_period_pclks);
+ }
+
+ if (status == VL53L0_ERROR_NONE) {
+ status = perform_histo_signal_meas(
+ dev,
+ VL53L0_AMBIENT_WINDOW_ONLY,
+ &amb_events);
+ }
+
+ if (status == VL53L0_ERROR_NONE) {
+ status = perform_histo_signal_meas(
+ dev,
+ VL53L0_AMBIENT_AND_SIGNAL_WINDOW,
+ &signal_events);
+ }
+
+ if (status == VL53L0_ERROR_NONE) {
+ status = calc_xtalk_mcps_per_spad(
+ (signal_events - amb_events),
+ timeout_ms,
+ max_spads,
+ final_range_vcsel_period_pclks,
+ pxtalk_per_spad);
+ }
+
+ /* Revert previous device mode. */
+ if (status == VL53L0_ERROR_NONE)
+ status = VL53L0_SetDeviceMode(dev, device_mode);
+
+ /* Revert previous timing budget, to ensure previous final range vcsel
+ * period is applied.
+ */
+ if (status == VL53L0_ERROR_NONE) {
+ VL53L0_GETPARAMETERFIELD(
+ dev,
+ MeasurementTimingBudgetMicroSeconds,
+ meas_timing_budget_us);
+
+ status = VL53L0_SetMeasurementTimingBudgetMicroSeconds(
+ dev, meas_timing_budget_us);
+ }
+
+ return status;
+}
+
diff --git a/drivers/input/misc/vl53L0/src/vl53l0_api_ranging.c b/drivers/input/misc/vl53L0/src/vl53l0_api_ranging.c
new file mode 100644
index 000000000000..d1b065b00fe9
--- /dev/null
+++ b/drivers/input/misc/vl53L0/src/vl53l0_api_ranging.c
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ Copyright © 2016, STMicroelectronics International N.V.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+ NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+ IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ******************************************************************************/
+
+#include "vl53l0_api.h"
+#include "vl53l0_api_core.h"
+
+
+#ifndef __KERNEL__
+#include
+#endif
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(TRACE_MODULE_API, status, fmt, ##__VA_ARGS__)
+
diff --git a/drivers/input/misc/vl53L0/src/vl53l0_api_strings.c b/drivers/input/misc/vl53L0/src/vl53l0_api_strings.c
new file mode 100644
index 000000000000..eacdd9ae4959
--- /dev/null
+++ b/drivers/input/misc/vl53L0/src/vl53l0_api_strings.c
@@ -0,0 +1,448 @@
+/*******************************************************************************
+ Copyright © 2016, STMicroelectronics International N.V.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+ NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+ IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ******************************************************************************/
+
+#include "vl53l0_api.h"
+#include "vl53l0_api_core.h"
+#include "vl53l0_api_strings.h"
+
+#ifndef __KERNEL__
+#include
+#endif
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(TRACE_MODULE_API, status, fmt, ##__VA_ARGS__)
+
+
+VL53L0_Error VL53L0_check_part_used(VL53L0_DEV Dev,
+ uint8_t *Revision,
+ VL53L0_DeviceInfo_t *pVL53L0_DeviceInfo)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t ModuleIdInt;
+ char *ProductId_tmp;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L0_get_info_from_device(Dev, 2);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ ModuleIdInt = VL53L0_GETDEVICESPECIFICPARAMETER(Dev, ModuleId);
+
+ if (ModuleIdInt == 0) {
+ *Revision = 0;
+ VL53L0_COPYSTRING(pVL53L0_DeviceInfo->ProductId, "");
+ } else {
+ *Revision = VL53L0_GETDEVICESPECIFICPARAMETER(Dev, Revision);
+ ProductId_tmp = VL53L0_GETDEVICESPECIFICPARAMETER(Dev,
+ ProductId);
+ VL53L0_COPYSTRING(pVL53L0_DeviceInfo->ProductId, ProductId_tmp);
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_get_device_info(VL53L0_DEV Dev,
+ VL53L0_DeviceInfo_t *pVL53L0_DeviceInfo)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ uint8_t revision_id;
+ uint8_t Revision;
+
+ Status = VL53L0_check_part_used(Dev, &Revision, pVL53L0_DeviceInfo);
+
+ if (Status == VL53L0_ERROR_NONE) {
+ if (Revision == 0) {
+ VL53L0_COPYSTRING(pVL53L0_DeviceInfo->Name,
+ VL53L0_STRING_DEVICE_INFO_NAME_TS0);
+ } else if ((Revision <= 34) && (Revision != 32)) {
+ VL53L0_COPYSTRING(pVL53L0_DeviceInfo->Name,
+ VL53L0_STRING_DEVICE_INFO_NAME_TS1);
+ } else if (Revision < 39) {
+ VL53L0_COPYSTRING(pVL53L0_DeviceInfo->Name,
+ VL53L0_STRING_DEVICE_INFO_NAME_TS2);
+ } else {
+ VL53L0_COPYSTRING(pVL53L0_DeviceInfo->Name,
+ VL53L0_STRING_DEVICE_INFO_NAME_ES1);
+ }
+
+ VL53L0_COPYSTRING(pVL53L0_DeviceInfo->Type,
+ VL53L0_STRING_DEVICE_INFO_TYPE);
+
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdByte(Dev, VL53L0_REG_IDENTIFICATION_MODEL_ID,
+ &pVL53L0_DeviceInfo->ProductType);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ Status = VL53L0_RdByte(Dev,
+ VL53L0_REG_IDENTIFICATION_REVISION_ID,
+ &revision_id);
+ pVL53L0_DeviceInfo->ProductRevisionMajor = 1;
+ pVL53L0_DeviceInfo->ProductRevisionMinor =
+ (revision_id & 0xF0) >> 4;
+ }
+
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_get_device_error_string(VL53L0_DeviceError ErrorCode,
+ char *pDeviceErrorString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ switch (ErrorCode) {
+ case VL53L0_DEVICEERROR_NONE:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_NONE);
+ break;
+ case VL53L0_DEVICEERROR_VCSELCONTINUITYTESTFAILURE:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE);
+ break;
+ case VL53L0_DEVICEERROR_VCSELWATCHDOGTESTFAILURE:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE);
+ break;
+ case VL53L0_DEVICEERROR_NOVHVVALUEFOUND:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_NOVHVVALUEFOUND);
+ break;
+ case VL53L0_DEVICEERROR_MSRCNOTARGET:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_MSRCNOTARGET);
+ break;
+ case VL53L0_DEVICEERROR_SNRCHECK:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_SNRCHECK);
+ break;
+ case VL53L0_DEVICEERROR_RANGEPHASECHECK:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_RANGEPHASECHECK);
+ break;
+ case VL53L0_DEVICEERROR_SIGMATHRESHOLDCHECK:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK);
+ break;
+ case VL53L0_DEVICEERROR_TCC:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_TCC);
+ break;
+ case VL53L0_DEVICEERROR_PHASECONSISTENCY:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_PHASECONSISTENCY);
+ break;
+ case VL53L0_DEVICEERROR_MINCLIP:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_MINCLIP);
+ break;
+ case VL53L0_DEVICEERROR_RANGECOMPLETE:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_RANGECOMPLETE);
+ break;
+ case VL53L0_DEVICEERROR_ALGOUNDERFLOW:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_ALGOUNDERFLOW);
+ break;
+ case VL53L0_DEVICEERROR_ALGOOVERFLOW:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_ALGOOVERFLOW);
+ break;
+ case VL53L0_DEVICEERROR_RANGEIGNORETHRESHOLD:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD);
+ break;
+
+ default:
+ VL53L0_COPYSTRING(pDeviceErrorString,
+ VL53L0_STRING_UNKNOW_ERROR_CODE);
+
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_get_range_status_string(uint8_t RangeStatus,
+ char *pRangeStatusString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ switch (RangeStatus) {
+ case 0:
+ VL53L0_COPYSTRING(pRangeStatusString,
+ VL53L0_STRING_RANGESTATUS_RANGEVALID);
+ break;
+ case 1:
+ VL53L0_COPYSTRING(pRangeStatusString,
+ VL53L0_STRING_RANGESTATUS_SIGMA);
+ break;
+ case 2:
+ VL53L0_COPYSTRING(pRangeStatusString,
+ VL53L0_STRING_RANGESTATUS_SIGNAL);
+ break;
+ case 3:
+ VL53L0_COPYSTRING(pRangeStatusString,
+ VL53L0_STRING_RANGESTATUS_MINRANGE);
+ break;
+ case 4:
+ VL53L0_COPYSTRING(pRangeStatusString,
+ VL53L0_STRING_RANGESTATUS_PHASE);
+ break;
+ case 5:
+ VL53L0_COPYSTRING(pRangeStatusString,
+ VL53L0_STRING_RANGESTATUS_HW);
+ break;
+
+ default: /**/
+ VL53L0_COPYSTRING(pRangeStatusString,
+ VL53L0_STRING_RANGESTATUS_NONE);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_get_pal_error_string(VL53L0_Error PalErrorCode,
+ char *pPalErrorString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ switch (PalErrorCode) {
+ case VL53L0_ERROR_NONE:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_NONE);
+ break;
+ case VL53L0_ERROR_CALIBRATION_WARNING:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_CALIBRATION_WARNING);
+ break;
+ case VL53L0_ERROR_MIN_CLIPPED:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_MIN_CLIPPED);
+ break;
+ case VL53L0_ERROR_UNDEFINED:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_UNDEFINED);
+ break;
+ case VL53L0_ERROR_INVALID_PARAMS:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_INVALID_PARAMS);
+ break;
+ case VL53L0_ERROR_NOT_SUPPORTED:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_NOT_SUPPORTED);
+ break;
+ case VL53L0_ERROR_RANGE_ERROR:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_RANGE_ERROR);
+ break;
+ case VL53L0_ERROR_TIME_OUT:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_TIME_OUT);
+ break;
+ case VL53L0_ERROR_MODE_NOT_SUPPORTED:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_MODE_NOT_SUPPORTED);
+ break;
+ case VL53L0_ERROR_BUFFER_TOO_SMALL:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_BUFFER_TOO_SMALL);
+ break;
+ case VL53L0_ERROR_GPIO_NOT_EXISTING:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_GPIO_NOT_EXISTING);
+ break;
+ case VL53L0_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED);
+ break;
+ case VL53L0_ERROR_CONTROL_INTERFACE:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_CONTROL_INTERFACE);
+ break;
+ case VL53L0_ERROR_INVALID_COMMAND:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_INVALID_COMMAND);
+ break;
+ case VL53L0_ERROR_DIVISION_BY_ZERO:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_DIVISION_BY_ZERO);
+ break;
+ case VL53L0_ERROR_REF_SPAD_INIT:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_REF_SPAD_INIT);
+ break;
+ case VL53L0_ERROR_NOT_IMPLEMENTED:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_ERROR_NOT_IMPLEMENTED);
+ break;
+
+ default:
+ VL53L0_COPYSTRING(pPalErrorString,
+ VL53L0_STRING_UNKNOW_ERROR_CODE);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_get_pal_state_string(VL53L0_State PalStateCode,
+ char *pPalStateString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ switch (PalStateCode) {
+ case VL53L0_STATE_POWERDOWN:
+ VL53L0_COPYSTRING(pPalStateString,
+ VL53L0_STRING_STATE_POWERDOWN);
+ break;
+ case VL53L0_STATE_WAIT_STATICINIT:
+ VL53L0_COPYSTRING(pPalStateString,
+ VL53L0_STRING_STATE_WAIT_STATICINIT);
+ break;
+ case VL53L0_STATE_STANDBY:
+ VL53L0_COPYSTRING(pPalStateString,
+ VL53L0_STRING_STATE_STANDBY);
+ break;
+ case VL53L0_STATE_IDLE:
+ VL53L0_COPYSTRING(pPalStateString,
+ VL53L0_STRING_STATE_IDLE);
+ break;
+ case VL53L0_STATE_RUNNING:
+ VL53L0_COPYSTRING(pPalStateString,
+ VL53L0_STRING_STATE_RUNNING);
+ break;
+ case VL53L0_STATE_UNKNOWN:
+ VL53L0_COPYSTRING(pPalStateString,
+ VL53L0_STRING_STATE_UNKNOWN);
+ break;
+ case VL53L0_STATE_ERROR:
+ VL53L0_COPYSTRING(pPalStateString,
+ VL53L0_STRING_STATE_ERROR);
+ break;
+
+ default:
+ VL53L0_COPYSTRING(pPalStateString,
+ VL53L0_STRING_STATE_UNKNOWN);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L0_Error VL53L0_get_sequence_steps_info(
+ VL53L0_SequenceStepId SequenceStepId,
+ char *pSequenceStepsString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ switch (SequenceStepId) {
+ case VL53L0_SEQUENCESTEP_TCC:
+ VL53L0_COPYSTRING(pSequenceStepsString,
+ VL53L0_STRING_SEQUENCESTEP_TCC);
+ break;
+ case VL53L0_SEQUENCESTEP_DSS:
+ VL53L0_COPYSTRING(pSequenceStepsString,
+ VL53L0_STRING_SEQUENCESTEP_DSS);
+ break;
+ case VL53L0_SEQUENCESTEP_MSRC:
+ VL53L0_COPYSTRING(pSequenceStepsString,
+ VL53L0_STRING_SEQUENCESTEP_MSRC);
+ break;
+ case VL53L0_SEQUENCESTEP_PRE_RANGE:
+ VL53L0_COPYSTRING(pSequenceStepsString,
+ VL53L0_STRING_SEQUENCESTEP_PRE_RANGE);
+ break;
+ case VL53L0_SEQUENCESTEP_FINAL_RANGE:
+ VL53L0_COPYSTRING(pSequenceStepsString,
+ VL53L0_STRING_SEQUENCESTEP_FINAL_RANGE);
+ break;
+
+ default:
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+ }
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_get_limit_check_info(VL53L0_DEV Dev, uint16_t LimitCheckId,
+ char *pLimitCheckString)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ switch (LimitCheckId) {
+ case VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE:
+ VL53L0_COPYSTRING(pLimitCheckString,
+ VL53L0_STRING_CHECKENABLE_SIGMA_FINAL_RANGE);
+ break;
+ case VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+ VL53L0_COPYSTRING(pLimitCheckString,
+ VL53L0_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE);
+ break;
+ case VL53L0_CHECKENABLE_SIGNAL_REF_CLIP:
+ VL53L0_COPYSTRING(pLimitCheckString,
+ VL53L0_STRING_CHECKENABLE_SIGNAL_REF_CLIP);
+ break;
+ case VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
+ VL53L0_COPYSTRING(pLimitCheckString,
+ VL53L0_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD);
+ break;
+
+ default:
+ VL53L0_COPYSTRING(pLimitCheckString,
+ VL53L0_STRING_UNKNOW_ERROR_CODE);
+
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
diff --git a/drivers/input/misc/vl53L0/src/vl53l0_i2c_platform.c b/drivers/input/misc/vl53L0/src/vl53l0_i2c_platform.c
new file mode 100644
index 000000000000..a86287b9a6d2
--- /dev/null
+++ b/drivers/input/misc/vl53L0/src/vl53l0_i2c_platform.c
@@ -0,0 +1,379 @@
+/*
+ * COPYRIGHT (C) STMicroelectronics 2015. All rights reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * STMicroelectronics ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with STMicroelectronics
+ *
+ * Programming Golden Rule: Keep it Simple!
+ *
+ */
+
+/*!
+ * \file VL53L0_platform.c
+ * \brief Code function defintions for EWOK Platform Layer
+ *
+ */
+
+
+#include
+#include
+#include
+#include "stmvl53l0-i2c.h"
+#include "stmvl53l0-cci.h"
+
+#include "vl53l0_platform.h"
+#include "vl53l0_i2c_platform.h"
+#include "vl53l0_def.h"
+
+#include "vl53l0_platform_log.h"
+
+#ifdef VL53L0_LOG_ENABLE
+#define trace_print(level, ...) \
+ trace_print_module_function(TRACE_MODULE_PLATFORM, level,\
+ TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+#define trace_i2c(...) \
+ trace_print_module_function(TRACE_MODULE_NONE, \
+ TRACE_LEVEL_NONE, TRACE_FUNCTION_I2C, ##__VA_ARGS__)
+#endif
+
+/**
+ * @def I2C_BUFFER_CONFIG
+ *
+ * @brief Configure Device register I2C access
+ *
+ * @li 0 : one GLOBAL buffer \n
+ * Use one global buffer of MAX_I2C_XFER_SIZE byte in data space \n
+ * This solution is not multi-Device compliant nor multi-thread cpu safe \n
+ * It can be the best option for small 8/16 bit MCU without stack and limited
+ * ram (STM8s, 80C51 ...)
+ *
+ * @li 1 : ON_STACK/local \n
+ * Use local variable (on stack) buffer \n
+ * This solution is multi-thread with use of i2c resource lock or mutex see
+ * VL6180x_GetI2CAccess() \n
+ *
+ * @li 2 : User defined \n
+ * Per Device potentially dynamic allocated. Requires VL6180x_GetI2cBuffer()
+ * to be implemented.
+ * @ingroup Configuration
+ */
+#define I2C_BUFFER_CONFIG 1
+
+#if I2C_BUFFER_CONFIG == 0
+ /* GLOBAL config buffer */
+ uint8_t i2c_global_buffer[VL53L0_MAX_I2C_XFER_SIZE];
+
+ #define DECL_I2C_BUFFER
+ #define VL53L0_GetLocalBuffer(Dev, n_byte) i2c_global_buffer
+
+#elif I2C_BUFFER_CONFIG == 1
+ /* ON STACK */
+ uint8_t LocBuffer[VL53L0_MAX_I2C_XFER_SIZE];
+ #define VL53L0_GetLocalBuffer(Dev, n_byte) LocBuffer
+#elif I2C_BUFFER_CONFIG == 2
+ /* user define buffer type declare DECL_I2C_BUFFER as access via
+ VL53L0_GetLocalBuffer */
+ #define DECL_I2C_BUFFER
+#else
+#error "invalid I2C_BUFFER_CONFIG "
+#endif
+
+
+#define VL53L0_I2C_USER_VAR /* none but could be for a flag var to
+ get/pass to mutex interruptible return flags and try again */
+#define VL53L0_GetI2CAccess(Dev) /* todo mutex acquire */
+#define VL53L0_DoneI2CAcces(Dev) /* todo mutex release */
+
+
+char debug_string[VL53L0_MAX_STRING_LENGTH_PLT];
+
+
+#define MIN_COMMS_VERSION_MAJOR 1
+#define MIN_COMMS_VERSION_MINOR 8
+#define MIN_COMMS_VERSION_BUILD 1
+#define MIN_COMMS_VERSION_REVISION 0
+
+#define STATUS_OK 0x00
+#define STATUS_FAIL 0x01
+
+bool_t _check_min_version(void)
+{
+ bool_t min_version_comms_dll = false;
+
+ min_version_comms_dll = true;
+
+ return min_version_comms_dll;
+}
+
+int32_t VL53L0_comms_initialise(uint8_t comms_type, uint16_t comms_speed_khz)
+{
+ int32_t status = STATUS_OK;
+
+ return status;
+}
+
+int32_t VL53L0_comms_close(void)
+{
+ int32_t status = STATUS_OK;
+
+
+ return status;
+}
+
+int32_t VL53L0_set_page(VL53L0_DEV dev, uint8_t page_data)
+{
+ int32_t status = STATUS_OK;
+ uint16_t page_index = 0xFF;
+ uint8_t *buffer;
+
+ buffer = VL53L0_GetLocalBuffer(dev, 3);
+ buffer[0] = page_index >> 8;
+ buffer[1] = page_index & 0xff;
+ buffer[2] = page_data;
+
+ status = VL53L0_I2CWrite(dev, buffer, (uint8_t) 3);
+ return status;
+}
+
+int32_t VL53L0_write_multi(VL53L0_DEV dev, uint8_t index, uint8_t *pdata,
+ int32_t count)
+{
+ int32_t status = STATUS_OK;
+ uint8_t *buffer;
+
+#ifdef VL53L0_LOG_ENABLE
+ int32_t i = 0;
+ char value_as_str[VL53L0_MAX_STRING_LENGTH_PLT];
+ char *pvalue_as_str;
+
+ pvalue_as_str = value_as_str;
+
+ for (i = 0 ; i < count ; i++) {
+ snprintf(pvalue_as_str, sizeof(pvalue_as_str),
+ "%02X", *(pdata + i));
+
+ pvalue_as_str += 2;
+ }
+ trace_i2c("Write reg : 0x%04X, Val : 0x%s\n", index, value_as_str);
+#endif
+ if ((count + 1) > VL53L0_MAX_I2C_XFER_SIZE)
+ return STATUS_FAIL;
+ buffer = VL53L0_GetLocalBuffer(dev, (count+1));
+ buffer[0] = index;
+ memcpy(&buffer[1], pdata, count);
+ status = VL53L0_I2CWrite(dev, buffer, (count+1));
+
+ return status;
+}
+
+int32_t VL53L0_read_multi(VL53L0_DEV dev, uint8_t index, uint8_t *pdata,
+ int32_t count)
+{
+ int32_t status = STATUS_OK;
+ uint8_t *buffer;
+
+#ifdef VL53L0_LOG_ENABLE
+ int32_t i = 0;
+ char value_as_str[VL53L0_MAX_STRING_LENGTH_PLT];
+ char *pvalue_as_str;
+#endif
+
+ if ((count + 1) > VL53L0_MAX_I2C_XFER_SIZE)
+ return STATUS_FAIL;
+
+ buffer = VL53L0_GetLocalBuffer(dev, 1);
+ buffer[0] = index;
+ status = VL53L0_I2CWrite(dev, (uint8_t *)buffer, (uint8_t)1);
+ if (!status) {
+ pdata[0] = index;
+ status = VL53L0_I2CRead(dev, pdata, count);
+ }
+
+#ifdef VL53L0_LOG_ENABLE
+ pvalue_as_str = value_as_str;
+
+ for (i = 0 ; i < count ; i++) {
+ snprintf(pvalue_as_str, sizeof(value_as_str),
+ "%02X", *(pdata+i));
+ pvalue_as_str += 2;
+ }
+
+ trace_i2c("Read reg : 0x%04X, Val : 0x%s\n", index, value_as_str);
+#endif
+
+ return status;
+}
+
+
+int32_t VL53L0_write_byte(VL53L0_DEV dev, uint8_t index, uint8_t data)
+{
+ int32_t status = STATUS_OK;
+ const int32_t cbyte_count = 1;
+
+ status = VL53L0_write_multi(dev, index, &data, cbyte_count);
+
+ return status;
+
+}
+
+
+int32_t VL53L0_write_word(VL53L0_DEV dev, uint8_t index, uint16_t data)
+{
+ int32_t status = STATUS_OK;
+
+ uint8_t buffer[BYTES_PER_WORD];
+
+ /* Split 16-bit word into MS and LS uint8_t */
+ buffer[0] = (uint8_t)(data >> 8);
+ buffer[1] = (uint8_t)(data & 0x00FF);
+
+ status = VL53L0_write_multi(dev, index, buffer, BYTES_PER_WORD);
+
+ return status;
+
+}
+
+
+int32_t VL53L0_write_dword(VL53L0_DEV dev, uint8_t index, uint32_t data)
+{
+ int32_t status = STATUS_OK;
+ uint8_t buffer[BYTES_PER_DWORD];
+
+ /* Split 32-bit word into MS ... LS bytes */
+ buffer[0] = (uint8_t) (data >> 24);
+ buffer[1] = (uint8_t)((data & 0x00FF0000) >> 16);
+ buffer[2] = (uint8_t)((data & 0x0000FF00) >> 8);
+ buffer[3] = (uint8_t) (data & 0x000000FF);
+
+ status = VL53L0_write_multi(dev, index, buffer, BYTES_PER_DWORD);
+
+ return status;
+
+}
+
+
+int32_t VL53L0_read_byte(VL53L0_DEV dev, uint8_t index, uint8_t *pdata)
+{
+ int32_t status = STATUS_OK;
+ int32_t cbyte_count = 1;
+
+ status = VL53L0_read_multi(dev, index, pdata, cbyte_count);
+
+ return status;
+
+}
+
+
+int32_t VL53L0_read_word(VL53L0_DEV dev, uint8_t index, uint16_t *pdata)
+{
+ int32_t status = STATUS_OK;
+ uint8_t buffer[BYTES_PER_WORD];
+
+ status = VL53L0_read_multi(dev, index, buffer, BYTES_PER_WORD);
+ *pdata = ((uint16_t)buffer[0]<<8) + (uint16_t)buffer[1];
+
+ return status;
+
+}
+
+int32_t VL53L0_read_dword(VL53L0_DEV dev, uint8_t index, uint32_t *pdata)
+{
+ int32_t status = STATUS_OK;
+ uint8_t buffer[BYTES_PER_DWORD];
+
+ status = VL53L0_read_multi(dev, index, buffer, BYTES_PER_DWORD);
+ *pdata = ((uint32_t)buffer[0]<<24) + ((uint32_t)buffer[1]<<16) +
+ ((uint32_t)buffer[2]<<8) + (uint32_t)buffer[3];
+
+ return status;
+
+}
+
+int32_t VL53L0_platform_wait_us(int32_t wait_us)
+{
+ int32_t status = STATUS_OK;
+
+ msleep((wait_us/1000));
+
+#ifdef VL53L0_LOG_ENABLE
+ trace_i2c("Wait us : %6d\n", wait_us);
+#endif
+
+ return status;
+
+}
+
+
+int32_t VL53L0_wait_ms(int32_t wait_ms)
+{
+ int32_t status = STATUS_OK;
+
+ msleep(wait_ms);
+
+#ifdef VL53L0_LOG_ENABLE
+ trace_i2c("Wait ms : %6d\n", wait_ms);
+#endif
+
+ return status;
+
+}
+
+
+int32_t VL53L0_set_gpio(uint8_t level)
+{
+ int32_t status = STATUS_OK;
+#ifdef VL53L0_LOG_ENABLE
+ trace_i2c("// Set GPIO = %d;\n", level);
+#endif
+
+ return status;
+
+}
+
+
+int32_t VL53L0_get_gpio(uint8_t *plevel)
+{
+ int32_t status = STATUS_OK;
+#ifdef VL53L0_LOG_ENABLE
+ trace_i2c("// Get GPIO = %d;\n", *plevel);
+#endif
+ return status;
+}
+
+
+int32_t VL53L0_release_gpio(void)
+{
+ int32_t status = STATUS_OK;
+#ifdef VL53L0_LOG_ENABLE
+ trace_i2c("// Releasing force on GPIO\n");
+#endif
+ return status;
+
+}
+
+int32_t VL53L0_cycle_power(void)
+{
+ int32_t status = STATUS_OK;
+#ifdef VL53L0_LOG_ENABLE
+ trace_i2c("// cycle sensor power\n");
+#endif
+
+ return status;
+}
+
+
+int32_t VL53L0_get_timer_frequency(int32_t *ptimer_freq_hz)
+{
+ *ptimer_freq_hz = 0;
+ return STATUS_FAIL;
+}
+
+
+int32_t VL53L0_get_timer_value(int32_t *ptimer_count)
+{
+ *ptimer_count = 0;
+ return STATUS_FAIL;
+}
diff --git a/drivers/input/misc/vl53L0/src/vl53l0_platform.c b/drivers/input/misc/vl53L0/src/vl53l0_platform.c
new file mode 100644
index 000000000000..e971b4813e6d
--- /dev/null
+++ b/drivers/input/misc/vl53L0/src/vl53l0_platform.c
@@ -0,0 +1,242 @@
+/*******************************************************************************
+Copyright © 2016, STMicroelectronics International N.V.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+
+/**
+ * @file VL53L0_i2c.c
+ *
+ * Copyright (C) 2014 ST MicroElectronics
+ *
+ * provide variable word size byte/Word/dword VL6180x register access via i2c
+ *
+ */
+#include "vl53l0_platform.h"
+#include "vl53l0_i2c_platform.h"
+#include "vl53l0_api.h"
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(TRACE_MODULE_PLATFORM, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(TRACE_MODULE_PLATFORM, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...)\
+ _LOG_FUNCTION_END_FMT(TRACE_MODULE_PLATFORM, status,\
+ fmt, ##__VA_ARGS__)
+
+
+
+VL53L0_Error VL53L0_LockSequenceAccess(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_UnlockSequenceAccess(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ return Status;
+}
+
+/* the ranging_sensor_comms.dll will take care of the page selection */
+VL53L0_Error VL53L0_WriteMulti(VL53L0_DEV Dev, uint8_t index,
+ uint8_t *pdata, uint32_t count)
+{
+
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int32_t status_int = 0;
+ uint8_t deviceAddress;
+
+ if (count >= VL53L0_MAX_I2C_XFER_SIZE)
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+
+
+ deviceAddress = Dev->I2cDevAddr;
+
+ status_int = VL53L0_write_multi(Dev, index, pdata, count);
+
+ if (status_int != 0)
+ Status = VL53L0_ERROR_CONTROL_INTERFACE;
+
+ return Status;
+}
+
+/* the ranging_sensor_comms.dll will take care of the page selection */
+VL53L0_Error VL53L0_ReadMulti(VL53L0_DEV Dev, uint8_t index,
+ uint8_t *pdata, uint32_t count)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int32_t status_int;
+ uint8_t deviceAddress;
+
+ if (count >= VL53L0_MAX_I2C_XFER_SIZE)
+ Status = VL53L0_ERROR_INVALID_PARAMS;
+
+
+ deviceAddress = Dev->I2cDevAddr;
+
+ status_int = VL53L0_read_multi(Dev, index, pdata, count);
+
+ if (status_int != 0)
+ Status = VL53L0_ERROR_CONTROL_INTERFACE;
+
+ return Status;
+}
+
+
+VL53L0_Error VL53L0_WrByte(VL53L0_DEV Dev, uint8_t index, uint8_t data)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int32_t status_int;
+ uint8_t deviceAddress;
+
+ deviceAddress = Dev->I2cDevAddr;
+
+ status_int = VL53L0_write_byte(Dev, index, data);
+
+ if (status_int != 0)
+ Status = VL53L0_ERROR_CONTROL_INTERFACE;
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_WrWord(VL53L0_DEV Dev, uint8_t index, uint16_t data)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int32_t status_int;
+ uint8_t deviceAddress;
+
+ deviceAddress = Dev->I2cDevAddr;
+
+ status_int = VL53L0_write_word(Dev, index, data);
+
+ if (status_int != 0)
+ Status = VL53L0_ERROR_CONTROL_INTERFACE;
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_WrDWord(VL53L0_DEV Dev, uint8_t index, uint32_t data)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int32_t status_int;
+ uint8_t deviceAddress;
+
+ deviceAddress = Dev->I2cDevAddr;
+
+ status_int = VL53L0_write_dword(Dev, index, data);
+
+ if (status_int != 0)
+ Status = VL53L0_ERROR_CONTROL_INTERFACE;
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_UpdateByte(VL53L0_DEV Dev, uint8_t index,
+ uint8_t AndData, uint8_t OrData)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int32_t status_int;
+ uint8_t deviceAddress;
+ uint8_t data;
+
+ deviceAddress = Dev->I2cDevAddr;
+
+ status_int = VL53L0_read_byte(Dev, index, &data);
+
+ if (status_int != 0)
+ Status = VL53L0_ERROR_CONTROL_INTERFACE;
+
+ if (Status == VL53L0_ERROR_NONE) {
+ data = (data & AndData) | OrData;
+ status_int = VL53L0_write_byte(Dev, index, data);
+
+ if (status_int != 0)
+ Status = VL53L0_ERROR_CONTROL_INTERFACE;
+ }
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_RdByte(VL53L0_DEV Dev, uint8_t index, uint8_t *data)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int32_t status_int;
+ uint8_t deviceAddress;
+
+ deviceAddress = Dev->I2cDevAddr;
+
+ status_int = VL53L0_read_byte(Dev, index, data);
+
+ if (status_int != 0)
+ Status = VL53L0_ERROR_CONTROL_INTERFACE;
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_RdWord(VL53L0_DEV Dev, uint8_t index, uint16_t *data)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int32_t status_int;
+ uint8_t deviceAddress;
+
+ deviceAddress = Dev->I2cDevAddr;
+
+ status_int = VL53L0_read_word(Dev, index, data);
+
+ if (status_int != 0)
+ Status = VL53L0_ERROR_CONTROL_INTERFACE;
+
+ return Status;
+}
+
+VL53L0_Error VL53L0_RdDWord(VL53L0_DEV Dev, uint8_t index, uint32_t *data)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ int32_t status_int;
+ uint8_t deviceAddress;
+
+ deviceAddress = Dev->I2cDevAddr;
+
+ status_int = VL53L0_read_dword(Dev, index, data);
+
+ if (status_int != 0)
+ Status = VL53L0_ERROR_CONTROL_INTERFACE;
+
+ return Status;
+}
+
+#define VL53L0_POLLINGDELAY_LOOPNB 250
+VL53L0_Error VL53L0_PollingDelay(VL53L0_DEV Dev)
+{
+ VL53L0_Error status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+ udelay(1000);
+ LOG_FUNCTION_END(status);
+ return status;
+}
diff --git a/drivers/input/misc/vl53L0/src/vl53l0_port_i2c.c b/drivers/input/misc/vl53L0/src/vl53l0_port_i2c.c
new file mode 100644
index 000000000000..1346de0cbd18
--- /dev/null
+++ b/drivers/input/misc/vl53L0/src/vl53l0_port_i2c.c
@@ -0,0 +1,150 @@
+/*
+ * vl53l0_port_i2c.c
+ *
+ * Created on: July, 2015
+ * Author: Teresa Tao
+ */
+
+#include
+#include
+#include "stmvl53l0-i2c.h"
+#include "stmvl53l0-cci.h"
+#include "vl53l0_platform.h"
+#include "vl53l0_i2c_platform.h"
+#include "stmvl53l0.h"
+
+#define I2C_M_WR 0x00
+#define STATUS_OK 0x00
+#define STATUS_FAIL (-1)
+/** int VL53L0_I2CWrite(VL53L0_Dev_t dev, void *buff, uint8_t len);
+ * @brief Write data buffer to VL53L0 device via i2c
+ * @param dev The device to write to
+ * @param buff The data buffer
+ * @param len The length of the transaction in byte
+ * @return 0 on success
+ */
+int VL53L0_I2CWrite(VL53L0_DEV dev, uint8_t *buff, uint8_t len)
+{
+
+
+ int err = 0;
+ if (dev->bus_type == CCI_BUS) {
+#ifdef CAMERA_CCI
+ uint16_t index;
+ struct cci_data *cci_client_obj =
+ (struct cci_data *)dev->client_object;
+ struct msm_camera_i2c_client *client = cci_client_obj->client;
+
+ index = buff[0];
+ /*pr_err("%s: index: %d len: %d\n", __func__, index, len); */
+
+ if (len == 2) {
+ uint8_t data;
+
+ data = buff[1];
+ /* for byte access */
+ err = client->i2c_func_tbl->i2c_write(client, index,
+ data, MSM_CAMERA_I2C_BYTE_DATA);
+ if (err < 0) {
+ pr_err("%s:%d failed status=%d\n",
+ __func__, __LINE__, err);
+ return err;
+ }
+ } else if (len == 3) {
+ uint16_t data;
+
+ data = ((uint16_t)buff[1] << 8) | (uint16_t)buff[2];
+ err = client->i2c_func_tbl->i2c_write(client, index,
+ data, MSM_CAMERA_I2C_WORD_DATA);
+ if (err < 0) {
+ pr_err("%s:%d failed status=%d\n",
+ __func__, __LINE__, err);
+ return err;
+ }
+ } else if (len >= 5) {
+ err = client->i2c_func_tbl->i2c_write_seq(client,
+ index, &buff[1], (len-1));
+ if (err < 0) {
+ pr_err("%s:%d failed status=%d\n",
+ __func__, __LINE__, err);
+ return err;
+ }
+
+ }
+#endif
+ } else {
+ struct i2c_msg msg[1];
+ struct i2c_data *i2c_client_obj =
+ (struct i2c_data *)dev->client_object;
+ struct i2c_client *client = (struct i2c_client*)i2c_client_obj->client;
+
+ msg[0].addr = client->addr;
+ msg[0].flags = I2C_M_WR;
+ msg[0].buf = buff;
+ msg[0].len = len;
+
+ err = i2c_transfer(client->adapter, msg, 1);
+ /* return the actual messages transfer */
+ if (err != 1) {
+ pr_err("%s: i2c_transfer err:%d, addr:0x%x, reg:0x%x\n",
+ __func__, err, client->addr,
+ (buff[0] << 8 | buff[1]));
+ return STATUS_FAIL;
+ }
+ }
+
+ return 0;
+}
+
+
+/** int VL53L0_I2CRead(VL53L0_Dev_t dev, void *buff, uint8_t len);
+ * @brief Read data buffer from VL53L0 device via i2c
+ * @param dev The device to read from
+ * @param buff The data buffer to fill
+ * @param len The length of the transaction in byte
+ * @return transaction status
+ */
+int VL53L0_I2CRead(VL53L0_DEV dev, uint8_t *buff, uint8_t len)
+{
+
+ int err = 0;
+
+ if (dev->bus_type == CCI_BUS) {
+#ifdef CAMERA_CCI
+ uint16_t index;
+ struct cci_data *cci_client_obj =
+ (struct cci_data *)dev->client_object;
+ struct msm_camera_i2c_client *client = cci_client_obj->client;
+
+ index = buff[0];
+ /* pr_err("%s: index: %d\n", __func__, index); */
+ err = client->i2c_func_tbl->i2c_read_seq(client,
+ index, buff, len);
+ if (err < 0) {
+ pr_err("%s:%d failed status=%d\n",
+ __func__, __LINE__, err);
+ return err;
+ }
+#endif
+ } else {
+ struct i2c_msg msg[1];
+ struct i2c_data *i2c_client_obj =
+ (struct i2c_data *)dev->client_object;
+ struct i2c_client *client = (struct i2c_client*) i2c_client_obj->client;
+
+ msg[0].addr = client->addr;
+ msg[0].flags = I2C_M_RD|client->flags;
+ msg[0].buf = buff;
+ msg[0].len = len;
+
+ err = i2c_transfer(client->adapter, &msg[0], 1);
+ /* return the actual mesage transfer */
+ if (err != 1) {
+ pr_err("%s: Read i2c_transfer err:%d, addr:0x%x\n",
+ __func__, err, client->addr);
+ return STATUS_FAIL;
+ }
+ }
+
+ return 0;
+}
diff --git a/drivers/input/misc/vl53L0/src/vl53l0_tuning.c b/drivers/input/misc/vl53L0/src/vl53l0_tuning.c
new file mode 100644
index 000000000000..2efca96a7713
--- /dev/null
+++ b/drivers/input/misc/vl53L0/src/vl53l0_tuning.c
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ Copyright © 2015, STMicroelectronics International N.V.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of STMicroelectronics nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+ NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
+ IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ******************************************************************************/
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(TRACE_MODULE_API, status, fmt, ##__VA_ARGS__)
+
+#ifdef VL53L0_LOG_ENABLE
+#define trace_print(level, ...) \
+ trace_print_module_function(TRACE_MODULE_API,\
+ level, TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+#endif
+
+/*
+//////////////////////////////////////////////////////
+//// DEFAULT TUNING SETTINGS ////
+//////////////////////////////////////////////////////
+*/
+/*VL53L0_Error VL53L0_load_tuning_settings(VL53L0_DEV Dev)
+{
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x91, 0x3C);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x54, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x33, 0x05);
+ Status |= VL53L0_WrByte(Dev, 0x32, 0x03);
+ Status |= VL53L0_WrByte(Dev, 0x30, 0x05);
+ Status |= VL53L0_WrByte(Dev, 0x50, 0x05);
+ Status |= VL53L0_WrByte(Dev, 0x60, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x70, 0x06);
+
+ Status |= VL53L0_WrByte(Dev, 0x46, 0x1a);
+ Status |= VL53L0_WrWord(Dev, 0x51, 0x01a3);
+ Status |= VL53L0_WrWord(Dev, 0x61, 0x01c4);
+ Status |= VL53L0_WrWord(Dev, 0x71, 0x018c);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x31, 0x0f);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x66, 0x38);
+
+ Status |= VL53L0_WrByte(Dev, 0x47, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x48, 0xff);
+ Status |= VL53L0_WrByte(Dev, 0x57, 0x4c);
+ Status |= VL53L0_WrByte(Dev, 0x67, 0x3c);
+ Status |= VL53L0_WrByte(Dev, 0x77, 0x5c);
+
+ Status |= VL53L0_WrWord(Dev, 0x44, 0x0000);
+
+ Status |= VL53L0_WrByte(Dev, 0x27, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x55, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x30, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0x10, 0x0f);
+ Status |= VL53L0_WrByte(Dev, 0x11, 0xff);
+ Status |= VL53L0_WrByte(Dev, 0x41, 0xff);
+ Status |= VL53L0_WrByte(Dev, 0x42, 0x07);
+ Status |= VL53L0_WrByte(Dev, 0x43, 0x12);
+
+ Status |= VL53L0_WrByte(Dev, 0x20, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x21, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0x28, 0x06);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x48, 0x28);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0x7a, 0x0a);
+ Status |= VL53L0_WrByte(Dev, 0x7b, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x78, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x44, 0xff);
+ Status |= VL53L0_WrByte(Dev, 0x45, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x46, 0x10);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0x04, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x05, 0x04);
+ Status |= VL53L0_WrByte(Dev, 0x06, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x07, 0x00);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x0d, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+ Status |= VL53L0_WrByte(Dev, 0x80, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x01, 0xF8);
+
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x8e, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0x00, 0x01);
+ Status |= VL53L0_WrByte(Dev, 0xFF, 0x00);
+
+
+ if (Status != 0)
+ Status = VL53L0_ERROR_CONTROL_INTERFACE;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+*/
diff --git a/drivers/input/misc/vl53L0/stmvl53l0-cci.h b/drivers/input/misc/vl53L0/stmvl53l0-cci.h
new file mode 100644
index 000000000000..d8c3b778a04d
--- /dev/null
+++ b/drivers/input/misc/vl53L0/stmvl53l0-cci.h
@@ -0,0 +1,65 @@
+/*
+ * stmvl53l0-cci.h - Linux kernel modules for STM VL53L0 FlightSense TOF sensor
+ *
+ * Copyright (C) 2015 STMicroelectronics Imaging Division
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/*
+ * Defines
+ */
+#ifndef STMVL53L0_CCI_H
+#define STMVL53L0_CCI_H
+#include
+
+#include
+#include "msm_camera_i2c.h"
+#include "msm_camera_dt_util.h"
+#include "msm_camera_io_util.h"
+#include "msm_cci.h"
+
+#define MSM_TOF_MAX_VREGS (10)
+
+struct msm_tof_vreg {
+ struct camera_vreg_t *cam_vreg;
+ void *data[MSM_TOF_MAX_VREGS];
+ int num_vreg;
+};
+
+struct cci_data {
+ struct msm_camera_i2c_client g_client;
+ struct msm_camera_i2c_client *client;
+ struct platform_device *pdev;
+ enum msm_camera_device_type_t device_type;
+ enum cci_i2c_master_t cci_master;
+ struct msm_tof_vreg vreg_cfg;
+ struct msm_sd_subdev msm_sd;
+ struct v4l2_subdev sdev;
+ struct v4l2_subdev_ops *subdev_ops;
+ char subdev_initialized;
+ uint32_t subdev_id;
+ uint8_t power_up;
+ uint32_t lowv;
+ uint32_t highv;
+ uint32_t xtalk;
+ struct msm_camera_gpio_conf gconf;
+ struct msm_pinctrl_info pinctrl_info;
+};
+int stmvl53l0_init_cci(void);
+void stmvl53l0_exit_cci(void *);
+int stmvl53l0_power_down_cci(void *);
+int stmvl53l0_power_up_cci(void *, unsigned int *);
+
+#endif /* STMVL53L0_CCI_H */
diff --git a/drivers/input/misc/vl53L0/stmvl53l0-i2c.h b/drivers/input/misc/vl53L0/stmvl53l0-i2c.h
new file mode 100644
index 000000000000..a75a9e58da97
--- /dev/null
+++ b/drivers/input/misc/vl53L0/stmvl53l0-i2c.h
@@ -0,0 +1,47 @@
+/*
+ * stmvl53l0-i2c.h - Linux kernel modules for STM VL53L0 FlightSense TOF sensor
+ *
+ * Copyright (C) 2015 STMicroelectronics Imaging Division
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/*
+ * Defines
+ */
+#ifndef STMVL53L0_I2C_H
+#define STMVL53L0_I2C_H
+#include
+#include
+#include "msm_camera_i2c.h"
+#include "msm_camera_dt_util.h"
+#include "msm_camera_io_util.h"
+#include "msm_cci.h"
+
+struct i2c_data {
+ struct i2c_client *client;
+ struct regulator *vana;
+ uint8_t power_up;
+ uint32_t lowv;
+ uint32_t highv;
+ uint32_t xtalk;
+ struct msm_camera_gpio_conf gconf;
+ struct msm_pinctrl_info pinctrl_info;
+};
+int stmvl53l0_init_i2c(void);
+void stmvl53l0_exit_i2c(void *);
+int stmvl53l0_power_up_i2c(void *, unsigned int *);
+int stmvl53l0_power_down_i2c(void *);
+
+#endif /* STMVL53L0_I2C_H */
diff --git a/drivers/input/misc/vl53L0/stmvl53l0.h b/drivers/input/misc/vl53L0/stmvl53l0.h
new file mode 100644
index 000000000000..4ae84c9e8e83
--- /dev/null
+++ b/drivers/input/misc/vl53L0/stmvl53l0.h
@@ -0,0 +1,201 @@
+/*
+ * stmvl53l0.h - Linux kernel modules for STM VL53L0 FlightSense TOF sensor
+ *
+ * Copyright (C) 2015 STMicroelectronics Imaging Division
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/*
+ * Defines
+ */
+#ifndef STMVL53L0_H
+#define STMVL53L0_H
+
+#include
+#include
+#include
+#include
+
+#define STMVL53L0_DRV_NAME "stmvl53l0"
+#define STMVL53L0_SLAVE_ADDR (0x52>>1)
+
+#define DRIVER_VERSION "1.1.18"
+#define DRIVER_VERSION_NUM 18
+#define I2C_M_WR 0x00
+/* #define INT_POLLING_DELAY 20 */
+
+/* if don't want to have output from vl6180_dbgmsg, comment out #DEBUG macro */
+/*#define DEBUG*/
+/* #define vl6180_dbgmsg(str, args...) pr_debug("%s: " str, __func__, ##args) */
+#define vl53l0_dbgmsg_en(str, args...) \
+ pr_debug("%s: " str, __func__, ##args)
+
+#define vl53l0_dbgmsg(str, args...) \
+ pr_debug("%s: " str, __func__, ##args)
+/* #define vl6180_errmsg(str, args...) pr_err("%s: " str, __func__, ##args) */
+#define vl53l0_errmsg(str, args...) \
+ printk(KERN_ERR "%s: " str, __func__, ##args)
+
+#define VL53L0_VDD_MIN 2850000
+#define VL53L0_VDD_MAX 2850000
+/*driver working mode*/
+#define OFF_MODE 0
+#define CAM_MODE 1
+#define SAR_MODE 2
+#define SUPER_MODE 3
+#define XTALKCAL_MODE 4
+#define OFFSETCAL_MODE 5
+
+/*user actions*/
+#define CAM_ON 0
+#define CAM_OFF 1
+#define SAR_ON 2
+#define SAR_OFF 3
+#define XTALKCAL_ON 4
+#define OFFSETCAL_ON 5
+#define CAL_OFF 6
+#define RESET 7
+/*parameter types*/
+#define OFFSET_PAR 0
+#define XTALKRATE_PAR 1
+#define XTALKENABLE_PAR 2
+#define SIGMAVAL_PRA 3
+#define SIGMACTL_PRA 4
+#define WRAPAROUNDCTL_PRA 5
+#define INTERMEASUREMENTPERIOD_PAR 6
+#define MEASUREMENTTIMINGBUDGET_PAR 7
+#define SGLVAL_PRA 8
+#define SGLCTL_PRA 9
+#define CUTV_PRA 10
+#define DRVV_PRA 11
+#define PLLPRE_PRA 12
+#define PLLFINAL_PRA 13
+#define CCI_BUS 0
+#define I2C_BUS 1
+
+
+/*
+ * IOCTL register data structs
+ */
+struct stmvl53l0_register {
+ uint32_t is_read; /*1: read 0: #define write*/
+ uint32_t reg_index;
+ uint32_t reg_bytes;
+ uint32_t reg_data;
+ int32_t status;
+};
+
+/*
+ * IOCTL parameter structs
+ */
+struct stmvl53l0_parameter {
+ uint32_t is_read; /*1: Get 0: Set*/
+ uint32_t name;
+ int32_t value;
+ int32_t status;
+};
+
+/*
+ * driver data structs
+ */
+struct stmvl53l0_data {
+ /* embed ST VL53L0 Dev data as "dev_data" */
+ VL53L0_DevData_t Data;
+ /* i2c device address user specific field */
+ uint8_t I2cDevAddr;
+ uint8_t comms_type;
+ uint16_t comms_speed_khz;
+
+ struct cci_data cci_client_object;
+ struct i2c_data i2c_client_object;
+ void *client_object;
+ struct mutex update_lock;
+ struct delayed_work dwork; /* for PS work handler */
+ struct delayed_work initwork;
+ struct delayed_work resetwork;
+ struct delayed_work checkwork;
+ struct input_dev *input_dev_ps;
+ struct kobject *range_kobj;
+
+ const char *dev_name;
+
+ /* misc device */
+ struct miscdevice miscdev;
+
+ int irq;
+ unsigned int reset;
+
+ /* control flag from HAL */
+ unsigned int enable_ps_sensor;
+
+ /* PS parameters */
+ unsigned int ps_is_singleshot;
+ unsigned int ps_is_started;
+ unsigned int ps_data; /* to store PS data */
+
+ /* Range Data */
+ VL53L0_RangingMeasurementData_t rangeData;
+ int offset;
+ int xtalk;
+
+ /* delay time in miniseconds*/
+ unsigned int delay_ms;
+
+ struct mutex work_mutex;
+ /* Debug */
+ unsigned int enableDebug;
+ uint8_t interrupt_received;
+ int d_mode;
+ uint8_t w_mode;
+ /*for SAR mode indicate low range interrupt*/
+ uint8_t lowint;
+ uint8_t bus_type;
+ uint32_t lowv;
+ uint32_t highv;
+ wait_queue_head_t range_data_wait;
+ uint8_t d_ready;
+ uint8_t cut_v;
+ unsigned int xtalkCalDistance;
+ unsigned int offsetCalDistance;
+ unsigned int xtalkcalval;
+ VL53L0_GpioFunctionality gpio_function;
+ uint8_t c_suspend;
+ uint8_t c_stopped;
+ uint32_t refSpadCount;
+ uint8_t isApertureSpads;
+ uint8_t VhvSettings;
+ uint8_t PhaseCal;
+ uint8_t pll_p;
+ uint8_t pll_f;
+};
+
+/*
+ * funtion pointer structs
+ */
+struct stmvl53l0_module_fn_t {
+ int (*init)(void);
+ void (*deinit)(void *);
+ int (*power_up)(void *, unsigned int *);
+ int (*power_down)(void *);
+};
+
+struct stmvl53l0_data *stmvl53l0_getobject(void);
+int stmvl53l0_setup(struct stmvl53l0_data *data, uint8_t type);
+int stmvl53l0_checkmoduleid(struct stmvl53l0_data *data,
+ void *client, uint8_t type);
+int stmvl53l0_livechecking(struct stmvl53l0_data *data);
+void i2c_setclient(void *client, uint8_t type);
+
+#endif /* STMVL53L0_H */
diff --git a/drivers/input/misc/vl53L0/stmvl53l0_module-cci.c b/drivers/input/misc/vl53L0/stmvl53l0_module-cci.c
new file mode 100644
index 000000000000..74c5c9077502
--- /dev/null
+++ b/drivers/input/misc/vl53L0/stmvl53l0_module-cci.c
@@ -0,0 +1,475 @@
+/*
+* stmvl53l0_module-cci.c - Linux kernel modules for STM VL53L0 FlightSense TOF
+* sensor
+*
+* Copyright (C) 2015 STMicroelectronics Imaging Division.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program;
+*/
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+/*
+ * power specific includes
+ */
+#include
+#include
+#include
+#include
+#include
+/*
+ * API includes
+ */
+#include "vl53l0_api.h"
+#include "vl53l0_def.h"
+#include "vl53l0_platform.h"
+#include "stmvl53l0-cci.h"
+#include "stmvl53l0-i2c.h"
+#include "stmvl53l0.h"
+#define LASER_SENSOR_PINCTRL_STATE_SLEEP "laser_suspend"
+#define LASER_SENSOR_PINCTRL_STATE_DEFAULT "laser_default"
+
+/*
+ * Global data
+ */
+static struct v4l2_file_operations msm_tof_v4l2_subdev_fops;
+static struct msm_camera_i2c_fn_t msm_sensor_cci_func_tbl = {
+ .i2c_read = msm_camera_cci_i2c_read,
+ .i2c_read_seq = msm_camera_cci_i2c_read_seq,
+ .i2c_write = msm_camera_cci_i2c_write,
+ .i2c_write_seq = msm_camera_cci_i2c_write_seq,
+ .i2c_write_table = msm_camera_cci_i2c_write_table,
+ .i2c_write_seq_table = msm_camera_cci_i2c_write_seq_table,
+ .i2c_write_table_w_microdelay =
+ msm_camera_cci_i2c_write_table_w_microdelay,
+ .i2c_util = msm_sensor_cci_i2c_util,
+ .i2c_poll = msm_camera_cci_i2c_poll,
+};
+
+int vl53l0_get_dt_xtalk_data(struct device_node *of_node, int *xtalk)
+{
+ int rc = 0;
+ uint32_t count = 0;
+ uint32_t v_array[1];
+
+ count = of_property_count_strings(of_node, "st,xtalkval");
+
+ if (!count)
+ return 0;
+
+ rc = of_property_read_u32_array(of_node, "st,xtalkval",
+ v_array, 1);
+
+ if (rc != -EINVAL) {
+ if (rc < 0)
+ pr_err("%s failed %d\n", __func__, __LINE__);
+ else
+ *xtalk = v_array[0];
+ } else
+ rc = 0;
+
+ return rc;
+}
+static int stmvl53l0_get_dt_data(struct device *dev, struct cci_data *data);
+
+/*
+ * QCOM specific functions
+ */
+static int stmvl53l0_get_dt_data(struct device *dev, struct cci_data *data)
+{
+ int rc = 0;
+ struct msm_camera_gpio_conf *gconf = NULL;
+ uint16_t *gpio_array = NULL;
+ uint16_t gpio_array_size = 0;
+ int i;
+ struct msm_pinctrl_info *sensor_pctrl = NULL;
+ struct msm_tof_vreg *vreg_cfg = NULL;
+
+ vl53l0_dbgmsg("Enter\n");
+
+ sensor_pctrl = &data->pinctrl_info;
+ sensor_pctrl->pinctrl = devm_pinctrl_get(dev);
+ if (IS_ERR_OR_NULL(sensor_pctrl->pinctrl)) {
+ pr_err("%s:%d Getting pinctrl handle failed\n",
+ __func__, __LINE__);
+ return -EINVAL;
+ }
+ sensor_pctrl->gpio_state_active =
+ pinctrl_lookup_state(sensor_pctrl->pinctrl,
+ LASER_SENSOR_PINCTRL_STATE_DEFAULT);
+
+ sensor_pctrl->gpio_state_suspend
+ = pinctrl_lookup_state(sensor_pctrl->pinctrl,
+ LASER_SENSOR_PINCTRL_STATE_SLEEP);
+
+ if (dev->of_node) {
+ struct device_node *of_node = dev->of_node;
+
+ if (!of_node) {
+ vl53l0_errmsg("failed %d\n", __LINE__);
+ return -EINVAL;
+ }
+
+ rc = of_property_read_u32(of_node,
+ "cell-index", &data->pdev->id);
+ if (rc < 0) {
+ vl53l0_errmsg("failed %d\n", __LINE__);
+ return rc;
+ }
+ vl53l0_dbgmsg("cell-index: %d\n", data->pdev->id);
+ rc = of_property_read_u32(of_node,
+ "qcom,cci-master", &data->cci_master);
+ if (rc < 0) {
+ vl53l0_errmsg("failed %d\n", __LINE__);
+ /* Set default master 0 */
+ data->cci_master = MASTER_0;
+ rc = 0;
+ }
+ vl53l0_dbgmsg("cci_master: %d\n", data->cci_master);
+
+ if (of_find_property(of_node,
+ "qcom,cam-vreg-name", NULL)) {
+ vl53l0_dbgmsg("vreg setting is found");
+ vreg_cfg = &data->vreg_cfg;
+ rc = msm_camera_get_dt_vreg_data(of_node,
+ &vreg_cfg->cam_vreg, &vreg_cfg->num_vreg);
+ if (rc < 0) {
+ vl53l0_errmsg("failed %d\n", __LINE__);
+ rc = 0;
+ }
+ }
+ vl53l0_dbgmsg("vreg num: %d\n", vreg_cfg->num_vreg);
+
+ gpio_array_size = of_gpio_count(of_node);
+ gconf = &data->gconf;
+
+ if (gpio_array_size) {
+ gpio_array = kcalloc(gpio_array_size, sizeof(uint16_t),
+ GFP_KERNEL);
+
+ for (i = 0; i < gpio_array_size; i++) {
+ gpio_array[i] = of_get_gpio(of_node, i);
+ pr_err("%s gpio_array[%d] = %d\n", __func__, i,
+ gpio_array[i]);
+ }
+
+ rc = msm_camera_get_dt_gpio_req_tbl(of_node, gconf,
+ gpio_array, gpio_array_size);
+ if (rc < 0) {
+ pr_err("%s failed %d\n", __func__, __LINE__);
+ return rc;
+ }
+
+ rc = msm_camera_init_gpio_pin_tbl(of_node, gconf,
+ gpio_array, gpio_array_size);
+ if (rc < 0) {
+ pr_err("%s failed %d\n", __func__, __LINE__);
+ return rc;
+ }
+ }
+ rc = vl53l0_get_dt_xtalk_data(of_node,
+ &(data->xtalk));
+ }
+ vl53l0_dbgmsg("End rc =%d\n", rc);
+
+ return rc;
+}
+
+static int32_t stmvl53l0_vreg_control(struct cci_data *data, int config)
+{
+ int rc = 0, i, cnt;
+ struct msm_tof_vreg *vreg_cfg;
+
+ vl53l0_dbgmsg("Enter with config %d\n", config);
+
+ vreg_cfg = &data->vreg_cfg;
+ cnt = vreg_cfg->num_vreg;
+ if (!cnt) {
+ vl53l0_errmsg("failed %d\n", __LINE__);
+ return 0;
+ }
+
+ if (cnt >= MSM_TOF_MAX_VREGS) {
+ vl53l0_errmsg("failed %d cnt %d\n", __LINE__, cnt);
+ return -EINVAL;
+ }
+
+ for (i = 0; i < cnt; i++) {
+ rc = msm_camera_config_single_vreg(&(data->pdev->dev),
+ &vreg_cfg->cam_vreg[i],
+ (struct regulator **)&vreg_cfg->data[i],
+ config);
+ }
+
+ vl53l0_dbgmsg("EXIT rc =%d\n", rc);
+ return rc;
+}
+
+static int msm_tof_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
+{
+ int rc = 0;
+ return rc;
+}
+
+
+static const struct v4l2_subdev_internal_ops msm_tof_internal_ops = {
+ .close = msm_tof_close,
+};
+
+static long msm_tof_subdev_ioctl(struct v4l2_subdev *sd,
+ unsigned int cmd, void *arg)
+{
+ vl53l0_dbgmsg("Subdev_ioctl not handled\n");
+ return 0;
+}
+
+static int32_t msm_tof_power(struct v4l2_subdev *sd, int on)
+{
+ vl53l0_dbgmsg("TOF power called\n");
+ return 0;
+}
+
+static struct v4l2_subdev_core_ops msm_tof_subdev_core_ops = {
+ .ioctl = msm_tof_subdev_ioctl,
+ .s_power = msm_tof_power,
+};
+
+static struct v4l2_subdev_ops msm_tof_subdev_ops = {
+ .core = &msm_tof_subdev_core_ops,
+};
+
+static int stmvl53l0_cci_init(struct cci_data *data)
+{
+ int rc = 0;
+ struct msm_camera_cci_client *cci_client = data->client->cci_client;
+
+ if (FALSE == data->subdev_initialized) {
+ data->client->i2c_func_tbl = &msm_sensor_cci_func_tbl;
+ data->client->cci_client =
+ kzalloc(sizeof(struct msm_camera_cci_client),
+ GFP_KERNEL);
+
+ if (!data->client->cci_client) {
+ vl53l0_errmsg("%d, failed no memory\n", __LINE__);
+ return -ENOMEM;
+ }
+ cci_client = data->client->cci_client;
+ cci_client->cci_subdev = msm_cci_get_subdev();
+ cci_client->cci_i2c_master = data->cci_master;
+ v4l2_subdev_init(&data->msm_sd.sd, data->subdev_ops);
+ v4l2_set_subdevdata(&data->msm_sd.sd, data);
+ data->msm_sd.sd.internal_ops = &msm_tof_internal_ops;
+ data->msm_sd.sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+ snprintf(data->msm_sd.sd.name,
+ ARRAY_SIZE(data->msm_sd.sd.name), "msm_tof");
+ media_entity_init(&data->msm_sd.sd.entity, 0, NULL, 0);
+ data->msm_sd.sd.entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
+ data->msm_sd.sd.entity.group_id = MSM_CAMERA_SUBDEV_TOF;
+ data->msm_sd.close_seq = MSM_SD_CLOSE_2ND_CATEGORY | 0x2;
+ msm_sd_register(&data->msm_sd);
+ msm_tof_v4l2_subdev_fops = v4l2_subdev_fops;
+ data->msm_sd.sd.devnode->fops = &msm_tof_v4l2_subdev_fops;
+ data->subdev_initialized = TRUE;
+ }
+
+ vl53l0_dbgmsg("inited\n");
+ cci_client->sid = 0x29;
+ cci_client->retries = 3;
+ cci_client->id_map = 0;
+ cci_client->cci_i2c_master = data->cci_master;
+ cci_client->i2c_freq_mode = I2C_FAST_MODE;
+ rc = data->client->i2c_func_tbl->i2c_util(data->client, MSM_CCI_INIT);
+ if (rc < 0) {
+ vl53l0_errmsg("%d: CCI Init failed\n", __LINE__);
+ return rc;
+ }
+ vl53l0_dbgmsg("CCI Init Succeeded\n");
+ data->client->addr_type = MSM_CAMERA_I2C_BYTE_ADDR;
+
+ return 0;
+}
+
+static int32_t stmvl53l0_platform_probe(struct platform_device *pdev)
+{
+ struct stmvl53l0_data *vl53l0_data = NULL;
+ struct cci_data *data = NULL;
+ unsigned int present = 0;
+
+ int32_t rc = 0;
+
+ vl53l0_dbgmsg("Enter\n");
+
+ if (!pdev->dev.of_node) {
+ vl53l0_errmsg("%d,of_node NULL\n", __LINE__);
+ return -EINVAL;
+ }
+
+ vl53l0_data = stmvl53l0_getobject();
+ if (NULL == vl53l0_data) {
+ vl53l0_errmsg("%d,Object not found!\n", __LINE__);
+ return -EINVAL;
+ }
+ data = &(vl53l0_data->cci_client_object);
+ if (!data) {
+ vl53l0_errmsg("%d,data NULL\n", __LINE__);
+ return -EINVAL;
+ }
+
+ /* Set platform device handle */
+ data->subdev_ops = &msm_tof_subdev_ops;
+ data->pdev = pdev;
+ stmvl53l0_get_dt_data(&pdev->dev, data);
+ data->subdev_id = pdev->id;
+
+ /* Set device type as platform device */
+ data->device_type = MSM_CAMERA_PLATFORM_DEVICE;
+ data->subdev_initialized = FALSE;
+
+ data->client = (struct msm_camera_i2c_client *)&data->g_client;
+
+ rc = stmvl53l0_power_up_cci(data, &present);
+ if (rc) {
+ vl53l0_errmsg("%d,error rc %d\n", __LINE__, rc);
+ return rc;
+ }
+ rc = stmvl53l0_checkmoduleid(vl53l0_data, data->client, CCI_BUS);
+ if (rc != 0) {
+ vl53l0_errmsg("%d,error rc %d\n", __LINE__, rc);
+ stmvl53l0_power_down_cci(data);
+ return rc;
+ }
+ stmvl53l0_power_down_cci(data);
+ stmvl53l0_setup(vl53l0_data, CCI_BUS);
+
+ vl53l0_dbgmsg("End\n");
+
+ return rc;
+
+}
+
+
+static const struct of_device_id st_stmvl53l0_dt_match[] = {
+ { .compatible = "st,stmvl53l0", },
+ { },
+};
+
+static struct platform_driver stmvl53l0_platform_driver = {
+ .probe = stmvl53l0_platform_probe,
+ .driver = {
+ .name = STMVL53L0_DRV_NAME,
+ .owner = THIS_MODULE,
+ .of_match_table = st_stmvl53l0_dt_match,
+ },
+};
+
+int stmvl53l0_power_up_cci(void *cci_object, unsigned int *preset_flag)
+{
+ int ret = 0;
+ struct cci_data *data = (struct cci_data *)cci_object;
+
+ vl53l0_dbgmsg("Enter");
+ pinctrl_select_state(data->pinctrl_info.pinctrl,
+ data->pinctrl_info.gpio_state_active);
+
+ stmvl53l0_vreg_control(data, 1);
+ msleep(20);
+
+ /* need to init cci first */
+ ret = stmvl53l0_cci_init(data);
+ if (ret) {
+ vl53l0_errmsg("stmvl53l0_cci_init failed %d\n", __LINE__);
+ return ret;
+ }
+
+ msm_camera_request_gpio_table(
+ data->gconf.cam_gpio_req_tbl,
+ data->gconf.cam_gpio_req_tbl_size, 1);
+ gpio_set_value_cansleep(data->gconf.cam_gpio_req_tbl[0].gpio, 1);
+ data->power_up = 1;
+ *preset_flag = 1;
+ vl53l0_dbgmsg("End\n");
+ msleep(20);
+ return ret;
+}
+
+int stmvl53l0_power_down_cci(void *cci_object)
+{
+ int ret = 0;
+ struct cci_data *data = (struct cci_data *)cci_object;
+
+ vl53l0_dbgmsg("Enter\n");
+ if (data->power_up) {
+ /* need to release cci first */
+ ret = data->client->i2c_func_tbl->i2c_util(data->client,
+ MSM_CCI_RELEASE);
+ if (ret < 0)
+ vl53l0_errmsg("%d,CCI Release failed rc %d\n",
+ __LINE__, ret);
+
+ pinctrl_select_state(data->pinctrl_info.pinctrl,
+ data->pinctrl_info.gpio_state_suspend);
+
+ msm_camera_request_gpio_table(
+ data->gconf.cam_gpio_req_tbl,
+ data->gconf.cam_gpio_req_tbl_size, 0);
+
+ gpio_set_value_cansleep(
+ data->gconf.cam_gpio_req_tbl[0].gpio, 0);
+
+ stmvl53l0_vreg_control(data, 0);
+ }
+ data->power_up = 0;
+ vl53l0_dbgmsg("End\n");
+ return ret;
+}
+
+int stmvl53l0_init_cci(void)
+{
+ int ret = 0;
+ vl53l0_dbgmsg("Enter\n");
+
+ /* register as a platform device */
+ ret = platform_driver_register(&stmvl53l0_platform_driver);
+ if (ret)
+ vl53l0_errmsg("%d, error ret:%d\n", __LINE__, ret);
+
+ vl53l0_dbgmsg("End\n");
+
+ return ret;
+}
+
+void stmvl53l0_exit_cci(void *cci_object)
+{
+ struct cci_data *data = (struct cci_data *)cci_object;
+ vl53l0_dbgmsg("Enter\n");
+
+ if (data && data->client->cci_client)
+ kfree(data->client->cci_client);
+
+ vl53l0_dbgmsg("End\n");
+}
+
diff --git a/drivers/input/misc/vl53L0/stmvl53l0_module-i2c.c b/drivers/input/misc/vl53L0/stmvl53l0_module-i2c.c
new file mode 100644
index 000000000000..6bc4f390ebfa
--- /dev/null
+++ b/drivers/input/misc/vl53L0/stmvl53l0_module-i2c.c
@@ -0,0 +1,422 @@
+/*
+* stmvl53l0_module-i2c.c - Linux kernel modules for STM VL53L0 FlightSense TOF
+* sensor
+*
+* Copyright (C) 2015 STMicroelectronics Imaging Division.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program;
+*/
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+/*
+ * power specific includes
+ */
+#include
+#include
+#include
+#include
+#include
+/*
+ * API includes
+ */
+#include "vl53l0_api.h"
+#include "vl53l0_def.h"
+#include "vl53l0_platform.h"
+#include "stmvl53l0-i2c.h"
+#include "stmvl53l0-cci.h"
+#include "stmvl53l0.h"
+
+#define LASER_SENSOR_PINCTRL_STATE_SLEEP "laser_suspend"
+#define LASER_SENSOR_PINCTRL_STATE_DEFAULT "laser_default"
+
+/*
+ * Global data
+ */
+static int stmvl53l0_parse_vdd(struct device *dev, struct i2c_data *data);
+
+/*
+ * QCOM specific functions
+ */
+static int stmvl53l0_parse_vdd(struct device *dev, struct i2c_data *data)
+{
+ int ret = 0;
+ vl53l0_dbgmsg("Enter\n");
+
+ if (dev->of_node) {
+ data->vana = regulator_get_optional(dev, "vdd");
+ if (IS_ERR(data->vana)) {
+ vl53l0_dbgmsg("%d,vdd supply is not provided\n",
+ __LINE__);
+ ret = -1;
+ }
+ }
+ vl53l0_dbgmsg("End\n");
+
+ return ret;
+}
+int get_dt_xtalk_data(struct device_node *of_node, int *xtalk)
+{
+ int rc = 0;
+ uint32_t count = 0;
+ uint32_t v_array[1];
+
+ count = of_property_count_strings(of_node, "st,xtalkval");
+
+ if (!count)
+ return 0;
+
+ rc = of_property_read_u32_array(of_node, "st,xtalkval",
+ v_array, 1);
+
+ if (rc != -EINVAL) {
+ if (rc < 0)
+ pr_err("%s failed %d\n", __func__, __LINE__);
+ else
+ *xtalk = v_array[0];
+ } else
+ rc = 0;
+
+ return rc;
+}
+int get_dt_threshold_data(struct device_node *of_node, int *lowv, int *highv)
+{
+ int rc = 0;
+ uint32_t count = 0;
+ uint32_t v_array[2];
+
+ count = of_property_count_strings(of_node, "st,sensorthreshold");
+
+ if (!count)
+ return 0;
+
+ rc = of_property_read_u32_array(of_node, "st,sensorthreshold",
+ v_array, 2);
+
+ if (rc != -EINVAL) {
+ if (rc < 0) {
+ pr_err("%s failed %d\n", __func__, __LINE__);
+ } else {
+ *lowv = v_array[0];
+ *highv = v_array[1];
+ }
+ } else {
+ rc = 0;
+ }
+
+ return rc;
+}
+
+static int stmvl53l0_get_dt_data(struct device *dev, struct i2c_data *data)
+{
+ int rc = 0;
+ struct msm_camera_gpio_conf *gconf;
+ uint16_t *gpio_array;
+ uint16_t gpio_array_size;
+ int i;
+ struct msm_pinctrl_info *sensor_pctrl;
+
+ vl53l0_dbgmsg("Enter\n");
+
+ sensor_pctrl = &data->pinctrl_info;
+ sensor_pctrl->pinctrl = devm_pinctrl_get(dev);
+ if (IS_ERR_OR_NULL(sensor_pctrl->pinctrl)) {
+ pr_err("%s:%d Getting pinctrl handle failed\n",
+ __func__, __LINE__);
+ return -EINVAL;
+ }
+ sensor_pctrl->gpio_state_active =
+ pinctrl_lookup_state(sensor_pctrl->pinctrl,
+ LASER_SENSOR_PINCTRL_STATE_DEFAULT);
+
+ sensor_pctrl->gpio_state_suspend
+ = pinctrl_lookup_state(sensor_pctrl->pinctrl,
+ LASER_SENSOR_PINCTRL_STATE_SLEEP);
+
+ if (dev->of_node) {
+ struct device_node *of_node = dev->of_node;
+
+ gpio_array_size = of_gpio_count(of_node);
+ gconf = &data->gconf;
+
+ if (gpio_array_size) {
+ gpio_array = kcalloc(gpio_array_size, sizeof(uint16_t),
+ GFP_KERNEL);
+ if (!gpio_array)
+ return -ENOMEM;
+
+ for (i = 0; i < gpio_array_size; i++) {
+ gpio_array[i] = of_get_gpio(of_node, i);
+ pr_err("%s gpio_array[%d] = %d\n", __func__, i,
+ gpio_array[i]);
+ }
+
+ rc = msm_camera_get_dt_gpio_req_tbl(of_node, gconf,
+ gpio_array, gpio_array_size);
+ if (rc < 0) {
+ pr_err("%s failed %d\n", __func__, __LINE__);
+ kfree(gpio_array);
+ return rc;
+ }
+
+ rc = msm_camera_init_gpio_pin_tbl(of_node, gconf,
+ gpio_array, gpio_array_size);
+ if (rc < 0) {
+ pr_err("%s failed %d\n", __func__, __LINE__);
+ kfree(gpio_array);
+ return rc;
+ }
+ kfree(gpio_array);
+ }
+ rc = get_dt_threshold_data(of_node,
+ &(data->lowv), &(data->highv));
+ rc = get_dt_xtalk_data(of_node,
+ &(data->xtalk));
+ }
+ vl53l0_dbgmsg("End rc =%d\n", rc);
+
+ return rc;
+}
+
+static int stmvl53l0_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ int rc = 0, i = 0;
+ struct stmvl53l0_data *vl53l0_data = NULL;
+ struct i2c_data *i2c_object = NULL;
+ int present;
+
+ vl53l0_dbgmsg("Enter\n");
+
+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) {
+ rc = -EIO;
+ return rc;
+ }
+
+ vl53l0_data = stmvl53l0_getobject();
+ if (!vl53l0_data) {
+ vl53l0_errmsg("%d,data NULL\n", __LINE__);
+ return -EINVAL;
+ }
+
+ if (vl53l0_data)
+ i2c_object = &(vl53l0_data->i2c_client_object);
+ i2c_object->client = client;
+
+ /* setup regulator */
+ stmvl53l0_parse_vdd(&i2c_object->client->dev, i2c_object);
+
+ /* setup device name */
+ vl53l0_data->dev_name = dev_name(&client->dev);
+
+ /* setup device data */
+ dev_set_drvdata(&client->dev, vl53l0_data);
+
+ /* setup client data */
+ i2c_set_clientdata(client, vl53l0_data);
+
+ stmvl53l0_get_dt_data(&client->dev, i2c_object);
+ rc = stmvl53l0_power_up_i2c(i2c_object, &present);
+ if (rc) {
+ vl53l0_errmsg("%d,error rc %d\n", __LINE__, rc);
+ return rc;
+ }
+ for (i = 0; i < 5; i++) {
+ rc = stmvl53l0_checkmoduleid
+ (vl53l0_data, i2c_object->client, I2C_BUS);
+ if (!rc)
+ break;
+ msleep(20);
+ }
+ if (rc != 0) {
+ stmvl53l0_power_down_i2c(i2c_object);
+ msleep(20);
+ stmvl53l0_power_up_i2c(i2c_object, &present);
+ for (i = 0; i < 10; i++) {
+ rc = stmvl53l0_checkmoduleid
+ (vl53l0_data, i2c_object->client, I2C_BUS);
+ if (!rc)
+ break;
+ msleep(20);
+ }
+ }
+ if (rc != 0) {
+ vl53l0_errmsg("%d,error rc %d\n", __LINE__, rc);
+ stmvl53l0_power_down_i2c(i2c_object);
+ return rc;
+ }
+ stmvl53l0_power_down_i2c(i2c_object);
+
+ rc = stmvl53l0_setup(vl53l0_data, I2C_BUS);
+
+ vl53l0_dbgmsg("End\n");
+ return rc;
+}
+
+static int stmvl53l0_remove(struct i2c_client *client)
+{
+ struct stmvl53l0_data *data = stmvl53l0_getobject();
+
+ vl53l0_dbgmsg("Enter\n");
+
+ /* Power down the device */
+ stmvl53l0_power_down_i2c((void *)data->client_object);
+
+ vl53l0_dbgmsg("End\n");
+ return 0;
+}
+
+static const struct i2c_device_id stmvl53l0_id[] = {
+ { STMVL53L0_DRV_NAME, 0 },
+ { },
+};
+MODULE_DEVICE_TABLE(i2c, stmvl53l0_id);
+
+static const struct of_device_id st_stmvl53l0_dt_match[] = {
+ { .compatible = "st,stmvl53l0_i2c", },
+ { },
+};
+
+int stmv153l0_resume(struct i2c_client *clt)
+{
+ struct stmvl53l0_data *vl53l0_data = NULL;
+
+ vl53l0_dbgmsg("Enter\n");
+ vl53l0_data = stmvl53l0_getobject();
+ stmvl53l0_livechecking(vl53l0_data);
+ return 0;
+}
+
+static struct i2c_driver stmvl6180_driver = {
+ .driver = {
+ .name = STMVL53L0_DRV_NAME,
+ .owner = THIS_MODULE,
+ .of_match_table = st_stmvl53l0_dt_match,
+ },
+ .probe = stmvl53l0_probe,
+ .remove = stmvl53l0_remove,
+ .resume = stmv153l0_resume,
+ .id_table = stmvl53l0_id,
+
+};
+
+int stmvl53l0_power_up_i2c(void *i2c_object, unsigned int *preset_flag)
+{
+ int ret = 0;
+
+ struct i2c_data *data = (struct i2c_data *)i2c_object;
+
+ vl53l0_dbgmsg("Enter i2c powerup\n");
+ pinctrl_select_state(data->pinctrl_info.pinctrl,
+ data->pinctrl_info.gpio_state_active);
+
+ if (!IS_ERR(data->vana)) {
+ ret = regulator_set_voltage(data->vana, VL53L0_VDD_MIN,
+ VL53L0_VDD_MAX);
+ if (ret < 0) {
+ vl53l0_errmsg("set_vol(%p) fail %d\n", data->vana, ret);
+ return ret;
+ }
+ ret = regulator_enable(data->vana);
+
+ if (ret < 0) {
+ vl53l0_errmsg("reg enable(%p) failed.rc=%d\n",
+ data->vana, ret);
+ return ret;
+ }
+ }
+
+ msm_camera_request_gpio_table(
+ data->gconf.cam_gpio_req_tbl,
+ data->gconf.cam_gpio_req_tbl_size, 1);
+
+ gpio_set_value_cansleep(data->gconf.cam_gpio_req_tbl[0].gpio, 1);
+
+ data->power_up = 1;
+ *preset_flag = 1;
+
+ vl53l0_dbgmsg("End\n");
+ return ret;
+}
+
+int stmvl53l0_power_down_i2c(void *i2c_object)
+{
+ int ret = 0;
+
+ struct i2c_data *data = (struct i2c_data *)i2c_object;
+
+ vl53l0_dbgmsg("Enter\n");
+ if (data->power_up) {
+ pinctrl_select_state(data->pinctrl_info.pinctrl,
+ data->pinctrl_info.gpio_state_suspend);
+
+ msm_camera_request_gpio_table(
+ data->gconf.cam_gpio_req_tbl,
+ data->gconf.cam_gpio_req_tbl_size, 0);
+
+ gpio_set_value_cansleep(
+ data->gconf.cam_gpio_req_tbl[0].gpio, 0);
+
+ if (!IS_ERR(data->vana)) {
+ ret = regulator_disable(data->vana);
+ if (ret < 0)
+ vl53l0_errmsg("reg disable(%p) failed.rc=%d\n",
+ data->vana, ret);
+ }
+
+ data->power_up = 0;
+ }
+
+
+ vl53l0_dbgmsg("End\n");
+ return ret;
+}
+
+int stmvl53l0_init_i2c(void)
+{
+ int ret = 0;
+
+ vl53l0_dbgmsg("Enter\n");
+
+ /* register as a i2c client device */
+ ret = i2c_add_driver(&stmvl6180_driver);
+ if (ret)
+ vl53l0_errmsg("%d erro ret:%d\n", __LINE__, ret);
+
+ vl53l0_dbgmsg("End with rc:%d\n", ret);
+
+ return ret;
+}
+
+void stmvl53l0_exit_i2c(void *i2c_object)
+{
+ vl53l0_dbgmsg("Enter\n");
+ i2c_del_driver(&stmvl6180_driver);
+
+ vl53l0_dbgmsg("End\n");
+}
+
diff --git a/drivers/input/misc/vl53L0/stmvl53l0_module.c b/drivers/input/misc/vl53L0/stmvl53l0_module.c
new file mode 100644
index 000000000000..9ed08dc27af9
--- /dev/null
+++ b/drivers/input/misc/vl53L0/stmvl53l0_module.c
@@ -0,0 +1,2804 @@
+/*
+* stmvl53l0_module.c - Linux kernel modules for STM VL53L0 FlightSense TOF
+* sensor
+*
+* Copyright (C) 2015 STMicroelectronics Imaging Division.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program;
+*/
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+/*
+* API includes
+*/
+#include "vl53l0_api.h"
+#include "vl53l010_api.h"
+/*
+#include "vl53l0_def.h"
+#include "vl53l0_platform.h"
+#include "stmvl53l0-i2c.h"
+#include "stmvl53l0-cci.h"
+#include "stmvl53l0.h"
+*/
+
+#include "vl53l0_api_histogram.h"
+
+#define USE_INT
+#define IRQ_NUM 59
+#define DATA_TIMEOUT msecs_to_jiffies(150)
+/*#define DEBUG_TIME_LOG*/
+#ifdef DEBUG_TIME_LOG
+struct timeval start_tv, stop_tv;
+#endif
+
+#define SAR_LOW 30
+#define SAR_HIGH 40
+static char *devname = "laser";
+
+static struct stmvl53l0_data *gp_vl53l0_data;
+static int s_count;
+static int s_prevalue;
+
+static struct stmvl53l0_module_fn_t stmvl53l0_module_func_tbl_cci = {
+ .init = stmvl53l0_init_cci,
+ .deinit = stmvl53l0_exit_cci,
+ .power_up = stmvl53l0_power_up_cci,
+ .power_down = stmvl53l0_power_down_cci,
+};
+
+static struct stmvl53l0_module_fn_t stmvl53l0_module_func_tbl_i2c = {
+ .init = stmvl53l0_init_i2c,
+ .deinit = stmvl53l0_exit_i2c,
+ .power_up = stmvl53l0_power_up_i2c,
+ .power_down = stmvl53l0_power_down_i2c,
+};
+
+struct stmvl53l0_module_fn_t *pmodule_func_tbl;
+static struct stmvl53l0_parameter s_parameters[10];
+static int s_nump;
+
+
+struct stmvl53l0_api_fn_t {
+ VL53L0_Error(*GetVersion)(VL53L0_Version_t *pVersion);
+ VL53L0_Error(*GetPalSpecVersion)(VL53L0_Version_t *pPalSpecVersion);
+
+ VL53L0_Error(*GetProductRevision)(VL53L0_DEV Dev,
+ uint8_t *pProductRevisionMajor,
+ uint8_t *pProductRevisionMinor);
+ VL53L0_Error(*GetDeviceInfo)(VL53L0_DEV Dev,
+ VL53L0_DeviceInfo_t *pVL53L0_DeviceInfo);
+ VL53L0_Error(*GetDeviceErrorStatus)(VL53L0_DEV Dev,
+ VL53L0_DeviceError * pDeviceErrorStatus);
+ int8_t (*GetRangeStatusString)(uint8_t RangeStatus,
+ char *pRangeStatusString);
+ VL53L0_Error(*GetDeviceErrorString)(VL53L0_DeviceError ErrorCode,
+ char *pDeviceErrorString);
+ VL53L0_Error(*GetPalErrorString)(VL53L0_Error PalErrorCode,
+ char *pPalErrorString);
+ int8_t (*GetPalStateString)(VL53L0_State PalStateCode,
+ char *pPalStateString);
+ VL53L0_Error(*GetPalState)(VL53L0_DEV Dev, VL53L0_State * pPalState);
+ VL53L0_Error(*SetPowerMode)(VL53L0_DEV Dev,
+ VL53L0_PowerModes PowerMode);
+ VL53L0_Error(*GetPowerMode)(VL53L0_DEV Dev,
+ VL53L0_PowerModes * pPowerMode);
+ VL53L0_Error(*SetOffsetCalibrationDataMicroMeter)(VL53L0_DEV Dev,
+ int32_t OffsetCalibrationDataMicroMeter);
+ VL53L0_Error(*GetOffsetCalibrationDataMicroMeter)(VL53L0_DEV Dev,
+ int32_t *pOffsetCalibrationDataMicroMeter);
+ int8_t (*SetLinearityCorrectiveGain)(VL53L0_DEV Dev,
+ int16_t LinearityCorrectiveGain);
+ int8_t (*GetLinearityCorrectiveGain)(VL53L0_DEV Dev,
+ uint16_t *pLinearityCorrectiveGain);
+ VL53L0_Error(*SetGroupParamHold)(VL53L0_DEV Dev,
+ uint8_t GroupParamHold);
+ VL53L0_Error(*GetUpperLimitMilliMeter)(VL53L0_DEV Dev,
+ uint16_t *pUpperLimitMilliMeter);
+ VL53L0_Error(*SetDeviceAddress)(VL53L0_DEV Dev,
+ uint8_t DeviceAddress);
+ VL53L0_Error(*DataInit)(VL53L0_DEV Dev);
+ VL53L0_Error(*SetTuningSettingBuffer)(VL53L0_DEV Dev,
+ uint8_t *pTuningSettingBuffer,
+ uint8_t UseInternalTuningSettings);
+ VL53L0_Error(*GetTuningSettingBuffer)(VL53L0_DEV Dev,
+ uint8_t **pTuningSettingBuffer,
+ uint8_t *pUseInternalTuningSettings);
+ VL53L0_Error(*StaticInit)(VL53L0_DEV Dev);
+ VL53L0_Error(*WaitDeviceBooted)(VL53L0_DEV Dev);
+ VL53L0_Error(*ResetDevice)(VL53L0_DEV Dev);
+ VL53L0_Error(*SetDeviceParameters)(VL53L0_DEV Dev,
+ const VL53L0_DeviceParameters_t *pDeviceParameters);
+ VL53L0_Error(*GetDeviceParameters)(VL53L0_DEV Dev,
+ VL53L0_DeviceParameters_t *pDeviceParameters);
+ VL53L0_Error(*SetDeviceMode)(VL53L0_DEV Dev,
+ VL53L0_DeviceModes DeviceMode);
+ VL53L0_Error(*GetDeviceMode)(VL53L0_DEV Dev,
+ VL53L0_DeviceModes * pDeviceMode);
+ VL53L0_Error(*SetHistogramMode)(VL53L0_DEV Dev,
+ VL53L0_HistogramModes HistogramMode);
+ VL53L0_Error(*GetHistogramMode)(VL53L0_DEV Dev,
+ VL53L0_HistogramModes * pHistogramMode);
+ VL53L0_Error(*SetMeasurementTimingBudgetMicroSeconds)(VL53L0_DEV Dev,
+ uint32_t MeasurementTimingBudgetMicroSeconds);
+ VL53L0_Error(*GetMeasurementTimingBudgetMicroSeconds)(
+ VL53L0_DEV Dev,
+ uint32_t *pMeasurementTimingBudgetMicroSeconds);
+ VL53L0_Error(*GetVcselPulsePeriod)(VL53L0_DEV Dev,
+ VL53L0_VcselPeriod VcselPeriodType,
+ uint8_t *pVCSELPulsePeriod);
+ VL53L0_Error(*SetVcselPulsePeriod)(VL53L0_DEV Dev,
+ VL53L0_VcselPeriod VcselPeriodType,
+ uint8_t VCSELPulsePeriod);
+ VL53L0_Error(*SetSequenceStepEnable)(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId,
+ uint8_t SequenceStepEnabled);
+ VL53L0_Error(*GetSequenceStepEnable)(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId,
+ uint8_t *pSequenceStepEnabled);
+ VL53L0_Error(*GetSequenceStepEnables)(VL53L0_DEV Dev,
+ VL53L0_SchedulerSequenceSteps_t *pSchedulerSequenceSteps);
+ VL53L0_Error(*SetSequenceStepTimeout)(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId,
+ FixPoint1616_t TimeOutMilliSecs);
+ VL53L0_Error(*GetSequenceStepTimeout)(VL53L0_DEV Dev,
+ VL53L0_SequenceStepId SequenceStepId,
+ FixPoint1616_t *pTimeOutMilliSecs);
+ VL53L0_Error(*GetNumberOfSequenceSteps)(VL53L0_DEV Dev,
+ uint8_t *pNumberOfSequenceSteps);
+ VL53L0_Error(*GetSequenceStepsInfo)(VL53L0_SequenceStepId SequenceStepId,
+ char *pSequenceStepsString);
+ VL53L0_Error(*SetInterMeasurementPeriodMilliSeconds)(
+ VL53L0_DEV Dev,
+ uint32_t InterMeasurementPeriodMilliSeconds);
+ VL53L0_Error(*GetInterMeasurementPeriodMilliSeconds)(
+ VL53L0_DEV Dev,
+ uint32_t *pInterMeasurementPeriodMilliSeconds);
+ VL53L0_Error(*SetXTalkCompensationEnable)(VL53L0_DEV Dev,
+ uint8_t XTalkCompensationEnable);
+ VL53L0_Error(*GetXTalkCompensationEnable)(VL53L0_DEV Dev,
+ uint8_t *pXTalkCompensationEnable);
+ VL53L0_Error(*SetXTalkCompensationRateMegaCps)(
+ VL53L0_DEV Dev,
+ FixPoint1616_t XTalkCompensationRateMegaCps);
+ VL53L0_Error(*GetXTalkCompensationRateMegaCps)(
+ VL53L0_DEV Dev,
+ FixPoint1616_t *pXTalkCompensationRateMegaCps);
+ VL53L0_Error(*GetNumberOfLimitCheck)(
+ uint16_t *pNumberOfLimitCheck);
+ VL53L0_Error(*GetLimitCheckInfo)(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, char *pLimitCheckString);
+ VL53L0_Error(*SetLimitCheckEnable)(VL53L0_DEV Dev,
+ uint16_t LimitCheckId,
+ uint8_t LimitCheckEnable);
+ VL53L0_Error(*GetLimitCheckEnable)(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, uint8_t *pLimitCheckEnable);
+ VL53L0_Error(*SetLimitCheckValue)(VL53L0_DEV Dev,
+ uint16_t LimitCheckId,
+ FixPoint1616_t LimitCheckValue);
+ VL53L0_Error(*GetLimitCheckValue)(VL53L0_DEV Dev,
+ uint16_t LimitCheckId,
+ FixPoint1616_t *pLimitCheckValue);
+ VL53L0_Error(*GetLimitCheckCurrent)(VL53L0_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t *pLimitCheckCurrent);
+ VL53L0_Error(*SetWrapAroundCheckEnable)(VL53L0_DEV Dev,
+ uint8_t WrapAroundCheckEnable);
+ VL53L0_Error(*GetWrapAroundCheckEnable)(VL53L0_DEV Dev,
+ uint8_t *pWrapAroundCheckEnable);
+ VL53L0_Error(*PerformSingleMeasurement)(VL53L0_DEV Dev);
+ VL53L0_Error(*PerformRefCalibration)(VL53L0_DEV Dev,
+ uint8_t *pVhvSettings, uint8_t *pPhaseCal);
+ VL53L0_Error(*PerformXTalkCalibration)(VL53L0_DEV Dev,
+ FixPoint1616_t XTalkCalDistance,
+ FixPoint1616_t *pXTalkCompensationRateMegaCps);
+ VL53L0_Error(*PerformOffsetCalibration)(VL53L0_DEV Dev,
+ FixPoint1616_t CalDistanceMilliMeter,
+ int32_t *pOffsetMicroMeter);
+ VL53L0_Error(*StartMeasurement)(VL53L0_DEV Dev);
+ VL53L0_Error(*StopMeasurement)(VL53L0_DEV Dev);
+ VL53L0_Error(*GetMeasurementDataReady)(VL53L0_DEV Dev,
+ uint8_t *pMeasurementDataReady);
+ VL53L0_Error(*WaitDeviceReadyForNewMeasurement)(VL53L0_DEV Dev,
+ uint32_t MaxLoop);
+ VL53L0_Error(*GetRangingMeasurementData)(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData);
+ VL53L0_Error(*GetHistogramMeasurementData)(VL53L0_DEV Dev,
+ VL53L0_HistogramMeasurementData_t *pHistogramMeasurementData);
+ VL53L0_Error(*PerformSingleRangingMeasurement)(VL53L0_DEV Dev,
+ VL53L0_RangingMeasurementData_t *pRangingMeasurementData);
+ VL53L0_Error(*PerformSingleHistogramMeasurement)(VL53L0_DEV Dev,
+ VL53L0_HistogramMeasurementData_t *pHistogramMeasurementData);
+ VL53L0_Error(*SetNumberOfROIZones)(VL53L0_DEV Dev,
+ uint8_t NumberOfROIZones);
+ VL53L0_Error(*GetNumberOfROIZones)(VL53L0_DEV Dev,
+ uint8_t *pNumberOfROIZones);
+ VL53L0_Error(*GetMaxNumberOfROIZones)(VL53L0_DEV Dev,
+ uint8_t *pMaxNumberOfROIZones);
+ VL53L0_Error(*SetGpioConfig)(VL53L0_DEV Dev,
+ uint8_t Pin,
+ VL53L0_DeviceModes DeviceMode,
+ VL53L0_GpioFunctionality Functionality,
+ VL53L0_InterruptPolarity Polarity);
+ VL53L0_Error(*GetGpioConfig)(VL53L0_DEV Dev,
+ uint8_t Pin,
+ VL53L0_DeviceModes * pDeviceMode,
+ VL53L0_GpioFunctionality * pFunctionality,
+ VL53L0_InterruptPolarity * pPolarity);
+ VL53L0_Error(*SetInterruptThresholds)(VL53L0_DEV Dev,
+ VL53L0_DeviceModes DeviceMode,
+ FixPoint1616_t ThresholdLow,
+ FixPoint1616_t ThresholdHigh);
+ VL53L0_Error(*GetInterruptThresholds)(VL53L0_DEV Dev,
+ VL53L0_DeviceModes DeviceMode,
+ FixPoint1616_t *pThresholdLow,
+ FixPoint1616_t *pThresholdHigh);
+ VL53L0_Error(*ClearInterruptMask)(VL53L0_DEV Dev,
+ uint32_t InterruptMask);
+ VL53L0_Error(*GetInterruptMaskStatus)(VL53L0_DEV Dev,
+ uint32_t *pInterruptMaskStatus);
+ VL53L0_Error(*EnableInterruptMask)(VL53L0_DEV Dev,
+ uint32_t InterruptMask);
+ VL53L0_Error(*SetSpadAmbientDamperThreshold)(VL53L0_DEV Dev,
+ uint16_t SpadAmbientDamperThreshold);
+ VL53L0_Error(*GetSpadAmbientDamperThreshold)(VL53L0_DEV Dev,
+ uint16_t *pSpadAmbientDamperThreshold);
+ VL53L0_Error(*SetSpadAmbientDamperFactor)(VL53L0_DEV Dev,
+ uint16_t SpadAmbientDamperFactor);
+ VL53L0_Error(*GetSpadAmbientDamperFactor)(VL53L0_DEV Dev,
+ uint16_t *pSpadAmbientDamperFactor);
+ VL53L0_Error(*PerformRefSpadManagement)(VL53L0_DEV Dev,
+ uint32_t *refSpadCount, uint8_t *isApertureSpads);
+};
+
+static struct stmvl53l0_api_fn_t stmvl53l0_api_func_tbl = {
+ .GetVersion = VL53L0_GetVersion,
+ .GetPalSpecVersion = VL53L0_GetPalSpecVersion,
+ .GetProductRevision = VL53L0_GetProductRevision,
+ .GetDeviceInfo = VL53L0_GetDeviceInfo,
+ .GetDeviceErrorStatus = VL53L0_GetDeviceErrorStatus,
+ .GetRangeStatusString = VL53L0_GetRangeStatusString,
+ .GetDeviceErrorString = VL53L0_GetDeviceErrorString,
+ .GetPalErrorString = VL53L0_GetPalErrorString,
+ .GetPalState = VL53L0_GetPalState,
+ .SetPowerMode = VL53L0_SetPowerMode,
+ .GetPowerMode = VL53L0_GetPowerMode,
+ .SetOffsetCalibrationDataMicroMeter =
+ VL53L0_SetOffsetCalibrationDataMicroMeter,
+ .SetLinearityCorrectiveGain =
+ VL53L0_SetLinearityCorrectiveGain,
+ .GetLinearityCorrectiveGain =
+ VL53L0_GetLinearityCorrectiveGain,
+ .GetOffsetCalibrationDataMicroMeter =
+ VL53L0_GetOffsetCalibrationDataMicroMeter,
+ .SetGroupParamHold = VL53L0_SetGroupParamHold,
+ .GetUpperLimitMilliMeter = VL53L0_GetUpperLimitMilliMeter,
+ .SetDeviceAddress = VL53L0_SetDeviceAddress,
+ .DataInit = VL53L0_DataInit,
+ .SetTuningSettingBuffer = VL53L0_SetTuningSettingBuffer,
+ .GetTuningSettingBuffer = VL53L0_GetTuningSettingBuffer,
+ .StaticInit = VL53L0_StaticInit,
+ .WaitDeviceBooted = VL53L0_WaitDeviceBooted,
+ .ResetDevice = VL53L0_ResetDevice,
+ .SetDeviceParameters = VL53L0_SetDeviceParameters,
+ .SetDeviceMode = VL53L0_SetDeviceMode,
+ .GetDeviceMode = VL53L0_GetDeviceMode,
+ .SetHistogramMode = VL53L0_SetHistogramMode,
+ .GetHistogramMode = VL53L0_GetHistogramMode,
+ .SetMeasurementTimingBudgetMicroSeconds =
+ VL53L0_SetMeasurementTimingBudgetMicroSeconds,
+ .GetMeasurementTimingBudgetMicroSeconds =
+ VL53L0_GetMeasurementTimingBudgetMicroSeconds,
+ .GetVcselPulsePeriod = VL53L0_GetVcselPulsePeriod,
+ .SetVcselPulsePeriod = VL53L0_SetVcselPulsePeriod,
+ .SetSequenceStepEnable = VL53L0_SetSequenceStepEnable,
+ .GetSequenceStepEnable = VL53L0_GetSequenceStepEnable,
+ .GetSequenceStepEnables = VL53L0_GetSequenceStepEnables,
+ .SetSequenceStepTimeout = VL53L0_SetSequenceStepTimeout,
+ .GetSequenceStepTimeout = VL53L0_GetSequenceStepTimeout,
+ .GetNumberOfSequenceSteps = VL53L0_GetNumberOfSequenceSteps,
+ .GetSequenceStepsInfo = VL53L0_GetSequenceStepsInfo,
+ .SetInterMeasurementPeriodMilliSeconds =
+ VL53L0_SetInterMeasurementPeriodMilliSeconds,
+ .GetInterMeasurementPeriodMilliSeconds =
+ VL53L0_GetInterMeasurementPeriodMilliSeconds,
+ .SetXTalkCompensationEnable = VL53L0_SetXTalkCompensationEnable,
+ .GetXTalkCompensationEnable = VL53L0_GetXTalkCompensationEnable,
+ .SetXTalkCompensationRateMegaCps =
+ VL53L0_SetXTalkCompensationRateMegaCps,
+ .GetXTalkCompensationRateMegaCps =
+ VL53L0_GetXTalkCompensationRateMegaCps,
+ .GetNumberOfLimitCheck = VL53L0_GetNumberOfLimitCheck,
+ .GetLimitCheckInfo = VL53L0_GetLimitCheckInfo,
+ .SetLimitCheckEnable = VL53L0_SetLimitCheckEnable,
+ .GetLimitCheckEnable = VL53L0_GetLimitCheckEnable,
+ .SetLimitCheckValue = VL53L0_SetLimitCheckValue,
+ .GetLimitCheckValue = VL53L0_GetLimitCheckValue,
+ .GetLimitCheckCurrent = VL53L0_GetLimitCheckCurrent,
+ .SetWrapAroundCheckEnable = VL53L0_SetWrapAroundCheckEnable,
+ .GetWrapAroundCheckEnable = VL53L0_GetWrapAroundCheckEnable,
+ .PerformSingleMeasurement = VL53L0_PerformSingleMeasurement,
+ .PerformRefCalibration = VL53L0_PerformRefCalibration,
+ .PerformXTalkCalibration = VL53L0_PerformXTalkCalibration,
+ .PerformOffsetCalibration = VL53L0_PerformOffsetCalibration,
+ .StartMeasurement = VL53L0_StartMeasurement,
+ .StopMeasurement = VL53L0_StopMeasurement,
+ .GetMeasurementDataReady = VL53L0_GetMeasurementDataReady,
+ .WaitDeviceReadyForNewMeasurement =
+ VL53L0_WaitDeviceReadyForNewMeasurement,
+ .GetRangingMeasurementData = VL53L0_GetRangingMeasurementData,
+ .GetHistogramMeasurementData = VL53L0_GetHistogramMeasurementData,
+ .PerformSingleRangingMeasurement =
+ VL53L0_PerformSingleRangingMeasurement,
+ .PerformSingleHistogramMeasurement =
+ VL53L0_PerformSingleHistogramMeasurement,
+ .SetNumberOfROIZones = VL53L0_SetNumberOfROIZones,
+ .GetNumberOfROIZones = VL53L0_GetNumberOfROIZones,
+ .GetMaxNumberOfROIZones = VL53L0_GetMaxNumberOfROIZones,
+ .SetGpioConfig = VL53L0_SetGpioConfig,
+ .GetGpioConfig = VL53L0_GetGpioConfig,
+ .SetInterruptThresholds = VL53L0_SetInterruptThresholds,
+ .GetInterruptThresholds = VL53L0_GetInterruptThresholds,
+ .ClearInterruptMask = VL53L0_ClearInterruptMask,
+ .GetInterruptMaskStatus = VL53L0_GetInterruptMaskStatus,
+ .EnableInterruptMask = VL53L0_EnableInterruptMask,
+ .SetSpadAmbientDamperThreshold = VL53L0_SetSpadAmbientDamperThreshold,
+ .GetSpadAmbientDamperThreshold = VL53L0_GetSpadAmbientDamperThreshold,
+ .SetSpadAmbientDamperFactor = VL53L0_SetSpadAmbientDamperFactor,
+ .GetSpadAmbientDamperFactor = VL53L0_GetSpadAmbientDamperFactor,
+ .PerformRefSpadManagement = VL53L0_PerformRefSpadManagement,
+};
+struct stmvl53l0_api_fn_t *papi_func_tbl;
+
+int stmvl53l0_stopmeasurement(struct stmvl53l0_data *data)
+{
+ uint32_t us;
+
+ VL53L0_StopMeasurement(data);
+ VL53L0_GetMeasurementTimingBudgetMicroSeconds(
+ data, (uint32_t *)&us);
+ udelay(us);
+ return 0;
+}
+
+static void stmvl53l0_setupAPIFunctions(struct stmvl53l0_data *data)
+{
+ uint8_t revision = 0;
+ VL53L0_DEV vl53l0_dev = data;
+
+ /* Read Revision ID */
+ VL53L0_RdByte(vl53l0_dev,
+ VL53L0_REG_IDENTIFICATION_REVISION_ID, &revision);
+ vl53l0_errmsg("read REVISION_ID: 0x%x\n", revision);
+ revision = (revision & 0xF0) >> 4;
+ data->cut_v = revision;
+ if (revision == 1) {
+ /*cut 1.1*/
+ vl53l0_errmsg("to setup API cut 1.1\n");
+ papi_func_tbl->GetVersion = VL53L0_GetVersion;
+ papi_func_tbl->GetPalSpecVersion = VL53L0_GetPalSpecVersion;
+ papi_func_tbl->GetProductRevision = VL53L0_GetProductRevision;
+ papi_func_tbl->GetDeviceInfo = VL53L0_GetDeviceInfo;
+ papi_func_tbl->GetDeviceErrorStatus =
+ VL53L0_GetDeviceErrorStatus;
+ papi_func_tbl->GetDeviceErrorString =
+ VL53L0_GetDeviceErrorString;
+ papi_func_tbl->GetPalErrorString = VL53L0_GetPalErrorString;
+ papi_func_tbl->GetPalState = VL53L0_GetPalState;
+ papi_func_tbl->SetPowerMode = VL53L0_SetPowerMode;
+ papi_func_tbl->GetPowerMode = VL53L0_GetPowerMode;
+ papi_func_tbl->SetOffsetCalibrationDataMicroMeter =
+ VL53L0_SetOffsetCalibrationDataMicroMeter;
+ papi_func_tbl->GetOffsetCalibrationDataMicroMeter =
+ VL53L0_GetOffsetCalibrationDataMicroMeter;
+ papi_func_tbl->SetLinearityCorrectiveGain =
+ VL53L0_SetLinearityCorrectiveGain;
+ papi_func_tbl->GetLinearityCorrectiveGain =
+ VL53L0_GetLinearityCorrectiveGain;
+ papi_func_tbl->SetGroupParamHold = VL53L0_SetGroupParamHold;
+ papi_func_tbl->GetUpperLimitMilliMeter =
+ VL53L0_GetUpperLimitMilliMeter;
+ papi_func_tbl->SetDeviceAddress = VL53L0_SetDeviceAddress;
+ papi_func_tbl->DataInit = VL53L0_DataInit;
+ papi_func_tbl->SetTuningSettingBuffer =
+ VL53L0_SetTuningSettingBuffer;
+ papi_func_tbl->GetTuningSettingBuffer =
+ VL53L0_GetTuningSettingBuffer;
+ papi_func_tbl->StaticInit = VL53L0_StaticInit;
+ papi_func_tbl->WaitDeviceBooted = VL53L0_WaitDeviceBooted;
+ papi_func_tbl->ResetDevice = VL53L0_ResetDevice;
+ papi_func_tbl->SetDeviceParameters = VL53L0_SetDeviceParameters;
+ papi_func_tbl->SetDeviceMode = VL53L0_SetDeviceMode;
+ papi_func_tbl->GetDeviceMode = VL53L0_GetDeviceMode;
+ papi_func_tbl->SetHistogramMode = VL53L0_SetHistogramMode;
+ papi_func_tbl->GetHistogramMode = VL53L0_GetHistogramMode;
+ papi_func_tbl->SetMeasurementTimingBudgetMicroSeconds =
+ VL53L0_SetMeasurementTimingBudgetMicroSeconds;
+ papi_func_tbl->GetMeasurementTimingBudgetMicroSeconds =
+ VL53L0_GetMeasurementTimingBudgetMicroSeconds;
+ papi_func_tbl->GetVcselPulsePeriod = VL53L0_GetVcselPulsePeriod;
+ papi_func_tbl->SetVcselPulsePeriod = VL53L0_SetVcselPulsePeriod;
+ papi_func_tbl->SetSequenceStepEnable =
+ VL53L0_SetSequenceStepEnable;
+ papi_func_tbl->GetSequenceStepEnable =
+ VL53L0_GetSequenceStepEnable;
+ papi_func_tbl->GetSequenceStepEnables =
+ VL53L0_GetSequenceStepEnables;
+ papi_func_tbl->SetSequenceStepTimeout =
+ VL53L0_SetSequenceStepTimeout;
+ papi_func_tbl->GetSequenceStepTimeout =
+ VL53L0_GetSequenceStepTimeout;
+ papi_func_tbl->GetNumberOfSequenceSteps =
+ VL53L0_GetNumberOfSequenceSteps;
+ papi_func_tbl->GetSequenceStepsInfo =
+ VL53L0_GetSequenceStepsInfo;
+ papi_func_tbl->SetInterMeasurementPeriodMilliSeconds =
+ VL53L0_SetInterMeasurementPeriodMilliSeconds;
+ papi_func_tbl->GetInterMeasurementPeriodMilliSeconds =
+ VL53L0_GetInterMeasurementPeriodMilliSeconds;
+ papi_func_tbl->SetXTalkCompensationEnable =
+ VL53L0_SetXTalkCompensationEnable;
+ papi_func_tbl->GetXTalkCompensationEnable =
+ VL53L0_GetXTalkCompensationEnable;
+ papi_func_tbl->SetXTalkCompensationRateMegaCps =
+ VL53L0_SetXTalkCompensationRateMegaCps;
+ papi_func_tbl->GetXTalkCompensationRateMegaCps =
+ VL53L0_GetXTalkCompensationRateMegaCps;
+ papi_func_tbl->GetNumberOfLimitCheck =
+ VL53L0_GetNumberOfLimitCheck;
+ papi_func_tbl->GetLimitCheckInfo = VL53L0_GetLimitCheckInfo;
+ papi_func_tbl->SetLimitCheckEnable = VL53L0_SetLimitCheckEnable;
+ papi_func_tbl->GetLimitCheckEnable = VL53L0_GetLimitCheckEnable;
+ papi_func_tbl->SetLimitCheckValue = VL53L0_SetLimitCheckValue;
+ papi_func_tbl->GetLimitCheckValue = VL53L0_GetLimitCheckValue;
+ papi_func_tbl->GetLimitCheckCurrent =
+ VL53L0_GetLimitCheckCurrent;
+ papi_func_tbl->SetWrapAroundCheckEnable =
+ VL53L0_SetWrapAroundCheckEnable;
+ papi_func_tbl->GetWrapAroundCheckEnable =
+ VL53L0_GetWrapAroundCheckEnable;
+ papi_func_tbl->PerformSingleMeasurement =
+ VL53L0_PerformSingleMeasurement;
+ papi_func_tbl->PerformRefCalibration =
+ VL53L0_PerformRefCalibration;
+ papi_func_tbl->PerformXTalkCalibration =
+ VL53L0_PerformXTalkCalibration;
+ papi_func_tbl->PerformOffsetCalibration =
+ VL53L0_PerformOffsetCalibration;
+ papi_func_tbl->StartMeasurement = VL53L0_StartMeasurement;
+ papi_func_tbl->StopMeasurement = VL53L0_StopMeasurement;
+ papi_func_tbl->GetMeasurementDataReady =
+ VL53L0_GetMeasurementDataReady;
+ papi_func_tbl->WaitDeviceReadyForNewMeasurement =
+ VL53L0_WaitDeviceReadyForNewMeasurement;
+ papi_func_tbl->GetRangingMeasurementData =
+ VL53L0_GetRangingMeasurementData;
+ papi_func_tbl->GetHistogramMeasurementData =
+ VL53L0_GetHistogramMeasurementData;
+ papi_func_tbl->PerformSingleRangingMeasurement =
+ VL53L0_PerformSingleRangingMeasurement;
+ papi_func_tbl->PerformSingleHistogramMeasurement =
+ VL53L0_PerformSingleHistogramMeasurement;
+ papi_func_tbl->SetNumberOfROIZones = VL53L0_SetNumberOfROIZones;
+ papi_func_tbl->GetNumberOfROIZones = VL53L0_GetNumberOfROIZones;
+ papi_func_tbl->GetMaxNumberOfROIZones =
+ VL53L0_GetMaxNumberOfROIZones;
+ papi_func_tbl->SetGpioConfig = VL53L0_SetGpioConfig;
+ papi_func_tbl->GetGpioConfig = VL53L0_GetGpioConfig;
+ papi_func_tbl->SetInterruptThresholds =
+ VL53L0_SetInterruptThresholds;
+ papi_func_tbl->GetInterruptThresholds =
+ VL53L0_GetInterruptThresholds;
+ papi_func_tbl->ClearInterruptMask = VL53L0_ClearInterruptMask;
+ papi_func_tbl->GetInterruptMaskStatus =
+ VL53L0_GetInterruptMaskStatus;
+ papi_func_tbl->EnableInterruptMask =
+ VL53L0_EnableInterruptMask;
+ papi_func_tbl->SetSpadAmbientDamperThreshold =
+ VL53L0_SetSpadAmbientDamperThreshold;
+ papi_func_tbl->GetSpadAmbientDamperThreshold =
+ VL53L0_GetSpadAmbientDamperThreshold;
+ papi_func_tbl->SetSpadAmbientDamperFactor =
+ VL53L0_SetSpadAmbientDamperFactor;
+ papi_func_tbl->GetSpadAmbientDamperFactor =
+ VL53L0_GetSpadAmbientDamperFactor;
+ papi_func_tbl->PerformRefSpadManagement =
+ VL53L0_PerformRefSpadManagement;
+
+ } else if (revision == 0) {
+ /*cut 1.0*/
+ vl53l0_errmsg("to setup API cut 1.0\n");
+ papi_func_tbl->GetVersion = VL53L010_GetVersion;
+ papi_func_tbl->GetPalSpecVersion = VL53L010_GetPalSpecVersion;
+ papi_func_tbl->GetDeviceInfo = VL53L010_GetDeviceInfo;
+ papi_func_tbl->GetDeviceErrorStatus =
+ VL53L010_GetDeviceErrorStatus;
+ papi_func_tbl->GetDeviceErrorString =
+ VL53L010_GetDeviceErrorString;
+ papi_func_tbl->GetPalErrorString = VL53L010_GetPalErrorString;
+ papi_func_tbl->GetPalState = VL53L010_GetPalState;
+ papi_func_tbl->SetPowerMode = VL53L010_SetPowerMode;
+ papi_func_tbl->GetPowerMode = VL53L010_GetPowerMode;
+ papi_func_tbl->SetOffsetCalibrationDataMicroMeter =
+ VL53L010_SetOffsetCalibrationDataMicroMeter;
+ papi_func_tbl->GetOffsetCalibrationDataMicroMeter =
+ VL53L010_GetOffsetCalibrationDataMicroMeter;
+ papi_func_tbl->SetGroupParamHold = VL53L010_SetGroupParamHold;
+ papi_func_tbl->GetUpperLimitMilliMeter =
+ VL53L010_GetUpperLimitMilliMeter;
+ papi_func_tbl->SetDeviceAddress = VL53L010_SetDeviceAddress;
+ papi_func_tbl->DataInit = VL53L010_DataInit;
+ /*
+ papi_func_tbl->SetTuningSettingBuffer = NULL;
+ papi_func_tbl->GetTuningSettingBuffer = NULL;
+ */
+ papi_func_tbl->StaticInit = VL53L010_StaticInit;
+ papi_func_tbl->WaitDeviceBooted = VL53L010_WaitDeviceBooted;
+ papi_func_tbl->ResetDevice = VL53L010_ResetDevice;
+ papi_func_tbl->SetDeviceParameters =
+ VL53L010_SetDeviceParameters;
+ papi_func_tbl->SetDeviceMode = VL53L010_SetDeviceMode;
+ papi_func_tbl->GetDeviceMode = VL53L010_GetDeviceMode;
+ papi_func_tbl->SetHistogramMode = VL53L010_SetHistogramMode;
+ papi_func_tbl->GetHistogramMode = VL53L010_GetHistogramMode;
+ papi_func_tbl->SetMeasurementTimingBudgetMicroSeconds =
+ VL53L010_SetMeasurementTimingBudgetMicroSeconds;
+ papi_func_tbl->GetMeasurementTimingBudgetMicroSeconds =
+ VL53L010_GetMeasurementTimingBudgetMicroSeconds;
+ /*
+ papi_func_tbl->GetVcselPulsePeriod = NULL;
+ papi_func_tbl->SetVcselPulsePeriod = NULL;
+ papi_func_tbl->SetSequenceStepEnable = NULL;
+ papi_func_tbl->GetSequenceStepEnable = NULL;
+ papi_func_tbl->GetSequenceStepEnables = NULL;
+ papi_func_tbl->SetSequenceStepTimeout = NULL;
+ papi_func_tbl->GetSequenceStepTimeout = NULL;
+ papi_func_tbl->GetNumberOfSequenceSteps =NULL;
+ papi_func_tbl->GetSequenceStepsInfo = NULL;
+ */
+ papi_func_tbl->SetInterMeasurementPeriodMilliSeconds =
+ VL53L010_SetInterMeasurementPeriodMilliSeconds;
+ papi_func_tbl->GetInterMeasurementPeriodMilliSeconds =
+ VL53L010_GetInterMeasurementPeriodMilliSeconds;
+ papi_func_tbl->SetXTalkCompensationEnable =
+ VL53L010_SetXTalkCompensationEnable;
+ papi_func_tbl->GetXTalkCompensationEnable =
+ VL53L010_GetXTalkCompensationEnable;
+ papi_func_tbl->SetXTalkCompensationRateMegaCps =
+ VL53L010_SetXTalkCompensationRateMegaCps;
+ papi_func_tbl->GetXTalkCompensationRateMegaCps =
+ VL53L010_GetXTalkCompensationRateMegaCps;
+ papi_func_tbl->GetNumberOfLimitCheck =
+ VL53L010_GetNumberOfLimitCheck;
+ papi_func_tbl->GetLimitCheckInfo = VL53L010_GetLimitCheckInfo;
+ papi_func_tbl->SetLimitCheckEnable =
+ VL53L010_SetLimitCheckEnable;
+ papi_func_tbl->GetLimitCheckEnable =
+ VL53L010_GetLimitCheckEnable;
+ papi_func_tbl->SetLimitCheckValue = VL53L010_SetLimitCheckValue;
+ papi_func_tbl->GetLimitCheckValue = VL53L010_GetLimitCheckValue;
+ papi_func_tbl->GetLimitCheckCurrent =
+ VL53L010_GetLimitCheckCurrent;
+ papi_func_tbl->SetWrapAroundCheckEnable =
+ VL53L010_SetWrapAroundCheckEnable;
+ papi_func_tbl->GetWrapAroundCheckEnable =
+ VL53L010_GetWrapAroundCheckEnable;
+ papi_func_tbl->PerformSingleMeasurement =
+ VL53L010_PerformSingleMeasurement;
+ papi_func_tbl->PerformXTalkCalibration =
+ VL53L010_PerformXTalkCalibration;
+ papi_func_tbl->PerformOffsetCalibration =
+ VL53L010_PerformOffsetCalibration;
+ papi_func_tbl->StartMeasurement = VL53L010_StartMeasurement;
+ papi_func_tbl->StopMeasurement = VL53L010_StopMeasurement;
+ papi_func_tbl->GetMeasurementDataReady =
+ VL53L010_GetMeasurementDataReady;
+ papi_func_tbl->WaitDeviceReadyForNewMeasurement =
+ VL53L010_WaitDeviceReadyForNewMeasurement;
+ papi_func_tbl->GetRangingMeasurementData =
+ VL53L010_GetRangingMeasurementData;
+ papi_func_tbl->GetHistogramMeasurementData =
+ VL53L010_GetHistogramMeasurementData;
+ papi_func_tbl->PerformSingleRangingMeasurement =
+ VL53L010_PerformSingleRangingMeasurement;
+ papi_func_tbl->PerformSingleHistogramMeasurement =
+ VL53L010_PerformSingleHistogramMeasurement;
+ papi_func_tbl->SetNumberOfROIZones =
+ VL53L010_SetNumberOfROIZones;
+ papi_func_tbl->GetNumberOfROIZones =
+ VL53L010_GetNumberOfROIZones;
+ papi_func_tbl->GetMaxNumberOfROIZones =
+ VL53L010_GetMaxNumberOfROIZones;
+ papi_func_tbl->SetGpioConfig = VL53L010_SetGpioConfig;
+ papi_func_tbl->GetGpioConfig = VL53L010_GetGpioConfig;
+ papi_func_tbl->SetInterruptThresholds =
+ VL53L010_SetInterruptThresholds;
+ papi_func_tbl->GetInterruptThresholds =
+ VL53L010_GetInterruptThresholds;
+ papi_func_tbl->ClearInterruptMask =
+ VL53L010_ClearInterruptMask;
+ papi_func_tbl->GetInterruptMaskStatus =
+ VL53L010_GetInterruptMaskStatus;
+ papi_func_tbl->EnableInterruptMask =
+ VL53L010_EnableInterruptMask;
+ papi_func_tbl->SetSpadAmbientDamperThreshold =
+ VL53L010_SetSpadAmbientDamperThreshold;
+ papi_func_tbl->GetSpadAmbientDamperThreshold =
+ VL53L010_GetSpadAmbientDamperThreshold;
+ papi_func_tbl->SetSpadAmbientDamperFactor =
+ VL53L010_SetSpadAmbientDamperFactor;
+ papi_func_tbl->GetSpadAmbientDamperFactor =
+ VL53L010_GetSpadAmbientDamperFactor;
+ }
+
+}
+/*
+ * IOCTL definitions
+ */
+#define VL53L0_IOCTL_INIT _IO('p', 0x01)
+#define VL53L0_IOCTL_INIT_NS _IO('p', 0x11)
+#define VL53L0_IOCTL_INIT_NB _IO('p', 0x90)
+#define VL53L0_IOCTL_SUSPEND _IO('p', 0x93)
+#define VL53L0_IOCTL_RESUME _IO('p', 0x94)
+#define VL53L0_IOCTL_RESET _IO('p', 0x95)
+#define VL53L0_IOCTL_RESET_NB _IO('p', 0x96)
+#define VL53L0_IOCTL_XTALKCALB _IOWR('p', 0x02, unsigned int)
+#define VL53L0_IOCTL_OFFCALB _IOW('p', 0x03, unsigned int)
+#define VL53L0_IOCTL_STOPCALB _IO('p', 0x04)
+#define VL53L0_IOCTL_STOP _IO('p', 0x05)
+#define VL53L0_IOCTL_SETXTALK _IOW('p', 0x06, unsigned int)
+#define VL53L0_IOCTL_SETOFFSET _IOW('p', 0x07, int8_t)
+#define VL53L0_IOCTL_GETDATAS \
+ _IOR('p', 0x0b, VL53L0_RangingMeasurementData_t)
+#define VL53L0_IOCTL_REGISTER \
+ _IOWR('p', 0x0c, struct stmvl53l0_register)
+#define VL53L0_IOCTL_PARAMETER \
+ _IOWR('p', 0x0d, struct stmvl53l0_parameter)
+#define VL53L0_IOCTL_GETDATAS_BLOCK \
+ _IOR('p', 0x0e, VL53L0_RangingMeasurementData_t)
+
+#define VL53L0_FAST_HISTOGRAMMODE_REFERENCE ((VL53L0_HistogramTest) 1)
+#define VL53L0_FAST_HISTOGRAMMODE_RETURN ((VL53L0_HistogramTest) 2)
+#define VL53L0_FAST_HISTOGRAMMODE_AMBIENT ((VL53L0_HistogramTest) 3)
+
+
+static long stmvl53l0_ioctl(struct file *file,
+ unsigned int cmd,
+ unsigned long arg);
+static int stmvl53l0_flush(struct file *file, fl_owner_t id);
+static int stmvl53l0_open(struct inode *inode, struct file *file);
+static int stmvl53l0_close(struct inode *inode, struct file *file);
+static int stmvl53l0_init_client(struct stmvl53l0_data *data);
+static int stmvl53l0_start(struct stmvl53l0_data *data);
+static int stmvl53l0_stop(struct stmvl53l0_data *data);
+
+void stmvl53l0_dumpreg(struct stmvl53l0_data *data)
+{
+ int i = 0;
+ uint8_t reg;
+
+ if (data->enableDebug) {
+ for (i = 1; i <= 0xff; i++) {
+ VL53L0_RdByte(data, i, ®);
+ pr_err("STM VL53L0 reg= %x. value:%x.\n", i, reg);
+ }
+ }
+
+}
+
+void stmvl53l0_apply_parameters(struct stmvl53l0_data *vl53l0_dev)
+{
+ int i;
+ struct stmvl53l0_parameter parameter;
+
+ for (i = 0; i < s_nump; i++) {
+ parameter = s_parameters[i];
+ switch (parameter.name) {
+ case (OFFSET_PAR):
+ if (parameter.is_read)
+ parameter.status =
+ papi_func_tbl->GetOffsetCalibrationDataMicroMeter(
+ vl53l0_dev, ¶meter.value);
+ else
+ parameter.status =
+ papi_func_tbl->SetOffsetCalibrationDataMicroMeter(
+ vl53l0_dev, parameter.value);
+ break;
+ case (XTALKRATE_PAR):
+ if (parameter.is_read)
+ parameter.status =
+ VL53L0_GetXTalkCompensationRateMegaCps(
+ vl53l0_dev, (FixPoint1616_t *)¶meter.value);
+ else
+ parameter.status =
+ papi_func_tbl->SetXTalkCompensationRateMegaCps(
+ vl53l0_dev, (FixPoint1616_t)parameter.value);
+ break;
+ case (XTALKENABLE_PAR):
+ if (parameter.is_read)
+ parameter.status =
+ papi_func_tbl->GetXTalkCompensationEnable(
+ vl53l0_dev, (uint8_t *)¶meter.value);
+ else
+ parameter.status =
+ papi_func_tbl->SetXTalkCompensationEnable(
+ vl53l0_dev, (uint8_t)parameter.value);
+ break;
+ case (SIGMAVAL_PRA):
+ if (!parameter.is_read)
+ parameter.status = papi_func_tbl->
+ SetLimitCheckValue(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (FixPoint1616_t)parameter.value);
+ else
+ parameter.status = papi_func_tbl->
+ GetLimitCheckValue(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (FixPoint1616_t *)¶meter.value);
+ break;
+
+ case (SIGMACTL_PRA):
+ if (!parameter.is_read)
+ parameter.status =
+ papi_func_tbl->SetLimitCheckEnable(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (uint8_t)parameter.value);
+ else
+ parameter.status =
+ papi_func_tbl->GetLimitCheckEnable(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (uint8_t *)¶meter.value);
+ break;
+ case (SGLVAL_PRA):
+ if (!parameter.is_read)
+ parameter.status = papi_func_tbl->
+ SetLimitCheckValue(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (FixPoint1616_t)parameter.value);
+ else
+ parameter.status = papi_func_tbl->
+ GetLimitCheckValue(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (FixPoint1616_t *)¶meter.value);
+ break;
+
+ case (SGLCTL_PRA):
+ if (!parameter.is_read)
+ parameter.status =
+ papi_func_tbl->SetLimitCheckEnable(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (uint8_t)parameter.value);
+ else
+ parameter.status =
+ papi_func_tbl->GetLimitCheckEnable(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (uint8_t *)¶meter.value);
+ break;
+
+ case (WRAPAROUNDCTL_PRA):
+ if (parameter.is_read)
+ parameter.status =
+ VL53L0_GetWrapAroundCheckEnable(
+ vl53l0_dev, (uint8_t *)¶meter.value);
+ else
+ parameter.status =
+ VL53L0_SetWrapAroundCheckEnable(
+ vl53l0_dev, (uint8_t)parameter.value);
+ break;
+
+ case (MEASUREMENTTIMINGBUDGET_PAR):
+ if (parameter.is_read)
+ parameter.status =
+ VL53L0_GetMeasurementTimingBudgetMicroSeconds(
+ vl53l0_dev, (uint32_t *)¶meter.value);
+ else
+ parameter.status =
+ VL53L0_SetMeasurementTimingBudgetMicroSeconds(
+ vl53l0_dev, (uint32_t)parameter.value);
+ break;
+ case (PLLPRE_PRA):
+ if (parameter.is_read)
+ parameter.status =
+ papi_func_tbl->GetVcselPulsePeriod(vl53l0_dev,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE, (uint8_t *)¶meter.value);
+ else
+ parameter.status =
+ papi_func_tbl->SetVcselPulsePeriod(vl53l0_dev,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE, (uint8_t)parameter.value);
+ break;
+ case (PLLFINAL_PRA):
+ if (parameter.is_read)
+ parameter.status =
+ papi_func_tbl->GetVcselPulsePeriod(vl53l0_dev,
+ VL53L0_VCSEL_PERIOD_FINAL_RANGE, (uint8_t *)¶meter.value);
+ else
+ parameter.status =
+ papi_func_tbl->SetVcselPulsePeriod(vl53l0_dev,
+ VL53L0_VCSEL_PERIOD_FINAL_RANGE, (uint8_t)parameter.value);
+ break;
+ }
+
+ }
+ s_nump = 0;
+}
+
+static void stmvl53l0_ps_read_measurement(struct stmvl53l0_data *data)
+{
+ struct timeval tv;
+
+ do_gettimeofday(&tv);
+ data->ps_data = 100;
+ if (data->rangeData.RangeMilliMeter < data->highv)
+ data->ps_data = 10;
+ if (data->gpio_function == VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW)
+ data->ps_data = 10;
+
+ input_report_abs(data->input_dev_ps, ABS_DISTANCE,
+ (int)(data->ps_data + 5) / 10);
+ input_report_abs(data->input_dev_ps, ABS_HAT0X, tv.tv_sec);
+ input_report_abs(data->input_dev_ps, ABS_HAT0Y, tv.tv_usec);
+ input_report_abs(data->input_dev_ps, ABS_HAT1X,
+ data->rangeData.RangeMilliMeter);
+ input_report_abs(data->input_dev_ps, ABS_HAT1Y,
+ data->rangeData.RangeStatus);
+ input_report_abs(data->input_dev_ps, ABS_HAT2X,
+ data->rangeData.SignalRateRtnMegaCps);
+ input_report_abs(data->input_dev_ps, ABS_HAT2Y,
+ data->rangeData.AmbientRateRtnMegaCps);
+ input_report_abs(data->input_dev_ps, ABS_HAT3X,
+ data->rangeData.MeasurementTimeUsec);
+ input_report_abs(data->input_dev_ps, ABS_HAT3Y,
+ data->rangeData.RangeDMaxMilliMeter);
+ input_sync(data->input_dev_ps);
+
+ if (data->enableDebug)
+ vl53l0_errmsg("range:%d, signalRateRtnMegaCps:%d, \
+ error:0x%x,rtnambrate:%u,DMax:%d,measuretime:%u\n",
+ data->rangeData.RangeMilliMeter,
+ data->rangeData.SignalRateRtnMegaCps,
+ data->rangeData.RangeStatus,
+ data->rangeData.AmbientRateRtnMegaCps,
+ data->rangeData.RangeDMaxMilliMeter,
+ data->rangeData.MeasurementTimeUsec);
+
+}
+
+static void stmvl53l0_enter_off(struct stmvl53l0_data *data, uint8_t from)
+{
+ vl53l0_dbgmsg_en("Enter, stmvl53l0_enter_off from:%d\n", from);
+ if (data->enable_ps_sensor == 0)
+ stmvl53l0_start(data);
+ papi_func_tbl->StopMeasurement(data);
+ papi_func_tbl->ClearInterruptMask(data, 0);
+ papi_func_tbl->SetDeviceMode(data,
+ VL53L0_DEVICEMODE_SINGLE_RANGING);
+ papi_func_tbl->SetGpioConfig(data, 0, 0,
+ VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY,
+ VL53L0_INTERRUPTPOLARITY_LOW);
+ data->gpio_function = VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY;
+
+ vl53l0_dbgmsg_en("End\n");
+}
+
+static void stmvl53l0_enter_cam(struct stmvl53l0_data *data, uint8_t from)
+{
+
+ vl53l0_errmsg("Enter, stmvl53l0_enter_cam from:%d\n", from);
+ /* turn on tof sensor */
+ if (data->enable_ps_sensor == 0)
+ stmvl53l0_start(data);
+ papi_func_tbl->SetVcselPulsePeriod(data,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE, data->pll_p);
+ papi_func_tbl->SetVcselPulsePeriod(data,
+ VL53L0_VCSEL_PERIOD_FINAL_RANGE, data->pll_f);
+
+ vl53l0_errmsg("Call of setlimt \n");
+ papi_func_tbl->SetLimitCheckEnable(data,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (uint8_t)0);
+
+ papi_func_tbl->SetLimitCheckEnable(data,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (uint8_t)0);
+ vl53l0_errmsg("Call ofSetMeasurementTimingBudgetMicroSeconds \n");
+ papi_func_tbl->SetMeasurementTimingBudgetMicroSeconds(
+ data, 26000);
+
+ papi_func_tbl->SetDeviceMode(data,
+ VL53L0_DEVICEMODE_SINGLE_RANGING);
+
+ vl53l0_errmsg("Call of VL53L0_DEVICEMODE_SINGLE_RANGING\n");
+ papi_func_tbl->SetGpioConfig(data, 0, 0,
+ VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY,
+ VL53L0_INTERRUPTPOLARITY_LOW);
+ data->gpio_function = VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY;
+
+ papi_func_tbl->StartMeasurement(data);
+
+ vl53l0_errmsg("End\n");
+}
+
+static void stmvl53l0_enter_sar(struct stmvl53l0_data *data, uint8_t from)
+{
+ VL53L0_RangingMeasurementData_t RMData;
+ vl53l0_errmsg("Enter, from:%d\n", from);
+ /* turn on tof sensor */
+ if (data->enable_ps_sensor == 0)
+ stmvl53l0_start(data);
+
+ memset(&RMData, 0, sizeof(RMData));
+
+ papi_func_tbl->SetDeviceMode(data,
+ VL53L0_DEVICEMODE_SINGLE_RANGING);
+
+ papi_func_tbl->SetVcselPulsePeriod(data,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE, 14);
+
+ papi_func_tbl->SetVcselPulsePeriod(data,
+ VL53L0_VCSEL_PERIOD_FINAL_RANGE, 10);
+
+ papi_func_tbl->SetLimitCheckEnable(data,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (uint8_t)1);
+
+ papi_func_tbl->SetLimitCheckEnable(data,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (uint8_t)0);
+
+ papi_func_tbl->SetMeasurementTimingBudgetMicroSeconds(
+ data, 33000);
+
+ papi_func_tbl->PerformSingleRangingMeasurement(data,
+ &RMData);
+ memcpy(&(data->rangeData), &RMData,
+ sizeof(VL53L0_RangingMeasurementData_t));
+ stmvl53l0_ps_read_measurement(data);
+
+ papi_func_tbl->SetGpioConfig(data, 0, 0,
+ VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW,
+ VL53L0_INTERRUPTPOLARITY_LOW);
+ data->gpio_function = VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW;
+ papi_func_tbl->SetInterMeasurementPeriodMilliSeconds(
+ data, 5000);
+ papi_func_tbl->SetMeasurementTimingBudgetMicroSeconds(
+ data, 33000);
+ papi_func_tbl->SetInterruptThresholds(
+ data, 0, data->lowv << 16, data->highv << 16);
+ papi_func_tbl->SetDeviceMode(data,
+ VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING);
+ data->lowint = 1;
+ papi_func_tbl->ClearInterruptMask(data, 0);
+ papi_func_tbl->StartMeasurement(data);
+ vl53l0_errmsg("End\n");
+}
+static void stmvl53l0_enter_super(struct stmvl53l0_data *data, uint8_t from)
+{
+ vl53l0_errmsg("Enter, stmvl53l0_enter_super flag:%d\n", from);
+ if (from == SAR_MODE || from == SUPER_MODE) {
+ vl53l0_dbgmsg_en("Call of VL53L0_DEVICEMODE_CONTINUOUS_RANGING\n");
+ papi_func_tbl->ClearInterruptMask(data, 0);
+
+ papi_func_tbl->SetVcselPulsePeriod(data,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE, 18);
+
+ papi_func_tbl->SetVcselPulsePeriod(data,
+ VL53L0_VCSEL_PERIOD_FINAL_RANGE, 14);
+
+ papi_func_tbl->SetLimitCheckEnable(data,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (uint8_t)0);
+
+ papi_func_tbl->SetLimitCheckEnable(data,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (uint8_t)0);
+
+ papi_func_tbl->SetMeasurementTimingBudgetMicroSeconds(
+ data, 26000);
+
+ papi_func_tbl->SetDeviceMode(data,
+ VL53L0_DEVICEMODE_SINGLE_RANGING);
+
+ vl53l0_errmsg("Call of VL53L0_DEVICEMODE_SINGLE_RANGING\n");
+ papi_func_tbl->SetGpioConfig(data, 0, 0,
+ VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY,
+ VL53L0_INTERRUPTPOLARITY_LOW);
+ data->gpio_function = VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY;
+
+ papi_func_tbl->StartMeasurement(data);
+
+ vl53l0_errmsg("End\n");
+ }
+
+ vl53l0_dbgmsg_en("End\n");
+}
+static void stmvl53l0_enter_xtalkcal(struct stmvl53l0_data *data,
+ uint8_t from)
+{
+ FixPoint1616_t XTalkCompensationRateMegaCps;
+
+ vl53l0_dbgmsg_en("Enter, stmvl53l0_enter_cal flag:%d\n", from);
+ if (data->enable_ps_sensor == 0)
+ stmvl53l0_start(data);
+
+ papi_func_tbl->SetXTalkCompensationEnable(data, 0);
+
+ papi_func_tbl->PerformXTalkCalibration(data,
+ (data->xtalkCalDistance << 16), &XTalkCompensationRateMegaCps);
+ data->xtalkcalval = XTalkCompensationRateMegaCps;
+ vl53l0_dbgmsg_en("End\n");
+}
+static void stmvl53l0_enter_offsetcal(struct stmvl53l0_data *data,
+ uint8_t from)
+{
+ FixPoint1616_t OffsetMicroMeter;
+
+ vl53l0_dbgmsg_en("Enter, stmvl53l0_enter_cal flag:%d\n", from);
+ papi_func_tbl->PerformOffsetCalibration(data,
+ (data->offsetCalDistance<<16),
+ &OffsetMicroMeter);
+ pr_err("Offset calibration:%u\n", OffsetMicroMeter);
+ vl53l0_dbgmsg_en("End\n");
+}
+static void stmvl53l0_work_state(
+struct stmvl53l0_data *data, uint8_t input)
+{
+ int nochange = 0;
+ uint8_t from = data->w_mode;
+
+ vl53l0_dbgmsg_en("Enter, stmvl53l0_work_state:%d\n", input);
+ mutex_lock(&data->work_mutex);
+ switch (data->w_mode) {
+ case OFF_MODE:
+ if (input == CAM_ON)
+ data->w_mode = CAM_MODE;
+ else if (input == SAR_ON)
+ data->w_mode = SAR_MODE;
+ else if (input == XTALKCAL_ON)
+ data->w_mode = XTALKCAL_MODE;
+ else if (input == OFFSETCAL_ON)
+ data->w_mode = OFFSETCAL_MODE;
+ else {
+ vl53l0_dbgmsg_en("unsopport status = %d,cs = OFF_MODE",
+ input);
+ nochange = 1;
+ }
+ break;
+ case CAM_MODE:
+ if (input == CAM_OFF)
+ data->w_mode = OFF_MODE;
+ else if (input == SAR_ON)
+ data->w_mode = SUPER_MODE;
+ else {
+ vl53l0_dbgmsg_en("unsopport status = %d,cs = CAM_MODE", input);
+ nochange = 1;
+ }
+ break;
+ case SAR_MODE:
+ if (input == CAM_ON)
+ data->w_mode = SUPER_MODE;
+ else if (input == SAR_OFF)
+ data->w_mode = OFF_MODE;
+ else {
+ vl53l0_dbgmsg_en("unsopport status = %d,cs = SAR_MODE", input);
+ nochange = 1;
+ }
+ break;
+ case SUPER_MODE:
+ if (input == CAM_OFF) {
+ stmvl53l0_stopmeasurement(data);
+ data->w_mode = SAR_MODE;
+ } else if (input == SAR_OFF) {
+ stmvl53l0_stopmeasurement(data);
+ data->w_mode = CAM_MODE;
+ } else {
+ vl53l0_dbgmsg_en("unsopport status= %d,cs = SUPER_MODE", input);
+ nochange = 1;
+ }
+ break;
+ case XTALKCAL_MODE:
+ if (input == CAL_OFF)
+ data->w_mode = OFF_MODE;
+ else {
+ vl53l0_dbgmsg_en("unsopport status = %d,cs= SUPER_MODE", input);
+ data->w_mode = OFF_MODE;
+ }
+ break;
+ case OFFSETCAL_MODE:
+ if (input == CAL_OFF)
+ data->w_mode = OFF_MODE;
+ else {
+ vl53l0_dbgmsg_en("unsopport status= %d,cs = SUPER_MODE", input);
+ data->w_mode = OFF_MODE;
+ }
+ break;
+ default:
+ vl53l0_dbgmsg_en("unsopport status= %d,cs = unknown", input);
+ nochange = 1;
+ break;
+ }
+ if (input == CAM_OFF && data->c_suspend == 1)
+ data->c_suspend = 0;
+
+ if (nochange && input != RESET) {
+ vl53l0_dbgmsg_en("unsopport status= %d,cs = %d",
+ input, data->w_mode);
+ mutex_unlock(&data->work_mutex);
+ return;
+ }
+ data->c_stopped = 1;
+ if (input == RESET) {
+ stmvl53l0_stop(data);
+ data->reset = 0;
+ if (data->enable_ps_sensor == 0)
+ stmvl53l0_start(data);
+ }
+
+ cancel_delayed_work(&data->dwork);
+ switch (data->w_mode) {
+ case OFF_MODE:
+ stmvl53l0_stopmeasurement(data);
+ stmvl53l0_enter_off(data, from);
+ break;
+ case CAM_MODE:
+ stmvl53l0_enter_cam(data, from);
+ break;
+ case SAR_MODE:
+ stmvl53l0_enter_sar(data, from);
+ break;
+ case SUPER_MODE:
+ stmvl53l0_stopmeasurement(data);
+ stmvl53l0_enter_super(data, from);
+ break;
+ case XTALKCAL_MODE:
+ stmvl53l0_enter_xtalkcal(data, from);
+ break;
+ case OFFSETCAL_MODE:
+ stmvl53l0_enter_offsetcal(data, from);
+ break;
+ default:
+ pr_err("status unknown, input = %d", input);
+ break;
+ }
+ data->c_stopped = 0;
+ mutex_unlock(&data->work_mutex);
+}
+
+static void stmvl53l0_cancel_handler(struct stmvl53l0_data *data)
+{
+ unsigned long flags;
+ bool ret;
+
+ spin_lock_irqsave(&data->update_lock.wait_lock, flags);
+ /*
+ * If work is already scheduled then subsequent schedules will not
+ * change the scheduled time that's why we have to cancel it first.
+ */
+ ret = cancel_delayed_work(&data->dwork);
+ if (ret == 0)
+ vl53l0_errmsg("%d,cancel_delayed_work return FALSE\n",
+ __LINE__);
+ ret = cancel_delayed_work(&data->initwork);
+ if (ret == 0)
+ vl53l0_errmsg("%d,cancel_delayed_work return FALSE\n",
+ __LINE__);
+ ret = cancel_delayed_work(&data->resetwork);
+ if (ret == 0)
+ vl53l0_errmsg("%d,cancel_delayed_work return FALSE\n",
+ __LINE__);
+ ret = cancel_delayed_work(&data->checkwork);
+ if (ret == 0)
+ vl53l0_errmsg("%d,cancel_delayEd_work return FALSE\n",
+ __LINE__);
+ spin_unlock_irqrestore(&data->update_lock.wait_lock, flags);
+
+ return;
+}
+
+static void stmvl53l0_state_process(void)
+{
+VL53L0_RangingMeasurementData_t RMData;
+struct stmvl53l0_data *data = gp_vl53l0_data;
+VL53L0_DEV vl53l0_dev = data;
+struct timeval tv;
+int newv;
+
+do_gettimeofday(&tv);
+memset(&RMData, 0, sizeof(RMData));
+papi_func_tbl->GetRangingMeasurementData(vl53l0_dev, &RMData);
+
+vl53l0_dbgmsg_en("which MODE =%d\n", data->w_mode);
+papi_func_tbl->ClearInterruptMask(vl53l0_dev, 0);
+memcpy(&(data->rangeData), &RMData,
+ sizeof(VL53L0_RangingMeasurementData_t));
+data->d_ready = 1;
+
+data->rangeData.TimeStamp = tv.tv_sec;
+data->rangeData.MeasurementTimeUsec = tv.tv_usec;
+wake_up(&data->range_data_wait);
+
+ if (CAM_MODE == data->w_mode) {
+ vl53l0_dbgmsg_en("CAM_MODE\n");
+ stmvl53l0_apply_parameters(data);
+ papi_func_tbl->StartMeasurement(data);
+ if (data->enableDebug)
+ vl53l0_errmsg("range:%d, signalRateRtnMegaCps:%d, \
+ error:0x%x,rtnambrate:%u,Dmax:%d,measuretime:%u\n",
+ data->rangeData.RangeMilliMeter,
+ data->rangeData.SignalRateRtnMegaCps,
+ data->rangeData.RangeStatus,
+ data->rangeData.AmbientRateRtnMegaCps,
+ data->rangeData.RangeDMaxMilliMeter,
+ data->rangeData.MeasurementTimeUsec);
+ } else if (SAR_MODE == data->w_mode) {
+ vl53l0_dbgmsg("SAR_MODE\n");
+ if (data->gpio_function == VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW) {
+ vl53l0_dbgmsg("SAR enter LOW\n");
+ if (data->lowint < 2) {
+ data->lowint++;
+ papi_func_tbl->ClearInterruptMask(vl53l0_dev, 0);
+ return;
+ }
+
+ papi_func_tbl->ClearInterruptMask(vl53l0_dev, 0);
+ stmvl53l0_ps_read_measurement(vl53l0_dev);
+ papi_func_tbl->SetGpioConfig(data, 0, 0,
+ VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH,
+ VL53L0_INTERRUPTPOLARITY_LOW);
+ data->gpio_function = VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH;
+ papi_func_tbl->SetInterMeasurementPeriodMilliSeconds(
+ data, 5000);
+ papi_func_tbl->SetMeasurementTimingBudgetMicroSeconds(
+ data, 33000);
+ papi_func_tbl->SetInterruptThresholds(
+ data, 0, data->lowv << 16, data->highv << 16);
+ papi_func_tbl->SetDeviceMode(data,
+ VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING);
+ data->lowint = 5;
+ papi_func_tbl->StartMeasurement(data);
+ vl53l0_dbgmsg("SAR enter LOW sent uevent\n");
+ } else if (data->gpio_function == VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH) {
+ vl53l0_dbgmsg("SAR enter HIGH\n");
+ if (data->lowint > 4) {
+ data->lowint--;
+ papi_func_tbl->ClearInterruptMask(vl53l0_dev, 0);
+ return;
+ }
+
+ papi_func_tbl->ClearInterruptMask(vl53l0_dev, 0);
+ stmvl53l0_ps_read_measurement(vl53l0_dev);
+ papi_func_tbl->SetGpioConfig(data, 0, 0,
+ VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW,
+ VL53L0_INTERRUPTPOLARITY_LOW);
+ data->gpio_function = VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW;
+ papi_func_tbl->SetInterMeasurementPeriodMilliSeconds(
+ data, 5000);
+ papi_func_tbl->SetMeasurementTimingBudgetMicroSeconds(
+ data, 33000);
+ papi_func_tbl->SetInterruptThresholds(
+ data, 0, data->lowv << 16, data->highv << 16);
+ papi_func_tbl->SetDeviceMode(data,
+ VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING);
+ data->lowint = 1;
+ papi_func_tbl->StartMeasurement(data);
+ vl53l0_dbgmsg("SAR enter high sent uevent\n");
+ }
+
+ vl53l0_dbgmsg_en("SAR measurement ready\n");
+ } else if (SUPER_MODE == data->w_mode) {
+ vl53l0_dbgmsg_en("SUPER_MODE\n");
+ stmvl53l0_apply_parameters(data);
+ newv = data->rangeData.RangeMilliMeter > data->highv ? 100:10;
+ if (s_prevalue != newv || s_count > 100)
+ stmvl53l0_ps_read_measurement(vl53l0_dev);
+ if (s_count > 100)
+ s_count = 0;
+ s_count++;
+ s_prevalue = newv;
+ papi_func_tbl->StartMeasurement(data);
+ }
+
+}
+static void stmvl53l0_init_handler(struct work_struct *work)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ vl53l0_dbgmsg_en("get in the handler\n");
+ stmvl53l0_work_state(data, CAM_ON);
+ return;
+
+}
+static void stmvl53l0_reset_handler(struct work_struct *work)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ vl53l0_dbgmsg_en("get in the handler\n");
+ stmvl53l0_work_state(data, RESET);
+ return;
+
+}
+static void stmvl53l0_check_handler(struct work_struct *work)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ vl53l0_dbgmsg_en("get in the handler\n");
+ stmvl53l0_livechecking(data);
+ schedule_delayed_work(&data->checkwork, 1800000);
+}
+/* interrupt work handler */
+static void stmvl53l0_work_handler(struct work_struct *work)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+ VL53L0_DEV vl53l0_dev = data;
+ uint32_t InterruptMask;
+
+ vl53l0_dbgmsg_en("get in the handler\n");
+
+ mutex_lock(&data->work_mutex);
+
+ if (data->enable_ps_sensor == 1 && data->c_suspend == 0 && 7 != data->d_mode && data->c_stopped == 0) {
+ papi_func_tbl->GetInterruptMaskStatus(
+ vl53l0_dev, &InterruptMask);
+
+ vl53l0_dbgmsg_en(" InterruptMasksssss :%d\n", InterruptMask);
+ if (InterruptMask > 0 && data->interrupt_received == 1) {
+ data->interrupt_received = 0;
+ stmvl53l0_state_process();
+ }
+ }
+
+ mutex_unlock(&data->work_mutex);
+
+ return;
+}
+
+/*
+ * SysFS support
+ */
+static ssize_t stmvl53l0_show_enable_ps_sensor(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ return snprintf(buf, 2, "%d\n", data->enable_ps_sensor);
+}
+
+static ssize_t stmvl53l0_store_enable_ps_sensor(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ unsigned long val;
+
+ if (kstrtoul(buf, 10, &val))
+ return count;
+
+ if ((val != 0) && (val != 1)) {
+ vl53l0_errmsg("%d,store unvalid value=%ld\n", __LINE__, val);
+ return count;
+ }
+ mutex_lock(&data->work_mutex);
+ vl53l0_dbgmsg_en("Enter, enable_ps_sensor flag:%d\n",
+ data->enable_ps_sensor);
+ vl53l0_dbgmsg_en("enable ps senosr ( %ld)\n", val);
+
+ if (val == 1) {
+ /* turn on tof sensor */
+ if (data->enable_ps_sensor == 0) {
+ /* to start */
+ stmvl53l0_start(data);
+ } else {
+ vl53l0_errmsg("%d,Already enabled. Skip !", __LINE__);
+ }
+ } else {
+ /* turn off tof sensor */
+ if (data->enable_ps_sensor == 1) {
+ data->enable_ps_sensor = 0;
+ /* to stop */
+ stmvl53l0_stop(data);
+ }
+ }
+ vl53l0_dbgmsg_en("End\n");
+ mutex_unlock(&data->work_mutex);
+
+ return count;
+}
+
+static DEVICE_ATTR(enable_ps_sensor, S_IWUSR | S_IWGRP | S_IRUGO,
+ stmvl53l0_show_enable_ps_sensor, stmvl53l0_store_enable_ps_sensor);
+static ssize_t stmvl53l0_show_set_mode(struct device *dev,
+struct device_attribute *attr, char *buf)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ return snprintf(buf, 3, "%d\n", data->d_mode);
+}
+
+/* for debug */
+static ssize_t stmvl53l0_store_set_mode(struct device *dev,
+struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+ VL53L0_RangingMeasurementData_t RMData;
+ long on;
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+
+ if (kstrtoul(buf, 10, &on))
+ return count;
+ if (on > 7) {
+ vl53l0_errmsg("%d,set d_mode=%ld\n", __LINE__, on);
+ return count;
+ }
+ data->d_mode = on;
+ /* turn on tof sensor */
+ if (data->enable_ps_sensor == 0) {
+ /* to start */
+ stmvl53l0_start(data);
+ }
+ memset(&RMData, 0, sizeof(RMData));
+ if (VL53L0_DEVICEMODE_SINGLE_RANGING == data->d_mode) {
+ vl53l0_errmsg("Call of VL53L0_DEVICEMODE_SINGLE_RANGING\n");
+ Status = papi_func_tbl->SetGpioConfig(data, 0, 0,
+ VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY,
+ VL53L0_INTERRUPTPOLARITY_LOW);
+ data->gpio_function = VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY;
+ Status = papi_func_tbl->SetDeviceMode(data,
+ VL53L0_DEVICEMODE_SINGLE_RANGING);
+ papi_func_tbl->SetMeasurementTimingBudgetMicroSeconds(
+ data, 50000);
+ Status = papi_func_tbl->PerformSingleRangingMeasurement(data,
+ &RMData);
+ stmvl53l0_ps_read_measurement(data);
+ } else if (1 == data->d_mode) {
+ vl53l0_errmsg("Call of mode 1\n");
+ Status = papi_func_tbl->SetGpioConfig(data, 0, 0,
+ VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY,
+ VL53L0_INTERRUPTPOLARITY_LOW);
+ data->gpio_function = VL53L0_GPIOFUNCTIONALITY_NEW_MEASURE_READY;
+ Status = papi_func_tbl->SetDeviceMode(data,
+ VL53L0_DEVICEMODE_CONTINUOUS_RANGING);
+ papi_func_tbl->StartMeasurement(data);
+ } else if (2 == data->d_mode) {
+ vl53l0_errmsg("Call of mode 2\n");
+ Status = papi_func_tbl->SetGpioConfig(data, 0, 0,
+ VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW,
+ VL53L0_INTERRUPTPOLARITY_LOW);
+ data->gpio_function = VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW;
+ Status = papi_func_tbl->SetDeviceMode(data,
+ VL53L0_DEVICEMODE_CONTINUOUS_RANGING);
+ papi_func_tbl->SetInterruptThresholds
+ (data, 0, 60 << 16, 80 << 16);
+ papi_func_tbl->StartMeasurement(data);
+
+ } else if (3 == data->d_mode) {
+ vl53l0_errmsg("Call mode 3\n");
+ papi_func_tbl->SetInterMeasurementPeriodMilliSeconds
+ (data, 0x00001388);
+ papi_func_tbl->SetGpioConfig(data, 0, 0,
+ VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH,
+ VL53L0_INTERRUPTPOLARITY_LOW);
+ data->gpio_function = VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH;
+ papi_func_tbl->SetInterruptThresholds
+ (data, 0, 30 << 16, 80 << 16);
+ Status = papi_func_tbl->SetDeviceMode(data,
+ VL53L0_DEVICEMODE_CONTINUOUS_TIMED_RANGING);
+ papi_func_tbl->StartMeasurement(data);
+ } else if (4 == data->d_mode) {
+ vl53l0_errmsg("Call of mode 4\n");
+ Status = papi_func_tbl->SetGpioConfig(data, 0, 0,
+ VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH,
+ VL53L0_INTERRUPTPOLARITY_LOW);
+ data->gpio_function = VL53L0_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH;
+ Status = papi_func_tbl->SetDeviceMode(data,
+ VL53L0_DEVICEMODE_CONTINUOUS_RANGING);
+ papi_func_tbl->SetInterruptThresholds
+ (data, 0, 30 << 16, 40 << 16);
+ papi_func_tbl->StartMeasurement(data);
+ } else if (5 == data->d_mode)
+ stmvl53l0_work_state(data, CAM_ON);
+ else if (6 == data->d_mode)
+ stmvl53l0_work_state(data, CAM_OFF);
+ else if (7 == data->d_mode) {
+ vl53l0_errmsg("call VL53L0_perform_single_histogram3\n");
+ /*changes for feture*/
+ /*papi_func_tbl->SetMeasurementTimingBudgetMicroSeconds(
+ data, 500000);
+ for (hdata.FirstBin = 0; hdata.FirstBin < 12; hdata.FirstBin++)
+ hdata.HistogramData[hdata.FirstBin] = 0;
+ VL53L0_perform_single_histogram(data, 1, 1, 0, &hdata);
+ vl53l0_errmsg("VL53L0_perform_single_histogram start_bin %d, NumberOfBins %d, ErrorStatus %d\n", hdata.FirstBin, hdata.NumberOfBins, hdata.ErrorStatus);
+ Start_bin = hdata.FirstBin;
+ vl53l0_errmsg("call VL53L0_perform_single_histogram3\n");
+ VL53L0_perform_single_histogram(data, 2, 1, Start_bin, &hdata);
+ vl53l0_errmsg("VL53L0_perform_single_histogram start_bin %d, NumberOfBins %d, ErrorStatus %d\n", hdata.FirstBin, hdata.NumberOfBins, hdata.ErrorStatus);
+ vl53l0_errmsg("VL53L0_perform_single_histogram 1 %d, 2 %d, 3 %d, 4 %d\n", hdata.HistogramData[hdata.FirstBin], hdata.HistogramData[hdata.FirstBin+1],
+ hdata.HistogramData[hdata.FirstBin+2], hdata.HistogramData[hdata.FirstBin+3]);
+ vl53l0_errmsg("VL53L0_perform_single_histogram 5 %d, 6 %d, 7 %d, 8 %d\n", hdata.HistogramData[hdata.FirstBin+4], hdata.HistogramData[hdata.FirstBin+5],
+ hdata.HistogramData[hdata.FirstBin+6], hdata.HistogramData[hdata.FirstBin+7]);
+ vl53l0_errmsg("VL53L0_perform_single_histogram 9 %d, 10 %d, 11 %d, 12 %d\n", hdata.HistogramData[hdata.FirstBin+8], hdata.HistogramData[hdata.FirstBin+9],
+ hdata.HistogramData[hdata.FirstBin+10], hdata.HistogramData[hdata.FirstBin+11]);
+
+ VL53L0_perform_single_histogram(data, 2, 1, 3, &hdata);
+ vl53l0_errmsg("VL53L0_perform_single_histogram start_bin %d, NumberOfBins %d, ErrorStatus %d\n", hdata.FirstBin, hdata.NumberOfBins, hdata.ErrorStatus);
+ vl53l0_errmsg("VL53L0_perform_single_histogram 1 %d, 2 %d, 3 %d, 4 %d\n", hdata.HistogramData[hdata.FirstBin], hdata.HistogramData[hdata.FirstBin+1],
+ hdata.HistogramData[hdata.FirstBin+2], hdata.HistogramData[hdata.FirstBin+3]);
+ VL53L0_perform_single_histogram(data, 2, 1, 7, &hdata);
+ vl53l0_errmsg("VL53L0_perform_single_histogram start_bin %d, NumberOfBins %d, ErrorStatus %d\n", hdata.FirstBin, hdata.NumberOfBins, hdata.ErrorStatus);
+ vl53l0_errmsg("VL53L0_perform_single_histogram 1 %d, 2 %d, 3 %d, 4 %d\n", hdata.HistogramData[hdata.FirstBin], hdata.HistogramData[hdata.FirstBin+1],
+ hdata.HistogramData[hdata.FirstBin+2], hdata.HistogramData[hdata.FirstBin+3]);*/
+ }
+
+ return count;
+}
+/* DEVICE_ATTR(name,mode,show,store) */
+static DEVICE_ATTR(set_mode, S_IWUSR | S_IRUGO,
+ stmvl53l0_show_set_mode, stmvl53l0_store_set_mode);
+
+static ssize_t stmvl53l0_show_enable_sar(struct device *dev,
+struct device_attribute *attr, char *buf)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ return snprintf(buf, 3, "%d\n", data->w_mode);
+}
+
+/*
+ * to set sar working mode for rear proximity sensor
+ * parameter value 0: to turn sar mode off
+ * parameter value 1: to turn sar mode on
+ * parameter value 2: to reply flush call from user space by
+ * using current EV_ABS api
+ */
+static ssize_t stmvl53l0_store_enable_sar(struct device *dev,
+struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+ long on;
+
+ if (kstrtoul(buf, 10, &on))
+ return count;
+
+ if (on == 2) {
+ /* send flush reply */
+ int dt_flush = 1;
+
+ input_report_abs(data->input_dev_ps, ABS_MISC, dt_flush);
+ input_report_abs(data->input_dev_ps, ABS_MISC, ++dt_flush);
+ input_sync(data->input_dev_ps);
+ return count;
+ }
+
+ if ((on != 0) && (on != 1)) {
+ vl53l0_errmsg("%d,set debug=%ld\n", __LINE__, on);
+ return count;
+ }
+
+ if (on)
+ stmvl53l0_work_state(data, SAR_ON);
+ else
+ stmvl53l0_work_state(data, SAR_OFF);
+
+ return count;
+}
+
+/* DEVICE_ATTR(name,mode,show,store) */
+static DEVICE_ATTR(enable_sar, S_IWUSR | S_IRUGO,
+ stmvl53l0_show_enable_sar, stmvl53l0_store_enable_sar);
+
+static ssize_t stmvl53l0_show_enable_debug(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ return snprintf(buf, 3, "%d\n", data->enableDebug);
+}
+
+/* for debug */
+static ssize_t stmvl53l0_store_enable_debug(struct device *dev,
+struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+ long on;
+
+ if (kstrtoul(buf, 10, &on))
+ return count;
+ if ((on != 0) && (on != 1)) {
+ vl53l0_errmsg("%d,set debug=%ld\n", __LINE__, on);
+ return count;
+ }
+ data->enableDebug = on;
+
+ return count;
+}
+
+/* DEVICE_ATTR(name,mode,show,store) */
+static DEVICE_ATTR(enable_debug, S_IWUSR | S_IRUGO,
+ stmvl53l0_show_enable_debug, stmvl53l0_store_enable_debug);
+
+static ssize_t stmvl53l0_show_offset(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ return snprintf(buf, 5, "%d\n", data->offset);
+}
+
+static ssize_t stmvl53l0_store_offset(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+ long on;
+
+ if (buf[0] == '-') {
+ if (kstrtoul(&buf[1], 10, &on))
+ return count;
+ on = 0 - on;
+ } else {
+ if (kstrtoul(buf, 10, &on))
+ return count;
+ }
+ vl53l0_errmsg("%d,set offset=%ld\n", __LINE__, on);
+ data->offset = on * 1000;
+ mutex_lock(&data->work_mutex);
+ if (data->enable_ps_sensor == 0)
+ stmvl53l0_start(data);
+ if (data->w_mode != OFF_MODE) {
+ vl53l0_errmsg("%d, set offsetcal in other mode, it will be postpone \n", __LINE__);
+ if (s_nump < 10) {
+ s_parameters[s_nump].name = OFFSET_PAR;
+ s_parameters[s_nump].is_read = 0;
+ s_parameters[s_nump].value = data->offset;
+ s_nump++;
+ }
+ }
+ if (data->enable_ps_sensor == 1) {
+ data->enable_ps_sensor = 0;
+ /* to stop */
+ stmvl53l0_stop(data);
+ }
+ mutex_unlock(&data->work_mutex);
+ return count;
+}
+
+/* DEVICE_ATTR(name,mode,show,store) */
+static DEVICE_ATTR(offset, S_IWUSR | S_IRUGO,
+ stmvl53l0_show_offset, stmvl53l0_store_offset);
+
+static ssize_t stmvl53l0_show_xtalk(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ return snprintf(buf, 5, "%d\n", data->xtalk);
+}
+
+static ssize_t stmvl53l0_store_xtalk(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+ long on;
+
+ if (kstrtoul(buf, 10, &on))
+ return count;
+ data->xtalk = on;
+ vl53l0_errmsg("%d,set xtalk=%ld\n", __LINE__, on);
+ return count;
+}
+
+/* DEVICE_ATTR(name,mode,show,store) */
+static DEVICE_ATTR(xtalk, S_IWUSR | S_IRUGO,
+ stmvl53l0_show_xtalk, stmvl53l0_store_xtalk);
+
+static ssize_t stmvl53l0_show_set_delay_ms(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ return snprintf(buf, 3, "%d\n", data->delay_ms);
+}
+
+/* for work handler scheduler time */
+static ssize_t stmvl53l0_store_set_delay_ms(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+ long delay_ms;
+
+ if (kstrtoul(buf, 10, &delay_ms))
+ return count;
+ if (delay_ms == 0) {
+ vl53l0_errmsg("%d,set delay_ms=%ld\n", __LINE__, delay_ms);
+ return count;
+ }
+ mutex_lock(&data->work_mutex);
+ data->delay_ms = delay_ms;
+ mutex_unlock(&data->work_mutex);
+
+ return count;
+}
+
+/* DEVICE_ATTR(name,mode,show,store) */
+static DEVICE_ATTR(set_delay_ms, S_IWUSR | S_IWGRP | S_IRUGO,
+ stmvl53l0_show_set_delay_ms, stmvl53l0_store_set_delay_ms);
+
+static ssize_t stmvl53l0_show_near(struct device *dev,
+struct device_attribute *attr, char *buf)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ return snprintf(buf, 5, "%d\n",
+ data->rangeData.RangeMilliMeter);
+}
+
+/* for work handler scheduler time */
+static ssize_t stmvl53l0_store_near(struct device *dev,
+struct device_attribute *attr, const char *buf, size_t count)
+{
+ return count;
+}
+
+/* DEVICE_ATTR(name,mode,show,store) */
+static DEVICE_ATTR(near, S_IRUGO,
+ stmvl53l0_show_near, stmvl53l0_store_near);
+
+
+static struct attribute *stmvl53l0_attributes[] = {
+ &dev_attr_enable_ps_sensor.attr,
+ &dev_attr_enable_debug.attr,
+ &dev_attr_set_delay_ms.attr,
+ &dev_attr_set_mode.attr,
+ &dev_attr_enable_sar.attr,
+ &dev_attr_near.attr,
+ &dev_attr_xtalk.attr,
+ &dev_attr_offset.attr,
+ NULL
+};
+
+
+static const struct attribute_group stmvl53l0_attr_group = {
+ .attrs = stmvl53l0_attributes,
+};
+
+
+/*
+* misc device file operation functions
+*/
+static int stmvl53l0_ioctl_handler(struct file *file,
+ unsigned int cmd, unsigned long arg, void __user *p)
+{
+ int rc = 0;
+ unsigned int xtalkint = 0;
+ unsigned int targetDistance = 0;
+ int8_t offsetint = 0;
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ struct stmvl53l0_register reg;
+ struct stmvl53l0_parameter parameter;
+ VL53L0_DEV vl53l0_dev = data;
+ uint8_t page_num = 0;
+ if (!data)
+ return -EINVAL;
+
+ vl53l0_dbgmsg_en("Enter enable_ps_sensor:%d\n", data->enable_ps_sensor);
+ switch (cmd) {
+ /* enable */
+ case VL53L0_IOCTL_INIT:
+ vl53l0_dbgmsg_en("VL53L0_IOCTL_INIT\n");
+ stmvl53l0_work_state(data, CAM_ON);
+ break;
+ case VL53L0_IOCTL_INIT_NS:
+ if (data->enable_ps_sensor == 0)
+ stmvl53l0_start(data);
+ break;
+ case VL53L0_IOCTL_INIT_NB:
+ vl53l0_dbgmsg_en("init nb called\n");
+ schedule_delayed_work(&data->initwork, 0);
+ break;
+ case VL53L0_IOCTL_SUSPEND:
+ mutex_lock(&data->work_mutex);
+ vl53l0_dbgmsg_en("VL53L0_IOCTL_SUSPEND\n");
+ data->c_suspend = 1;
+ mutex_unlock(&data->work_mutex);
+ break;
+ case VL53L0_IOCTL_RESUME:
+ vl53l0_dbgmsg_en("VL53L0_IOCTL_RESUME\n");
+ mutex_lock(&data->work_mutex);
+ if (data->c_suspend == 1) {
+ data->c_suspend = 0;
+ VL53L0_ClearInterruptMask(data, 0);
+ papi_func_tbl->StartMeasurement(data);
+ }
+ mutex_unlock(&data->work_mutex);
+ break;
+ case VL53L0_IOCTL_RESET:
+ stmvl53l0_work_state(data, RESET);
+ break;
+ case VL53L0_IOCTL_RESET_NB:
+ schedule_delayed_work(&data->resetwork, 0);
+ break;
+ /* crosstalk calibration */
+ case VL53L0_IOCTL_XTALKCALB:
+ vl53l0_dbgmsg_en("VL53L0_IOCTL_XTALKCALB\n");
+ data->xtalkCalDistance = 100;
+ if (copy_from_user(&targetDistance, (unsigned int *)p,
+ sizeof(unsigned int))) {
+ vl53l0_errmsg("%d, fail\n", __LINE__);
+ return -EFAULT;
+ }
+ data->xtalkCalDistance = targetDistance;
+ stmvl53l0_work_state(data, XTALKCAL_ON);
+ if (copy_to_user((unsigned int *)p,
+ &(data->xtalkcalval),
+ sizeof(unsigned int))) {
+ vl53l0_errmsg("%d, fail\n", __LINE__);
+ return -EFAULT;
+ }
+ break;
+ /* set up Xtalk value */
+ case VL53L0_IOCTL_SETXTALK:
+ vl53l0_dbgmsg_en("VL53L0_IOCTL_SETXTALK\n");
+ if (copy_from_user(&xtalkint, (unsigned int *)p,
+ sizeof(unsigned int))) {
+ vl53l0_errmsg("%d, fail\n", __LINE__);
+ return -EFAULT;
+ }
+ vl53l0_dbgmsg_en("SETXTALK as 0x%x\n", xtalkint);
+ break;
+ /* offset calibration */
+ case VL53L0_IOCTL_OFFCALB:
+ vl53l0_dbgmsg_en("VL53L0_IOCTL_OFFCALB\n");
+ data->offsetCalDistance = 50;
+ if (copy_from_user(&targetDistance, (unsigned int *)p,
+ sizeof(unsigned int))) {
+ vl53l0_errmsg("%d, fail\n", __LINE__);
+ return -EFAULT;
+ }
+ data->offsetCalDistance = targetDistance;
+ stmvl53l0_work_state(data, OFFSETCAL_ON);
+ break;
+ case VL53L0_IOCTL_STOPCALB:
+ vl53l0_dbgmsg_en("VL53L0_IOCTL_STOPCALB\n");
+ stmvl53l0_work_state(data, CAL_OFF);
+ break;
+ /* set up offset value */
+ case VL53L0_IOCTL_SETOFFSET:
+ vl53l0_dbgmsg_en("VL53L0_IOCTL_SETOFFSET\n");
+ if (copy_from_user(&offsetint, (int8_t *)p, sizeof(int8_t))) {
+ vl53l0_errmsg("%d, fail\n", __LINE__);
+ return -EFAULT;
+ }
+ vl53l0_dbgmsg_en("SETOFFSET as %d\n", offsetint);
+
+ break;
+ /* disable */
+ case VL53L0_IOCTL_STOP:
+ vl53l0_dbgmsg_en("VL53L0_IOCTL_STOP\n");
+ stmvl53l0_work_state(data, CAM_OFF);
+ break;
+ case VL53L0_IOCTL_GETDATAS_BLOCK:
+ vl53l0_dbgmsg_en("VL53L0_IOCTL_GETDATAS_BLOCK\n");
+ data->d_ready = 0;
+ wait_event_timeout(data->range_data_wait,
+ data->d_ready > 0,
+ DATA_TIMEOUT);
+ if (copy_to_user((VL53L0_RangingMeasurementData_t *)p,
+ &(data->rangeData),
+ sizeof(VL53L0_RangingMeasurementData_t))) {
+ vl53l0_errmsg("%d, fail\n", __LINE__);
+ return -EFAULT;
+ }
+ break;
+ /* Get all range data */
+ case VL53L0_IOCTL_GETDATAS:
+ vl53l0_dbgmsg_en("VL53L0_IOCTL_GETDATAS\n");
+ if (data->enable_ps_sensor == 0)
+ return -EFAULT;
+ if (copy_to_user((VL53L0_RangingMeasurementData_t *)p,
+ &(data->rangeData),
+ sizeof(VL53L0_RangingMeasurementData_t))) {
+ vl53l0_errmsg("%d, fail\n", __LINE__);
+ return -EFAULT;
+ }
+ break;
+ /* Register tool */
+ case VL53L0_IOCTL_REGISTER:
+ vl53l0_dbgmsg_en("VL53L0_IOCTL_REGISTER\n");
+ /* turn on tof sensor */
+ if (data->enable_ps_sensor == 0) {
+ /* to start */
+ stmvl53l0_start(data);
+ }
+ if (copy_from_user(®, (struct stmvl53l0_register *)p,
+ sizeof(struct stmvl53l0_register))) {
+ vl53l0_errmsg("%d, fail\n", __LINE__);
+ return -EFAULT;
+ }
+ reg.status = 0;
+ page_num = (uint8_t)((reg.reg_index & 0x0000ff00) >> 8);
+ vl53l0_dbgmsg_en("IOCTL_REGISTER, page num:%d\n", page_num);
+ if (page_num != 0)
+ reg.status = VL53L0_WrByte(vl53l0_dev, 0xFF, page_num);
+
+ switch (reg.reg_bytes) {
+ case(4):
+ if (reg.is_read)
+ reg.status = VL53L0_RdDWord(vl53l0_dev,
+ (uint8_t)reg.reg_index, ®.reg_data);
+ else
+ reg.status = VL53L0_WrDWord(vl53l0_dev,
+ (uint8_t)reg.reg_index, reg.reg_data);
+ break;
+ case(2):
+ if (reg.is_read)
+ reg.status = VL53L0_RdWord(vl53l0_dev,
+ (uint8_t)reg.reg_index,
+ (uint16_t *)®.reg_data);
+ else
+ reg.status = VL53L0_WrWord(vl53l0_dev,
+ (uint8_t)reg.reg_index,
+ (uint16_t)reg.reg_data);
+ break;
+ case(1):
+ if (reg.is_read)
+ reg.status = VL53L0_RdByte(vl53l0_dev,
+ (uint8_t)reg.reg_index,
+ (uint8_t *)®.reg_data);
+ else
+ reg.status = VL53L0_WrByte(vl53l0_dev,
+ (uint8_t)reg.reg_index,
+ (uint8_t)reg.reg_data);
+ break;
+ default:
+ reg.status = -1;
+
+ }
+ if (page_num != 0)
+ reg.status = VL53L0_WrByte(vl53l0_dev, 0xFF, 0);
+
+
+ if (copy_to_user((struct stmvl53l0_register *)p, ®,
+ sizeof(struct stmvl53l0_register))) {
+ vl53l0_errmsg("%d, fail\n", __LINE__);
+ return -EFAULT;
+ }
+ break;
+ /* parameter access */
+ case VL53L0_IOCTL_PARAMETER:
+ vl53l0_dbgmsg_en("VL53L0_IOCTL_PARAMETER\n");
+ /* turn on tof sensor */
+ if (data->enable_ps_sensor == 0) {
+ /* to start */
+ stmvl53l0_start(data);
+ }
+ if (copy_from_user(¶meter, (struct stmvl53l0_parameter *)p,
+ sizeof(struct stmvl53l0_parameter))) {
+ vl53l0_errmsg("%d, fail\n", __LINE__);
+ return -EFAULT;
+ }
+ parameter.status = 0;
+ mutex_lock(&data->work_mutex);
+ if (!parameter.is_read && data->w_mode != OFF_MODE) {
+ vl53l0_errmsg("%d, write parameter in other mode, it will be postpone \n", __LINE__);
+ if (s_nump < 10) {
+ if (!copy_from_user(&s_parameters[s_nump],
+ (struct stmvl53l0_parameter *)p, sizeof(struct stmvl53l0_parameter)))
+ s_nump++;
+ }
+ mutex_unlock(&data->work_mutex);
+ return rc;
+ }
+ switch (parameter.name) {
+ case (OFFSET_PAR):
+ if (parameter.is_read)
+ parameter.status =
+ papi_func_tbl->GetOffsetCalibrationDataMicroMeter(
+ vl53l0_dev, ¶meter.value);
+ else
+ parameter.status =
+ papi_func_tbl->SetOffsetCalibrationDataMicroMeter(
+ vl53l0_dev, parameter.value);
+ break;
+ case (XTALKRATE_PAR):
+ if (parameter.is_read)
+ parameter.status =
+ VL53L0_GetXTalkCompensationRateMegaCps(
+ vl53l0_dev, (FixPoint1616_t *)¶meter.value);
+ else
+ parameter.status =
+ papi_func_tbl->SetXTalkCompensationRateMegaCps(
+ vl53l0_dev, (FixPoint1616_t)parameter.value);
+
+ break;
+ case (XTALKENABLE_PAR):
+ if (parameter.is_read)
+ parameter.status =
+ papi_func_tbl->GetXTalkCompensationEnable(
+ vl53l0_dev, (uint8_t *)¶meter.value);
+ else
+ parameter.status =
+ papi_func_tbl->SetXTalkCompensationEnable(
+ vl53l0_dev, (uint8_t)parameter.value);
+ break;
+ case (SIGMAVAL_PRA):
+ if (!parameter.is_read)
+ parameter.status = papi_func_tbl->
+ SetLimitCheckValue(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (FixPoint1616_t)parameter.value);
+ else
+ parameter.status = papi_func_tbl->
+ GetLimitCheckValue(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (FixPoint1616_t *)¶meter.value);
+ break;
+
+ case (SIGMACTL_PRA):
+ if (!parameter.is_read)
+ parameter.status =
+ papi_func_tbl->SetLimitCheckEnable(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (uint8_t)parameter.value);
+ else
+ parameter.status =
+ papi_func_tbl->GetLimitCheckEnable(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (uint8_t *)¶meter.value);
+ break;
+ case (SGLVAL_PRA):
+ if (!parameter.is_read)
+ parameter.status = papi_func_tbl->
+ SetLimitCheckValue(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (FixPoint1616_t)parameter.value);
+ else
+ parameter.status = papi_func_tbl->
+ GetLimitCheckValue(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (FixPoint1616_t *)¶meter.value);
+ break;
+
+ case (SGLCTL_PRA):
+ if (!parameter.is_read)
+ parameter.status =
+ papi_func_tbl->SetLimitCheckEnable(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (uint8_t)parameter.value);
+ else
+ parameter.status =
+ papi_func_tbl->GetLimitCheckEnable(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (uint8_t *)¶meter.value);
+ break;
+
+ case (WRAPAROUNDCTL_PRA):
+ if (parameter.is_read)
+ parameter.status =
+ VL53L0_GetWrapAroundCheckEnable(
+ vl53l0_dev, (uint8_t *)¶meter.value);
+ else
+ parameter.status =
+ VL53L0_SetWrapAroundCheckEnable(
+ vl53l0_dev, (uint8_t)parameter.value);
+ break;
+
+ case (MEASUREMENTTIMINGBUDGET_PAR):
+ if (parameter.is_read)
+ parameter.status =
+ VL53L0_GetMeasurementTimingBudgetMicroSeconds(
+ vl53l0_dev, (uint32_t *)¶meter.value);
+ else
+ parameter.status =
+ VL53L0_SetMeasurementTimingBudgetMicroSeconds(
+ vl53l0_dev, (uint32_t)parameter.value);
+ break;
+ case (CUTV_PRA):
+ if (parameter.is_read)
+ parameter.value = vl53l0_dev->cut_v;
+ break;
+ case (DRVV_PRA):
+ if (parameter.is_read)
+ parameter.value = DRIVER_VERSION_NUM;
+ break;
+ case (PLLPRE_PRA):
+ if (parameter.is_read)
+ parameter.status =
+ papi_func_tbl->GetVcselPulsePeriod(vl53l0_dev,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE, (uint8_t *)¶meter.value);
+ else {
+ parameter.status =
+ papi_func_tbl->SetVcselPulsePeriod(vl53l0_dev,
+ VL53L0_VCSEL_PERIOD_PRE_RANGE, (uint8_t)parameter.value);
+ vl53l0_dev->pll_p = (uint8_t)parameter.value;
+ }
+ break;
+ case (PLLFINAL_PRA):
+ if (parameter.is_read)
+ parameter.status =
+ papi_func_tbl->GetVcselPulsePeriod(vl53l0_dev,
+ VL53L0_VCSEL_PERIOD_FINAL_RANGE, (uint8_t *)¶meter.value);
+ else {
+ parameter.status =
+ papi_func_tbl->SetVcselPulsePeriod(vl53l0_dev,
+ VL53L0_VCSEL_PERIOD_FINAL_RANGE, (uint8_t)parameter.value);
+ vl53l0_dev->pll_f = (uint8_t)parameter.value;
+ }
+ break;
+ }
+
+
+
+ mutex_unlock(&data->work_mutex);
+ if (copy_to_user((struct stmvl53l0_parameter *)p, ¶meter,
+ sizeof(struct stmvl53l0_parameter))) {
+ vl53l0_errmsg("%d, fail\n", __LINE__);
+ return -EFAULT;
+ }
+ break;
+
+ default:
+ rc = -EINVAL;
+ break;
+ }
+
+ return rc;
+}
+
+static int stmvl53l0_open(struct inode *inode, struct file *file)
+{
+ return 0;
+}
+
+static int stmvl53l0_close(struct inode *inode, struct file *file)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ if (data->w_mode == CAM_MODE || data->w_mode == SUPER_MODE) {
+ stmvl53l0_work_state(data, CAM_OFF);
+ }
+ if (data->w_mode == XTALKCAL_MODE || data->w_mode == OFFSETCAL_MODE)
+ stmvl53l0_work_state(data, CAL_OFF);
+ return 0;
+}
+
+static int stmvl53l0_flush(struct file *file, fl_owner_t id)
+{
+ return 0;
+}
+
+static long stmvl53l0_ioctl(struct file *file,
+ unsigned int cmd, unsigned long arg)
+{
+ int ret;
+ ret = stmvl53l0_ioctl_handler(file, cmd, arg, (void __user *)arg);
+ return ret;
+}
+
+#ifdef CONFIG_COMPAT
+static long stmvl53l0_compat_ioctl(struct file *file,
+ unsigned int cmd, unsigned long arg)
+{
+ int ret;
+
+ ret = stmvl53l0_ioctl_handler(file, cmd, arg, compat_ptr(arg));
+ return ret;
+}
+#endif
+
+int stmvl53l0_livechecking(struct stmvl53l0_data *data)
+{
+ uint8_t id = 0;
+ VL53L0_DEV vl53l0_dev = data;
+ struct timeval tv;
+
+ vl53l0_dbgmsg_en("Enter\n");
+ /* Read Model ID */
+ mutex_lock(&data->work_mutex);
+ if (data->enable_ps_sensor == 1 && SAR_MODE == data->w_mode) {
+ VL53L0_RdByte(vl53l0_dev,
+ VL53L0_REG_IDENTIFICATION_MODEL_ID, &id);
+ vl53l0_dbgmsg("read MODLE_ID: 0x%x\n", id);
+ if (id == 0xee)
+ vl53l0_dbgmsg("STM VL53L0 still alive\n");
+ else {
+ vl53l0_errmsg("STM VL53L0 looks dead\n");
+ do_gettimeofday(&tv);
+
+ input_report_abs(data->input_dev_ps, ABS_DISTANCE, 1);
+ input_report_abs(data->input_dev_ps, ABS_HAT0X, tv.tv_sec);
+ input_report_abs(data->input_dev_ps, ABS_HAT0Y, tv.tv_usec);
+ input_report_abs(data->input_dev_ps, ABS_HAT1X,
+ data->rangeData.RangeMilliMeter);
+ input_report_abs(data->input_dev_ps, ABS_HAT1Y,
+ data->rangeData.RangeStatus);
+ input_report_abs(data->input_dev_ps, ABS_HAT2X,
+ data->rangeData.SignalRateRtnMegaCps);
+ input_report_abs(data->input_dev_ps, ABS_HAT2Y,
+ data->rangeData.AmbientRateRtnMegaCps);
+ input_report_abs(data->input_dev_ps, ABS_HAT3X,
+ data->rangeData.MeasurementTimeUsec);
+ input_report_abs(data->input_dev_ps, ABS_HAT3Y,
+ data->rangeData.RangeDMaxMilliMeter);
+ input_sync(data->input_dev_ps);
+ }
+ }
+ mutex_unlock(&data->work_mutex);
+
+return 0;
+}
+int stmvl53l0_checkmoduleid(struct stmvl53l0_data *data,
+ void *client, uint8_t type)
+{
+ uint8_t id = 0;
+ int err;
+
+ vl53l0_dbgmsg("Enter\n");
+ if (type == CCI_BUS) {
+ struct msm_camera_i2c_client *cci_pclient =
+ (struct msm_camera_i2c_client *)client;
+
+ cci_pclient->i2c_func_tbl->i2c_read_seq(cci_pclient,
+ 0xc0, &id, 1);
+ } else {
+ struct i2c_client *i2c_pclient = (struct i2c_client *)client;
+ struct i2c_msg msg[1];
+ uint8_t buff;
+
+ buff = 0xc0;
+ msg[0].addr = i2c_pclient->addr;
+ msg[0].flags = I2C_M_WR;
+ msg[0].buf = &buff;
+ msg[0].len = 1;
+
+ err = i2c_transfer(i2c_pclient->adapter, msg, 1);
+ if (err != 1) {
+ pr_err("%s: i2c_transfer err:%d, addr:0x%x, reg:0x%x\n",
+ __func__, err, i2c_pclient->addr, buff);
+ err = -1;
+ return err;
+ }
+
+ msg[0].addr = i2c_pclient->addr;
+ msg[0].flags = I2C_M_RD | i2c_pclient->flags;
+ msg[0].buf = &id;
+ msg[0].len = 1;
+
+ err = i2c_transfer(i2c_pclient->adapter, &msg[0], 1);
+ if (err != 1) {
+ pr_err("%s: Read i2c_transfer err:%d, addr:0x%x\n",
+ __func__, err, i2c_pclient->addr);
+ err = -1;
+ return err;
+ }
+ }
+ /* Read Model ID */
+
+ vl53l0_dbgmsg("read MODLE_ID: 0x%x\n", id);
+ if (id == 0xee) {
+ vl53l0_errmsg("STM VL53L0 Found %d\n", __LINE__);
+ return 0;
+ }
+
+ vl53l0_errmsg("Not found STM VL53L0 %d\n", __LINE__);
+ return -EIO;
+}
+
+/*
+* Initialization function
+*/
+static int stmvl53l0_init_client(struct stmvl53l0_data *data)
+{
+ uint8_t id = 0, type = 0, i = 0;
+ uint8_t revision = 0, module_id = 0;
+ VL53L0_Error Status = VL53L0_ERROR_NONE;
+ VL53L0_DeviceInfo_t DeviceInfo;
+ VL53L0_DEV vl53l0_dev = data;
+ FixPoint1616_t LimitValue;
+ uint8_t LimitEnable;
+
+ vl53l0_dbgmsg_en("Enter\n");
+
+ /* Read Model ID */
+ for (i = 0; i < 5; i++) {
+ VL53L0_RdByte(vl53l0_dev,
+ VL53L0_REG_IDENTIFICATION_MODEL_ID, &id);
+ vl53l0_errmsg("read MODLE_ID: 0x%x\n", id);
+ if (id == 0xee) {
+ vl53l0_errmsg("STM VL53L0 Found\n");
+ break;
+ }
+
+ udelay(1000);
+ }
+ if (id != 0xee) {
+ vl53l0_errmsg("Not found STM VL53L0\n");
+ return -EIO;
+ }
+ if (data->reset) {
+ VL53L0_RdByte(vl53l0_dev, 0xc1, &id);
+ vl53l0_errmsg("read 0xc1: 0x%x\n", id);
+ VL53L0_RdByte(vl53l0_dev, 0xc2, &id);
+ vl53l0_errmsg("read 0xc2: 0x%x\n", id);
+ VL53L0_RdByte(vl53l0_dev, 0xc3, &id);
+ vl53l0_errmsg("read 0xc3: 0x%x\n", id);
+
+ /* Read Model Version */
+ VL53L0_RdByte(vl53l0_dev, 0xC0, &type);
+ VL53L0_RdByte(vl53l0_dev, VL53L0_REG_IDENTIFICATION_REVISION_ID,
+ &revision);
+ VL53L0_RdByte(vl53l0_dev, 0xc3,
+ &module_id);
+ vl53l0_errmsg("STM VL53L0 Model type : %d. rev:%d. module:%d\n", type,
+ revision, module_id);
+
+ vl53l0_dev->I2cDevAddr = 0x52;
+ vl53l0_dev->comms_type = 1;
+ vl53l0_dev->comms_speed_khz = 400;
+
+ /* Setup API functions based on revision */
+ stmvl53l0_setupAPIFunctions(data);
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ pr_err("Call of VL53L0_DataInit\n");
+ Status = papi_func_tbl->DataInit(vl53l0_dev);
+ }
+
+ if (Status == VL53L0_ERROR_NONE && data->reset) {
+ pr_err("VL53L0_GetDeviceInfo:\n");
+ Status = papi_func_tbl->GetDeviceInfo(vl53l0_dev, &DeviceInfo);
+ if (Status == VL53L0_ERROR_NONE) {
+ pr_err("Device Name : %s\n", DeviceInfo.Name);
+ pr_err("Device Type : %s\n", DeviceInfo.Type);
+ pr_err("Device ID : %s\n", DeviceInfo.ProductId);
+ pr_err("Product type: %d\n", DeviceInfo.ProductType);
+ pr_err("ProductRevisionMajor : %d\n",
+ DeviceInfo.ProductRevisionMajor);
+ pr_err("ProductRevisionMinor : %d\n",
+ DeviceInfo.ProductRevisionMinor);
+ }
+ }
+
+ if (Status == VL53L0_ERROR_NONE) {
+ pr_err("Call of VL53L0_StaticInit\n");
+ Status = papi_func_tbl->StaticInit(vl53l0_dev);
+ /* Device Initialization */
+ }
+
+ if (Status == VL53L0_ERROR_NONE && data->reset) {
+ pr_err("Call of VL53L0_PerformRefCalibration\n");
+ Status = papi_func_tbl->PerformRefCalibration(vl53l0_dev,
+ &(data->VhvSettings), &(data->PhaseCal)); /* Ref calibration */
+
+ pr_err("VL53L0_PerformRefCalibration %d, %d\n", data->VhvSettings, data->PhaseCal);
+ } else if (Status == VL53L0_ERROR_NONE && data->reset == 0) {
+ pr_err("Call of VL53L0_SetRefCalibration\n");
+ VL53L0_SetRefCalibration(vl53l0_dev, data->VhvSettings, data->PhaseCal);
+ }
+
+ if (Status == VL53L0_ERROR_NONE && data->reset) {
+ pr_err("Call of VL53L0_PerformRefSpadManagement\n");
+ Status = papi_func_tbl->PerformRefSpadManagement(vl53l0_dev,
+ &(data->refSpadCount), &(data->isApertureSpads));
+ data->reset = 0;
+ pr_err("VL53L0_PerformRefSpadManagement, %d, %d\n", data->refSpadCount, data->isApertureSpads);
+ } else if (Status == VL53L0_ERROR_NONE && data->reset == 0) {
+ pr_err("Call of VL53L0_SetReferenceSpads\n");
+ VL53L0_SetReferenceSpads(vl53l0_dev, data->refSpadCount, data->isApertureSpads);
+ }
+ if (Status == VL53L0_ERROR_NONE && data->reset) {
+
+ pr_err("Call of papi_func_tbl->SetDeviceMode\n");
+ Status = papi_func_tbl->SetDeviceMode(vl53l0_dev,
+ VL53L0_DEVICEMODE_SINGLE_RANGING);
+ /* Setup in single ranging mode */
+ }
+ if (Status == VL53L0_ERROR_NONE && data->reset) {
+ Status = papi_func_tbl->GetLimitCheckValue(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ &LimitValue);
+ Status = papi_func_tbl->GetLimitCheckEnable(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
+ &LimitEnable);
+ pr_err("Get LimitCheckValue SIGMA_FINAL_RANGE as:%d,Enable:%d\n",
+ (LimitValue>>16), LimitEnable);
+ }
+
+ if (Status == VL53L0_ERROR_NONE && data->reset) {
+ Status = papi_func_tbl->GetLimitCheckValue(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ &LimitValue);
+ Status = papi_func_tbl->GetLimitCheckEnable(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ &LimitEnable);
+ pr_err("Get LimitCheckValue SIGNAL_FINAL_RANGE as:%d(Fix1616),Eanble:%d\n",
+ (LimitValue), LimitEnable);
+ }
+
+ if (Status == VL53L0_ERROR_NONE && data->reset) {
+ Status = papi_func_tbl->GetLimitCheckValue(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGNAL_REF_CLIP,
+ &LimitValue);
+ Status = papi_func_tbl->GetLimitCheckEnable(vl53l0_dev,
+ VL53L0_CHECKENABLE_SIGNAL_REF_CLIP,
+ &LimitEnable);
+ pr_err("Get LimitCheckValue SIGNAL_REF_CLIP as:%d(fix1616),Enable:%d\n",
+ (LimitValue), LimitEnable);
+ }
+
+ if (Status == VL53L0_ERROR_NONE && data->reset) {
+ Status = papi_func_tbl->GetLimitCheckValue(vl53l0_dev,
+ VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
+ &LimitValue);
+ Status = papi_func_tbl->GetLimitCheckEnable(vl53l0_dev,
+ VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
+ &LimitEnable);
+ pr_err("Get LimitCheckValue RANGE_IGNORE_THRESHOLD as:%d(fix1616),Enable:%d\n",
+ (LimitValue), LimitEnable);
+ }
+
+ if (Status == VL53L0_ERROR_NONE)
+ Status = papi_func_tbl->SetWrapAroundCheckEnable(vl53l0_dev, 1);
+ if (data->offset != 0)
+ papi_func_tbl->SetOffsetCalibrationDataMicroMeter(
+ vl53l0_dev, data->offset);
+ if (data->xtalk != 0)
+ papi_func_tbl->SetXTalkCompensationRateMegaCps(
+ vl53l0_dev, (FixPoint1616_t)data->xtalk);
+ papi_func_tbl->SetXTalkCompensationEnable(vl53l0_dev, 1);
+
+#ifdef CALIBRATION_FILE
+ /*stmvl53l0_read_calibration_file(data);*/
+#endif
+
+ vl53l0_dbgmsg_en("End\n");
+
+ return 0;
+}
+
+irqreturn_t laser_isr(int irq, void *dev)
+{
+ struct stmvl53l0_data *data = gp_vl53l0_data;
+
+ vl53l0_dbgmsg_en("interrupt called");
+
+ if (data->w_mode != OFF_MODE || data->d_mode > 0) {
+ vl53l0_dbgmsg_en("have mode");
+ data->interrupt_received = 1;
+ cancel_delayed_work(&data->dwork);
+ schedule_delayed_work(&data->dwork, 0);
+ }
+
+ return IRQ_HANDLED;
+}
+static int stmvl53l0_start(struct stmvl53l0_data *data)
+{
+ int rc = 0;
+ int reset = 0;
+
+ /* Power up */
+ rc = pmodule_func_tbl->power_up(data->client_object, &reset);
+ if (rc) {
+ vl53l0_errmsg("%d,error rc %d\n", __LINE__, rc);
+ return rc;
+ }
+ /* init */
+ rc = stmvl53l0_init_client(data);
+ if (rc) {
+ vl53l0_errmsg("%d, error rc %d\n", __LINE__, rc);
+ pmodule_func_tbl->power_down(data->client_object);
+ return -EINVAL;
+ }
+
+ data->enable_ps_sensor = 1;
+ schedule_delayed_work(&data->checkwork, 1800000);
+ vl53l0_dbgmsg_en("End\n");
+
+ return rc;
+}
+
+static int stmvl53l0_stop(struct stmvl53l0_data *data)
+{
+ int rc = 0;
+
+ vl53l0_dbgmsg_en("Enter\n");
+ VL53L0_StopMeasurement(data);
+
+ /* clean interrupt */
+ VL53L0_ClearInterruptMask(data, 0);
+ /* cancel work handler */
+ stmvl53l0_cancel_handler(data);
+ data->enable_ps_sensor = 0;
+ /* power down */
+ rc = pmodule_func_tbl->power_down(data->client_object);
+ if (rc) {
+ vl53l0_errmsg("%d, error rc %d\n", __LINE__, rc);
+ return rc;
+ }
+ vl53l0_dbgmsg_en("End\n");
+
+
+ return rc;
+}
+
+/*
+ * I2C init/probing/exit functions
+ */
+static const struct file_operations stmvl53l0_ranging_fops = {
+ .owner = THIS_MODULE,
+ .unlocked_ioctl = stmvl53l0_ioctl,
+#ifdef CONFIG_COMPAT
+ .compat_ioctl = stmvl53l0_compat_ioctl,
+#endif
+ .open = stmvl53l0_open,
+ .flush = stmvl53l0_flush,
+ .release = stmvl53l0_close,
+};
+
+/*
+static struct miscdevice stmvl53l0_ranging_dev = {
+ .minor = MISC_DYNAMIC_MINOR,
+ .name = "stmvl53l0_ranging",
+ .fops = &stmvl53l0_ranging_fops
+};
+*/
+
+int stmvl53l0_setup(struct stmvl53l0_data *data, uint8_t type)
+{
+ int rc = 0;
+ int irq;
+ int gpio;
+
+ vl53l0_dbgmsg("Enter\n");
+ data->lowv = 40;
+ data->highv = 45;
+ if (type == CCI_BUS) {
+ data->bus_type = CCI_BUS;
+ data->client_object = &(data->cci_client_object);
+ /* assign function table */
+ pmodule_func_tbl = &stmvl53l0_module_func_tbl_cci;
+ gpio = data->cci_client_object.gconf.cam_gpio_req_tbl[1].gpio;
+ data->lowv = data->cci_client_object.lowv;
+ data->highv = data->cci_client_object.highv;
+ data->xtalk = data->cci_client_object.xtalk;
+ } else {
+ data->bus_type = I2C_BUS;
+ data->client_object = &(data->i2c_client_object);
+ pmodule_func_tbl = &stmvl53l0_module_func_tbl_i2c;
+ gpio = data->i2c_client_object.gconf.cam_gpio_req_tbl[1].gpio;
+ data->lowv = data->i2c_client_object.lowv;
+ data->highv = data->i2c_client_object.highv;
+ data->xtalk = data->i2c_client_object.xtalk;
+ }
+
+ /* init interrupt */
+ gpio_request(gpio, "vl6180_gpio_int");
+ gpio_direction_input(gpio);
+ irq = gpio_to_irq(gpio);
+
+
+ if (irq < 0) {
+ vl53l0_errmsg("%d,filed to map GPIO: %d to interrupt:%d\n",
+ __LINE__, gpio, irq);
+ } else {
+
+ vl53l0_dbgmsg("register_irq:%d\n", irq);
+/* IRQF_TRIGGER_FALLING- poliarity:0 IRQF_TRIGGER_RISNG - poliarty:1 */
+ rc = request_irq(irq, laser_isr,
+ IRQF_TRIGGER_FALLING ,
+ "vl6180_lb_gpio_int", (void *)data);
+ if (rc) {
+ vl53l0_errmsg("%d, Could not allocate INT %d\n",
+ __LINE__, rc);
+ goto exit_free_irq;
+ }
+ }
+ data->irq = irq;
+ enable_irq_wake(irq);
+ vl53l0_dbgmsg("interrupt is hooked\n");
+ /* init mutex */
+ mutex_init(&data->update_lock);
+ mutex_init(&data->work_mutex);
+ data->w_mode = OFF_MODE;
+ init_waitqueue_head(&data->range_data_wait);
+ s_nump = 0;
+ /* init work handler */
+ INIT_DELAYED_WORK(&data->dwork, stmvl53l0_work_handler);
+ INIT_DELAYED_WORK(&data->initwork, stmvl53l0_init_handler);
+ INIT_DELAYED_WORK(&data->resetwork, stmvl53l0_reset_handler);
+ INIT_DELAYED_WORK(&data->checkwork, stmvl53l0_check_handler);
+ /* Register to Input Device */
+ data->input_dev_ps = input_allocate_device();
+ if (!data->input_dev_ps) {
+ rc = -ENOMEM;
+ vl53l0_errmsg("%d error:%d\n", __LINE__, rc);
+
+ goto exit_free_irq;
+ }
+ set_bit(EV_ABS, data->input_dev_ps->evbit);
+ /* range in cm*/
+ input_set_abs_params(
+ data->input_dev_ps, ABS_DISTANCE, 0, 76, 0, 0);
+ /* tv_sec */
+ input_set_abs_params(
+ data->input_dev_ps, ABS_HAT0X, 0, 0xffffffff, 0, 0);
+ /* tv_usec */
+ input_set_abs_params(
+ data->input_dev_ps, ABS_HAT0Y, 0, 0xffffffff, 0, 0);
+ /* range in_mm */
+ input_set_abs_params(
+ data->input_dev_ps, ABS_HAT1X, 0, 765, 0, 0);
+ /* error code change maximum to 0xff for more flexibility */
+ input_set_abs_params(
+ data->input_dev_ps, ABS_HAT1Y, 0, 0xff, 0, 0);
+ /* rtnRate */
+ input_set_abs_params(
+ data->input_dev_ps, ABS_HAT2X, 0, 0xffffffff, 0, 0);
+ /* rtn_amb_rate */
+ input_set_abs_params(
+ data->input_dev_ps, ABS_HAT2Y, 0, 0xffffffff, 0, 0);
+ /* rtn_conv_time */
+ input_set_abs_params(
+ data->input_dev_ps, ABS_HAT3X, 0, 0xffffffff, 0, 0);
+ /* dmax */
+ input_set_abs_params(
+ data->input_dev_ps, ABS_HAT3Y, 0, 0xffffffff, 0, 0);
+ /* misc */
+ input_set_abs_params(
+ data->input_dev_ps, ABS_MISC, 0, 0xff, 0, 0);
+ data->input_dev_ps->name = "Rear proximity sensor";
+
+ rc = input_register_device(data->input_dev_ps);
+ if (rc) {
+ rc = -ENOMEM;
+ vl53l0_errmsg("%d error:%d\n", __LINE__, rc);
+ goto exit_free_dev_ps;
+ }
+
+ /* Register sysfs hooks */
+ data->range_kobj = kobject_create_and_add("range", kernel_kobj);
+ if (!data->range_kobj) {
+ rc = -ENOMEM;
+ vl53l0_errmsg("%d error:%d\n", __LINE__, rc);
+
+ goto exit_unregister_dev_ps;
+ }
+ rc = sysfs_create_group(data->range_kobj, &stmvl53l0_attr_group);
+ if (rc) {
+ rc = -ENOMEM;
+ vl53l0_errmsg("%d error:%d\n", __LINE__, rc);
+
+ goto exit_unregister_dev_ps_1;
+ }
+
+ /* to register as a misc device */
+ data->miscdev.minor = MISC_DYNAMIC_MINOR;
+ data->dev_name = devname;
+ data->miscdev.name = data->dev_name;
+ data->miscdev.fops = &stmvl53l0_ranging_fops;
+
+ if (misc_register(&data->miscdev) != 0)
+ vl53l0_errmsg("%d,Couldn't register misc dev\n", __LINE__);
+
+ /* init default value */
+ data->enable_ps_sensor = 0;
+ data->reset = 1;
+ data->c_suspend = 0;
+ data->c_stopped = 0;
+ data->delay_ms = 2000; /* delay time to 2s */
+ data->enableDebug = 0;
+ data->pll_p = 18;
+ data->pll_f = 14;
+/* data->client_object.power_up = 0; */
+
+ vl53l0_dbgmsg("support ver. %s enabled\n", DRIVER_VERSION);
+ vl53l0_dbgmsg("End");
+
+ return 0;
+exit_unregister_dev_ps_1:
+ kobject_put(data->range_kobj);
+exit_unregister_dev_ps:
+ input_unregister_device(data->input_dev_ps);
+
+exit_free_dev_ps:
+ input_free_device(data->input_dev_ps);
+
+exit_free_irq:
+
+ free_irq(irq, data);
+ kfree(data);
+ return rc;
+}
+
+static int __init stmvl53l0_init(void)
+{
+ struct stmvl53l0_data *vl53l0_data = NULL;
+ int ret = 0;
+
+ vl53l0_dbgmsg("Enter\n");
+
+ if (gp_vl53l0_data == NULL) {
+ vl53l0_data =
+ kzalloc(sizeof(struct stmvl53l0_data), GFP_KERNEL);
+ if (!vl53l0_data) {
+ vl53l0_errmsg("%d failed no memory\n", __LINE__);
+ return -ENOMEM;
+ }
+ /* assign to global variable */
+ gp_vl53l0_data = vl53l0_data;
+ } else {
+ vl53l0_data = gp_vl53l0_data;
+ }
+ /* assign function table */
+ papi_func_tbl = &stmvl53l0_api_func_tbl;
+ /* client specific init function */
+ stmvl53l0_module_func_tbl_i2c.init();
+ stmvl53l0_module_func_tbl_cci.init();
+
+ if (ret) {
+ kfree(vl53l0_data);
+ gp_vl53l0_data = NULL;
+ vl53l0_errmsg("%d failed with %d\n", __LINE__, ret);
+ }
+ vl53l0_dbgmsg("End\n");
+
+ return ret;
+}
+
+static void __exit stmvl53l0_exit(void)
+{
+ vl53l0_dbgmsg_en("Enter\n");
+#if 0
+ if (gp_vl53l0_data) {
+ input_unregister_device(gp_vl53l0_data->input_dev_ps);
+ input_free_device(gp_vl53l0_data->input_dev_ps);
+#ifdef USE_INT
+ free_irq(data->irq, gp_vl53l0_data);
+#endif
+ sysfs_remove_group(
+ gp_vl53l0_data->range_kobj, &stmvl53l0_attr_group);
+ gp_vl53l0_data->pmodule_func_tbl->deinit(
+ gp_vl53l0_data->client_object);
+ kfree(gp_vl53l0_data);
+ gp_vl53l0_data = NULL;
+ }
+#endif
+ vl53l0_dbgmsg_en("End\n");
+}
+
+
+struct stmvl53l0_data *stmvl53l0_getobject(void)
+{
+ return gp_vl53l0_data;
+}
+
+
+MODULE_AUTHOR("STMicroelectronics Imaging Division");
+MODULE_DESCRIPTION("ST FlightSense Time-of-Flight sensor driver");
+MODULE_LICENSE("GPL");
+MODULE_VERSION(DRIVER_VERSION);
+
+late_initcall(stmvl53l0_init);
+module_exit(stmvl53l0_exit);
diff --git a/drivers/input/misc/vl53L1/Android.mk b/drivers/input/misc/vl53L1/Android.mk
new file mode 100644
index 000000000000..2fc25dc43319
--- /dev/null
+++ b/drivers/input/misc/vl53L1/Android.mk
@@ -0,0 +1,8 @@
+DLKM_DIR := motorola/kernel/modules
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := stmvl53l1.ko
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_PATH := $(KERNEL_MODULES_OUT)
+include $(DLKM_DIR)/AndroidKernelModule.mk
diff --git a/drivers/input/misc/vl53L1/Kbuild b/drivers/input/misc/vl53L1/Kbuild
new file mode 100644
index 000000000000..71cbc7ecdec1
--- /dev/null
+++ b/drivers/input/misc/vl53L1/Kbuild
@@ -0,0 +1,26 @@
+#
+# Makefile for the vl53L1 drivers.
+#
+
+ccflags-y += -Idrivers/input/misc/vl53L1/inc \
+ -Idrivers/input/misc/vl53L1/ipp -Idrivers/input/misc/vl53L1
+
+# define this environment variable if you want to compile driver for an old
+# kernel
+ifdef OLD_NETLINK_API
+ccflags-y += -DOLD_NETLINK_API
+endif
+
+obj-m += stmvl53l1.o
+stmvl53l1-objs := stmvl53l1_module.o stmvl53l1_module-i2c.o
+stmvl53l1-objs += stmvl53l1_i2c.o stmvl53l1_ipp_nl.o
+stmvl53l1-objs += src/vl53l1_api.o src/vl53l1_api_core.o
+stmvl53l1-objs += src/vl53l1_api_strings.o src/vl53l1_error_strings.o
+stmvl53l1-objs += src/vl53l1_core.o src/vl53l1_register_funcs.o
+stmvl53l1-objs += src/vl53l1_api_preset_modes.o
+stmvl53l1-objs += src/vl53l1_api_calibration.o
+stmvl53l1-objs += src/vl53l1_fpga_core.o src/vl53l1_silicon_core.o
+stmvl53l1-objs += src/vl53l1_zone_presets.o src/vl53l1_nvm.o
+stmvl53l1-objs += src/vl53l1_wait.o ipp/ipp_linux.o
+stmvl53l1-objs += src/vl53l1_api_debug.o src/vl53l1_core_support.o
+stmvl53l1-objs += src/vl53l1_nvm_debug.o stmvl53l1_log.o
diff --git a/drivers/input/misc/vl53L1/Makefile b/drivers/input/misc/vl53L1/Makefile
new file mode 100644
index 000000000000..4191dea22679
--- /dev/null
+++ b/drivers/input/misc/vl53L1/Makefile
@@ -0,0 +1,10 @@
+KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build
+
+all:
+ $(MAKE) -C $(KERNEL_SRC) M=$(shell pwd) modules $(KBUILD_OPTIONS)
+
+modules_install:
+ $(MAKE) INSTALL_MOD_STRIP=1 -C $(KERNEL_SRC) M=$(shell pwd) modules_install
+
+clean:
+ $(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_api.h b/drivers/input/misc/vl53L1/inc/vl53l1_api.h
new file mode 100644
index 000000000000..8c310fb463db
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_api.h
@@ -0,0 +1,1264 @@
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either
+* 'STMicroelectronics Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+#ifndef _VL53L1_API_H_
+#define _VL53L1_API_H_
+
+#include "vl53l1_api_strings.h"
+#include "vl53l1_api_core.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/** @defgroup VL53L1_cut11_group VL53L1 cut1.1 Function Definition
+ * @brief VL53L1 cut1.1 Function Definition
+ * @{
+ */
+
+/** @defgroup VL53L1_general_group VL53L1 General Functions
+ * @brief General functions and definitions
+ * @{
+ */
+
+/**
+ * @brief Return the VL53L1 PAL Implementation Version
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param pVersion Pointer to current PAL Implementation Version
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetVersion(VL53L1_Version_t *pVersion);
+
+/**
+ * @brief Return the PAL Specification Version used for the current
+ * implementation.
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param pPalSpecVersion Pointer to current PAL Specification Version
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetPalSpecVersion(
+ VL53L1_Version_t *pPalSpecVersion);
+
+/**
+ * @brief Reads the Product Revision for a for given Device
+ * This function can be used to distinguish cut1.0 from cut1.1.
+ *
+ * @param Dev Device Handle
+ * @param pProductRevisionMajor Pointer to Product Revision Major
+ * for a given Device
+ * @param pProductRevisionMinor Pointer to Product Revision Minor
+ * for a given Device
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetProductRevision(VL53L1_DEV Dev,
+ uint8_t *pProductRevisionMajor, uint8_t *pProductRevisionMinor);
+
+/**
+ * @brief Reads the Device information for given Device
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pVL53L1_DeviceInfo Pointer to current device info for a given
+ * Device
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetDeviceInfo(VL53L1_DEV Dev,
+ VL53L1_DeviceInfo_t *pVL53L1_DeviceInfo);
+
+/**
+ * @brief Human readable Range Status string for a given RangeStatus
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param RangeStatus The RangeStatus code as stored on
+ * @a VL53L1_RangingMeasurementData_t
+ * @param pRangeStatusString The returned RangeStatus string. Shall be
+ * defined as char buf[VL53L1_MAX_STRING_LENGTH]
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetRangeStatusString(uint8_t RangeStatus,
+ char *pRangeStatusString);
+
+/**
+ * @brief Human readable error string for current PAL error status
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param PalErrorCode The error code as stored on @a VL53L1_Error
+ * @param pPalErrorString The error string corresponding to the
+ * PalErrorCode. Shall be defined as char buf[VL53L1_MAX_STRING_LENGTH]
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetPalErrorString(VL53L1_Error PalErrorCode,
+ char *pPalErrorString);
+
+/**
+ * @brief Human readable PAL State string
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param PalStateCode The State code as stored on @a VL53L1_State
+ * @param pPalStateString The State string corresponding to the
+ * PalStateCode. Shall be defined as char buf[VL53L1_MAX_STRING_LENGTH]
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetPalStateString(VL53L1_State PalStateCode,
+ char *pPalStateString);
+
+/**
+ * @brief Reads the internal state of the PAL for a given Device
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param Dev Device Handle
+ * @param pPalState Pointer to current state of the PAL for a
+ * given Device
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetPalState(VL53L1_DEV Dev,
+ VL53L1_State *pPalState);
+
+
+
+/** @} VL53L1_general_group */
+
+/** @defgroup VL53L1_init_group VL53L1 Init Functions
+ * @brief VL53L1 Init Functions
+ * @{
+ */
+
+/**
+ * @brief Set new device address
+ *
+ * After completion the device will answer to the new address programmed.
+ * This function should be called when several devices are used in parallel
+ * before start programming the sensor.
+ * When a single device us used, there is no need to call this function.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param DeviceAddress The new Device address
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetDeviceAddress(VL53L1_DEV Dev,
+ uint8_t DeviceAddress);
+
+/**
+ *
+ * @brief One time device initialization
+ *
+ * To be called once and only once after device is brought out of reset
+ * (Chip enable) and booted see @a VL53L1_WaitDeviceBooted()
+ *
+ * @par Function Description
+ * When not used after a fresh device "power up" or reset, it may return
+ * @a #VL53L1_ERROR_CALIBRATION_WARNING meaning wrong calibration data
+ * may have been fetched from device that can result in ranging offset error\n
+ * If application cannot execute device reset or need to run VL53L1_DataInit
+ * multiple time then it must ensure proper offset calibration saving and
+ * restore on its own by using @a VL53L1_GetOffsetCalibrationData() on first
+ * power up and then @a VL53L1_SetOffsetCalibrationData() in all subsequent init
+ * This function will change the VL53L1_State from VL53L1_STATE_POWERDOWN to
+ * VL53L1_STATE_WAIT_STATICINIT.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_DataInit(VL53L1_DEV Dev);
+
+
+/**
+ * @brief Do basic device init (and eventually patch loading)
+ * This function will change the VL53L1_State from
+ * VL53L1_STATE_WAIT_STATICINIT to VL53L1_STATE_IDLE.
+ * In this stage all default setting will be applied.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_StaticInit(VL53L1_DEV Dev);
+
+/**
+ * @brief Wait for device booted after chip enable (hardware standby)
+ * This function can be run only when VL53L1_State is VL53L1_STATE_POWERDOWN.
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ *
+ */
+VL53L1_Error VL53L1_WaitDeviceBooted(VL53L1_DEV Dev);
+
+
+/** @} VL53L1_init_group */
+
+/** @defgroup VL53L1_parameters_group VL53L1 Parameters Functions
+ * @brief Functions used to prepare and setup the device
+ * @{
+ */
+
+/**
+ * @brief Set a new Preset Mode
+ * @par Function Description
+ * Set device to a new Operating Mode (High speed ranging, Multi objects ...)
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @warning This function change the timing budget to 16 ms and the inter-
+ * measurement period to 1000 ms. Also the VL53L1_DISTANCEMODE_LONG is used.
+ *
+ * @param Dev Device Handle
+ * @param PresetMode New Preset mode to apply
+ * Valid values are:
+ * VL53L1_PRESETMODE_MULTIZONES_SCANNING
+ * VL53L1_PRESETMODE_RANGING
+ * VL53L1_PRESETMODE_AUTONOMOUS
+ * VL53L1_PRESETMODE_LITE_RANGING
+ * VL53L1_PRESETMODE_OLT
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_MODE_NOT_SUPPORTED This error occurs when PresetMode is
+ * not in the supported list
+ */
+VL53L1_Error VL53L1_SetPresetMode(VL53L1_DEV Dev,
+ VL53L1_PresetModes PresetMode);
+
+/**
+ * @brief Get current Preset Mode
+ * @par Function Description
+ * Get actual mode of the device(ranging, histogram ...)
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pPresetMode Pointer to current apply mode value
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_MODE_NOT_SUPPORTED This error occurs when
+ * DeviceMode is not in the supported list
+ */
+VL53L1_Error VL53L1_GetPresetMode(VL53L1_DEV Dev,
+ VL53L1_PresetModes *pPresetMode);
+
+
+/**
+ * @brief Set the distance mode
+ * @par Function Description
+ * Set the distance mode to be used for the next ranging.
+ * The modes Short, Medium and Long are used to optimize the ranging accuracy
+ * in a specific range of distance. The user select one of these modes to fix
+ * the distance range, for this reason these are also called Manual modes.
+ * Two additional modes are supported: AUTO and AUTO_LITE the difference between
+ * these modes is the following.
+ * The mode AUTO take into account both the ranging distance (RangeMilliMeter)
+ * and the dmax distance (DmaxMilliMeter). The algorithm uses the ranging
+ * distance when the range status is ok i.e. when range
+ * status = VL53L1_RANGESTATUS_RANGE_VALID or
+ * status = VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK
+ * and it uses the dmax distance when the range status is not ok.
+ * The AUTO_LITE take into account only the ranging distance, so nothing is done
+ * in case of range error i.e. the distance mode will not be changed.
+ * @note This function doesn't Access to the device
+ *
+ * @warning This function should be called after @a VL53L1_SetPresetMode().
+
+ * @param Dev Device Handle
+ * @param DistanceMode Distance mode to apply
+ * Valid values are:
+ * for all Preset Mode (MANUAL MODE)
+ * VL53L1_DISTANCEMODE_SHORT
+ * VL53L1_DISTANCEMODE_MEDIUM
+ * VL53L1_DISTANCEMODE_LONG
+ *
+ * for LIGHT_RANGING and RANGING (AUTO MODE)
+ * VL53L1_DISTANCEMODE_AUTO_LITE
+ * VL53L1_DISTANCEMODE_AUTO
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_MODE_NOT_SUPPORTED This error occurs when DistanceMode
+ * is not in the supported list
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetDistanceMode(VL53L1_DEV Dev,
+ VL53L1_DistanceModes DistanceMode);
+
+/**
+ * @brief Get the distance mode
+ * @par Function Description
+ * Get the distance mode used for the next ranging.
+ *
+ * @param Dev Device Handle
+ * @param *pDistanceMode Pointer to Distance mode
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetDistanceMode(VL53L1_DEV Dev,
+ VL53L1_DistanceModes *pDistanceMode);
+
+
+/**
+ * @brief Set the output mode
+ * @par Function Description
+ * Set the output mode to be used for the next ranging. The output mode is used
+ * to select, in case of multiple objects, which one will be used in
+ * function @a VL53L1_GetRangingMeasurementData().
+ * VL53L1_SetOutputMode also sets the object used by automatic
+ * distance mode algorithm when @a VL53L1_SetDistanceMode() is
+ * set to automatic mode.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @warning This function should be called after @a VL53L1_SetPresetMode().
+
+ * @param Dev Device Handle
+ * @param OutputMode Output mode to apply
+ * Valid values are:
+ * VL53L1_OUTPUTMODE_NEAREST
+ * VL53L1_OUTPUTMODE_STRONGEST
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_MODE_NOT_SUPPORTED This error occurs when OutputMode
+ * is not in the supported list
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetOutputMode(VL53L1_DEV Dev,
+ VL53L1_OutputModes OutputMode);
+
+/**
+ * @brief Get the output mode
+ * @par Function Description
+ * Get the output mode used for the next ranging.
+ *
+ * @param Dev Device Handle
+ * @param *pOutputMode Pointer to Output mode
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetOutputMode(VL53L1_DEV Dev,
+ VL53L1_OutputModes *pOutputMode);
+
+
+/**
+ * @brief Set Ranging Timing Budget in microseconds
+ *
+ * @par Function Description
+ * Defines the maximum time allowed by the user to the device to run a
+ * full ranging sequence for the current mode (ranging, histogram, ASL ...)
+ *
+ * @param Dev Device Handle
+ * @param MeasurementTimingBudgetMicroSeconds Max measurement time in
+ * microseconds.
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_INVALID_PARAMS Error timing parameter not
+ * supported.
+ * The maximum accepted value for the
+ * computed timing budget is 10 seconds
+ * the minimum value depends on the preset
+ * mode selected.
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetMeasurementTimingBudgetMicroSeconds(
+ VL53L1_DEV Dev, uint32_t MeasurementTimingBudgetMicroSeconds);
+
+/**
+ * @brief Get Ranging Timing Budget in microseconds
+ *
+ * @par Function Description
+ * Returns the programmed the maximum time allowed by the user to the
+ * device to run a full ranging sequence for the current mode
+ * (ranging, histogram, ASL ...)
+ *
+ * @param Dev Device Handle
+ * @param pMeasurementTimingBudgetMicroSeconds Max measurement time in
+ * microseconds.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetMeasurementTimingBudgetMicroSeconds(
+ VL53L1_DEV Dev, uint32_t *pMeasurementTimingBudgetMicroSeconds);
+
+
+/**
+ * Program continuous mode Inter-Measurement period in milliseconds
+ *
+ * @par Function Description
+ * When trying to set too short time return INVALID_PARAMS minimal value
+ *
+ * @param Dev Device Handle
+ * @param InterMeasurementPeriodMilliSeconds Inter-Measurement Period in ms.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetInterMeasurementPeriodMilliSeconds(
+ VL53L1_DEV Dev, uint32_t InterMeasurementPeriodMilliSeconds);
+
+/**
+ * Get continuous mode Inter-Measurement period in milliseconds
+ *
+ * @par Function Description
+ *
+ * @param Dev Device Handle
+ * @param pInterMeasurementPeriodMilliSeconds Pointer to programmed
+ * Inter-Measurement Period in milliseconds.
+ * @return VL53L1_ERROR_NONE
+ */
+VL53L1_Error VL53L1_GetInterMeasurementPeriodMilliSeconds(
+ VL53L1_DEV Dev, uint32_t *pInterMeasurementPeriodMilliSeconds);
+
+/**
+ * @brief target reflectance for Dmax setting
+ * @par Function Description
+ * Allow user to set the value for target reflectance @ 940nm to calculate the
+ * ambient DMAX values for. Set to 50% by default by @a VL53L1_DataInit()
+ *
+ * @param Dev Device Handle
+ * @param value Reflectance % in 16.16 fixed point
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetDmaxReflectance(VL53L1_DEV Dev,
+ FixPoint1616_t value);
+
+/**
+ * @brief Get target reflectance for Dmax
+ * @par Function Description
+ * Retrieves the value for target reflectance @ 940nm to calculate the
+ * ambient DMAX values for. Set to 50% by default by @a VL53L1_DataInit()
+ *
+ * @param Dev Device Handle
+ * @param pvalue pointer to Reflectance % in 16.16 fixed point
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetDmaxReflectance(VL53L1_DEV Dev,
+ FixPoint1616_t *pvalue);
+/**
+ * @brief Set function for ambient Dmax mode
+ *
+ *
+ * @param Dev Device Handle
+ * @param DmaxMode DMAX mode to be used in ranging
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+
+VL53L1_Error VL53L1_SetDmaxMode(VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxModes DmaxMode);
+
+/**
+ * @brief Get function for ambient Dmax mode
+ *
+ * @param Dev Device Handle
+ * @param pDmaxMode output pointer to DMAX mode currently in use
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+
+VL53L1_Error VL53L1_GetDmaxMode(VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxModes *pDmaxMode);
+
+/** @} VL53L1_parameters_group */
+
+
+/** @defgroup VL53L1_limitcheck_group VL53L1 Limit Check Functions
+ * @brief Functions used for the Limit checks
+ * @{
+ */
+
+
+
+/**
+ * @brief Get the number of the check limit managed by a given Device
+ *
+ * @par Function Description
+ * This function give the number of the check limit managed by the Device
+ *
+ * @param pNumberOfLimitCheck Pointer to the number of check limit.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetNumberOfLimitCheck(
+ uint16_t *pNumberOfLimitCheck);
+
+/**
+ * @brief Return a description string for a given limit check number
+ *
+ * @par Function Description
+ * This function returns a description string for a given limit check number.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @param LimitCheckId Limit Check ID
+ (0<= LimitCheckId < VL53L1_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckString Pointer to the description string of
+ * the given check limit. Shall be defined as char buf[VL53L1_MAX_STRING_LENGTH]
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetLimitCheckInfo(uint16_t LimitCheckId,
+ char *pLimitCheckString);
+
+/**
+ * @brief Return a the Status of the specified check limit
+ *
+ * @par Function Description
+ * This function returns the Status of the specified check limit.
+ * The value indicate if the check is fail or not.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ (0<= LimitCheckId < VL53L1_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckStatus Pointer to the
+ Limit Check Status of the given check limit.
+ * LimitCheckStatus :
+ * 0 the check is not fail or not enabled
+ * 1 the check if fail
+ *
+ *
+ * - VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE: the sigma indicate the quality
+ * of the measure. The more it is little the better it is.
+ * The status is 1 when current sigma is greater then the limit.
+ * - VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE: the signal rate indicate
+ * the strength of the returned signal. The more it is big the better it is.
+ * The status is 1 when current signal is lower then the limit.
+ *
+ *
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetLimitCheckStatus(VL53L1_DEV Dev,
+ uint16_t LimitCheckId, uint8_t *pLimitCheckStatus);
+
+/**
+ * @brief Enable/Disable a specific limit check
+ *
+ * @par Function Description
+ * This function Enable/Disable a specific limit check.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L1_GetNumberOfLimitCheck() ).
+ * @param LimitCheckEnable if 1 the check limit
+ * corresponding to LimitCheckId is Enabled
+ * if 0 the check limit
+ * corresponding to LimitCheckId is disabled
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_INVALID_PARAMS This error is returned
+ * when LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetLimitCheckEnable(VL53L1_DEV Dev,
+ uint16_t LimitCheckId, uint8_t LimitCheckEnable);
+
+/**
+ * @brief Get specific limit check enable state
+ *
+ * @par Function Description
+ * This function get the enable state of a specific limit check.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L1_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckEnable Pointer to the check limit enable
+ * value.
+ * if 1 the check limit
+ * corresponding to LimitCheckId is Enabled
+ * if 0 the check limit
+ * corresponding to LimitCheckId is disabled
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_INVALID_PARAMS This error is returned
+ * when LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetLimitCheckEnable(VL53L1_DEV Dev,
+ uint16_t LimitCheckId, uint8_t *pLimitCheckEnable);
+
+/**
+ * @brief Set a specific limit check value
+ *
+ * @par Function Description
+ * This function set a specific limit check value.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note Note that the value written with that function will not be applied if
+ * the limit is not enabled. In other words this function will not enable the
+ * limit but change only the value. In case the limit is not enabled the value
+ * is saved internally and applied with VL53L1_SetLimitCheckEnable.
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L1_GetNumberOfLimitCheck() ).
+ * @param LimitCheckValue Limit check Value for a given
+ * LimitCheckId
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetLimitCheckValue(VL53L1_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t LimitCheckValue);
+
+/**
+ * @brief Get a specific limit check value
+ *
+ * @par Function Description
+ * This function get a specific limit check value from device then it updates
+ * internal values and check enables.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function get the current value from device if zero then the value
+ * returned is the one stored by the user, but in that case the check is store
+ * as disabled. If the value from device is not zero, this is returned and set
+ * into the memory at the same way that user call VL53L1_SetLimitCheckValue()
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L1_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckValue Pointer to Limit
+ * check Value for a given LimitCheckId.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetLimitCheckValue(VL53L1_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t *pLimitCheckValue);
+
+/**
+ * @brief Get the current value of the signal used for the limit check
+ *
+ * @par Function Description
+ * This function get a the current value of the signal used for the limit check.
+ * To obtain the latest value you should run a valid ranging before.
+ * The value reported is linked to the limit check identified with the
+ * LimitCheckId.
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L1_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckCurrent Pointer to current Value for a
+ * given LimitCheckId.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetLimitCheckCurrent(VL53L1_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t *pLimitCheckCurrent);
+
+/** @} VL53L1_limitcheck_group */
+
+
+
+/** @defgroup VL53L1_ROI_group VL53L1 ROI Functions
+ * @brief Functions used to select ROIs
+ * @{
+ */
+
+/**
+ * @brief Get the Maximum number of ROI Zones managed by the Device
+ *
+ * @par Function Description
+ * Get Maximum number of ROI Zones managed by the Device.
+ *
+ * @note The number of Zone depends on the preset mode used so to have the
+ * right number this function should be call after @a VL53L1_SetPresetMode()
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pMaxNumberOfROI Pointer to the Maximum Number
+ * of ROI Zones value.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetMaxNumberOfROI(VL53L1_DEV Dev,
+ uint8_t *pMaxNumberOfROI);
+
+/**
+ * @brief Set the ROI to be used for a specific Device
+ *
+ * @par Function Description
+ * Set the ROI to be used for a specific Device.
+ * Rectangle in user's coordinate system:
+ * 15 TL(x,y) o-----*
+ * ^ | |
+ * | *-----o BR(x,y)
+ * 0------------------------- >15
+ * Minimal ROI size is 4x4
+ *
+ * @param Dev Device Handle
+ * @param pRoiConfig Pointer to the Structure containing all the
+ * ROI to be used.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetROI(VL53L1_DEV Dev,
+ VL53L1_RoiConfig_t *pRoiConfig);
+
+/**
+ * @brief Get the ROI managed by the Device
+ *
+ * @par Function Description
+ * Get the ROI managed by the Device
+ *
+ * @param Dev Device Handle
+ * @param pRoiConfig Pointer to the Structure containing all the
+ * ROI to be used.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetROI(VL53L1_DEV Dev,
+ VL53L1_RoiConfig_t *pRoiConfig);
+
+
+/** @} VL53L1_ROI_group */
+
+
+/** @defgroup VL53L1_sequencestep_group VL53L1 Sequence Step Functions
+ * @brief Functions used to select Steps done on each ranging
+ * @{
+ */
+
+/**
+ * @brief Gets number of sequence steps managed by the API.
+ *
+ * @par Function Description
+ * This function retrieves the number of sequence steps currently managed
+ * by the API
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param pNumberOfSequenceSteps Out parameter reporting the number of
+ * sequence steps.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetNumberOfSequenceSteps(VL53L1_DEV Dev,
+ uint8_t *pNumberOfSequenceSteps);
+
+/**
+ * @brief Gets the name of a given sequence step.
+ *
+ * @par Function Description
+ * This function retrieves the name of sequence steps corresponding to
+ * SequenceStepId.
+ *
+ * @note This function doesn't Accesses the device
+ *
+ * @param SequenceStepId Sequence step identifier.
+ * @param pSequenceStepsString Pointer to Info string. Shall be
+ * defined as char buf[VL53L1_MAX_STRING_LENGTH]
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetSequenceStepsInfo(
+ VL53L1_SequenceStepId SequenceStepId, char *pSequenceStepsString);
+
+
+
+/**
+ * @brief Sets the (on/off) state of a requested sequence step.
+ *
+ * @par Function Description
+ * This function enables/disables a requested sequence step.
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param SequenceStepId Sequence step identifier.
+ * @param SequenceStepEnabled Demanded state {0=Off,1=On}
+ * is enabled.
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_INVALID_PARAMS Error SequenceStepId parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetSequenceStepEnable(VL53L1_DEV Dev,
+ VL53L1_SequenceStepId SequenceStepId, uint8_t SequenceStepEnabled);
+
+/**
+ * @brief Gets the (on/off) state of a requested sequence step.
+ *
+ * @par Function Description
+ * This function retrieves the state of a requested sequence step, i.e. on/off.
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param SequenceStepId Sequence step identifier.
+ * @param pSequenceStepEnabled Out parameter reporting if the sequence step
+ * is enabled {0=Off,1=On}.
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_INVALID_PARAMS Error SequenceStepId parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetSequenceStepEnable(VL53L1_DEV Dev,
+ VL53L1_SequenceStepId SequenceStepId, uint8_t *pSequenceStepEnabled);
+
+
+/** @} VL53L1_sequencestep_group */
+
+
+
+/** @defgroup VL53L1_measurement_group VL53L1 Measurement Functions
+ * @brief Functions used for the measurements
+ * @{
+ */
+
+/**
+ * @brief Start device measurement
+ *
+ * @details Started measurement will depend on preset parameters set through
+ * @a VL53L1_SetPreseMode()
+ * This function will change the VL53L1_State from VL53L1_STATE_IDLE to
+ * VL53L1_STATE_RUNNING.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_MODE_NOT_SUPPORTED This error occurs when
+ * PresetMode programmed with @a VL53L1_SetPresetMode
+ *
+ * @return VL53L1_ERROR_TIME_OUT Time out on start measurement
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_StartMeasurement(VL53L1_DEV Dev);
+
+/**
+ * @brief Stop device measurement
+ *
+ * @details Will set the device in standby mode at end of current measurement\n
+ * Not necessary in single mode as device shall return automatically
+ * in standby mode at end of measurement.
+ * This function will change the VL53L1_State from VL53L1_STATE_RUNNING
+ * to VL53L1_STATE_IDLE.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_StopMeasurement(VL53L1_DEV Dev);
+
+/**
+ * @brief Clear the Interrupt flag and start new measurement
+ * *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_ClearInterruptAndStartMeasurement(VL53L1_DEV Dev);
+
+/**
+ * @brief Return Measurement Data Ready
+ *
+ * @par Function Description
+ * This function indicate that a measurement data is ready.
+ * This function is used for non-blocking capture.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pMeasurementDataReady Pointer to Measurement Data Ready.
+ * 0 = data not ready, 1 = data ready
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetMeasurementDataReady(VL53L1_DEV Dev,
+ uint8_t *pMeasurementDataReady);
+
+/**
+ * @brief Wait for measurement data ready.
+ * Blocking function.
+ * Note that the timeout is given by:
+ * VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS defined in def.h
+ *
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_TIME_OUT In case of timeout
+ */
+VL53L1_Error VL53L1_WaitMeasurementDataReady(VL53L1_DEV Dev);
+
+
+/**
+ * @brief Retrieve the measurements from device for a given setup
+ *
+ * @par Function Description
+ * Get data from last successful Ranging measurement
+ * @warning this function will return only the first ROI data and only the
+ * first object. For multi objects or multi ROI use:
+ * @a Vl53L1_GetMultiRangingData.
+ * In case of RANGING or MULTIZONES_SCANNING, only one output is given, this can
+ * be selected with the help of @a VL53L1_SetOutputMode()
+ *
+ * @note This function Access to the device
+ *
+ * @note The first valid value returned by this function will have a range
+ * status equal to VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK which means that
+ * the data is valid but no wrap around check have been done. User should take
+ * care about that.
+ *
+ * @param Dev Device Handle
+ * @param pRangingMeasurementData Pointer to the data structure to fill up.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetRangingMeasurementData(VL53L1_DEV Dev,
+ VL53L1_RangingMeasurementData_t *pRangingMeasurementData);
+
+/**
+ * @brief Retrieve all ROI's measurements from device for a given setup
+ *
+ * @par Function Description
+ * Get data from last successful Ranging measurement
+ * @warning USER should take care about @a VL53L1_GetNumberOfROI()
+ * before get data.
+ * PAL will fill a NumberOfROI times the corresponding data
+ * structure used in the measurement function.
+ *
+ * @note This function Access to the device
+ *
+ * @note The first valid value returned by this function will have a range
+ * status equal to VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK which means that
+ * the data is valid but no wrap around check have been done. User should take
+ * care about that.
+ *
+ * @param Dev Device Handle
+ * @param pMultiRangingData Pointer to the data structure to fill up.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetMultiRangingData(VL53L1_DEV Dev,
+ VL53L1_MultiRangingData_t *pMultiRangingData);
+
+/** @} VL53L1_measurement_group */
+
+/** @defgroup VL53L1_Calibration_group VL53L1 Calibration Functions
+ * @brief Functions used for Calibration
+ * @{
+ */
+
+
+/**
+ * @brief Performs Reference Spad Management
+ *
+ * @par Function Description
+ * The reference SPAD initialization procedure determines the minimum amount
+ * of reference spads to be enables to achieve a target reference signal rate
+ * and should be performed once during initialization.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_PerformRefSpadManagement(VL53L1_DEV Dev);
+
+/**
+* @brief Enable/Disable Cross talk compensation feature
+*
+* Enable/Disable Cross Talk correction.
+*
+* @param Dev Device Handle
+* @param XTalkCompensationEnable Cross talk compensation
+* to be set 0 = disabled; other values than zero = enabled.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+*/
+VL53L1_Error VL53L1_SetXTalkCompensationEnable(VL53L1_DEV Dev,
+uint8_t XTalkCompensationEnable);
+
+/**
+ * @brief Get Cross talk compensation rate enable
+ *
+ * Get if the Cross Talk is Enabled or Disabled.
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param Dev Device Handle
+ * @param pXTalkCompensationEnable Pointer to the Cross talk compensation
+ * state 0=disabled or 1 = enabled
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetXTalkCompensationEnable(VL53L1_DEV Dev,
+ uint8_t *pXTalkCompensationEnable);
+
+/**
+ * @brief Perform XTalk Calibration
+ *
+ * @details Perform a XTalk calibration of the Device.
+ * This function will launch a ranging measurement, if interrupts
+ * are enabled an interrupt will be done.
+ * This function will clear the interrupt generated automatically.
+ * This function will program a new value for the XTalk compensation
+ * and it will enable the cross talk before exit.
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @note This function change the preset mode so a new preset mode should
+ * be done after the call to this function
+ *
+ * @param Dev Device Handle
+ * @param CalibrationOption Select the Calibration to be run
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_PerformXTalkCalibration(VL53L1_DEV Dev,
+ uint8_t CalibrationOption);
+
+/**
+* @brief Define the mode to be used for the offset calibration
+*
+* Define the mode to be used for the offset calibration. This function should
+* be called before run the @a VL53L1_PerformOffsetCalibration()
+*
+* @param Dev Device Handle
+* @param OffsetCalibrationMode Offset Calibration Mode
+* valid values are:
+* VL53L1_OFFSETCALIBRATIONMODE_STANDARD
+* VL53L1_OFFSETCALIBRATIONMODE_PRERANGE_ONLY
+* VL53L1_OFFSETCALIBRATIONMODE_MULTI_ZONE
+*
+* @return VL53L1_ERROR_NONE Success
+* @return "Other error code" See ::VL53L1_Error
+*/
+VL53L1_Error VL53L1_SetOffsetCalibrationMode(VL53L1_DEV Dev,
+ VL53L1_OffsetCalibrationModes OffsetCalibrationMode);
+
+/**
+* @brief Define the mode to be used for the offset correction
+*
+* Define the mode to be used for the offset correction.
+*
+* @param Dev Device Handle
+* @param OffsetCorrectionMode Offset Correction Mode
+* valid values are:
+* VL53L1_OFFSETCORRECTIONMODE_STANDARD
+* VL53L1_OFFSETCORRECTIONMODE_PERZONE
+*
+* @return VL53L1_ERROR_NONE Success
+* @return "Other error code" See ::VL53L1_Error
+*/
+VL53L1_Error VL53L1_SetOffsetCorrectionMode(VL53L1_DEV Dev,
+ VL53L1_OffsetCorrectionModes OffsetCorrectionMode);
+
+
+/**
+ * @brief Perform Offset Calibration
+ *
+ * @details Perform a Offset calibration of the Device.
+ * This function will launch a ranging measurement, if interrupts are
+ * enabled interrupts will be done.
+ * This function will program a new value for the Offset calibration value
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param CalDistanceMilliMeter Calibration distance value used for the
+ * offset compensation.
+ * @param CalReflectancePercent Calibration Target reflectance @ 940nm
+ * in percentage.
+ *
+ * @return VL53L1_ERROR_NONE
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_PerformOffsetCalibration(VL53L1_DEV Dev,
+ int32_t CalDistanceMilliMeter,
+ FixPoint1616_t CalReflectancePercent);
+
+/**
+ * @brief Sets the Calibration Data.
+ *
+ * @par Function Description
+ * This function set all the Calibration Data issued from the functions
+ * @a VL53L1_PerformRefSpadManagement(), @a VL53L1_PerformXTalkCalibration,
+ * @a VL53L1_PerformOffsetCalibration()
+ *
+ * @note This function doesn't Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param *pCalibrationData Pointer to Calibration data to be set.
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_INVALID_PARAMS pCalibrationData points to an older
+ * version of the inner structure. Need for support to convert its content.
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetCalibrationData(VL53L1_DEV Dev,
+ VL53L1_CalibrationData_t *pCalibrationData);
+
+/**
+ * @brief Gets the Calibration Data.
+ *
+ * @par Function Description
+ * This function get all the Calibration Data issued from the functions
+ * @a VL53L1_PerformRefSpadManagement(), @a VL53L1_PerformXTalkCalibration,
+ * @a VL53L1_PerformOffsetCalibration()
+ *
+ * @note This function doesn't Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param *pCalibrationData pointer where to store Calibration
+ * data.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetCalibrationData(VL53L1_DEV Dev,
+ VL53L1_CalibrationData_t *pCalibrationData);
+
+/**
+ * @brief Gets the optical center.
+ *
+ * @par Function Description
+ * This function get the optical center issued from the nvm set at FTM stage
+ * expressed in the same coordinate system as the ROI are
+ *
+ * @note This function doesn't Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param *pOpticalCentreX pointer to the X position of center
+ * @param *pOpticalCentreY pointer to the Y position of center
+ * data.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetOpticalCenter(VL53L1_DEV Dev,
+ uint8_t *pOpticalCenterX, uint8_t *pOpticalCenterY);
+
+/** @} VL53L1_Calibration_group */
+
+/** @defgroup VL53L1_Thresholds_group VL53L1 IRQ Triggered events Functions
+ * @brief Functions used to configure interrupt to be triggered only when
+ * a measurement satisfies some thresholds parameters
+ * @{
+ */
+
+/**
+* @brief Configure the interrupt config, from the given structure
+*
+* @param[in] Dev : Device Handle
+* @param[in] pConfig : pointer to configuration structure
+*/
+
+VL53L1_Error VL53L1_SetThresholdConfig(VL53L1_DEV Dev,
+ VL53L1_DetectionConfig_t *pConfig);
+
+/**
+* @brief Retrieves the interrupt config structure currently programmed
+* into the API
+*
+* @param[in] Dev : Device Handle
+* @param[out] pConfig : pointer to configuration structure
+*/
+
+VL53L1_Error VL53L1_GetThresholdConfig(VL53L1_DEV Dev,
+ VL53L1_DetectionConfig_t *pConfig);
+
+
+/** @} VL53L1_Thresholds_group */
+
+
+/** @} VL53L1_cut11_group */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VL53L1_API_H_ */
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_api_calibration.h b/drivers/input/misc/vl53L1/inc/vl53l1_api_calibration.h
new file mode 100644
index 000000000000..4ab74b666bf8
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_api_calibration.h
@@ -0,0 +1,569 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_API_CALIBRATION_H_
+#define _VL53L1_API_CALIBRATION_H_
+
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_ref_spad_char(VL53L1_DEV Dev, VL53L1_Error *pcal_status);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_device_test(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceTestMode device_test_mode);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_spad_rate_map(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceTestMode device_test_mode,
+ VL53L1_DeviceSscArray array_select,
+ uint32_t ssc_config_timeout_us,
+ VL53L1_spad_rate_data_t *pspad_rate_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_xtalk_extraction(
+ VL53L1_DEV Dev,
+ uint16_t dss_config__target_total_rate_mcps,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint8_t num_of_samples,
+ VL53L1_Error *pcal_status);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_xtalk_extraction_dual_reflectance(
+ VL53L1_DEV Dev,
+ uint16_t dss_config__target_total_rate_mcps,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint8_t num_of_samples,
+ uint8_t calc_parms,
+ uint8_t higher_reflectance,
+ uint16_t expected_target_distance_mm,
+ uint16_t xtalk_filter_thresh_mm,
+ VL53L1_Error *pcal_status);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_and_avg_xtalk_samples(
+ VL53L1_DEV Dev,
+ uint8_t num_of_samples,
+ uint8_t measurement_mode,
+ int16_t xtalk_filter_thresh_max_mm,
+ int16_t xtalk_filter_thresh_min_mm,
+ uint16_t xtalk_max_valid_rate_kcps,
+ uint8_t xtalk_result_id,
+ uint8_t xtalk_histo_id,
+ VL53L1_xtalk_range_results_t *pxtalk_results,
+ VL53L1_histogram_bin_data_t *psum_histo,
+ VL53L1_histogram_bin_data_t *pavg_histo);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_and_avg_all_xtalk_samples(
+ VL53L1_DEV Dev,
+ uint8_t num_of_samples,
+ uint8_t measurement_mode,
+ int16_t xtalk_filter_thresh_mm,
+ VL53L1_xtalk_range_results_t *pxtalk_results,
+ VL53L1_histogram_bin_data_t *pavg_histo_z0,
+ VL53L1_histogram_bin_data_t *pavg_histo_z1,
+ VL53L1_histogram_bin_data_t *pavg_histo_z2,
+ VL53L1_histogram_bin_data_t *pavg_histo_z3,
+ VL53L1_histogram_bin_data_t *pavg_histo_z4);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_offset_calibration(
+ VL53L1_DEV Dev,
+ uint16_t dss_config__target_total_rate_mcps,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint8_t pre_num_of_samples,
+ uint8_t mm1_num_of_samples,
+ uint8_t mm2_num_of_samples,
+ int16_t cal_distance_mm,
+ uint16_t cal_reflectance_pc,
+ VL53L1_Error *pcal_status);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_zone_calibration(
+ VL53L1_DEV Dev,
+ VL53L1_DevicePresetModes device_preset_mode,
+ VL53L1_DeviceZonePreset zone_preset,
+ VL53L1_zone_config_t *pzone_cfg,
+ uint16_t dss_config__target_total_rate_mcps,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint16_t num_of_samples,
+ int16_t cal_distance_mm,
+ uint16_t cal_reflectance_pc,
+ VL53L1_Error *pcal_status);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_api_core.h b/drivers/input/misc/vl53L1/inc/vl53l1_api_core.h
new file mode 100644
index 000000000000..b9d9a96668ab
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_api_core.h
@@ -0,0 +1,1579 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_API_CORE_H_
+#define _VL53L1_API_CORE_H_
+
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_version(
+ VL53L1_DEV Dev,
+ VL53L1_ll_version_t *pversion);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_is_fpga_system(
+ VL53L1_DEV Dev,
+ uint8_t *pfpga_system);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_device_firmware_version(
+ VL53L1_DEV Dev,
+ uint16_t *pfw_version);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_data_init(
+ VL53L1_DEV Dev,
+ uint8_t read_p2p_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_read_p2p_data(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_software_reset(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_part_to_part_data(
+ VL53L1_DEV Dev,
+ VL53L1_calibration_data_t *pcal_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_part_to_part_data(
+ VL53L1_DEV Dev,
+ VL53L1_calibration_data_t *pcal_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_inter_measurement_period_ms(
+ VL53L1_DEV Dev,
+ uint32_t inter_measurement_period_ms);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_inter_measurement_period_ms(
+ VL53L1_DEV Dev,
+ uint32_t *pinter_measurement_period_ms);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_timeouts_us(
+ VL53L1_DEV Dev,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_timeouts_us(
+ VL53L1_DEV Dev,
+ uint32_t *pphasecal_config_timeout_us,
+ uint32_t *pmm_config_timeout_us,
+ uint32_t *prange_config_timeout_us);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_calibration_repeat_period(
+ VL53L1_DEV Dev,
+ uint16_t cal_config__repeat_period);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_calibration_repeat_period(
+ VL53L1_DEV Dev,
+ uint16_t *pcal_config__repeat_period);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_sequence_config_bit(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceSequenceConfig bit_id,
+ uint8_t value);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_sequence_config_bit(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceSequenceConfig bit_id,
+ uint8_t *pvalue);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_interrupt_polarity(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceInterruptPolarity interrupt_polarity);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_interrupt_polarity(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceInterruptPolarity *pinterrupt_polarity);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_refspadchar_config_struct(
+ VL53L1_DEV Dev,
+ VL53L1_refspadchar_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_refspadchar_config_struct(
+ VL53L1_DEV Dev,
+ VL53L1_refspadchar_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_range_ignore_threshold(
+ VL53L1_DEV Dev,
+ uint8_t range_ignore_thresh_mult,
+ uint16_t range_ignore_threshold_mcps);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_range_ignore_threshold(
+ VL53L1_DEV Dev,
+ uint8_t *prange_ignore_thresh_mult,
+ uint16_t *prange_ignore_threshold_mcps_internal,
+ uint16_t *prange_ignore_threshold_mcps_current);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_user_zone(
+ VL53L1_DEV Dev,
+ VL53L1_user_zone_t *puser_zone);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_user_zone(
+ VL53L1_DEV Dev,
+ VL53L1_user_zone_t *puser_zone);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_mode_mitigation_roi(
+ VL53L1_DEV Dev,
+ VL53L1_user_zone_t *pmm_roi);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_zone_config(
+ VL53L1_DEV Dev,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_zone_config(
+ VL53L1_DEV Dev,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_preset_mode(
+ VL53L1_DEV Dev,
+ VL53L1_DevicePresetModes device_preset_mode,
+ uint16_t dss_config__target_total_rate_mcps,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint32_t inter_measurement_period_ms);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_zone_preset(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceZonePreset zone_preset);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_enable_xtalk_compensation(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_disable_xtalk_compensation(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_get_xtalk_compensation_enable(
+ VL53L1_DEV Dev,
+ uint8_t *pcrosstalk_compensation_enable);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_and_start_range(
+ VL53L1_DEV Dev,
+ uint8_t measurement_mode,
+ VL53L1_DeviceConfigLevel device_config_level);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_stop_range(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_measurement_results(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceResultsLevel device_result_level);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_device_results(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceResultsLevel device_result_level,
+ VL53L1_range_results_t *prange_results);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_clear_interrupt_and_enable_next_range(
+ VL53L1_DEV Dev,
+ uint8_t measurement_mode);
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_histogram_bin_data(
+ VL53L1_DEV Dev,
+ VL53L1_histogram_bin_data_t *phist_data);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_copy_sys_and_core_results_to_range_results(
+ int32_t gain_factor,
+ VL53L1_system_results_t *psys,
+ VL53L1_core_results_t *pcore,
+ VL53L1_range_results_t *presults);
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_zone_dss_config(
+ VL53L1_DEV Dev,
+ VL53L1_zone_private_dyn_cfg_t *pzone_dyn_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_calc_ambient_dmax(
+ VL53L1_DEV Dev,
+ uint16_t target_reflectance,
+ int16_t *pambient_dmax_mm);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_interrupt_config(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_Interrupt_Mode intr_mode_distance,
+ VL53L1_GPIO_Interrupt_Mode intr_mode_rate,
+ uint8_t intr_new_measure_ready,
+ uint8_t intr_no_target,
+ uint8_t intr_combined_mode,
+ uint16_t thresh_distance_high,
+ uint16_t thresh_distance_low,
+ uint16_t thresh_rate_high,
+ uint16_t thresh_rate_low
+ );
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_interrupt_config_struct(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_interrupt_config_t intconf);
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_GPIO_interrupt_config(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_interrupt_config_t *pintconf);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_dmax_mode(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxMode dmax_mode);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_dmax_mode(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxMode *pdmax_mode);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_dmax_calibration_data(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxMode dmax_mode,
+ uint8_t zone_id,
+ VL53L1_dmax_calibration_data_t *pdmax_cal);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_hist_dmax_config(
+ VL53L1_DEV Dev,
+ VL53L1_hist_gen3_dmax_config_t *pdmax_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_hist_dmax_config(
+ VL53L1_DEV Dev,
+ VL53L1_hist_gen3_dmax_config_t *pdmax_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_offset_calibration_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCalibrationMode offset_cal_mode);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_offset_calibration_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCalibrationMode *poffset_cal_mode);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_offset_correction_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCalibrationMode offset_cor_mode);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_offset_correction_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCorrectionMode *poffset_cor_mode);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_zone_calibration_data(
+ VL53L1_DEV Dev,
+ VL53L1_zone_calibration_results_t *pzone_cal);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_zone_calibration_data(
+ VL53L1_DEV Dev,
+ VL53L1_zone_calibration_results_t *pzone_cal);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_lite_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t *pxtalk_margin);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_lite_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t xtalk_margin);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_histogram_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t *pxtalk_margin);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_histogram_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t xtalk_margin);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_histogram_phase_consistency(
+ VL53L1_DEV Dev,
+ uint8_t *pphase_consistency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_histogram_phase_consistency(
+ VL53L1_DEV Dev,
+ uint8_t phase_consistency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_histogram_event_consistency(
+ VL53L1_DEV Dev,
+ uint8_t *pevent_consistency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_histogram_event_consistency(
+ VL53L1_DEV Dev,
+ uint8_t event_consistency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_histogram_ambient_threshold_sigma(
+ VL53L1_DEV Dev,
+ uint8_t *pamb_thresh_sigma);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_histogram_ambient_threshold_sigma(
+ VL53L1_DEV Dev,
+ uint8_t amb_thresh_sigma);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_lite_min_count_rate(
+ VL53L1_DEV Dev,
+ uint16_t *plite_mincountrate);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_lite_min_count_rate(
+ VL53L1_DEV Dev,
+ uint16_t lite_mincountrate);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_lite_sigma_threshold(
+ VL53L1_DEV Dev,
+ uint16_t *plite_sigma);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_lite_sigma_threshold(
+ VL53L1_DEV Dev,
+ uint16_t lite_sigma);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_restore_xtalk_nvm_default(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_xtalk_detect_config(
+ VL53L1_DEV Dev,
+ int16_t *pmax_valid_range_mm,
+ int16_t *pmin_valid_range_mm,
+ uint16_t *pmax_valid_rate_kcps,
+ uint16_t *pmax_sigma_mm);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_xtalk_detect_config(
+ VL53L1_DEV Dev,
+ int16_t max_valid_range_mm,
+ int16_t min_valid_range_mm,
+ uint16_t max_valid_rate_kcps,
+ uint16_t max_sigma_mm);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_target_order_mode(
+ VL53L1_DEV Dev,
+ VL53L1_HistTargetOrder *phist_target_order);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_target_order_mode(
+ VL53L1_DEV Dev,
+ VL53L1_HistTargetOrder hist_target_order);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_dmax_reflectance_values(
+ VL53L1_DEV Dev,
+ VL53L1_dmax_reflectance_array_t *pdmax_reflectances);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_dmax_reflectance_values(
+ VL53L1_DEV Dev,
+ VL53L1_dmax_reflectance_array_t *pdmax_reflectances);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_api_debug.h b/drivers/input/misc/vl53L1/inc/vl53l1_api_debug.h
new file mode 100644
index 000000000000..1203caa2f532
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_api_debug.h
@@ -0,0 +1,649 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_API_DEBUG_H_
+#define _VL53L1_API_DEBUG_H_
+
+#include "vl53l1_platform.h"
+#include "vl53l1_nvm_structs.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_decode_calibration_data_buffer(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_calibration_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_nvm_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_decoded_nvm_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_histogram_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_xtalk_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_xtalk_debug_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_offset_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_offset_debug_data_t *pdata);
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_signed_fixed_point_sprintf(
+ int32_t fp_value,
+ uint8_t frac_bits,
+ uint16_t buf_size,
+ char *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_static_nvm_managed(
+ VL53L1_static_nvm_managed_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_customer_nvm_managed(
+ VL53L1_customer_nvm_managed_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_nvm_copy_data(
+ VL53L1_nvm_copy_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_histogram_bin_data(
+ VL53L1_histogram_bin_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_histogram_data(
+ VL53L1_xtalk_histogram_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_histogram_shape_data(
+ VL53L1_xtalk_histogram_shape_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_range_results(
+ VL53L1_range_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_range_data(
+ VL53L1_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_offset_range_results(
+ VL53L1_offset_range_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_offset_range_data(
+ VL53L1_offset_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_cal_peak_rate_map(
+ VL53L1_cal_peak_rate_map_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_additional_offset_cal_data(
+ VL53L1_additional_offset_cal_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_gain_calibration_data(
+ VL53L1_gain_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_zone_calibration_data(
+ VL53L1_zone_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_zone_calibration_results(
+ VL53L1_zone_calibration_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_range_results(
+ VL53L1_xtalk_range_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_range_data(
+ VL53L1_xtalk_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_calibration_results(
+ VL53L1_xtalk_calibration_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_config(
+ VL53L1_xtalk_config_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_dmax_calibration_data(
+ VL53L1_dmax_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_calibration_data(
+ VL53L1_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_debug_data(
+ VL53L1_xtalk_debug_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_offset_debug_data(
+ VL53L1_offset_debug_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_user_zone(
+ VL53L1_user_zone_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_zone_config(
+ VL53L1_zone_config_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_spad_rate_data(
+ VL53L1_spad_rate_data_t *pspad_rates,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_spad_rate_map(
+ VL53L1_spad_rate_data_t *pspad_rates,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_api_preset_modes.h b/drivers/input/misc/vl53L1/inc/vl53l1_api_preset_modes.h
new file mode 100644
index 000000000000..5ba58a97e79b
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_api_preset_modes.h
@@ -0,0 +1,1191 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_API_PRESET_MODES_H_
+#define _VL53L1_API_PRESET_MODES_H_
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_dmax_structs.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_refspadchar_config_struct(
+ VL53L1_refspadchar_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_ssc_config_struct(
+ VL53L1_ssc_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_xtalk_config_struct(
+ VL53L1_customer_nvm_managed_t *pnvm,
+ VL53L1_xtalk_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_hist_post_process_config_struct(
+ uint8_t xtalk_compensation_enable,
+ VL53L1_hist_post_process_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_dmax_calibration_data_struct(
+ VL53L1_dmax_calibration_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_hist_gen3_dmax_config_struct(
+ VL53L1_hist_gen3_dmax_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_short_range(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_long_range(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_mm1_cal(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_mm2_cal(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_timed_ranging(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_timed_ranging_short_range(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_timed_ranging_long_range(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_with_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_with_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_mm1_cal(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_mm2_cal(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_ref(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_characterisation(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_xtalk_planar(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_xtalk_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_xtalk_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_multizone(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_multizone_short_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_multizone_long_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_short_timing(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_long_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_medium_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_short_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_long_range_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_long_range_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_medium_range_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_medium_range_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_short_range_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_short_range_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_olt(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_singleshot_ranging(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_copy_hist_cfg_to_static_cfg(
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_copy_hist_bins_to_static_cfg(
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_timing_config_t *ptiming);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_api_strings.h b/drivers/input/misc/vl53L1/inc/vl53l1_api_strings.h
new file mode 100644
index 000000000000..24f12bc698d4
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_api_strings.h
@@ -0,0 +1,210 @@
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either
+* 'STMicroelectronics Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+/**
+ * @file vl53l1_api_strings.h
+ * @brief VL53L1 API function declarations for decoding error codes to a
+ * text strings
+ */
+
+
+#ifndef VL53L1_API_STRINGS_H_
+#define VL53L1_API_STRINGS_H_
+
+#include "vl53l1_def.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+/**
+ * @brief Generates a string for the input device range status code
+ *
+ * @param[in] RangeStatus : Device Range AStatus Code
+ * @param[out] pRangeStatusString : pointer to character buffer
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+
+VL53L1_Error VL53L1_get_range_status_string(
+ uint8_t RangeStatus,
+ char *pRangeStatusString);
+
+/**
+ * @brief Generates an error string for the input PAL error code
+ *
+ * @param[in] PalErrorCode : PAL Error Code
+ * @param[out] pPalErrorString : pointer to character buffer
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+
+VL53L1_Error VL53L1_get_pal_error_string(
+ VL53L1_Error PalErrorCode,
+ char *pPalErrorString);
+
+/**
+ * @brief Generates a string for the input PAL State code
+ *
+ * @param[in] PalStateCode : PAL State Code
+ * @param[out] pPalStateString : pointer to character buffer
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+
+VL53L1_Error VL53L1_get_pal_state_string(
+ VL53L1_State PalStateCode,
+ char *pPalStateString);
+
+
+/**
+ * @brief Generates a string for the sequence step Id
+ *
+ * @param[in] SequenceStepId : Sequence Step Id
+ * @param[out] pSequenceStepsString : pointer to character buffer
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_get_sequence_steps_info(
+ VL53L1_SequenceStepId SequenceStepId,
+ char *pSequenceStepsString);
+
+/**
+ * @brief Generates a string for the limit check Id
+ *
+ * @param[in] LimitCheckId : Limit check Id
+ * @param[out] pLimitCheckString : pointer to character buffer
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_get_limit_check_info(uint16_t LimitCheckId,
+ char *pLimitCheckString);
+
+#ifndef VL53L1_USE_EMPTY_STRING
+ #define VL53L1_STRING_DEVICE_INFO_NAME0 "VL53L1 cut1.0"
+ #define VL53L1_STRING_DEVICE_INFO_NAME1 "VL53L1 cut1.1"
+ #define VL53L1_STRING_DEVICE_INFO_TYPE "VL53L1"
+
+ /* Range Status */
+ #define VL53L1_STRING_RANGESTATUS_NONE "No Update"
+ #define VL53L1_STRING_RANGESTATUS_RANGEVALID "Range Valid"
+ #define VL53L1_STRING_RANGESTATUS_SIGMA "Sigma Fail"
+ #define VL53L1_STRING_RANGESTATUS_SIGNAL "Signal Fail"
+ #define VL53L1_STRING_RANGESTATUS_MINRANGE "Min Range Fail"
+ #define VL53L1_STRING_RANGESTATUS_PHASE "Phase Fail"
+ #define VL53L1_STRING_RANGESTATUS_HW "Hardware Fail"
+
+
+ /* Range Status */
+ #define VL53L1_STRING_STATE_POWERDOWN "POWERDOWN State"
+ #define VL53L1_STRING_STATE_WAIT_STATICINIT \
+ "Wait for staticinit State"
+ #define VL53L1_STRING_STATE_STANDBY "STANDBY State"
+ #define VL53L1_STRING_STATE_IDLE "IDLE State"
+ #define VL53L1_STRING_STATE_RUNNING "RUNNING State"
+ #define VL53L1_STRING_STATE_RESET "RESET State"
+ #define VL53L1_STRING_STATE_UNKNOWN "UNKNOWN State"
+ #define VL53L1_STRING_STATE_ERROR "ERROR State"
+
+
+
+ /* Check Enable */
+ #define VL53L1_STRING_CHECKENABLE_SIGMA_FINAL_RANGE \
+ "SIGMA FINAL RANGE"
+ #define VL53L1_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE \
+ "SIGNAL RATE FINAL RANGE"
+ #define VL53L1_STRING_CHECKENABLE_SIGNAL_MIN_CLIP \
+ "SIGNAL MIN CLIP"
+ #define VL53L1_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD \
+ "RANGE IGNORE THRESHOLD"
+ #define VL53L1_STRING_CHECKENABLE_RANGE_PHASE_HIGH \
+ "RANGE PHASE HIGH"
+ #define VL53L1_STRING_CHECKENABLE_RANGE_PHASE_LOW \
+ "RANGE PHASE LOW"
+ #define VL53L1_STRING_CHECKENABLE_RANGE_PHASE_CONSISTENCY \
+ "RANGE PHASE CONSISTENCY"
+
+ /* Sequence Step */
+ #define VL53L1_STRING_SEQUENCESTEP_VHV "VHV"
+ #define VL53L1_STRING_SEQUENCESTEP_PHASECAL "PHASE CAL"
+ #define VL53L1_STRING_SEQUENCESTEP_REFPHASE "REF PHASE"
+ #define VL53L1_STRING_SEQUENCESTEP_DSS1 "DSS1"
+ #define VL53L1_STRING_SEQUENCESTEP_DSS2 "DSS2"
+ #define VL53L1_STRING_SEQUENCESTEP_MM1 "MM1"
+ #define VL53L1_STRING_SEQUENCESTEP_MM2 "MM2"
+ #define VL53L1_STRING_SEQUENCESTEP_RANGE "RANGE"
+#endif /* VL53L1_USE_EMPTY_STRING */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_core.h b/drivers/input/misc/vl53L1/inc/vl53l1_core.h
new file mode 100644
index 000000000000..bc5e5ea2326c
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_core.h
@@ -0,0 +1,1513 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_CORE_H_
+#define _VL53L1_CORE_H_
+
+#include "vl53l1_platform.h"
+#include "vl53l1_core_support.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+void VL53L1_init_version(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+void VL53L1_init_ll_driver_state(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceState ll_state);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_update_ll_driver_rd_state(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_check_ll_driver_rd_state(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_update_ll_driver_cfg_state(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+void VL53L1_copy_rtn_good_spads_to_buffer(
+ VL53L1_nvm_copy_data_t *pdata,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_init_system_results(
+ VL53L1_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+void V53L1_init_zone_results_structure(
+ uint8_t active_zones,
+ VL53L1_zone_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_init_histogram_config_structure(
+ uint8_t even_bin0,
+ uint8_t even_bin1,
+ uint8_t even_bin2,
+ uint8_t even_bin3,
+ uint8_t even_bin4,
+ uint8_t even_bin5,
+ uint8_t odd_bin0,
+ uint8_t odd_bin1,
+ uint8_t odd_bin2,
+ uint8_t odd_bin3,
+ uint8_t odd_bin4,
+ uint8_t odd_bin5,
+ VL53L1_histogram_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_init_histogram_multizone_config_structure(
+ uint8_t even_bin0,
+ uint8_t even_bin1,
+ uint8_t even_bin2,
+ uint8_t even_bin3,
+ uint8_t even_bin4,
+ uint8_t even_bin5,
+ uint8_t odd_bin0,
+ uint8_t odd_bin1,
+ uint8_t odd_bin2,
+ uint8_t odd_bin3,
+ uint8_t odd_bin4,
+ uint8_t odd_bin5,
+ VL53L1_histogram_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_init_xtalk_bin_data_struct(
+ uint32_t bin_value,
+ uint16_t VL53L1_PRM_00017,
+ VL53L1_xtalk_histogram_shape_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_i2c_encode_uint16_t(
+ uint16_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint16_t VL53L1_i2c_decode_uint16_t(
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_i2c_encode_int16_t(
+ int16_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+int16_t VL53L1_i2c_decode_int16_t(
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_i2c_encode_uint32_t(
+ uint32_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_i2c_decode_uint32_t(
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_i2c_decode_with_mask(
+ uint16_t count,
+ uint8_t *pbuffer,
+ uint32_t bit_mask,
+ uint32_t down_shift,
+ uint32_t offset);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_i2c_encode_int32_t(
+ int32_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+int32_t VL53L1_i2c_decode_int32_t(
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_start_test(
+ VL53L1_DEV Dev,
+ uint8_t test_mode__ctrl);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_firmware_enable_register(
+ VL53L1_DEV Dev,
+ uint8_t value);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_enable_firmware(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_disable_firmware(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_powerforce_register(
+ VL53L1_DEV Dev,
+ uint8_t value);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_enable_powerforce(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_disable_powerforce(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_clear_interrupt(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_force_shadow_stream_count_to_zero(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_calc_macro_period_us(
+ uint16_t fast_osc_frequency,
+ uint8_t VL53L1_PRM_00007);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint16_t VL53L1_calc_range_ignore_threshold(
+ uint16_t central_rate,
+ int16_t x_gradient,
+ int16_t y_gradient,
+ uint8_t rate_mult);
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_calc_timeout_mclks(
+ uint32_t timeout_us,
+ uint32_t macro_period_us);
+
+
+
+
+
+
+
+
+
+
+
+
+uint16_t VL53L1_calc_encoded_timeout(
+ uint32_t timeout_us,
+ uint32_t macro_period_us);
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_calc_timeout_us(
+ uint32_t timeout_mclks,
+ uint32_t macro_period_us);
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_calc_decoded_timeout_us(
+ uint16_t timeout_encoded,
+ uint32_t macro_period_us);
+
+
+
+
+
+
+
+
+
+
+
+uint16_t VL53L1_encode_timeout(
+ uint32_t timeout_mclks);
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_decode_timeout(
+ uint16_t encoded_timeout);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+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);
+
+
+
+
+
+
+
+
+
+
+
+
+uint8_t VL53L1_encode_vcsel_period(
+ uint8_t VL53L1_PRM_00028);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_decode_unsigned_integer(
+ uint8_t *pbuffer,
+ uint8_t no_of_bytes);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_encode_unsigned_integer(
+ uint32_t ip_value,
+ uint8_t no_of_bytes,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_copy_and_scale_ambient_info(
+ VL53L1_zone_hist_info_t *pidata,
+ VL53L1_histogram_bin_data_t *podata);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_get_bin_sequence_config(
+ VL53L1_DEV Dev,
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_phase_consistency_check(
+ VL53L1_DEV Dev,
+ VL53L1_zone_hist_info_t *phist_prev,
+ VL53L1_histogram_bin_data_t *phist_curr,
+ VL53L1_zone_objects_t *prange_prev,
+ VL53L1_range_results_t *prange_curr);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_events_consistency_check(
+ VL53L1_DEV Dev,
+ uint8_t VL53L1_PRM_00001,
+ uint8_t p,
+ VL53L1_zone_hist_info_t *phist_prev,
+ VL53L1_histogram_bin_data_t *phist_curr,
+ VL53L1_zone_objects_t *prange_prev,
+ VL53L1_range_results_t *prange_curr,
+ int32_t *pevents_tolerance,
+ int32_t *pevents_delta,
+ VL53L1_DeviceError *prange_status);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_wrap_dmax(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_histogram_bin_data_t *pcurrent,
+ int16_t *pwrap_dmax_mm);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_combine_mm1_mm2_offsets(
+ int16_t mm1_offset_mm,
+ int16_t mm2_offset_mm,
+ uint8_t encoded_mm_roi_centre,
+ uint8_t encoded_mm_roi_size,
+ uint8_t encoded_zone_centre,
+ uint8_t encoded_zone_size,
+ VL53L1_additional_offset_cal_data_t *pcal_data,
+ uint8_t *pgood_spads,
+ uint16_t aperture_attenuation,
+ int16_t *prange_offset_mm);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_spad_number_to_byte_bit_index(
+ uint8_t spad_number,
+ uint8_t *pbyte_index,
+ uint8_t *pbit_index,
+ uint8_t *pbit_mask);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_encode_row_col(
+ uint8_t row,
+ uint8_t col,
+ uint8_t *pspad_number);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_decode_zone_size(
+ uint8_t encoded_xy_size,
+ uint8_t *pwidth,
+ uint8_t *pheight);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_encode_zone_size(
+ uint8_t width,
+ uint8_t height,
+ uint8_t *pencoded_xy_size);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+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);
+
+
+
+
+
+
+
+
+
+
+
+
+uint8_t VL53L1_is_aperture_location(
+ uint8_t row,
+ uint8_t col);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+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);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_copy_results_to_sys_and_core(
+ VL53L1_histogram_bin_data_t *pbins,
+ VL53L1_range_results_t *phist,
+ VL53L1_system_results_t *psys,
+ VL53L1_core_results_t *pcore);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_sum_histogram_data (
+ VL53L1_histogram_bin_data_t *phist_input,
+ VL53L1_histogram_bin_data_t *phist_output);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_avg_histogram_data (
+ uint8_t no_of_samples,
+ VL53L1_histogram_bin_data_t *phist_sum,
+ VL53L1_histogram_bin_data_t *phist_avg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_save_cfg_data(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_zone_update(
+ VL53L1_DEV Dev,
+ VL53L1_range_results_t *presults);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_update_internal_stream_counters(
+ VL53L1_DEV Dev,
+ uint8_t external_stream_count,
+ uint8_t *pinternal_stream_count,
+ uint8_t *pinternal_stream_count_val
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_multizone_hist_bins_update(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_histogram_multizone_initial_bin_config(
+ VL53L1_zone_config_t *pzone_cfg,
+ VL53L1_histogram_config_t *phist_cfg,
+ VL53L1_histogram_config_t *pmulti_hist
+ );
+
+
+
+
+
+
+
+
+
+uint8_t VL53L1_encode_GPIO_interrupt_config(
+ VL53L1_GPIO_interrupt_config_t *pintconf);
+
+
+
+
+
+
+
+
+
+VL53L1_GPIO_interrupt_config_t VL53L1_decode_GPIO_interrupt_config(
+ uint8_t system__interrupt_config);
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_distance_threshold(
+ VL53L1_DEV Dev,
+ uint16_t threshold_high,
+ uint16_t threshold_low);
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_rate_threshold(
+ VL53L1_DEV Dev,
+ uint16_t threshold_high,
+ uint16_t threshold_low);
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_thresholds_from_struct(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_interrupt_config_t *pintconf);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+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);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_ssc_config(
+ VL53L1_DEV Dev,
+ VL53L1_ssc_config_t *pssc_cfg,
+ uint16_t fast_osc_frequency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_spad_rate_data(
+ VL53L1_DEV Dev,
+ VL53L1_spad_rate_data_t *pspad_rates);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint16_t VL53L1_calc_crosstalk_plane_offset_with_margin(
+ uint16_t plane_offset_kcps,
+ int16_t margin_offset_kcps);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_core_support.h b/drivers/input/misc/vl53L1/inc/vl53l1_core_support.h
new file mode 100644
index 000000000000..e66c5ec97202
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_core_support.h
@@ -0,0 +1,410 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_CORE_SUPPORT_H_
+#define _VL53L1_CORE_SUPPORT_H_
+
+#include "vl53l1_types.h"
+#include "vl53l1_hist_structs.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_calc_pll_period_us(
+ uint16_t fast_osc_frequency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_duration_maths(
+ uint32_t pll_period_us,
+ uint32_t vcsel_parm_pclks,
+ uint32_t window_vclks,
+ uint32_t periods_elapsed_mclks);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_events_per_spad_maths(
+ int32_t VL53L1_PRM_00009,
+ uint16_t num_spads,
+ uint32_t duration);
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_isqrt(
+ uint32_t num);
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_calc_zero_distance_phase(
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_estimate_ambient_from_thresholded_bins(
+ int32_t ambient_threshold_sigma,
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_remove_ambient_bins(
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_calc_pll_period_mm(
+ uint16_t fast_osc_frequency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint16_t VL53L1_rate_maths(
+ int32_t VL53L1_PRM_00006,
+ uint32_t time_us);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint16_t VL53L1_rate_per_spad_maths(
+ uint32_t frac_bits,
+ uint32_t peak_count_rate,
+ uint16_t num_spads,
+ uint32_t max_output_value);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+int32_t VL53L1_range_maths(
+ uint16_t fast_osc_frequency,
+ uint16_t VL53L1_PRM_00013,
+ uint16_t zero_distance_phase,
+ int32_t gain_factor,
+ int32_t range_offset_mm);
+
+
+
+
+
+
+
+
+
+
+
+
+uint8_t VL53L1_decode_vcsel_period(
+ uint8_t vcsel_period_reg);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_copy_xtalk_bin_data_to_histogram_data_struct(
+ VL53L1_xtalk_histogram_shape_t *pxtalk,
+ VL53L1_histogram_bin_data_t *phist);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_init_histogram_bin_data_struct(
+ int32_t bin_value,
+ uint16_t VL53L1_PRM_00017,
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_decode_row_col(
+ uint8_t spad_number,
+ uint8_t *prow,
+ uint8_t *pcol);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_find_min_max_bin_values(
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_estimate_ambient_from_ambient_bins(
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_def.h b/drivers/input/misc/vl53L1/inc/vl53l1_def.h
new file mode 100644
index 000000000000..71e60165d9ce
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_def.h
@@ -0,0 +1,704 @@
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either
+* 'STMicroelectronics Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+/**
+ * @file vl53l1_def.h
+ *
+ * @brief Type definitions for VL53L1 API.
+ *
+ */
+
+
+#ifndef _VL53L1_DEF_H_
+#define _VL53L1_DEF_H_
+
+#include "vl53l1_ll_def.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @defgroup VL53L1_globaldefine_group VL53L1 Defines
+ * @brief VL53L1 Defines
+ * @{
+ */
+
+
+/** PAL SPECIFICATION major version */
+#define VL53L1_SPECIFICATION_VER_MAJOR 1
+/** PAL SPECIFICATION minor version */
+#define VL53L1_SPECIFICATION_VER_MINOR 2
+/** PAL SPECIFICATION sub version */
+#define VL53L1_SPECIFICATION_VER_SUB 7
+/** PAL SPECIFICATION sub version */
+#define VL53L1_SPECIFICATION_VER_REVISION 1440
+
+/** VL53L1 IMPLEMENTATION major version */
+#define VL53L1_IMPLEMENTATION_VER_MAJOR 4
+/** VL53L1 IMPLEMENTATION minor version */
+#define VL53L1_IMPLEMENTATION_VER_MINOR 1
+/** VL53L1 IMPLEMENTATION sub version */
+#define VL53L1_IMPLEMENTATION_VER_SUB 0
+/** VL53L1 IMPLEMENTATION sub version */
+#define VL53L1_IMPLEMENTATION_VER_REVISION 1249
+
+
+/****************************************
+ * PRIVATE define do not edit
+ ****************************************/
+
+/** @brief Defines the parameters of the Get Version Functions
+ */
+typedef struct {
+ uint32_t revision; /*!< revision number */
+ uint8_t major; /*!< major number */
+ uint8_t minor; /*!< minor number */
+ uint8_t build; /*!< build number */
+} VL53L1_Version_t;
+
+
+#define VL53L1_DEVINFO_STRLEN 32
+
+/** @brief Defines the parameters of the Get Device Info Functions
+ */
+typedef struct {
+ char Name[VL53L1_DEVINFO_STRLEN];
+ /*!< Name of the Device e.g. Left_Distance */
+ char Type[VL53L1_DEVINFO_STRLEN];
+ /*!< Type of the Device e.g VL53L1 */
+ char ProductId[VL53L1_DEVINFO_STRLEN];
+ /*!< Product Identifier String
+ * @warning Not yet implemented
+ */
+ uint8_t ProductType;
+ /*!< Product Type, VL53L1 = 1, VL53L1 = 2*/
+ uint8_t ProductRevisionMajor;
+ /*!< Product revision major */
+ uint8_t ProductRevisionMinor;
+ /*!< Product revision minor */
+} VL53L1_DeviceInfo_t;
+
+
+
+/** @defgroup VL53L1_define_PresetModes_group Defines Preset modes
+ * Defines all possible preset modes for the device
+ * @{
+ */
+typedef uint8_t VL53L1_PresetModes;
+
+#define VL53L1_PRESETMODE_RANGING ((VL53L1_PresetModes) 1)
+#define VL53L1_PRESETMODE_MULTIZONES_SCANNING ((VL53L1_PresetModes) 2)
+#define VL53L1_PRESETMODE_AUTONOMOUS ((VL53L1_PresetModes) 3)
+#define VL53L1_PRESETMODE_LITE_RANGING ((VL53L1_PresetModes) 4)
+#define VL53L1_PRESETMODE_OLT ((VL53L1_PresetModes) 7)
+
+ /* ... Modes to be added depending on device */
+/** @} VL53L1_define_PresetModes_group */
+
+
+/** @defgroup VL53L1_define_DistanceModes_group Defines Distance modes
+ * Defines all possible Distance modes for the device
+ * @{
+ */
+typedef uint8_t VL53L1_DistanceModes;
+
+#define VL53L1_DISTANCEMODE_SHORT ((VL53L1_DistanceModes) 1)
+#define VL53L1_DISTANCEMODE_MEDIUM ((VL53L1_DistanceModes) 2)
+#define VL53L1_DISTANCEMODE_LONG ((VL53L1_DistanceModes) 3)
+#define VL53L1_DISTANCEMODE_AUTO_LITE ((VL53L1_DistanceModes) 4)
+#define VL53L1_DISTANCEMODE_AUTO ((VL53L1_DistanceModes) 5)
+
+ /* ... Modes to be added depending on device */
+/** @} VL53L1_define_DistanceModes_group */
+
+/** @defgroup VL53L1_define_OutputModes_group Defines Output modes
+ * Defines all possible Output modes for the device
+ * @{
+ */
+typedef uint8_t VL53L1_OutputModes;
+
+#define VL53L1_OUTPUTMODE_NEAREST ((VL53L1_OutputModes) 1)
+#define VL53L1_OUTPUTMODE_STRONGEST ((VL53L1_OutputModes) 2)
+
+/** @} VL53L1_define_OutputModes_group */
+
+/** @defgroup VL53L1_define_OffsetCalibrationModes_group Defines Offset Calibration modes
+* Defines all possible Offset Calibration modes for the device
+* @{
+*/
+typedef uint8_t VL53L1_OffsetCalibrationModes;
+
+#define VL53L1_OFFSETCALIBRATIONMODE_STANDARD \
+ ((VL53L1_OffsetCalibrationModes) 1)
+#define VL53L1_OFFSETCALIBRATIONMODE_PRERANGE_ONLY \
+ ((VL53L1_OffsetCalibrationModes) 2)
+#define VL53L1_OFFSETCALIBRATIONMODE_MULTI_ZONE \
+ ((VL53L1_OffsetCalibrationModes) 3)
+
+/** @} VL53L1_define_OffsetCalibrationModes_group */
+
+/** @defgroup VL53L1_define_DeviceDmaxModes_group Defines Dmax source modes
+* Defines all possible sources for Dmax calibration for the device
+* @{
+*/
+typedef uint8_t VL53L1_DeviceDmaxModes;
+
+#define DMAXMODE_FMT_CAL_DATA ((VL53L1_DeviceDmaxModes) 1)
+#define DMAXMODE_CUSTCAL_DATA ((VL53L1_DeviceDmaxModes) 2)
+#define DMAXMODE_PER_ZONE_CAL_DATA ((VL53L1_DeviceDmaxModes) 3)
+
+/** @} VL53L1_define_DeviceDmaxModes_group */
+
+/** @defgroup VL53L1_define_OffsetCalibrationModesBD_group
+ * Device Offset Correction Mode
+ *
+ * @brief Defines all possible offset correction modes for the device
+ * @{
+ */
+typedef uint8_t VL53L1_OffsetCorrectionModes;
+
+#define VL53L1_OFFSETCORRECTIONMODE_STANDARD ((VL53L1_OffsetCorrectionMode) 1)
+#define VL53L1_OFFSETCORRECTIONMODE_PERZONE ((VL53L1_OffsetCorrectionMode) 2)
+
+/** @} VL53L1_define_OffsetCalibrationModesBD_group */
+
+
+/** @defgroup VL53L1_define_RoiStatus_group Defines Roi Status
+ * Defines the read status mode
+ * @{
+ */
+typedef uint8_t VL53L1_RoiStatus;
+
+#define VL53L1_ROISTATUS_NOT_VALID ((VL53L1_RoiStatus) 0)
+#define VL53L1_ROISTATUS_VALID_NOT_LAST ((VL53L1_RoiStatus) 1)
+#define VL53L1_ROISTATUS_VALID_LAST ((VL53L1_RoiStatus) 2)
+/** @} VL53L1_define_RoiStatus_group */
+
+
+/** @defgroup VL53L1_CheckEnable_group Check Enable list
+ * @brief Check Enable code
+ *
+ * Define used to specify the LimitCheckId.
+ * Use @a VL53L1_GetLimitCheckInfo() to get the string.
+ * @{
+ */
+
+#define VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE 0
+#define VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE 1
+
+#define VL53L1_CHECKENABLE_NUMBER_OF_CHECKS 2
+
+/** @} end of VL53L1_CheckEnable_group */
+
+
+/** @defgroup VL53L1_define_InterruptPolarity_group Defines the Polarity
+ * of the Interrupt
+ * Defines the Polarity of the Interrupt
+ * @{
+ */
+typedef uint8_t VL53L1_InterruptPolarity;
+
+#define VL53L1_INTERRUPTPOLARITY_LOW ((VL53L1_InterruptPolarity) 0)
+/*!< Set active low polarity best setup for falling edge. */
+#define VL53L1_INTERRUPTPOLARITY_HIGH ((VL53L1_InterruptPolarity) 1)
+/*!< Set active high polarity best setup for rising edge. */
+
+/** @} VL53L1_define_InterruptPolarity_group */
+
+/** @defgroup VL53L1_ThresholdMode_gropup Detection Functionality
+ * @brief Defines the different functionalities for the detection feature
+ * @{
+ */
+typedef uint8_t VL53L1_ThresholdMode;
+
+#define VL53L1_THRESHOLD_CROSSED_LOW \
+ ((VL53L1_ThresholdMode) 0)
+ /*!< Trigger interrupt if value < thresh_low */
+#define VL53L1_THRESHOLD_CROSSED_HIGH \
+ ((VL53L1_ThresholdMode) 1)
+ /*!< Trigger interrupt if value > thresh_high */
+#define VL53L1_THRESHOLD_OUT_OF_WINDOW \
+ ((VL53L1_ThresholdMode) 2)
+ /*!< Trigger interrupt if value < thresh_low OR value > thresh_high */
+#define VL53L1_THRESHOLD_IN_WINDOW \
+ ((VL53L1_ThresholdMode) 3)
+ /*!< Trigger interrupt if value > thresh_low AND value < thresh_high */
+
+/** @} end of VL53L1_ThresholdMode_gropup */
+
+/** @brief Defines parameters for Distance detection Thresholds configuration
+ */
+typedef struct {
+ VL53L1_ThresholdMode CrossMode; /*!< See #VL53L1_GpioThreshold */
+ uint16_t High; /*!< Distance threshold high limit in mm */
+ uint16_t Low; /*!< Distance threshold low limit in mm */
+} VL53L1_DistanceThreshold_t;
+
+/** @brief Defines parameters for Signal rate detection Thresholds configuration
+ */
+typedef struct {
+ VL53L1_ThresholdMode CrossMode; /*!< See #VL53L1_GpioThreshold */
+ FixPoint1616_t High; /*!< Signal rate threshold high limit */
+ FixPoint1616_t Low; /*!< Signal rate threshold low limit */
+} VL53L1_RateThreshold_t;
+
+/** @defgroup VL53L1_DetectionMode_group Gpio Functionality
+ * @brief Defines conditions leading to device's IT on GPIO
+ * @{
+ */
+typedef uint8_t VL53L1_DetectionMode;
+
+#define VL53L1_DETECTION_NORMAL_RUN \
+ ((VL53L1_DetectionMode) 0)
+ /*!< Trigger interrupt on new measurement regardless of threshold
+ * just like after a VL53L1_SetPresetMode() call
+ */
+#define VL53L1_DETECTION_DISTANCE_ONLY \
+ ((VL53L1_DetectionMode) 1)
+ /*!< Trigger interrupt if "threshold event" occurs on distance */
+#define VL53L1_DETECTION_RATE_ONLY \
+ ((VL53L1_DetectionMode) 2)
+ /*!< Trigger interrupt if "threshold event" occurs on signal rate */
+#define VL53L1_DETECTION_DISTANCE_AND_RATE \
+ ((VL53L1_DetectionMode) 3)
+ /*!< Trigger interrupt if "threshold event" occurs on distance AND rate
+ */
+#define VL53L1_DETECTION_DISTANCE_OR_RATE \
+ ((VL53L1_DetectionMode) 4)
+ /*!< Trigger interrupt if "threshold event" occurs on distance OR rate
+ */
+
+/** @} end of VL53L1_DetectionMode_group */
+
+/** @brief Defines parameters for User/object Detection configuration
+ */
+typedef struct {
+ VL53L1_DetectionMode DetectionMode;
+ /*!< See #VL53L1_GPIODetectionMode*/
+ uint8_t IntrNoTarget; /*!< 1 to trigger IT in case of no target found */
+ VL53L1_DistanceThreshold_t Distance; /*!< limits in mm */
+ VL53L1_RateThreshold_t Rate;/*!< limits in FixPoint1616_t */
+} VL53L1_DetectionConfig_t;
+
+
+/** @brief Defines all parameters for the device
+ */
+typedef struct {
+ VL53L1_PresetModes PresetMode;
+ /*!< Defines the operating mode to be used for the next measure */
+ VL53L1_OutputModes OutputMode;
+ /*!< Defines the Output mode to be used for the next measure */
+ VL53L1_DistanceModes DistanceMode;
+ /*!< Defines the operating mode to be used for the next measure */
+ VL53L1_DistanceModes InternalDistanceMode;
+ /*!< Defines the internal operating mode to be used for the next
+ * measure
+ */
+ VL53L1_DistanceModes NewDistanceMode;
+ /*!< Defines the new operating mode to be programmed for the next
+ * measure
+ */
+ uint32_t MeasurementTimingBudgetMicroSeconds;
+ /*!< Defines the allowed total time for a single measurement */
+ uint8_t LimitChecksEnable[VL53L1_CHECKENABLE_NUMBER_OF_CHECKS];
+ /*!< This Array store all the Limit Check enable for this device. */
+ uint8_t LimitChecksStatus[VL53L1_CHECKENABLE_NUMBER_OF_CHECKS];
+ /*!< This Array stores all the Status of the check linked to last
+ * measurement.
+ */
+ FixPoint1616_t LimitChecksValue[VL53L1_CHECKENABLE_NUMBER_OF_CHECKS];
+ /*!< This Array stores all the Limit Check value for this device */
+ FixPoint1616_t LimitChecksCurrent[VL53L1_CHECKENABLE_NUMBER_OF_CHECKS];
+ /*!< This Array stores all the Limit Check current value from latest
+ * ranging
+ */
+ uint8_t AmbientDmaxIndex;
+ /*!< This value stores the index of the ambient Dmax to take from
+ * ambient_dmax_mm[] table to populate ranging results
+ */
+} VL53L1_DeviceParameters_t;
+
+
+/** @defgroup VL53L1_define_State_group Defines the current status of the device
+ * Defines the current status of the device
+ * @{
+ */
+
+typedef uint8_t VL53L1_State;
+
+#define VL53L1_STATE_POWERDOWN ((VL53L1_State) 0)
+ /*!< Device is in HW reset */
+#define VL53L1_STATE_WAIT_STATICINIT ((VL53L1_State) 1)
+ /*!< Device is initialized and wait for static initialization */
+#define VL53L1_STATE_STANDBY ((VL53L1_State) 2)
+ /*!< Device is in Low power Standby mode */
+#define VL53L1_STATE_IDLE ((VL53L1_State) 3)
+ /*!< Device has been initialized and ready to do measurements */
+#define VL53L1_STATE_RUNNING ((VL53L1_State) 4)
+ /*!< Device is performing measurement */
+#define VL53L1_STATE_RESET ((VL53L1_State) 5)
+ /*!< Soft reset has been run on Device */
+#define VL53L1_STATE_UNKNOWN ((VL53L1_State) 98)
+ /*!< Device is in unknown state and need to be rebooted */
+#define VL53L1_STATE_ERROR ((VL53L1_State) 99)
+ /*!< Device is in error state and need to be rebooted */
+
+/** @} VL53L1_define_State_group */
+
+
+/**
+ * @struct VL53L1_SingleRangingData_t
+ * @brief Single Range measurement data.
+ */
+typedef struct {
+ uint32_t TimeStamp;
+ /*!< 32-bit time stamp.
+ * @warning Not yet implemented
+ */
+
+ uint8_t StreamCount; /*!< 8-bit Stream Count. */
+
+ uint8_t RangeQualityLevel;
+ /*!< indicate a quality level in percentage from 0 to 100
+ * @warning Not yet implemented
+ */
+
+ int16_t DmaxMilliMeter;
+ /*!< range Dmax distance in millimeter.
+ */
+
+ int16_t RangeMaxMilliMeter;
+ /*!< Tells what is the maximum detection distance of the object
+ * in current setup and environment conditions (Filled when
+ * applicable)
+ */
+
+ int16_t RangeMinMilliMeter;
+ /*!< Tells what is the minimum detection distance of the object
+ * in current setup and environment conditions (Filled when
+ * applicable)
+ */
+
+ FixPoint1616_t SignalRateRtnMegaCps;
+ /*!< Return signal rate (MCPS)\n these is a 16.16 fix point
+ * value, which is effectively a measure of target
+ * reflectance.
+ */
+
+ FixPoint1616_t AmbientRateRtnMegaCps;
+ /*!< Return ambient rate (MCPS)\n these is a 16.16 fix point
+ * value, which is effectively a measure of the ambien
+ * t light.
+ */
+
+ uint16_t EffectiveSpadRtnCount;
+ /*!< Return the effective SPAD count for the return signal.
+ * To obtain Real value it should be divided by 256
+ */
+
+ FixPoint1616_t SigmaMilliMeter;
+ /*!< Return the Sigma value in millimeter */
+
+ int16_t RangeMilliMeter;
+ /*!< range distance in millimeter. This should be between
+ * RangeMinMilliMeter and RangeMaxMilliMeter */
+
+ uint8_t RangeFractionalPart;
+ /*!< Fractional part of range distance. Final value is a
+ * RangeMilliMeter + RangeFractionalPart/256.
+ * @warning Not yet implemented
+ */
+
+ uint8_t RangeStatus;
+ /*!< Range Status for the current measurement. This is device
+ * dependent. Value = 0 means value is valid.
+ */
+} VL53L1_RangingMeasurementData_t;
+
+/**
+ * @struct VL53L1_ROIRangeResults_t
+ * @brief Structure for storing the set of range results for a single ROI
+ *
+ */
+typedef struct {
+
+ uint8_t RoiNumber;
+ /*!< Denotes on which ROI the range data is related to. */
+ uint8_t NumberOfObjectsFound;
+ /*!< Indicate the number of objects found in the current ROI.
+ * This is used to know how many ranging data should be get.
+ * NumberOfObjectsFound is in the range 0 to
+ * VL53L1_MAX_RANGE_RESULTS.
+ */
+ VL53L1_RoiStatus RoiStatus;
+ /*!< Indicate if the data read is valid or not or if this is
+ * the last valid data in the ROI.
+ */
+ VL53L1_RangingMeasurementData_t RangeData[VL53L1_MAX_RANGE_RESULTS];
+ /*!< Range data each target distance */
+
+} VL53L1_MultiRangingData_t;
+
+
+/** @brief Defines User Zone(ROI) parameters
+ *
+ */
+typedef struct {
+
+ uint8_t TopLeftX; /*!< Top Left x coordinate: 0-15 range */
+ uint8_t TopLeftY; /*!< Top Left y coordinate: 0-15 range */
+ uint8_t BotRightX; /*!< Bot Right x coordinate: 0-15 range */
+ uint8_t BotRightY; /*!< Bot Right x coordinate:0-15 range */
+
+} VL53L1_UserRoi_t;
+
+
+/** @brief Defines ROI configuration parameters
+ *
+ * Support up a max of 16 zones, Each Zone has the same size
+ *
+ */
+typedef struct {
+
+ uint8_t NumberOfRoi; /*!< Number of Rois defined*/
+
+ VL53L1_UserRoi_t UserRois[VL53L1_MAX_USER_ZONES];
+ /*!< List of Rois */
+
+} VL53L1_RoiConfig_t;
+
+
+
+/**
+ * @struct VL53L1_CalibrationData_t
+ * @brief Structure for storing the Calibration Data
+ *
+ */
+typedef VL53L1_calibration_data_t VL53L1_CalibrationData_t;
+
+
+/** @defgroup VL53L1_define_SequenceStepId_group Defines the SequenceStep
+ * Defines the the sequence steps performed during ranging..
+ * @{
+ */
+typedef uint8_t VL53L1_SequenceStepId;
+
+#define VL53L1_SEQUENCESTEP_VHV ((VL53L1_SequenceStepId) 0)
+/*!>2)&0xFFFF)
+#define VL53L1_FIXPOINT72TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<2)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT97(Value) \
+ (uint16_t)((Value>>9)&0xFFFF)
+#define VL53L1_FIXPOINT97TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<9)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT88(Value) \
+ (uint16_t)((Value>>8)&0xFFFF)
+#define VL53L1_FIXPOINT88TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<8)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT412(Value) \
+ (uint16_t)((Value>>4)&0xFFFF)
+#define VL53L1_FIXPOINT412TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<4)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT313(Value) \
+ (uint16_t)((Value>>3)&0xFFFF)
+#define VL53L1_FIXPOINT313TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<3)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT08(Value) \
+ (uint8_t)((Value>>8)&0x00FF)
+#define VL53L1_FIXPOINT08TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<8)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT53(Value) \
+ (uint8_t)((Value>>13)&0x00FF)
+#define VL53L1_FIXPOINT53TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<13)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT102(Value) \
+ (uint16_t)((Value>>14)&0x0FFF)
+#define VL53L1_FIXPOINT102TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<14)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT142(Value) \
+ (uint16_t)((Value>>14)&0xFFFF)
+#define VL53L1_FIXPOINT142TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<14)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT160(Value) \
+ (uint16_t)((Value>>16)&0xFFFF)
+#define VL53L1_FIXPOINT160TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)(Value<<16)
+
+#define VL53L1_MAKEUINT16(lsb, msb) (uint16_t)((((uint16_t)msb)<<8) + \
+ (uint16_t)lsb)
+
+#ifndef SUPPRESS_UNUSED_WARNING
+#define SUPPRESS_UNUSED_WARNING(x) ((void) (x))
+#endif
+
+/** @} VL53L1_define_GeneralMacro_group */
+
+
+/** @} VL53L1_globaldefine_group */
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _VL53L1_DEF_H_ */
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_dmax_structs.h b/drivers/input/misc/vl53L1/inc/vl53l1_dmax_structs.h
new file mode 100644
index 000000000000..5b77f4517feb
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_dmax_structs.h
@@ -0,0 +1,205 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_DMAX_STRUCTS_H_
+#define _VL53L1_DMAX_STRUCTS_H_
+
+#include "vl53l1_types.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+#define VL53L1_MAX_AMBIENT_DMAX_VALUES 5
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+
+ uint16_t ref__actual_effective_spads;
+
+
+ uint16_t ref__peak_signal_count_rate_mcps;
+
+
+ uint16_t ref__distance_mm;
+
+
+ uint16_t ref_reflectance_pc;
+
+
+
+
+
+
+ uint16_t coverglass_transmission;
+
+
+
+} VL53L1_dmax_calibration_data_t ;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+
+ uint8_t signal_thresh_sigma;
+
+
+ uint8_t ambient_thresh_sigma;
+
+
+ int32_t min_ambient_thresh_events;
+
+
+
+ uint16_t target_reflectance_for_dmax_calc[VL53L1_MAX_AMBIENT_DMAX_VALUES];
+
+
+ uint8_t estimated_spad_yield;
+
+
+
+
+
+
+ uint16_t dss_config__target_total_rate_mcps;
+
+
+ uint8_t dss_config__aperture_attenuation;
+
+
+
+} VL53L1_hist_gen3_dmax_config_t;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_error_codes.h b/drivers/input/misc/vl53L1/inc/vl53l1_error_codes.h
new file mode 100644
index 000000000000..dd197e9f0873
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_error_codes.h
@@ -0,0 +1,323 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_ERROR_CODES_H_
+#define _VL53L1_ERROR_CODES_H_
+
+#include "vl53l1_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef int8_t VL53L1_Error;
+
+#define VL53L1_ERROR_NONE ((VL53L1_Error) 0)
+#define VL53L1_ERROR_CALIBRATION_WARNING ((VL53L1_Error) - 1)
+
+
+
+
+
+#define VL53L1_ERROR_MIN_CLIPPED ((VL53L1_Error) - 2)
+
+
+
+#define VL53L1_ERROR_UNDEFINED ((VL53L1_Error) - 3)
+
+
+#define VL53L1_ERROR_INVALID_PARAMS ((VL53L1_Error) - 4)
+
+
+#define VL53L1_ERROR_NOT_SUPPORTED ((VL53L1_Error) - 5)
+
+
+#define VL53L1_ERROR_RANGE_ERROR ((VL53L1_Error) - 6)
+
+
+#define VL53L1_ERROR_TIME_OUT ((VL53L1_Error) - 7)
+
+
+#define VL53L1_ERROR_MODE_NOT_SUPPORTED ((VL53L1_Error) - 8)
+
+
+#define VL53L1_ERROR_BUFFER_TOO_SMALL ((VL53L1_Error) - 9)
+
+
+#define VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL ((VL53L1_Error) - 10)
+
+
+#define VL53L1_ERROR_GPIO_NOT_EXISTING ((VL53L1_Error) - 11)
+
+
+#define VL53L1_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED ((VL53L1_Error) - 12)
+
+
+#define VL53L1_ERROR_CONTROL_INTERFACE ((VL53L1_Error) - 13)
+
+
+#define VL53L1_ERROR_INVALID_COMMAND ((VL53L1_Error) - 14)
+
+
+
+#define VL53L1_ERROR_DIVISION_BY_ZERO ((VL53L1_Error) - 15)
+
+
+#define VL53L1_ERROR_REF_SPAD_INIT ((VL53L1_Error) - 16)
+
+
+#define VL53L1_ERROR_GPH_SYNC_CHECK_FAIL ((VL53L1_Error) - 17)
+
+
+#define VL53L1_ERROR_STREAM_COUNT_CHECK_FAIL ((VL53L1_Error) - 18)
+
+
+#define VL53L1_ERROR_GPH_ID_CHECK_FAIL ((VL53L1_Error) - 19)
+
+
+#define VL53L1_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL ((VL53L1_Error) - 20)
+
+
+#define VL53L1_ERROR_ZONE_GPH_ID_CHECK_FAIL ((VL53L1_Error) - 21)
+
+
+
+#define VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL ((VL53L1_Error) - 22)
+
+
+
+
+
+#define VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL ((VL53L1_Error) - 23)
+
+
+
+
+
+
+
+
+#define VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL ((VL53L1_Error) - 24)
+
+
+
+#define VL53L1_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL ((VL53L1_Error) - 25)
+
+
+
+
+#define VL53L1_ERROR_ZONE_CAL_NO_SAMPLE_FAIL ((VL53L1_Error) - 26)
+
+
+
+
+
+#define VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS ((VL53L1_Error) - 27)
+
+
+#define VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH ((VL53L1_Error) - 28)
+
+
+
+
+#define VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW ((VL53L1_Error) - 29)
+
+
+
+
+
+
+#define VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES ((VL53L1_Error) - 30)
+
+
+
+#define VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH ((VL53L1_Error) - 31)
+
+
+
+
+#define VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH ((VL53L1_Error) - 32)
+
+
+
+
+#define VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW ((VL53L1_Error) - 33)
+
+
+
+
+
+
+#define VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES ((VL53L1_Error) - 34)
+
+
+
+#define VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH ((VL53L1_Error) - 35)
+
+
+
+
+#define VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH ((VL53L1_Error) - 36)
+
+
+
+
+
+
+#define VL53L1_WARNING_XTALK_MISSING_SAMPLES ((VL53L1_Error) - 37)
+
+
+
+
+
+
+
+
+#define VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT ((VL53L1_Error) - 38)
+
+
+
+
+
+
+
+
+
+#define VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT ((VL53L1_Error) - 39)
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ERROR_NOT_IMPLEMENTED ((VL53L1_Error) - 40)
+
+
+
+#define VL53L1_ERROR_PLATFORM_SPECIFIC_START ((VL53L1_Error) - 60)
+
+
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_error_exceptions.h b/drivers/input/misc/vl53L1/inc/vl53l1_error_exceptions.h
new file mode 100644
index 000000000000..4fbd38b5d9a6
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_error_exceptions.h
@@ -0,0 +1,125 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_ERROR_EXCEPTIONS_H_
+#define _VL53L1_ERROR_EXCEPTIONS_H_
+
+#define IGNORE_DIVISION_BY_ZERO 0
+
+#define IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FAIL 0
+#define IGNORE_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL 0
+#define IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FOR_GRADIENT_WARN 0
+#define IGNORE_XTALK_EXTRACTION_SIGMA_LIMIT_FOR_GRADIENT_WARN 0
+#define IGNORE_XTALK_EXTRACTION_MISSING_SAMPLES_WARN 0
+
+#define IGNORE_REF_SPAD_CHAR_NOT_ENOUGH_SPADS 0
+#define IGNORE_REF_SPAD_CHAR_RATE_TOO_HIGH 0
+#define IGNORE_REF_SPAD_CHAR_RATE_TOO_LOW 0
+
+#define IGNORE_OFFSET_CAL_MISSING_SAMPLES 0
+#define IGNORE_OFFSET_CAL_SIGMA_TOO_HIGH 0
+#define IGNORE_OFFSET_CAL_RATE_TOO_HIGH 0
+#define IGNORE_OFFSET_CAL_SPAD_COUNT_TOO_LOW 0
+
+#define IGNORE_ZONE_CAL_MISSING_SAMPLES 0
+#define IGNORE_ZONE_CAL_SIGMA_TOO_HIGH 0
+#define IGNORE_ZONE_CAL_RATE_TOO_HIGH 0
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_error_strings.h b/drivers/input/misc/vl53L1/inc/vl53l1_error_strings.h
new file mode 100644
index 000000000000..5fd63d1f6e28
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_error_strings.h
@@ -0,0 +1,243 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef VL53L1_ERROR_STRINGS_H_
+#define VL53L1_ERROR_STRINGS_H_
+
+#include "vl53l1_error_codes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_pal_error_string(
+ VL53L1_Error PalErrorCode,
+ char *pPalErrorString);
+
+
+#ifndef VL53L1_USE_EMPTY_STRING
+
+
+
+ #define VL53L1_STRING_ERROR_NONE \
+ "No Error"
+ #define VL53L1_STRING_ERROR_CALIBRATION_WARNING \
+ "Calibration Warning Error"
+ #define VL53L1_STRING_ERROR_MIN_CLIPPED \
+ "Min clipped error"
+ #define VL53L1_STRING_ERROR_UNDEFINED \
+ "Undefined error"
+ #define VL53L1_STRING_ERROR_INVALID_PARAMS \
+ "Invalid parameters error"
+ #define VL53L1_STRING_ERROR_NOT_SUPPORTED \
+ "Not supported error"
+ #define VL53L1_STRING_ERROR_RANGE_ERROR \
+ "Range error"
+ #define VL53L1_STRING_ERROR_TIME_OUT \
+ "Time out error"
+ #define VL53L1_STRING_ERROR_MODE_NOT_SUPPORTED \
+ "Mode not supported error"
+ #define VL53L1_STRING_ERROR_BUFFER_TOO_SMALL \
+ "Buffer too small"
+ #define VL53L1_STRING_ERROR_COMMS_BUFFER_TOO_SMALL \
+ "Comms Buffer too small"
+ #define VL53L1_STRING_ERROR_GPIO_NOT_EXISTING \
+ "GPIO not existing"
+ #define VL53L1_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED \
+ "GPIO funct not supported"
+ #define VL53L1_STRING_ERROR_CONTROL_INTERFACE \
+ "Control Interface Error"
+ #define VL53L1_STRING_ERROR_INVALID_COMMAND \
+ "Invalid Command Error"
+ #define VL53L1_STRING_ERROR_DIVISION_BY_ZERO \
+ "Division by zero Error"
+ #define VL53L1_STRING_ERROR_REF_SPAD_INIT \
+ "Reference Spad Init Error"
+ #define VL53L1_STRING_ERROR_GPH_SYNC_CHECK_FAIL \
+ "GPH Sync Check Fail - API out of sync"
+ #define VL53L1_STRING_ERROR_STREAM_COUNT_CHECK_FAIL \
+ "Stream Count Check Fail - API out of sync"
+ #define VL53L1_STRING_ERROR_GPH_ID_CHECK_FAIL \
+ "GPH ID Check Fail - API out of sync"
+ #define VL53L1_STRING_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL \
+ "Zone Stream Count Check Fail - API out of sync"
+ #define VL53L1_STRING_ERROR_ZONE_GPH_ID_CHECK_FAIL \
+ "Zone GPH ID Check Fail - API out of sync"
+
+ #define VL53L1_STRING_ERROR_XTALK_EXTRACTION_NO_SAMPLES_FAIL \
+ "No Xtalk using full array - Xtalk Extract Fail"
+ #define VL53L1_STRING_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL \
+ "Xtalk does not meet required VL53L1_PRM_00012 limit - Xtalk Extract Fail"
+
+ #define VL53L1_STRING_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL \
+ "Offset Cal - one of more stages with no valid samples - fatal"
+ #define VL53L1_STRING_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL \
+ "Offset Cal - one of more stages with no SPADS enables - fatal"
+ #define VL53L1_STRING_ERROR_ZONE_CAL_NO_SAMPLE_FAIL \
+ "Zone Cal - one of more zones with no valid samples - fatal"
+
+ #define VL53L1_STRING_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS \
+ "Ref SPAD Char - Not Enough Good SPADs"
+ #define VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH \
+ "Ref SPAD Char - Final Ref Rate too high"
+ #define VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW \
+ "Ref SPAD Char - Final Ref Rate too low"
+
+ #define VL53L1_STRING_WARNING_OFFSET_CAL_MISSING_SAMPLES \
+ "Offset Cal - Less than the requested number of valid samples"
+ #define VL53L1_STRING_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH \
+ "Offset Cal - Sigma estimate value too high - offset not stable"
+ #define VL53L1_STRING_WARNING_OFFSET_CAL_RATE_TOO_HIGH \
+ "Offset Cal - Rate too high - in pile up"
+ #define VL53L1_STRING_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW \
+ "Offset Cal - Insufficient SPADs - offset may not be stable"
+
+ #define VL53L1_STRING_WARNING_ZONE_CAL_MISSING_SAMPLES \
+ "Zone Cal - One or more zone with less than requested valid samples"
+ #define VL53L1_STRING_WARNING_ZONE_CAL_SIGMA_TOO_HIGH \
+ "Zone Cal - One of more zones the VL53L1_PRM_00012 estimate too high"
+ #define VL53L1_STRING_WARNING_ZONE_CAL_RATE_TOO_HIGH \
+ "Zone Cal - One of more zones with rate too high - in pile up"
+
+ #define VL53L1_STRING_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT \
+ "Xtalk - Gradient sample num = 0"
+ #define VL53L1_STRING_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT \
+ "Xtalk - Gradient Sigma > Limit"
+ #define VL53L1_STRING_WARNING_XTALK_MISSING_SAMPLES \
+ "Xtalk - Some missing and invalid samples"
+
+ #define VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_OLD \
+ "Device Firmware too old"
+ #define VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_NEW \
+ "Device Firmware too new"
+ #define VL53L1_STRING_ERROR_UNIT_TEST_FAIL \
+ "Unit Test Fail"
+ #define VL53L1_STRING_ERROR_FILE_READ_FAIL \
+ "File Read Fail"
+ #define VL53L1_STRING_ERROR_FILE_WRITE_FAIL \
+ "File Write Fail"
+
+ #define VL53L1_STRING_ERROR_NOT_IMPLEMENTED \
+ "Not implemented error"
+ #define VL53L1_STRING_UNKNOW_ERROR_CODE \
+ "Unknown Error Code"
+
+#endif
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_fpga_core.h b/drivers/input/misc/vl53L1/inc/vl53l1_fpga_core.h
new file mode 100644
index 000000000000..e5d13a65bb9c
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_fpga_core.h
@@ -0,0 +1,134 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_FPGA_CORE_H_
+#define _VL53L1_FPGA_CORE_H_
+
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_is_firmware_ready_fpga(
+ VL53L1_DEV Dev,
+ uint8_t *pready);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_hist_char.h b/drivers/input/misc/vl53L1/inc/vl53l1_hist_char.h
new file mode 100644
index 000000000000..46ac93f42250
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_hist_char.h
@@ -0,0 +1,175 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_HIST_CHAR_H_
+#define _VL53L1_HIST_CHAR_H_
+
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_calib_config(
+ VL53L1_DEV Dev,
+ uint8_t vcsel_delay__a0,
+ uint8_t calib_1,
+ uint8_t calib_2,
+ uint8_t calib_3,
+ uint8_t calib_2__a0,
+ uint8_t spad_readout);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_hist_calib_pulse_delay(
+ VL53L1_DEV Dev,
+ uint8_t calib_delay);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_disable_calib_pulse_delay(
+ VL53L1_DEV Dev);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_hist_map.h b/drivers/input/misc/vl53L1/inc/vl53l1_hist_map.h
new file mode 100644
index 000000000000..514bc2cdec51
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_hist_map.h
@@ -0,0 +1,154 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_HIST_MAP_H_
+#define _VL53L1_HIST_MAP_H_
+
+#include "vl53l1_register_map.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+
+
+
+#define VL53L1_HISTOGRAM_CONFIG__OPCODE_SEQUENCE_0 \
+ VL53L1_SIGMA_ESTIMATOR__EFFECTIVE_PULSE_WIDTH_NS
+
+#define VL53L1_HISTOGRAM_CONFIG__OPCODE_SEQUENCE_1 \
+ VL53L1_SIGMA_ESTIMATOR__EFFECTIVE_AMBIENT_WIDTH_NS
+
+#define VL53L1_HISTOGRAM_CONFIG__OPCODE_SEQUENCE_2 \
+ VL53L1_SIGMA_ESTIMATOR__SIGMA_REF_MM
+
+#define VL53L1_HISTOGRAM_CONFIG__AMB_THRESH_HIGH \
+ VL53L1_ALGO__RANGE_IGNORE_THRESHOLD_MCPS
+
+
+
+
+
+#define VL53L1_RESULT__HISTOGRAM_BIN_0_2 0x008E
+#define VL53L1_RESULT__HISTOGRAM_BIN_0_1 0x008F
+#define VL53L1_RESULT__HISTOGRAM_BIN_0_0 0x0090
+
+#define VL53L1_RESULT__HISTOGRAM_BIN_23_2 0x00D3
+#define VL53L1_RESULT__HISTOGRAM_BIN_23_1 0x00D4
+#define VL53L1_RESULT__HISTOGRAM_BIN_23_0 0x00D5
+
+#define VL53L1_RESULT__HISTOGRAM_BIN_23_0_MSB 0x00D9
+#define VL53L1_RESULT__HISTOGRAM_BIN_23_0_LSB 0x00DA
+
+
+
+
+#define VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX \
+ VL53L1_RESULT__INTERRUPT_STATUS
+#define VL53L1_HISTOGRAM_BIN_DATA_I2C_SIZE_BYTES \
+ (VL53L1_RESULT__HISTOGRAM_BIN_23_0_LSB - VL53L1_RESULT__INTERRUPT_STATUS + 1)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_hist_structs.h b/drivers/input/misc/vl53L1/inc/vl53l1_hist_structs.h
new file mode 100644
index 000000000000..6c7c6925f0ca
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_hist_structs.h
@@ -0,0 +1,477 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_HIST_STRUCTS_H_
+#define _VL53L1_HIST_STRUCTS_H_
+
+#include "vl53l1_ll_device.h"
+#include "vl53l1_dmax_structs.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define VL53L1_MAX_BIN_SEQUENCE_LENGTH 6
+#define VL53L1_MAX_BIN_SEQUENCE_CODE 15
+#define VL53L1_HISTOGRAM_BUFFER_SIZE 24
+#define VL53L1_XTALK_HISTO_BINS 12
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t histogram_config__spad_array_selection;
+
+ uint8_t histogram_config__low_amb_even_bin_0_1;
+ uint8_t histogram_config__low_amb_even_bin_2_3;
+ uint8_t histogram_config__low_amb_even_bin_4_5;
+
+ uint8_t histogram_config__low_amb_odd_bin_0_1;
+ uint8_t histogram_config__low_amb_odd_bin_2_3;
+ uint8_t histogram_config__low_amb_odd_bin_4_5;
+
+ uint8_t histogram_config__mid_amb_even_bin_0_1;
+ uint8_t histogram_config__mid_amb_even_bin_2_3;
+ uint8_t histogram_config__mid_amb_even_bin_4_5;
+
+ uint8_t histogram_config__mid_amb_odd_bin_0_1;
+ uint8_t histogram_config__mid_amb_odd_bin_2;
+ uint8_t histogram_config__mid_amb_odd_bin_3_4;
+ uint8_t histogram_config__mid_amb_odd_bin_5;
+
+ uint8_t histogram_config__user_bin_offset;
+
+ uint8_t histogram_config__high_amb_even_bin_0_1;
+ uint8_t histogram_config__high_amb_even_bin_2_3;
+ uint8_t histogram_config__high_amb_even_bin_4_5;
+
+ uint8_t histogram_config__high_amb_odd_bin_0_1;
+ uint8_t histogram_config__high_amb_odd_bin_2_3;
+ uint8_t histogram_config__high_amb_odd_bin_4_5;
+
+ uint16_t histogram_config__amb_thresh_low;
+
+
+
+ uint16_t histogram_config__amb_thresh_high;
+
+
+
+
+} VL53L1_histogram_config_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_HistAlgoSelect hist_algo_select;
+
+
+
+ VL53L1_HistTargetOrder hist_target_order;
+
+
+
+
+
+ uint8_t filter_woi0;
+
+
+
+ uint8_t filter_woi1;
+
+
+
+
+ VL53L1_HistAmbEstMethod hist_amb_est_method;
+
+
+ uint8_t ambient_thresh_sigma0;
+
+
+
+ uint8_t ambient_thresh_sigma1;
+
+
+ int32_t min_ambient_thresh_events;
+
+
+ uint16_t noise_threshold;
+
+
+
+ int32_t signal_total_events_limit;
+
+
+ uint8_t sigma_estimator__sigma_ref_mm;
+
+
+ uint16_t sigma_thresh;
+
+
+ int16_t range_offset_mm;
+
+
+ uint16_t gain_factor;
+
+
+
+ uint8_t valid_phase_low;
+
+
+
+ uint8_t valid_phase_high;
+
+
+
+ uint8_t algo__consistency_check__phase_tolerance;
+
+
+
+ uint8_t algo__consistency_check__event_sigma;
+
+
+
+
+ uint8_t algo__crosstalk_compensation_enable;
+
+
+ uint16_t algo__crosstalk_compensation_plane_offset_kcps;
+
+
+ int16_t algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+ int16_t algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+ int16_t algo__crosstalk_detect_min_valid_range_mm;
+
+
+ int16_t algo__crosstalk_detect_max_valid_range_mm;
+
+
+ uint16_t algo__crosstalk_detect_max_valid_rate_kcps;
+
+
+
+ uint16_t algo__crosstalk_detect_max_sigma_mm;
+
+
+
+
+} VL53L1_hist_post_process_config_t;
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+ VL53L1_DeviceState cfg_device_state;
+
+
+ VL53L1_DeviceState rd_device_state;
+
+
+
+ uint8_t zone_id;
+
+
+ uint32_t time_stamp;
+
+
+
+ uint8_t VL53L1_PRM_00015;
+
+
+ uint8_t VL53L1_PRM_00016;
+
+
+ uint8_t VL53L1_PRM_00017;
+
+
+
+ uint8_t number_of_ambient_bins;
+
+
+
+ uint8_t bin_seq[VL53L1_MAX_BIN_SEQUENCE_LENGTH];
+
+
+ uint8_t bin_rep[VL53L1_MAX_BIN_SEQUENCE_LENGTH];
+
+
+
+
+ int32_t bin_data[VL53L1_HISTOGRAM_BUFFER_SIZE];
+
+
+
+ uint8_t result__interrupt_status;
+
+
+ uint8_t result__range_status;
+
+
+ uint8_t result__report_status;
+
+
+ uint8_t result__stream_count;
+
+
+ uint16_t result__dss_actual_effective_spads;
+
+
+
+ uint16_t phasecal_result__reference_phase;
+
+
+ uint8_t phasecal_result__vcsel_start;
+
+
+ uint8_t cal_config__vcsel_start;
+
+
+ uint16_t vcsel_width;
+
+
+ uint8_t VL53L1_PRM_00007;
+
+
+ uint16_t VL53L1_PRM_00018;
+
+
+ uint32_t total_periods_elapsed;
+
+
+
+ uint32_t peak_duration_us;
+
+
+ uint32_t woi_duration_us;
+
+
+
+ int32_t min_bin_value;
+
+
+ int32_t max_bin_value;
+
+
+
+ uint16_t zero_distance_phase;
+
+
+ uint8_t number_of_ambient_samples;
+
+
+ int32_t ambient_events_sum;
+
+
+ int32_t VL53L1_PRM_00026;
+
+
+
+ uint8_t roi_config__user_roi_centre_spad;
+
+
+ uint8_t roi_config__user_roi_requested_global_xy_size;
+
+
+
+} VL53L1_histogram_bin_data_t;
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+ uint8_t zone_id;
+
+
+ uint32_t time_stamp;
+
+
+
+ uint8_t VL53L1_PRM_00015;
+
+
+ uint8_t VL53L1_PRM_00016;
+
+
+ uint8_t VL53L1_PRM_00017;
+
+
+ uint32_t bin_data[VL53L1_XTALK_HISTO_BINS];
+
+
+
+
+ uint16_t phasecal_result__reference_phase;
+
+
+ uint8_t phasecal_result__vcsel_start;
+
+
+ uint8_t cal_config__vcsel_start;
+
+
+ uint16_t vcsel_width;
+
+
+ uint16_t VL53L1_PRM_00018;
+
+
+ uint16_t zero_distance_phase;
+
+
+
+} VL53L1_xtalk_histogram_shape_t;
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+ VL53L1_xtalk_histogram_shape_t xtalk_shape;
+
+
+ VL53L1_histogram_bin_data_t xtalk_hist_removed;
+
+} VL53L1_xtalk_histogram_data_t;
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_ll_def.h b/drivers/input/misc/vl53L1/inc/vl53l1_ll_def.h
new file mode 100644
index 000000000000..0b1c4275b3c4
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_ll_def.h
@@ -0,0 +1,1625 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_LL_DEF_H_
+#define _VL53L1_LL_DEF_H_
+
+#include "vl53l1_error_codes.h"
+#include "vl53l1_register_structs.h"
+#include "vl53l1_platform_user_config.h"
+#include "vl53l1_platform_user_defines.h"
+#include "vl53l1_hist_structs.h"
+#include "vl53l1_dmax_structs.h"
+#include "vl53l1_error_exceptions.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+#define VL53L1_LL_API_IMPLEMENTATION_VER_MAJOR 1
+
+
+#define VL53L1_LL_API_IMPLEMENTATION_VER_MINOR 1
+
+
+#define VL53L1_LL_API_IMPLEMENTATION_VER_SUB 16
+
+
+#define VL53L1_LL_API_IMPLEMENTATION_VER_REVISION 11634
+
+#define VL53L1_LL_API_IMPLEMENTATION_VER_STRING "1.1.16.11634"
+
+
+
+#define VL53L1_FIRMWARE_VER_MINIMUM 398
+#define VL53L1_FIRMWARE_VER_MAXIMUM 400
+
+
+
+
+
+
+
+#define VL53L1_LL_CALIBRATION_DATA_STRUCT_VERSION 0xECAB0101
+
+
+
+#define VL53L1_MAX_XTALK_RANGE_RESULTS 5
+
+
+
+
+
+
+#define VL53L1_MAX_OFFSET_RANGE_RESULTS 3
+
+
+
+
+
+#define VL53L1_NVM_MAX_FMT_RANGE_DATA 4
+
+
+
+#define VL53L1_NVM_PEAK_RATE_MAP_SAMPLES 25
+
+
+#define VL53L1_NVM_PEAK_RATE_MAP_WIDTH 5
+
+
+#define VL53L1_NVM_PEAK_RATE_MAP_HEIGHT 5
+
+
+
+
+
+
+
+
+
+#define VL53L1_ERROR_DEVICE_FIRMWARE_TOO_OLD ((VL53L1_Error) - 80)
+
+
+#define VL53L1_ERROR_DEVICE_FIRMWARE_TOO_NEW ((VL53L1_Error) - 85)
+
+
+#define VL53L1_ERROR_UNIT_TEST_FAIL ((VL53L1_Error) - 90)
+
+
+#define VL53L1_ERROR_FILE_READ_FAIL ((VL53L1_Error) - 95)
+
+
+#define VL53L1_ERROR_FILE_WRITE_FAIL ((VL53L1_Error) - 96)
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint32_t ll_revision;
+
+ uint8_t ll_major;
+
+ uint8_t ll_minor;
+
+ uint8_t ll_build;
+
+} VL53L1_ll_version_t;
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t device_test_mode;
+
+ uint8_t VL53L1_PRM_00007;
+
+ uint32_t timeout_us;
+
+ uint16_t target_count_rate_mcps;
+
+
+ uint16_t min_count_rate_limit_mcps;
+
+
+ uint16_t max_count_rate_limit_mcps;
+
+
+
+} VL53L1_refspadchar_config_t;
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_DeviceSscArray array_select;
+
+
+
+
+ uint8_t VL53L1_PRM_00007;
+
+
+ uint8_t vcsel_start;
+
+
+ uint8_t vcsel_width;
+
+
+ uint32_t timeout_us;
+
+
+ uint16_t rate_limit_mcps;
+
+
+
+
+
+} VL53L1_ssc_config_t;
+
+
+
+
+
+
+typedef struct {
+
+
+ uint16_t algo__crosstalk_compensation_plane_offset_kcps;
+
+
+ int16_t algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+ int16_t algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+ uint16_t nvm_default__crosstalk_compensation_plane_offset_kcps;
+
+
+ int16_t nvm_default__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+ int16_t nvm_default__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+ uint8_t global_crosstalk_compensation_enable;
+
+
+ int16_t histogram_mode_crosstalk_margin_kcps;
+
+
+
+
+
+
+ int16_t lite_mode_crosstalk_margin_kcps;
+
+
+
+
+
+
+ uint8_t crosstalk_range_ignore_threshold_mult;
+
+
+ uint16_t crosstalk_range_ignore_threshold_rate_mcps;
+
+
+
+
+ int16_t algo__crosstalk_detect_min_valid_range_mm;
+
+
+ int16_t algo__crosstalk_detect_max_valid_range_mm;
+
+
+ uint16_t algo__crosstalk_detect_max_valid_rate_kcps;
+
+
+
+ uint16_t algo__crosstalk_detect_max_sigma_mm;
+
+
+
+
+
+} VL53L1_xtalk_config_t;
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t x_centre;
+
+ uint8_t y_centre;
+
+ uint8_t width;
+
+ uint8_t height;
+
+
+} VL53L1_user_zone_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t max_zones;
+
+ uint8_t active_zones;
+
+
+
+
+
+
+
+
+
+VL53L1_histogram_config_t multizone_hist_cfg;
+
+ VL53L1_user_zone_t user_zones[VL53L1_MAX_USER_ZONES];
+
+
+
+ uint8_t bin_config[VL53L1_MAX_USER_ZONES];
+
+
+
+} VL53L1_zone_config_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+ VL53L1_GPIO_Interrupt_Mode intr_mode_distance;
+
+
+
+ VL53L1_GPIO_Interrupt_Mode intr_mode_rate;
+
+
+
+
+
+ uint8_t intr_new_measure_ready;
+
+
+
+ uint8_t intr_no_target;
+
+
+
+
+
+
+ uint8_t intr_combined_mode;
+
+
+
+
+
+
+
+
+
+
+ uint16_t threshold_distance_high;
+
+
+
+ uint16_t threshold_distance_low;
+
+
+
+ uint16_t threshold_rate_high;
+
+
+
+ uint16_t threshold_rate_low;
+
+} VL53L1_GPIO_interrupt_config_t;
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+
+ uint8_t range_id;
+
+
+ uint32_t time_stamp;
+
+
+ uint8_t VL53L1_PRM_00010;
+
+
+ uint8_t VL53L1_PRM_00015;
+
+
+ uint8_t VL53L1_PRM_00019;
+
+
+ uint8_t VL53L1_PRM_00020;
+
+
+ uint8_t VL53L1_PRM_00011;
+
+
+ uint8_t VL53L1_PRM_00021;
+
+
+
+ uint16_t width;
+
+
+ uint8_t VL53L1_PRM_00027;
+
+
+
+
+ uint16_t fast_osc_frequency;
+
+
+ uint16_t zero_distance_phase;
+
+
+ uint16_t VL53L1_PRM_00003;
+
+
+
+ uint32_t total_periods_elapsed;
+
+
+
+ uint32_t peak_duration_us;
+
+
+
+ uint32_t woi_duration_us;
+
+
+
+
+
+
+
+ uint32_t VL53L1_PRM_00023;
+
+
+ uint32_t VL53L1_PRM_00022;
+
+
+
+ int32_t VL53L1_PRM_00009;
+
+
+
+
+
+
+
+ uint16_t peak_signal_count_rate_mcps;
+
+
+ uint16_t avg_signal_count_rate_mcps;
+
+
+ uint16_t ambient_count_rate_mcps;
+
+
+ uint16_t total_rate_per_spad_mcps;
+
+
+ uint32_t VL53L1_PRM_00008;
+
+
+
+
+
+
+ uint16_t VL53L1_PRM_00004;
+
+
+
+
+
+
+ uint16_t VL53L1_PRM_00024;
+
+
+
+ uint16_t VL53L1_PRM_00014;
+
+
+ uint16_t VL53L1_PRM_00025;
+
+
+
+
+
+
+
+ int16_t min_range_mm;
+
+
+
+
+
+ int16_t median_range_mm;
+
+
+
+
+ int16_t max_range_mm;
+
+
+
+
+
+
+
+
+
+ uint8_t range_status;
+
+} VL53L1_range_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_DeviceState cfg_device_state;
+
+
+ VL53L1_DeviceState rd_device_state;
+
+
+ uint8_t zone_id;
+
+
+ uint8_t stream_count;
+
+
+
+ int16_t ambient_dmax_mm[VL53L1_MAX_AMBIENT_DMAX_VALUES];
+
+
+
+
+ int16_t wrap_dmax_mm;
+
+
+
+ uint8_t max_results;
+
+
+
+ uint8_t active_results;
+
+
+ VL53L1_range_data_t VL53L1_PRM_00005[VL53L1_MAX_RANGE_RESULTS];
+
+
+
+
+} VL53L1_range_results_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t no_of_samples;
+
+
+ uint32_t rate_per_spad_kcps_sum;
+
+
+
+ uint32_t rate_per_spad_kcps_avg;
+
+
+ int32_t signal_total_events_sum;
+
+
+
+ int32_t signal_total_events_avg;
+
+
+
+ uint32_t sigma_mm_sum;
+
+
+
+ uint32_t sigma_mm_avg;
+
+
+
+} VL53L1_xtalk_range_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_Error cal_status;
+
+
+ uint8_t num_of_samples_status;
+
+
+
+
+
+
+
+
+ uint8_t zero_samples_status;
+
+
+
+
+
+
+
+
+ uint8_t max_sigma_status;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t max_results;
+
+
+
+ uint8_t active_results;
+
+
+
+ VL53L1_xtalk_range_data_t VL53L1_PRM_00005[VL53L1_MAX_XTALK_RANGE_RESULTS];
+
+
+ VL53L1_histogram_bin_data_t central_histogram_sum;
+
+
+
+ VL53L1_histogram_bin_data_t central_histogram_avg;
+
+
+
+ uint8_t central_histogram__window_start;
+
+
+
+ uint8_t central_histogram__window_end;
+
+
+
+ VL53L1_histogram_bin_data_t histogram_avg_1[VL53L1_MAX_XTALK_RANGE_RESULTS];
+
+
+
+ VL53L1_histogram_bin_data_t histogram_avg_2[VL53L1_MAX_XTALK_RANGE_RESULTS];
+
+
+
+ VL53L1_histogram_bin_data_t xtalk_avg[VL53L1_MAX_XTALK_RANGE_RESULTS];
+
+
+
+
+} VL53L1_xtalk_range_results_t;
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t preset_mode;
+
+
+ uint8_t dss_config__roi_mode_control;
+
+
+ uint16_t dss_config__manual_effective_spads_select;
+
+
+ uint8_t no_of_samples;
+
+
+ uint32_t effective_spads;
+
+
+ uint32_t peak_rate_mcps;
+
+
+ uint32_t VL53L1_PRM_00004;
+
+
+ int32_t median_range_mm;
+
+
+
+ int32_t range_mm_offset;
+
+
+
+} VL53L1_offset_range_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ int16_t cal_distance_mm;
+
+
+ uint16_t cal_reflectance_pc;
+
+
+ VL53L1_Error cal_status;
+
+
+ uint8_t cal_report;
+
+
+ uint8_t max_results;
+
+
+
+ uint8_t active_results;
+
+
+ VL53L1_offset_range_data_t VL53L1_PRM_00005[VL53L1_MAX_OFFSET_RANGE_RESULTS];
+
+
+
+} VL53L1_offset_range_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint16_t result__mm_inner_actual_effective_spads;
+
+
+ uint16_t result__mm_outer_actual_effective_spads;
+
+
+ uint16_t result__mm_inner_peak_signal_count_rtn_mcps;
+
+
+ uint16_t result__mm_outer_peak_signal_count_rtn_mcps;
+
+
+
+} VL53L1_additional_offset_cal_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint32_t VL53L1_PRM_00023;
+
+
+ uint32_t VL53L1_PRM_00022;
+
+
+
+ uint16_t VL53L1_PRM_00014;
+
+
+
+} VL53L1_object_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_DeviceState cfg_device_state;
+
+
+ VL53L1_DeviceState rd_device_state;
+
+
+ uint8_t zone_id;
+
+
+ uint8_t stream_count;
+
+
+
+ uint8_t max_objects;
+
+
+
+ uint8_t active_objects;
+
+
+ VL53L1_object_data_t VL53L1_PRM_00005[VL53L1_MAX_RANGE_RESULTS];
+
+
+
+} VL53L1_zone_objects_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t max_zones;
+
+
+
+ uint8_t active_zones;
+
+
+ VL53L1_zone_objects_t VL53L1_PRM_00005[VL53L1_MAX_USER_ZONES];
+
+
+
+} VL53L1_zone_results_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_DeviceState rd_device_state;
+
+
+
+ uint8_t number_of_ambient_bins;
+
+
+
+
+ uint16_t result__dss_actual_effective_spads;
+
+
+ uint8_t VL53L1_PRM_00007;
+
+
+ uint32_t total_periods_elapsed;
+
+
+
+ int32_t ambient_events_sum;
+
+
+
+} VL53L1_zone_hist_info_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t max_zones;
+
+
+
+ uint8_t active_zones;
+
+
+ VL53L1_zone_hist_info_t VL53L1_PRM_00005[VL53L1_MAX_USER_ZONES];
+
+
+
+} VL53L1_zone_histograms_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint32_t no_of_samples;
+
+
+ uint32_t effective_spads;
+
+
+ uint32_t peak_rate_mcps;
+
+
+ uint32_t VL53L1_PRM_00014;
+
+
+ uint32_t VL53L1_PRM_00004;
+
+
+
+ int32_t median_range_mm;
+
+
+
+ int32_t range_mm_offset;
+
+
+
+} VL53L1_zone_calibration_data_t;
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_DevicePresetModes preset_mode;
+
+
+ VL53L1_DeviceZonePreset zone_preset;
+
+
+ int16_t cal_distance_mm;
+
+
+ uint16_t cal_reflectance_pc;
+
+
+ uint16_t phasecal_result__reference_phase;
+
+
+ uint16_t zero_distance_phase;
+
+
+ VL53L1_Error cal_status;
+
+
+ uint8_t max_zones;
+
+
+
+ uint8_t active_zones;
+
+
+ VL53L1_zone_calibration_data_t VL53L1_PRM_00005[VL53L1_MAX_USER_ZONES];
+
+
+
+} VL53L1_zone_calibration_results_t;
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ int16_t cal_distance_mm;
+
+
+ uint16_t cal_reflectance_pc;
+
+
+ uint16_t max_samples;
+
+
+ uint16_t width;
+
+
+ uint16_t height;
+
+
+ uint16_t peak_rate_mcps[VL53L1_NVM_PEAK_RATE_MAP_SAMPLES];
+
+
+
+} VL53L1_cal_peak_rate_map_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t expected_stream_count;
+
+
+ uint8_t expected_gph_id;
+
+
+ uint8_t dss_mode;
+
+
+ uint16_t dss_requested_effective_spad_count;
+
+
+
+ uint8_t seed_cfg;
+
+
+ uint8_t initial_phase_seed;
+
+
+
+ uint8_t roi_config__user_roi_centre_spad;
+
+
+ uint8_t roi_config__user_roi_requested_global_xy_size;
+
+
+
+} VL53L1_zone_private_dyn_cfg_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t max_zones;
+
+
+
+ uint8_t active_zones;
+
+
+ VL53L1_zone_private_dyn_cfg_t VL53L1_PRM_00005[VL53L1_MAX_USER_ZONES];
+
+
+
+} VL53L1_zone_private_dyn_cfgs_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint16_t algo__crosstalk_compensation_plane_offset_kcps;
+
+
+ int16_t algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+ int16_t algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+} VL53L1_xtalk_calibration_results_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint16_t standard_ranging_gain_factor;
+
+
+ uint16_t histogram_ranging_gain_factor;
+
+
+
+} VL53L1_gain_calibration_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_DeviceState cfg_device_state;
+
+
+ uint8_t cfg_stream_count;
+
+
+
+ uint8_t cfg_internal_stream_count;
+
+
+ uint8_t cfg_internal_stream_count_val;
+
+
+ uint8_t cfg_gph_id;
+
+
+ uint8_t cfg_timing_status;
+
+
+ uint8_t cfg_zone_id;
+
+
+
+ VL53L1_DeviceState rd_device_state;
+
+
+ uint8_t rd_stream_count;
+
+
+ uint8_t rd_internal_stream_count;
+
+
+ uint8_t rd_internal_stream_count_val;
+
+
+ uint8_t rd_gph_id;
+
+
+ uint8_t rd_timing_status;
+
+
+ uint8_t rd_zone_id;
+
+
+
+} VL53L1_ll_driver_state_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t wait_method;
+
+
+ VL53L1_DevicePresetModes preset_mode;
+
+
+ VL53L1_DeviceZonePreset zone_preset;
+
+
+ VL53L1_DeviceMeasurementModes measurement_mode;
+
+
+ VL53L1_OffsetCalibrationMode offset_calibration_mode;
+
+
+ VL53L1_OffsetCorrectionMode offset_correction_mode;
+
+
+ VL53L1_DeviceDmaxMode dmax_mode;
+
+
+ uint32_t phasecal_config_timeout_us;
+
+
+ uint32_t mm_config_timeout_us;
+
+
+ uint32_t range_config_timeout_us;
+
+
+ uint32_t inter_measurement_period_ms;
+
+
+ uint32_t fw_ready_poll_duration_ms;
+
+
+ uint8_t fw_ready;
+
+
+ uint8_t debug_mode;
+
+
+ uint8_t fpga_system;
+
+
+
+
+
+ VL53L1_ll_version_t version;
+
+
+
+ VL53L1_ll_driver_state_t ll_state;
+
+
+
+ VL53L1_GPIO_interrupt_config_t gpio_interrupt_config;
+
+
+
+ VL53L1_customer_nvm_managed_t customer;
+ VL53L1_cal_peak_rate_map_t cal_peak_rate_map;
+ VL53L1_additional_offset_cal_data_t add_off_cal_data;
+ VL53L1_dmax_calibration_data_t fmt_dmax_cal;
+ VL53L1_dmax_calibration_data_t cust_dmax_cal;
+ VL53L1_gain_calibration_data_t gain_cal;
+ VL53L1_user_zone_t mm_roi;
+ VL53L1_zone_config_t zone_cfg;
+
+
+
+ uint8_t rtn_good_spads[VL53L1_RTN_SPAD_BUFFER_SIZE];
+
+
+
+ VL53L1_refspadchar_config_t refspadchar;
+ VL53L1_ssc_config_t ssc_cfg;
+ VL53L1_hist_post_process_config_t histpostprocess;
+ VL53L1_hist_gen3_dmax_config_t dmax_cfg;
+ VL53L1_xtalk_config_t xtalk_cfg;
+
+
+
+ VL53L1_static_nvm_managed_t stat_nvm;
+ VL53L1_histogram_config_t hist_cfg;
+ VL53L1_static_config_t stat_cfg;
+ VL53L1_general_config_t gen_cfg;
+ VL53L1_timing_config_t tim_cfg;
+ VL53L1_dynamic_config_t dyn_cfg;
+ VL53L1_system_control_t sys_ctrl;
+ VL53L1_system_results_t sys_results;
+ VL53L1_nvm_copy_data_t nvm_copy_data;
+
+
+
+ VL53L1_histogram_bin_data_t hist_data;
+ VL53L1_histogram_bin_data_t hist_xtalk;
+
+
+
+ VL53L1_xtalk_histogram_data_t xtalk_shapes;
+ VL53L1_xtalk_range_results_t xtalk_results;
+ VL53L1_xtalk_calibration_results_t xtalk_cal;
+
+
+
+ VL53L1_offset_range_results_t offset_results;
+
+
+
+ VL53L1_core_results_t core_results;
+ VL53L1_debug_results_t dbg_results;
+
+#ifdef PAL_EXTENDED
+
+
+ VL53L1_patch_results_t patch_results;
+ VL53L1_shadow_core_results_t shadow_core_results;
+ VL53L1_shadow_system_results_t shadow_sys_results;
+ VL53L1_prev_shadow_core_results_t prev_shadow_core_results;
+ VL53L1_prev_shadow_system_results_t prev_shadow_sys_results;
+#endif
+
+} VL53L1_LLDriverData_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+ VL53L1_range_results_t range_results;
+
+
+
+ VL53L1_zone_private_dyn_cfgs_t zone_dyn_cfgs;
+
+
+
+ VL53L1_zone_results_t zone_results;
+ VL53L1_zone_histograms_t zone_hists;
+ VL53L1_zone_calibration_results_t zone_cal;
+
+} VL53L1_LLDriverResults_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint32_t struct_version;
+ VL53L1_customer_nvm_managed_t customer;
+ VL53L1_dmax_calibration_data_t fmt_dmax_cal;
+ VL53L1_dmax_calibration_data_t cust_dmax_cal;
+ VL53L1_additional_offset_cal_data_t add_off_cal_data;
+ VL53L1_user_zone_t mm_roi;
+ VL53L1_xtalk_histogram_data_t xtalkhisto;
+ VL53L1_gain_calibration_data_t gain_cal;
+ VL53L1_cal_peak_rate_map_t cal_peak_rate_map;
+
+} VL53L1_calibration_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_customer_nvm_managed_t customer;
+ VL53L1_xtalk_config_t xtalk_cfg;
+ VL53L1_histogram_bin_data_t hist_data;
+ VL53L1_xtalk_histogram_data_t xtalk_shapes;
+ VL53L1_xtalk_range_results_t xtalk_results;
+
+} VL53L1_xtalk_debug_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_customer_nvm_managed_t customer;
+ VL53L1_dmax_calibration_data_t fmt_dmax_cal;
+ VL53L1_dmax_calibration_data_t cust_dmax_cal;
+ VL53L1_additional_offset_cal_data_t add_off_cal_data;
+ VL53L1_offset_range_results_t offset_results;
+
+} VL53L1_offset_debug_data_t;
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint16_t target_reflectance_for_dmax[VL53L1_MAX_AMBIENT_DMAX_VALUES];
+
+} VL53L1_dmax_reflectance_array_t;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t spad_type;
+
+
+ uint16_t VL53L1_PRM_00016;
+
+
+ uint16_t rate_data[VL53L1_NO_OF_SPAD_ENABLES];
+
+
+ uint16_t no_of_values;
+
+
+ uint8_t fractional_bits;
+
+
+ uint8_t error_status;
+
+
+
+} VL53L1_spad_rate_data_t;
+
+
+
+
+
+#define SUPPRESS_UNUSED_WARNING(x) \
+ ((void) (x))
+
+
+#define IGNORE_STATUS(__FUNCTION_ID__, __ERROR_STATUS_CHECK__, __STATUS__) \
+ do { \
+ DISABLE_WARNINGS(); \
+ if (__FUNCTION_ID__) { \
+ if (__STATUS__ == __ERROR_STATUS_CHECK__) { \
+ __STATUS__ = VL53L1_ERROR_NONE; \
+ WARN_OVERRIDE_STATUS(__FUNCTION_ID__); \
+ } \
+ } \
+ ENABLE_WARNINGS(); \
+ } \
+ while (0)
+
+#define VL53L1_COPYSTRING(str, ...) \
+ (strncpy(str, ##__VA_ARGS__, VL53L1_MAX_STRING_LENGTH-1))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_ll_device.h b/drivers/input/misc/vl53L1/inc/vl53l1_ll_device.h
new file mode 100644
index 000000000000..a7990f49dd01
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_ll_device.h
@@ -0,0 +1,843 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_LL_DEVICE_H_
+#define _VL53L1_LL_DEVICE_H_
+
+#include "vl53l1_types.h"
+
+#define VL53L1_I2C 0x01
+#define VL53L1_SPI 0x00
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_WaitMethod;
+
+#define VL53L1_WAIT_METHOD_BLOCKING ((VL53L1_WaitMethod) 0)
+#define VL53L1_WAIT_METHOD_NON_BLOCKING ((VL53L1_WaitMethod) 1)
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceState;
+
+#define VL53L1_DEVICESTATE_POWERDOWN ((VL53L1_DeviceState) 0)
+#define VL53L1_DEVICESTATE_HW_STANDBY ((VL53L1_DeviceState) 1)
+#define VL53L1_DEVICESTATE_FW_COLDBOOT ((VL53L1_DeviceState) 2)
+#define VL53L1_DEVICESTATE_SW_STANDBY ((VL53L1_DeviceState) 3)
+#define VL53L1_DEVICESTATE_RANGING_DSS_AUTO ((VL53L1_DeviceState) 4)
+#define VL53L1_DEVICESTATE_RANGING_DSS_MANUAL ((VL53L1_DeviceState) 5)
+#define VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC ((VL53L1_DeviceState) 6)
+#define VL53L1_DEVICESTATE_RANGING_GATHER_DATA ((VL53L1_DeviceState) 7)
+#define VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA ((VL53L1_DeviceState) 8)
+
+#define VL53L1_DEVICESTATE_UNKNOWN ((VL53L1_DeviceState) 98)
+#define VL53L1_DEVICESTATE_ERROR ((VL53L1_DeviceState) 99)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceZonePreset;
+
+#define VL53L1_DEVICEZONEPRESET_NONE ((VL53L1_DeviceZonePreset) 0)
+
+#define VL53L1_DEVICEZONEPRESET_XTALK_PLANAR ((VL53L1_DeviceZonePreset) 1)
+#define VL53L1_DEVICEZONEPRESET_1X1_SIZE_16X16 ((VL53L1_DeviceZonePreset) 2)
+#define VL53L1_DEVICEZONEPRESET_1X2_SIZE_16X8 ((VL53L1_DeviceZonePreset) 3)
+#define VL53L1_DEVICEZONEPRESET_2X1_SIZE_8X16 ((VL53L1_DeviceZonePreset) 4)
+#define VL53L1_DEVICEZONEPRESET_2X2_SIZE_8X8 ((VL53L1_DeviceZonePreset) 5)
+#define VL53L1_DEVICEZONEPRESET_3X3_SIZE_5X5 ((VL53L1_DeviceZonePreset) 6)
+#define VL53L1_DEVICEZONEPRESET_4X4_SIZE_4X4 ((VL53L1_DeviceZonePreset) 7)
+#define VL53L1_DEVICEZONEPRESET_5X5_SIZE_4X4 ((VL53L1_DeviceZonePreset) 8)
+#define VL53L1_DEVICEZONEPRESET_11X11_SIZE_5X5 ((VL53L1_DeviceZonePreset) 9)
+#define VL53L1_DEVICEZONEPRESET_13X13_SIZE_4X4 ((VL53L1_DeviceZonePreset) 10)
+
+#define VL53L1_DEVICEZONEPRESET_1X1_SIZE_4X4_POS_8X8 ((VL53L1_DeviceZonePreset) 11)
+
+#define VL53L1_DEVICEZONEPRESET_CUSTOM ((VL53L1_DeviceZonePreset) 255)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DevicePresetModes;
+
+#define VL53L1_DEVICEPRESETMODE_NONE ((VL53L1_DevicePresetModes) 0)
+#define VL53L1_DEVICEPRESETMODE_STANDARD_RANGING ((VL53L1_DevicePresetModes) 1)
+#define VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_SHORT_RANGE ((VL53L1_DevicePresetModes) 2)
+#define VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_LONG_RANGE ((VL53L1_DevicePresetModes) 3)
+#define VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM1_CAL ((VL53L1_DevicePresetModes) 4)
+#define VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM2_CAL ((VL53L1_DevicePresetModes) 5)
+#define VL53L1_DEVICEPRESETMODE_TIMED_RANGING ((VL53L1_DevicePresetModes) 6)
+#define VL53L1_DEVICEPRESETMODE_TIMED_RANGING_SHORT_RANGE ((VL53L1_DevicePresetModes) 7)
+#define VL53L1_DEVICEPRESETMODE_TIMED_RANGING_LONG_RANGE ((VL53L1_DevicePresetModes) 8)
+#define VL53L1_DEVICEPRESETMODE_NEAR_FARRANGING ((VL53L1_DevicePresetModes) 9)
+#define VL53L1_DEVICEPRESETMODE_QUADRANT_RANGING ((VL53L1_DevicePresetModes) 10)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING ((VL53L1_DevicePresetModes) 11)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_SHORT_TIMING ((VL53L1_DevicePresetModes) 12)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_CHARACTERISATION ((VL53L1_DevicePresetModes) 13)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_PLANAR ((VL53L1_DevicePresetModes) 14)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_MM1 ((VL53L1_DevicePresetModes) 15)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_MM2 ((VL53L1_DevicePresetModes) 16)
+#define VL53L1_DEVICEPRESETMODE_OLT ((VL53L1_DevicePresetModes) 17)
+#define VL53L1_DEVICEPRESETMODE_SINGLESHOT_RANGING ((VL53L1_DevicePresetModes) 18)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_REF_ARRAY ((VL53L1_DevicePresetModes) 19)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_WITH_MM1 ((VL53L1_DevicePresetModes) 20)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_WITH_MM2 ((VL53L1_DevicePresetModes) 21)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM1_CAL ((VL53L1_DevicePresetModes) 22)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM2_CAL ((VL53L1_DevicePresetModes) 23)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE ((VL53L1_DevicePresetModes) 24)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_SHORT_RANGE ((VL53L1_DevicePresetModes) 25)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_LONG_RANGE ((VL53L1_DevicePresetModes) 26)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE ((VL53L1_DevicePresetModes) 27)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE_MM1 ((VL53L1_DevicePresetModes) 28)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE_MM2 ((VL53L1_DevicePresetModes) 29)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE ((VL53L1_DevicePresetModes) 30)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE_MM1 ((VL53L1_DevicePresetModes) 31)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE_MM2 ((VL53L1_DevicePresetModes) 32)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE ((VL53L1_DevicePresetModes) 33)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE_MM1 ((VL53L1_DevicePresetModes) 34)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE_MM2 ((VL53L1_DevicePresetModes) 35)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceMeasurementModes;
+
+#define VL53L1_DEVICEMEASUREMENTMODE_STOP ((VL53L1_DeviceMeasurementModes) 0x00)
+#define VL53L1_DEVICEMEASUREMENTMODE_SINGLESHOT ((VL53L1_DeviceMeasurementModes) 0x10)
+#define VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK ((VL53L1_DeviceMeasurementModes) 0x20)
+#define VL53L1_DEVICEMEASUREMENTMODE_TIMED ((VL53L1_DeviceMeasurementModes) 0x40)
+#define VL53L1_DEVICEMEASUREMENTMODE_ABORT ((VL53L1_DeviceMeasurementModes) 0x80)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_OffsetCalibrationMode;
+
+#define VL53L1_OFFSETCALIBRATIONMODE__NONE ((VL53L1_OffsetCalibrationMode) 0)
+#define VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD ((VL53L1_OffsetCalibrationMode) 1)
+#define VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM ((VL53L1_OffsetCalibrationMode) 2)
+#define VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD_PRE_RANGE_ONLY ((VL53L1_OffsetCalibrationMode) 3)
+#define VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM_PRE_RANGE_ONLY ((VL53L1_OffsetCalibrationMode) 4)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_OffsetCorrectionMode;
+
+#define VL53L1_OFFSETCORRECTIONMODE__NONE ((VL53L1_OffsetCorrectionMode) 0)
+#define VL53L1_OFFSETCORRECTIONMODE__MM1_MM2_OFFSETS ((VL53L1_OffsetCorrectionMode) 1)
+#define VL53L1_OFFSETCORRECTIONMODE__PER_ZONE_OFFSETS ((VL53L1_OffsetCorrectionMode) 2)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceDmaxMode;
+
+#define VL53L1_DEVICEDMAXMODE__NONE ((VL53L1_DeviceDmaxMode) 0)
+#define VL53L1_DEVICEDMAXMODE__FMT_CAL_DATA ((VL53L1_DeviceDmaxMode) 1)
+#define VL53L1_DEVICEDMAXMODE__CUST_CAL_DATA ((VL53L1_DeviceDmaxMode) 2)
+#define VL53L1_DEVICEDMAXMODE__PER_ZONE_CAL_DATA ((VL53L1_DeviceDmaxMode) 3)
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceSequenceConfig;
+
+#define VL53L1_DEVICESEQUENCECONFIG_VHV ((VL53L1_DeviceSequenceConfig) 0)
+#define VL53L1_DEVICESEQUENCECONFIG_PHASECAL ((VL53L1_DeviceSequenceConfig) 1)
+#define VL53L1_DEVICESEQUENCECONFIG_REFERENCE_PHASE ((VL53L1_DeviceSequenceConfig) 2)
+#define VL53L1_DEVICESEQUENCECONFIG_DSS1 ((VL53L1_DeviceSequenceConfig) 3)
+#define VL53L1_DEVICESEQUENCECONFIG_DSS2 ((VL53L1_DeviceSequenceConfig) 4)
+#define VL53L1_DEVICESEQUENCECONFIG_MM1 ((VL53L1_DeviceSequenceConfig) 5)
+#define VL53L1_DEVICESEQUENCECONFIG_MM2 ((VL53L1_DeviceSequenceConfig) 6)
+#define VL53L1_DEVICESEQUENCECONFIG_RANGE ((VL53L1_DeviceSequenceConfig) 7)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceInterruptPolarity;
+
+#define VL53L1_DEVICEINTERRUPTPOLARITY_ACTIVE_HIGH ((VL53L1_DeviceInterruptPolarity) 0x00)
+#define VL53L1_DEVICEINTERRUPTPOLARITY_ACTIVE_LOW ((VL53L1_DeviceInterruptPolarity) 0x10)
+#define VL53L1_DEVICEINTERRUPTPOLARITY_BIT_MASK ((VL53L1_DeviceInterruptPolarity) 0x10)
+#define VL53L1_DEVICEINTERRUPTPOLARITY_CLEAR_MASK ((VL53L1_DeviceInterruptPolarity) 0xEF)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceGpioMode;
+
+#define VL53L1_DEVICEGPIOMODE_OUTPUT_CONSTANT_ZERO ((VL53L1_DeviceGpioMode) 0x00)
+#define VL53L1_DEVICEGPIOMODE_OUTPUT_RANGE_AND_ERROR_INTERRUPTS ((VL53L1_DeviceGpioMode) 0x01)
+#define VL53L1_DEVICEGPIOMODE_OUTPUT_TIMIER_INTERRUPTS ((VL53L1_DeviceGpioMode) 0x02)
+#define VL53L1_DEVICEGPIOMODE_OUTPUT_RANGE_MODE_INTERRUPT_STATUS ((VL53L1_DeviceGpioMode) 0x03)
+#define VL53L1_DEVICEGPIOMODE_OUTPUT_SLOW_OSCILLATOR_CLOCK ((VL53L1_DeviceGpioMode) 0x04)
+#define VL53L1_DEVICEGPIOMODE_BIT_MASK ((VL53L1_DeviceGpioMode) 0x0F)
+#define VL53L1_DEVICEGPIOMODE_CLEAR_MASK ((VL53L1_DeviceGpioMode) 0xF0)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceError;
+
+#define VL53L1_DEVICEERROR_NOUPDATE ((VL53L1_DeviceError) 0)
+
+
+#define VL53L1_DEVICEERROR_VCSELCONTINUITYTESTFAILURE ((VL53L1_DeviceError) 1)
+#define VL53L1_DEVICEERROR_VCSELWATCHDOGTESTFAILURE ((VL53L1_DeviceError) 2)
+#define VL53L1_DEVICEERROR_NOVHVVALUEFOUND ((VL53L1_DeviceError) 3)
+#define VL53L1_DEVICEERROR_MSRCNOTARGET ((VL53L1_DeviceError) 4)
+#define VL53L1_DEVICEERROR_RANGEPHASECHECK ((VL53L1_DeviceError) 5)
+#define VL53L1_DEVICEERROR_SIGMATHRESHOLDCHECK ((VL53L1_DeviceError) 6)
+#define VL53L1_DEVICEERROR_PHASECONSISTENCY ((VL53L1_DeviceError) 7)
+#define VL53L1_DEVICEERROR_MINCLIP ((VL53L1_DeviceError) 8)
+#define VL53L1_DEVICEERROR_RANGECOMPLETE ((VL53L1_DeviceError) 9)
+#define VL53L1_DEVICEERROR_ALGOUNDERFLOW ((VL53L1_DeviceError) 10)
+#define VL53L1_DEVICEERROR_ALGOOVERFLOW ((VL53L1_DeviceError) 11)
+#define VL53L1_DEVICEERROR_RANGEIGNORETHRESHOLD ((VL53L1_DeviceError) 12)
+#define VL53L1_DEVICEERROR_USERROICLIP ((VL53L1_DeviceError) 13)
+#define VL53L1_DEVICEERROR_REFSPADCHARNOTENOUGHDPADS ((VL53L1_DeviceError) 14)
+#define VL53L1_DEVICEERROR_REFSPADCHARMORETHANTARGET ((VL53L1_DeviceError) 15)
+#define VL53L1_DEVICEERROR_REFSPADCHARLESSTHANTARGET ((VL53L1_DeviceError) 16)
+#define VL53L1_DEVICEERROR_MULTCLIPFAIL ((VL53L1_DeviceError) 17)
+#define VL53L1_DEVICEERROR_GPHSTREAMCOUNT0READY ((VL53L1_DeviceError) 18)
+#define VL53L1_DEVICEERROR_RANGECOMPLETE_NO_WRAP_CHECK ((VL53L1_DeviceError) 19)
+#define VL53L1_DEVICEERROR_EVENTCONSISTENCY ((VL53L1_DeviceError) 20)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceReportStatus;
+
+#define VL53L1_DEVICEREPORTSTATUS_NOUPDATE ((VL53L1_DeviceReportStatus) 0)
+
+
+#define VL53L1_DEVICEREPORTSTATUS_ROI_SETUP ((VL53L1_DeviceReportStatus) 1)
+#define VL53L1_DEVICEREPORTSTATUS_VHV ((VL53L1_DeviceReportStatus) 2)
+#define VL53L1_DEVICEREPORTSTATUS_PHASECAL ((VL53L1_DeviceReportStatus) 3)
+#define VL53L1_DEVICEREPORTSTATUS_REFERENCE_PHASE ((VL53L1_DeviceReportStatus) 4)
+#define VL53L1_DEVICEREPORTSTATUS_DSS1 ((VL53L1_DeviceReportStatus) 5)
+#define VL53L1_DEVICEREPORTSTATUS_DSS2 ((VL53L1_DeviceReportStatus) 6)
+#define VL53L1_DEVICEREPORTSTATUS_MM1 ((VL53L1_DeviceReportStatus) 7)
+#define VL53L1_DEVICEREPORTSTATUS_MM2 ((VL53L1_DeviceReportStatus) 8)
+#define VL53L1_DEVICEREPORTSTATUS_RANGE ((VL53L1_DeviceReportStatus) 9)
+#define VL53L1_DEVICEREPORTSTATUS_HISTOGRAM ((VL53L1_DeviceReportStatus) 10)
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceDssMode;
+
+#define VL53L1_DEVICEDSSMODE__DISABLED \
+ ((VL53L1_DeviceDssMode) 0)
+#define VL53L1_DEVICEDSSMODE__TARGET_RATE \
+ ((VL53L1_DeviceDssMode) 1)
+#define VL53L1_DEVICEDSSMODE__REQUESTED_EFFFECTIVE_SPADS \
+ ((VL53L1_DeviceDssMode) 2)
+#define VL53L1_DEVICEDSSMODE__BLOCK_SELECT \
+ ((VL53L1_DeviceDssMode) 3)
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_HistAlgoSelect;
+
+#define VL53L1_HIST_ALGO_SELECT__PW_HIST_GEN1 \
+ ((VL53L1_HistAlgoSelect) 1)
+#define VL53L1_HIST_ALGO_SELECT__PW_HIST_GEN2 \
+ ((VL53L1_HistAlgoSelect) 2)
+#define VL53L1_HIST_ALGO_SELECT__PW_HIST_GEN3 \
+ ((VL53L1_HistAlgoSelect) 3)
+#define VL53L1_HIST_ALGO_SELECT__PW_HIST_GEN4 \
+ ((VL53L1_HistAlgoSelect) 4)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_HistTargetOrder;
+
+#define VL53L1_HIST_TARGET_ORDER__INCREASING_DISTANCE \
+ ((VL53L1_HistTargetOrder) 1)
+#define VL53L1_HIST_TARGET_ORDER__STRONGEST_FIRST \
+ ((VL53L1_HistTargetOrder) 2)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_HistAmbEstMethod;
+
+#define VL53L1_HIST_AMB_EST_METHOD__AMBIENT_BINS \
+ ((VL53L1_HistAmbEstMethod) 1)
+#define VL53L1_HIST_AMB_EST_METHOD__THRESHOLDED_BINS \
+ ((VL53L1_HistAmbEstMethod) 2)
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_HistXtalkCompEnable;
+
+#define VL53L1_HIST_XTALK_COMP__DIS \
+ ((VL53L1_HistXtalkCompEnable) 0)
+#define VL53L1_HIST_XTALK_COMP__EN \
+ ((VL53L1_HistXtalkCompEnable) 1)
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceConfigLevel;
+
+#define VL53L1_DEVICECONFIGLEVEL_SYSTEM_CONTROL \
+ ((VL53L1_DeviceConfigLevel) 0)
+
+
+#define VL53L1_DEVICECONFIGLEVEL_DYNAMIC_ONWARDS \
+ ((VL53L1_DeviceConfigLevel) 1)
+
+
+#define VL53L1_DEVICECONFIGLEVEL_TIMING_ONWARDS \
+ ((VL53L1_DeviceConfigLevel) 2)
+
+
+
+#define VL53L1_DEVICECONFIGLEVEL_GENERAL_ONWARDS \
+ ((VL53L1_DeviceConfigLevel) 3)
+
+
+
+#define VL53L1_DEVICECONFIGLEVEL_STATIC_ONWARDS \
+ ((VL53L1_DeviceConfigLevel) 4)
+
+
+
+#define VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS \
+ ((VL53L1_DeviceConfigLevel) 5)
+
+
+
+#define VL53L1_DEVICECONFIGLEVEL_FULL \
+ ((VL53L1_DeviceConfigLevel) 6)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceResultsLevel;
+
+#define VL53L1_DEVICERESULTSLEVEL_SYSTEM_RESULTS \
+ ((VL53L1_DeviceResultsLevel) 0)
+
+
+#define VL53L1_DEVICERESULTSLEVEL_UPTO_CORE \
+ ((VL53L1_DeviceResultsLevel) 1)
+
+
+#define VL53L1_DEVICERESULTSLEVEL_FULL \
+ ((VL53L1_DeviceResultsLevel) 2)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceTestMode;
+
+#define VL53L1_DEVICETESTMODE_NONE \
+ ((VL53L1_DeviceTestMode) 0x00)
+
+
+#define VL53L1_DEVICETESTMODE_NVM_ZERO \
+ ((VL53L1_DeviceTestMode) 0x01)
+
+
+#define VL53L1_DEVICETESTMODE_NVM_COPY \
+ ((VL53L1_DeviceTestMode) 0x02)
+
+
+#define VL53L1_DEVICETESTMODE_PATCH \
+ ((VL53L1_DeviceTestMode) 0x03)
+
+
+#define VL53L1_DEVICETESTMODE_DCR \
+ ((VL53L1_DeviceTestMode) 0x04)
+
+
+#define VL53L1_DEVICETESTMODE_LCR_VCSEL_OFF \
+ ((VL53L1_DeviceTestMode) 0x05)
+
+
+
+#define VL53L1_DEVICETESTMODE_LCR_VCSEL_ON \
+ ((VL53L1_DeviceTestMode) 0x06)
+
+
+
+#define VL53L1_DEVICETESTMODE_SPOT_CENTRE_LOCATE \
+ ((VL53L1_DeviceTestMode) 0x07)
+
+
+#define VL53L1_DEVICETESTMODE_REF_SPAD_CHAR_WITH_PRE_VHV \
+ ((VL53L1_DeviceTestMode) 0x08)
+
+
+#define VL53L1_DEVICETESTMODE_REF_SPAD_CHAR_ONLY \
+ ((VL53L1_DeviceTestMode) 0x09)
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceSscArray;
+
+#define VL53L1_DEVICESSCARRAY_RTN ((VL53L1_DeviceSscArray) 0x00)
+
+
+#define VL53L1_DEVICETESTMODE_REF ((VL53L1_DeviceSscArray) 0x01)
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RETURN_ARRAY_ONLY 0x01
+
+
+#define VL53L1_REFERENCE_ARRAY_ONLY 0x10
+
+
+#define VL53L1_BOTH_RETURN_AND_REFERENCE_ARRAYS 0x11
+
+
+#define VL53L1_NEITHER_RETURN_AND_REFERENCE_ARRAYS 0x00
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_HIGH 0x00
+
+
+#define VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_LOW 0x10
+
+
+#define VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_MASK 0x10
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_POLLING_DELAY_US 1000
+
+
+#define VL53L1_SOFTWARE_RESET_DURATION_US 100
+
+
+#define VL53L1_FIRMWARE_BOOT_TIME_US 1200
+
+
+
+#define VL53L1_ENABLE_POWERFORCE_SETTLING_TIME_US 250
+
+
+
+
+#define VL53L1_SPAD_ARRAY_WIDTH 16
+
+
+#define VL53L1_SPAD_ARRAY_HEIGHT 16
+
+
+#define VL53L1_NVM_SIZE_IN_BYTES 512
+
+
+#define VL53L1_NO_OF_SPAD_ENABLES 256
+
+
+#define VL53L1_RTN_SPAD_BUFFER_SIZE 32
+
+
+#define VL53L1_REF_SPAD_BUFFER_SIZE 6
+
+
+#define VL53L1_AMBIENT_WINDOW_VCSEL_PERIODS 256
+
+
+#define VL53L1_RANGING_WINDOW_VCSEL_PERIODS 2048
+
+
+#define VL53L1_MACRO_PERIOD_VCSEL_PERIODS \
+ (VL53L1_AMBIENT_WINDOW_VCSEL_PERIODS + VL53L1_RANGING_WINDOW_VCSEL_PERIODS)
+
+
+#define VL53L1_MAX_ALLOWED_PHASE 0xFFFF
+
+
+
+#define VL53L1_RTN_SPAD_UNITY_TRANSMISSION 0x0100
+
+
+#define VL53L1_RTN_SPAD_APERTURE_TRANSMISSION 0x0038
+
+
+
+
+
+#define VL53L1_SPAD_TOTAL_COUNT_MAX ((0x01 << 29) - 1)
+
+
+#define VL53L1_SPAD_TOTAL_COUNT_RES_THRES (0x01 << 24)
+
+
+#define VL53L1_COUNT_RATE_INTERNAL_MAX ((0x01 << 24) - 1)
+
+
+#define VL53L1_SPEED_OF_LIGHT_IN_AIR 299704
+
+
+#define VL53L1_SPEED_OF_LIGHT_IN_AIR_DIV_8 (299704 >> 3)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_ZoneConfig_BinConfig_select;
+
+#define VL53L1_ZONECONFIG_BINCONFIG__LOWAMB \
+ ((VL53L1_ZoneConfig_BinConfig_select) 1)
+#define VL53L1_ZONECONFIG_BINCONFIG__MIDAMB \
+ ((VL53L1_ZoneConfig_BinConfig_select) 2)
+#define VL53L1_ZONECONFIG_BINCONFIG__HIGHAMB \
+ ((VL53L1_ZoneConfig_BinConfig_select) 3)
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_GPIO_Interrupt_Mode;
+
+#define VL53L1_GPIOINTMODE_LEVEL_LOW \
+ ((VL53L1_GPIO_Interrupt_Mode) 0)
+
+
+#define VL53L1_GPIOINTMODE_LEVEL_HIGH \
+ ((VL53L1_GPIO_Interrupt_Mode) 1)
+
+
+#define VL53L1_GPIOINTMODE_OUT_OF_WINDOW \
+ ((VL53L1_GPIO_Interrupt_Mode) 2)
+
+
+#define VL53L1_GPIOINTMODE_IN_WINDOW \
+ ((VL53L1_GPIO_Interrupt_Mode) 3)
+
+
+
+
+
+
+
+#endif
+
+
+
+
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_nvm.h b/drivers/input/misc/vl53L1/inc/vl53l1_nvm.h
new file mode 100644
index 000000000000..fc09febb733b
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_nvm.h
@@ -0,0 +1,422 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_NVM_H_
+#define _VL53L1_NVM_H_
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define VL53L1_NVM_POWER_UP_DELAY_US 50
+#define VL53L1_NVM_READ_TRIGGER_DELAY_US 5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_enable(
+ VL53L1_DEV Dev,
+ uint16_t nvm_ctrl_pulse_width,
+ int32_t nvm_power_up_delay_us);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_read(
+ VL53L1_DEV Dev,
+ uint8_t start_address,
+ uint8_t count,
+ uint8_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_disable(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_format_decode(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_decode_cal_peak_rate_map(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_cal_peak_rate_map_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_decode_additional_offset_cal_data(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_additional_offset_cal_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_decode_fmt_range_results_data(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_fmt_range_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_decode_fmt_info(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_fmt_info_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_decode_ews_info(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_ews_info_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_nvm_format_encode(
+ VL53L1_decoded_nvm_data_t *pnvm_info,
+ uint8_t *pnvm_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_read_nvm_raw_data(
+ VL53L1_DEV Dev,
+ uint8_t start_address,
+ uint8_t count,
+ uint8_t *pnvm_raw_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_read_nvm(
+ VL53L1_DEV Dev,
+ uint8_t nvm_format,
+ VL53L1_decoded_nvm_data_t *pnvm_info);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_read_nvm_cal_peak_rate_map(
+ VL53L1_DEV Dev,
+ VL53L1_cal_peak_rate_map_t *pcal_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_read_nvm_additional_offset_cal_data(
+ VL53L1_DEV Dev,
+ VL53L1_additional_offset_cal_data_t *pcal_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_read_nvm_fmt_range_results_data(
+ VL53L1_DEV Dev,
+ uint16_t range_results_select,
+ VL53L1_decoded_nvm_fmt_range_data_t *prange_data);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_nvm_debug.h b/drivers/input/misc/vl53L1/inc/vl53l1_nvm_debug.h
new file mode 100644
index 000000000000..b42bcbafe03d
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_nvm_debug.h
@@ -0,0 +1,201 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_NVM_DEBUG_H_
+#define _VL53L1_NVM_DEBUG_H_
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_nvm_structs.h"
+
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_nvm_raw_data(
+ uint8_t *pnvm_raw_data,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_decoded_nvm_data(
+ VL53L1_decoded_nvm_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_decoded_nvm_fmt_range_data(
+ VL53L1_decoded_nvm_fmt_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_decoded_nvm_fmt_info(
+ VL53L1_decoded_nvm_fmt_info_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_decoded_nvm_ews_info(
+ VL53L1_decoded_nvm_ews_info_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_nvm_map.h b/drivers/input/misc/vl53L1/inc/vl53l1_nvm_map.h
new file mode 100644
index 000000000000..a9f76da706f7
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_nvm_map.h
@@ -0,0 +1,3246 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_NVM_MAP_H_
+#define _VL53L1_NVM_MAP_H_
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+
+
+
+
+
+#define VL53L1_NVM__IDENTIFICATION__MODEL_ID 0x0008
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__IDENTIFICATION__MODULE_TYPE 0x000C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__IDENTIFICATION__REVISION_ID 0x000D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__IDENTIFICATION__MODULE_ID 0x000E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__I2C_VALID 0x0010
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__I2C_SLAVE__DEVICE_ADDRESS 0x0011
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__OSC_MEASURED__FAST_OSC_FREQUENCY 0x0014
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__FAST_OSC_TRIM_MAX 0x0016
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__FAST_OSC_FREQ_SET 0x0017
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SLOW_OSC_CALIBRATION 0x0018
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__OSC_MEASURED__FAST_OSC_FREQUENCY 0x001C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FAST_OSC_TRIM_MAX 0x001E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FAST_OSC_FREQ_SET 0x001F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SLOW_OSC_CALIBRATION 0x0020
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__VHV_CONFIG_UNLOCK 0x0028
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__REF_SELVDDPIX 0x0029
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__REF_SELVQUENCH 0x002A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__REGAVDD1V2_SEL_REGDVDD1V2_SEL 0x002B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND 0x002C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__VHV_CONFIG__COUNT_THRESH 0x002D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__VHV_CONFIG__OFFSET 0x002E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__VHV_CONFIG__INIT 0x002F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__VCSEL_TRIM_LL 0x0030
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_LL 0x0031
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_MAX_LL 0x0032
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__MULT_LL 0x0034
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__CLIP_LL 0x0035
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__VCSEL_TRIM_LD 0x0038
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_LD 0x0039
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_MAX_LD 0x003A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__MULT_LD 0x003C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__CLIP_LD 0x003D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY_LOCK_BYTE 0x0040
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY_UNLOCK_BYTE 0x0044
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_0_ 0x0048
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_1_ 0x0049
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_2_ 0x004A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_3_ 0x004B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_4_ 0x004C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_5_ 0x004D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_6_ 0x004E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_7_ 0x004F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_8_ 0x0050
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_9_ 0x0051
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_10_ 0x0052
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_11_ 0x0053
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_12_ 0x0054
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_13_ 0x0055
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_14_ 0x0056
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_15_ 0x0057
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_16_ 0x0058
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_17_ 0x0059
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_18_ 0x005A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_19_ 0x005B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_20_ 0x005C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_21_ 0x005D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_22_ 0x005E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_23_ 0x005F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_24_ 0x0060
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_25_ 0x0061
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_26_ 0x0062
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_27_ 0x0063
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_28_ 0x0064
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_29_ 0x0065
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_30_ 0x0066
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_31_ 0x0067
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_0_ 0x0068
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_1_ 0x0069
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_2_ 0x006A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_3_ 0x006B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_4_ 0x006C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_5_ 0x006D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_0_ 0x0070
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_1_ 0x0071
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_2_ 0x0072
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_3_ 0x0073
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_4_ 0x0074
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_5_ 0x0075
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_0_ 0x0078
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_1_ 0x0079
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_2_ 0x007A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_3_ 0x007B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_4_ 0x007C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_5_ 0x007D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_0_ 0x0080
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_1_ 0x0081
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_2_ 0x0082
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_3_ 0x0083
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_4_ 0x0084
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_5_ 0x0085
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_6_ 0x0086
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_7_ 0x0087
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_8_ 0x0088
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_9_ 0x0089
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_10_ 0x008A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_11_ 0x008B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_12_ 0x008C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_13_ 0x008D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_14_ 0x008E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_15_ 0x008F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_16_ 0x0090
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_17_ 0x0091
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_18_ 0x0092
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_19_ 0x0093
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_20_ 0x0094
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_21_ 0x0095
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_22_ 0x0096
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_23_ 0x0097
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_24_ 0x0098
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_25_ 0x0099
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_26_ 0x009A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_27_ 0x009B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_28_ 0x009C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_29_ 0x009D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_30_ 0x009E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_31_ 0x009F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_0_ 0x00A0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_1_ 0x00A1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_2_ 0x00A2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_3_ 0x00A3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_4_ 0x00A4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_5_ 0x00A5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_0_ 0x00A8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_1_ 0x00A9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_2_ 0x00AA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_3_ 0x00AB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_4_ 0x00AC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_5_ 0x00AD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_0_ 0x00B0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_1_ 0x00B1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_2_ 0x00B2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_3_ 0x00B3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_4_ 0x00B4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_5_ 0x00B5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__ROI_CONFIG__MODE_ROI_CENTRE_SPAD 0x00B8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__ROI_CONFIG__MODE_ROI_XY_SIZE 0x00B9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__REF_SPAD_APPLY__NUM_REQUESTED_REF_SPAD 0x00BC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__REF_SPAD_MAN__REF_LOCATION 0x00BD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__MM_CONFIG__INNER_OFFSET_MM 0x00C0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__MM_CONFIG__OUTER_OFFSET_MM 0x00C2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__ALGO__PART_TO_PART_RANGE_OFFSET_MM 0x00C4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS 0x00C8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS 0x00CA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS 0x00CC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_0 0x00CE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_1 0x00CF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUSTOMER_NVM_SPACE_PROGRAMMED 0x00E0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__I2C_SLAVE__DEVICE_ADDRESS 0x00E4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__REF_SPAD_APPLY__NUM_REQUESTED_REF_SPAD 0x00E8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__REF_SPAD_MAN__REF_LOCATION 0x00E9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__MM_CONFIG__INNER_OFFSET_MM 0x00EC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__MM_CONFIG__OUTER_OFFSET_MM 0x00EE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__ALGO__PART_TO_PART_RANGE_OFFSET_MM 0x00F0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS 0x00F4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS 0x00F6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS 0x00F8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_0 0x00FA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_1 0x00FB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_0 0x01DC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_1 0x01DD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_2 0x01DE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_3 0x01DF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_4 0x01E0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_5 0x01E1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_6 0x01E2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_7 0x01E3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_8 0x01E4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_9 0x01E5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_10 0x01E6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_11 0x01E7
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_12 0x01E8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_13 0x01E9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_14 0x01EA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_15 0x01EB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__TEST_PROGRAM_MAJOR_MINOR 0x01EC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__MAP_MAJOR_MINOR 0x01ED
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__YEAR_MONTH 0x01EE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__DAY_MODULE_DATE_PHASE 0x01EF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__TIME 0x01F0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__TESTER_ID 0x01F2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SITE_ID 0x01F3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__TEST_PROGRAM_MAJOR_MINOR 0x01F4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__PROBE_CARD_MAJOR_MINOR 0x01F5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__TESTER_ID 0x01F6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__LOT__BYTE_0 0x01F8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__LOT__BYTE_1 0x01F9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__LOT__BYTE_2 0x01FA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__LOT__BYTE_3 0x01FB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__LOT__BYTE_4 0x01FC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__LOT__BYTE_5 0x01FD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__WAFER 0x01FD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__XCOORD 0x01FE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__YCOORD 0x01FF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_INDEX 0x015C
+#define VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_SIZE 56
+
+#define VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_INDEX 0x0194
+#define VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_SIZE 8
+
+#define VL53L1_NVM__FMT__RANGE_RESULTS__140MM_MM_PRE_RANGE 0x019C
+#define VL53L1_NVM__FMT__RANGE_RESULTS__140MM_DARK 0x01AC
+#define VL53L1_NVM__FMT__RANGE_RESULTS__400MM_DARK 0x01BC
+#define VL53L1_NVM__FMT__RANGE_RESULTS__400MM_AMBIENT 0x01CC
+#define VL53L1_NVM__FMT__RANGE_RESULTS__SIZE_BYTES 16
+
+
+
+
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_nvm_structs.h b/drivers/input/misc/vl53L1/inc/vl53l1_nvm_structs.h
new file mode 100644
index 000000000000..5676bb6a487a
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_nvm_structs.h
@@ -0,0 +1,804 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_NVM_STRUCTS_H_
+#define _VL53L1_NVM_STRUCTS_H_
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "vl53l1_platform.h"
+#include "vl53l1_ll_def.h"
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint16_t result__actual_effective_rtn_spads;
+
+
+ uint8_t ref_spad_array__num_requested_ref_spads;
+
+
+ uint8_t ref_spad_array__ref_location;
+
+
+ uint16_t result__peak_signal_count_rate_rtn_mcps;
+
+
+ uint16_t result__ambient_count_rate_rtn_mcps;
+
+
+ uint16_t result__peak_signal_count_rate_ref_mcps;
+
+
+ uint16_t result__ambient_count_rate_ref_mcps;
+
+
+ uint16_t measured_distance_mm;
+
+
+ uint16_t measured_distance_stdev_mm;
+
+
+
+} VL53L1_decoded_nvm_fmt_range_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ char nvm__fmt__fgc[19];
+
+
+ uint8_t nvm__fmt__test_program_major;
+
+
+
+
+
+ uint8_t nvm__fmt__test_program_minor;
+
+
+
+
+
+ uint8_t nvm__fmt__map_major;
+
+
+
+
+
+ uint8_t nvm__fmt__map_minor;
+
+
+
+
+
+ uint8_t nvm__fmt__year;
+
+
+
+
+
+ uint8_t nvm__fmt__month;
+
+
+
+
+
+ uint8_t nvm__fmt__day;
+
+
+
+
+
+ uint8_t nvm__fmt__module_date_phase;
+
+
+
+
+
+ uint16_t nvm__fmt__time;
+
+
+
+
+
+ uint8_t nvm__fmt__tester_id;
+
+
+
+
+
+ uint8_t nvm__fmt__site_id;
+
+
+
+
+
+ uint8_t nvm__ews__test_program_major;
+
+
+
+
+
+ uint8_t nvm__ews__test_program_minor;
+
+
+
+
+
+ uint8_t nvm__ews__probe_card_major;
+
+
+
+
+
+ uint8_t nvm__ews__probe_card_minor;
+
+
+
+
+
+ uint8_t nvm__ews__tester_id;
+
+
+
+
+
+
+ char nvm__ews__lot[8];
+
+
+ uint8_t nvm__ews__wafer;
+
+
+
+
+
+ uint8_t nvm__ews__xcoord;
+
+
+
+
+
+ uint8_t nvm__ews__ycoord;
+
+
+
+
+
+} VL53L1_decoded_nvm_fmt_info_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t nvm__ews__test_program_major;
+
+
+
+
+
+ uint8_t nvm__ews__test_program_minor;
+
+
+
+
+
+ uint8_t nvm__ews__probe_card_major;
+
+
+
+
+
+ uint8_t nvm__ews__probe_card_minor;
+
+
+
+
+
+ uint8_t nvm__ews__tester_id;
+
+
+
+
+
+
+ char nvm__ews__lot[8];
+
+
+ uint8_t nvm__ews__wafer;
+
+
+
+
+
+ uint8_t nvm__ews__xcoord;
+
+
+
+
+
+ uint8_t nvm__ews__ycoord;
+
+
+
+
+
+
+} VL53L1_decoded_nvm_ews_info_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t nvm__identification_model_id;
+
+
+
+
+
+ uint8_t nvm__identification_module_type;
+
+
+
+
+
+ uint8_t nvm__identification_revision_id;
+
+
+
+
+
+ uint16_t nvm__identification_module_id;
+
+
+
+
+
+ uint8_t nvm__i2c_valid;
+
+
+
+
+
+ uint8_t nvm__i2c_device_address_ews;
+
+
+
+
+
+ uint16_t nvm__ews__fast_osc_frequency;
+
+
+
+
+
+ uint8_t nvm__ews__fast_osc_trim_max;
+
+
+
+
+
+ uint8_t nvm__ews__fast_osc_freq_set;
+
+
+
+
+
+ uint16_t nvm__ews__slow_osc_calibration;
+
+
+
+
+
+ uint16_t nvm__fmt__fast_osc_frequency;
+
+
+
+
+
+ uint8_t nvm__fmt__fast_osc_trim_max;
+
+
+
+
+
+ uint8_t nvm__fmt__fast_osc_freq_set;
+
+
+
+
+
+ uint16_t nvm__fmt__slow_osc_calibration;
+
+
+
+
+
+ uint8_t nvm__vhv_config_unlock;
+
+
+
+
+
+ uint8_t nvm__ref_selvddpix;
+
+
+
+
+
+ uint8_t nvm__ref_selvquench;
+
+
+
+
+
+ uint8_t nvm__regavdd1v2_sel;
+
+
+
+
+
+ uint8_t nvm__regdvdd1v2_sel;
+
+
+
+
+
+ uint8_t nvm__vhv_timeout__macrop;
+
+
+
+
+
+ uint8_t nvm__vhv_loop_bound;
+
+
+
+
+
+ uint8_t nvm__vhv_count_threshold;
+
+
+
+
+
+ uint8_t nvm__vhv_offset;
+
+
+
+
+
+ uint8_t nvm__vhv_init_enable;
+
+
+
+
+
+ uint8_t nvm__vhv_init_value;
+
+
+
+
+
+ uint8_t nvm__laser_safety_vcsel_trim_ll;
+
+
+
+
+
+ uint8_t nvm__laser_safety_vcsel_selion_ll;
+
+
+
+
+
+ uint8_t nvm__laser_safety_vcsel_selion_max_ll;
+
+
+
+
+
+ uint8_t nvm__laser_safety_mult_ll;
+
+
+
+
+
+ uint8_t nvm__laser_safety_clip_ll;
+
+
+
+
+
+ uint8_t nvm__laser_safety_vcsel_trim_ld;
+
+
+
+
+
+ uint8_t nvm__laser_safety_vcsel_selion_ld;
+
+
+
+
+
+ uint8_t nvm__laser_safety_vcsel_selion_max_ld;
+
+
+
+
+
+ uint8_t nvm__laser_safety_mult_ld;
+
+
+
+
+
+ uint8_t nvm__laser_safety_clip_ld;
+
+
+
+
+
+ uint8_t nvm__laser_safety_lock_byte;
+
+
+
+
+
+ uint8_t nvm__laser_safety_unlock_byte;
+
+
+
+
+
+ uint8_t nvm__ews__spad_enables_rtn[VL53L1_RTN_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__ews__spad_enables_ref__loc1[VL53L1_REF_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__ews__spad_enables_ref__loc2[VL53L1_REF_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__ews__spad_enables_ref__loc3[VL53L1_REF_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__fmt__spad_enables_rtn[VL53L1_RTN_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__fmt__spad_enables_ref__loc1[VL53L1_REF_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__fmt__spad_enables_ref__loc2[VL53L1_REF_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__fmt__spad_enables_ref__loc3[VL53L1_REF_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__fmt__roi_config__mode_roi_centre_spad;
+
+
+
+
+
+ uint8_t nvm__fmt__roi_config__mode_roi_x_size;
+
+
+
+
+
+ uint8_t nvm__fmt__roi_config__mode_roi_y_size;
+
+
+
+
+
+ uint8_t nvm__fmt__ref_spad_apply__num_requested_ref_spad;
+
+
+
+
+
+ uint8_t nvm__fmt__ref_spad_man__ref_location;
+
+
+
+
+
+ uint16_t nvm__fmt__mm_config__inner_offset_mm;
+
+
+
+
+
+ uint16_t nvm__fmt__mm_config__outer_offset_mm;
+
+
+
+
+
+ uint16_t nvm__fmt__algo_part_to_part_range_offset_mm;
+
+
+
+
+
+ uint16_t nvm__fmt__algo__crosstalk_compensation_plane_offset_kcps;
+
+
+
+
+
+ uint16_t nvm__fmt__algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+
+
+
+ uint16_t nvm__fmt__algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+
+
+ uint8_t nvm__fmt__spare__host_config__nvm_config_spare_0;
+
+
+
+
+
+ uint8_t nvm__fmt__spare__host_config__nvm_config_spare_1;
+
+
+
+
+
+ uint8_t nvm__customer_space_programmed;
+
+
+
+
+
+ uint8_t nvm__cust__i2c_device_address;
+
+
+
+
+
+ uint8_t nvm__cust__ref_spad_apply__num_requested_ref_spad;
+
+
+
+
+
+ uint8_t nvm__cust__ref_spad_man__ref_location;
+
+
+
+
+
+ uint16_t nvm__cust__mm_config__inner_offset_mm;
+
+
+
+
+
+ uint16_t nvm__cust__mm_config__outer_offset_mm;
+
+
+
+
+
+ uint16_t nvm__cust__algo_part_to_part_range_offset_mm;
+
+
+
+
+
+ uint16_t nvm__cust__algo__crosstalk_compensation_plane_offset_kcps;
+
+
+
+
+
+ uint16_t nvm__cust__algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+
+
+
+ uint16_t nvm__cust__algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+
+
+ uint8_t nvm__cust__spare__host_config__nvm_config_spare_0;
+
+
+
+
+
+ uint8_t nvm__cust__spare__host_config__nvm_config_spare_1;
+
+
+
+
+
+
+ VL53L1_cal_peak_rate_map_t fmt_peak_rate_map;
+ VL53L1_additional_offset_cal_data_t fmt_add_offset_data;
+ VL53L1_decoded_nvm_fmt_range_data_t fmt_range_data[VL53L1_NVM_MAX_FMT_RANGE_DATA];
+ VL53L1_decoded_nvm_fmt_info_t fmt_info;
+ VL53L1_decoded_nvm_ews_info_t ews_info;
+
+} VL53L1_decoded_nvm_data_t;
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_register_funcs.h b/drivers/input/misc/vl53L1/inc/vl53l1_register_funcs.h
new file mode 100644
index 000000000000..b6e2bab57832
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_register_funcs.h
@@ -0,0 +1,1693 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_REGISTER_FUNCS_H_
+#define _VL53L1_REGISTER_FUNCS_H_
+
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_static_nvm_managed(
+ VL53L1_static_nvm_managed_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_static_nvm_managed(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_static_nvm_managed_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_static_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_static_nvm_managed_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_static_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_static_nvm_managed_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_customer_nvm_managed(
+ VL53L1_customer_nvm_managed_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_customer_nvm_managed(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_customer_nvm_managed_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_customer_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_customer_nvm_managed_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_customer_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_customer_nvm_managed_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_static_config(
+ VL53L1_static_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_static_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_static_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_static_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_static_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_general_config(
+ VL53L1_general_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_general_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_general_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_general_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_general_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_timing_config(
+ VL53L1_timing_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_timing_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_timing_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_timing_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_timing_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_dynamic_config(
+ VL53L1_dynamic_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_dynamic_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_dynamic_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_dynamic_config(
+ VL53L1_DEV Dev,
+ VL53L1_dynamic_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_dynamic_config(
+ VL53L1_DEV Dev,
+ VL53L1_dynamic_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_system_control(
+ VL53L1_system_control_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_system_control(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_system_control_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_system_control(
+ VL53L1_DEV Dev,
+ VL53L1_system_control_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_system_control(
+ VL53L1_DEV Dev,
+ VL53L1_system_control_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_system_results(
+ VL53L1_system_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_system_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_core_results(
+ VL53L1_core_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_core_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_debug_results(
+ VL53L1_debug_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_debug_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_debug_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_debug_results(
+ VL53L1_DEV Dev,
+ VL53L1_debug_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_debug_results(
+ VL53L1_DEV Dev,
+ VL53L1_debug_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_nvm_copy_data(
+ VL53L1_nvm_copy_data_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_nvm_copy_data(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_nvm_copy_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_nvm_copy_data(
+ VL53L1_DEV Dev,
+ VL53L1_nvm_copy_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_nvm_copy_data(
+ VL53L1_DEV Dev,
+ VL53L1_nvm_copy_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_prev_shadow_system_results(
+ VL53L1_prev_shadow_system_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_prev_shadow_system_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_prev_shadow_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_prev_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_prev_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_prev_shadow_core_results(
+ VL53L1_prev_shadow_core_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_prev_shadow_core_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_prev_shadow_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_prev_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_prev_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_patch_debug(
+ VL53L1_patch_debug_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_patch_debug(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_patch_debug_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_patch_debug(
+ VL53L1_DEV Dev,
+ VL53L1_patch_debug_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_patch_debug(
+ VL53L1_DEV Dev,
+ VL53L1_patch_debug_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_gph_general_config(
+ VL53L1_gph_general_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_gph_general_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_gph_general_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_gph_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_general_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_gph_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_general_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_gph_static_config(
+ VL53L1_gph_static_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_gph_static_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_gph_static_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_gph_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_static_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_gph_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_static_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_gph_timing_config(
+ VL53L1_gph_timing_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_gph_timing_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_gph_timing_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_gph_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_timing_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_gph_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_timing_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_fw_internal(
+ VL53L1_fw_internal_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_fw_internal(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_fw_internal_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_fw_internal(
+ VL53L1_DEV Dev,
+ VL53L1_fw_internal_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_fw_internal(
+ VL53L1_DEV Dev,
+ VL53L1_fw_internal_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_patch_results(
+ VL53L1_patch_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_patch_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_patch_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_patch_results(
+ VL53L1_DEV Dev,
+ VL53L1_patch_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_patch_results(
+ VL53L1_DEV Dev,
+ VL53L1_patch_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_shadow_system_results(
+ VL53L1_shadow_system_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_shadow_system_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_shadow_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_shadow_core_results(
+ VL53L1_shadow_core_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_shadow_core_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_shadow_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_core_results_t *pdata);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_register_map.h b/drivers/input/misc/vl53L1/inc/vl53l1_register_map.h
new file mode 100644
index 000000000000..cb4be06573c2
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_register_map.h
@@ -0,0 +1,13113 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_REGISTER_MAP_H_
+#define _VL53L1_REGISTER_MAP_H_
+
+
+
+
+
+
+#define VL53L1_SOFT_RESET 0x0000
+
+
+
+
+
+
+
+#define VL53L1_I2C_SLAVE__DEVICE_ADDRESS 0x0001
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__VHV_REF_SEL_VDDPIX 0x0002
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__VHV_REF_SEL_VQUENCH 0x0003
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__REG_AVDD1V2_SEL 0x0004
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__FAST_OSC__TRIM 0x0005
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_OSC_MEASURED__FAST_OSC__FREQUENCY 0x0006
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_OSC_MEASURED__FAST_OSC__FREQUENCY_HI 0x0006
+
+
+
+
+
+
+
+#define VL53L1_OSC_MEASURED__FAST_OSC__FREQUENCY_LO 0x0007
+
+
+
+
+
+
+
+#define VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND 0x0008
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_CONFIG__COUNT_THRESH 0x0009
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_CONFIG__OFFSET 0x000A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_CONFIG__INIT 0x000B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0 0x000D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_1 0x000E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_2 0x000F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_3 0x0010
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_4 0x0011
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_5 0x0012
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__REF_EN_START_SELECT 0x0013
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_REF_SPAD_MAN__NUM_REQUESTED_REF_SPADS 0x0014
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_REF_SPAD_MAN__REF_LOCATION 0x0015
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS 0x0016
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS_HI 0x0016
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS_LO 0x0017
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS 0x0018
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS_HI 0x0018
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS_LO 0x0019
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS 0x001A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS_HI 0x001A
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS_LO 0x001B
+
+
+
+
+
+
+
+#define VL53L1_REF_SPAD_CHAR__TOTAL_RATE_TARGET_MCPS 0x001C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_REF_SPAD_CHAR__TOTAL_RATE_TARGET_MCPS_HI 0x001C
+
+
+
+
+
+
+
+#define VL53L1_REF_SPAD_CHAR__TOTAL_RATE_TARGET_MCPS_LO 0x001D
+
+
+
+
+
+
+
+#define VL53L1_ALGO__PART_TO_PART_RANGE_OFFSET_MM 0x001E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__PART_TO_PART_RANGE_OFFSET_MM_HI 0x001E
+
+
+
+
+
+
+
+#define VL53L1_ALGO__PART_TO_PART_RANGE_OFFSET_MM_LO 0x001F
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__INNER_OFFSET_MM 0x0020
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__INNER_OFFSET_MM_HI 0x0020
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__INNER_OFFSET_MM_LO 0x0021
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__OUTER_OFFSET_MM 0x0022
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__OUTER_OFFSET_MM_HI 0x0022
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__OUTER_OFFSET_MM_LO 0x0023
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS 0x0024
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS_HI 0x0024
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS_LO 0x0025
+
+
+
+
+
+
+
+#define VL53L1_DEBUG__CTRL 0x0026
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_TEST_MODE__CTRL 0x0027
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_CLK_GATING__CTRL 0x0028
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM_BIST__CTRL 0x0029
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM_BIST__NUM_NVM_WORDS 0x002A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM_BIST__START_ADDRESS 0x002B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_HOST_IF__STATUS 0x002C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PAD_I2C_HV__CONFIG 0x002D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PAD_I2C_HV__EXTSUP_CONFIG 0x002E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPIO_HV_PAD__CTRL 0x002F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPIO_HV_MUX__CTRL 0x0030
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPIO__TIO_HV_STATUS 0x0031
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPIO__FIO_HV_STATUS 0x0032
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__SPAD_SEL_PSWIDTH 0x0033
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__VCSEL_PULSE_WIDTH_OFFSET 0x0034
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__FAST_OSC__CONFIG_CTRL 0x0035
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SIGMA_ESTIMATOR__EFFECTIVE_PULSE_WIDTH_NS 0x0036
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SIGMA_ESTIMATOR__EFFECTIVE_AMBIENT_WIDTH_NS 0x0037
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SIGMA_ESTIMATOR__SIGMA_REF_MM 0x0038
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_VALID_HEIGHT_MM 0x0039
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SPARE_HOST_CONFIG__STATIC_CONFIG_SPARE_0 0x003A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SPARE_HOST_CONFIG__STATIC_CONFIG_SPARE_1 0x003B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__RANGE_IGNORE_THRESHOLD_MCPS 0x003C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__RANGE_IGNORE_THRESHOLD_MCPS_HI 0x003C
+
+
+
+
+
+
+
+#define VL53L1_ALGO__RANGE_IGNORE_THRESHOLD_MCPS_LO 0x003D
+
+
+
+
+
+
+
+#define VL53L1_ALGO__RANGE_IGNORE_VALID_HEIGHT_MM 0x003E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__RANGE_MIN_CLIP 0x003F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CONSISTENCY_CHECK__TOLERANCE 0x0040
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SPARE_HOST_CONFIG__STATIC_CONFIG_SPARE_2 0x0041
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__RESET_STAGES_MSB 0x0042
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__RESET_STAGES_LSB 0x0043
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH_CONFIG__STREAM_COUNT_UPDATE_VALUE 0x0044
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__STREAM_DIVIDER 0x0045
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERRUPT_CONFIG_GPIO 0x0046
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_CAL_CONFIG__VCSEL_START 0x0047
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_CAL_CONFIG__REPEAT_RATE 0x0048
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_CAL_CONFIG__REPEAT_RATE_HI 0x0048
+
+
+
+
+
+
+
+#define VL53L1_CAL_CONFIG__REPEAT_RATE_LO 0x0049
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__VCSEL_WIDTH 0x004A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_CONFIG__TIMEOUT_MACROP 0x004B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_CONFIG__TARGET 0x004C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_CONFIG__OVERRIDE 0x004D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__ROI_MODE_CONTROL 0x004F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_RATE_HIGH 0x0050
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_RATE_HIGH_HI 0x0050
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_RATE_HIGH_LO 0x0051
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_RATE_LOW 0x0052
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_RATE_LOW_HI 0x0052
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_RATE_LOW_LO 0x0053
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__MANUAL_EFFECTIVE_SPADS_SELECT 0x0054
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__MANUAL_EFFECTIVE_SPADS_SELECT_HI 0x0054
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__MANUAL_EFFECTIVE_SPADS_SELECT_LO 0x0055
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__MANUAL_BLOCK_SELECT 0x0056
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__APERTURE_ATTENUATION 0x0057
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__MAX_SPADS_LIMIT 0x0058
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__MIN_SPADS_LIMIT 0x0059
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__TIMEOUT_MACROP_A_HI 0x005A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__TIMEOUT_MACROP_A_LO 0x005B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__TIMEOUT_MACROP_B_HI 0x005C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__TIMEOUT_MACROP_B_LO 0x005D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__TIMEOUT_MACROP_A_HI 0x005E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__TIMEOUT_MACROP_A_LO 0x005F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__VCSEL_PERIOD_A 0x0060
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__TIMEOUT_MACROP_B_HI 0x0061
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__TIMEOUT_MACROP_B_LO 0x0062
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__VCSEL_PERIOD_B 0x0063
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__SIGMA_THRESH 0x0064
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__SIGMA_THRESH_HI 0x0064
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__SIGMA_THRESH_LO 0x0065
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS 0x0066
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS_HI 0x0066
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS_LO 0x0067
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__VALID_PHASE_LOW 0x0068
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__VALID_PHASE_HIGH 0x0069
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD 0x006C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD_3 0x006C
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD_2 0x006D
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD_1 0x006E
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD_0 0x006F
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__FRACTIONAL_ENABLE 0x0070
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD_0 0x0071
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_HIGH 0x0072
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_HIGH_HI 0x0072
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_HIGH_LO 0x0073
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_LOW 0x0074
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_LOW_HI 0x0074
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_LOW_LO 0x0075
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__ENABLE_XTALK_PER_QUADRANT 0x0076
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__SEED_CONFIG 0x0077
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__WOI_SD0 0x0078
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__WOI_SD1 0x0079
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__INITIAL_PHASE_SD0 0x007A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__INITIAL_PHASE_SD1 0x007B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD_1 0x007C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__FIRST_ORDER_SELECT 0x007D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__QUANTIFIER 0x007E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ROI_CONFIG__USER_ROI_CENTRE_SPAD 0x007F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE 0x0080
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__SEQUENCE_CONFIG 0x0081
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD 0x0082
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_POWER_MANAGEMENT__GO1_POWER_FORCE 0x0083
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__STREAM_COUNT_CTRL 0x0084
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__ENABLE 0x0085
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERRUPT_CLEAR 0x0086
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__MODE_START 0x0087
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__INTERRUPT_STATUS 0x0088
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__RANGE_STATUS 0x0089
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__REPORT_STATUS 0x008A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__STREAM_COUNT 0x008B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0 0x008C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x008C
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x008D
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0 0x008E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0_HI 0x008E
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0_LO 0x008F
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0 0x0090
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0_HI 0x0090
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0_LO 0x0091
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SIGMA_SD0 0x0092
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SIGMA_SD0_HI 0x0092
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SIGMA_SD0_LO 0x0093
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PHASE_SD0 0x0094
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PHASE_SD0_HI 0x0094
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PHASE_SD0_LO 0x0095
+
+
+
+
+
+
+
+#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0 0x0096
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0_HI 0x0096
+
+
+
+
+
+
+
+#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0_LO 0x0097
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0 0x0098
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0_HI 0x0098
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0_LO 0x0099
+
+
+
+
+
+
+
+#define VL53L1_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0 0x009A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x009A
+
+
+
+
+
+
+
+#define VL53L1_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x009B
+
+
+
+
+
+
+
+#define VL53L1_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0 0x009C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x009C
+
+
+
+
+
+
+
+#define VL53L1_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x009D
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0 0x009E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0_HI 0x009E
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0_LO 0x009F
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1 0x00A0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1_HI 0x00A0
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1_LO 0x00A1
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1 0x00A2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1_HI 0x00A2
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1_LO 0x00A3
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1 0x00A4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1_HI 0x00A4
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1_LO 0x00A5
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SIGMA_SD1 0x00A6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SIGMA_SD1_HI 0x00A6
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SIGMA_SD1_LO 0x00A7
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PHASE_SD1 0x00A8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PHASE_SD1_HI 0x00A8
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PHASE_SD1_LO 0x00A9
+
+
+
+
+
+
+
+#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1 0x00AA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1_HI 0x00AA
+
+
+
+
+
+
+
+#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1_LO 0x00AB
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_0_SD1 0x00AC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_0_SD1_HI 0x00AC
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_0_SD1_LO 0x00AD
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_1_SD1 0x00AE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_1_SD1_HI 0x00AE
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_1_SD1_LO 0x00AF
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_2_SD1 0x00B0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_2_SD1_HI 0x00B0
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_2_SD1_LO 0x00B1
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_3_SD1 0x00B2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__THRESH_INFO 0x00B3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0 0x00B4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_3 0x00B4
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_2 0x00B5
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_1 0x00B6
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_0 0x00B7
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0 0x00B8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_3 0x00B8
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_2 0x00B9
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_1 0x00BA
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_0 0x00BB
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0 0x00BC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_3 0x00BC
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_2 0x00BD
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_1 0x00BE
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_0 0x00BF
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0 0x00C0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_3 0x00C0
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_2 0x00C1
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_1 0x00C2
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_0 0x00C3
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1 0x00C4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_3 0x00C4
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_2 0x00C5
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_1 0x00C6
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_0 0x00C7
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1 0x00C8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_3 0x00C8
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_2 0x00C9
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_1 0x00CA
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_0 0x00CB
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1 0x00CC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_3 0x00CC
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_2 0x00CD
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_1 0x00CE
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_0 0x00CF
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1 0x00D0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_3 0x00D0
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_2 0x00D1
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_1 0x00D2
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_0 0x00D3
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SPARE_0 0x00D4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_RESULT__REFERENCE_PHASE 0x00D6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_RESULT__REFERENCE_PHASE_HI 0x00D6
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_RESULT__REFERENCE_PHASE_LO 0x00D7
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_RESULT__VCSEL_START 0x00D8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_REF_SPAD_CHAR_RESULT__NUM_ACTUAL_REF_SPADS 0x00D9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_REF_SPAD_CHAR_RESULT__REF_LOCATION 0x00DA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__COLDBOOT_STATUS 0x00DB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__SEARCH_RESULT 0x00DC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__LATEST_SETTING 0x00DD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__OSC_CALIBRATE_VAL 0x00DE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__OSC_CALIBRATE_VAL_HI 0x00DE
+
+
+
+
+
+
+
+#define VL53L1_RESULT__OSC_CALIBRATE_VAL_LO 0x00DF
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__POWERDOWN_GO1 0x00E0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__REF_BG_CTRL 0x00E1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__REGDVDD1V2_CTRL 0x00E2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__OSC_SLOW_CTRL 0x00E3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_TEST_MODE__STATUS 0x00E4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__SYSTEM_STATUS 0x00E5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__MODE_STATUS 0x00E6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__SECONDARY_MODE_STATUS 0x00E7
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__CAL_REPEAT_RATE_COUNTER 0x00E8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__CAL_REPEAT_RATE_COUNTER_HI 0x00E8
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__CAL_REPEAT_RATE_COUNTER_LO 0x00E9
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__HISTOGRAM_BIN 0x00EA
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_HIGH 0x00EC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_HIGH_HI 0x00EC
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_HIGH_LO 0x00ED
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_LOW 0x00EE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_LOW_HI 0x00EE
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_LOW_LO 0x00EF
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__ENABLE_XTALK_PER_QUADRANT 0x00F0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SPARE_0 0x00F1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SD_CONFIG__WOI_SD0 0x00F2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SD_CONFIG__WOI_SD1 0x00F3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SD_CONFIG__INITIAL_PHASE_SD0 0x00F4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SD_CONFIG__INITIAL_PHASE_SD1 0x00F5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SD_CONFIG__FIRST_ORDER_SELECT 0x00F6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SD_CONFIG__QUANTIFIER 0x00F7
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__ROI_CONFIG__USER_ROI_CENTRE_SPAD 0x00F8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE 0x00F9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__SEQUENCE_CONFIG 0x00FA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__GPH_ID 0x00FB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERRUPT_SET 0x00FC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_MANAGER__ENABLES 0x00FD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_MANAGER__CLEAR 0x00FE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_MANAGER__STATUS 0x00FF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_TO_HOST_BANK__WR_ACCESS_EN 0x0100
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_POWER_MANAGEMENT__GO1_RESET_STATUS 0x0101
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PAD_STARTUP_MODE__VALUE_RO 0x0102
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PAD_STARTUP_MODE__VALUE_CTRL 0x0103
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PLL_PERIOD_US 0x0104
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PLL_PERIOD_US_3 0x0104
+
+
+
+
+
+
+
+#define VL53L1_PLL_PERIOD_US_2 0x0105
+
+
+
+
+
+
+
+#define VL53L1_PLL_PERIOD_US_1 0x0106
+
+
+
+
+
+
+
+#define VL53L1_PLL_PERIOD_US_0 0x0107
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_SCHEDULER__DATA_OUT 0x0108
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_SCHEDULER__DATA_OUT_3 0x0108
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_SCHEDULER__DATA_OUT_2 0x0109
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_SCHEDULER__DATA_OUT_1 0x010A
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_SCHEDULER__DATA_OUT_0 0x010B
+
+
+
+
+
+
+
+#define VL53L1_NVM_BIST__COMPLETE 0x010C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM_BIST__STATUS 0x010D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_IDENTIFICATION__MODEL_ID 0x010F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_IDENTIFICATION__MODULE_TYPE 0x0110
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_IDENTIFICATION__REVISION_ID 0x0111
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_IDENTIFICATION__MODULE_ID 0x0112
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_IDENTIFICATION__MODULE_ID_HI 0x0112
+
+
+
+
+
+
+
+#define VL53L1_IDENTIFICATION__MODULE_ID_LO 0x0113
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__FAST_OSC__TRIM_MAX 0x0114
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__FAST_OSC__FREQ_SET 0x0115
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__VCSEL_TRIM 0x0116
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__VCSEL_SELION 0x0117
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__VCSEL_SELION_MAX 0x0118
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PROTECTED_LASER_SAFETY__LOCK_BIT 0x0119
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_LASER_SAFETY__KEY 0x011A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_LASER_SAFETY__KEY_RO 0x011B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_LASER_SAFETY__CLIP 0x011C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_LASER_SAFETY__MULT 0x011D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_0 0x011E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_1 0x011F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_2 0x0120
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_3 0x0121
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_4 0x0122
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_5 0x0123
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_6 0x0124
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_7 0x0125
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_8 0x0126
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_9 0x0127
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_10 0x0128
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_11 0x0129
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_12 0x012A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_13 0x012B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_14 0x012C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_15 0x012D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_16 0x012E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_17 0x012F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_18 0x0130
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_19 0x0131
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_20 0x0132
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_21 0x0133
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_22 0x0134
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_23 0x0135
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_24 0x0136
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_25 0x0137
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_26 0x0138
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_27 0x0139
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_28 0x013A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_29 0x013B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_30 0x013C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_31 0x013D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD 0x013E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ROI_CONFIG__MODE_ROI_XY_SIZE 0x013F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GO2_HOST_BANK_ACCESS__OVERRIDE 0x0300
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLICAND 0x0400
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLICAND_3 0x0400
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLICAND_2 0x0401
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLICAND_1 0x0402
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLICAND_0 0x0403
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLIER 0x0404
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLIER_3 0x0404
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLIER_2 0x0405
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLIER_1 0x0406
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLIER_0 0x0407
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_HI 0x0408
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_HI_3 0x0408
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_HI_2 0x0409
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_HI_1 0x040A
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_HI_0 0x040B
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_LO 0x040C
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_LO_3 0x040C
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_LO_2 0x040D
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_LO_1 0x040E
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_LO_0 0x040F
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__START 0x0410
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__STATUS 0x0411
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__START 0x0412
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__STATUS 0x0413
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVIDEND 0x0414
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVIDEND_3 0x0414
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVIDEND_2 0x0415
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVIDEND_1 0x0416
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVIDEND_0 0x0417
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVISOR 0x0418
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVISOR_3 0x0418
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVISOR_2 0x0419
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVISOR_1 0x041A
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVISOR_0 0x041B
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__QUOTIENT 0x041C
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__QUOTIENT_3 0x041C
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__QUOTIENT_2 0x041D
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__QUOTIENT_1 0x041E
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__QUOTIENT_0 0x041F
+
+
+
+
+
+
+
+#define VL53L1_TIMER0__VALUE_IN 0x0420
+
+
+
+
+
+
+
+#define VL53L1_TIMER0__VALUE_IN_3 0x0420
+
+
+
+
+
+
+
+#define VL53L1_TIMER0__VALUE_IN_2 0x0421
+
+
+
+
+
+
+
+#define VL53L1_TIMER0__VALUE_IN_1 0x0422
+
+
+
+
+
+
+
+#define VL53L1_TIMER0__VALUE_IN_0 0x0423
+
+
+
+
+
+
+
+#define VL53L1_TIMER1__VALUE_IN 0x0424
+
+
+
+
+
+
+
+#define VL53L1_TIMER1__VALUE_IN_3 0x0424
+
+
+
+
+
+
+
+#define VL53L1_TIMER1__VALUE_IN_2 0x0425
+
+
+
+
+
+
+
+#define VL53L1_TIMER1__VALUE_IN_1 0x0426
+
+
+
+
+
+
+
+#define VL53L1_TIMER1__VALUE_IN_0 0x0427
+
+
+
+
+
+
+
+#define VL53L1_TIMER0__CTRL 0x0428
+
+
+
+
+
+
+
+#define VL53L1_TIMER1__CTRL 0x0429
+
+
+
+
+
+
+
+#define VL53L1_MCU_GENERAL_PURPOSE__GP_0 0x042C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_GENERAL_PURPOSE__GP_1 0x042D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_GENERAL_PURPOSE__GP_2 0x042E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_GENERAL_PURPOSE__GP_3 0x042F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__CONFIG 0x0430
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__OFFSET_CORRECTED_RANGE 0x0432
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__OFFSET_CORRECTED_RANGE_HI 0x0432
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__OFFSET_CORRECTED_RANGE_LO 0x0433
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_4 0x0434
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_4_3 0x0434
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_4_2 0x0435
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_4_1 0x0436
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_4_0 0x0437
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AMBIENT_DURATION_PRE_CALC 0x0438
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AMBIENT_DURATION_PRE_CALC_HI 0x0438
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AMBIENT_DURATION_PRE_CALC_LO 0x0439
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_VCSEL_PERIOD 0x043C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_5 0x043D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_TOTAL_PERIODS 0x043E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_TOTAL_PERIODS_HI 0x043E
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_TOTAL_PERIODS_LO 0x043F
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ACCUM_PHASE 0x0440
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ACCUM_PHASE_3 0x0440
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ACCUM_PHASE_2 0x0441
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ACCUM_PHASE_1 0x0442
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ACCUM_PHASE_0 0x0443
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_SIGNAL_EVENTS 0x0444
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_SIGNAL_EVENTS_3 0x0444
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_SIGNAL_EVENTS_2 0x0445
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_SIGNAL_EVENTS_1 0x0446
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_SIGNAL_EVENTS_0 0x0447
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_AMBIENT_EVENTS 0x0448
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_AMBIENT_EVENTS_3 0x0448
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_AMBIENT_EVENTS_2 0x0449
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_AMBIENT_EVENTS_1 0x044A
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_AMBIENT_EVENTS_0 0x044B
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_6 0x044C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_6_HI 0x044C
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_6_LO 0x044D
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ADJUST_VCSEL_PERIOD 0x044E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ADJUST_VCSEL_PERIOD_HI 0x044E
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ADJUST_VCSEL_PERIOD_LO 0x044F
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__NUM_SPADS 0x0450
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__NUM_SPADS_HI 0x0450
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__NUM_SPADS_LO 0x0451
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PHASE_OUTPUT 0x0452
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PHASE_OUTPUT_HI 0x0452
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PHASE_OUTPUT_LO 0x0453
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__RATE_PER_SPAD_MCPS 0x0454
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__RATE_PER_SPAD_MCPS_3 0x0454
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__RATE_PER_SPAD_MCPS_2 0x0455
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__RATE_PER_SPAD_MCPS_1 0x0456
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__RATE_PER_SPAD_MCPS_0 0x0457
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_7 0x0458
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_8 0x0459
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PEAK_SIGNAL_RATE_MCPS 0x045A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PEAK_SIGNAL_RATE_MCPS_HI 0x045A
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PEAK_SIGNAL_RATE_MCPS_LO 0x045B
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AVG_SIGNAL_RATE_MCPS 0x045C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AVG_SIGNAL_RATE_MCPS_HI 0x045C
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AVG_SIGNAL_RATE_MCPS_LO 0x045D
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AMBIENT_RATE_MCPS 0x045E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AMBIENT_RATE_MCPS_HI 0x045E
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AMBIENT_RATE_MCPS_LO 0x045F
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__XTALK 0x0460
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__XTALK_HI 0x0460
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__XTALK_LO 0x0461
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__CALC_STATUS 0x0462
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__DEBUG 0x0463
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PEAK_SIGNAL_RATE_XTALK_CORR_MCPS 0x0464
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PEAK_SIGNAL_RATE_XTALK_CORR_MCPS_HI 0x0464
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PEAK_SIGNAL_RATE_XTALK_CORR_MCPS_LO 0x0465
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_0 0x0468
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_1 0x0469
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_2 0x046A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_3 0x046B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PATCH__CTRL 0x0470
+
+
+
+
+
+
+
+#define VL53L1_PATCH__JMP_ENABLES 0x0472
+
+
+
+
+
+
+
+#define VL53L1_PATCH__JMP_ENABLES_HI 0x0472
+
+
+
+
+
+
+
+#define VL53L1_PATCH__JMP_ENABLES_LO 0x0473
+
+
+
+
+
+
+
+#define VL53L1_PATCH__DATA_ENABLES 0x0474
+
+
+
+
+
+
+
+#define VL53L1_PATCH__DATA_ENABLES_HI 0x0474
+
+
+
+
+
+
+
+#define VL53L1_PATCH__DATA_ENABLES_LO 0x0475
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_0 0x0476
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_0_HI 0x0476
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_0_LO 0x0477
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_1 0x0478
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_1_HI 0x0478
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_1_LO 0x0479
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_2 0x047A
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_2_HI 0x047A
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_2_LO 0x047B
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_3 0x047C
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_3_HI 0x047C
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_3_LO 0x047D
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_4 0x047E
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_4_HI 0x047E
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_4_LO 0x047F
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_5 0x0480
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_5_HI 0x0480
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_5_LO 0x0481
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_6 0x0482
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_6_HI 0x0482
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_6_LO 0x0483
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_7 0x0484
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_7_HI 0x0484
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_7_LO 0x0485
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_8 0x0486
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_8_HI 0x0486
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_8_LO 0x0487
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_9 0x0488
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_9_HI 0x0488
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_9_LO 0x0489
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_10 0x048A
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_10_HI 0x048A
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_10_LO 0x048B
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_11 0x048C
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_11_HI 0x048C
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_11_LO 0x048D
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_12 0x048E
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_12_HI 0x048E
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_12_LO 0x048F
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_13 0x0490
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_13_HI 0x0490
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_13_LO 0x0491
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_14 0x0492
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_14_HI 0x0492
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_14_LO 0x0493
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_15 0x0494
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_15_HI 0x0494
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_15_LO 0x0495
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_0 0x0496
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_0_HI 0x0496
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_0_LO 0x0497
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_1 0x0498
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_1_HI 0x0498
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_1_LO 0x0499
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_2 0x049A
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_2_HI 0x049A
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_2_LO 0x049B
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_3 0x049C
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_3_HI 0x049C
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_3_LO 0x049D
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_4 0x049E
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_4_HI 0x049E
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_4_LO 0x049F
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_5 0x04A0
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_5_HI 0x04A0
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_5_LO 0x04A1
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_6 0x04A2
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_6_HI 0x04A2
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_6_LO 0x04A3
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_7 0x04A4
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_7_HI 0x04A4
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_7_LO 0x04A5
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_8 0x04A6
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_8_HI 0x04A6
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_8_LO 0x04A7
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_9 0x04A8
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_9_HI 0x04A8
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_9_LO 0x04A9
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_10 0x04AA
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_10_HI 0x04AA
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_10_LO 0x04AB
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_11 0x04AC
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_11_HI 0x04AC
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_11_LO 0x04AD
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_12 0x04AE
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_12_HI 0x04AE
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_12_LO 0x04AF
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_13 0x04B0
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_13_HI 0x04B0
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_13_LO 0x04B1
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_14 0x04B2
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_14_HI 0x04B2
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_14_LO 0x04B3
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_15 0x04B4
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_15_HI 0x04B4
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_15_LO 0x04B5
+
+
+
+
+
+
+
+#define VL53L1_SPI_ASYNC_MUX__CTRL 0x04C0
+
+
+
+
+
+
+
+#define VL53L1_CLK__CONFIG 0x04C4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPIO_LV_MUX__CTRL 0x04CC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPIO_LV_PAD__CTRL 0x04CD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PAD_I2C_LV__CONFIG 0x04D0
+
+
+
+
+
+
+
+#define VL53L1_PAD_STARTUP_MODE__VALUE_RO_GO1 0x04D4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_HOST_IF__STATUS_GO1 0x04D5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_CLK_GATING__CTRL 0x04D8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_TEST__BIST_ROM_CTRL 0x04E0
+
+
+
+
+
+
+
+#define VL53L1_TEST__BIST_ROM_RESULT 0x04E1
+
+
+
+
+
+
+
+#define VL53L1_TEST__BIST_ROM_MCU_SIG 0x04E2
+
+
+
+
+
+
+
+#define VL53L1_TEST__BIST_ROM_MCU_SIG_HI 0x04E2
+
+
+
+
+
+
+
+#define VL53L1_TEST__BIST_ROM_MCU_SIG_LO 0x04E3
+
+
+
+
+
+
+
+#define VL53L1_TEST__BIST_RAM_CTRL 0x04E4
+
+
+
+
+
+
+
+#define VL53L1_TEST__BIST_RAM_RESULT 0x04E5
+
+
+
+
+
+
+
+#define VL53L1_TEST__TMC 0x04E8
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_MIN_THRESHOLD 0x04F0
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_MIN_THRESHOLD_HI 0x04F0
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_MIN_THRESHOLD_LO 0x04F1
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_MAX_THRESHOLD 0x04F2
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_MAX_THRESHOLD_HI 0x04F2
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_MAX_THRESHOLD_LO 0x04F3
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_COUNT_OUT 0x04F4
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_COUNT_OUT_HI 0x04F4
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_COUNT_OUT_LO 0x04F5
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_GONOGO 0x04F6
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_CTRL 0x04F7
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__DEVICE_ID 0x0680
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REVISION_ID 0x0681
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CLK_CTRL1 0x0683
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CLK_CTRL2 0x0684
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__WOI_1 0x0685
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__WOI_REF_1 0x0686
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__START_RANGING 0x0687
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__LOW_LIMIT_1 0x0690
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__HIGH_LIMIT_1 0x0691
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__LOW_LIMIT_REF_1 0x0692
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__HIGH_LIMIT_REF_1 0x0693
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__QUANTIFIER_1_MSB 0x0694
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__QUANTIFIER_1_LSB 0x0695
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__QUANTIFIER_REF_1_MSB 0x0696
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__QUANTIFIER_REF_1_LSB 0x0697
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_OFFSET_1_MSB 0x0698
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_OFFSET_1_LSB 0x0699
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_OFFSET_REF_1_MSB 0x069A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_OFFSET_REF_1_LSB 0x069B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__FILTER_STRENGTH_1 0x069C
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__FILTER_STRENGTH_REF_1 0x069D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_EVENT_LIMIT_1_MSB 0x069E
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_EVENT_LIMIT_1_LSB 0x069F
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_EVENT_LIMIT_REF_1_MSB 0x06A0
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_EVENT_LIMIT_REF_1_LSB 0x06A1
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TIMEOUT_OVERALL_PERIODS_MSB 0x06A4
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TIMEOUT_OVERALL_PERIODS_LSB 0x06A5
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__INVERT_HW 0x06A6
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__FORCE_HW 0x06A7
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STATIC_HW_VALUE 0x06A8
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__FORCE_CONTINUOUS_AMBIENT 0x06A9
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TEST_PHASE_SELECT_TO_FILTER 0x06AA
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TEST_PHASE_SELECT_TO_TIMING_GEN 0x06AB
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__INITIAL_PHASE_VALUE_1 0x06AC
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__INITIAL_PHASE_VALUE_REF_1 0x06AD
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__FORCE_UP_IN 0x06AE
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__FORCE_DN_IN 0x06AF
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STATIC_UP_VALUE_1 0x06B0
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STATIC_UP_VALUE_REF_1 0x06B1
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STATIC_DN_VALUE_1 0x06B2
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STATIC_DN_VALUE_REF_1 0x06B3
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__MONITOR_UP_DN 0x06B4
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__INVERT_UP_DN 0x06B5
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CPUMP_1 0x06B6
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CPUMP_2 0x06B7
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CPUMP_3 0x06B8
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__OSC_1 0x06B9
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__PLL_1 0x06BB
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__PLL_2 0x06BC
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REFERENCE_1 0x06BD
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REFERENCE_3 0x06BF
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REFERENCE_4 0x06C0
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REFERENCE_5 0x06C1
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REGAVDD1V2 0x06C3
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CALIB_1 0x06C4
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CALIB_2 0x06C5
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CALIB_3 0x06C6
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TST_MUX_SEL1 0x06C9
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TST_MUX_SEL2 0x06CA
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TST_MUX 0x06CB
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__GPIO_OUT_TESTMUX 0x06CC
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CUSTOM_FE 0x06CD
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CUSTOM_FE_2 0x06CE
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_READOUT 0x06CF
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_READOUT_1 0x06D0
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_READOUT_2 0x06D1
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_PS 0x06D2
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__LASER_SAFETY_2 0x06D4
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__MODE 0x0780
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__PDN 0x0781
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__PROGN 0x0782
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__READN 0x0783
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__PULSE_WIDTH_MSB 0x0784
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__PULSE_WIDTH_LSB 0x0785
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__HV_RISE_MSB 0x0786
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__HV_RISE_LSB 0x0787
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__HV_FALL_MSB 0x0788
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__HV_FALL_LSB 0x0789
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__TST 0x078A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__TESTREAD 0x078B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAIN_MMM 0x078C
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAIN_LMM 0x078D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAIN_LLM 0x078E
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAIN_LLL 0x078F
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAOUT_MMM 0x0790
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAOUT_LMM 0x0791
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAOUT_LLM 0x0792
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAOUT_LLL 0x0793
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__ADDR 0x0794
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAOUT_ECC 0x0795
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_0 0x0796
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_1 0x0797
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_2 0x0798
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_3 0x0799
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_4 0x079A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_5 0x079B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_6 0x079C
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_7 0x079D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_8 0x079E
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_9 0x079F
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_10 0x07A0
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_11 0x07A1
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_12 0x07A2
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_13 0x07A3
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_14 0x07A4
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_15 0x07A5
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_16 0x07A6
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_17 0x07A7
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_SHIFT_EN 0x07BA
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_DISABLE_CTRL 0x07BB
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_EN_SHIFT_OUT_DEBUG 0x07BC
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPI_MODE 0x07BD
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__GPIO_DIR 0x07BE
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_PERIOD 0x0880
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_START 0x0881
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_STOP 0x0882
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_1 0x0885
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_STATUS 0x088D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STATUS 0x0980
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__LASER_CONTINUITY_STATE 0x0981
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_1_MMM 0x0982
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_1_LMM 0x0983
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_1_LLM 0x0984
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_1_LLL 0x0985
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_REF_1_MMM 0x0986
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_REF_1_LMM 0x0987
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_REF_1_LLM 0x0988
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_REF_1_LLL 0x0989
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_1_MMM 0x098A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_1_LMM 0x098B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_1_LLM 0x098C
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_1_LLL 0x098D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_1_MMM 0x098E
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_1_LMM 0x098F
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_1_LLM 0x0990
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_1_LLL 0x0991
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_1_MMM 0x0992
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_1_LMM 0x0993
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_1_LLM 0x0994
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_1_LLL 0x0995
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TOTAL_PERIODS_ELAPSED_1_MM 0x0996
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TOTAL_PERIODS_ELAPSED_1_LM 0x0997
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TOTAL_PERIODS_ELAPSED_1_LL 0x0998
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_MISMATCH_MM 0x0999
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_MISMATCH_LM 0x099A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_MISMATCH_LL 0x099B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_REF_1_MMM 0x099C
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_REF_1_LMM 0x099D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_REF_1_LLM 0x099E
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_REF_1_LLL 0x099F
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_REF_1_MMM 0x09A0
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_REF_1_LMM 0x09A1
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_REF_1_LLM 0x09A2
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_REF_1_LLL 0x09A3
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_REF_1_MMM 0x09A4
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_REF_1_LMM 0x09A5
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_REF_1_LLM 0x09A6
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_REF_1_LLL 0x09A7
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TOTAL_PERIODS_ELAPSED_REF_1_MM 0x09A8
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TOTAL_PERIODS_ELAPSED_REF_1_LM 0x09A9
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TOTAL_PERIODS_ELAPSED_REF_1_LL 0x09AA
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_MISMATCH_REF_MM 0x09AB
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_MISMATCH_REF_LM 0x09AC
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_MISMATCH_REF_LL 0x09AD
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__GPIO_CONFIG__A0 0x0A00
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RESET_CONTROL__A0 0x0A01
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__INTR_MANAGER__A0 0x0A02
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__POWER_FSM_TIME_OSC__A0 0x0A06
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_ATEST__A0 0x0A07
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_PERIOD_CLIPPED__A0 0x0A08
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_STOP_CLIPPED__A0 0x0A09
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CALIB_2__A0 0x0A0A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STOP_CONDITION__A0 0x0A0B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STATUS_RESET__A0 0x0A0C
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__READOUT_CFG__A0 0x0A0D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__WINDOW_SETTING__A0 0x0A0E
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_DELAY__A0 0x0A1A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REFERENCE_2__A0 0x0A1B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REGAVDD1V2__A0 0x0A1D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TST_MUX__A0 0x0A1F
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CUSTOM_FE_2__A0 0x0A20
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_READOUT__A0 0x0A21
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CPUMP_1__A0 0x0A22
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPARE_REGISTER__A0 0x0A23
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_CONT_STAGE5_BYPASS__A0 0x0A24
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_18 0x0A25
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_19 0x0A26
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_20 0x0A27
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_21 0x0A28
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_22 0x0A29
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_23 0x0A2A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_24 0x0A2B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_25 0x0A2C
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_26 0x0A2D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_27 0x0A2E
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_28 0x0A2F
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_29 0x0A30
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_30 0x0A31
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_31 0x0A32
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REF_SPAD_EN_0__EWOK 0x0A33
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REF_SPAD_EN_1__EWOK 0x0A34
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REF_SPAD_EN_2__EWOK 0x0A35
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REF_SPAD_EN_3__EWOK 0x0A36
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REF_SPAD_EN_4__EWOK 0x0A37
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REF_SPAD_EN_5__EWOK 0x0A38
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REF_EN_START_SELECT 0x0A39
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REGDVDD1V2_ATEST__EWOK 0x0A41
+
+
+
+
+
+
+
+#define VL53L1_SOFT_RESET_GO1 0x0B00
+
+
+
+
+
+
+
+#define VL53L1_PRIVATE__PATCH_BASE_ADDR_RSLV 0x0E00
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__INTERRUPT_STATUS 0x0ED0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__RANGE_STATUS 0x0ED1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__REPORT_STATUS 0x0ED2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__STREAM_COUNT 0x0ED3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0 0x0ED4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x0ED4
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x0ED5
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0 0x0ED6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0_HI 0x0ED6
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0_LO 0x0ED7
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0 0x0ED8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0_HI 0x0ED8
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0_LO 0x0ED9
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SIGMA_SD0 0x0EDA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SIGMA_SD0_HI 0x0EDA
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SIGMA_SD0_LO 0x0EDB
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PHASE_SD0 0x0EDC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PHASE_SD0_HI 0x0EDC
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PHASE_SD0_LO 0x0EDD
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0 0x0EDE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0_HI 0x0EDE
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0_LO 0x0EDF
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0 0x0EE0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0_HI 0x0EE0
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0_LO 0x0EE1
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0 0x0EE2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x0EE2
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x0EE3
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0 0x0EE4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x0EE4
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x0EE5
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0 0x0EE6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0_HI 0x0EE6
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0_LO 0x0EE7
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1 0x0EE8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1_HI 0x0EE8
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1_LO 0x0EE9
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1 0x0EEA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1_HI 0x0EEA
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1_LO 0x0EEB
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1 0x0EEC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1_HI 0x0EEC
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1_LO 0x0EED
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SIGMA_SD1 0x0EEE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SIGMA_SD1_HI 0x0EEE
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SIGMA_SD1_LO 0x0EEF
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PHASE_SD1 0x0EF0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PHASE_SD1_HI 0x0EF0
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PHASE_SD1_LO 0x0EF1
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1 0x0EF2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1_HI 0x0EF2
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1_LO 0x0EF3
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_0_SD1 0x0EF4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_0_SD1_HI 0x0EF4
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_0_SD1_LO 0x0EF5
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_1_SD1 0x0EF6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_1_SD1_HI 0x0EF6
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_1_SD1_LO 0x0EF7
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_2_SD1 0x0EF8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_2_SD1_HI 0x0EF8
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_2_SD1_LO 0x0EF9
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_3_SD1 0x0EFA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_3_SD1_HI 0x0EFA
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_3_SD1_LO 0x0EFB
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0 0x0EFC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_3 0x0EFC
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_2 0x0EFD
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_1 0x0EFE
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_0 0x0EFF
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0 0x0F00
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_3 0x0F00
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_2 0x0F01
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_1 0x0F02
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_0 0x0F03
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0 0x0F04
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_3 0x0F04
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_2 0x0F05
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_1 0x0F06
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_0 0x0F07
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0 0x0F08
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_3 0x0F08
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_2 0x0F09
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_1 0x0F0A
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_0 0x0F0B
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1 0x0F0C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_3 0x0F0C
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_2 0x0F0D
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_1 0x0F0E
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_0 0x0F0F
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1 0x0F10
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_3 0x0F10
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_2 0x0F11
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_1 0x0F12
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_0 0x0F13
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1 0x0F14
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_3 0x0F14
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_2 0x0F15
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_1 0x0F16
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_0 0x0F17
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1 0x0F18
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_3 0x0F18
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_2 0x0F19
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_1 0x0F1A
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_0 0x0F1B
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SPARE_0 0x0F1C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DEBUG_STATUS 0x0F20
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DEBUG_STAGE 0x0F21
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH 0x0F24
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH_HI 0x0F24
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH_LO 0x0F25
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_RATE_LOW 0x0F26
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_RATE_LOW_HI 0x0F26
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_RATE_LOW_LO 0x0F27
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__INTERRUPT_CONFIG_GPIO 0x0F28
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__DSS_CONFIG__ROI_MODE_CONTROL 0x0F2F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__DSS_CONFIG__MANUAL_EFFECTIVE_SPADS_SELECT 0x0F30
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__DSS_CONFIG__MANUAL_EFFECTIVE_SPADS_SELECT_HI 0x0F30
+
+
+
+
+
+
+
+#define VL53L1_GPH__DSS_CONFIG__MANUAL_EFFECTIVE_SPADS_SELECT_LO 0x0F31
+
+
+
+
+
+
+
+#define VL53L1_GPH__DSS_CONFIG__MANUAL_BLOCK_SELECT 0x0F32
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__DSS_CONFIG__MAX_SPADS_LIMIT 0x0F33
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__DSS_CONFIG__MIN_SPADS_LIMIT 0x0F34
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_A_HI 0x0F36
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_A_LO 0x0F37
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_B_HI 0x0F38
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_B_LO 0x0F39
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__TIMEOUT_MACROP_A_HI 0x0F3A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__TIMEOUT_MACROP_A_LO 0x0F3B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__VCSEL_PERIOD_A 0x0F3C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__VCSEL_PERIOD_B 0x0F3D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__TIMEOUT_MACROP_B_HI 0x0F3E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__TIMEOUT_MACROP_B_LO 0x0F3F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__SIGMA_THRESH 0x0F40
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__SIGMA_THRESH_HI 0x0F40
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__SIGMA_THRESH_LO 0x0F41
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS 0x0F42
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS_HI 0x0F42
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS_LO 0x0F43
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__VALID_PHASE_LOW 0x0F44
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__VALID_PHASE_HIGH 0x0F45
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__INTERNAL_STREAM_COUNT_DIV 0x0F46
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__INTERNAL_STREAM_COUNTER_VAL 0x0F47
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__ROI_CTRL 0x0F54
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__SPARE_1 0x0F55
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__SPARE_2 0x0F56
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__SPARE_3 0x0F57
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__SPARE_4 0x0F58
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__SPARE_5 0x0F59
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__SPARE_6 0x0F5A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__SPARE_7 0x0F5B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_0 0x0F5C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_1 0x0F5D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_2 0x0F5E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_3 0x0F5F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_4 0x0F60
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_5 0x0F61
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_6 0x0F62
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_7 0x0F63
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_8 0x0F64
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_9 0x0F65
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_10 0x0F66
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_11 0x0F67
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_12 0x0F68
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_13 0x0F69
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_14 0x0F6A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_15 0x0F6B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_16 0x0F6C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_17 0x0F6D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_18 0x0F6E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_19 0x0F6F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_20 0x0F70
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_21 0x0F71
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_22 0x0F72
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_23 0x0F73
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_24 0x0F74
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_25 0x0F75
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_26 0x0F76
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_27 0x0F77
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_28 0x0F78
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_29 0x0F79
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_30 0x0F7A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_31 0x0F7B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_0 0x0F7C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_1 0x0F7D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__MODE_ROI_0 0x0F7E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__MODE_ROI_1 0x0F7F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SIGMA_ESTIMATOR_CALC__SPARE_0 0x0F80
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__PEAK_SIGNAL_RATE_MCPS 0x0F82
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__PEAK_SIGNAL_RATE_MCPS_HI 0x0F82
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__PEAK_SIGNAL_RATE_MCPS_LO 0x0F83
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__SIGNAL_TOTAL_EVENTS_REF 0x0F84
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__SIGNAL_TOTAL_EVENTS_REF_3 0x0F84
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__SIGNAL_TOTAL_EVENTS_REF_2 0x0F85
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__SIGNAL_TOTAL_EVENTS_REF_1 0x0F86
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__SIGNAL_TOTAL_EVENTS_REF_0 0x0F87
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_RESULT__PHASE_OUTPUT_REF 0x0F88
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_RESULT__PHASE_OUTPUT_REF_HI 0x0F88
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_RESULT__PHASE_OUTPUT_REF_LO 0x0F89
+
+
+
+
+
+
+
+#define VL53L1_DSS_RESULT__TOTAL_RATE_PER_SPAD 0x0F8A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_RESULT__TOTAL_RATE_PER_SPAD_HI 0x0F8A
+
+
+
+
+
+
+
+#define VL53L1_DSS_RESULT__TOTAL_RATE_PER_SPAD_LO 0x0F8B
+
+
+
+
+
+
+
+#define VL53L1_DSS_RESULT__ENABLED_BLOCKS 0x0F8C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_RESULT__NUM_REQUESTED_SPADS 0x0F8E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_RESULT__NUM_REQUESTED_SPADS_HI 0x0F8E
+
+
+
+
+
+
+
+#define VL53L1_DSS_RESULT__NUM_REQUESTED_SPADS_LO 0x0F8F
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__INNER_INTERSECTION_RATE 0x0F92
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__INNER_INTERSECTION_RATE_HI 0x0F92
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__INNER_INTERSECTION_RATE_LO 0x0F93
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__OUTER_COMPLEMENT_RATE 0x0F94
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__OUTER_COMPLEMENT_RATE_HI 0x0F94
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__OUTER_COMPLEMENT_RATE_LO 0x0F95
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__TOTAL_OFFSET 0x0F96
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__TOTAL_OFFSET_HI 0x0F96
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__TOTAL_OFFSET_LO 0x0F97
+
+
+
+
+
+
+
+#define VL53L1_XTALK_CALC__XTALK_FOR_ENABLED_SPADS 0x0F98
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_XTALK_CALC__XTALK_FOR_ENABLED_SPADS_3 0x0F98
+
+
+
+
+
+
+
+#define VL53L1_XTALK_CALC__XTALK_FOR_ENABLED_SPADS_2 0x0F99
+
+
+
+
+
+
+
+#define VL53L1_XTALK_CALC__XTALK_FOR_ENABLED_SPADS_1 0x0F9A
+
+
+
+
+
+
+
+#define VL53L1_XTALK_CALC__XTALK_FOR_ENABLED_SPADS_0 0x0F9B
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_USER_ROI_KCPS 0x0F9C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_USER_ROI_KCPS_3 0x0F9C
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_USER_ROI_KCPS_2 0x0F9D
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_USER_ROI_KCPS_1 0x0F9E
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_USER_ROI_KCPS_0 0x0F9F
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_INNER_ROI_KCPS 0x0FA0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_INNER_ROI_KCPS_3 0x0FA0
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_INNER_ROI_KCPS_2 0x0FA1
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_INNER_ROI_KCPS_1 0x0FA2
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_INNER_ROI_KCPS_0 0x0FA3
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_OUTER_ROI_KCPS 0x0FA4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_OUTER_ROI_KCPS_3 0x0FA4
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_OUTER_ROI_KCPS_2 0x0FA5
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_OUTER_ROI_KCPS_1 0x0FA6
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_OUTER_ROI_KCPS_0 0x0FA7
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__ACCUM_PHASE 0x0FA8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__ACCUM_PHASE_3 0x0FA8
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__ACCUM_PHASE_2 0x0FA9
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__ACCUM_PHASE_1 0x0FAA
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__ACCUM_PHASE_0 0x0FAB
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__OFFSET_CORRECTED_RANGE 0x0FAC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__OFFSET_CORRECTED_RANGE_HI 0x0FAC
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__OFFSET_CORRECTED_RANGE_LO 0x0FAD
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_PHASECAL_RESULT__VCSEL_START 0x0FAE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__INTERRUPT_STATUS 0x0FB0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__RANGE_STATUS 0x0FB1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__REPORT_STATUS 0x0FB2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__STREAM_COUNT 0x0FB3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0 0x0FB4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x0FB4
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x0FB5
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0 0x0FB6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0_HI 0x0FB6
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0_LO 0x0FB7
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0 0x0FB8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0_HI 0x0FB8
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0_LO 0x0FB9
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SIGMA_SD0 0x0FBA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SIGMA_SD0_HI 0x0FBA
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SIGMA_SD0_LO 0x0FBB
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PHASE_SD0 0x0FBC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PHASE_SD0_HI 0x0FBC
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PHASE_SD0_LO 0x0FBD
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0 0x0FBE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0_HI 0x0FBE
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0_LO 0x0FBF
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0 0x0FC0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0_HI 0x0FC0
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0_LO 0x0FC1
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0 0x0FC2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x0FC2
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x0FC3
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0 0x0FC4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x0FC4
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x0FC5
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0 0x0FC6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0_HI 0x0FC6
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0_LO 0x0FC7
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1 0x0FC8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1_HI 0x0FC8
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1_LO 0x0FC9
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1 0x0FCA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1_HI 0x0FCA
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1_LO 0x0FCB
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1 0x0FCC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1_HI 0x0FCC
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1_LO 0x0FCD
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SIGMA_SD1 0x0FCE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SIGMA_SD1_HI 0x0FCE
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SIGMA_SD1_LO 0x0FCF
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PHASE_SD1 0x0FD0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PHASE_SD1_HI 0x0FD0
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PHASE_SD1_LO 0x0FD1
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1 0x0FD2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1_HI 0x0FD2
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1_LO 0x0FD3
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_0_SD1 0x0FD4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_0_SD1_HI 0x0FD4
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_0_SD1_LO 0x0FD5
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_1_SD1 0x0FD6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_1_SD1_HI 0x0FD6
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_1_SD1_LO 0x0FD7
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_2_SD1 0x0FD8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_2_SD1_HI 0x0FD8
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_2_SD1_LO 0x0FD9
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_3_SD1 0x0FDA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__THRESH_INFO 0x0FDB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0 0x0FDC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_3 0x0FDC
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_2 0x0FDD
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_1 0x0FDE
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_0 0x0FDF
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0 0x0FE0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_3 0x0FE0
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_2 0x0FE1
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_1 0x0FE2
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_0 0x0FE3
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0 0x0FE4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_3 0x0FE4
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_2 0x0FE5
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_1 0x0FE6
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_0 0x0FE7
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0 0x0FE8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_3 0x0FE8
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_2 0x0FE9
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_1 0x0FEA
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_0 0x0FEB
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1 0x0FEC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_3 0x0FEC
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_2 0x0FED
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_1 0x0FEE
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_0 0x0FEF
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1 0x0FF0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_3 0x0FF0
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_2 0x0FF1
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_1 0x0FF2
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_0 0x0FF3
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1 0x0FF4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_3 0x0FF4
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_2 0x0FF5
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_1 0x0FF6
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_0 0x0FF7
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1 0x0FF8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_3 0x0FF8
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_2 0x0FF9
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_1 0x0FFA
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_0 0x0FFB
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SPARE_0 0x0FFC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_PHASECAL_RESULT__REFERENCE_PHASE_HI 0x0FFE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_PHASECAL_RESULT__REFERENCE_PHASE_LO 0x0FFF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_register_settings.h b/drivers/input/misc/vl53L1/inc/vl53l1_register_settings.h
new file mode 100644
index 000000000000..6caf2ba9a997
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_register_settings.h
@@ -0,0 +1,273 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_REGISTER_SETTINGS_H_
+#define _VL53L1_REGISTER_SETTINGS_H_
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DEVICESCHEDULERMODE_PSEUDO_SOLO 0x00
+#define VL53L1_DEVICESCHEDULERMODE_STREAMING 0x01
+#define VL53L1_DEVICESCHEDULERMODE_HISTOGRAM 0x02
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DEVICEREADOUTMODE_SINGLE_SD (0x00 << 2)
+#define VL53L1_DEVICEREADOUTMODE_DUAL_SD (0x01 << 2)
+#define VL53L1_DEVICEREADOUTMODE_SPLIT_READOUT (0x02 << 2)
+#define VL53L1_DEVICEREADOUTMODE_SPLIT_MANUAL (0x03 << 2)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DEVICEMEASUREMENTMODE_MODE_MASK 0xF0
+#define VL53L1_DEVICEMEASUREMENTMODE_STOP_MASK 0x0F
+
+#define VL53L1_GROUPEDPARAMETERHOLD_ID_MASK 0x02
+
+
+
+
+#define VL53L1_EWOK_I2C_DEV_ADDR_DEFAULT 0x29
+
+
+#define VL53L1_OSC_FREQUENCY 0x00
+#define VL53L1_OSC_TRIM_DEFAULT 0x00
+#define VL53L1_OSC_FREQ_SET_DEFAULT 0x00
+
+#define VL53L1_RANGE_HISTOGRAM_REF 0x08
+#define VL53L1_RANGE_HISTOGRAM_RET 0x10
+#define VL53L1_RANGE_HISTOGRAM_BOTH 0x18
+#define VL53L1_RANGE_HISTOGRAM_INIT 0x20
+#define VL53L1_RANGE_VHV_INIT 0x40
+
+
+
+#define VL53L1_RESULT_RANGE_STATUS 0x1F
+
+
+
+#define VL53L1_SYSTEM__SEED_CONFIG__MANUAL 0x00
+#define VL53L1_SYSTEM__SEED_CONFIG__STANDARD 0x01
+#define VL53L1_SYSTEM__SEED_CONFIG__EVEN_UPDATE_ONLY 0x02
+
+
+
+#define VL53L1_INTERRUPT_CONFIG_LEVEL_LOW 0x00
+#define VL53L1_INTERRUPT_CONFIG_LEVEL_HIGH 0x01
+#define VL53L1_INTERRUPT_CONFIG_OUT_OF_WINDOW 0x02
+#define VL53L1_INTERRUPT_CONFIG_IN_WINDOW 0x03
+#define VL53L1_INTERRUPT_CONFIG_NEW_SAMPLE_READY 0x20
+
+
+
+#define VL53L1_CLEAR_RANGE_INT 0x01
+#define VL53L1_CLEAR_ERROR_INT 0x02
+
+
+
+#define VL53L1_SEQUENCE_VHV_EN 0x01
+#define VL53L1_SEQUENCE_PHASECAL_EN 0x02
+#define VL53L1_SEQUENCE_REFERENCE_PHASE_EN 0x04
+#define VL53L1_SEQUENCE_DSS1_EN 0x08
+#define VL53L1_SEQUENCE_DSS2_EN 0x10
+#define VL53L1_SEQUENCE_MM1_EN 0x20
+#define VL53L1_SEQUENCE_MM2_EN 0x40
+#define VL53L1_SEQUENCE_RANGE_EN 0x80
+
+
+
+#define VL53L1_DSS_CONTROL__ROI_SUBTRACT 0x20
+#define VL53L1_DSS_CONTROL__ROI_INTERSECT 0x10
+
+#define VL53L1_DSS_CONTROL__MODE_DISABLED 0x00
+#define VL53L1_DSS_CONTROL__MODE_TARGET_RATE 0x01
+#define VL53L1_DSS_CONTROL__MODE_EFFSPADS 0x02
+#define VL53L1_DSS_CONTROL__MODE_BLOCKSELECT 0x03
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_READOUT__STANDARD 0x45
+#define VL53L1_RANGING_CORE__SPAD_READOUT__RETURN_ARRAY_ONLY 0x05
+#define VL53L1_RANGING_CORE__SPAD_READOUT__REFERENCE_ARRAY_ONLY 0x55
+#define VL53L1_RANGING_CORE__SPAD_READOUT__RETURN_SPLIT_ARRAY 0x25
+#define VL53L1_RANGING_CORE__SPAD_READOUT__CALIB_PULSES 0xF5
+
+
+#define VL53L1_LASER_SAFETY__KEY_VALUE 0x6C
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_STATUS__RANGE_STATUS_MASK 0x1F
+#define VL53L1_RANGE_STATUS__MAX_THRESHOLD_HIT_MASK 0x20
+#define VL53L1_RANGE_STATUS__MIN_THRESHOLD_HIT_MASK 0x40
+#define VL53L1_RANGE_STATUS__GPH_ID_RANGE_STATUS_MASK 0x80
+
+
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_STATUS__INT_STATUS_MASK 0x07
+#define VL53L1_INTERRUPT_STATUS__INT_ERROR_STATUS_MASK 0x18
+#define VL53L1_INTERRUPT_STATUS__GPH_ID_INT_STATUS_MASK 0x20
+
+
+
+
+
+#endif
+
+
+
+
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_register_structs.h b/drivers/input/misc/vl53L1/inc/vl53l1_register_structs.h
new file mode 100644
index 000000000000..1da22e7f5f2a
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_register_structs.h
@@ -0,0 +1,4848 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_REGISTER_STRUCTS_H_
+#define _VL53L1_REGISTER_STRUCTS_H_
+
+#include "vl53l1_types.h"
+#include "vl53l1_register_map.h"
+
+#define VL53L1_STATIC_NVM_MANAGED_I2C_INDEX VL53L1_I2C_SLAVE__DEVICE_ADDRESS
+#define VL53L1_CUSTOMER_NVM_MANAGED_I2C_INDEX VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0
+#define VL53L1_STATIC_CONFIG_I2C_INDEX VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS
+#define VL53L1_GENERAL_CONFIG_I2C_INDEX VL53L1_GPH_CONFIG__STREAM_COUNT_UPDATE_VALUE
+#define VL53L1_TIMING_CONFIG_I2C_INDEX VL53L1_MM_CONFIG__TIMEOUT_MACROP_A_HI
+#define VL53L1_DYNAMIC_CONFIG_I2C_INDEX VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD_0
+#define VL53L1_SYSTEM_CONTROL_I2C_INDEX VL53L1_POWER_MANAGEMENT__GO1_POWER_FORCE
+#define VL53L1_SYSTEM_RESULTS_I2C_INDEX VL53L1_RESULT__INTERRUPT_STATUS
+#define VL53L1_CORE_RESULTS_I2C_INDEX VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0
+#define VL53L1_DEBUG_RESULTS_I2C_INDEX VL53L1_PHASECAL_RESULT__REFERENCE_PHASE
+#define VL53L1_NVM_COPY_DATA_I2C_INDEX VL53L1_IDENTIFICATION__MODEL_ID
+#define VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_INDEX VL53L1_PREV_SHADOW_RESULT__INTERRUPT_STATUS
+#define VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_INDEX VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0
+#define VL53L1_PATCH_DEBUG_I2C_INDEX VL53L1_RESULT__DEBUG_STATUS
+#define VL53L1_GPH_GENERAL_CONFIG_I2C_INDEX VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH
+#define VL53L1_GPH_STATIC_CONFIG_I2C_INDEX VL53L1_GPH__DSS_CONFIG__ROI_MODE_CONTROL
+#define VL53L1_GPH_TIMING_CONFIG_I2C_INDEX VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_A_HI
+#define VL53L1_FW_INTERNAL_I2C_INDEX VL53L1_FIRMWARE__INTERNAL_STREAM_COUNT_DIV
+#define VL53L1_PATCH_RESULTS_I2C_INDEX VL53L1_DSS_CALC__ROI_CTRL
+#define VL53L1_SHADOW_SYSTEM_RESULTS_I2C_INDEX VL53L1_SHADOW_PHASECAL_RESULT__VCSEL_START
+#define VL53L1_SHADOW_CORE_RESULTS_I2C_INDEX VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0
+
+#define VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES 11
+#define VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES 23
+#define VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES 32
+#define VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES 22
+#define VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES 23
+#define VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES 18
+#define VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES 5
+#define VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES 44
+#define VL53L1_CORE_RESULTS_I2C_SIZE_BYTES 33
+#define VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES 56
+#define VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES 49
+#define VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES 44
+#define VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES 33
+#define VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES 2
+#define VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES 5
+#define VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES 6
+#define VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES 16
+#define VL53L1_FW_INTERNAL_I2C_SIZE_BYTES 2
+#define VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES 90
+#define VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES 82
+#define VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES 33
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t i2c_slave__device_address;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__vhv_ref_sel_vddpix;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__vhv_ref_sel_vquench;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__reg_avdd1v2_sel;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__fast_osc__trim;
+
+
+
+
+
+
+
+
+
+
+ uint16_t osc_measured__fast_osc__frequency;
+
+
+
+
+
+
+
+
+
+
+ uint8_t vhv_config__timeout_macrop_loop_bound;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t vhv_config__count_thresh;
+
+
+
+
+
+
+
+
+
+
+ uint8_t vhv_config__offset;
+
+
+
+
+
+
+
+
+
+
+ uint8_t vhv_config__init;
+
+
+
+
+
+
+
+
+
+
+
+} VL53L1_static_nvm_managed_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t global_config__spad_enables_ref_0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_ref_1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_ref_2;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_ref_3;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_ref_4;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_ref_5;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__ref_en_start_select;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ref_spad_man__num_requested_ref_spads;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ref_spad_man__ref_location;
+
+
+
+
+
+
+
+
+
+
+ uint16_t algo__crosstalk_compensation_plane_offset_kcps;
+
+
+
+
+
+
+
+
+
+
+ int16_t algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+
+
+
+
+
+
+
+
+ int16_t algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+
+
+
+
+
+
+
+ uint16_t ref_spad_char__total_rate_target_mcps;
+
+
+
+
+
+
+
+
+
+
+ int16_t algo__part_to_part_range_offset_mm;
+
+
+
+
+
+
+
+
+
+
+ int16_t mm_config__inner_offset_mm;
+
+
+
+
+
+
+
+
+
+
+ int16_t mm_config__outer_offset_mm;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_customer_nvm_managed_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint16_t dss_config__target_total_rate_mcps;
+
+
+
+
+
+
+
+
+
+
+ uint8_t debug__ctrl;
+
+
+
+
+
+
+
+
+
+
+ uint8_t test_mode__ctrl;
+
+
+
+
+
+
+
+
+
+
+ uint8_t clk_gating__ctrl;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t nvm_bist__ctrl;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t nvm_bist__num_nvm_words;
+
+
+
+
+
+
+
+
+
+
+ uint8_t nvm_bist__start_address;
+
+
+
+
+
+
+
+
+
+
+ uint8_t host_if__status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t pad_i2c_hv__config;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t pad_i2c_hv__extsup_config;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gpio_hv_pad__ctrl;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t gpio_hv_mux__ctrl;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t gpio__tio_hv_status;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t gpio__fio_hv_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__spad_sel_pswidth;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__vcsel_pulse_width_offset;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__fast_osc__config_ctrl;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sigma_estimator__effective_pulse_width_ns;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sigma_estimator__effective_ambient_width_ns;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sigma_estimator__sigma_ref_mm;
+
+
+
+
+
+
+
+
+
+
+ uint8_t algo__crosstalk_compensation_valid_height_mm;
+
+
+
+
+
+
+
+
+
+
+ uint8_t spare_host_config__static_config_spare_0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t spare_host_config__static_config_spare_1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t algo__range_ignore_threshold_mcps;
+
+
+
+
+
+
+
+
+
+
+ uint8_t algo__range_ignore_valid_height_mm;
+
+
+
+
+
+
+
+
+
+
+ uint8_t algo__range_min_clip;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t algo__consistency_check__tolerance;
+
+
+
+
+
+
+
+
+
+
+ uint8_t spare_host_config__static_config_spare_2;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__reset_stages_msb;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__reset_stages_lsb;
+
+
+
+
+
+
+
+
+
+
+
+} VL53L1_static_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t gph_config__stream_count_update_value;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__stream_divider;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__interrupt_config_gpio;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t cal_config__vcsel_start;
+
+
+
+
+
+
+
+
+
+
+ uint16_t cal_config__repeat_rate;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__vcsel_width;
+
+
+
+
+
+
+
+
+
+
+ uint8_t phasecal_config__timeout_macrop;
+
+
+
+
+
+
+
+
+
+
+ uint8_t phasecal_config__target;
+
+
+
+
+
+
+
+
+
+
+ uint8_t phasecal_config__override;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_config__roi_mode_control;
+
+
+
+
+
+
+
+
+
+
+
+ uint16_t system__thresh_rate_high;
+
+
+
+
+
+
+
+
+
+
+ uint16_t system__thresh_rate_low;
+
+
+
+
+
+
+
+
+
+
+ uint16_t dss_config__manual_effective_spads_select;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_config__manual_block_select;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_config__aperture_attenuation;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_config__max_spads_limit;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_config__min_spads_limit;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_general_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t mm_config__timeout_macrop_a_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t mm_config__timeout_macrop_a_lo;
+
+
+
+
+
+
+
+
+
+
+ uint8_t mm_config__timeout_macrop_b_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t mm_config__timeout_macrop_b_lo;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__timeout_macrop_a_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__timeout_macrop_a_lo;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__vcsel_period_a;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__timeout_macrop_b_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__timeout_macrop_b_lo;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__vcsel_period_b;
+
+
+
+
+
+
+
+
+
+
+ uint16_t range_config__sigma_thresh;
+
+
+
+
+
+
+
+
+
+
+ uint16_t range_config__min_count_rate_rtn_limit_mcps;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__valid_phase_low;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__valid_phase_high;
+
+
+
+
+
+
+
+
+
+
+ uint32_t system__intermeasurement_period;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__fractional_enable;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_timing_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t system__grouped_parameter_hold_0;
+
+
+
+
+
+
+
+
+
+
+
+ uint16_t system__thresh_high;
+
+
+
+
+
+
+
+
+
+
+ uint16_t system__thresh_low;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__enable_xtalk_per_quadrant;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__seed_config;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__woi_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__woi_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__initial_phase_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__initial_phase_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__grouped_parameter_hold_1;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__first_order_select;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__quantifier;
+
+
+
+
+
+
+
+
+
+
+ uint8_t roi_config__user_roi_centre_spad;
+
+
+
+
+
+
+
+
+
+
+ uint8_t roi_config__user_roi_requested_global_xy_size;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__sequence_config;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__grouped_parameter_hold;
+
+
+
+
+
+
+
+
+
+
+
+} VL53L1_dynamic_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t power_management__go1_power_force;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__stream_count_ctrl;
+
+
+
+
+
+
+
+
+
+
+ uint8_t firmware__enable;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__interrupt_clear;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__mode_start;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+} VL53L1_system_control_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t result__interrupt_status;
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t result__range_status;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t result__report_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t result__stream_count;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__dss_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__peak_signal_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__ambient_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__sigma_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__phase_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__final_crosstalk_corrected_range_mm_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__mm_inner_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__mm_outer_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__avg_signal_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__dss_actual_effective_spads_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__peak_signal_count_rate_mcps_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__ambient_count_rate_mcps_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__sigma_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__phase_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__final_crosstalk_corrected_range_mm_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__spare_0_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__spare_1_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__spare_2_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t result__spare_3_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t result__thresh_info;
+
+
+
+
+
+
+
+
+
+
+
+} VL53L1_system_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint32_t result_core__ambient_window_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t result_core__ranging_total_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ int32_t result_core__signal_total_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t result_core__total_periods_elapsed_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t result_core__ambient_window_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint32_t result_core__ranging_total_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ int32_t result_core__signal_total_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint32_t result_core__total_periods_elapsed_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t result_core__spare_0;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_core_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint16_t phasecal_result__reference_phase;
+
+
+
+
+
+
+
+
+
+
+ uint8_t phasecal_result__vcsel_start;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ref_spad_char_result__num_actual_ref_spads;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ref_spad_char_result__ref_location;
+
+
+
+
+
+
+
+
+
+
+ uint8_t vhv_result__coldboot_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t vhv_result__search_result;
+
+
+
+
+
+
+
+
+
+
+ uint8_t vhv_result__latest_setting;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__osc_calibrate_val;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__powerdown_go1;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__ref_bg_ctrl;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__regdvdd1v2_ctrl;
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__osc_slow_ctrl;
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t test_mode__status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t firmware__system_status;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t firmware__mode_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t firmware__secondary_mode_status;
+
+
+
+
+
+
+
+
+
+
+ uint16_t firmware__cal_repeat_rate_counter;
+
+
+
+
+
+
+
+
+
+
+ uint16_t gph__system__thresh_high;
+
+
+
+
+
+
+
+
+
+
+ uint16_t gph__system__thresh_low;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__system__enable_xtalk_per_quadrant;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__spare_0;
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__sd_config__woi_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__sd_config__woi_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__sd_config__initial_phase_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__sd_config__initial_phase_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__sd_config__first_order_select;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__sd_config__quantifier;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__roi_config__user_roi_centre_spad;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__roi_config__user_roi_requested_global_xy_size;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__system__sequence_config;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__gph_id;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__interrupt_set;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t interrupt_manager__enables;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t interrupt_manager__clear;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t interrupt_manager__status;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t mcu_to_host_bank__wr_access_en;
+
+
+
+
+
+
+
+
+
+
+ uint8_t power_management__go1_reset_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t pad_startup_mode__value_ro;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t pad_startup_mode__value_ctrl;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint32_t pll_period_us;
+
+
+
+
+
+
+
+
+
+
+ uint32_t interrupt_scheduler__data_out;
+
+
+
+
+
+
+
+
+
+
+ uint8_t nvm_bist__complete;
+
+
+
+
+
+
+
+
+
+
+ uint8_t nvm_bist__status;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_debug_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t identification__model_id;
+
+
+
+
+
+
+
+
+
+
+ uint8_t identification__module_type;
+
+
+
+
+
+
+
+
+
+
+ uint8_t identification__revision_id;
+
+
+
+
+
+
+
+
+
+
+
+ uint16_t identification__module_id;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__fast_osc__trim_max;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__fast_osc__freq_set;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__vcsel_trim;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__vcsel_selion;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__vcsel_selion_max;
+
+
+
+
+
+
+
+
+
+
+ uint8_t protected_laser_safety__lock_bit;
+
+
+
+
+
+
+
+
+
+
+ uint8_t laser_safety__key;
+
+
+
+
+
+
+
+
+
+
+ uint8_t laser_safety__key_ro;
+
+
+
+
+
+
+
+
+
+
+ uint8_t laser_safety__clip;
+
+
+
+
+
+
+
+
+
+
+ uint8_t laser_safety__mult;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_2;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_3;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_4;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_5;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_6;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_7;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_8;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_9;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_10;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_11;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_12;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_13;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_14;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_15;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_16;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_17;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_18;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_19;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_20;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_21;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_22;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_23;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_24;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_25;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_26;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_27;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_28;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_29;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_30;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_31;
+
+
+
+
+
+
+
+
+
+
+ uint8_t roi_config__mode_roi_centre_spad;
+
+
+
+
+
+
+
+
+
+
+ uint8_t roi_config__mode_roi_xy_size;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_nvm_copy_data_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t prev_shadow_result__interrupt_status;
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t prev_shadow_result__range_status;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t prev_shadow_result__report_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t prev_shadow_result__stream_count;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__dss_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__peak_signal_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__ambient_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__sigma_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__phase_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__final_crosstalk_corrected_range_mm_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__mm_inner_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__mm_outer_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__avg_signal_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__dss_actual_effective_spads_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__peak_signal_count_rate_mcps_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__ambient_count_rate_mcps_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__sigma_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__phase_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__final_crosstalk_corrected_range_mm_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__spare_0_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__spare_1_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__spare_2_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__spare_3_sd1;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_prev_shadow_system_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint32_t prev_shadow_result_core__ambient_window_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t prev_shadow_result_core__ranging_total_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ int32_t prev_shadow_result_core__signal_total_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t prev_shadow_result_core__total_periods_elapsed_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t prev_shadow_result_core__ambient_window_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint32_t prev_shadow_result_core__ranging_total_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ int32_t prev_shadow_result_core__signal_total_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint32_t prev_shadow_result_core__total_periods_elapsed_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t prev_shadow_result_core__spare_0;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_prev_shadow_core_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t result__debug_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t result__debug_stage;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_patch_debug_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint16_t gph__system__thresh_rate_high;
+
+
+
+
+
+
+
+
+
+
+ uint16_t gph__system__thresh_rate_low;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__system__interrupt_config_gpio;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+} VL53L1_gph_general_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t gph__dss_config__roi_mode_control;
+
+
+
+
+
+
+
+
+
+
+
+ uint16_t gph__dss_config__manual_effective_spads_select;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__dss_config__manual_block_select;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__dss_config__max_spads_limit;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__dss_config__min_spads_limit;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_gph_static_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t gph__mm_config__timeout_macrop_a_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__mm_config__timeout_macrop_a_lo;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__mm_config__timeout_macrop_b_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__mm_config__timeout_macrop_b_lo;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__timeout_macrop_a_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__timeout_macrop_a_lo;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__vcsel_period_a;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__vcsel_period_b;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__timeout_macrop_b_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__timeout_macrop_b_lo;
+
+
+
+
+
+
+
+
+
+
+ uint16_t gph__range_config__sigma_thresh;
+
+
+
+
+
+
+
+
+
+
+ uint16_t gph__range_config__min_count_rate_rtn_limit_mcps;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__valid_phase_low;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__valid_phase_high;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_gph_timing_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t firmware__internal_stream_count_div;
+
+
+
+
+
+
+
+
+
+
+ uint8_t firmware__internal_stream_counter_val;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_fw_internal_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t dss_calc__roi_ctrl;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__spare_1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__spare_2;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__spare_3;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__spare_4;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__spare_5;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__spare_6;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__spare_7;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_2;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_3;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_4;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_5;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_6;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_7;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_8;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_9;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_10;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_11;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_12;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_13;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_14;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_15;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_16;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_17;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_18;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_19;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_20;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_21;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_22;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_23;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_24;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_25;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_26;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_27;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_28;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_29;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_30;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_31;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__mode_roi_0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__mode_roi_1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sigma_estimator_calc__spare_0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t vhv_result__peak_signal_rate_mcps;
+
+
+
+
+
+
+
+
+
+
+ uint32_t vhv_result__signal_total_events_ref;
+
+
+
+
+
+
+
+
+
+
+ uint16_t phasecal_result__phase_output_ref;
+
+
+
+
+
+
+
+
+
+
+ uint16_t dss_result__total_rate_per_spad;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_result__enabled_blocks;
+
+
+
+
+
+
+
+
+
+
+ uint16_t dss_result__num_requested_spads;
+
+
+
+
+
+
+
+
+
+
+ uint16_t mm_result__inner_intersection_rate;
+
+
+
+
+
+
+
+
+
+
+ uint16_t mm_result__outer_complement_rate;
+
+
+
+
+
+
+
+
+
+
+ uint16_t mm_result__total_offset;
+
+
+
+
+
+
+
+
+
+
+ uint32_t xtalk_calc__xtalk_for_enabled_spads;
+
+
+
+
+
+
+
+
+
+
+ uint32_t xtalk_result__avg_xtalk_user_roi_kcps;
+
+
+
+
+
+
+
+
+
+
+ uint32_t xtalk_result__avg_xtalk_mm_inner_roi_kcps;
+
+
+
+
+
+
+
+
+
+
+ uint32_t xtalk_result__avg_xtalk_mm_outer_roi_kcps;
+
+
+
+
+
+
+
+
+
+
+ uint32_t range_result__accum_phase;
+
+
+
+
+
+
+
+
+
+
+ uint16_t range_result__offset_corrected_range;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_patch_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t shadow_phasecal_result__vcsel_start;
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_result__interrupt_status;
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_result__range_status;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_result__report_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_result__stream_count;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__dss_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__peak_signal_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__ambient_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__sigma_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__phase_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__final_crosstalk_corrected_range_mm_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__mm_inner_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__mm_outer_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__avg_signal_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__dss_actual_effective_spads_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__peak_signal_count_rate_mcps_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__ambient_count_rate_mcps_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__sigma_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__phase_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__final_crosstalk_corrected_range_mm_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__spare_0_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__spare_1_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__spare_2_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_result__spare_3_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_result__thresh_info;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_phasecal_result__reference_phase_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_phasecal_result__reference_phase_lo;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_shadow_system_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint32_t shadow_result_core__ambient_window_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t shadow_result_core__ranging_total_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ int32_t shadow_result_core__signal_total_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t shadow_result_core__total_periods_elapsed_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t shadow_result_core__ambient_window_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint32_t shadow_result_core__ranging_total_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ int32_t shadow_result_core__signal_total_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint32_t shadow_result_core__total_periods_elapsed_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_result_core__spare_0;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_shadow_core_results_t;
+
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_silicon_core.h b/drivers/input/misc/vl53L1/inc/vl53l1_silicon_core.h
new file mode 100644
index 000000000000..8ba9f3a97244
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_silicon_core.h
@@ -0,0 +1,133 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_SILICON_CORE_H_
+#define _VL53L1_SILICON_CORE_H_
+
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_is_firmware_ready_silicon(
+ VL53L1_DEV Dev,
+ uint8_t *pready);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_wait.h b/drivers/input/misc/vl53L1/inc/vl53l1_wait.h
new file mode 100644
index 000000000000..d26c2f243f88
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_wait.h
@@ -0,0 +1,318 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_WAIT_H_
+#define _VL53L1_WAIT_H_
+
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_wait_for_boot_completion(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_wait_for_firmware_ready(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_wait_for_range_completion(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_wait_for_test_completion(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_is_boot_complete(
+ VL53L1_DEV Dev,
+ uint8_t *pready);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_is_firmware_ready(
+ VL53L1_DEV Dev,
+ uint8_t *pready);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_is_new_data_ready(
+ VL53L1_DEV Dev,
+ uint8_t *pready);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_poll_for_boot_completion(
+ VL53L1_DEV Dev,
+ uint32_t timeout_ms);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_poll_for_firmware_ready(
+ VL53L1_DEV Dev,
+ uint32_t timeout_ms);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_poll_for_range_completion(
+ VL53L1_DEV Dev,
+ uint32_t timeout_ms);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/inc/vl53l1_zone_presets.h b/drivers/input/misc/vl53L1/inc/vl53l1_zone_presets.h
new file mode 100644
index 000000000000..1288e88f1245
--- /dev/null
+++ b/drivers/input/misc/vl53L1/inc/vl53l1_zone_presets.h
@@ -0,0 +1,182 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_ZONE_PRESETS_H_
+#define _VL53L1_ZONE_PRESETS_H_
+
+#include "vl53l1_ll_def.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_zone_config_structure(
+ uint8_t x_off,
+ uint8_t x_inc,
+ uint8_t x_zones,
+ uint8_t y_off,
+ uint8_t y_inc,
+ uint8_t y_zones,
+ uint8_t width,
+ uint8_t height,
+ VL53L1_zone_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_zone_preset_xtalk_planar(
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_zone_config_histogram_bins(
+ VL53L1_zone_config_t *pdata);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/ipp/ipp_linux.c b/drivers/input/misc/vl53L1/ipp/ipp_linux.c
new file mode 100644
index 000000000000..94d69c8762b7
--- /dev/null
+++ b/drivers/input/misc/vl53L1/ipp/ipp_linux.c
@@ -0,0 +1,343 @@
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/**
+ * @file ipp_linux.c kernel side implementation of vl53l1 protected processing
+ *
+ * @date Sep 1, 2016
+ * @author : imaging
+ *
+ * @ingroup ipp_dev
+ */
+
+#include "stmvl53l1.h"
+
+#define IPP_ERR_CODE (VL53L1_ERROR_PLATFORM_SPECIFIC_START-1)
+
+static int stmvl53l1_ipp_do_wrapper(struct stmvl53l1_data *data,
+ struct ipp_work_t *pin, struct ipp_work_t *pout, int payload_out)
+{
+ int rc;
+
+ if (data->ipp.buzy) {
+ vl53l1_errmsg("try exec new ipp but still buzy on previous");
+ /* TODO shall we discard it and push new ? */
+ rc = IPP_ERR_CODE;
+ goto done;
+ }
+ BUG_ON(pin->payload > IPP_WORK_MAX_PAYLOAD);
+ stmvl531_ipp_tim_start(data);
+ rc = stmvl53l1_ipp_do(data, pin, pout);
+ if (rc != 0) {
+ vl53l1_errmsg("stmvl53l1_ipp_do err %d\n", rc);
+ rc = IPP_ERR_CODE;
+ goto done;
+ }
+ vl53l1_dbgmsg("ipp ok \n");
+ /* check what we got back if valid answer error etc */
+ if (pout->status) {
+ vl53l1_errmsg("ipp error status %d from user", pout->status);
+ if (pout->status >= stmvl53l1_ipp_status_proc_code)
+ rc = pout->status & (stmvl53l1_ipp_status_proc_code-1);
+ else
+ rc = IPP_ERR_CODE;
+ goto done;
+ }
+ BUG_ON(pout->payload > IPP_WORK_MAX_PAYLOAD);
+ if (pout->payload != payload_out) {
+ /* bad formated answer */
+ vl53l1_errmsg("bad payload %d != %d in ipp work back",
+ pout->payload, payload_out);
+ rc = IPP_ERR_CODE;
+ goto done;
+ }
+ stmvl531_ipp_tim_stop(data);
+ stmvl531_ipp_stat(data, "ipp #%5x to=%3d fm=%3d in %5ld us",
+ pin->xfer_id, pin->payload,
+ pout->payload,
+ stmvl531_ipp_time(data));
+
+ rc = 0;
+done:
+
+ return rc;
+}
+
+/**
+ * @file vl53l1_platform_ipp.h
+ *
+ * @brief EwokPlus25 IPP Wrapper Functions
+ */
+
+/**
+ * @brief IPP Wrapper call for histogram post processing
+ *
+ *
+ * @param[in] Dev : Device handle
+ * @param[in] pdmax_cal : DMAX calibration data
+ * @param[in] pdmax_cfg : DMAX configuration data
+ * @param[in] ppost_cfg : VL53L1_hist_post_process_config_t
+ * @param[in] pbins : Input histogram raw bin data
+ * @param[in] pxtalk : Cross talk histogram data
+ * @param[out] presults : Output VL53L1_range_results_t
+ * structure
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_ipp_hist_process_data(
+ VL53L1_DEV dev,
+ VL53L1_dmax_calibration_data_t *pdmax_cal,
+ VL53L1_hist_gen3_dmax_config_t *pdmax_cfg,
+ VL53L1_hist_post_process_config_t *ppost_cfg,
+ VL53L1_histogram_bin_data_t *pbins,
+ VL53L1_xtalk_histogram_data_t *pxtalk,
+ VL53L1_range_results_t *presults)
+{
+ struct stmvl53l1_data *data = (struct stmvl53l1_data *)
+ container_of(dev, struct stmvl53l1_data, stdev);
+ struct ipp_work_t *pout = &data->ipp.work_out;
+ struct ipp_work_t *pin = &data->ipp.work;
+ int rc;
+ VL53L1_range_results_t *presults_ipp;
+
+ IPP_SERIALIZE_VAR;
+
+ /* setup pin */
+ IPP_SERIALIZE_START(pin->data, 5);
+ IPP_SET_ARG_PTR(pin->data, 0, pdmax_cal);
+ IPP_SET_ARG_PTR(pin->data, 1, pdmax_cfg);
+ IPP_SET_ARG_PTR(pin->data, 2, ppost_cfg);
+ IPP_SET_ARG_PTR(pin->data, 3, pbins);
+ IPP_SET_ARG_PTR(pin->data, 4, pxtalk);
+ pin->payload = IPP_SERIALIZE_PAYLAOD();
+ pin->process_no = stmvl53l1_ipp_cal_hist;
+
+ /* setup pout */
+ IPP_SERIALIZE_START(pout->data, 1);
+ IPP_OUT_ARG_PTR(pout->data, 0, presults_ipp);
+
+ /* do ipp */
+ rc = stmvl53l1_ipp_do_wrapper(data, pin, pout, IPP_SERIALIZE_PAYLAOD());
+ if (rc)
+ goto done;
+
+ /* copy output */
+ memcpy(presults, presults_ipp, sizeof(*presults));
+
+ rc = 0;
+done:
+
+ return rc;
+}
+
+/**
+ * @brief IPP Wrapper call for histogram ambient dmax calc
+ *
+ * The target reflectance in percent for the DMAX calculation
+ * is set by target_reflectance input
+ *
+ * The fixed point format is 7.2
+ *
+ * @param[in] Dev : Device handle
+ * @param[in] target_reflectance : target reflectance to report ambient DMAX
+ * Percentage in 7.2 fixed point format
+ * @param[in] pdmax_cal : DMAX calibration data
+ * @param[in] pdmax_cfg : DMAX configuration data
+ * @param[in] pbins : Input histogram raw bin data
+ * @param[out] pambient_dmax_mm : Output ambient DMAX distance in [mm]
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_ipp_hist_ambient_dmax(
+ VL53L1_DEV dev,
+ uint16_t target_reflectance,
+ VL53L1_dmax_calibration_data_t *pdmax_cal,
+ VL53L1_hist_gen3_dmax_config_t *pdmax_cfg,
+ VL53L1_histogram_bin_data_t *pbins,
+ int16_t *pambient_dmax_mm)
+{
+ struct stmvl53l1_data *data = (struct stmvl53l1_data *)
+ container_of(dev, struct stmvl53l1_data, stdev);
+ struct ipp_work_t *pout = &data->ipp.work_out;
+ struct ipp_work_t *pin = &data->ipp.work;
+ int rc;
+ int16_t *pambient_dmax_mm_ipp;
+
+ IPP_SERIALIZE_VAR;
+
+ /* setup pin */
+ IPP_SERIALIZE_START(pin->data, 4);
+ IPP_SET_ARG(pin->data, 0, target_reflectance);
+ IPP_SET_ARG_PTR(pin->data, 1, pdmax_cal);
+ IPP_SET_ARG_PTR(pin->data, 2, pdmax_cfg);
+ IPP_SET_ARG_PTR(pin->data, 3, pbins);
+ pin->payload = IPP_SERIALIZE_PAYLAOD();
+ pin->process_no = stmvl53l1_ipp_hist_ambient_dmax;
+
+ /* setup pout */
+ IPP_SERIALIZE_START(pout->data, 1);
+ IPP_OUT_ARG_PTR(pout->data, 0, pambient_dmax_mm_ipp);
+
+ /* do ipp */
+ rc = stmvl53l1_ipp_do_wrapper(data, pin, pout, IPP_SERIALIZE_PAYLAOD());
+ if (rc)
+ goto done;
+
+ /* copy output */
+ memcpy(pambient_dmax_mm, pambient_dmax_mm_ipp,
+ sizeof(*pambient_dmax_mm));
+
+ rc = 0;
+done:
+
+ return rc;
+}
+
+/**
+ * @brief IPP Wrapper call for xtalk calibration post processing
+ *
+ * @param[in] Dev : Device handle
+ * @param[in] pxtalk_ranges : Input VL53L1_xtalk_range_results_t
+ * Must contain 5 ranges, 4 quadrants + 1
+ * full FoV
+ * @param[out] pxtalk_shape : Output normalised Cross talk histogram
+ * shape
+ * @param[out] pxtalk_cal : Output VL53L1_xtalk_calibration_results_t
+ * structure
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_ipp_xtalk_calibration_process_data(
+ VL53L1_DEV dev,
+ VL53L1_xtalk_range_results_t *pxtalk_ranges,
+ VL53L1_xtalk_histogram_data_t *pxtalk_shape,
+ VL53L1_xtalk_calibration_results_t *pxtalk_cal)
+{
+ struct stmvl53l1_data *data = (struct stmvl53l1_data *)
+ container_of(dev, struct stmvl53l1_data, stdev);
+ struct ipp_work_t *pout = &data->ipp.work_out;
+ struct ipp_work_t *pin = &data->ipp.work;
+ int rc;
+ VL53L1_xtalk_histogram_data_t *pxtalk_shape_ipp;
+ VL53L1_xtalk_calibration_results_t *pxtalk_cal_ipp;
+
+ IPP_SERIALIZE_VAR;
+
+ /* setup pin */
+ IPP_SERIALIZE_START(pin->data, 1);
+ IPP_SET_ARG_PTR(pin->data, 0, pxtalk_ranges);
+ pin->payload = IPP_SERIALIZE_PAYLAOD();
+ pin->process_no = stmvl53l1_ipp_xtalk_calibration;
+
+ /* setup pout */
+ IPP_SERIALIZE_START(pout->data, 2);
+ IPP_OUT_ARG_PTR(pout->data, 0, pxtalk_shape_ipp);
+ IPP_OUT_ARG_PTR(pout->data, 1, pxtalk_cal_ipp);
+
+ /* do ipp */
+ rc = stmvl53l1_ipp_do_wrapper(data, pin, pout, IPP_SERIALIZE_PAYLAOD());
+ if (rc)
+ goto done;
+
+ /* copy output */
+ memcpy(pxtalk_shape, pxtalk_shape_ipp, sizeof(*pxtalk_shape));
+ memcpy(pxtalk_cal, pxtalk_cal_ipp, sizeof(*pxtalk_cal));
+
+ rc = 0;
+done:
+
+ return rc;
+}
+
+/**
+ * @brief IPP Wrapper call for Generating Xtalk data from dual reflectance
+ * histogram data
+ *
+ * @param[in] Dev : Device handle
+ * @param[in] pxtalk_results : Pointer to xtalk_results structure
+ * containing dual reflectance
+ * histogram data
+ * @param[in] expected_target_distance_mm : User input of true target distance
+ * @param[in] higher_reflectance : User input detailing which
+ * histogram data 1 or 2 has the
+ * highest reflectance.
+ * @param[out] pxtalk_avg_samples : Pointer to output xtalk histogram
+ * data
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+
+VL53L1_Error VL53L1_ipp_generate_dual_reflectance_xtalk_samples(
+ VL53L1_DEV dev,
+ VL53L1_xtalk_range_results_t *pxtalk_results,
+ uint16_t expected_target_distance_mm,
+ uint8_t higher_reflectance,
+ VL53L1_histogram_bin_data_t *pxtalk_avg_samples)
+{
+ struct stmvl53l1_data *data = (struct stmvl53l1_data *)
+ container_of(dev, struct stmvl53l1_data, stdev);
+ struct ipp_work_t *pout = &data->ipp.work_out;
+ struct ipp_work_t *pin = &data->ipp.work;
+ int rc;
+ VL53L1_histogram_bin_data_t *pxtalk_avg_samples_ipp;
+
+ IPP_SERIALIZE_VAR;
+
+ /* setup pin */
+ IPP_SERIALIZE_START(pin->data, 3);
+ IPP_SET_ARG_PTR(pin->data, 0, pxtalk_results);
+ IPP_SET_ARG(pin->data, 1, expected_target_distance_mm);
+ IPP_SET_ARG(pin->data, 2, higher_reflectance);
+ pin->payload = IPP_SERIALIZE_PAYLAOD();
+ pin->process_no = stmvl53l1_ipp_generate_dual_reflectance_xtalk_samples;
+
+ /* setup pout */
+ IPP_SERIALIZE_START(pout->data, 1);
+ IPP_OUT_ARG_PTR(pout->data, 0, pxtalk_avg_samples_ipp);
+
+ /* do ipp */
+ rc = stmvl53l1_ipp_do_wrapper(data, pin, pout, IPP_SERIALIZE_PAYLAOD());
+ if (rc)
+ goto done;
+
+ /* copy output */
+ memcpy(pxtalk_avg_samples, pxtalk_avg_samples_ipp,
+ sizeof(*pxtalk_avg_samples));
+
+ rc = 0;
+done:
+
+ return rc;
+}
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_api.c b/drivers/input/misc/vl53L1/src/vl53l1_api.c
new file mode 100644
index 000000000000..a166dea001ae
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_api.c
@@ -0,0 +1,2809 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_api.h"
+#include "vl53l1_api_strings.h"
+#include "vl53l1_register_settings.h"
+#include "vl53l1_core.h"
+#include "vl53l1_api_calibration.h"
+#include "vl53l1_wait.h"
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, status, \
+ fmt, ##__VA_ARGS__)
+
+#ifdef VL53L1_LOG_ENABLE
+#define trace_print(level, ...) trace_print_module_function(\
+ VL53L1_TRACE_MODULE_API, level, VL53L1_TRACE_FUNCTION_NONE, \
+ ##__VA_ARGS__)
+#endif
+
+#ifndef MIN
+#define MIN(VL53L1_PRM_00002,VL53L1_PRM_00030) ((VL53L1_PRM_00002) < (VL53L1_PRM_00030) ? (VL53L1_PRM_00002) : (VL53L1_PRM_00030))
+#endif
+#ifndef MAX
+#define MAX(VL53L1_PRM_00002,VL53L1_PRM_00030) ((VL53L1_PRM_00002) < (VL53L1_PRM_00030) ? (VL53L1_PRM_00030) : (VL53L1_PRM_00002))
+#endif
+
+#define DMAX_REFLECTANCE_IDX 2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+static VL53L1_Error CheckValidRectRoi(VL53L1_UserRoi_t ROI)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+ if ((ROI.TopLeftX > 15) || (ROI.TopLeftY > 15) ||
+ (ROI.BotRightX > 15) || (ROI.BotRightY > 15))
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+
+ if ((ROI.TopLeftX > ROI.BotRightX) || (ROI.TopLeftY < ROI.BotRightY))
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+static VL53L1_GPIO_Interrupt_Mode ConvertModeToLLD(VL53L1_Error *pStatus,
+ VL53L1_ThresholdMode CrossMode)
+{
+ VL53L1_GPIO_Interrupt_Mode Mode;
+
+ switch (CrossMode) {
+ case VL53L1_THRESHOLD_CROSSED_LOW:
+ Mode = VL53L1_GPIOINTMODE_LEVEL_LOW;
+ break;
+ case VL53L1_THRESHOLD_CROSSED_HIGH:
+ Mode = VL53L1_GPIOINTMODE_LEVEL_HIGH;
+ break;
+ case VL53L1_THRESHOLD_OUT_OF_WINDOW:
+ Mode = VL53L1_GPIOINTMODE_OUT_OF_WINDOW;
+ break;
+ case VL53L1_THRESHOLD_IN_WINDOW:
+ Mode = VL53L1_GPIOINTMODE_IN_WINDOW;
+ break;
+ default:
+
+
+ Mode = VL53L1_GPIOINTMODE_LEVEL_HIGH;
+ *pStatus = VL53L1_ERROR_INVALID_PARAMS;
+ }
+ return Mode;
+}
+
+static VL53L1_ThresholdMode ConvertModeFromLLD(VL53L1_Error *pStatus,
+ VL53L1_GPIO_Interrupt_Mode CrossMode)
+{
+ VL53L1_ThresholdMode Mode;
+
+ switch (CrossMode) {
+ case VL53L1_GPIOINTMODE_LEVEL_LOW:
+ Mode = VL53L1_THRESHOLD_CROSSED_LOW;
+ break;
+ case VL53L1_GPIOINTMODE_LEVEL_HIGH:
+ Mode = VL53L1_THRESHOLD_CROSSED_HIGH;
+ break;
+ case VL53L1_GPIOINTMODE_OUT_OF_WINDOW:
+ Mode = VL53L1_THRESHOLD_OUT_OF_WINDOW;
+ break;
+ case VL53L1_GPIOINTMODE_IN_WINDOW:
+ Mode = VL53L1_THRESHOLD_IN_WINDOW;
+ break;
+ default:
+
+
+ Mode = VL53L1_THRESHOLD_CROSSED_HIGH;
+ *pStatus = VL53L1_ERROR_UNDEFINED;
+ }
+ return Mode;
+}
+
+
+
+
+VL53L1_Error VL53L1_GetVersion(VL53L1_Version_t *pVersion)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ pVersion->major = VL53L1_IMPLEMENTATION_VER_MAJOR;
+ pVersion->minor = VL53L1_IMPLEMENTATION_VER_MINOR;
+ pVersion->build = VL53L1_IMPLEMENTATION_VER_SUB;
+
+ pVersion->revision = VL53L1_IMPLEMENTATION_VER_REVISION;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetPalSpecVersion(VL53L1_Version_t *pPalSpecVersion)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ pPalSpecVersion->major = VL53L1_SPECIFICATION_VER_MAJOR;
+ pPalSpecVersion->minor = VL53L1_SPECIFICATION_VER_MINOR;
+ pPalSpecVersion->build = VL53L1_SPECIFICATION_VER_SUB;
+
+ pPalSpecVersion->revision = VL53L1_SPECIFICATION_VER_REVISION;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetProductRevision(VL53L1_DEV Dev,
+ uint8_t *pProductRevisionMajor, uint8_t *pProductRevisionMinor)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t revision_id;
+ VL53L1_LLDriverData_t *pLLData;
+
+ LOG_FUNCTION_START("");
+
+ pLLData = VL53L1DevStructGetLLDriverHandle(Dev);
+ revision_id = pLLData->nvm_copy_data.identification__revision_id;
+ *pProductRevisionMajor = 1;
+ *pProductRevisionMinor = (revision_id & 0xF0) >> 4;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+VL53L1_Error VL53L1_GetDeviceInfo(VL53L1_DEV Dev,
+ VL53L1_DeviceInfo_t *pVL53L1_DeviceInfo)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t revision_id;
+ VL53L1_LLDriverData_t *pLLData;
+
+ LOG_FUNCTION_START("");
+
+ pLLData = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ strncpy(pVL53L1_DeviceInfo->ProductId, "",
+ VL53L1_DEVINFO_STRLEN-1);
+ pVL53L1_DeviceInfo->ProductType =
+ pLLData->nvm_copy_data.identification__module_type;
+
+ revision_id = pLLData->nvm_copy_data.identification__revision_id;
+ pVL53L1_DeviceInfo->ProductRevisionMajor = 1;
+ pVL53L1_DeviceInfo->ProductRevisionMinor = (revision_id & 0xF0) >> 4;
+
+#ifndef VL53L1_USE_EMPTY_STRING
+ if (pVL53L1_DeviceInfo->ProductRevisionMinor == 0)
+ strncpy(pVL53L1_DeviceInfo->Name,
+ VL53L1_STRING_DEVICE_INFO_NAME0,
+ VL53L1_DEVINFO_STRLEN-1);
+ else
+ strncpy(pVL53L1_DeviceInfo->Name,
+ VL53L1_STRING_DEVICE_INFO_NAME1,
+ VL53L1_DEVINFO_STRLEN-1);
+ strncpy(pVL53L1_DeviceInfo->Type,
+ VL53L1_STRING_DEVICE_INFO_TYPE,
+ VL53L1_DEVINFO_STRLEN-1);
+#else
+ pVL53L1_DeviceInfo->Name[0] = 0;
+ pVL53L1_DeviceInfo->Type[0] = 0;
+#endif
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetRangeStatusString(uint8_t RangeStatus,
+ char *pRangeStatusString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_range_status_string(RangeStatus,
+ pRangeStatusString);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetPalErrorString(VL53L1_Error PalErrorCode,
+ char *pPalErrorString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_pal_error_string(PalErrorCode, pPalErrorString);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetPalStateString(VL53L1_State PalStateCode,
+ char *pPalStateString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_pal_state_string(PalStateCode, pPalStateString);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetPalState(VL53L1_DEV Dev, VL53L1_State *pPalState)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pPalState = PALDevDataGet(Dev, PalState);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+
+VL53L1_Error VL53L1_SetDeviceAddress(VL53L1_DEV Dev, uint8_t DeviceAddress)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_WrByte(Dev, VL53L1_I2C_SLAVE__DEVICE_ADDRESS,
+ DeviceAddress / 2);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_DataInit(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t i;
+
+ LOG_FUNCTION_START("");
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_data_init(Dev, 1);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ PALDevDataSet(Dev, PalState, VL53L1_STATE_WAIT_STATICINIT);
+ PALDevDataSet(Dev, CurrentParameters.PresetMode,
+ VL53L1_PRESETMODE_RANGING);
+ }
+
+
+
+ for (i = 0; i < VL53L1_CHECKENABLE_NUMBER_OF_CHECKS; i++) {
+ if (Status == VL53L1_ERROR_NONE)
+ Status |= VL53L1_SetLimitCheckEnable(Dev, i, 1);
+ else
+ break;
+
+ }
+
+
+
+ if (Status == VL53L1_ERROR_NONE) {
+ Status = VL53L1_SetLimitCheckValue(Dev,
+ VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (FixPoint1616_t)(18 * 65536));
+ }
+ if (Status == VL53L1_ERROR_NONE) {
+ Status = VL53L1_SetLimitCheckValue(Dev,
+ VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (FixPoint1616_t)(25 * 65536 / 100));
+
+
+ }
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_StaticInit(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t measurement_mode;
+
+ LOG_FUNCTION_START("");
+
+ if (Status == VL53L1_ERROR_NONE)
+ PALDevDataSet(Dev, PalState, VL53L1_STATE_IDLE);
+
+ measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ PALDevDataSet(Dev, LLData.measurement_mode, measurement_mode);
+
+ PALDevDataSet(Dev, CurrentParameters.NewDistanceMode,
+ VL53L1_DISTANCEMODE_LONG);
+
+ PALDevDataSet(Dev, CurrentParameters.InternalDistanceMode,
+ VL53L1_DISTANCEMODE_LONG);
+
+ PALDevDataSet(Dev, CurrentParameters.DistanceMode,
+ VL53L1_DISTANCEMODE_LONG);
+
+ PALDevDataSet(Dev, CurrentParameters.OutputMode,
+ VL53L1_OUTPUTMODE_NEAREST);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_WaitDeviceBooted(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_poll_for_boot_completion(Dev,
+ VL53L1_BOOT_COMPLETION_POLLING_TIMEOUT_MS);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+
+static VL53L1_Error ComputeDevicePresetMode(
+ VL53L1_PresetModes PresetMode,
+ VL53L1_DistanceModes DistanceMode,
+ uint16_t *pdss_config__target_total_rate_mcps,
+ uint32_t *pphasecal_config_timeout_us,
+ VL53L1_DevicePresetModes *pDevicePresetMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ *pDevicePresetMode = VL53L1_DEVICEPRESETMODE_STANDARD_RANGING;
+
+ switch (PresetMode) {
+ case VL53L1_PRESETMODE_LITE_RANGING:
+ *pdss_config__target_total_rate_mcps = 0x0A00;
+ *pphasecal_config_timeout_us = 1000;
+
+ if (DistanceMode == VL53L1_DISTANCEMODE_SHORT)
+ *pDevicePresetMode =
+ VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_SHORT_RANGE;
+ else if (DistanceMode == VL53L1_DISTANCEMODE_MEDIUM)
+ *pDevicePresetMode =
+ VL53L1_DEVICEPRESETMODE_STANDARD_RANGING;
+ else
+
+ *pDevicePresetMode =
+ VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_LONG_RANGE;
+ break;
+ case VL53L1_PRESETMODE_RANGING:
+ *pdss_config__target_total_rate_mcps = 0x1400;
+ *pphasecal_config_timeout_us = 4000;
+
+ if (DistanceMode == VL53L1_DISTANCEMODE_SHORT)
+ *pDevicePresetMode =
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE;
+ else if (DistanceMode == VL53L1_DISTANCEMODE_MEDIUM)
+ *pDevicePresetMode =
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE;
+ else
+
+ *pDevicePresetMode =
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE;
+ break;
+ case VL53L1_PRESETMODE_MULTIZONES_SCANNING:
+ *pdss_config__target_total_rate_mcps = 0x1400;
+ *pphasecal_config_timeout_us = 4000;
+
+ if (DistanceMode == VL53L1_DISTANCEMODE_SHORT)
+ *pDevicePresetMode =
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_SHORT_RANGE;
+ else if (DistanceMode == VL53L1_DISTANCEMODE_MEDIUM)
+ *pDevicePresetMode =
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE;
+ else
+
+ *pDevicePresetMode =
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_LONG_RANGE;
+ break;
+ case VL53L1_PRESETMODE_AUTONOMOUS:
+ *pdss_config__target_total_rate_mcps = 0x0A00;
+ *pphasecal_config_timeout_us = 1000;
+
+ if (DistanceMode == VL53L1_DISTANCEMODE_SHORT)
+ *pDevicePresetMode =
+ VL53L1_DEVICEPRESETMODE_TIMED_RANGING_SHORT_RANGE;
+ else if (DistanceMode == VL53L1_DISTANCEMODE_MEDIUM)
+ *pDevicePresetMode =
+ VL53L1_DEVICEPRESETMODE_TIMED_RANGING;
+ else
+
+ *pDevicePresetMode =
+ VL53L1_DEVICEPRESETMODE_TIMED_RANGING_LONG_RANGE;
+ break;
+ case VL53L1_PRESETMODE_OLT:
+ *pdss_config__target_total_rate_mcps = 0x0A00;
+ *pphasecal_config_timeout_us = 1000;
+
+ *pDevicePresetMode = VL53L1_DEVICEPRESETMODE_OLT;
+ break;
+ default:
+
+
+ Status = VL53L1_ERROR_MODE_NOT_SUPPORTED;
+ }
+
+ return Status;
+}
+
+static VL53L1_Error SetPresetMode(VL53L1_DEV Dev,
+ VL53L1_PresetModes PresetMode,
+ VL53L1_DistanceModes DistanceMode,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint32_t inter_measurement_period_ms)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_DevicePresetModes device_preset_mode;
+ uint8_t measurement_mode;
+ uint16_t dss_config__target_total_rate_mcps;
+ uint32_t phasecal_config_timeout_us;
+
+ LOG_FUNCTION_START("%d", (int)PresetMode);
+
+ if (PresetMode == VL53L1_PRESETMODE_AUTONOMOUS)
+ measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_TIMED;
+ else
+ measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+
+
+ Status = ComputeDevicePresetMode(
+ PresetMode,
+ DistanceMode,
+ &dss_config__target_total_rate_mcps,
+ &phasecal_config_timeout_us,
+ &device_preset_mode);
+
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_set_preset_mode(
+ Dev,
+ device_preset_mode,
+ dss_config__target_total_rate_mcps,
+ phasecal_config_timeout_us,
+ mm_config_timeout_us,
+ range_config_timeout_us,
+ inter_measurement_period_ms);
+
+ if (Status == VL53L1_ERROR_NONE)
+ PALDevDataSet(Dev, LLData.measurement_mode, measurement_mode);
+
+ if (Status == VL53L1_ERROR_NONE)
+ PALDevDataSet(Dev, CurrentParameters.PresetMode, PresetMode);
+
+ PALDevDataSet(Dev, CurrentParameters.OutputMode,
+ VL53L1_OUTPUTMODE_NEAREST);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetPresetMode(VL53L1_DEV Dev, VL53L1_PresetModes PresetMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("%d", (int)PresetMode);
+
+
+
+
+
+
+ Status = SetPresetMode(Dev,
+ PresetMode,
+ VL53L1_DISTANCEMODE_LONG,
+ 2000,
+ 16000,
+ 1000);
+
+
+ if (Status == VL53L1_ERROR_NONE) {
+ PALDevDataSet(Dev, CurrentParameters.InternalDistanceMode,
+ VL53L1_DISTANCEMODE_LONG);
+
+ PALDevDataSet(Dev, CurrentParameters.NewDistanceMode,
+ VL53L1_DISTANCEMODE_LONG);
+
+ if (PresetMode == VL53L1_PRESETMODE_LITE_RANGING)
+
+
+ Status = VL53L1_SetMeasurementTimingBudgetMicroSeconds(
+ Dev, 33000);
+ else
+
+
+ Status = VL53L1_SetMeasurementTimingBudgetMicroSeconds(
+ Dev, 16000);
+ }
+
+ if (Status == VL53L1_ERROR_NONE) {
+
+
+ Status = VL53L1_SetInterMeasurementPeriodMilliSeconds(Dev,
+ 1000);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetPresetMode(VL53L1_DEV Dev,
+ VL53L1_PresetModes *pPresetMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pPresetMode = PALDevDataGet(Dev, CurrentParameters.PresetMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetDistanceMode(VL53L1_DEV Dev,
+ VL53L1_DistanceModes DistanceMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_PresetModes PresetMode;
+ VL53L1_DistanceModes InternalDistanceMode;
+ uint32_t mm_config_timeout_us;
+ uint32_t range_config_timeout_us;
+ uint32_t inter_measurement_period_ms;
+ uint8_t manual_not_auto = 0;
+
+ LOG_FUNCTION_START("%d", (int)DistanceMode);
+
+ PresetMode = PALDevDataGet(Dev, CurrentParameters.PresetMode);
+
+
+
+
+
+
+
+
+ if ((DistanceMode == VL53L1_DISTANCEMODE_SHORT) ||
+ (DistanceMode == VL53L1_DISTANCEMODE_MEDIUM) ||
+ (DistanceMode == VL53L1_DISTANCEMODE_LONG))
+ manual_not_auto = 1;
+ else
+ manual_not_auto = 0;
+
+
+ if ((manual_not_auto == 0) &&
+ ((PresetMode != VL53L1_PRESETMODE_LITE_RANGING) &&
+ (PresetMode != VL53L1_PRESETMODE_RANGING))) {
+ Status = VL53L1_ERROR_MODE_NOT_SUPPORTED;
+ }
+
+
+
+
+
+ if (Status == VL53L1_ERROR_NONE) {
+ if ((DistanceMode == VL53L1_DISTANCEMODE_SHORT) ||
+ (DistanceMode == VL53L1_DISTANCEMODE_MEDIUM))
+ InternalDistanceMode = DistanceMode;
+ else
+
+ InternalDistanceMode = VL53L1_DISTANCEMODE_LONG;
+ }
+
+ mm_config_timeout_us = PALDevDataGet(Dev, LLData.mm_config_timeout_us);
+ range_config_timeout_us = PALDevDataGet(Dev,
+ LLData.range_config_timeout_us);
+ inter_measurement_period_ms = PALDevDataGet(Dev,
+ LLData.inter_measurement_period_ms);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = SetPresetMode(Dev,
+ PresetMode,
+ InternalDistanceMode,
+ mm_config_timeout_us,
+ range_config_timeout_us,
+ inter_measurement_period_ms);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ PALDevDataSet(Dev, CurrentParameters.InternalDistanceMode,
+ InternalDistanceMode);
+ PALDevDataSet(Dev, CurrentParameters.NewDistanceMode,
+ InternalDistanceMode);
+ PALDevDataSet(Dev, CurrentParameters.DistanceMode,
+ DistanceMode);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetDistanceMode(VL53L1_DEV Dev,
+ VL53L1_DistanceModes *pDistanceMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pDistanceMode = PALDevDataGet(Dev, CurrentParameters.DistanceMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetOutputMode(VL53L1_DEV Dev,
+ VL53L1_OutputModes OutputMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if ((OutputMode != VL53L1_OUTPUTMODE_NEAREST) &&
+ (OutputMode != VL53L1_OUTPUTMODE_STRONGEST))
+ Status = VL53L1_ERROR_MODE_NOT_SUPPORTED;
+ else
+ PALDevDataSet(Dev, CurrentParameters.OutputMode, OutputMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetOutputMode(VL53L1_DEV Dev,
+ VL53L1_OutputModes *pOutputMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pOutputMode = PALDevDataGet(Dev, CurrentParameters.OutputMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+VL53L1_Error VL53L1_SetMeasurementTimingBudgetMicroSeconds(VL53L1_DEV Dev,
+ uint32_t MeasurementTimingBudgetMicroSeconds)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t Mm1Enabled;
+ uint8_t Mm2Enabled;
+ uint32_t TimingGuard;
+ uint32_t divisor;
+ uint32_t TimingBudget;
+ uint32_t MmTimeoutUs;
+ VL53L1_PresetModes PresetMode;
+ uint32_t PhaseCalTimeoutUs;
+
+ LOG_FUNCTION_START("");
+
+
+
+ if (MeasurementTimingBudgetMicroSeconds > 10000000)
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+
+ if (Status == VL53L1_ERROR_NONE) {
+ Status = VL53L1_GetSequenceStepEnable(Dev,
+ VL53L1_SEQUENCESTEP_MM1, &Mm1Enabled);
+ }
+
+ if (Status == VL53L1_ERROR_NONE) {
+ Status = VL53L1_GetSequenceStepEnable(Dev,
+ VL53L1_SEQUENCESTEP_MM2, &Mm2Enabled);
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_get_timeouts_us(Dev,
+ &PhaseCalTimeoutUs,
+ &MmTimeoutUs,
+ &TimingBudget);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ PresetMode = PALDevDataGet(Dev, CurrentParameters.PresetMode);
+
+ TimingGuard = 0;
+ divisor = 1;
+ switch (PresetMode) {
+ case VL53L1_PRESETMODE_LITE_RANGING:
+ case VL53L1_PRESETMODE_AUTONOMOUS:
+ if ((Mm1Enabled == 1) || (Mm2Enabled == 1))
+ TimingGuard = 5000;
+ else
+ TimingGuard = 1000;
+ break;
+ case VL53L1_PRESETMODE_RANGING:
+ case VL53L1_PRESETMODE_MULTIZONES_SCANNING:
+ TimingGuard = 1700;
+ divisor = 6;
+ break;
+ case VL53L1_PRESETMODE_OLT:
+ TimingGuard = MmTimeoutUs + 5000;
+ break;
+ default:
+
+
+ Status = VL53L1_ERROR_MODE_NOT_SUPPORTED;
+ }
+
+ if (MeasurementTimingBudgetMicroSeconds > TimingGuard) {
+ TimingBudget = (MeasurementTimingBudgetMicroSeconds
+ - TimingGuard) / divisor;
+
+ Status = VL53L1_set_timeouts_us(
+ Dev,
+ PhaseCalTimeoutUs,
+ MmTimeoutUs,
+ TimingBudget);
+
+ if (Status == VL53L1_ERROR_NONE)
+ PALDevDataSet(Dev,
+ LLData.range_config_timeout_us,
+ TimingBudget);
+ } else {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+ }
+ if (Status == VL53L1_ERROR_NONE) {
+ PALDevDataSet(Dev,
+ CurrentParameters.MeasurementTimingBudgetMicroSeconds,
+ MeasurementTimingBudgetMicroSeconds);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetMeasurementTimingBudgetMicroSeconds(VL53L1_DEV Dev,
+ uint32_t *pMeasurementTimingBudgetMicroSeconds)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t Mm1Enabled = 0;
+ uint8_t Mm2Enabled = 0;
+ uint32_t MmTimeoutUs = 0;
+ uint32_t RangeTimeoutUs = 0;
+ uint32_t MeasTimingBdg = 0;
+ uint32_t PhaseCalTimeoutUs = 0;
+ VL53L1_PresetModes PresetMode;
+
+ LOG_FUNCTION_START("");
+
+ *pMeasurementTimingBudgetMicroSeconds = 0;
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_GetSequenceStepEnable(Dev,
+ VL53L1_SEQUENCESTEP_MM1, &Mm1Enabled);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_GetSequenceStepEnable(Dev,
+ VL53L1_SEQUENCESTEP_MM2, &Mm2Enabled);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_get_timeouts_us(Dev,
+ &PhaseCalTimeoutUs,
+ &MmTimeoutUs,
+ &RangeTimeoutUs);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ PresetMode = PALDevDataGet(Dev, CurrentParameters.PresetMode);
+
+ switch (PresetMode) {
+ case VL53L1_PRESETMODE_LITE_RANGING:
+ case VL53L1_PRESETMODE_AUTONOMOUS:
+ if ((Mm1Enabled == 1) || (Mm2Enabled == 1))
+ MeasTimingBdg = RangeTimeoutUs + 5000;
+ else
+ MeasTimingBdg = RangeTimeoutUs + 1000;
+
+ break;
+ case VL53L1_PRESETMODE_RANGING:
+ MeasTimingBdg = (6 * RangeTimeoutUs) + 1700;
+ break;
+ case VL53L1_PRESETMODE_MULTIZONES_SCANNING:
+ MeasTimingBdg = (6 * RangeTimeoutUs) + 1700;
+ break;
+ case VL53L1_PRESETMODE_OLT:
+ MeasTimingBdg = RangeTimeoutUs + MmTimeoutUs + 5000;
+ break;
+ default:
+
+
+ Status = VL53L1_ERROR_MODE_NOT_SUPPORTED;
+ }
+ }
+ if (Status == VL53L1_ERROR_NONE)
+ *pMeasurementTimingBudgetMicroSeconds = MeasTimingBdg;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+VL53L1_Error VL53L1_SetInterMeasurementPeriodMilliSeconds(VL53L1_DEV Dev,
+ uint32_t InterMeasurementPeriodMilliSeconds)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_set_inter_measurement_period_ms(Dev,
+ InterMeasurementPeriodMilliSeconds);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetInterMeasurementPeriodMilliSeconds(VL53L1_DEV Dev,
+ uint32_t *pInterMeasurementPeriodMilliSeconds)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_inter_measurement_period_ms(Dev,
+ pInterMeasurementPeriodMilliSeconds);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetDmaxReflectance(VL53L1_DEV Dev,
+ FixPoint1616_t value)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_dmax_reflectance_array_t dmax_reflectances;
+
+ LOG_FUNCTION_START("");
+ Status = VL53L1_get_dmax_reflectance_values(Dev, &dmax_reflectances);
+ if (Status == VL53L1_ERROR_NONE) {
+ dmax_reflectances.target_reflectance_for_dmax[DMAX_REFLECTANCE_IDX] =
+ VL53L1_FIXPOINT1616TOFIXPOINT72(value);
+ Status = VL53L1_set_dmax_reflectance_values(Dev, &dmax_reflectances);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetDmaxReflectance(VL53L1_DEV Dev,
+ FixPoint1616_t *pvalue)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_dmax_reflectance_array_t dmax_reflectances;
+ uint16_t r;
+
+ LOG_FUNCTION_START("");
+ Status = VL53L1_get_dmax_reflectance_values(Dev, &dmax_reflectances);
+ if (Status == VL53L1_ERROR_NONE) {
+ r = dmax_reflectances.target_reflectance_for_dmax[DMAX_REFLECTANCE_IDX];
+ *pvalue = VL53L1_FIXPOINT72TOFIXPOINT1616(r);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_SetDmaxMode(VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxModes DmaxMode)
+{
+
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_DeviceDmaxMode dmax_mode;
+
+ LOG_FUNCTION_START("");
+
+ switch(DmaxMode) {
+ case DMAXMODE_FMT_CAL_DATA:
+ dmax_mode = VL53L1_DEVICEDMAXMODE__FMT_CAL_DATA;
+ break;
+ case DMAXMODE_CUSTCAL_DATA:
+ dmax_mode = VL53L1_DEVICEDMAXMODE__CUST_CAL_DATA;
+ break;
+ case DMAXMODE_PER_ZONE_CAL_DATA:
+ dmax_mode = VL53L1_DEVICEDMAXMODE__PER_ZONE_CAL_DATA;
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ break;
+ }
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_set_dmax_mode(Dev, dmax_mode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetDmaxMode(VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxModes *pDmaxMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_DeviceDmaxMode dmax_mode;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_dmax_mode(Dev, &dmax_mode);
+ if (Status == VL53L1_ERROR_NONE) {
+ switch(dmax_mode) {
+ case VL53L1_DEVICEDMAXMODE__FMT_CAL_DATA:
+ *pDmaxMode = DMAXMODE_FMT_CAL_DATA;
+ break;
+ case VL53L1_DEVICEDMAXMODE__CUST_CAL_DATA:
+ *pDmaxMode = DMAXMODE_CUSTCAL_DATA;
+ break;
+ case VL53L1_DEVICEDMAXMODE__PER_ZONE_CAL_DATA:
+ *pDmaxMode = DMAXMODE_PER_ZONE_CAL_DATA;
+ break;
+ default:
+
+
+ *pDmaxMode = VL53L1_ERROR_NOT_IMPLEMENTED;
+ break;
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_GetNumberOfLimitCheck(uint16_t *pNumberOfLimitCheck)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pNumberOfLimitCheck = VL53L1_CHECKENABLE_NUMBER_OF_CHECKS;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetLimitCheckInfo(uint16_t LimitCheckId,
+ char *pLimitCheckString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_limit_check_info(LimitCheckId,
+ pLimitCheckString);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetLimitCheckStatus(VL53L1_DEV Dev, uint16_t LimitCheckId,
+ uint8_t *pLimitCheckStatus)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t Temp8;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ } else {
+ VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
+ LimitCheckId, Temp8);
+ *pLimitCheckStatus = Temp8;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+static VL53L1_Error SetLimitValue(VL53L1_DEV Dev, uint16_t LimitCheckId,
+ FixPoint1616_t value)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint16_t *pmin_count_rate;
+
+ uint16_t tmpuint16;
+
+
+ LOG_FUNCTION_START("");
+
+ pmin_count_rate = &(PALDevDataGet(Dev,
+ LLData.tim_cfg.range_config__min_count_rate_rtn_limit_mcps));
+
+ switch (LimitCheckId) {
+ case VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE:
+ tmpuint16 = VL53L1_FIXPOINT1616TOFIXPOINT142(value);
+ PALDevDataSet(Dev, LLData.tim_cfg.range_config__sigma_thresh,
+ tmpuint16);
+ break;
+ case VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+ tmpuint16 = VL53L1_FIXPOINT1616TOFIXPOINT97(value);
+
+ *pmin_count_rate = tmpuint16;
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_SetLimitCheckEnable(VL53L1_DEV Dev, uint16_t LimitCheckId,
+ uint8_t LimitCheckEnable)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ FixPoint1616_t TempFix1616 = 0;
+
+ LOG_FUNCTION_START("");
+
+
+ if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ } else {
+
+
+ if (LimitCheckEnable == 0)
+ TempFix1616 = 0;
+ else
+ VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
+ LimitCheckId, TempFix1616);
+
+ Status = SetLimitValue(Dev, LimitCheckId, TempFix1616);
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksEnable,
+ LimitCheckId,
+ ((LimitCheckEnable == 0) ? 0 : 1));
+
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetLimitCheckEnable(VL53L1_DEV Dev, uint16_t LimitCheckId,
+ uint8_t *pLimitCheckEnable)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t Temp8;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ *pLimitCheckEnable = 0;
+ } else {
+ VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
+ LimitCheckId, Temp8);
+ *pLimitCheckEnable = Temp8;
+ }
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetLimitCheckValue(VL53L1_DEV Dev, uint16_t LimitCheckId,
+ FixPoint1616_t LimitCheckValue)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t LimitChecksEnable;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ } else {
+
+ VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
+ LimitCheckId,
+ LimitChecksEnable);
+
+ if (LimitChecksEnable == 0) {
+
+
+ VL53L1_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
+ LimitCheckId, LimitCheckValue);
+ } else {
+
+ Status = SetLimitValue(Dev, LimitCheckId,
+ LimitCheckValue);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksValue,
+ LimitCheckId, LimitCheckValue);
+ }
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetLimitCheckValue(VL53L1_DEV Dev, uint16_t LimitCheckId,
+ FixPoint1616_t *pLimitCheckValue)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint16_t MinCountRate;
+ FixPoint1616_t TempFix1616;
+ uint16_t SigmaThresh;
+
+ LOG_FUNCTION_START("");
+
+ MinCountRate = PALDevDataGet(Dev,
+ LLData.tim_cfg.range_config__min_count_rate_rtn_limit_mcps);
+
+ switch (LimitCheckId) {
+ case VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE:
+ SigmaThresh = PALDevDataGet(Dev,
+ LLData.tim_cfg.range_config__sigma_thresh);
+ TempFix1616 = VL53L1_FIXPOINT142TOFIXPOINT1616(SigmaThresh);
+ break;
+ case VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+ TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616(MinCountRate);
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ if (Status == VL53L1_ERROR_NONE) {
+
+ if (TempFix1616 == 0) {
+
+
+ VL53L1_GETARRAYPARAMETERFIELD(Dev,
+ LimitChecksValue, LimitCheckId,
+ TempFix1616);
+ *pLimitCheckValue = TempFix1616;
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksEnable, LimitCheckId, 0);
+ } else {
+ *pLimitCheckValue = TempFix1616;
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksValue, LimitCheckId,
+ TempFix1616);
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksEnable, LimitCheckId, 1);
+ }
+ }
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+VL53L1_Error VL53L1_GetLimitCheckCurrent(VL53L1_DEV Dev, uint16_t LimitCheckId,
+ FixPoint1616_t *pLimitCheckCurrent)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ FixPoint1616_t TempFix1616 = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ } else {
+ VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksCurrent,
+ LimitCheckId, TempFix1616);
+ *pLimitCheckCurrent = TempFix1616;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_GetMaxNumberOfROI(VL53L1_DEV Dev,
+ uint8_t *pMaxNumberOfROI)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_PresetModes PresetMode;
+
+ LOG_FUNCTION_START("");
+
+ PresetMode = PALDevDataGet(Dev, CurrentParameters.PresetMode);
+
+
+
+ if (PresetMode == VL53L1_PRESETMODE_MULTIZONES_SCANNING)
+ *pMaxNumberOfROI = VL53L1_MAX_USER_ZONES;
+ else
+ *pMaxNumberOfROI = 1;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetROI(VL53L1_DEV Dev,
+ VL53L1_RoiConfig_t *pRoiConfig)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_PresetModes PresetMode;
+ uint8_t MaxNumberOfROI;
+ VL53L1_zone_config_t zone_cfg;
+ VL53L1_UserRoi_t CurrROI;
+ uint8_t i;
+ uint8_t x_centre;
+ uint8_t y_centre;
+ uint8_t width, height;
+
+ LOG_FUNCTION_START("");
+
+
+
+ PresetMode = PALDevDataGet(Dev, CurrentParameters.PresetMode);
+
+
+
+ if (PresetMode == VL53L1_PRESETMODE_MULTIZONES_SCANNING)
+ MaxNumberOfROI = VL53L1_MAX_USER_ZONES;
+ else
+ MaxNumberOfROI = 1;
+
+ if ((pRoiConfig->NumberOfRoi > MaxNumberOfROI) ||
+ (pRoiConfig->NumberOfRoi < 1))
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+
+ if (Status == VL53L1_ERROR_NONE) {
+
+
+
+ zone_cfg.max_zones = MaxNumberOfROI;
+ zone_cfg.active_zones = pRoiConfig->NumberOfRoi - 1;
+
+ for (i = 0; i < pRoiConfig->NumberOfRoi; i++) {
+ CurrROI = pRoiConfig->UserRois[i];
+
+
+
+
+
+
+
+
+
+ Status = CheckValidRectRoi(CurrROI);
+ if (Status != VL53L1_ERROR_NONE)
+ break;
+
+ x_centre = (CurrROI.BotRightX + CurrROI.TopLeftX + 1)
+ / 2;
+ y_centre = (CurrROI.TopLeftY + CurrROI.BotRightY + 1)
+ / 2;
+ width = (CurrROI.BotRightX - CurrROI.TopLeftX);
+ height = (CurrROI.TopLeftY - CurrROI.BotRightY);
+ if ((width < 3) || (height < 3)) {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ break;
+ }
+ zone_cfg.user_zones[i].x_centre = x_centre;
+ zone_cfg.user_zones[i].y_centre = y_centre;
+ zone_cfg.user_zones[i].width = width;
+ zone_cfg.user_zones[i].height = height;
+ }
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_set_zone_config(Dev, &zone_cfg);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetROI(VL53L1_DEV Dev,
+ VL53L1_RoiConfig_t *pRoiConfig)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_zone_config_t zone_cfg;
+ uint8_t i;
+ uint8_t TopLeftX;
+ uint8_t TopLeftY;
+ uint8_t BotRightX;
+ uint8_t BotRightY;
+
+ LOG_FUNCTION_START("");
+
+ VL53L1_get_zone_config(Dev, &zone_cfg);
+
+ pRoiConfig->NumberOfRoi = zone_cfg.active_zones + 1;
+
+ for (i = 0; i < pRoiConfig->NumberOfRoi; i++) {
+ TopLeftX = (2 * zone_cfg.user_zones[i].x_centre -
+ zone_cfg.user_zones[i].width) >> 1;
+ TopLeftY = (2 * zone_cfg.user_zones[i].y_centre +
+ zone_cfg.user_zones[i].height) >> 1;
+ BotRightX = (2 * zone_cfg.user_zones[i].x_centre +
+ zone_cfg.user_zones[i].width) >> 1;
+ BotRightY = (2 * zone_cfg.user_zones[i].y_centre -
+ zone_cfg.user_zones[i].height) >> 1;
+ pRoiConfig->UserRois[i].TopLeftX = TopLeftX;
+ pRoiConfig->UserRois[i].TopLeftY = TopLeftY;
+ pRoiConfig->UserRois[i].BotRightX = BotRightX;
+ pRoiConfig->UserRois[i].BotRightY = BotRightY;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_GetNumberOfSequenceSteps(VL53L1_DEV Dev,
+ uint8_t *pNumberOfSequenceSteps)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ SUPPRESS_UNUSED_WARNING(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pNumberOfSequenceSteps = VL53L1_SEQUENCESTEP_NUMBER_OF_ITEMS;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetSequenceStepsInfo(VL53L1_SequenceStepId SequenceStepId,
+ char *pSequenceStepsString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_sequence_steps_info(
+ SequenceStepId,
+ pSequenceStepsString);
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetSequenceStepEnable(VL53L1_DEV Dev,
+ VL53L1_SequenceStepId SequenceStepId, uint8_t SequenceStepEnabled)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t SequenceConfig = 0;
+ uint8_t SequenceConfigNew = 0;
+ uint32_t MeasurementTimingBudgetMicroSeconds;
+
+ LOG_FUNCTION_START("");
+
+ SequenceConfig = PALDevDataGet(Dev,
+ LLData.dyn_cfg.system__sequence_config);
+
+ SequenceConfigNew = SequenceConfig;
+
+ if (Status == VL53L1_ERROR_NONE) {
+ if (SequenceStepEnabled == 1) {
+
+
+
+
+ switch (SequenceStepId) {
+ case VL53L1_SEQUENCESTEP_VHV:
+ SequenceConfigNew |= 0x01;
+ break;
+ case VL53L1_SEQUENCESTEP_PHASECAL:
+ SequenceConfigNew |= 0x02;
+ break;
+ case VL53L1_SEQUENCESTEP_REFPHASE:
+ SequenceConfigNew |= 0x04;
+ break;
+ case VL53L1_SEQUENCESTEP_DSS1:
+ SequenceConfigNew |= 0x08;
+ break;
+ case VL53L1_SEQUENCESTEP_DSS2:
+ SequenceConfigNew |= 0x10;
+ break;
+ case VL53L1_SEQUENCESTEP_MM1:
+ SequenceConfigNew |= 0x20;
+ break;
+ case VL53L1_SEQUENCESTEP_MM2:
+ SequenceConfigNew |= 0x40;
+ break;
+ case VL53L1_SEQUENCESTEP_RANGE:
+ SequenceConfigNew |= 0x80;
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+ } else {
+
+
+
+ switch (SequenceStepId) {
+ case VL53L1_SEQUENCESTEP_VHV:
+ SequenceConfigNew &= 0xfe;
+ break;
+ case VL53L1_SEQUENCESTEP_PHASECAL:
+ SequenceConfigNew &= 0xfd;
+ break;
+ case VL53L1_SEQUENCESTEP_REFPHASE:
+ SequenceConfigNew &= 0xfb;
+ break;
+ case VL53L1_SEQUENCESTEP_DSS1:
+ SequenceConfigNew &= 0xf7;
+ break;
+ case VL53L1_SEQUENCESTEP_DSS2:
+ SequenceConfigNew &= 0xef;
+ break;
+ case VL53L1_SEQUENCESTEP_MM1:
+ SequenceConfigNew &= 0xdf;
+ break;
+ case VL53L1_SEQUENCESTEP_MM2:
+ SequenceConfigNew &= 0xbf;
+ break;
+ case VL53L1_SEQUENCESTEP_RANGE:
+ SequenceConfigNew &= 0x7f;
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+ }
+ }
+
+
+
+ if ((SequenceConfigNew != SequenceConfig) &&
+ (Status == VL53L1_ERROR_NONE)) {
+ PALDevDataSet(Dev, LLData.dyn_cfg.system__sequence_config,
+ SequenceConfigNew);
+
+
+
+ MeasurementTimingBudgetMicroSeconds = PALDevDataGet(Dev,
+ CurrentParameters.MeasurementTimingBudgetMicroSeconds);
+
+ VL53L1_SetMeasurementTimingBudgetMicroSeconds(Dev,
+ MeasurementTimingBudgetMicroSeconds);
+ }
+
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetSequenceStepEnable(VL53L1_DEV Dev,
+ VL53L1_SequenceStepId SequenceStepId, uint8_t *pSequenceStepEnabled)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t SequenceConfig = 0;
+
+ LOG_FUNCTION_START("");
+
+ SequenceConfig = PALDevDataGet(Dev,
+ LLData.dyn_cfg.system__sequence_config);
+
+ switch (SequenceStepId) {
+ case VL53L1_SEQUENCESTEP_VHV:
+ *pSequenceStepEnabled = SequenceConfig & 0x01;
+ break;
+ case VL53L1_SEQUENCESTEP_PHASECAL:
+ *pSequenceStepEnabled = (SequenceConfig & 0x02) >> 1;
+ break;
+ case VL53L1_SEQUENCESTEP_REFPHASE:
+ *pSequenceStepEnabled = (SequenceConfig & 0x04) >> 2;
+ break;
+ case VL53L1_SEQUENCESTEP_DSS1:
+ *pSequenceStepEnabled = (SequenceConfig & 0x08) >> 3;
+ break;
+ case VL53L1_SEQUENCESTEP_DSS2:
+ *pSequenceStepEnabled = (SequenceConfig & 0x10) >> 4;
+ break;
+ case VL53L1_SEQUENCESTEP_MM1:
+ *pSequenceStepEnabled = (SequenceConfig & 0x20) >> 5;
+ break;
+ case VL53L1_SEQUENCESTEP_MM2:
+ *pSequenceStepEnabled = (SequenceConfig & 0x40) >> 6;
+ break;
+ case VL53L1_SEQUENCESTEP_RANGE:
+ *pSequenceStepEnabled = (SequenceConfig & 0x80) >> 7;
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_StartMeasurement(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t DeviceMeasurementMode;
+ VL53L1_State CurrPalState;
+
+ LOG_FUNCTION_START("");
+
+ CurrPalState = PALDevDataGet(Dev, PalState);
+ switch (CurrPalState) {
+ case VL53L1_STATE_IDLE:
+ Status = VL53L1_ERROR_NONE;
+ break;
+ case VL53L1_STATE_POWERDOWN:
+ case VL53L1_STATE_WAIT_STATICINIT:
+ case VL53L1_STATE_STANDBY:
+ case VL53L1_STATE_RUNNING:
+ case VL53L1_STATE_RESET:
+ case VL53L1_STATE_UNKNOWN:
+ case VL53L1_STATE_ERROR:
+ Status = VL53L1_ERROR_INVALID_COMMAND;
+ break;
+ default:
+ Status = VL53L1_ERROR_UNDEFINED;
+ }
+
+ DeviceMeasurementMode = PALDevDataGet(Dev, LLData.measurement_mode);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_init_and_start_range(
+ Dev,
+ DeviceMeasurementMode,
+ VL53L1_DEVICECONFIGLEVEL_FULL);
+
+ if (Status == VL53L1_ERROR_NONE) {
+
+
+ PALDevDataSet(Dev, PalState, VL53L1_STATE_RUNNING);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_StopMeasurement(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_stop_range(Dev);
+
+ if (Status == VL53L1_ERROR_NONE) {
+
+
+ PALDevDataSet(Dev, PalState, VL53L1_STATE_IDLE);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+static VL53L1_Error ChangePresetMode(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_PresetModes PresetMode;
+ VL53L1_DistanceModes NewDistanceMode;
+ VL53L1_zone_config_t zone_config;
+ uint8_t DeviceMeasurementMode;
+ uint32_t mm_config_timeout_us;
+ uint32_t range_config_timeout_us;
+ uint32_t inter_measurement_period_ms;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_zone_config(Dev, &zone_config);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_stop_range(Dev);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_WaitUs(Dev, 500);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ PresetMode = PALDevDataGet(Dev,
+ CurrentParameters.PresetMode);
+ NewDistanceMode = PALDevDataGet(Dev,
+ CurrentParameters.NewDistanceMode);
+ mm_config_timeout_us = PALDevDataGet(Dev,
+ LLData.mm_config_timeout_us);
+ range_config_timeout_us = PALDevDataGet(Dev,
+ LLData.range_config_timeout_us);
+ inter_measurement_period_ms = PALDevDataGet(Dev,
+ LLData.inter_measurement_period_ms);
+
+ Status = SetPresetMode(Dev,
+ PresetMode,
+ NewDistanceMode,
+ mm_config_timeout_us,
+ range_config_timeout_us,
+ inter_measurement_period_ms);
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_set_zone_config(Dev, &zone_config);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ DeviceMeasurementMode = PALDevDataGet(Dev,
+ LLData.measurement_mode);
+
+ Status = VL53L1_init_and_start_range(
+ Dev,
+ DeviceMeasurementMode,
+ VL53L1_DEVICECONFIGLEVEL_FULL);
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ PALDevDataSet(Dev,
+ CurrentParameters.InternalDistanceMode,
+ NewDistanceMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_ClearInterruptAndStartMeasurement(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t DeviceMeasurementMode;
+ VL53L1_DistanceModes InternalDistanceMode;
+ VL53L1_DistanceModes NewDistanceMode;
+
+ LOG_FUNCTION_START("");
+
+ DeviceMeasurementMode = PALDevDataGet(Dev, LLData.measurement_mode);
+ InternalDistanceMode = PALDevDataGet(Dev,
+ CurrentParameters.InternalDistanceMode);
+ NewDistanceMode = PALDevDataGet(Dev,
+ CurrentParameters.NewDistanceMode);
+
+ if (NewDistanceMode != InternalDistanceMode)
+ Status = ChangePresetMode(Dev);
+ else
+ Status = VL53L1_clear_interrupt_and_enable_next_range(
+ Dev,
+ DeviceMeasurementMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetMeasurementDataReady(VL53L1_DEV Dev,
+ uint8_t *pMeasurementDataReady)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_is_new_data_ready(Dev, pMeasurementDataReady);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_WaitMeasurementDataReady(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ Status = VL53L1_poll_for_range_completion(Dev,
+ VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+static void GenNewPresetMode(VL53L1_DEV Dev, int16_t RefRange)
+{
+ VL53L1_DistanceModes InternalDistanceMode;
+ VL53L1_DistanceModes NewDistanceMode;
+ uint16_t HRLI = 600;
+ uint16_t HRLH = 700;
+ uint16_t MRLI = 1400;
+ uint16_t MRLH = 1500;
+
+ InternalDistanceMode = PALDevDataGet(Dev,
+ CurrentParameters.InternalDistanceMode);
+
+ NewDistanceMode = InternalDistanceMode;
+ switch (InternalDistanceMode) {
+ case VL53L1_DISTANCEMODE_SHORT:
+
+
+
+
+
+ if (RefRange > MRLH)
+ NewDistanceMode = VL53L1_DISTANCEMODE_LONG;
+ else if (RefRange > HRLH)
+ NewDistanceMode = VL53L1_DISTANCEMODE_MEDIUM;
+ break;
+ case VL53L1_DISTANCEMODE_MEDIUM:
+
+
+
+
+
+ if (RefRange > MRLH)
+ NewDistanceMode = VL53L1_DISTANCEMODE_LONG;
+ else if (RefRange < HRLI)
+ NewDistanceMode = VL53L1_DISTANCEMODE_SHORT;
+ break;
+ default:
+
+
+
+
+
+
+ if (RefRange < HRLI)
+ NewDistanceMode = VL53L1_DISTANCEMODE_SHORT;
+ else if (RefRange < MRLI)
+ NewDistanceMode = VL53L1_DISTANCEMODE_MEDIUM;
+ break;
+ }
+
+ PALDevDataSet(Dev, CurrentParameters.NewDistanceMode, NewDistanceMode);
+
+}
+
+static void CheckAndChangeDistanceMode(VL53L1_DEV Dev,
+ VL53L1_RangingMeasurementData_t *pRangeData,
+ int16_t AmbientDmaxMm)
+{
+
+ VL53L1_DistanceModes DistanceMode;
+ int16_t RefRange;
+ uint8_t RangeValid;
+
+
+
+
+
+
+ RangeValid = (pRangeData->RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID)
+ ? 1: 0;
+
+ RefRange = (RangeValid == 1) ? pRangeData->RangeMilliMeter :
+ AmbientDmaxMm;
+
+ DistanceMode = PALDevDataGet(Dev, CurrentParameters.DistanceMode);
+
+ if (((DistanceMode == VL53L1_DISTANCEMODE_AUTO_LITE) &&
+ (RangeValid == 0)) ||
+ ((DistanceMode == VL53L1_DISTANCEMODE_AUTO) &&
+ (RangeValid == 0) && (AmbientDmaxMm == 0))) {
+ PALDevDataSet(Dev, CurrentParameters.NewDistanceMode,
+ VL53L1_DISTANCEMODE_LONG);
+
+ } else if ((DistanceMode == VL53L1_DISTANCEMODE_AUTO_LITE) ||
+ (DistanceMode == VL53L1_DISTANCEMODE_AUTO))
+ GenNewPresetMode(Dev, RefRange);
+
+}
+
+
+static uint8_t ComputeRQL(uint8_t active_results,
+ VL53L1_range_data_t *presults_data)
+{
+ int16_t T_Wide = 150;
+ int16_t SRL = 300;
+ uint16_t SRAS = 30;
+ FixPoint1616_t RAS;
+ FixPoint1616_t SRQL;
+ FixPoint1616_t GI = 117.7 * 65536;
+ FixPoint1616_t GGm = 48.8 * 65536;
+ FixPoint1616_t LRAP = 0.1 * 65536;
+ FixPoint1616_t partial;
+ uint8_t finalvalue;
+
+ if (active_results == 0)
+ return 0;
+ else if ((presults_data->max_range_mm -
+ presults_data->min_range_mm) >= T_Wide)
+ return 50;
+ else {
+ if (presults_data->median_range_mm < SRL)
+ RAS = SRAS * 65536;
+ else
+ RAS = LRAP * presults_data->median_range_mm;
+
+
+
+ if (RAS != 0) {
+ partial = (GGm * presults_data->VL53L1_PRM_00004) + (RAS >> 1);
+ partial = partial / RAS;
+ partial = partial * 65536;
+ if (GI > partial)
+ SRQL = GI - partial;
+ else
+ SRQL = 50 * 65536;
+ } else
+ SRQL = 100 * 65536;
+
+ finalvalue = (uint8_t)(SRQL >> 16);
+ return MAX(50, MIN(100, finalvalue));
+ }
+}
+
+static VL53L1_Error SetSimpleData(VL53L1_DEV Dev,
+ uint8_t active_results,
+ VL53L1_range_data_t *presults_data,
+ VL53L1_RangingMeasurementData_t *pRangeData)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t FilteredRangeStatus;
+ uint8_t SigmaLimitflag;
+ uint8_t SignalLimitflag;
+ uint8_t Temp8Enable;
+ uint8_t Temp8;
+ uint8_t NoneFlag = 0;
+ FixPoint1616_t AmbientRate;
+ FixPoint1616_t SignalRate;
+ FixPoint1616_t TempFix1616;
+ FixPoint1616_t LimitCheckValue;
+
+ pRangeData->TimeStamp = presults_data->time_stamp;
+ FilteredRangeStatus = presults_data->range_status & 0x1F;
+
+ pRangeData->RangeQualityLevel = ComputeRQL(active_results,
+ presults_data);
+
+ pRangeData->RangeMaxMilliMeter = presults_data->max_range_mm;
+ pRangeData->RangeMinMilliMeter = presults_data->min_range_mm;
+
+ SignalRate = VL53L1_FIXPOINT97TOFIXPOINT1616(
+ presults_data->peak_signal_count_rate_mcps);
+ pRangeData->SignalRateRtnMegaCps
+ = SignalRate;
+
+ AmbientRate = VL53L1_FIXPOINT97TOFIXPOINT1616(
+ presults_data->ambient_count_rate_mcps);
+ pRangeData->AmbientRateRtnMegaCps = AmbientRate;
+
+ pRangeData->EffectiveSpadRtnCount =
+ presults_data->VL53L1_PRM_00003;
+
+ TempFix1616 = VL53L1_FIXPOINT142TOFIXPOINT1616(
+ presults_data->VL53L1_PRM_00004);
+
+ pRangeData->SigmaMilliMeter = TempFix1616;
+
+ pRangeData->RangeMilliMeter = presults_data->median_range_mm;
+
+ pRangeData->RangeFractionalPart = 0;
+
+ if (FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_NOUPDATE ||
+ FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_ALGOUNDERFLOW ||
+ FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_ALGOOVERFLOW ||
+ FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_RANGEIGNORETHRESHOLD ||
+ FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_REFSPADCHARNOTENOUGHDPADS ||
+ FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_REFSPADCHARMORETHANTARGET ||
+ FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_REFSPADCHARLESSTHANTARGET ||
+ FilteredRangeStatus == VL53L1_DEVICEERROR_MULTCLIPFAIL ||
+ FilteredRangeStatus == VL53L1_DEVICEERROR_GPHSTREAMCOUNT0READY
+ ) {
+ NoneFlag = 1;
+ } else {
+ NoneFlag = 0;
+ }
+
+ if (FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE) {
+ pRangeData->RangeStatus =
+ VL53L1_RANGESTATUS_RANGE_VALID;
+ } else if (FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE_NO_WRAP_CHECK) {
+ pRangeData->RangeStatus =
+ VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK;
+ } else {
+ if (NoneFlag == 1) {
+ pRangeData->RangeStatus = VL53L1_RANGESTATUS_NONE;
+ } else if (FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_VCSELCONTINUITYTESTFAILURE ||
+ FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_VCSELWATCHDOGTESTFAILURE ||
+ FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_NOVHVVALUEFOUND) {
+ pRangeData->RangeStatus =
+ VL53L1_RANGESTATUS_HARDWARE_FAIL;
+ } else if (FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_RANGEPHASECHECK ||
+ FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_PHASECONSISTENCY) {
+ pRangeData->RangeStatus =
+ VL53L1_RANGESTATUS_PHASE_FAIL;
+ } else if (FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_MINCLIP ||
+ FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_USERROICLIP) {
+ pRangeData->RangeStatus =
+ VL53L1_RANGESTATUS_MIN_RANGE_FAIL;
+ } else if (FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_MSRCNOTARGET) {
+ pRangeData->RangeStatus =
+ VL53L1_RANGESTATUS_SIGNAL_FAIL;
+ } else if (FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_SIGMATHRESHOLDCHECK) {
+ pRangeData->RangeStatus =
+ VL53L1_RANGESTATUS_SIGMA_FAIL;
+ } else {
+ pRangeData->RangeStatus =
+ VL53L1_RANGESTATUS_NONE;
+ }
+
+ }
+
+
+
+ TempFix1616 = VL53L1_FIXPOINT142TOFIXPOINT1616(
+ presults_data->VL53L1_PRM_00004);
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksCurrent, VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE,
+ TempFix1616);
+
+ TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616(
+ presults_data->peak_signal_count_rate_mcps);
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksCurrent, VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ TempFix1616);
+
+
+
+
+
+ VL53L1_GetLimitCheckValue(Dev,
+ VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE,
+ &LimitCheckValue);
+
+ SigmaLimitflag = (FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_SIGMATHRESHOLDCHECK)
+ ? 1 : 0;
+
+ VL53L1_GetLimitCheckEnable(Dev,
+ VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE,
+ &Temp8Enable);
+
+ Temp8 = ((Temp8Enable == 1) && (SigmaLimitflag == 1)) ? 1 : 0;
+ VL53L1_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
+ VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE, Temp8);
+
+
+
+ VL53L1_GetLimitCheckValue(Dev,
+ VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ &LimitCheckValue);
+
+ SignalLimitflag = (FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_MSRCNOTARGET)
+ ? 1 : 0;
+
+ VL53L1_GetLimitCheckEnable(Dev,
+ VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ &Temp8Enable);
+
+ Temp8 = ((Temp8Enable == 1) && (SignalLimitflag == 1)) ? 1 : 0;
+ VL53L1_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
+ VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, Temp8);
+
+ return Status;
+}
+
+
+static uint8_t GetOutputDataIndex(VL53L1_DEV Dev,
+ VL53L1_range_results_t *presults)
+{
+ uint8_t i;
+ uint8_t index = 0;
+ VL53L1_OutputModes OutputMode;
+
+ OutputMode = PALDevDataGet(Dev, CurrentParameters.OutputMode);
+
+
+
+
+ if (OutputMode == VL53L1_OUTPUTMODE_NEAREST)
+ return 0;
+
+
+
+
+
+ for (i = 1; i < presults->active_results; i++) {
+ if (presults->VL53L1_PRM_00005[i].peak_signal_count_rate_mcps >
+ presults->VL53L1_PRM_00005[index].peak_signal_count_rate_mcps)
+ index = i;
+ }
+
+ return index;
+}
+
+VL53L1_Error VL53L1_GetRangingMeasurementData(VL53L1_DEV Dev,
+ VL53L1_RangingMeasurementData_t *pRangingMeasurementData)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_range_results_t results;
+ VL53L1_range_results_t *presults = &results;
+ VL53L1_range_data_t *presults_data;
+ uint8_t index = 0;
+ int16_t dmax_min;
+
+ LOG_FUNCTION_START("");
+
+
+
+ memset(pRangingMeasurementData, 0xFF,
+ sizeof(VL53L1_RangingMeasurementData_t));
+
+
+
+ Status = VL53L1_get_device_results(
+ Dev,
+ VL53L1_DEVICERESULTSLEVEL_FULL,
+ presults);
+ dmax_min = MIN(presults->wrap_dmax_mm,
+ presults->ambient_dmax_mm[DMAX_REFLECTANCE_IDX]);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ pRangingMeasurementData->StreamCount = presults->stream_count;
+ pRangingMeasurementData->DmaxMilliMeter = dmax_min;
+
+
+
+
+ index = GetOutputDataIndex(Dev, presults);
+ presults_data = &(presults->VL53L1_PRM_00005[index]);
+ Status = SetSimpleData(Dev, presults->active_results,
+ presults_data,
+ pRangingMeasurementData);
+ }
+
+ if (Status == VL53L1_ERROR_NONE) {
+ CheckAndChangeDistanceMode(Dev, pRangingMeasurementData,
+ presults->ambient_dmax_mm[VL53L1_MAX_AMBIENT_DMAX_VALUES
+ - 1]);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+static VL53L1_Error SetMeasurementData(VL53L1_DEV Dev,
+ VL53L1_range_results_t *presults,
+ VL53L1_MultiRangingData_t *pMultiRangingData)
+{
+ uint8_t i;
+ uint8_t iteration;
+ VL53L1_RangingMeasurementData_t *pRangeData;
+ VL53L1_range_data_t *presults_data;
+ int16_t dmax_min;
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t index = 0;
+
+ pMultiRangingData->NumberOfObjectsFound = presults->active_results;
+ pMultiRangingData->RoiNumber = presults->zone_id;
+
+ dmax_min = MIN(presults->wrap_dmax_mm,
+ presults->ambient_dmax_mm[DMAX_REFLECTANCE_IDX]);
+
+
+
+
+ if (presults->active_results < 1)
+ iteration = 1;
+ else
+ iteration = presults->active_results;
+
+ for (i = 0; i < iteration; i++) {
+ pRangeData = &(pMultiRangingData->RangeData[i]);
+
+ presults_data = &(presults->VL53L1_PRM_00005[i]);
+ pRangeData->StreamCount = presults->stream_count;
+ pRangeData->DmaxMilliMeter = dmax_min;
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = SetSimpleData(Dev, presults->active_results,
+ presults_data,
+ pRangeData);
+ }
+
+ if (Status == VL53L1_ERROR_NONE) {
+ index = GetOutputDataIndex(Dev, presults);
+ pRangeData = &(pMultiRangingData->RangeData[index]);
+ CheckAndChangeDistanceMode(Dev, pRangeData,
+ presults->ambient_dmax_mm[
+ VL53L1_MAX_AMBIENT_DMAX_VALUES - 1]);
+ }
+
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetMultiRangingData(VL53L1_DEV Dev,
+ VL53L1_MultiRangingData_t *pMultiRangingData)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_range_results_t results;
+ VL53L1_range_results_t *presults = &results;
+
+ LOG_FUNCTION_START("");
+
+
+
+ memset(pMultiRangingData, 0xFF,
+ sizeof(VL53L1_MultiRangingData_t));
+
+
+
+ Status = VL53L1_get_device_results(
+ Dev,
+ VL53L1_DEVICERESULTSLEVEL_FULL,
+ presults);
+
+
+ if (Status == VL53L1_ERROR_NONE) {
+
+ switch (presults->rd_device_state) {
+ case VL53L1_DEVICESTATE_RANGING_GATHER_DATA:
+ pMultiRangingData->RoiStatus =
+ VL53L1_ROISTATUS_VALID_NOT_LAST;
+ break;
+ case VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA:
+ pMultiRangingData->RoiStatus =
+ VL53L1_ROISTATUS_VALID_LAST;
+ break;
+ default:
+ pMultiRangingData->RoiStatus =
+ VL53L1_ROISTATUS_NOT_VALID;
+ }
+
+ Status = SetMeasurementData(Dev,
+ presults,
+ pMultiRangingData);
+
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_PerformRefSpadManagement(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_Error UnfilteredStatus;
+
+ LOG_FUNCTION_START("");
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_run_ref_spad_char(Dev, &UnfilteredStatus);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetXTalkCompensationEnable(VL53L1_DEV Dev,
+ uint8_t XTalkCompensationEnable)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (XTalkCompensationEnable == 0)
+ Status = VL53L1_disable_xtalk_compensation(Dev);
+ else
+ Status = VL53L1_enable_xtalk_compensation(Dev);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetXTalkCompensationEnable(VL53L1_DEV Dev,
+ uint8_t *pXTalkCompensationEnable)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ VL53L1_get_xtalk_compensation_enable(
+ Dev,
+ pXTalkCompensationEnable);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_PerformXTalkCalibration(VL53L1_DEV Dev,
+ uint8_t CalibrationOption)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_Error UnfilteredStatus;
+ uint32_t mm_config_timeout_us = 2000;
+ uint32_t range_config_timeout_us = 10000;
+ uint16_t dss_config__target_total_rate_mcps = 0x1400;
+ uint32_t phasecal_config_timeout_us = 4000;
+ uint8_t num_of_samples = 7;
+
+ SUPPRESS_UNUSED_WARNING(CalibrationOption);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_run_xtalk_extraction(
+ Dev,
+ dss_config__target_total_rate_mcps,
+ phasecal_config_timeout_us,
+ mm_config_timeout_us,
+ range_config_timeout_us,
+ num_of_samples,
+ &UnfilteredStatus);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetOffsetCalibrationMode(VL53L1_DEV Dev,
+ VL53L1_OffsetCalibrationModes OffsetCalibrationMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_OffsetCalibrationMode offset_cal_mode;
+
+ LOG_FUNCTION_START("");
+
+ if (OffsetCalibrationMode == VL53L1_OFFSETCALIBRATIONMODE_STANDARD) {
+ offset_cal_mode =
+ VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD;
+ } else if (OffsetCalibrationMode ==
+ VL53L1_OFFSETCALIBRATIONMODE_PRERANGE_ONLY) {
+ offset_cal_mode =
+ VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD_PRE_RANGE_ONLY;
+ } else if (OffsetCalibrationMode ==
+ VL53L1_OFFSETCALIBRATIONMODE_MULTI_ZONE) {
+ offset_cal_mode =
+ VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM;
+ } else {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_set_offset_calibration_mode(Dev,
+ offset_cal_mode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetOffsetCorrectionMode(VL53L1_DEV Dev,
+ VL53L1_OffsetCorrectionModes OffsetCorrectionMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_OffsetCorrectionMode offset_cor_mode;
+
+ LOG_FUNCTION_START("");
+
+ if (OffsetCorrectionMode == VL53L1_OFFSETCORRECTIONMODE_STANDARD) {
+ offset_cor_mode =
+ VL53L1_OFFSETCORRECTIONMODE__MM1_MM2_OFFSETS;
+ } else if (OffsetCorrectionMode ==
+ VL53L1_OFFSETCORRECTIONMODE_PERZONE) {
+ offset_cor_mode =
+ VL53L1_OFFSETCORRECTIONMODE__PER_ZONE_OFFSETS;
+ } else {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_set_offset_correction_mode(Dev,
+ offset_cor_mode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_PerformOffsetCalibration(VL53L1_DEV Dev,
+ int32_t CalDistanceMilliMeter, FixPoint1616_t CalReflectancePercent)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_Error UnfilteredStatus;
+ uint32_t range_config_timeout_us = 13000;
+ uint8_t pre_num_of_samples = 32;
+ uint8_t mm1_num_of_samples = 100;
+ uint8_t mm2_num_of_samples = 64;
+ uint16_t dss_config__target_total_rate_mcps = 0x1400;
+ uint32_t phasecal_config_timeout_us = 1000;
+ uint16_t CalReflectancePercent_int;
+
+
+ VL53L1_DevicePresetModes device_preset_mode;
+ VL53L1_DeviceZonePreset zone_preset;
+ VL53L1_zone_config_t zone_cfg;
+ uint32_t phasecal_config_timeout_us_pz;
+ uint32_t mm_config_timeout_us_pz;
+ uint32_t range_config_timeout_us_pz;
+ uint16_t num_of_samples;
+ VL53L1_OffsetCalibrationMode offset_cal_mode;
+
+ LOG_FUNCTION_START("");
+
+ CalReflectancePercent_int =
+ VL53L1_FIXPOINT1616TOFIXPOINT72(CalReflectancePercent);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_get_offset_calibration_mode(Dev,
+ &offset_cal_mode);
+
+ if ((offset_cal_mode ==
+ VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD) ||
+ (offset_cal_mode ==
+ VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD_PRE_RANGE_ONLY)) {
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_run_offset_calibration(
+ Dev,
+ dss_config__target_total_rate_mcps,
+ phasecal_config_timeout_us,
+ range_config_timeout_us,
+ pre_num_of_samples,
+ mm1_num_of_samples,
+ mm2_num_of_samples,
+ (int16_t)CalDistanceMilliMeter,
+ CalReflectancePercent_int,
+ &UnfilteredStatus);
+
+ } else if (offset_cal_mode ==
+ VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM) {
+
+ device_preset_mode =
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_LONG_RANGE;
+ zone_preset = VL53L1_DEVICEZONEPRESET_CUSTOM;
+ phasecal_config_timeout_us_pz = 4000;
+ mm_config_timeout_us_pz = 2000;
+ range_config_timeout_us_pz = 10000;
+ num_of_samples = 64;
+
+ Status = VL53L1_get_zone_config(Dev, &zone_cfg);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_run_zone_calibration(
+ Dev,
+ device_preset_mode,
+ zone_preset,
+ &zone_cfg,
+ dss_config__target_total_rate_mcps,
+ phasecal_config_timeout_us_pz,
+ mm_config_timeout_us_pz,
+ range_config_timeout_us_pz,
+ num_of_samples,
+ (int16_t)CalDistanceMilliMeter,
+ CalReflectancePercent_int,
+ &UnfilteredStatus);
+
+ } else {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetCalibrationData(VL53L1_DEV Dev,
+ VL53L1_CalibrationData_t *pCalibrationData)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_set_part_to_part_data(
+ Dev, pCalibrationData);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+VL53L1_Error VL53L1_GetCalibrationData(VL53L1_DEV Dev,
+ VL53L1_CalibrationData_t *pCalibrationData)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_part_to_part_data(
+ Dev, pCalibrationData);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetOpticalCenter(VL53L1_DEV Dev,
+ uint8_t *pOpticalCenterX, uint8_t *pOpticalCenterY)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_CalibrationData_t CalibrationData;
+
+ LOG_FUNCTION_START("");
+
+ *pOpticalCenterX = 0;
+ *pOpticalCenterY = 0;
+ Status = VL53L1_get_part_to_part_data(Dev, &CalibrationData);
+ if (Status == VL53L1_ERROR_NONE) {
+ *pOpticalCenterX = CalibrationData.mm_roi.x_centre;
+ *pOpticalCenterY = CalibrationData.mm_roi.y_centre;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_SetThresholdConfig(VL53L1_DEV Dev,
+ VL53L1_DetectionConfig_t *pConfig)
+{
+#define BADTHRESBOUNDS(T) \
+ (((T.CrossMode == VL53L1_THRESHOLD_OUT_OF_WINDOW) || \
+ (T.CrossMode == VL53L1_THRESHOLD_IN_WINDOW)) && (T.Low > T.High))
+
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_GPIO_interrupt_config_t Cfg;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_GPIO_interrupt_config(Dev, &Cfg);
+ if (Status == VL53L1_ERROR_NONE) {
+ if (pConfig->DetectionMode == VL53L1_DETECTION_NORMAL_RUN) {
+ Cfg.intr_new_measure_ready = 1;
+ Status = VL53L1_set_GPIO_interrupt_config_struct(Dev,
+ Cfg);
+ } else {
+ if (BADTHRESBOUNDS(pConfig->Distance))
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ if ((Status == VL53L1_ERROR_NONE) &&
+ (BADTHRESBOUNDS(pConfig->Rate)))
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ if (Status == VL53L1_ERROR_NONE) {
+ Cfg.intr_new_measure_ready = 0;
+ Cfg.intr_no_target = pConfig->IntrNoTarget;
+ Cfg.threshold_distance_high =
+ pConfig->Distance.High;
+ Cfg.threshold_distance_low =
+ pConfig->Distance.Low;
+ Cfg.threshold_rate_high =
+ VL53L1_FIXPOINT1616TOFIXPOINT97(
+ pConfig->Rate.High);
+ Cfg.threshold_rate_low =
+ VL53L1_FIXPOINT1616TOFIXPOINT97(
+ pConfig->Rate.Low);
+
+ Cfg.intr_mode_distance = ConvertModeToLLD(
+ &Status,
+ pConfig->Distance.CrossMode);
+ if (Status == VL53L1_ERROR_NONE)
+ Cfg.intr_mode_rate = ConvertModeToLLD(
+ &Status,
+ pConfig->Rate.CrossMode);
+ }
+
+
+
+ if (Status == VL53L1_ERROR_NONE) {
+ Cfg.intr_combined_mode = 1;
+ switch (pConfig->DetectionMode) {
+ case VL53L1_DETECTION_DISTANCE_ONLY:
+ Cfg.threshold_rate_high = 0;
+ Cfg.threshold_rate_low = 0;
+ break;
+ case VL53L1_DETECTION_RATE_ONLY:
+ Cfg.threshold_distance_high = 0;
+ Cfg.threshold_distance_low = 0;
+ break;
+ case VL53L1_DETECTION_DISTANCE_OR_RATE:
+
+
+
+
+ break;
+ case VL53L1_DETECTION_DISTANCE_AND_RATE:
+ Cfg.intr_combined_mode = 0;
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status =
+ VL53L1_set_GPIO_interrupt_config_struct(Dev,
+ Cfg);
+
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetThresholdConfig(VL53L1_DEV Dev,
+ VL53L1_DetectionConfig_t *pConfig)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_GPIO_interrupt_config_t Cfg;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_GPIO_interrupt_config(Dev, &Cfg);
+
+ if (Status != VL53L1_ERROR_NONE) {
+ LOG_FUNCTION_END(Status);
+ return Status;
+ }
+
+ pConfig->IntrNoTarget = Cfg.intr_no_target;
+ pConfig->Distance.High = Cfg.threshold_distance_high;
+ pConfig->Distance.Low = Cfg.threshold_distance_low;
+ pConfig->Rate.High =
+ VL53L1_FIXPOINT97TOFIXPOINT1616(
+ Cfg.threshold_rate_high);
+ pConfig->Rate.Low =
+ VL53L1_FIXPOINT97TOFIXPOINT1616(Cfg.threshold_rate_low);
+ pConfig->Distance.CrossMode =
+ ConvertModeFromLLD(&Status, Cfg.intr_mode_distance);
+ if (Status == VL53L1_ERROR_NONE)
+ pConfig->Rate.CrossMode =
+ ConvertModeFromLLD(&Status, Cfg.intr_mode_rate);
+
+ if (Cfg.intr_new_measure_ready == 1) {
+ pConfig->DetectionMode = VL53L1_DETECTION_NORMAL_RUN;
+ } else {
+
+
+ if (Status == VL53L1_ERROR_NONE) {
+ if (Cfg.intr_combined_mode == 0)
+ pConfig->DetectionMode =
+ VL53L1_DETECTION_DISTANCE_AND_RATE;
+ else {
+ if ((Cfg.threshold_distance_high == 0) &&
+ (Cfg.threshold_distance_low == 0))
+ pConfig->DetectionMode =
+ VL53L1_DETECTION_RATE_ONLY;
+ else if ((Cfg.threshold_rate_high == 0) &&
+ (Cfg.threshold_rate_low == 0))
+ pConfig->DetectionMode =
+ VL53L1_DETECTION_DISTANCE_ONLY;
+ else
+ pConfig->DetectionMode =
+ VL53L1_DETECTION_DISTANCE_OR_RATE;
+ }
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_api_calibration.c b/drivers/input/misc/vl53L1/src/vl53l1_api_calibration.c
new file mode 100644
index 000000000000..b10b2935a25a
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_api_calibration.c
@@ -0,0 +1,2617 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_ll_device.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_platform_ipp.h"
+#include "vl53l1_register_map.h"
+#include "vl53l1_register_funcs.h"
+#include "vl53l1_register_settings.h"
+#include "vl53l1_hist_map.h"
+#include "vl53l1_hist_structs.h"
+#include "vl53l1_core.h"
+#include "vl53l1_wait.h"
+#include "vl53l1_api_preset_modes.h"
+#include "vl53l1_fpga_core.h"
+#include "vl53l1_silicon_core.h"
+#include "vl53l1_api_core.h"
+#include "vl53l1_api_calibration.h"
+
+#ifdef VL53L1_LOG_ENABLE
+ #include "vl53l1_api_debug.h"
+#endif
+
+
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, \
+ fmt, ##__VA_ARGS__)
+
+#define trace_print(level, ...) \
+ _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_CORE, \
+ level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_run_ref_spad_char(
+ VL53L1_DEV Dev,
+ VL53L1_Error *pcal_status)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t comms_buffer[6];
+
+ VL53L1_refspadchar_config_t *prefspadchar = &(pdev->refspadchar);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_enable_powerforce(Dev);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_ref_spad_char_config(
+ Dev,
+ prefspadchar->VL53L1_PRM_00007,
+ prefspadchar->timeout_us,
+ prefspadchar->target_count_rate_mcps,
+ prefspadchar->max_count_rate_limit_mcps,
+ prefspadchar->min_count_rate_limit_mcps,
+ pdev->stat_nvm.osc_measured__fast_osc__frequency);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_run_device_test(
+ Dev,
+ prefspadchar->device_test_mode);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_ReadMulti(
+ Dev,
+ VL53L1_REF_SPAD_CHAR_RESULT__NUM_ACTUAL_REF_SPADS,
+ comms_buffer,
+ 2);
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->dbg_results.ref_spad_char_result__num_actual_ref_spads =
+ comms_buffer[0];
+ pdev->dbg_results.ref_spad_char_result__ref_location =
+ comms_buffer[1];
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WriteMulti(
+ Dev,
+ VL53L1_REF_SPAD_MAN__NUM_REQUESTED_REF_SPADS,
+ comms_buffer,
+ 2);
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->customer.ref_spad_man__num_requested_ref_spads =
+ comms_buffer[0];
+ pdev->customer.ref_spad_man__ref_location =
+ comms_buffer[1];
+ }
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_ReadMulti(
+ Dev,
+ VL53L1_RESULT__SPARE_0_SD1,
+ comms_buffer,
+ 6);
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WriteMulti(
+ Dev,
+ VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0,
+ comms_buffer,
+ 6);
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->customer.global_config__spad_enables_ref_0 =
+ comms_buffer[0];
+ pdev->customer.global_config__spad_enables_ref_1 =
+ comms_buffer[1];
+ pdev->customer.global_config__spad_enables_ref_2 =
+ comms_buffer[2];
+ pdev->customer.global_config__spad_enables_ref_3 =
+ comms_buffer[3];
+ pdev->customer.global_config__spad_enables_ref_4 =
+ comms_buffer[4];
+ pdev->customer.global_config__spad_enables_ref_5 =
+ comms_buffer[5];
+ }
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_print_customer_nvm_managed(
+ &(pdev->customer),
+ "run_ref_spad_char():pdev->lldata.customer.",
+ VL53L1_TRACE_MODULE_REF_SPAD_CHAR);
+#endif
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ switch (pdev->sys_results.result__range_status) {
+
+ case VL53L1_DEVICEERROR_REFSPADCHARNOTENOUGHDPADS:
+ status = VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS;
+ break;
+
+ case VL53L1_DEVICEERROR_REFSPADCHARMORETHANTARGET:
+ status = VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH;
+ break;
+
+ case VL53L1_DEVICEERROR_REFSPADCHARLESSTHANTARGET:
+ status = VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW;
+ break;
+ }
+ }
+
+
+
+
+
+
+ *pcal_status = status;
+
+
+
+
+ IGNORE_STATUS(
+ IGNORE_REF_SPAD_CHAR_NOT_ENOUGH_SPADS,
+ VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_REF_SPAD_CHAR_RATE_TOO_HIGH,
+ VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_REF_SPAD_CHAR_RATE_TOO_LOW,
+ VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW,
+ status);
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_run_xtalk_extraction(
+ VL53L1_DEV Dev,
+ uint16_t dss_config__target_total_rate_mcps,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint8_t num_of_samples,
+ VL53L1_Error *pcal_status)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+
+
+
+
+
+ uint8_t results_invalid = 0;
+
+ uint8_t i = 0;
+ uint8_t measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->xtalk_results.central_histogram_avg));
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->xtalk_results.central_histogram_sum));
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_set_preset_mode(
+ Dev,
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_PLANAR,
+ dss_config__target_total_rate_mcps,
+ phasecal_config_timeout_us,
+ mm_config_timeout_us,
+ range_config_timeout_us,
+ 100);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_disable_xtalk_compensation(
+ Dev);
+ }
+
+
+
+
+
+
+ pdev->xtalk_results.max_results = VL53L1_MAX_XTALK_RANGE_RESULTS;
+ pdev->xtalk_results.active_results = pdev->zone_cfg.active_zones+1;
+
+
+
+
+ pdev->xtalk_results.central_histogram__window_start = 0xFF;
+ pdev->xtalk_results.central_histogram__window_end = 0x00;
+
+ pdev->xtalk_results.num_of_samples_status = 0x00;
+ pdev->xtalk_results.zero_samples_status = 0x00;
+ pdev->xtalk_results.max_sigma_status = 0x00;
+
+ for (i = 0 ; i < pdev->xtalk_results.max_results ; i++) {
+ pdev->xtalk_results.VL53L1_PRM_00005[i].no_of_samples = 0;
+ pdev->xtalk_results.VL53L1_PRM_00005[i].signal_total_events_avg = 0;
+ pdev->xtalk_results.VL53L1_PRM_00005[i].signal_total_events_sum = 0;
+ pdev->xtalk_results.VL53L1_PRM_00005[i].rate_per_spad_kcps_sum = 0;
+ pdev->xtalk_results.VL53L1_PRM_00005[i].rate_per_spad_kcps_avg = 0;
+ pdev->xtalk_results.VL53L1_PRM_00005[i].sigma_mm_sum = 0;
+ pdev->xtalk_results.VL53L1_PRM_00005[i].sigma_mm_avg = 0;
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status = VL53L1_get_and_avg_xtalk_samples(
+ Dev,
+ num_of_samples,
+ measurement_mode,
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_range_mm,
+ pdev->xtalk_cfg.algo__crosstalk_detect_min_valid_range_mm,
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_rate_kcps,
+ 0x0,
+
+ 0x4,
+
+ &(pdev->xtalk_results),
+ &(pdev->xtalk_results.central_histogram_sum),
+ &(pdev->xtalk_results.central_histogram_avg));
+ }
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ if ((pdev->xtalk_results.VL53L1_PRM_00005[4].no_of_samples == 0) ||
+ (pdev->xtalk_results.VL53L1_PRM_00005[4].sigma_mm_avg >
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_sigma_mm)) {
+ results_invalid = 0x01;
+ }
+ }
+
+#ifdef VL53L1_LOG_ENABLE
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_print_xtalk_range_results(
+ &(pdev->xtalk_results),
+ "pdev->xtalk_results",
+ VL53L1_TRACE_MODULE_CORE);
+#endif
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ if (results_invalid == 0) {
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ipp_xtalk_calibration_process_data(
+ Dev,
+ &(pdev->xtalk_results),
+ &(pdev->xtalk_shapes),
+ &(pdev->xtalk_cal));
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pdev->xtalk_cfg.algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pdev->xtalk_cal.algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pdev->xtalk_cfg.algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pdev->xtalk_cal.algo__crosstalk_compensation_y_plane_gradient_kcps;
+ pdev->xtalk_cfg.algo__crosstalk_compensation_plane_offset_kcps =
+ pdev->xtalk_cal.algo__crosstalk_compensation_plane_offset_kcps;
+
+
+ }
+
+
+ }
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_enable_xtalk_compensation(
+ Dev);
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ for (i = 0 ; i < pdev->xtalk_results.max_results ; i++) {
+
+
+ if (pdev->xtalk_results.VL53L1_PRM_00005[i].no_of_samples !=
+ num_of_samples) {
+ pdev->xtalk_results.num_of_samples_status =
+ pdev->xtalk_results.num_of_samples_status |
+ (1 << i);
+ }
+
+
+ if (pdev->xtalk_results.VL53L1_PRM_00005[i].no_of_samples ==
+ 0x00) {
+ pdev->xtalk_results.zero_samples_status =
+ pdev->xtalk_results.zero_samples_status |
+ (1 << i);
+ }
+
+
+
+
+
+
+
+
+
+ if (pdev->xtalk_results.VL53L1_PRM_00005[i].sigma_mm_avg >
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_sigma_mm) {
+ pdev->xtalk_results.max_sigma_status =
+ pdev->xtalk_results.max_sigma_status |
+ (1 << i);
+ }
+ }
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (results_invalid > 0) {
+
+
+ if (pdev->xtalk_results.VL53L1_PRM_00005[4].no_of_samples == 0) {
+ status = VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL;
+ } else {
+ if (pdev->xtalk_results.VL53L1_PRM_00005[4].sigma_mm_avg >
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_sigma_mm) {
+ status = VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL;
+ }
+ }
+ } else {
+
+
+ if (pdev->xtalk_results.zero_samples_status != 0x00) {
+ status = VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT;
+ } else {
+ if (pdev->xtalk_results.max_sigma_status != 0x00) {
+ status = VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT;
+ } else {
+ if (pdev->xtalk_results.num_of_samples_status !=
+ 0x00) {
+ status = VL53L1_WARNING_XTALK_MISSING_SAMPLES;
+ }
+ }
+ }
+ }
+
+
+
+
+
+
+ pdev->xtalk_results.cal_status = status;
+ *pcal_status = pdev->xtalk_results.cal_status;
+
+
+
+
+ IGNORE_STATUS(
+ IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FAIL,
+ VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL,
+ VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FOR_GRADIENT_WARN,
+ VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_XTALK_EXTRACTION_SIGMA_LIMIT_FOR_GRADIENT_WARN,
+ VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_XTALK_EXTRACTION_MISSING_SAMPLES_WARN,
+ VL53L1_WARNING_XTALK_MISSING_SAMPLES,
+ status);
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+
+
+ VL53L1_print_customer_nvm_managed(
+ &(pdev->customer),
+ "run_xtalk_extraction():pdev->lldata.customer.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_xtalk_config(
+ &(pdev->xtalk_cfg),
+ "run_xtalk_extraction():pdev->lldata.xtalk_cfg.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_histogram_bin_data(
+ &(pdev->hist_data),
+ "run_xtalk_extraction():pdev->lldata.hist_data.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_xtalk_histogram_data(
+ &(pdev->xtalk_shapes),
+ "pdev->lldata.xtalk_shapes.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_xtalk_range_results(
+ &(pdev->xtalk_results),
+ "run_xtalk_extraction():pdev->lldata.xtalk_results.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+
+VL53L1_Error VL53L1_run_xtalk_extraction_dual_reflectance(
+ VL53L1_DEV Dev,
+ uint16_t dss_config__target_total_rate_mcps,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint8_t num_of_samples,
+ uint8_t calc_parms,
+ uint8_t higher_reflectance,
+ uint16_t expected_target_distance_mm,
+ uint16_t xtalk_filter_thresh_mm,
+ VL53L1_Error *pcal_status)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+
+
+
+
+
+ VL53L1_histogram_bin_data_t *pxtalk_avg_samples = &(pdev->xtalk_results.xtalk_avg[0]);
+
+ VL53L1_range_results_t results_int;
+ VL53L1_range_results_t *presults_int = &(results_int);
+
+ VL53L1_range_data_t *prange_data = &(presults_int->VL53L1_PRM_00005[0]);
+
+ uint8_t results_invalid = 0;
+
+ uint8_t i = 0;
+ uint8_t measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+ if (calc_parms == 0x00) {
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->xtalk_results.histogram_avg_1[0]));
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->xtalk_results.histogram_avg_1[1]));
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->xtalk_results.histogram_avg_1[2]));
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->xtalk_results.histogram_avg_1[3]));
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->xtalk_results.histogram_avg_1[4]));
+ }
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->xtalk_results.histogram_avg_2[0]));
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->xtalk_results.histogram_avg_2[1]));
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->xtalk_results.histogram_avg_2[2]));
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->xtalk_results.histogram_avg_2[3]));
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->xtalk_results.histogram_avg_2[4]));
+
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_set_preset_mode(
+ Dev,
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_PLANAR,
+ dss_config__target_total_rate_mcps,
+ phasecal_config_timeout_us,
+ mm_config_timeout_us,
+ range_config_timeout_us,
+ 100);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_disable_xtalk_compensation(
+ Dev);
+ }
+
+
+
+
+
+
+ pdev->xtalk_results.max_results = VL53L1_MAX_XTALK_RANGE_RESULTS;
+ pdev->xtalk_results.active_results = pdev->zone_cfg.active_zones+1;
+
+ for (i = 0 ; i < pdev->xtalk_results.max_results ; i++) {
+ pdev->xtalk_results.VL53L1_PRM_00005[i].no_of_samples = 0;
+ pdev->xtalk_results.VL53L1_PRM_00005[i].signal_total_events_avg = 0;
+ pdev->xtalk_results.VL53L1_PRM_00005[i].signal_total_events_sum = 0;
+ pdev->xtalk_results.VL53L1_PRM_00005[i].rate_per_spad_kcps_sum = 0;
+ pdev->xtalk_results.VL53L1_PRM_00005[i].rate_per_spad_kcps_avg = 0;
+ }
+
+
+
+
+ if ((status == VL53L1_ERROR_NONE) &&
+ (calc_parms == 0x00)) {
+
+ status = VL53L1_get_and_avg_all_xtalk_samples(
+ Dev,
+ num_of_samples,
+ measurement_mode,
+ xtalk_filter_thresh_mm,
+ &(pdev->xtalk_results),
+ &(pdev->xtalk_results.histogram_avg_1[0]),
+ &(pdev->xtalk_results.histogram_avg_1[1]),
+ &(pdev->xtalk_results.histogram_avg_1[2]),
+ &(pdev->xtalk_results.histogram_avg_1[3]),
+ &(pdev->xtalk_results.histogram_avg_1[4])
+ );
+
+ } else {
+
+ status = VL53L1_get_and_avg_all_xtalk_samples(
+ Dev,
+ num_of_samples,
+ measurement_mode,
+ xtalk_filter_thresh_mm,
+ &(pdev->xtalk_results),
+ &(pdev->xtalk_results.histogram_avg_2[0]),
+ &(pdev->xtalk_results.histogram_avg_2[1]),
+ &(pdev->xtalk_results.histogram_avg_2[2]),
+ &(pdev->xtalk_results.histogram_avg_2[3]),
+ &(pdev->xtalk_results.histogram_avg_2[4])
+ );
+ }
+
+
+
+
+ if ((status == VL53L1_ERROR_NONE) &&
+ (calc_parms == 0x01)) {
+ status = VL53L1_ipp_generate_dual_reflectance_xtalk_samples(
+ Dev,
+ &(pdev->xtalk_results),
+ expected_target_distance_mm,
+ higher_reflectance,
+ &(pdev->xtalk_results.xtalk_avg[0]));
+ }
+
+
+
+
+ for (i = 0 ; i < 5 ; i++) {
+
+ if ((status == VL53L1_ERROR_NONE) &&
+ (calc_parms == 0x01)) {
+
+ status = VL53L1_ipp_hist_process_data(
+ Dev,
+ &(pdev->fmt_dmax_cal),
+ &(pdev->dmax_cfg),
+ &(pdev->histpostprocess),
+ &(pxtalk_avg_samples[i]),
+ &(pdev->xtalk_shapes),
+ presults_int);
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+ if ((presults_int->active_results > 0) &&
+ (prange_data->median_range_mm <
+ (int16_t)xtalk_filter_thresh_mm)) {
+
+ pdev->xtalk_results.VL53L1_PRM_00005[i].no_of_samples++;
+
+ pdev->xtalk_results.VL53L1_PRM_00005[i].rate_per_spad_kcps_avg =
+ prange_data->VL53L1_PRM_00008;
+
+ pdev->xtalk_results.VL53L1_PRM_00005[i].signal_total_events_avg =
+ prange_data->VL53L1_PRM_00009;
+ }
+ }
+ }
+
+
+
+
+ memcpy(&(pdev->xtalk_results.central_histogram_avg),
+ &(pxtalk_avg_samples[4]),
+ sizeof(VL53L1_histogram_bin_data_t));
+
+
+
+
+
+
+
+
+
+
+ if ((status == VL53L1_ERROR_NONE) &&
+ (calc_parms == 0x01)) {
+ if (pdev->xtalk_results.VL53L1_PRM_00005[4].no_of_samples == 0) {
+ results_invalid = 0x01;
+ }
+ }
+
+
+#ifdef VL53L1_LOG_ENABLE
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_print_xtalk_range_results(
+ &(pdev->xtalk_results),
+ "pdev->xtalk_results",
+ VL53L1_TRACE_MODULE_CORE);
+#endif
+
+
+ if ((status == VL53L1_ERROR_NONE) &&
+ (calc_parms == 0x01)) {
+
+ if (results_invalid == 0) {
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ipp_xtalk_calibration_process_data(
+ Dev,
+ &(pdev->xtalk_results),
+ &(pdev->xtalk_shapes),
+ &(pdev->xtalk_cal));
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pdev->xtalk_cfg.algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pdev->xtalk_cal.algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pdev->xtalk_cfg.algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pdev->xtalk_cal.algo__crosstalk_compensation_y_plane_gradient_kcps;
+ pdev->xtalk_cfg.algo__crosstalk_compensation_plane_offset_kcps =
+ pdev->xtalk_cal.algo__crosstalk_compensation_plane_offset_kcps;
+
+
+ }
+
+
+ }
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_enable_xtalk_compensation(
+ Dev);
+ }
+
+
+
+
+ if (results_invalid > 0)
+ status = VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL;
+
+
+
+
+
+
+ pdev->xtalk_results.cal_status = status;
+ *pcal_status = pdev->xtalk_results.cal_status;
+
+
+
+
+ IGNORE_STATUS(
+ IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FAIL,
+ VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL,
+ status);
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+
+
+ VL53L1_print_customer_nvm_managed(
+ &(pdev->customer),
+ "pdev->lldata.customer.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_xtalk_config(
+ &(pdev->xtalk_cfg),
+ "pdev->lldata.xtalk_cfg.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_histogram_bin_data(
+ &(pdev->hist_data),
+ "pdev->lldata.hist_data.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_xtalk_histogram_data(
+ &(pdev->xtalk_shapes),
+ "pdev->lldata.xtalk_shapes.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_xtalk_range_results(
+ &(pdev->xtalk_results),
+ "pdev->lldata.xtalk_results.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+
+VL53L1_Error VL53L1_get_and_avg_xtalk_samples(
+ VL53L1_DEV Dev,
+ uint8_t num_of_samples,
+ uint8_t measurement_mode,
+ int16_t xtalk_filter_thresh_max_mm,
+ int16_t xtalk_filter_thresh_min_mm,
+ uint16_t xtalk_max_valid_rate_kcps,
+ uint8_t xtalk_result_id,
+ uint8_t xtalk_histo_id,
+ VL53L1_xtalk_range_results_t *pxtalk_results,
+ VL53L1_histogram_bin_data_t *psum_histo,
+ VL53L1_histogram_bin_data_t *pavg_histo)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+#ifdef VL53L1_LOG_ENABLE
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+#endif
+
+ VL53L1_range_results_t range_results;
+ VL53L1_range_results_t *prange_results = &range_results;
+
+ VL53L1_range_data_t *prange_data;
+ VL53L1_xtalk_range_data_t *pxtalk_range_data;
+
+ uint8_t i = 0;
+ uint8_t j = 0;
+ uint8_t zone_id = 0;
+ uint8_t final_zone = pdev->zone_cfg.active_zones+1;
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_init_and_start_range(
+ Dev,
+ measurement_mode,
+ VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS);
+
+
+ for (i = 0 ; i <= (final_zone*num_of_samples) ; i++) {
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_wait_for_range_completion(Dev);
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_get_device_results(
+ Dev,
+ VL53L1_DEVICERESULTSLEVEL_FULL,
+ prange_results);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE &&
+ pdev->ll_state.rd_device_state !=
+ VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC) {
+
+ zone_id = pdev->ll_state.rd_zone_id + xtalk_result_id;
+ prange_data = &(prange_results->VL53L1_PRM_00005[0]);
+
+
+
+ if (prange_results->active_results > 1) {
+ for (j = 1 ; j < prange_results->active_results ; j++) {
+
+ if (prange_results->VL53L1_PRM_00005[j].median_range_mm <
+ prange_data->median_range_mm){
+ prange_data = &(prange_results->VL53L1_PRM_00005[j]);
+ }
+ }
+ }
+
+ pxtalk_range_data = &(pxtalk_results->VL53L1_PRM_00005[zone_id]);
+
+
+
+
+
+ if ((prange_results->active_results > 0) &&
+ (prange_data->median_range_mm <
+ xtalk_filter_thresh_max_mm) &&
+ (prange_data->median_range_mm >
+ xtalk_filter_thresh_min_mm) &&
+ (prange_data->VL53L1_PRM_00008 <
+ (uint32_t)(xtalk_max_valid_rate_kcps * 16))) {
+
+ pxtalk_range_data->no_of_samples++;
+
+ pxtalk_range_data->rate_per_spad_kcps_sum +=
+ prange_data->VL53L1_PRM_00008;
+
+ pxtalk_range_data->signal_total_events_sum +=
+ prange_data->VL53L1_PRM_00009;
+
+ pxtalk_range_data->sigma_mm_sum +=
+ prange_data->VL53L1_PRM_00004;
+
+
+
+
+
+
+
+
+ if (zone_id >= 4) {
+ status = VL53L1_sum_histogram_data(
+ &(pdev->hist_data),
+ psum_histo);
+
+
+
+
+
+ if (prange_data->VL53L1_PRM_00010 <
+ pxtalk_results->central_histogram__window_start) {
+ pxtalk_results->central_histogram__window_start =
+ prange_data->VL53L1_PRM_00010;
+ }
+
+
+
+ if (prange_data->VL53L1_PRM_00011 >
+ pxtalk_results->central_histogram__window_end) {
+ pxtalk_results->central_histogram__window_end =
+ prange_data->VL53L1_PRM_00011;
+ }
+
+ }
+ }
+ }
+
+
+
+
+
+
+
+#ifdef VL53L1_LOG_ENABLE
+ if ((status == VL53L1_ERROR_NONE)) {
+ VL53L1_print_range_results(
+ &(pres->range_results),
+ "pres->range_results.",
+ VL53L1_TRACE_MODULE_CORE);
+ }
+#endif
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_wait_for_firmware_ready(Dev);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_clear_interrupt_and_enable_next_range(
+ Dev,
+ measurement_mode);
+
+
+ }
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_stop_range(Dev);
+
+
+
+
+
+ for (i = 0 ; i < (pdev->zone_cfg.active_zones+1) ; i++) {
+
+ pxtalk_range_data = &(pxtalk_results->VL53L1_PRM_00005[i+xtalk_result_id]);
+
+ if (pxtalk_range_data->no_of_samples > 0) {
+ pxtalk_range_data->rate_per_spad_kcps_avg =
+ pxtalk_range_data->rate_per_spad_kcps_sum /
+ (uint32_t)pxtalk_range_data->no_of_samples;
+
+ pxtalk_range_data->signal_total_events_avg =
+ pxtalk_range_data->signal_total_events_sum /
+ (int32_t)pxtalk_range_data->no_of_samples;
+
+ pxtalk_range_data->sigma_mm_avg =
+ pxtalk_range_data->sigma_mm_sum /
+ (uint32_t)pxtalk_range_data->no_of_samples;
+
+ } else {
+ pxtalk_range_data->rate_per_spad_kcps_avg =
+ pxtalk_range_data->rate_per_spad_kcps_sum;
+ pxtalk_range_data->signal_total_events_avg =
+ pxtalk_range_data->signal_total_events_sum;
+ pxtalk_range_data->sigma_mm_avg =
+ pxtalk_range_data->sigma_mm_sum;
+ }
+ }
+
+
+
+
+ memcpy(pavg_histo, &(pdev->hist_data), sizeof(VL53L1_histogram_bin_data_t));
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pxtalk_range_data = &(pxtalk_results->VL53L1_PRM_00005[xtalk_histo_id]);
+
+ status = VL53L1_avg_histogram_data(
+ pxtalk_range_data->no_of_samples,
+ psum_histo,
+ pavg_histo);
+ }
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+
+VL53L1_Error VL53L1_get_and_avg_all_xtalk_samples(
+ VL53L1_DEV Dev,
+ uint8_t num_of_samples,
+ uint8_t measurement_mode,
+ int16_t xtalk_filter_thresh_mm,
+ VL53L1_xtalk_range_results_t *pxtalk_results,
+ VL53L1_histogram_bin_data_t *pavg_histo_z0,
+ VL53L1_histogram_bin_data_t *pavg_histo_z1,
+ VL53L1_histogram_bin_data_t *pavg_histo_z2,
+ VL53L1_histogram_bin_data_t *pavg_histo_z3,
+ VL53L1_histogram_bin_data_t *pavg_histo_z4)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+
+
+
+
+
+ VL53L1_range_results_t range_results;
+ VL53L1_range_results_t *prange_results = &range_results;
+
+ VL53L1_range_data_t *prange_data;
+
+
+ VL53L1_histogram_bin_data_t z_sum[4];
+
+ VL53L1_histogram_bin_data_t *pz0_sum = &z_sum[0];
+ VL53L1_histogram_bin_data_t *pz1_sum = &z_sum[1];
+ VL53L1_histogram_bin_data_t *pz2_sum = &z_sum[2];
+ VL53L1_histogram_bin_data_t *pz3_sum = &z_sum[3];
+ VL53L1_histogram_bin_data_t *pz4_sum = &z_sum[4];
+
+ VL53L1_histogram_bin_data_t *pzcurrent_sum = &z_sum[0];
+
+ VL53L1_histogram_bin_data_t *pzcurrent_avg = pavg_histo_z0;
+
+ uint8_t i = 0;
+ uint8_t zone_id = 0;
+ uint8_t final_zone = pdev->zone_cfg.active_zones+1;
+
+ SUPPRESS_UNUSED_WARNING(pxtalk_results);
+
+
+
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ pz0_sum);
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ pz1_sum);
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ pz2_sum);
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ pz3_sum);
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_init_and_start_range(
+ Dev,
+ measurement_mode,
+ VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS);
+
+
+ for (i = 0 ; i <= (final_zone*num_of_samples) ; i++) {
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_wait_for_range_completion(Dev);
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_get_device_results(
+ Dev,
+ VL53L1_DEVICERESULTSLEVEL_FULL,
+ prange_results);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE &&
+ pdev->ll_state.rd_device_state !=
+ VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC) {
+
+ zone_id = pdev->ll_state.rd_zone_id;
+ prange_data = &(prange_results->VL53L1_PRM_00005[0]);
+
+
+
+
+
+ if ((prange_results->active_results > 0) &&
+ (prange_data->median_range_mm <
+ (int16_t)xtalk_filter_thresh_mm)) {
+
+
+
+
+ switch (zone_id) {
+ case 0:
+ pzcurrent_sum = pz0_sum;
+ break;
+ case 1:
+ pzcurrent_sum = pz1_sum;
+ break;
+ case 2:
+ pzcurrent_sum = pz2_sum;
+ break;
+ case 3:
+ pzcurrent_sum = pz3_sum;
+ break;
+ case 4:
+ pzcurrent_sum = pz4_sum;
+ break;
+ default:
+ pzcurrent_sum = pz0_sum;
+ break;
+ }
+
+
+
+
+
+
+ status = VL53L1_sum_histogram_data(
+ &(pdev->hist_data),
+ pzcurrent_sum);
+
+
+ }
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_wait_for_firmware_ready(Dev);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_clear_interrupt_and_enable_next_range(
+ Dev,
+ measurement_mode);
+
+
+ }
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_stop_range(Dev);
+
+
+
+
+
+ memcpy(pavg_histo_z0, &(pdev->hist_data), sizeof(VL53L1_histogram_bin_data_t));
+ memcpy(pavg_histo_z1, &(pdev->hist_data), sizeof(VL53L1_histogram_bin_data_t));
+ memcpy(pavg_histo_z2, &(pdev->hist_data), sizeof(VL53L1_histogram_bin_data_t));
+ memcpy(pavg_histo_z3, &(pdev->hist_data), sizeof(VL53L1_histogram_bin_data_t));
+ memcpy(pavg_histo_z4, &(pdev->hist_data), sizeof(VL53L1_histogram_bin_data_t));
+
+
+
+
+
+ pzcurrent_sum = pz0_sum;
+
+ for (i = 0 ; i < (pdev->zone_cfg.active_zones+1) ; i++) {
+
+ switch (i) {
+ case 0:
+ pzcurrent_avg = pavg_histo_z0;
+ break;
+ case 1:
+ pzcurrent_avg = pavg_histo_z1;
+ break;
+ case 2:
+ pzcurrent_avg = pavg_histo_z2;
+ break;
+ case 3:
+ pzcurrent_avg = pavg_histo_z3;
+ break;
+ case 4:
+ pzcurrent_avg = pavg_histo_z4;
+ break;
+ default:
+ pzcurrent_avg = pavg_histo_z0;
+ break;
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_avg_histogram_data(
+ num_of_samples,
+ pzcurrent_sum,
+ pzcurrent_avg);
+ }
+
+ pzcurrent_sum++;
+
+ }
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_run_offset_calibration(
+ VL53L1_DEV Dev,
+ uint16_t dss_config__target_total_rate_mcps,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint8_t pre_num_of_samples,
+ uint8_t mm1_num_of_samples,
+ uint8_t mm2_num_of_samples,
+ int16_t cal_distance_mm,
+ uint16_t cal_reflectance_pc,
+ VL53L1_Error *pcal_status)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ VL53L1_DevicePresetModes device_preset_modes[VL53L1_MAX_OFFSET_RANGE_RESULTS];
+
+ VL53L1_range_results_t range_results;
+ VL53L1_range_results_t *prange_results = &range_results;
+ VL53L1_range_data_t *prange_data = NULL;
+ VL53L1_offset_range_data_t *poffset = NULL;
+
+ uint8_t i = 0;
+ uint8_t m = 0;
+ uint8_t measurement_mode =
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ uint16_t manual_effective_spads =
+ pdev->gen_cfg.dss_config__manual_effective_spads_select;
+
+ uint8_t num_of_samples[VL53L1_MAX_OFFSET_RANGE_RESULTS];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ switch (pdev->offset_calibration_mode) {
+
+ case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM:
+ case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM_PRE_RANGE_ONLY:
+ device_preset_modes[0] =
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING;
+ device_preset_modes[1] =
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM1_CAL;
+ device_preset_modes[2] =
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM2_CAL;
+ break;
+
+ default:
+ device_preset_modes[0] =
+ VL53L1_DEVICEPRESETMODE_STANDARD_RANGING;
+ device_preset_modes[1] =
+ VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM1_CAL;
+ device_preset_modes[2] =
+ VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM2_CAL;
+ break;
+ }
+
+
+
+ num_of_samples[0] = pre_num_of_samples;
+ num_of_samples[1] = mm1_num_of_samples;
+ num_of_samples[2] = mm2_num_of_samples;
+
+
+
+
+ switch (pdev->offset_calibration_mode) {
+
+ case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD_PRE_RANGE_ONLY:
+ case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM_PRE_RANGE_ONLY:
+
+
+ pdev->offset_results.active_results = 1;
+
+ break;
+
+ default:
+
+ pdev->customer.mm_config__inner_offset_mm = 0;
+ pdev->customer.mm_config__outer_offset_mm = 0;
+ pdev->offset_results.active_results =
+ VL53L1_MAX_OFFSET_RANGE_RESULTS;
+
+ break;
+ }
+
+ pdev->customer.algo__part_to_part_range_offset_mm = 0;
+
+
+
+
+ pdev->offset_results.max_results = VL53L1_MAX_OFFSET_RANGE_RESULTS;
+ pdev->offset_results.cal_distance_mm = cal_distance_mm;
+ pdev->offset_results.cal_reflectance_pc = cal_reflectance_pc;
+
+ for (m = 0 ; m < VL53L1_MAX_OFFSET_RANGE_RESULTS; m++) {
+
+ poffset = &(pdev->offset_results.VL53L1_PRM_00005[m]);
+ poffset->preset_mode = 0;
+ poffset->no_of_samples = 0;
+ poffset->effective_spads = 0;
+ poffset->peak_rate_mcps = 0;
+ poffset->VL53L1_PRM_00004 = 0;
+ poffset->median_range_mm = 0;
+ }
+
+ for (m = 0 ; m < pdev->offset_results.active_results ; m++) {
+
+ poffset = &(pdev->offset_results.VL53L1_PRM_00005[m]);
+
+ poffset->preset_mode = device_preset_modes[m];
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_preset_mode(
+ Dev,
+ device_preset_modes[m],
+ dss_config__target_total_rate_mcps,
+ phasecal_config_timeout_us,
+ range_config_timeout_us,
+ range_config_timeout_us,
+ 100);
+
+ pdev->gen_cfg.dss_config__manual_effective_spads_select =
+ manual_effective_spads;
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_init_and_start_range(
+ Dev,
+ measurement_mode,
+ VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS);
+
+ for (i = 0 ; i <= (num_of_samples[m]+2) ; i++) {
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_wait_for_range_completion(Dev);
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_get_device_results(
+ Dev,
+ VL53L1_DEVICERESULTSLEVEL_FULL,
+ prange_results);
+
+
+
+
+
+
+
+
+
+ prange_data = &(prange_results->VL53L1_PRM_00005[0]);
+
+ if (prange_results->active_results > 0 &&
+ prange_results->stream_count > 1) {
+
+ if (prange_data->range_status ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE) {
+
+ poffset->no_of_samples++;
+ poffset->effective_spads +=
+ (uint32_t)prange_data->VL53L1_PRM_00003;
+ poffset->peak_rate_mcps +=
+ (uint32_t)prange_data->peak_signal_count_rate_mcps;
+ poffset->VL53L1_PRM_00004 +=
+ (uint32_t)prange_data->VL53L1_PRM_00004;
+ poffset->median_range_mm +=
+ (int32_t)prange_data->median_range_mm;
+
+ poffset->dss_config__roi_mode_control =
+ pdev->gen_cfg.dss_config__roi_mode_control;
+ poffset->dss_config__manual_effective_spads_select =
+ pdev->gen_cfg.dss_config__manual_effective_spads_select;
+ }
+ }
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_wait_for_firmware_ready(Dev);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_clear_interrupt_and_enable_next_range(
+ Dev,
+ measurement_mode);
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_stop_range(Dev);
+
+
+
+ if (poffset->no_of_samples > 0) {
+
+ poffset->effective_spads += (poffset->no_of_samples/2);
+ poffset->effective_spads /= poffset->no_of_samples;
+
+ poffset->peak_rate_mcps += (poffset->no_of_samples/2);
+ poffset->peak_rate_mcps /= poffset->no_of_samples;
+
+ poffset->VL53L1_PRM_00004 += (poffset->no_of_samples/2);
+ poffset->VL53L1_PRM_00004 /= poffset->no_of_samples;
+
+ poffset->median_range_mm += (poffset->no_of_samples/2);
+ poffset->median_range_mm /= poffset->no_of_samples;
+
+ poffset->range_mm_offset = (int32_t)cal_distance_mm;
+ poffset->range_mm_offset -= poffset->median_range_mm;
+
+
+
+ if (poffset->preset_mode ==
+ VL53L1_DEVICEPRESETMODE_STANDARD_RANGING)
+ manual_effective_spads =
+ (uint16_t)poffset->effective_spads;
+ }
+ }
+
+
+
+
+ switch (pdev->offset_calibration_mode) {
+
+ case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD_PRE_RANGE_ONLY:
+ case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM_PRE_RANGE_ONLY:
+
+
+
+ pdev->customer.mm_config__inner_offset_mm +=
+ (int16_t)pdev->offset_results.VL53L1_PRM_00005[0].range_mm_offset;
+ pdev->customer.mm_config__outer_offset_mm +=
+ (int16_t)pdev->offset_results.VL53L1_PRM_00005[0].range_mm_offset;
+ break;
+
+ default:
+
+
+ pdev->customer.mm_config__inner_offset_mm =
+ (int16_t)pdev->offset_results.VL53L1_PRM_00005[1].range_mm_offset;
+ pdev->customer.mm_config__outer_offset_mm =
+ (int16_t)pdev->offset_results.VL53L1_PRM_00005[2].range_mm_offset;
+ pdev->customer.algo__part_to_part_range_offset_mm = 0;
+
+
+
+
+
+ pdev->add_off_cal_data.result__mm_inner_actual_effective_spads =
+ (uint16_t)pdev->offset_results.VL53L1_PRM_00005[1].effective_spads;
+ pdev->add_off_cal_data.result__mm_outer_actual_effective_spads =
+ (uint16_t)pdev->offset_results.VL53L1_PRM_00005[2].effective_spads;
+
+ pdev->add_off_cal_data.result__mm_inner_peak_signal_count_rtn_mcps =
+ (uint16_t)pdev->offset_results.VL53L1_PRM_00005[1].peak_rate_mcps;
+ pdev->add_off_cal_data.result__mm_outer_peak_signal_count_rtn_mcps =
+ (uint16_t)pdev->offset_results.VL53L1_PRM_00005[2].peak_rate_mcps;
+
+ break;
+ }
+
+
+
+
+
+
+
+
+
+ pdev->cust_dmax_cal.ref__actual_effective_spads =
+ (uint16_t)pdev->offset_results.VL53L1_PRM_00005[0].effective_spads;
+ pdev->cust_dmax_cal.ref__peak_signal_count_rate_mcps =
+ (uint16_t)pdev->offset_results.VL53L1_PRM_00005[0].peak_rate_mcps;
+
+
+
+ pdev->cust_dmax_cal.ref__distance_mm = cal_distance_mm * 16;
+
+ pdev->cust_dmax_cal.ref_reflectance_pc = cal_reflectance_pc;
+ pdev->cust_dmax_cal.coverglass_transmission = 0x0100;
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_customer_nvm_managed(
+ Dev,
+ &(pdev->customer));
+
+
+
+
+
+
+ for (m = 0 ; m < pdev->offset_results.active_results ; m++) {
+
+ poffset = &(pdev->offset_results.VL53L1_PRM_00005[m]);
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pdev->offset_results.cal_report = m;
+
+ if (poffset->no_of_samples < num_of_samples[m])
+ status = VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES;
+
+
+
+
+
+
+ if (m == 0 && poffset->VL53L1_PRM_00004 >
+ VL53L1_OFFSET_CAL_MAX_SIGMA_MM)
+ status = VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH;
+
+ if (poffset->peak_rate_mcps >
+ VL53L1_OFFSET_CAL_MAX_PRE_PEAK_RATE_MCPS)
+ status = VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH;
+
+ if (poffset->dss_config__manual_effective_spads_select <
+ VL53L1_OFFSET_CAL_MIN_EFFECTIVE_SPADS)
+ status = VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW;
+
+ if (poffset->dss_config__manual_effective_spads_select == 0)
+ status = VL53L1_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL;
+
+ if (poffset->no_of_samples == 0)
+ status = VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL;
+ }
+ }
+
+
+
+
+
+
+ pdev->offset_results.cal_status = status;
+ *pcal_status = pdev->offset_results.cal_status;
+
+
+
+
+ IGNORE_STATUS(
+ IGNORE_OFFSET_CAL_MISSING_SAMPLES,
+ VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_OFFSET_CAL_SIGMA_TOO_HIGH,
+ VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_OFFSET_CAL_RATE_TOO_HIGH,
+ VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_OFFSET_CAL_SPAD_COUNT_TOO_LOW,
+ VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW,
+ status);
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+
+
+ VL53L1_print_customer_nvm_managed(
+ &(pdev->customer),
+ "run_offset_calibration():pdev->lldata.customer.",
+ VL53L1_TRACE_MODULE_OFFSET_DATA);
+
+ VL53L1_print_dmax_calibration_data(
+ &(pdev->fmt_dmax_cal),
+ "run_offset_calibration():pdev->lldata.fmt_dmax_cal.",
+ VL53L1_TRACE_MODULE_OFFSET_DATA);
+
+ VL53L1_print_dmax_calibration_data(
+ &(pdev->cust_dmax_cal),
+ "run_offset_calibration():pdev->lldata.cust_dmax_cal.",
+ VL53L1_TRACE_MODULE_OFFSET_DATA);
+
+ VL53L1_print_additional_offset_cal_data(
+ &(pdev->add_off_cal_data),
+ "run_offset_calibration():pdev->lldata.add_off_cal_data.",
+ VL53L1_TRACE_MODULE_OFFSET_DATA);
+
+ VL53L1_print_offset_range_results(
+ &(pdev->offset_results),
+ "run_offset_calibration():pdev->lldata.offset_results.",
+ VL53L1_TRACE_MODULE_OFFSET_DATA);
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_run_zone_calibration(
+ VL53L1_DEV Dev,
+ VL53L1_DevicePresetModes device_preset_mode,
+ VL53L1_DeviceZonePreset zone_preset,
+ VL53L1_zone_config_t *pzone_cfg,
+ uint16_t dss_config__target_total_rate_mcps,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint16_t num_of_samples,
+ int16_t cal_distance_mm,
+ uint16_t cal_reflectance_pc,
+ VL53L1_Error *pcal_status)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ VL53L1_range_results_t range_results;
+ VL53L1_range_results_t *prange_results = &range_results;
+ VL53L1_range_data_t *prange_data = NULL;
+ VL53L1_zone_calibration_data_t *pzone_data = NULL;
+
+ uint16_t i = 0;
+ uint16_t m = 0;
+
+ uint8_t z = 0;
+ uint8_t measurement_mode =
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+
+ VL53L1_OffsetCorrectionMode offset_cor_mode =
+ VL53L1_OFFSETCORRECTIONMODE__NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_preset_mode(
+ Dev,
+ device_preset_mode,
+ dss_config__target_total_rate_mcps,
+ phasecal_config_timeout_us,
+ mm_config_timeout_us,
+ range_config_timeout_us,
+ 100);
+
+
+
+
+ if (zone_preset == VL53L1_DEVICEZONEPRESET_CUSTOM) {
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_zone_config(
+ Dev,
+ pzone_cfg);
+
+ } else if (zone_preset != VL53L1_DEVICEZONEPRESET_NONE) {
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_zone_preset(
+ Dev,
+ zone_preset);
+ }
+
+
+
+
+
+
+ pres->zone_cal.preset_mode = device_preset_mode;
+ pres->zone_cal.zone_preset = zone_preset;
+
+
+ pres->zone_cal.cal_distance_mm = cal_distance_mm * 16;
+ pres->zone_cal.cal_reflectance_pc = cal_reflectance_pc;
+ pres->zone_cal.max_zones = VL53L1_MAX_USER_ZONES;
+ pres->zone_cal.active_zones = pdev->zone_cfg.active_zones + 1;
+
+ for (i = 0 ; i < VL53L1_MAX_USER_ZONES ; i++) {
+ pres->zone_cal.VL53L1_PRM_00005[i].no_of_samples = 0;
+ pres->zone_cal.VL53L1_PRM_00005[i].effective_spads = 0;
+ pres->zone_cal.VL53L1_PRM_00005[i].peak_rate_mcps = 0;
+ pres->zone_cal.VL53L1_PRM_00005[i].VL53L1_PRM_00014 = 0;
+ pres->zone_cal.VL53L1_PRM_00005[i].VL53L1_PRM_00004 = 0;
+ pres->zone_cal.VL53L1_PRM_00005[i].median_range_mm = 0;
+ pres->zone_cal.VL53L1_PRM_00005[i].range_mm_offset = 0;
+ }
+
+ pres->zone_cal.phasecal_result__reference_phase = 0;
+ pres->zone_cal.zero_distance_phase = 0;
+
+
+
+
+
+
+
+ status =
+ VL53L1_get_offset_correction_mode(
+ Dev,
+ &offset_cor_mode);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_offset_correction_mode(
+ Dev,
+ VL53L1_OFFSETCORRECTIONMODE__NONE);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_init_and_start_range(
+ Dev,
+ measurement_mode,
+ VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS);
+
+
+
+
+ m = (num_of_samples + 2) * (uint16_t)pres->zone_cal.active_zones;
+
+ for (i = 0 ; i <= m ; i++) {
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_wait_for_range_completion(Dev);
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_get_device_results(
+ Dev,
+ VL53L1_DEVICERESULTSLEVEL_FULL,
+ prange_results);
+
+
+
+
+
+
+
+
+
+ prange_data = &(prange_results->VL53L1_PRM_00005[0]);
+
+ if (prange_results->active_results > 0 &&
+ i > (uint16_t)pres->zone_cal.active_zones) {
+
+ if (prange_data->range_status ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE) {
+
+ pres->zone_cal.phasecal_result__reference_phase =
+ pdev->hist_data.phasecal_result__reference_phase;
+ pres->zone_cal.zero_distance_phase =
+ pdev->hist_data.zero_distance_phase;
+
+ pzone_data = &(pres->zone_cal.VL53L1_PRM_00005[prange_results->zone_id]);
+ pzone_data->no_of_samples++;
+ pzone_data->effective_spads +=
+ (uint32_t)prange_data->VL53L1_PRM_00003;
+ pzone_data->peak_rate_mcps +=
+ (uint32_t)prange_data->peak_signal_count_rate_mcps;
+ pzone_data->VL53L1_PRM_00014 +=
+ (uint32_t)prange_data->VL53L1_PRM_00014;
+ pzone_data->VL53L1_PRM_00004 +=
+ (uint32_t)prange_data->VL53L1_PRM_00004;
+ pzone_data->median_range_mm +=
+ (int32_t)prange_data->median_range_mm;
+
+ }
+ }
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_wait_for_firmware_ready(Dev);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_clear_interrupt_and_enable_next_range(
+ Dev,
+ measurement_mode);
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_stop_range(Dev);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_offset_correction_mode(
+ Dev,
+ offset_cor_mode);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ for (z = 0 ; z < pres->zone_cal.active_zones ; z++) {
+
+ pzone_data = &(pres->zone_cal.VL53L1_PRM_00005[z]);
+
+
+
+ if (pzone_data->no_of_samples > 0) {
+
+ pzone_data->effective_spads += (pzone_data->no_of_samples/2);
+ pzone_data->effective_spads /= pzone_data->no_of_samples;
+
+ pzone_data->peak_rate_mcps += (pzone_data->no_of_samples/2);
+ pzone_data->peak_rate_mcps /= pzone_data->no_of_samples;
+
+ pzone_data->VL53L1_PRM_00014 += (pzone_data->no_of_samples/2);
+ pzone_data->VL53L1_PRM_00014 /= pzone_data->no_of_samples;
+
+ pzone_data->VL53L1_PRM_00004 += (pzone_data->no_of_samples/2);
+ pzone_data->VL53L1_PRM_00004 /= pzone_data->no_of_samples;
+
+
+
+ pzone_data->median_range_mm *= 4;
+ pzone_data->median_range_mm += (pzone_data->no_of_samples/2);
+ pzone_data->median_range_mm /= pzone_data->no_of_samples;
+
+ pzone_data->range_mm_offset = ((int32_t)cal_distance_mm) * 4;
+ pzone_data->range_mm_offset -= pzone_data->median_range_mm;
+
+ if (pzone_data->no_of_samples < num_of_samples)
+ status = VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES;
+
+ if (pzone_data->VL53L1_PRM_00004 >
+ VL53L1_ZONE_CAL_MAX_SIGMA_MM)
+ status = VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH;
+
+ if (pzone_data->peak_rate_mcps >
+ VL53L1_ZONE_CAL_MAX_PRE_PEAK_RATE_MCPS)
+ status = VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH;
+
+ } else {
+ status = VL53L1_ERROR_ZONE_CAL_NO_SAMPLE_FAIL;
+ }
+ }
+ }
+
+
+
+
+
+
+ pres->zone_cal.cal_status = status;
+ *pcal_status = pres->zone_cal.cal_status;
+
+
+
+
+ IGNORE_STATUS(
+ IGNORE_ZONE_CAL_MISSING_SAMPLES,
+ VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_ZONE_CAL_SIGMA_TOO_HIGH,
+ VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_ZONE_CAL_RATE_TOO_HIGH,
+ VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH,
+ status);
+
+
+
+
+
+
+
+
+
+
+
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_run_spad_rate_map(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceTestMode device_test_mode,
+ VL53L1_DeviceSscArray array_select,
+ uint32_t ssc_config_timeout_us,
+ VL53L1_spad_rate_data_t *pspad_rate_data)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_powerforce(Dev);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->ssc_cfg.array_select = array_select;
+ pdev->ssc_cfg.timeout_us = ssc_config_timeout_us;
+ status =
+ VL53L1_set_ssc_config(
+ Dev,
+ &(pdev->ssc_cfg),
+ pdev->stat_nvm.osc_measured__fast_osc__frequency);
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_run_device_test(
+ Dev,
+ device_test_mode);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_get_spad_rate_data(
+ Dev,
+ pspad_rate_data);
+
+ if (device_test_mode == VL53L1_DEVICETESTMODE_LCR_VCSEL_ON)
+ pspad_rate_data->fractional_bits = 7;
+ else
+ pspad_rate_data->fractional_bits = 15;
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_powerforce(Dev);
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ VL53L1_print_spad_rate_data(
+ pspad_rate_data,
+ "run_spad_rate_map():",
+ VL53L1_TRACE_MODULE_SPAD_RATE_MAP);
+ VL53L1_print_spad_rate_map(
+ pspad_rate_data,
+ "run_spad_rate_map():",
+ VL53L1_TRACE_MODULE_SPAD_RATE_MAP);
+ }
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_run_device_test(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceTestMode device_test_mode)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t comms_buffer[2];
+ uint8_t gpio_hv_mux__ctrl = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_RdByte(
+ Dev,
+ VL53L1_GPIO_HV_MUX__CTRL,
+ &gpio_hv_mux__ctrl);
+
+ if (status == VL53L1_ERROR_NONE)
+ pdev->stat_cfg.gpio_hv_mux__ctrl = gpio_hv_mux__ctrl;
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_start_test(
+ Dev,
+ device_test_mode);
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_wait_for_test_completion(Dev);
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_ReadMulti(
+ Dev,
+ VL53L1_RESULT__RANGE_STATUS,
+ comms_buffer,
+ 2);
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->sys_results.result__range_status = comms_buffer[0];
+ pdev->sys_results.result__report_status = comms_buffer[1];
+ }
+
+
+
+
+ pdev->sys_results.result__range_status &=
+ VL53L1_RANGE_STATUS__RANGE_STATUS_MASK;
+
+ if (status == VL53L1_ERROR_NONE) {
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ " Device Test Complete:\n\t%-32s = %3u\n\t%-32s = %3u\n",
+ "result__range_status",
+ pdev->sys_results.result__range_status,
+ "result__report_status",
+ pdev->sys_results.result__report_status);
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_clear_interrupt(Dev);
+ }
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_start_test(
+ Dev,
+ 0x00);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_api_core.c b/drivers/input/misc/vl53L1/src/vl53l1_api_core.c
new file mode 100644
index 000000000000..7f32b6a92a8e
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_api_core.c
@@ -0,0 +1,4790 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_ll_device.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_platform_ipp.h"
+#include "vl53l1_register_map.h"
+#include "vl53l1_register_settings.h"
+#include "vl53l1_register_funcs.h"
+#include "vl53l1_hist_map.h"
+#include "vl53l1_hist_structs.h"
+#include "vl53l1_nvm_map.h"
+#include "vl53l1_nvm_structs.h"
+#include "vl53l1_nvm.h"
+#include "vl53l1_core.h"
+#include "vl53l1_wait.h"
+#include "vl53l1_zone_presets.h"
+#include "vl53l1_api_preset_modes.h"
+#include "vl53l1_fpga_core.h"
+#include "vl53l1_silicon_core.h"
+#include "vl53l1_api_core.h"
+
+#ifdef VL53L1_LOG_ENABLE
+#include "vl53l1_api_debug.h"
+#endif
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, \
+ fmt, ##__VA_ARGS__)
+
+#define trace_print(level, ...) \
+ _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_CORE, \
+ level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+
+#define VL53L1_MAX_I2C_XFER_SIZE 256
+
+VL53L1_Error VL53L1_get_version(
+ VL53L1_DEV Dev,
+ VL53L1_ll_version_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ VL53L1_init_version(Dev);
+
+ memcpy(pdata, &(pdev->version), sizeof(VL53L1_ll_version_t));
+
+ return VL53L1_ERROR_NONE;
+}
+
+
+VL53L1_Error VL53L1_is_fpga_system(
+ VL53L1_DEV Dev,
+ uint8_t *pfpga_system)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status = VL53L1_RdByte(
+ Dev,
+ VL53L1_NVM_BIST__COMPLETE,
+ pfpga_system);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_device_firmware_version(
+ VL53L1_DEV Dev,
+ uint16_t *pfw_version)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_RdWord(
+ Dev,
+ VL53L1_MCU_GENERAL_PURPOSE__GP_0,
+ pfw_version);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_data_init(
+ VL53L1_DEV Dev,
+ uint8_t read_p2p_data)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ uint8_t i = 0;
+
+ LOG_FUNCTION_START("");
+
+ VL53L1_init_ll_driver_state(
+ Dev,
+ VL53L1_DEVICESTATE_UNKNOWN);
+
+ pres->range_results.max_results = VL53L1_MAX_RANGE_RESULTS;
+ pres->range_results.active_results = 0;
+ pres->zone_results.max_zones = VL53L1_MAX_USER_ZONES;
+ pres->zone_results.active_zones = 0;
+ pres->zone_hists.max_zones = VL53L1_MAX_USER_ZONES;
+ pres->zone_hists.active_zones = 0;
+
+
+
+
+ pres->zone_cal.max_zones = VL53L1_MAX_USER_ZONES;
+ pres->zone_cal.active_zones = 0;
+ for (i = 0 ; i < VL53L1_MAX_USER_ZONES ; i++) {
+ pres->zone_cal.VL53L1_PRM_00005[i].no_of_samples = 0;
+ pres->zone_cal.VL53L1_PRM_00005[i].effective_spads = 0;
+ pres->zone_cal.VL53L1_PRM_00005[i].peak_rate_mcps = 0;
+ pres->zone_cal.VL53L1_PRM_00005[i].median_range_mm = 0;
+ pres->zone_cal.VL53L1_PRM_00005[i].range_mm_offset = 0;
+ }
+
+ pdev->wait_method = VL53L1_WAIT_METHOD_BLOCKING;
+ pdev->preset_mode = VL53L1_DEVICEPRESETMODE_STANDARD_RANGING;
+ pdev->zone_preset = VL53L1_DEVICEZONEPRESET_NONE;
+ pdev->measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_STOP;
+
+ pdev->offset_calibration_mode =
+ VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD;
+ pdev->offset_correction_mode =
+ VL53L1_OFFSETCORRECTIONMODE__MM1_MM2_OFFSETS;
+ pdev->dmax_mode =
+ VL53L1_DEVICEDMAXMODE__FMT_CAL_DATA;
+
+ pdev->phasecal_config_timeout_us = 1000;
+ pdev->mm_config_timeout_us = 2000;
+ pdev->range_config_timeout_us = 13000;
+ pdev->inter_measurement_period_ms = 100;
+ pdev->debug_mode = 0x00;
+
+ pdev->offset_results.max_results = VL53L1_MAX_OFFSET_RANGE_RESULTS;
+ pdev->offset_results.active_results = 0;
+
+
+
+
+
+ pdev->gain_cal.standard_ranging_gain_factor =
+ VL53L1_GAIN_FACTOR__STANDARD_DEFAULT;
+ pdev->gain_cal.histogram_ranging_gain_factor =
+ VL53L1_GAIN_FACTOR__HISTOGRAM_DEFAULT;
+
+
+
+
+
+ VL53L1_init_version(Dev);
+
+
+
+
+
+
+
+
+
+
+ if (read_p2p_data > 0 && status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_read_p2p_data(Dev);
+
+
+
+ status =
+ VL53L1_init_refspadchar_config_struct(
+ &(pdev->refspadchar));
+
+
+
+ status =
+ VL53L1_init_ssc_config_struct(
+ &(pdev->ssc_cfg));
+
+
+
+
+
+ status =
+ VL53L1_init_xtalk_config_struct(
+ &(pdev->customer),
+ &(pdev->xtalk_cfg));
+
+
+
+ status =
+ VL53L1_init_hist_post_process_config_struct(
+ pdev->xtalk_cfg.global_crosstalk_compensation_enable,
+ &(pdev->histpostprocess));
+
+
+
+ status =
+ VL53L1_init_hist_gen3_dmax_config_struct(
+ &(pdev->dmax_cfg));
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_set_preset_mode(
+ Dev,
+ pdev->preset_mode,
+ 0x0A00,
+
+ pdev->phasecal_config_timeout_us,
+ pdev->mm_config_timeout_us,
+ pdev->range_config_timeout_us,
+ pdev->inter_measurement_period_ms);
+
+
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->hist_data));
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->hist_xtalk));
+
+
+
+ VL53L1_init_xtalk_bin_data_struct(
+ 0,
+ VL53L1_XTALK_HISTO_BINS,
+ &(pdev->xtalk_shapes.xtalk_shape));
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+
+
+ VL53L1_print_static_nvm_managed(
+ &(pdev->stat_nvm),
+ "data_init():pdev->lldata.stat_nvm.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_customer_nvm_managed(
+ &(pdev->customer),
+ "data_init():pdev->lldata.customer.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_nvm_copy_data(
+ &(pdev->nvm_copy_data),
+ "data_init():pdev->lldata.nvm_copy_data.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_dmax_calibration_data(
+ &(pdev->fmt_dmax_cal),
+ "data_init():pdev->lldata.fmt_dmax_cal.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_dmax_calibration_data(
+ &(pdev->cust_dmax_cal),
+ "data_init():pdev->lldata.cust_dmax_cal.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_additional_offset_cal_data(
+ &(pdev->add_off_cal_data),
+ "data_init():pdev->lldata.add_off_cal_data.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_user_zone(
+ &(pdev->mm_roi),
+ "data_init():pdev->lldata.mm_roi.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_cal_peak_rate_map(
+ &(pdev->cal_peak_rate_map),
+ "data_init():pdev->lldata.cal_peak_rate_map.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_read_p2p_data(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ VL53L1_decoded_nvm_fmt_range_data_t fmt_range_result_data;
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_is_fpga_system(
+ Dev,
+ &(pdev->fpga_system));
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_get_static_nvm_managed(
+ Dev,
+ &(pdev->stat_nvm));
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_get_customer_nvm_managed(
+ Dev,
+ &(pdev->customer));
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status = VL53L1_get_nvm_copy_data(
+ Dev,
+ &(pdev->nvm_copy_data));
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_copy_rtn_good_spads_to_buffer(
+ &(pdev->nvm_copy_data),
+ &(pdev->rtn_good_spads[0]));
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pdev->histpostprocess.algo__crosstalk_compensation_plane_offset_kcps =
+ pdev->customer.algo__crosstalk_compensation_plane_offset_kcps;
+ pdev->histpostprocess.algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pdev->customer.algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pdev->histpostprocess.algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pdev->customer.algo__crosstalk_compensation_y_plane_gradient_kcps;
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_read_nvm_cal_peak_rate_map(
+ Dev,
+ &(pdev->cal_peak_rate_map));
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status =
+ VL53L1_read_nvm_additional_offset_cal_data(
+ Dev,
+ &(pdev->add_off_cal_data));
+
+
+
+
+
+
+ if (pdev->add_off_cal_data.result__mm_inner_peak_signal_count_rtn_mcps == 0 &&
+ pdev->add_off_cal_data.result__mm_outer_peak_signal_count_rtn_mcps == 0) {
+
+ pdev->add_off_cal_data.result__mm_inner_peak_signal_count_rtn_mcps = 0x0080;
+
+ pdev->add_off_cal_data.result__mm_outer_peak_signal_count_rtn_mcps = 0x0180;
+
+
+
+
+
+ VL53L1_calc_mm_effective_spads(
+ pdev->nvm_copy_data.roi_config__mode_roi_centre_spad,
+ pdev->nvm_copy_data.roi_config__mode_roi_xy_size,
+ 0xC7,
+
+ 0xFF,
+ &(pdev->rtn_good_spads[0]),
+ VL53L1_RTN_SPAD_APERTURE_TRANSMISSION,
+ &(pdev->add_off_cal_data.result__mm_inner_actual_effective_spads),
+ &(pdev->add_off_cal_data.result__mm_outer_actual_effective_spads));
+ }
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status =
+ VL53L1_read_nvm_fmt_range_results_data(
+ Dev,
+ VL53L1_NVM__FMT__RANGE_RESULTS__140MM_DARK,
+ &fmt_range_result_data);
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->fmt_dmax_cal.ref__actual_effective_spads =
+ fmt_range_result_data.result__actual_effective_rtn_spads;
+ pdev->fmt_dmax_cal.ref__peak_signal_count_rate_mcps =
+ fmt_range_result_data.result__peak_signal_count_rate_rtn_mcps;
+ pdev->fmt_dmax_cal.ref__distance_mm =
+ fmt_range_result_data.measured_distance_mm;
+
+
+
+ pdev->fmt_dmax_cal.ref_reflectance_pc = 0x000F;
+
+
+
+ pdev->fmt_dmax_cal.coverglass_transmission = 0x0100;
+ }
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_RdWord(
+ Dev,
+ VL53L1_RESULT__OSC_CALIBRATE_VAL,
+ &(pdev->dbg_results.result__osc_calibrate_val));
+
+
+
+
+
+
+ if (pdev->stat_nvm.osc_measured__fast_osc__frequency < 0x1000) {
+ trace_print(
+ VL53L1_TRACE_LEVEL_WARNING,
+ "\nInvalid %s value (0x%04X) - forcing to 0x%04X\n\n",
+ "pdev->stat_nvm.osc_measured__fast_osc__frequency",
+ pdev->stat_nvm.osc_measured__fast_osc__frequency,
+ 0xBCCC);
+ pdev->stat_nvm.osc_measured__fast_osc__frequency = 0xBCCC;
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_get_mode_mitigation_roi(
+ Dev,
+ &(pdev->mm_roi));
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_software_reset(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_SOFT_RESET,
+ 0x00);
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WaitUs(
+ Dev,
+ VL53L1_SOFTWARE_RESET_DURATION_US);
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_SOFT_RESET,
+ 0x01);
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_wait_for_boot_completion(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_part_to_part_data(
+ VL53L1_DEV Dev,
+ VL53L1_calibration_data_t *pcal_data)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ if (pcal_data->struct_version !=
+ VL53L1_LL_CALIBRATION_DATA_STRUCT_VERSION) {
+ status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+ memcpy(
+ &(pdev->customer),
+ &(pcal_data->customer),
+ sizeof(VL53L1_customer_nvm_managed_t));
+
+
+
+ memcpy(
+ &(pdev->add_off_cal_data),
+ &(pcal_data->add_off_cal_data),
+ sizeof(VL53L1_additional_offset_cal_data_t));
+
+
+
+ memcpy(
+ &(pdev->fmt_dmax_cal),
+ &(pcal_data->fmt_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+
+
+ memcpy(
+ &(pdev->cust_dmax_cal),
+ &(pcal_data->cust_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+
+
+ memcpy(
+ &(pdev->xtalk_shapes),
+ &(pcal_data->xtalkhisto),
+ sizeof(VL53L1_xtalk_histogram_data_t));
+
+
+
+ memcpy(
+ &(pdev->gain_cal),
+ &(pcal_data->gain_cal),
+ sizeof(VL53L1_gain_calibration_data_t));
+
+
+
+ memcpy(
+ &(pdev->cal_peak_rate_map),
+ &(pcal_data->cal_peak_rate_map),
+ sizeof(VL53L1_cal_peak_rate_map_t));
+
+
+
+
+
+
+ pdev->xtalk_cfg.algo__crosstalk_compensation_plane_offset_kcps =
+ pdev->customer.algo__crosstalk_compensation_plane_offset_kcps;
+ pdev->xtalk_cfg.algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pdev->customer.algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pdev->xtalk_cfg.algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pdev->customer.algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+ pdev->histpostprocess.algo__crosstalk_compensation_plane_offset_kcps =
+ VL53L1_calc_crosstalk_plane_offset_with_margin(
+ pdev->xtalk_cfg.algo__crosstalk_compensation_plane_offset_kcps,
+ pdev->xtalk_cfg.histogram_mode_crosstalk_margin_kcps);
+
+ pdev->histpostprocess.algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pdev->histpostprocess.algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+
+ if (pdev->xtalk_cfg.global_crosstalk_compensation_enable == 0x00) {
+ pdev->customer.algo__crosstalk_compensation_plane_offset_kcps =
+ 0x00;
+ pdev->customer.algo__crosstalk_compensation_x_plane_gradient_kcps =
+ 0x00;
+ pdev->customer.algo__crosstalk_compensation_y_plane_gradient_kcps =
+ 0x00;
+ } else {
+ pdev->customer.algo__crosstalk_compensation_plane_offset_kcps =
+ VL53L1_calc_crosstalk_plane_offset_with_margin(
+ pdev->xtalk_cfg.algo__crosstalk_compensation_plane_offset_kcps,
+ pdev->xtalk_cfg.lite_mode_crosstalk_margin_kcps);
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_part_to_part_data(
+ VL53L1_DEV Dev,
+ VL53L1_calibration_data_t *pcal_data)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pcal_data->struct_version =
+ VL53L1_LL_CALIBRATION_DATA_STRUCT_VERSION;
+
+
+
+ memcpy(
+ &(pcal_data->customer),
+ &(pdev->customer),
+ sizeof(VL53L1_customer_nvm_managed_t));
+
+
+
+
+
+
+ pcal_data->customer.algo__crosstalk_compensation_plane_offset_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_compensation_plane_offset_kcps;
+ pcal_data->customer.algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pcal_data->customer.algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+ memcpy(
+ &(pcal_data->fmt_dmax_cal),
+ &(pdev->fmt_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+
+
+ memcpy(
+ &(pcal_data->cust_dmax_cal),
+ &(pdev->cust_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+
+
+ memcpy(
+ &(pcal_data->add_off_cal_data),
+ &(pdev->add_off_cal_data),
+ sizeof(VL53L1_additional_offset_cal_data_t));
+
+
+
+ memcpy(
+ &(pcal_data->mm_roi),
+ &(pdev->mm_roi),
+ sizeof(VL53L1_user_zone_t));
+
+
+
+ memcpy(
+ &(pcal_data->xtalkhisto),
+ &(pdev->xtalk_shapes),
+ sizeof(VL53L1_xtalk_histogram_data_t));
+
+
+
+ memcpy(
+ &(pcal_data->gain_cal),
+ &(pdev->gain_cal),
+ sizeof(VL53L1_gain_calibration_data_t));
+
+
+
+ memcpy(
+ &(pcal_data->cal_peak_rate_map),
+ &(pdev->cal_peak_rate_map),
+ sizeof(VL53L1_cal_peak_rate_map_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_inter_measurement_period_ms(
+ VL53L1_DEV Dev,
+ uint32_t inter_measurement_period_ms)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->dbg_results.result__osc_calibrate_val == 0)
+ status = VL53L1_ERROR_DIVISION_BY_ZERO;
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->inter_measurement_period_ms = inter_measurement_period_ms;
+ pdev->tim_cfg.system__intermeasurement_period = \
+ inter_measurement_period_ms *
+ (uint32_t)pdev->dbg_results.result__osc_calibrate_val;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_inter_measurement_period_ms(
+ VL53L1_DEV Dev,
+ uint32_t *pinter_measurement_period_ms)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->dbg_results.result__osc_calibrate_val == 0)
+ status = VL53L1_ERROR_DIVISION_BY_ZERO;
+
+ if (status == VL53L1_ERROR_NONE)
+ *pinter_measurement_period_ms = \
+ pdev->tim_cfg.system__intermeasurement_period /
+ (uint32_t)pdev->dbg_results.result__osc_calibrate_val;
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_timeouts_us(
+ VL53L1_DEV Dev,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->stat_nvm.osc_measured__fast_osc__frequency == 0)
+ status = VL53L1_ERROR_DIVISION_BY_ZERO;
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pdev->phasecal_config_timeout_us = phasecal_config_timeout_us;
+ pdev->mm_config_timeout_us = mm_config_timeout_us;
+ pdev->range_config_timeout_us = range_config_timeout_us;
+
+ status =
+ VL53L1_calc_timeout_register_values(
+ phasecal_config_timeout_us,
+ mm_config_timeout_us,
+ range_config_timeout_us,
+ pdev->stat_nvm.osc_measured__fast_osc__frequency,
+ &(pdev->gen_cfg),
+ &(pdev->tim_cfg));
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_timeouts_us(
+ VL53L1_DEV Dev,
+ uint32_t *pphasecal_config_timeout_us,
+ uint32_t *pmm_config_timeout_us,
+ uint32_t *prange_config_timeout_us)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint32_t macro_period_us = 0;
+ uint16_t timeout_encoded = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->stat_nvm.osc_measured__fast_osc__frequency == 0)
+ status = VL53L1_ERROR_DIVISION_BY_ZERO;
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+ macro_period_us =
+ VL53L1_calc_macro_period_us(
+ pdev->stat_nvm.osc_measured__fast_osc__frequency,
+ pdev->tim_cfg.range_config__vcsel_period_a);
+
+
+
+
+ *pphasecal_config_timeout_us =
+ VL53L1_calc_timeout_us(
+ (uint32_t)pdev->gen_cfg.phasecal_config__timeout_macrop,
+ macro_period_us);
+
+
+
+
+ timeout_encoded =
+ (uint16_t)pdev->tim_cfg.mm_config__timeout_macrop_a_hi;
+ timeout_encoded = (timeout_encoded << 8) +
+ (uint16_t)pdev->tim_cfg.mm_config__timeout_macrop_a_lo;
+
+ *pmm_config_timeout_us =
+ VL53L1_calc_decoded_timeout_us(
+ timeout_encoded,
+ macro_period_us);
+
+
+
+
+ timeout_encoded =
+ (uint16_t)pdev->tim_cfg.range_config__timeout_macrop_a_hi;
+ timeout_encoded = (timeout_encoded << 8) +
+ (uint16_t)pdev->tim_cfg.range_config__timeout_macrop_a_lo;
+
+ *prange_config_timeout_us =
+ VL53L1_calc_decoded_timeout_us(
+ timeout_encoded,
+ macro_period_us);
+
+ pdev->phasecal_config_timeout_us = *pphasecal_config_timeout_us;
+ pdev->mm_config_timeout_us = *pmm_config_timeout_us;
+ pdev->range_config_timeout_us = *prange_config_timeout_us;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_calibration_repeat_period(
+ VL53L1_DEV Dev,
+ uint16_t cal_config__repeat_period)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ pdev->gen_cfg.cal_config__repeat_rate = cal_config__repeat_period;
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_get_calibration_repeat_period(
+ VL53L1_DEV Dev,
+ uint16_t *pcal_config__repeat_period)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ *pcal_config__repeat_period = pdev->gen_cfg.cal_config__repeat_rate;
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_set_sequence_config_bit(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceSequenceConfig bit_id,
+ uint8_t value)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t bit_mask = 0x01;
+ uint8_t clr_mask = 0xFF - bit_mask;
+ uint8_t bit_value = value & bit_mask;
+
+ if (bit_id <= VL53L1_DEVICESEQUENCECONFIG_RANGE) {
+
+ if (bit_id > 0) {
+ bit_mask = 0x01 << bit_id;
+ bit_value = bit_value << bit_id;
+ clr_mask = 0xFF - bit_mask;
+ }
+
+ pdev->dyn_cfg.system__sequence_config = \
+ (pdev->dyn_cfg.system__sequence_config & clr_mask) | \
+ bit_value;
+
+ } else {
+ status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_get_sequence_config_bit(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceSequenceConfig bit_id,
+ uint8_t *pvalue)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t bit_mask = 0x01;
+
+ if (bit_id <= VL53L1_DEVICESEQUENCECONFIG_RANGE) {
+
+ if (bit_id > 0) {
+ bit_mask = 0x01 << bit_id;
+ }
+
+ *pvalue =
+ pdev->dyn_cfg.system__sequence_config & bit_mask;
+
+ if (bit_id > 0) {
+ *pvalue = *pvalue >> bit_id;
+ }
+
+ } else {
+ status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_interrupt_polarity(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceInterruptPolarity interrupt_polarity)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ pdev->stat_cfg.gpio_hv_mux__ctrl = \
+ (pdev->stat_cfg.gpio_hv_mux__ctrl & \
+ VL53L1_DEVICEINTERRUPTPOLARITY_CLEAR_MASK) | \
+ (interrupt_polarity & \
+ VL53L1_DEVICEINTERRUPTPOLARITY_BIT_MASK);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_set_refspadchar_config_struct(
+ VL53L1_DEV Dev,
+ VL53L1_refspadchar_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->refspadchar.device_test_mode = pdata->device_test_mode;
+ pdev->refspadchar.VL53L1_PRM_00007 = pdata->VL53L1_PRM_00007;
+ pdev->refspadchar.timeout_us = pdata->timeout_us;
+ pdev->refspadchar.target_count_rate_mcps =
+ pdata->target_count_rate_mcps;
+ pdev->refspadchar.min_count_rate_limit_mcps =
+ pdata->min_count_rate_limit_mcps;
+ pdev->refspadchar.max_count_rate_limit_mcps =
+ pdata->max_count_rate_limit_mcps;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_get_refspadchar_config_struct(
+ VL53L1_DEV Dev,
+ VL53L1_refspadchar_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdata->device_test_mode = pdev->refspadchar.device_test_mode;
+ pdata->VL53L1_PRM_00007 = pdev->refspadchar.VL53L1_PRM_00007;
+ pdata->timeout_us = pdev->refspadchar.timeout_us;
+ pdata->target_count_rate_mcps = pdev->refspadchar.target_count_rate_mcps;
+ pdata->min_count_rate_limit_mcps =
+ pdev->refspadchar.min_count_rate_limit_mcps;
+ pdata->max_count_rate_limit_mcps =
+ pdev->refspadchar.max_count_rate_limit_mcps;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+VL53L1_Error VL53L1_set_range_ignore_threshold(
+ VL53L1_DEV Dev,
+ uint8_t range_ignore_thresh_mult,
+ uint16_t range_ignore_threshold_mcps)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_rate_mcps =
+ range_ignore_threshold_mcps;
+
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_mult =
+ range_ignore_thresh_mult;
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_range_ignore_threshold(
+ VL53L1_DEV Dev,
+ uint8_t *prange_ignore_thresh_mult,
+ uint16_t *prange_ignore_threshold_mcps_internal,
+ uint16_t *prange_ignore_threshold_mcps_current)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ *prange_ignore_thresh_mult =
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_mult;
+
+ *prange_ignore_threshold_mcps_current =
+ pdev->stat_cfg.algo__range_ignore_threshold_mcps;
+
+ *prange_ignore_threshold_mcps_internal =
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_rate_mcps;
+
+ return status;
+
+}
+
+
+
+VL53L1_Error VL53L1_get_interrupt_polarity(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceInterruptPolarity *pinterrupt_polarity)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ *pinterrupt_polarity = \
+ pdev->stat_cfg.gpio_hv_mux__ctrl & \
+ VL53L1_DEVICEINTERRUPTPOLARITY_BIT_MASK ;
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_set_user_zone(
+ VL53L1_DEV Dev,
+ VL53L1_user_zone_t *puser_zone)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ VL53L1_encode_row_col(
+ puser_zone->y_centre,
+ puser_zone->x_centre,
+ &(pdev->dyn_cfg.roi_config__user_roi_centre_spad));
+
+
+
+ VL53L1_encode_zone_size(
+ puser_zone->width,
+ puser_zone->height,
+ &(pdev->dyn_cfg.roi_config__user_roi_requested_global_xy_size));
+
+
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_user_zone(
+ VL53L1_DEV Dev,
+ VL53L1_user_zone_t *puser_zone)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ VL53L1_decode_row_col(
+ pdev->dyn_cfg.roi_config__user_roi_centre_spad,
+ &(puser_zone->y_centre),
+ &(puser_zone->x_centre));
+
+
+
+ VL53L1_decode_zone_size(
+ pdev->dyn_cfg.roi_config__user_roi_requested_global_xy_size,
+ &(puser_zone->width),
+ &(puser_zone->height));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+VL53L1_Error VL53L1_get_mode_mitigation_roi(
+ VL53L1_DEV Dev,
+ VL53L1_user_zone_t *pmm_roi)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t x = 0;
+ uint8_t y = 0;
+ uint8_t xy_size = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+ VL53L1_decode_row_col(
+ pdev->nvm_copy_data.roi_config__mode_roi_centre_spad,
+ &y,
+ &x);
+
+ pmm_roi->x_centre = x;
+ pmm_roi->y_centre = y;
+
+
+
+
+
+
+
+
+
+
+ xy_size = pdev->nvm_copy_data.roi_config__mode_roi_xy_size;
+
+ pmm_roi->height = xy_size >> 4;
+ pmm_roi->width = xy_size & 0x0F;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_zone_config(
+ VL53L1_DEV Dev,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(&(pdev->zone_cfg.user_zones), &(pzone_cfg->user_zones),
+ sizeof(pdev->zone_cfg.user_zones));
+
+
+
+ pdev->zone_cfg.max_zones = pzone_cfg->max_zones;
+ pdev->zone_cfg.active_zones = pzone_cfg->active_zones;
+
+ status = VL53L1_init_zone_config_histogram_bins(&pdev->zone_cfg);
+
+
+
+
+
+
+
+
+
+
+ if (pzone_cfg->active_zones == 0)
+ pdev->gen_cfg.global_config__stream_divider = 0;
+ else if (pzone_cfg->active_zones < VL53L1_MAX_USER_ZONES)
+ pdev->gen_cfg.global_config__stream_divider = pzone_cfg->active_zones + 1;
+ else
+ pdev->gen_cfg.global_config__stream_divider = VL53L1_MAX_USER_ZONES + 1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_get_zone_config(
+ VL53L1_DEV Dev,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(pzone_cfg, &(pdev->zone_cfg), sizeof(VL53L1_zone_config_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_preset_mode(
+ VL53L1_DEV Dev,
+ VL53L1_DevicePresetModes device_preset_mode,
+ uint16_t dss_config__target_total_rate_mcps,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint32_t inter_measurement_period_ms)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ VL53L1_hist_post_process_config_t *phistpostprocess =
+ &(pdev->histpostprocess);
+
+ VL53L1_static_config_t *pstatic = &(pdev->stat_cfg);
+ VL53L1_histogram_config_t *phistogram = &(pdev->hist_cfg);
+ VL53L1_general_config_t *pgeneral = &(pdev->gen_cfg);
+ VL53L1_timing_config_t *ptiming = &(pdev->tim_cfg);
+ VL53L1_dynamic_config_t *pdynamic = &(pdev->dyn_cfg);
+ VL53L1_system_control_t *psystem = &(pdev->sys_ctrl);
+ VL53L1_zone_config_t *pzone_cfg = &(pdev->zone_cfg);
+
+ LOG_FUNCTION_START("");
+
+
+
+ pdev->preset_mode = device_preset_mode;
+ pdev->mm_config_timeout_us = mm_config_timeout_us;
+ pdev->range_config_timeout_us = range_config_timeout_us;
+ pdev->inter_measurement_period_ms = inter_measurement_period_ms;
+
+
+
+
+ VL53L1_init_ll_driver_state(
+ Dev,
+ VL53L1_DEVICESTATE_SW_STANDBY);
+
+
+
+
+ switch (device_preset_mode) {
+
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING:
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_SHORT_RANGE:
+ status = VL53L1_preset_mode_standard_ranging_short_range(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_LONG_RANGE:
+ status = VL53L1_preset_mode_standard_ranging_long_range(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM1_CAL:
+ status = VL53L1_preset_mode_standard_ranging_mm1_cal(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM2_CAL:
+ status = VL53L1_preset_mode_standard_ranging_mm2_cal(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_TIMED_RANGING:
+ status = VL53L1_preset_mode_timed_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_TIMED_RANGING_SHORT_RANGE:
+ status = VL53L1_preset_mode_timed_ranging_short_range(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_TIMED_RANGING_LONG_RANGE:
+ status = VL53L1_preset_mode_timed_ranging_long_range(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING:
+ status = VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_WITH_MM1:
+ status = VL53L1_preset_mode_histogram_ranging_with_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_WITH_MM2:
+ status = VL53L1_preset_mode_histogram_ranging_with_mm2(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM1_CAL:
+ status = VL53L1_preset_mode_histogram_ranging_mm1_cal(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM2_CAL:
+ status = VL53L1_preset_mode_histogram_ranging_mm2_cal(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE:
+ status = VL53L1_preset_mode_histogram_multizone(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_SHORT_RANGE:
+ status = VL53L1_preset_mode_histogram_multizone_short_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_LONG_RANGE:
+ status = VL53L1_preset_mode_histogram_multizone_long_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_REF_ARRAY:
+ status = VL53L1_preset_mode_histogram_ranging_ref(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_SHORT_TIMING:
+ status = VL53L1_preset_mode_histogram_ranging_short_timing(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE:
+ status = VL53L1_preset_mode_histogram_long_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE_MM1:
+ status = VL53L1_preset_mode_histogram_long_range_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE_MM2:
+ status = VL53L1_preset_mode_histogram_long_range_mm2(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE:
+ status = VL53L1_preset_mode_histogram_medium_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE_MM1:
+ status = VL53L1_preset_mode_histogram_medium_range_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE_MM2:
+ status = VL53L1_preset_mode_histogram_medium_range_mm2(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE:
+ status = VL53L1_preset_mode_histogram_short_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE_MM1:
+ status = VL53L1_preset_mode_histogram_short_range_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE_MM2:
+ status = VL53L1_preset_mode_histogram_short_range_mm2(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_CHARACTERISATION:
+ status = VL53L1_preset_mode_histogram_characterisation(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_PLANAR:
+ status = VL53L1_preset_mode_histogram_xtalk_planar(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_MM1:
+ status = VL53L1_preset_mode_histogram_xtalk_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_MM2:
+ status = VL53L1_preset_mode_histogram_xtalk_mm2(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_OLT:
+ status = VL53L1_preset_mode_olt(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_SINGLESHOT_RANGING:
+ status = VL53L1_preset_mode_singleshot_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+ break;
+
+ default:
+ status = VL53L1_ERROR_INVALID_PARAMS;
+ break;
+
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ pstatic->dss_config__target_total_rate_mcps =
+ dss_config__target_total_rate_mcps;
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_timeouts_us(
+ Dev,
+ phasecal_config_timeout_us,
+ mm_config_timeout_us,
+ range_config_timeout_us);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_inter_measurement_period_ms(
+ Dev,
+ inter_measurement_period_ms);
+
+
+
+
+ V53L1_init_zone_results_structure(
+ pdev->zone_cfg.active_zones+1,
+ &(pres->zone_results));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_zone_preset(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceZonePreset zone_preset)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ VL53L1_general_config_t *pgeneral = &(pdev->gen_cfg);
+ VL53L1_zone_config_t *pzone_cfg = &(pdev->zone_cfg);
+
+ LOG_FUNCTION_START("");
+
+
+
+ pdev->zone_preset = zone_preset;
+
+
+
+
+ switch (zone_preset) {
+
+ case VL53L1_DEVICEZONEPRESET_XTALK_PLANAR:
+ status =
+ VL53L1_zone_preset_xtalk_planar(
+ pgeneral,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_1X1_SIZE_16X16:
+ status =
+ VL53L1_init_zone_config_structure(
+ 8, 1, 1,
+
+ 8, 1, 1,
+
+ 15, 15,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_1X2_SIZE_16X8:
+ status =
+ VL53L1_init_zone_config_structure(
+ 8, 1, 1,
+
+ 4, 8, 2,
+
+ 15, 7,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_2X1_SIZE_8X16:
+ status =
+ VL53L1_init_zone_config_structure(
+ 4, 8, 2,
+
+ 8, 1, 1,
+
+ 7, 15,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_2X2_SIZE_8X8:
+ status =
+ VL53L1_init_zone_config_structure(
+ 4, 8, 2,
+
+ 4, 8, 2,
+
+ 7, 7,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_3X3_SIZE_5X5:
+ status =
+ VL53L1_init_zone_config_structure(
+ 2, 5, 3,
+
+ 2, 5, 3,
+
+ 4, 4,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_4X4_SIZE_4X4:
+ status =
+ VL53L1_init_zone_config_structure(
+ 2, 4, 4,
+
+ 2, 4, 4,
+
+ 3, 3,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_5X5_SIZE_4X4:
+ status =
+ VL53L1_init_zone_config_structure(
+ 2, 3, 5,
+
+ 2, 3, 5,
+
+ 3, 3,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_11X11_SIZE_5X5:
+ status =
+ VL53L1_init_zone_config_structure(
+ 3, 1, 11,
+
+ 3, 1, 11,
+
+ 4, 4,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_13X13_SIZE_4X4:
+ status =
+ VL53L1_init_zone_config_structure(
+ 2, 1, 13,
+
+ 2, 1, 13,
+
+ 3, 3,
+
+ pzone_cfg);
+
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_1X1_SIZE_4X4_POS_8X8:
+ status =
+ VL53L1_init_zone_config_structure(
+ 8, 1, 1,
+
+ 8, 1, 1,
+
+ 3, 3,
+
+ pzone_cfg);
+ break;
+
+ }
+
+
+
+
+
+
+
+
+
+
+ if (pzone_cfg->active_zones == 0)
+ pdev->gen_cfg.global_config__stream_divider = 0;
+ else if (pzone_cfg->active_zones < VL53L1_MAX_USER_ZONES)
+ pdev->gen_cfg.global_config__stream_divider = pzone_cfg->active_zones + 1;
+ else
+ pdev->gen_cfg.global_config__stream_divider = VL53L1_MAX_USER_ZONES + 1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_enable_xtalk_compensation(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ pdev->customer.algo__crosstalk_compensation_plane_offset_kcps =
+ VL53L1_calc_crosstalk_plane_offset_with_margin(
+ pdev->xtalk_cfg.algo__crosstalk_compensation_plane_offset_kcps,
+ pdev->xtalk_cfg.lite_mode_crosstalk_margin_kcps);
+
+ pdev->customer.algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+ pdev->customer.algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+ pdev->histpostprocess.algo__crosstalk_compensation_plane_offset_kcps =
+ VL53L1_calc_crosstalk_plane_offset_with_margin(
+ pdev->xtalk_cfg.algo__crosstalk_compensation_plane_offset_kcps,
+ pdev->xtalk_cfg.histogram_mode_crosstalk_margin_kcps);
+
+ pdev->histpostprocess.algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pdev->histpostprocess.algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+
+ pdev->xtalk_cfg.global_crosstalk_compensation_enable = 0x01;
+
+ pdev->histpostprocess.algo__crosstalk_compensation_enable =
+ pdev->xtalk_cfg.global_crosstalk_compensation_enable;
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_rate_mcps =
+ VL53L1_calc_range_ignore_threshold(
+ pdev->xtalk_cfg.algo__crosstalk_compensation_plane_offset_kcps,
+ pdev->xtalk_cfg.algo__crosstalk_compensation_x_plane_gradient_kcps,
+ pdev->xtalk_cfg.algo__crosstalk_compensation_y_plane_gradient_kcps,
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_mult);
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_set_customer_nvm_managed(
+ Dev,
+ &(pdev->customer));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+void VL53L1_get_xtalk_compensation_enable(
+ VL53L1_DEV Dev,
+ uint8_t *pcrosstalk_compensation_enable)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ *pcrosstalk_compensation_enable =
+ pdev->xtalk_cfg.global_crosstalk_compensation_enable;
+
+}
+
+
+VL53L1_Error VL53L1_get_lite_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t *pxtalk_margin)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pxtalk_margin = pdev->xtalk_cfg.lite_mode_crosstalk_margin_kcps;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_lite_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t xtalk_margin)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->xtalk_cfg.lite_mode_crosstalk_margin_kcps = xtalk_margin;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_histogram_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t *pxtalk_margin)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pxtalk_margin = pdev->xtalk_cfg.histogram_mode_crosstalk_margin_kcps;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_histogram_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t xtalk_margin)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->xtalk_cfg.histogram_mode_crosstalk_margin_kcps = xtalk_margin;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_restore_xtalk_nvm_default(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->xtalk_cfg.algo__crosstalk_compensation_plane_offset_kcps =
+ pdev->xtalk_cfg.nvm_default__crosstalk_compensation_plane_offset_kcps;
+ pdev->xtalk_cfg.algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pdev->xtalk_cfg.nvm_default__crosstalk_compensation_x_plane_gradient_kcps;
+ pdev->xtalk_cfg.algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pdev->xtalk_cfg.nvm_default__crosstalk_compensation_y_plane_gradient_kcps;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_disable_xtalk_compensation(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ pdev->customer.algo__crosstalk_compensation_plane_offset_kcps =
+ 0x00;
+
+ pdev->customer.algo__crosstalk_compensation_x_plane_gradient_kcps =
+ 0x00;
+
+ pdev->customer.algo__crosstalk_compensation_y_plane_gradient_kcps =
+ 0x00;
+
+
+
+
+ pdev->xtalk_cfg.global_crosstalk_compensation_enable = 0x00;
+
+ pdev->histpostprocess.algo__crosstalk_compensation_enable =
+ pdev->xtalk_cfg.global_crosstalk_compensation_enable;
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_rate_mcps =
+ 0x0000;
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status =
+ VL53L1_set_customer_nvm_managed(
+ Dev,
+ &(pdev->customer));
+ }
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_get_histogram_phase_consistency(
+ VL53L1_DEV Dev,
+ uint8_t *pphase_consistency)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pphase_consistency =
+ pdev->histpostprocess.algo__consistency_check__phase_tolerance;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_histogram_phase_consistency(
+ VL53L1_DEV Dev,
+ uint8_t phase_consistency)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->histpostprocess.algo__consistency_check__phase_tolerance =
+ phase_consistency;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_histogram_event_consistency(
+ VL53L1_DEV Dev,
+ uint8_t *pevent_consistency)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pevent_consistency =
+ pdev->histpostprocess.algo__consistency_check__event_sigma;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_histogram_event_consistency(
+ VL53L1_DEV Dev,
+ uint8_t event_consistency)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->histpostprocess.algo__consistency_check__event_sigma =
+ event_consistency;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_histogram_ambient_threshold_sigma(
+ VL53L1_DEV Dev,
+ uint8_t *pamb_thresh_sigma)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pamb_thresh_sigma =
+ pdev->histpostprocess.ambient_thresh_sigma1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_histogram_ambient_threshold_sigma(
+ VL53L1_DEV Dev,
+ uint8_t amb_thresh_sigma)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->histpostprocess.ambient_thresh_sigma1 =
+ amb_thresh_sigma;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_lite_sigma_threshold(
+ VL53L1_DEV Dev,
+ uint16_t *plite_sigma)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *plite_sigma =
+ pdev->tim_cfg.range_config__sigma_thresh;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_lite_sigma_threshold(
+ VL53L1_DEV Dev,
+ uint16_t lite_sigma)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->tim_cfg.range_config__sigma_thresh = lite_sigma;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_lite_min_count_rate(
+ VL53L1_DEV Dev,
+ uint16_t *plite_mincountrate)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *plite_mincountrate =
+ pdev->tim_cfg.range_config__min_count_rate_rtn_limit_mcps;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_lite_min_count_rate(
+ VL53L1_DEV Dev,
+ uint16_t lite_mincountrate)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->tim_cfg.range_config__min_count_rate_rtn_limit_mcps =
+ lite_mincountrate;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_xtalk_detect_config(
+ VL53L1_DEV Dev,
+ int16_t *pmax_valid_range_mm,
+ int16_t *pmin_valid_range_mm,
+ uint16_t *pmax_valid_rate_kcps,
+ uint16_t *pmax_sigma_mm)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pmax_valid_range_mm =
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_range_mm;
+ *pmin_valid_range_mm =
+ pdev->xtalk_cfg.algo__crosstalk_detect_min_valid_range_mm;
+ *pmax_valid_rate_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_rate_kcps;
+ *pmax_sigma_mm =
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_sigma_mm;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_xtalk_detect_config(
+ VL53L1_DEV Dev,
+ int16_t max_valid_range_mm,
+ int16_t min_valid_range_mm,
+ uint16_t max_valid_rate_kcps,
+ uint16_t max_sigma_mm)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_range_mm =
+ max_valid_range_mm;
+ pdev->xtalk_cfg.algo__crosstalk_detect_min_valid_range_mm =
+ min_valid_range_mm;
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_rate_kcps =
+ max_valid_rate_kcps;
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_sigma_mm =
+ max_sigma_mm;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_target_order_mode(
+ VL53L1_DEV Dev,
+ VL53L1_HistTargetOrder *phist_target_order)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *phist_target_order =
+ pdev->histpostprocess.hist_target_order;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_target_order_mode(
+ VL53L1_DEV Dev,
+ VL53L1_HistTargetOrder hist_target_order)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->histpostprocess.hist_target_order = hist_target_order;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_get_dmax_reflectance_values(
+ VL53L1_DEV Dev,
+ VL53L1_dmax_reflectance_array_t *pdmax_reflectances)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t i = 0;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+ for (i = 0 ; i < VL53L1_MAX_AMBIENT_DMAX_VALUES ; i++) {
+ pdmax_reflectances->target_reflectance_for_dmax[i] =
+ pdev->dmax_cfg.target_reflectance_for_dmax_calc[i];
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_dmax_reflectance_values(
+ VL53L1_DEV Dev,
+ VL53L1_dmax_reflectance_array_t *pdmax_reflectances)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t i = 0;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+ for (i = 0 ; i < VL53L1_MAX_AMBIENT_DMAX_VALUES ; i++) {
+ pdev->dmax_cfg.target_reflectance_for_dmax_calc[i] =
+ pdmax_reflectances->target_reflectance_for_dmax[i];
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_vhv_loopbound(
+ VL53L1_DEV Dev,
+ uint8_t *pvhv_loopbound)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pvhv_loopbound = pdev->stat_nvm.vhv_config__timeout_macrop_loop_bound / 4 ;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+
+VL53L1_Error VL53L1_set_vhv_loopbound(
+ VL53L1_DEV Dev,
+ uint8_t vhv_loopbound)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->stat_nvm.vhv_config__timeout_macrop_loop_bound =
+ (pdev->stat_nvm.vhv_config__timeout_macrop_loop_bound & 0x03) +
+ (vhv_loopbound * 4);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+
+VL53L1_Error VL53L1_init_and_start_range(
+ VL53L1_DEV Dev,
+ uint8_t measurement_mode,
+ VL53L1_DeviceConfigLevel device_config_level)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ uint8_t buffer[VL53L1_MAX_I2C_XFER_SIZE];
+
+ VL53L1_static_nvm_managed_t *pstatic_nvm = &(pdev->stat_nvm);
+ VL53L1_customer_nvm_managed_t *pcustomer_nvm = &(pdev->customer);
+ VL53L1_static_config_t *pstatic = &(pdev->stat_cfg);
+ VL53L1_general_config_t *pgeneral = &(pdev->gen_cfg);
+ VL53L1_timing_config_t *ptiming = &(pdev->tim_cfg);
+ VL53L1_dynamic_config_t *pdynamic = &(pdev->dyn_cfg);
+ VL53L1_system_control_t *psystem = &(pdev->sys_ctrl);
+
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+
+ uint8_t *pbuffer = &buffer[0];
+ uint16_t i = 0;
+ uint16_t i2c_index = 0;
+ uint16_t i2c_buffer_offset_bytes = 0;
+ uint16_t i2c_buffer_size_bytes = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+ pdev->measurement_mode = measurement_mode;
+
+
+
+
+ psystem->system__mode_start =
+ (psystem->system__mode_start &
+ VL53L1_DEVICEMEASUREMENTMODE_STOP_MASK) |
+ measurement_mode;
+
+
+
+
+
+
+ status =
+ VL53L1_set_user_zone(
+ Dev,
+ &(pdev->zone_cfg.user_zones[pdev->ll_state.cfg_zone_id]));
+
+
+
+
+
+ if (pdev->zone_cfg.active_zones > 0) {
+ status =
+ VL53L1_set_zone_dss_config(
+ Dev,
+ &(pres->zone_dyn_cfgs.VL53L1_PRM_00005[pdev->ll_state.cfg_zone_id]));
+ }
+
+
+
+
+
+
+ if (((pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM) == 0x00) &&
+ (pdev->xtalk_cfg.global_crosstalk_compensation_enable == 0x01)) {
+ pdev->stat_cfg.algo__range_ignore_threshold_mcps =
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_rate_mcps;
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_save_cfg_data(Dev);
+ }
+
+
+
+
+
+
+ switch (device_config_level) {
+ case VL53L1_DEVICECONFIGLEVEL_FULL:
+ i2c_index = VL53L1_STATIC_NVM_MANAGED_I2C_INDEX;
+ break;
+ case VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS:
+ i2c_index = VL53L1_CUSTOMER_NVM_MANAGED_I2C_INDEX;
+ break;
+ case VL53L1_DEVICECONFIGLEVEL_STATIC_ONWARDS:
+ i2c_index = VL53L1_STATIC_CONFIG_I2C_INDEX;
+ break;
+ case VL53L1_DEVICECONFIGLEVEL_GENERAL_ONWARDS:
+ i2c_index = VL53L1_GENERAL_CONFIG_I2C_INDEX;
+ break;
+ case VL53L1_DEVICECONFIGLEVEL_TIMING_ONWARDS:
+ i2c_index = VL53L1_TIMING_CONFIG_I2C_INDEX;
+ break;
+ case VL53L1_DEVICECONFIGLEVEL_DYNAMIC_ONWARDS:
+ i2c_index = VL53L1_DYNAMIC_CONFIG_I2C_INDEX;
+ break;
+ default:
+ i2c_index = VL53L1_SYSTEM_CONTROL_I2C_INDEX;
+ break;
+ }
+
+
+
+
+ i2c_buffer_size_bytes = \
+ (VL53L1_SYSTEM_CONTROL_I2C_INDEX +
+ VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES) -
+ i2c_index;
+
+
+
+
+ pbuffer = &buffer[0];
+ for (i = 0 ; i < i2c_buffer_size_bytes ; i++) {
+ *pbuffer++ = 0;
+ }
+
+
+
+
+ if (device_config_level >= VL53L1_DEVICECONFIGLEVEL_FULL &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes = \
+ VL53L1_STATIC_NVM_MANAGED_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_encode_static_nvm_managed(
+ pstatic_nvm,
+ VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes]);
+ }
+
+ if (device_config_level >= VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes = \
+ VL53L1_CUSTOMER_NVM_MANAGED_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_encode_customer_nvm_managed(
+ pcustomer_nvm,
+ VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes]);
+ }
+
+ if (device_config_level >= VL53L1_DEVICECONFIGLEVEL_STATIC_ONWARDS &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes = \
+ VL53L1_STATIC_CONFIG_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_encode_static_config(
+ pstatic,
+ VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes]);
+ }
+
+ if (device_config_level >= VL53L1_DEVICECONFIGLEVEL_GENERAL_ONWARDS &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes =
+ VL53L1_GENERAL_CONFIG_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_encode_general_config(
+ pgeneral,
+ VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes]);
+ }
+
+ if (device_config_level >= VL53L1_DEVICECONFIGLEVEL_TIMING_ONWARDS &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes = \
+ VL53L1_TIMING_CONFIG_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_encode_timing_config(
+ ptiming,
+ VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes]);
+ }
+
+ if (device_config_level >= VL53L1_DEVICECONFIGLEVEL_DYNAMIC_ONWARDS &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes = \
+ VL53L1_DYNAMIC_CONFIG_I2C_INDEX - i2c_index;
+
+
+
+ if ((psystem->system__mode_start &
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK) ==
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK) {
+ pdynamic->system__grouped_parameter_hold_0 = pstate->cfg_gph_id | 0x01;
+ pdynamic->system__grouped_parameter_hold_1 = pstate->cfg_gph_id | 0x01;
+ pdynamic->system__grouped_parameter_hold = pstate->cfg_gph_id;
+ }
+ status =
+ VL53L1_i2c_encode_dynamic_config(
+ pdynamic,
+ VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes]);
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes = \
+ VL53L1_SYSTEM_CONTROL_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_encode_system_control(
+ psystem,
+ VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes]);
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status =
+ VL53L1_WriteMulti(
+ Dev,
+ i2c_index,
+ buffer,
+ (uint32_t)i2c_buffer_size_bytes);
+ }
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_update_ll_driver_rd_state(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_update_ll_driver_cfg_state(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_stop_range(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+
+
+
+ pdev->sys_ctrl.system__mode_start =
+ (pdev->sys_ctrl.system__mode_start & VL53L1_DEVICEMEASUREMENTMODE_STOP_MASK) |
+ VL53L1_DEVICEMEASUREMENTMODE_ABORT;
+
+ status = VL53L1_set_system_control(
+ Dev,
+ &pdev->sys_ctrl);
+
+
+
+ pdev->sys_ctrl.system__mode_start =
+ (pdev->sys_ctrl.system__mode_start & VL53L1_DEVICEMEASUREMENTMODE_STOP_MASK);
+
+
+
+ VL53L1_init_ll_driver_state(
+ Dev,
+ VL53L1_DEVICESTATE_SW_STANDBY);
+
+
+
+ V53L1_init_zone_results_structure(
+ pdev->zone_cfg.active_zones+1,
+ &(pres->zone_results));
+
+ return status;
+}
+
+VL53L1_Error VL53L1_get_measurement_results(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceResultsLevel device_results_level)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t buffer[VL53L1_MAX_I2C_XFER_SIZE];
+
+ VL53L1_system_results_t *psystem_results = &(pdev->sys_results);
+ VL53L1_core_results_t *pcore_results = &(pdev->core_results);
+ VL53L1_debug_results_t *pdebug_results = &(pdev->dbg_results);
+
+ uint16_t i2c_index = VL53L1_SYSTEM_RESULTS_I2C_INDEX;
+ uint16_t i2c_buffer_offset_bytes = 0;
+ uint16_t i2c_buffer_size_bytes = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ switch (device_results_level) {
+ case VL53L1_DEVICERESULTSLEVEL_FULL:
+ i2c_buffer_size_bytes =
+ (VL53L1_DEBUG_RESULTS_I2C_INDEX +
+ VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES) -
+ i2c_index;
+ break;
+ case VL53L1_DEVICERESULTSLEVEL_UPTO_CORE:
+ i2c_buffer_size_bytes =
+ (VL53L1_CORE_RESULTS_I2C_INDEX +
+ VL53L1_CORE_RESULTS_I2C_SIZE_BYTES) -
+ i2c_index;
+ break;
+ default:
+ i2c_buffer_size_bytes =
+ VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES;
+ break;
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_ReadMulti(
+ Dev,
+ i2c_index,
+ buffer,
+ (uint32_t)i2c_buffer_size_bytes);
+
+
+
+
+ if (device_results_level >= VL53L1_DEVICERESULTSLEVEL_FULL &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes =
+ VL53L1_DEBUG_RESULTS_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_decode_debug_results(
+ VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes],
+ pdebug_results);
+ }
+
+ if (device_results_level >= VL53L1_DEVICERESULTSLEVEL_UPTO_CORE &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes =
+ VL53L1_CORE_RESULTS_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_decode_core_results(
+ VL53L1_CORE_RESULTS_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes],
+ pcore_results);
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes = 0;
+ status =
+ VL53L1_i2c_decode_system_results(
+ VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes],
+ psystem_results);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_device_results(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceResultsLevel device_results_level,
+ VL53L1_range_results_t *prange_results)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ VL53L1_range_results_t *presults = &(pres->range_results);
+ VL53L1_zone_objects_t *pobjects = &(pres->zone_results.VL53L1_PRM_00005[0]);
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+ VL53L1_zone_config_t *pzone_cfg = &(pdev->zone_cfg);
+ VL53L1_zone_hist_info_t *phist_info = &(pres->zone_hists.VL53L1_PRM_00005[0]);
+
+ VL53L1_dmax_calibration_data_t dmax_cal;
+ VL53L1_dmax_calibration_data_t *pdmax_cal = &dmax_cal;
+
+ uint8_t i;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ if ((pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM)
+ == VL53L1_DEVICESCHEDULERMODE_HISTOGRAM) {
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_get_histogram_bin_data(
+ Dev,
+ &(pdev->hist_data));
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE &&
+ pdev->hist_data.number_of_ambient_bins == 0)
+ status = VL53L1_hist_copy_and_scale_ambient_info(
+ &(pres->zone_hists.VL53L1_PRM_00005[pdev->ll_state.rd_zone_id]),
+ &(pdev->hist_data));
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pdev->histpostprocess.gain_factor =
+ pdev->gain_cal.histogram_ranging_gain_factor;
+
+ pdev->histpostprocess.algo__crosstalk_compensation_plane_offset_kcps =
+ VL53L1_calc_crosstalk_plane_offset_with_margin(
+ pdev->xtalk_cfg.algo__crosstalk_compensation_plane_offset_kcps,
+ pdev->xtalk_cfg.histogram_mode_crosstalk_margin_kcps);
+
+ pdev->histpostprocess.algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pdev->histpostprocess.algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+ pdev->dmax_cfg.ambient_thresh_sigma =
+ pdev->histpostprocess.ambient_thresh_sigma1;
+ pdev->dmax_cfg.min_ambient_thresh_events =
+ pdev->histpostprocess.min_ambient_thresh_events;
+ pdev->dmax_cfg.dss_config__target_total_rate_mcps =
+ pdev->stat_cfg.dss_config__target_total_rate_mcps;
+ pdev->dmax_cfg.dss_config__aperture_attenuation =
+ pdev->gen_cfg.dss_config__aperture_attenuation;
+
+ pdev->histpostprocess.algo__crosstalk_detect_max_valid_range_mm =
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_range_mm;
+ pdev->histpostprocess.algo__crosstalk_detect_min_valid_range_mm =
+ pdev->xtalk_cfg.algo__crosstalk_detect_min_valid_range_mm;
+ pdev->histpostprocess.algo__crosstalk_detect_max_valid_rate_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_rate_kcps;
+ pdev->histpostprocess.algo__crosstalk_detect_max_sigma_mm =
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_sigma_mm;
+
+
+
+
+ VL53L1_copy_rtn_good_spads_to_buffer(
+ &(pdev->nvm_copy_data),
+ &(pdev->rtn_good_spads[0]));
+
+
+
+
+ switch (pdev->offset_correction_mode) {
+
+ case VL53L1_OFFSETCORRECTIONMODE__MM1_MM2_OFFSETS:
+
+ VL53L1_hist_combine_mm1_mm2_offsets(
+ pdev->customer.mm_config__inner_offset_mm,
+ pdev->customer.mm_config__outer_offset_mm,
+ pdev->nvm_copy_data.roi_config__mode_roi_centre_spad,
+ pdev->nvm_copy_data.roi_config__mode_roi_xy_size,
+ pdev->hist_data.roi_config__user_roi_centre_spad,
+ pdev->hist_data.roi_config__user_roi_requested_global_xy_size,
+ &(pdev->add_off_cal_data),
+ &(pdev->rtn_good_spads[0]),
+ (uint16_t)pdev->gen_cfg.dss_config__aperture_attenuation,
+ &(pdev->histpostprocess.range_offset_mm));
+
+ break;
+
+ case VL53L1_OFFSETCORRECTIONMODE__PER_ZONE_OFFSETS:
+ pdev->histpostprocess.range_offset_mm =
+ (int16_t)pres->zone_cal.VL53L1_PRM_00005[pdev->ll_state.rd_zone_id].range_mm_offset;
+ break;
+
+ default:
+ pdev->histpostprocess.range_offset_mm = 0;
+ break;
+
+ }
+ }
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_get_dmax_calibration_data(
+ Dev,
+ pdev->dmax_mode,
+ pdev->ll_state.rd_zone_id,
+ pdmax_cal);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_ipp_hist_process_data(
+ Dev,
+ pdmax_cal,
+ &(pdev->dmax_cfg),
+ &(pdev->histpostprocess),
+ &(pdev->hist_data),
+ &(pdev->xtalk_shapes),
+ presults);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_hist_wrap_dmax(
+ &(pdev->histpostprocess),
+ &(pdev->hist_data),
+ &(presults->wrap_dmax_mm));
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_hist_phase_consistency_check(
+ Dev,
+ &(pres->zone_hists.VL53L1_PRM_00005[pdev->ll_state.rd_zone_id]),
+ &(pdev->hist_data),
+ &(pres->zone_results.VL53L1_PRM_00005[pdev->ll_state.rd_zone_id]),
+ presults);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pres->zone_hists.max_zones = VL53L1_MAX_USER_ZONES;
+ pres->zone_hists.active_zones = pdev->zone_cfg.active_zones+1;
+ pdev->hist_data.zone_id = pdev->ll_state.rd_zone_id;
+
+ if (pdev->ll_state.rd_zone_id < pres->zone_results.max_zones) {
+
+ phist_info =
+ &(pres->zone_hists.VL53L1_PRM_00005[pdev->ll_state.rd_zone_id]);
+
+ phist_info->rd_device_state =
+ pdev->hist_data.rd_device_state;
+
+ phist_info->number_of_ambient_bins =
+ pdev->hist_data.number_of_ambient_bins;
+
+ phist_info->result__dss_actual_effective_spads =
+ pdev->hist_data.result__dss_actual_effective_spads;
+
+ phist_info->VL53L1_PRM_00007 =
+ pdev->hist_data.VL53L1_PRM_00007;
+
+ phist_info->total_periods_elapsed =
+ pdev->hist_data.total_periods_elapsed;
+
+ phist_info->ambient_events_sum =
+ pdev->hist_data.ambient_events_sum;
+ }
+
+ }
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_hist_copy_results_to_sys_and_core(
+ &(pdev->hist_data),
+ presults,
+ &(pdev->sys_results),
+ &(pdev->core_results));
+
+
+
+
+
+
+
+ if (pzone_cfg->active_zones > 0) {
+ if (pstate->rd_device_state !=
+ VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC) {
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_dynamic_zone_update(
+ Dev, presults);
+ }
+ }
+
+
+
+
+
+ for (i = 0; i < VL53L1_MAX_USER_ZONES; i++) {
+ pzone_cfg->bin_config[i] =
+ ((pdev->ll_state.cfg_internal_stream_count) & 0x01) ?
+ VL53L1_ZONECONFIG_BINCONFIG__HIGHAMB :
+ VL53L1_ZONECONFIG_BINCONFIG__LOWAMB;
+ }
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_multizone_hist_bins_update(Dev);
+
+ }
+
+#ifdef VL53L1_LOG_ENABLE
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_print_histogram_bin_data(
+ &(pdev->hist_data),
+ "get_device_results():pdev->lldata.hist_data.",
+ VL53L1_TRACE_MODULE_HISTOGRAM_DATA);
+#endif
+
+ } else {
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_get_measurement_results(
+ Dev,
+ device_results_level);
+
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_copy_sys_and_core_results_to_range_results(
+ (int32_t)pdev->gain_cal.standard_ranging_gain_factor,
+ &(pdev->sys_results),
+ &(pdev->core_results),
+ presults);
+ }
+
+
+
+ presults->cfg_device_state = pdev->ll_state.cfg_device_state;
+ presults->rd_device_state = pdev->ll_state.rd_device_state;
+ presults->zone_id = pdev->ll_state.rd_zone_id;
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+ pres->zone_results.max_zones = VL53L1_MAX_USER_ZONES;
+ pres->zone_results.active_zones = pdev->zone_cfg.active_zones+1;
+
+ if (pdev->ll_state.rd_zone_id < pres->zone_results.max_zones) {
+
+ pobjects =
+ &(pres->zone_results.VL53L1_PRM_00005[pdev->ll_state.rd_zone_id]);
+
+ pobjects->cfg_device_state = presults->cfg_device_state;
+ pobjects->rd_device_state = presults->rd_device_state;
+ pobjects->zone_id = presults->zone_id;
+ pobjects->stream_count = presults->stream_count;
+
+ pobjects->max_objects = presults->max_results;
+ pobjects->active_objects = presults->active_results;
+
+ for (i = 0; i < presults->active_results; i++) {
+ pobjects->VL53L1_PRM_00005[i].VL53L1_PRM_00023 =
+ presults->VL53L1_PRM_00005[i].VL53L1_PRM_00023;
+ pobjects->VL53L1_PRM_00005[i].VL53L1_PRM_00022 =
+ presults->VL53L1_PRM_00005[i].VL53L1_PRM_00022;
+ pobjects->VL53L1_PRM_00005[i].VL53L1_PRM_00014 =
+ presults->VL53L1_PRM_00005[i].VL53L1_PRM_00014;
+ }
+ }
+ }
+
+
+
+
+ memcpy(
+ prange_results,
+ presults,
+ sizeof(VL53L1_range_results_t));
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_check_ll_driver_rd_state(Dev);
+
+#ifdef VL53L1_LOG_ENABLE
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_print_range_results(
+ presults,
+ "get_device_results():pdev->llresults.range_results.",
+ VL53L1_TRACE_MODULE_RANGE_RESULTS_DATA);
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_clear_interrupt_and_enable_next_range(
+ VL53L1_DEV Dev,
+ uint8_t measurement_mode)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_init_and_start_range(
+ Dev,
+ measurement_mode,
+ VL53L1_DEVICECONFIGLEVEL_GENERAL_ONWARDS);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_histogram_bin_data(
+ VL53L1_DEV Dev,
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ VL53L1_zone_private_dyn_cfg_t *pzone_dyn_cfg;
+
+ VL53L1_static_nvm_managed_t *pstat_nvm = &(pdev->stat_nvm);
+ VL53L1_static_config_t *pstat_cfg = &(pdev->stat_cfg);
+ VL53L1_general_config_t *pgen_cfg = &(pdev->gen_cfg);
+ VL53L1_timing_config_t *ptim_cfg = &(pdev->tim_cfg);
+
+ uint8_t buffer[VL53L1_MAX_I2C_XFER_SIZE];
+ uint8_t *pbuffer = &buffer[0];
+ uint8_t bin_23_0 = 0x00;
+ uint16_t bin = 0;
+ uint16_t i2c_buffer_offset_bytes = 0;
+ uint16_t encoded_timeout = 0;
+
+ uint32_t pll_period_us = 0;
+ uint32_t periods_elapsed_tmp = 0;
+
+ uint8_t i = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX,
+ pbuffer,
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_SIZE_BYTES);
+
+
+
+
+
+
+ pdata->result__interrupt_status = *(pbuffer + 0);
+ pdata->result__range_status = *(pbuffer + 1);
+ pdata->result__report_status = *(pbuffer + 2);
+ pdata->result__stream_count = *(pbuffer + 3);
+ pdata->result__dss_actual_effective_spads =
+ VL53L1_i2c_decode_uint16_t(2, pbuffer + 4);
+
+
+
+
+
+
+ i2c_buffer_offset_bytes = \
+ VL53L1_PHASECAL_RESULT__REFERENCE_PHASE - \
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX;
+
+ pbuffer = &buffer[i2c_buffer_offset_bytes];
+
+ pdata->phasecal_result__reference_phase =
+ VL53L1_i2c_decode_uint16_t(2, pbuffer);
+
+ i2c_buffer_offset_bytes = \
+ VL53L1_PHASECAL_RESULT__VCSEL_START - \
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX;
+
+ pdata->phasecal_result__vcsel_start = buffer[i2c_buffer_offset_bytes];
+
+
+
+
+ pdev->dbg_results.phasecal_result__reference_phase =
+ pdata->phasecal_result__reference_phase;
+ pdev->dbg_results.phasecal_result__vcsel_start =
+ pdata->phasecal_result__vcsel_start;
+
+
+
+
+
+
+
+ i2c_buffer_offset_bytes = \
+ VL53L1_RESULT__HISTOGRAM_BIN_23_0_MSB - \
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX;
+
+ bin_23_0 = buffer[i2c_buffer_offset_bytes] << 2;
+
+ i2c_buffer_offset_bytes = \
+ VL53L1_RESULT__HISTOGRAM_BIN_23_0_LSB - \
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX;
+
+ bin_23_0 += buffer[i2c_buffer_offset_bytes];
+
+ i2c_buffer_offset_bytes = \
+ VL53L1_RESULT__HISTOGRAM_BIN_23_0 - \
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX;
+
+ buffer[i2c_buffer_offset_bytes] = bin_23_0;
+
+
+
+
+
+
+
+ i2c_buffer_offset_bytes = \
+ VL53L1_RESULT__HISTOGRAM_BIN_0_2 - \
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX;
+
+ pbuffer = &buffer[i2c_buffer_offset_bytes];
+ for (bin = 0 ; bin < VL53L1_HISTOGRAM_BUFFER_SIZE ; bin++) {
+ pdata->bin_data[bin] =
+ (int32_t)VL53L1_i2c_decode_uint32_t(3, pbuffer);
+ pbuffer += 3;
+ }
+
+
+
+ pdata->zone_id = pdev->ll_state.rd_zone_id;
+ pdata->VL53L1_PRM_00015 = 0;
+ pdata->VL53L1_PRM_00016 = VL53L1_HISTOGRAM_BUFFER_SIZE;
+ pdata->VL53L1_PRM_00017 = VL53L1_HISTOGRAM_BUFFER_SIZE;
+
+ pdata->cal_config__vcsel_start = pgen_cfg->cal_config__vcsel_start;
+
+
+
+
+ pdata->vcsel_width =
+ ((uint16_t)pgen_cfg->global_config__vcsel_width) << 4;
+ pdata->vcsel_width +=
+ (uint16_t)pstat_cfg->ana_config__vcsel_pulse_width_offset;
+
+
+
+ pdata->VL53L1_PRM_00018 =
+ pstat_nvm->osc_measured__fast_osc__frequency;
+
+
+
+
+ VL53L1_hist_get_bin_sequence_config(Dev, pdata);
+
+
+
+
+
+
+ if (pdev->ll_state.rd_timing_status == 0) {
+
+ encoded_timeout = \
+ (ptim_cfg->range_config__timeout_macrop_a_hi << 8) \
+ + ptim_cfg->range_config__timeout_macrop_a_lo;
+ pdata->VL53L1_PRM_00007 = ptim_cfg->range_config__vcsel_period_a;
+ } else {
+
+ encoded_timeout = \
+ (ptim_cfg->range_config__timeout_macrop_b_hi << 8) \
+ + ptim_cfg->range_config__timeout_macrop_b_lo;
+ pdata->VL53L1_PRM_00007 = ptim_cfg->range_config__vcsel_period_b;
+ }
+
+
+
+
+ pdata->number_of_ambient_bins = 0;
+
+ for (i = 0; i < 6; i++) {
+ if ((pdata->bin_seq[i] & 0x07) == 0x07) {
+ pdata->number_of_ambient_bins =
+ pdata->number_of_ambient_bins + 0x04;
+ }
+ }
+
+ pdata->total_periods_elapsed =
+ VL53L1_decode_timeout(encoded_timeout);
+
+
+
+
+
+
+
+ pll_period_us =
+ VL53L1_calc_pll_period_us(pdata->VL53L1_PRM_00018);
+
+
+
+
+ periods_elapsed_tmp = pdata->total_periods_elapsed + 1;
+
+
+
+
+
+
+ pdata->peak_duration_us =
+ VL53L1_duration_maths(
+ pll_period_us,
+ (uint32_t)pdata->vcsel_width,
+ VL53L1_RANGING_WINDOW_VCSEL_PERIODS,
+ periods_elapsed_tmp);
+
+ pdata->woi_duration_us = 0;
+
+
+
+
+ VL53L1_hist_calc_zero_distance_phase(pdata);
+
+
+
+
+
+
+ VL53L1_hist_estimate_ambient_from_ambient_bins(pdata);
+
+
+
+
+ pdata->cfg_device_state = pdev->ll_state.cfg_device_state;
+ pdata->rd_device_state = pdev->ll_state.rd_device_state;
+
+
+
+
+ pzone_dyn_cfg = &(pres->zone_dyn_cfgs.VL53L1_PRM_00005[pdata->zone_id]);
+
+ pdata->roi_config__user_roi_centre_spad =
+ pzone_dyn_cfg->roi_config__user_roi_centre_spad;
+ pdata->roi_config__user_roi_requested_global_xy_size =
+ pzone_dyn_cfg->roi_config__user_roi_requested_global_xy_size;
+
+
+
+
+ switch (pdata->result__range_status &
+ VL53L1_RANGE_STATUS__RANGE_STATUS_MASK) {
+
+ case VL53L1_DEVICEERROR_VCSELCONTINUITYTESTFAILURE:
+ case VL53L1_DEVICEERROR_VCSELWATCHDOGTESTFAILURE:
+ case VL53L1_DEVICEERROR_NOVHVVALUEFOUND:
+ case VL53L1_DEVICEERROR_USERROICLIP:
+ case VL53L1_DEVICEERROR_MULTCLIPFAIL:
+ status = VL53L1_ERROR_RANGE_ERROR;
+ break;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+void VL53L1_copy_sys_and_core_results_to_range_results(
+ int32_t gain_factor,
+ VL53L1_system_results_t *psys,
+ VL53L1_core_results_t *pcore,
+ VL53L1_range_results_t *presults)
+{
+ uint8_t i = 0;
+
+ VL53L1_range_data_t *pdata;
+ int32_t range_mm = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ presults->zone_id = 0;
+ presults->stream_count = psys->result__stream_count;
+ presults->wrap_dmax_mm = 0;
+ presults->max_results = VL53L1_MAX_RANGE_RESULTS;
+ presults->active_results = 1;
+
+ for (i = 0 ; i < VL53L1_MAX_AMBIENT_DMAX_VALUES ; i++)
+ presults->ambient_dmax_mm[i] = 0;
+
+ pdata = &(presults->VL53L1_PRM_00005[0]);
+
+ for (i = 0 ; i < 2 ; i++) {
+
+ pdata->range_id = i;
+ pdata->time_stamp = 0;
+ pdata->range_status =
+ psys->result__range_status & VL53L1_RANGE_STATUS__RANGE_STATUS_MASK;
+
+ pdata->VL53L1_PRM_00010 = 0;
+ pdata->VL53L1_PRM_00015 = 0;
+ pdata->VL53L1_PRM_00019 = 0;
+ pdata->VL53L1_PRM_00020 = 0;
+ pdata->VL53L1_PRM_00011 = 0;
+ pdata->VL53L1_PRM_00021 = 0;
+
+ switch (i) {
+
+ case 0:
+
+ if (psys->result__report_status == VL53L1_DEVICEREPORTSTATUS_MM1)
+ pdata->VL53L1_PRM_00003 =
+ psys->result__mm_inner_actual_effective_spads_sd0;
+ else if (psys->result__report_status == VL53L1_DEVICEREPORTSTATUS_MM2)
+ pdata->VL53L1_PRM_00003 =
+ psys->result__mm_outer_actual_effective_spads_sd0;
+ else
+ pdata->VL53L1_PRM_00003 =
+ psys->result__dss_actual_effective_spads_sd0;
+
+ pdata->peak_signal_count_rate_mcps =
+ psys->result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0;
+ pdata->avg_signal_count_rate_mcps =
+ psys->result__avg_signal_count_rate_mcps_sd0;
+ pdata->ambient_count_rate_mcps =
+ psys->result__ambient_count_rate_mcps_sd0;
+
+ pdata->VL53L1_PRM_00004 =
+ psys->result__sigma_sd0;
+ pdata->VL53L1_PRM_00014 =
+ psys->result__phase_sd0;
+
+ range_mm =
+ (int32_t)psys->result__final_crosstalk_corrected_range_mm_sd0;
+
+
+
+ range_mm *= gain_factor;
+ range_mm += 0x0400;
+ range_mm /= 0x0800;
+
+ pdata->median_range_mm = (int16_t)range_mm;
+
+ pdata->VL53L1_PRM_00022 =
+ pcore->result_core__ranging_total_events_sd0;
+ pdata->VL53L1_PRM_00009 =
+ pcore->result_core__signal_total_events_sd0;
+ pdata->total_periods_elapsed =
+ pcore->result_core__total_periods_elapsed_sd0;
+ pdata->VL53L1_PRM_00023 =
+ pcore->result_core__ambient_window_events_sd0;
+
+ break;
+ case 1:
+
+ pdata->VL53L1_PRM_00003 =
+ psys->result__dss_actual_effective_spads_sd1;
+ pdata->peak_signal_count_rate_mcps =
+ psys->result__peak_signal_count_rate_mcps_sd1;
+ pdata->avg_signal_count_rate_mcps =
+ 0xFFFF;
+ pdata->ambient_count_rate_mcps =
+ psys->result__ambient_count_rate_mcps_sd1;
+
+ pdata->VL53L1_PRM_00004 =
+ psys->result__sigma_sd1;
+ pdata->VL53L1_PRM_00014 =
+ psys->result__phase_sd1;
+
+ range_mm =
+ (int32_t)psys->result__final_crosstalk_corrected_range_mm_sd1;
+
+
+
+ range_mm *= gain_factor;
+ range_mm += 0x0400;
+ range_mm /= 0x0800;
+
+ pdata->median_range_mm = (int16_t)range_mm;
+
+ pdata->VL53L1_PRM_00022 =
+ pcore->result_core__ranging_total_events_sd1;
+ pdata->VL53L1_PRM_00009 =
+ pcore->result_core__signal_total_events_sd1;
+ pdata->total_periods_elapsed =
+ pcore->result_core__total_periods_elapsed_sd1;
+ pdata->VL53L1_PRM_00023 =
+ pcore->result_core__ambient_window_events_sd1;
+
+ break;
+ }
+
+
+
+
+
+ pdata->VL53L1_PRM_00024 = pdata->VL53L1_PRM_00014;
+ pdata->VL53L1_PRM_00025 = pdata->VL53L1_PRM_00014;
+ pdata->min_range_mm = pdata->median_range_mm;
+ pdata->max_range_mm = pdata->median_range_mm;
+
+ pdata++;
+ }
+
+ LOG_FUNCTION_END(0);
+}
+
+
+VL53L1_Error VL53L1_set_zone_dss_config(
+ VL53L1_DEV Dev,
+ VL53L1_zone_private_dyn_cfg_t *pzone_dyn_cfg)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ if (pzone_dyn_cfg->dss_requested_effective_spad_count == 0) {
+ pdev->gen_cfg.dss_config__roi_mode_control =
+ VL53L1_DSS_CONTROL__MODE_TARGET_RATE;
+ } else {
+ pdev->gen_cfg.dss_config__roi_mode_control =
+ VL53L1_DSS_CONTROL__MODE_EFFSPADS;
+ pdev->gen_cfg.dss_config__manual_effective_spads_select =
+ pzone_dyn_cfg->dss_requested_effective_spad_count;
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+VL53L1_Error VL53L1_calc_ambient_dmax(
+ VL53L1_DEV Dev,
+ uint16_t target_reflectance,
+ int16_t *pambient_dmax_mm)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ VL53L1_dmax_calibration_data_t dmax_cal;
+ VL53L1_dmax_calibration_data_t *pdmax_cal = &dmax_cal;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ status =
+ VL53L1_get_dmax_calibration_data(
+ Dev,
+ pdev->debug_mode,
+ pdev->ll_state.rd_zone_id,
+ pdmax_cal);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_ipp_hist_ambient_dmax(
+ Dev,
+ target_reflectance,
+ &(pdev->fmt_dmax_cal),
+ &(pdev->dmax_cfg),
+ &(pdev->hist_data),
+ pambient_dmax_mm);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_interrupt_config(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_Interrupt_Mode intr_mode_distance,
+ VL53L1_GPIO_Interrupt_Mode intr_mode_rate,
+ uint8_t intr_new_measure_ready,
+ uint8_t intr_no_target,
+ uint8_t intr_combined_mode,
+ uint16_t thresh_distance_high,
+ uint16_t thresh_distance_low,
+ uint16_t thresh_rate_high,
+ uint16_t thresh_rate_low
+ )
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_GPIO_interrupt_config_t *pintconf = &(pdev->gpio_interrupt_config);
+
+ LOG_FUNCTION_START("");
+
+
+
+ pintconf->intr_mode_distance = intr_mode_distance;
+ pintconf->intr_mode_rate = intr_mode_rate;
+ pintconf->intr_new_measure_ready = intr_new_measure_ready;
+ pintconf->intr_no_target = intr_no_target;
+ pintconf->intr_combined_mode = intr_combined_mode;
+ pintconf->threshold_distance_high = thresh_distance_high;
+ pintconf->threshold_distance_low = thresh_distance_low;
+ pintconf->threshold_rate_high = thresh_rate_high;
+ pintconf->threshold_rate_low = thresh_rate_low;
+
+
+
+ pdev->gen_cfg.system__interrupt_config_gpio =
+ VL53L1_encode_GPIO_interrupt_config(pintconf);
+
+
+
+
+ status = VL53L1_set_GPIO_thresholds_from_struct(
+ Dev,
+ pintconf);
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_interrupt_config_struct(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_interrupt_config_t intconf)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_GPIO_interrupt_config_t *pintconf = &(pdev->gpio_interrupt_config);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(pintconf, &(intconf), sizeof(VL53L1_GPIO_interrupt_config_t));
+
+
+
+ pdev->gen_cfg.system__interrupt_config_gpio =
+ VL53L1_encode_GPIO_interrupt_config(pintconf);
+
+
+
+ status = VL53L1_set_GPIO_thresholds_from_struct(
+ Dev,
+ pintconf);
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_GPIO_interrupt_config(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_interrupt_config_t *pintconf)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ pdev->gpio_interrupt_config = VL53L1_decode_GPIO_interrupt_config(
+ pdev->gen_cfg.system__interrupt_config_gpio);
+
+
+
+
+
+ pdev->gpio_interrupt_config.threshold_distance_high =
+ pdev->dyn_cfg.system__thresh_high;
+ pdev->gpio_interrupt_config.threshold_distance_low =
+ pdev->dyn_cfg.system__thresh_low;
+
+ pdev->gpio_interrupt_config.threshold_rate_high =
+ pdev->gen_cfg.system__thresh_rate_high;
+ pdev->gpio_interrupt_config.threshold_rate_low =
+ pdev->gen_cfg.system__thresh_rate_low;
+
+ if (pintconf == &(pdev->gpio_interrupt_config)) {
+
+
+ } else {
+
+
+
+ memcpy(pintconf, &(pdev->gpio_interrupt_config),
+ sizeof(VL53L1_GPIO_interrupt_config_t));
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_dmax_mode(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxMode dmax_mode)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->dmax_mode = dmax_mode;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_dmax_mode(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxMode *pdmax_mode)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pdmax_mode = pdev->dmax_mode;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_dmax_calibration_data(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxMode dmax_mode,
+ uint8_t zone_id,
+ VL53L1_dmax_calibration_data_t *pdmax_cal)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ switch (dmax_mode) {
+
+ case VL53L1_DEVICEDMAXMODE__PER_ZONE_CAL_DATA:
+ pdmax_cal->ref__actual_effective_spads =
+ (uint16_t)pres->zone_cal.VL53L1_PRM_00005[zone_id].effective_spads;
+ pdmax_cal->ref__peak_signal_count_rate_mcps =
+ (uint16_t)pres->zone_cal.VL53L1_PRM_00005[zone_id].peak_rate_mcps;
+ pdmax_cal->ref__distance_mm =
+ pres->zone_cal.cal_distance_mm;
+ pdmax_cal->ref_reflectance_pc =
+ pres->zone_cal.cal_reflectance_pc;
+ pdmax_cal->coverglass_transmission = 0x0100;
+ break;
+
+ case VL53L1_DEVICEDMAXMODE__CUST_CAL_DATA:
+ memcpy(
+ pdmax_cal,
+ &(pdev->cust_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+ break;
+
+ case VL53L1_DEVICEDMAXMODE__FMT_CAL_DATA:
+ memcpy(
+ pdmax_cal,
+ &(pdev->fmt_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+ break;
+
+ default:
+ status = VL53L1_ERROR_INVALID_PARAMS;
+ break;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_hist_dmax_config(
+ VL53L1_DEV Dev,
+ VL53L1_hist_gen3_dmax_config_t *pdmax_cfg)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(
+ &(pdev->dmax_cfg),
+ pdmax_cfg,
+ sizeof(VL53L1_hist_gen3_dmax_config_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_hist_dmax_config(
+ VL53L1_DEV Dev,
+ VL53L1_hist_gen3_dmax_config_t *pdmax_cfg)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(
+ pdmax_cfg,
+ &(pdev->dmax_cfg),
+ sizeof(VL53L1_hist_gen3_dmax_config_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_offset_calibration_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCalibrationMode offset_cal_mode)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->offset_calibration_mode = offset_cal_mode;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_offset_calibration_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCalibrationMode *poffset_cal_mode)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *poffset_cal_mode = pdev->offset_calibration_mode;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_offset_correction_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCorrectionMode offset_cor_mode)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->offset_correction_mode = offset_cor_mode;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_offset_correction_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCorrectionMode *poffset_cor_mode)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *poffset_cor_mode = pdev->offset_correction_mode;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_zone_calibration_data(
+ VL53L1_DEV Dev,
+ VL53L1_zone_calibration_results_t *pzone_cal)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverResults_t *pres = VL53L1DevStructGetLLResultsHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(
+ &(pres->zone_cal),
+ pzone_cal,
+ sizeof(VL53L1_zone_calibration_results_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_zone_calibration_data(
+ VL53L1_DEV Dev,
+ VL53L1_zone_calibration_results_t *pzone_cal)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverResults_t *pres = VL53L1DevStructGetLLResultsHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(
+ pzone_cal,
+ &(pres->zone_cal),
+ sizeof(VL53L1_zone_calibration_results_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_api_debug.c b/drivers/input/misc/vl53L1/src/vl53l1_api_debug.c
new file mode 100644
index 000000000000..558317721c55
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_api_debug.c
@@ -0,0 +1,3184 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_ll_device.h"
+#include "vl53l1_register_structs.h"
+#include "vl53l1_hist_structs.h"
+#include "vl53l1_nvm_structs.h"
+#include "vl53l1_nvm.h"
+#include "vl53l1_core.h"
+#include "vl53l1_api_debug.h"
+
+#ifdef VL53L1_LOG_ENABLE
+#include "vl53l1_nvm_debug.h"
+#endif
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, \
+ fmt, ##__VA_ARGS__)
+
+#define trace_print(level, ...) \
+ _LOG_TRACE_PRINT(trace_flags, \
+ level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_decode_calibration_data_buffer(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_calibration_data_t *pdata)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (sizeof(VL53L1_calibration_data_t) > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ memcpy(pdata, pbuffer, sizeof(VL53L1_calibration_data_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_nvm_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_decoded_nvm_data_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status = VL53L1_read_nvm(Dev, 0, pdata);
+
+#ifdef VL53L1_LOG_ENABLE
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_print_decoded_nvm_data(
+ pdata,
+ "get_nvm_debug_data():pnvm_info.",
+ VL53L1_TRACE_MODULE_NVM_DATA);
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_histogram_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(
+ pdata,
+ &(pdev->hist_data),
+ sizeof(VL53L1_histogram_bin_data_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_xtalk_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_xtalk_debug_data_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(
+ &(pdata->customer),
+ &(pdev->customer),
+ sizeof(VL53L1_customer_nvm_managed_t));
+
+ memcpy(
+ &(pdata->xtalk_cfg),
+ &(pdev->xtalk_cfg),
+ sizeof(VL53L1_xtalk_config_t));
+
+ memcpy(
+ &(pdata->hist_data),
+ &(pdev->hist_data),
+ sizeof(VL53L1_histogram_bin_data_t));
+
+ memcpy(
+ &(pdata->xtalk_shapes),
+ &(pdev->xtalk_shapes),
+ sizeof(VL53L1_xtalk_histogram_data_t));
+
+ memcpy(
+ &(pdata->xtalk_results),
+ &(pdev->xtalk_results),
+ sizeof(VL53L1_xtalk_range_results_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_offset_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_offset_debug_data_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(
+ &(pdata->customer),
+ &(pdev->customer),
+ sizeof(VL53L1_customer_nvm_managed_t));
+
+ memcpy(
+ &(pdata->fmt_dmax_cal),
+ &(pdev->fmt_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+ memcpy(
+ &(pdata->cust_dmax_cal),
+ &(pdev->cust_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+ memcpy(
+ &(pdata->add_off_cal_data),
+ &(pdev->add_off_cal_data),
+ sizeof(VL53L1_additional_offset_cal_data_t));
+
+ memcpy(
+ &(pdata->offset_results),
+ &(pdev->offset_results),
+ sizeof(VL53L1_offset_range_results_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+#ifdef VL53L1_LOG_ENABLE
+
+void VL53L1_signed_fixed_point_sprintf(
+ int32_t signed_fp_value,
+ uint8_t frac_bits,
+ uint16_t buf_size,
+ char *pbuffer)
+{
+
+
+
+
+
+ uint32_t fp_value = 0;
+ uint32_t unity_fp_value = 0;
+ uint32_t sign_bit = 0;
+ uint32_t int_part = 0;
+ uint32_t frac_part = 0;
+ uint32_t dec_points = 0;
+ uint32_t dec_scaler = 0;
+ uint32_t dec_part = 0;
+
+ uint64_t tmp_long_int = 0;
+
+ char fmt[VL53L1_MAX_STRING_LENGTH];
+
+ SUPPRESS_UNUSED_WARNING(buf_size);
+
+
+
+
+ sign_bit = signed_fp_value >> 31;
+
+ if (sign_bit > 0) {
+ fp_value = 0x80000000 -
+ (0x7FFFFFFF & (uint32_t)signed_fp_value);
+ } else
+ fp_value = (uint32_t)signed_fp_value;
+
+ int_part = fp_value >> frac_bits;
+ unity_fp_value = 0x01 << frac_bits;
+ frac_part = fp_value & (unity_fp_value-1);
+
+
+
+
+
+ dec_points = 2;
+ dec_scaler = 100;
+
+ while (dec_scaler < unity_fp_value) {
+ dec_points++;
+ dec_scaler *= 10;
+ }
+
+
+
+ if (sign_bit > 0)
+ sprintf(fmt, "-%%u.%%0%uu", dec_points);
+ else
+ sprintf(fmt, "%%u.%%0%uu", dec_points);
+
+
+
+
+
+ tmp_long_int = (uint64_t)frac_part * (uint64_t)dec_scaler;
+ tmp_long_int += (uint64_t)unity_fp_value/2;
+
+ tmp_long_int = do_division_u(tmp_long_int, (uint64_t)unity_fp_value);
+
+ dec_part = (uint32_t)tmp_long_int;
+
+
+
+ sprintf(
+ pbuffer,
+ fmt,
+ int_part,
+ dec_part);
+}
+
+
+void VL53L1_print_static_nvm_managed(
+ VL53L1_static_nvm_managed_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = 0x%02X\n",
+ pprefix,
+ "i2c_slave__device_address",
+ pdata->i2c_slave__device_address);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__vhv_ref_sel_vddpix",
+ pdata->ana_config__vhv_ref_sel_vddpix);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__vhv_ref_sel_vquench",
+ pdata->ana_config__vhv_ref_sel_vquench);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__reg_avdd1v2_sel",
+ pdata->ana_config__reg_avdd1v2_sel);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__fast_osc__trim",
+ pdata->ana_config__fast_osc__trim);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->osc_measured__fast_osc__frequency,
+ 12,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "osc_measured__fast_osc__frequency",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "vhv_config__timeout_macrop_loop_bound",
+ pdata->vhv_config__timeout_macrop_loop_bound);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "vhv_config__count_thresh",
+ pdata->vhv_config__count_thresh);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "vhv_config__offset",
+ pdata->vhv_config__offset);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "vhv_config__init",
+ pdata->vhv_config__init);
+}
+
+
+void VL53L1_print_customer_nvm_managed(
+ VL53L1_customer_nvm_managed_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_ref_0",
+ pdata->global_config__spad_enables_ref_0);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_ref_1",
+ pdata->global_config__spad_enables_ref_1);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_ref_2",
+ pdata->global_config__spad_enables_ref_2);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_ref_3",
+ pdata->global_config__spad_enables_ref_3);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_ref_4",
+ pdata->global_config__spad_enables_ref_4);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_ref_5",
+ pdata->global_config__spad_enables_ref_5);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__ref_en_start_select",
+ pdata->global_config__ref_en_start_select);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ref_spad_man__num_requested_ref_spads",
+ pdata->ref_spad_man__num_requested_ref_spads);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ref_spad_man__ref_location",
+ pdata->ref_spad_man__ref_location);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_compensation_plane_offset_kcps,
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_plane_offset_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_compensation_x_plane_gradient_kcps,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_x_plane_gradient_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_compensation_y_plane_gradient_kcps,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_y_plane_gradient_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->ref_spad_char__total_rate_target_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "ref_spad_char__total_rate_target_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__part_to_part_range_offset_mm,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__part_to_part_range_offset_mm",
+ fp_text);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "mm_config__inner_offset_mm",
+ pdata->mm_config__inner_offset_mm);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "mm_config__outer_offset_mm",
+ pdata->mm_config__outer_offset_mm);
+}
+
+
+void VL53L1_print_nvm_copy_data(
+ VL53L1_nvm_copy_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "identification__model_id",
+ pdata->identification__model_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "identification__module_type",
+ pdata->identification__module_type);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "identification__revision_id",
+ pdata->identification__revision_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "identification__module_id",
+ pdata->identification__module_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__fast_osc__trim_max",
+ pdata->ana_config__fast_osc__trim_max);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__fast_osc__freq_set",
+ pdata->ana_config__fast_osc__freq_set);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__vcsel_trim",
+ pdata->ana_config__vcsel_trim);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__vcsel_selion",
+ pdata->ana_config__vcsel_selion);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__vcsel_selion_max",
+ pdata->ana_config__vcsel_selion_max);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "protected_laser_safety__lock_bit",
+ pdata->protected_laser_safety__lock_bit);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "laser_safety__key",
+ pdata->laser_safety__key);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "laser_safety__key_ro",
+ pdata->laser_safety__key_ro);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "laser_safety__clip",
+ pdata->laser_safety__clip);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "laser_safety__mult",
+ pdata->laser_safety__mult);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_0",
+ pdata->global_config__spad_enables_rtn_0);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_1",
+ pdata->global_config__spad_enables_rtn_1);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_2",
+ pdata->global_config__spad_enables_rtn_2);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_3",
+ pdata->global_config__spad_enables_rtn_3);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_4",
+ pdata->global_config__spad_enables_rtn_4);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_5",
+ pdata->global_config__spad_enables_rtn_5);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_6",
+ pdata->global_config__spad_enables_rtn_6);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_7",
+ pdata->global_config__spad_enables_rtn_7);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_8",
+ pdata->global_config__spad_enables_rtn_8);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_9",
+ pdata->global_config__spad_enables_rtn_9);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_10",
+ pdata->global_config__spad_enables_rtn_10);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_11",
+ pdata->global_config__spad_enables_rtn_11);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_12",
+ pdata->global_config__spad_enables_rtn_12);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_13",
+ pdata->global_config__spad_enables_rtn_13);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_14",
+ pdata->global_config__spad_enables_rtn_14);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_15",
+ pdata->global_config__spad_enables_rtn_15);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_16",
+ pdata->global_config__spad_enables_rtn_16);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_17",
+ pdata->global_config__spad_enables_rtn_17);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_18",
+ pdata->global_config__spad_enables_rtn_18);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_19",
+ pdata->global_config__spad_enables_rtn_19);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_20",
+ pdata->global_config__spad_enables_rtn_20);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_21",
+ pdata->global_config__spad_enables_rtn_21);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_22",
+ pdata->global_config__spad_enables_rtn_22);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_23",
+ pdata->global_config__spad_enables_rtn_23);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_24",
+ pdata->global_config__spad_enables_rtn_24);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_25",
+ pdata->global_config__spad_enables_rtn_25);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_26",
+ pdata->global_config__spad_enables_rtn_26);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_27",
+ pdata->global_config__spad_enables_rtn_27);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_28",
+ pdata->global_config__spad_enables_rtn_28);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_29",
+ pdata->global_config__spad_enables_rtn_29);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_30",
+ pdata->global_config__spad_enables_rtn_30);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_31",
+ pdata->global_config__spad_enables_rtn_31);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "roi_config__mode_roi_centre_spad",
+ pdata->roi_config__mode_roi_centre_spad);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = 0x%02X\n",
+ pprefix,
+ "roi_config__mode_roi_xy_size",
+ pdata->roi_config__mode_roi_xy_size);
+}
+
+
+void VL53L1_print_histogram_bin_data(
+ VL53L1_histogram_bin_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cfg_device_state",
+ pdata->cfg_device_state);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "rd_device_state",
+ pdata->rd_device_state);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00015",
+ pdata->VL53L1_PRM_00015);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00016",
+ pdata->VL53L1_PRM_00016);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00017",
+ pdata->VL53L1_PRM_00017);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "number_of_ambient_bins",
+ pdata->number_of_ambient_bins);
+
+ for (i = 0 ; i < VL53L1_MAX_BIN_SEQUENCE_LENGTH ; i++) {
+ sprintf(ppre_text, "%sbin_seq[%u]", pprefix, i);
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->bin_seq[i]);
+ }
+
+ for (i = 0 ; i < VL53L1_MAX_BIN_SEQUENCE_LENGTH ; i++) {
+ sprintf(ppre_text, "%sbin_rep[%u]", pprefix, i);
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->bin_rep[i]);
+ }
+
+ for (i = 0 ; i < pdata->VL53L1_PRM_00017 ; i++) {
+ sprintf(ppre_text, "%sbin_data[%u]", pprefix, i);
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %d\n",
+ ppre_text,
+ pdata->bin_data[i]);
+ }
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "result__interrupt_status",
+ pdata->result__interrupt_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "result__range_status",
+ pdata->result__range_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "result__report_status",
+ pdata->result__report_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "result__stream_count",
+ pdata->result__stream_count);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__dss_actual_effective_spads,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__dss_actual_effective_spads",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->phasecal_result__reference_phase,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "phasecal_result__reference_phase",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "phasecal_result__vcsel_start",
+ pdata->phasecal_result__vcsel_start);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_config__vcsel_start",
+ pdata->cal_config__vcsel_start);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (uint32_t)pdata->vcsel_width,
+ 4,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "vcsel_width",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00007",
+ pdata->VL53L1_PRM_00007);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_PRM_00018,
+ 12,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_PRM_00018",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "total_periods_elapsed",
+ pdata->total_periods_elapsed);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "peak_duration_us",
+ pdata->peak_duration_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "woi_duration_us",
+ pdata->woi_duration_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "min_bin_value",
+ pdata->min_bin_value);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_bin_value",
+ pdata->max_bin_value);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->zero_distance_phase,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "zero_distance_phase",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "number_of_ambient_samples",
+ pdata->number_of_ambient_samples);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "ambient_events_sum",
+ pdata->ambient_events_sum);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "VL53L1_PRM_00026",
+ pdata->VL53L1_PRM_00026);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = 0x%02X\n",
+ pprefix,
+ "roi_config__user_roi_centre_spad",
+ pdata->roi_config__user_roi_centre_spad);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = 0x%02X\n",
+ pprefix,
+ "roi_config__user_roi_requested_global_xy_size",
+ pdata->roi_config__user_roi_requested_global_xy_size);
+}
+
+
+void VL53L1_print_xtalk_histogram_shape_data(
+ VL53L1_xtalk_histogram_shape_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00015",
+ pdata->VL53L1_PRM_00015);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00016",
+ pdata->VL53L1_PRM_00016);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00017",
+ pdata->VL53L1_PRM_00017);
+
+ for (i = 0 ; i < pdata->VL53L1_PRM_00017 ; i++) {
+
+ sprintf(ppre_text, "%sbin_data[%u]", pprefix, i);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->bin_data[i],
+ 10,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %s\n",
+ ppre_text,
+ fp_text);
+ }
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->phasecal_result__reference_phase,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "phasecal_result__reference_phase",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "phasecal_result__vcsel_start",
+ pdata->phasecal_result__vcsel_start);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_config__vcsel_start",
+ pdata->cal_config__vcsel_start);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->vcsel_width,
+ 4,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "vcsel_width",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_PRM_00018,
+ 12,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_PRM_00018",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->zero_distance_phase,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "zero_distance_phase",
+ fp_text);
+}
+
+
+void VL53L1_print_xtalk_histogram_data(
+ VL53L1_xtalk_histogram_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+
+
+ sprintf(ppre_text, "%sxtalk_shape.", pprefix);
+ VL53L1_print_xtalk_histogram_shape_data(
+ &(pdata->xtalk_shape),
+ ppre_text, trace_flags);
+
+
+
+ sprintf(ppre_text, "%sxtalk_hist_removed.", pprefix);
+ VL53L1_print_histogram_bin_data(
+ &(pdata->xtalk_hist_removed),
+ ppre_text, trace_flags);
+}
+
+
+void VL53L1_print_range_data(
+ VL53L1_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "range_id",
+ pdata->range_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "time_stamp",
+ pdata->time_stamp);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00010",
+ pdata->VL53L1_PRM_00010);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00015",
+ pdata->VL53L1_PRM_00015);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00019",
+ pdata->VL53L1_PRM_00019);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00020",
+ pdata->VL53L1_PRM_00020);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00011",
+ pdata->VL53L1_PRM_00011);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00021",
+ pdata->VL53L1_PRM_00021);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->width,
+ 4, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "width",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00027",
+ pdata->VL53L1_PRM_00027);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->fast_osc_frequency,
+ 12, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "fast_osc_frequency",
+ fp_text);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->zero_distance_phase,
+ 11, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "zero_distance_phase",
+ fp_text);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_PRM_00003,
+ 8, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "actual_effective_spad",
+ fp_text);
+
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "total_periods_elapsed",
+ pdata->total_periods_elapsed);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "peak_duration_us",
+ pdata->peak_duration_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "woi_duration_us",
+ pdata->woi_duration_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "VL53L1_PRM_00023",
+ pdata->VL53L1_PRM_00023);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "VL53L1_PRM_00022",
+ pdata->VL53L1_PRM_00022);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "VL53L1_PRM_00009",
+ pdata->VL53L1_PRM_00009);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->peak_signal_count_rate_mcps,
+ 7, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "peak_signal_count_rate_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->avg_signal_count_rate_mcps,
+ 7, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "avg_signal_count_rate_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->ambient_count_rate_mcps,
+ 7, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "ambient_count_rate_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->total_rate_per_spad_mcps,
+ 13, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "total_rate_per_spad_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_PRM_00008,
+ 11, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_PRM_00008",
+ fp_text);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_PRM_00004,
+ 2, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_PRM_00004",
+ fp_text);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_PRM_00024,
+ 11, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_PRM_00024",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_PRM_00014,
+ 11, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_PRM_00014",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_PRM_00025,
+ 11, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_PRM_00025",
+ fp_text);
+
+
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "min_range_mm",
+ pdata->min_range_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "median_range_mm",
+ pdata->median_range_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "max_range_mm",
+ pdata->max_range_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "range_status",
+ pdata->range_status);
+}
+
+
+void VL53L1_print_range_results(
+ VL53L1_range_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cfg_device_state",
+ pdata->cfg_device_state);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "rd_device_state",
+ pdata->rd_device_state);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "zone_id",
+ pdata->zone_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "stream_count",
+ pdata->stream_count);
+
+ for (i = 0 ; i < VL53L1_MAX_AMBIENT_DMAX_VALUES ; i++) {
+ sprintf(
+ ppre_text,
+ "%sambient_dmax_mm[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->ambient_dmax_mm[i]);
+ }
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "wrap_dmax_mm",
+ pdata->wrap_dmax_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_results",
+ pdata->max_results);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "active_results",
+ pdata->active_results);
+
+ for (i = 0 ; i < pdata->active_results ; i++) {
+ sprintf(ppre_text, "%sdata[%u].", pprefix, i);
+ VL53L1_print_range_data(
+ &pdata->VL53L1_PRM_00005[i],
+ ppre_text, trace_flags);
+ }
+}
+
+
+void VL53L1_print_offset_range_results(
+ VL53L1_offset_range_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_distance_mm",
+ pdata->cal_distance_mm);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->cal_reflectance_pc,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "cal_reflectance_pc",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_status",
+ pdata->cal_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_report",
+ pdata->cal_report);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_results",
+ pdata->max_results);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "active_results",
+ pdata->active_results);
+
+ for (i = 0 ; i < pdata->active_results ; i++) {
+ sprintf(ppre_text, "%sdata[%u].", pprefix, i);
+ VL53L1_print_offset_range_data(
+ &(pdata->VL53L1_PRM_00005[i]),
+ ppre_text, trace_flags);
+ }
+}
+
+
+void VL53L1_print_offset_range_data(
+ VL53L1_offset_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "preset_mode",
+ pdata->preset_mode);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "dss_config__roi_mode_control",
+ pdata->dss_config__roi_mode_control);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->dss_config__manual_effective_spads_select,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "dss_config__manual_effective_spads_select",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "no_of_samples",
+ pdata->no_of_samples);
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->effective_spads,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "effective_spads",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->peak_rate_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "peak_rate_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_PRM_00004,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_PRM_00004",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "median_range_mm",
+ pdata->median_range_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "range_mm_offset",
+ pdata->range_mm_offset);
+}
+
+
+void VL53L1_print_cal_peak_rate_map(
+ VL53L1_cal_peak_rate_map_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+ uint8_t x = 0;
+ uint8_t y = 0;
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->cal_distance_mm,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "cal_distance_mm",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->cal_reflectance_pc,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "cal_reflectance_pc",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_samples",
+ pdata->max_samples);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "width",
+ pdata->width);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "height",
+ pdata->height);
+
+ i = 0;
+ for (y = 0 ; y < pdata->height ; y++) {
+ for (x = 0 ; x < pdata->width ; x++) {
+
+ sprintf(ppre_text, "%speak_rate_mcps[%u]", pprefix, i);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->peak_rate_mcps[i],
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %s\n",
+ ppre_text,
+ fp_text);
+
+ i++;
+ }
+ }
+}
+
+
+void VL53L1_print_additional_offset_cal_data(
+ VL53L1_additional_offset_cal_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__mm_inner_actual_effective_spads,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__mm_inner_actual_effective_spads",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__mm_outer_actual_effective_spads,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__mm_outer_actual_effective_spads",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__mm_inner_peak_signal_count_rtn_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__mm_inner_peak_signal_count_rtn_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__mm_outer_peak_signal_count_rtn_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__mm_outer_peak_signal_count_rtn_mcps",
+ fp_text);
+}
+
+
+void VL53L1_print_gain_calibration_data(
+ VL53L1_gain_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->standard_ranging_gain_factor,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "standard_ranging_gain_factor",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->histogram_ranging_gain_factor,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "histogram_ranging_gain_factor",
+ fp_text);
+}
+
+
+void VL53L1_print_zone_calibration_data(
+ VL53L1_zone_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "no_of_samples",
+ pdata->no_of_samples);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->effective_spads,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "effective_spads",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->peak_rate_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "peak_rate_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_PRM_00014,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_PRM_00014",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_PRM_00004,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_PRM_00004",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->median_range_mm,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "median_range_mm",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->range_mm_offset,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "range_mm_offset",
+ fp_text);
+}
+
+
+void VL53L1_print_zone_calibration_results(
+ VL53L1_zone_calibration_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "preset_mode",
+ pdata->preset_mode);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "zone_preset",
+ pdata->zone_preset);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_distance_mm",
+ pdata->cal_distance_mm);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->cal_reflectance_pc,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "cal_reflectance_pc",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->phasecal_result__reference_phase,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "phasecal_result__reference_phase",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->zero_distance_phase,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "zero_distance_phase",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_status",
+ pdata->cal_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_zones",
+ pdata->max_zones);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "active_zones",
+ pdata->active_zones);
+
+ for (i = 0 ; i < pdata->active_zones ; i++) {
+ sprintf(ppre_text, "%sdata[%u].", pprefix, i);
+ VL53L1_print_zone_calibration_data(
+ &(pdata->VL53L1_PRM_00005[i]),
+ ppre_text, trace_flags);
+ }
+}
+
+void VL53L1_print_xtalk_range_results(
+ VL53L1_xtalk_range_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+ uint8_t i = 0;
+
+ VL53L1_histogram_bin_data_t *pbin_data;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_status",
+ pdata->cal_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "num_of_samples_status",
+ pdata->num_of_samples_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "zero_samples_status",
+ pdata->zero_samples_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_sigma_status",
+ pdata->max_sigma_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_results",
+ pdata->max_results);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "active_results",
+ pdata->active_results);
+
+ for (i = 0 ; i < pdata->active_results ; i++) {
+ sprintf(ppre_text, "%sdata[%u].", pprefix, i);
+ VL53L1_print_xtalk_range_data(
+ &(pdata->VL53L1_PRM_00005[i]),
+ ppre_text, trace_flags);
+ }
+
+ sprintf(ppre_text, "%scentral_histogram_sum.", pprefix);
+ VL53L1_print_histogram_bin_data(
+ &pdata->central_histogram_sum,
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%scentral_histogram_avg.", pprefix);
+ VL53L1_print_histogram_bin_data(
+ &pdata->central_histogram_avg,
+ ppre_text, trace_flags);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00010",
+ pdata->central_histogram__window_start);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_PRM_00011",
+ pdata->central_histogram__window_end);
+
+ pbin_data = &(pdata->histogram_avg_1[0]);
+
+ for (i = 0 ; i < 5 ; i++) {
+ sprintf(ppre_text, "%shistogram_avg_1[%u].", pprefix, i);
+ VL53L1_print_histogram_bin_data(
+ pbin_data,
+ ppre_text, trace_flags);
+ pbin_data++;
+ }
+
+ pbin_data = &(pdata->histogram_avg_2[0]);
+
+ for (i = 0 ; i < 5 ; i++) {
+ sprintf(ppre_text, "%shistogram_avg_2[%u].", pprefix, i);
+ VL53L1_print_histogram_bin_data(
+ pbin_data,
+ ppre_text, trace_flags);
+ pbin_data++;
+ }
+
+ pbin_data = &(pdata->xtalk_avg[0]);
+
+ for (i = 0 ; i < 5 ; i++) {
+ sprintf(ppre_text, "%sxtalk_avg[%u].", pprefix, i);
+ VL53L1_print_histogram_bin_data(
+ pbin_data,
+ ppre_text, trace_flags);
+ pbin_data++;
+ }
+}
+
+
+void VL53L1_print_xtalk_range_data(
+ VL53L1_xtalk_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "no_of_samples",
+ pdata->no_of_samples);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "signal_total_events_sum",
+ pdata->signal_total_events_sum);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "signal_total_events_avg",
+ pdata->signal_total_events_avg);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->rate_per_spad_kcps_sum,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "rate_per_spad_kcps_sum",
+ fp_text);
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->rate_per_spad_kcps_avg,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "rate_per_spad_kcps_avg",
+ fp_text);
+}
+
+
+void VL53L1_print_xtalk_calibration_results(
+ VL53L1_xtalk_calibration_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_compensation_plane_offset_kcps,
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_plane_offset_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_compensation_x_plane_gradient_kcps,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_x_plane_gradient_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_compensation_y_plane_gradient_kcps,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_y_plane_gradient_kcps",
+ fp_text);
+}
+
+
+void VL53L1_print_xtalk_config(
+ VL53L1_xtalk_config_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_compensation_plane_offset_kcps,
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_plane_offset_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_compensation_x_plane_gradient_kcps,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_x_plane_gradient_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_compensation_y_plane_gradient_kcps,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_y_plane_gradient_kcps",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_crosstalk_compensation_enable",
+ pdata->global_crosstalk_compensation_enable);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->histogram_mode_crosstalk_margin_kcps,
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "histogram_mode_crosstalk_margin_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->lite_mode_crosstalk_margin_kcps,
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "lite_mode_crosstalk_margin_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->crosstalk_range_ignore_threshold_mult,
+ 5,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "crosstalk_range_ignore_threshold_mult",
+ fp_text);
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->crosstalk_range_ignore_threshold_rate_mcps,
+ 13,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "crosstalk_range_ignore_threshold_rate_mcps",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "algo__crosstalk_detect_max_valid_range_mm",
+ pdata->algo__crosstalk_detect_max_valid_range_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "algo__crosstalk_detect_min_valid_range_mm",
+ pdata->algo__crosstalk_detect_min_valid_range_mm);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_detect_max_valid_rate_kcps,
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_detect_max_valid_rate_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_detect_max_sigma_mm,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_detect_max_sigma_mm",
+ fp_text);
+
+}
+
+
+void VL53L1_print_dmax_calibration_data(
+ VL53L1_dmax_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->ref__actual_effective_spads,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "ref__actual_effective_spads",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->ref__peak_signal_count_rate_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "ref__peak_signal_count_rate_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->ref__distance_mm,
+ 4,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "ref__distance_mm",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->ref_reflectance_pc,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "ref_reflectance_pc",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->coverglass_transmission,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "coverglass_transmission",
+ fp_text);
+}
+
+
+void VL53L1_print_calibration_data(
+ VL53L1_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = 0x%08X\n",
+ pprefix,
+ "struct_version",
+ pdata->struct_version);
+
+ sprintf(ppre_text, "%scustomer.", pprefix);
+ VL53L1_print_customer_nvm_managed(
+ &(pdata->customer),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sfmt_dmax_cal.", pprefix);
+ VL53L1_print_dmax_calibration_data(
+ &(pdata->fmt_dmax_cal),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%scust_dmax_cal.", pprefix);
+ VL53L1_print_dmax_calibration_data(
+ &(pdata->cust_dmax_cal),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sadd_off_cal_data.", pprefix);
+ VL53L1_print_additional_offset_cal_data(
+ &(pdata->add_off_cal_data),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%smm_roi.", pprefix);
+ VL53L1_print_user_zone(
+ &(pdata->mm_roi),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sxtalkhisto.", pprefix);
+ VL53L1_print_xtalk_histogram_data(
+ &(pdata->xtalkhisto),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sgain_cal.", pprefix);
+ VL53L1_print_gain_calibration_data(
+ &(pdata->gain_cal),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%scal_peak_rate_map.", pprefix);
+ VL53L1_print_cal_peak_rate_map(
+ &(pdata->cal_peak_rate_map),
+ ppre_text, trace_flags);
+}
+
+
+void VL53L1_print_xtalk_debug_data(
+ VL53L1_xtalk_debug_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ sprintf(ppre_text, "%scustomer.", pprefix);
+ VL53L1_print_customer_nvm_managed(
+ &(pdata->customer),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sxtalk_cfg.", pprefix);
+ VL53L1_print_xtalk_config(
+ &(pdata->xtalk_cfg),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%shist_data.", pprefix);
+ VL53L1_print_histogram_bin_data(
+ &(pdata->hist_data),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sxtalk_shapes.", pprefix);
+ VL53L1_print_xtalk_histogram_data(
+ &(pdata->xtalk_shapes),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sgain_cal.", pprefix);
+ VL53L1_print_xtalk_range_results(
+ &(pdata->xtalk_results),
+ ppre_text, trace_flags);
+}
+
+
+void VL53L1_print_offset_debug_data(
+ VL53L1_offset_debug_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ sprintf(ppre_text, "%scustomer.", pprefix);
+ VL53L1_print_customer_nvm_managed(
+ &(pdata->customer),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sfmt_dmax_cal.", pprefix);
+ VL53L1_print_dmax_calibration_data(
+ &(pdata->fmt_dmax_cal),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%scust_dmax_cal.", pprefix);
+ VL53L1_print_dmax_calibration_data(
+ &(pdata->cust_dmax_cal),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sadd_off_cal_data.", pprefix);
+ VL53L1_print_additional_offset_cal_data(
+ &(pdata->add_off_cal_data),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%soffset_results.", pprefix);
+ VL53L1_print_offset_range_results(
+ &(pdata->offset_results),
+ ppre_text, trace_flags);
+}
+
+
+void VL53L1_print_zone_config(
+ VL53L1_zone_config_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_zones",
+ pdata->max_zones);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "active_zones",
+ pdata->active_zones);
+
+ for (i = 0; i < pdata->active_zones; i++) {
+ sprintf(ppre_text, "%suser_zones[%u].", pprefix, i);
+ VL53L1_print_user_zone(
+ &pdata->user_zones[i],
+ ppre_text,
+ trace_flags);
+ }
+}
+
+
+void VL53L1_print_user_zone(
+ VL53L1_user_zone_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "x_centre",
+ pdata->x_centre);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "y_centre",
+ pdata->y_centre);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "width",
+ pdata->width);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "height",
+ pdata->height);
+}
+
+
+void VL53L1_print_spad_rate_data(
+ VL53L1_spad_rate_data_t *pspad_rates,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+
+ uint16_t spad_no = 0;
+ uint8_t row = 0;
+ uint8_t col = 0;
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%8s,%4s,%4s, %s\n",
+ pprefix,
+ "spad_no",
+ "row",
+ "col",
+ "peak_rate_mcps");
+
+ for (spad_no = 0 ; spad_no < pspad_rates->no_of_values ; spad_no++) {
+
+
+
+ VL53L1_decode_row_col(
+ (uint8_t)spad_no,
+ &row,
+ &col);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pspad_rates->rate_data[spad_no],
+ pspad_rates->fractional_bits,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%8u,%4u,%4u, %s\n",
+ pprefix,
+ spad_no,
+ row,
+ col,
+ fp_text);
+ }
+}
+
+
+void VL53L1_print_spad_rate_map(
+ VL53L1_spad_rate_data_t *pspad_rates,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+
+ uint8_t spad_no = 0;
+ uint8_t row = 0;
+ uint8_t col = 0;
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%4s",
+ pprefix,
+ " ");
+
+ for (col = 0 ; col < VL53L1_SPAD_ARRAY_WIDTH ; col++)
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ ",%8u",
+ col);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "\n");
+
+
+
+
+ for (row = 0 ; row < VL53L1_SPAD_ARRAY_HEIGHT ; row++) {
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%4u",
+ pprefix,
+ row);
+
+ for (col = 0 ; col < VL53L1_SPAD_ARRAY_HEIGHT ; col++) {
+
+
+
+
+ VL53L1_encode_row_col(
+ row,
+ col,
+ &spad_no);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pspad_rates->rate_data[spad_no],
+ pspad_rates->fractional_bits,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ ",%8s",
+ fp_text);
+ }
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "\n");
+ }
+}
+
+
+#endif
+
+
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_api_preset_modes.c b/drivers/input/misc/vl53L1/src/vl53l1_api_preset_modes.c
new file mode 100644
index 000000000000..8a637da6d4d0
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_api_preset_modes.c
@@ -0,0 +1,4086 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_platform_log.h"
+#include "vl53l1_register_structs.h"
+#include "vl53l1_register_settings.h"
+#include "vl53l1_hist_structs.h"
+#include "vl53l1_zone_presets.h"
+#include "vl53l1_core.h"
+#include "vl53l1_api_preset_modes.h"
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, status, fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_init_refspadchar_config_struct(
+ VL53L1_refspadchar_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+
+
+
+ pdata->device_test_mode =
+ VL53L1_DEVICETESTMODE_REF_SPAD_CHAR_WITH_PRE_VHV;
+ pdata->VL53L1_PRM_00007 = 0x0B;
+ pdata->timeout_us = 1000;
+ pdata->target_count_rate_mcps = 0x0A00;
+ pdata->min_count_rate_limit_mcps = 0x0500;
+ pdata->max_count_rate_limit_mcps = 0x1400;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_init_ssc_config_struct(
+ VL53L1_ssc_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+ pdata->array_select = VL53L1_DEVICESSCARRAY_RTN;
+
+
+
+ pdata->VL53L1_PRM_00007 = 0x12;
+
+
+
+ pdata->vcsel_start = 0x0F;
+
+
+
+ pdata->vcsel_start = 0x02;
+
+
+
+ pdata->timeout_us = 36000;
+
+
+
+
+
+
+ pdata->rate_limit_mcps = 0x000C;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_init_xtalk_config_struct(
+ VL53L1_customer_nvm_managed_t *pnvm,
+ VL53L1_xtalk_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pdata->algo__crosstalk_compensation_plane_offset_kcps =
+ pnvm->algo__crosstalk_compensation_plane_offset_kcps;
+ pdata->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pnvm->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pdata->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pnvm->algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+
+ pdata->nvm_default__crosstalk_compensation_plane_offset_kcps =
+ pnvm->algo__crosstalk_compensation_plane_offset_kcps;
+ pdata->nvm_default__crosstalk_compensation_x_plane_gradient_kcps =
+ pnvm->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pdata->nvm_default__crosstalk_compensation_y_plane_gradient_kcps =
+ pnvm->algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+ pdata->histogram_mode_crosstalk_margin_kcps =
+ 0x00;
+ pdata->lite_mode_crosstalk_margin_kcps =
+ 0x00;
+
+
+
+
+ pdata->crosstalk_range_ignore_threshold_mult = 64;
+
+ if ((pdata->algo__crosstalk_compensation_plane_offset_kcps == 0x00)
+ && (pdata->algo__crosstalk_compensation_x_plane_gradient_kcps == 0x00)
+ && (pdata->algo__crosstalk_compensation_y_plane_gradient_kcps == 0x00))
+ pdata->global_crosstalk_compensation_enable = 0x00;
+ else
+ pdata->global_crosstalk_compensation_enable = 0x01;
+
+
+ if ((status == VL53L1_ERROR_NONE) &&
+ (pdata->global_crosstalk_compensation_enable == 0x01)) {
+ pdata->crosstalk_range_ignore_threshold_rate_mcps =
+ VL53L1_calc_range_ignore_threshold(
+ pdata->algo__crosstalk_compensation_plane_offset_kcps,
+ pdata->algo__crosstalk_compensation_x_plane_gradient_kcps,
+ pdata->algo__crosstalk_compensation_y_plane_gradient_kcps,
+ pdata->crosstalk_range_ignore_threshold_mult);
+ } else {
+ pdata->crosstalk_range_ignore_threshold_rate_mcps = 0;
+ }
+
+
+
+
+
+
+
+
+
+ pdata->algo__crosstalk_detect_min_valid_range_mm = -50;
+ pdata->algo__crosstalk_detect_max_valid_range_mm = 50;
+ pdata->algo__crosstalk_detect_max_valid_rate_kcps = 0xC800;
+ pdata->algo__crosstalk_detect_max_sigma_mm =
+ VL53L1_XTALK_EXTRACT_MAX_SIGMA_MM;
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_init_hist_post_process_config_struct(
+ uint8_t xtalk_compensation_enable,
+ VL53L1_hist_post_process_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ pdata->hist_algo_select =
+ VL53L1_HIST_ALGO_SELECT__PW_HIST_GEN4;
+
+ pdata->hist_target_order =
+ VL53L1_HIST_TARGET_ORDER__INCREASING_DISTANCE;
+
+
+
+
+ pdata->filter_woi0 = 1;
+
+ pdata->filter_woi1 = 2;
+
+
+ pdata->hist_amb_est_method =
+ VL53L1_HIST_AMB_EST_METHOD__AMBIENT_BINS;
+ pdata->ambient_thresh_sigma0 = 80;
+
+ pdata->ambient_thresh_sigma1 = 112;
+
+ pdata->min_ambient_thresh_events = 16;
+
+
+ pdata->noise_threshold = 50;
+
+
+ pdata->signal_total_events_limit = 100;
+
+ pdata->sigma_estimator__sigma_ref_mm = 1;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pdata->sigma_thresh = 160;
+
+ pdata->range_offset_mm = 0;
+
+
+ pdata->gain_factor = 0x0800;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pdata->valid_phase_low = 0x08;
+ pdata->valid_phase_high = 0x88;
+
+
+
+
+
+
+
+
+
+ pdata->algo__consistency_check__phase_tolerance = 8;
+
+
+
+
+
+
+
+ pdata->algo__consistency_check__event_sigma = 112;
+
+
+
+ pdata->algo__crosstalk_compensation_enable = xtalk_compensation_enable;
+
+
+
+
+
+
+
+ pdata->algo__crosstalk_detect_min_valid_range_mm = -50;
+ pdata->algo__crosstalk_detect_max_valid_range_mm = 50;
+ pdata->algo__crosstalk_detect_max_valid_rate_kcps = 0xC800;
+ pdata->algo__crosstalk_detect_max_sigma_mm =
+ VL53L1_XTALK_EXTRACT_MAX_SIGMA_MM;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_init_dmax_calibration_data_struct(
+ VL53L1_dmax_calibration_data_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ pdata->ref__actual_effective_spads = 0x5F2D;
+
+
+ pdata->ref__peak_signal_count_rate_mcps = 0x0844;
+
+
+ pdata->ref__distance_mm = 0x08A5;
+
+
+
+
+
+
+
+
+ pdata->ref_reflectance_pc = 0x000F;
+
+
+
+ pdata->coverglass_transmission = 0x0100;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_init_hist_gen3_dmax_config_struct(
+ VL53L1_hist_gen3_dmax_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+ pdata->dss_config__target_total_rate_mcps = 0x1400;
+ pdata->dss_config__aperture_attenuation = 0x38;
+
+ pdata->signal_thresh_sigma = 0x20;
+ pdata->ambient_thresh_sigma = 0x70;
+ pdata->min_ambient_thresh_events = 16;
+ pdata->estimated_spad_yield = 85;
+
+
+
+
+
+
+
+
+
+
+
+ pdata->target_reflectance_for_dmax_calc[0] = 15;
+ pdata->target_reflectance_for_dmax_calc[1] = 52;
+ pdata->target_reflectance_for_dmax_calc[2] = 200;
+ pdata->target_reflectance_for_dmax_calc[3] = 364;
+ pdata->target_reflectance_for_dmax_calc[4] = 400;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ pstatic->dss_config__target_total_rate_mcps = 0x0A00;
+ pstatic->debug__ctrl = 0x00;
+ pstatic->test_mode__ctrl = 0x00;
+ pstatic->clk_gating__ctrl = 0x00;
+ pstatic->nvm_bist__ctrl = 0x00;
+ pstatic->nvm_bist__num_nvm_words = 0x00;
+ pstatic->nvm_bist__start_address = 0x00;
+ pstatic->host_if__status = 0x00;
+ pstatic->pad_i2c_hv__config = 0x00;
+ pstatic->pad_i2c_hv__extsup_config = 0x00;
+
+
+
+
+
+
+ pstatic->gpio_hv_pad__ctrl = 0x00;
+
+
+
+
+
+
+
+
+ pstatic->gpio_hv_mux__ctrl = \
+ VL53L1_DEVICEINTERRUPTPOLARITY_ACTIVE_LOW | \
+ VL53L1_DEVICEGPIOMODE_OUTPUT_RANGE_AND_ERROR_INTERRUPTS;
+
+ pstatic->gpio__tio_hv_status = 0x02;
+ pstatic->gpio__fio_hv_status = 0x00;
+ pstatic->ana_config__spad_sel_pswidth = 0x02;
+ pstatic->ana_config__vcsel_pulse_width_offset = 0x08;
+ pstatic->ana_config__fast_osc__config_ctrl = 0x00;
+
+ pstatic->sigma_estimator__effective_pulse_width_ns = 0x08;
+ pstatic->sigma_estimator__effective_ambient_width_ns = 0x10;
+ pstatic->sigma_estimator__sigma_ref_mm = 0x01;
+
+
+ pstatic->algo__crosstalk_compensation_valid_height_mm = 0x01;
+ pstatic->spare_host_config__static_config_spare_0 = 0x00;
+ pstatic->spare_host_config__static_config_spare_1 = 0x00;
+
+ pstatic->algo__range_ignore_threshold_mcps = 0x0000;
+
+
+
+ pstatic->algo__range_ignore_valid_height_mm = 0xff;
+ pstatic->algo__range_min_clip = 0x00;
+
+
+
+
+
+
+ pstatic->algo__consistency_check__tolerance = 0x02;
+ pstatic->spare_host_config__static_config_spare_2 = 0x00;
+ pstatic->sd_config__reset_stages_msb = 0x00;
+ pstatic->sd_config__reset_stages_lsb = 0x00;
+
+ pgeneral->gph_config__stream_count_update_value = 0x00;
+ pgeneral->global_config__stream_divider = 0x00;
+ pgeneral->system__interrupt_config_gpio =
+ VL53L1_INTERRUPT_CONFIG_NEW_SAMPLE_READY;
+ pgeneral->cal_config__vcsel_start = 0x0B;
+
+
+
+
+
+
+
+
+ pgeneral->cal_config__repeat_rate = 0;
+ pgeneral->global_config__vcsel_width = 0x02;
+
+
+ pgeneral->phasecal_config__timeout_macrop = 0x0D;
+
+
+ pgeneral->phasecal_config__target = 0x21;
+ pgeneral->phasecal_config__override = 0x00;
+ pgeneral->dss_config__roi_mode_control =
+ VL53L1_DEVICEDSSMODE__TARGET_RATE;
+
+
+ pgeneral->system__thresh_rate_high = 0x0000;
+ pgeneral->system__thresh_rate_low = 0x0000;
+
+
+ pgeneral->dss_config__manual_effective_spads_select = 0x8C00;
+ pgeneral->dss_config__manual_block_select = 0x00;
+
+
+
+
+
+
+
+
+ pgeneral->dss_config__aperture_attenuation = 0x38;
+ pgeneral->dss_config__max_spads_limit = 0xFF;
+ pgeneral->dss_config__min_spads_limit = 0x01;
+
+
+
+
+ ptiming->mm_config__timeout_macrop_a_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_a_lo = 0x06;
+ ptiming->mm_config__timeout_macrop_b_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_b_lo = 0x06;
+ ptiming->range_config__timeout_macrop_a_hi = 0x02;
+ ptiming->range_config__timeout_macrop_a_lo = 0x85;
+
+
+ ptiming->range_config__vcsel_period_a = 0x0B;
+ ptiming->range_config__timeout_macrop_b_hi = 0x01;
+ ptiming->range_config__timeout_macrop_b_lo = 0x92;
+
+
+ ptiming->range_config__vcsel_period_b = 0x09;
+
+
+
+
+
+
+
+ ptiming->range_config__sigma_thresh = 0x003C;
+
+
+
+
+
+
+ ptiming->range_config__min_count_rate_rtn_limit_mcps = 0x0080;
+
+
+
+
+
+
+ ptiming->range_config__valid_phase_low = 0x08;
+ ptiming->range_config__valid_phase_high = 0x78;
+ ptiming->system__intermeasurement_period = 0x00000000;
+ ptiming->system__fractional_enable = 0x00;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ phistogram->histogram_config__low_amb_even_bin_0_1 = 0x07;
+ phistogram->histogram_config__low_amb_even_bin_2_3 = 0x21;
+ phistogram->histogram_config__low_amb_even_bin_4_5 = 0x43;
+
+ phistogram->histogram_config__low_amb_odd_bin_0_1 = 0x10;
+ phistogram->histogram_config__low_amb_odd_bin_2_3 = 0x32;
+ phistogram->histogram_config__low_amb_odd_bin_4_5 = 0x54;
+
+ phistogram->histogram_config__mid_amb_even_bin_0_1 = 0x07;
+ phistogram->histogram_config__mid_amb_even_bin_2_3 = 0x21;
+ phistogram->histogram_config__mid_amb_even_bin_4_5 = 0x43;
+
+ phistogram->histogram_config__mid_amb_odd_bin_0_1 = 0x10;
+ phistogram->histogram_config__mid_amb_odd_bin_2 = 0x02;
+ phistogram->histogram_config__mid_amb_odd_bin_3_4 = 0x43;
+ phistogram->histogram_config__mid_amb_odd_bin_5 = 0x05;
+
+ phistogram->histogram_config__user_bin_offset = 0x00;
+
+ phistogram->histogram_config__high_amb_even_bin_0_1 = 0x07;
+ phistogram->histogram_config__high_amb_even_bin_2_3 = 0x21;
+ phistogram->histogram_config__high_amb_even_bin_4_5 = 0x43;
+
+ phistogram->histogram_config__high_amb_odd_bin_0_1 = 0x10;
+ phistogram->histogram_config__high_amb_odd_bin_2_3 = 0x32;
+ phistogram->histogram_config__high_amb_odd_bin_4_5 = 0x54;
+
+ phistogram->histogram_config__amb_thresh_low = 0xFFFF;
+ phistogram->histogram_config__amb_thresh_high = 0xFFFF;
+
+ phistogram->histogram_config__spad_array_selection = 0x00;
+
+
+
+
+
+
+
+
+ pzone_cfg->max_zones = VL53L1_MAX_USER_ZONES;
+ pzone_cfg->active_zones = 0x00;
+ pzone_cfg->user_zones[0].height = 0x0f;
+ pzone_cfg->user_zones[0].width = 0x0f;
+ pzone_cfg->user_zones[0].x_centre = 0x08;
+ pzone_cfg->user_zones[0].y_centre = 0x08;
+
+
+
+
+ pdynamic->system__grouped_parameter_hold_0 = 0x01;
+
+ pdynamic->system__thresh_high = 0x0000;
+ pdynamic->system__thresh_low = 0x0000;
+ pdynamic->system__enable_xtalk_per_quadrant = 0x00;
+ pdynamic->system__seed_config =
+ VL53L1_SYSTEM__SEED_CONFIG__EVEN_UPDATE_ONLY;
+
+
+ pdynamic->sd_config__woi_sd0 = 0x0B;
+
+
+ pdynamic->sd_config__woi_sd1 = 0x09;
+ pdynamic->sd_config__initial_phase_sd0 = 0x0A;
+ pdynamic->sd_config__initial_phase_sd1 = 0x0A;
+
+ pdynamic->system__grouped_parameter_hold_1 = 0x01;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pdynamic->sd_config__first_order_select = 0x00;
+ pdynamic->sd_config__quantifier = 0x02;
+
+
+
+
+
+
+ pdynamic->roi_config__user_roi_centre_spad = 0xC7;
+
+
+ pdynamic->roi_config__user_roi_requested_global_xy_size = 0xFF;
+
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM2_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+
+ pdynamic->system__grouped_parameter_hold = 0x02;
+
+
+
+
+
+ psystem->system__stream_count_ctrl = 0x00;
+ psystem->firmware__enable = 0x01;
+ psystem->system__interrupt_clear = \
+ VL53L1_CLEAR_RANGE_INT;
+
+ psystem->system__mode_start = \
+ VL53L1_DEVICESCHEDULERMODE_STREAMING | \
+ VL53L1_DEVICEREADOUTMODE_SINGLE_SD | \
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_short_range(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x07;
+ ptiming->range_config__vcsel_period_b = 0x05;
+ ptiming->range_config__sigma_thresh = 0x0050;
+ ptiming->range_config__min_count_rate_rtn_limit_mcps = 0x0020;
+ ptiming->range_config__valid_phase_low = 0x08;
+ ptiming->range_config__valid_phase_high = 0x38;
+
+
+
+
+
+
+
+ pdynamic->sd_config__woi_sd0 = 0x07;
+ pdynamic->sd_config__woi_sd1 = 0x05;
+ pdynamic->sd_config__initial_phase_sd0 = 0x06;
+ pdynamic->sd_config__initial_phase_sd1 = 0x06;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_long_range(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x0F;
+ ptiming->range_config__vcsel_period_b = 0x0D;
+ ptiming->range_config__sigma_thresh = 0x0050;
+ ptiming->range_config__min_count_rate_rtn_limit_mcps = 0x0020;
+ ptiming->range_config__valid_phase_low = 0x08;
+ ptiming->range_config__valid_phase_high = 0xB8;
+
+
+
+
+
+
+
+ pdynamic->sd_config__woi_sd0 = 0x0F;
+ pdynamic->sd_config__woi_sd1 = 0x0D;
+ pdynamic->sd_config__initial_phase_sd0 = 0x0E;
+ pdynamic->sd_config__initial_phase_sd1 = 0x0E;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_mm1_cal(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pgeneral->dss_config__roi_mode_control =
+ VL53L1_DEVICEDSSMODE__REQUESTED_EFFFECTIVE_SPADS;
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM1_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_mm2_cal(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pgeneral->dss_config__roi_mode_control =
+ VL53L1_DEVICEDSSMODE__REQUESTED_EFFFECTIVE_SPADS;
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM2_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_timed_ranging(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ pdynamic->system__grouped_parameter_hold = 0x00;
+
+
+
+
+
+ ptiming->system__intermeasurement_period = 0x00000600;
+ pdynamic->system__seed_config =
+ VL53L1_SYSTEM__SEED_CONFIG__STANDARD;
+
+
+
+
+
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_PSEUDO_SOLO | \
+ VL53L1_DEVICEREADOUTMODE_SINGLE_SD | \
+ VL53L1_DEVICEMEASUREMENTMODE_TIMED;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_preset_mode_timed_ranging_short_range(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging_short_range(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ pdynamic->system__grouped_parameter_hold = 0x00;
+
+
+
+
+
+ ptiming->system__intermeasurement_period = 0x00000600;
+ pdynamic->system__seed_config =
+ VL53L1_SYSTEM__SEED_CONFIG__STANDARD;
+
+
+
+
+
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_PSEUDO_SOLO | \
+ VL53L1_DEVICEREADOUTMODE_SINGLE_SD | \
+ VL53L1_DEVICEMEASUREMENTMODE_TIMED;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_preset_mode_timed_ranging_long_range(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging_long_range(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ pdynamic->system__grouped_parameter_hold = 0x00;
+
+
+
+
+
+ ptiming->system__intermeasurement_period = 0x00000600;
+ pdynamic->system__seed_config =
+ VL53L1_SYSTEM__SEED_CONFIG__STANDARD;
+
+
+
+
+
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_PSEUDO_SOLO | \
+ VL53L1_DEVICEREADOUTMODE_SINGLE_SD | \
+ VL53L1_DEVICEMEASUREMENTMODE_TIMED;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_preset_mode_singleshot_ranging(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ pdynamic->system__grouped_parameter_hold = 0x00;
+
+
+
+
+ pdynamic->system__seed_config =
+ VL53L1_SYSTEM__SEED_CONFIG__STANDARD;
+
+
+
+
+
+
+ psystem->system__mode_start = \
+ VL53L1_DEVICESCHEDULERMODE_PSEUDO_SOLO | \
+ VL53L1_DEVICEREADOUTMODE_SINGLE_SD | \
+ VL53L1_DEVICEMEASUREMENTMODE_SINGLESHOT;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ pstatic->dss_config__target_total_rate_mcps = 0x1400;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 0, 1, 2, 3, 4, 5,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 0, 1, 2, 3, 4, 5,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x09;
+ ptiming->range_config__vcsel_period_b = 0x0B;
+ pdynamic->sd_config__woi_sd0 = 0x09;
+ pdynamic->sd_config__woi_sd1 = 0x0B;
+
+
+
+
+
+
+
+
+ phistpostprocess->valid_phase_low = 0x08;
+ phistpostprocess->valid_phase_high = 0x88;
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+
+
+
+
+
+
+ pgeneral->phasecal_config__timeout_macrop = 0x40;
+
+
+
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+
+
+
+
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+
+
+ psystem->system__mode_start = \
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM | \
+ VL53L1_DEVICEREADOUTMODE_DUAL_SD | \
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_with_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 8+0, 8+1, 8+2, 3, 4, 5,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 8+0, 8+1, 8+2, 3, 4, 5,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM1_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+
+ psystem->system__mode_start = \
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM | \
+ VL53L1_DEVICEREADOUTMODE_DUAL_SD | \
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_with_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging_with_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM2_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_mm1_cal(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 8+0, 8+1, 8+2, 8+3, 8+4,
+ 8+0, 8+1, 8+2, 8+3, 8+4, 8+5,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 8+0, 8+1, 8+2, 8+3, 8+4,
+ 8+0, 8+1, 8+2, 8+3, 8+4, 8+5,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+ pgeneral->dss_config__roi_mode_control =
+ VL53L1_DEVICEDSSMODE__REQUESTED_EFFFECTIVE_SPADS;
+
+
+
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM1_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_mm2_cal(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging_mm1_cal(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM2_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_short_timing(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ pstatic->dss_config__target_total_rate_mcps = 0x1400;
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 7, 0, 1, 2, 3, 4,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 7, 0, 1, 2, 3, 4,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x04;
+ ptiming->range_config__vcsel_period_b = 0x03;
+ ptiming->mm_config__timeout_macrop_a_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_a_lo = 0x42;
+ ptiming->mm_config__timeout_macrop_b_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_b_lo = 0x42;
+ ptiming->range_config__timeout_macrop_a_hi = 0x00;
+ ptiming->range_config__timeout_macrop_a_lo = 0x52;
+ ptiming->range_config__timeout_macrop_b_hi = 0x00;
+ ptiming->range_config__timeout_macrop_b_lo = 0x66;
+
+ pgeneral->cal_config__vcsel_start = 0x04;
+
+
+
+
+
+
+
+
+
+
+ pgeneral->phasecal_config__timeout_macrop = 0xa4;
+
+
+
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+
+
+
+
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+
+
+ psystem->system__mode_start = \
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM | \
+ VL53L1_DEVICEREADOUTMODE_DUAL_SD | \
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_long_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 0, 1, 2, 3, 4, 5,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 2, 3, 4,
+
+ 0, 1, 2, 3, 4, 5,
+
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x09;
+ ptiming->range_config__vcsel_period_b = 0x0b;
+
+
+
+
+
+
+ ptiming->mm_config__timeout_macrop_a_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_a_lo = 0x21;
+ ptiming->mm_config__timeout_macrop_b_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_b_lo = 0x1b;
+
+
+
+
+ ptiming->range_config__timeout_macrop_a_hi = 0x00;
+ ptiming->range_config__timeout_macrop_a_lo = 0x29;
+ ptiming->range_config__timeout_macrop_b_hi = 0x00;
+ ptiming->range_config__timeout_macrop_b_lo = 0x22;
+
+
+
+
+ pgeneral->cal_config__vcsel_start = 0x09;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pgeneral->phasecal_config__timeout_macrop = 0x42;
+
+
+
+
+ pdynamic->sd_config__woi_sd0 = 0x09;
+ pdynamic->sd_config__woi_sd1 = 0x0B;
+ pdynamic->sd_config__initial_phase_sd0 = 0x09;
+ pdynamic->sd_config__initial_phase_sd1 = 0x09;
+
+
+
+
+
+
+
+
+ phistpostprocess->valid_phase_low = 0x08;
+ phistpostprocess->valid_phase_high = 0x88;
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+
+
+ psystem->system__mode_start = \
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM | \
+ VL53L1_DEVICEREADOUTMODE_DUAL_SD | \
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_long_range_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_long_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 8+0, 8+1, 8+2, 3, 4, 5,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 8+0, 8+1, 8+2, 3, 4, 5,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM1_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_long_range_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_long_range_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM2_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_medium_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 1, 2, 2,
+ 0, 1, 2, 1, 2, 3,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 0, 1, 2, 1, 2, 3,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x05;
+ ptiming->range_config__vcsel_period_b = 0x07;
+
+
+
+
+
+
+ ptiming->mm_config__timeout_macrop_a_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_a_lo = 0x37;
+ ptiming->mm_config__timeout_macrop_b_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_b_lo = 0x29;
+
+
+
+
+ ptiming->range_config__timeout_macrop_a_hi = 0x00;
+ ptiming->range_config__timeout_macrop_a_lo = 0x44;
+ ptiming->range_config__timeout_macrop_b_hi = 0x00;
+ ptiming->range_config__timeout_macrop_b_lo = 0x33;
+
+
+
+
+ pgeneral->cal_config__vcsel_start = 0x05;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pgeneral->phasecal_config__timeout_macrop = 0x6D;
+
+
+
+
+ pdynamic->sd_config__woi_sd0 = 0x05;
+ pdynamic->sd_config__woi_sd1 = 0x07;
+ pdynamic->sd_config__initial_phase_sd0 = 0x05;
+ pdynamic->sd_config__initial_phase_sd1 = 0x05;
+
+
+
+
+
+
+
+
+ phistpostprocess->valid_phase_low = 0x08;
+ phistpostprocess->valid_phase_high = 0x48;
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+
+
+ psystem->system__mode_start = \
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM | \
+ VL53L1_DEVICEREADOUTMODE_DUAL_SD | \
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_medium_range_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_medium_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 1, 2, 2,
+ 8+0, 8+1, 8+2, 1, 2, 3,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 1, 2, 2,
+ 8+0, 8+1, 8+2, 1, 2, 3,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM1_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_medium_range_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_medium_range_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM2_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_short_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 7, 0, 1, 1, 1,
+ 0, 1, 1, 1, 2, 2,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 7, 0, 1, 1, 1,
+ 0, 1, 1, 1, 2, 2,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x03;
+ ptiming->range_config__vcsel_period_b = 0x05;
+
+
+
+
+
+
+ ptiming->mm_config__timeout_macrop_a_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_a_lo = 0x52;
+ ptiming->mm_config__timeout_macrop_b_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_b_lo = 0x37;
+
+
+
+
+ ptiming->range_config__timeout_macrop_a_hi = 0x00;
+ ptiming->range_config__timeout_macrop_a_lo = 0x66;
+ ptiming->range_config__timeout_macrop_b_hi = 0x00;
+ ptiming->range_config__timeout_macrop_b_lo = 0x44;
+
+
+
+
+ pgeneral->cal_config__vcsel_start = 0x03;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pgeneral->phasecal_config__timeout_macrop = 0xA4;
+
+
+
+
+ pdynamic->sd_config__woi_sd0 = 0x03;
+ pdynamic->sd_config__woi_sd1 = 0x05;
+ pdynamic->sd_config__initial_phase_sd0 = 0x03;
+ pdynamic->sd_config__initial_phase_sd1 = 0x03;
+
+
+
+
+
+
+
+
+ phistpostprocess->valid_phase_low = 0x08;
+ phistpostprocess->valid_phase_high = 0x28;
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM1_EN | \
+
+
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+
+
+ psystem->system__mode_start = \
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM | \
+ VL53L1_DEVICEREADOUTMODE_DUAL_SD | \
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_short_range_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_short_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 7, 0, 1, 1, 1,
+ 8+0, 8+1, 1, 1, 2, 2,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 1, 1, 1,
+ 8+0, 8+1, 1, 1, 2, 2,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM1_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_short_range_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_short_range_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM2_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_characterisation(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ pstatic->debug__ctrl = 0x01;
+ psystem->power_management__go1_power_force = 0x01;
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+
+ psystem->system__mode_start = \
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM | \
+ VL53L1_DEVICEREADOUTMODE_SPLIT_MANUAL | \
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_xtalk_planar(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_multizone_long_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ status =
+ VL53L1_zone_preset_xtalk_planar(
+ pgeneral,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+ ptiming->range_config__sigma_thresh = 0x0000;
+
+
+ ptiming->range_config__min_count_rate_rtn_limit_mcps = 0x0000;
+
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x09;
+ ptiming->range_config__vcsel_period_b = 0x09;
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 7, 0, 1, 2, 3, 4,
+ phistogram);
+
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 2, 3, 4,
+
+ 7, 0, 1, 2, 3, 4,
+
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_set_histogram_multizone_initial_bin_config(
+ pzone_cfg,
+ phistogram,
+ &(pzone_cfg->multizone_hist_cfg));
+ }
+
+
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_preset_mode_histogram_xtalk_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+ ptiming->range_config__sigma_thresh = 0x0000;
+
+
+ ptiming->range_config__min_count_rate_rtn_limit_mcps = 0x0000;
+
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 8+7, 8+0, 8+1, 8+2, 8+3, 8+4,
+ 8+7, 8+0, 8+1, 8+2, 8+3, 8+4,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 8+7, 8+0, 8+1, 8+2, 8+3, 8+4,
+ 8+7, 8+0, 8+1, 8+2, 8+3, 8+4,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x09;
+ ptiming->range_config__vcsel_period_b = 0x09;
+
+
+
+
+
+
+ ptiming->mm_config__timeout_macrop_a_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_a_lo = 0x21;
+ ptiming->mm_config__timeout_macrop_b_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_b_lo = 0x21;
+
+
+
+
+ ptiming->range_config__timeout_macrop_a_hi = 0x00;
+ ptiming->range_config__timeout_macrop_a_lo = 0x29;
+ ptiming->range_config__timeout_macrop_b_hi = 0x00;
+ ptiming->range_config__timeout_macrop_b_lo = 0x29;
+
+
+
+
+ pgeneral->cal_config__vcsel_start = 0x09;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pgeneral->phasecal_config__timeout_macrop = 0x42;
+
+
+
+
+ pdynamic->sd_config__woi_sd0 = 0x09;
+ pdynamic->sd_config__woi_sd1 = 0x09;
+ pdynamic->sd_config__initial_phase_sd0 = 0x09;
+ pdynamic->sd_config__initial_phase_sd1 = 0x09;
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM1_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+
+
+ psystem->system__mode_start = \
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM | \
+ VL53L1_DEVICEREADOUTMODE_DUAL_SD | \
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_xtalk_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_xtalk_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+ pdynamic->system__sequence_config = \
+ VL53L1_SEQUENCE_VHV_EN | \
+ VL53L1_SEQUENCE_PHASECAL_EN | \
+ VL53L1_SEQUENCE_DSS1_EN | \
+ VL53L1_SEQUENCE_DSS2_EN | \
+ VL53L1_SEQUENCE_MM2_EN | \
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_multizone(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_medium_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ status =
+ VL53L1_init_zone_config_structure(
+ 4, 8, 2,
+
+ 4, 8, 2,
+
+ 7, 7,
+
+ pzone_cfg);
+
+ pgeneral->global_config__stream_divider =
+ pzone_cfg->active_zones + 1;
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_set_histogram_multizone_initial_bin_config (
+ pzone_cfg,
+ phistogram,
+ &(pzone_cfg->multizone_hist_cfg));
+ }
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_preset_mode_histogram_multizone_short_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_short_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ status =
+ VL53L1_init_zone_config_structure(
+ 4, 8, 2,
+
+ 4, 8, 2,
+
+ 7, 7,
+
+ pzone_cfg);
+
+ pgeneral->global_config__stream_divider =
+ pzone_cfg->active_zones + 1;
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_set_histogram_multizone_initial_bin_config (
+ pzone_cfg,
+ phistogram,
+ &(pzone_cfg->multizone_hist_cfg)
+ );
+ }
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_multizone_long_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_long_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ status =
+ VL53L1_init_zone_config_structure(
+ 4, 8, 2,
+
+ 4, 8, 2,
+
+ 7, 7,
+
+ pzone_cfg);
+
+ pgeneral->global_config__stream_divider =
+ pzone_cfg->active_zones + 1;
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_set_histogram_multizone_initial_bin_config (
+ pzone_cfg,
+ phistogram,
+ &(pzone_cfg->multizone_hist_cfg));
+ }
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_olt(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+ psystem->system__stream_count_ctrl = 0x01;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+void VL53L1_copy_hist_cfg_to_static_cfg(
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic)
+{
+
+
+
+
+
+
+ LOG_FUNCTION_START("");
+
+ SUPPRESS_UNUSED_WARNING(pgeneral);
+
+ pstatic->sigma_estimator__effective_pulse_width_ns =
+ phistogram->histogram_config__high_amb_even_bin_0_1;
+ pstatic->sigma_estimator__effective_ambient_width_ns =
+ phistogram->histogram_config__high_amb_even_bin_2_3;
+ pstatic->sigma_estimator__sigma_ref_mm =
+ phistogram->histogram_config__high_amb_even_bin_4_5;
+
+ pstatic->algo__crosstalk_compensation_valid_height_mm =
+ phistogram->histogram_config__high_amb_odd_bin_0_1;
+
+ pstatic->spare_host_config__static_config_spare_0 =
+ phistogram->histogram_config__high_amb_odd_bin_2_3;
+ pstatic->spare_host_config__static_config_spare_1 =
+ phistogram->histogram_config__high_amb_odd_bin_4_5;
+
+ pstatic->algo__range_ignore_threshold_mcps =
+ (((uint16_t)phistogram->histogram_config__mid_amb_even_bin_0_1) << 8)
+ + (uint16_t)phistogram->histogram_config__mid_amb_even_bin_2_3;
+
+ pstatic->algo__range_ignore_valid_height_mm =
+ phistogram->histogram_config__mid_amb_even_bin_4_5;
+ pstatic->algo__range_min_clip =
+ phistogram->histogram_config__mid_amb_odd_bin_0_1;
+ pstatic->algo__consistency_check__tolerance =
+ phistogram->histogram_config__mid_amb_odd_bin_2;
+
+ pstatic->spare_host_config__static_config_spare_2 =
+ phistogram->histogram_config__mid_amb_odd_bin_3_4;
+ pstatic->sd_config__reset_stages_msb =
+ phistogram->histogram_config__mid_amb_odd_bin_5;
+
+ pstatic->sd_config__reset_stages_lsb =
+ phistogram->histogram_config__user_bin_offset;
+
+ ptiming->range_config__sigma_thresh =
+ (((uint16_t)phistogram->histogram_config__low_amb_even_bin_0_1) << 8)
+ + (uint16_t)phistogram->histogram_config__low_amb_even_bin_2_3;
+
+ ptiming->range_config__min_count_rate_rtn_limit_mcps =
+ (((uint16_t)phistogram->histogram_config__low_amb_even_bin_4_5) << 8)
+ + (uint16_t)phistogram->histogram_config__low_amb_odd_bin_0_1;
+
+ ptiming->range_config__valid_phase_low =
+ phistogram->histogram_config__low_amb_odd_bin_2_3;
+ ptiming->range_config__valid_phase_high =
+ phistogram->histogram_config__low_amb_odd_bin_4_5;
+
+ pdynamic->system__thresh_high =
+ phistogram->histogram_config__amb_thresh_low;
+
+ pdynamic->system__thresh_low =
+ phistogram->histogram_config__amb_thresh_high;
+
+ pdynamic->system__enable_xtalk_per_quadrant =
+ phistogram->histogram_config__spad_array_selection;
+
+ LOG_FUNCTION_END(0);
+
+}
+
+void VL53L1_copy_hist_bins_to_static_cfg(
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_timing_config_t *ptiming
+ )
+{
+
+
+
+
+
+
+ LOG_FUNCTION_START("");
+
+ pstatic->sigma_estimator__effective_pulse_width_ns =
+ phistogram->histogram_config__high_amb_even_bin_0_1;
+ pstatic->sigma_estimator__effective_ambient_width_ns =
+ phistogram->histogram_config__high_amb_even_bin_2_3;
+ pstatic->sigma_estimator__sigma_ref_mm =
+ phistogram->histogram_config__high_amb_even_bin_4_5;
+
+ pstatic->algo__crosstalk_compensation_valid_height_mm =
+ phistogram->histogram_config__high_amb_odd_bin_0_1;
+
+ pstatic->spare_host_config__static_config_spare_0 =
+ phistogram->histogram_config__high_amb_odd_bin_2_3;
+ pstatic->spare_host_config__static_config_spare_1 =
+ phistogram->histogram_config__high_amb_odd_bin_4_5;
+
+ pstatic->algo__range_ignore_threshold_mcps =
+ (((uint16_t)phistogram->histogram_config__mid_amb_even_bin_0_1) << 8)
+ + (uint16_t)phistogram->histogram_config__mid_amb_even_bin_2_3;
+
+ pstatic->algo__range_ignore_valid_height_mm =
+ phistogram->histogram_config__mid_amb_even_bin_4_5;
+ pstatic->algo__range_min_clip =
+ phistogram->histogram_config__mid_amb_odd_bin_0_1;
+ pstatic->algo__consistency_check__tolerance =
+ phistogram->histogram_config__mid_amb_odd_bin_2;
+
+ pstatic->spare_host_config__static_config_spare_2 =
+ phistogram->histogram_config__mid_amb_odd_bin_3_4;
+ pstatic->sd_config__reset_stages_msb =
+ phistogram->histogram_config__mid_amb_odd_bin_5;
+
+ ptiming->range_config__sigma_thresh =
+ (((uint16_t)phistogram->histogram_config__low_amb_even_bin_0_1) << 8)
+ + (uint16_t)phistogram->histogram_config__low_amb_even_bin_2_3;
+
+ ptiming->range_config__min_count_rate_rtn_limit_mcps =
+ (((uint16_t)phistogram->histogram_config__low_amb_even_bin_4_5) << 8)
+ + (uint16_t)phistogram->histogram_config__low_amb_odd_bin_0_1;
+
+ ptiming->range_config__valid_phase_low =
+ phistogram->histogram_config__low_amb_odd_bin_2_3;
+ ptiming->range_config__valid_phase_high =
+ phistogram->histogram_config__low_amb_odd_bin_4_5;
+
+ LOG_FUNCTION_END(0);
+
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_ref(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ phistogram->histogram_config__spad_array_selection = 0x00;
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_api_strings.c b/drivers/input/misc/vl53L1/src/vl53l1_api_strings.c
new file mode 100644
index 000000000000..bdab77694bbc
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_api_strings.c
@@ -0,0 +1,333 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_api_core.h"
+#include "vl53l1_api_strings.h"
+#include "vl53l1_error_codes.h"
+#include "vl53l1_error_strings.h"
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, status, fmt, \
+ ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_get_range_status_string(
+ uint8_t RangeStatus,
+ char *pRangeStatusString)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+#ifdef VL53L1_USE_EMPTY_STRING
+ VL53L1_COPYSTRING(pRangeStatusString, "");
+#else
+ switch (RangeStatus) {
+ case 0:
+ VL53L1_COPYSTRING(pRangeStatusString,
+ VL53L1_STRING_RANGESTATUS_RANGEVALID);
+ break;
+ case 1:
+ VL53L1_COPYSTRING(pRangeStatusString,
+ VL53L1_STRING_RANGESTATUS_SIGMA);
+ break;
+ case 2:
+ VL53L1_COPYSTRING(pRangeStatusString,
+ VL53L1_STRING_RANGESTATUS_SIGNAL);
+ break;
+ case 3:
+ VL53L1_COPYSTRING(pRangeStatusString,
+ VL53L1_STRING_RANGESTATUS_MINRANGE);
+ break;
+ case 4:
+ VL53L1_COPYSTRING(pRangeStatusString,
+ VL53L1_STRING_RANGESTATUS_PHASE);
+ break;
+ case 5:
+ VL53L1_COPYSTRING(pRangeStatusString,
+ VL53L1_STRING_RANGESTATUS_HW);
+ break;
+
+ default:
+
+ VL53L1_COPYSTRING(pRangeStatusString,
+ VL53L1_STRING_RANGESTATUS_NONE);
+ }
+#endif
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_pal_state_string(
+ VL53L1_State PalStateCode,
+ char *pPalStateString)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+#ifdef VL53L1_USE_EMPTY_STRING
+ VL53L1_COPYSTRING(pPalStateString, "");
+#else
+ switch (PalStateCode) {
+ case VL53L1_STATE_POWERDOWN:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_POWERDOWN);
+ break;
+ case VL53L1_STATE_WAIT_STATICINIT:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_WAIT_STATICINIT);
+ break;
+ case VL53L1_STATE_STANDBY:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_STANDBY);
+ break;
+ case VL53L1_STATE_IDLE:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_IDLE);
+ break;
+ case VL53L1_STATE_RUNNING:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_RUNNING);
+ break;
+ case VL53L1_STATE_RESET:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_RESET);
+ break;
+ case VL53L1_STATE_UNKNOWN:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_UNKNOWN);
+ break;
+ case VL53L1_STATE_ERROR:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_ERROR);
+ break;
+
+ default:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_UNKNOWN);
+ }
+#endif
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+VL53L1_Error VL53L1_get_sequence_steps_info(
+ VL53L1_SequenceStepId SequenceStepId,
+ char *pSequenceStepsString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+#ifdef VL53L1_USE_EMPTY_STRING
+ VL53L1_COPYSTRING(pSequenceStepsString, "");
+#else
+ switch (SequenceStepId) {
+ case VL53L1_SEQUENCESTEP_VHV:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_VHV);
+ break;
+ case VL53L1_SEQUENCESTEP_PHASECAL:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_PHASECAL);
+ break;
+ case VL53L1_SEQUENCESTEP_REFPHASE:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_DSS1);
+ break;
+ case VL53L1_SEQUENCESTEP_DSS1:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_DSS1);
+ break;
+ case VL53L1_SEQUENCESTEP_DSS2:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_DSS2);
+ break;
+ case VL53L1_SEQUENCESTEP_MM1:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_MM1);
+ break;
+ case VL53L1_SEQUENCESTEP_MM2:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_MM2);
+ break;
+ case VL53L1_SEQUENCESTEP_RANGE:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_RANGE);
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+#endif
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+VL53L1_Error VL53L1_get_limit_check_info(uint16_t LimitCheckId,
+ char *pLimitCheckString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+#ifdef VL53L1_USE_EMPTY_STRING
+ VL53L1_COPYSTRING(pLimitCheckString, "");
+#else
+ switch (LimitCheckId) {
+ case VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE:
+ VL53L1_COPYSTRING(pLimitCheckString,
+ VL53L1_STRING_CHECKENABLE_SIGMA_FINAL_RANGE);
+ break;
+ case VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+ VL53L1_COPYSTRING(pLimitCheckString,
+ VL53L1_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE);
+ break;
+ default:
+ VL53L1_COPYSTRING(pLimitCheckString,
+ VL53L1_STRING_UNKNOW_ERROR_CODE);
+ }
+#endif
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_core.c b/drivers/input/misc/vl53L1/src/vl53l1_core.c
new file mode 100644
index 000000000000..405182db0ec4
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_core.c
@@ -0,0 +1,3961 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#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_hist_structs.h"
+#include "vl53l1_api_preset_modes.h"
+#include "vl53l1_core.h"
+
+
+
+
+
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, \
+ status, fmt, ##__VA_ARGS__)
+
+#define trace_print(level, ...) \
+ _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_CORE, \
+ level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+
+
+void VL53L1_init_version(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ pdev->version.ll_major = VL53L1_LL_API_IMPLEMENTATION_VER_MAJOR;
+ pdev->version.ll_minor = VL53L1_LL_API_IMPLEMENTATION_VER_MINOR;
+ pdev->version.ll_build = VL53L1_LL_API_IMPLEMENTATION_VER_SUB;
+ pdev->version.ll_revision = VL53L1_LL_API_IMPLEMENTATION_VER_REVISION;
+}
+
+
+void VL53L1_init_ll_driver_state(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceState device_state)
+{
+
+
+
+
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+
+ pstate->cfg_device_state = device_state;
+ pstate->cfg_stream_count = 0;
+ pstate->cfg_gph_id = VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+ pstate->cfg_timing_status = 0;
+ pstate->cfg_zone_id = 0;
+
+ pstate->rd_device_state = device_state;
+ pstate->rd_stream_count = 0;
+ pstate->rd_gph_id = VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+ pstate->rd_timing_status = 0;
+ pstate->rd_zone_id = 0;
+
+}
+
+
+VL53L1_Error VL53L1_update_ll_driver_rd_state(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+
+
+
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ if ((pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICEMEASUREMENTMODE_MODE_MASK) == 0x00) {
+
+ pstate->rd_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
+ pstate->rd_stream_count = 0;
+ pstate->rd_internal_stream_count = 0;
+ pstate->rd_internal_stream_count_val = 0;
+ pstate->rd_gph_id = VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+ pstate->rd_timing_status = 0;
+ pstate->rd_zone_id = 0;
+
+ } else {
+
+
+
+
+
+
+ if (pstate->rd_stream_count == 0xFF) {
+ pstate->rd_stream_count = 0x80;
+ } else {
+ pstate->rd_stream_count++;
+ }
+
+
+
+
+
+ status = VL53L1_update_internal_stream_counters(Dev,
+ pstate->rd_stream_count,
+ &(pstate->rd_internal_stream_count),
+ &(pstate->rd_internal_stream_count_val));
+
+
+
+
+
+
+ pstate->rd_gph_id ^= VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+
+
+
+
+ switch (pstate->rd_device_state) {
+
+ case VL53L1_DEVICESTATE_SW_STANDBY:
+
+ if ((pdev->dyn_cfg.system__grouped_parameter_hold &
+ VL53L1_GROUPEDPARAMETERHOLD_ID_MASK) > 0) {
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC;
+ } else {
+ if (pstate->rd_zone_id >=
+ pdev->zone_cfg.active_zones) {
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA;
+ } else {
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_GATHER_DATA;
+ }
+ }
+
+ pstate->rd_stream_count = 0;
+ pstate->rd_internal_stream_count = 0;
+ pstate->rd_internal_stream_count_val = 0;
+ pstate->rd_timing_status = 0;
+ pstate->rd_zone_id = 0;
+
+ break;
+
+ case VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC:
+ pstate->rd_stream_count = 0;
+ pstate->rd_internal_stream_count = 0;
+ pstate->rd_internal_stream_count_val = 0;
+ pstate->rd_zone_id = 0;
+ if (pstate->rd_zone_id >=
+ pdev->zone_cfg.active_zones) {
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA;
+ } else {
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_GATHER_DATA;
+ }
+ break;
+
+ case VL53L1_DEVICESTATE_RANGING_GATHER_DATA:
+ pstate->rd_zone_id++;
+ if (pstate->rd_zone_id >=
+ pdev->zone_cfg.active_zones) {
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA;
+ } else {
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_GATHER_DATA;
+ }
+ break;
+
+ case VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA:
+ pstate->rd_zone_id = 0;
+ pstate->rd_timing_status ^= 0x01;
+
+ if (pstate->rd_zone_id >=
+ pdev->zone_cfg.active_zones) {
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA;
+ } else {
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_GATHER_DATA;
+ }
+ break;
+
+ default:
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_SW_STANDBY;
+ pstate->rd_stream_count = 0;
+ pstate->rd_internal_stream_count = 0;
+ pstate->rd_internal_stream_count_val = 0;
+ pstate->rd_gph_id = VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+ pstate->rd_timing_status = 0;
+ pstate->rd_zone_id = 0;
+ break;
+ }
+ }
+
+
+
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_check_ll_driver_rd_state(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+ VL53L1_system_results_t *psys_results = &(pdev->sys_results);
+ VL53L1_histogram_bin_data_t *phist_data = &(pdev->hist_data);
+
+ uint8_t device_range_status = 0;
+ uint8_t device_stream_count = 0;
+ uint8_t device_gph_id = 0;
+ uint8_t histogram_mode = 0;
+ uint8_t expected_stream_count = 0;
+ uint8_t expected_gph_id = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ device_range_status =
+ psys_results->result__range_status &
+ VL53L1_RANGE_STATUS__RANGE_STATUS_MASK;
+
+ device_stream_count = psys_results->result__stream_count;
+
+
+
+
+ histogram_mode =
+ (pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM) ==
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM;
+
+
+
+ device_gph_id = (psys_results->result__interrupt_status &
+ VL53L1_INTERRUPT_STATUS__GPH_ID_INT_STATUS_MASK) >> 4;
+
+ if (histogram_mode) {
+ device_gph_id = (phist_data->result__interrupt_status &
+ VL53L1_INTERRUPT_STATUS__GPH_ID_INT_STATUS_MASK) >> 4;
+ }
+
+
+
+
+ if ((pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK) ==
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (pstate->rd_device_state ==
+ VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC) {
+
+ if (histogram_mode == 0) {
+ if (device_range_status !=
+ VL53L1_DEVICEERROR_GPHSTREAMCOUNT0READY) {
+ status = VL53L1_ERROR_GPH_SYNC_CHECK_FAIL;
+ }
+ }
+ } else {
+ if (pstate->rd_stream_count != device_stream_count) {
+ status = VL53L1_ERROR_STREAM_COUNT_CHECK_FAIL;
+ }
+
+
+
+
+
+
+ if (pstate->rd_gph_id != device_gph_id) {
+ status = VL53L1_ERROR_GPH_ID_CHECK_FAIL;
+
+
+
+
+
+
+
+ } else {
+
+
+
+
+
+
+
+ }
+
+
+
+
+
+
+ expected_stream_count =
+ pres->zone_dyn_cfgs.VL53L1_PRM_00005[pstate->rd_zone_id].expected_stream_count;
+ expected_gph_id =
+ pres->zone_dyn_cfgs.VL53L1_PRM_00005[pstate->rd_zone_id].expected_gph_id;
+
+
+
+
+
+
+ if (expected_stream_count != device_stream_count) {
+
+
+
+
+ if ((pdev->zone_cfg.active_zones == 0) &&
+ (device_stream_count == 255)) {
+
+
+
+
+
+
+
+
+ } else {
+ status = VL53L1_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL;
+
+
+
+
+
+
+
+ }
+ }
+
+
+
+
+
+
+ if (expected_gph_id != device_gph_id) {
+ status = VL53L1_ERROR_ZONE_GPH_ID_CHECK_FAIL;
+
+
+
+
+
+
+
+ }
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+ }
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_update_ll_driver_cfg_state(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+
+ uint8_t prev_cfg_zone_id;
+ uint8_t prev_cfg_gph_id;
+ uint8_t prev_cfg_stream_count;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+ if ((pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICEMEASUREMENTMODE_MODE_MASK) == 0x00) {
+
+ pstate->cfg_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
+ pstate->cfg_stream_count = 0;
+ pstate->cfg_internal_stream_count = 0;
+ pstate->cfg_internal_stream_count_val = 0;
+ pstate->cfg_gph_id = VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+ pstate->cfg_timing_status = 0;
+ pstate->cfg_zone_id = 0;
+ prev_cfg_zone_id = 0;
+ prev_cfg_gph_id = 0;
+ prev_cfg_stream_count = 0;
+
+ } else {
+
+
+
+
+ prev_cfg_gph_id = pstate->cfg_gph_id;
+ prev_cfg_zone_id = pstate->cfg_zone_id;
+ prev_cfg_stream_count = pstate->cfg_stream_count;
+
+
+
+
+
+
+ if (pstate->cfg_stream_count == 0xFF) {
+ pstate->cfg_stream_count = 0x80;
+ } else {
+ pstate->cfg_stream_count++;
+ }
+
+
+
+
+
+ status = VL53L1_update_internal_stream_counters(
+ Dev,
+ pstate->cfg_stream_count,
+ &(pstate->cfg_internal_stream_count),
+ &(pstate->cfg_internal_stream_count_val));
+
+
+
+
+
+
+ pstate->cfg_gph_id ^= VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+
+
+
+
+
+
+ switch (pstate->cfg_device_state) {
+
+ case VL53L1_DEVICESTATE_SW_STANDBY:
+ pstate->cfg_zone_id = 1;
+ if (pstate->cfg_zone_id >
+ pdev->zone_cfg.active_zones) {
+ pstate->cfg_zone_id = 0;
+ pstate->cfg_timing_status ^= 0x01;
+ }
+ pstate->cfg_stream_count = 1;
+
+ if (pdev->gen_cfg.global_config__stream_divider == 0) {
+ pstate->cfg_internal_stream_count = 1;
+ pstate->cfg_internal_stream_count_val = 0;
+ } else {
+ pstate->cfg_internal_stream_count = 0;
+ pstate->cfg_internal_stream_count_val = 1;
+ }
+ pstate->cfg_device_state = VL53L1_DEVICESTATE_RANGING_DSS_AUTO;
+ break;
+
+ case VL53L1_DEVICESTATE_RANGING_DSS_AUTO:
+ pstate->cfg_zone_id++;
+ if (pstate->cfg_zone_id >
+ pdev->zone_cfg.active_zones) {
+
+ pstate->cfg_zone_id = 0;
+ pstate->cfg_timing_status ^= 0x01;
+
+
+
+
+
+
+ if (pdev->zone_cfg.active_zones > 0) {
+ pstate->cfg_device_state =
+ VL53L1_DEVICESTATE_RANGING_DSS_MANUAL;
+ }
+ }
+ break;
+
+ case VL53L1_DEVICESTATE_RANGING_DSS_MANUAL:
+ pstate->cfg_zone_id++;
+ if (pstate->cfg_zone_id >
+ pdev->zone_cfg.active_zones) {
+ pstate->cfg_zone_id = 0;
+ pstate->cfg_timing_status ^= 0x01;
+ }
+ break;
+
+ default:
+ pstate->cfg_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
+ pstate->cfg_stream_count = 0;
+ pstate->cfg_internal_stream_count = 0;
+ pstate->cfg_internal_stream_count_val = 0;
+ pstate->cfg_gph_id = VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+ pstate->cfg_timing_status = 0;
+ pstate->cfg_zone_id = 0;
+ break;
+ }
+ }
+
+
+
+
+
+
+ if (pdev->zone_cfg.active_zones == 0) {
+
+
+
+
+
+ pres->zone_dyn_cfgs.VL53L1_PRM_00005[prev_cfg_zone_id].expected_stream_count =
+ prev_cfg_stream_count - 1;
+
+ pres->zone_dyn_cfgs.VL53L1_PRM_00005[pstate->rd_zone_id].expected_gph_id =
+ prev_cfg_gph_id ^ VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+ } else {
+ pres->zone_dyn_cfgs.VL53L1_PRM_00005[prev_cfg_zone_id].expected_stream_count =
+ prev_cfg_stream_count;
+ pres->zone_dyn_cfgs.VL53L1_PRM_00005[prev_cfg_zone_id].expected_gph_id =
+ prev_cfg_gph_id;
+ }
+
+
+
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+void VL53L1_copy_rtn_good_spads_to_buffer(
+ VL53L1_nvm_copy_data_t *pdata,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+ *(pbuffer + 0) = pdata->global_config__spad_enables_rtn_0;
+ *(pbuffer + 1) = pdata->global_config__spad_enables_rtn_1;
+ *(pbuffer + 2) = pdata->global_config__spad_enables_rtn_2;
+ *(pbuffer + 3) = pdata->global_config__spad_enables_rtn_3;
+ *(pbuffer + 4) = pdata->global_config__spad_enables_rtn_4;
+ *(pbuffer + 5) = pdata->global_config__spad_enables_rtn_5;
+ *(pbuffer + 6) = pdata->global_config__spad_enables_rtn_6;
+ *(pbuffer + 7) = pdata->global_config__spad_enables_rtn_7;
+ *(pbuffer + 8) = pdata->global_config__spad_enables_rtn_8;
+ *(pbuffer + 9) = pdata->global_config__spad_enables_rtn_9;
+ *(pbuffer + 10) = pdata->global_config__spad_enables_rtn_10;
+ *(pbuffer + 11) = pdata->global_config__spad_enables_rtn_11;
+ *(pbuffer + 12) = pdata->global_config__spad_enables_rtn_12;
+ *(pbuffer + 13) = pdata->global_config__spad_enables_rtn_13;
+ *(pbuffer + 14) = pdata->global_config__spad_enables_rtn_14;
+ *(pbuffer + 15) = pdata->global_config__spad_enables_rtn_15;
+ *(pbuffer + 16) = pdata->global_config__spad_enables_rtn_16;
+ *(pbuffer + 17) = pdata->global_config__spad_enables_rtn_17;
+ *(pbuffer + 18) = pdata->global_config__spad_enables_rtn_18;
+ *(pbuffer + 19) = pdata->global_config__spad_enables_rtn_19;
+ *(pbuffer + 20) = pdata->global_config__spad_enables_rtn_20;
+ *(pbuffer + 21) = pdata->global_config__spad_enables_rtn_21;
+ *(pbuffer + 22) = pdata->global_config__spad_enables_rtn_22;
+ *(pbuffer + 23) = pdata->global_config__spad_enables_rtn_23;
+ *(pbuffer + 24) = pdata->global_config__spad_enables_rtn_24;
+ *(pbuffer + 25) = pdata->global_config__spad_enables_rtn_25;
+ *(pbuffer + 26) = pdata->global_config__spad_enables_rtn_26;
+ *(pbuffer + 27) = pdata->global_config__spad_enables_rtn_27;
+ *(pbuffer + 28) = pdata->global_config__spad_enables_rtn_28;
+ *(pbuffer + 29) = pdata->global_config__spad_enables_rtn_29;
+ *(pbuffer + 30) = pdata->global_config__spad_enables_rtn_30;
+ *(pbuffer + 31) = pdata->global_config__spad_enables_rtn_31;
+}
+
+
+void VL53L1_init_system_results(
+ VL53L1_system_results_t *pdata)
+{
+
+
+
+
+
+
+ pdata->result__interrupt_status = 0xFF;
+ pdata->result__range_status = 0xFF;
+ pdata->result__report_status = 0xFF;
+ pdata->result__stream_count = 0xFF;
+
+ pdata->result__dss_actual_effective_spads_sd0 = 0xFFFF;
+ pdata->result__peak_signal_count_rate_mcps_sd0 = 0xFFFF;
+ pdata->result__ambient_count_rate_mcps_sd0 = 0xFFFF;
+ pdata->result__sigma_sd0 = 0xFFFF;
+ pdata->result__phase_sd0 = 0xFFFF;
+ pdata->result__final_crosstalk_corrected_range_mm_sd0 = 0xFFFF;
+ pdata->result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0 =
+ 0xFFFF;
+ pdata->result__mm_inner_actual_effective_spads_sd0 = 0xFFFF;
+ pdata->result__mm_outer_actual_effective_spads_sd0 = 0xFFFF;
+ pdata->result__avg_signal_count_rate_mcps_sd0 = 0xFFFF;
+
+ pdata->result__dss_actual_effective_spads_sd1 = 0xFFFF;
+ pdata->result__peak_signal_count_rate_mcps_sd1 = 0xFFFF;
+ pdata->result__ambient_count_rate_mcps_sd1 = 0xFFFF;
+ pdata->result__sigma_sd1 = 0xFFFF;
+ pdata->result__phase_sd1 = 0xFFFF;
+ pdata->result__final_crosstalk_corrected_range_mm_sd1 = 0xFFFF;
+ pdata->result__spare_0_sd1 = 0xFFFF;
+ pdata->result__spare_1_sd1 = 0xFFFF;
+ pdata->result__spare_2_sd1 = 0xFFFF;
+ pdata->result__spare_3_sd1 = 0xFF;
+
+}
+
+
+void V53L1_init_zone_results_structure(
+ uint8_t active_zones,
+ VL53L1_zone_results_t *pdata)
+{
+
+
+
+
+ uint8_t z = 0;
+ VL53L1_zone_objects_t *pobjects;
+
+ pdata->max_zones = VL53L1_MAX_USER_ZONES;
+ pdata->active_zones = active_zones;
+
+ for (z = 0 ; z < pdata->max_zones ; z++) {
+ pobjects = &(pdata->VL53L1_PRM_00005[z]);
+ pobjects->cfg_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
+ pobjects->rd_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
+ pobjects->max_objects = VL53L1_MAX_RANGE_RESULTS;
+ pobjects->active_objects = 0;
+ }
+}
+
+
+void VL53L1_init_histogram_config_structure(
+ uint8_t even_bin0,
+ uint8_t even_bin1,
+ uint8_t even_bin2,
+ uint8_t even_bin3,
+ uint8_t even_bin4,
+ uint8_t even_bin5,
+ uint8_t odd_bin0,
+ uint8_t odd_bin1,
+ uint8_t odd_bin2,
+ uint8_t odd_bin3,
+ uint8_t odd_bin4,
+ uint8_t odd_bin5,
+ VL53L1_histogram_config_t *pdata)
+{
+
+
+
+
+
+
+ pdata->histogram_config__low_amb_even_bin_0_1 = (even_bin1 << 4) + even_bin0;
+ pdata->histogram_config__low_amb_even_bin_2_3 = (even_bin3 << 4) + even_bin2;
+ pdata->histogram_config__low_amb_even_bin_4_5 = (even_bin5 << 4) + even_bin4;
+
+ pdata->histogram_config__low_amb_odd_bin_0_1 = (odd_bin1 << 4) + odd_bin0;
+ pdata->histogram_config__low_amb_odd_bin_2_3 = (odd_bin3 << 4) + odd_bin2;
+ pdata->histogram_config__low_amb_odd_bin_4_5 = (odd_bin5 << 4) + odd_bin4;
+
+ pdata->histogram_config__mid_amb_even_bin_0_1 = pdata->histogram_config__low_amb_even_bin_0_1;
+ pdata->histogram_config__mid_amb_even_bin_2_3 = pdata->histogram_config__low_amb_even_bin_2_3;
+ pdata->histogram_config__mid_amb_even_bin_4_5 = pdata->histogram_config__low_amb_even_bin_4_5;
+
+ pdata->histogram_config__mid_amb_odd_bin_0_1 = pdata->histogram_config__low_amb_odd_bin_0_1;
+ pdata->histogram_config__mid_amb_odd_bin_2 = odd_bin2;
+ pdata->histogram_config__mid_amb_odd_bin_3_4 = (odd_bin4 << 4) + odd_bin3;
+ pdata->histogram_config__mid_amb_odd_bin_5 = odd_bin5;
+
+ pdata->histogram_config__user_bin_offset = 0x00;
+
+ pdata->histogram_config__high_amb_even_bin_0_1 = pdata->histogram_config__low_amb_even_bin_0_1;
+ pdata->histogram_config__high_amb_even_bin_2_3 = pdata->histogram_config__low_amb_even_bin_2_3;
+ pdata->histogram_config__high_amb_even_bin_4_5 = pdata->histogram_config__low_amb_even_bin_4_5;
+
+ pdata->histogram_config__high_amb_odd_bin_0_1 = pdata->histogram_config__low_amb_odd_bin_0_1;
+ pdata->histogram_config__high_amb_odd_bin_2_3 = pdata->histogram_config__low_amb_odd_bin_2_3;
+ pdata->histogram_config__high_amb_odd_bin_4_5 = pdata->histogram_config__low_amb_odd_bin_4_5;
+
+
+
+
+ pdata->histogram_config__amb_thresh_low = 0xFFFF;
+ pdata->histogram_config__amb_thresh_high = 0xFFFF;
+
+
+
+
+ pdata->histogram_config__spad_array_selection = 0x00;
+
+}
+
+void VL53L1_init_histogram_multizone_config_structure(
+ uint8_t even_bin0,
+ uint8_t even_bin1,
+ uint8_t even_bin2,
+ uint8_t even_bin3,
+ uint8_t even_bin4,
+ uint8_t even_bin5,
+ uint8_t odd_bin0,
+ uint8_t odd_bin1,
+ uint8_t odd_bin2,
+ uint8_t odd_bin3,
+ uint8_t odd_bin4,
+ uint8_t odd_bin5,
+ VL53L1_histogram_config_t *pdata)
+{
+
+
+
+
+
+
+
+ pdata->histogram_config__low_amb_even_bin_0_1 = (even_bin1 << 4) + even_bin0;
+ pdata->histogram_config__low_amb_even_bin_2_3 = (even_bin3 << 4) + even_bin2;
+ pdata->histogram_config__low_amb_even_bin_4_5 = (even_bin5 << 4) + even_bin4;
+
+ pdata->histogram_config__low_amb_odd_bin_0_1 =
+ pdata->histogram_config__low_amb_even_bin_0_1;
+ pdata->histogram_config__low_amb_odd_bin_2_3
+ = pdata->histogram_config__low_amb_even_bin_2_3;
+ pdata->histogram_config__low_amb_odd_bin_4_5
+ = pdata->histogram_config__low_amb_even_bin_4_5;
+
+ pdata->histogram_config__mid_amb_even_bin_0_1 =
+ pdata->histogram_config__low_amb_even_bin_0_1;
+ pdata->histogram_config__mid_amb_even_bin_2_3
+ = pdata->histogram_config__low_amb_even_bin_2_3;
+ pdata->histogram_config__mid_amb_even_bin_4_5
+ = pdata->histogram_config__low_amb_even_bin_4_5;
+
+ pdata->histogram_config__mid_amb_odd_bin_0_1
+ = pdata->histogram_config__low_amb_odd_bin_0_1;
+ pdata->histogram_config__mid_amb_odd_bin_2 = odd_bin2;
+ pdata->histogram_config__mid_amb_odd_bin_3_4 = (odd_bin4 << 4) + odd_bin3;
+ pdata->histogram_config__mid_amb_odd_bin_5 = odd_bin5;
+
+ pdata->histogram_config__user_bin_offset = 0x00;
+
+ pdata->histogram_config__high_amb_even_bin_0_1 = (odd_bin1 << 4) + odd_bin0;
+ pdata->histogram_config__high_amb_even_bin_2_3 = (odd_bin3 << 4) + odd_bin2;
+ pdata->histogram_config__high_amb_even_bin_4_5 = (odd_bin5 << 4) + odd_bin4;
+
+ pdata->histogram_config__high_amb_odd_bin_0_1
+ = pdata->histogram_config__high_amb_even_bin_0_1;
+ pdata->histogram_config__high_amb_odd_bin_2_3
+ = pdata->histogram_config__high_amb_even_bin_2_3;
+ pdata->histogram_config__high_amb_odd_bin_4_5
+ = pdata->histogram_config__high_amb_even_bin_4_5;
+
+
+
+
+ pdata->histogram_config__amb_thresh_low = 0xFFFF;
+ pdata->histogram_config__amb_thresh_high = 0xFFFF;
+
+
+
+
+ pdata->histogram_config__spad_array_selection = 0x00;
+}
+
+
+void VL53L1_init_xtalk_bin_data_struct(
+ uint32_t bin_value,
+ uint16_t VL53L1_PRM_00017,
+ VL53L1_xtalk_histogram_shape_t *pdata)
+{
+
+
+
+
+
+
+ uint16_t i = 0;
+
+ pdata->zone_id = 0;
+ pdata->time_stamp = 0;
+
+ pdata->VL53L1_PRM_00015 = 0;
+ pdata->VL53L1_PRM_00016 = VL53L1_XTALK_HISTO_BINS;
+ pdata->VL53L1_PRM_00017 = (uint8_t)VL53L1_PRM_00017;
+
+ pdata->phasecal_result__reference_phase = 0;
+ pdata->phasecal_result__vcsel_start = 0;
+ pdata->cal_config__vcsel_start = 0;
+
+ pdata->vcsel_width = 0;
+ pdata->VL53L1_PRM_00018 = 0;
+
+ pdata->zero_distance_phase = 0;
+
+ for (i = 0 ; i < VL53L1_XTALK_HISTO_BINS; i++) {
+ if (i < VL53L1_PRM_00017) {
+ pdata->bin_data[i] = bin_value;
+ } else {
+ pdata->bin_data[i] = 0;
+ }
+ }
+}
+
+
+void VL53L1_i2c_encode_uint16_t(
+ uint16_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ uint16_t i = 0;
+ uint16_t VL53L1_PRM_00005 = 0;
+
+ VL53L1_PRM_00005 = ip_value;
+
+ for (i = 0; i < count ; i++) {
+ pbuffer[count-i-1] = (uint8_t)(VL53L1_PRM_00005 & 0x00FF);
+ VL53L1_PRM_00005 = VL53L1_PRM_00005 >> 8;
+ }
+}
+
+uint16_t VL53L1_i2c_decode_uint16_t(
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ uint16_t value = 0x00;
+
+ while (count-- > 0) {
+ value = (value << 8) | (uint16_t)*pbuffer++;
+ }
+
+ return value;
+}
+
+
+void VL53L1_i2c_encode_int16_t(
+ int16_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ uint16_t i = 0;
+ int16_t VL53L1_PRM_00005 = 0;
+
+ VL53L1_PRM_00005 = ip_value;
+
+ for (i = 0; i < count ; i++) {
+ pbuffer[count-i-1] = (uint8_t)(VL53L1_PRM_00005 & 0x00FF);
+ VL53L1_PRM_00005 = VL53L1_PRM_00005 >> 8;
+ }
+}
+
+int16_t VL53L1_i2c_decode_int16_t(
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ int16_t value = 0x00;
+
+
+
+ if (*pbuffer >= 0x80) {
+ value = 0xFFFF;
+ }
+
+ while (count-- > 0) {
+ value = (value << 8) | (int16_t)*pbuffer++;
+ }
+
+ return value;
+}
+
+void VL53L1_i2c_encode_uint32_t(
+ uint32_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ uint16_t i = 0;
+ uint32_t VL53L1_PRM_00005 = 0;
+
+ VL53L1_PRM_00005 = ip_value;
+
+ for (i = 0; i < count ; i++) {
+ pbuffer[count-i-1] = (uint8_t)(VL53L1_PRM_00005 & 0x00FF);
+ VL53L1_PRM_00005 = VL53L1_PRM_00005 >> 8;
+ }
+}
+
+uint32_t VL53L1_i2c_decode_uint32_t(
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ uint32_t value = 0x00;
+
+ while (count-- > 0) {
+ value = (value << 8) | (uint32_t)*pbuffer++;
+ }
+
+ return value;
+}
+
+
+uint32_t VL53L1_i2c_decode_with_mask(
+ uint16_t count,
+ uint8_t *pbuffer,
+ uint32_t bit_mask,
+ uint32_t down_shift,
+ uint32_t offset)
+{
+
+
+
+
+
+
+ uint32_t value = 0x00;
+
+
+
+ while (count-- > 0) {
+ value = (value << 8) | (uint32_t)*pbuffer++;
+ }
+
+
+
+ value = value & bit_mask;
+ if (down_shift > 0) {
+ value = value >> down_shift;
+ }
+
+
+
+ value = value + offset;
+
+ return value;
+}
+
+
+void VL53L1_i2c_encode_int32_t(
+ int32_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ uint16_t i = 0;
+ int32_t VL53L1_PRM_00005 = 0;
+
+ VL53L1_PRM_00005 = ip_value;
+
+ for (i = 0; i < count ; i++) {
+ pbuffer[count-i-1] = (uint8_t)(VL53L1_PRM_00005 & 0x00FF);
+ VL53L1_PRM_00005 = VL53L1_PRM_00005 >> 8;
+ }
+}
+
+int32_t VL53L1_i2c_decode_int32_t(
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ int32_t value = 0x00;
+
+
+
+ if (*pbuffer >= 0x80) {
+ value = 0xFFFFFFFF;
+ }
+
+ while (count-- > 0) {
+ value = (value << 8) | (int32_t)*pbuffer++;
+ }
+
+ return value;
+}
+
+
+VL53L1_Error VL53L1_start_test(
+ VL53L1_DEV Dev,
+ uint8_t test_mode__ctrl)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_TEST_MODE__CTRL,
+ test_mode__ctrl);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_firmware_enable_register(
+ VL53L1_DEV Dev,
+ uint8_t value)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ pdev->sys_ctrl.firmware__enable = value;
+
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_FIRMWARE__ENABLE,
+ pdev->sys_ctrl.firmware__enable);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_enable_firmware(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status = VL53L1_set_firmware_enable_register(Dev, 0x01);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_disable_firmware(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status = VL53L1_set_firmware_enable_register(Dev, 0x00);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_powerforce_register(
+ VL53L1_DEV Dev,
+ uint8_t value)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ pdev->sys_ctrl.power_management__go1_power_force = value;
+
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_POWER_MANAGEMENT__GO1_POWER_FORCE,
+ pdev->sys_ctrl.power_management__go1_power_force);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_enable_powerforce(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status = VL53L1_set_powerforce_register(Dev, 0x01);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_disable_powerforce(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status = VL53L1_set_powerforce_register(Dev, 0x00);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_clear_interrupt(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->sys_ctrl.system__interrupt_clear = VL53L1_CLEAR_RANGE_INT;
+
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_SYSTEM__INTERRUPT_CLEAR,
+ pdev->sys_ctrl.system__interrupt_clear);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_force_shadow_stream_count_to_zero(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status = VL53L1_disable_firmware(Dev);
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_SHADOW_RESULT__STREAM_COUNT,
+ 0x00);
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_enable_firmware(Dev);
+ }
+
+ return status;
+}
+
+
+uint32_t VL53L1_calc_macro_period_us(
+ uint16_t fast_osc_frequency,
+ uint8_t VL53L1_PRM_00007)
+{
+
+
+
+
+
+
+
+
+ uint32_t pll_period_us = 0;
+ uint8_t VL53L1_PRM_00028 = 0;
+ uint32_t macro_period_us = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ pll_period_us = VL53L1_calc_pll_period_us(fast_osc_frequency);
+
+
+
+
+
+
+ VL53L1_PRM_00028 = VL53L1_decode_vcsel_period(VL53L1_PRM_00007);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ macro_period_us =
+ (uint32_t)VL53L1_MACRO_PERIOD_VCSEL_PERIODS *
+ pll_period_us;
+ macro_period_us = macro_period_us >> 6;
+
+ macro_period_us = macro_period_us * (uint32_t)VL53L1_PRM_00028;
+ macro_period_us = macro_period_us >> 6;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ LOG_FUNCTION_END(0);
+
+ return macro_period_us;
+}
+
+
+uint16_t VL53L1_calc_range_ignore_threshold(
+ uint16_t central_rate,
+ int16_t x_gradient,
+ int16_t y_gradient,
+ uint8_t rate_mult)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ int32_t range_ignore_thresh_int = 0;
+ uint16_t range_ignore_thresh_kcps = 0;
+ int32_t central_rate_int = 0;
+ int16_t x_gradient_int = 0;
+ int16_t y_gradient_int = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ central_rate_int = ((int32_t)central_rate * (1 << 4)) / (1000);
+
+ if (x_gradient < 0) {
+ x_gradient_int = x_gradient * -1;
+ }
+
+ if (y_gradient < 0) {
+ y_gradient_int = y_gradient * -1;
+ }
+
+
+
+
+
+
+
+
+ range_ignore_thresh_int = (8 * x_gradient_int * 4) + (8 * y_gradient_int * 4);
+
+
+
+
+ range_ignore_thresh_int = range_ignore_thresh_int / 1000;
+
+
+
+
+ range_ignore_thresh_int = range_ignore_thresh_int + central_rate_int;
+
+
+
+
+ range_ignore_thresh_int = (int32_t)rate_mult * range_ignore_thresh_int;
+
+ range_ignore_thresh_int = (range_ignore_thresh_int + (1<<4)) / (1<<5);
+
+
+
+
+ if (range_ignore_thresh_int > 0xFFFF) {
+ range_ignore_thresh_kcps = 0xFFFF;
+ } else {
+ range_ignore_thresh_kcps = (uint16_t)range_ignore_thresh_int;
+ }
+
+
+
+
+
+
+
+ LOG_FUNCTION_END(0);
+
+ return range_ignore_thresh_kcps;
+}
+
+
+uint32_t VL53L1_calc_timeout_mclks(
+ uint32_t timeout_us,
+ uint32_t macro_period_us)
+{
+
+
+
+
+
+
+
+
+
+
+ uint32_t timeout_mclks = 0;
+
+ LOG_FUNCTION_START("");
+
+ timeout_mclks =
+ ((timeout_us << 12) + (macro_period_us>>1)) /
+ macro_period_us;
+
+ LOG_FUNCTION_END(0);
+
+ return timeout_mclks;
+}
+
+
+uint16_t VL53L1_calc_encoded_timeout(
+ uint32_t timeout_us,
+ uint32_t macro_period_us)
+{
+
+
+
+
+
+
+
+
+
+
+ uint32_t timeout_mclks = 0;
+ uint16_t timeout_encoded = 0;
+
+ LOG_FUNCTION_START("");
+
+ timeout_mclks =
+ VL53L1_calc_timeout_mclks(timeout_us, macro_period_us);
+
+ timeout_encoded =
+ VL53L1_encode_timeout(timeout_mclks);
+
+
+
+
+
+
+
+
+
+
+ LOG_FUNCTION_END(0);
+
+ return timeout_encoded;
+}
+
+
+uint32_t VL53L1_calc_timeout_us(
+ uint32_t timeout_mclks,
+ uint32_t macro_period_us)
+{
+
+
+
+
+
+
+
+
+
+
+ uint32_t timeout_us = 0;
+ uint64_t tmp = 0;
+
+ LOG_FUNCTION_START("");
+
+ tmp = (uint64_t)timeout_mclks * (uint64_t)macro_period_us;
+ tmp += 0x00800;
+ tmp = tmp >> 12;
+
+ timeout_us = (uint32_t)tmp;
+
+
+
+
+
+
+
+
+
+
+
+ LOG_FUNCTION_END(0);
+
+ return timeout_us;
+}
+
+uint16_t VL53L1_calc_crosstalk_plane_offset_with_margin(
+ uint16_t plane_offset_kcps,
+ int16_t margin_offset_kcps)
+{
+ uint16_t plane_offset_with_margin = 0;
+ int32_t plane_offset_kcps_temp = 0;
+
+ LOG_FUNCTION_START("");
+
+ plane_offset_kcps_temp =
+ (int32_t)plane_offset_kcps +
+ (int32_t)margin_offset_kcps;
+
+ if (plane_offset_kcps_temp < 0) {
+ plane_offset_kcps_temp = 0;
+ } else {
+ if (plane_offset_kcps_temp > 0xFFFF) {
+ plane_offset_kcps_temp = 0xFFFF;
+ }
+ }
+
+ plane_offset_with_margin = (uint16_t) plane_offset_kcps_temp;
+
+ LOG_FUNCTION_END(0);
+
+ return plane_offset_with_margin;
+
+}
+
+uint32_t VL53L1_calc_decoded_timeout_us(
+ uint16_t timeout_encoded,
+ uint32_t macro_period_us)
+{
+
+
+
+
+
+
+
+
+
+
+ uint32_t timeout_mclks = 0;
+ uint32_t timeout_us = 0;
+
+ LOG_FUNCTION_START("");
+
+ timeout_mclks =
+ VL53L1_decode_timeout(timeout_encoded);
+
+ timeout_us =
+ VL53L1_calc_timeout_us(timeout_mclks, macro_period_us);
+
+ LOG_FUNCTION_END(0);
+
+ return timeout_us;
+}
+
+
+uint16_t VL53L1_encode_timeout(uint32_t timeout_mclks)
+{
+
+
+
+
+
+ uint16_t encoded_timeout = 0;
+ uint32_t ls_byte = 0;
+ uint16_t ms_byte = 0;
+
+ if (timeout_mclks > 0) {
+ ls_byte = timeout_mclks - 1;
+
+ while ((ls_byte & 0xFFFFFF00) > 0) {
+ ls_byte = ls_byte >> 1;
+ ms_byte++;
+ }
+
+ encoded_timeout = (ms_byte << 8)
+ + (uint16_t) (ls_byte & 0x000000FF);
+ }
+
+ return encoded_timeout;
+}
+
+
+uint32_t VL53L1_decode_timeout(uint16_t encoded_timeout)
+{
+
+
+
+
+
+
+ uint32_t timeout_macro_clks = 0;
+
+ timeout_macro_clks = ((uint32_t) (encoded_timeout & 0x00FF)
+ << (uint32_t) ((encoded_timeout & 0xFF00) >> 8)) + 1;
+
+ return timeout_macro_clks;
+}
+
+
+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)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint32_t macro_period_us = 0;
+ uint32_t timeout_mclks = 0;
+ uint16_t timeout_encoded = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (fast_osc_frequency == 0) {
+ status = VL53L1_ERROR_DIVISION_BY_ZERO;
+ } else {
+
+
+ macro_period_us =
+ VL53L1_calc_macro_period_us(
+ fast_osc_frequency,
+ ptiming->range_config__vcsel_period_a);
+
+
+
+ timeout_mclks =
+ VL53L1_calc_timeout_mclks(
+ phasecal_config_timeout_us,
+ macro_period_us);
+
+
+
+ if (timeout_mclks > 0xFF)
+ timeout_mclks = 0xFF;
+
+ pgeneral->phasecal_config__timeout_macrop =
+ (uint8_t)timeout_mclks;
+
+
+
+ timeout_encoded =
+ VL53L1_calc_encoded_timeout(
+ mm_config_timeout_us,
+ macro_period_us);
+
+ ptiming->mm_config__timeout_macrop_a_hi =
+ (uint8_t)((timeout_encoded & 0xFF00) >> 8);
+ ptiming->mm_config__timeout_macrop_a_lo =
+ (uint8_t) (timeout_encoded & 0x00FF);
+
+
+
+ timeout_encoded =
+ VL53L1_calc_encoded_timeout(
+ range_config_timeout_us,
+ macro_period_us);
+
+ ptiming->range_config__timeout_macrop_a_hi =
+ (uint8_t)((timeout_encoded & 0xFF00) >> 8);
+ ptiming->range_config__timeout_macrop_a_lo =
+ (uint8_t) (timeout_encoded & 0x00FF);
+
+
+
+ macro_period_us =
+ VL53L1_calc_macro_period_us(
+ fast_osc_frequency,
+ ptiming->range_config__vcsel_period_b);
+
+
+
+ timeout_encoded =
+ VL53L1_calc_encoded_timeout(
+ mm_config_timeout_us,
+ macro_period_us);
+
+ ptiming->mm_config__timeout_macrop_b_hi =
+ (uint8_t)((timeout_encoded & 0xFF00) >> 8);
+ ptiming->mm_config__timeout_macrop_b_lo =
+ (uint8_t) (timeout_encoded & 0x00FF);
+
+
+
+ timeout_encoded = VL53L1_calc_encoded_timeout(
+ range_config_timeout_us,
+ macro_period_us);
+
+ ptiming->range_config__timeout_macrop_b_hi =
+ (uint8_t)((timeout_encoded & 0xFF00) >> 8);
+ ptiming->range_config__timeout_macrop_b_lo =
+ (uint8_t) (timeout_encoded & 0x00FF);
+ }
+
+ LOG_FUNCTION_END(0);
+
+ return status;
+
+}
+
+
+uint8_t VL53L1_encode_vcsel_period(uint8_t VL53L1_PRM_00028)
+{
+
+
+
+
+
+
+ uint8_t vcsel_period_reg = 0;
+
+ vcsel_period_reg = (VL53L1_PRM_00028 >> 1) - 1;
+
+ return vcsel_period_reg;
+}
+
+
+uint32_t VL53L1_decode_unsigned_integer(
+ uint8_t *pbuffer,
+ uint8_t no_of_bytes)
+{
+
+
+
+
+
+ uint8_t i = 0;
+ uint32_t decoded_value = 0;
+
+ for (i = 0 ; i < no_of_bytes ; i++) {
+ decoded_value = (decoded_value << 8) + (uint32_t)pbuffer[i];
+ }
+
+ return decoded_value;
+}
+
+
+void VL53L1_encode_unsigned_integer(
+ uint32_t ip_value,
+ uint8_t no_of_bytes,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+ uint8_t i = 0;
+ uint32_t VL53L1_PRM_00005 = 0;
+
+ VL53L1_PRM_00005 = ip_value;
+ for (i = 0; i < no_of_bytes ; i++) {
+ pbuffer[no_of_bytes-i-1] = VL53L1_PRM_00005 & 0x00FF;
+ VL53L1_PRM_00005 = VL53L1_PRM_00005 >> 8;
+ }
+}
+
+
+VL53L1_Error VL53L1_hist_copy_and_scale_ambient_info(
+ VL53L1_zone_hist_info_t *pidata,
+ VL53L1_histogram_bin_data_t *podata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ int64_t VL53L1_PRM_00006 = 0;
+ int64_t tmpi = 0;
+ int64_t tmpo = 0;
+
+ LOG_FUNCTION_START("");
+
+
+ if (pidata->result__dss_actual_effective_spads == 0) {
+ status = VL53L1_ERROR_DIVISION_BY_ZERO;
+ } else {
+ if (pidata->number_of_ambient_bins > 0 &&
+ podata->number_of_ambient_bins == 0) {
+
+
+
+
+
+
+
+
+
+
+ tmpo = 1 + (int64_t)podata->total_periods_elapsed;
+ tmpo *= (int64_t)podata->result__dss_actual_effective_spads;
+
+ tmpi = 1 + (int64_t)pidata->total_periods_elapsed;
+ tmpi *= (int64_t)pidata->result__dss_actual_effective_spads;
+
+ VL53L1_PRM_00006 = tmpo * (int64_t)pidata->ambient_events_sum;
+ VL53L1_PRM_00006 += (tmpi/2);
+
+
+
+
+ VL53L1_PRM_00006 = do_division_s(VL53L1_PRM_00006, tmpi);
+
+ podata->ambient_events_sum = (int32_t)VL53L1_PRM_00006;
+
+
+
+
+
+
+ podata->VL53L1_PRM_00026 = podata->ambient_events_sum;
+ podata->VL53L1_PRM_00026 +=
+ ((int32_t)pidata->number_of_ambient_bins / 2);
+ podata->VL53L1_PRM_00026 /=
+ (int32_t)pidata->number_of_ambient_bins;
+ }
+ }
+
+ LOG_FUNCTION_END(0);
+
+ return status;
+}
+
+
+void VL53L1_hist_get_bin_sequence_config(
+ VL53L1_DEV Dev,
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ int32_t amb_thresh_low = 0;
+ int32_t amb_thresh_high = 0;
+
+ uint8_t i = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ amb_thresh_low = 1024 *
+ (int32_t)pdev->hist_cfg.histogram_config__amb_thresh_low;
+ amb_thresh_high = 1024 *
+ (int32_t)pdev->hist_cfg.histogram_config__amb_thresh_high;
+
+
+
+
+
+
+
+
+
+
+ if ((pdev->ll_state.rd_stream_count & 0x01) == 0) {
+
+ pdata->bin_seq[5] =
+ pdev->hist_cfg.histogram_config__mid_amb_even_bin_4_5 >> 4;
+ pdata->bin_seq[4] =
+ pdev->hist_cfg.histogram_config__mid_amb_even_bin_4_5 & 0x0F;
+ pdata->bin_seq[3] =
+ pdev->hist_cfg.histogram_config__mid_amb_even_bin_2_3 >> 4;
+ pdata->bin_seq[2] =
+ pdev->hist_cfg.histogram_config__mid_amb_even_bin_2_3 & 0x0F;
+ pdata->bin_seq[1] =
+ pdev->hist_cfg.histogram_config__mid_amb_even_bin_0_1 >> 4;
+ pdata->bin_seq[0] =
+ pdev->hist_cfg.histogram_config__mid_amb_even_bin_0_1 & 0x0F;
+
+ if (pdata->ambient_events_sum > amb_thresh_high) {
+ pdata->bin_seq[5] =
+ pdev->hist_cfg.histogram_config__high_amb_even_bin_4_5 >> 4;
+ pdata->bin_seq[4] =
+ pdev->hist_cfg.histogram_config__high_amb_even_bin_4_5 & 0x0F;
+ pdata->bin_seq[3] =
+ pdev->hist_cfg.histogram_config__high_amb_even_bin_2_3 >> 4;
+ pdata->bin_seq[2] =
+ pdev->hist_cfg.histogram_config__high_amb_even_bin_2_3 & 0x0F;
+ pdata->bin_seq[1] =
+ pdev->hist_cfg.histogram_config__high_amb_even_bin_0_1 >> 4;
+ pdata->bin_seq[0] =
+ pdev->hist_cfg.histogram_config__high_amb_even_bin_0_1 & 0x0F;
+ }
+
+ if (pdata->ambient_events_sum < amb_thresh_low) {
+ pdata->bin_seq[5] =
+ pdev->hist_cfg.histogram_config__low_amb_even_bin_4_5 >> 4;
+ pdata->bin_seq[4] =
+ pdev->hist_cfg.histogram_config__low_amb_even_bin_4_5 & 0x0F;
+ pdata->bin_seq[3] =
+ pdev->hist_cfg.histogram_config__low_amb_even_bin_2_3 >> 4;
+ pdata->bin_seq[2] =
+ pdev->hist_cfg.histogram_config__low_amb_even_bin_2_3 & 0x0F;
+ pdata->bin_seq[1] =
+ pdev->hist_cfg.histogram_config__low_amb_even_bin_0_1 >> 4;
+ pdata->bin_seq[0] =
+ pdev->hist_cfg.histogram_config__low_amb_even_bin_0_1 & 0x0F;
+ }
+
+ } else {
+ pdata->bin_seq[5] =
+ pdev->hist_cfg.histogram_config__mid_amb_odd_bin_5 & 0x0F;
+ pdata->bin_seq[4] =
+ pdev->hist_cfg.histogram_config__mid_amb_odd_bin_3_4 & 0x0F;
+ pdata->bin_seq[3] =
+ pdev->hist_cfg.histogram_config__mid_amb_odd_bin_3_4 >> 4;
+ pdata->bin_seq[2] =
+ pdev->hist_cfg.histogram_config__mid_amb_odd_bin_2 & 0x0F;
+ pdata->bin_seq[1] =
+ pdev->hist_cfg.histogram_config__mid_amb_odd_bin_0_1 >> 4;
+ pdata->bin_seq[0] =
+ pdev->hist_cfg.histogram_config__mid_amb_odd_bin_0_1 & 0x0F;
+
+ if (pdata->ambient_events_sum > amb_thresh_high) {
+ pdata->bin_seq[5] =
+ pdev->hist_cfg.histogram_config__high_amb_odd_bin_4_5 >> 4;
+ pdata->bin_seq[4] =
+ pdev->hist_cfg.histogram_config__high_amb_odd_bin_4_5 & 0x0F;
+ pdata->bin_seq[3] =
+ pdev->hist_cfg.histogram_config__high_amb_odd_bin_2_3 >> 4;
+ pdata->bin_seq[2] =
+ pdev->hist_cfg.histogram_config__high_amb_odd_bin_2_3 & 0x0F;
+ pdata->bin_seq[1] =
+ pdev->hist_cfg.histogram_config__high_amb_odd_bin_0_1 >> 4;
+ pdata->bin_seq[0] =
+ pdev->hist_cfg.histogram_config__high_amb_odd_bin_0_1 & 0x0F;
+ }
+
+ if (pdata->ambient_events_sum < amb_thresh_low) {
+ pdata->bin_seq[5] =
+ pdev->hist_cfg.histogram_config__low_amb_odd_bin_4_5 >> 4;
+ pdata->bin_seq[4] =
+ pdev->hist_cfg.histogram_config__low_amb_odd_bin_4_5 & 0x0F;
+ pdata->bin_seq[3] =
+ pdev->hist_cfg.histogram_config__low_amb_odd_bin_2_3 >> 4;
+ pdata->bin_seq[2] =
+ pdev->hist_cfg.histogram_config__low_amb_odd_bin_2_3 & 0x0F;
+ pdata->bin_seq[1] =
+ pdev->hist_cfg.histogram_config__low_amb_odd_bin_0_1 >> 4;
+ pdata->bin_seq[0] =
+ pdev->hist_cfg.histogram_config__low_amb_odd_bin_0_1 & 0x0F;
+ }
+ }
+
+
+
+
+ for (i = 0 ; i < VL53L1_MAX_BIN_SEQUENCE_LENGTH ; i++) {
+ pdata->bin_rep[i] = 1;
+ }
+
+ LOG_FUNCTION_END(0);
+
+}
+
+
+VL53L1_Error VL53L1_hist_phase_consistency_check(
+ VL53L1_DEV Dev,
+ VL53L1_zone_hist_info_t *phist_prev,
+ VL53L1_histogram_bin_data_t *phist_curr,
+ VL53L1_zone_objects_t *prange_prev,
+ VL53L1_range_results_t *prange_curr)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t VL53L1_PRM_00001 = 0;
+ uint8_t p = 0;
+
+ uint16_t phase_delta = 0;
+ uint16_t phase_tolerance = 0;
+
+ int32_t events_delta = 0;
+ int32_t events_tolerance = 0;
+
+ VL53L1_DeviceError range_status = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ phase_tolerance =
+ (uint16_t)pdev->histpostprocess.algo__consistency_check__phase_tolerance;
+ phase_tolerance = phase_tolerance << 8;
+
+
+
+
+ if (prange_prev->rd_device_state != VL53L1_DEVICESTATE_RANGING_GATHER_DATA &&
+ prange_prev->rd_device_state != VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA) {
+ return status;
+ }
+
+
+
+
+ if (phase_tolerance == 0) {
+ return status;
+ }
+
+ for (VL53L1_PRM_00001 = 0 ; VL53L1_PRM_00001 < prange_curr->active_results ; VL53L1_PRM_00001++) {
+
+ if ((prange_curr->VL53L1_PRM_00005[VL53L1_PRM_00001].range_status ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE) ||
+ (prange_curr->VL53L1_PRM_00005[VL53L1_PRM_00001].range_status ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE_NO_WRAP_CHECK)) {
+
+
+
+
+ prange_curr->VL53L1_PRM_00005[VL53L1_PRM_00001].range_status =
+ VL53L1_DEVICEERROR_PHASECONSISTENCY;
+
+
+
+
+
+
+
+ for (p = 0 ; p < prange_prev->active_objects ; p++) {
+
+ if (prange_curr->VL53L1_PRM_00005[VL53L1_PRM_00001].VL53L1_PRM_00014 >
+ prange_prev->VL53L1_PRM_00005[p].VL53L1_PRM_00014) {
+ phase_delta =
+ prange_curr->VL53L1_PRM_00005[VL53L1_PRM_00001].VL53L1_PRM_00014 -
+ prange_prev->VL53L1_PRM_00005[p].VL53L1_PRM_00014;
+ } else {
+ phase_delta =
+ prange_prev->VL53L1_PRM_00005[p].VL53L1_PRM_00014 -
+ prange_curr->VL53L1_PRM_00005[VL53L1_PRM_00001].VL53L1_PRM_00014;
+ }
+
+ if (phase_delta < phase_tolerance) {
+
+
+
+
+
+
+ status =
+ VL53L1_hist_events_consistency_check(
+ Dev,
+ VL53L1_PRM_00001,
+ p,
+ phist_prev,
+ phist_curr,
+ prange_prev,
+ prange_curr,
+ &events_tolerance,
+ &events_delta,
+ &range_status);
+
+ prange_curr->VL53L1_PRM_00005[VL53L1_PRM_00001].range_status =
+ range_status;
+ }
+ }
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_hist_events_consistency_check(
+ VL53L1_DEV Dev,
+ uint8_t VL53L1_PRM_00001,
+ uint8_t p,
+ VL53L1_zone_hist_info_t *phist_prev,
+ VL53L1_histogram_bin_data_t *phist_curr,
+ VL53L1_zone_objects_t *prange_prev,
+ VL53L1_range_results_t *prange_curr,
+ int32_t *pevents_tolerance,
+ int32_t *pevents_delta,
+ VL53L1_DeviceError *prange_status)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t event_sigma = 0;
+
+ int64_t tmpp = 0;
+ int64_t tmpc = 0;
+ int64_t events_scaler = 0;
+ int64_t events_scaler_sq = 0;
+ int64_t c_signal_events = 0;
+ int64_t c_sig_noise_sq = 0;
+ int64_t c_amb_noise_sq = 0;
+ int64_t p_amb_noise_sq = 0;
+
+ int32_t p_signal_events = 0;
+ uint32_t noise_sq_sum = 0;
+
+ SUPPRESS_UNUSED_WARNING(phist_curr);
+
+
+
+
+ event_sigma =
+ pdev->histpostprocess.algo__consistency_check__event_sigma;
+
+ if (event_sigma == 0) {
+ *prange_status = VL53L1_DEVICEERROR_RANGECOMPLETE;
+ return status;
+ }
+
+
+
+
+ tmpp = 1 + (int64_t)phist_prev->total_periods_elapsed;
+ tmpp *= (int64_t)phist_prev->result__dss_actual_effective_spads;
+
+
+
+
+ tmpc = 1 + (int64_t)prange_curr->VL53L1_PRM_00005[VL53L1_PRM_00001].total_periods_elapsed;
+ tmpc *= (int64_t)prange_curr->VL53L1_PRM_00005[VL53L1_PRM_00001].VL53L1_PRM_00003;
+
+
+
+
+ events_scaler = tmpp * 4096;
+ events_scaler += (tmpc/2);
+ events_scaler = do_division_s(events_scaler, tmpc);
+
+ events_scaler_sq = events_scaler * events_scaler;
+ events_scaler_sq += 2048;
+ events_scaler_sq /= 4096;
+
+
+
+
+ c_signal_events = (int64_t)prange_curr->VL53L1_PRM_00005[VL53L1_PRM_00001].VL53L1_PRM_00022;
+ c_signal_events -= (int64_t)prange_curr->VL53L1_PRM_00005[VL53L1_PRM_00001].VL53L1_PRM_00023;
+ c_signal_events *= (int64_t)events_scaler;
+ c_signal_events += 2048;
+ c_signal_events /= 4096;
+
+ c_sig_noise_sq = (int64_t)events_scaler_sq;
+ c_sig_noise_sq *= (int64_t)prange_curr->VL53L1_PRM_00005[VL53L1_PRM_00001].VL53L1_PRM_00022;
+ c_sig_noise_sq += 2048;
+ c_sig_noise_sq /= 4096;
+
+ c_amb_noise_sq = (int64_t)events_scaler_sq;
+ c_amb_noise_sq *= (int64_t)prange_curr->VL53L1_PRM_00005[VL53L1_PRM_00001].VL53L1_PRM_00023;
+ c_amb_noise_sq += 2048;
+ c_amb_noise_sq /= 4096;
+
+
+
+ c_amb_noise_sq += 2;
+ c_amb_noise_sq /= 4;
+
+
+
+
+
+
+
+ p_amb_noise_sq =
+ (int64_t)prange_prev->VL53L1_PRM_00005[p].VL53L1_PRM_00023;
+
+
+
+ p_amb_noise_sq += 2;
+ p_amb_noise_sq /= 4;
+
+ noise_sq_sum =
+ (uint32_t)prange_prev->VL53L1_PRM_00005[p].VL53L1_PRM_00022 +
+ (uint32_t)c_sig_noise_sq +
+ (uint32_t)p_amb_noise_sq +
+ (uint32_t)c_amb_noise_sq;
+
+ *pevents_tolerance =
+ (int32_t)VL53L1_isqrt(noise_sq_sum * 16);
+
+ *pevents_tolerance *= (int32_t)event_sigma;
+ *pevents_tolerance += 32;
+ *pevents_tolerance /= 64;
+
+ p_signal_events = (int32_t)prange_prev->VL53L1_PRM_00005[p].VL53L1_PRM_00022;
+ p_signal_events -= (int32_t)prange_prev->VL53L1_PRM_00005[p].VL53L1_PRM_00023;
+
+ if ((int32_t)c_signal_events > p_signal_events) {
+ *pevents_delta =
+ (int32_t)c_signal_events - p_signal_events;
+ } else {
+ *pevents_delta =
+ p_signal_events - (int32_t)c_signal_events;
+ }
+
+ if (*pevents_delta > *pevents_tolerance)
+ *prange_status = VL53L1_DEVICEERROR_EVENTCONSISTENCY;
+ else
+ *prange_status = VL53L1_DEVICEERROR_RANGECOMPLETE;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_hist_wrap_dmax(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_histogram_bin_data_t *pcurrent,
+ int16_t *pwrap_dmax_mm)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint32_t pll_period_mm = 0;
+ uint32_t wrap_dmax_phase = 0;
+ uint32_t range_mm = 0;
+
+ LOG_FUNCTION_START("");
+
+ *pwrap_dmax_mm = 0;
+
+
+ if (pcurrent->VL53L1_PRM_00018 != 0) {
+
+
+
+
+ pll_period_mm =
+ VL53L1_calc_pll_period_mm(
+ pcurrent->VL53L1_PRM_00018);
+
+
+
+
+ wrap_dmax_phase =
+ (uint32_t)phistpostprocess->valid_phase_high << 8;
+
+
+
+
+
+ range_mm = wrap_dmax_phase * pll_period_mm;
+ range_mm = (range_mm + (1<<14)) >> 15;
+
+ *pwrap_dmax_mm = (int16_t)range_mm;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+void VL53L1_hist_combine_mm1_mm2_offsets(
+ int16_t mm1_offset_mm,
+ int16_t mm2_offset_mm,
+ uint8_t encoded_mm_roi_centre,
+ uint8_t encoded_mm_roi_size,
+ uint8_t encoded_zone_centre,
+ uint8_t encoded_zone_size,
+ VL53L1_additional_offset_cal_data_t *pcal_data,
+ uint8_t *pgood_spads,
+ uint16_t aperture_attenuation,
+ int16_t *prange_offset_mm)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint16_t max_mm_inner_effective_spads = 0;
+ uint16_t max_mm_outer_effective_spads = 0;
+ uint16_t mm_inner_effective_spads = 0;
+ uint16_t mm_outer_effective_spads = 0;
+
+ uint32_t scaled_mm1_peak_rate_mcps = 0;
+ uint32_t scaled_mm2_peak_rate_mcps = 0;
+
+ int32_t tmp0 = 0;
+ int32_t tmp1 = 0;
+
+
+
+
+ VL53L1_calc_mm_effective_spads(
+ encoded_mm_roi_centre,
+ encoded_mm_roi_size,
+ 0xC7,
+
+ 0xFF,
+ pgood_spads,
+ aperture_attenuation,
+ &max_mm_inner_effective_spads,
+ &max_mm_outer_effective_spads);
+
+
+
+
+ VL53L1_calc_mm_effective_spads(
+ encoded_mm_roi_centre,
+ encoded_mm_roi_size,
+ encoded_zone_centre,
+ encoded_zone_size,
+ pgood_spads,
+ aperture_attenuation,
+ &mm_inner_effective_spads,
+ &mm_outer_effective_spads);
+
+
+
+
+ scaled_mm1_peak_rate_mcps = (uint32_t)pcal_data->result__mm_inner_peak_signal_count_rtn_mcps;
+ scaled_mm1_peak_rate_mcps *= (uint32_t)mm_inner_effective_spads;
+ scaled_mm1_peak_rate_mcps /= (uint32_t)max_mm_inner_effective_spads;
+
+ scaled_mm2_peak_rate_mcps = (uint32_t)pcal_data->result__mm_outer_peak_signal_count_rtn_mcps;
+ scaled_mm2_peak_rate_mcps *= (uint32_t)mm_outer_effective_spads;
+ scaled_mm2_peak_rate_mcps /= (uint32_t)max_mm_outer_effective_spads;
+
+
+
+
+ tmp0 = ((int32_t)mm1_offset_mm * (int32_t)scaled_mm1_peak_rate_mcps);
+ tmp0 += ((int32_t)mm2_offset_mm * (int32_t)scaled_mm2_peak_rate_mcps);
+
+ tmp1 = (int32_t)scaled_mm1_peak_rate_mcps +
+ (int32_t)scaled_mm2_peak_rate_mcps;
+
+
+
+
+
+
+ if (tmp1 != 0) {
+ tmp0 = (tmp0 * 4) / tmp1;
+ }
+
+ *prange_offset_mm = (int16_t)tmp0;
+
+}
+
+
+void VL53L1_spad_number_to_byte_bit_index(
+ uint8_t spad_number,
+ uint8_t *pbyte_index,
+ uint8_t *pbit_index,
+ uint8_t *pbit_mask)
+{
+
+
+
+
+
+
+
+
+
+
+ *pbyte_index = spad_number >> 3;
+ *pbit_index = spad_number & 0x07;
+ *pbit_mask = 0x01 << *pbit_index;
+
+}
+
+
+void VL53L1_encode_row_col(
+ uint8_t row,
+ uint8_t col,
+ uint8_t *pspad_number)
+{
+
+
+
+
+
+ if (row > 7) {
+ *pspad_number = 128 + (col << 3) + (15-row);
+ } else {
+ *pspad_number = ((15-col) << 3) + row;
+ }
+}
+
+
+void VL53L1_decode_zone_size(
+ uint8_t encoded_xy_size,
+ uint8_t *pwidth,
+ uint8_t *pheight)
+{
+
+
+
+
+
+
+
+
+
+
+
+ *pheight = encoded_xy_size >> 4;
+ *pwidth = encoded_xy_size & 0x0F;
+
+}
+
+
+void VL53L1_encode_zone_size(
+ uint8_t width,
+ uint8_t height,
+ uint8_t *pencoded_xy_size)
+{
+
+
+
+
+
+
+
+
+
+
+ *pencoded_xy_size = (height << 4) + width;
+
+}
+
+
+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)
+{
+
+
+
+
+
+
+
+
+
+ uint8_t x_centre = 0;
+ uint8_t y_centre = 0;
+ uint8_t width = 0;
+ uint8_t height = 0;
+
+
+
+
+ VL53L1_decode_row_col(
+ encoded_xy_centre,
+ &y_centre,
+ &x_centre);
+
+ VL53L1_decode_zone_size(
+ encoded_xy_size,
+ &width,
+ &height);
+
+
+
+
+ *px_ll = (int16_t)x_centre - ((int16_t)width + 1) / 2;
+ if (*px_ll < 0)
+ *px_ll = 0;
+
+ *px_ur = *px_ll + (int16_t)width;
+ if (*px_ur > (VL53L1_SPAD_ARRAY_WIDTH-1))
+ *px_ur = VL53L1_SPAD_ARRAY_WIDTH-1;
+
+ *py_ll = (int16_t)y_centre - ((int16_t)height + 1) / 2;
+ if (*py_ll < 0)
+ *py_ll = 0;
+
+ *py_ur = *py_ll + (int16_t)height;
+ if (*py_ur > (VL53L1_SPAD_ARRAY_HEIGHT-1))
+ *py_ur = VL53L1_SPAD_ARRAY_HEIGHT-1;
+}
+
+
+uint8_t VL53L1_is_aperture_location(
+ uint8_t row,
+ uint8_t col)
+{
+
+
+
+
+
+ uint8_t is_aperture = 0;
+ uint8_t mod_row = row % 4;
+ uint8_t mod_col = col % 4;
+
+ if (mod_row == 0 && mod_col == 2)
+ is_aperture = 1;
+
+ if (mod_row == 2 && mod_col == 0)
+ is_aperture = 1;
+
+ return is_aperture;
+}
+
+
+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)
+{
+
+
+
+
+
+
+
+ int16_t x = 0;
+ int16_t y = 0;
+
+ int16_t mm_x_ll = 0;
+ int16_t mm_y_ll = 0;
+ int16_t mm_x_ur = 0;
+ int16_t mm_y_ur = 0;
+
+ int16_t zone_x_ll = 0;
+ int16_t zone_y_ll = 0;
+ int16_t zone_x_ur = 0;
+ int16_t zone_y_ur = 0;
+
+ uint8_t spad_number = 0;
+ uint8_t byte_index = 0;
+ uint8_t bit_index = 0;
+ uint8_t bit_mask = 0;
+
+ uint8_t is_aperture = 0;
+ uint16_t spad_attenuation = 0;
+
+
+
+
+ VL53L1_decode_zone_limits(
+ encoded_mm_roi_centre,
+ encoded_mm_roi_size,
+ &mm_x_ll,
+ &mm_y_ll,
+ &mm_x_ur,
+ &mm_y_ur);
+
+ VL53L1_decode_zone_limits(
+ encoded_zone_centre,
+ encoded_zone_size,
+ &zone_x_ll,
+ &zone_y_ll,
+ &zone_x_ur,
+ &zone_y_ur);
+
+
+
+
+
+
+
+
+
+ *pmm_inner_effective_spads = 0;
+ *pmm_outer_effective_spads = 0;
+
+ for (y = zone_y_ll ; y <= zone_y_ur ; y++) {
+ for (x = zone_x_ll ; x <= zone_x_ur ; x++) {
+
+
+
+
+ VL53L1_encode_row_col(
+ (uint8_t)y,
+ (uint8_t)x,
+ &spad_number);
+
+
+
+
+
+
+
+
+ VL53L1_spad_number_to_byte_bit_index(
+ spad_number,
+ &byte_index,
+ &bit_index,
+ &bit_mask);
+
+
+
+
+ if ((pgood_spads[byte_index] & bit_mask) > 0) {
+
+
+
+ is_aperture = VL53L1_is_aperture_location(
+ (uint8_t)y,
+ (uint8_t)x);
+
+ if (is_aperture > 0)
+ spad_attenuation = aperture_attenuation;
+ else
+ spad_attenuation = 0x0100;
+
+
+
+
+
+
+
+ if (x >= mm_x_ll && x <= mm_x_ur &&
+ y >= mm_y_ll && y <= mm_y_ur)
+ *pmm_inner_effective_spads +=
+ spad_attenuation;
+ else
+ *pmm_outer_effective_spads +=
+ spad_attenuation;
+ }
+ }
+ }
+}
+
+
+void VL53L1_hist_copy_results_to_sys_and_core(
+ VL53L1_histogram_bin_data_t *pbins,
+ VL53L1_range_results_t *phist,
+ VL53L1_system_results_t *psys,
+ VL53L1_core_results_t *pcore)
+{
+
+
+
+
+
+ uint8_t i = 0;
+
+ VL53L1_range_data_t *pdata;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ VL53L1_init_system_results(psys);
+
+
+
+
+ psys->result__interrupt_status = pbins->result__interrupt_status;
+ psys->result__range_status = phist->active_results;
+ psys->result__report_status = pbins->result__report_status;
+ psys->result__stream_count = pbins->result__stream_count;
+
+ pdata = &(phist->VL53L1_PRM_00005[0]);
+
+ for (i = 0 ; i < phist->active_results ; i++) {
+
+ switch (i) {
+ case 0:
+ psys->result__dss_actual_effective_spads_sd0 = \
+ pdata->VL53L1_PRM_00003;
+ psys->result__peak_signal_count_rate_mcps_sd0 = \
+ pdata->peak_signal_count_rate_mcps;
+ psys->result__avg_signal_count_rate_mcps_sd0 = \
+ pdata->avg_signal_count_rate_mcps;
+ psys->result__ambient_count_rate_mcps_sd0 = \
+ pdata->ambient_count_rate_mcps;
+
+ psys->result__sigma_sd0 = pdata->VL53L1_PRM_00004;
+ psys->result__phase_sd0 = pdata->VL53L1_PRM_00014;
+
+ psys->result__final_crosstalk_corrected_range_mm_sd0 = \
+ (uint16_t)pdata->median_range_mm;
+
+ psys->result__phase_sd1 = pdata->zero_distance_phase;
+
+ pcore->result_core__ranging_total_events_sd0 = \
+ pdata->VL53L1_PRM_00022;
+ pcore->result_core__signal_total_events_sd0 = \
+ pdata->VL53L1_PRM_00009;
+ pcore->result_core__total_periods_elapsed_sd0 = \
+ pdata->total_periods_elapsed;
+ pcore->result_core__ambient_window_events_sd0 = \
+ pdata->VL53L1_PRM_00023;
+
+ break;
+ case 1:
+ psys->result__dss_actual_effective_spads_sd1 = \
+ pdata->VL53L1_PRM_00003;
+ psys->result__peak_signal_count_rate_mcps_sd1 = \
+ pdata->peak_signal_count_rate_mcps;
+ psys->result__ambient_count_rate_mcps_sd1 = \
+ pdata->ambient_count_rate_mcps;
+
+ psys->result__sigma_sd1 = pdata->VL53L1_PRM_00004;
+ psys->result__phase_sd1 = pdata->VL53L1_PRM_00014;
+
+ psys->result__final_crosstalk_corrected_range_mm_sd1 = \
+ (uint16_t)pdata->median_range_mm;
+
+ pcore->result_core__ranging_total_events_sd1 = \
+ pdata->VL53L1_PRM_00022;
+ pcore->result_core__signal_total_events_sd1 = \
+ pdata->VL53L1_PRM_00009;
+ pcore->result_core__total_periods_elapsed_sd1 = \
+ pdata->total_periods_elapsed;
+ pcore->result_core__ambient_window_events_sd1 = \
+ pdata->VL53L1_PRM_00023;
+ break;
+ }
+
+ pdata++;
+ }
+
+ LOG_FUNCTION_END(0);
+
+}
+
+
+VL53L1_Error VL53L1_sum_histogram_data (
+ VL53L1_histogram_bin_data_t *phist_input,
+ VL53L1_histogram_bin_data_t *phist_output)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t i = 0;
+ uint8_t smallest_bin_num = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ if (phist_output->VL53L1_PRM_00017 >= phist_input->VL53L1_PRM_00017) {
+ smallest_bin_num = phist_input->VL53L1_PRM_00017;
+ } else {
+ smallest_bin_num = phist_output->VL53L1_PRM_00017;
+ }
+ }
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ for (i = 0 ; i < smallest_bin_num ; i++) {
+
+
+
+
+ phist_output->bin_data[i] += phist_input->bin_data[i];
+ }
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ phist_output->VL53L1_PRM_00026 +=
+ phist_input->VL53L1_PRM_00026;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_avg_histogram_data(
+ uint8_t no_of_samples,
+ VL53L1_histogram_bin_data_t *phist_sum,
+ VL53L1_histogram_bin_data_t *phist_avg)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t i = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ for (i = 0 ; i < phist_sum->VL53L1_PRM_00017 ; i++) {
+
+
+
+
+ if (no_of_samples > 0) {
+ phist_avg->bin_data[i] = phist_sum->bin_data[i] /
+ (int32_t)no_of_samples;
+ } else {
+ phist_avg->bin_data[i] = phist_sum->bin_data[i];
+ }
+ }
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ if (no_of_samples > 0) {
+ phist_avg->VL53L1_PRM_00026 =
+ phist_sum->VL53L1_PRM_00026 / (int32_t)no_of_samples;
+ } else {
+ phist_avg->VL53L1_PRM_00026 =
+ phist_sum->VL53L1_PRM_00026;
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_save_cfg_data(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ VL53L1_zone_private_dyn_cfg_t *pzone_dyn_cfg;
+ VL53L1_dynamic_config_t *pdynamic = &(pdev->dyn_cfg);
+
+ LOG_FUNCTION_START("");
+
+ pzone_dyn_cfg = &(pres->zone_dyn_cfgs.VL53L1_PRM_00005[pdev->ll_state.cfg_zone_id]);
+
+ pzone_dyn_cfg->expected_stream_count =
+ pdev->ll_state.cfg_stream_count;
+
+ pzone_dyn_cfg->expected_gph_id =
+ pdev->ll_state.cfg_gph_id;
+
+ pzone_dyn_cfg->roi_config__user_roi_centre_spad =
+ pdynamic->roi_config__user_roi_centre_spad;
+
+ pzone_dyn_cfg->roi_config__user_roi_requested_global_xy_size =
+ pdynamic->roi_config__user_roi_requested_global_xy_size;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_dynamic_zone_update(
+ VL53L1_DEV Dev,
+ VL53L1_range_results_t *presults)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+#if 0 //Feb 24 - Local change to prevent compilation warning
+ VL53L1_zone_config_t *pzone_cfg;
+#endif
+ uint8_t zone_id = pdev->ll_state.rd_zone_id;
+ uint8_t i;
+ uint16_t max_total_rate_per_spads;
+ uint16_t target_rate = pdev->stat_cfg.dss_config__target_total_rate_mcps;
+ uint32_t temp = 0xFFFF;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+
+
+
+ if (pstate->cfg_device_state ==
+ VL53L1_DEVICESTATE_RANGING_DSS_MANUAL) {
+
+
+
+
+
+
+
+ pres->zone_dyn_cfgs.VL53L1_PRM_00005[zone_id].dss_requested_effective_spad_count = 0;
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: peak signal count rate mcps:\
+ %u actual effective spads: %u\n",
+ presults->VL53L1_PRM_00005[0].peak_signal_count_rate_mcps,
+ presults->VL53L1_PRM_00005[0].VL53L1_PRM_00003);
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: active results: %u\n",
+ presults->active_results);
+
+ max_total_rate_per_spads = presults->VL53L1_PRM_00005[0].total_rate_per_spad_mcps;
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: max total rate per spad at start: %u\n",
+ max_total_rate_per_spads);
+
+ for (i = 1; i < presults->active_results; i++) {
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: zone total rate per spad: zone_id: %u,\
+ total rate per spad: %u\n",
+ i,
+ presults->VL53L1_PRM_00005[i].total_rate_per_spad_mcps);
+
+ if (presults->VL53L1_PRM_00005[i].total_rate_per_spad_mcps >
+ max_total_rate_per_spads) {
+ max_total_rate_per_spads =
+ presults->VL53L1_PRM_00005[i].total_rate_per_spad_mcps;
+ }
+ }
+
+ if (max_total_rate_per_spads == 0) {
+
+
+
+
+
+ temp = 0xFFFF;
+ } else {
+
+
+
+
+
+ temp = target_rate << 14;
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: 1: temp: %u\n",
+ temp);
+
+
+
+
+
+ temp = temp / max_total_rate_per_spads;
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: 2: temp: %u\n",
+ temp);
+
+
+
+
+
+ if (temp > 0xFFFF) {
+ temp = 0xFFFF;
+ }
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: 3: temp: %u\n",
+ temp);
+ }
+
+ pres->zone_dyn_cfgs.VL53L1_PRM_00005[zone_id].dss_requested_effective_spad_count =
+ (uint16_t)temp;
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: zone_id: %u, target_rate: %u,\
+ max_total_rate_per_spads: %u, requested_spads: %u\n",
+ zone_id,
+ target_rate,
+ max_total_rate_per_spads,
+ pres->zone_dyn_cfgs.VL53L1_PRM_00005[zone_id].dss_requested_effective_spad_count);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_multizone_hist_bins_update(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+ VL53L1_zone_config_t *pzone_cfg = &(pdev->zone_cfg);
+ VL53L1_histogram_config_t *phist_cfg = &(pdev->hist_cfg);
+ VL53L1_histogram_config_t *pmulti_hist = &(pzone_cfg->multizone_hist_cfg);
+
+ uint8_t next_range_is_odd_timing = (pstate->cfg_stream_count) % 2;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ if (pzone_cfg->bin_config[pdev->ll_state.cfg_zone_id] ==
+ VL53L1_ZONECONFIG_BINCONFIG__LOWAMB) {
+ if (!next_range_is_odd_timing) {
+ trace_print (VL53L1_TRACE_LEVEL_DEBUG,
+ " HISTBINCONFIGUPDATE: Setting LOWAMB EVEN timing\n");
+ phist_cfg->histogram_config__low_amb_even_bin_0_1 =
+ pmulti_hist->histogram_config__low_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_even_bin_2_3 =
+ pmulti_hist->histogram_config__low_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_even_bin_4_5 =
+ pmulti_hist->histogram_config__low_amb_even_bin_4_5;
+ }
+
+ if (next_range_is_odd_timing) {
+ trace_print (VL53L1_TRACE_LEVEL_DEBUG,
+ " HISTBINCONFIGUPDATE: Setting LOWAMB ODD timing\n");
+ phist_cfg->histogram_config__low_amb_odd_bin_0_1 =
+ pmulti_hist->histogram_config__low_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_odd_bin_2_3 =
+ pmulti_hist->histogram_config__low_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_odd_bin_4_5 =
+ pmulti_hist->histogram_config__low_amb_even_bin_4_5;
+ }
+ } else if (pzone_cfg->bin_config[pdev->ll_state.cfg_zone_id] ==
+ VL53L1_ZONECONFIG_BINCONFIG__MIDAMB) {
+
+ trace_print (VL53L1_TRACE_LEVEL_DEBUG,
+ " HISTBINCONFIGUPDATE: Setting MIDAMB timing\n");
+ if (!next_range_is_odd_timing) {
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " HISTBINCONFIGUPDATE: Setting MIDAMB EVEN timing\n");
+ phist_cfg->histogram_config__low_amb_even_bin_0_1 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_even_bin_2_3 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_even_bin_4_5 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_4_5;
+ }
+
+ if (next_range_is_odd_timing) {
+ trace_print (VL53L1_TRACE_LEVEL_DEBUG,
+ " HISTBINCONFIGUPDATE: Setting MIDAMB ODD timing\n");
+ phist_cfg->histogram_config__low_amb_odd_bin_0_1 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_odd_bin_2_3 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_odd_bin_4_5 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_4_5;
+ }
+ } else if (pzone_cfg->bin_config[pdev->ll_state.cfg_zone_id] ==
+ VL53L1_ZONECONFIG_BINCONFIG__HIGHAMB) {
+ if (!next_range_is_odd_timing) {
+ trace_print (VL53L1_TRACE_LEVEL_DEBUG,
+ " HISTBINCONFIGUPDATE: Setting HIGHAMB EVEN timing\n");
+ phist_cfg->histogram_config__low_amb_even_bin_0_1 =
+ pmulti_hist->histogram_config__high_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_even_bin_2_3 =
+ pmulti_hist->histogram_config__high_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_even_bin_4_5 =
+ pmulti_hist->histogram_config__high_amb_even_bin_4_5;
+ }
+
+ if (next_range_is_odd_timing) {
+ trace_print (VL53L1_TRACE_LEVEL_DEBUG,
+ " HISTBINCONFIGUPDATE: Setting HIGHAMB ODD timing\n");
+ phist_cfg->histogram_config__low_amb_odd_bin_0_1 =
+ pmulti_hist->histogram_config__high_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_odd_bin_2_3 =
+ pmulti_hist->histogram_config__high_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_odd_bin_4_5 =
+ pmulti_hist->histogram_config__high_amb_even_bin_4_5;
+ }
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ VL53L1_copy_hist_bins_to_static_cfg(
+ phist_cfg,
+ &(pdev->stat_cfg),
+ &(pdev->tim_cfg));
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_update_internal_stream_counters(
+ VL53L1_DEV Dev,
+ uint8_t external_stream_count,
+ uint8_t *pinternal_stream_count,
+ uint8_t *pinternal_stream_count_val)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t stream_divider;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ stream_divider = pdev->gen_cfg.global_config__stream_divider;
+
+ if (stream_divider == 0) {
+
+
+
+
+
+
+ *pinternal_stream_count = external_stream_count;
+
+ } else if (*pinternal_stream_count_val == (stream_divider-1)) {
+
+
+
+
+
+ if (*pinternal_stream_count == 0xFF) {
+ *pinternal_stream_count = 0x80;
+ } else {
+ *pinternal_stream_count = *pinternal_stream_count + 1;
+ }
+
+
+
+
+
+ *pinternal_stream_count_val = 0;
+
+ } else {
+
+
+
+
+
+ *pinternal_stream_count_val = *pinternal_stream_count_val + 1;
+ }
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ "UPDINTSTREAMCOUNT internal_steam_count: %d,\
+ internal_stream_count_val: %d, divider: %d\n",
+ *pinternal_stream_count,
+ *pinternal_stream_count_val,
+ stream_divider);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_histogram_multizone_initial_bin_config(
+ VL53L1_zone_config_t *pzone_cfg,
+ VL53L1_histogram_config_t *phist_cfg,
+ VL53L1_histogram_config_t *pmulti_hist
+ )
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ if (pzone_cfg->bin_config[0] ==
+ VL53L1_ZONECONFIG_BINCONFIG__LOWAMB) {
+ phist_cfg->histogram_config__low_amb_even_bin_0_1 =
+ pmulti_hist->histogram_config__low_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_even_bin_2_3 =
+ pmulti_hist->histogram_config__low_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_even_bin_4_5 =
+ pmulti_hist->histogram_config__low_amb_even_bin_4_5;
+
+ phist_cfg->histogram_config__low_amb_odd_bin_0_1 =
+ pmulti_hist->histogram_config__low_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_odd_bin_2_3 =
+ pmulti_hist->histogram_config__low_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_odd_bin_4_5 =
+ pmulti_hist->histogram_config__low_amb_even_bin_4_5;
+ } else if (pzone_cfg->bin_config[0] ==
+ VL53L1_ZONECONFIG_BINCONFIG__MIDAMB) {
+
+ phist_cfg->histogram_config__low_amb_even_bin_0_1 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_even_bin_2_3 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_even_bin_4_5 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_4_5;
+
+ phist_cfg->histogram_config__low_amb_odd_bin_0_1 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_odd_bin_2_3 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_odd_bin_4_5 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_4_5;
+ } else if (pzone_cfg->bin_config[0] ==
+ VL53L1_ZONECONFIG_BINCONFIG__HIGHAMB) {
+ phist_cfg->histogram_config__low_amb_even_bin_0_1 =
+ pmulti_hist->histogram_config__high_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_even_bin_2_3 =
+ pmulti_hist->histogram_config__high_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_even_bin_4_5 =
+ pmulti_hist->histogram_config__high_amb_even_bin_4_5;
+ phist_cfg->histogram_config__low_amb_odd_bin_0_1 =
+ pmulti_hist->histogram_config__high_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_odd_bin_2_3 =
+ pmulti_hist->histogram_config__high_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_odd_bin_4_5 =
+ pmulti_hist->histogram_config__high_amb_even_bin_4_5;
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+
+
+
+
+uint8_t VL53L1_encode_GPIO_interrupt_config(
+ VL53L1_GPIO_interrupt_config_t *pintconf)
+{
+ uint8_t system__interrupt_config;
+
+ system__interrupt_config = pintconf->intr_mode_distance;
+ system__interrupt_config |= ((pintconf->intr_mode_rate) << 2);
+ system__interrupt_config |= ((pintconf->intr_new_measure_ready) << 5);
+ system__interrupt_config |= ((pintconf->intr_no_target) << 6);
+ system__interrupt_config |= ((pintconf->intr_combined_mode) << 7);
+
+ return system__interrupt_config;
+}
+
+
+
+
+
+
+VL53L1_GPIO_interrupt_config_t VL53L1_decode_GPIO_interrupt_config(
+ uint8_t system__interrupt_config)
+{
+ VL53L1_GPIO_interrupt_config_t intconf;
+
+ intconf.intr_mode_distance = system__interrupt_config & 0x03;
+ intconf.intr_mode_rate = (system__interrupt_config >> 2) & 0x03;
+ intconf.intr_new_measure_ready = (system__interrupt_config >> 5) & 0x01;
+ intconf.intr_no_target = (system__interrupt_config >> 6) & 0x01;
+ intconf.intr_combined_mode = (system__interrupt_config >> 7) & 0x01;
+
+ return intconf;
+}
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_distance_threshold(
+ VL53L1_DEV Dev,
+ uint16_t threshold_high,
+ uint16_t threshold_low)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->dyn_cfg.system__thresh_high = threshold_high;
+ pdev->dyn_cfg.system__thresh_low = threshold_low;
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_rate_threshold(
+ VL53L1_DEV Dev,
+ uint16_t threshold_high,
+ uint16_t threshold_low)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->gen_cfg.system__thresh_rate_high = threshold_high;
+ pdev->gen_cfg.system__thresh_rate_low = threshold_low;
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_thresholds_from_struct(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_interrupt_config_t *pintconf)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status = VL53L1_set_GPIO_distance_threshold(
+ Dev,
+ pintconf->threshold_distance_high,
+ pintconf->threshold_distance_low);
+
+ if (status == VL53L1_ERROR_NONE) {
+ status =
+ VL53L1_set_GPIO_rate_threshold(
+ Dev,
+ pintconf->threshold_rate_high,
+ pintconf->threshold_rate_low);
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+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)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t buffer[2];
+
+ uint32_t macro_period_us = 0;
+ uint32_t timeout_mclks = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ macro_period_us =
+ VL53L1_calc_macro_period_us(
+ fast_osc_frequency,
+ vcsel_period_a);
+
+
+
+
+
+
+ timeout_mclks = phasecal_timeout_us << 12;
+ timeout_mclks = timeout_mclks + (macro_period_us>>1);
+ timeout_mclks = timeout_mclks / macro_period_us;
+
+ if (timeout_mclks > 0xFF)
+ pdev->gen_cfg.phasecal_config__timeout_macrop = 0xFF;
+ else
+ pdev->gen_cfg.phasecal_config__timeout_macrop =
+ (uint8_t)timeout_mclks;
+
+ pdev->tim_cfg.range_config__vcsel_period_a = vcsel_period_a;
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_WrByte(
+ Dev,
+ VL53L1_PHASECAL_CONFIG__TIMEOUT_MACROP,
+ pdev->gen_cfg.phasecal_config__timeout_macrop);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGE_CONFIG__VCSEL_PERIOD_A,
+ pdev->tim_cfg.range_config__vcsel_period_a);
+
+
+
+
+
+
+
+ buffer[0] = pdev->tim_cfg.range_config__vcsel_period_a;
+ buffer[1] = pdev->tim_cfg.range_config__vcsel_period_a;
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WriteMulti(
+ Dev,
+ VL53L1_SD_CONFIG__WOI_SD0,
+ buffer,
+ 2);
+
+
+
+
+
+
+
+ pdev->customer.ref_spad_char__total_rate_target_mcps =
+ total_rate_target_mcps;
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WrWord(
+ Dev,
+ VL53L1_REF_SPAD_CHAR__TOTAL_RATE_TARGET_MCPS,
+ total_rate_target_mcps);
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WrWord(
+ Dev,
+ VL53L1_RANGE_CONFIG__SIGMA_THRESH,
+ max_count_rate_rtn_limit_mcps);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WrWord(
+ Dev,
+ VL53L1_RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS,
+ min_count_rate_rtn_limit_mcps);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_ssc_config(
+ VL53L1_DEV Dev,
+ VL53L1_ssc_config_t *pssc_cfg,
+ uint16_t fast_osc_frequency)
+{
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t buffer[5];
+
+ uint32_t macro_period_us = 0;
+ uint16_t timeout_encoded = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ macro_period_us =
+ VL53L1_calc_macro_period_us(
+ fast_osc_frequency,
+ pssc_cfg->VL53L1_PRM_00007);
+
+
+
+
+
+ timeout_encoded =
+ VL53L1_calc_encoded_timeout(
+ pssc_cfg->timeout_us,
+ macro_period_us);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WrByte(
+ Dev,
+ VL53L1_CAL_CONFIG__VCSEL_START,
+ pssc_cfg->vcsel_start);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WrByte(
+ Dev,
+ VL53L1_GLOBAL_CONFIG__VCSEL_WIDTH,
+ pssc_cfg->vcsel_width);
+
+
+
+
+ buffer[0] = (uint8_t)((timeout_encoded & 0x0000FF00) >> 8);
+ buffer[1] = (uint8_t) (timeout_encoded & 0x000000FF);
+ buffer[2] = pssc_cfg->VL53L1_PRM_00007;
+ buffer[3] = (uint8_t)((pssc_cfg->rate_limit_mcps & 0x0000FF00) >> 8);
+ buffer[4] = (uint8_t) (pssc_cfg->rate_limit_mcps & 0x000000FF);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WriteMulti(
+ Dev,
+ VL53L1_RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+ buffer,
+ 5);
+
+
+
+
+
+
+
+ buffer[0] = pssc_cfg->VL53L1_PRM_00007;
+ buffer[1] = pssc_cfg->VL53L1_PRM_00007;
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WriteMulti(
+ Dev,
+ VL53L1_SD_CONFIG__WOI_SD0,
+ buffer,
+ 2);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WrByte(
+ Dev,
+ VL53L1_NVM_BIST__CTRL,
+ pssc_cfg->array_select);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_spad_rate_data(
+ VL53L1_DEV Dev,
+ VL53L1_spad_rate_data_t *pspad_rates)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ int i = 0;
+
+ uint8_t VL53L1_PRM_00005[512];
+ uint8_t *pdata = &VL53L1_PRM_00005[0];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_ReadMulti(
+ Dev,
+ VL53L1_PRIVATE__PATCH_BASE_ADDR_RSLV,
+ pdata,
+ 512);
+
+
+
+ pdata = &VL53L1_PRM_00005[0];
+ for (i = 0 ; i < VL53L1_NO_OF_SPAD_ENABLES ; i++) {
+ pspad_rates->rate_data[i] =
+ (uint16_t)VL53L1_decode_unsigned_integer(pdata, 2);
+ pdata += 2;
+ }
+
+
+
+
+ pspad_rates->VL53L1_PRM_00016 = VL53L1_NO_OF_SPAD_ENABLES;
+ pspad_rates->no_of_values = VL53L1_NO_OF_SPAD_ENABLES;
+ pspad_rates->fractional_bits = 15;
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_core_support.c b/drivers/input/misc/vl53L1/src/vl53l1_core_support.c
new file mode 100644
index 000000000000..3176e424d4c0
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_core_support.c
@@ -0,0 +1,931 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_ll_device.h"
+#include "vl53l1_platform_log.h"
+#include "vl53l1_core_support.h"
+#include "vl53l1_platform_user_data.h"
+#include "vl53l1_platform_user_defines.h"
+
+
+
+
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, \
+ status, fmt, ##__VA_ARGS__)
+
+#define trace_print(level, ...) \
+ _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_CORE, \
+ level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+
+
+uint32_t VL53L1_calc_pll_period_us(
+ uint16_t fast_osc_frequency)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint32_t pll_period_us = 0;
+
+ LOG_FUNCTION_START("");
+
+ pll_period_us = (0x01 << 30) / fast_osc_frequency;
+
+
+
+
+
+
+
+ LOG_FUNCTION_END(0);
+
+ return pll_period_us;
+}
+
+
+uint32_t VL53L1_duration_maths(
+ uint32_t pll_period_us,
+ uint32_t vcsel_parm_pclks,
+ uint32_t window_vclks,
+ uint32_t elapsed_mclks)
+{
+
+
+
+
+
+
+
+
+
+
+ uint64_t tmp_long_int = 0;
+ uint32_t duration_us = 0;
+
+
+
+
+
+
+ duration_us = window_vclks * pll_period_us;
+
+
+
+
+
+ duration_us = duration_us >> 12;
+
+
+
+ tmp_long_int = (uint64_t)duration_us;
+
+
+
+
+
+
+ duration_us = elapsed_mclks * vcsel_parm_pclks;
+
+
+
+
+
+ duration_us = duration_us >> 4;
+
+
+
+
+
+ tmp_long_int = tmp_long_int * (uint64_t)duration_us;
+
+
+
+
+
+ tmp_long_int = tmp_long_int >> 12;
+
+
+
+ if (tmp_long_int > 0xFFFFFFFF) {
+ tmp_long_int = 0xFFFFFFFF;
+ }
+
+ duration_us = (uint32_t)tmp_long_int;
+
+ return duration_us;
+}
+
+
+uint32_t VL53L1_events_per_spad_maths(
+ int32_t VL53L1_PRM_00009,
+ uint16_t num_spads,
+ uint32_t duration)
+{
+ uint64_t total_hist_counts = 0;
+ uint64_t xtalk_per_spad = 0;
+ uint32_t rate_per_spad_kcps = 0;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint64_t dividend = ((uint64_t)VL53L1_PRM_00009
+ * 1000 * 256);
+
+ total_hist_counts = do_division_u(dividend, (uint64_t)num_spads);
+
+
+
+
+ if (duration > 0) {
+
+
+
+
+
+
+
+
+ uint64_t dividend = (((uint64_t)(total_hist_counts << 11))
+ + ((uint64_t)duration / 2));
+
+ xtalk_per_spad = do_division_u(dividend, (uint64_t)duration);
+ } else {
+ xtalk_per_spad = (uint64_t)(total_hist_counts << 11);
+ }
+
+ rate_per_spad_kcps = (uint32_t)xtalk_per_spad;
+
+ return rate_per_spad_kcps;
+}
+
+
+uint32_t VL53L1_isqrt(uint32_t num)
+{
+
+
+
+
+
+
+
+
+ uint32_t res = 0;
+ uint32_t bit = 1 << 30;
+
+
+
+
+ while (bit > num) {
+ bit >>= 2;
+ }
+
+ while (bit != 0) {
+ if (num >= res + bit) {
+ num -= res + bit;
+ res = (res >> 1) + bit;
+ } else {
+ res >>= 1;
+ }
+ bit >>= 2;
+ }
+
+ return res;
+}
+
+
+void VL53L1_hist_calc_zero_distance_phase(
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+
+ uint32_t period = 0;
+ uint32_t VL53L1_PRM_00013 = 0;
+
+ LOG_FUNCTION_START("");
+
+ period = 2048 *
+ (uint32_t)VL53L1_decode_vcsel_period(pdata->VL53L1_PRM_00007);
+
+ VL53L1_PRM_00013 = period;
+ VL53L1_PRM_00013 += (uint32_t)pdata->phasecal_result__reference_phase;
+ VL53L1_PRM_00013 += (2048 * (uint32_t)pdata->phasecal_result__vcsel_start);
+ VL53L1_PRM_00013 -= (2048 * (uint32_t)pdata->cal_config__vcsel_start);
+
+ VL53L1_PRM_00013 = VL53L1_PRM_00013 % period;
+
+ pdata->zero_distance_phase = (uint16_t)VL53L1_PRM_00013;
+
+ LOG_FUNCTION_END(0);
+}
+
+
+void VL53L1_hist_estimate_ambient_from_thresholded_bins(
+ int32_t ambient_threshold_sigma,
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+
+
+
+
+ uint8_t bin = 0;
+ int32_t VL53L1_PRM_00029 = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ VL53L1_hist_find_min_max_bin_values(pdata);
+
+
+
+
+
+
+
+ VL53L1_PRM_00029 = (int32_t)VL53L1_isqrt((uint32_t)pdata->min_bin_value);
+ VL53L1_PRM_00029 *= ambient_threshold_sigma;
+ VL53L1_PRM_00029 += 0x07;
+ VL53L1_PRM_00029 = VL53L1_PRM_00029 >> 4;
+ VL53L1_PRM_00029 += pdata->min_bin_value;
+
+
+
+
+
+
+ pdata->number_of_ambient_samples = 0;
+ pdata->ambient_events_sum = 0;
+
+ for (bin = 0 ; bin < pdata->VL53L1_PRM_00017 ; bin++) {
+ if (pdata->bin_data[bin] < VL53L1_PRM_00029) {
+ pdata->ambient_events_sum += pdata->bin_data[bin];
+ pdata->number_of_ambient_samples++;
+ }
+ }
+
+
+
+
+
+
+ if (pdata->number_of_ambient_samples > 0) {
+ pdata->VL53L1_PRM_00026 = pdata->ambient_events_sum;
+ pdata->VL53L1_PRM_00026 += ((int32_t)pdata->number_of_ambient_samples/2);
+ pdata->VL53L1_PRM_00026 /= (int32_t)pdata->number_of_ambient_samples;
+ }
+
+ LOG_FUNCTION_END(0);
+}
+
+
+void VL53L1_hist_remove_ambient_bins(
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+
+
+ uint8_t bin = 0;
+ uint8_t VL53L1_PRM_00001 = 0;
+ uint8_t i = 0;
+
+
+
+
+ if ((pdata->bin_seq[0] & 0x07) == 0x07) {
+
+ i = 0;
+ for (VL53L1_PRM_00001 = 0 ; VL53L1_PRM_00001 < VL53L1_MAX_BIN_SEQUENCE_LENGTH ; VL53L1_PRM_00001++) {
+ if ((pdata->bin_seq[VL53L1_PRM_00001] & 0x07) != 0x07) {
+ pdata->bin_seq[i] = pdata->bin_seq[VL53L1_PRM_00001];
+ pdata->bin_rep[i] = pdata->bin_rep[VL53L1_PRM_00001];
+ i++;
+ }
+ }
+
+
+
+
+
+
+ for (VL53L1_PRM_00001 = i ; VL53L1_PRM_00001 < VL53L1_MAX_BIN_SEQUENCE_LENGTH ; VL53L1_PRM_00001++) {
+ pdata->bin_seq[VL53L1_PRM_00001] = VL53L1_MAX_BIN_SEQUENCE_CODE + 1;
+ pdata->bin_rep[VL53L1_PRM_00001] = 0;
+ }
+ }
+
+ if (pdata->number_of_ambient_bins > 0) {
+
+
+
+ for (bin = pdata->number_of_ambient_bins ;
+ bin < pdata->VL53L1_PRM_00016 ; bin++) {
+ pdata->bin_data[bin-pdata->number_of_ambient_bins] =
+ pdata->bin_data[bin];
+ }
+
+
+
+ pdata->VL53L1_PRM_00017 =
+ pdata->VL53L1_PRM_00017 -
+ pdata->number_of_ambient_bins;
+ pdata->number_of_ambient_bins = 0;
+ }
+}
+
+
+uint32_t VL53L1_calc_pll_period_mm(
+ uint16_t fast_osc_frequency)
+{
+
+
+
+
+
+
+ uint32_t pll_period_us = 0;
+ uint32_t pll_period_mm = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ pll_period_us = VL53L1_calc_pll_period_us(fast_osc_frequency);
+
+
+
+
+
+
+
+
+
+
+
+
+ pll_period_mm =
+ VL53L1_SPEED_OF_LIGHT_IN_AIR_DIV_8 *
+ (pll_period_us >> 2);
+
+
+
+ pll_period_mm = (pll_period_mm + (0x01<<15)) >> 16;
+
+ LOG_FUNCTION_END(0);
+
+ return pll_period_mm;
+}
+
+
+uint16_t VL53L1_rate_maths(
+ int32_t VL53L1_PRM_00006,
+ uint32_t time_us)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ uint32_t tmp_int = 0;
+ uint32_t frac_bits = 7;
+ uint16_t rate_mcps = 0;
+
+
+
+
+
+
+
+ if (VL53L1_PRM_00006 > VL53L1_SPAD_TOTAL_COUNT_MAX) {
+ tmp_int = VL53L1_SPAD_TOTAL_COUNT_MAX;
+ } else if (VL53L1_PRM_00006 > 0) {
+ tmp_int = (uint32_t)VL53L1_PRM_00006;
+ }
+
+
+
+
+
+
+
+ if (VL53L1_PRM_00006 > VL53L1_SPAD_TOTAL_COUNT_RES_THRES) {
+ frac_bits = 3;
+ } else {
+ frac_bits = 7;
+ }
+
+
+
+
+
+
+
+ if (time_us > 0) {
+ tmp_int = ((tmp_int << frac_bits) + (time_us / 2)) / time_us;
+ }
+
+
+
+
+
+ if (VL53L1_PRM_00006 > VL53L1_SPAD_TOTAL_COUNT_RES_THRES) {
+ tmp_int = tmp_int << 4;
+ }
+
+
+
+
+
+
+
+ if (tmp_int > 0xFFFF) {
+ tmp_int = 0xFFFF;
+ }
+
+ rate_mcps = (uint16_t)tmp_int;
+
+ return rate_mcps;
+}
+
+
+uint16_t VL53L1_rate_per_spad_maths(
+ uint32_t frac_bits,
+ uint32_t peak_count_rate,
+ uint16_t num_spads,
+ uint32_t max_output_value)
+{
+
+ uint32_t tmp_int = 0;
+
+
+
+ uint16_t rate_per_spad = 0;
+
+
+
+
+
+
+
+
+
+ if (num_spads > 0) {
+ tmp_int = (peak_count_rate << 8) << frac_bits;
+ tmp_int = (tmp_int + ((uint32_t)num_spads / 2)) / (uint32_t)num_spads;
+ } else {
+ tmp_int = ((peak_count_rate) << frac_bits);
+ }
+
+
+
+
+ if (tmp_int > max_output_value) {
+ tmp_int = max_output_value;
+ }
+
+ rate_per_spad = (uint16_t)tmp_int;
+
+ return rate_per_spad;
+}
+
+
+int32_t VL53L1_range_maths(
+ uint16_t fast_osc_frequency,
+ uint16_t VL53L1_PRM_00013,
+ uint16_t zero_distance_phase,
+ int32_t gain_factor,
+ int32_t range_offset_mm)
+{
+
+
+
+
+
+ uint32_t pll_period_us = 0;
+
+ int64_t tmp_long_int = 0;
+ int32_t range_mm = 0;
+
+
+
+
+ pll_period_us = VL53L1_calc_pll_period_us(fast_osc_frequency);
+
+
+
+
+
+
+
+
+
+
+ tmp_long_int = (int64_t)VL53L1_PRM_00013 - (int64_t)zero_distance_phase;
+
+
+
+
+
+
+
+
+
+
+ tmp_long_int = tmp_long_int * (int64_t)pll_period_us;
+
+
+
+
+
+
+ tmp_long_int = tmp_long_int / (0x01 << 9);
+
+
+
+
+
+
+
+
+
+
+
+ tmp_long_int = tmp_long_int * VL53L1_SPEED_OF_LIGHT_IN_AIR_DIV_8;
+
+
+
+
+
+
+ tmp_long_int = tmp_long_int / (0x01 << 22);
+
+
+
+ range_mm = (int32_t)tmp_long_int + range_offset_mm;
+
+
+
+ range_mm *= gain_factor;
+ range_mm += 0x0400;
+ range_mm /= 0x0800;
+
+
+
+ range_mm = range_mm / (0x01 << 2);
+
+ return range_mm;
+}
+
+
+uint8_t VL53L1_decode_vcsel_period(uint8_t vcsel_period_reg)
+{
+
+
+
+
+
+
+ uint8_t VL53L1_PRM_00028 = 0;
+
+ VL53L1_PRM_00028 = (vcsel_period_reg + 1) << 1;
+
+ return VL53L1_PRM_00028;
+}
+
+
+void VL53L1_copy_xtalk_bin_data_to_histogram_data_struct(
+ VL53L1_xtalk_histogram_shape_t *pxtalk,
+ VL53L1_histogram_bin_data_t *phist)
+{
+
+
+
+
+
+
+ phist->cal_config__vcsel_start =
+ pxtalk->cal_config__vcsel_start;
+ phist->VL53L1_PRM_00018 =
+ pxtalk->VL53L1_PRM_00018;
+ phist->VL53L1_PRM_00015 =
+ pxtalk->VL53L1_PRM_00015;
+
+ phist->phasecal_result__reference_phase =
+ pxtalk->phasecal_result__reference_phase;
+ phist->phasecal_result__vcsel_start =
+ pxtalk->phasecal_result__vcsel_start;
+
+ phist->vcsel_width =
+ pxtalk->vcsel_width;
+ phist->zero_distance_phase =
+ pxtalk->zero_distance_phase;
+
+ phist->zone_id = pxtalk->zone_id;
+ phist->VL53L1_PRM_00016 = pxtalk->VL53L1_PRM_00016;
+ phist->time_stamp = pxtalk->time_stamp;
+}
+
+
+void VL53L1_init_histogram_bin_data_struct(
+ int32_t bin_value,
+ uint16_t VL53L1_PRM_00017,
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+
+ uint16_t i = 0;
+
+ pdata->cfg_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
+ pdata->rd_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
+
+ pdata->zone_id = 0;
+ pdata->time_stamp = 0;
+
+ pdata->VL53L1_PRM_00015 = 0;
+ pdata->VL53L1_PRM_00016 = VL53L1_HISTOGRAM_BUFFER_SIZE;
+ pdata->VL53L1_PRM_00017 = (uint8_t)VL53L1_PRM_00017;
+ pdata->number_of_ambient_bins = 0;
+
+ pdata->result__interrupt_status = 0;
+ pdata->result__range_status = 0;
+ pdata->result__report_status = 0;
+ pdata->result__stream_count = 0;
+
+ pdata->result__dss_actual_effective_spads = 0;
+ pdata->phasecal_result__reference_phase = 0;
+ pdata->phasecal_result__vcsel_start = 0;
+ pdata->cal_config__vcsel_start = 0;
+
+ pdata->vcsel_width = 0;
+ pdata->VL53L1_PRM_00007 = 0;
+ pdata->VL53L1_PRM_00018 = 0;
+ pdata->total_periods_elapsed = 0;
+
+ pdata->min_bin_value = 0;
+ pdata->max_bin_value = 0;
+
+ pdata->zero_distance_phase = 0;
+ pdata->number_of_ambient_samples = 0;
+ pdata->ambient_events_sum = 0;
+ pdata->VL53L1_PRM_00026 = 0;
+
+ for (i = 0 ; i < VL53L1_MAX_BIN_SEQUENCE_LENGTH ; i++) {
+ pdata->bin_seq[i] = (uint8_t)i;
+ }
+ for (i = 0 ; i < VL53L1_MAX_BIN_SEQUENCE_LENGTH ; i++) {
+ pdata->bin_rep[i] = 1;
+ }
+
+ for (i = 0 ; i < VL53L1_HISTOGRAM_BUFFER_SIZE ; i++) {
+ if (i < VL53L1_PRM_00017) {
+ pdata->bin_data[i] = bin_value;
+ } else {
+ pdata->bin_data[i] = 0;
+ }
+ }
+}
+
+
+void VL53L1_decode_row_col(
+ uint8_t spad_number,
+ uint8_t *prow,
+ uint8_t *pcol)
+{
+
+
+
+
+
+
+
+ if (spad_number > 127) {
+ *prow = 8 + ((255-spad_number) & 0x07);
+ *pcol = (spad_number-128) >> 3;
+ } else {
+ *prow = spad_number & 0x07;
+ *pcol = (127-spad_number) >> 3;
+ }
+}
+
+
+void VL53L1_hist_find_min_max_bin_values(
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+ uint8_t bin = 0;
+
+ LOG_FUNCTION_START("");
+
+ for (bin = 0 ; bin < pdata->VL53L1_PRM_00017 ; bin++) {
+
+ if (bin == 0 || pdata->min_bin_value >= pdata->bin_data[bin]) {
+ pdata->min_bin_value = pdata->bin_data[bin];
+ }
+
+ if (bin == 0 || pdata->max_bin_value <= pdata->bin_data[bin]) {
+ pdata->max_bin_value = pdata->bin_data[bin];
+ }
+ }
+
+ LOG_FUNCTION_END(0);
+
+}
+
+
+void VL53L1_hist_estimate_ambient_from_ambient_bins(
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+
+ uint8_t bin = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (pdata->number_of_ambient_bins > 0) {
+
+ pdata->number_of_ambient_samples =
+ pdata->number_of_ambient_bins;
+
+
+
+
+ pdata->ambient_events_sum = 0;
+ for (bin = 0 ; bin < pdata->number_of_ambient_bins ; bin++) {
+ pdata->ambient_events_sum += pdata->bin_data[bin];
+ }
+
+ pdata->VL53L1_PRM_00026 = pdata->ambient_events_sum;
+ pdata->VL53L1_PRM_00026 +=
+ ((int32_t)pdata->number_of_ambient_bins / 2);
+ pdata->VL53L1_PRM_00026 /=
+ (int32_t)pdata->number_of_ambient_bins;
+
+ }
+
+ LOG_FUNCTION_END(0);
+}
+
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_error_strings.c b/drivers/input/misc/vl53L1/src/vl53l1_error_strings.c
new file mode 100644
index 000000000000..716ef9ba3607
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_error_strings.c
@@ -0,0 +1,327 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_error_codes.h"
+#include "vl53l1_error_strings.h"
+#include "vl53l1_platform_log.h"
+#include "vl53l1_ll_def.h"
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, \
+ status, fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_get_pal_error_string(
+ VL53L1_Error PalErrorCode,
+ char *pPalErrorString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+#ifdef VL53L1_USE_EMPTY_STRING
+ VL53L1_COPYSTRING(pPalErrorString, "");
+#else
+
+ switch (PalErrorCode) {
+ case VL53L1_ERROR_NONE:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_NONE);
+ break;
+ case VL53L1_ERROR_CALIBRATION_WARNING:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_CALIBRATION_WARNING);
+ break;
+ case VL53L1_ERROR_MIN_CLIPPED:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_MIN_CLIPPED);
+ break;
+ case VL53L1_ERROR_UNDEFINED:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_UNDEFINED);
+ break;
+ case VL53L1_ERROR_INVALID_PARAMS:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_INVALID_PARAMS);
+ break;
+ case VL53L1_ERROR_NOT_SUPPORTED:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_NOT_SUPPORTED);
+ break;
+ case VL53L1_ERROR_RANGE_ERROR:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_RANGE_ERROR);
+ break;
+ case VL53L1_ERROR_TIME_OUT:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_TIME_OUT);
+ break;
+ case VL53L1_ERROR_MODE_NOT_SUPPORTED:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_MODE_NOT_SUPPORTED);
+ break;
+ case VL53L1_ERROR_BUFFER_TOO_SMALL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_BUFFER_TOO_SMALL);
+ break;
+ case VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_COMMS_BUFFER_TOO_SMALL);
+ break;
+ case VL53L1_ERROR_GPIO_NOT_EXISTING:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_GPIO_NOT_EXISTING);
+ break;
+ case VL53L1_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED);
+ break;
+ case VL53L1_ERROR_CONTROL_INTERFACE:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_CONTROL_INTERFACE);
+ break;
+ case VL53L1_ERROR_INVALID_COMMAND:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_INVALID_COMMAND);
+ break;
+ case VL53L1_ERROR_DIVISION_BY_ZERO:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_DIVISION_BY_ZERO);
+ break;
+ case VL53L1_ERROR_REF_SPAD_INIT:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_REF_SPAD_INIT);
+ break;
+ case VL53L1_ERROR_GPH_SYNC_CHECK_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_GPH_SYNC_CHECK_FAIL);
+ break;
+ case VL53L1_ERROR_STREAM_COUNT_CHECK_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_STREAM_COUNT_CHECK_FAIL);
+ break;
+ case VL53L1_ERROR_GPH_ID_CHECK_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_GPH_ID_CHECK_FAIL);
+ break;
+ case VL53L1_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL);
+ break;
+ case VL53L1_ERROR_ZONE_GPH_ID_CHECK_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_ZONE_GPH_ID_CHECK_FAIL);
+ break;
+
+ case VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_XTALK_EXTRACTION_NO_SAMPLES_FAIL);
+ break;
+ case VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL);
+ break;
+
+ case VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL);
+ break;
+ case VL53L1_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL);
+ break;
+ case VL53L1_ERROR_ZONE_CAL_NO_SAMPLE_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_ZONE_CAL_NO_SAMPLE_FAIL);
+ break;
+
+ case VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_OFFSET_CAL_MISSING_SAMPLES);
+ break;
+ case VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH);
+ break;
+ case VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_OFFSET_CAL_RATE_TOO_HIGH);
+ break;
+ case VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW);
+ break;
+
+ case VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_ZONE_CAL_MISSING_SAMPLES);
+ break;
+ case VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_ZONE_CAL_SIGMA_TOO_HIGH);
+ break;
+ case VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_ZONE_CAL_RATE_TOO_HIGH);
+ break;
+
+ case VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS);
+ break;
+ case VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH);
+ break;
+ case VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW);
+ break;
+
+ case VL53L1_WARNING_XTALK_MISSING_SAMPLES:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_XTALK_MISSING_SAMPLES);
+ break;
+ case VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT);
+ break;
+ case VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT);
+ break;
+
+ case VL53L1_ERROR_DEVICE_FIRMWARE_TOO_OLD:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_OLD);
+ break;
+ case VL53L1_ERROR_DEVICE_FIRMWARE_TOO_NEW:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_NEW);
+ break;
+ case VL53L1_ERROR_UNIT_TEST_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_UNIT_TEST_FAIL);
+ break;
+ case VL53L1_ERROR_FILE_READ_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_FILE_READ_FAIL);
+ break;
+ case VL53L1_ERROR_FILE_WRITE_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_FILE_WRITE_FAIL);
+ break;
+ case VL53L1_ERROR_NOT_IMPLEMENTED:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_NOT_IMPLEMENTED);
+ break;
+ default:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_UNKNOW_ERROR_CODE);
+ }
+
+#endif
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_fpga_core.c b/drivers/input/misc/vl53L1/src/vl53l1_fpga_core.c
new file mode 100644
index 000000000000..194eb570c306
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_fpga_core.c
@@ -0,0 +1,167 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_register_map.h"
+#include "vl53l1_core.h"
+#include "vl53l1_fpga_core.h"
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_is_firmware_ready_fpga(
+ VL53L1_DEV Dev,
+ uint8_t *pready)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t comms_buffer[5];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_INTERRUPT_MANAGER__ENABLES,
+ comms_buffer,
+ 5);
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pdev->dbg_results.interrupt_manager__enables =
+ comms_buffer[0];
+ pdev->dbg_results.interrupt_manager__clear =
+ comms_buffer[1];
+ pdev->dbg_results.interrupt_manager__status =
+ comms_buffer[2];
+ pdev->dbg_results.mcu_to_host_bank__wr_access_en =
+ comms_buffer[3];
+ pdev->dbg_results.power_management__go1_reset_status =
+ comms_buffer[4];
+
+ if (((pdev->dbg_results.interrupt_manager__enables & 0x1F) == 0x1F) &&
+ ((pdev->dbg_results.interrupt_manager__clear & 0x1F) == 0x1F))
+ *pready = 0x01;
+ else
+ *pready = 0x00;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_hist_char.c b/drivers/input/misc/vl53L1/src/vl53l1_hist_char.c
new file mode 100644
index 000000000000..0570d90dd969
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_hist_char.c
@@ -0,0 +1,282 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include
+
+#include
+
+
+
+
+
+
+
+#include "vl53l1_core.h"
+#include "vl53l1_register_settings.h"
+#include "vl53l1_hist_char.h"
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_HISTOGRAM, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_HISTOGRAM, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_HISTOGRAM, status, fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_set_calib_config(
+ VL53L1_DEV Dev,
+ uint8_t vcsel_delay__a0,
+ uint8_t calib_1,
+ uint8_t calib_2,
+ uint8_t calib_3,
+ uint8_t calib_2__a0,
+ uint8_t spad_readout)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[3];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status = VL53L1_enable_powerforce(Dev);
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_disable_firmware(Dev);
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__VCSEL_DELAY__A0,
+ vcsel_delay__a0);
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+ comms_buffer[0] = calib_1;
+ comms_buffer[1] = calib_2;
+ comms_buffer[2] = calib_3;
+
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_RANGING_CORE__CALIB_1,
+ comms_buffer,
+ 3);
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__CALIB_2__A0,
+ calib_2__a0);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__SPAD_READOUT,
+ spad_readout);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+VL53L1_Error VL53L1_set_hist_calib_pulse_delay(
+ VL53L1_DEV Dev,
+ uint8_t calib_delay)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status =
+ VL53L1_set_calib_config(
+ Dev,
+ 0x01,
+
+ calib_delay,
+
+ 0x04,
+
+ 0x08,
+
+ 0x14,
+
+ VL53L1_RANGING_CORE__SPAD_READOUT__CALIB_PULSES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_disable_calib_pulse_delay(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status =
+ VL53L1_set_calib_config(
+ Dev,
+ 0x00,
+
+ 0x00,
+
+ 0x00,
+
+ 0x00,
+
+ 0x00,
+
+ VL53L1_RANGING_CORE__SPAD_READOUT__STANDARD);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_nvm.c b/drivers/input/misc/vl53L1/src/vl53l1_nvm.c
new file mode 100644
index 000000000000..f595257aceaa
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_nvm.c
@@ -0,0 +1,1639 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#endif
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_platform_log.h"
+#include "vl53l1_register_map.h"
+#include "vl53l1_core.h"
+#include "vl53l1_nvm_structs.h"
+#include "vl53l1_nvm_map.h"
+#include "vl53l1_nvm.h"
+
+
+
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_NVM, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_NVM, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_NVM, status, fmt, ##__VA_ARGS__)
+
+#define trace_print(level, ...) \
+ _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_NVM, \
+ level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_nvm_enable(
+ VL53L1_DEV Dev,
+ uint16_t nvm_ctrl_pulse_width,
+ int32_t nvm_power_up_delay_us)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_powerforce(Dev);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WaitUs(
+ Dev,
+ VL53L1_ENABLE_POWERFORCE_SETTLING_TIME_US);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__PDN,
+ 0x01);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__CLK_CTRL1,
+ 0x05);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WaitUs(
+ Dev,
+ nvm_power_up_delay_us);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__MODE,
+ 0x01);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrWord(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__PULSE_WIDTH_MSB,
+ nvm_ctrl_pulse_width);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_nvm_read(
+ VL53L1_DEV Dev,
+ uint8_t start_address,
+ uint8_t count,
+ uint8_t *pdata)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t nvm_addr = 0;
+
+ LOG_FUNCTION_START("");
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%-12s = 0x%02X (%3u)\n",
+ "nvm_addr", nvm_addr, nvm_addr);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%-12s = 0x%02X (%3u)\n",
+ "count", count, count);
+
+ for (nvm_addr = start_address; nvm_addr < (start_address+count) ; nvm_addr++) {
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__ADDR,
+ nvm_addr);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__READN,
+ 0x00);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WaitUs(
+ Dev,
+ VL53L1_NVM_READ_TRIGGER_DELAY_US);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__READN,
+ 0x01);
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__DATAOUT_MMM,
+ pdata,
+ 4);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "NVM address : 0x%02X = 0x%02X%02X%02X%02X\n",
+ nvm_addr, *pdata, *(pdata+1), *(pdata+2), *(pdata+3));
+
+
+
+
+ pdata = pdata + 4;
+
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_nvm_disable(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__READN,
+ 0x01);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__PDN,
+ 0x00);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_powerforce(Dev);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_nvm_format_decode(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_data_t *pdata)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t i = 0;
+ uint8_t *ptmp = NULL;
+ int pptmp[VL53L1_NVM_MAX_FMT_RANGE_DATA];
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_NVM_SIZE_IN_BYTES > buf_size)
+ return VL53L1_ERROR_BUFFER_TOO_SMALL;
+
+ pdata->nvm__identification_model_id =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__IDENTIFICATION__MODEL_ID,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__identification_module_type =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__IDENTIFICATION__MODULE_TYPE,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__identification_revision_id =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__IDENTIFICATION__REVISION_ID,
+ 0x0000000F,
+ 0,
+ 0);
+ pdata->nvm__identification_module_id =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__IDENTIFICATION__MODULE_ID,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__i2c_valid =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__I2C_VALID,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__i2c_device_address_ews =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__I2C_SLAVE__DEVICE_ADDRESS,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__ews__fast_osc_frequency =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__EWS__OSC_MEASURED__FAST_OSC_FREQUENCY,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__ews__fast_osc_trim_max =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__FAST_OSC_TRIM_MAX,
+ 0x0000007F,
+ 0,
+ 0);
+ pdata->nvm__ews__fast_osc_freq_set =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__FAST_OSC_FREQ_SET,
+ 0x00000007,
+ 0,
+ 0);
+ pdata->nvm__ews__slow_osc_calibration =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__EWS__SLOW_OSC_CALIBRATION,
+ 0x000003FF,
+ 0,
+ 0);
+ pdata->nvm__fmt__fast_osc_frequency =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__FMT__OSC_MEASURED__FAST_OSC_FREQUENCY,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__fast_osc_trim_max =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FAST_OSC_TRIM_MAX,
+ 0x0000007F,
+ 0,
+ 0);
+ pdata->nvm__fmt__fast_osc_freq_set =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FAST_OSC_FREQ_SET,
+ 0x00000007,
+ 0,
+ 0);
+ pdata->nvm__fmt__slow_osc_calibration =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__FMT__SLOW_OSC_CALIBRATION,
+ 0x000003FF,
+ 0,
+ 0);
+ pdata->nvm__vhv_config_unlock =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__VHV_CONFIG_UNLOCK,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__ref_selvddpix =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__REF_SELVDDPIX,
+ 0x0000000F,
+ 0,
+ 0);
+ pdata->nvm__ref_selvquench =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__REF_SELVQUENCH,
+ 0x00000078,
+ 3,
+ 0);
+ pdata->nvm__regavdd1v2_sel =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__REGAVDD1V2_SEL_REGDVDD1V2_SEL,
+ 0x0000000C,
+ 2,
+ 0);
+ pdata->nvm__regdvdd1v2_sel =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__REGAVDD1V2_SEL_REGDVDD1V2_SEL,
+ 0x00000003,
+ 0,
+ 0);
+ pdata->nvm__vhv_timeout__macrop =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND,
+ 0x00000003,
+ 0,
+ 0);
+ pdata->nvm__vhv_loop_bound =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND,
+ 0x000000FC,
+ 2,
+ 0);
+ pdata->nvm__vhv_count_threshold =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__VHV_CONFIG__COUNT_THRESH,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__vhv_offset =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__VHV_CONFIG__OFFSET,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__vhv_init_enable =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__VHV_CONFIG__INIT,
+ 0x00000080,
+ 7,
+ 0);
+ pdata->nvm__vhv_init_value =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__VHV_CONFIG__INIT,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_vcsel_trim_ll =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_TRIM_LL,
+ 0x00000007,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_vcsel_selion_ll =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_LL,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_vcsel_selion_max_ll =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_MAX_LL,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_mult_ll =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__MULT_LL,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_clip_ll =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__CLIP_LL,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_vcsel_trim_ld =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_TRIM_LD,
+ 0x00000007,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_vcsel_selion_ld =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_LD,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_vcsel_selion_max_ld =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_MAX_LD,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_mult_ld =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__MULT_LD,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_clip_ld =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__CLIP_LD,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_lock_byte =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY_LOCK_BYTE,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_unlock_byte =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY_UNLOCK_BYTE,
+ 0x000000FF,
+ 0,
+ 0);
+
+
+
+
+ ptmp = pbuffer + VL53L1_NVM__EWS__SPAD_ENABLES_RTN_0_;
+ for (i = 0 ; i < VL53L1_RTN_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__ews__spad_enables_rtn[i] = *ptmp++;
+
+ ptmp = pbuffer + VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_0_;
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__ews__spad_enables_ref__loc1[i] = *ptmp++;
+
+ ptmp = pbuffer + VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_0_;
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__ews__spad_enables_ref__loc2[i] = *ptmp++;
+
+ ptmp = pbuffer + VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_0_;
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__ews__spad_enables_ref__loc3[i] = *ptmp++;
+
+
+
+
+ ptmp = pbuffer + VL53L1_NVM__FMT__SPAD_ENABLES_RTN_0_;
+ for (i = 0 ; i < VL53L1_RTN_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__fmt__spad_enables_rtn[i] = *ptmp++;
+
+ ptmp = pbuffer + VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_0_;
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__fmt__spad_enables_ref__loc1[i] = *ptmp++;
+
+ ptmp = pbuffer + VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_0_;
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__fmt__spad_enables_ref__loc2[i] = *ptmp++;
+
+ ptmp = pbuffer + VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_0_;
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__fmt__spad_enables_ref__loc3[i] = *ptmp++;
+
+
+ pdata->nvm__fmt__roi_config__mode_roi_centre_spad =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__ROI_CONFIG__MODE_ROI_CENTRE_SPAD,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__fmt__roi_config__mode_roi_x_size =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__ROI_CONFIG__MODE_ROI_XY_SIZE,
+ 0x000000F0,
+ 4,
+ 0);
+ pdata->nvm__fmt__roi_config__mode_roi_y_size =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__ROI_CONFIG__MODE_ROI_XY_SIZE,
+ 0x0000000F,
+ 0,
+ 0);
+ pdata->nvm__fmt__ref_spad_apply__num_requested_ref_spad =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__REF_SPAD_APPLY__NUM_REQUESTED_REF_SPAD,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__fmt__ref_spad_man__ref_location =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__REF_SPAD_MAN__REF_LOCATION,
+ 0x00000003,
+ 0,
+ 0);
+ pdata->nvm__fmt__mm_config__inner_offset_mm =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__FMT__MM_CONFIG__INNER_OFFSET_MM,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__mm_config__outer_offset_mm =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__FMT__MM_CONFIG__OUTER_OFFSET_MM,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__algo_part_to_part_range_offset_mm =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__FMT__ALGO__PART_TO_PART_RANGE_OFFSET_MM,
+ 0x00000FFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__algo__crosstalk_compensation_plane_offset_kcps =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__algo__crosstalk_compensation_x_plane_gradient_kcps =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__algo__crosstalk_compensation_y_plane_gradient_kcps =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__spare__host_config__nvm_config_spare_0 =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_0,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__fmt__spare__host_config__nvm_config_spare_1 =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_1,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__customer_space_programmed =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__CUSTOMER_NVM_SPACE_PROGRAMMED,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__cust__i2c_device_address =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__CUST__I2C_SLAVE__DEVICE_ADDRESS,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__cust__ref_spad_apply__num_requested_ref_spad =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__CUST__REF_SPAD_APPLY__NUM_REQUESTED_REF_SPAD,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__cust__ref_spad_man__ref_location =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__CUST__REF_SPAD_MAN__REF_LOCATION,
+ 0x00000003,
+ 0,
+ 0);
+ pdata->nvm__cust__mm_config__inner_offset_mm =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__CUST__MM_CONFIG__INNER_OFFSET_MM,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__cust__mm_config__outer_offset_mm =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__CUST__MM_CONFIG__OUTER_OFFSET_MM,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__cust__algo_part_to_part_range_offset_mm =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__CUST__ALGO__PART_TO_PART_RANGE_OFFSET_MM,
+ 0x00000FFF,
+ 0,
+ 0);
+ pdata->nvm__cust__algo__crosstalk_compensation_plane_offset_kcps =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__cust__algo__crosstalk_compensation_x_plane_gradient_kcps =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__cust__algo__crosstalk_compensation_y_plane_gradient_kcps =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__cust__spare__host_config__nvm_config_spare_0 =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__CUST__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_0,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__cust__spare__host_config__nvm_config_spare_1 =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__CUST__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_1,
+ 0x000000FF,
+ 0,
+ 0);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_cal_peak_rate_map(
+ buf_size,
+ pbuffer + VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_INDEX,
+ &(pdata->fmt_peak_rate_map));
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_additional_offset_cal_data(
+ buf_size,
+ pbuffer + VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_INDEX,
+ &(pdata->fmt_add_offset_data));
+
+
+
+
+ pptmp[0] = VL53L1_NVM__FMT__RANGE_RESULTS__140MM_MM_PRE_RANGE;
+ pptmp[1] = VL53L1_NVM__FMT__RANGE_RESULTS__140MM_DARK;
+ pptmp[2] = VL53L1_NVM__FMT__RANGE_RESULTS__400MM_DARK;
+ pptmp[3] = VL53L1_NVM__FMT__RANGE_RESULTS__400MM_AMBIENT;
+
+ for (i = 0 ; i < VL53L1_NVM_MAX_FMT_RANGE_DATA ; i++) {
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_fmt_range_results_data(
+ buf_size,
+ pbuffer + pptmp[i],
+ &(pdata->fmt_range_data[i]));
+ }
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_fmt_info(
+ buf_size,
+ pbuffer,
+ &(pdata->fmt_info));
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_ews_info(
+ buf_size,
+ pbuffer,
+ &(pdata->ews_info));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_nvm_decode_cal_peak_rate_map(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_cal_peak_rate_map_t *pdata)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t *ptmp = NULL;
+ uint8_t i = 0;
+
+ if (VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_SIZE > buf_size)
+ return VL53L1_ERROR_BUFFER_TOO_SMALL;
+
+ pdata->cal_distance_mm =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer);
+
+ pdata->cal_reflectance_pc =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 2);
+ pdata->cal_reflectance_pc =
+ pdata->cal_reflectance_pc >> 6;
+
+ pdata->max_samples = VL53L1_NVM_PEAK_RATE_MAP_SAMPLES;
+ pdata->width = VL53L1_NVM_PEAK_RATE_MAP_WIDTH;
+ pdata->height = VL53L1_NVM_PEAK_RATE_MAP_HEIGHT;
+
+ ptmp = pbuffer + 4;
+ for (i = 0 ; i < VL53L1_NVM_PEAK_RATE_MAP_SAMPLES ; i++) {
+ pdata->peak_rate_mcps[i] =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, ptmp);
+ ptmp += 2;
+ }
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_nvm_decode_additional_offset_cal_data(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_additional_offset_cal_data_t *pdata)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ if (VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_SIZE > buf_size)
+ return VL53L1_ERROR_BUFFER_TOO_SMALL;
+
+ pdata->result__mm_inner_actual_effective_spads =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer);
+
+ pdata->result__mm_outer_actual_effective_spads =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 2);
+
+ pdata->result__mm_inner_peak_signal_count_rtn_mcps =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 4);
+
+ pdata->result__mm_outer_peak_signal_count_rtn_mcps =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 6);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_nvm_decode_fmt_range_results_data(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_fmt_range_data_t *pdata)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ if (VL53L1_NVM__FMT__RANGE_RESULTS__SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_BUFFER_TOO_SMALL;
+
+ pdata->result__actual_effective_rtn_spads =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer);
+
+ pdata->ref_spad_array__num_requested_ref_spads =
+ *(pbuffer+2);
+
+ pdata->ref_spad_array__ref_location =
+ *(pbuffer+3);
+
+ pdata->result__peak_signal_count_rate_rtn_mcps =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 4);
+
+ pdata->result__ambient_count_rate_rtn_mcps =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 6);
+
+ pdata->result__peak_signal_count_rate_ref_mcps =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 8);
+
+ pdata->result__ambient_count_rate_ref_mcps =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 10);
+
+ pdata->measured_distance_mm =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 12);
+
+ pdata->measured_distance_stdev_mm =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 14);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_nvm_decode_fmt_info(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_fmt_info_t *pdata)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ if (VL53L1_NVM_SIZE_IN_BYTES > buf_size)
+ return VL53L1_ERROR_BUFFER_TOO_SMALL;
+
+ pdata->nvm__fmt__fgc[0] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_0,
+ 0x000000FE,
+ 1,
+ 0);
+ pdata->nvm__fmt__fgc[1] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_1,
+ 0x000001FC,
+ 2,
+ 0);
+ pdata->nvm__fmt__fgc[2] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_2 - 1,
+ 0x000003F8,
+ 3,
+ 0);
+ pdata->nvm__fmt__fgc[3] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_3 - 1,
+ 0x000007F0,
+ 4,
+ 0);
+ pdata->nvm__fmt__fgc[4] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_4 - 1,
+ 0x00000FE0,
+ 5,
+ 0);
+ pdata->nvm__fmt__fgc[5] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_5 - 1,
+ 0x00001FC0,
+ 6,
+ 0);
+ pdata->nvm__fmt__fgc[6] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_6 - 1,
+ 0x00003F80,
+ 7,
+ 0);
+ pdata->nvm__fmt__fgc[7] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_6,
+ 0x0000007F,
+ 0,
+ 0);
+ pdata->nvm__fmt__fgc[8] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_7,
+ 0x000000FE,
+ 1,
+ 0);
+ pdata->nvm__fmt__fgc[9] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_8,
+ 0x000001FC,
+ 2,
+ 0);
+ pdata->nvm__fmt__fgc[10] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_9 - 1,
+ 0x000003F8,
+ 3,
+ 0);
+ pdata->nvm__fmt__fgc[11] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_10 - 1,
+ 0x000007F0,
+ 4,
+ 0);
+ pdata->nvm__fmt__fgc[12] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_11 - 1,
+ 0x00000FE0,
+ 5,
+ 0);
+ pdata->nvm__fmt__fgc[13] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_12 - 1,
+ 0x00001FC0,
+ 6,
+ 0);
+ pdata->nvm__fmt__fgc[14] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_13 - 1,
+ 0x00003F80,
+ 7,
+ 0);
+ pdata->nvm__fmt__fgc[15] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_13,
+ 0x0000007F,
+ 0,
+ 0);
+ pdata->nvm__fmt__fgc[16] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_14,
+ 0x000000FE,
+ 1,
+ 0);
+ pdata->nvm__fmt__fgc[17] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_15,
+ 0x000001FC,
+ 2,
+ 0);
+ pdata->nvm__fmt__fgc[18] = 0x00;
+
+ pdata->nvm__fmt__test_program_major =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__TEST_PROGRAM_MAJOR_MINOR,
+ 0x000000E0,
+ 5,
+ 0);
+ pdata->nvm__fmt__test_program_minor =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__TEST_PROGRAM_MAJOR_MINOR,
+ 0x0000001F,
+ 0,
+ 0);
+ pdata->nvm__fmt__map_major =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__MAP_MAJOR_MINOR,
+ 0x000000E0,
+ 5,
+ 0);
+ pdata->nvm__fmt__map_minor =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__MAP_MAJOR_MINOR,
+ 0x0000001F,
+ 0,
+ 0);
+ pdata->nvm__fmt__year =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__YEAR_MONTH,
+ 0x000000F0,
+ 4,
+ 0);
+ pdata->nvm__fmt__month =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__YEAR_MONTH,
+ 0x0000000F,
+ 0,
+ 0);
+ pdata->nvm__fmt__day =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__DAY_MODULE_DATE_PHASE,
+ 0x000000F8,
+ 3,
+ 0);
+ pdata->nvm__fmt__module_date_phase =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__DAY_MODULE_DATE_PHASE,
+ 0x00000007,
+ 0,
+ 0);
+ pdata->nvm__fmt__time =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__FMT__TIME,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__tester_id =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__TESTER_ID,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__fmt__site_id =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__SITE_ID,
+ 0x000000FF,
+ 0,
+ 0);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_nvm_decode_ews_info(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_ews_info_t *pdata)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ if (VL53L1_NVM_SIZE_IN_BYTES > buf_size)
+ return VL53L1_ERROR_BUFFER_TOO_SMALL;
+
+ pdata->nvm__ews__test_program_major =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__TEST_PROGRAM_MAJOR_MINOR,
+ 0x000000E0,
+ 5,
+ 0);
+ pdata->nvm__ews__test_program_minor =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__TEST_PROGRAM_MAJOR_MINOR,
+ 0x0000001F,
+ 0,
+ 0);
+ pdata->nvm__ews__probe_card_major =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__PROBE_CARD_MAJOR_MINOR,
+ 0x000000F0,
+ 4,
+ 0);
+ pdata->nvm__ews__probe_card_minor =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__PROBE_CARD_MAJOR_MINOR,
+ 0x0000000F,
+ 0,
+ 0);
+ pdata->nvm__ews__tester_id =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__TESTER_ID,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__ews__lot[6] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__LOT__BYTE_0,
+ 0x000000FC,
+ 2,
+ 32);
+ pdata->nvm__ews__lot[5] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__LOT__BYTE_1 - 1,
+ 0x000003F0,
+ 4,
+ 32);
+ pdata->nvm__ews__lot[4] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__LOT__BYTE_2 - 1,
+ 0x00000FC0,
+ 6,
+ 32);
+ pdata->nvm__ews__lot[3] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__LOT__BYTE_2,
+ 0x0000003F,
+ 0,
+ 32);
+ pdata->nvm__ews__lot[2] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__LOT__BYTE_3,
+ 0x000000FC,
+ 2,
+ 32);
+ pdata->nvm__ews__lot[1] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__LOT__BYTE_4 - 1,
+ 0x000003F0,
+ 4,
+ 32);
+ pdata->nvm__ews__lot[0] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__LOT__BYTE_5 - 1,
+ 0x00000FC0,
+ 6,
+ 32);
+
+ pdata->nvm__ews__lot[7] = 0x00;
+
+ pdata->nvm__ews__wafer =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__WAFER,
+ 0x0000001F,
+ 0,
+ 0);
+ pdata->nvm__ews__xcoord =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__XCOORD,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__ews__ycoord =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__YCOORD,
+ 0x000000FF,
+ 0,
+ 0);
+
+ return status;
+
+}
+
+
+void VL53L1_nvm_format_encode(
+ VL53L1_decoded_nvm_data_t *pnvm_info,
+ uint8_t *pnvm_data)
+{
+ SUPPRESS_UNUSED_WARNING(pnvm_info);
+ SUPPRESS_UNUSED_WARNING(pnvm_data);
+}
+
+
+VL53L1_Error VL53L1_read_nvm_raw_data(
+ VL53L1_DEV Dev,
+ uint8_t start_address,
+ uint8_t count,
+ uint8_t *pnvm_raw_data)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_nvm_enable(
+ Dev,
+ 0x0004,
+ VL53L1_NVM_POWER_UP_DELAY_US);
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_nvm_read(
+ Dev,
+ start_address,
+ count,
+ pnvm_raw_data);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_nvm_disable(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_read_nvm(
+ VL53L1_DEV Dev,
+ uint8_t nvm_format,
+ VL53L1_decoded_nvm_data_t *pnvm_info)
+{
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+
+
+ uint8_t nvm_data[2*VL53L1_NVM_SIZE_IN_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ SUPPRESS_UNUSED_WARNING(nvm_format);
+
+
+
+
+ status = VL53L1_read_nvm_raw_data(
+ Dev,
+ 0,
+ VL53L1_NVM_SIZE_IN_BYTES >> 2,
+ nvm_data);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_nvm_format_decode(
+ VL53L1_NVM_SIZE_IN_BYTES,
+ nvm_data,
+ pnvm_info);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_read_nvm_cal_peak_rate_map(
+ VL53L1_DEV Dev,
+ VL53L1_cal_peak_rate_map_t *pcal_data)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+
+
+ uint8_t nvm_data[2*VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_SIZE];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_read_nvm_raw_data(
+ Dev,
+ (uint8_t)(VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_INDEX >> 2),
+ (uint8_t)(VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_SIZE >> 2),
+ nvm_data);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_cal_peak_rate_map(
+ VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_SIZE,
+ nvm_data,
+ pcal_data);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_read_nvm_additional_offset_cal_data(
+ VL53L1_DEV Dev,
+ VL53L1_additional_offset_cal_data_t *pcal_data)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+
+
+ uint8_t nvm_data[2*VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_SIZE];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_read_nvm_raw_data(
+ Dev,
+ (uint8_t)(VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_INDEX >> 2),
+ (uint8_t)(VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_SIZE >> 2),
+ nvm_data);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_nvm_decode_additional_offset_cal_data(
+ VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_SIZE,
+ nvm_data,
+ pcal_data);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_read_nvm_fmt_range_results_data(
+ VL53L1_DEV Dev,
+ uint16_t range_results_select,
+ VL53L1_decoded_nvm_fmt_range_data_t *prange_data)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+
+
+ uint8_t nvm_data[2*VL53L1_NVM__FMT__RANGE_RESULTS__SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_read_nvm_raw_data(
+ Dev,
+ (uint8_t)(range_results_select >> 2),
+ (uint8_t)(VL53L1_NVM__FMT__RANGE_RESULTS__SIZE_BYTES >> 2),
+ nvm_data);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_fmt_range_results_data(
+ VL53L1_NVM__FMT__RANGE_RESULTS__SIZE_BYTES,
+ nvm_data,
+ prange_data);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_nvm_debug.c b/drivers/input/misc/vl53L1/src/vl53l1_nvm_debug.c
new file mode 100644
index 000000000000..fcf9ce51f5cf
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_nvm_debug.c
@@ -0,0 +1,1103 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_platform_log.h"
+#include "vl53l1_register_map.h"
+#include "vl53l1_api_debug.h"
+#include "vl53l1_nvm_structs.h"
+#include "vl53l1_nvm_debug.h"
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_NVM, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_NVM, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_NVM, status, fmt, ##__VA_ARGS__)
+
+#define trace_print(level, ...) \
+ _LOG_TRACE_PRINT(trace_flags, \
+ level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+
+#ifdef VL53L1_LOG_ENABLE
+
+void VL53L1_print_nvm_raw_data(
+ uint8_t *pnvm_raw_data,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ int i = 0;
+
+ LOG_FUNCTION_START("");
+
+ for (i = 0 ; i < VL53L1_NVM_SIZE_IN_BYTES ; i++) {
+ if (i % 4 == 0)
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "\n NVM Addr 0x%02X : 0x",
+ i/4);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%02X",
+ *pnvm_raw_data++);
+ }
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "\n");
+
+ LOG_FUNCTION_END(0);
+}
+
+
+void VL53L1_print_decoded_nvm_data(
+ VL53L1_decoded_nvm_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__identification_model_id",
+ pdata->nvm__identification_model_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__identification_module_type",
+ pdata->nvm__identification_module_type);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__identification_revision_id",
+ pdata->nvm__identification_revision_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__identification_module_id",
+ pdata->nvm__identification_module_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__i2c_valid",
+ pdata->nvm__i2c_valid);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__i2c_device_address_ews",
+ pdata->nvm__i2c_device_address_ews);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->nvm__ews__fast_osc_frequency,
+ 12,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__ews__fast_osc_frequency",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__fast_osc_trim_max",
+ pdata->nvm__ews__fast_osc_trim_max);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__fast_osc_freq_set",
+ pdata->nvm__ews__fast_osc_freq_set);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__slow_osc_calibration",
+ pdata->nvm__ews__slow_osc_calibration);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->nvm__fmt__fast_osc_frequency,
+ 12,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__fmt__fast_osc_frequency",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__fast_osc_trim_max",
+ pdata->nvm__fmt__fast_osc_trim_max);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__fast_osc_freq_set",
+ pdata->nvm__fmt__fast_osc_freq_set);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__slow_osc_calibration",
+ pdata->nvm__fmt__slow_osc_calibration);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__vhv_config_unlock",
+ pdata->nvm__vhv_config_unlock);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ref_selvddpix",
+ pdata->nvm__ref_selvddpix);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ref_selvquench",
+ pdata->nvm__ref_selvquench);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__regavdd1v2_sel",
+ pdata->nvm__regavdd1v2_sel);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__regdvdd1v2_sel",
+ pdata->nvm__regdvdd1v2_sel);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__vhv_timeout__macrop",
+ pdata->nvm__vhv_timeout__macrop);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__vhv_loop_bound",
+ pdata->nvm__vhv_loop_bound);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__vhv_count_threshold",
+ pdata->nvm__vhv_count_threshold);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__vhv_offset",
+ pdata->nvm__vhv_offset);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__vhv_init_enable",
+ pdata->nvm__vhv_init_enable);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__vhv_init_value",
+ pdata->nvm__vhv_init_value);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_vcsel_trim_ll",
+ pdata->nvm__laser_safety_vcsel_trim_ll);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_vcsel_selion_ll",
+ pdata->nvm__laser_safety_vcsel_selion_ll);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_vcsel_selion_max_ll",
+ pdata->nvm__laser_safety_vcsel_selion_max_ll);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_mult_ll",
+ pdata->nvm__laser_safety_mult_ll);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_clip_ll",
+ pdata->nvm__laser_safety_clip_ll);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_vcsel_trim_ld",
+ pdata->nvm__laser_safety_vcsel_trim_ld);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_vcsel_selion_ld",
+ pdata->nvm__laser_safety_vcsel_selion_ld);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_vcsel_selion_max_ld",
+ pdata->nvm__laser_safety_vcsel_selion_max_ld);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_mult_ld",
+ pdata->nvm__laser_safety_mult_ld);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_clip_ld",
+ pdata->nvm__laser_safety_clip_ld);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_lock_byte",
+ pdata->nvm__laser_safety_lock_byte);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_unlock_byte",
+ pdata->nvm__laser_safety_unlock_byte);
+
+
+
+
+ for (i = 0 ; i < VL53L1_RTN_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__ews__spad_enables_rtn[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__ews__spad_enables_rtn[i]);
+ }
+
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__ews__spad_enables_ref__loc1[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__ews__spad_enables_ref__loc1[i]);
+ }
+
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__ews__spad_enables_ref__loc2[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__ews__spad_enables_ref__loc2[i]);
+ }
+
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__ews__spad_enables_ref__loc3[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__ews__spad_enables_ref__loc3[i]);
+ }
+
+
+
+
+
+ for (i = 0 ; i < VL53L1_RTN_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__fmt__spad_enables_rtn[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__fmt__spad_enables_rtn[i]);
+ }
+
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__fmt__spad_enables_ref__loc1[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__fmt__spad_enables_ref__loc1[i]);
+ }
+
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__fmt__spad_enables_ref__loc2[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__fmt__spad_enables_ref__loc2[i]);
+ }
+
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__fmt__spad_enables_ref__loc3[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__fmt__spad_enables_ref__loc3[i]);
+ }
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__roi_config__mode_roi_centre_spad",
+ pdata->nvm__fmt__roi_config__mode_roi_centre_spad);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__roi_config__mode_roi_x_size",
+ pdata->nvm__fmt__roi_config__mode_roi_x_size);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__roi_config__mode_roi_y_size",
+ pdata->nvm__fmt__roi_config__mode_roi_y_size);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__ref_spad_apply__num_requested_ref_spad",
+ pdata->nvm__fmt__ref_spad_apply__num_requested_ref_spad);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__ref_spad_man__ref_location",
+ pdata->nvm__fmt__ref_spad_man__ref_location);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "nvm__fmt__mm_config__inner_offset_mm",
+ pdata->nvm__fmt__mm_config__inner_offset_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "nvm__fmt__mm_config__outer_offset_mm",
+ pdata->nvm__fmt__mm_config__outer_offset_mm);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->nvm__fmt__algo_part_to_part_range_offset_mm,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__fmt__algo_part_to_part_range_offset_mm",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->nvm__fmt__algo__crosstalk_compensation_plane_offset_kcps,
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__fmt__algo__crosstalk_compensation_plane_offset_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->nvm__fmt__algo__crosstalk_compensation_x_plane_gradient_kcps,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__fmt__algo__crosstalk_compensation_x_plane_gradient_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->nvm__fmt__algo__crosstalk_compensation_y_plane_gradient_kcps,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__fmt__algo__crosstalk_compensation_y_plane_gradient_kcps",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__spare__host_config__nvm_config_spare_0",
+ pdata->nvm__fmt__spare__host_config__nvm_config_spare_0);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__spare__host_config__nvm_config_spare_1",
+ pdata->nvm__fmt__spare__host_config__nvm_config_spare_1);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__customer_space_programmed",
+ pdata->nvm__customer_space_programmed);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__cust__i2c_device_address",
+ pdata->nvm__cust__i2c_device_address);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__cust__ref_spad_apply__num_requested_ref_spad",
+ pdata->nvm__cust__ref_spad_apply__num_requested_ref_spad);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__cust__ref_spad_man__ref_location",
+ pdata->nvm__cust__ref_spad_man__ref_location);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "nvm__cust__mm_config__inner_offset_mm",
+ pdata->nvm__cust__mm_config__inner_offset_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "nvm__cust__mm_config__outer_offset_mm",
+ pdata->nvm__cust__mm_config__outer_offset_mm);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->nvm__cust__algo_part_to_part_range_offset_mm,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__cust__algo_part_to_part_range_offset_mm",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (uint32_t)pdata->nvm__cust__algo__crosstalk_compensation_plane_offset_kcps,
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__cust__algo__crosstalk_compensation_plane_offset_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->nvm__cust__algo__crosstalk_compensation_x_plane_gradient_kcps,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__cust__algo__crosstalk_compensation_x_plane_gradient_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->nvm__cust__algo__crosstalk_compensation_y_plane_gradient_kcps,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__cust__algo__crosstalk_compensation_y_plane_gradient_kcps",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__cust__spare__host_config__nvm_config_spare_0",
+ pdata->nvm__cust__spare__host_config__nvm_config_spare_0);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__cust__spare__host_config__nvm_config_spare_1",
+ pdata->nvm__cust__spare__host_config__nvm_config_spare_1);
+
+
+
+
+ sprintf(
+ ppre_text,
+ "%sfmt_peak_rate_map.", pprefix);
+
+ VL53L1_print_cal_peak_rate_map(
+ &(pdata->fmt_peak_rate_map),
+ ppre_text,
+ VL53L1_TRACE_MODULE_NVM_DATA);
+
+ sprintf(
+ ppre_text,
+ "%sfmt_add_offset_data.",
+ pprefix);
+
+ VL53L1_print_additional_offset_cal_data(
+ &(pdata->fmt_add_offset_data),
+ ppre_text,
+ VL53L1_TRACE_MODULE_NVM_DATA);
+
+
+
+
+ for (i = 0 ; i < VL53L1_NVM_MAX_FMT_RANGE_DATA ; i++) {
+ sprintf(
+ ppre_text,
+ "%sfmt_range_data[%u].",
+ pprefix, i);
+
+ VL53L1_print_decoded_nvm_fmt_range_data(
+ &(pdata->fmt_range_data[i]),
+ ppre_text,
+ trace_flags);
+ }
+
+ sprintf(
+ ppre_text,
+ "%sfmt_info.",
+ pprefix);
+
+ VL53L1_print_decoded_nvm_fmt_info(
+ &(pdata->fmt_info),
+ ppre_text,
+ trace_flags);
+
+ sprintf(
+ ppre_text,
+ "%sews_info.",
+ pprefix);
+
+ VL53L1_print_decoded_nvm_ews_info(
+ &(pdata->ews_info),
+ ppre_text,
+ trace_flags);
+}
+
+
+void VL53L1_print_decoded_nvm_fmt_range_data(
+ VL53L1_decoded_nvm_fmt_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__actual_effective_rtn_spads,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__actual_effective_rtn_spads",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ref_spad_array__num_requested_ref_spads",
+ pdata->ref_spad_array__num_requested_ref_spads);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ref_spad_array__ref_location",
+ pdata->ref_spad_array__ref_location);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__peak_signal_count_rate_rtn_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__peak_signal_count_rate_rtn_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__ambient_count_rate_rtn_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__ambient_count_rate_rtn_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__peak_signal_count_rate_ref_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "result__peak_signal_count_rate_ref_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__ambient_count_rate_ref_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__ambient_count_rate_ref_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->measured_distance_mm,
+ 4,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "measured_distance_mm",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (uint32_t)pdata->measured_distance_stdev_mm,
+ 4,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "measured_distance_stdev_mm",
+ fp_text);
+}
+
+
+void VL53L1_print_decoded_nvm_fmt_info(
+ VL53L1_decoded_nvm_fmt_info_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = \"%s\"\n",
+ pprefix,
+ "nvm__fmt__fgc",
+ pdata->nvm__fmt__fgc);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__test_program_major",
+ pdata->nvm__fmt__test_program_major);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__test_program_minor",
+ pdata->nvm__fmt__test_program_minor);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__map_major",
+ pdata->nvm__fmt__map_major);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__map_minor",
+ pdata->nvm__fmt__map_minor);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__year",
+ pdata->nvm__fmt__year);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__month",
+ pdata->nvm__fmt__month);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__day",
+ pdata->nvm__fmt__day);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__module_date_phase",
+ pdata->nvm__fmt__module_date_phase);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__time",
+ pdata->nvm__fmt__time);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__tester_id",
+ pdata->nvm__fmt__tester_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__site_id",
+ pdata->nvm__fmt__site_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__test_program_major",
+ pdata->nvm__ews__test_program_major);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__test_program_minor",
+ pdata->nvm__ews__test_program_minor);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__probe_card_major",
+ pdata->nvm__ews__probe_card_major);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__probe_card_minor",
+ pdata->nvm__ews__probe_card_minor);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__tester_id",
+ pdata->nvm__ews__tester_id);
+}
+
+
+void VL53L1_print_decoded_nvm_ews_info(
+ VL53L1_decoded_nvm_ews_info_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = \"%s\"\n",
+ pprefix,
+ "nvm__ews__lot",
+ pdata->nvm__ews__lot);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__wafer",
+ pdata->nvm__ews__wafer);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__xcoord",
+ pdata->nvm__ews__xcoord);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__ycoord",
+ pdata->nvm__ews__ycoord);
+}
+
+#endif
+
+
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_register_funcs.c b/drivers/input/misc/vl53L1/src/vl53l1_register_funcs.c
new file mode 100644
index 000000000000..2651c4b37384
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_register_funcs.c
@@ -0,0 +1,4594 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_platform_log.h"
+#include "vl53l1_core.h"
+#include "vl53l1_register_map.h"
+#include "vl53l1_register_structs.h"
+#include "vl53l1_register_funcs.h"
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_REGISTERS, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_REGISTERS, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_REGISTERS, status, fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_i2c_encode_static_nvm_managed(
+ VL53L1_static_nvm_managed_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->i2c_slave__device_address & 0x7F;
+ *(pbuffer + 1) =
+ pdata->ana_config__vhv_ref_sel_vddpix & 0xF;
+ *(pbuffer + 2) =
+ pdata->ana_config__vhv_ref_sel_vquench & 0x7F;
+ *(pbuffer + 3) =
+ pdata->ana_config__reg_avdd1v2_sel & 0x3;
+ *(pbuffer + 4) =
+ pdata->ana_config__fast_osc__trim & 0x7F;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->osc_measured__fast_osc__frequency,
+ 2,
+ pbuffer + 5);
+ *(pbuffer + 7) =
+ pdata->vhv_config__timeout_macrop_loop_bound;
+ *(pbuffer + 8) =
+ pdata->vhv_config__count_thresh;
+ *(pbuffer + 9) =
+ pdata->vhv_config__offset & 0x3F;
+ *(pbuffer + 10) =
+ pdata->vhv_config__init;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_static_nvm_managed(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_static_nvm_managed_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->i2c_slave__device_address =
+ (*(pbuffer + 0)) & 0x7F;
+ pdata->ana_config__vhv_ref_sel_vddpix =
+ (*(pbuffer + 1)) & 0xF;
+ pdata->ana_config__vhv_ref_sel_vquench =
+ (*(pbuffer + 2)) & 0x7F;
+ pdata->ana_config__reg_avdd1v2_sel =
+ (*(pbuffer + 3)) & 0x3;
+ pdata->ana_config__fast_osc__trim =
+ (*(pbuffer + 4)) & 0x7F;
+ pdata->osc_measured__fast_osc__frequency =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 5));
+ pdata->vhv_config__timeout_macrop_loop_bound =
+ (*(pbuffer + 7));
+ pdata->vhv_config__count_thresh =
+ (*(pbuffer + 8));
+ pdata->vhv_config__offset =
+ (*(pbuffer + 9)) & 0x3F;
+ pdata->vhv_config__init =
+ (*(pbuffer + 10));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_static_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_static_nvm_managed_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_static_nvm_managed(
+ pdata,
+ VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_I2C_SLAVE__DEVICE_ADDRESS,
+ comms_buffer,
+ VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_static_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_static_nvm_managed_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_I2C_SLAVE__DEVICE_ADDRESS,
+ comms_buffer,
+ VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_static_nvm_managed(
+ VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_customer_nvm_managed(
+ VL53L1_customer_nvm_managed_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->global_config__spad_enables_ref_0;
+ *(pbuffer + 1) =
+ pdata->global_config__spad_enables_ref_1;
+ *(pbuffer + 2) =
+ pdata->global_config__spad_enables_ref_2;
+ *(pbuffer + 3) =
+ pdata->global_config__spad_enables_ref_3;
+ *(pbuffer + 4) =
+ pdata->global_config__spad_enables_ref_4;
+ *(pbuffer + 5) =
+ pdata->global_config__spad_enables_ref_5 & 0xF;
+ *(pbuffer + 6) =
+ pdata->global_config__ref_en_start_select;
+ *(pbuffer + 7) =
+ pdata->ref_spad_man__num_requested_ref_spads & 0x3F;
+ *(pbuffer + 8) =
+ pdata->ref_spad_man__ref_location & 0x3;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->algo__crosstalk_compensation_plane_offset_kcps,
+ 2,
+ pbuffer + 9);
+ VL53L1_i2c_encode_int16_t(
+ pdata->algo__crosstalk_compensation_x_plane_gradient_kcps,
+ 2,
+ pbuffer + 11);
+ VL53L1_i2c_encode_int16_t(
+ pdata->algo__crosstalk_compensation_y_plane_gradient_kcps,
+ 2,
+ pbuffer + 13);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->ref_spad_char__total_rate_target_mcps,
+ 2,
+ pbuffer + 15);
+ VL53L1_i2c_encode_int16_t(
+ pdata->algo__part_to_part_range_offset_mm & 0x1FFF,
+ 2,
+ pbuffer + 17);
+ VL53L1_i2c_encode_int16_t(
+ pdata->mm_config__inner_offset_mm,
+ 2,
+ pbuffer + 19);
+ VL53L1_i2c_encode_int16_t(
+ pdata->mm_config__outer_offset_mm,
+ 2,
+ pbuffer + 21);
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_customer_nvm_managed(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_customer_nvm_managed_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->global_config__spad_enables_ref_0 =
+ (*(pbuffer + 0));
+ pdata->global_config__spad_enables_ref_1 =
+ (*(pbuffer + 1));
+ pdata->global_config__spad_enables_ref_2 =
+ (*(pbuffer + 2));
+ pdata->global_config__spad_enables_ref_3 =
+ (*(pbuffer + 3));
+ pdata->global_config__spad_enables_ref_4 =
+ (*(pbuffer + 4));
+ pdata->global_config__spad_enables_ref_5 =
+ (*(pbuffer + 5)) & 0xF;
+ pdata->global_config__ref_en_start_select =
+ (*(pbuffer + 6));
+ pdata->ref_spad_man__num_requested_ref_spads =
+ (*(pbuffer + 7)) & 0x3F;
+ pdata->ref_spad_man__ref_location =
+ (*(pbuffer + 8)) & 0x3;
+ pdata->algo__crosstalk_compensation_plane_offset_kcps =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 9));
+ pdata->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ (VL53L1_i2c_decode_int16_t(2, pbuffer + 11));
+ pdata->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ (VL53L1_i2c_decode_int16_t(2, pbuffer + 13));
+ pdata->ref_spad_char__total_rate_target_mcps =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 15));
+ pdata->algo__part_to_part_range_offset_mm =
+ (VL53L1_i2c_decode_int16_t(2, pbuffer + 17)) & 0x1FFF;
+ pdata->mm_config__inner_offset_mm =
+ (VL53L1_i2c_decode_int16_t(2, pbuffer + 19));
+ pdata->mm_config__outer_offset_mm =
+ (VL53L1_i2c_decode_int16_t(2, pbuffer + 21));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_customer_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_customer_nvm_managed_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_customer_nvm_managed(
+ pdata,
+ VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0,
+ comms_buffer,
+ VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_customer_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_customer_nvm_managed_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0,
+ comms_buffer,
+ VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_customer_nvm_managed(
+ VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_static_config(
+ VL53L1_static_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ VL53L1_i2c_encode_uint16_t(
+ pdata->dss_config__target_total_rate_mcps,
+ 2,
+ pbuffer + 0);
+ *(pbuffer + 2) =
+ pdata->debug__ctrl & 0x1;
+ *(pbuffer + 3) =
+ pdata->test_mode__ctrl & 0xF;
+ *(pbuffer + 4) =
+ pdata->clk_gating__ctrl & 0xF;
+ *(pbuffer + 5) =
+ pdata->nvm_bist__ctrl & 0x1F;
+ *(pbuffer + 6) =
+ pdata->nvm_bist__num_nvm_words & 0x7F;
+ *(pbuffer + 7) =
+ pdata->nvm_bist__start_address & 0x7F;
+ *(pbuffer + 8) =
+ pdata->host_if__status & 0x1;
+ *(pbuffer + 9) =
+ pdata->pad_i2c_hv__config;
+ *(pbuffer + 10) =
+ pdata->pad_i2c_hv__extsup_config & 0x1;
+ *(pbuffer + 11) =
+ pdata->gpio_hv_pad__ctrl & 0x3;
+ *(pbuffer + 12) =
+ pdata->gpio_hv_mux__ctrl & 0x1F;
+ *(pbuffer + 13) =
+ pdata->gpio__tio_hv_status & 0x3;
+ *(pbuffer + 14) =
+ pdata->gpio__fio_hv_status & 0x3;
+ *(pbuffer + 15) =
+ pdata->ana_config__spad_sel_pswidth & 0x7;
+ *(pbuffer + 16) =
+ pdata->ana_config__vcsel_pulse_width_offset & 0x1F;
+ *(pbuffer + 17) =
+ pdata->ana_config__fast_osc__config_ctrl & 0x1;
+ *(pbuffer + 18) =
+ pdata->sigma_estimator__effective_pulse_width_ns;
+ *(pbuffer + 19) =
+ pdata->sigma_estimator__effective_ambient_width_ns;
+ *(pbuffer + 20) =
+ pdata->sigma_estimator__sigma_ref_mm;
+ *(pbuffer + 21) =
+ pdata->algo__crosstalk_compensation_valid_height_mm;
+ *(pbuffer + 22) =
+ pdata->spare_host_config__static_config_spare_0;
+ *(pbuffer + 23) =
+ pdata->spare_host_config__static_config_spare_1;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->algo__range_ignore_threshold_mcps,
+ 2,
+ pbuffer + 24);
+ *(pbuffer + 26) =
+ pdata->algo__range_ignore_valid_height_mm;
+ *(pbuffer + 27) =
+ pdata->algo__range_min_clip;
+ *(pbuffer + 28) =
+ pdata->algo__consistency_check__tolerance & 0xF;
+ *(pbuffer + 29) =
+ pdata->spare_host_config__static_config_spare_2;
+ *(pbuffer + 30) =
+ pdata->sd_config__reset_stages_msb & 0xF;
+ *(pbuffer + 31) =
+ pdata->sd_config__reset_stages_lsb;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_static_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_static_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->dss_config__target_total_rate_mcps =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 0));
+ pdata->debug__ctrl =
+ (*(pbuffer + 2)) & 0x1;
+ pdata->test_mode__ctrl =
+ (*(pbuffer + 3)) & 0xF;
+ pdata->clk_gating__ctrl =
+ (*(pbuffer + 4)) & 0xF;
+ pdata->nvm_bist__ctrl =
+ (*(pbuffer + 5)) & 0x1F;
+ pdata->nvm_bist__num_nvm_words =
+ (*(pbuffer + 6)) & 0x7F;
+ pdata->nvm_bist__start_address =
+ (*(pbuffer + 7)) & 0x7F;
+ pdata->host_if__status =
+ (*(pbuffer + 8)) & 0x1;
+ pdata->pad_i2c_hv__config =
+ (*(pbuffer + 9));
+ pdata->pad_i2c_hv__extsup_config =
+ (*(pbuffer + 10)) & 0x1;
+ pdata->gpio_hv_pad__ctrl =
+ (*(pbuffer + 11)) & 0x3;
+ pdata->gpio_hv_mux__ctrl =
+ (*(pbuffer + 12)) & 0x1F;
+ pdata->gpio__tio_hv_status =
+ (*(pbuffer + 13)) & 0x3;
+ pdata->gpio__fio_hv_status =
+ (*(pbuffer + 14)) & 0x3;
+ pdata->ana_config__spad_sel_pswidth =
+ (*(pbuffer + 15)) & 0x7;
+ pdata->ana_config__vcsel_pulse_width_offset =
+ (*(pbuffer + 16)) & 0x1F;
+ pdata->ana_config__fast_osc__config_ctrl =
+ (*(pbuffer + 17)) & 0x1;
+ pdata->sigma_estimator__effective_pulse_width_ns =
+ (*(pbuffer + 18));
+ pdata->sigma_estimator__effective_ambient_width_ns =
+ (*(pbuffer + 19));
+ pdata->sigma_estimator__sigma_ref_mm =
+ (*(pbuffer + 20));
+ pdata->algo__crosstalk_compensation_valid_height_mm =
+ (*(pbuffer + 21));
+ pdata->spare_host_config__static_config_spare_0 =
+ (*(pbuffer + 22));
+ pdata->spare_host_config__static_config_spare_1 =
+ (*(pbuffer + 23));
+ pdata->algo__range_ignore_threshold_mcps =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24));
+ pdata->algo__range_ignore_valid_height_mm =
+ (*(pbuffer + 26));
+ pdata->algo__range_min_clip =
+ (*(pbuffer + 27));
+ pdata->algo__consistency_check__tolerance =
+ (*(pbuffer + 28)) & 0xF;
+ pdata->spare_host_config__static_config_spare_2 =
+ (*(pbuffer + 29));
+ pdata->sd_config__reset_stages_msb =
+ (*(pbuffer + 30)) & 0xF;
+ pdata->sd_config__reset_stages_lsb =
+ (*(pbuffer + 31));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_static_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_static_config(
+ pdata,
+ VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS,
+ comms_buffer,
+ VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_static_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS,
+ comms_buffer,
+ VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_static_config(
+ VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_general_config(
+ VL53L1_general_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->gph_config__stream_count_update_value;
+ *(pbuffer + 1) =
+ pdata->global_config__stream_divider;
+ *(pbuffer + 2) =
+ pdata->system__interrupt_config_gpio;
+ *(pbuffer + 3) =
+ pdata->cal_config__vcsel_start & 0x7F;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->cal_config__repeat_rate & 0xFFF,
+ 2,
+ pbuffer + 4);
+ *(pbuffer + 6) =
+ pdata->global_config__vcsel_width & 0x7F;
+ *(pbuffer + 7) =
+ pdata->phasecal_config__timeout_macrop;
+ *(pbuffer + 8) =
+ pdata->phasecal_config__target;
+ *(pbuffer + 9) =
+ pdata->phasecal_config__override & 0x1;
+ *(pbuffer + 11) =
+ pdata->dss_config__roi_mode_control & 0x7;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->system__thresh_rate_high,
+ 2,
+ pbuffer + 12);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->system__thresh_rate_low,
+ 2,
+ pbuffer + 14);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->dss_config__manual_effective_spads_select,
+ 2,
+ pbuffer + 16);
+ *(pbuffer + 18) =
+ pdata->dss_config__manual_block_select;
+ *(pbuffer + 19) =
+ pdata->dss_config__aperture_attenuation;
+ *(pbuffer + 20) =
+ pdata->dss_config__max_spads_limit;
+ *(pbuffer + 21) =
+ pdata->dss_config__min_spads_limit;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_general_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_general_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->gph_config__stream_count_update_value =
+ (*(pbuffer + 0));
+ pdata->global_config__stream_divider =
+ (*(pbuffer + 1));
+ pdata->system__interrupt_config_gpio =
+ (*(pbuffer + 2));
+ pdata->cal_config__vcsel_start =
+ (*(pbuffer + 3)) & 0x7F;
+ pdata->cal_config__repeat_rate =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 4)) & 0xFFF;
+ pdata->global_config__vcsel_width =
+ (*(pbuffer + 6)) & 0x7F;
+ pdata->phasecal_config__timeout_macrop =
+ (*(pbuffer + 7));
+ pdata->phasecal_config__target =
+ (*(pbuffer + 8));
+ pdata->phasecal_config__override =
+ (*(pbuffer + 9)) & 0x1;
+ pdata->dss_config__roi_mode_control =
+ (*(pbuffer + 11)) & 0x7;
+ pdata->system__thresh_rate_high =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12));
+ pdata->system__thresh_rate_low =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14));
+ pdata->dss_config__manual_effective_spads_select =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16));
+ pdata->dss_config__manual_block_select =
+ (*(pbuffer + 18));
+ pdata->dss_config__aperture_attenuation =
+ (*(pbuffer + 19));
+ pdata->dss_config__max_spads_limit =
+ (*(pbuffer + 20));
+ pdata->dss_config__min_spads_limit =
+ (*(pbuffer + 21));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_general_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_general_config(
+ pdata,
+ VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_GPH_CONFIG__STREAM_COUNT_UPDATE_VALUE,
+ comms_buffer,
+ VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_general_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_GPH_CONFIG__STREAM_COUNT_UPDATE_VALUE,
+ comms_buffer,
+ VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_general_config(
+ VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_timing_config(
+ VL53L1_timing_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->mm_config__timeout_macrop_a_hi & 0xF;
+ *(pbuffer + 1) =
+ pdata->mm_config__timeout_macrop_a_lo;
+ *(pbuffer + 2) =
+ pdata->mm_config__timeout_macrop_b_hi & 0xF;
+ *(pbuffer + 3) =
+ pdata->mm_config__timeout_macrop_b_lo;
+ *(pbuffer + 4) =
+ pdata->range_config__timeout_macrop_a_hi & 0xF;
+ *(pbuffer + 5) =
+ pdata->range_config__timeout_macrop_a_lo;
+ *(pbuffer + 6) =
+ pdata->range_config__vcsel_period_a & 0x3F;
+ *(pbuffer + 7) =
+ pdata->range_config__timeout_macrop_b_hi & 0xF;
+ *(pbuffer + 8) =
+ pdata->range_config__timeout_macrop_b_lo;
+ *(pbuffer + 9) =
+ pdata->range_config__vcsel_period_b & 0x3F;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->range_config__sigma_thresh,
+ 2,
+ pbuffer + 10);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->range_config__min_count_rate_rtn_limit_mcps,
+ 2,
+ pbuffer + 12);
+ *(pbuffer + 14) =
+ pdata->range_config__valid_phase_low;
+ *(pbuffer + 15) =
+ pdata->range_config__valid_phase_high;
+ VL53L1_i2c_encode_uint32_t(
+ pdata->system__intermeasurement_period,
+ 4,
+ pbuffer + 18);
+ *(pbuffer + 22) =
+ pdata->system__fractional_enable & 0x1;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_timing_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_timing_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->mm_config__timeout_macrop_a_hi =
+ (*(pbuffer + 0)) & 0xF;
+ pdata->mm_config__timeout_macrop_a_lo =
+ (*(pbuffer + 1));
+ pdata->mm_config__timeout_macrop_b_hi =
+ (*(pbuffer + 2)) & 0xF;
+ pdata->mm_config__timeout_macrop_b_lo =
+ (*(pbuffer + 3));
+ pdata->range_config__timeout_macrop_a_hi =
+ (*(pbuffer + 4)) & 0xF;
+ pdata->range_config__timeout_macrop_a_lo =
+ (*(pbuffer + 5));
+ pdata->range_config__vcsel_period_a =
+ (*(pbuffer + 6)) & 0x3F;
+ pdata->range_config__timeout_macrop_b_hi =
+ (*(pbuffer + 7)) & 0xF;
+ pdata->range_config__timeout_macrop_b_lo =
+ (*(pbuffer + 8));
+ pdata->range_config__vcsel_period_b =
+ (*(pbuffer + 9)) & 0x3F;
+ pdata->range_config__sigma_thresh =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10));
+ pdata->range_config__min_count_rate_rtn_limit_mcps =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12));
+ pdata->range_config__valid_phase_low =
+ (*(pbuffer + 14));
+ pdata->range_config__valid_phase_high =
+ (*(pbuffer + 15));
+ pdata->system__intermeasurement_period =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 18));
+ pdata->system__fractional_enable =
+ (*(pbuffer + 22)) & 0x1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_timing_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_timing_config(
+ pdata,
+ VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_MM_CONFIG__TIMEOUT_MACROP_A_HI,
+ comms_buffer,
+ VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_timing_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_MM_CONFIG__TIMEOUT_MACROP_A_HI,
+ comms_buffer,
+ VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_timing_config(
+ VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_dynamic_config(
+ VL53L1_dynamic_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->system__grouped_parameter_hold_0 & 0x3;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->system__thresh_high,
+ 2,
+ pbuffer + 1);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->system__thresh_low,
+ 2,
+ pbuffer + 3);
+ *(pbuffer + 5) =
+ pdata->system__enable_xtalk_per_quadrant & 0x1;
+ *(pbuffer + 6) =
+ pdata->system__seed_config & 0x7;
+ *(pbuffer + 7) =
+ pdata->sd_config__woi_sd0;
+ *(pbuffer + 8) =
+ pdata->sd_config__woi_sd1;
+ *(pbuffer + 9) =
+ pdata->sd_config__initial_phase_sd0 & 0x7F;
+ *(pbuffer + 10) =
+ pdata->sd_config__initial_phase_sd1 & 0x7F;
+ *(pbuffer + 11) =
+ pdata->system__grouped_parameter_hold_1 & 0x3;
+ *(pbuffer + 12) =
+ pdata->sd_config__first_order_select & 0x3;
+ *(pbuffer + 13) =
+ pdata->sd_config__quantifier & 0xF;
+ *(pbuffer + 14) =
+ pdata->roi_config__user_roi_centre_spad;
+ *(pbuffer + 15) =
+ pdata->roi_config__user_roi_requested_global_xy_size;
+ *(pbuffer + 16) =
+ pdata->system__sequence_config;
+ *(pbuffer + 17) =
+ pdata->system__grouped_parameter_hold & 0x3;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_dynamic_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_dynamic_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->system__grouped_parameter_hold_0 =
+ (*(pbuffer + 0)) & 0x3;
+ pdata->system__thresh_high =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 1));
+ pdata->system__thresh_low =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 3));
+ pdata->system__enable_xtalk_per_quadrant =
+ (*(pbuffer + 5)) & 0x1;
+ pdata->system__seed_config =
+ (*(pbuffer + 6)) & 0x7;
+ pdata->sd_config__woi_sd0 =
+ (*(pbuffer + 7));
+ pdata->sd_config__woi_sd1 =
+ (*(pbuffer + 8));
+ pdata->sd_config__initial_phase_sd0 =
+ (*(pbuffer + 9)) & 0x7F;
+ pdata->sd_config__initial_phase_sd1 =
+ (*(pbuffer + 10)) & 0x7F;
+ pdata->system__grouped_parameter_hold_1 =
+ (*(pbuffer + 11)) & 0x3;
+ pdata->sd_config__first_order_select =
+ (*(pbuffer + 12)) & 0x3;
+ pdata->sd_config__quantifier =
+ (*(pbuffer + 13)) & 0xF;
+ pdata->roi_config__user_roi_centre_spad =
+ (*(pbuffer + 14));
+ pdata->roi_config__user_roi_requested_global_xy_size =
+ (*(pbuffer + 15));
+ pdata->system__sequence_config =
+ (*(pbuffer + 16));
+ pdata->system__grouped_parameter_hold =
+ (*(pbuffer + 17)) & 0x3;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_dynamic_config(
+ VL53L1_DEV Dev,
+ VL53L1_dynamic_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_dynamic_config(
+ pdata,
+ VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD_0,
+ comms_buffer,
+ VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_dynamic_config(
+ VL53L1_DEV Dev,
+ VL53L1_dynamic_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD_0,
+ comms_buffer,
+ VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_dynamic_config(
+ VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_system_control(
+ VL53L1_system_control_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->power_management__go1_power_force & 0x1;
+ *(pbuffer + 1) =
+ pdata->system__stream_count_ctrl & 0x1;
+ *(pbuffer + 2) =
+ pdata->firmware__enable & 0x1;
+ *(pbuffer + 3) =
+ pdata->system__interrupt_clear & 0x3;
+ *(pbuffer + 4) =
+ pdata->system__mode_start;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_system_control(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_system_control_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->power_management__go1_power_force =
+ (*(pbuffer + 0)) & 0x1;
+ pdata->system__stream_count_ctrl =
+ (*(pbuffer + 1)) & 0x1;
+ pdata->firmware__enable =
+ (*(pbuffer + 2)) & 0x1;
+ pdata->system__interrupt_clear =
+ (*(pbuffer + 3)) & 0x3;
+ pdata->system__mode_start =
+ (*(pbuffer + 4));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_system_control(
+ VL53L1_DEV Dev,
+ VL53L1_system_control_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_system_control(
+ pdata,
+ VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_POWER_MANAGEMENT__GO1_POWER_FORCE,
+ comms_buffer,
+ VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_system_control(
+ VL53L1_DEV Dev,
+ VL53L1_system_control_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_POWER_MANAGEMENT__GO1_POWER_FORCE,
+ comms_buffer,
+ VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_system_control(
+ VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_system_results(
+ VL53L1_system_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->result__interrupt_status & 0x3F;
+ *(pbuffer + 1) =
+ pdata->result__range_status;
+ *(pbuffer + 2) =
+ pdata->result__report_status & 0xF;
+ *(pbuffer + 3) =
+ pdata->result__stream_count;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__dss_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 4);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__peak_signal_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 6);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__ambient_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 8);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__sigma_sd0,
+ 2,
+ pbuffer + 10);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__phase_sd0,
+ 2,
+ pbuffer + 12);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__final_crosstalk_corrected_range_mm_sd0,
+ 2,
+ pbuffer + 14);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0,
+ 2,
+ pbuffer + 16);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__mm_inner_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 18);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__mm_outer_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 20);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__avg_signal_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 22);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__dss_actual_effective_spads_sd1,
+ 2,
+ pbuffer + 24);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__peak_signal_count_rate_mcps_sd1,
+ 2,
+ pbuffer + 26);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__ambient_count_rate_mcps_sd1,
+ 2,
+ pbuffer + 28);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__sigma_sd1,
+ 2,
+ pbuffer + 30);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__phase_sd1,
+ 2,
+ pbuffer + 32);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__final_crosstalk_corrected_range_mm_sd1,
+ 2,
+ pbuffer + 34);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__spare_0_sd1,
+ 2,
+ pbuffer + 36);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__spare_1_sd1,
+ 2,
+ pbuffer + 38);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__spare_2_sd1,
+ 2,
+ pbuffer + 40);
+ *(pbuffer + 42) =
+ pdata->result__spare_3_sd1;
+ *(pbuffer + 43) =
+ pdata->result__thresh_info;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_system_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->result__interrupt_status =
+ (*(pbuffer + 0)) & 0x3F;
+ pdata->result__range_status =
+ (*(pbuffer + 1));
+ pdata->result__report_status =
+ (*(pbuffer + 2)) & 0xF;
+ pdata->result__stream_count =
+ (*(pbuffer + 3));
+ pdata->result__dss_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 4));
+ pdata->result__peak_signal_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 6));
+ pdata->result__ambient_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8));
+ pdata->result__sigma_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10));
+ pdata->result__phase_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12));
+ pdata->result__final_crosstalk_corrected_range_mm_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14));
+ pdata->result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16));
+ pdata->result__mm_inner_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18));
+ pdata->result__mm_outer_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 20));
+ pdata->result__avg_signal_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22));
+ pdata->result__dss_actual_effective_spads_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24));
+ pdata->result__peak_signal_count_rate_mcps_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 26));
+ pdata->result__ambient_count_rate_mcps_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 28));
+ pdata->result__sigma_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 30));
+ pdata->result__phase_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 32));
+ pdata->result__final_crosstalk_corrected_range_mm_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 34));
+ pdata->result__spare_0_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 36));
+ pdata->result__spare_1_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 38));
+ pdata->result__spare_2_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 40));
+ pdata->result__spare_3_sd1 =
+ (*(pbuffer + 42));
+ pdata->result__thresh_info =
+ (*(pbuffer + 43));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_system_results(
+ pdata,
+ VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_RESULT__INTERRUPT_STATUS,
+ comms_buffer,
+ VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_RESULT__INTERRUPT_STATUS,
+ comms_buffer,
+ VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_system_results(
+ VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_core_results(
+ VL53L1_core_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_CORE_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ VL53L1_i2c_encode_uint32_t(
+ pdata->result_core__ambient_window_events_sd0,
+ 4,
+ pbuffer + 0);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->result_core__ranging_total_events_sd0,
+ 4,
+ pbuffer + 4);
+ VL53L1_i2c_encode_int32_t(
+ pdata->result_core__signal_total_events_sd0,
+ 4,
+ pbuffer + 8);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->result_core__total_periods_elapsed_sd0,
+ 4,
+ pbuffer + 12);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->result_core__ambient_window_events_sd1,
+ 4,
+ pbuffer + 16);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->result_core__ranging_total_events_sd1,
+ 4,
+ pbuffer + 20);
+ VL53L1_i2c_encode_int32_t(
+ pdata->result_core__signal_total_events_sd1,
+ 4,
+ pbuffer + 24);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->result_core__total_periods_elapsed_sd1,
+ 4,
+ pbuffer + 28);
+ *(pbuffer + 32) =
+ pdata->result_core__spare_0;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_core_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_CORE_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->result_core__ambient_window_events_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 0));
+ pdata->result_core__ranging_total_events_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 4));
+ pdata->result_core__signal_total_events_sd0 =
+ (VL53L1_i2c_decode_int32_t(4, pbuffer + 8));
+ pdata->result_core__total_periods_elapsed_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 12));
+ pdata->result_core__ambient_window_events_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 16));
+ pdata->result_core__ranging_total_events_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 20));
+ pdata->result_core__signal_total_events_sd1 =
+ (VL53L1_i2c_decode_int32_t(4, pbuffer + 24));
+ pdata->result_core__total_periods_elapsed_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 28));
+ pdata->result_core__spare_0 =
+ (*(pbuffer + 32));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_CORE_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_core_results(
+ pdata,
+ VL53L1_CORE_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0,
+ comms_buffer,
+ VL53L1_CORE_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_CORE_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0,
+ comms_buffer,
+ VL53L1_CORE_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_core_results(
+ VL53L1_CORE_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_debug_results(
+ VL53L1_debug_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ VL53L1_i2c_encode_uint16_t(
+ pdata->phasecal_result__reference_phase,
+ 2,
+ pbuffer + 0);
+ *(pbuffer + 2) =
+ pdata->phasecal_result__vcsel_start & 0x7F;
+ *(pbuffer + 3) =
+ pdata->ref_spad_char_result__num_actual_ref_spads & 0x3F;
+ *(pbuffer + 4) =
+ pdata->ref_spad_char_result__ref_location & 0x3;
+ *(pbuffer + 5) =
+ pdata->vhv_result__coldboot_status & 0x1;
+ *(pbuffer + 6) =
+ pdata->vhv_result__search_result & 0x3F;
+ *(pbuffer + 7) =
+ pdata->vhv_result__latest_setting & 0x3F;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__osc_calibrate_val & 0x3FF,
+ 2,
+ pbuffer + 8);
+ *(pbuffer + 10) =
+ pdata->ana_config__powerdown_go1 & 0x3;
+ *(pbuffer + 11) =
+ pdata->ana_config__ref_bg_ctrl & 0x3;
+ *(pbuffer + 12) =
+ pdata->ana_config__regdvdd1v2_ctrl & 0xF;
+ *(pbuffer + 13) =
+ pdata->ana_config__osc_slow_ctrl & 0x7;
+ *(pbuffer + 14) =
+ pdata->test_mode__status & 0x1;
+ *(pbuffer + 15) =
+ pdata->firmware__system_status & 0x3;
+ *(pbuffer + 16) =
+ pdata->firmware__mode_status;
+ *(pbuffer + 17) =
+ pdata->firmware__secondary_mode_status;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->firmware__cal_repeat_rate_counter & 0xFFF,
+ 2,
+ pbuffer + 18);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->gph__system__thresh_high,
+ 2,
+ pbuffer + 22);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->gph__system__thresh_low,
+ 2,
+ pbuffer + 24);
+ *(pbuffer + 26) =
+ pdata->gph__system__enable_xtalk_per_quadrant & 0x1;
+ *(pbuffer + 27) =
+ pdata->gph__spare_0 & 0x7;
+ *(pbuffer + 28) =
+ pdata->gph__sd_config__woi_sd0;
+ *(pbuffer + 29) =
+ pdata->gph__sd_config__woi_sd1;
+ *(pbuffer + 30) =
+ pdata->gph__sd_config__initial_phase_sd0 & 0x7F;
+ *(pbuffer + 31) =
+ pdata->gph__sd_config__initial_phase_sd1 & 0x7F;
+ *(pbuffer + 32) =
+ pdata->gph__sd_config__first_order_select & 0x3;
+ *(pbuffer + 33) =
+ pdata->gph__sd_config__quantifier & 0xF;
+ *(pbuffer + 34) =
+ pdata->gph__roi_config__user_roi_centre_spad;
+ *(pbuffer + 35) =
+ pdata->gph__roi_config__user_roi_requested_global_xy_size;
+ *(pbuffer + 36) =
+ pdata->gph__system__sequence_config;
+ *(pbuffer + 37) =
+ pdata->gph__gph_id & 0x1;
+ *(pbuffer + 38) =
+ pdata->system__interrupt_set & 0x3;
+ *(pbuffer + 39) =
+ pdata->interrupt_manager__enables & 0x1F;
+ *(pbuffer + 40) =
+ pdata->interrupt_manager__clear & 0x1F;
+ *(pbuffer + 41) =
+ pdata->interrupt_manager__status & 0x1F;
+ *(pbuffer + 42) =
+ pdata->mcu_to_host_bank__wr_access_en & 0x1;
+ *(pbuffer + 43) =
+ pdata->power_management__go1_reset_status & 0x1;
+ *(pbuffer + 44) =
+ pdata->pad_startup_mode__value_ro & 0x3;
+ *(pbuffer + 45) =
+ pdata->pad_startup_mode__value_ctrl & 0x3F;
+ VL53L1_i2c_encode_uint32_t(
+ pdata->pll_period_us & 0x3FFFF,
+ 4,
+ pbuffer + 46);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->interrupt_scheduler__data_out,
+ 4,
+ pbuffer + 50);
+ *(pbuffer + 54) =
+ pdata->nvm_bist__complete & 0x1;
+ *(pbuffer + 55) =
+ pdata->nvm_bist__status & 0x1;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_debug_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_debug_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->phasecal_result__reference_phase =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 0));
+ pdata->phasecal_result__vcsel_start =
+ (*(pbuffer + 2)) & 0x7F;
+ pdata->ref_spad_char_result__num_actual_ref_spads =
+ (*(pbuffer + 3)) & 0x3F;
+ pdata->ref_spad_char_result__ref_location =
+ (*(pbuffer + 4)) & 0x3;
+ pdata->vhv_result__coldboot_status =
+ (*(pbuffer + 5)) & 0x1;
+ pdata->vhv_result__search_result =
+ (*(pbuffer + 6)) & 0x3F;
+ pdata->vhv_result__latest_setting =
+ (*(pbuffer + 7)) & 0x3F;
+ pdata->result__osc_calibrate_val =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8)) & 0x3FF;
+ pdata->ana_config__powerdown_go1 =
+ (*(pbuffer + 10)) & 0x3;
+ pdata->ana_config__ref_bg_ctrl =
+ (*(pbuffer + 11)) & 0x3;
+ pdata->ana_config__regdvdd1v2_ctrl =
+ (*(pbuffer + 12)) & 0xF;
+ pdata->ana_config__osc_slow_ctrl =
+ (*(pbuffer + 13)) & 0x7;
+ pdata->test_mode__status =
+ (*(pbuffer + 14)) & 0x1;
+ pdata->firmware__system_status =
+ (*(pbuffer + 15)) & 0x3;
+ pdata->firmware__mode_status =
+ (*(pbuffer + 16));
+ pdata->firmware__secondary_mode_status =
+ (*(pbuffer + 17));
+ pdata->firmware__cal_repeat_rate_counter =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18)) & 0xFFF;
+ pdata->gph__system__thresh_high =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22));
+ pdata->gph__system__thresh_low =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24));
+ pdata->gph__system__enable_xtalk_per_quadrant =
+ (*(pbuffer + 26)) & 0x1;
+ pdata->gph__spare_0 =
+ (*(pbuffer + 27)) & 0x7;
+ pdata->gph__sd_config__woi_sd0 =
+ (*(pbuffer + 28));
+ pdata->gph__sd_config__woi_sd1 =
+ (*(pbuffer + 29));
+ pdata->gph__sd_config__initial_phase_sd0 =
+ (*(pbuffer + 30)) & 0x7F;
+ pdata->gph__sd_config__initial_phase_sd1 =
+ (*(pbuffer + 31)) & 0x7F;
+ pdata->gph__sd_config__first_order_select =
+ (*(pbuffer + 32)) & 0x3;
+ pdata->gph__sd_config__quantifier =
+ (*(pbuffer + 33)) & 0xF;
+ pdata->gph__roi_config__user_roi_centre_spad =
+ (*(pbuffer + 34));
+ pdata->gph__roi_config__user_roi_requested_global_xy_size =
+ (*(pbuffer + 35));
+ pdata->gph__system__sequence_config =
+ (*(pbuffer + 36));
+ pdata->gph__gph_id =
+ (*(pbuffer + 37)) & 0x1;
+ pdata->system__interrupt_set =
+ (*(pbuffer + 38)) & 0x3;
+ pdata->interrupt_manager__enables =
+ (*(pbuffer + 39)) & 0x1F;
+ pdata->interrupt_manager__clear =
+ (*(pbuffer + 40)) & 0x1F;
+ pdata->interrupt_manager__status =
+ (*(pbuffer + 41)) & 0x1F;
+ pdata->mcu_to_host_bank__wr_access_en =
+ (*(pbuffer + 42)) & 0x1;
+ pdata->power_management__go1_reset_status =
+ (*(pbuffer + 43)) & 0x1;
+ pdata->pad_startup_mode__value_ro =
+ (*(pbuffer + 44)) & 0x3;
+ pdata->pad_startup_mode__value_ctrl =
+ (*(pbuffer + 45)) & 0x3F;
+ pdata->pll_period_us =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 46)) & 0x3FFFF;
+ pdata->interrupt_scheduler__data_out =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 50));
+ pdata->nvm_bist__complete =
+ (*(pbuffer + 54)) & 0x1;
+ pdata->nvm_bist__status =
+ (*(pbuffer + 55)) & 0x1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_debug_results(
+ VL53L1_DEV Dev,
+ VL53L1_debug_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_debug_results(
+ pdata,
+ VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_PHASECAL_RESULT__REFERENCE_PHASE,
+ comms_buffer,
+ VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_debug_results(
+ VL53L1_DEV Dev,
+ VL53L1_debug_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_PHASECAL_RESULT__REFERENCE_PHASE,
+ comms_buffer,
+ VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_debug_results(
+ VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_nvm_copy_data(
+ VL53L1_nvm_copy_data_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->identification__model_id;
+ *(pbuffer + 1) =
+ pdata->identification__module_type;
+ *(pbuffer + 2) =
+ pdata->identification__revision_id;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->identification__module_id,
+ 2,
+ pbuffer + 3);
+ *(pbuffer + 5) =
+ pdata->ana_config__fast_osc__trim_max & 0x7F;
+ *(pbuffer + 6) =
+ pdata->ana_config__fast_osc__freq_set & 0x7;
+ *(pbuffer + 7) =
+ pdata->ana_config__vcsel_trim & 0x7;
+ *(pbuffer + 8) =
+ pdata->ana_config__vcsel_selion & 0x3F;
+ *(pbuffer + 9) =
+ pdata->ana_config__vcsel_selion_max & 0x3F;
+ *(pbuffer + 10) =
+ pdata->protected_laser_safety__lock_bit & 0x1;
+ *(pbuffer + 11) =
+ pdata->laser_safety__key & 0x7F;
+ *(pbuffer + 12) =
+ pdata->laser_safety__key_ro & 0x1;
+ *(pbuffer + 13) =
+ pdata->laser_safety__clip & 0x3F;
+ *(pbuffer + 14) =
+ pdata->laser_safety__mult & 0x3F;
+ *(pbuffer + 15) =
+ pdata->global_config__spad_enables_rtn_0;
+ *(pbuffer + 16) =
+ pdata->global_config__spad_enables_rtn_1;
+ *(pbuffer + 17) =
+ pdata->global_config__spad_enables_rtn_2;
+ *(pbuffer + 18) =
+ pdata->global_config__spad_enables_rtn_3;
+ *(pbuffer + 19) =
+ pdata->global_config__spad_enables_rtn_4;
+ *(pbuffer + 20) =
+ pdata->global_config__spad_enables_rtn_5;
+ *(pbuffer + 21) =
+ pdata->global_config__spad_enables_rtn_6;
+ *(pbuffer + 22) =
+ pdata->global_config__spad_enables_rtn_7;
+ *(pbuffer + 23) =
+ pdata->global_config__spad_enables_rtn_8;
+ *(pbuffer + 24) =
+ pdata->global_config__spad_enables_rtn_9;
+ *(pbuffer + 25) =
+ pdata->global_config__spad_enables_rtn_10;
+ *(pbuffer + 26) =
+ pdata->global_config__spad_enables_rtn_11;
+ *(pbuffer + 27) =
+ pdata->global_config__spad_enables_rtn_12;
+ *(pbuffer + 28) =
+ pdata->global_config__spad_enables_rtn_13;
+ *(pbuffer + 29) =
+ pdata->global_config__spad_enables_rtn_14;
+ *(pbuffer + 30) =
+ pdata->global_config__spad_enables_rtn_15;
+ *(pbuffer + 31) =
+ pdata->global_config__spad_enables_rtn_16;
+ *(pbuffer + 32) =
+ pdata->global_config__spad_enables_rtn_17;
+ *(pbuffer + 33) =
+ pdata->global_config__spad_enables_rtn_18;
+ *(pbuffer + 34) =
+ pdata->global_config__spad_enables_rtn_19;
+ *(pbuffer + 35) =
+ pdata->global_config__spad_enables_rtn_20;
+ *(pbuffer + 36) =
+ pdata->global_config__spad_enables_rtn_21;
+ *(pbuffer + 37) =
+ pdata->global_config__spad_enables_rtn_22;
+ *(pbuffer + 38) =
+ pdata->global_config__spad_enables_rtn_23;
+ *(pbuffer + 39) =
+ pdata->global_config__spad_enables_rtn_24;
+ *(pbuffer + 40) =
+ pdata->global_config__spad_enables_rtn_25;
+ *(pbuffer + 41) =
+ pdata->global_config__spad_enables_rtn_26;
+ *(pbuffer + 42) =
+ pdata->global_config__spad_enables_rtn_27;
+ *(pbuffer + 43) =
+ pdata->global_config__spad_enables_rtn_28;
+ *(pbuffer + 44) =
+ pdata->global_config__spad_enables_rtn_29;
+ *(pbuffer + 45) =
+ pdata->global_config__spad_enables_rtn_30;
+ *(pbuffer + 46) =
+ pdata->global_config__spad_enables_rtn_31;
+ *(pbuffer + 47) =
+ pdata->roi_config__mode_roi_centre_spad;
+ *(pbuffer + 48) =
+ pdata->roi_config__mode_roi_xy_size;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_nvm_copy_data(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_nvm_copy_data_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->identification__model_id =
+ (*(pbuffer + 0));
+ pdata->identification__module_type =
+ (*(pbuffer + 1));
+ pdata->identification__revision_id =
+ (*(pbuffer + 2));
+ pdata->identification__module_id =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 3));
+ pdata->ana_config__fast_osc__trim_max =
+ (*(pbuffer + 5)) & 0x7F;
+ pdata->ana_config__fast_osc__freq_set =
+ (*(pbuffer + 6)) & 0x7;
+ pdata->ana_config__vcsel_trim =
+ (*(pbuffer + 7)) & 0x7;
+ pdata->ana_config__vcsel_selion =
+ (*(pbuffer + 8)) & 0x3F;
+ pdata->ana_config__vcsel_selion_max =
+ (*(pbuffer + 9)) & 0x3F;
+ pdata->protected_laser_safety__lock_bit =
+ (*(pbuffer + 10)) & 0x1;
+ pdata->laser_safety__key =
+ (*(pbuffer + 11)) & 0x7F;
+ pdata->laser_safety__key_ro =
+ (*(pbuffer + 12)) & 0x1;
+ pdata->laser_safety__clip =
+ (*(pbuffer + 13)) & 0x3F;
+ pdata->laser_safety__mult =
+ (*(pbuffer + 14)) & 0x3F;
+ pdata->global_config__spad_enables_rtn_0 =
+ (*(pbuffer + 15));
+ pdata->global_config__spad_enables_rtn_1 =
+ (*(pbuffer + 16));
+ pdata->global_config__spad_enables_rtn_2 =
+ (*(pbuffer + 17));
+ pdata->global_config__spad_enables_rtn_3 =
+ (*(pbuffer + 18));
+ pdata->global_config__spad_enables_rtn_4 =
+ (*(pbuffer + 19));
+ pdata->global_config__spad_enables_rtn_5 =
+ (*(pbuffer + 20));
+ pdata->global_config__spad_enables_rtn_6 =
+ (*(pbuffer + 21));
+ pdata->global_config__spad_enables_rtn_7 =
+ (*(pbuffer + 22));
+ pdata->global_config__spad_enables_rtn_8 =
+ (*(pbuffer + 23));
+ pdata->global_config__spad_enables_rtn_9 =
+ (*(pbuffer + 24));
+ pdata->global_config__spad_enables_rtn_10 =
+ (*(pbuffer + 25));
+ pdata->global_config__spad_enables_rtn_11 =
+ (*(pbuffer + 26));
+ pdata->global_config__spad_enables_rtn_12 =
+ (*(pbuffer + 27));
+ pdata->global_config__spad_enables_rtn_13 =
+ (*(pbuffer + 28));
+ pdata->global_config__spad_enables_rtn_14 =
+ (*(pbuffer + 29));
+ pdata->global_config__spad_enables_rtn_15 =
+ (*(pbuffer + 30));
+ pdata->global_config__spad_enables_rtn_16 =
+ (*(pbuffer + 31));
+ pdata->global_config__spad_enables_rtn_17 =
+ (*(pbuffer + 32));
+ pdata->global_config__spad_enables_rtn_18 =
+ (*(pbuffer + 33));
+ pdata->global_config__spad_enables_rtn_19 =
+ (*(pbuffer + 34));
+ pdata->global_config__spad_enables_rtn_20 =
+ (*(pbuffer + 35));
+ pdata->global_config__spad_enables_rtn_21 =
+ (*(pbuffer + 36));
+ pdata->global_config__spad_enables_rtn_22 =
+ (*(pbuffer + 37));
+ pdata->global_config__spad_enables_rtn_23 =
+ (*(pbuffer + 38));
+ pdata->global_config__spad_enables_rtn_24 =
+ (*(pbuffer + 39));
+ pdata->global_config__spad_enables_rtn_25 =
+ (*(pbuffer + 40));
+ pdata->global_config__spad_enables_rtn_26 =
+ (*(pbuffer + 41));
+ pdata->global_config__spad_enables_rtn_27 =
+ (*(pbuffer + 42));
+ pdata->global_config__spad_enables_rtn_28 =
+ (*(pbuffer + 43));
+ pdata->global_config__spad_enables_rtn_29 =
+ (*(pbuffer + 44));
+ pdata->global_config__spad_enables_rtn_30 =
+ (*(pbuffer + 45));
+ pdata->global_config__spad_enables_rtn_31 =
+ (*(pbuffer + 46));
+ pdata->roi_config__mode_roi_centre_spad =
+ (*(pbuffer + 47));
+ pdata->roi_config__mode_roi_xy_size =
+ (*(pbuffer + 48));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_nvm_copy_data(
+ VL53L1_DEV Dev,
+ VL53L1_nvm_copy_data_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_nvm_copy_data(
+ pdata,
+ VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_IDENTIFICATION__MODEL_ID,
+ comms_buffer,
+ VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_nvm_copy_data(
+ VL53L1_DEV Dev,
+ VL53L1_nvm_copy_data_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_IDENTIFICATION__MODEL_ID,
+ comms_buffer,
+ VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_nvm_copy_data(
+ VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_prev_shadow_system_results(
+ VL53L1_prev_shadow_system_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->prev_shadow_result__interrupt_status & 0x3F;
+ *(pbuffer + 1) =
+ pdata->prev_shadow_result__range_status;
+ *(pbuffer + 2) =
+ pdata->prev_shadow_result__report_status & 0xF;
+ *(pbuffer + 3) =
+ pdata->prev_shadow_result__stream_count;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__dss_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 4);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 6);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__ambient_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 8);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__sigma_sd0,
+ 2,
+ pbuffer + 10);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__phase_sd0,
+ 2,
+ pbuffer + 12);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd0,
+ 2,
+ pbuffer + 14);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0,
+ 2,
+ pbuffer + 16);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__mm_inner_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 18);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__mm_outer_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 20);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__avg_signal_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 22);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__dss_actual_effective_spads_sd1,
+ 2,
+ pbuffer + 24);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd1,
+ 2,
+ pbuffer + 26);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__ambient_count_rate_mcps_sd1,
+ 2,
+ pbuffer + 28);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__sigma_sd1,
+ 2,
+ pbuffer + 30);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__phase_sd1,
+ 2,
+ pbuffer + 32);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd1,
+ 2,
+ pbuffer + 34);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__spare_0_sd1,
+ 2,
+ pbuffer + 36);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__spare_1_sd1,
+ 2,
+ pbuffer + 38);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__spare_2_sd1,
+ 2,
+ pbuffer + 40);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__spare_3_sd1,
+ 2,
+ pbuffer + 42);
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_prev_shadow_system_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_prev_shadow_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->prev_shadow_result__interrupt_status =
+ (*(pbuffer + 0)) & 0x3F;
+ pdata->prev_shadow_result__range_status =
+ (*(pbuffer + 1));
+ pdata->prev_shadow_result__report_status =
+ (*(pbuffer + 2)) & 0xF;
+ pdata->prev_shadow_result__stream_count =
+ (*(pbuffer + 3));
+ pdata->prev_shadow_result__dss_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 4));
+ pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 6));
+ pdata->prev_shadow_result__ambient_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8));
+ pdata->prev_shadow_result__sigma_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10));
+ pdata->prev_shadow_result__phase_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12));
+ pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14));
+ pdata->prev_shadow_result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16));
+ pdata->prev_shadow_result__mm_inner_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18));
+ pdata->prev_shadow_result__mm_outer_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 20));
+ pdata->prev_shadow_result__avg_signal_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22));
+ pdata->prev_shadow_result__dss_actual_effective_spads_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24));
+ pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 26));
+ pdata->prev_shadow_result__ambient_count_rate_mcps_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 28));
+ pdata->prev_shadow_result__sigma_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 30));
+ pdata->prev_shadow_result__phase_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 32));
+ pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 34));
+ pdata->prev_shadow_result__spare_0_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 36));
+ pdata->prev_shadow_result__spare_1_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 38));
+ pdata->prev_shadow_result__spare_2_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 40));
+ pdata->prev_shadow_result__spare_3_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 42));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_prev_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_prev_shadow_system_results(
+ pdata,
+ VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_PREV_SHADOW_RESULT__INTERRUPT_STATUS,
+ comms_buffer,
+ VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_prev_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_PREV_SHADOW_RESULT__INTERRUPT_STATUS,
+ comms_buffer,
+ VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_prev_shadow_system_results(
+ VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_prev_shadow_core_results(
+ VL53L1_prev_shadow_core_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ VL53L1_i2c_encode_uint32_t(
+ pdata->prev_shadow_result_core__ambient_window_events_sd0,
+ 4,
+ pbuffer + 0);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->prev_shadow_result_core__ranging_total_events_sd0,
+ 4,
+ pbuffer + 4);
+ VL53L1_i2c_encode_int32_t(
+ pdata->prev_shadow_result_core__signal_total_events_sd0,
+ 4,
+ pbuffer + 8);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->prev_shadow_result_core__total_periods_elapsed_sd0,
+ 4,
+ pbuffer + 12);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->prev_shadow_result_core__ambient_window_events_sd1,
+ 4,
+ pbuffer + 16);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->prev_shadow_result_core__ranging_total_events_sd1,
+ 4,
+ pbuffer + 20);
+ VL53L1_i2c_encode_int32_t(
+ pdata->prev_shadow_result_core__signal_total_events_sd1,
+ 4,
+ pbuffer + 24);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->prev_shadow_result_core__total_periods_elapsed_sd1,
+ 4,
+ pbuffer + 28);
+ *(pbuffer + 32) =
+ pdata->prev_shadow_result_core__spare_0;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_prev_shadow_core_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_prev_shadow_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->prev_shadow_result_core__ambient_window_events_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 0));
+ pdata->prev_shadow_result_core__ranging_total_events_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 4));
+ pdata->prev_shadow_result_core__signal_total_events_sd0 =
+ (VL53L1_i2c_decode_int32_t(4, pbuffer + 8));
+ pdata->prev_shadow_result_core__total_periods_elapsed_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 12));
+ pdata->prev_shadow_result_core__ambient_window_events_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 16));
+ pdata->prev_shadow_result_core__ranging_total_events_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 20));
+ pdata->prev_shadow_result_core__signal_total_events_sd1 =
+ (VL53L1_i2c_decode_int32_t(4, pbuffer + 24));
+ pdata->prev_shadow_result_core__total_periods_elapsed_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 28));
+ pdata->prev_shadow_result_core__spare_0 =
+ (*(pbuffer + 32));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_prev_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_prev_shadow_core_results(
+ pdata,
+ VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0,
+ comms_buffer,
+ VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_prev_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0,
+ comms_buffer,
+ VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_prev_shadow_core_results(
+ VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_patch_debug(
+ VL53L1_patch_debug_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->result__debug_status;
+ *(pbuffer + 1) =
+ pdata->result__debug_stage;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_patch_debug(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_patch_debug_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->result__debug_status =
+ (*(pbuffer + 0));
+ pdata->result__debug_stage =
+ (*(pbuffer + 1));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_patch_debug(
+ VL53L1_DEV Dev,
+ VL53L1_patch_debug_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_patch_debug(
+ pdata,
+ VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_RESULT__DEBUG_STATUS,
+ comms_buffer,
+ VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_patch_debug(
+ VL53L1_DEV Dev,
+ VL53L1_patch_debug_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_RESULT__DEBUG_STATUS,
+ comms_buffer,
+ VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_patch_debug(
+ VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_gph_general_config(
+ VL53L1_gph_general_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ VL53L1_i2c_encode_uint16_t(
+ pdata->gph__system__thresh_rate_high,
+ 2,
+ pbuffer + 0);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->gph__system__thresh_rate_low,
+ 2,
+ pbuffer + 2);
+ *(pbuffer + 4) =
+ pdata->gph__system__interrupt_config_gpio;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_gph_general_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_gph_general_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->gph__system__thresh_rate_high =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 0));
+ pdata->gph__system__thresh_rate_low =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 2));
+ pdata->gph__system__interrupt_config_gpio =
+ (*(pbuffer + 4));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_gph_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_general_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_gph_general_config(
+ pdata,
+ VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH,
+ comms_buffer,
+ VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_gph_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_general_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH,
+ comms_buffer,
+ VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_gph_general_config(
+ VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_gph_static_config(
+ VL53L1_gph_static_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->gph__dss_config__roi_mode_control & 0x7;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->gph__dss_config__manual_effective_spads_select,
+ 2,
+ pbuffer + 1);
+ *(pbuffer + 3) =
+ pdata->gph__dss_config__manual_block_select;
+ *(pbuffer + 4) =
+ pdata->gph__dss_config__max_spads_limit;
+ *(pbuffer + 5) =
+ pdata->gph__dss_config__min_spads_limit;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_gph_static_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_gph_static_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->gph__dss_config__roi_mode_control =
+ (*(pbuffer + 0)) & 0x7;
+ pdata->gph__dss_config__manual_effective_spads_select =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 1));
+ pdata->gph__dss_config__manual_block_select =
+ (*(pbuffer + 3));
+ pdata->gph__dss_config__max_spads_limit =
+ (*(pbuffer + 4));
+ pdata->gph__dss_config__min_spads_limit =
+ (*(pbuffer + 5));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_gph_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_static_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_gph_static_config(
+ pdata,
+ VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_GPH__DSS_CONFIG__ROI_MODE_CONTROL,
+ comms_buffer,
+ VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_gph_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_static_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_GPH__DSS_CONFIG__ROI_MODE_CONTROL,
+ comms_buffer,
+ VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_gph_static_config(
+ VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_gph_timing_config(
+ VL53L1_gph_timing_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->gph__mm_config__timeout_macrop_a_hi & 0xF;
+ *(pbuffer + 1) =
+ pdata->gph__mm_config__timeout_macrop_a_lo;
+ *(pbuffer + 2) =
+ pdata->gph__mm_config__timeout_macrop_b_hi & 0xF;
+ *(pbuffer + 3) =
+ pdata->gph__mm_config__timeout_macrop_b_lo;
+ *(pbuffer + 4) =
+ pdata->gph__range_config__timeout_macrop_a_hi & 0xF;
+ *(pbuffer + 5) =
+ pdata->gph__range_config__timeout_macrop_a_lo;
+ *(pbuffer + 6) =
+ pdata->gph__range_config__vcsel_period_a & 0x3F;
+ *(pbuffer + 7) =
+ pdata->gph__range_config__vcsel_period_b & 0x3F;
+ *(pbuffer + 8) =
+ pdata->gph__range_config__timeout_macrop_b_hi & 0xF;
+ *(pbuffer + 9) =
+ pdata->gph__range_config__timeout_macrop_b_lo;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->gph__range_config__sigma_thresh,
+ 2,
+ pbuffer + 10);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->gph__range_config__min_count_rate_rtn_limit_mcps,
+ 2,
+ pbuffer + 12);
+ *(pbuffer + 14) =
+ pdata->gph__range_config__valid_phase_low;
+ *(pbuffer + 15) =
+ pdata->gph__range_config__valid_phase_high;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_gph_timing_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_gph_timing_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->gph__mm_config__timeout_macrop_a_hi =
+ (*(pbuffer + 0)) & 0xF;
+ pdata->gph__mm_config__timeout_macrop_a_lo =
+ (*(pbuffer + 1));
+ pdata->gph__mm_config__timeout_macrop_b_hi =
+ (*(pbuffer + 2)) & 0xF;
+ pdata->gph__mm_config__timeout_macrop_b_lo =
+ (*(pbuffer + 3));
+ pdata->gph__range_config__timeout_macrop_a_hi =
+ (*(pbuffer + 4)) & 0xF;
+ pdata->gph__range_config__timeout_macrop_a_lo =
+ (*(pbuffer + 5));
+ pdata->gph__range_config__vcsel_period_a =
+ (*(pbuffer + 6)) & 0x3F;
+ pdata->gph__range_config__vcsel_period_b =
+ (*(pbuffer + 7)) & 0x3F;
+ pdata->gph__range_config__timeout_macrop_b_hi =
+ (*(pbuffer + 8)) & 0xF;
+ pdata->gph__range_config__timeout_macrop_b_lo =
+ (*(pbuffer + 9));
+ pdata->gph__range_config__sigma_thresh =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10));
+ pdata->gph__range_config__min_count_rate_rtn_limit_mcps =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12));
+ pdata->gph__range_config__valid_phase_low =
+ (*(pbuffer + 14));
+ pdata->gph__range_config__valid_phase_high =
+ (*(pbuffer + 15));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_gph_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_timing_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_gph_timing_config(
+ pdata,
+ VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_A_HI,
+ comms_buffer,
+ VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_gph_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_timing_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_A_HI,
+ comms_buffer,
+ VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_gph_timing_config(
+ VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_fw_internal(
+ VL53L1_fw_internal_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_FW_INTERNAL_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->firmware__internal_stream_count_div;
+ *(pbuffer + 1) =
+ pdata->firmware__internal_stream_counter_val;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_fw_internal(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_fw_internal_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_FW_INTERNAL_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->firmware__internal_stream_count_div =
+ (*(pbuffer + 0));
+ pdata->firmware__internal_stream_counter_val =
+ (*(pbuffer + 1));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_fw_internal(
+ VL53L1_DEV Dev,
+ VL53L1_fw_internal_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_FW_INTERNAL_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_fw_internal(
+ pdata,
+ VL53L1_FW_INTERNAL_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_FIRMWARE__INTERNAL_STREAM_COUNT_DIV,
+ comms_buffer,
+ VL53L1_FW_INTERNAL_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_fw_internal(
+ VL53L1_DEV Dev,
+ VL53L1_fw_internal_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_FW_INTERNAL_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_FIRMWARE__INTERNAL_STREAM_COUNT_DIV,
+ comms_buffer,
+ VL53L1_FW_INTERNAL_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_fw_internal(
+ VL53L1_FW_INTERNAL_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_patch_results(
+ VL53L1_patch_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->dss_calc__roi_ctrl & 0x3;
+ *(pbuffer + 1) =
+ pdata->dss_calc__spare_1;
+ *(pbuffer + 2) =
+ pdata->dss_calc__spare_2;
+ *(pbuffer + 3) =
+ pdata->dss_calc__spare_3;
+ *(pbuffer + 4) =
+ pdata->dss_calc__spare_4;
+ *(pbuffer + 5) =
+ pdata->dss_calc__spare_5;
+ *(pbuffer + 6) =
+ pdata->dss_calc__spare_6;
+ *(pbuffer + 7) =
+ pdata->dss_calc__spare_7;
+ *(pbuffer + 8) =
+ pdata->dss_calc__user_roi_spad_en_0;
+ *(pbuffer + 9) =
+ pdata->dss_calc__user_roi_spad_en_1;
+ *(pbuffer + 10) =
+ pdata->dss_calc__user_roi_spad_en_2;
+ *(pbuffer + 11) =
+ pdata->dss_calc__user_roi_spad_en_3;
+ *(pbuffer + 12) =
+ pdata->dss_calc__user_roi_spad_en_4;
+ *(pbuffer + 13) =
+ pdata->dss_calc__user_roi_spad_en_5;
+ *(pbuffer + 14) =
+ pdata->dss_calc__user_roi_spad_en_6;
+ *(pbuffer + 15) =
+ pdata->dss_calc__user_roi_spad_en_7;
+ *(pbuffer + 16) =
+ pdata->dss_calc__user_roi_spad_en_8;
+ *(pbuffer + 17) =
+ pdata->dss_calc__user_roi_spad_en_9;
+ *(pbuffer + 18) =
+ pdata->dss_calc__user_roi_spad_en_10;
+ *(pbuffer + 19) =
+ pdata->dss_calc__user_roi_spad_en_11;
+ *(pbuffer + 20) =
+ pdata->dss_calc__user_roi_spad_en_12;
+ *(pbuffer + 21) =
+ pdata->dss_calc__user_roi_spad_en_13;
+ *(pbuffer + 22) =
+ pdata->dss_calc__user_roi_spad_en_14;
+ *(pbuffer + 23) =
+ pdata->dss_calc__user_roi_spad_en_15;
+ *(pbuffer + 24) =
+ pdata->dss_calc__user_roi_spad_en_16;
+ *(pbuffer + 25) =
+ pdata->dss_calc__user_roi_spad_en_17;
+ *(pbuffer + 26) =
+ pdata->dss_calc__user_roi_spad_en_18;
+ *(pbuffer + 27) =
+ pdata->dss_calc__user_roi_spad_en_19;
+ *(pbuffer + 28) =
+ pdata->dss_calc__user_roi_spad_en_20;
+ *(pbuffer + 29) =
+ pdata->dss_calc__user_roi_spad_en_21;
+ *(pbuffer + 30) =
+ pdata->dss_calc__user_roi_spad_en_22;
+ *(pbuffer + 31) =
+ pdata->dss_calc__user_roi_spad_en_23;
+ *(pbuffer + 32) =
+ pdata->dss_calc__user_roi_spad_en_24;
+ *(pbuffer + 33) =
+ pdata->dss_calc__user_roi_spad_en_25;
+ *(pbuffer + 34) =
+ pdata->dss_calc__user_roi_spad_en_26;
+ *(pbuffer + 35) =
+ pdata->dss_calc__user_roi_spad_en_27;
+ *(pbuffer + 36) =
+ pdata->dss_calc__user_roi_spad_en_28;
+ *(pbuffer + 37) =
+ pdata->dss_calc__user_roi_spad_en_29;
+ *(pbuffer + 38) =
+ pdata->dss_calc__user_roi_spad_en_30;
+ *(pbuffer + 39) =
+ pdata->dss_calc__user_roi_spad_en_31;
+ *(pbuffer + 40) =
+ pdata->dss_calc__user_roi_0;
+ *(pbuffer + 41) =
+ pdata->dss_calc__user_roi_1;
+ *(pbuffer + 42) =
+ pdata->dss_calc__mode_roi_0;
+ *(pbuffer + 43) =
+ pdata->dss_calc__mode_roi_1;
+ *(pbuffer + 44) =
+ pdata->sigma_estimator_calc__spare_0;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->vhv_result__peak_signal_rate_mcps,
+ 2,
+ pbuffer + 46);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->vhv_result__signal_total_events_ref,
+ 4,
+ pbuffer + 48);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->phasecal_result__phase_output_ref,
+ 2,
+ pbuffer + 52);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->dss_result__total_rate_per_spad,
+ 2,
+ pbuffer + 54);
+ *(pbuffer + 56) =
+ pdata->dss_result__enabled_blocks;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->dss_result__num_requested_spads,
+ 2,
+ pbuffer + 58);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->mm_result__inner_intersection_rate,
+ 2,
+ pbuffer + 62);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->mm_result__outer_complement_rate,
+ 2,
+ pbuffer + 64);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->mm_result__total_offset,
+ 2,
+ pbuffer + 66);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->xtalk_calc__xtalk_for_enabled_spads & 0xFFFFFF,
+ 4,
+ pbuffer + 68);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->xtalk_result__avg_xtalk_user_roi_kcps & 0xFFFFFF,
+ 4,
+ pbuffer + 72);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->xtalk_result__avg_xtalk_mm_inner_roi_kcps & 0xFFFFFF,
+ 4,
+ pbuffer + 76);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->xtalk_result__avg_xtalk_mm_outer_roi_kcps & 0xFFFFFF,
+ 4,
+ pbuffer + 80);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->range_result__accum_phase,
+ 4,
+ pbuffer + 84);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->range_result__offset_corrected_range,
+ 2,
+ pbuffer + 88);
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_patch_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_patch_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->dss_calc__roi_ctrl =
+ (*(pbuffer + 0)) & 0x3;
+ pdata->dss_calc__spare_1 =
+ (*(pbuffer + 1));
+ pdata->dss_calc__spare_2 =
+ (*(pbuffer + 2));
+ pdata->dss_calc__spare_3 =
+ (*(pbuffer + 3));
+ pdata->dss_calc__spare_4 =
+ (*(pbuffer + 4));
+ pdata->dss_calc__spare_5 =
+ (*(pbuffer + 5));
+ pdata->dss_calc__spare_6 =
+ (*(pbuffer + 6));
+ pdata->dss_calc__spare_7 =
+ (*(pbuffer + 7));
+ pdata->dss_calc__user_roi_spad_en_0 =
+ (*(pbuffer + 8));
+ pdata->dss_calc__user_roi_spad_en_1 =
+ (*(pbuffer + 9));
+ pdata->dss_calc__user_roi_spad_en_2 =
+ (*(pbuffer + 10));
+ pdata->dss_calc__user_roi_spad_en_3 =
+ (*(pbuffer + 11));
+ pdata->dss_calc__user_roi_spad_en_4 =
+ (*(pbuffer + 12));
+ pdata->dss_calc__user_roi_spad_en_5 =
+ (*(pbuffer + 13));
+ pdata->dss_calc__user_roi_spad_en_6 =
+ (*(pbuffer + 14));
+ pdata->dss_calc__user_roi_spad_en_7 =
+ (*(pbuffer + 15));
+ pdata->dss_calc__user_roi_spad_en_8 =
+ (*(pbuffer + 16));
+ pdata->dss_calc__user_roi_spad_en_9 =
+ (*(pbuffer + 17));
+ pdata->dss_calc__user_roi_spad_en_10 =
+ (*(pbuffer + 18));
+ pdata->dss_calc__user_roi_spad_en_11 =
+ (*(pbuffer + 19));
+ pdata->dss_calc__user_roi_spad_en_12 =
+ (*(pbuffer + 20));
+ pdata->dss_calc__user_roi_spad_en_13 =
+ (*(pbuffer + 21));
+ pdata->dss_calc__user_roi_spad_en_14 =
+ (*(pbuffer + 22));
+ pdata->dss_calc__user_roi_spad_en_15 =
+ (*(pbuffer + 23));
+ pdata->dss_calc__user_roi_spad_en_16 =
+ (*(pbuffer + 24));
+ pdata->dss_calc__user_roi_spad_en_17 =
+ (*(pbuffer + 25));
+ pdata->dss_calc__user_roi_spad_en_18 =
+ (*(pbuffer + 26));
+ pdata->dss_calc__user_roi_spad_en_19 =
+ (*(pbuffer + 27));
+ pdata->dss_calc__user_roi_spad_en_20 =
+ (*(pbuffer + 28));
+ pdata->dss_calc__user_roi_spad_en_21 =
+ (*(pbuffer + 29));
+ pdata->dss_calc__user_roi_spad_en_22 =
+ (*(pbuffer + 30));
+ pdata->dss_calc__user_roi_spad_en_23 =
+ (*(pbuffer + 31));
+ pdata->dss_calc__user_roi_spad_en_24 =
+ (*(pbuffer + 32));
+ pdata->dss_calc__user_roi_spad_en_25 =
+ (*(pbuffer + 33));
+ pdata->dss_calc__user_roi_spad_en_26 =
+ (*(pbuffer + 34));
+ pdata->dss_calc__user_roi_spad_en_27 =
+ (*(pbuffer + 35));
+ pdata->dss_calc__user_roi_spad_en_28 =
+ (*(pbuffer + 36));
+ pdata->dss_calc__user_roi_spad_en_29 =
+ (*(pbuffer + 37));
+ pdata->dss_calc__user_roi_spad_en_30 =
+ (*(pbuffer + 38));
+ pdata->dss_calc__user_roi_spad_en_31 =
+ (*(pbuffer + 39));
+ pdata->dss_calc__user_roi_0 =
+ (*(pbuffer + 40));
+ pdata->dss_calc__user_roi_1 =
+ (*(pbuffer + 41));
+ pdata->dss_calc__mode_roi_0 =
+ (*(pbuffer + 42));
+ pdata->dss_calc__mode_roi_1 =
+ (*(pbuffer + 43));
+ pdata->sigma_estimator_calc__spare_0 =
+ (*(pbuffer + 44));
+ pdata->vhv_result__peak_signal_rate_mcps =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 46));
+ pdata->vhv_result__signal_total_events_ref =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 48));
+ pdata->phasecal_result__phase_output_ref =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 52));
+ pdata->dss_result__total_rate_per_spad =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 54));
+ pdata->dss_result__enabled_blocks =
+ (*(pbuffer + 56));
+ pdata->dss_result__num_requested_spads =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 58));
+ pdata->mm_result__inner_intersection_rate =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 62));
+ pdata->mm_result__outer_complement_rate =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 64));
+ pdata->mm_result__total_offset =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 66));
+ pdata->xtalk_calc__xtalk_for_enabled_spads =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 68)) & 0xFFFFFF;
+ pdata->xtalk_result__avg_xtalk_user_roi_kcps =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 72)) & 0xFFFFFF;
+ pdata->xtalk_result__avg_xtalk_mm_inner_roi_kcps =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 76)) & 0xFFFFFF;
+ pdata->xtalk_result__avg_xtalk_mm_outer_roi_kcps =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 80)) & 0xFFFFFF;
+ pdata->range_result__accum_phase =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 84));
+ pdata->range_result__offset_corrected_range =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 88));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_patch_results(
+ VL53L1_DEV Dev,
+ VL53L1_patch_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_patch_results(
+ pdata,
+ VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_DSS_CALC__ROI_CTRL,
+ comms_buffer,
+ VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_patch_results(
+ VL53L1_DEV Dev,
+ VL53L1_patch_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_DSS_CALC__ROI_CTRL,
+ comms_buffer,
+ VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_patch_results(
+ VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_shadow_system_results(
+ VL53L1_shadow_system_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->shadow_phasecal_result__vcsel_start;
+ *(pbuffer + 2) =
+ pdata->shadow_result__interrupt_status & 0x3F;
+ *(pbuffer + 3) =
+ pdata->shadow_result__range_status;
+ *(pbuffer + 4) =
+ pdata->shadow_result__report_status & 0xF;
+ *(pbuffer + 5) =
+ pdata->shadow_result__stream_count;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__dss_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 6);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__peak_signal_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 8);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__ambient_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 10);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__sigma_sd0,
+ 2,
+ pbuffer + 12);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__phase_sd0,
+ 2,
+ pbuffer + 14);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__final_crosstalk_corrected_range_mm_sd0,
+ 2,
+ pbuffer + 16);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0,
+ 2,
+ pbuffer + 18);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__mm_inner_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 20);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__mm_outer_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 22);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__avg_signal_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 24);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__dss_actual_effective_spads_sd1,
+ 2,
+ pbuffer + 26);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__peak_signal_count_rate_mcps_sd1,
+ 2,
+ pbuffer + 28);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__ambient_count_rate_mcps_sd1,
+ 2,
+ pbuffer + 30);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__sigma_sd1,
+ 2,
+ pbuffer + 32);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__phase_sd1,
+ 2,
+ pbuffer + 34);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__final_crosstalk_corrected_range_mm_sd1,
+ 2,
+ pbuffer + 36);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__spare_0_sd1,
+ 2,
+ pbuffer + 38);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__spare_1_sd1,
+ 2,
+ pbuffer + 40);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__spare_2_sd1,
+ 2,
+ pbuffer + 42);
+ *(pbuffer + 44) =
+ pdata->shadow_result__spare_3_sd1;
+ *(pbuffer + 45) =
+ pdata->shadow_result__thresh_info;
+ *(pbuffer + 80) =
+ pdata->shadow_phasecal_result__reference_phase_hi;
+ *(pbuffer + 81) =
+ pdata->shadow_phasecal_result__reference_phase_lo;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_shadow_system_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_shadow_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->shadow_phasecal_result__vcsel_start =
+ (*(pbuffer + 0));
+ pdata->shadow_result__interrupt_status =
+ (*(pbuffer + 2)) & 0x3F;
+ pdata->shadow_result__range_status =
+ (*(pbuffer + 3));
+ pdata->shadow_result__report_status =
+ (*(pbuffer + 4)) & 0xF;
+ pdata->shadow_result__stream_count =
+ (*(pbuffer + 5));
+ pdata->shadow_result__dss_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 6));
+ pdata->shadow_result__peak_signal_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8));
+ pdata->shadow_result__ambient_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10));
+ pdata->shadow_result__sigma_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12));
+ pdata->shadow_result__phase_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14));
+ pdata->shadow_result__final_crosstalk_corrected_range_mm_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16));
+ pdata->shadow_result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18));
+ pdata->shadow_result__mm_inner_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 20));
+ pdata->shadow_result__mm_outer_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22));
+ pdata->shadow_result__avg_signal_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24));
+ pdata->shadow_result__dss_actual_effective_spads_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 26));
+ pdata->shadow_result__peak_signal_count_rate_mcps_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 28));
+ pdata->shadow_result__ambient_count_rate_mcps_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 30));
+ pdata->shadow_result__sigma_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 32));
+ pdata->shadow_result__phase_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 34));
+ pdata->shadow_result__final_crosstalk_corrected_range_mm_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 36));
+ pdata->shadow_result__spare_0_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 38));
+ pdata->shadow_result__spare_1_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 40));
+ pdata->shadow_result__spare_2_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 42));
+ pdata->shadow_result__spare_3_sd1 =
+ (*(pbuffer + 44));
+ pdata->shadow_result__thresh_info =
+ (*(pbuffer + 45));
+ pdata->shadow_phasecal_result__reference_phase_hi =
+ (*(pbuffer + 80));
+ pdata->shadow_phasecal_result__reference_phase_lo =
+ (*(pbuffer + 81));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_shadow_system_results(
+ pdata,
+ VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_SHADOW_PHASECAL_RESULT__VCSEL_START,
+ comms_buffer,
+ VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_SHADOW_PHASECAL_RESULT__VCSEL_START,
+ comms_buffer,
+ VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_shadow_system_results(
+ VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_shadow_core_results(
+ VL53L1_shadow_core_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ VL53L1_i2c_encode_uint32_t(
+ pdata->shadow_result_core__ambient_window_events_sd0,
+ 4,
+ pbuffer + 0);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->shadow_result_core__ranging_total_events_sd0,
+ 4,
+ pbuffer + 4);
+ VL53L1_i2c_encode_int32_t(
+ pdata->shadow_result_core__signal_total_events_sd0,
+ 4,
+ pbuffer + 8);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->shadow_result_core__total_periods_elapsed_sd0,
+ 4,
+ pbuffer + 12);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->shadow_result_core__ambient_window_events_sd1,
+ 4,
+ pbuffer + 16);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->shadow_result_core__ranging_total_events_sd1,
+ 4,
+ pbuffer + 20);
+ VL53L1_i2c_encode_int32_t(
+ pdata->shadow_result_core__signal_total_events_sd1,
+ 4,
+ pbuffer + 24);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->shadow_result_core__total_periods_elapsed_sd1,
+ 4,
+ pbuffer + 28);
+ *(pbuffer + 32) =
+ pdata->shadow_result_core__spare_0;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_shadow_core_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_shadow_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->shadow_result_core__ambient_window_events_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 0));
+ pdata->shadow_result_core__ranging_total_events_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 4));
+ pdata->shadow_result_core__signal_total_events_sd0 =
+ (VL53L1_i2c_decode_int32_t(4, pbuffer + 8));
+ pdata->shadow_result_core__total_periods_elapsed_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 12));
+ pdata->shadow_result_core__ambient_window_events_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 16));
+ pdata->shadow_result_core__ranging_total_events_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 20));
+ pdata->shadow_result_core__signal_total_events_sd1 =
+ (VL53L1_i2c_decode_int32_t(4, pbuffer + 24));
+ pdata->shadow_result_core__total_periods_elapsed_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 28));
+ pdata->shadow_result_core__spare_0 =
+ (*(pbuffer + 32));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_shadow_core_results(
+ pdata,
+ VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0,
+ comms_buffer,
+ VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0,
+ comms_buffer,
+ VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_shadow_core_results(
+ VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_silicon_core.c b/drivers/input/misc/vl53L1/src/vl53l1_silicon_core.c
new file mode 100644
index 000000000000..acd5c1769eb9
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_silicon_core.c
@@ -0,0 +1,180 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_register_map.h"
+#include "vl53l1_core.h"
+#include "vl53l1_silicon_core.h"
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_is_firmware_ready_silicon(
+ VL53L1_DEV Dev,
+ uint8_t *pready)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t comms_buffer[5];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_INTERRUPT_MANAGER__ENABLES,
+ comms_buffer,
+ 5);
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pdev->dbg_results.interrupt_manager__enables =
+ comms_buffer[0];
+ pdev->dbg_results.interrupt_manager__clear =
+ comms_buffer[1];
+ pdev->dbg_results.interrupt_manager__status =
+ comms_buffer[2];
+ pdev->dbg_results.mcu_to_host_bank__wr_access_en =
+ comms_buffer[3];
+ pdev->dbg_results.power_management__go1_reset_status =
+ comms_buffer[4];
+
+ if ((pdev->sys_ctrl.power_management__go1_power_force & 0x01) == 0x01) {
+
+ if (((pdev->dbg_results.interrupt_manager__enables & 0x1F) == 0x1F) &&
+ ((pdev->dbg_results.interrupt_manager__clear & 0x1F) == 0x1F))
+ *pready = 0x01;
+ else
+ *pready = 0x00;
+
+ } else {
+
+
+
+ if ((pdev->dbg_results.power_management__go1_reset_status & 0x01) == 0x00)
+ *pready = 0x01;
+ else
+ *pready = 0x00;
+ }
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_wait.c b/drivers/input/misc/vl53L1/src/vl53l1_wait.c
new file mode 100644
index 000000000000..a04854961bbb
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_wait.c
@@ -0,0 +1,627 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_ll_device.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_core.h"
+#include "vl53l1_fpga_core.h"
+#include "vl53l1_silicon_core.h"
+#include "vl53l1_wait.h"
+#include "vl53l1_register_settings.h"
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, \
+ fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_wait_for_boot_completion(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t fw_ready = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
+
+
+
+
+ status =
+ VL53L1_poll_for_boot_completion(
+ Dev,
+ VL53L1_BOOT_COMPLETION_POLLING_TIMEOUT_MS);
+
+ } else {
+
+
+
+
+ fw_ready = 0;
+ while (fw_ready == 0x00 && status == VL53L1_ERROR_NONE) {
+ status = VL53L1_is_boot_complete(
+ Dev,
+ &fw_ready);
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_WaitMs(
+ Dev,
+ VL53L1_POLLING_DELAY_MS);
+ }
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_wait_for_firmware_ready(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t fw_ready = 0;
+ uint8_t mode_start = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ mode_start =
+ pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICEMEASUREMENTMODE_MODE_MASK;
+
+
+
+
+
+
+
+ if ((mode_start == VL53L1_DEVICEMEASUREMENTMODE_TIMED) ||
+ (mode_start == VL53L1_DEVICEMEASUREMENTMODE_SINGLESHOT)) {
+
+ if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
+
+
+
+
+ status =
+ VL53L1_poll_for_firmware_ready(
+ Dev,
+ VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS);
+
+ } else {
+
+
+
+
+ fw_ready = 0;
+ while (fw_ready == 0x00 && status == VL53L1_ERROR_NONE) {
+ status = VL53L1_is_firmware_ready(
+ Dev,
+ &fw_ready);
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_WaitMs(
+ Dev,
+ VL53L1_POLLING_DELAY_MS);
+ }
+ }
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_wait_for_range_completion(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t data_ready = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
+
+
+
+
+ status =
+ VL53L1_poll_for_range_completion(
+ Dev,
+ VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS);
+
+ } else {
+
+
+
+
+ data_ready = 0;
+ while (data_ready == 0x00 && status == VL53L1_ERROR_NONE) {
+ status = VL53L1_is_new_data_ready(
+ Dev,
+ &data_ready);
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_WaitMs(
+ Dev,
+ VL53L1_POLLING_DELAY_MS);
+ }
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_wait_for_test_completion(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t data_ready = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
+
+
+
+
+ status =
+ VL53L1_poll_for_range_completion(
+ Dev,
+ VL53L1_TEST_COMPLETION_POLLING_TIMEOUT_MS);
+
+ } else {
+
+
+
+
+ data_ready = 0;
+ while (data_ready == 0x00 && status == VL53L1_ERROR_NONE) {
+ status = VL53L1_is_new_data_ready(
+ Dev,
+ &data_ready);
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_WaitMs(
+ Dev,
+ VL53L1_POLLING_DELAY_MS);
+ }
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+VL53L1_Error VL53L1_is_boot_complete(
+ VL53L1_DEV Dev,
+ uint8_t *pready)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t firmware__system_status = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_RdByte(
+ Dev,
+ VL53L1_FIRMWARE__SYSTEM_STATUS,
+ &firmware__system_status);
+
+
+
+
+
+
+ if ((firmware__system_status & 0x01) == 0x01) {
+ *pready = 0x01;
+ VL53L1_init_ll_driver_state(
+ Dev,
+ VL53L1_DEVICESTATE_SW_STANDBY);
+ } else {
+ *pready = 0x00;
+ VL53L1_init_ll_driver_state(
+ Dev,
+ VL53L1_DEVICESTATE_FW_COLDBOOT);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_is_firmware_ready(
+ VL53L1_DEV Dev,
+ uint8_t *pready)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->fpga_system > 0)
+ status = VL53L1_is_firmware_ready_fpga(
+ Dev,
+ pready);
+ else
+ status = VL53L1_is_firmware_ready_silicon(
+ Dev,
+ pready);
+
+ pdev->fw_ready = *pready;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_is_new_data_ready(
+ VL53L1_DEV Dev,
+ uint8_t *pready)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t gpio__mux_active_high_hv = 0;
+ uint8_t gpio__tio_hv_status = 0;
+ uint8_t interrupt_ready = 0;
+
+ LOG_FUNCTION_START("");
+
+ gpio__mux_active_high_hv =
+ pdev->stat_cfg.gpio_hv_mux__ctrl &
+ VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_MASK;
+
+ if (gpio__mux_active_high_hv == VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_HIGH)
+ interrupt_ready = 0x01;
+ else
+ interrupt_ready = 0x00;
+
+
+
+
+ status = VL53L1_RdByte(
+ Dev,
+ VL53L1_GPIO__TIO_HV_STATUS,
+ &gpio__tio_hv_status);
+
+
+
+
+ if ((gpio__tio_hv_status & 0x01) == interrupt_ready)
+ *pready = 0x01;
+ else
+ *pready = 0x00;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+VL53L1_Error VL53L1_poll_for_boot_completion(
+ VL53L1_DEV Dev,
+ uint32_t timeout_ms)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+ status = VL53L1_WaitUs(
+ Dev,
+ VL53L1_FIRMWARE_BOOT_TIME_US);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WaitValueMaskEx(
+ Dev,
+ timeout_ms,
+ VL53L1_FIRMWARE__SYSTEM_STATUS,
+ 0x01,
+ 0x01,
+ VL53L1_POLLING_DELAY_MS);
+
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_init_ll_driver_state(Dev, VL53L1_DEVICESTATE_SW_STANDBY);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_poll_for_firmware_ready(
+ VL53L1_DEV Dev,
+ uint32_t timeout_ms)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint32_t start_time_ms = 0;
+ uint32_t current_time_ms = 0;
+ int32_t poll_delay_ms = VL53L1_POLLING_DELAY_MS;
+ uint8_t fw_ready = 0;
+
+
+
+
+ VL53L1_GetTickCount(&start_time_ms);
+
+ pdev->fw_ready_poll_duration_ms = 0;
+
+
+
+
+ while ((status == VL53L1_ERROR_NONE) &&
+ (pdev->fw_ready_poll_duration_ms < timeout_ms) &&
+ (fw_ready == 0)) {
+
+ status = VL53L1_is_firmware_ready(
+ Dev,
+ &fw_ready);
+
+ if (status == VL53L1_ERROR_NONE &&
+ fw_ready == 0 &&
+ poll_delay_ms > 0) {
+ status = VL53L1_WaitMs(
+ Dev,
+ poll_delay_ms);
+ }
+
+
+
+
+
+
+ VL53L1_GetTickCount(¤t_time_ms);
+
+ pdev->fw_ready_poll_duration_ms =
+ current_time_ms - start_time_ms;
+ }
+
+ if (fw_ready == 0 && status == VL53L1_ERROR_NONE)
+ status = VL53L1_ERROR_TIME_OUT;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_poll_for_range_completion(
+ VL53L1_DEV Dev,
+ uint32_t timeout_ms)
+{
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t gpio__mux_active_high_hv = 0;
+ uint8_t interrupt_ready = 0;
+
+ LOG_FUNCTION_START("");
+
+ gpio__mux_active_high_hv =
+ pdev->stat_cfg.gpio_hv_mux__ctrl &
+ VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_MASK;
+
+ if (gpio__mux_active_high_hv == VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_HIGH)
+ interrupt_ready = 0x01;
+ else
+ interrupt_ready = 0x00;
+
+ status =
+ VL53L1_WaitValueMaskEx(
+ Dev,
+ timeout_ms,
+ VL53L1_GPIO__TIO_HV_STATUS,
+ interrupt_ready,
+ 0x01,
+ VL53L1_POLLING_DELAY_MS);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
diff --git a/drivers/input/misc/vl53L1/src/vl53l1_zone_presets.c b/drivers/input/misc/vl53L1/src/vl53l1_zone_presets.c
new file mode 100644
index 000000000000..de75b9211b2c
--- /dev/null
+++ b/drivers/input/misc/vl53L1/src/vl53l1_zone_presets.c
@@ -0,0 +1,253 @@
+
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* This file is part of VL53L1 Core and is dual licensed, either 'STMicroelectronics
+* Proprietary license'
+* or 'BSD 3-clause "New" or "Revised" License' , at your option.
+*
+********************************************************************************
+*
+* 'STMicroelectronics Proprietary license'
+*
+********************************************************************************
+*
+* License terms: STMicroelectronics Proprietary in accordance with licensing
+* terms at www.st.com/sla0044
+*
+* STMicroelectronics confidential
+* Reproduction and Communication of this document is strictly prohibited unless
+* specifically authorized in writing by STMicroelectronics.
+*
+*
+********************************************************************************
+*
+* Alternatively, VL53L1 Core may be distributed under the terms of
+* 'BSD 3-clause "New" or "Revised" License', in which case the following
+* provisions apply instead of the ones
+* mentioned above :
+*
+********************************************************************************
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*
+********************************************************************************
+*
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_ll_device.h"
+#include "vl53l1_platform_log.h"
+#include "vl53l1_zone_presets.h"
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_init_zone_config_structure(
+ uint8_t x_off,
+ uint8_t x_inc,
+ uint8_t x_zones,
+ uint8_t y_off,
+ uint8_t y_inc,
+ uint8_t y_zones,
+ uint8_t width,
+ uint8_t height,
+ VL53L1_zone_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t x = 0;
+ uint8_t y = 0;
+ uint16_t i = 0;
+
+ LOG_FUNCTION_START("");
+
+ pdata->max_zones = VL53L1_MAX_USER_ZONES;
+
+ i = 0;
+
+ for (x = 0 ; x < x_zones ; x++) {
+ for (y = 0 ; y < y_zones ; y++) {
+
+ if (i < VL53L1_MAX_USER_ZONES) {
+
+ pdata->active_zones = (uint8_t)i;
+ pdata->user_zones[i].height = height;
+ pdata->user_zones[i].width = width;
+ pdata->user_zones[i].x_centre = x_off + (x * x_inc);
+ pdata->user_zones[i].y_centre = y_off + (y * y_inc);
+ }
+
+ i++;
+ }
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status = VL53L1_init_zone_config_histogram_bins(pdata);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_zone_preset_xtalk_planar(
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ pgeneral->global_config__stream_divider = 0x05;
+
+
+
+ pzone_cfg->active_zones = 0x04;
+
+ pzone_cfg->user_zones[0].height = 15;
+ pzone_cfg->user_zones[0].width = 7;
+ pzone_cfg->user_zones[0].x_centre = 4;
+ pzone_cfg->user_zones[0].y_centre = 8;
+
+ pzone_cfg->user_zones[1].height = 15;
+ pzone_cfg->user_zones[1].width = 7;
+ pzone_cfg->user_zones[1].x_centre = 12;
+ pzone_cfg->user_zones[1].y_centre = 8;
+
+ pzone_cfg->user_zones[2].height = 7;
+ pzone_cfg->user_zones[2].width = 15;
+ pzone_cfg->user_zones[2].x_centre = 8;
+ pzone_cfg->user_zones[2].y_centre = 4;
+
+ pzone_cfg->user_zones[3].height = 7;
+ pzone_cfg->user_zones[3].width = 15;
+ pzone_cfg->user_zones[3].x_centre = 8;
+ pzone_cfg->user_zones[3].y_centre = 12;
+
+
+
+
+ pzone_cfg->user_zones[4].height = 15;
+ pzone_cfg->user_zones[4].width = 15;
+ pzone_cfg->user_zones[4].x_centre = 8;
+ pzone_cfg->user_zones[4].y_centre = 8;
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status = VL53L1_init_zone_config_histogram_bins(pzone_cfg);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_init_zone_config_histogram_bins(
+ VL53L1_zone_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t i;
+
+ LOG_FUNCTION_START("");
+
+ for (i = 0; i < pdata->max_zones; i++)
+ pdata->bin_config[i] = VL53L1_ZONECONFIG_BINCONFIG__LOWAMB;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
diff --git a/drivers/input/misc/vl53L1/stmvl53l1-i2c.h b/drivers/input/misc/vl53L1/stmvl53l1-i2c.h
new file mode 100644
index 000000000000..e68ca420783d
--- /dev/null
+++ b/drivers/input/misc/vl53L1/stmvl53l1-i2c.h
@@ -0,0 +1,109 @@
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+* License terms: BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/** @file stmvl53l1-i2c.h
+ * Linux kernel i2c/cci wrapper for ST VL53L1 sensor i2c interface
+ **/
+
+#ifndef STMVL53L1_I2C_H
+#define STMVL53L1_I2C_H
+#include
+#include "stmvl53l1.h"
+
+struct i2c_data {
+ struct i2c_client *client;
+ /** back link to driver for interrupt and clean-up */
+ struct stmvl53l1_data *vl53l1_data;
+
+ /* reference counter */
+ struct kref ref;
+
+ /*!< if null no regulator use for power ctrl */
+ struct regulator *vdd;
+
+ /*!< power enable gpio number
+ *
+ * if -1 no gpio if vdd not avl pwr is not controllable
+ */
+ int pwren_gpio;
+
+ /*!< xsdn reset (low active) gpio number to device
+ *
+ * -1 mean none assume no "resetable"
+ */
+ int xsdn_gpio;
+
+ /*!< intr gpio number to device
+ *
+ * intr is active/low negative edge by default
+ *
+ * -1 mean none assume use polling
+ * @warning if the dev tree and intr gpio is require please adapt code
+ */
+ int intr_gpio;
+
+ /*!< device boot i2c register address
+ *
+ * boot_reg is the value of device i2c address after it is bring out
+ * of reset.
+ */
+ int boot_reg;
+
+ /*!< is set if above irq gpio got acquired */
+ struct i2d_data_flags_t {
+ unsigned pwr_owned:1; /*!< set if pwren gpio is owned*/
+ unsigned xsdn_owned:1; /*!< set if sxdn gpio is owned*/
+ unsigned intr_owned:1; /*!< set if intr gpio is owned*/
+ unsigned intr_started:1; /*!< set if irq is hanlde */
+ } io_flag;
+
+ /** the irq vectore assigned to gpio
+ * -1 if no irq hanled
+ */
+ int irq;
+
+ struct msgtctrl_t {
+ unsigned unhandled_irq_vec:1;
+ } msg_flag;
+};
+
+int stmvl53l1_init_i2c(void);
+void __exit stmvl53l1_exit_i2c(void *);
+int stmvl53l1_power_up_i2c(void *);
+int stmvl53l1_power_down_i2c(void *);
+int stmvl53l1_reset_release_i2c(void *);
+int stmvl53l1_reset_hold_i2c(void *);
+void stmvl53l1_clean_up_i2c(void);
+int stmvl53l1_start_intr(void *object, int *poll_mode);
+void *stmvl53l1_get(void *);
+void stmvl53l1_put(void *);
+
+#endif /* STMVL53L1_I2C_H */
diff --git a/drivers/input/misc/vl53L1/stmvl53l1.h b/drivers/input/misc/vl53L1/stmvl53l1.h
new file mode 100644
index 000000000000..04cba5d04617
--- /dev/null
+++ b/drivers/input/misc/vl53L1/stmvl53l1.h
@@ -0,0 +1,379 @@
+/*
+* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+*
+*License terms : BSD 3-clause "New" or "Revised" License.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/**
+ * @file stmvl53l1.h header for vl53l1 sensor driver
+ */
+#ifndef STMVL53L1_H
+#define STMVL53L1_H
+
+#include
+#include
+#include
+#include
+#include
+
+#include "vl53l1_api.h"
+
+/**
+ * IPP adapt
+ */
+#ifdef DEBUG
+# define IPP_PRINT(...) printk(__VA_ARGS__)
+#else
+# define IPP_PRINT(...) (void)0
+#endif
+
+#include "stmvl53l1_ipp.h"
+#include "stmvl53l1_if.h"
+
+/**
+ * Configure the Netlink-id use
+ */
+#define STMVL531_CFG_NETLINK_USER 23
+
+#define STMVL53L1_MAX_CCI_XFER_SZ 256
+#define STMVL53L1_DRV_NAME "stmvl53l1"
+
+/**
+ * configure usage of regulator device from device tree info
+ * to enable/disable sensor power
+ * see module-i2c or module-cci file
+ */
+/* define CFG_STMVL53L1_HAVE_REGULATOR */
+
+#define DRIVER_VERSION "8.0.0_b4.1._1268"
+
+/** @ingroup vl53l1_config
+ * @{
+ */
+/**
+ * Configure max number of device the driver can support
+ */
+#define STMVL53L1_CFG_MAX_DEV 2
+/** @ingroup vl53l1_mod_dbg
+ * @{
+ */
+#if 1
+#define DEBUG 1
+#endif
+#if 0
+#define FORCE_CONSOLE_DEBUG
+#endif
+
+extern int stmvl53l1_enable_debug;
+
+#ifdef DEBUG
+# ifdef FORCE_CONSOLE_DEBUG
+#define vl53l1_dbgmsg(str, ...) do { \
+ if (stmvl53l1_enable_debug) \
+ pr_info("%s: " str, __func__, ##__VA_ARGS__); \
+ } while (0)
+# else
+#define vl53l1_dbgmsg(str, ...) do { \
+ if (stmvl53l1_enable_debug) \
+ pr_debug("%s: " str, __func__, ##__VA_ARGS__); \
+ } while (0)
+# endif
+#else
+# define vl53l1_dbgmsg(...) (void)0
+#endif
+
+/**
+ * set to 0 1 activate or not debug from work (data interrupt/polling)
+ */
+#define WORK_DEBUG 0
+#if WORK_DEBUG
+# define work_dbg(msg, ...)\
+ printk("[D WK53L1] :" msg "\n", ##__VA_ARGS__)
+#else
+# define work_dbg(...) (void)0
+#endif
+
+#define vl53l1_info(str, args...) \
+ pr_info("%s: " str, __func__, ##args)
+
+#define vl53l1_errmsg(str, args...) \
+ pr_err("%s: " str, __func__, ##args)
+
+#define vl53l1_wanrmsg(str, args...) \
+ pr_warn("%s: " str, __func__, ##args)
+
+/* turn off poll log if not defined */
+#ifndef STMVL53L1_LOG_POLL_TIMING
+# define STMVL53L1_LOG_POLL_TIMING 0
+#endif
+/* turn off cci log timing if not defined */
+#ifndef STMVL53L1_LOG_CCI_TIMING
+# define STMVL53L1_LOG_CCI_TIMING 0
+#endif
+
+/**@} */ /* ingroup mod_dbg*/
+
+#include
+#include
+#include
+
+/** if set to 1 enable ipp execution timing (if debug enabled)
+ * @ingroup vl53l1_mod_dbg
+ */
+#define IPP_LOG_TIMING 1
+
+struct ipp_data_t {
+ struct ipp_work_t work;
+ struct ipp_work_t work_out;
+ int test_n;
+ int buzy; /*!< buzy state 0 is idle
+ * any other value do not try to use (state value defined in source)
+ */
+ int waited_xfer_id;
+ /*!< when buzy is set that is the id we are expecting
+ * note that value 0 is reserved and stand for "not waiting"
+ * as such never id 0 will be in any round trip exchange
+ * it's ok for daemon to use 0 in "ping" when it identify himself
+ */
+ int status; /** if that is not 0 do not look at out work data */
+ wait_queue_head_t waitq;
+ /*!< ipp caller are put in that queue wait while job is posted to user
+ * @warning ipp and dev mutex will be released before waiting
+ * see @ref ipp_abort
+ */
+#if IPP_LOG_TIMING
+ struct timeval start_tv, stop_tv;
+#endif
+};
+
+struct stmvl53l1_waiters {
+ struct list_head list;
+ pid_t pid;
+};
+
+/*
+ * driver data structs
+ */
+struct stmvl53l1_data {
+ int id; /*!< multiple device id 0 based*/
+ char name[64]; /*!< misc device name */
+ int32_t hw_rev; /*!< hardware revision number*/
+
+ VL53L1_DevData_t stdev; /*!