eLab Team / Mbed 2 deprecated myRobot

Dependencies:   mbed WS2812

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers VL53L0X_def.h Source File

VL53L0X_def.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 Copyright © 2016, STMicroelectronics International N.V.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of STMicroelectronics nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
00019 NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
00020 IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
00021 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 *******************************************************************************/
00028 
00029 /**
00030  * @file VL53L0X_def.h
00031  *
00032  * @brief Type definitions for VL53L0X API.   */
00033 
00034 #ifndef _VL53L0X_DEF_H_
00035 #define _VL53L0X_DEF_H_
00036 
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040 
00041 /** @defgroup VL53L0X_globaldefine_group VL53L0X Defines
00042  *  @brief    VL53L0X Defines
00043  *  @{    */
00044 /** PAL SPECIFICATION major version */
00045 #define VL53L0X10_SPECIFICATION_VER_MAJOR   1
00046 /** PAL SPECIFICATION minor version */
00047 #define VL53L0X10_SPECIFICATION_VER_MINOR   2
00048 /** PAL SPECIFICATION sub version */
00049 #define VL53L0X10_SPECIFICATION_VER_SUB     7
00050 /** PAL SPECIFICATION sub version */
00051 #define VL53L0X10_SPECIFICATION_VER_REVISION 1440
00052 
00053 /** VL53L0X PAL IMPLEMENTATION major version */
00054 #define VL53L0X10_IMPLEMENTATION_VER_MAJOR  1
00055 /** VL53L0X PAL IMPLEMENTATION minor version */
00056 #define VL53L0X10_IMPLEMENTATION_VER_MINOR  0
00057 /** VL53L0X PAL IMPLEMENTATION sub version */
00058 #define VL53L0X10_IMPLEMENTATION_VER_SUB    9
00059 /** VL53L0X PAL IMPLEMENTATION sub version */
00060 #define VL53L0X10_IMPLEMENTATION_VER_REVISION   3673
00061 
00062 /** PAL SPECIFICATION major version */
00063 #define VL53L0X_SPECIFICATION_VER_MAJOR     1
00064 /** PAL SPECIFICATION minor version */
00065 #define VL53L0X_SPECIFICATION_VER_MINOR     2
00066 /** PAL SPECIFICATION sub version */
00067 #define VL53L0X_SPECIFICATION_VER_SUB       7
00068 /** PAL SPECIFICATION sub version */
00069 #define VL53L0X_SPECIFICATION_VER_REVISION  1440
00070 
00071 /** VL53L0X PAL IMPLEMENTATION major version */
00072 #define VL53L0X_IMPLEMENTATION_VER_MAJOR    1
00073 /** VL53L0X PAL IMPLEMENTATION minor version */
00074 #define VL53L0X_IMPLEMENTATION_VER_MINOR    1
00075 /** VL53L0X PAL IMPLEMENTATION sub version */
00076 #define VL53L0X_IMPLEMENTATION_VER_SUB      21
00077 /** VL53L0X PAL IMPLEMENTATION sub version */
00078 #define VL53L0X_IMPLEMENTATION_VER_REVISION 4823
00079 
00080 /** FixPoint1616_t is used where fractional values are needed
00081  * Given a floating point value f it's .16 bit point is (int)(f*(1<<16))*/
00082 typedef uint32_t FixPoint1616_t;
00083 #define VL53L0X_FP1616TOFP97(Value) (uint16_t)((Value>>9)&0xFFFF)
00084 #define VL53L0X_FP97TOFP1616(Value) (FixPoint1616_t)(Value<<9)
00085 #define VL53L0X_FP1616TOFP88(Value) (uint16_t)((Value>>8)&0xFFFF)
00086 #define VL53L0X_FP88TOFP1616(Value) (FixPoint1616_t)(Value<<8)
00087 #define VL53L0X_FP1616TOFP412(Value) (uint16_t)((Value>>4)&0xFFFF)
00088 #define VL53L0X_FP412TOFP1616(Value) (FixPoint1616_t)(Value<<4)
00089 #define VL53L0X_FP1616TOFP313(Value) (uint16_t)((Value>>3)&0xFFFF)
00090 #define VL53L0X_FP313TOFP1616(Value) (FixPoint1616_t)(Value<<3)
00091 #define VL53L0X_FP1616TOFP08(Value) (uint8_t)((Value>>8)&0x00FF)
00092 #define VL53L0X_FP08TOFP1616(Value) (FixPoint1616_t)(Value<<8)
00093 #define VL53L0X_FP1616TOFP53(Value) (uint8_t)((Value>>13)&0x00FF)
00094 #define VL53L0X_FP53TOFP1616(Value) (FixPoint1616_t)(Value<<13)
00095 #define VL53L0X_FP1616TOFP102(Value) (uint16_t)((Value>>14)&0x0FFF)
00096 #define VL53L0X_FP102TOFP1616(Value) (FixPoint1616_t)(Value<<12)
00097 #define VL53L0X_MAKEUINT16(lsb, msb) (uint16_t)((((uint16_t)msb)<<8) + (uint16_t)lsb)
00098 
00099 
00100 /**  The device model ID  */ 
00101 #define IDENTIFICATION_MODEL_ID      0x000
00102 
00103 #define VL53L0X_OsDelay(...) wait_ms(2) // 2 msec delay. can also use wait(float secs)/wait_us(int)
00104 
00105 /** Maximum buffer size to be used in i2c */
00106 #define VL53L0X_MAX_I2C_XFER_SIZE   64 
00107   
00108 #define VL53L0X_COPYSTRING(str, ...) strcpy(str, ##__VA_ARGS__)
00109 
00110 /*  Speed of light in um per 1E-10 Seconds  */
00111 #define VL53L0X_SPEED_OF_LIGHT_IN_AIR       2997 
00112 
00113 /** default device address */
00114 #define VL53L0X_DEFAULT_ADDRESS     0x52 /* (8-bit) */
00115 
00116 #define VL53L0X_DEFAULT_MAX_LOOP            2000
00117 
00118 #define VL53L0X_MAX_STRING_LENGTH           32
00119 
00120 /* equivalent to a range sigma of 655.35mm */
00121 #define VL53L0X_SIGMA_ESTIMATE_MAX_VALUE    65535
00122 
00123 #define REF_ARRAY_SPAD_0  0
00124 #define REF_ARRAY_SPAD_5  5
00125 #define REF_ARRAY_SPAD_10 10
00126 
00127 static uint32_t refArrayQuadrants[4] = {REF_ARRAY_SPAD_10, REF_ARRAY_SPAD_5,
00128                                  REF_ARRAY_SPAD_0, REF_ARRAY_SPAD_5 };
00129 
00130 #define  VL53L0X_STRING_DEVICE_INFO_NAME          "VL53L0X cut1.0"
00131 #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS0      "VL53L0X TS0"
00132 #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS1      "VL53L0X TS1"
00133 #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS2      "VL53L0X TS2"
00134 #define  VL53L0X_STRING_DEVICE_INFO_NAME_ES1      "VL53L0X ES1 or later"
00135 #define  VL53L0X_STRING_DEVICE_INFO_TYPE          "VL53L0X"
00136 
00137 /* sensor operating modes */
00138 typedef enum {
00139     range_single_shot_polling = 1,
00140     range_continuous_polling,
00141     range_continuous_interrupt,
00142     range_continuous_polling_low_threshold,
00143     range_continuous_polling_high_threshold,
00144     range_continuous_polling_out_of_window,
00145     range_continuous_interrupt_low_threshold,
00146     range_continuous_interrupt_high_threshold,
00147     range_continuous_interrupt_out_of_window,
00148 } OperatingMode;
00149 
00150 /** @defgroup VL53L0X_DeviceError_group Device Error
00151  *  @brief Device Error code
00152  *
00153  *  This enum is Device specific it should be updated in the implementation
00154  *  Use @a VL53L0X_GetStatusErrorString() to get the string.
00155  *  It is related to Status Register of the Device.
00156  *  @{   */
00157 typedef uint8_t VL53L0X_DeviceError;
00158 #define VL53L0X_DEVICEERROR_NONE                        ((VL53L0X_DeviceError) 0) /*!< 0  NoError  */
00159 #define VL53L0X_DEVICEERROR_VCSELCONTINUITYTESTFAILURE  ((VL53L0X_DeviceError) 1)
00160 #define VL53L0X_DEVICEERROR_VCSELWATCHDOGTESTFAILURE    ((VL53L0X_DeviceError) 2)
00161 #define VL53L0X_DEVICEERROR_NOVHVVALUEFOUND             ((VL53L0X_DeviceError) 3)
00162 #define VL53L0X_DEVICEERROR_MSRCNOTARGET                ((VL53L0X_DeviceError) 4)
00163 #define VL53L0X_DEVICEERROR_SNRCHECK                    ((VL53L0X_DeviceError) 5)
00164 #define VL53L0X_DEVICEERROR_RANGEPHASECHECK             ((VL53L0X_DeviceError) 6)
00165 #define VL53L0X_DEVICEERROR_SIGMATHRESHOLDCHECK         ((VL53L0X_DeviceError) 7)
00166 #define VL53L0X_DEVICEERROR_TCC                         ((VL53L0X_DeviceError) 8)
00167 #define VL53L0X_DEVICEERROR_PHASECONSISTENCY            ((VL53L0X_DeviceError) 9)
00168 #define VL53L0X_DEVICEERROR_MINCLIP                     ((VL53L0X_DeviceError) 10)
00169 #define VL53L0X_DEVICEERROR_RANGECOMPLETE               ((VL53L0X_DeviceError) 11)
00170 #define VL53L0X_DEVICEERROR_ALGOUNDERFLOW               ((VL53L0X_DeviceError) 12)
00171 #define VL53L0X_DEVICEERROR_ALGOOVERFLOW                ((VL53L0X_DeviceError) 13)
00172 #define VL53L0X_DEVICEERROR_RANGEIGNORETHRESHOLD        ((VL53L0X_DeviceError) 14)
00173 /** @} end of VL53L0X_DeviceError_group */
00174 
00175 
00176 /* PAL ERROR strings */
00177 #define  VL53L0X_STRING_ERROR_NONE          "No Error"
00178 #define  VL53L0X_STRING_ERROR_CALIBRATION_WARNING "Calibration Warning Error"
00179 #define  VL53L0X_STRING_ERROR_MIN_CLIPPED   "Min clipped error"
00180 #define  VL53L0X_STRING_ERROR_UNDEFINED     "Undefined error"
00181 #define  VL53L0X_STRING_ERROR_INVALID_PARAMS "Invalid parameters error"
00182 #define  VL53L0X_STRING_ERROR_NOT_SUPPORTED "Not supported error"
00183 #define  VL53L0X_STRING_ERROR_RANGE_ERROR   "Range error"
00184 #define  VL53L0X_STRING_ERROR_TIME_OUT      "Time out error"
00185 #define  VL53L0X_STRING_ERROR_MODE_NOT_SUPPORTED "Mode not supported error"
00186 #define  VL53L0X_STRING_ERROR_BUFFER_TOO_SMALL "Buffer too small"
00187 #define  VL53L0X_STRING_ERROR_GPIO_NOT_EXISTING "GPIO not existing"
00188 #define  VL53L0X_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED "GPIO funct not supported"
00189 #define  VL53L0X_STRING_ERROR_INTERRUPT_NOT_CLEARED "Interrupt not Cleared"
00190 #define  VL53L0X_STRING_ERROR_CONTROL_INTERFACE "Control Interface Error"
00191 #define  VL53L0X_STRING_ERROR_INVALID_COMMAND   "Invalid Command Error"
00192 #define  VL53L0X_STRING_ERROR_DIVISION_BY_ZERO  "Division by zero Error"
00193 #define  VL53L0X_STRING_ERROR_REF_SPAD_INIT     "Reference Spad Init Error"
00194 #define  VL53L0X_STRING_UNKNOW_ERROR_CODE       "Unknown Error Code"
00195 
00196 /* Range Status */
00197 #define  VL53L0X_STRING_RANGESTATUS_NONE                 "No Update"
00198 #define  VL53L0X_STRING_RANGESTATUS_RANGEVALID           "Range Valid"
00199 #define  VL53L0X_STRING_RANGESTATUS_SIGMA                "Sigma Fail"
00200 #define  VL53L0X_STRING_RANGESTATUS_SIGNAL               "Signal Fail"
00201 #define  VL53L0X_STRING_RANGESTATUS_MINRANGE             "Min Range Fail"
00202 #define  VL53L0X_STRING_RANGESTATUS_PHASE                "Phase Fail"
00203 #define  VL53L0X_STRING_RANGESTATUS_HW                   "Hardware Fail"
00204 
00205 /* Range Status */
00206 #define  VL53L0X_STRING_STATE_POWERDOWN         "POWERDOWN State"
00207 #define  VL53L0X_STRING_STATE_WAIT_STATICINIT   "Wait for staticinit State"
00208 #define  VL53L0X_STRING_STATE_STANDBY           "STANDBY State"
00209 #define  VL53L0X_STRING_STATE_IDLE                    "IDLE State"
00210 #define  VL53L0X_STRING_STATE_RUNNING                 "RUNNING State"
00211 #define  VL53L0X_STRING_STATE_UNKNOWN                 "UNKNOWN State"
00212 #define  VL53L0X_STRING_STATE_ERROR                   "ERROR State"
00213 
00214 /* Device Specific */
00215 #define  VL53L0X_STRING_DEVICEERROR_NONE              "No Update"
00216 #define  VL53L0X_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE "VCSEL Continuity Test Failure"
00217 #define  VL53L0X_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE "VCSEL Watchdog Test Failure"
00218 #define  VL53L0X_STRING_DEVICEERROR_NOVHVVALUEFOUND     "No VHV Value found"
00219 #define  VL53L0X_STRING_DEVICEERROR_MSRCNOTARGET        "MSRC No Target Error"
00220 #define  VL53L0X_STRING_DEVICEERROR_SNRCHECK            "SNR Check Exit"
00221 #define  VL53L0X_STRING_DEVICEERROR_RANGEPHASECHECK     "Range Phase Check Error"
00222 #define  VL53L0X_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK "Sigma Threshold Check Error"
00223 #define  VL53L0X_STRING_DEVICEERROR_TCC             "TCC Error"
00224 #define  VL53L0X_STRING_DEVICEERROR_PHASECONSISTENCY    "Phase Consistency Error"
00225 #define  VL53L0X_STRING_DEVICEERROR_MINCLIP             "Min Clip Error"
00226 #define  VL53L0X_STRING_DEVICEERROR_RANGECOMPLETE       "Range Complete"
00227 #define  VL53L0X_STRING_DEVICEERROR_ALGOUNDERFLOW       "Range Algo Underflow Error"
00228 #define  VL53L0X_STRING_DEVICEERROR_ALGOOVERFLOW        "Range Algo Overlow Error"
00229 #define  VL53L0X_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD "Range Ignore Threshold Error"
00230 #define  VL53L0X_STRING_DEVICEERROR_UNKNOWN             "Unknown error code"
00231 
00232 /* Check Enable */
00233 #define  VL53L0X_STRING_CHECKENABLE_SIGMA_FINAL_RANGE       "SIGMA FINAL RANGE"
00234 #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE "SIGNAL RATE FINAL RANGE"
00235 #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_REF_CLIP         "SIGNAL REF CLIP"
00236 #define  VL53L0X_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD  "RANGE IGNORE THRESHOLD"
00237 #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_MSRC        "SIGNAL RATE MSRC"
00238 #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_PRE_RANGE   "SIGNAL RATE PRE RANGE"
00239 
00240 /* Sequence Step */
00241 #define  VL53L0X_STRING_SEQUENCESTEP_TCC                   "TCC"
00242 #define  VL53L0X_STRING_SEQUENCESTEP_DSS                   "DSS"
00243 #define  VL53L0X_STRING_SEQUENCESTEP_MSRC                  "MSRC"
00244 #define  VL53L0X_STRING_SEQUENCESTEP_PRE_RANGE             "PRE RANGE"
00245 #define  VL53L0X_STRING_SEQUENCESTEP_FINAL_RANGE           "FINAL RANGE"
00246 
00247 
00248 /** @defgroup VL53L0X_CheckEnable_group Check Enable list
00249  *  @brief Check Enable code
00250  *
00251  *  Define used to specify the LimitCheckId.
00252  *  Use @a VL53L0X_GetLimitCheckInfo() to get the string.
00253  *  @{    */
00254 #define VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE           0
00255 #define VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE     1
00256 #define VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP             2
00257 #define VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD      3
00258 #define VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC            4
00259 #define VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE       5
00260 #define VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS            6
00261 /** @}  end of VL53L0X_CheckEnable_group */
00262 
00263 
00264 
00265 /** @defgroup VL53L0X_DefineRegisters_group Define Registers
00266  *  @brief List of all the defined registers
00267  *  @{  */
00268 #define VL53L0X_REG_SYSRANGE_START                  0x000
00269 /** mask existing bit in #VL53L0X_REG_SYSRANGE_START*/
00270 #define VL53L0X_REG_SYSRANGE_MODE_MASK              0x0F
00271 /** bit 0 in #VL53L0X_REG_SYSRANGE_START write 1 toggle state in
00272  * continuous mode and arm next shot in single shot mode */
00273 #define VL53L0X_REG_SYSRANGE_MODE_START_STOP        0x01
00274 /** bit 1 write 0 in #VL53L0X_REG_SYSRANGE_START set single shot mode */
00275 #define VL53L0X_REG_SYSRANGE_MODE_SINGLESHOT        0x00
00276 /** bit 1 write 1 in #VL53L0X_REG_SYSRANGE_START set back-to-back operation mode */
00277 #define VL53L0X_REG_SYSRANGE_MODE_BACKTOBACK        0x02
00278 /** bit 2 write 1 in #VL53L0X_REG_SYSRANGE_START set timed operation  mode */
00279 #define VL53L0X_REG_SYSRANGE_MODE_TIMED             0x04
00280 /** bit 3 write 1 in #VL53L0X_REG_SYSRANGE_START set histogram operation mode */
00281 #define VL53L0X_REG_SYSRANGE_MODE_HISTOGRAM                 0x08
00282 #define VL53L0X_REG_SYSTEM_THRESH_HIGH                      0x000C
00283 #define VL53L0X_REG_SYSTEM_THRESH_LOW                       0x000E
00284 #define VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG                  0x0001
00285 #define VL53L0X_REG_SYSTEM_RANGE_CONFIG                     0x0009
00286 #define VL53L0X_REG_SYSTEM_INTERMEASUREMENT_PERIOD          0x0004
00287 #define VL53L0X_REG_SYSTEM_INTERRUPT_CONFIG_GPIO            0x000A
00288 #define VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_DISABLED          0x00
00289 #define VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_LEVEL_LOW         0x01
00290 #define VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_LEVEL_HIGH        0x02
00291 #define VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_OUT_OF_WINDOW     0x03
00292 #define VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY  0x04
00293 #define VL53L0X_REG_GPIO_HV_MUX_ACTIVE_HIGH                 0x0084
00294 #define VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR                  0x000B
00295 
00296 /* Result registers */
00297 #define VL53L0X_REG_RESULT_INTERRUPT_STATUS                 0x0013
00298 #define VL53L0X_REG_RESULT_RANGE_STATUS                     0x0014
00299 #define VL53L0X_REG_RESULT_CORE_PAGE                        1
00300 #define VL53L0X_REG_RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN   0x00BC
00301 #define VL53L0X_REG_RESULT_CORE_RANGING_TOTAL_EVENTS_RTN    0x00C0
00302 #define VL53L0X_REG_RESULT_CORE_AMBIENT_WINDOW_EVENTS_REF   0x00D0
00303 #define VL53L0X_REG_RESULT_CORE_RANGING_TOTAL_EVENTS_REF    0x00D4
00304 #define VL53L0X_REG_RESULT_PEAK_SIGNAL_RATE_REF             0x00B6
00305 /* Algo register */
00306 #define VL53L0X_REG_ALGO_PART_TO_PART_RANGE_OFFSET_MM       0x0028
00307 #define VL53L0X_REG_I2C_SLAVE_DEVICE_ADDRESS                0x008a
00308 /* Check Limit registers */
00309 #define VL53L0X_REG_MSRC_CONFIG_CONTROL                     0x0060
00310 #define VL53L0X_REG_PRE_RANGE_CONFIG_MIN_SNR                0X0027
00311 #define VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW        0x0056
00312 #define VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH       0x0057
00313 #define VL53L0X_REG_PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT      0x0064
00314 #define VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_SNR              0X0067
00315 #define VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW      0x0047
00316 #define VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH     0x0048
00317 #define VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT   0x0044
00318 #define VL53L0X_REG_PRE_RANGE_CONFIG_SIGMA_THRESH_HI        0X0061
00319 #define VL53L0X_REG_PRE_RANGE_CONFIG_SIGMA_THRESH_LO        0X0062
00320 
00321 /* PRE RANGE registers */
00322 #define VL53L0X_REG_PRE_RANGE_CONFIG_VCSEL_PERIOD           0x0050
00323 #define VL53L0X_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI      0x0051
00324 #define VL53L0X_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_LO      0x0052
00325 #define VL53L0X_REG_SYSTEM_HISTOGRAM_BIN                    0x0081
00326 #define VL53L0X_REG_HISTOGRAM_CONFIG_INITIAL_PHASE_SELECT   0x0033
00327 #define VL53L0X_REG_HISTOGRAM_CONFIG_READOUT_CTRL           0x0055
00328 #define VL53L0X_REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD         0x0070
00329 #define VL53L0X_REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI    0x0071
00330 #define VL53L0X_REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_LO    0x0072
00331 #define VL53L0X_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MHz   0x0020
00332 #define VL53L0X_REG_MSRC_CONFIG_TIMEOUT_MACROP              0x0046
00333 #define VL53L0X_REG_SOFT_RESET_GO2_SOFT_RESET_N             0x00bf
00334 #define VL53L0X_REG_IDENTIFICATION_MODEL_ID                 0x00c0
00335 #define VL53L0X_REG_IDENTIFICATION_REVISION_ID              0x00c2
00336 #define VL53L0X_REG_OSC_CALIBRATE_VAL                       0x00f8
00337 #define VL53L0X_REG_GLOBAL_CONFIG_VCSEL_WIDTH               0x0032
00338 #define VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0        0x00B0
00339 #define VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_1        0x00B1
00340 #define VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_2        0x00B2
00341 #define VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_3        0x00B3
00342 #define VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_4        0x00B4
00343 #define VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_5        0x00B5
00344 #define VL53L0X_REG_GLOBAL_CONFIG_REF_EN_START_SELECT       0x00B6
00345 #define VL53L0X_REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD     0x004E /* 0x14E */
00346 #define VL53L0X_REG_DYNAMIC_SPAD_REF_EN_START_OFFSET        0x004F /* 0x14F */
00347 #define VL53L0X_REG_POWER_MANAGEMENT_GO1_POWER_FORCE        0x0080
00348 #define VL53L0X_REG_VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV       0x0089
00349 #define VL53L0X_REG_ALGO_PHASECAL_LIM                       0x0030 /* 0x130 */
00350 #define VL53L0X_REG_ALGO_PHASECAL_CONFIG_TIMEOUT            0x0030
00351 /** @} VL53L0X_DefineRegisters_group */
00352 
00353 
00354 static uint8_t DefaultTuningSettings[] = {
00355 
00356     /* update 02/11/2015_v36 */
00357     0x01, 0xFF, 0x01,    0x01, 0x00, 0x00,    0x01, 0xFF, 0x00,    0x01, 0x09, 0x00,
00358     0x01, 0x10, 0x00,    0x01, 0x11, 0x00,    0x01, 0x24, 0x01,    0x01, 0x25, 0xff,
00359     0x01, 0x75, 0x00,    0x01, 0xFF, 0x01,    0x01, 0x4e, 0x2c,    0x01, 0x48, 0x00,
00360     0x01, 0x30, 0x20,    0x01, 0xFF, 0x00,    0x01, 0x30, 0x09,    /* mja changed from 0x64. */
00361     0x01, 0x54, 0x00,    0x01, 0x31, 0x04,    0x01, 0x32, 0x03,    0x01, 0x40, 0x83,
00362     0x01, 0x46, 0x25,    0x01, 0x60, 0x00,    0x01, 0x27, 0x00,    0x01, 0x50, 0x06,
00363     0x01, 0x51, 0x00,    0x01, 0x52, 0x96,    0x01, 0x56, 0x08,    0x01, 0x57, 0x30,
00364     0x01, 0x61, 0x00,    0x01, 0x62, 0x00,    0x01, 0x64, 0x00,    0x01, 0x65, 0x00,
00365     0x01, 0x66, 0xa0,    0x01, 0xFF, 0x01,    0x01, 0x22, 0x32,    0x01, 0x47, 0x14,
00366     0x01, 0x49, 0xff,    0x01, 0x4a, 0x00,    0x01, 0xFF, 0x00,    0x01, 0x7a, 0x0a,
00367     0x01, 0x7b, 0x00,    0x01, 0x78, 0x21,    0x01, 0xFF, 0x01,    0x01, 0x23, 0x34,
00368     0x01, 0x42, 0x00,    0x01, 0x44, 0xff,    0x01, 0x45, 0x26,    0x01, 0x46, 0x05,
00369     0x01, 0x40, 0x40,    0x01, 0x0E, 0x06,    0x01, 0x20, 0x1a,    0x01, 0x43, 0x40,
00370     0x01, 0xFF, 0x00,    0x01, 0x34, 0x03,    0x01, 0x35, 0x44,    0x01, 0xFF, 0x01,
00371     0x01, 0x31, 0x04,    0x01, 0x4b, 0x09,    0x01, 0x4c, 0x05,    0x01, 0x4d, 0x04,
00372     0x01, 0xFF, 0x00,    0x01, 0x44, 0x00,    0x01, 0x45, 0x20,    0x01, 0x47, 0x08,
00373     0x01, 0x48, 0x28,    0x01, 0x67, 0x00,    0x01, 0x70, 0x04,    0x01, 0x71, 0x01,
00374     0x01, 0x72, 0xfe,    0x01, 0x76, 0x00,    0x01, 0x77, 0x00,    0x01, 0xFF, 0x01,
00375     0x01, 0x0d, 0x01,    0x01, 0xFF, 0x00,    0x01, 0x80, 0x01,    0x01, 0x01, 0xF8,
00376     0x01, 0xFF, 0x01,    0x01, 0x8e, 0x01,    0x01, 0x00, 0x01,    0x01, 0xFF, 0x00,
00377     0x01, 0x80, 0x00,    0x00, 0x00, 0x00
00378 };
00379 
00380 static uint8_t InterruptThresholdSettings[] = {
00381     /* Start of Interrupt Threshold Settings */
00382     0x1, 0xff, 0x00,    0x1, 0x80, 0x01,    0x1, 0xff, 0x01,    0x1, 0x00, 0x00,
00383     0x1, 0xff, 0x01,    0x1, 0x4f, 0x02,    0x1, 0xFF, 0x0E,    0x1, 0x00, 0x03,
00384     0x1, 0x01, 0x84,    0x1, 0x02, 0x0A,    0x1, 0x03, 0x03,    0x1, 0x04, 0x08,
00385     0x1, 0x05, 0xC8,    0x1, 0x06, 0x03,    0x1, 0x07, 0x8D,    0x1, 0x08, 0x08,
00386     0x1, 0x09, 0xC6,    0x1, 0x0A, 0x01,    0x1, 0x0B, 0x02,    0x1, 0x0C, 0x00,
00387     0x1, 0x0D, 0xD5,    0x1, 0x0E, 0x18,    0x1, 0x0F, 0x12,    0x1, 0x10, 0x01,
00388     0x1, 0x11, 0x82,    0x1, 0x12, 0x00,    0x1, 0x13, 0xD5,    0x1, 0x14, 0x18,
00389     0x1, 0x15, 0x13,    0x1, 0x16, 0x03,    0x1, 0x17, 0x86,    0x1, 0x18, 0x0A,
00390     0x1, 0x19, 0x09,    0x1, 0x1A, 0x08,    0x1, 0x1B, 0xC2,    0x1, 0x1C, 0x03,
00391     0x1, 0x1D, 0x8F,    0x1, 0x1E, 0x0A,    0x1, 0x1F, 0x06,    0x1, 0x20, 0x01,
00392     0x1, 0x21, 0x02,    0x1, 0x22, 0x00,    0x1, 0x23, 0xD5,    0x1, 0x24, 0x18,
00393     0x1, 0x25, 0x22,    0x1, 0x26, 0x01,    0x1, 0x27, 0x82,    0x1, 0x28, 0x00,
00394     0x1, 0x29, 0xD5,    0x1, 0x2A, 0x18,    0x1, 0x2B, 0x0B,    0x1, 0x2C, 0x28,
00395     0x1, 0x2D, 0x78,    0x1, 0x2E, 0x28,    0x1, 0x2F, 0x91,    0x1, 0x30, 0x00,
00396     0x1, 0x31, 0x0B,    0x1, 0x32, 0x00,    0x1, 0x33, 0x0B,    0x1, 0x34, 0x00,
00397     0x1, 0x35, 0xA1,    0x1, 0x36, 0x00,    0x1, 0x37, 0xA0,    0x1, 0x38, 0x00,
00398     0x1, 0x39, 0x04,    0x1, 0x3A, 0x28,    0x1, 0x3B, 0x30,    0x1, 0x3C, 0x0C,
00399     0x1, 0x3D, 0x04,    0x1, 0x3E, 0x0F,    0x1, 0x3F, 0x79,    0x1, 0x40, 0x28,
00400     0x1, 0x41, 0x1E,    0x1, 0x42, 0x2F,    0x1, 0x43, 0x87,    0x1, 0x44, 0x00,
00401     0x1, 0x45, 0x0B,    0x1, 0x46, 0x00,    0x1, 0x47, 0x0B,    0x1, 0x48, 0x00,
00402     0x1, 0x49, 0xA7,    0x1, 0x4A, 0x00,    0x1, 0x4B, 0xA6,    0x1, 0x4C, 0x00,
00403     0x1, 0x4D, 0x04,    0x1, 0x4E, 0x01,    0x1, 0x4F, 0x00,    0x1, 0x50, 0x00,
00404     0x1, 0x51, 0x80,    0x1, 0x52, 0x09,    0x1, 0x53, 0x08,    0x1, 0x54, 0x01,
00405     0x1, 0x55, 0x00,    0x1, 0x56, 0x0F,    0x1, 0x57, 0x79,    0x1, 0x58, 0x09,
00406     0x1, 0x59, 0x05,    0x1, 0x5A, 0x00,    0x1, 0x5B, 0x60,    0x1, 0x5C, 0x05,
00407     0x1, 0x5D, 0xD1,    0x1, 0x5E, 0x0C,    0x1, 0x5F, 0x3C,    0x1, 0x60, 0x00,
00408     0x1, 0x61, 0xD0,    0x1, 0x62, 0x0B,    0x1, 0x63, 0x03,    0x1, 0x64, 0x28,
00409     0x1, 0x65, 0x10,    0x1, 0x66, 0x2A,    0x1, 0x67, 0x39,    0x1, 0x68, 0x0B,
00410     0x1, 0x69, 0x02,    0x1, 0x6A, 0x28,    0x1, 0x6B, 0x10,    0x1, 0x6C, 0x2A,
00411     0x1, 0x6D, 0x61,    0x1, 0x6E, 0x0C,    0x1, 0x6F, 0x00,    0x1, 0x70, 0x0F,
00412     0x1, 0x71, 0x79,    0x1, 0x72, 0x00,    0x1, 0x73, 0x0B,    0x1, 0x74, 0x00,
00413     0x1, 0x75, 0x0B,    0x1, 0x76, 0x00,    0x1, 0x77, 0xA1,    0x1, 0x78, 0x00,
00414     0x1, 0x79, 0xA0,    0x1, 0x7A, 0x00,    0x1, 0x7B, 0x04,    0x1, 0xFF, 0x04,
00415     0x1, 0x79, 0x1D,    0x1, 0x7B, 0x27,    0x1, 0x96, 0x0E,    0x1, 0x97, 0xFE,
00416     0x1, 0x98, 0x03,    0x1, 0x99, 0xEF,    0x1, 0x9A, 0x02,    0x1, 0x9B, 0x44,
00417     0x1, 0x73, 0x07,    0x1, 0x70, 0x01,    0x1, 0xff, 0x01,    0x1, 0x00, 0x01,
00418     0x1, 0xff, 0x00,    
00419     0x0, 0x00, 0x00};
00420 
00421 /** @defgroup VL53L0X_GpioFunctionality_group Gpio Functionality
00422  *  @brief Defines the different functionalities for the device GPIO(s)
00423  *  @{   */
00424 typedef uint8_t VL53L0X_GpioFunctionality;
00425 #define VL53L0X_GPIOFUNCTIONALITY_OFF                     \
00426     ((VL53L0X_GpioFunctionality)  0) /*!< NO Interrupt  */
00427 #define VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW   \
00428     ((VL53L0X_GpioFunctionality)  1) /*!< Level Low (value < thresh_low)  */
00429 #define VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH   \
00430     ((VL53L0X_GpioFunctionality)  2) /*!< Level High (value > thresh_high) */
00431 #define VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT    \
00432     ((VL53L0X_GpioFunctionality)  3)
00433 /*!< Out Of Window (value < thresh_low OR value > thresh_high)  */
00434 #define VL53L0X_GPIOFUNCTIONALITY_NEW_MEASURE_READY        \
00435     ((VL53L0X_GpioFunctionality)  4) /*!< New Sample Ready  */
00436 /** @} end of VL53L0X_GpioFunctionality_group */
00437 
00438 
00439 /** @brief Defines the parameters of the Get Version Functions  */
00440 typedef struct {
00441     uint32_t     revision ; /*!< revision number */
00442     uint8_t      major ;    /*!< major number */
00443     uint8_t      minor ;    /*!< minor number */
00444     uint8_t      build ;    /*!< build number */
00445 } VL53L0X_Version_t;
00446 
00447 /** @defgroup VL53L0X_define_Error_group Error and Warning code returned by API
00448  *  The following DEFINE are used to identify the PAL ERROR
00449  *  @{   */
00450 typedef int8_t VL53L0X_Error;
00451 #define VL53L0X_ERROR_NONE              ((VL53L0X_Error)    0)
00452 #define VL53L0X_ERROR_CALIBRATION_WARNING ((VL53L0X_Error) -1)
00453 /*!< Warning invalid calibration data may be in used
00454     \a  VL53L0X_InitData()
00455     \a VL53L0X_GetOffsetCalibrationData
00456     \a VL53L0X_SetOffsetCalibrationData */
00457 #define VL53L0X_ERROR_MIN_CLIPPED       ((VL53L0X_Error) -2)
00458 /*!< Warning parameter passed was clipped to min before to be applied */
00459 #define VL53L0X_ERROR_UNDEFINED         ((VL53L0X_Error) -3)
00460 /*!< Unqualified error */
00461 #define VL53L0X_ERROR_INVALID_PARAMS    ((VL53L0X_Error) -4)
00462 /*!< Parameter passed is invalid or out of range */
00463 #define VL53L0X_ERROR_NOT_SUPPORTED     ((VL53L0X_Error) -5)
00464 /*!< Function is not supported in current mode or configuration */
00465 #define VL53L0X_ERROR_RANGE_ERROR       ((VL53L0X_Error) -6)
00466 /*!< Device report a ranging error interrupt status */
00467 #define VL53L0X_ERROR_TIME_OUT          ((VL53L0X_Error) -7)
00468 /*!< Aborted due to time out */
00469 #define VL53L0X_ERROR_MODE_NOT_SUPPORTED ((VL53L0X_Error) -8)
00470 /*!< Asked mode is not supported by the device */
00471 #define VL53L0X_ERROR_BUFFER_TOO_SMALL  ((VL53L0X_Error) -9)
00472 /*!< ... */
00473 #define VL53L0X_ERROR_GPIO_NOT_EXISTING ((VL53L0X_Error) -10)
00474 /*!< User tried to setup a non-existing GPIO pin */
00475 #define VL53L0X_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED  ((VL53L0X_Error) -11)
00476 /*!< unsupported GPIO functionality */
00477 #define VL53L0X_ERROR_INTERRUPT_NOT_CLEARED ((VL53L0X_Error) -12)
00478 /*!< Error during interrupt clear */
00479 #define VL53L0X_ERROR_CONTROL_INTERFACE ((VL53L0X_Error) -20)
00480 /*!< error reported from IO functions */
00481 #define VL53L0X_ERROR_INVALID_COMMAND   ((VL53L0X_Error) -30)
00482 /*!< The command is not allowed in the current device state (power down) */
00483 #define VL53L0X_ERROR_DIVISION_BY_ZERO  ((VL53L0X_Error) -40)
00484 /*!< In the function a division by zero occurs */
00485 #define VL53L0X_ERROR_REF_SPAD_INIT         ((VL53L0X_Error) -50)
00486 /*!< Error during reference SPAD initialization */
00487 /** @} VL53L0X_define_Error_group */
00488 
00489 
00490 /** @defgroup VL53L0X_define_DeviceModes_group Defines Device modes
00491  *  Defines all possible modes for the device
00492  *  @{    */
00493 typedef uint8_t VL53L0X_DeviceModes;
00494 #define VL53L0X_DEVICEMODE_SINGLE_RANGING   ((VL53L0X_DeviceModes)  0)
00495 #define VL53L0X_DEVICEMODE_CONTINUOUS_RANGING   ((VL53L0X_DeviceModes)  1)
00496 #define VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING ((VL53L0X_DeviceModes) 3)
00497 #define VL53L0X_DEVICEMODE_SINGLE_ALS       ((VL53L0X_DeviceModes) 10)
00498 #define VL53L0X_DEVICEMODE_GPIO_DRIVE       ((VL53L0X_DeviceModes) 20)
00499 #define VL53L0X_DEVICEMODE_GPIO_OSC     ((VL53L0X_DeviceModes) 21)
00500 /* ... Modes to be added depending on device */
00501 /** @} VL53L0X_define_DeviceModes_group */
00502 
00503 
00504 /** @defgroup VL53L0X_define_PowerModes_group List of available Power Modes
00505  *  List of available Power Modes
00506  *  @{   */
00507 typedef uint8_t VL53L0X_PowerModes;
00508 #define VL53L0X_POWERMODE_STANDBY_LEVEL1 ((VL53L0X_PowerModes) 0)
00509 /*!< Standby level 1 */
00510 #define VL53L0X_POWERMODE_STANDBY_LEVEL2 ((VL53L0X_PowerModes) 1)
00511 /*!< Standby level 2 */
00512 #define VL53L0X_POWERMODE_IDLE_LEVEL1   ((VL53L0X_PowerModes) 2)
00513 /*!< Idle level 1 */
00514 #define VL53L0X_POWERMODE_IDLE_LEVEL2   ((VL53L0X_PowerModes) 3)
00515 /*!< Idle level 2 */
00516 /** @} VL53L0X_define_PowerModes_group */
00517 
00518 /** @defgroup VL53L0X_define_State_group Defines the current status of the device
00519  *  Defines the current status of the device
00520  *  @{ */
00521 typedef uint8_t VL53L0X_State;
00522 #define VL53L0X_STATE_POWERDOWN      ((VL53L0X_State)  0)
00523 /*!< Device is in HW reset  */
00524 #define VL53L0X_STATE_WAIT_STATICINIT ((VL53L0X_State)  1)
00525 /*!< Device is initialized and wait for static initialization  */
00526 #define VL53L0X_STATE_STANDBY        ((VL53L0X_State)  2)
00527 /*!< Device is in Low power Standby mode   */
00528 #define VL53L0X_STATE_IDLE           ((VL53L0X_State)  3)
00529 /*!< Device has been initialized and ready to do measurements  */
00530 #define VL53L0X_STATE_RUNNING        ((VL53L0X_State)  4)
00531 /*!< Device is performing measurement */
00532 #define VL53L0X_STATE_UNKNOWN        ((VL53L0X_State)  98)
00533 /*!< Device is in unknown state and need to be rebooted  */
00534 #define VL53L0X_STATE_ERROR          ((VL53L0X_State)  99)
00535 /*!< Device is in error state and need to be rebooted  */
00536 /** @} VL53L0X_define_State_group */
00537 
00538 
00539 /** @brief Defines the parameters of the Get Device Info Functions  */
00540 typedef struct {
00541     char Name[VL53L0X_MAX_STRING_LENGTH];
00542     /*!< Name of the Device e.g. Left_Distance */
00543     char Type[VL53L0X_MAX_STRING_LENGTH];
00544     /*!< Type of the Device e.g VL53L0X */
00545     char ProductId[VL53L0X_MAX_STRING_LENGTH];
00546     /*!< Product Identifier String  */
00547     uint8_t ProductType;
00548     /*!< Product Type, VL53L0X = 1, VL53L1 = 2 */
00549     uint8_t ProductRevisionMajor;
00550     /*!< Product revision major */
00551     uint8_t ProductRevisionMinor;
00552     /*!< Product revision minor */
00553 } VL53L0X_DeviceInfo_t;
00554 
00555 /** @brief Defines all parameters for the device   */
00556 typedef struct {
00557     VL53L0X_DeviceModes DeviceMode;
00558     /*!< Defines type of measurement to be done for the next measurement */
00559     uint32_t MeasurementTimingBudget_us;
00560     /*!< Defines the allowed total time for a single measurement */
00561     uint32_t InterMeasurementPeriod_ms;
00562     /*!< Defines time between two consecutive measurements (between two
00563      *  measurement starts). If set to 0 means back-to-back mode */
00564     uint8_t XTalkCompensationEnable;
00565     /*!< Tells if Crosstalk compensation shall be enable or not  */
00566     uint16_t XTalkCompensationRange_mm;
00567     /*!< CrossTalk compensation range in _mm     */
00568     FixPoint1616_t XTalkCompensationRate_MHz;
00569     /*!< CrossTalk compensation rate in Mega counts per seconds.
00570      *  Expressed in 16.16 fixed point format.  */
00571     int32_t RangeOffset_um;
00572     /*!< Range offset adjustment (mm) last programmed.  */
00573     uint8_t LimitChecksEnable[VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS];
00574     /*!< This Array store all the  6 Limit Check enables for this device. */
00575     uint8_t LimitChecksStatus[VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS];
00576     /*!< This Array store all the  6 Status of the check linked to last measurement. */
00577     FixPoint1616_t LimitChecksValue[VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS];
00578     /*!< This Array store all the Limit Check value for this device */
00579     uint8_t WrapAroundCheckEnable;
00580     /*!< Tells if Wrap Around Check shall be enable or not */
00581 } VL53L0X_DeviceParameters_t;
00582 
00583 /**
00584  * @struct VL53L0X_RangeData_t
00585  * @brief Range measurement data.  */
00586 typedef struct {
00587     uint16_t Range_mm;  /*!< range distance in _mm. */
00588     uint16_t RangeDMax_mm; /*!< Tells what is the maximum detection distance of the device
00589      * in current setup and environment conditions (Filled when applicable) */
00590     FixPoint1616_t SignalRateRtn_MHz; /*!< Return signal rate (MHz), as 16.16 fix point, effectively a measure of target reflectance.*/
00591     FixPoint1616_t AmbientRateRtn_MHz; /*!< Return ambient rate (MHz), as 16.16 fix point, effectively a measure of the ambient light.*/
00592     uint16_t EffectiveSpadRtnCount; /*!< Return the effective SPAD count for the return signal, as a 8.8 fix point value. */
00593     uint8_t RangeFractionalPart; /*!< Fractional part of range distance. Final value is a  FixPoint168 value.; only noise :( */
00594     uint8_t RangeStatus; /*!< Range Status for the current measurement. Value = 0 means value is valid. See \ref RangeStatusPage */
00595     FixPoint1616_t SigmaEstimate;       /*!< Estimated Sigma - based on ambient & VCSEL rates and signal_total_events */
00596 } VL53L0X_RangingMeasurementData_t;
00597 
00598 
00599 #define VL53L0X_REF_SPAD_BUFFER_SIZE 6
00600 typedef struct {
00601     // merged in here all parts of "VL53L0X_DeviceSpecificParameters_t DeviceSpecificParameters;"
00602     FixPoint1616_t OscFrequency_MHz;    /* Frequency used */
00603     uint16_t LastEncodedTimeout;        /* last encoded Time out used for timing budget*/
00604     VL53L0X_GpioFunctionality Pin0GpioFunctionality; /* store the functionality of the GPIO: pin0 */
00605     uint32_t FinalRangeTimeout_us;/*!< Execution time of the final range*/
00606     uint8_t FinalRangeVcselPulsePeriod; /*!< Vcsel pulse period (pll clocks) for the final range measurement*/
00607     uint32_t PreRangeTimeout_us;    /*!< Execution time of the final range*/
00608     uint8_t PreRangeVcselPulsePeriod;   /*!< Vcsel pulse period (pll clocks) for the pre-range measurement*/
00609     uint8_t ReadDataFromDeviceDone; /* Indicate if read from device has been done (==1) or not (==0) */
00610     uint8_t ModuleId;               /* Module ID */
00611     uint8_t Revision;               /* test Revision */
00612     char ProductId[VL53L0X_MAX_STRING_LENGTH]; /* Product Identifier String  */
00613     uint8_t ReferenceSpadCount; /* used for ref spad management */
00614     uint8_t ReferenceSpadType;  /* used for ref spad management */
00615     uint8_t RefSpadsInitialised; /* reports if ref spads are initialised. */
00616     uint32_t PartUIDUpper; /*!< Unique Part ID Upper */
00617     uint32_t PartUIDLower; /*!< Unique Part ID Lower */
00618     FixPoint1616_t SignalRateMeasFixed400mm; /*!< Peek Signal rate at 400 mm*/
00619     
00620     // Merged in here the VL53L0X_SpadData_t SpadData;      /*!< Spad Data; Enables and Good-Map */
00621     uint8_t RefSpadEnables[VL53L0X_REF_SPAD_BUFFER_SIZE]; /*!< Reference Spad Enables */
00622     uint8_t RefGoodSpadMap[VL53L0X_REF_SPAD_BUFFER_SIZE]; /*!< Reference Spad Good Spad Map */
00623     
00624     // Merged in here all parts of DeviceParams_t
00625     int32_t  Part2PartOffsetNVM_um; /*!< backed up NVM value */
00626     int32_t  Part2PartOffsetAdjustNVM_um; /*!< backed up NVM value representing additional offset adjustment */
00627     uint8_t SequenceConfig;             /*!< Internal value for the sequence config */
00628     uint8_t RangeFractionalEnable;      /*!< Enable/Disable fractional part of ranging data */
00629     VL53L0X_State PalState;             /*!< Current state of the PAL for this device */
00630     VL53L0X_PowerModes PowerMode;       /*!< Current Power Mode; Stdby1/2, Idle1/2   */
00631     uint16_t SigmaEstRefArray;          /*!< Reference array sigma value in 1/100th of [mm] e.g. 100 = 1mm; loaded from tuning settings */
00632     uint16_t SigmaEstEffPulseWidth;     /*!< Effective Pulse width for sigma estimate in 1/100th of ns e.g. 900 = 9.0ns */
00633     uint16_t SigmaEstEffAmbWidth;       /*!< Effective Ambient width for sigma estimate in 1/100th of ns e.g. 500 = 5.0ns */
00634     uint8_t StopVariable;               /*!< StopVariable used during the stop sequence */
00635     uint16_t targetRefRate;             /*!< Target Ambient Rate for Ref spad management */
00636     FixPoint1616_t LastSignalRef_MHz;   /*!< Latest Signal ref in MHz */
00637     uint8_t *pTuningSettingsPointer;    /*!< Pointer for alternative Tuning Settings table */
00638     uint8_t UseInternalTuningSettings;  /*!< Indicate if we use  Tuning Settings table, default = True */
00639     uint16_t LinearityCorrectiveGain;   /*!< Linearity Corrective Gain value in x1000 */
00640     uint16_t DmaxCalRange_mm;   /*!< Dmax Calibration Range _mm */
00641     FixPoint1616_t DmaxCalSignalRateRtn_MHz;/*!< Dmax Calibration Signal Rate Return _MHz */
00642     
00643 } VL53L0X_DevData_t;
00644 
00645  /*  All these macros were replaced with following regulator expressions: 
00646 a)  Search for: \QVL53L0X_SETARRAYPARAMETERFIELD(\E(\s*)([A-Z\d_]+)[[:punct:]](\s*)([A-Z\d_]+)[[:punct:]](\s*)([A-Z\d_\*]+)\Q);\E
00647     Replace by: Data.CurrentParameters.\2[\4] = \6;
00648     to replace this:  VL53L0X_SETARRAYPARAMETERFIELD(field, index, value);  
00649     by this:  Data.CurrentParameters.field[index] = value; 
00650 
00651 b)  Search for: \QVL53L0X_GETARRAYPARAMETERFIELD(\E(\s*)([A-Z\d_]+)[[:punct:]](\s*)([A-Z\d_]+)[[:punct:]](\s*)([A-Z\d_\*]+)\Q);\E
00652     Replace by: \6 = Data.CurrentParameters.\2[\4];
00653     to replace this: VL53L0X_GETARRAYPARAMETERFIELD(  LimitChecksValue, limit_check_id, temp_fix1616); 
00654     by this:  temp_fix1616 = Data.CurrentParameters.LimitChecksValue[limit_check_id]; 
00655 
00656 c)  Search for: \QVL53L0X_SETPARAMETERFIELD(\E(\s*)([A-Z\d_]+)[[:punct:]](\s*)([A-Z\d_\*]+)\Q);\E
00657     Replace by: Data.CurrentParameters.\2 = \4;
00658     to replace this:  VL53L0X_SETPARAMETERFIELD(field, value);  
00659     by this:  Data.CurrentParameters.field = value 
00660 
00661 d)  Search for: \QVL53L0X_GETPARAMETERFIELD(\E(\s*)([A-Z\d_]+)[[:punct:]](\s*)([A-Z\d_\*]+)\Q);\E
00662     Replace by: \4 = Data.CurrentParameters.\2 ;
00663     to replace this: VL53L0X_GETPARAMET ERFIELD(field, variable);  
00664     by this:  variable = Data.CurrentParameters.field; 
00665 
00666 d)  Search for: \QPALDevDataSet(\E(\s*)([A-Z\d_]+)[[:punct:]](\s*)([A-Z\d_\*]+)\Q);\E
00667     Replace by: Data.\2 = \4;
00668     to replace this: PALDevDataSet(field, value);
00669     by this:  Data.field = value;
00670 
00671 d)  Search for: \QPALDevDataGet(\E(\s*)([A-Z\d]+)\Q)\E
00672     Replace by: Data.\2
00673     to replace this: PALDevDataGet(field)
00674     by this:  Data.field
00675 
00676 #define PALDevDataSet(field, value) (Data.field)=(value)
00677 #define PALDevDataGet(field) (Data.field)
00678 #define VL53L0X_SETPARAMETERFIELD(field, value) Data.CurrentParameters.field = value
00679 #define VL53L0X_GETPARAMETERFIELD(field, variable) variable = Data.CurrentParameters.field
00680 #define VL53L0X_SETARRAYPARAMETERFIELD(field, index, value) Data.CurrentParameters.field[index] = value
00681 #define VL53L0X_GETARRAYPARAMETERFIELD(field, index, variable)  variable = Data.CurrentParameters.field[index]
00682 #define VL53L0X_SETDEVICESPECIFICPARAMETER(field, value) Data.field = value
00683 #define VL53L0X_GETDEVICESPECIFICPARAMETER(field)        Data.field
00684  */
00685  
00686  
00687 /** @defgroup VL53L0X_define_InterruptPolarity_group Defines the Polarity  of the Interrupt
00688  *  Defines the Polarity of the Interrupt
00689  *  @{
00690  */
00691 typedef uint8_t VL53L0X_InterruptPolarity;
00692 #define VL53L0X_INTERRUPTPOLARITY_LOW      ((VL53L0X_InterruptPolarity) 0)
00693 /*!< Set active low polarity best setup for falling edge. */
00694 #define VL53L0X_INTERRUPTPOLARITY_HIGH     ((VL53L0X_InterruptPolarity) 1)
00695 /*!< Set active high polarity best setup for rising edge. */
00696 
00697 /** @} VL53L0X_define_InterruptPolarity_group */
00698 
00699 
00700 /** @defgroup VL53L0X_define_VcselPeriod_group Vcsel Period Defines
00701  *  Defines the range measurement for which to access the vcsel period.
00702  *  @{  */
00703 typedef uint8_t VL53L0X_VcselPeriod;
00704 #define VL53L0X_VCSEL_PERIOD_PRE_RANGE  ((VL53L0X_VcselPeriod) 0)
00705 /*!<Identifies the pre-range vcsel period. */
00706 #define VL53L0X_VCSEL_PERIOD_FINAL_RANGE ((VL53L0X_VcselPeriod) 1)
00707 /*!<Identifies the final range vcsel period. */
00708 
00709 /** @} VL53L0X_define_VcselPeriod_group */
00710 /** @defgroup VL53L0X_define_SchedulerSequence_group Defines the steps
00711  * carried out by the scheduler during a range measurement.
00712  *  @{
00713  *  Defines the states of all the steps in the scheduler i.e. enabled/disabled. */
00714 typedef struct {
00715     uint8_t      TccOn;         /*!<Reports if Target Centre Check On  */
00716     uint8_t      MsrcOn;        /*!<Reports if MSRC On  */
00717     uint8_t      DssOn;         /*!<Reports if DSS On  */
00718     uint8_t      PreRangeOn;    /*!<Reports if Pre-Range On */
00719     uint8_t      FinalRangeOn;  /*!<Reports if Final-Range On  */
00720 } VL53L0X_SchedulerSequenceSteps_t;
00721 /** @} VL53L0X_define_SchedulerSequence_group */
00722 
00723 /** @defgroup VL53L0X_define_SequenceStepId_group 
00724  *  Defines the the sequence steps performed during ranging..
00725  *  @{  */
00726 typedef uint8_t VL53L0X_SequenceStepId;
00727 #define  VL53L0X_SEQUENCESTEP_TCC         ((VL53L0X_VcselPeriod) 0) /*!<Target CentreCheck identifier. */
00728 #define  VL53L0X_SEQUENCESTEP_DSS         ((VL53L0X_VcselPeriod) 1) /*!<Dynamic Spad Selection function Identifier. */
00729 #define  VL53L0X_SEQUENCESTEP_MSRC        ((VL53L0X_VcselPeriod) 2) /*!<Minimum Signal Rate Check function Identifier. */
00730 #define  VL53L0X_SEQUENCESTEP_PRE_RANGE   ((VL53L0X_VcselPeriod) 3) /*!<Pre-Range check Identifier. */
00731 #define  VL53L0X_SEQUENCESTEP_FINAL_RANGE ((VL53L0X_VcselPeriod) 4) /*!<Final Range Check Identifier. */
00732 #define  VL53L0X_SEQUENCESTEP_NUMBER_OF_CHECKS           5 /*!<Number of Sequence Step Managed by the API. */
00733 /** @} VL53L0X_define_SequenceStepId_group */
00734 
00735 
00736 typedef enum {
00737     Range_Config_DEFAULT,
00738     Range_Config_LONG_RANGE,
00739     Range_Config_HIGH_ACCURACY,
00740     Range_Config_HIGH_SPEED
00741 } VL53L0X_RangingConfig;
00742 /** @} VL53L0X_define_SequenceStepId_group */
00743 
00744 /** @} VL53L0X_globaldefine_group */
00745 
00746 
00747 #ifdef __cplusplus
00748 }
00749 #endif
00750 
00751 
00752 #endif /* _VL53L0X_DEF_H_ */