ST Expansion SW Team / VL53L1X_mbed

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   X_NUCLEO_53L1A1_mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers vl53l1x_class.h Source File

vl53l1x_class.h

00001 /*******************************************************************************
00002  * @file    vl53l1x_class.h
00003  * @author  JS
00004  * @version V0.0.1
00005  * @date    15-January-2019
00006  * @brief   Header file for VL53L1 sensor component
00007  ******************************************************************************
00008  Copyright © 2019, STMicroelectronics International N.V.
00009  All rights reserved.
00010  Redistribution and use in source and binary forms, with or without
00011  modification, are permitted provided that the following conditions are met:
00012  * Redistributions of source code must retain the above copyright
00013  notice, this list of conditions and the following disclaimer.
00014  * Redistributions in binary form must reproduce the above copyright
00015  notice, this list of conditions and the following disclaimer in the
00016  documentation and/or other materials provided with the distribution.
00017  * Neither the name of STMicroelectronics nor the
00018  names of its contributors may be used to endorse or promote products
00019  derived from this software without specific prior written permission.
00020  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00021  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022  WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
00023  NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
00024  IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
00025  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00026  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00028  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  *****************************************************************************/
00032 
00033 #ifndef __VL53L1X_CLASS_H
00034 #define __VL53L1X_CLASS_H
00035 
00036 
00037 #ifdef _MSC_VER
00038 #   ifdef VL53L1X_API_EXPORTS
00039 #       define VL53L1X_API  __declspec(dllexport)
00040 #   else
00041 #       define VL53L1X_API
00042 #   endif
00043 #else
00044 #   define VL53L1X_API
00045 #endif
00046 
00047 
00048 /* Includes ------------------------------------------------------------------*/
00049 #include "mbed.h"
00050 #include "PinNames.h"
00051 #include "RangeSensor.h"
00052 #include "vl53l1x_error_codes.h"
00053 #include "vl53L1x_I2c.h"
00054 #include "Stmpe1600.h"
00055 
00056 #if (MBED_VERSION  > 60300)
00057 extern "C" void wait_ms(int ms);
00058 #endif
00059 
00060 #define VL53L1X_IMPLEMENTATION_VER_MAJOR       1
00061 #define VL53L1X_IMPLEMENTATION_VER_MINOR       0
00062 #define VL53L1X_IMPLEMENTATION_VER_SUB         1
00063 #define VL53L1X_IMPLEMENTATION_VER_REVISION  0000
00064 
00065 typedef int8_t VL53L1X_ERROR;
00066 
00067 #define VL53L1_I2C_SLAVE__DEVICE_ADDRESS                    0x0001
00068 #define VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND        0x0008
00069 #define ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS      0x0016
00070 #define ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS  0x0018
00071 #define ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS  0x001A
00072 #define ALGO__PART_TO_PART_RANGE_OFFSET_MM                  0x001E
00073 #define MM_CONFIG__INNER_OFFSET_MM                          0x0020
00074 #define MM_CONFIG__OUTER_OFFSET_MM                          0x0022
00075 #define GPIO_HV_MUX__CTRL                                   0x0030
00076 #define GPIO__TIO_HV_STATUS                                 0x0031
00077 #define SYSTEM__INTERRUPT_CONFIG_GPIO                       0x0046
00078 #define PHASECAL_CONFIG__TIMEOUT_MACROP                     0x004B
00079 #define RANGE_CONFIG__TIMEOUT_MACROP_A_HI                   0x005E
00080 #define RANGE_CONFIG__VCSEL_PERIOD_A                        0x0060
00081 #define RANGE_CONFIG__VCSEL_PERIOD_B                        0x0063
00082 #define RANGE_CONFIG__TIMEOUT_MACROP_B_HI                   0x0061
00083 #define RANGE_CONFIG__TIMEOUT_MACROP_B_LO                   0x0062
00084 #define RANGE_CONFIG__SIGMA_THRESH                          0x0064
00085 #define RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS         0x0066
00086 #define RANGE_CONFIG__VALID_PHASE_HIGH                      0x0069
00087 #define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD              0x006C
00088 #define SYSTEM__THRESH_HIGH                                 0x0072
00089 #define SYSTEM__THRESH_LOW                                  0x0074
00090 #define SD_CONFIG__WOI_SD0                                  0x0078
00091 #define SD_CONFIG__INITIAL_PHASE_SD0                        0x007A
00092 #define ROI_CONFIG__USER_ROI_CENTRE_SPAD                    0x007F
00093 #define ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE       0x0080
00094 #define SYSTEM__SEQUENCE_CONFIG                             0x0081
00095 #define VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD               0x0082
00096 #define SYSTEM__INTERRUPT_CLEAR                             0x0086
00097 #define SYSTEM__MODE_START                                  0x0087
00098 #define VL53L1_RESULT__RANGE_STATUS                         0x0089
00099 #define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0       0x008C
00100 #define RESULT__AMBIENT_COUNT_RATE_MCPS_SD                  0x0090
00101 #define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0               0x0096
00102 #define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0  0x0098
00103 #define VL53L1_RESULT__OSC_CALIBRATE_VAL                    0x00DE
00104 #define VL53L1_FIRMWARE__SYSTEM_STATUS                      0x00E5
00105 #define VL53L1_IDENTIFICATION__MODEL_ID                     0x010F
00106 #define VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD             0x013E
00107 
00108 
00109 #define VL53L1X_DEFAULT_DEVICE_ADDRESS                      0x52
00110 
00111 #define VL53L1X_REG_IDENTIFICATION_MODEL_ID                 0x010F
00112 /****************************************
00113  * PRIVATE define do not edit
00114  ****************************************/
00115 
00116 /**
00117  *  @brief defines SW Version
00118  */
00119 typedef struct {
00120     uint8_t      major ;    /*!< major number */
00121     uint8_t      minor ;    /*!< minor number */
00122     uint8_t      build ;    /*!< build number */
00123     uint32_t     revision ; /*!< revision number */
00124 } VL53L1X_Version_t;
00125 
00126 
00127 typedef struct {
00128 
00129     uint8_t   I2cDevAddr;
00130 
00131 } VL53L1_Dev_t;
00132 
00133 typedef VL53L1_Dev_t *VL53L1_DEV;
00134 
00135 
00136 /* Classes -------------------------------------------------------------------*/
00137 /** Class representing a VL53L1 sensor component
00138  */
00139 class VL53L1X : public RangeSensor
00140 {
00141  public:
00142     /** Constructor
00143      * @param[in] &i2c device I2C to be used for communication
00144      * @param[in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
00145      * @param[in] DevAddr device address, 0x52 by default
00146      */
00147     VL53L1X(vl53L1X_DevI2C *i2c, DigitalOut *pin, PinName pin_gpio1, uint8_t dev_addr = VL53L1X_DEFAULT_DEVICE_ADDRESS) 
00148     : RangeSensor(), dev_i2c(i2c), _gpio0(pin)
00149     {
00150         MyDevice.I2cDevAddr=dev_addr;
00151         Device = &MyDevice;
00152                
00153         _expgpio0 = NULL;
00154         if (pin_gpio1 != NC) {
00155             _gpio1Int = new InterruptIn(pin_gpio1);
00156         } else {
00157             _gpio1Int = NULL;
00158         }
00159     }
00160     
00161     /** Constructor 2 (STMPE1600DigiOut)
00162      * @param[in] i2c device I2C to be used for communication
00163      * @param[in] &pin Gpio Expander STMPE1600DigiOut pin to be used as component GPIO_0 CE
00164      * @param[in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
00165      * @param[in] device address, 0x29 by default
00166      */
00167     VL53L1X(vl53L1X_DevI2C *i2c, Stmpe1600DigiOut *pin, PinName pin_gpio1,
00168             uint8_t dev_addr = VL53L1X_DEFAULT_DEVICE_ADDRESS) 
00169             : dev_i2c(i2c), _expgpio0(pin)
00170     {
00171         MyDevice.I2cDevAddr=dev_addr;
00172         Device = &MyDevice;
00173                
00174         _gpio0 = NULL;
00175         if (pin_gpio1 != NC) {
00176             _gpio1Int = new InterruptIn(pin_gpio1);
00177         } else {
00178             _gpio1Int = NULL;
00179         }
00180     }    
00181     
00182    /** Destructor
00183     */
00184     virtual ~VL53L1X()
00185     {        
00186         if (_gpio1Int != NULL) {
00187             delete _gpio1Int;
00188         }
00189     }
00190     
00191         
00192     
00193     VL53L1_DEV getDevicePtr() { return Device; }
00194 
00195     
00196     /* warning: VL53L1 class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor.
00197        The warning should request to introduce a virtual destructor to make sure to delete the object */
00198 
00199     /*** Interface Methods ***/
00200     /*** High level API ***/
00201     /**
00202      * @brief       PowerOn the sensor
00203      * @return      void
00204      */
00205     /* turns on the sensor */
00206     virtual void VL53L1_On(void)
00207     {
00208         printf("VL53L1_On\r\n");
00209         if (_gpio0) {
00210             *_gpio0 = 1;
00211         } else {
00212             if (_expgpio0) {
00213                 *_expgpio0 = 1;
00214             }
00215         }
00216         wait_ms(10);
00217     }
00218 
00219     /**
00220      * @brief       PowerOff the sensor
00221      * @return      void
00222      */
00223     /* turns off the sensor */
00224     virtual void VL53L1_Off(void)
00225     {
00226         printf("VL53L1_Off\r\n");
00227         if (_gpio0) {
00228             *_gpio0 = 0;
00229         } else {
00230             if (_expgpio0) {
00231                 *_expgpio0 = 0;
00232             }
00233         }
00234         wait_ms(10);
00235     }
00236     
00237     int is_present()
00238     {
00239         int status;
00240         uint8_t id = 0;
00241 
00242         status = read_id(&id);
00243         if (status) {
00244             printf("Failed to read ID device. Device not present!\n\r");
00245         }
00246         return status;
00247     }
00248 
00249     /**
00250      * @brief       Initialize the sensor with default values
00251      * @return      0 on Success
00252      */
00253      
00254      VL53L1X_ERROR InitSensor(uint8_t address){
00255         VL53L1X_ERROR status = 0;
00256         uint8_t sensorState = 0;
00257         VL53L1_Off();
00258         VL53L1_On();
00259         status = VL53L1X_SetI2CAddress(address);
00260         
00261         if(!status){
00262             status = VL53L1X_SensorInit();
00263         }      
00264         
00265         while(!status && !sensorState) {
00266             status = VL53L1X_BootState(&sensorState);
00267             wait_ms(2);
00268         }
00269         
00270         return status;
00271      }
00272 
00273 
00274 
00275     /**
00276      *
00277      * @brief One time device initialization
00278      * @param void
00279      * @return     0 on success,  @a #CALIBRATION_WARNING if failed
00280      */
00281     virtual int init(void *init)
00282     {
00283        return VL53L1X_SensorInit();
00284 
00285     }
00286 
00287     /**
00288      * @brief       Initialize the sensor with default values
00289      * @return      "0" on success
00290      */
00291     int init_sensor(uint8_t new_addr);
00292 
00293     /* Read function of the ID device */
00294     virtual int read_id(uint8_t *id){
00295         int status = 0;
00296         uint16_t rl_id = 0;
00297     
00298         uint8_t ExpanderData[2];
00299     
00300         ExpanderData[0] = 0;
00301         ExpanderData[1] = 0;
00302         rl_id = 0;
00303         dev_i2c->v53l1x_i2c_read(&ExpanderData[0], Device->I2cDevAddr, VL53L1X_REG_IDENTIFICATION_MODEL_ID, 2);
00304     
00305         rl_id = (ExpanderData[0] << 8) + ExpanderData[1];
00306         printf("Model ID is: %d (%X)  \r\n",rl_id, rl_id);
00307     
00308         uint8_t tmp = 0;
00309         ExpanderData[0] = VL53L1_FIRMWARE__SYSTEM_STATUS >> 8;
00310         ExpanderData[1] = VL53L1_FIRMWARE__SYSTEM_STATUS & 0x0FF;
00311         dev_i2c->v53l1x_i2c_read(&tmp, Device->I2cDevAddr, VL53L1_FIRMWARE__SYSTEM_STATUS, 1);
00312 
00313         printf("Firmware system is: %d\r\n",tmp);
00314     
00315         if (rl_id == 0xEACC) {
00316             printf("Device is present %d:\r\n", rl_id);
00317             return status;
00318         }
00319         return -1;
00320     }
00321 
00322     /**
00323      * @brief       Interrupt handling func to be called by user after an INT is occurred
00324      * @param[out]  Data pointer to the distance to read data in to
00325      * @return      0 on Success
00326      */
00327     int handle_irq(uint16_t *distance);
00328 
00329     /**
00330      * @brief       Start the measure indicated by operating mode
00331      * @param[in]   fptr specifies call back function must be !NULL in case of interrupt measure
00332      * @return      0 on Success
00333      */
00334     int start_measurement(void (*fptr)(void));
00335     /**
00336      * @brief       Stop the currently running measure indicate by operating_mode
00337      * @return      0 on Success
00338      */
00339     int stop_measurement();
00340     /**
00341      * @brief       Get results for the measure
00342      * @param[out]  Data pointer to the distance_data to read data in to
00343      * @return      0 on Success
00344      */
00345     int get_measurement(uint16_t *distance);
00346     /**
00347      * @brief       Enable interrupt measure IRQ
00348      * @return      0 on Success
00349      */
00350     void enable_interrupt_measure_detection_irq(void)
00351     {
00352         if (_gpio1Int != NULL)
00353             _gpio1Int->enable_irq();
00354     }
00355 
00356     /**
00357      * @brief       Disable interrupt measure IRQ
00358      * @return      0 on Success
00359      */
00360     void disable_interrupt_measure_detection_irq(void)
00361     {
00362         if (_gpio1Int != NULL)
00363             _gpio1Int->disable_irq();
00364     }
00365     /**
00366      * @brief       Attach a function to call when an interrupt is detected, i.e. measurement is ready
00367      * @param[in]   fptr pointer to call back function to be called whenever an interrupt occours
00368      * @return      0 on Success
00369      */
00370     void attach_interrupt_measure_detection_irq(void (*fptr)(void))
00371     {
00372         if (_gpio1Int != NULL)
00373             _gpio1Int->rise(fptr);
00374     }
00375     /**
00376      * @brief Get ranging result and only that
00377      * @param pRange_mm  Pointer to range distance
00378      * @return           0 on success
00379      */
00380     virtual int get_distance(uint32_t *piData)
00381     {
00382     int status;
00383     uint16_t distance;
00384     status = VL53L1X_GetDistance(&distance);
00385     *piData = (uint32_t) distance;
00386     return status;
00387     }
00388 
00389 
00390     /* VL53L1X_api.h functions */
00391 
00392     /**
00393      * @brief This function returns the SW driver version
00394      */
00395     VL53L1X_ERROR VL53L1X_GetSWVersion(VL53L1X_Version_t *pVersion);
00396 
00397     /**
00398      * @brief This function sets the sensor I2C address used in case multiple devices application, default address 0x52
00399      */
00400     VL53L1X_ERROR VL53L1X_SetI2CAddress(uint8_t new_address);
00401 
00402     /**
00403      * @brief This function loads the 135 bytes default values to initialize the sensor.
00404      * @param dev Device address
00405      * @return 0:success, != 0:failed
00406      */
00407     VL53L1X_ERROR VL53L1X_SensorInit();
00408 
00409     /**
00410      * @brief This function clears the interrupt, to be called after a ranging data reading
00411      * to arm the interrupt for the next data ready event.
00412      */
00413     VL53L1X_ERROR VL53L1X_ClearInterrupt();
00414 
00415     /**
00416      * @brief This function programs the interrupt polarity\n
00417      * 1=active high (default), 0=active low
00418      */
00419     VL53L1X_ERROR VL53L1X_SetInterruptPolarity(uint8_t IntPol);
00420 
00421     /**
00422      * @brief This function returns the current interrupt polarity\n
00423      * 1=active high (default), 0=active low
00424      */
00425     VL53L1X_ERROR VL53L1X_GetInterruptPolarity(uint8_t *pIntPol);
00426 
00427     /**
00428      * @brief This function starts the ranging distance operation\n
00429      * The ranging operation is continuous. The clear interrupt has to be done after each get data to allow the interrupt to raise when the next data is ready\n
00430      * 1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required.
00431      */
00432     VL53L1X_ERROR VL53L1X_StartRanging();
00433 
00434     /**
00435      * @brief This function stops the ranging.
00436      */
00437     VL53L1X_ERROR VL53L1X_StopRanging();
00438 
00439     /**
00440      * @brief This function checks if the new ranging data is available by polling the dedicated register.
00441      * @param : isDataReady==0 -> not ready; isDataReady==1 -> ready
00442      */
00443     VL53L1X_ERROR VL53L1X_CheckForDataReady(uint8_t *isDataReady);
00444     
00445     /**
00446      * @brief This function programs the timing budget in ms.
00447      * Predefined values = 15, 20, 33, 50, 100(default), 200, 500.
00448      */
00449     VL53L1X_ERROR VL53L1X_SetTimingBudgetInMs(uint16_t TimingBudgetInMs);
00450 
00451     /**
00452      * @brief This function returns the current timing budget in ms.
00453      */
00454     VL53L1X_ERROR VL53L1X_GetTimingBudgetInMs(uint16_t *pTimingBudgetInMs);
00455 
00456     /**
00457      * @brief This function programs the distance mode (1=short, 2=long(default)).
00458      * Short mode max distance is limited to 1.3 m but better ambient immunity.\n
00459      * Long mode can range up to 4 m in the dark with 200 ms timing budget.
00460      */
00461     VL53L1X_ERROR VL53L1X_SetDistanceMode(uint16_t DistanceMode);
00462 
00463     /**
00464      * @brief This function returns the current distance mode (1=short, 2=long).
00465      */
00466     VL53L1X_ERROR VL53L1X_GetDistanceMode(uint16_t *pDistanceMode);
00467 
00468     /**
00469      * @brief This function programs the Intermeasurement period in ms\n
00470      * Intermeasurement period must be >/= timing budget. This condition is not checked by the API,
00471      * the customer has the duty to check the condition. Default = 100 ms
00472      */
00473     VL53L1X_ERROR VL53L1X_SetInterMeasurementInMs(uint16_t InterMeasurementInMs);
00474 
00475     /**
00476      * @brief This function returns the Intermeasurement period in ms.
00477      */
00478     VL53L1X_ERROR VL53L1X_GetInterMeasurementInMs(uint16_t * pIM);
00479 
00480     /**
00481      * @brief This function returns the boot state of the device (1:booted, 0:not booted)
00482      */
00483     VL53L1X_ERROR VL53L1X_BootState(uint8_t *state);
00484 
00485     /**
00486      * @brief This function returns the sensor id, sensor Id must be 0xEEAC
00487      */
00488     VL53L1X_ERROR VL53L1X_GetSensorId(uint16_t *id);
00489 
00490     /**
00491      * @brief This function returns the distance measured by the sensor in mm
00492      */
00493     VL53L1X_ERROR VL53L1X_GetDistance(uint16_t *distance);
00494 
00495     /**
00496      * @brief This function returns the returned signal per SPAD in kcps/SPAD.
00497      * With kcps stands for Kilo Count Per Second
00498      */
00499     VL53L1X_ERROR VL53L1X_GetSignalPerSpad(uint16_t *signalPerSp);
00500 
00501     /**
00502      * @brief This function returns the ambient per SPAD in kcps/SPAD
00503      */
00504     VL53L1X_ERROR VL53L1X_GetAmbientPerSpad(uint16_t *amb);
00505 
00506     /**
00507      * @brief This function returns the returned signal in kcps.
00508      */
00509     VL53L1X_ERROR VL53L1X_GetSignalRate(uint16_t *signalRate);
00510 
00511     /**
00512      * @brief This function returns the current number of enabled SPADs
00513      */
00514     VL53L1X_ERROR VL53L1X_GetSpadNb(uint16_t *spNb);
00515 
00516     /**
00517      * @brief This function returns the ambient rate in kcps
00518      */
00519     VL53L1X_ERROR VL53L1X_GetAmbientRate(uint16_t *ambRate);
00520 
00521     /**
00522      * @brief This function returns the ranging status error \n
00523      * (0:no error, 1:sigma failed, 2:signal failed, ..., 7:wrap-around)
00524      */
00525     VL53L1X_ERROR VL53L1X_GetRangeStatus(uint8_t *rangeStatus);
00526 
00527     /**
00528      * @brief This function programs the offset correction in mm
00529      * @param OffsetValue:the offset correction value to program in mm
00530      */
00531     VL53L1X_ERROR VL53L1X_SetOffset(int16_t OffsetValue);
00532 
00533     /**
00534      * @brief This function returns the programmed offset correction value in mm
00535      */
00536     VL53L1X_ERROR VL53L1X_GetOffset(int16_t *Offset);
00537 
00538     /**
00539      * @brief This function programs the xtalk correction value in cps (Count Per Second).\n
00540      * This is the number of photons reflected back from the cover glass in cps.
00541      */
00542     VL53L1X_ERROR VL53L1X_SetXtalk(uint16_t XtalkValue);
00543 
00544     /**
00545      * @brief This function returns the current programmed xtalk correction value in cps
00546      */
00547     VL53L1X_ERROR VL53L1X_GetXtalk(uint16_t *Xtalk);
00548 
00549     /**
00550      * @brief This function programs the threshold detection mode\n
00551      * Example:\n
00552      * VL53L1X_SetDistanceThreshold(dev,100,300,0,1): Below 100 \n
00553      * VL53L1X_SetDistanceThreshold(dev,100,300,1,1): Above 300 \n
00554      * VL53L1X_SetDistanceThreshold(dev,100,300,2,1): Out of window \n
00555      * VL53L1X_SetDistanceThreshold(dev,100,300,3,1): In window \n
00556      * @param   dev : device address
00557      * @param   ThreshLow(in mm) : the threshold under which one the device raises an interrupt if Window = 0
00558      * @param   ThreshHigh(in mm) :  the threshold above which one the device raises an interrupt if Window = 1
00559      * @param   Window detection mode : 0=below, 1=above, 2=out, 3=in
00560      * @param   IntOnNoTarget = 1 (No longer used - just use 1)
00561      */
00562     VL53L1X_ERROR VL53L1X_SetDistanceThreshold(uint16_t ThreshLow,
00563                       uint16_t ThreshHigh, uint8_t Window,
00564                       uint8_t IntOnNoTarget);
00565 
00566     /**
00567      * @brief This function returns the window detection mode (0=below; 1=above; 2=out; 3=in)
00568      */
00569     VL53L1X_ERROR VL53L1X_GetDistanceThresholdWindow(uint16_t *window);
00570 
00571     /**
00572      * @brief This function returns the low threshold in mm
00573      */
00574     VL53L1X_ERROR VL53L1X_GetDistanceThresholdLow(uint16_t *low);
00575 
00576     /**
00577      * @brief This function returns the high threshold in mm
00578      */
00579     VL53L1X_ERROR VL53L1X_GetDistanceThresholdHigh(uint16_t *high);
00580 
00581     /**
00582      * @brief This function programs the ROI (Region of Interest)\n
00583      * The ROI position is centered, only the ROI size can be reprogrammed.\n
00584      * The smallest acceptable ROI size = 4\n
00585      * @param X:ROI Width; Y=ROI Height
00586      */
00587     VL53L1X_ERROR VL53L1X_SetROI(uint16_t X, uint16_t Y);
00588 
00589     /**
00590      *@brief This function returns width X and height Y
00591      */
00592     VL53L1X_ERROR VL53L1X_GetROI_XY(uint16_t *ROI_X, uint16_t *ROI_Y);
00593 
00594     /**
00595      * @brief This function programs a new signal threshold in kcps (default=1024 kcps\n
00596      */
00597     VL53L1X_ERROR VL53L1X_SetSignalThreshold(uint16_t signal);
00598 
00599     /**
00600      * @brief This function returns the current signal threshold in kcps
00601      */
00602     VL53L1X_ERROR VL53L1X_GetSignalThreshold(uint16_t *signal);
00603 
00604     /**
00605      * @brief This function programs a new sigma threshold in mm (default=15 mm)
00606      */
00607     VL53L1X_ERROR VL53L1X_SetSigmaThreshold(uint16_t sigma);
00608 
00609     /**
00610      * @brief This function returns the current sigma threshold in mm
00611      */
00612     VL53L1X_ERROR VL53L1X_GetSigmaThreshold(uint16_t *signal);
00613 
00614     /**
00615      * @brief This function performs the temperature calibration.
00616      * It is recommended to call this function any time the temperature might have changed by more than 8 deg C
00617      * without sensor ranging activity for an extended period.
00618      */
00619     VL53L1X_ERROR VL53L1X_StartTemperatureUpdate();
00620 
00621 
00622     /* VL53L1X_calibration.h functions */
00623     
00624         /**
00625      * @brief This function performs the offset calibration.\n
00626      * The function returns the offset value found and programs the offset compensation into the device.
00627      * @param TargetDistInMm target distance in mm, ST recommended 100 mm
00628      * Target reflectance = grey17%
00629      * @return 0:success, !=0: failed
00630      * @return offset pointer contains the offset found in mm
00631      */
00632     int8_t VL53L1X_CalibrateOffset(uint16_t TargetDistInMm, int16_t *offset);
00633 
00634     /**
00635      * @brief This function performs the xtalk calibration.\n
00636      * The function returns the xtalk value found and programs the xtalk compensation to the device
00637      * @param TargetDistInMm target distance in mm\n
00638      * The target distance : the distance where the sensor start to "under range"\n
00639      * due to the influence of the photons reflected back from the cover glass becoming strong\n
00640      * It's also called inflection point\n
00641      * Target reflectance = grey 17%
00642      * @return 0: success, !=0: failed
00643      * @return xtalk pointer contains the xtalk value found in cps (number of photons in count per second)
00644      */
00645     int8_t VL53L1X_CalibrateXtalk(uint16_t TargetDistInMm, uint16_t *xtalk);
00646     
00647 
00648     /* Write and read functions from I2C */
00649 
00650     VL53L1X_ERROR VL53L1_WrByte(VL53L1_DEV dev, uint16_t index, uint8_t data);
00651     VL53L1X_ERROR VL53L1_WrWord(VL53L1_DEV dev, uint16_t index, uint16_t data);
00652     VL53L1X_ERROR VL53L1_WrDWord(VL53L1_DEV dev, uint16_t index, uint32_t data);
00653     VL53L1X_ERROR VL53L1_RdByte(VL53L1_DEV dev, uint16_t index, uint8_t *data);
00654     VL53L1X_ERROR VL53L1_RdWord(VL53L1_DEV dev, uint16_t index, uint16_t *data);
00655     VL53L1X_ERROR VL53L1_RdDWord(VL53L1_DEV dev, uint16_t index, uint32_t *data);
00656     VL53L1X_ERROR VL53L1_UpdateByte(VL53L1_DEV dev, uint16_t index, uint8_t AndData, uint8_t OrData);
00657 
00658     VL53L1X_ERROR VL53L1_WriteMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count);
00659     VL53L1X_ERROR VL53L1_ReadMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count);
00660 
00661     VL53L1X_ERROR VL53L1_I2CWrite(uint8_t dev, uint16_t index, uint8_t *data, uint16_t number_of_bytes);
00662     VL53L1X_ERROR VL53L1_I2CRead(uint8_t dev, uint16_t index, uint8_t *data, uint16_t number_of_bytes);
00663     VL53L1X_ERROR VL53L1_GetTickCount(uint32_t *ptick_count_ms);
00664     VL53L1X_ERROR VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us);
00665     VL53L1X_ERROR VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms);
00666     
00667     VL53L1X_ERROR VL53L1_WaitValueMaskEx(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uint16_t index, uint8_t value, uint8_t mask, uint32_t poll_delay_ms);
00668 
00669  protected:
00670 
00671     /* IO Device */
00672     vl53L1X_DevI2C *dev_i2c;
00673     
00674     /* Digital out pin */
00675     DigitalOut *_gpio0;
00676     /* GPIO expander */
00677     Stmpe1600DigiOut *_expgpio0;
00678     /* Measure detection IRQ */
00679     InterruptIn *_gpio1Int;
00680  
00681     /* Device data */
00682     VL53L1_Dev_t MyDevice;
00683     VL53L1_DEV Device;
00684 };
00685 /*
00686 #if (MBED_VERSION  > 60300)
00687 extern "C" void wait_ms(int ms)
00688 {
00689     thread_sleep_for(ms);
00690 }
00691 #endif
00692 */
00693 
00694 #endif /* _VL53L1X_CLASS_H_ */