Pierrick Mekerke / VL53L0Xforrobotix

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   X_NUCLEO_53L0A1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers VL53L0X.h Source File

VL53L0X.h

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 #ifndef __VL53L0X_CLASS_H
00030 #define __VL53L0X_CLASS_H
00031 
00032 
00033 #ifdef _MSC_VER
00034 #   ifdef VL53L0X_API_EXPORTS
00035 #       define VL53L0X_API  __declspec(dllexport)
00036 #   else
00037 #       define VL53L0X_API
00038 #   endif
00039 #else
00040 #   define VL53L0X_API
00041 #endif
00042 
00043 
00044 /* Includes ------------------------------------------------------------------*/
00045 #include "mbed.h"
00046 #include "RangeSensor.h"
00047 #include "DevI2C.h"
00048 #include "PinNames.h"
00049 #include "VL53L0X_def.h"
00050 #include "VL53L0X_platform.h"
00051 #include "Stmpe1600.h"
00052 
00053 
00054 /**
00055  * The device model ID
00056  */
00057 #define IDENTIFICATION_MODEL_ID                 0x000
00058 
00059 
00060 #define STATUS_OK              0x00
00061 #define STATUS_FAIL            0x01
00062 
00063 #define VL53L0X_OsDelay(...) wait_ms(2) // 2 msec delay. can also use wait(float secs)/wait_us(int)
00064 
00065 #ifdef USE_EMPTY_STRING
00066 #define  VL53L0X_STRING_DEVICE_INFO_NAME                             ""
00067 #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS0                         ""
00068 #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS1                         ""
00069 #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS2                         ""
00070 #define  VL53L0X_STRING_DEVICE_INFO_NAME_ES1                         ""
00071 #define  VL53L0X_STRING_DEVICE_INFO_TYPE                             ""
00072 
00073 /* PAL ERROR strings */
00074 #define  VL53L0X_STRING_ERROR_NONE                                   ""
00075 #define  VL53L0X_STRING_ERROR_CALIBRATION_WARNING                    ""
00076 #define  VL53L0X_STRING_ERROR_MIN_CLIPPED                            ""
00077 #define  VL53L0X_STRING_ERROR_UNDEFINED                              ""
00078 #define  VL53L0X_STRING_ERROR_INVALID_PARAMS                         ""
00079 #define  VL53L0X_STRING_ERROR_NOT_SUPPORTED                          ""
00080 #define  VL53L0X_STRING_ERROR_RANGE_ERROR                            ""
00081 #define  VL53L0X_STRING_ERROR_TIME_OUT                               ""
00082 #define  VL53L0X_STRING_ERROR_MODE_NOT_SUPPORTED                     ""
00083 #define  VL53L0X_STRING_ERROR_BUFFER_TOO_SMALL                       ""
00084 #define  VL53L0X_STRING_ERROR_GPIO_NOT_EXISTING                      ""
00085 #define  VL53L0X_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED       ""
00086 #define  VL53L0X_STRING_ERROR_CONTROL_INTERFACE                      ""
00087 #define  VL53L0X_STRING_ERROR_INVALID_COMMAND                        ""
00088 #define  VL53L0X_STRING_ERROR_DIVISION_BY_ZERO                       ""
00089 #define  VL53L0X_STRING_ERROR_REF_SPAD_INIT                          ""
00090 #define  VL53L0X_STRING_ERROR_NOT_IMPLEMENTED                        ""
00091 
00092 #define  VL53L0X_STRING_UNKNOW_ERROR_CODE                            ""
00093 
00094 
00095 
00096 /* Range Status */
00097 #define  VL53L0X_STRING_RANGESTATUS_NONE                             ""
00098 #define  VL53L0X_STRING_RANGESTATUS_RANGEVALID                       ""
00099 #define  VL53L0X_STRING_RANGESTATUS_SIGMA                            ""
00100 #define  VL53L0X_STRING_RANGESTATUS_SIGNAL                           ""
00101 #define  VL53L0X_STRING_RANGESTATUS_MINRANGE                         ""
00102 #define  VL53L0X_STRING_RANGESTATUS_PHASE                            ""
00103 #define  VL53L0X_STRING_RANGESTATUS_HW                               ""
00104 
00105 
00106 /* Range Status */
00107 #define  VL53L0X_STRING_STATE_POWERDOWN                              ""
00108 #define  VL53L0X_STRING_STATE_WAIT_STATICINIT                        ""
00109 #define  VL53L0X_STRING_STATE_STANDBY                                ""
00110 #define  VL53L0X_STRING_STATE_IDLE                                   ""
00111 #define  VL53L0X_STRING_STATE_RUNNING                                ""
00112 #define  VL53L0X_STRING_STATE_UNKNOWN                                ""
00113 #define  VL53L0X_STRING_STATE_ERROR                                  ""
00114 
00115 
00116 /* Device Specific */
00117 #define  VL53L0X_STRING_DEVICEERROR_NONE                             ""
00118 #define  VL53L0X_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE       ""
00119 #define  VL53L0X_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE         ""
00120 #define  VL53L0X_STRING_DEVICEERROR_NOVHVVALUEFOUND                  ""
00121 #define  VL53L0X_STRING_DEVICEERROR_MSRCNOTARGET                     ""
00122 #define  VL53L0X_STRING_DEVICEERROR_SNRCHECK                         ""
00123 #define  VL53L0X_STRING_DEVICEERROR_RANGEPHASECHECK                  ""
00124 #define  VL53L0X_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK              ""
00125 #define  VL53L0X_STRING_DEVICEERROR_TCC                              ""
00126 #define  VL53L0X_STRING_DEVICEERROR_PHASECONSISTENCY                 ""
00127 #define  VL53L0X_STRING_DEVICEERROR_MINCLIP                          ""
00128 #define  VL53L0X_STRING_DEVICEERROR_RANGECOMPLETE                    ""
00129 #define  VL53L0X_STRING_DEVICEERROR_ALGOUNDERFLOW                    ""
00130 #define  VL53L0X_STRING_DEVICEERROR_ALGOOVERFLOW                     ""
00131 #define  VL53L0X_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD             ""
00132 #define  VL53L0X_STRING_DEVICEERROR_UNKNOWN                          ""
00133 
00134 /* Check Enable */
00135 #define  VL53L0X_STRING_CHECKENABLE_SIGMA_FINAL_RANGE                ""
00136 #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE          ""
00137 #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_REF_CLIP                  ""
00138 #define  VL53L0X_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD           ""
00139 
00140 /* Sequence Step */
00141 #define  VL53L0X_STRING_SEQUENCESTEP_TCC                             ""
00142 #define  VL53L0X_STRING_SEQUENCESTEP_DSS                             ""
00143 #define  VL53L0X_STRING_SEQUENCESTEP_MSRC                            ""
00144 #define  VL53L0X_STRING_SEQUENCESTEP_PRE_RANGE                       ""
00145 #define  VL53L0X_STRING_SEQUENCESTEP_FINAL_RANGE                     ""
00146 #else
00147 #define  VL53L0X_STRING_DEVICE_INFO_NAME          "VL53L0X cut1.0"
00148 #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS0      "VL53L0X TS0"
00149 #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS1      "VL53L0X TS1"
00150 #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS2      "VL53L0X TS2"
00151 #define  VL53L0X_STRING_DEVICE_INFO_NAME_ES1      "VL53L0X ES1 or later"
00152 #define  VL53L0X_STRING_DEVICE_INFO_TYPE          "VL53L0X"
00153 
00154 /* PAL ERROR strings */
00155 #define  VL53L0X_STRING_ERROR_NONE \
00156             "No Error"
00157 #define  VL53L0X_STRING_ERROR_CALIBRATION_WARNING \
00158             "Calibration Warning Error"
00159 #define  VL53L0X_STRING_ERROR_MIN_CLIPPED \
00160             "Min clipped error"
00161 #define  VL53L0X_STRING_ERROR_UNDEFINED \
00162             "Undefined error"
00163 #define  VL53L0X_STRING_ERROR_INVALID_PARAMS \
00164             "Invalid parameters error"
00165 #define  VL53L0X_STRING_ERROR_NOT_SUPPORTED \
00166             "Not supported error"
00167 #define  VL53L0X_STRING_ERROR_RANGE_ERROR \
00168             "Range error"
00169 #define  VL53L0X_STRING_ERROR_TIME_OUT \
00170             "Time out error"
00171 #define  VL53L0X_STRING_ERROR_MODE_NOT_SUPPORTED \
00172             "Mode not supported error"
00173 #define  VL53L0X_STRING_ERROR_BUFFER_TOO_SMALL \
00174             "Buffer too small"
00175 #define  VL53L0X_STRING_ERROR_GPIO_NOT_EXISTING \
00176             "GPIO not existing"
00177 #define  VL53L0X_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED \
00178             "GPIO funct not supported"
00179 #define  VL53L0X_STRING_ERROR_INTERRUPT_NOT_CLEARED \
00180             "Interrupt not Cleared"
00181 #define  VL53L0X_STRING_ERROR_CONTROL_INTERFACE \
00182             "Control Interface Error"
00183 #define  VL53L0X_STRING_ERROR_INVALID_COMMAND \
00184             "Invalid Command Error"
00185 #define  VL53L0X_STRING_ERROR_DIVISION_BY_ZERO \
00186             "Division by zero Error"
00187 #define  VL53L0X_STRING_ERROR_REF_SPAD_INIT \
00188             "Reference Spad Init Error"
00189 #define  VL53L0X_STRING_ERROR_NOT_IMPLEMENTED \
00190             "Not implemented error"
00191 
00192 #define  VL53L0X_STRING_UNKNOW_ERROR_CODE \
00193             "Unknown Error Code"
00194 
00195 
00196 
00197 /* Range Status */
00198 #define  VL53L0X_STRING_RANGESTATUS_NONE                 "No Update"
00199 #define  VL53L0X_STRING_RANGESTATUS_RANGEVALID           "Range Valid"
00200 #define  VL53L0X_STRING_RANGESTATUS_SIGMA                "Sigma Fail"
00201 #define  VL53L0X_STRING_RANGESTATUS_SIGNAL               "Signal Fail"
00202 #define  VL53L0X_STRING_RANGESTATUS_MINRANGE             "Min Range Fail"
00203 #define  VL53L0X_STRING_RANGESTATUS_PHASE                "Phase Fail"
00204 #define  VL53L0X_STRING_RANGESTATUS_HW                   "Hardware Fail"
00205 
00206 
00207 /* Range Status */
00208 #define  VL53L0X_STRING_STATE_POWERDOWN               "POWERDOWN State"
00209 #define  VL53L0X_STRING_STATE_WAIT_STATICINIT \
00210             "Wait for staticinit State"
00211 #define  VL53L0X_STRING_STATE_STANDBY                 "STANDBY State"
00212 #define  VL53L0X_STRING_STATE_IDLE                    "IDLE State"
00213 #define  VL53L0X_STRING_STATE_RUNNING                 "RUNNING State"
00214 #define  VL53L0X_STRING_STATE_UNKNOWN                 "UNKNOWN State"
00215 #define  VL53L0X_STRING_STATE_ERROR                   "ERROR State"
00216 
00217 
00218 /* Device Specific */
00219 #define  VL53L0X_STRING_DEVICEERROR_NONE              "No Update"
00220 #define  VL53L0X_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE \
00221             "VCSEL Continuity Test Failure"
00222 #define  VL53L0X_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE \
00223             "VCSEL Watchdog Test Failure"
00224 #define  VL53L0X_STRING_DEVICEERROR_NOVHVVALUEFOUND \
00225             "No VHV Value found"
00226 #define  VL53L0X_STRING_DEVICEERROR_MSRCNOTARGET \
00227             "MSRC No Target Error"
00228 #define  VL53L0X_STRING_DEVICEERROR_SNRCHECK \
00229             "SNR Check Exit"
00230 #define  VL53L0X_STRING_DEVICEERROR_RANGEPHASECHECK \
00231             "Range Phase Check Error"
00232 #define  VL53L0X_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK \
00233             "Sigma Threshold Check Error"
00234 #define  VL53L0X_STRING_DEVICEERROR_TCC \
00235             "TCC Error"
00236 #define  VL53L0X_STRING_DEVICEERROR_PHASECONSISTENCY \
00237             "Phase Consistency Error"
00238 #define  VL53L0X_STRING_DEVICEERROR_MINCLIP \
00239             "Min Clip Error"
00240 #define  VL53L0X_STRING_DEVICEERROR_RANGECOMPLETE \
00241             "Range Complete"
00242 #define  VL53L0X_STRING_DEVICEERROR_ALGOUNDERFLOW \
00243             "Range Algo Underflow Error"
00244 #define  VL53L0X_STRING_DEVICEERROR_ALGOOVERFLOW \
00245             "Range Algo Overlow Error"
00246 #define  VL53L0X_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD \
00247             "Range Ignore Threshold Error"
00248 #define  VL53L0X_STRING_DEVICEERROR_UNKNOWN \
00249             "Unknown error code"
00250 
00251 /* Check Enable */
00252 #define  VL53L0X_STRING_CHECKENABLE_SIGMA_FINAL_RANGE \
00253             "SIGMA FINAL RANGE"
00254 #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE \
00255             "SIGNAL RATE FINAL RANGE"
00256 #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_REF_CLIP \
00257             "SIGNAL REF CLIP"
00258 #define  VL53L0X_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD \
00259             "RANGE IGNORE THRESHOLD"
00260 #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_MSRC \
00261             "SIGNAL RATE MSRC"
00262 #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_PRE_RANGE \
00263             "SIGNAL RATE PRE RANGE"
00264 
00265 /* Sequence Step */
00266 #define  VL53L0X_STRING_SEQUENCESTEP_TCC                   "TCC"
00267 #define  VL53L0X_STRING_SEQUENCESTEP_DSS                   "DSS"
00268 #define  VL53L0X_STRING_SEQUENCESTEP_MSRC                  "MSRC"
00269 #define  VL53L0X_STRING_SEQUENCESTEP_PRE_RANGE             "PRE RANGE"
00270 #define  VL53L0X_STRING_SEQUENCESTEP_FINAL_RANGE           "FINAL RANGE"
00271 #endif /* USE_EMPTY_STRING */
00272 
00273 /* sensor operating modes */
00274 typedef enum {
00275     range_single_shot_polling = 1,
00276     range_continuous_polling,
00277     range_continuous_interrupt,
00278     range_continuous_polling_low_threshold,
00279     range_continuous_polling_high_threshold,
00280     range_continuous_polling_out_of_window,
00281     range_continuous_interrupt_low_threshold,
00282     range_continuous_interrupt_high_threshold,
00283     range_continuous_interrupt_out_of_window,
00284 } OperatingMode;
00285 
00286 /** default device address */
00287 #define VL53L0X_DEFAULT_ADDRESS     0x52 /* (8-bit) */
00288 
00289 /* Classes -------------------------------------------------------------------*/
00290 /** Class representing a VL53L0 sensor component
00291  */
00292 class VL53L0X : public RangeSensor
00293 {
00294 public:
00295     /** Constructor
00296      * @param[in] &i2c device I2C to be used for communication
00297      * @param[in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
00298      * @param[in] dev_addr device address, 0x29 by default
00299      */
00300     VL53L0X(DevI2C *i2c, DigitalOut *pin, PinName pin_gpio1, uint8_t dev_addr = VL53L0X_DEFAULT_ADDRESS) : _dev_i2c(i2c),
00301         _gpio0(pin)
00302     {
00303         _my_device.I2cDevAddr  = dev_addr;
00304         _my_device.comms_type  = 1; // VL53L0X_COMMS_I2C
00305         _my_device.comms_speed_khz  = 400;
00306         _device = &_my_device;
00307         _expgpio0 = NULL;
00308         if (pin_gpio1 != NC) {
00309             _gpio1Int = new InterruptIn(pin_gpio1);
00310         } else {
00311             _gpio1Int = NULL;
00312         }
00313     }
00314     
00315 
00316     /** Constructor 2 (STMPE1600DigiOut)
00317      * @param[in] i2c device I2C to be used for communication
00318      * @param[in] &pin Gpio Expander STMPE1600DigiOut pin to be used as component GPIO_0 CE
00319      * @param[in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
00320      * @param[in] device address, 0x29 by default
00321      */
00322     VL53L0X(DevI2C *i2c, Stmpe1600DigiOut *pin, PinName pin_gpio1,
00323             uint8_t dev_addr = VL53L0X_DEFAULT_ADDRESS) : _dev_i2c(i2c), _expgpio0(pin)
00324     {
00325         _my_device.I2cDevAddr  = dev_addr;
00326         _my_device.comms_type  = 1; // VL53L0X_COMMS_I2C
00327         _my_device.comms_speed_khz  = 400;
00328         _device = &_my_device;
00329         _gpio0 = NULL;
00330         if (pin_gpio1 != NC) {
00331             _gpio1Int = new InterruptIn(pin_gpio1);
00332         } else {
00333             _gpio1Int = NULL;
00334         }
00335     }
00336 
00337     /** Destructor
00338      */
00339     virtual ~VL53L0X()
00340     {
00341         if (_gpio1Int != NULL) {
00342             delete _gpio1Int;
00343         }
00344     }
00345 
00346     /*** Interface Methods ***/
00347     /*** High level API ***/
00348     /**
00349      * @brief       PowerOn the sensor
00350      * @return      void
00351      */
00352     /* turns on the sensor */
00353     void VL53L0X_on(void)
00354     {
00355         if (_gpio0) {
00356             *_gpio0 = 1;
00357         } else {
00358             if (_expgpio0) {
00359                 *_expgpio0 = 1;
00360             }
00361         }
00362         wait_ms(10);
00363     }
00364 
00365     /**
00366      * @brief       PowerOff the sensor
00367      * @return      void
00368      */
00369     /* turns off the sensor */
00370     void VL53L0X_off(void)
00371     {
00372         if (_gpio0) {
00373             *_gpio0 = 0;
00374         } else {
00375             if (_expgpio0) {
00376                 *_expgpio0 = 0;
00377             }
00378         }
00379         wait_ms(10);
00380     }
00381 
00382 
00383     /**
00384      * @brief       Initialize the sensor with default values
00385      * @return      "0" on success
00386      */
00387     int init_sensor(uint8_t new_addr);
00388 
00389     /**
00390      * @brief       Start the measure indicated by operating mode
00391      * @param[in]   operating_mode specifies requested measure
00392      * @param[in]   fptr specifies call back function must be !NULL in case of interrupt measure
00393      * @return      "0" on success
00394      */
00395     int start_measurement(OperatingMode operating_mode, void (*fptr)(void));
00396 
00397     /**
00398      * @brief       Get results for the measure indicated by operating mode
00399      * @param[in]   operating_mode specifies requested measure results
00400      * @param[out]  p_data pointer to the MeasureData_t structure to read data in to
00401      * @return      "0" on success
00402      */
00403     int get_measurement(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *p_data);
00404 
00405     /**
00406      * @brief       Stop the currently running measure indicate by operating_mode
00407      * @param[in]   operating_mode specifies requested measure to stop
00408      * @return      "0" on success
00409      */
00410     int stop_measurement(OperatingMode operating_mode);
00411 
00412     /**
00413      * @brief       Interrupt handling func to be called by user after an INT is occourred
00414      * @param[in]   opeating_mode indicating the in progress measure
00415      * @param[out]  Data pointer to the MeasureData_t structure to read data in to
00416      * @return      "0" on success
00417      */
00418     int handle_irq(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *data);
00419 
00420     /**
00421      * @brief       Enable interrupt measure IRQ
00422      * @return      "0" on success
00423      */
00424     void enable_interrupt_measure_detection_irq(void)
00425     {
00426         if (_gpio1Int != NULL) {
00427             _gpio1Int->enable_irq();
00428         }
00429     }
00430 
00431     /**
00432      * @brief       Disable interrupt measure IRQ
00433      * @return      "0" on success
00434      */
00435     void disable_interrupt_measure_detection_irq(void)
00436     {
00437         if (_gpio1Int != NULL) {
00438             _gpio1Int->disable_irq();
00439         }
00440     }
00441 
00442     /**
00443      * @brief       Attach a function to call when an interrupt is detected, i.e. measurement is ready
00444      * @param[in]   fptr pointer to call back function to be called whenever an interrupt occours
00445      * @return      "0" on success
00446      */
00447     void attach_interrupt_measure_detection_irq(void (*fptr)(void))
00448     {
00449         if (_gpio1Int != NULL) {
00450             _gpio1Int->rise(fptr);
00451         }
00452     }
00453 
00454     /** Wrapper functions */
00455     /** @defgroup api_init Init functions
00456      *  @brief    API init functions
00457      *  @ingroup  api_hl
00458      *  @{
00459      */
00460 
00461     /**
00462      *
00463      * @brief One time device initialization
00464      *
00465      * To be called once and only once after device is brought out of reset (Chip enable) and booted.
00466      *
00467      * @par Function Description
00468      * When not used after a fresh device "power up" or reset, it may return @a #CALIBRATION_WARNING
00469      * meaning wrong calibration data may have been fetched from device that can result in ranging offset error\n
00470      * If application cannot execute device reset or need to run VL53L0X_data_init  multiple time
00471      * then it  must ensure proper offset calibration saving and restore on its own
00472      * by using @a VL53L0X_get_offset_calibration_data_micro_meter() on first power up and then @a VL53L0X_set_offset_calibration_data_micro_meter() all all subsequent init
00473      *
00474      * @param void
00475      * @return     "0" on success,  @a #CALIBRATION_WARNING if failed
00476      */
00477     virtual int init(void *init)
00478     {
00479         return VL53L0X_data_init(_device);
00480     }
00481 
00482     /**
00483       * @brief  Prepare device for operation
00484       * @par Function Description
00485       * Does static initialization and reprogram common default settings \n
00486       * Device is prepared for new measure, ready single shot ranging or ALS typical polling operation\n
00487       * After prepare user can : \n
00488       * @li Call other API function to set other settings\n
00489       * @li Configure the interrupt pins, etc... \n
00490       * @li Then start ranging or ALS operations in single shot or continuous mode
00491       *
00492       * @param void
00493       * @return  "0" on success
00494       */
00495     int prepare()
00496     {
00497         VL53L0X_Error status = VL53L0X_ERROR_NONE;
00498         uint32_t ref_spad_count;
00499         uint8_t is_aperture_spads;
00500         uint8_t vhv_settings;
00501         uint8_t phase_cal;
00502 
00503         if (status == VL53L0X_ERROR_NONE) {
00504             printf("Call of VL53L0X_StaticInit\r\n");
00505             status = VL53L0X_static_init(_device);   // Device Initialization
00506         }
00507 
00508         if (status == VL53L0X_ERROR_NONE) {
00509             printf("Call of VL53L0X_PerformRefCalibration\r\n");
00510             status = VL53L0X_perform_ref_calibration(_device,
00511                      &vhv_settings, &phase_cal);  // Device Initialization
00512         }
00513 
00514         if (status == VL53L0X_ERROR_NONE) {
00515             printf("Call of VL53L0X_PerformRefSpadManagement\r\n");
00516             status = VL53L0X_perform_ref_spad_management(_device,
00517                      &ref_spad_count, &is_aperture_spads);  // Device Initialization
00518 //            printf ("refSpadCount = %d, isApertureSpads = %d\r\n", refSpadCount, isApertureSpads);
00519         }
00520 
00521         return status;
00522     }
00523 
00524     /**
00525     * @brief Start continuous ranging mode
00526     *
00527     * @details End user should ensure device is in idle state and not already running
00528     * @return  "0" on success
00529     */
00530     int range_start_continuous_mode()
00531     {
00532         int status;
00533         status = VL53L0X_set_device_mode(_device, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING);
00534 
00535         if (status == VL53L0X_ERROR_NONE) {
00536             //printf ("Call of VL53L0X_StartMeasurement\r\n");
00537             status = VL53L0X_start_measurement(_device);
00538         }
00539 
00540         return status;
00541     }
00542 
00543     /**
00544      * @brief Get ranging result and only that
00545      *
00546      * @par Function Description
00547      * Unlike @a VL53L0X_get_ranging_measurement_data() this function only retrieves the range in millimeter \n
00548      * It does any required up-scale translation\n
00549      * It can be called after success status polling or in interrupt mode \n
00550      * @warning these function is not doing wrap around filtering \n
00551      * This function doesn't perform any data ready check!
00552      *
00553      * @param p_data  Pointer to range distance
00554      * @return        "0" on success
00555      */
00556     virtual int get_distance(uint32_t *p_data)
00557     {
00558         int status = 0;
00559         VL53L0X_RangingMeasurementData_t p_ranging_measurement_data;
00560 
00561         status = start_measurement(range_single_shot_polling, NULL);
00562         if (!status) {
00563             status = get_measurement(range_single_shot_polling, &p_ranging_measurement_data);
00564         }
00565         if (p_ranging_measurement_data.RangeStatus == 0) {
00566             // we have a valid range.
00567             *p_data = p_ranging_measurement_data.RangeMilliMeter;
00568         } else {
00569             *p_data = 0;
00570             status = VL53L0X_ERROR_RANGE_ERROR;
00571         }
00572         stop_measurement(range_single_shot_polling);
00573         return status;
00574     }
00575 
00576     /** @}  */
00577 
00578     /**
00579      * @brief Set new device i2c address
00580      *
00581      * After completion the device will answer to the new address programmed.
00582      *
00583      * @param new_addr  The new i2c address (7bit)
00584      * @return          "0" on success
00585      */
00586     int set_device_address(int new_addr)
00587     {
00588         int status;
00589 
00590         status = VL53L0X_set_device_address(_device, new_addr);
00591         if (!status) {
00592             _device->I2cDevAddr  = new_addr;
00593         }
00594         return status;
00595 
00596     }
00597 
00598     /**
00599      * @brief Clear given system interrupt condition
00600      *
00601      * @par Function Description
00602      * Clear given interrupt cause by writing into register #SYSTEM_INTERRUPT_CLEAR register.
00603      * @param dev        The device
00604      * @param int_clear  Which interrupt source to clear. Use any combinations of #INTERRUPT_CLEAR_RANGING , #INTERRUPT_CLEAR_ALS , #INTERRUPT_CLEAR_ERROR.
00605      * @return           "0" on success
00606      */
00607     int clear_interrupt(uint8_t int_clear)
00608     {
00609         return VL53L0X_clear_interrupt_mask(_device, int_clear);
00610     }
00611 
00612     /**
00613      *
00614      * @brief Get the 53L0 device
00615      *
00616      * To be called to retrive the internal device descriptor to allow usage of 
00617      * low level API having device as parameter. To be called  after set_device_address()
00618      * (if any).
00619      *
00620      * @par Function Description
00621      * To be called if low level API usage is needed as those functions requires
00622      * device as a parameter.TICINIT.
00623      *
00624      * @note This function return a pointer to an object internal structure
00625      *
00626      * @param   dev                   ptr to ptr to Device Handle
00627      * @return  VL53L0X_ERROR_NONE     Success
00628      * @return  "Other error code"    See ::VL53L0X_Error
00629      */
00630     VL53L0X_Error vl53l0x_get_device(VL53L0X_DEV *dev)
00631 {
00632    *dev = _device;
00633    return VL53L0X_ERROR_NONE;
00634 }             
00635 
00636     /**
00637      *
00638      * @brief One time device initialization
00639      *
00640      * To be called once and only once after device is brought out of reset
00641      * (Chip enable) and booted see @a VL53L0X_WaitDeviceBooted()
00642      *
00643      * @par Function Description
00644      * When not used after a fresh device "power up" or reset, it may return
00645      * @a #VL53L0X_ERROR_CALIBRATION_WARNING meaning wrong calibration data
00646      * may have been fetched from device that can result in ranging offset error\n
00647      * If application cannot execute device reset or need to run VL53L0X_DataInit
00648      * multiple time then it  must ensure proper offset calibration saving and
00649      * restore on its own by using @a VL53L0X_GetOffsetCalibrationData() on first
00650      * power up and then @a VL53L0X_SetOffsetCalibrationData() in all subsequent init
00651      * This function will change the VL53L0X_State from VL53L0X_STATE_POWERDOWN to
00652      * VL53L0X_STATE_WAIT_STATICINIT.
00653      *
00654      * @note This function accesses to the device
00655      *
00656      * @param   dev                   Device Handle
00657      * @return  VL53L0X_ERROR_NONE    Success
00658      * @return  "Other error code"    See ::VL53L0X_Error
00659      */
00660     VL53L0X_Error VL53L0X_data_init(VL53L0X_DEV dev);
00661 
00662     /**
00663      * @brief Do basic device init (and eventually patch loading)
00664      * This function will change the VL53L0X_State from
00665      * VL53L0X_STATE_WAIT_STATICINIT to VL53L0X_STATE_IDLE.
00666      * In this stage all default setting will be applied.
00667      *
00668      * @note This function Access to the device
00669      *
00670      * @param   dev                   Device Handle
00671      * @return  VL53L0X_ERROR_NONE    Success
00672      * @return  "Other error code"    See ::VL53L0X_Error
00673      */
00674     VL53L0X_Error VL53L0X_static_init(VL53L0X_DEV dev);
00675 
00676     /**
00677      * @brief Perform Reference Calibration
00678      *
00679      * @details Perform a reference calibration of the Device.
00680      * This function should be run from time to time before doing
00681      * a ranging measurement.
00682      * This function will launch a special ranging measurement, so
00683      * if interrupt are enable an interrupt will be done.
00684      * This function will clear the interrupt generated automatically.
00685      *
00686      * @warning This function is a blocking function
00687      *
00688      * @note This function Access to the device
00689      *
00690      * @param   dev                  Device Handle
00691      * @param   p_vhv_settings       Pointer to vhv settings parameter.
00692      * @param   p_phase_cal          Pointer to PhaseCal parameter.
00693      * @return  VL53L0X_ERROR_NONE   Success
00694      * @return  "Other error code"   See ::VL53L0X_Error
00695      */
00696     VL53L0X_Error VL53L0X_perform_ref_calibration(VL53L0X_DEV dev, uint8_t *p_vhv_settings,
00697             uint8_t *p_phase_cal);
00698 
00699     /**
00700      * @brief Get Reference Calibration Parameters
00701      *
00702      * @par Function Description
00703      * Get Reference Calibration Parameters.
00704      *
00705      * @note This function Access to the device
00706      *
00707      * @param   dev                            Device Handle
00708      * @param   p_vhv_settings                 Pointer to VHV parameter
00709      * @param   p_phase_cal                    Pointer to PhaseCal Parameter
00710      * @return  VL53L0X_ERROR_NONE             Success
00711      * @return  "Other error code"             See ::VL53L0X_Error
00712      */
00713     VL53L0X_Error VL53L0X_get_ref_calibration(VL53L0X_DEV dev,
00714             uint8_t *p_vhv_settings, uint8_t *p_phase_cal);
00715 
00716     VL53L0X_Error VL53L0X_set_ref_calibration(VL53L0X_DEV dev,
00717             uint8_t vhv_settings, uint8_t phase_cal);
00718 
00719     /**
00720      * @brief Performs Reference Spad Management
00721      *
00722      * @par Function Description
00723      * The reference SPAD initialization procedure determines the minimum amount
00724      * of reference spads to be enables to achieve a target reference signal rate
00725      * and should be performed once during initialization.
00726      *
00727      * @note This function Access to the device
00728      *
00729      * @note This function change the device mode to
00730      * VL53L0X_DEVICEMODE_SINGLE_RANGING
00731      *
00732      * @param   dev                          Device Handle
00733      * @param   ref_spad_count               Reports ref Spad Count
00734      * @param   is_aperture_spads            Reports if spads are of type
00735      *                                       aperture or non-aperture.
00736      *                                       1:=aperture, 0:=Non-Aperture
00737      * @return  VL53L0X_ERROR_NONE           Success
00738      * @return  VL53L0X_ERROR_REF_SPAD_INIT  Error in the Ref Spad procedure.
00739      * @return  "Other error code"           See ::VL53L0X_Error
00740      */
00741     VL53L0X_Error VL53L0X_perform_ref_spad_management(VL53L0X_DEV dev,
00742             uint32_t *ref_spad_count, uint8_t *is_aperture_spads);
00743 
00744     /**
00745      * @brief Applies Reference SPAD configuration
00746      *
00747      * @par Function Description
00748      * This function applies a given number of reference spads, identified as
00749      * either Aperture or Non-Aperture.
00750      * The requested spad count and type are stored within the device specific
00751      * parameters data for access by the host.
00752      *
00753      * @note This function Access to the device
00754      *
00755      * @param   dev                          Device Handle
00756      * @param   refSpadCount                 Number of ref spads.
00757      * @param   is_aperture_spads            Defines if spads are of type
00758      *                                       aperture or non-aperture.
00759      *                                       1:=aperture, 0:=Non-Aperture
00760      * @return  VL53L0X_ERROR_NONE           Success
00761      * @return  VL53L0X_ERROR_REF_SPAD_INIT  Error in the in the reference
00762      *                                       spad configuration.
00763      * @return  "Other error code"           See ::VL53L0X_Error
00764      */
00765     VL53L0X_Error VL53L0X_set_reference_spads(VL53L0X_DEV dev,
00766             uint32_t refSpadCount, uint8_t is_aperture_spads);
00767 
00768     /**
00769      * @brief Retrieves SPAD configuration
00770      *
00771      * @par Function Description
00772      * This function retrieves the current number of applied reference spads
00773      * and also their type : Aperture or Non-Aperture.
00774      *
00775      * @note This function Access to the device
00776      *
00777      * @param   dev                          Device Handle
00778      * @param   p_spad_count                 Number ref Spad Count
00779      * @param   p_is_aperture_spads          Reports if spads are of type
00780      *                                       aperture or non-aperture.
00781      *                                       1:=aperture, 0:=Non-Aperture
00782      * @return  VL53L0X_ERROR_NONE           Success
00783      * @return  VL53L0X_ERROR_REF_SPAD_INIT  Error in the in the reference
00784      *                                       spad configuration.
00785      * @return  "Other error code"           See ::VL53L0X_Error
00786      */
00787     VL53L0X_Error VL53L0X_get_reference_spads(VL53L0X_DEV dev,
00788             uint32_t *p_spad_count, uint8_t *p_is_aperture_spads);
00789 
00790     /**
00791      * @brief Get part to part calibration offset
00792      *
00793      * @par Function Description
00794      * Should only be used after a successful call to @a VL53L0X_DataInit to backup
00795      * device NVM value
00796      *
00797      * @note This function Access to the device
00798      *
00799      * @param   dev                                     Device Handle
00800      * @param   p_offset_calibration_data_micro_meter   Return part to part
00801      * calibration offset from device (microns)
00802      * @return  VL53L0X_ERROR_NONE                      Success
00803      * @return  "Other error code"                      See ::VL53L0X_Error
00804      */
00805     VL53L0X_Error VL53L0X_get_offset_calibration_data_micro_meter(VL53L0X_DEV dev,
00806             int32_t *p_offset_calibration_data_micro_meter);
00807     /**
00808      * Set or over-hide part to part calibration offset
00809      * \sa VL53L0X_DataInit()   VL53L0X_GetOffsetCalibrationDataMicroMeter()
00810      *
00811      * @note This function Access to the device
00812      *
00813      * @param   dev                                      Device Handle
00814      * @param   p_offset_calibration_data_micro_meter    Offset (microns)
00815      * @return  VL53L0X_ERROR_NONE                       Success
00816      * @return  "Other error code"                       See ::VL53L0X_Error
00817      */
00818     VL53L0X_Error VL53L0X_set_offset_calibration_data_micro_meter(VL53L0X_DEV dev,
00819             int32_t offset_calibration_data_micro_meter);
00820 
00821     VL53L0X_Error VL53L0X_perform_offset_calibration(VL53L0X_DEV dev,
00822             FixPoint1616_t cal_distance_milli_meter,
00823             int32_t *p_offset_micro_meter);
00824 
00825     VL53L0X_Error VL53L0X_perform_xtalk_calibration(VL53L0X_DEV dev,
00826             FixPoint1616_t xtalk_cal_distance,
00827             FixPoint1616_t *p_xtalk_compensation_rate_mega_cps);
00828 
00829     /**
00830      * @brief Perform XTalk Measurement
00831      *
00832      * @details Measures the current cross talk from glass in front
00833      * of the sensor.
00834      * This functions performs a histogram measurement and uses the results
00835      * to measure the crosstalk. For the function to be successful, there
00836      * must be no target in front of the sensor.
00837      *
00838      * @warning This function is a blocking function
00839      *
00840      * @warning This function is not supported when the final range
00841      * vcsel clock period is set below 10 PCLKS.
00842      *
00843      * @note This function Access to the device
00844      *
00845      * @param   dev                    Device Handle
00846      * @param   timeout_ms             Histogram measurement duration.
00847      * @param   p_xtalk_per_spad       Output parameter containing the crosstalk
00848      *                                 measurement result, in MCPS/Spad.
00849      *                                 Format fixpoint 16:16.
00850      * @param   p_ambient_too_high     Output parameter which indicate that
00851      *                                 pXtalkPerSpad is not good if the Ambient
00852      *                                 is too high.
00853      * @return  VL53L0X_ERROR_NONE     Success
00854      * @return  VL53L0X_ERROR_INVALID_PARAMS vcsel clock period not supported
00855      *                                 for this operation.
00856      *                                 Must not be less than 10PCLKS.
00857      * @return  "Other error code"     See ::VL53L0X_Error
00858      */
00859     VL53L0X_Error VL53L0X_perform_xtalk_measurement(VL53L0X_DEV dev,
00860             uint32_t timeout_ms, FixPoint1616_t *p_xtalk_per_spad,
00861             uint8_t *p_ambient_too_high);
00862 
00863     /**
00864      * @brief Enable/Disable Cross talk compensation feature
00865      *
00866      * @note This function is not Implemented.
00867      * Enable/Disable Cross Talk by set to zero the Cross Talk value
00868      * by using @a VL53L0X_SetXTalkCompensationRateMegaCps().
00869      *
00870      * @param  dev                           Device Handle
00871      * @param  x_talk_compensation_enable    Cross talk compensation
00872      *                                       to be set 0=disabled else = enabled
00873      * @return VL53L0X_ERROR_NOT_IMPLEMENTED Not implemented
00874      */
00875     VL53L0X_Error VL53L0X_set_x_talk_compensation_enable(VL53L0X_DEV dev,
00876             uint8_t x_talk_compensation_enable);
00877 
00878     /**
00879      * @brief Get Cross talk compensation rate
00880      *
00881      * @note This function is not Implemented.
00882      * Enable/Disable Cross Talk by set to zero the Cross Talk value by
00883      * using @a VL53L0X_SetXTalkCompensationRateMegaCps().
00884      *
00885      * @param   dev                           Device Handle
00886      * @param   p_x_talk_compensation_enable  Pointer to the Cross talk compensation
00887      *                                        state 0=disabled or 1 = enabled
00888      * @return  VL53L0X_ERROR_NOT_IMPLEMENTED Not implemented
00889      */
00890     VL53L0X_Error VL53L0X_get_x_talk_compensation_enable(VL53L0X_DEV dev,
00891             uint8_t *p_x_talk_compensation_enable);
00892     /**
00893      * @brief Set Cross talk compensation rate
00894      *
00895      * @par Function Description
00896      * Set Cross talk compensation rate.
00897      *
00898      * @note This function Access to the device
00899      *
00900      * @param   dev                                 Device Handle
00901      * @param   x_talk_compensation_rate_mega_cps   Compensation rate in
00902      *                                              Mega counts per second
00903      *                                              (16.16 fix point) see
00904      *                                              datasheet for details
00905      * @return  VL53L0X_ERROR_NONE                  Success
00906      * @return  "Other error code"                  See ::VL53L0X_Error
00907      */
00908     VL53L0X_Error VL53L0X_set_x_talk_compensation_rate_mega_cps(VL53L0X_DEV dev,
00909             FixPoint1616_t x_talk_compensation_rate_mega_cps);
00910 
00911     /**
00912      * @brief Get Cross talk compensation rate
00913      *
00914      * @par Function Description
00915      * Get Cross talk compensation rate.
00916      *
00917      * @note This function Access to the device
00918      *
00919      * @param   dev                                 Device Handle
00920      * @param   p_xtalk_compensation_rate_mega_cps  Pointer to Compensation rate
00921      *                                              in Mega counts per second
00922      *                                              (16.16 fix point) see
00923      *                                              datasheet for details
00924      * @return  VL53L0X_ERROR_NONE                  Success
00925      * @return  "Other error code"                  See ::VL53L0X_Error
00926      */
00927     VL53L0X_Error VL53L0X_get_x_talk_compensation_rate_mega_cps(VL53L0X_DEV dev,
00928             FixPoint1616_t *p_xtalk_compensation_rate_mega_cps);
00929 
00930     /**
00931      * @brief  Set a new device mode
00932      * @par Function Description
00933      * Set device to a new mode (ranging, histogram ...)
00934      *
00935      * @note This function doesn't Access to the device
00936      *
00937      * @param   dev                   Device Handle
00938      * @param   device_mode           New device mode to apply
00939      *                                Valid values are:
00940      *                                VL53L0X_DEVICEMODE_SINGLE_RANGING
00941      *                                VL53L0X_DEVICEMODE_CONTINUOUS_RANGING
00942      *                                VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING
00943      *                                VL53L0X_DEVICEMODE_SINGLE_HISTOGRAM
00944      *                                VL53L0X_HISTOGRAMMODE_REFERENCE_ONLY
00945      *                                VL53L0X_HISTOGRAMMODE_RETURN_ONLY
00946      *                                VL53L0X_HISTOGRAMMODE_BOTH
00947      *
00948      *
00949      * @return  VL53L0X_ERROR_NONE               Success
00950      * @return  VL53L0X_ERROR_MODE_NOT_SUPPORTED This error occurs when
00951      *                                           DeviceMode is not in the
00952      *                                           supported list
00953      */
00954     VL53L0X_Error VL53L0X_set_device_mode(VL53L0X_DEV dev, VL53L0X_DeviceModes device_mode);
00955 
00956     /**
00957      * @brief  Get current new device mode
00958      * @par Function Description
00959      * Get actual mode of the device(ranging, histogram ...)
00960      *
00961      * @note This function doesn't Access to the device
00962      *
00963      * @param   dev                   Device Handle
00964      * @param   p_device_mode         Pointer to current apply mode value
00965      *                                Valid values are:
00966      *                                VL53L0X_DEVICEMODE_SINGLE_RANGING
00967      *                                VL53L0X_DEVICEMODE_CONTINUOUS_RANGING
00968      *                                VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING
00969      *                                VL53L0X_DEVICEMODE_SINGLE_HISTOGRAM
00970      *                                VL53L0X_HISTOGRAMMODE_REFERENCE_ONLY
00971      *                                VL53L0X_HISTOGRAMMODE_RETURN_ONLY
00972      *                                VL53L0X_HISTOGRAMMODE_BOTH
00973      *
00974      * @return  VL53L0X_ERROR_NONE                   Success
00975      * @return  VL53L0X_ERROR_MODE_NOT_SUPPORTED     This error occurs when
00976      *                                               DeviceMode is not in the
00977      *                                               supported list
00978      */
00979     VL53L0X_Error VL53L0X_get_device_mode(VL53L0X_DEV dev,
00980                                           VL53L0X_DeviceModes *p_device_mode);
00981 
00982     /**
00983     * @brief Get current configuration for GPIO pin for a given device
00984     *
00985     * @note This function Access to the device
00986     *
00987     * @param   dev                   Device Handle
00988     * @param   pin                   ID of the GPIO Pin
00989     * @param   p_device_mode         Pointer to Device Mode associated to the Gpio.
00990     * @param   p_functionality       Pointer to Pin functionality.
00991     *                                Refer to ::VL53L0X_GpioFunctionality
00992     * @param   p_polarity            Pointer to interrupt polarity.
00993     *                                Active high or active low see
00994     *                                ::VL53L0X_InterruptPolarity
00995     * @return  VL53L0X_ERROR_NONE    Success
00996     * @return  VL53L0X_ERROR_GPIO_NOT_EXISTING           Only Pin=0 is accepted.
00997     * @return  VL53L0X_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED
00998     *          This error occurs
00999     *          when Funcionality programmed is not in the supported list:
01000     *                      Supported value are:
01001     *                      VL53L0X_GPIOFUNCTIONALITY_OFF,
01002     *                      VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW,
01003     *                      VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH,
01004     *                      VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT,
01005     *                      VL53L0X_GPIOFUNCTIONALITY_NEW_MEASURE_READY
01006     * @return  "Other error code"    See ::VL53L0X_Error
01007     */
01008     VL53L0X_Error VL53L0X_get_gpio_config(VL53L0X_DEV dev, uint8_t pin,
01009                                           VL53L0X_DeviceModes *p_device_mode,
01010                                           VL53L0X_GpioFunctionality *p_functionality,
01011                                           VL53L0X_InterruptPolarity *p_polarity);
01012 
01013     /**
01014      * @brief Set the configuration of GPIO pin for a given device
01015      *
01016      * @note This function Access to the device
01017      *
01018      * @param   dev                   Device Handle
01019      * @param   pin                   ID of the GPIO Pin
01020      * @param   functionality         Select Pin functionality.
01021      *  Refer to ::VL53L0X_GpioFunctionality
01022      * @param   device_mode            Device Mode associated to the Gpio.
01023      * @param   polarity              Set interrupt polarity. Active high
01024      *   or active low see ::VL53L0X_InterruptPolarity
01025      * @return  VL53L0X_ERROR_NONE                            Success
01026      * @return  VL53L0X_ERROR_GPIO_NOT_EXISTING               Only Pin=0 is accepted.
01027      * @return  VL53L0X_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED    This error occurs
01028      * when Functionality programmed is not in the supported list:
01029      *                             Supported value are:
01030      *                             VL53L0X_GPIOFUNCTIONALITY_OFF,
01031      *                             VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW,
01032      *                             VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH,
01033      VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT,
01034      *                               VL53L0X_GPIOFUNCTIONALITY_NEW_MEASURE_READY
01035      * @return  "Other error code"    See ::VL53L0X_Error
01036      */
01037     VL53L0X_Error VL53L0X_set_gpio_config(VL53L0X_DEV dev, uint8_t pin,
01038                                           VL53L0X_DeviceModes device_mode, VL53L0X_GpioFunctionality functionality,
01039                                           VL53L0X_InterruptPolarity polarity);
01040 
01041     /**
01042      * @brief Start device measurement
01043      *
01044      * @details Started measurement will depend on device parameters set through
01045      * @a VL53L0X_SetParameters()
01046      * This is a non-blocking function.
01047      * This function will change the VL53L0X_State from VL53L0X_STATE_IDLE to
01048      * VL53L0X_STATE_RUNNING.
01049      *
01050      * @note This function Access to the device
01051      *
01052 
01053      * @param   dev                  Device Handle
01054      * @return  VL53L0X_ERROR_NONE                  Success
01055      * @return  VL53L0X_ERROR_MODE_NOT_SUPPORTED    This error occurs when
01056      * DeviceMode programmed with @a VL53L0X_SetDeviceMode is not in the supported
01057      * list:
01058      *                                   Supported mode are:
01059      *                                   VL53L0X_DEVICEMODE_SINGLE_RANGING,
01060      *                                   VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
01061      *                                   VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING
01062      * @return  VL53L0X_ERROR_TIME_OUT    Time out on start measurement
01063      * @return  "Other error code"   See ::VL53L0X_Error
01064      */
01065     VL53L0X_Error VL53L0X_start_measurement(VL53L0X_DEV dev);
01066 
01067     /**
01068      * @brief Stop device measurement
01069      *
01070      * @details Will set the device in standby mode at end of current measurement\n
01071      *          Not necessary in single mode as device shall return automatically
01072      *          in standby mode at end of measurement.
01073      *          This function will change the VL53L0X_State from VL53L0X_STATE_RUNNING
01074      *          to VL53L0X_STATE_IDLE.
01075      *
01076      * @note This function Access to the device
01077      *
01078      * @param   dev                  Device Handle
01079      * @return  VL53L0X_ERROR_NONE    Success
01080      * @return  "Other error code"   See ::VL53L0X_Error
01081      */
01082     VL53L0X_Error VL53L0X_stop_measurement(VL53L0X_DEV dev);
01083 
01084     /**
01085      * @brief Return device stop completion status
01086      *
01087      * @par Function Description
01088      * Returns stop completiob status.
01089      * User shall call this function after a stop command
01090      *
01091      * @note This function Access to the device
01092      *
01093      * @param   dev                    Device Handle
01094      * @param   p_stop_status            Pointer to status variable to update
01095      * @return  VL53L0X_ERROR_NONE      Success
01096      * @return  "Other error code"     See ::VL53L0X_Error
01097      */
01098     VL53L0X_Error VL53L0X_get_stop_completed_status(VL53L0X_DEV dev,
01099             uint32_t *p_stop_status);
01100 
01101     /**
01102      * @brief Return Measurement Data Ready
01103      *
01104      * @par Function Description
01105      * This function indicate that a measurement data is ready.
01106      * This function check if interrupt mode is used then check is done accordingly.
01107      * If perform function clear the interrupt, this function will not work,
01108      * like in case of @a VL53L0X_PerformSingleRangingMeasurement().
01109      * The previous function is blocking function, VL53L0X_GetMeasurementDataReady
01110      * is used for non-blocking capture.
01111      *
01112      * @note This function Access to the device
01113      *
01114      * @param   dev                    Device Handle
01115      * @param   p_measurement_data_ready  Pointer to Measurement Data Ready.
01116      *  0=data not ready, 1 = data ready
01117      * @return  VL53L0X_ERROR_NONE      Success
01118      * @return  "Other error code"     See ::VL53L0X_Error
01119      */
01120     VL53L0X_Error VL53L0X_get_measurement_data_ready(VL53L0X_DEV dev,
01121             uint8_t *p_measurement_data_ready);
01122 
01123     /**
01124      * @brief Retrieve the measurements from device for a given setup
01125      *
01126      * @par Function Description
01127      * Get data from last successful Ranging measurement
01128      * @warning USER should take care about  @a VL53L0X_GetNumberOfROIZones()
01129      * before get data.
01130      * PAL will fill a NumberOfROIZones times the corresponding data
01131      * structure used in the measurement function.
01132      *
01133      * @note This function Access to the device
01134      *
01135      * @param   dev                      Device Handle
01136      * @param   p_ranging_measurement_data  Pointer to the data structure to fill up.
01137      * @return  VL53L0X_ERROR_NONE        Success
01138      * @return  "Other error code"       See ::VL53L0X_Error
01139      */
01140     VL53L0X_Error VL53L0X_get_ranging_measurement_data(VL53L0X_DEV dev,
01141             VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data);
01142 
01143     /**
01144      * @brief Clear given system interrupt condition
01145      *
01146      * @par Function Description
01147      * Clear given interrupt(s).
01148      *
01149      * @note This function Access to the device
01150      *
01151      * @param   dev                  Device Handle
01152      * @param   interrupt_mask        Mask of interrupts to clear
01153      * @return  VL53L0X_ERROR_NONE    Success
01154      * @return  VL53L0X_ERROR_INTERRUPT_NOT_CLEARED    Cannot clear interrupts
01155      *
01156      * @return  "Other error code"   See ::VL53L0X_Error
01157      */
01158     VL53L0X_Error VL53L0X_clear_interrupt_mask(VL53L0X_DEV dev, uint32_t interrupt_mask);
01159 
01160     /**
01161      * @brief Return device interrupt status
01162      *
01163      * @par Function Description
01164      * Returns currently raised interrupts by the device.
01165      * User shall be able to activate/deactivate interrupts through
01166      * @a VL53L0X_SetGpioConfig()
01167      *
01168      * @note This function Access to the device
01169      *
01170      * @param   dev                    Device Handle
01171      * @param   p_interrupt_mask_status   Pointer to status variable to update
01172      * @return  VL53L0X_ERROR_NONE      Success
01173      * @return  "Other error code"     See ::VL53L0X_Error
01174      */
01175     VL53L0X_Error VL53L0X_get_interrupt_mask_status(VL53L0X_DEV dev,
01176             uint32_t *p_interrupt_mask_status);
01177 
01178     /**
01179      * @brief Performs a single ranging measurement and retrieve the ranging
01180      * measurement data
01181      *
01182      * @par Function Description
01183      * This function will change the device mode to VL53L0X_DEVICEMODE_SINGLE_RANGING
01184      * with @a VL53L0X_SetDeviceMode(),
01185      * It performs measurement with @a VL53L0X_PerformSingleMeasurement()
01186      * It get data from last successful Ranging measurement with
01187      * @a VL53L0X_GetRangingMeasurementData.
01188      * Finally it clear the interrupt with @a VL53L0X_ClearInterruptMask().
01189      *
01190      * @note This function Access to the device
01191      *
01192      * @note This function change the device mode to
01193      * VL53L0X_DEVICEMODE_SINGLE_RANGING
01194      *
01195      * @param   dev                       Device Handle
01196      * @param   p_ranging_measurement_data   Pointer to the data structure to fill up.
01197      * @return  VL53L0X_ERROR_NONE         Success
01198      * @return  "Other error code"        See ::VL53L0X_Error
01199      */
01200     VL53L0X_Error VL53L0X_perform_single_ranging_measurement(VL53L0X_DEV dev,
01201             VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data);
01202 
01203     /**
01204      * @brief Single shot measurement.
01205      *
01206      * @par Function Description
01207      * Perform simple measurement sequence (Start measure, Wait measure to end,
01208      * and returns when measurement is done).
01209      * Once function returns, user can get valid data by calling
01210      * VL53L0X_GetRangingMeasurement or VL53L0X_GetHistogramMeasurement
01211      * depending on defined measurement mode
01212      * User should Clear the interrupt in case this are enabled by using the
01213      * function VL53L0X_ClearInterruptMask().
01214      *
01215      * @warning This function is a blocking function
01216      *
01217      * @note This function Access to the device
01218      *
01219      * @param   dev                  Device Handle
01220      * @return  VL53L0X_ERROR_NONE    Success
01221      * @return  "Other error code"   See ::VL53L0X_Error
01222      */
01223     VL53L0X_Error VL53L0X_perform_single_measurement(VL53L0X_DEV dev);
01224 
01225     /**
01226     * @brief Read current status of the error register for the selected device
01227     *
01228     * @note This function Access to the device
01229     *
01230     * @param   dev                   Device Handle
01231     * @param   p_device_error_status    Pointer to current error code of the device
01232     * @return  VL53L0X_ERROR_NONE     Success
01233     * @return  "Other error code"    See ::VL53L0X_Error
01234     */
01235     VL53L0X_Error VL53L0X_get_device_error_status(VL53L0X_DEV dev,
01236             VL53L0X_DeviceError *p_device_error_status);
01237 
01238     /**
01239     * @brief Human readable error string for a given Error Code
01240     *
01241     * @note This function doesn't access to the device
01242     *
01243     * @param   error_code           The error code as stored on ::VL53L0X_DeviceError
01244     * @param   p_device_error_string  The error string corresponding to the ErrorCode
01245     * @return  VL53L0X_ERROR_NONE   Success
01246     * @return  "Other error code"  See ::VL53L0X_Error
01247     */
01248     VL53L0X_Error VL53L0X_get_device_error_string(
01249         VL53L0X_DeviceError error_code, char *p_device_error_string);
01250 
01251     /**
01252      * @brief Human readable Range Status string for a given RangeStatus
01253      *
01254      * @note This function doesn't access to the device
01255      *
01256      * @param   range_status         The RangeStatus code as stored on
01257      * @a VL53L0X_RangingMeasurementData_t
01258      * @param   p_range_status_string  The returned RangeStatus string.
01259      * @return  VL53L0X_ERROR_NONE   Success
01260      * @return  "Other error code"  See ::VL53L0X_Error
01261      */
01262     VL53L0X_Error VL53L0X_get_range_status_string(uint8_t range_status,
01263             char *p_range_status_string);
01264 
01265     VL53L0X_Error VL53L0X_get_total_signal_rate(VL53L0X_DEV dev,
01266             VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data,
01267             FixPoint1616_t *p_total_signal_rate_mcps);
01268 
01269     VL53L0X_Error VL53L0X_get_total_xtalk_rate(VL53L0X_DEV dev,
01270             VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data,
01271             FixPoint1616_t *p_total_xtalk_rate_mcps);
01272 
01273     /**
01274      * @brief Get Ranging Timing Budget in microseconds
01275      *
01276      * @par Function Description
01277      * Returns the programmed the maximum time allowed by the user to the
01278      * device to run a full ranging sequence for the current mode
01279      * (ranging, histogram, ASL ...)
01280      *
01281      * @note This function Access to the device
01282      *
01283      * @param   dev                                    Device Handle
01284      * @param   p_measurement_timing_budget_micro_seconds   Max measurement time in
01285      * microseconds.
01286      *                                   Valid values are:
01287      *                                   >= 17000 microsecs when wraparound enabled
01288      *                                   >= 12000 microsecs when wraparound disabled
01289      * @return  VL53L0X_ERROR_NONE                      Success
01290      * @return  "Other error code"                     See ::VL53L0X_Error
01291      */
01292     VL53L0X_Error VL53L0X_get_measurement_timing_budget_micro_seconds(VL53L0X_DEV dev,
01293             uint32_t *p_measurement_timing_budget_micro_seconds);
01294 
01295     /**
01296      * @brief Set Ranging Timing Budget in microseconds
01297      *
01298      * @par Function Description
01299      * Defines the maximum time allowed by the user to the device to run a
01300      * full ranging sequence for the current mode (ranging, histogram, ASL ...)
01301      *
01302      * @note This function Access to the device
01303      *
01304      * @param   dev                                Device Handle
01305      * @param measurement_timing_budget_micro_seconds  Max measurement time in
01306      * microseconds.
01307      *                                   Valid values are:
01308      *                                   >= 17000 microsecs when wraparound enabled
01309      *                                   >= 12000 microsecs when wraparound disabled
01310      * @return  VL53L0X_ERROR_NONE             Success
01311      * @return  VL53L0X_ERROR_INVALID_PARAMS   This error is returned if
01312      MeasurementTimingBudgetMicroSeconds out of range
01313      * @return  "Other error code"            See ::VL53L0X_Error
01314      */
01315     VL53L0X_Error VL53L0X_set_measurement_timing_budget_micro_seconds(VL53L0X_DEV dev,
01316             uint32_t measurement_timing_budget_micro_seconds);
01317 
01318     /**
01319      * @brief  Get specific limit check enable state
01320      *
01321      * @par Function Description
01322      * This function get the enable state of a specific limit check.
01323      * The limit check is identified with the LimitCheckId.
01324      *
01325      * @note This function Access to the device
01326      *
01327      * @param   dev                           Device Handle
01328      * @param   limit_check_id                  Limit Check ID
01329      *  (0<= LimitCheckId < VL53L0X_GetNumberOfLimitCheck() ).
01330      * @param   p_limit_check_enable             Pointer to the check limit enable
01331      * value.
01332      *  if 1 the check limit
01333      *        corresponding to LimitCheckId is Enabled
01334      *  if 0 the check limit
01335      *        corresponding to LimitCheckId is disabled
01336      * @return  VL53L0X_ERROR_NONE             Success
01337      * @return  VL53L0X_ERROR_INVALID_PARAMS   This error is returned
01338      *  when LimitCheckId value is out of range.
01339      * @return  "Other error code"            See ::VL53L0X_Error
01340      */
01341     VL53L0X_Error VL53L0X_get_limit_check_enable(VL53L0X_DEV dev, uint16_t limit_check_id,
01342             uint8_t *p_limit_check_enable);
01343 
01344     /**
01345      * @brief  Enable/Disable a specific limit check
01346      *
01347      * @par Function Description
01348      * This function Enable/Disable a specific limit check.
01349      * The limit check is identified with the LimitCheckId.
01350      *
01351      * @note This function doesn't Access to the device
01352      *
01353      * @param   dev                           Device Handle
01354      * @param   limit_check_id                  Limit Check ID
01355      *  (0<= LimitCheckId < VL53L0X_GetNumberOfLimitCheck() ).
01356      * @param   limit_check_enable              if 1 the check limit
01357      *  corresponding to LimitCheckId is Enabled
01358      *                                        if 0 the check limit
01359      *  corresponding to LimitCheckId is disabled
01360      * @return  VL53L0X_ERROR_NONE             Success
01361      * @return  VL53L0X_ERROR_INVALID_PARAMS   This error is returned
01362      *  when LimitCheckId value is out of range.
01363      * @return  "Other error code"            See ::VL53L0X_Error
01364      */
01365     VL53L0X_Error VL53L0X_set_limit_check_enable(VL53L0X_DEV dev, uint16_t limit_check_id,
01366             uint8_t limit_check_enable);
01367 
01368     /**
01369      * @brief  Get a specific limit check value
01370      *
01371      * @par Function Description
01372      * This function get a specific limit check value from device then it updates
01373      * internal values and check enables.
01374      * The limit check is identified with the LimitCheckId.
01375      *
01376      * @note This function Access to the device
01377      *
01378      * @param   dev                           Device Handle
01379      * @param   limit_check_id                  Limit Check ID
01380      *  (0<= LimitCheckId < VL53L0X_GetNumberOfLimitCheck() ).
01381      * @param   p_limit_check_value              Pointer to Limit
01382      *  check Value for a given LimitCheckId.
01383      * @return  VL53L0X_ERROR_NONE             Success
01384      * @return  VL53L0X_ERROR_INVALID_PARAMS   This error is returned
01385      *  when LimitCheckId value is out of range.
01386      * @return  "Other error code"            See ::VL53L0X_Error
01387      */
01388     VL53L0X_Error VL53L0X_get_limit_check_value(VL53L0X_DEV dev, uint16_t limit_check_id,
01389             FixPoint1616_t *p_limit_check_value);
01390 
01391     /**
01392      * @brief  Set a specific limit check value
01393      *
01394      * @par Function Description
01395      * This function set a specific limit check value.
01396      * The limit check is identified with the LimitCheckId.
01397      *
01398      * @note This function Access to the device
01399      *
01400      * @param   dev                           Device Handle
01401      * @param   limit_check_id                  Limit Check ID
01402      *  (0<= LimitCheckId < VL53L0X_GetNumberOfLimitCheck() ).
01403      * @param   limit_check_value               Limit check Value for a given
01404      * LimitCheckId
01405      * @return  VL53L0X_ERROR_NONE             Success
01406      * @return  VL53L0X_ERROR_INVALID_PARAMS   This error is returned when either
01407      *  LimitCheckId or LimitCheckValue value is out of range.
01408      * @return  "Other error code"            See ::VL53L0X_Error
01409      */
01410     VL53L0X_Error VL53L0X_set_limit_check_value(VL53L0X_DEV dev, uint16_t limit_check_id,
01411             FixPoint1616_t limit_check_value);
01412 
01413     /**
01414      * @brief  Get the current value of the signal used for the limit check
01415      *
01416      * @par Function Description
01417      * This function get a the current value of the signal used for the limit check.
01418      * To obtain the latest value you should run a ranging before.
01419      * The value reported is linked to the limit check identified with the
01420      * LimitCheckId.
01421      *
01422      * @note This function Access to the device
01423      *
01424      * @param   dev                           Device Handle
01425      * @param   limit_check_id                  Limit Check ID
01426      *  (0<= LimitCheckId < VL53L0X_GetNumberOfLimitCheck() ).
01427      * @param   p_limit_check_current            Pointer to current Value for a
01428      * given LimitCheckId.
01429      * @return  VL53L0X_ERROR_NONE             Success
01430      * @return  VL53L0X_ERROR_INVALID_PARAMS   This error is returned when
01431      * LimitCheckId value is out of range.
01432      * @return  "Other error code"            See ::VL53L0X_Error
01433      */
01434     VL53L0X_Error VL53L0X_get_limit_check_current(VL53L0X_DEV dev, uint16_t limit_check_id,
01435             FixPoint1616_t *p_limit_check_current);
01436 
01437     /**
01438      * @brief  Return a the Status of the specified check limit
01439      *
01440      * @par Function Description
01441      * This function returns the Status of the specified check limit.
01442      * The value indicate if the check is fail or not.
01443      * The limit check is identified with the LimitCheckId.
01444      *
01445      * @note This function doesn't Access to the device
01446      *
01447      * @param   dev                           Device Handle
01448      * @param   limit_check_id                  Limit Check ID
01449      (0<= LimitCheckId < VL53L0X_GetNumberOfLimitCheck() ).
01450      * @param   p_limit_check_status             Pointer to the
01451      Limit Check Status of the given check limit.
01452      * LimitCheckStatus :
01453      * 0 the check is not fail
01454      * 1 the check if fail or not enabled
01455      *
01456      * @return  VL53L0X_ERROR_NONE             Success
01457      * @return  VL53L0X_ERROR_INVALID_PARAMS   This error is
01458      returned when LimitCheckId value is out of range.
01459      * @return  "Other error code"            See ::VL53L0X_Error
01460      */
01461     VL53L0X_Error VL53L0X_get_limit_check_status(VL53L0X_DEV dev,
01462             uint16_t limit_check_id, uint8_t *p_limit_check_status);
01463 
01464     /**
01465      * Get continuous mode Inter-Measurement period in milliseconds
01466      *
01467      * @par Function Description
01468      * When trying to set too short time return  INVALID_PARAMS minimal value
01469      *
01470      * @note This function Access to the device
01471      *
01472      * @param   dev                                  Device Handle
01473      * @param   p_inter_measurement_period_milli_seconds  Pointer to programmed
01474      *  Inter-Measurement Period in milliseconds.
01475      * @return  VL53L0X_ERROR_NONE                    Success
01476      * @return  "Other error code"                   See ::VL53L0X_Error
01477      */
01478     VL53L0X_Error VL53L0X_get_inter_measurement_period_milli_seconds(VL53L0X_DEV dev,
01479             uint32_t *p_inter_measurement_period_milli_seconds);
01480 
01481     /**
01482      * Program continuous mode Inter-Measurement period in milliseconds
01483      *
01484      * @par Function Description
01485      * When trying to set too short time return  INVALID_PARAMS minimal value
01486      *
01487      * @note This function Access to the device
01488      *
01489      * @param   dev                                  Device Handle
01490      * @param   inter_measurement_period_milli_seconds   Inter-Measurement Period in ms.
01491      * @return  VL53L0X_ERROR_NONE                    Success
01492      * @return  "Other error code"                   See ::VL53L0X_Error
01493      */
01494     VL53L0X_Error VL53L0X_set_inter_measurement_period_milli_seconds(
01495         VL53L0X_DEV dev, uint32_t inter_measurement_period_milli_seconds);
01496 
01497     /**
01498      * @brief Set new device address
01499      *
01500      * After completion the device will answer to the new address programmed.
01501      * This function should be called when several devices are used in parallel
01502      * before start programming the sensor.
01503      * When a single device us used, there is no need to call this function.
01504      *
01505      * @note This function Access to the device
01506      *
01507      * @param   dev                   Device Handle
01508      * @param   device_address         The new Device address
01509      * @return  VL53L0X_ERROR_NONE     Success
01510      * @return  "Other error code"    See ::VL53L0X_Error
01511      */
01512     VL53L0X_Error VL53L0X_set_device_address(VL53L0X_DEV dev, uint8_t device_address);
01513 
01514     /**
01515      * @brief Do an hard reset or soft reset (depending on implementation) of the
01516      * device \nAfter call of this function, device must be in same state as right
01517      * after a power-up sequence.This function will change the VL53L0X_State to
01518      * VL53L0X_STATE_POWERDOWN.
01519      *
01520      * @note This function Access to the device
01521      *
01522      * @param   dev                   Device Handle
01523      * @return  VL53L0X_ERROR_NONE     Success
01524      * @return  "Other error code"    See ::VL53L0X_Error
01525      */
01526     VL53L0X_Error VL53L0X_reset_device(VL53L0X_DEV dev);
01527 
01528     /**
01529      * @brief  Get setup of Wrap around Check
01530      *
01531      * @par Function Description
01532      * This function get the wrapAround check enable parameters
01533      *
01534      * @note This function Access to the device
01535      *
01536      * @param   dev                     Device Handle
01537      * @param   p_wrap_around_check_enable  Pointer to the Wrap around Check state
01538      *                                  0=disabled or 1 = enabled
01539      * @return  VL53L0X_ERROR_NONE       Success
01540      * @return  "Other error code"      See ::VL53L0X_Error
01541      */
01542     VL53L0X_Error VL53L0X_get_wrap_around_check_enable(VL53L0X_DEV dev,
01543             uint8_t *p_wrap_around_check_enable);
01544 
01545     /**
01546      * @brief  Enable (or disable) Wrap around Check
01547      *
01548      * @note This function Access to the device
01549      *
01550      * @param   dev                    Device Handle
01551      * @param   wrap_around_check_enable  Wrap around Check to be set
01552      *                                 0=disabled, other = enabled
01553      * @return  VL53L0X_ERROR_NONE      Success
01554      * @return  "Other error code"     See ::VL53L0X_Error
01555      */
01556     VL53L0X_Error VL53L0X_set_wrap_around_check_enable(VL53L0X_DEV dev,
01557             uint8_t wrap_around_check_enable);
01558 
01559     /**
01560      * @brief Gets the VCSEL pulse period.
01561      *
01562      * @par Function Description
01563      * This function retrieves the VCSEL pulse period for the given period type.
01564      *
01565      * @note This function Accesses the device
01566      *
01567      * @param   dev                      Device Handle
01568      * @param   vcsel_period_type          VCSEL period identifier (pre-range|final).
01569      * @param   p_vcsel_pulse_period_pclk        Pointer to VCSEL period value.
01570      * @return  VL53L0X_ERROR_NONE        Success
01571      * @return  VL53L0X_ERROR_INVALID_PARAMS  Error VcselPeriodType parameter not
01572      *                                       supported.
01573      * @return  "Other error code"           See ::VL53L0X_Error
01574      */
01575     VL53L0X_Error VL53L0X_get_vcsel_pulse_period(VL53L0X_DEV dev,
01576             VL53L0X_VcselPeriod vcsel_period_type, uint8_t *p_vcsel_pulse_period_pclk);
01577 
01578     /**
01579      * @brief Sets the VCSEL pulse period.
01580      *
01581      * @par Function Description
01582      * This function retrieves the VCSEL pulse period for the given period type.
01583      *
01584      * @note This function Accesses the device
01585      *
01586      * @param   dev                       Device Handle
01587      * @param   vcsel_period_type         VCSEL period identifier (pre-range|final).
01588      * @param   vcsel_pulse_period          VCSEL period value
01589      * @return  VL53L0X_ERROR_NONE            Success
01590      * @return  VL53L0X_ERROR_INVALID_PARAMS  Error VcselPeriodType parameter not
01591      *                                       supported.
01592      * @return  "Other error code"           See ::VL53L0X_Error
01593      */
01594     VL53L0X_Error VL53L0X_set_vcsel_pulse_period(VL53L0X_DEV dev,
01595             VL53L0X_VcselPeriod vcsel_period_type, uint8_t vcsel_pulse_period);
01596 
01597     /**
01598      * @brief Set low and high Interrupt thresholds for a given mode
01599      * (ranging, ALS, ...) for a given device
01600      *
01601      * @par Function Description
01602      * Set low and high Interrupt thresholds for a given mode (ranging, ALS, ...)
01603      * for a given device
01604      *
01605      * @note This function Access to the device
01606      *
01607      * @note DeviceMode is ignored for the current device
01608      *
01609      * @param   dev              Device Handle
01610      * @param   device_mode       Device Mode for which change thresholds
01611      * @param   threshold_low     Low threshold (mm, lux ..., depending on the mode)
01612      * @param   threshold_high    High threshold (mm, lux ..., depending on the mode)
01613      * @return  VL53L0X_ERROR_NONE    Success
01614      * @return  "Other error code"   See ::VL53L0X_Error
01615      */
01616     VL53L0X_Error VL53L0X_set_interrupt_thresholds(VL53L0X_DEV dev,
01617             VL53L0X_DeviceModes device_mode, FixPoint1616_t threshold_low,
01618             FixPoint1616_t threshold_high);
01619 
01620     /**
01621      * @brief  Get high and low Interrupt thresholds for a given mode
01622      *  (ranging, ALS, ...) for a given device
01623      *
01624      * @par Function Description
01625      * Get high and low Interrupt thresholds for a given mode (ranging, ALS, ...)
01626      * for a given device
01627      *
01628      * @note This function Access to the device
01629      *
01630      * @note DeviceMode is ignored for the current device
01631      *
01632      * @param   dev              Device Handle
01633      * @param   device_mode       Device Mode from which read thresholds
01634      * @param   p_threshold_low    Low threshold (mm, lux ..., depending on the mode)
01635      * @param   p_threshold_high   High threshold (mm, lux ..., depending on the mode)
01636      * @return  VL53L0X_ERROR_NONE   Success
01637      * @return  "Other error code"  See ::VL53L0X_Error
01638      */
01639     VL53L0X_Error VL53L0X_get_interrupt_thresholds(VL53L0X_DEV dev,
01640             VL53L0X_DeviceModes device_mode, FixPoint1616_t *p_threshold_low,
01641             FixPoint1616_t *p_threshold_high);
01642 
01643     /**
01644      * @brief Reads the Device information for given Device
01645      *
01646      * @note This function Access to the device
01647      *
01648      * @param   dev                 Device Handle
01649      * @param   p_VL53L0X_device_info  Pointer to current device info for a given
01650      *  Device
01651      * @return  VL53L0X_ERROR_NONE   Success
01652      * @return  "Other error code"  See ::VL53L0X_Error
01653      */
01654     VL53L0X_Error VL53L0X_get_device_info(VL53L0X_DEV dev,
01655                                           VL53L0X_DeviceInfo_t *p_VL53L0X_device_info);
01656 
01657     /**
01658      * @brief Gets the (on/off) state of all sequence steps.
01659      *
01660      * @par Function Description
01661      * This function retrieves the state of all sequence step in the scheduler.
01662      *
01663      * @note This function Accesses the device
01664      *
01665      * @param   dev                          Device Handle
01666      * @param   p_scheduler_sequence_steps      Pointer to struct containing result.
01667      * @return  VL53L0X_ERROR_NONE            Success
01668      * @return  "Other error code"           See ::VL53L0X_Error
01669      */
01670     VL53L0X_Error VL53L0X_get_sequence_step_enables(VL53L0X_DEV dev,
01671             VL53L0X_SchedulerSequenceSteps_t *p_scheduler_sequence_steps);
01672 
01673     /**
01674      * @brief Sets the (on/off) state of a requested sequence step.
01675      *
01676      * @par Function Description
01677      * This function enables/disables a requested sequence step.
01678      *
01679      * @note This function Accesses the device
01680      *
01681      * @param   dev                          Device Handle
01682      * @param   sequence_step_id             Sequence step identifier.
01683      * @param   sequence_step_enabled          Demanded state {0=Off,1=On}
01684      *                                       is enabled.
01685      * @return  VL53L0X_ERROR_NONE            Success
01686      * @return  VL53L0X_ERROR_INVALID_PARAMS  Error SequenceStepId parameter not
01687      *                                       supported.
01688      * @return  "Other error code"           See ::VL53L0X_Error
01689      */
01690     VL53L0X_Error VL53L0X_set_sequence_step_enable(VL53L0X_DEV dev,
01691             VL53L0X_SequenceStepId sequence_step_id, uint8_t sequence_step_enabled);
01692 
01693     /**
01694      * @brief  Gets the fraction enable parameter indicating the resolution of
01695      * range measurements.
01696      *
01697      * @par Function Description
01698      * Gets the fraction enable state, which translates to the resolution of
01699      * range measurements as follows :Enabled:=0.25mm resolution,
01700      * Not Enabled:=1mm resolution.
01701      *
01702      * @note This function Accesses the device
01703      *
01704      * @param   dev               Device Handle
01705      * @param   p_enabled           Output Parameter reporting the fraction enable state.
01706      *
01707      * @return  VL53L0X_ERROR_NONE                   Success
01708      * @return  "Other error code"                  See ::VL53L0X_Error
01709      */
01710     VL53L0X_Error VL53L0X_get_fraction_enable(VL53L0X_DEV dev, uint8_t *p_enabled);
01711 
01712     /**
01713      * @brief  Sets the resolution of range measurements.
01714      * @par Function Description
01715      * Set resolution of range measurements to either 0.25mm if
01716      * fraction enabled or 1mm if not enabled.
01717      *
01718      * @note This function Accesses the device
01719      *
01720      * @param   dev               Device Handle
01721      * @param   enable            Enable high resolution
01722      *
01723      * @return  VL53L0X_ERROR_NONE               Success
01724      * @return  "Other error code"              See ::VL53L0X_Error
01725      */
01726     VL53L0X_Error VL53L0X_set_range_fraction_enable(VL53L0X_DEV dev,
01727             uint8_t enable);
01728 
01729     /**
01730     * @brief Return the VL53L0X PAL Implementation Version
01731     *
01732     * @note This function doesn't access to the device
01733     *
01734     * @param   p_version              Pointer to current PAL Implementation Version
01735     * @return  VL53L0X_ERROR_NONE     Success
01736     * @return  "Other error code"    See ::VL53L0X_Error
01737     */
01738     VL53L0X_Error VL53L0X_get_version(VL53L0X_Version_t *p_version);
01739 
01740     /**
01741      * @brief Reads the Product Revision for a for given Device
01742      * This function can be used to distinguish cut1.0 from cut1.1.
01743      *
01744      * @note This function Access to the device
01745      *
01746      * @param   dev                 Device Handle
01747      * @param   p_product_revision_major  Pointer to Product Revision Major
01748      * for a given Device
01749      * @param   p_product_revision_minor  Pointer to Product Revision Minor
01750      * for a given Device
01751      * @return  VL53L0X_ERROR_NONE      Success
01752      * @return  "Other error code"  See ::VL53L0X_Error
01753      */
01754     VL53L0X_Error VL53L0X_get_product_revision(VL53L0X_DEV dev,
01755             uint8_t *p_product_revision_major, uint8_t *p_product_revision_minor);
01756 
01757     /**
01758      * @brief  Retrieve current device parameters
01759      * @par Function Description
01760      * Get actual parameters of the device
01761      * @li Then start ranging operation.
01762      *
01763      * @note This function Access to the device
01764      *
01765      * @param   dev                   Device Handle
01766      * @param   p_device_parameters     Pointer to store current device parameters.
01767      * @return  VL53L0X_ERROR_NONE     Success
01768      * @return  "Other error code"    See ::VL53L0X_Error
01769      */
01770     VL53L0X_Error VL53L0X_get_device_parameters(VL53L0X_DEV dev,
01771             VL53L0X_DeviceParameters_t *p_device_parameters);
01772 
01773     /**
01774      * @brief Human readable error string for current PAL error status
01775      *
01776      * @note This function doesn't access to the device
01777      *
01778      * @param   pal_error_code       The error code as stored on @a VL53L0X_Error
01779      * @param   p_pal_error_string    The error string corresponding to the
01780      * PalErrorCode
01781      * @return  VL53L0X_ERROR_NONE  Success
01782      * @return  "Other error code" See ::VL53L0X_Error
01783      */
01784     VL53L0X_Error VL53L0X_get_pal_error_string(VL53L0X_Error pal_error_code,
01785             char *p_pal_error_string);
01786 
01787     /**
01788      * @brief Return the PAL Specification Version used for the current
01789      * implementation.
01790      *
01791      * @note This function doesn't access to the device
01792      *
01793      * @param   p_pal_spec_version       Pointer to current PAL Specification Version
01794      * @return  VL53L0X_ERROR_NONE        Success
01795      * @return  "Other error code"    See ::VL53L0X_Error
01796      */
01797     VL53L0X_Error VL53L0X_get_pal_spec_version(
01798         VL53L0X_Version_t *p_pal_spec_version);
01799 
01800     /**
01801      * @brief Reads the internal state of the PAL for a given Device
01802      *
01803      * @note This function doesn't access to the device
01804      *
01805      * @param   dev                   Device Handle
01806      * @param   p_pal_state             Pointer to current state of the PAL for a
01807      * given Device
01808      * @return  VL53L0X_ERROR_NONE     Success
01809      * @return  "Other error code"    See ::VL53L0X_Error
01810      */
01811     VL53L0X_Error VL53L0X_get_pal_state(VL53L0X_DEV dev,
01812                                         VL53L0X_State *p_pal_state);
01813 
01814     /**
01815      * @brief Human readable PAL State string
01816      *
01817      * @note This function doesn't access to the device
01818      *
01819      * @param   pal_state_code          The State code as stored on @a VL53L0X_State
01820      * @param   p_pal_state_string       The State string corresponding to the
01821      * PalStateCode
01822      * @return  VL53L0X_ERROR_NONE     Success
01823      * @return  "Other error code"    See ::VL53L0X_Error
01824      */
01825     VL53L0X_Error VL53L0X_get_pal_state_string(VL53L0X_State pal_state_code,
01826             char *p_pal_state_string);
01827 
01828     /*** End High level API ***/
01829 private:
01830     /* api.h functions */
01831 
01832     /**
01833      * @brief Wait for device booted after chip enable (hardware standby)
01834      * This function can be run only when VL53L0X_State is VL53L0X_STATE_POWERDOWN.
01835      *
01836      * @note This function is not Implemented
01837      *
01838      * @param   dev      Device Handle
01839      * @return  VL53L0X_ERROR_NOT_IMPLEMENTED Not implemented
01840      *
01841      */
01842     VL53L0X_Error VL53L0X_wait_device_booted(VL53L0X_DEV dev);
01843 
01844 
01845     VL53L0X_Error sequence_step_enabled(VL53L0X_DEV dev,
01846                                         VL53L0X_SequenceStepId sequence_step_id, uint8_t sequence_config,
01847                                         uint8_t *p_sequence_step_enabled);
01848 
01849     VL53L0X_Error VL53L0X_check_and_load_interrupt_settings(VL53L0X_DEV dev,
01850             uint8_t start_not_stopflag);
01851 
01852 
01853     /* api_core.h functions */
01854 
01855     VL53L0X_Error VL53L0X_get_info_from_device(VL53L0X_DEV dev, uint8_t option);
01856 
01857     VL53L0X_Error VL53L0X_device_read_strobe(VL53L0X_DEV dev);
01858 
01859     VL53L0X_Error wrapped_VL53L0X_get_measurement_timing_budget_micro_seconds(VL53L0X_DEV dev,
01860             uint32_t *p_measurement_timing_budget_micro_seconds);
01861 
01862     VL53L0X_Error wrapped_VL53L0X_get_vcsel_pulse_period(VL53L0X_DEV dev,
01863             VL53L0X_VcselPeriod vcsel_period_type, uint8_t *p_vcsel_pulse_period_pclk);
01864 
01865     uint8_t VL53L0X_decode_vcsel_period(uint8_t vcsel_period_reg);
01866 
01867     uint32_t VL53L0X_decode_timeout(uint16_t encoded_timeout);
01868 
01869     uint32_t VL53L0X_calc_timeout_us(VL53L0X_DEV dev,
01870                                      uint16_t timeout_period_mclks,
01871                                      uint8_t vcsel_period_pclks);
01872 
01873     uint32_t VL53L0X_calc_macro_period_ps(VL53L0X_DEV dev, uint8_t vcsel_period_pclks);
01874 
01875     VL53L0X_Error VL53L0X_measurement_poll_for_completion(VL53L0X_DEV dev);
01876 
01877     VL53L0X_Error VL53L0X_load_tuning_settings(VL53L0X_DEV dev,
01878             uint8_t *p_tuning_setting_buffer);
01879 
01880     VL53L0X_Error VL53L0X_get_pal_range_status(VL53L0X_DEV dev,
01881             uint8_t device_range_status,
01882             FixPoint1616_t signal_rate,
01883             uint16_t effective_spad_rtn_count,
01884             VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data,
01885             uint8_t *p_pal_range_status);
01886     VL53L0X_Error VL53L0X_calc_sigma_estimate(VL53L0X_DEV dev,
01887             VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data,
01888             FixPoint1616_t *p_sigma_estimate,
01889             uint32_t *p_dmax_mm);
01890     uint32_t VL53L0X_calc_timeout_mclks(VL53L0X_DEV dev,
01891                                         uint32_t timeout_period_us,
01892                                         uint8_t vcsel_period_pclks);
01893     uint32_t VL53L0X_isqrt(uint32_t num);
01894 
01895     uint32_t VL53L0X_quadrature_sum(uint32_t a, uint32_t b);
01896 
01897     VL53L0X_Error VL53L0X_calc_dmax(
01898         VL53L0X_DEV dev,
01899         FixPoint1616_t total_signal_rate_mcps,
01900         FixPoint1616_t total_corr_signal_rate_mcps,
01901         FixPoint1616_t pw_mult,
01902         uint32_t sigma_estimate_p1,
01903         FixPoint1616_t sigma_estimate_p2,
01904         uint32_t peak_vcsel_duration_us,
01905         uint32_t *pd_max_mm);
01906     VL53L0X_Error wrapped_VL53L0X_set_measurement_timing_budget_micro_seconds(VL53L0X_DEV dev,
01907             uint32_t measurement_timing_budget_micro_seconds);
01908     VL53L0X_Error get_sequence_step_timeout(VL53L0X_DEV dev,
01909                                             VL53L0X_SequenceStepId sequence_step_id,
01910                                             uint32_t *p_time_out_micro_secs);
01911     VL53L0X_Error set_sequence_step_timeout(VL53L0X_DEV dev,
01912                                             VL53L0X_SequenceStepId sequence_step_id,
01913                                             uint32_t timeout_micro_secs);
01914     uint16_t VL53L0X_encode_timeout(uint32_t timeout_macro_clks);
01915     VL53L0X_Error wrapped_VL53L0X_set_vcsel_pulse_period(VL53L0X_DEV dev,
01916             VL53L0X_VcselPeriod vcsel_period_type, uint8_t vcsel_pulse_period_pclk);
01917     uint8_t lv53l0x_encode_vcsel_period(uint8_t vcsel_period_pclks);
01918 
01919     /* api_calibration.h functions */
01920     VL53L0X_Error VL53L0X_apply_offset_adjustment(VL53L0X_DEV dev);
01921     VL53L0X_Error wrapped_VL53L0X_get_offset_calibration_data_micro_meter(VL53L0X_DEV dev,
01922             int32_t *p_offset_calibration_data_micro_meter);
01923     VL53L0X_Error wrapped_VL53L0X_set_offset_calibration_data_micro_meter(VL53L0X_DEV dev,
01924             int32_t offset_calibration_data_micro_meter);
01925     VL53L0X_Error wrapped_VL53L0X_perform_ref_spad_management(VL53L0X_DEV dev,
01926             uint32_t *ref_spad_count,
01927             uint8_t *is_aperture_spads);
01928     VL53L0X_Error VL53L0X_perform_ref_calibration(VL53L0X_DEV dev,
01929             uint8_t *p_vhv_settings, uint8_t *p_phase_cal, uint8_t get_data_enable);
01930     VL53L0X_Error VL53L0X_perform_vhv_calibration(VL53L0X_DEV dev,
01931             uint8_t *p_vhv_settings, const uint8_t get_data_enable,
01932             const uint8_t restore_config);
01933     VL53L0X_Error VL53L0X_perform_single_ref_calibration(VL53L0X_DEV dev,
01934             uint8_t vhv_init_byte);
01935     VL53L0X_Error VL53L0X_ref_calibration_io(VL53L0X_DEV dev, uint8_t read_not_write,
01936             uint8_t vhv_settings, uint8_t phase_cal,
01937             uint8_t *p_vhv_settings, uint8_t *p_phase_cal,
01938             const uint8_t vhv_enable, const uint8_t phase_enable);
01939     VL53L0X_Error VL53L0X_perform_phase_calibration(VL53L0X_DEV dev,
01940             uint8_t *p_phase_cal, const uint8_t get_data_enable,
01941             const uint8_t restore_config);
01942     VL53L0X_Error enable_ref_spads(VL53L0X_DEV dev,
01943                                    uint8_t aperture_spads,
01944                                    uint8_t good_spad_array[],
01945                                    uint8_t spad_array[],
01946                                    uint32_t size,
01947                                    uint32_t start,
01948                                    uint32_t offset,
01949                                    uint32_t spad_count,
01950                                    uint32_t *p_last_spad);
01951     void get_next_good_spad(uint8_t good_spad_array[], uint32_t size,
01952                             uint32_t curr, int32_t *p_next);
01953     uint8_t is_aperture(uint32_t spad_index);
01954     VL53L0X_Error enable_spad_bit(uint8_t spad_array[], uint32_t size,
01955                                   uint32_t spad_index);
01956     VL53L0X_Error set_ref_spad_map(VL53L0X_DEV dev, uint8_t *p_ref_spad_array);
01957     VL53L0X_Error get_ref_spad_map(VL53L0X_DEV dev, uint8_t *p_ref_spad_array);
01958     VL53L0X_Error perform_ref_signal_measurement(VL53L0X_DEV dev,
01959             uint16_t *p_ref_signal_rate);
01960     VL53L0X_Error wrapped_VL53L0X_set_reference_spads(VL53L0X_DEV dev,
01961             uint32_t count, uint8_t is_aperture_spads);
01962 
01963     /* api_strings.h functions */
01964     VL53L0X_Error wrapped_VL53L0X_get_device_info(VL53L0X_DEV dev,
01965             VL53L0X_DeviceInfo_t *p_VL53L0X_device_info);
01966     VL53L0X_Error VL53L0X_check_part_used(VL53L0X_DEV dev,
01967                                           uint8_t *revision,
01968                                           VL53L0X_DeviceInfo_t *p_VL53L0X_device_info);
01969 
01970     /* Read function of the ID device */
01971     //   virtual int read_id();
01972     virtual int read_id(uint8_t *id);
01973 
01974     VL53L0X_Error wait_measurement_data_ready(VL53L0X_DEV dev);
01975 
01976     VL53L0X_Error wait_stop_completed(VL53L0X_DEV dev);
01977 
01978     /* Write and read functions from I2C */
01979     /**
01980      * Write single byte register
01981      * @param   dev       Device Handle
01982      * @param   index     The register index
01983      * @param   data      8 bit register data
01984      * @return  VL53L0X_ERROR_NONE        Success
01985      * @return  "Other error code"    See ::VL53L0X_Error
01986      */
01987     VL53L0X_Error VL53L0X_write_byte(VL53L0X_DEV dev, uint8_t index, uint8_t data);
01988     /**
01989      * Write word register
01990      * @param   dev       Device Handle
01991      * @param   index     The register index
01992      * @param   data      16 bit register data
01993      * @return  VL53L0X_ERROR_NONE        Success
01994      * @return  "Other error code"    See ::VL53L0X_Error
01995      */
01996     VL53L0X_Error VL53L0X_write_word(VL53L0X_DEV dev, uint8_t index, uint16_t data);
01997     /**
01998      * Write double word (4 byte) register
01999      * @param   dev       Device Handle
02000      * @param   index     The register index
02001      * @param   data      32 bit register data
02002      * @return  VL53L0X_ERROR_NONE        Success
02003      * @return  "Other error code"    See ::VL53L0X_Error
02004      */
02005     VL53L0X_Error VL53L0X_write_dword(VL53L0X_DEV dev, uint8_t index, uint32_t data);
02006     /**
02007      * Read single byte register
02008      * @param   dev       Device Handle
02009      * @param   index     The register index
02010      * @param   data      pointer to 8 bit data
02011      * @return  VL53L0X_ERROR_NONE        Success
02012      * @return  "Other error code"    See ::VL53L0X_Error
02013      */
02014     VL53L0X_Error VL53L0X_read_byte(VL53L0X_DEV dev, uint8_t index, uint8_t *p_data);
02015     /**
02016      * Read word (2byte) register
02017      * @param   dev       Device Handle
02018      * @param   index     The register index
02019      * @param   data      pointer to 16 bit data
02020      * @return  VL53L0X_ERROR_NONE        Success
02021      * @return  "Other error code"    See ::VL53L0X_Error
02022      */
02023     VL53L0X_Error VL53L0X_read_word(VL53L0X_DEV dev, uint8_t index, uint16_t *p_data);
02024     /**
02025      * Read dword (4byte) register
02026      * @param   dev       Device Handle
02027      * @param   index     The register index
02028      * @param   data      pointer to 32 bit data
02029      * @return  VL53L0X_ERROR_NONE        Success
02030      * @return  "Other error code"    See ::VL53L0X_Error
02031      */
02032     VL53L0X_Error VL53L0X_read_dword(VL53L0X_DEV dev, uint8_t index, uint32_t *p_data);
02033     /**
02034      * Threat safe Update (read/modify/write) single byte register
02035      *
02036      * Final_reg = (Initial_reg & and_data) |or_data
02037      *
02038      * @param   dev        Device Handle
02039      * @param   index      The register index
02040      * @param   and_data    8 bit and data
02041      * @param   or_data     8 bit or data
02042      * @return  VL53L0X_ERROR_NONE        Success
02043      * @return  "Other error code"    See ::VL53L0X_Error
02044      */
02045     VL53L0X_Error VL53L0X_update_byte(VL53L0X_DEV dev, uint8_t index, uint8_t and_data, uint8_t or_data);
02046     /**
02047      * Writes the supplied byte buffer to the device
02048      * @param   dev       Device Handle
02049      * @param   index     The register index
02050      * @param   p_data     Pointer to uint8_t buffer containing the data to be written
02051      * @param   count     Number of bytes in the supplied byte buffer
02052      * @return  VL53L0X_ERROR_NONE        Success
02053      * @return  "Other error code"    See ::VL53L0X_Error
02054      */
02055     VL53L0X_Error VL53L0X_write_multi(VL53L0X_DEV dev, uint8_t index, uint8_t *p_data, uint32_t count);
02056     /**
02057      * Reads the requested number of bytes from the device
02058      * @param   dev       Device Handle
02059      * @param   index     The register index
02060      * @param   p_data     Pointer to the uint8_t buffer to store read data
02061      * @param   count     Number of uint8_t's to read
02062      * @return  VL53L0X_ERROR_NONE        Success
02063      * @return  "Other error code"    See ::VL53L0X_Error
02064      */
02065     VL53L0X_Error VL53L0X_read_multi(VL53L0X_DEV dev, uint8_t index, uint8_t *p_data, uint32_t count);
02066 
02067     /**
02068      * @brief  Writes a buffer towards the I2C peripheral device.
02069      * @param  dev       Device Handle
02070      * @param  p_data pointer to the byte-array data to send
02071      * @param  number_of_bytes number of bytes to be written.
02072      * @retval 0 if ok,
02073      * @retval -1 if an I2C error has occured
02074      * @note   On some devices if NumByteToWrite is greater
02075      *         than one, the RegisterAddr must be masked correctly!
02076      */
02077     VL53L0X_Error VL53L0X_i2c_write(uint8_t dev, uint8_t index, uint8_t *p_data, uint16_t number_of_bytes);
02078 
02079     /**
02080      * @brief  Reads a buffer from the I2C peripheral device.
02081      * @param  dev       Device Handle
02082      * @param  p_data pointer to the byte-array to read data in to
02083      * @param  number_of_bytes number of bytes to be read.
02084      * @retval 0 if ok,
02085      * @retval -1 if an I2C error has occured
02086      * @note   On some devices if NumByteToWrite is greater
02087      *         than one, the RegisterAddr must be masked correctly!
02088      */
02089     VL53L0X_Error VL53L0X_i2c_read(uint8_t dev, uint8_t index, uint8_t *p_data, uint16_t number_of_bytes);
02090 
02091     /**
02092      * @brief execute delay in all polling API call
02093      *
02094      * A typical multi-thread or RTOs implementation is to sleep the task for some 5ms (with 100Hz max rate faster polling is not needed)
02095      * if nothing specific is need you can define it as an empty/void macro
02096      * @code
02097      * #define VL53L0X_PollingDelay(...) (void)0
02098      * @endcode
02099      * @param dev       Device Handle
02100      * @return  VL53L0X_ERROR_NONE        Success
02101      * @return  "Other error code"    See ::VL53L0X_Error
02102      */
02103     VL53L0X_Error VL53L0X_polling_delay(VL53L0X_DEV dev);   /* usually best implemented as a real function */
02104 
02105     int is_present()
02106     {
02107         int status;
02108         uint8_t id = 0;
02109 
02110         status = read_id(&id);
02111         if (status) {
02112             VL53L0X_ErrLog("Failed to read ID device. Device not present!\n\r");
02113         }
02114         return status;
02115     }
02116 
02117     ///////////////////////////////////////////////////////////////////////////////////////////////////////
02118     //Added functions                                                                                    //
02119     ///////////////////////////////////////////////////////////////////////////////////////////////////////
02120 
02121     /**
02122      * @brief  Cycle Power to Device
02123      *
02124      * @return status - status 0 = ok, 1 = error
02125      *
02126      */
02127     int32_t VL53L0X_cycle_power(void);
02128 
02129     uint8_t VL53L0X_encode_vcsel_period(uint8_t vcsel_period_pclks);
02130 
02131     VL53L0X_Error wrapped_VL53L0X_get_device_error_string(VL53L0X_DeviceError error_code,
02132             char *p_device_error_string);
02133 
02134     VL53L0X_Error wrapped_VL53L0X_get_limit_check_info(VL53L0X_DEV dev, uint16_t limit_check_id,
02135             char *p_limit_check_string);
02136 
02137     VL53L0X_Error wrapped_VL53L0X_get_pal_error_string(VL53L0X_Error pal_error_code,
02138             char *p_pal_error_string);
02139 
02140     VL53L0X_Error wrapped_VL53L0X_get_pal_state_string(VL53L0X_State pal_state_code,
02141             char *p_pal_state_string);
02142 
02143     VL53L0X_Error wrapped_VL53L0X_get_range_status_string(uint8_t range_status,
02144             char *p_range_status_string);
02145 
02146     VL53L0X_Error wrapped_VL53L0X_get_ref_calibration(VL53L0X_DEV dev,
02147             uint8_t *p_vhv_settings, uint8_t *p_phase_cal);
02148 
02149 
02150     VL53L0X_Error count_enabled_spads(uint8_t spad_array[],
02151                                       uint32_t byte_count, uint32_t max_spads,
02152                                       uint32_t *p_total_spads_enabled, uint8_t *p_is_aperture);
02153 
02154     VL53L0X_Error wrapped_VL53L0X_get_sequence_steps_info(VL53L0X_SequenceStepId sequence_step_id,
02155             char *p_sequence_steps_string);
02156 
02157 
02158     /**
02159      * @brief Gets the name of a given sequence step.
02160      *
02161      * @par Function Description
02162      * This function retrieves the name of sequence steps corresponding to
02163      * SequenceStepId.
02164      *
02165      * @note This function doesn't Accesses the device
02166      *
02167      * @param   sequence_step_id               Sequence step identifier.
02168      * @param   p_sequence_steps_string         Pointer to Info string
02169      *
02170      * @return  VL53L0X_ERROR_NONE            Success
02171      * @return  "Other error code"           See ::VL53L0X_Error
02172      */
02173     VL53L0X_Error VL53L0X_get_sequence_steps_info(VL53L0X_SequenceStepId sequence_step_id,
02174             char *p_sequence_steps_string);
02175 
02176     /**
02177     * @brief Get the frequency of the timer used for ranging results time stamps
02178     *
02179     * @param[out] p_timer_freq_hz : pointer for timer frequency
02180     *
02181     * @return status : 0 = ok, 1 = error
02182     *
02183     */
02184     int32_t VL53L0X_get_timer_frequency(int32_t *p_timer_freq_hz);
02185 
02186     /**
02187     * @brief Get the timer value in units of timer_freq_hz (see VL53L0X_get_timestamp_frequency())
02188     *
02189     * @param[out] p_timer_count : pointer for timer count value
02190     *
02191     * @return status : 0 = ok, 1 = error
02192     *
02193     */
02194     int32_t VL53L0X_get_timer_value(int32_t *p_timer_count);
02195 
02196     /**
02197     * @brief Configure ranging interrupt reported to system
02198     *
02199     * @note This function is not Implemented
02200     *
02201     * @param   dev                  Device Handle
02202     * @param   interrupt_mask         Mask of interrupt to Enable/disable
02203     *  (0:interrupt disabled or 1: interrupt enabled)
02204     * @return  VL53L0X_ERROR_NOT_IMPLEMENTED   Not implemented
02205     */
02206     VL53L0X_Error VL53L0X_enable_interrupt_mask(VL53L0X_DEV dev,
02207             uint32_t interrupt_mask);
02208 
02209     /**
02210      * @brief  Get Dmax Calibration Parameters for a given device
02211      *
02212      *
02213      * @note This function Access to the device
02214      *
02215      * @param   dev                     Device Handle
02216      * @param   p_range_milli_meter        Pointer to Calibration Distance
02217      * @param   p_signal_rate_rtn_mega_cps   Pointer to Signal rate return
02218      * @return  VL53L0X_ERROR_NONE       Success
02219      * @return  "Other error code"      See ::VL53L0X_Error
02220      */
02221     VL53L0X_Error VL53L0X_get_dmax_cal_parameters(VL53L0X_DEV dev,
02222             uint16_t *p_range_milli_meter, FixPoint1616_t *p_signal_rate_rtn_mega_cps);
02223 
02224     /**
02225     * @brief   Set Dmax Calibration Parameters for a given device
02226     * When one of the parameter is zero, this function will get parameter
02227     * from NVM.
02228     * @note This function doesn't Access to the device
02229     *
02230     * @param   dev                    Device Handle
02231     * @param   range_milli_meter        Calibration Distance
02232     * @param   signal_rate_rtn_mega_cps   Signal rate return read at CalDistance
02233     * @return  VL53L0X_ERROR_NONE      Success
02234     * @return  "Other error code"     See ::VL53L0X_Error
02235     */
02236     VL53L0X_Error VL53L0X_get_dmax_cal_parameters(VL53L0X_DEV dev,
02237             uint16_t range_milli_meter, FixPoint1616_t signal_rate_rtn_mega_cps);
02238 
02239     /**
02240     * @brief Retrieve the measurements from device for a given setup
02241     *
02242     * @par Function Description
02243     * Get data from last successful Histogram measurement
02244     * @warning USER should take care about  @a VL53L0X_GetNumberOfROIZones()
02245     * before get data.
02246     * PAL will fill a NumberOfROIZones times the corresponding data structure
02247     * used in the measurement function.
02248     *
02249     * @note This function is not Implemented
02250     *
02251     * @param   dev                         Device Handle
02252     * @param   p_histogram_measurement_data   Pointer to the histogram data structure.
02253     * @return  VL53L0X_ERROR_NOT_IMPLEMENTED   Not implemented
02254     */
02255     VL53L0X_Error VL53L0X_get_histogram_measurement_data(VL53L0X_DEV dev,
02256             VL53L0X_HistogramMeasurementData_t *p_histogram_measurement_data);
02257 
02258     /**
02259     * @brief  Get current new device mode
02260     * @par Function Description
02261     * Get current Histogram mode of a Device
02262     *
02263     * @note This function doesn't Access to the device
02264     *
02265     * @param   dev                   Device Handle
02266     * @param   p_histogram_mode        Pointer to current Histogram Mode value
02267     *                                Valid values are:
02268     *                                VL53L0X_HISTOGRAMMODE_DISABLED
02269     *                                VL53L0X_DEVICEMODE_SINGLE_HISTOGRAM
02270     *                                VL53L0X_HISTOGRAMMODE_REFERENCE_ONLY
02271     *                                VL53L0X_HISTOGRAMMODE_RETURN_ONLY
02272     *                                VL53L0X_HISTOGRAMMODE_BOTH
02273     * @return  VL53L0X_ERROR_NONE     Success
02274     * @return  "Other error code"    See ::VL53L0X_Error
02275     */
02276     VL53L0X_Error VL53L0X_get_histogram_mode(VL53L0X_DEV dev,
02277             VL53L0X_HistogramModes *p_histogram_mode);
02278 
02279     /**
02280      * @brief  Set a new Histogram mode
02281      * @par Function Description
02282      * Set device to a new Histogram mode
02283      *
02284      * @note This function doesn't Access to the device
02285      *
02286      * @param   dev                   Device Handle
02287      * @param   histogram_mode         New device mode to apply
02288      *                                Valid values are:
02289      *                                VL53L0X_HISTOGRAMMODE_DISABLED
02290      *                                VL53L0X_DEVICEMODE_SINGLE_HISTOGRAM
02291      *                                VL53L0X_HISTOGRAMMODE_REFERENCE_ONLY
02292      *                                VL53L0X_HISTOGRAMMODE_RETURN_ONLY
02293      *                                VL53L0X_HISTOGRAMMODE_BOTH
02294      *
02295      * @return  VL53L0X_ERROR_NONE                   Success
02296      * @return  VL53L0X_ERROR_MODE_NOT_SUPPORTED     This error occurs when
02297      * HistogramMode is not in the supported list
02298      * @return  "Other error code"    See ::VL53L0X_Error
02299      */
02300     VL53L0X_Error VL53L0X_set_histogram_mode(VL53L0X_DEV dev,
02301             VL53L0X_HistogramModes histogram_mode);
02302 
02303     /**
02304      * @brief  Return a description string for a given limit check number
02305      *
02306      * @par Function Description
02307      * This function returns a description string for a given limit check number.
02308      * The limit check is identified with the LimitCheckId.
02309      *
02310      * @note This function doesn't Access to the device
02311      *
02312      * @param   dev                           Device Handle
02313      * @param   limit_check_id                  Limit Check ID
02314      (0<= LimitCheckId < VL53L0X_GetNumberOfLimitCheck() ).
02315      * @param   p_limit_check_string             Pointer to the
02316      description string of the given check limit.
02317      * @return  VL53L0X_ERROR_NONE             Success
02318      * @return  VL53L0X_ERROR_INVALID_PARAMS   This error is
02319      returned when LimitCheckId value is out of range.
02320      * @return  "Other error code"            See ::VL53L0X_Error
02321      */
02322     VL53L0X_Error VL53L0X_get_limit_check_info(VL53L0X_DEV dev,
02323             uint16_t limit_check_id, char *p_limit_check_string);
02324 
02325     /**
02326      * @brief Get the linearity corrective gain
02327      *
02328      * @par Function Description
02329      * Should only be used after a successful call to @a VL53L0X_DataInit to backup
02330      * device NVM value
02331      *
02332      * @note This function Access to the device
02333      *
02334      * @param   dev                                Device Handle
02335      * @param   p_linearity_corrective_gain           Pointer to the linearity
02336      * corrective gain in x1000
02337      * if value is 1000 then no modification is applied.
02338      * @return  VL53L0X_ERROR_NONE                  Success
02339      * @return  "Other error code"                 See ::VL53L0X_Error
02340      */
02341     VL53L0X_Error VL53L0X_get_linearity_corrective_gain(VL53L0X_DEV dev,
02342             uint16_t *p_linearity_corrective_gain);
02343 
02344     /**
02345      * Set the linearity corrective gain
02346      *
02347      * @note This function Access to the device
02348      *
02349      * @param   dev                                Device Handle
02350      * @param   linearity_corrective_gain            Linearity corrective
02351      * gain in x1000
02352      * if value is 1000 then no modification is applied.
02353      * @return  VL53L0X_ERROR_NONE                  Success
02354      * @return  "Other error code"                 See ::VL53L0X_Error
02355      */
02356     VL53L0X_Error VL53L0X_set_linearity_corrective_gain(VL53L0X_DEV dev,
02357             int16_t linearity_corrective_gain);
02358 
02359     /**
02360      * @brief Get the Maximum number of ROI Zones managed by the Device
02361      *
02362      * @par Function Description
02363      * Get Maximum number of ROI Zones managed by the Device.
02364      *
02365      * @note This function doesn't Access to the device
02366      *
02367      * @param   dev                    Device Handle
02368      * @param   p_max_number_of_roi_zones   Pointer to the Maximum Number
02369      *  of ROI Zones value.
02370      * @return  VL53L0X_ERROR_NONE      Success
02371      */
02372     VL53L0X_Error VL53L0X_get_max_number_of_roi_zones(VL53L0X_DEV dev,
02373             uint8_t *p_max_number_of_roi_zones);
02374 
02375     /**
02376      * @brief Retrieve the Reference Signal after a measurements
02377      *
02378      * @par Function Description
02379      * Get Reference Signal from last successful Ranging measurement
02380      * This function return a valid value after that you call the
02381      * @a VL53L0X_GetRangingMeasurementData().
02382      *
02383      * @note This function Access to the device
02384      *
02385      * @param   dev                      Device Handle
02386      * @param   p_measurement_ref_signal    Pointer to the Ref Signal to fill up.
02387      * @return  VL53L0X_ERROR_NONE        Success
02388      * @return  "Other error code"       See ::VL53L0X_Error
02389      */
02390     VL53L0X_Error VL53L0X_get_measurement_ref_signal(VL53L0X_DEV dev,
02391             FixPoint1616_t *p_measurement_ref_signal);
02392 
02393     /**
02394      * @brief  Get the number of the check limit managed by a given Device
02395      *
02396      * @par Function Description
02397      * This function give the number of the check limit managed by the Device
02398      *
02399      * @note This function doesn't Access to the device
02400      *
02401      * @param   p_number_of_limit_check           Pointer to the number of check limit.
02402      * @return  VL53L0X_ERROR_NONE             Success
02403      * @return  "Other error code"            See ::VL53L0X_Error
02404      */
02405     VL53L0X_Error VL53L0X_get_number_of_limit_check(
02406         uint16_t *p_number_of_limit_check);
02407 
02408     /**
02409      * @brief Get the number of ROI Zones managed by the Device
02410      *
02411      * @par Function Description
02412      * Get number of ROI Zones managed by the Device
02413      * USER should take care about  @a VL53L0X_GetNumberOfROIZones()
02414      * before get data after a perform measurement.
02415      * PAL will fill a NumberOfROIZones times the corresponding data
02416      * structure used in the measurement function.
02417      *
02418      * @note This function doesn't Access to the device
02419      *
02420      * @param   dev                   Device Handle
02421      * @param   p_number_of_roi_zones     Pointer to the Number of ROI Zones value.
02422      * @return  VL53L0X_ERROR_NONE     Success
02423      */
02424     VL53L0X_Error VL53L0X_get_number_of_roi_zones(VL53L0X_DEV dev,
02425             uint8_t *p_number_of_roi_zones);
02426 
02427     /**
02428      * @brief Set the number of ROI Zones to be used for a specific Device
02429      *
02430      * @par Function Description
02431      * Set the number of ROI Zones to be used for a specific Device.
02432      * The programmed value should be less than the max number of ROI Zones given
02433      * with @a VL53L0X_GetMaxNumberOfROIZones().
02434      * This version of API manage only one zone.
02435      *
02436      * @param   dev                           Device Handle
02437      * @param   number_of_roi_zones              Number of ROI Zones to be used for a
02438      *  specific Device.
02439      * @return  VL53L0X_ERROR_NONE             Success
02440      * @return  VL53L0X_ERROR_INVALID_PARAMS   This error is returned if
02441      * NumberOfROIZones != 1
02442      */
02443     VL53L0X_Error VL53L0X_set_number_of_roi_zones(VL53L0X_DEV dev,
02444             uint8_t number_of_roi_zones);
02445 
02446     /**
02447      * @brief Gets number of sequence steps managed by the API.
02448      *
02449      * @par Function Description
02450      * This function retrieves the number of sequence steps currently managed
02451      * by the API
02452      *
02453      * @note This function Accesses the device
02454      *
02455      * @param   dev                          Device Handle
02456      * @param   p_number_of_sequence_steps       Out parameter reporting the number of
02457      *                                       sequence steps.
02458      * @return  VL53L0X_ERROR_NONE            Success
02459      * @return  "Other error code"           See ::VL53L0X_Error
02460      */
02461     VL53L0X_Error VL53L0X_get_number_of_sequence_steps(VL53L0X_DEV dev,
02462             uint8_t *p_number_of_sequence_steps);
02463     /**
02464      * @brief Get the power mode for a given Device
02465      *
02466      * @note This function Access to the device
02467      *
02468      * @param   dev                   Device Handle
02469      * @param   p_power_mode            Pointer to the current value of the power
02470      * mode. see ::VL53L0X_PowerModes
02471      *                                Valid values are:
02472      *                                VL53L0X_POWERMODE_STANDBY_LEVEL1,
02473      *                                VL53L0X_POWERMODE_IDLE_LEVEL1
02474      * @return  VL53L0X_ERROR_NONE     Success
02475      * @return  "Other error code"    See ::VL53L0X_Error
02476      */
02477     VL53L0X_Error VL53L0X_get_power_mode(VL53L0X_DEV dev,
02478                                          VL53L0X_PowerModes *p_power_mode);
02479 
02480     /**
02481      * @brief Set the power mode for a given Device
02482      * The power mode can be Standby or Idle. Different level of both Standby and
02483      * Idle can exists.
02484      * This function should not be used when device is in Ranging state.
02485      *
02486      * @note This function Access to the device
02487      *
02488      * @param   dev                   Device Handle
02489      * @param   power_mode             The value of the power mode to set.
02490      * see ::VL53L0X_PowerModes
02491      *                                Valid values are:
02492      *                                VL53L0X_POWERMODE_STANDBY_LEVEL1,
02493      *                                VL53L0X_POWERMODE_IDLE_LEVEL1
02494      * @return  VL53L0X_ERROR_NONE                  Success
02495      * @return  VL53L0X_ERROR_MODE_NOT_SUPPORTED    This error occurs when PowerMode
02496      * is not in the supported list
02497      * @return  "Other error code"    See ::VL53L0X_Error
02498      */
02499     VL53L0X_Error VL53L0X_set_power_mode(VL53L0X_DEV dev,
02500                                          VL53L0X_PowerModes power_mode);
02501 
02502     /**
02503      * @brief Retrieves SPAD configuration
02504      *
02505      * @par Function Description
02506      * This function retrieves the current number of applied reference spads
02507      * and also their type : Aperture or Non-Aperture.
02508      *
02509      * @note This function Access to the device
02510      *
02511      * @param   dev                          Device Handle
02512      * @param   p_spad_count                 Number ref Spad Count
02513      * @param   p_is_aperture_spads              Reports if spads are of type
02514      *                                       aperture or non-aperture.
02515      *                                       1:=aperture, 0:=Non-Aperture
02516      * @return  VL53L0X_ERROR_NONE            Success
02517      * @return  VL53L0X_ERROR_REF_SPAD_INIT   Error in the in the reference
02518      *                                       spad configuration.
02519      * @return  "Other error code"           See ::VL53L0X_Error
02520      */
02521     VL53L0X_Error wrapped_VL53L0X_get_reference_spads(VL53L0X_DEV dev,
02522             uint32_t *p_spad_count, uint8_t *p_is_aperture_spads);
02523 
02524     /**
02525      * @brief Gets the (on/off) state of a requested sequence step.
02526      *
02527      * @par Function Description
02528      * This function retrieves the state of a requested sequence step, i.e. on/off.
02529      *
02530      * @note This function Accesses the device
02531      *
02532      * @param   dev                    Device Handle
02533      * @param   sequence_step_id         Sequence step identifier.
02534      * @param   p_sequence_step_enabled   Out parameter reporting if the sequence step
02535      *                                 is enabled {0=Off,1=On}.
02536      * @return  VL53L0X_ERROR_NONE            Success
02537      * @return  VL53L0X_ERROR_INVALID_PARAMS  Error SequenceStepId parameter not
02538      *                                       supported.
02539      * @return  "Other error code"           See ::VL53L0X_Error
02540      */
02541     VL53L0X_Error VL53L0X_get_sequence_step_enable(VL53L0X_DEV dev,
02542             VL53L0X_SequenceStepId sequence_step_id, uint8_t *p_sequence_step_enabled);
02543 
02544 
02545     /**
02546      * @brief Gets the timeout of a requested sequence step.
02547      *
02548      * @par Function Description
02549      * This function retrieves the timeout of a requested sequence step.
02550      *
02551      * @note This function Accesses the device
02552      *
02553      * @param   dev                          Device Handle
02554      * @param   sequence_step_id               Sequence step identifier.
02555      * @param   p_time_out_milli_secs            Timeout value.
02556      * @return  VL53L0X_ERROR_NONE            Success
02557      * @return  VL53L0X_ERROR_INVALID_PARAMS  Error SequenceStepId parameter not
02558      *                                       supported.
02559      * @return  "Other error code"           See ::VL53L0X_Error
02560      */
02561     VL53L0X_Error VL53L0X_get_sequence_step_timeout(VL53L0X_DEV dev,
02562             VL53L0X_SequenceStepId sequence_step_id,
02563             FixPoint1616_t *p_time_out_milli_secs);
02564 
02565     /**
02566      * @brief Sets the timeout of a requested sequence step.
02567      *
02568      * @par Function Description
02569      * This function sets the timeout of a requested sequence step.
02570      *
02571      * @note This function Accesses the device
02572      *
02573      * @param   dev                          Device Handle
02574      * @param   sequence_step_id               Sequence step identifier.
02575      * @param   time_out_milli_secs             Demanded timeout
02576      * @return  VL53L0X_ERROR_NONE            Success
02577      * @return  VL53L0X_ERROR_INVALID_PARAMS  Error SequenceStepId parameter not
02578      *                                       supported.
02579      * @return  "Other error code"           See ::VL53L0X_Error
02580      */
02581     VL53L0X_Error VL53L0X_set_sequence_step_timeout(VL53L0X_DEV dev,
02582             VL53L0X_SequenceStepId sequence_step_id, FixPoint1616_t time_out_milli_secs);
02583 
02584     /**
02585     * @brief  Get the current SPAD Ambient Damper Factor value
02586     *
02587     * @par Function Description
02588     * This function get the SPAD Ambient Damper Factor value
02589     *
02590     * @note This function Access to the device
02591     *
02592     * @param   dev                           Device Handle
02593     * @param   p_spad_ambient_damper_factor      Pointer to programmed SPAD Ambient
02594     * Damper Factor value
02595     * @return  VL53L0X_ERROR_NONE             Success
02596     * @return  "Other error code"            See ::VL53L0X_Error
02597     */
02598     VL53L0X_Error VL53L0X_get_spad_ambient_damper_factor(VL53L0X_DEV dev,
02599             uint16_t *p_spad_ambient_damper_factor);
02600     /**
02601     * @brief  Set the SPAD Ambient Damper Factor value
02602     *
02603     * @par Function Description
02604     * This function set the SPAD Ambient Damper Factor value
02605     *
02606     * @note This function Access to the device
02607     *
02608     * @param   dev                           Device Handle
02609     * @param   spad_ambient_damper_factor       SPAD Ambient Damper Factor value
02610     * @return  VL53L0X_ERROR_NONE             Success
02611     * @return  "Other error code"            See ::VL53L0X_Error
02612     */
02613     VL53L0X_Error VL53L0X_set_spad_ambient_damper_factor(VL53L0X_DEV dev,
02614             uint16_t spad_ambient_damper_factor);
02615 
02616     /**
02617      * @brief  Get the current SPAD Ambient Damper Threshold value
02618      *
02619      * @par Function Description
02620      * This function get the SPAD Ambient Damper Threshold value
02621      *
02622      * @note This function Access to the device
02623      *
02624      * @param   dev                           Device Handle
02625      * @param   p_spad_ambient_damper_threshold   Pointer to programmed
02626      *                                        SPAD Ambient Damper Threshold value
02627      * @return  VL53L0X_ERROR_NONE             Success
02628      * @return  "Other error code"            See ::VL53L0X_Error
02629      */
02630     VL53L0X_Error VL53L0X_get_spad_ambient_damper_threshold(VL53L0X_DEV dev,
02631             uint16_t *p_spad_ambient_damper_threshold);
02632 
02633     /**
02634      * @brief  Set the SPAD Ambient Damper Threshold value
02635      *
02636      * @par Function Description
02637      * This function set the SPAD Ambient Damper Threshold value
02638      *
02639      * @note This function Access to the device
02640      *
02641      * @param   dev                           Device Handle
02642      * @param   spad_ambient_damper_threshold    SPAD Ambient Damper Threshold value
02643      * @return  VL53L0X_ERROR_NONE             Success
02644      * @return  "Other error code"            See ::VL53L0X_Error
02645      */
02646     VL53L0X_Error VL53L0X_set_spad_ambient_damper_threshold(VL53L0X_DEV dev,
02647             uint16_t spad_ambient_damper_threshold);
02648 
02649     /**
02650      * @brief Get the maximal distance for actual setup
02651      * @par Function Description
02652      * Device must be initialized through @a VL53L0X_SetParameters() prior calling
02653      * this function.
02654      *
02655      * Any range value more than the value returned is to be considered as
02656      * "no target detected" or
02657      * "no target in detectable range"\n
02658      * @warning The maximal distance depends on the setup
02659      *
02660      * @note This function is not Implemented
02661      *
02662      * @param   dev      Device Handle
02663      * @param   p_upper_limit_milli_meter   The maximal range limit for actual setup
02664      * (in millimeter)
02665      * @return  VL53L0X_ERROR_NOT_IMPLEMENTED        Not implemented
02666      */
02667     VL53L0X_Error VL53L0X_get_upper_limit_milli_meter(VL53L0X_DEV dev,
02668             uint16_t *p_upper_limit_milli_meter);
02669 
02670     /**
02671     * @brief Get the tuning settings pointer and the internal external switch
02672     * value.
02673     *
02674     * This function is used to get the Tuning settings buffer pointer and the
02675     * value.
02676     * of the switch to select either external or internal tuning settings.
02677     *
02678     * @note This function Access to the device
02679     *
02680     * @param   dev                        Device Handle
02681     * @param   pp_tuning_setting_buffer      Pointer to tuning settings buffer.
02682     * @param   p_use_internal_tuning_settings Pointer to store Use internal tuning
02683     *                                     settings value.
02684     * @return  VL53L0X_ERROR_NONE          Success
02685     * @return  "Other error code"         See ::VL53L0X_Error
02686     */
02687     VL53L0X_Error VL53L0X_get_tuning_setting_buffer(VL53L0X_DEV dev,
02688             uint8_t **pp_tuning_setting_buffer, uint8_t *p_use_internal_tuning_settings);
02689 
02690     /**
02691      * @brief Set the tuning settings pointer
02692      *
02693      * This function is used to specify the Tuning settings buffer to be used
02694      * for a given device. The buffer contains all the necessary data to permit
02695      * the API to write tuning settings.
02696      * This function permit to force the usage of either external or internal
02697      * tuning settings.
02698      *
02699      * @note This function Access to the device
02700      *
02701      * @param   dev                             Device Handle
02702      * @param   p_tuning_setting_buffer            Pointer to tuning settings buffer.
02703      * @param   use_internal_tuning_settings       Use internal tuning settings value.
02704      * @return  VL53L0X_ERROR_NONE     Success
02705      * @return  "Other error code"    See ::VL53L0X_Error
02706      */
02707     VL53L0X_Error VL53L0X_set_tuning_setting_buffer(VL53L0X_DEV dev,
02708             uint8_t *p_tuning_setting_buffer, uint8_t use_internal_tuning_settings);
02709 
02710     /**
02711      * @defgroup VL53L0X_registerAccess_group PAL Register Access Functions
02712      * @brief    PAL Register Access Functions
02713      *  @{
02714      */
02715 
02716     /**
02717      * Lock comms interface to serialize all commands to a shared I2C interface for a specific device
02718      * @param   dev       Device Handle
02719      * @return  VL53L0X_ERROR_NONE        Success
02720      * @return  "Other error code"    See ::VL53L0X_Error
02721      */
02722     VL53L0X_Error VL53L0X_lock_sequence_access(VL53L0X_DEV dev);
02723 
02724     /**
02725      * Unlock comms interface to serialize all commands to a shared I2C interface for a specific device
02726      * @param   dev       Device Handle
02727      * @return  VL53L0X_ERROR_NONE        Success
02728      * @return  "Other error code"    See ::VL53L0X_Error
02729      */
02730     VL53L0X_Error VL53L0X_unlock_sequence_access(VL53L0X_DEV dev);
02731 
02732     /**
02733      * @brief  Prepare device for operation
02734      * @par Function Description
02735      * Update device with provided parameters
02736      * @li Then start ranging operation.
02737      *
02738      * @note This function Access to the device
02739      *
02740      * @param   Dev                   Device Handle
02741      * @param   pDeviceParameters     Pointer to store current device parameters.
02742      * @return  VL53L0X_ERROR_NONE     Success
02743      * @return  "Other error code"    See ::VL53L0X_Error
02744      */
02745     VL53L0X_Error vl53L0x_set_device_parameters(VL53L0X_DEV Dev,
02746             const VL53L0X_DeviceParameters_t *pDeviceParameters);
02747 
02748     /**
02749      * Set Group parameter Hold state
02750      *
02751      * @par Function Description
02752      * Set or remove device internal group parameter hold
02753      *
02754      * @note This function is not Implemented
02755      *
02756      * @param   dev      Device Handle
02757      * @param   group_param_hold   Group parameter Hold state to be set (on/off)
02758      * @return  VL53L0X_ERROR_NOT_IMPLEMENTED        Not implemented
02759      */
02760     VL53L0X_Error VL53L0X_set_group_param_hold(VL53L0X_DEV dev,
02761             uint8_t group_param_hold);
02762 
02763 
02764     /**
02765      * @brief Wait for device ready for a new measurement command.
02766      * Blocking function.
02767      *
02768      * @note This function is not Implemented
02769      *
02770      * @param   dev      Device Handle
02771      * @param   max_loop    Max Number of polling loop (timeout).
02772      * @return  VL53L0X_ERROR_NOT_IMPLEMENTED   Not implemented
02773      */
02774     VL53L0X_Error VL53L0X_wait_device_ready_for_new_measurement(VL53L0X_DEV dev,
02775             uint32_t max_loop);
02776 
02777     VL53L0X_Error VL53L0X_reverse_bytes(uint8_t *data, uint32_t size);
02778 
02779     int range_meas_int_continuous_mode(void (*fptr)(void));
02780 
02781 
02782     VL53L0X_DeviceInfo_t _device_info;
02783 
02784     /* IO Device */
02785     DevI2C *_dev_i2c;
02786     /* Digital out pin */
02787     DigitalOut *_gpio0;
02788     /* GPIO expander */
02789     Stmpe1600DigiOut *_expgpio0;
02790     /* Measure detection IRQ */
02791     InterruptIn *_gpio1Int;
02792     /* Device data */
02793     VL53L0X_Dev_t _my_device;
02794     VL53L0X_DEV _device;
02795 };
02796 
02797 
02798 #endif /* _VL53L0X_CLASS_H_ */