Add stm laser modules

1. Add vl53L0
2. Add vl53L1

Change-Id: Ib98cbddb95f1ec2ba2aaee79e215d0a5e0b7ffb4
Signed-off-by: guocx4 <guocx4@lenovo.com>
Reviewed-on: https://gerrit.mot.com/1160804
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Haichao Li <liuhc3@motorola.com>
Reviewed-by: Dawei Wang <wangdw10@motorola.com>
Reviewed-by: Zilong Zhang <zhangzl7@lenovo.com>
Reviewed-by: Zhenxin Xi <xizx@motorola.com>
Submit-Approved: Jira Key
This commit is contained in:
guocx4 2018-04-10 17:22:05 +08:00 • committed by Chuanxin Guo
commit f90880f2f8
108 changed files with 101153 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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_ */

View file

@ -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

View file

@ -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_ */

File diff suppressed because it is too large Load diff

View file

@ -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_ */

View file

@ -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_ */

View file

@ -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_ */

View file

@ -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_ */

View file

@ -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

View file

@ -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)
/*!<Identifies the pre-range vcsel period. */
#define VL53L0_VCSEL_PERIOD_FINAL_RANGE ((VL53L0_VcselPeriod) 1)
/*!<Identifies the final range vcsel period. */
/** @} VL53L0_define_VcselPeriod_group */
/** @defgroup VL53L0_define_SchedulerSequence_group Defines the steps
* carried out by the scheduler during a range measurement.
* @{
* Defines the states of all the steps in the scheduler
* i.e. enabled/disabled.
*/
typedef struct {
uint8_t TccOn; /*!<Reports if Target Centre Check On */
uint8_t MsrcOn; /*!<Reports if MSRC On */
uint8_t DssOn; /*!<Reports if DSS On */
uint8_t PreRangeOn; /*!<Reports if Pre-Range On */
uint8_t FinalRangeOn; /*!<Reports if Final-Range On */
} VL53L0_SchedulerSequenceSteps_t;
/** @} VL53L0_define_SchedulerSequence_group */
/** @defgroup VL53L0_define_SequenceStepId_group Defines the Polarity
* of the Interrupt
* Defines the the sequence steps performed during ranging..
* @{
*/
typedef uint8_t VL53L0_SequenceStepId;
#define VL53L0_SEQUENCESTEP_TCC ((VL53L0_VcselPeriod) 0)
/*!<Target CentreCheck identifier. */
#define VL53L0_SEQUENCESTEP_DSS ((VL53L0_VcselPeriod) 1)
/*!<Dynamic Spad Selection function Identifier. */
#define VL53L0_SEQUENCESTEP_MSRC ((VL53L0_VcselPeriod) 2)
/*!<Minimum Signal Rate Check function Identifier. */
#define VL53L0_SEQUENCESTEP_PRE_RANGE ((VL53L0_VcselPeriod) 3)
/*!<Pre-Range check Identifier. */
#define VL53L0_SEQUENCESTEP_FINAL_RANGE ((VL53L0_VcselPeriod) 4)
/*!<Final Range Check Identifier. */
#define VL53L0_SEQUENCESTEP_NUMBER_OF_CHECKS 5
/*!<Number of Sequence Step Managed by the API. */
/** @} VL53L0_define_SequenceStepId_group */
/* MACRO Definitions */
/** @defgroup VL53L0_define_GeneralMacro_group General Macro Defines
* General Macro Defines
* @{
*/
/* Defines */
#define VL53L0_SETPARAMETERFIELD(Dev, field, value) \
PALDevDataSet(Dev, CurrentParameters.field, value)
#define VL53L0_GETPARAMETERFIELD(Dev, field, variable) \
variable = PALDevDataGet(Dev, CurrentParameters).field
#define VL53L0_SETARRAYPARAMETERFIELD(Dev, field, index, value) \
PALDevDataSet(Dev, CurrentParameters.field[index], value)
#define VL53L0_GETARRAYPARAMETERFIELD(Dev, field, index, variable) \
variable = PALDevDataGet(Dev, CurrentParameters).field[index]
#define VL53L0_SETDEVICESPECIFICPARAMETER(Dev, field, value) \
PALDevDataSet(Dev, DeviceSpecificParameters.field, value)
#define VL53L0_GETDEVICESPECIFICPARAMETER(Dev, field) \
PALDevDataGet(Dev, DeviceSpecificParameters).field
#define VL53L0_FIXPOINT1616TOFIXPOINT97(Value) \
(uint16_t)((Value>>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_ */

View file

@ -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_ */

View file

@ -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_ */

View file

@ -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 <linux/delay.h>
#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_ */

View file

@ -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 <linux/string.h>
/* 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 <linux/module.h>
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_ */

View file

@ -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

View file

@ -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_ */

View file

@ -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 <linux/types.h>
#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_ */

File diff suppressed because it is too large Load diff

View file

@ -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;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -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 <stdlib.h>
#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;
}

View file

@ -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 <stdlib.h>
#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__)

View file

@ -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 <stdlib.h>
#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;
}

View file

@ -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 <linux/i2c.h>
#include <linux/module.h>
#include <linux/delay.h>
#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;
}

View file

@ -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;
}

View file

@ -0,0 +1,150 @@
/*
* vl53l0_port_i2c.c
*
* Created on: July, 2015
* Author: Teresa Tao
*/
#include <linux/i2c.h>
#include <linux/module.h>
#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;
}

View file

@ -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;
}
*/

View file

@ -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 <linux/types.h>
#include <soc/qcom/camera2.h>
#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 */

View file

@ -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 <linux/types.h>
#include <soc/qcom/camera2.h>
#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 */

View file

@ -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 <linux/types.h>
#include <linux/mutex.h>
#include <linux/workqueue.h>
#include <linux/miscdevice.h>
#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 */

View file

@ -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 <linux/uaccess.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/mutex.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/gpio.h>
#include <linux/input.h>
#include <linux/miscdevice.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/time.h>
#include <linux/platform_device.h>
/*
* power specific includes
*/
#include <linux/pwm.h>
#include <linux/regulator/consumer.h>
#include <linux/pinctrl/consumer.h>
#include <linux/clk.h>
#include <linux/of_gpio.h>
/*
* 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");
}

View file

@ -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 <linux/uaccess.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/mutex.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/gpio.h>
#include <linux/input.h>
#include <linux/miscdevice.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/time.h>
#include <linux/platform_device.h>
/*
* power specific includes
*/
#include <linux/pwm.h>
#include <linux/regulator/consumer.h>
#include <linux/pinctrl/consumer.h>
#include <linux/clk.h>
#include <linux/of_gpio.h>
/*
* 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");
}

File diff suppressed because it is too large Load diff

View file

@ -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

View file

@ -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

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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

View file

@ -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)
/*!<VHV. */
#define VL53L1_SEQUENCESTEP_PHASECAL ((VL53L1_SequenceStepId) 1)
/*!<Phase Calibration. */
#define VL53L1_SEQUENCESTEP_REFPHASE ((VL53L1_SequenceStepId) 2)
/*!<Reference Phase. */
#define VL53L1_SEQUENCESTEP_DSS1 ((VL53L1_SequenceStepId) 3)
/*!<DSS1. */
#define VL53L1_SEQUENCESTEP_DSS2 ((VL53L1_SequenceStepId) 4)
/*!<DSS2. */
#define VL53L1_SEQUENCESTEP_MM1 ((VL53L1_SequenceStepId) 5)
/*!<Mode Mitigation 1. */
#define VL53L1_SEQUENCESTEP_MM2 ((VL53L1_SequenceStepId) 6)
/*!<Mode Mitigation 2. */
#define VL53L1_SEQUENCESTEP_RANGE ((VL53L1_SequenceStepId) 7)
/*!<Final Range step. */
#define VL53L1_SEQUENCESTEP_NUMBER_OF_ITEMS 8
/*!<Number of Sequence Step Managed by the API. */
/** @} VL53L1_define_SequenceStepId_group */
/** @defgroup VL53L1_define_RangeStatus_group Defines the Range Status
* @{
*/
#define VL53L1_RANGESTATUS_RANGE_VALID 0
/*!<The Range is valid. */
#define VL53L1_RANGESTATUS_SIGMA_FAIL 1
/*!<Sigma Fail. */
#define VL53L1_RANGESTATUS_SIGNAL_FAIL 2
/*!<Signal fail. */
#define VL53L1_RANGESTATUS_MIN_RANGE_FAIL 3
/*!<Min Range fail. */
#define VL53L1_RANGESTATUS_PHASE_FAIL 4
/*!<Phase fail. */
#define VL53L1_RANGESTATUS_HARDWARE_FAIL 5
/*!<Hardware fail. */
#define VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK 6
/*!<The Range is valid but the wraparound check has not been done. */
#define VL53L1_RANGESTATUS_NONE 255
/*!<No Update. */
/** @} VL53L1_define_RangeStatus_group */
/** @brief Contains the Internal data of the Bare Driver
*/
typedef struct {
VL53L1_LLDriverData_t LLData;
/*!< Low Level Driver data structure */
VL53L1_LLDriverResults_t llresults;
/*!< Low Level Driver data structure */
VL53L1_State PalState; /* Store the pal state */
VL53L1_DeviceParameters_t CurrentParameters;
/*!< Current Device Parameter */
} VL53L1_DevData_t;
/* MACRO Definitions */
/** @defgroup VL53L1_define_GeneralMacro_group General Macro Defines
* General Macro Defines
* @{
*/
/* Defines */
#define VL53L1_SETPARAMETERFIELD(Dev, field, value) \
(PALDevDataSet(Dev, CurrentParameters.field, value))
#define VL53L1_GETPARAMETERFIELD(Dev, field, variable) \
(variable = PALDevDataGet(Dev, CurrentParameters).field)
#define VL53L1_SETARRAYPARAMETERFIELD(Dev, field, index, value) \
(PALDevDataSet(Dev, CurrentParameters.field[index], value))
#define VL53L1_GETARRAYPARAMETERFIELD(Dev, field, index, variable) \
(variable = PALDevDataGet(Dev, CurrentParameters).field[index])
#define VL53L1_SETDEVICESPECIFICPARAMETER(Dev, field, value) \
(PALDevDataSet(Dev, DeviceSpecificParameters.field, value))
#define VL53L1_GETDEVICESPECIFICPARAMETER(Dev, field) \
(PALDevDataGet(Dev, DeviceSpecificParameters).field)
#define VL53L1_FIXPOINT1616TOFIXPOINT72(Value) \
(uint16_t)((Value>>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_ */

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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

View file

@ -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

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -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;
}

File diff suppressed because it is too large Load diff

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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 <stdio.h>
#include <stdlib.h>
#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;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -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;
}

View file

@ -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(&current_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;
}

View file

@ -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;
}

View file

@ -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 <linux/types.h>
#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 */

View file

@ -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 <linux/types.h>
#include <linux/mutex.h>
#include <linux/workqueue.h>
#include <linux/miscdevice.h>
#include <linux/wait.h>
#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 <net/sock.h>
#include <linux/netlink.h>
#include <linux/wait.h>
/** 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; /*!<embed ST VL53L0 Dev data as "stdev" */
void *client_object; /*!< cci or i2c moduel i/f speficic ptr */
bool is_device_remove; /*!< true when device has been remove */
struct mutex work_mutex; /*!< main dev mutex/lock */;
struct delayed_work dwork;
/*!< work for pseudo irq polling check */
struct input_dev *input_dev_ps;
/*!< input device used for sending event */
/* misc device */
struct miscdevice miscdev;
/* first irq has no valid data, so avoid to update data on first one */
int is_first_irq;
/* control data */
int poll_mode; /*!< use poll even if interrupt line present*/
int poll_delay_ms; /*!< rescheduled time use in poll mode */
int enable_sensor; /*!< actual device enabled state */
struct timeval start_tv;/*!< stream start time */
int enable_debug;
bool allow_hidden_start_stop; /*!< allow stop/start sequence in bare */
/* Custom values set by app */
int preset_mode; /*!< preset working mode of the device */
uint32_t timing_budget; /*!< Timing Budget */
int distance_mode; /*!< distance mode of the device */
int crosstalk_enable; /*!< is crosstalk compensation is enable */
int output_mode; /*!< output mode of the device */
bool force_device_on_en;/*!< keep device active when stopped */
int sar_mode; /*!< is sar mode enable/disabled */
int cam_mode; /*!< is camera mode enable/disabled */
VL53L1_Error last_error;/*!< last device internal error */
/* PS parameters */
/* Calibration parameters */
bool is_calibrating; /*!< active during calibration phases */
uint16_t xtalk_offset; /*!< crosstalk compensation plane offset kcps */
int16_t xtalk_x; /*!< crosstalk compensation x plane gradient kcps */
int16_t xtalk_y; /*!< crosstalk compensation y plane gradient kcps */
int16_t inner_offset; /*!< inner offset mm */
int16_t outer_offset; /*!< outer offset mm */
/* Range Data and stat */
struct range_t {
uint32_t cnt;
uint32_t intr;
int poll_cnt;
uint32_t err_cnt; /* on actual measurement */
uint32_t err_tot; /* from start */
struct timeval start_tv;
struct timeval comp_tv;
VL53L1_MultiRangingData_t multi_range_data;
VL53L1_MultiRangingData_t tmp_range_data;
/* non mode 1 for data agregation */
} meas;
/* workqueue use to fire flush event */
uint32_t flushCount;
int flush_todo_counter;
/* Device parameters */
/* Polling thread */
/* Wait Queue on which the poll thread blocks */
/* Manage blocking ioctls */
struct list_head simple_data_reader_list;
struct list_head mz_data_reader_list;
wait_queue_head_t waiter_for_data;
bool is_data_valid;
/* control when using delay is acceptable */
bool is_delay_allowed;
/* maintain reset state */
int reset_state;
/* Recent interrupt status */
/* roi */
VL53L1_RoiConfig_t roi_cfg;
/* autonomous config */
uint32_t auto_pollingTimeInMs;
VL53L1_DetectionConfig_t auto_config;
/* autonomous config for camera */
uint32_t auto_pollingTimeInMs_cam;
VL53L1_DetectionConfig_t auto_config_cam;
int sysfs_base;
/* Debug */
struct ipp_data_t ipp;
#if IPP_LOG_TIMING
# define stmvl531_ipp_tim_stop(data)\
do_gettimeofday(&data->ipp.stop_tv)
# define stmvl531_ipp_tim_start(data)\
do_gettimeofday(&data->ipp.start_tv)
# define stmvl531_ipp_time(data)\
stmvl53l1_tv_dif(&data->ipp.start_tv, &data->ipp.stop_tv)
# define stmvl531_ipp_stat(data, fmt, ...)\
vl53l1_dbgmsg("IPPSTAT " fmt "\n", ##__VA_ARGS__)
#else
# define stmvl531_ipp_tim_stop(data) (void)0
# define stmvl531_ipp_tim_start(data) (void)0
# define stmvl531_ipp_stat(...) (void)0
#endif
};
/**
* timeval diff in us
*
* @param pstart_tv
* @param pstop_tv
*/
long stmvl53l1_tv_dif(struct timeval *pstart_tv, struct timeval *pstop_tv);
/**
* The device table list table is update as device get added
* we do not support adding removing device mutiple time !
* use for clean "unload" purpose
*/
extern struct stmvl53l1_data *stmvl53l1_dev_table[];
int stmvl53l1_setup(struct stmvl53l1_data *data);
void stmvl53l1_cleanup(struct stmvl53l1_data *data);
int stmvl53l1_intr_handler(struct stmvl53l1_data *data);
int stmvl53l1_sysfs_laser(struct stmvl53l1_data *data, bool create);
/**
* request ipp to abort or stop
*
* require dev work_mutex held
*
* @warning because the "waiting" work can't be aborted we must wake it up
* it will happen and at some later time not earlier than release of lock
* if after lock release we have a new request to start the race may not be
* handled correctly
*
* @param data the device
* @return 0 if no ipp got canceled, @warning this is maybe not grant we
* can't re-sched "dev work" and re-run the worker back
*/
int stmvl53l1_ipp_stop(struct stmvl53l1_data *data);
int stmvl53l1_ipp_do(struct stmvl53l1_data *data, struct ipp_work_t *work_in,
struct ipp_work_t *work_out);
/**
* per device netlink init
* @param data
* @return
*/
int stmvl53l1_ipp_setup(struct stmvl53l1_data *data);
/**
* per device ipp netlink cleaning
* @param data
* @return
*/
void stmvl53l1_ipp_cleanup(struct stmvl53l1_data *data);
/**
* Module init for netlink
* @return 0 on success
*/
int stmvl53l1_ipp_init(void);
/**
* Module exit for netlink
* @return 0 on success
*/
void __exit stmvl53l1_ipp_exit(void);
/**
* enable and start ipp exhange
* @param n_dev number of device to run on
* @param data dev struct
* @return 0 on success
*/
int stmvl53l1_ipp_enable(int n_dev, struct stmvl53l1_data *data);
/*
* function pointer structs
*/
#endif /* STMVL53L1_H */

View file

@ -0,0 +1,366 @@
/*
* 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.c vl53l1 linux native i2c interface
*
*/
#include "stmvl53l1.h"
#include "stmvl53l1-i2c.h"
#include <linux/i2c.h>
#if STMVL53L1_LOG_POLL_TIMING
/**
* helper to elapse time in polling
* @param ptv pointer to start time_val
*/
# define poll_timing_log(ptv) \
vl53l1_dbgmsg("poll in %d us\n", tv_elapsed_us(ptv))
#else
# define poll_timing_log(...) (void)0
#endif
#if STMVL53L1_LOG_CCI_TIMING
/**
* compute elapsed time in in micro sec based on do_gettimeofday
* @param tv pointer to start time_val
* @return time elapsed in micro seconde
*/
/**
* compute elapsed time in in micro sec based on do_gettimeofday
* @param tv pointer to start time_val
* @return time elapsed in micro seconde
*/
static uint32_t tv_elapsed_us(struct timeval *tv)
{
struct timeval now;
do_gettimeofday(&now);
return (now.tv_sec - tv->tv_sec)*1000000 + (now.tv_usec - tv->tv_usec);
}
# define cci_access_var struct timeval cci_log_start_tv
# define cci_access_start()\
do_gettimeofday(&cci_log_start_tv)
# define cci_access_over(fmt, ...) \
vl53l1_dbgmsg("cci_timing %d us" fmt "\n", \
tv_elapsed_us(&cci_log_start_tv), ##__VA_ARGS__)
#else
# define cci_access_var
# define cci_access_start(...) (void)0
# define cci_access_over(...) (void)0
#endif
#ifdef STMVL53L1_DEBUG_I2C
# define i2c_debug(fmt, ...) vl53l1_dbgmsg(fmt, ##__VA_ARGS__)
#else
# define i2c_debug(fmt, ...) (void)0
#endif
VL53L1_Error VL53L1_GetTickCount(uint32_t *ptime_ms)
{
(void)ptime_ms;
BUG_ON(1);
}
/**
* compute elapsed time in in milli sec based on do_gettimeofday
* @param tv pointer to start time_val
* @return time elapsed in milli seconde
*/
static uint32_t tv_elapsed_ms(struct timeval *tv)
{
struct timeval now;
do_gettimeofday(&now);
return (now.tv_sec - tv->tv_sec) * 1000 +
(now.tv_usec - tv->tv_usec) / 1000;
}
static int cci_write(struct stmvl53l1_data *dev, int index,
uint8_t *data, uint16_t len){
uint8_t buffer[STMVL53L1_MAX_CCI_XFER_SZ+2];
struct i2c_msg msg;
struct i2c_data *i2c_client_obj =
(struct i2c_data *) dev->client_object;
struct i2c_client *client =
(struct i2c_client *) i2c_client_obj->client;
int rc;
cci_access_var;
if (len > STMVL53L1_MAX_CCI_XFER_SZ || len == 0) {
vl53l1_errmsg("invalid len %d\n", len);
return -1;
}
cci_access_start();
/* build up little endian index in buffer */
buffer[0] = (index >> 8) & 0xFF;
buffer[1] = (index >> 0) & 0xFF;
/* copy write data to buffer after index */
memcpy(buffer+2, data, len);
/* set i2c msg */
msg.addr = client->addr;
msg.flags = client->flags;
msg.buf = buffer;
msg.len = len+2;
rc = i2c_transfer(client->adapter, &msg, 1);
if (rc != 1) {
vl53l1_errmsg("wr i2c_transfer err:%d, index 0x%x len %d\n",
rc, index, len);
}
cci_access_over("rd status %d long %d ", rc != 1, len);
return rc != 1;
}
static int cci_read(struct stmvl53l1_data *dev, int index,
uint8_t *data, uint16_t len)
{
uint8_t buffer[2];
struct i2c_msg msg[2];
struct i2c_data *i2c_client_obj =
(struct i2c_data *) dev->client_object;
struct i2c_client *client =
(struct i2c_client *) i2c_client_obj->client;
int rc;
cci_access_var;
if (len > STMVL53L1_MAX_CCI_XFER_SZ || len == 0) {
vl53l1_errmsg("invalid len %d\n", len);
return -1;
}
cci_access_start();
/* build up little endian index in buffer */
buffer[0] = (index >> 8) & 0xFF;
buffer[1] = (index >> 0) & 0xFF;
msg[0].addr = client->addr;
msg[0].flags = client->flags;/* Write */
msg[0].buf = buffer;
msg[0].len = 2;
/* read part of the i2c transaction */
msg[1].addr = client->addr;
msg[1].flags = I2C_M_RD|client->flags;
msg[1].buf = data;
msg[1].len = len;
rc = i2c_transfer(client->adapter, msg, 2);
if (rc != 2) {
pr_err("%s: i2c_transfer :%d, @%x index 0x%x len %d\n",
__func__, rc, client->addr, index, len);
}
cci_access_over(" wr len %d status %d", rc != 2, len);
return rc != 2;
}
VL53L1_Error VL53L1_WrByte(VL53L1_DEV pdev,
uint16_t index,
uint8_t data)
{
struct stmvl53l1_data *dev;
dev = (struct stmvl53l1_data *)container_of(pdev,
struct stmvl53l1_data, stdev);
return cci_write(dev, index, &data, 1);
}
VL53L1_Error VL53L1_RdByte(
VL53L1_DEV pdev,
uint16_t index,
uint8_t *pdata)
{
struct stmvl53l1_data *dev;
dev = (struct stmvl53l1_data *) container_of(pdev,
struct stmvl53l1_data, stdev);
return cci_read(dev, index, pdata, 1) ?
VL53L1_ERROR_CONTROL_INTERFACE : VL53L1_ERROR_NONE;
}
VL53L1_Error VL53L1_WrWord(VL53L1_DEV pdev, uint16_t index, uint16_t data)
{
VL53L1_Error status;
uint8_t buffer[2];
/* Split 16-bit word into MS and L* stmvl53l1 FlightSense sensor */
buffer[0] = (uint8_t) (data >> 8);
buffer[1] = (uint8_t) (data & 0x00FF);
i2c_debug(" @%x d= %x => [ %x , %x ] ", index, data, buffer[0],
buffer[1]);
status = VL53L1_WriteMulti(pdev, index, buffer, 2);
return status;
}
VL53L1_Error VL53L1_RdWord(VL53L1_DEV pdev, uint16_t index, uint16_t *pdata)
{
VL53L1_Error status;
uint8_t buffer[2];
status = VL53L1_ReadMulti(pdev, index, buffer, 2);
*pdata = ((uint16_t) buffer[0] << 8) + (uint16_t) buffer[1];
return status;
}
VL53L1_Error VL53L1_WrDWord(VL53L1_DEV pdev, uint16_t index, uint32_t data)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
uint8_t buffer[4];
/* 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 = VL53L1_WriteMulti(pdev, index, buffer, 4);
return status;
}
VL53L1_Error VL53L1_RdDWord(VL53L1_DEV pdev, uint16_t index, uint32_t *pdata)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
uint8_t buffer[4];
status = VL53L1_ReadMulti(pdev, index, buffer, 4);
*pdata = ((uint32_t) buffer[0] << 24) + ((uint32_t) buffer[1] << 16)
+ ((uint32_t) buffer[2] << 8) + (uint32_t) buffer[3];
return status;
}
VL53L1_Error VL53L1_WriteMulti(VL53L1_DEV pdev, uint16_t index,
uint8_t *pdata, uint32_t count)
{
struct stmvl53l1_data *dev;
dev = (struct stmvl53l1_data *) container_of(pdev,
struct stmvl53l1_data, stdev);
return cci_write(dev, index, pdata, count) ?
VL53L1_ERROR_CONTROL_INTERFACE : VL53L1_ERROR_NONE;
}
VL53L1_Error VL53L1_ReadMulti(VL53L1_DEV pdev, uint16_t index,
uint8_t *pdata, uint32_t count)
{
struct stmvl53l1_data *dev;
dev = (struct stmvl53l1_data *) container_of(pdev,
struct stmvl53l1_data, stdev);
return cci_read(dev, index, pdata, count) ?
VL53L1_ERROR_CONTROL_INTERFACE : VL53L1_ERROR_NONE;
}
static int is_time_over(struct timeval *tv, uint32_t msec)
{
return tv_elapsed_ms(tv) >= msec;
}
VL53L1_Error VL53L1_WaitValueMaskEx(
VL53L1_DEV pdev,
uint32_t timeout_ms,
uint16_t index,
uint8_t value,
uint8_t mask,
uint32_t poll_delay_ms)
{
struct timeval start_tv;
struct stmvl53l1_data *dev;
int rc, time_over;
uint8_t rd_val;
dev = (struct stmvl53l1_data *) container_of(pdev,
struct stmvl53l1_data, stdev);
do_gettimeofday(&start_tv);
do {
rc = cci_read(dev, index, &rd_val, 1);
if (rc)
return VL53L1_ERROR_CONTROL_INTERFACE;
if ((rd_val & mask) == value) {
poll_timing_log(&start_tv);
return VL53L1_ERROR_NONE;
}
vl53l1_dbgmsg("poll @%x %x & %d != %x", index,
rd_val, mask, value);
time_over = is_time_over(&start_tv, timeout_ms);
if (!time_over)
msleep(poll_delay_ms);
} while (!time_over);
vl53l1_errmsg("time over %d ms", timeout_ms);
return VL53L1_ERROR_TIME_OUT;
}
VL53L1_Error VL53L1_WaitUs(VL53L1_DEV pdev, int32_t wait_us)
{
struct stmvl53l1_data *data;
data = (struct stmvl53l1_data *) container_of(pdev,
struct stmvl53l1_data, stdev);
if (!data->is_delay_allowed)
return VL53L1_ERROR_PLATFORM_SPECIFIC_START;
/* follow Documentation/timers/timers-howto.txt recommendations */
if (wait_us < 10)
udelay(wait_us);
else if (wait_us < 20000)
usleep_range(wait_us, wait_us + 1);
else
msleep(wait_us / 1000);
return VL53L1_ERROR_NONE;
}
VL53L1_Error VL53L1_WaitMs(VL53L1_DEV pdev, int32_t wait_ms)
{
return VL53L1_WaitUs(pdev, wait_ms * 1000);
}

View file

@ -0,0 +1,564 @@
/*
* 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_if.h vl53l1 kernel driver user interface
*
* @note to use this header in a user space application it requires
* all st bare/ll driver platform wrapper files (for data struct def)
* this files (types etc ..) shall be same or compliant with bar driver version
* used in the kernel module
*/
#ifndef STMVL53L1_IF_H
#define STMVL53L1_IF_H
#include "vl53l1_def.h"
/**
* @addtogroup vl53l1_ioctl
* @{
*/
/**
* misc device name for ioctl device
*
* for mutli instance all device 2nd and next instance are basic name +"1"+"2"
* @li stmvl53l1_ranging
* @li stmvl53l1_ranging1
* @li stmvl53l1_ranging2
*/
#define VL53L1_MISC_DEV_NAME "laser"
/**
* register data use for simple/single ranging data @ref VL53L1_IOCTL_GETDATAS
*
* @warning this definition is subject to change !
*/
#define stmvl531_range_data_t VL53L1_RangingMeasurementData_t
/**
* parameter name in @ref stmvl53l1_parameter when using
* @ref VL53L1_IOCTL_PARAMETER
*/
enum __stmv53l1_parameter_name_e {
VL53L1_XTALKENABLE_PAR = 2,
/*!< VL53L1_XTALKENABLE_PAR enable/disable crosstalk compensation\n
* valid value :
* @li 0 disable crosstalk compensation
* @li 1 enable crosstalk compensation
*
* @warning mode can only be set while not ranging
*/
VL53L1_DEVICEMODE_PAR = 6,
/*!< DEVICEMODE_PAR set ranging mode  \n
* valid mode value :
* @li 1 @a VL53L1_PRESETMODE_RANGING default ranging
* @li 2 @a VL53L1_PRESETMODE_MULTIZONES_SCANNING multiple zone
* @li 3 @a VL53L1_PRESETMODE_AUTONOMOUS autonomous mode
* @li 4 @a VL53L1_PRESETMODE_LITE_RANGING low mips ranging mode
*
* @warning mode can only be set while not ranging
*/
VL53L1_POLLDELAY_PAR = 10,
/*!< set the polling delay (msec)\n
*
* @note apply only when operates in polling mode as no effect
* otherwise
*/
VL53L1_TIMINGBUDGET_PAR = 11,
/*!< VL53L1_TIMINGBUDGET_PAR
* @ref stmvl53l1_parameter.value field is timing budget in micro second
*
* @note the value cannot be set while ranging will set ebusy errno,
* value set is absorbed at next range start @ref VL53L1_IOCTL_START
*/
VL53L1_DISTANCEMODE_PAR = 12,
/*!< VL53L1_DISTANCEMODE_PAR
* valid distance mode value :
* @li 1 @a VL53L1_DISTANCEMODE_SHORT
* @li 2 @a VL53L1_DISTANCEMODE_MEDIUM
* @li 3 @a VL53L1_DISTANCEMODE_LONG
* @li 4 @a VL53L1_DISTANCEMODE_AUTO_LITE
* @li 5 @a VL53L1_DISTANCEMODE_AUTO
*
* @warning distance mode can only be set while not ranging
*/
VL53L1_OUTPUTMODE_PAR = 13,
/*!< VL53L1_OUTPUTMODE_PAR
* valid output mode value :
* @li 1 @a VL53L1_OUTPUTMODE_NEAREST
* @li 2 @a VL53L1_OUTPUTMODE_STRONGEST
*
* @warning distance mode can only be set while not ranging
*/
VL53L1_FORCEDEVICEONEN_PAR = 14,
/*!< VL53L1_FORCEDEVICEONEN_PAR
* This parameter will control if device is put under reset when
* stopped.
* valid force device on value :
* @li 0 feature is disable. Device is put under reset when stopped.
* @li 1 feature is enable. Device is not put under reset when stopped.
*/
VL53L1_LASTERROR_PAR = 15,
/*!< VL53L1_LASTERROR_PAR
* This is a read only parameter. It will return last device internal
* error. It's valid only after an ioctl/sysfs return an -EIO error.
*/
VL53L1_CAMERAMODE_PAR = 16,
/*!< VL53L1_CAMERAMODE_PAR
* valid camera mode value :
* @li 0 device is out of camera mode.
* @li 1 device is in camera mode.
*/
VL53L1_HWREV_PAR = 17,
/*!< VL53L1_HWREV_PAR
* This is a read only parameter. It will return HW revision number
*/
};
#define stmv53l1_parameter_name_e enum __stmv53l1_parameter_name_e
/**
* parameter structure use in @ref VL53L1_IOCTL_PARAMETER
*/
struct stmvl53l1_parameter {
uint32_t is_read; /*!< [in] 1: Get 0: Set*/
stmv53l1_parameter_name_e name; /*!< [in] parameter to set/get
* see @ref stmv53l1_parameter_name_e
*/
int32_t value; /*!< [in/out] value to set /get */
int32_t value2; /*!< [in/out] optional 2nd value */
int32_t status; /*!< [out] status of the operation */
};
/**
* roi structure use as @ref VL53L1_IOCTL_ROI arg
*
* see @ref stmvl53l1_roi_full_t for easy to use type variable declaration
* required
*/
struct stmvl53l1_roi_t {
int32_t is_read;
/*!< specify roi transfer direction \n
* @li 0 to get roi
* @li !0 to set roi
*/
/*! roi data and count type use in @ VL53L1_IOCTL_ROI */
struct roi_cfg_t {
uint8_t NumberOfRoi;
/*!< [in/out] Number of Rois to set/get
*
* on set :\n
* [in] number of roi to set
* @note 0 set can be used to return to device default roi usage
*
* on get :\n
* [in] max number provided\n
* [out] number of ROI copied back to user\n
* @warning 0 will not return any roi datas!
*/
VL53L1_UserRoi_t UserRois[1];
/*!< roi data array length definition is 1 but
* NumberOfRoi+ FirstRoiToScan in array are required
* and will be effectively copy to/from user space
*
* @sa stmvl53l1_roi_full_t
*/
} roi_cfg /*! [in/out] roi data and count */;
};
/**
* full roi struct use in @ref VL53L1_IOCTL_ROI arg
*
* this definition make easier variable declaration with the max roi storage
* capabilities.
*
* @sa stmvl53l1_roi_t for field details
*/
struct stmvl53l1_roi_full_t {
int32_t is_read;
/*!< specify roi transfer direction \n
* @li 0 to get roi
* @li !0 to set roi
*/
VL53L1_RoiConfig_t roi_cfg;
/*!< roi data array of max length but only requested copy to/from user
* space effectively used
* see @a stmvl53l1_roi_t::roi_cfg for details
*/
};
/**
* parameter structure use in @ref VL53L1_IOCTL_CALIBRATION_DATA
*/
struct stmvl53l1_ioctl_calibration_data_t {
int32_t is_read; /*!< [in] 1: Get 0: Set*/
VL53L1_CalibrationData_t data;
/*!< [in/out] data to set /get. Caller
* should consider this structure as an opaque one
*/
};
/** Select reference spad calibration in @ref VL53L1_IOCTL_PERFORM_CALIBRATION.
*
* param1, param2 and param3 not use
*/
#define VL53L1_CALIBRATION_REF_SPAD 0
/** Select crosstalk calibration in @ref VL53L1_IOCTL_PERFORM_CALIBRATION.
*
* param1 is calibration method. param2 and param3 not use.
*/
#define VL53L1_CALIBRATION_CROSSTALK 1
/** Select offset calibration @ref VL53L1_IOCTL_PERFORM_CALIBRATION.
* param1 is target distance in mm. param2 and
* param3 not use.
*/
#define VL53L1_CALIBRATION_OFFSET 2
/**
* parameter structure use in @ref VL53L1_IOCTL_PERFORM_CALIBRATION
*/
struct stmvl53l1_ioctl_perform_calibration_t {
uint32_t calibration_type;
/*!< [in] select which calibration to do :
* @li @ref VL53L1_CALIBRATION_REF_SPAD
* @li @ref VL53L1_CALIBRATION_CROSSTALK
* @li @ref VL53L1_CALIBRATION_OFFSET
*/
uint32_t param1;
/*!< [in] first param. Usage depends on calibration_type */
uint32_t param2;
/*!< [in] second param. Usage depends on calibration_type */
uint32_t param3;
/*!< [in] third param. Usage depends on calibration_type */
};
/**
* parameter structure use in @ref VL53L1_IOCTL_AUTONOMOUS_CONFIG
*/
struct stmvl53l1_autonomous_config_t {
int32_t is_read;
/*!< [in] 1: Get 0: Set*/
uint32_t pollingTimeInMs;
/*!< [in/out] interval between two measure in ms */
VL53L1_DetectionConfig_t config;
/*!< [int/out] autonomous mode configuration structure */
};
/*
* IOCTL definitions
*/
/**
* Start ranging (no argument)
*
* @note sysfs and ioctl control are assumed mutual exclusive use
* control from ioctl execute with no consideration of sysfs path.
*
* @return :
* @li 0 on success
* @li -EBUSY if already started
* @li other any possible over "st bare driver error code"
* (shall be positive)
*
* example user land :
@code
int smtvl53l1_start(int fd){error
int rc;
rc = ioctl(fd, VL53L1_IOCTL_START, NULL);
if( rc ){
if( errno == EBUSY){
//the device is already started
ioctl_warn("already started");
return EBUSY;
}
}
if( rc ){
ioctl_error("%d %s", rc,strerror(errno));
}
return rc;
}
@endcode
*/
#define VL53L1_IOCTL_START _IO('p', 0x01)
/* Alias for VL53L1_IOCTL_START. Still present for legacy support but usage is
* deprecated. Consider using VL53L1_IOCTL_START instead. May be removed without
* further notice.
*/
#define VL53L1_IOCTL_INIT VL53L1_IOCTL_START
/**
* stop ranging (no argument)
* @note sysfs and ioctl control are assumed mutual exclusive use
* control from ioctl execute action with no consideration of sysfs path.
*
* @return
* @li 0 on success
* @li -EBUSY if it was already
* @li other specific error code shall be >0
*
* c example userland :
@code
int smtvl53l1_stop(int fd){
int rc;
rc= ioctl(fd, VL53L1_IOCTL_STOP,NULL);
if( rc ){
if( errno == EBUSY ){
ioctl_warn("already stopped");
return errno;
}
ioctl_error("%d %s", rc,strerror(errno));
}
return rc;
}
@endcode
*/
#define VL53L1_IOCTL_STOP _IO('p', 0x05)
/**
* get single ranging data @sa for multi zone/objet
*
* retrieve the last range data available form the device
*
* @param in/out data struct ptr of type @ref stmvl531_range_data_t
* it may come in but is out as of now
*
* @return 0 on success else o, error check errno
* @li -EFAULT fault in cpy to f/m user out range data not copied
*
* @warning this ioctl will not wait for a new range sample acquisition
* it will return what available at time it get called . Hence same data maybe
* returned many time when doing fast polling.\n
* End user must inspect the data structure (time stamp etc )to find about it\n
* Despite it's non "waiting" nature this ioctl may still block/sleep shortly
* to ensure race free usage acquiring mutex and/or locks.
*/
#define VL53L1_IOCTL_GETDATAS \
_IOWR('p', 0x0b, stmvl531_range_data_t)
/**
* set or get parameter
*
* @param parameter in/out @ref stmvl53l1_parameter
* @sa stmv53l1_parameter_name_e
*
* for get if ioctl fail do not check for out params it is not valid
* for set theirs not copy back only see ioctl status, errno to get error case
*
* @note a set parameter may not be absorbed straight aways !
*/
#define VL53L1_IOCTL_PARAMETER \
_IOWR('p', 0x0d, struct stmvl53l1_parameter)
/**
* set/get roi
*
* shall only be use while device is stopped (EBUSY error otherwise)
* setting 0 rois stand for "disable user define roi usage, use device default"
*
* @param roi_cfg [in/out] type @ref stmvl53l1_roi_t and
* @ref stmvl53l1_roi_full_t
* @note when getting roi the returned roi cnt is set to available number
* of roi in driver but at most requested number or available one
* will be set in returned structure
* @warning the coordinate system is not usual image x,y (y down)but traditional
* ecludian x,y (y up)
*
* @warning once defined the user roi is kept alive until unset by user .
* User shall update roi when required (mode change etc ..)\n
* To return to default unset roi by setting none, device will return to default
* at next start
*
* @note roi validity is only checked at start ranging , as such invalid roi set
* can make start to fail
*
* @return 0 on success , see errno for error detail
* @li EBUSY when trying to set roi while ranging
* @li ENODEV never device get started and trying to get more rois than set
* @li other errno code could be ll driver specific
*/
#define VL53L1_IOCTL_ROI\
_IOWR('p', 0x0e, struct stmvl53l1_roi_t)
/**
* Get multi object/zone ranging data
*
* this call is non blocking and will return what available internally
* in all case (veen error)
*
* @param [out] multi zone range @ref VL53L1_MultiRangingData_t always update
* but -EFAULT error case
*
* @return 0 on success else o, error check errno
* @li -EFAULT fault in cpy to f/m user out range data not copyed
* @li -ENOEXEC active mode is not mutli-zone
* @li -ENODEV device is not ranging
* as in that case MZ data may not be fully valid
*/
#define VL53L1_IOCTL_MZ_DATA\
_IOR('p', 0x0f, VL53L1_MultiRangingData_t)
/**
* get single ranging data @sa for multi zone/objet
*
* this call is equivalent to VL53L1_IOCTL_GETDATAS but will block until
* new data are available since previous call.
*
* @param in/out data struct ptr of type @ref stmvl531_range_data_t
* it may come in but is out as of now
*
* @return 0 on success else o, error check errno
* @li -EFAULT fault in cpy to f/m user out range data not copied
* @li -ENODEV device is not ranging.
* @li -ERESTARTSYS interrupt while sleeping.
*/
#define VL53L1_IOCTL_GETDATAS_BLOCKING\
_IOWR('p', 0x10, stmvl531_range_data_t)
/**
* Get multi object/zone ranging data
*
* this call is equivalent to VL53L1_IOCTL_MZ_DATA but will block until
* new data are available since previous call.
*
* @param [out] multi zone range @ref VL53L1_MultiRangingData_t always update
* but -EFAULT error case
*
* @return 0 on success else o, error check errno
* @li -EFAULT fault in cpy to f/m user out range data not copyed
* @li -ENOEXEC active mode is not mutli-zone
* @li -ENODEV device is not ranging.
* @li -ERESTARTSYS interrupt while sleeping.
* as in that case MZ data may not be fully valid
*/
#define VL53L1_IOCTL_MZ_DATA_BLOCKING\
_IOR('p', 0x11, VL53L1_MultiRangingData_t)
/**
* Get / set calibration data
*
* this call allow client to either read calibration data after calibration
* has been performed to store them in the host filesystem or push calibration
* data before ranging at each start-up.
*
* @param [in/out] data struct ptr of type
* @ref stmvl53l1_ioctl_calibration_data_t. Caller should consider it as an
* opaque structure.
*
* @return 0 on success else o, error check errno
* @li -EFAULT fault in cpy to f/m user out range data not copied
* @li -EBUSY when trying to set calibration data while ranging
*/
#define VL53L1_IOCTL_CALIBRATION_DATA\
_IOWR('p', 0x12, struct stmvl53l1_ioctl_calibration_data_t)
/**
* perform calibration squence according to calibration_type
*
* this call is attended to be used during factory calibration. You select
* calibration to issue using calibration_type.
*
* @param [in] data struct ptr of type
* @ref stmvl53l1_ioctl_perform_calibration_t.
*
* @return 0 on success else o, error check errno
* @li -EFAULT fault in cpy to f/m user out range data not copied
* @li -EBUSY when trying to perform calibration data while ranging
*/
#define VL53L1_IOCTL_PERFORM_CALIBRATION\
_IOW('p', 0x13, struct stmvl53l1_ioctl_perform_calibration_t)
/**
* set/get configure autonomous mode parameters
*
* Allow to get or set autonomous configuration. Change it only when device
* is stopped otherwise you will receive an EBUSY error.
*
* @param stmvl53l1_autonomous_config_t [in/out]
*
* @note autonomous config validity is only checked at start ranging , as such
* invalid autonomous config set can make start to fail.
*
* @return 0 on success , see errno for error detail
* @li -EFAULT failed to copy from/to configuration.
* @li -EBUSY when trying to change configuration while ranging.
*/
#define VL53L1_IOCTL_AUTONOMOUS_CONFIG\
_IOWR('p', 0x14, struct stmvl53l1_autonomous_config_t)
/**
* suspend ranging (no argument)
* @note sysfs and ioctl control are assumed mutual exclusive use
* control from ioctl execute action with no consideration of sysfs path.
*
* @return
* @li 0 on success
* @li -EBUSY if it was already
* @li other specific error code shall be >0
*
* c example userland :
@code
int smtvl53l1_stop(int fd){
int rc;
rc= ioctl(fd, VL53L1_IOCTL_SUSPEND,NULL);
if( rc ){
if( errno == EBUSY ){
ioctl_warn("already suspended");
return errno;
}
ioctl_error("%d %s", rc,strerror(errno));
}
return rc;
}
@endcode
*/
#define VL53L1_IOCTL_SUSPEND _IO('p', 0x15)
/** @} */ /* ioctl group */
#endif /* STMVL53L1_IF_H */

View file

@ -0,0 +1,75 @@
/*
* 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.
*/
#ifndef STMVL53L1_INTERNAL_IF_H
#define STMVL53L1_INTERNAL_IF_H
#include "vl53l1_def.h"
/* interface definition move in this file is not supposed to be use by a normal
* client. It's only here for internal testing purpose.
*/
/* structure and ioctl that allow raw access to vl53l1 register */
struct stmvl53l1_register {
uint32_t is_read; /*!< type of the access 1: read 0: write*/
uint32_t index; /*!< register index */
uint32_t cnt; /*!< register size shall be 1 to n */
int32_t status; /*!< operation status 0 ok else error */
union reg_data_t {
uint8_t b; /*!< single data byte*/
uint16_t w; /*!< single data word (16 bits)*/
uint32_t dw; /*!< single data dword (32 bits)*/
uint8_t bytes[256]; /*!< any size byte array
* @note only effectively used array size is needed and will be
* set/used another possible register definition is
* @ref stmvl53l1_register_flexi
*/
} data; /*!< data only *@warning device is big endian and
* no endianess adaptation is performed by @ref VL53L1_IOCTL_REGISTER
*/
};
struct stmvl53l1_register_flexi {
uint32_t is_read; /*!< [in] type of the access 1: read 0: write*/
uint32_t index; /*!< [in] register index */
uint32_t cnt; /*!< [în] register size shall be 1 to n */
int32_t status; /*!< [out] operation status 0 ok else error */
uint8_t data[]; /*!< [in/out] flexible array size data */
/*!< data only *@warning device is big endian and
* no endianess adaptation is performed by @ref VL53L1_IOCTL_REGISTER
*/
};
#define VL53L1_IOCTL_REGISTER _IOWR('p', 0x0c, struct stmvl53l1_register)
#endif

View file

@ -0,0 +1,386 @@
/*
* 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_ipp.h
*
* helper to serialize de-serialize data in ipp exchange between user/kernel
*
* @date Sep 2, 2016
* @author imaging
*/
#ifndef _STMVL53L1_IPP_H_
#define _STMVL53L1_IPP_H_
#include "vl53l1_types.h"
/** @ingroup ipp_dev
* @{
*/
/**
* @defgroup ipp_serialize ST IPP serialization helper
*
* to use the dump help you lust define first a few extra "specific"
*
* @li IPP_PRINT(fmt,..) with typical printf/printk interface
*/
/** @{ */
/**
* generic data type to serialized scalar and offset for pointer
*
* serialized data can be seen as a first array of n ipp_art_t
* where each input are arg value for scaler type
* and an offset with respect to the ipp_arg base array where the data
*
* @note if all ipp argument can fit on 32 bit then ipp_arg_t is best set as
* a 32 bit base type '(i e uint32_t) to save space
* on 64 bit cpu it can remain 64 bit type to get better alignment
*/
typedef uint64_t ipp_arg_t;
/**
* set to the cpu structure alignment and packing constrain
*
* all serialized argument passed by pointer will be stored with
* this memory align constrain
*
*
* @note if target cpu is ok to access unaligned data or less constrain ie 64
* bit data align 32 are ok then it can be set to 4 to save space in data
* packing and copy\n
* We may be over constraining in many cases as a struct is only required to
* be aligned on i'st biggest item size
*
* @warning it must be a 2 power of 2 (& operation instead of mudulo used in
* align calculation)
* @warning using 8 byte constrain require that the @a ipp_arg_t is already
* aligned on that constrain
*/
#define IPP_ALIGN_REQ 8
/**
* set x to it's nearest aligned offset (not that 0 is fine as a valid offset
* than will not be up aligned to next align chunk )
*/
#define IPP_ALIGN_OFFSET(x) (((x)+(IPP_ALIGN_REQ-1)) & (~(IPP_ALIGN_REQ-1)))
/**
* declare variable needed for ipp serialization
*/
#define IPP_SERIALIZE_VAR int ipp_offset
/**
* Put in function start to init the serialization coding
*
* @param ipp_args buffer for data serialization
* @param n_args is the total number of argument scalar and ptr to serialized
* dot not count out only arg that will be returned
*
* it define local var "ipp_offset" used to accumulate all input args that must
* be serialize. It reserve header room in the buffer to place for scalar args
* and offset for args ptr copy
*
* args pass by pointer must be serialized by @ref IPP_SET_ARG_PTR in order they
* are declare\n
* scalar args can be serialized in any order with @ref IPP_SET_ARG
*
* scalar args that can't be cast to basic @ref ipp_arg_t shall be serialized
* Manually or using a macro similar to ptr that can be pass by copy
*
*@note @ref IPP_SERIALIZE_VAR must be use first
* @code
* int ipp_to _ser(int arg0, struct st_t *pdata1){
* char *local var;
* ipp_arg_t args[256];
* IPP_SERIALIZE_START(2);
* IPP_SET_ARG(args, 0, arg0);
* IPP_SET_ARG_PTR(args, 1, pdata);
* do_one_ipp(args);
* }
* @endcode
*
*/
#define IPP_SERIALIZE_START(ipp_args, n_args)\
(ipp_offset = IPP_ALIGN_OFFSET((char *)(&ipp_args[n_args]) - \
(char *)ipp_args))
/**
* @brief Serialize scalar argument
*
* serialized arg number n into ipp_args\n
* can be used in any order
*
* @param ipp_args the args buffer
* @param n 0 base arg number
* @param v the scalar argument variable
* @warning usable only for scalar type that can be copy on a ipp_arg_t
*/
#define IPP_SET_ARG(ipp_args, n, v) memcpy(&ipp_args[n], &v, sizeof(v))
/**
* @brief Serialize an arg passed by pointer
*
* @param ipp_args the arg ptr array
* @param n the arg number to serialize
* @param pdata argument it must be a type like struct x_t * int [n] etc ...
* that size is given by size of and and be copied by a single memcpy
*/
#define IPP_SET_ARG_PTR(ipp_args, n, pdata)\
do {\
ipp_args[n] = ipp_offset;\
memcpy(((char *)ipp_args) + ipp_offset, pdata, sizeof(*pdata));\
ipp_offset = IPP_ALIGN_OFFSET(ipp_offset + sizeof(*pdata));\
} while (0)
/**
* serialize out get ptr for pdata
*
* @note it does not cpy data just set ptr and update the offset
* @warning to be use in order
*
* @param ipp_args the arg ptr array
* @param n the arg number to serialize (unused)
* @param pdata init to ptr in ipp_args type is used for offset computation
* @warning to use sequential in order agr are serialized
*/
#define IPP_OUT_ARG_PTR(ipp_args, n, pdata)\
do {\
pdata = (void *)(((char *)ipp_args) + ipp_offset);\
ipp_offset = IPP_ALIGN_OFFSET(ipp_offset + \
(int)sizeof(*pdata));\
} while (0)
/**
* @brief ipp get payload
*
* @return paylaod at time used \n
* when all done it's overall out payload
*
* require @ref IPP_SERIALIZE_VAR and @ref IPP_SERIALIZE_START used first\n
* best use after all @ref IPP_OUT_ARG_PTR or @ref IPP_SET_ARG_PTR done to get
* full payload
**/
#define IPP_SERIALIZE_PAYLAOD() (ipp_offset + IPP_WORK_HDR_SIZE)
/**
* de-serialize and argument that was passed by value
* @param ipp_args the args array
* @param n the 0 base argument number
* @param v argument it must be exact type
*
*
* @code
* f_deserialize(ipp_arg_t args[])
* {
* // f_ser is like (uint16_t arg0, struct s_arg_t * arg1, int arg2)
* uint16_t arg0;
* void * parg1;
* int arg2;
*
* IPP_GET_ARG( args, 0, arg0)
* IPP_GET_ARG( args, 2, arg2)
* }
* @endcode
*/
#define IPP_GET_ARG(ipp_args, n, v) memcpy(&v, &ipp_args[n], sizeof(v))
/**
* de-serialize an argument passed by pointer
*
* @param ipp_args the serialized argument array
* @param n 0 base argument number
* @param p ptr to arg to be set
*
* @note unlike serializing de-serializing pointer args data can be done in any
* order
*
* @code
* struct some_struct_t *parg2;
* IPP_GET_ARG_PTR(args,2,parg2);
* @endcode
*/
#define IPP_GET_ARG_PTR(ipp_args, n, p) (p = (void *)((char *)ipp_args + \
ipp_args[n]))
/**
* debug macro to pint out all serialized args
*
* Implementation shall define IPP_PRINT_FUNC function to use
*/
#define IPP_PRINT_ARGS(ipp_args, n) \
do {\
int i;\
for (i = 0; i < n; i++)\
IPP_PRINT("arg#%d/%d is %8d 0x%08x\n", i, n,\
ipp_args[i], ipp_args[i]);\
IPP_PRINT("used data size %d\n", ipp_offset);\
} while (0)
/**
* processing code type of proccesing
*
* used in @a ipp_work_t::process_no
*/
enum stmvl53l1_ipp_proccesing_e {
stmvl53l1_ipp_ping = 0,
/*!< stmvl53l1_ipp_ping
* @li can be sent by driver to check client is alive
* @li daemon sent it to identify and register himself to the driver
*/
stmvl53l1_ipp_cal_hist = 1,
/*!< stmvl53l1_ipp_cal_hist process cal hist*/
stmvl53l1_ipp_xtalk_calibration = 2,
/*!< stmvl53l1_ipp_xtalk_calibration process crosstalk calibration data
*/
stmvl53l1_ipp_hist_ambient_dmax = 3,
/*!< stmvl53l1_ipp_hist_ambient_dmax process ambient dmac calculation
* from histogram
*/
stmvl53l1_ipp_generate_dual_reflectance_xtalk_samples = 4,
/*!< stmvl53l1_ipp_generate_dual_reflectance_xtalk_samples process
* Xtalk data from dual reflectance histogram data
*/
/** keep last*/
stmvl53l1_ipp_max /*!< stmvl53l1_ipp_max */
};
/**
* status use on @a ipp_work_t::status
*/
enum stmvl53l1_ipp_status_e {
stmvl53l1_ipp_status_ok = 0, /*!< ok work done */
stmvl53l1_ipp_status_inv_id, /*!< dev id not supported or invalid */
stmvl53l1_ipp_status_inv_proc,
/*!< process_no asked not supported or not implemented */
stmvl53l1_ipp_status_inv_payload,
/*!< data payload for asked processing incorrect*/
stmvl53l1_ipp_status_proc_code = 0x100,
/*!< the lowest 8 bit is the error code form the processing */
};
/**
* Ipp work (job) struct
*
* containing header with sequenc control information plus serialized data
*/
struct ipp_work_t {
int8_t dev_id; /*!< [in]/[out] device id */
/*!< Identify the work do be run see @a stmvl53l1_ipp_proccesing_e */
uint8_t process_no;
/*!< [out] status from daemon */
int16_t status;
/*!< [in/out] unique xfer id */
uint32_t xfer_id;
/*!< [in/out] effective data length including header*/
uint32_t payload;
/** max IPP data payload (not including header)
*
* we substract size of of item above
* must be lesss than one netlink packet
*/
#define MAX_IPP_DATA ((4096-4*3)/8)
ipp_arg_t data[MAX_IPP_DATA]; /*!< [in][out] */
};
/**
* size of header only message ( no payload)
* require \#include <stddef.h> in user land
*/
#define IPP_WORK_HDR_SIZE (offsetof(struct ipp_work_t, data[0]))
/**
* max payload per ipp transfer
*/
#define IPP_WORK_MAX_PAYLOAD sizeof(struct ipp_work_t)
/** copy ipp header from src to dest
*
* used to prepare return work using incoming work header
* @param dest dest work ptr
* @param src src work ptr
*/
#define IPP_CPY_HEADER(dest, src) memcpy(dest, src, IPP_WORK_HDR_SIZE)
/**
* dump in human readble way ipp struct
*
* @note require IPP_PRINT macro
*
* @param pw ipp_work struct to dump
* @param max_data max amount of data to be dump
* @param max_dev max number of dev (for check)
*/
static inline void ipp_dump_work(struct ipp_work_t *pw, uint32_t max_data,
int max_dev)
{
uint32_t data_cnt;
uint32_t i;
uint8_t *pbdata;
(void)max_dev; /* avoid warning when not used */
(void)pbdata; /*avoid warning in case no print no use*/
IPP_PRINT("dev #%d (%s)\n", pw->dev_id, pw->dev_id < max_dev ?
"ok" : "bad");
IPP_PRINT("process #%d (%s)\n", pw->process_no,
pw->process_no < stmvl53l1_ipp_max ? "ok" : "bad");
IPP_PRINT("status %d\n", pw->status);
IPP_PRINT("Xfer id 0x%08X payload %d bytes (%s)\n", pw->xfer_id,
pw->payload,
pw->payload > IPP_WORK_MAX_PAYLOAD ? "invalid" : "ok");
data_cnt = pw->payload > IPP_WORK_MAX_PAYLOAD ?
IPP_WORK_MAX_PAYLOAD : pw->payload;
data_cnt = data_cnt > max_data ? max_data : data_cnt;
for (i = 0, pbdata = (uint8_t *)pw->data; i < data_cnt; i++) {
if (i%16 == 0)
IPP_PRINT("\n%4X\t", i);
IPP_PRINT("%02X ", pbdata[i]);
}
IPP_PRINT("\n");
}
/** @} */ /* ingroup helper */
/** @} */ /* ingroup ipp_dev */
#endif /* _STMVL53L1_IPP_H_ */

View file

@ -0,0 +1,378 @@
/*
* 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_ipp_nl.c vl53l1 ipp proxy over netlink kernel side
*/
#include <linux/module.h>
#include <net/sock.h>
#include <linux/netlink.h>
#include <linux/skbuff.h>
#include <linux/version.h>
#include "stmvl53l1.h"
#include "vl53l1_platform_ipp.h"
#include "stmvl53l1_ipp.h"
#define IPP_DEBUG 1
#ifndef IPP_DEBUG
# define _ipp_dump_work(...) (void)0
#else
# define _ipp_dump_work(...) ipp_dump_work(__VA_ARGS__)
#endif
#define IPP_STATE_PENDING 1
#define IPP_STATE_COMPLETED 2
#define IPP_STATE_CANCELED 4
#define IPP_TIMEOUT_MS 100
/** the single netlink strut use by all instance
* @note is NULL until set
*/
static struct sock *nl_sk;
static DEFINE_MUTEX(ipp_mutex);
/**
* current registered daemon pid
* @note default value 0 or later 1 is kind of invalid and will require
* user space to connect before we can send any packet
*/
static int daemon_pid;
/**
* next xfer_id (shared other all dev)
* no direct us used @@ref get_next_xfer_id (will get lock)
* @note default to 0 what is "reserved"
*/
static int next_xfer_id;
#define ipp_err(fmt, ...) pr_err("STMVL53L1 IPP Err in %s %d :" fmt "\n", \
__func__, __LINE__, ##__VA_ARGS__)
#define ipp_warn(fmt, ...) pr_warn("STMVL53L1 IPP wng in %s %d : "fmt"\n",\
__func__, __LINE__, ##__VA_ARGS__)
#if 0
# define ipp_dbg(fmt, ...) pr_info("IPP %s %d " fmt "\n",\
__func__, __LINE__, ##__VA_ARGS__)
#else
# define ipp_dbg(...) (void)0
#endif
/**
* get and managed increment of next xfer_id
* @note will get ipp_mutex
* @return the xfer_id to be used
*/
static int get_next_xfer_id(void)
{
mutex_lock(&ipp_mutex);
next_xfer_id++;
/*0 is reserved skip it*/
if (next_xfer_id == 0)
next_xfer_id = 1;
mutex_unlock(&ipp_mutex);
return next_xfer_id;
}
static int send_client_msg(void *msg_data, int msg_size)
{
int rc;
struct sk_buff *skb_out;
struct nlmsghdr *nlh;
void *nl_data;
ipp_dbg("to send %d byte", msg_size);
skb_out = nlmsg_new(msg_size, 0);
if (!skb_out) {
ipp_err("nlmsg_new fail\n");
return -1;
}
nlh = nlmsg_put(skb_out, 0, 0, NLMSG_DONE, msg_size, 0);
NETLINK_CB(skb_out).dst_group = 0; /* not in mcast group */
nl_data = nlmsg_data(nlh); /*get data ptr from header*/
memcpy(nl_data, msg_data, msg_size);
/* FIXME do we real need to lock to send a data other nl_sk ? */
mutex_lock(&ipp_mutex);
rc = nlmsg_unicast(nl_sk, skb_out, daemon_pid);
if (rc < 0)
ipp_err("fail to send data size %d to pid %d\n",
msg_size, daemon_pid);
/* stat can be done here in else case */
mutex_unlock(&ipp_mutex);
return rc;
}
/*
* ipp lock is held ping already handled
*/
int ipp_in_process(struct ipp_work_t *pwork)
{
struct stmvl53l1_data *data;
ipp_dbg("enter");
_ipp_dump_work(pwork, IPP_WORK_MAX_PAYLOAD, STMVL53L1_CFG_MAX_DEV);
/* work id check already done */
data = stmvl53l1_dev_table[pwork->dev_id];
ipp_dbg("to lock ");
mutex_lock(&data->work_mutex);
if (data->ipp.buzy == IPP_STATE_PENDING) {
/* if it was already handled ignore it */
if (data->ipp.waited_xfer_id == pwork->xfer_id) {
/* ok that is what we are expecting back */
memcpy(&data->ipp.work_out, pwork, pwork->payload);
data->ipp.buzy |= IPP_STATE_COMPLETED;
ipp_dbg("to wake ipp waiter as buzy state %d",
data->ipp.buzy);
wake_up(&data->ipp.waitq);
goto done_lock;
}
}
/* either not waiting any more or not the expected id drop it */
ipp_err("dev #%d ippp buzy %d xfer id %d rcv id %d droping it",
data->id, data->ipp.buzy, data->ipp.waited_xfer_id,
pwork->xfer_id);
done_lock:
mutex_unlock(&data->work_mutex);
return 0;
}
int stmvl53l1_ipp_stop(struct stmvl53l1_data *data)
{
int rc;
rc = data->ipp.buzy;
ipp_dbg("#%d to stop buzy %d", data->id, data->ipp.buzy);
if (data->ipp.buzy) {
/* set invalid wait id to discard canceled job when back */
data->ipp.waited_xfer_id = 0;
data->ipp.buzy |= IPP_STATE_CANCELED|IPP_STATE_COMPLETED;
ipp_dbg("#%dto wake up worker", data->id);
/* wake up worker or abort the thread */
wake_up(&data->ipp.waitq);
}
return rc;
}
/*
* ipp and dev lock are held
* release and re-grabbed here
*/
int stmvl53l1_ipp_do(struct stmvl53l1_data *data,
struct ipp_work_t *pin, struct ipp_work_t *pout)
{
int xfer_id;
int rc;
bool has_timeout;
ipp_dbg("enter");
xfer_id = get_next_xfer_id();
/* set xfer and device dependent part of the work */
pin->dev_id = data->id;
pin->xfer_id = xfer_id;
data->ipp.waited_xfer_id = xfer_id;
/* try to do it */
rc = send_client_msg(pin, pin->payload);
/* shall we retry if fail to send for some time or number of try ? */
if (rc < 0) {
rc = -1;
ipp_err("fail to send msg %d", rc);
} else if (data->ipp.buzy == 0) {
/* send ok put the ipp on buzy state while locked */
data->ipp.buzy = IPP_STATE_PENDING;
/* unlock now that state is marked buzy */
mutex_unlock(&data->work_mutex);
/* put task to wait for completion */
ipp_dbg("to wait");
has_timeout = !wait_event_timeout(data->ipp.waitq,
(data->ipp.buzy != IPP_STATE_PENDING),
msecs_to_jiffies(IPP_TIMEOUT_MS));
/* relock the main lock */
mutex_lock(&data->work_mutex);
rc = (data->ipp.buzy & IPP_STATE_CANCELED) || has_timeout ?
-1 : 0;
if (rc) {
ipp_dbg("waking up with from canceled/timeout ipp");
} else {
/* return status from the ipp itself */
ipp_dbg("ip back with status %d", data->ipp.status);
rc = data->ipp.status;
}
data->ipp.buzy = 0;/* buzy clear but locked so safe */
} else {
ipp_dbg("buzy still not zero %d", data->ipp.buzy);
rc = -1;
}
/* done_lock: */
return rc;
}
static void stmvl53l1_nl_recv_msg(struct sk_buff *skb_in)
{
int pid_chg = 0;
int pid;
struct nlmsghdr *nlh;
struct ipp_work_t *pwork;
ipp_dbg("Entering");
nlh = (struct nlmsghdr *)skb_in->data;
pid = nlh->nlmsg_pid; /*pid of sending process */
pwork = nlmsg_data(nlh);
if (pwork->payload < IPP_WORK_HDR_SIZE ||
pwork->payload > IPP_WORK_MAX_PAYLOAD){
/* invalid header size */
ipp_err("invalid msg header size %d", pwork->payload);
_ipp_dump_work(pwork, IPP_WORK_MAX_PAYLOAD,
STMVL53L1_CFG_MAX_DEV);
return;
}
mutex_lock(&ipp_mutex);
if (pwork->dev_id >= STMVL53L1_CFG_MAX_DEV) {
ipp_err("invalid dev id on msg %d", pwork->dev_id);
_ipp_dump_work(pwork, IPP_WORK_MAX_PAYLOAD,
STMVL53L1_CFG_MAX_DEV);
goto done_locked;
}
if (pwork->process_no == stmvl53l1_ipp_ping) {
/* in that case the payload must be exact status size only
* if not it is a badly format message or bad message
*/
if (pwork->payload != IPP_WORK_HDR_SIZE) {
ipp_err("invalid ping msg size %d!=%zu ",
pwork->payload, IPP_WORK_HDR_SIZE);
_ipp_dump_work(pwork, IPP_WORK_MAX_PAYLOAD,
STMVL53L1_CFG_MAX_DEV);
goto done_locked;
}
/* if pid was not set or change resent all ongoing ipp */
if (pid != daemon_pid)
ipp_warn("pid chg %d => %d\n", daemon_pid, pid);
else
ipp_dbg("got ping fm pid %d\n", daemon_pid);
daemon_pid = pid;
pid_chg = 1;
} else {
ipp_in_process(pwork);
}
done_locked:
mutex_unlock(&ipp_mutex);
}
int stmvl53l1_ipp_setup(struct stmvl53l1_data *data)
{
int rc;
mutex_lock(&ipp_mutex);
data->ipp.buzy = 0;
init_waitqueue_head(&data->ipp.waitq);
ipp_dbg("now %d dev daemon pid is %d", STMVL53L1_CFG_MAX_DEV,
daemon_pid);
rc = 0;
mutex_unlock(&ipp_mutex);
return rc;
}
void stmvl53l1_ipp_cleanup(struct stmvl53l1_data *data)
{
/* nothink to do */
}
#if !defined(OLD_NETLINK_API)
struct netlink_kernel_cfg cfg = {
.input = stmvl53l1_nl_recv_msg
};
#endif
static int netlink_protocol_type = STMVL531_CFG_NETLINK_USER;
module_param(netlink_protocol_type, int, 0444);
MODULE_PARM_DESC(netlink_protocol_type,
"select netlink protocol type for ipp communications");
int stmvl53l1_ipp_init(void)
{
mutex_init(&ipp_mutex);
daemon_pid = 1; /* pid 1 is safe should not be use for user space */
#if defined(OLD_NETLINK_API)
nl_sk = netlink_kernel_create(&init_net,
netlink_protocol_type,
0,
stmvl53l1_nl_recv_msg,
NULL,
THIS_MODULE);
#else
nl_sk = netlink_kernel_create(&init_net,
netlink_protocol_type,
&cfg);
#endif
return nl_sk ? 0 : -1;
}
void __exit stmvl53l1_ipp_exit(void)
{
if (nl_sk != NULL) {
vl53l1_dbgmsg("releasing netlink socket");
netlink_kernel_release(nl_sk);
nl_sk = NULL;
}
}

View file

@ -0,0 +1,78 @@
/*
* 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_module.c vl53l1_module ST VL53L1 linux kernel module
*
* This is implementation of low level driver trace support
*/
#include <linux/module.h>
#include <linux/printk.h>
#include "stmvl53l1.h"
#ifdef VL53L1_LOG_ENABLE
static bool trace_function;
static int trace_module;
static int trace_level;
module_param(trace_function, bool, 0644);
MODULE_PARM_DESC(trace_function,
"allow tracing of low level function entry and exit");
module_param(trace_module, int, 0644);
MODULE_PARM_DESC(trace_module,
"control tracing of low level per module");
module_param(trace_level, int, 0644);
MODULE_PARM_DESC(trace_level,
"control tracing of low level per level");
void log_trace_print(uint32_t module, uint32_t level, uint32_t function,
const char *format, ...)
{
va_list args;
if (function && !trace_function)
return;
if (!(module & trace_module))
return;
if (level > trace_level)
return;
va_start(args, format);
vprintk(format, args);
va_end(args);
}
#endif

View file

@ -0,0 +1,890 @@
/*
* 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_module-i2c.c
*
* implement STM VL53L1 module interface i2c wrapper + control
* using linux native i2c + gpio + reg api
*/
#include <linux/uaccess.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/mutex.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/gpio.h>
#include <linux/input.h>
#include <linux/miscdevice.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/time.h>
#include <linux/platform_device.h>
#include <linux/version.h>
/*
* power specific includes
*/
#include <linux/pwm.h>
#include <linux/regulator/consumer.h>
#include <linux/pinctrl/consumer.h>
#include <linux/clk.h>
#include <linux/of_gpio.h>
#include <linux/gpio.h>
#include "stmvl53l1-i2c.h"
#include "stmvl53l1.h"
#define STMVL53L1_SLAVE_ADDR (0x52>>1)
/** @ingroup drv_port
* @{
*/
/**
* control specific debug message echo
*
* Set to 0/1 do not remove
*
* most dbg warn err messages goes true main driver macro
* this one permit some specific debug without activating all main dbg
*/
#define MODI2C_DEBUG 0
/*
* mutex to handle device i2c address changes. It allow to avoid multiple
* device active with same i2c addresses at the same time. Note that we don't
* support case where boot_reg has the same value as a final i2c address of
* another device.
*/
static DEFINE_MUTEX(dev_addr_change_mutex);
struct vl53l1_pinctrl_info {
struct pinctrl *pinctrl;
struct pinctrl_state *gpio_state_active;
struct pinctrl_state *gpio_state_suspend;
} g_pinctrl_info;
/**
* i2c client assigned to our driver
*
* this is use for stm test purpose as we fake client create and regstration
* we stores the i2c client for release in clean-up overwise we wan't reload
* the module multiple time
*
* in a normal dev tree prod system this is not required
*/
static struct i2c_client *stm_test_i2c_client;
/*
* pi3:
* insmod stmvl53l1.ko force_device=1 adapter_nb=1 xsdn_gpio_nb=19
* intr_gpio_nb=16 pwren_gpio_nb=12
*
* panda
* insmod stmvl53l1.ko force_device=1 adapter_nb=4 xsdn_gpio_nb=56
* intr_gpio_nb=59 pwren_gpio_nb=55
*/
static int force_device;
static int adapter_nb = -1;
static int xsdn_gpio_nb = -1;
static int pwren_gpio_nb = -1;
static int intr_gpio_nb = -1;
module_param(force_device, int, 0);
MODULE_PARM_DESC(force_device, "force device insertion at module init");
module_param(adapter_nb, int, 0);
MODULE_PARM_DESC(adapter_nb, "i2c adapter to use");
module_param(xsdn_gpio_nb, int, 0);
MODULE_PARM_DESC(xsdn_gpio_nb, "select gpio numer to use for vl53l1 reset");
module_param(pwren_gpio_nb, int, 0);
MODULE_PARM_DESC(pwren_gpio_nb, "select gpio numer to use for vl53l1 power");
module_param(intr_gpio_nb, int, 0);
MODULE_PARM_DESC(intr_gpio_nb, "select gpio numer to use for vl53l1 interrupt");
/**
* warn message
*
* @warning use only in scope where i2c_data ptr is present
**/
#define modi2c_warn(fmt, ...)\
dev_WARN(&i2c_data->client->dev, fmt, ##__VA_ARGS__)
/**
* err message
*
* @warning use only in scope where i2c_data ptr is present
*/
#define modi2c_err(fmt, ...)\
dev_err(&i2c_data->client->dev, fmt, ##__VA_ARGS__)
#if MODI2C_DEBUG
# define modi2c_dbg(fmt, ...)\
pr_devel("%s "fmt"\n", __func__, ##__VA_ARGS__)
#else
# define modi2c_dbg(...) (void)0
#endif
static int insert_device(void)
{
int ret = 0;
struct i2c_adapter *adapter;
struct i2c_board_info info = {
.type = "stmvl53l1",
.addr = STMVL53L1_SLAVE_ADDR,
};
adapter = i2c_get_adapter(adapter_nb);
if (!adapter)
ret = -EINVAL;
stm_test_i2c_client = i2c_new_device(adapter, &info);
if (!stm_test_i2c_client)
ret = -EINVAL;
return ret;
}
static int get_xsdn(struct device *dev, struct i2c_data *i2c_data)
{
int rc = 0;
i2c_data->io_flag.xsdn_owned = 0;
if (i2c_data->xsdn_gpio == -1) {
vl53l1_errmsg("reset gpio is required");
rc = -ENODEV;
goto no_gpio;
}
vl53l1_dbgmsg("request xsdn_gpio %d", i2c_data->xsdn_gpio);
rc = gpio_request(i2c_data->xsdn_gpio, "vl53l1_xsdn");
if (rc) {
vl53l1_errmsg("fail to acquire xsdn %d", rc);
goto request_failed;
}
rc = gpio_direction_output(i2c_data->xsdn_gpio, 0);
if (rc) {
vl53l1_errmsg("fail to configure xsdn as output %d", rc);
goto direction_failed;
}
i2c_data->io_flag.xsdn_owned = 1;
return rc;
direction_failed:
gpio_free(i2c_data->xsdn_gpio);
request_failed:
no_gpio:
return rc;
}
static void put_xsdn(struct i2c_data *i2c_data)
{
if (i2c_data->io_flag.xsdn_owned) {
vl53l1_dbgmsg("release xsdn_gpio %d", i2c_data->xsdn_gpio);
gpio_free(i2c_data->xsdn_gpio);
i2c_data->io_flag.xsdn_owned = 0;
i2c_data->xsdn_gpio = -1;
}
i2c_data->xsdn_gpio = -1;
}
static int get_pwren(struct device *dev, struct i2c_data *i2c_data)
{
int rc = 0;
i2c_data->io_flag.pwr_owned = 0;
if (i2c_data->pwren_gpio == -1) {
vl53l1_wanrmsg("pwren gpio disable");
goto no_gpio;
}
vl53l1_dbgmsg("request pwren_gpio %d", i2c_data->pwren_gpio);
rc = gpio_request(i2c_data->pwren_gpio, "vl53l1_pwren");
if (rc) {
vl53l1_errmsg("fail to acquire pwren %d", rc);
goto request_failed;
}
rc = gpio_direction_output(i2c_data->pwren_gpio, 0);
if (rc) {
vl53l1_errmsg("fail to configure pwren as output %d", rc);
goto direction_failed;
}
i2c_data->io_flag.pwr_owned = 1;
return rc;
direction_failed:
gpio_free(i2c_data->xsdn_gpio);
request_failed:
no_gpio:
return rc;
}
static void put_pwren(struct i2c_data *i2c_data)
{
if (i2c_data->io_flag.pwr_owned) {
vl53l1_dbgmsg("release pwren_gpio %d", i2c_data->pwren_gpio);
gpio_free(i2c_data->pwren_gpio);
i2c_data->io_flag.pwr_owned = 0;
i2c_data->pwren_gpio = -1;
}
i2c_data->pwren_gpio = -1;
}
static int get_intr(struct device *dev, struct i2c_data *i2c_data)
{
int rc = 0;
i2c_data->io_flag.intr_owned = 0;
if (i2c_data->intr_gpio == -1) {
vl53l1_wanrmsg("no interrupt gpio");
goto no_gpio;
}
vl53l1_dbgmsg("request intr_gpio %d", i2c_data->intr_gpio);
rc = gpio_request(i2c_data->intr_gpio, "vl53l1_intr");
if (rc) {
vl53l1_errmsg("fail to acquire intr %d", rc);
goto request_failed;
}
rc = gpio_direction_input(i2c_data->intr_gpio);
if (rc) {
vl53l1_errmsg("fail to configure intr as input %d", rc);
goto direction_failed;
}
i2c_data->irq = gpio_to_irq(i2c_data->intr_gpio);
if (i2c_data->irq < 0) {
vl53l1_errmsg("fail to map GPIO: %d to interrupt:%d\n",
i2c_data->intr_gpio, i2c_data->irq);
goto irq_failed;
}
i2c_data->io_flag.intr_owned = 1;
return rc;
irq_failed:
direction_failed:
gpio_free(i2c_data->intr_gpio);
request_failed:
no_gpio:
return rc;
}
static void put_intr(struct i2c_data *i2c_data)
{
if (i2c_data->io_flag.intr_owned) {
if (i2c_data->io_flag.intr_started) {
free_irq(i2c_data->irq, i2c_data);
i2c_data->io_flag.intr_started = 0;
}
vl53l1_dbgmsg("release intr_gpio %d", i2c_data->intr_gpio);
gpio_free(i2c_data->intr_gpio);
i2c_data->io_flag.intr_owned = 0;
}
i2c_data->intr_gpio = -1;
}
static int get_dt_xtalk_data(struct device_node *of_node,
struct stmvl53l1_data *vl53l1_data)
{
int rc = 0;
uint32_t x_array[3] = {0};
if(of_node == NULL || vl53l1_data == NULL)
return -EINVAL;
rc = of_property_read_u32_array(of_node, "st,xtalkval",
x_array, 3);
if (rc) {
vl53l1_errmsg("failed to read xtalk-offset\n");
vl53l1_data->xtalk_offset = 0;
vl53l1_data->xtalk_x = 0;
vl53l1_data->xtalk_y = 0;
} else {
vl53l1_data->xtalk_offset = (uint16_t)x_array[0] & 0xFFFF;
vl53l1_data->xtalk_x = (int16_t)(x_array[1] & 0xFFFF);
vl53l1_data->xtalk_y = (int16_t)(x_array[2] & 0xFFFF);
}
vl53l1_info("xtalk info: %u %d %d\n",
vl53l1_data->xtalk_offset,
vl53l1_data->xtalk_x,
vl53l1_data->xtalk_y);
return rc;
}
/**
* parse dev tree for all platform specific input
*/
static int stmvl53l1_parse_tree(struct device *dev, struct i2c_data *i2c_data)
{
int rc = 0;
/* if force device is in use then gpio nb comes from module param else
* we use devicetree.
*/
i2c_data->vdd = NULL;
i2c_data->pwren_gpio = -1;
i2c_data->xsdn_gpio = -1;
i2c_data->intr_gpio = -1;
i2c_data->boot_reg = STMVL53L1_SLAVE_ADDR;
if (force_device) {
i2c_data->xsdn_gpio = xsdn_gpio_nb;
i2c_data->pwren_gpio = pwren_gpio_nb;
i2c_data->intr_gpio = intr_gpio_nb;
} else if (dev->of_node) {
/* power : either vdd or pwren_gpio. try reulator first */
i2c_data->vdd = regulator_get_optional(dev, "vdd-vl53l1");
if (IS_ERR(i2c_data->vdd) || i2c_data->vdd == NULL) {
i2c_data->vdd = NULL;
/* try gpio */
rc = of_property_read_u32_array(dev->of_node,
"pwren-gpio", &i2c_data->pwren_gpio, 1);
if (rc) {
i2c_data->pwren_gpio = -1;
vl53l1_wanrmsg(
"no regulator, nor power gpio => power ctrl disabled");
}
}
g_pinctrl_info.pinctrl = devm_pinctrl_get(dev);
if (!IS_ERR_OR_NULL(g_pinctrl_info.pinctrl)) {
g_pinctrl_info.gpio_state_active =
pinctrl_lookup_state(g_pinctrl_info.pinctrl,
"laser_default");
g_pinctrl_info.gpio_state_suspend =
pinctrl_lookup_state(g_pinctrl_info.pinctrl,
"laser_suspend");
} else
vl53l1_errmsg("Getting pinctrl handle failed\n");
rc = of_property_read_u32_array(dev->of_node, "xsdn-gpio",
&i2c_data->xsdn_gpio, 1);
if (rc) {
vl53l1_wanrmsg("Unable to find xsdn-gpio %d %d",
rc, i2c_data->xsdn_gpio);
if (of_gpio_count(dev->of_node) >= 2)
i2c_data->xsdn_gpio = of_get_gpio(dev->of_node, 0);
else
i2c_data->xsdn_gpio = -1;
}
rc = of_property_read_u32_array(dev->of_node, "intr-gpio",
&i2c_data->intr_gpio, 1);
if (rc) {
vl53l1_wanrmsg("Unable to find intr-gpio %d %d",
rc, i2c_data->intr_gpio);
if (of_gpio_count(dev->of_node) >= 2)
i2c_data->intr_gpio = of_get_gpio(dev->of_node, 1);
else
i2c_data->intr_gpio = -1;
}
rc = of_property_read_u32_array(dev->of_node, "boot-reg",
&i2c_data->boot_reg, 1);
if (rc) {
vl53l1_wanrmsg("Unable to find boot-reg %d %d",
rc, i2c_data->boot_reg);
i2c_data->boot_reg = STMVL53L1_SLAVE_ADDR;
}
get_dt_xtalk_data(dev->of_node, i2c_data->vl53l1_data);
}
/* configure gpios */
rc = get_xsdn(dev, i2c_data);
if (rc)
goto no_xsdn;
rc = get_pwren(dev, i2c_data);
if (rc)
goto no_pwren;
rc = get_intr(dev, i2c_data);
if (rc)
goto no_intr;
return rc;
no_intr:
if (i2c_data->vdd) {
regulator_put(i2c_data->vdd);
i2c_data->vdd = NULL;
}
put_pwren(i2c_data);
no_pwren:
put_xsdn(i2c_data);
no_xsdn:
return rc;
}
static void stmvl53l1_release_gpios(struct i2c_data *i2c_data)
{
put_xsdn(i2c_data);
if (i2c_data->vdd) {
regulator_put(i2c_data->vdd);
i2c_data->vdd = NULL;
}
put_pwren(i2c_data);
put_intr(i2c_data);
}
static int stmvl53l1_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
int rc = 0;
struct stmvl53l1_data *vl53l1_data = NULL;
struct i2c_data *i2c_data = NULL;
vl53l1_dbgmsg("Enter %s : 0x%02x\n", client->name, client->addr);
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) {
rc = -EIO;
return rc;
}
vl53l1_data = kzalloc(sizeof(struct stmvl53l1_data), GFP_KERNEL);
if (!vl53l1_data) {
rc = -ENOMEM;
return rc;
}
if (vl53l1_data) {
vl53l1_data->client_object =
kzalloc(sizeof(struct i2c_data), GFP_KERNEL);
if (!vl53l1_data)
goto done_freemem;
i2c_data = (struct i2c_data *)vl53l1_data->client_object;
}
i2c_data->client = client;
i2c_data->vl53l1_data = vl53l1_data;
i2c_data->irq = -1 ; /* init to no irq */
/* parse and configure hardware */
rc = stmvl53l1_parse_tree(&i2c_data->client->dev, i2c_data);
if (rc)
goto done_freemem;
/* setup device name */
/* vl53l1_data->dev_name = dev_name(&client->dev); */
/* setup client data */
i2c_set_clientdata(client, vl53l1_data);
/* end up by core driver setup */
rc = stmvl53l1_setup(vl53l1_data);
if (rc)
goto release_gpios;
vl53l1_data->sysfs_base = i2c_data->client->addr;
rc = stmvl53l1_sysfs_laser(vl53l1_data, true);
if (rc)
goto release_gpios;
vl53l1_dbgmsg("End\n");
kref_init(&i2c_data->ref);
return rc;
release_gpios:
stmvl53l1_release_gpios(i2c_data);
done_freemem:
/* kfree safe against NULL */
kfree(vl53l1_data);
kfree(i2c_data);
return -1;
}
static int stmvl53l1_remove(struct i2c_client *client)
{
struct stmvl53l1_data *data = i2c_get_clientdata(client);
struct i2c_data *i2c_data = (struct i2c_data *)data->client_object;
vl53l1_dbgmsg("Enter\n");
mutex_lock(&data->work_mutex);
stmvl53l1_sysfs_laser(data, false);
/* main driver cleanup */
stmvl53l1_cleanup(data);
/* release gpios */
stmvl53l1_release_gpios(i2c_data);
mutex_unlock(&data->work_mutex);
stmvl53l1_put(data->client_object);
vl53l1_dbgmsg("End\n");
return 0;
}
static const struct i2c_device_id stmvl53l1_id[] = {
{ STMVL53L1_DRV_NAME, 0 },
{ },
};
MODULE_DEVICE_TABLE(i2c, stmvl53l1_id);
static const struct of_device_id st_stmvl53l1_dt_match[] = {
{ .compatible = "st,"STMVL53L1_DRV_NAME, },
{ },
};
static struct i2c_driver stmvl53l1_driver = {
.driver = {
.name = STMVL53L1_DRV_NAME,
.owner = THIS_MODULE,
.of_match_table = st_stmvl53l1_dt_match,
},
.probe = stmvl53l1_probe,
.remove = stmvl53l1_remove,
.id_table = stmvl53l1_id,
};
/**
* give power to device
*
* @param object the i2c layer object
* @return
*/
int stmvl53l1_power_up_i2c(void *object)
{
int rc = 0;
struct i2c_data *data = (struct i2c_data *) object;
vl53l1_dbgmsg("Enter\n");
/* turn on power */
if (data->vdd) {
rc = regulator_enable(data->vdd);
if (rc) {
vl53l1_errmsg("fail to turn on regulator");
return rc;
}
} else if (data->pwren_gpio != -1) {
gpio_set_value(data->pwren_gpio, 1);
vl53l1_info("slow power on");
} else
vl53l1_wanrmsg("no power control");
return rc;
}
/**
* remove power to device (reset it)
*
* @param i2c_object the i2c layer object
* @return 0 on success
*/
int stmvl53l1_power_down_i2c(void *i2c_object)
{
struct i2c_data *data = (struct i2c_data *) i2c_object;
int rc = 0;
vl53l1_dbgmsg("Enter\n");
/* turn off power */
if (data->vdd) {
rc = regulator_disable(data->vdd);
if (rc)
vl53l1_errmsg("reg disable failed. rc=%d\n",
rc);
} else if (data->pwren_gpio != -1) {
gpio_set_value(data->pwren_gpio, 0);
}
vl53l1_dbgmsg("power off");
vl53l1_dbgmsg("End\n");
return rc;
}
static int handle_i2c_address_device_change_lock(struct i2c_data *data)
{
struct i2c_client *client = (struct i2c_client *) data->client;
uint8_t buffer[3];
struct i2c_msg msg;
int rc = 0;
vl53l1_dbgmsg("change device i2c address from 0x%02x to 0x%02x",
data->boot_reg, client->addr);
/* no i2c-access must occur before fw boot time */
usleep_range(VL53L1_FIRMWARE_BOOT_TIME_US,
VL53L1_FIRMWARE_BOOT_TIME_US + 1);
/* manually send message to update i2c address */
buffer[0] = (VL53L1_I2C_SLAVE__DEVICE_ADDRESS >> 8) & 0xFF;
buffer[1] = (VL53L1_I2C_SLAVE__DEVICE_ADDRESS >> 0) & 0xFF;
buffer[2] = client->addr;
msg.addr = data->boot_reg;
msg.flags = client->flags;
msg.buf = buffer;
msg.len = 3;
if (i2c_transfer(client->adapter, &msg, 1) != 1) {
rc = -ENXIO;
vl53l1_errmsg("Fail to change i2c address to 0x%02x",
client->addr);
}
return rc;
}
/* reset release will also handle device address change. It will avoid state
* where multiple stm53l1 are bring out of reset at the same time with the
* same boot address.
* Note that we don't manage case where boot_reg has the same value as a final
* i2c address of another device. This case is not supported and will lead
* to unpredictable behavior.
*/
static int release_reset(struct i2c_data *data)
{
struct i2c_client *client = (struct i2c_client *) data->client;
int rc = 0;
bool is_address_change = client->addr != data->boot_reg;
if (is_address_change)
mutex_lock(&dev_addr_change_mutex);
gpio_set_value(data->xsdn_gpio, 1);
if (is_address_change) {
rc = handle_i2c_address_device_change_lock(data);
if (rc)
gpio_set_value(data->xsdn_gpio, 0);
}
if (is_address_change)
mutex_unlock(&dev_addr_change_mutex);
return rc;
}
/**
* release device reset
*
* @param i2c_object the i2c layer object
* @return 0 on success
*/
int stmvl53l1_reset_release_i2c(void *i2c_object)
{
int rc;
struct i2c_data *data = (struct i2c_data *) i2c_object;
vl53l1_dbgmsg("Enter\n");
rc = release_reset(data);
pinctrl_select_state(g_pinctrl_info.pinctrl,
g_pinctrl_info.gpio_state_active);
if (rc)
goto error;
/* and now wait for device end of boot */
data->vl53l1_data->is_delay_allowed = true;
rc = VL53L1_WaitDeviceBooted(&data->vl53l1_data->stdev);
data->vl53l1_data->is_delay_allowed = false;
if (rc) {
gpio_set_value(data->xsdn_gpio, 0);
vl53l1_errmsg("boot fail with error %d", rc);
data->vl53l1_data->last_error = rc;
rc = -EIO;
}
error:
vl53l1_dbgmsg("End\n");
return rc;
}
/**
* put device under reset
*
* @param i2c_object the i2c layer object
* @return 0 on success
*/
int stmvl53l1_reset_hold_i2c(void *i2c_object)
{
struct i2c_data *data = (struct i2c_data *) i2c_object;
vl53l1_dbgmsg("Enter\n");
gpio_set_value(data->xsdn_gpio, 0);
pinctrl_select_state(g_pinctrl_info.pinctrl,
g_pinctrl_info.gpio_state_suspend);
vl53l1_dbgmsg("End\n");
return 0;
}
int stmvl53l1_init_i2c(void)
{
int ret = 0;
vl53l1_dbgmsg("Enter\n");
/* register as a i2c client device */
ret = i2c_add_driver(&stmvl53l1_driver);
if (ret)
vl53l1_errmsg("%d erro ret:%d\n", __LINE__, ret);
if (!ret && force_device)
ret = insert_device();
vl53l1_dbgmsg("End with rc:%d\n", ret);
return ret;
}
void stmvl53l1_clean_up_i2c(void)
{
if (stm_test_i2c_client) {
vl53l1_dbgmsg("to unregister i2c client\n");
i2c_unregister_device(stm_test_i2c_client);
}
}
static irqreturn_t stmvl53l1_irq_handler_i2c(int vec, void *info)
{
struct i2c_data *i2c_data = (struct i2c_data *)info;
if (i2c_data->irq == vec) {
modi2c_dbg("irq");
stmvl53l1_intr_handler(i2c_data->vl53l1_data);
modi2c_dbg("over");
} else {
if (!i2c_data->msg_flag.unhandled_irq_vec) {
modi2c_warn("unmatching vec %d != %d\n",
vec, i2c_data->irq);
i2c_data->msg_flag.unhandled_irq_vec = 1;
}
}
return IRQ_HANDLED;
}
/**
* enable and start intr handling
*
* @param object our i2c_data specific object
* @param poll_mode [in/out] set to force mode clear to use irq
* @return 0 on success and set ->poll_mode if it faill ranging wan't start
*/
int stmvl53l1_start_intr(void *object, int *poll_mode)
{
struct i2c_data *i2c_data;
int rc;
i2c_data = (struct i2c_data *)object;
/* irq and gpio acquire config done in parse_tree */
if (i2c_data->irq < 0) {
/* the i2c tree as no intr force polling mode */
*poll_mode = -1;
return 0;
}
/* clear irq warning report enabe it again for this session */
i2c_data->msg_flag.unhandled_irq_vec = 0;
/* if started do no nothing */
if (i2c_data->io_flag.intr_started) {
/* nothing to do */
*poll_mode = 0;
return 0;
}
vl53l1_dbgmsg("to register_irq:%d\n", i2c_data->irq);
rc = request_threaded_irq(i2c_data->irq, NULL,
stmvl53l1_irq_handler_i2c,
IRQF_TRIGGER_FALLING|IRQF_ONESHOT,
"vl53l1_interrupt",
(void *)i2c_data);
if (rc) {
vl53l1_errmsg("fail to req threaded irq rc=%d\n", rc);
*poll_mode = 0;
} else {
vl53l1_dbgmsg("irq %d now handled\n", i2c_data->irq);
i2c_data->io_flag.intr_started = 1;
*poll_mode = 0;
}
return rc;
}
void *stmvl53l1_get(void *object)
{
struct i2c_data *data = (struct i2c_data *) object;
vl53l1_dbgmsg("Enter\n");
kref_get(&data->ref);
vl53l1_dbgmsg("End\n");
return object;
}
static void memory_release(struct kref *kref)
{
struct i2c_data *data = container_of(kref, struct i2c_data, ref);
vl53l1_dbgmsg("Enter\n");
kfree(data->vl53l1_data);
kfree(data);
vl53l1_dbgmsg("End\n");
}
void stmvl53l1_put(void *object)
{
struct i2c_data *data = (struct i2c_data *) object;
vl53l1_dbgmsg("Enter\n");
kref_put(&data->ref, memory_release);
vl53l1_dbgmsg("End\n");
}
void __exit stmvl53l1_exit_i2c(void *i2c_object)
{
vl53l1_dbgmsg("Enter\n");
i2c_del_driver(&stmvl53l1_driver);
vl53l1_dbgmsg("End\n");
}

File diff suppressed because it is too large Load diff

Some files were not shown because too many files have changed in this diff Show more