ST / VL53L1X_mbed

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   X_NUCLEO_53L1A1_mbed X_NUCLEO_53L1A1_mbed VL53L1X_Ranging_With_Standalone_Satellite_MbedOS X_NUCLEO_53L1A1

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  * @attention
00009  *
00010  * <h2><center>&copy; COPYRIGHT(c) 2019 STMicroelectronics</center></h2>
00011  *
00012  * Redistribution and use in source and binary forms, with or without modification,
00013  * are permitted provided that the following conditions are met:
00014  *   1. Redistributions of source code must retain the above copyright notice,
00015  *      this list of conditions and the following disclaimer.
00016  *   2. Redistributions in binary form must reproduce the above copyright notice,
00017  *      this list of conditions and the following disclaimer in the documentation
00018  *      and/or other materials provided with the distribution.
00019  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00020  *      may be used to endorse or promote products derived from this software
00021  *       without specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00026  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00027  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00028  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00029  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00031  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  *****************************************************************************/
00035 
00036 #ifndef __VL53L1X_CLASS_H
00037 #define __VL53L1X_CLASS_H
00038 
00039 
00040 #ifdef _MSC_VER
00041 #   ifdef VL53L1X_API_EXPORTS
00042 #       define VL53L1X_API  __declspec(dllexport)
00043 #   else
00044 #       define VL53L1X_API
00045 #   endif
00046 #else
00047 #   define VL53L1X_API
00048 #endif
00049 
00050 
00051 /* Includes ------------------------------------------------------------------*/
00052 #include "mbed.h"
00053 #include "PinNames.h"
00054 #include "RangeSensor.h"
00055 #include "vl53l1x_error_codes.h"
00056 #include "VL53L1X_I2C.h"
00057 #include "Stmpe1600.h"
00058 
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 #if (MBED_VERSION  > 60300) 
00218     thread_sleep_for(10);
00219 #else
00220     wait_ms(10);  // NEEDS A DELAY BETWEEN SENSORS
00221 #endif
00222     }
00223 
00224     /**
00225      * @brief       PowerOff the sensor
00226      * @return      void
00227      */
00228     /* turns off the sensor */
00229     virtual void vl53l1_off(void)
00230     {
00231         printf("VL53L1_Off\r\n");
00232         if (_gpio0) {
00233             *_gpio0 = 0;
00234         } else {
00235             if (_expgpio0) {
00236                 *_expgpio0 = 0;
00237             }
00238         }
00239 //        wait_ms(10);
00240 #if (MBED_VERSION  > 60300) 
00241     thread_sleep_for(10);
00242 #else
00243     wait_ms(10);  // NEEDS A DELAY BETWEEN SENSORS
00244 #endif
00245     }
00246     
00247     int is_present()
00248     {
00249         int status;
00250         uint8_t id = 0;
00251 
00252         status = read_id(&id);
00253         if (status) {
00254             printf("Failed to read ID device. Device not present!\n\r");
00255         }
00256         return status;
00257     }
00258 
00259     /**
00260      * @brief       Initialize the sensor with default values
00261      * @return      0 on Success
00262      */
00263      
00264      VL53L1X_ERROR init_sensor(uint8_t address){
00265         VL53L1X_ERROR status = 0;
00266         uint8_t sensorState = 0;
00267         vl53l1_off();
00268         vl53l1_on();
00269         status = vl53l1x_set_i2c_address(address);
00270         
00271         if(!status){
00272             status = vl53l1x_sensor_init();
00273         }      
00274         
00275         while(!status && !sensorState) {
00276             status = vl53l1x_boot_state(&sensorState);
00277 //            wait_ms(2);
00278 #if (MBED_VERSION  > 60300) 
00279         thread_sleep_for(2);
00280 #else
00281         wait_ms(2);  // NEEDS A DELAY BETWEEN SENSORS
00282 #endif
00283         }
00284         
00285         return status;
00286      }
00287 
00288 
00289 
00290     /**
00291      *
00292      * @brief One time device initialization
00293      * @param void
00294      * @return     0 on success,  @a #CALIBRATION_WARNING if failed
00295      */
00296     virtual int init(void *init)
00297     {
00298        return vl53l1x_sensor_init();
00299 
00300     }
00301 
00302     /* Read function of the ID device */
00303     virtual int read_id(uint8_t *id){
00304         int status = 0;
00305         uint16_t rl_id = 0;
00306     
00307         uint8_t ExpanderData[2];
00308     
00309         ExpanderData[0] = 0;
00310         ExpanderData[1] = 0;
00311         rl_id = 0;
00312         dev_i2c->v53l1x_i2c_read(&ExpanderData[0], Device->I2cDevAddr, VL53L1X_REG_IDENTIFICATION_MODEL_ID, 2);
00313     
00314         rl_id = (ExpanderData[0] << 8) + ExpanderData[1];
00315         printf("Model ID is: %d (%X)  \r\n",rl_id, rl_id);
00316     
00317         uint8_t tmp = 0;
00318         ExpanderData[0] = VL53L1_FIRMWARE__SYSTEM_STATUS >> 8;
00319         ExpanderData[1] = VL53L1_FIRMWARE__SYSTEM_STATUS & 0x0FF;
00320         dev_i2c->v53l1x_i2c_read(&tmp, Device->I2cDevAddr, VL53L1_FIRMWARE__SYSTEM_STATUS, 1);
00321 
00322         printf("Firmware system is: %d\r\n",tmp);
00323     
00324         if (rl_id == 0xEACC) {
00325             printf("Device is present %d:\r\n", rl_id);
00326             return status;
00327         }
00328         return -1;
00329     }
00330 
00331     /**
00332      * @brief       Interrupt handling func to be called by user after an INT is occurred
00333      * @param[out]  Data pointer to the distance to read data in to
00334      * @return      0 on Success
00335      */
00336     int handle_irq(uint16_t *distance);
00337 
00338     /**
00339      * @brief       Start the measure indicated by operating mode
00340      * @param[in]   fptr specifies call back function must be !NULL in case of interrupt measure
00341      * @return      0 on Success
00342      */
00343     int start_measurement(void (*fptr)(void));
00344     /**
00345      * @brief       Stop the currently running measure indicate by operating_mode
00346      * @return      0 on Success
00347      */
00348     int stop_measurement();
00349     /**
00350      * @brief       Get results for the measure
00351      * @param[out]  Data pointer to the distance_data to read data in to
00352      * @return      0 on Success
00353      */
00354     int get_measurement(uint16_t *distance);
00355     /**
00356      * @brief       Enable interrupt measure IRQ
00357      * @return      0 on Success
00358      */
00359     void enable_interrupt_measure_detection_irq(void)
00360     {
00361         if (_gpio1Int != NULL)
00362             _gpio1Int->enable_irq();
00363     }
00364 
00365     /**
00366      * @brief       Disable interrupt measure IRQ
00367      * @return      0 on Success
00368      */
00369     void disable_interrupt_measure_detection_irq(void)
00370     {
00371         if (_gpio1Int != NULL)
00372             _gpio1Int->disable_irq();
00373     }
00374     /**
00375      * @brief       Attach a function to call when an interrupt is detected, i.e. measurement is ready
00376      * @param[in]   fptr pointer to call back function to be called whenever an interrupt occours
00377      * @return      0 on Success
00378      */
00379     void attach_interrupt_measure_detection_irq(void (*fptr)(void))
00380     {
00381         if (_gpio1Int != NULL)
00382             _gpio1Int->rise(fptr);
00383     }
00384     /**
00385      * @brief Get ranging result and only that
00386      * @param pRange_mm  Pointer to range distance
00387      * @return           0 on success
00388      */
00389     virtual int get_distance(uint32_t *piData)
00390     {
00391     int status;
00392     uint16_t distance;
00393     status = vl53l1x_get_distance(&distance);
00394     *piData = (uint32_t) distance;
00395     return status;
00396     }
00397 
00398 
00399     /* VL53L1X_api.h functions */
00400 
00401     /**
00402      * @brief This function returns the SW driver version
00403      */
00404     VL53L1X_ERROR vl53l1x_get_sw_version(VL53L1X_Version_t *pVersion);
00405 
00406     /**
00407      * @brief This function sets the sensor I2C address used in case multiple devices application, default address 0x52
00408      */
00409     VL53L1X_ERROR vl53l1x_set_i2c_address(uint8_t new_address);
00410 
00411     /**
00412      * @brief This function loads the 135 bytes default values to initialize the sensor.
00413      * @param dev Device address
00414      * @return 0:success, != 0:failed
00415      */
00416     VL53L1X_ERROR vl53l1x_sensor_init();
00417 
00418     /**
00419      * @brief This function clears the interrupt, to be called after a ranging data reading
00420      * to arm the interrupt for the next data ready event.
00421      */
00422     VL53L1X_ERROR vl53l1x_clear_interrupt();
00423 
00424     /**
00425      * @brief This function programs the interrupt polarity\n
00426      * 1=active high (default), 0=active low
00427      */
00428     VL53L1X_ERROR vl53l1x_set_interrupt_polarity(uint8_t IntPol);
00429 
00430     /**
00431      * @brief This function returns the current interrupt polarity\n
00432      * 1=active high (default), 0=active low
00433      */
00434     VL53L1X_ERROR vl53l1x_get_interrupt_polarity(uint8_t *pIntPol);
00435 
00436     /**
00437      * @brief This function starts the ranging distance operation\n
00438      * 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
00439      * 1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required.
00440      */
00441     VL53L1X_ERROR vl53l1x_start_ranging();
00442 
00443     /**
00444      * @brief This function stops the ranging.
00445      */
00446     VL53L1X_ERROR vl53l1x_stop_ranging();
00447 
00448     /**
00449      * @brief This function checks if the new ranging data is available by polling the dedicated register.
00450      * @param : isDataReady==0 -> not ready; isDataReady==1 -> ready
00451      */
00452     VL53L1X_ERROR vl53l1x_check_for_data_ready(uint8_t *isDataReady);
00453     
00454     /**
00455      * @brief This function programs the timing budget in ms.
00456      * Predefined values = 15, 20, 33, 50, 100(default), 200, 500.
00457      */
00458     VL53L1X_ERROR vl53l1x_set_timing_budget_in_ms(uint16_t TimingBudgetInMs);
00459 
00460     /**
00461      * @brief This function returns the current timing budget in ms.
00462      */
00463     VL53L1X_ERROR vl53l1x_get_timing_budget_in_ms(uint16_t *pTimingBudgetInMs);
00464 
00465     /**
00466      * @brief This function programs the distance mode (1=short, 2=long(default)).
00467      * Short mode max distance is limited to 1.3 m but better ambient immunity.\n
00468      * Long mode can range up to 4 m in the dark with 200 ms timing budget.
00469      */
00470     VL53L1X_ERROR vl53l1x_set_distance_mode(uint16_t DistanceMode);
00471 
00472     /**
00473      * @brief This function returns the current distance mode (1=short, 2=long).
00474      */
00475     VL53L1X_ERROR vl53l1x_get_distance_mode(uint16_t *pDistanceMode);
00476 
00477     /**
00478      * @brief This function programs the Intermeasurement period in ms\n
00479      * Intermeasurement period must be >/= timing budget. This condition is not checked by the API,
00480      * the customer has the duty to check the condition. Default = 100 ms
00481      */
00482     VL53L1X_ERROR vl53l1x_set_inter_measurement_in_ms(uint16_t InterMeasurementInMs);
00483 
00484     /**
00485      * @brief This function returns the Intermeasurement period in ms.
00486      */
00487     VL53L1X_ERROR vl53l1x_get_inter_measurement_in_ms(uint16_t * pIM);
00488 
00489     /**
00490      * @brief This function returns the boot state of the device (1:booted, 0:not booted)
00491      */
00492     VL53L1X_ERROR vl53l1x_boot_state(uint8_t *state);
00493 
00494     /**
00495      * @brief This function returns the sensor id, sensor Id must be 0xEEAC
00496      */
00497     VL53L1X_ERROR vl53l1x_get_sensor_id(uint16_t *id);
00498 
00499     /**
00500      * @brief This function returns the distance measured by the sensor in mm
00501      */
00502     VL53L1X_ERROR vl53l1x_get_distance(uint16_t *distance);
00503 
00504     /**
00505      * @brief This function returns the returned signal per SPAD in kcps/SPAD.
00506      * With kcps stands for Kilo Count Per Second
00507      */
00508     VL53L1X_ERROR vl53l1x_get_signal_per_spad(uint16_t *signalPerSp);
00509 
00510     /**
00511      * @brief This function returns the ambient per SPAD in kcps/SPAD
00512      */
00513     VL53L1X_ERROR vl53l1x_get_ambient_per_spad(uint16_t *amb);
00514 
00515     /**
00516      * @brief This function returns the returned signal in kcps.
00517      */
00518     VL53L1X_ERROR vl53l1x_get_signal_rate(uint16_t *signalRate);
00519 
00520     /**
00521      * @brief This function returns the current number of enabled SPADs
00522      */
00523     VL53L1X_ERROR vl53l1x_get_spad_nb(uint16_t *spNb);
00524 
00525     /**
00526      * @brief This function returns the ambient rate in kcps
00527      */
00528     VL53L1X_ERROR vl53l1x_get_ambient_rate(uint16_t *ambRate);
00529 
00530     /**
00531      * @brief This function returns the ranging status error \n
00532      * (0:no error, 1:sigma failed, 2:signal failed, ..., 7:wrap-around)
00533      */
00534     VL53L1X_ERROR vl53l1x_get_range_status(uint8_t *rangeStatus);
00535 
00536     /**
00537      * @brief This function programs the offset correction in mm
00538      * @param OffsetValue:the offset correction value to program in mm
00539      */
00540     VL53L1X_ERROR vl53l1x_set_offset(int16_t OffsetValue);
00541 
00542     /**
00543      * @brief This function returns the programmed offset correction value in mm
00544      */
00545     VL53L1X_ERROR vl53l1x_get_offset(int16_t *Offset);
00546 
00547     /**
00548      * @brief This function programs the xtalk correction value in cps (Count Per Second).\n
00549      * This is the number of photons reflected back from the cover glass in cps.
00550      */
00551     VL53L1X_ERROR vl53l1x_set_xtalk(uint16_t XtalkValue);
00552 
00553     /**
00554      * @brief This function returns the current programmed xtalk correction value in cps
00555      */
00556     VL53L1X_ERROR vl53l1x_get_xtalk(uint16_t *Xtalk);
00557 
00558     /**
00559      * @brief This function programs the threshold detection mode\n
00560      * Example:\n
00561      * vl53l1x_set_distance_threshold(dev,100,300,0,1): Below 100 \n
00562      * vl53l1x_set_distance_threshold(dev,100,300,1,1): Above 300 \n
00563      * vl53l1x_set_distance_threshold(dev,100,300,2,1): Out of window \n
00564      * vl53l1x_set_distance_threshold(dev,100,300,3,1): In window \n
00565      * @param   dev : device address
00566      * @param   ThreshLow(in mm) : the threshold under which one the device raises an interrupt if Window = 0
00567      * @param   ThreshHigh(in mm) :  the threshold above which one the device raises an interrupt if Window = 1
00568      * @param   Window detection mode : 0=below, 1=above, 2=out, 3=in
00569      * @param   IntOnNoTarget = 1 (No longer used - just use 1)
00570      */
00571     VL53L1X_ERROR vl53l1x_set_distance_threshold(uint16_t ThreshLow,
00572                       uint16_t ThreshHigh, uint8_t Window,
00573                       uint8_t IntOnNoTarget);
00574 
00575     /**
00576      * @brief This function returns the window detection mode (0=below; 1=above; 2=out; 3=in)
00577      */
00578     VL53L1X_ERROR vl53l1x_get_distance_threshold_window(uint16_t *window);
00579 
00580     /**
00581      * @brief This function returns the low threshold in mm
00582      */
00583     VL53L1X_ERROR vl53l1x_get_distance_threshold_low(uint16_t *low);
00584 
00585     /**
00586      * @brief This function returns the high threshold in mm
00587      */
00588     VL53L1X_ERROR vl53l1x_get_distance_threshold_high(uint16_t *high);
00589 
00590     /**
00591      * @brief This function programs the ROI (Region of Interest)\n
00592      * The ROI position is centered, only the ROI size can be reprogrammed.\n
00593      * The smallest acceptable ROI size = 4\n
00594      * @param X:ROI Width; Y=ROI Height
00595      */
00596     VL53L1X_ERROR vl53l1x_set_roi(uint16_t X, uint16_t Y);
00597 
00598     /**
00599      *@brief This function returns width X and height Y
00600      */
00601     VL53L1X_ERROR vl53l1x_get_roi_xy(uint16_t *ROI_X, uint16_t *ROI_Y);
00602 
00603     /**
00604      * @brief This function programs a new signal threshold in kcps (default=1024 kcps\n
00605      */
00606     VL53L1X_ERROR vl53l1x_set_signal_threshold(uint16_t signal);
00607 
00608     /**
00609      * @brief This function returns the current signal threshold in kcps
00610      */
00611     VL53L1X_ERROR vl53l1x_get_signal_threshold(uint16_t *signal);
00612 
00613     /**
00614      * @brief This function programs a new sigma threshold in mm (default=15 mm)
00615      */
00616     VL53L1X_ERROR vl53l1x_set_sigma_threshold(uint16_t sigma);
00617 
00618     /**
00619      * @brief This function returns the current sigma threshold in mm
00620      */
00621     VL53L1X_ERROR vl53l1x_get_sigma_threshold(uint16_t *signal);
00622 
00623     /**
00624      * @brief This function performs the temperature calibration.
00625      * It is recommended to call this function any time the temperature might have changed by more than 8 deg C
00626      * without sensor ranging activity for an extended period.
00627      */
00628     VL53L1X_ERROR vl53l1x_start_temperature_update();
00629 
00630 
00631     /* VL53L1X_calibration.h functions */
00632     
00633         /**
00634      * @brief This function performs the offset calibration.\n
00635      * The function returns the offset value found and programs the offset compensation into the device.
00636      * @param TargetDistInMm target distance in mm, ST recommended 100 mm
00637      * Target reflectance = grey17%
00638      * @return 0:success, !=0: failed
00639      * @return offset pointer contains the offset found in mm
00640      */
00641     int8_t vl53l1x_calibrate_offset(uint16_t TargetDistInMm, int16_t *offset);
00642 
00643     /**
00644      * @brief This function performs the xtalk calibration.\n
00645      * The function returns the xtalk value found and programs the xtalk compensation to the device
00646      * @param TargetDistInMm target distance in mm\n
00647      * The target distance : the distance where the sensor start to "under range"\n
00648      * due to the influence of the photons reflected back from the cover glass becoming strong\n
00649      * It's also called inflection point\n
00650      * Target reflectance = grey 17%
00651      * @return 0: success, !=0: failed
00652      * @return xtalk pointer contains the xtalk value found in cps (number of photons in count per second)
00653      */
00654     int8_t vl53l1x_calibrate_xtalk(uint16_t TargetDistInMm, uint16_t *xtalk);
00655     
00656 
00657     /* Write and read functions from I2C */
00658 
00659     VL53L1X_ERROR vl53l1_wr_byte(VL53L1_DEV dev, uint16_t index, uint8_t data);
00660     VL53L1X_ERROR vl53l1_wr_word(VL53L1_DEV dev, uint16_t index, uint16_t data);
00661     VL53L1X_ERROR vl53l1_wr_double_word(VL53L1_DEV dev, uint16_t index, uint32_t data);
00662     VL53L1X_ERROR vl53l1_rd_byte(VL53L1_DEV dev, uint16_t index, uint8_t *data);
00663     VL53L1X_ERROR vl53l1_rd_word(VL53L1_DEV dev, uint16_t index, uint16_t *data);
00664     VL53L1X_ERROR vl53l1_rd_double_word(VL53L1_DEV dev, uint16_t index, uint32_t *data);
00665     VL53L1X_ERROR vl53l1_update_byte(VL53L1_DEV dev, uint16_t index, uint8_t AndData, uint8_t OrData);
00666 
00667     VL53L1X_ERROR vl53l1_write_multi(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count);
00668     VL53L1X_ERROR vl53l1_read_multi(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count);
00669 
00670     VL53L1X_ERROR vl53l1_i2c_write(uint8_t dev, uint16_t index, uint8_t *data, uint16_t number_of_bytes);
00671     VL53L1X_ERROR vl53l1_i2c_read(uint8_t dev, uint16_t index, uint8_t *data, uint16_t number_of_bytes);
00672     VL53L1X_ERROR vl53l1_get_tick_count(uint32_t *ptick_count_ms);
00673     VL53L1X_ERROR vl53l1_wait_us(VL53L1_Dev_t *pdev, int32_t wait_us);
00674     VL53L1X_ERROR vl53l1_wait_ms(VL53L1_Dev_t *pdev, int32_t wait_ms);
00675     
00676     VL53L1X_ERROR vl53l1_wait_value_mask_ex(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uint16_t index, uint8_t value, uint8_t mask, uint32_t poll_delay_ms);
00677 
00678  protected:
00679 
00680     /* IO Device */
00681     VL53L1X_DevI2C *dev_i2c;
00682     
00683     /* Digital out pin */
00684     DigitalOut *_gpio0;
00685     /* GPIO expander */
00686     Stmpe1600DigiOut *_expgpio0;
00687     /* Measure detection IRQ */
00688     InterruptIn *_gpio1Int;
00689  
00690     /* Device data */
00691     VL53L1_Dev_t MyDevice;
00692     VL53L1_DEV Device;
00693 };
00694 
00695 
00696 #endif /* _VL53L1X_CLASS_H_ */