hello world LIDAR

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Dependents:   HelloWorld_53L0A1

Fork of X_NUCLEO_53L0A1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers vl53l0x_class.h Source File

vl53l0x_class.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 
00049 #include "vl53l0x_def.h"
00050 #include "vl53l0x_platform.h"
00051 #include "stmpe1600_class.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 
00064 #define VL53L0X_OsDelay(...) wait_ms(2) // 2 msec delay. can also use wait(float secs)/wait_us(int)
00065 
00066 #ifdef USE_EMPTY_STRING
00067     #define  VL53L0X_STRING_DEVICE_INFO_NAME                             ""
00068     #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS0                         ""
00069     #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS1                         ""
00070     #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS2                         ""
00071     #define  VL53L0X_STRING_DEVICE_INFO_NAME_ES1                         ""
00072     #define  VL53L0X_STRING_DEVICE_INFO_TYPE                             ""
00073 
00074     /* PAL ERROR strings */
00075     #define  VL53L0X_STRING_ERROR_NONE                                   ""
00076     #define  VL53L0X_STRING_ERROR_CALIBRATION_WARNING                    ""
00077     #define  VL53L0X_STRING_ERROR_MIN_CLIPPED                            ""
00078     #define  VL53L0X_STRING_ERROR_UNDEFINED                              ""
00079     #define  VL53L0X_STRING_ERROR_INVALID_PARAMS                         ""
00080     #define  VL53L0X_STRING_ERROR_NOT_SUPPORTED                          ""
00081     #define  VL53L0X_STRING_ERROR_RANGE_ERROR                            ""
00082     #define  VL53L0X_STRING_ERROR_TIME_OUT                               ""
00083     #define  VL53L0X_STRING_ERROR_MODE_NOT_SUPPORTED                     ""
00084     #define  VL53L0X_STRING_ERROR_BUFFER_TOO_SMALL                       ""
00085     #define  VL53L0X_STRING_ERROR_GPIO_NOT_EXISTING                      ""
00086     #define  VL53L0X_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED       ""
00087     #define  VL53L0X_STRING_ERROR_CONTROL_INTERFACE                      ""
00088     #define  VL53L0X_STRING_ERROR_INVALID_COMMAND                        ""
00089     #define  VL53L0X_STRING_ERROR_DIVISION_BY_ZERO                       ""
00090     #define  VL53L0X_STRING_ERROR_REF_SPAD_INIT                          ""
00091     #define  VL53L0X_STRING_ERROR_NOT_IMPLEMENTED                        ""
00092 
00093     #define  VL53L0X_STRING_UNKNOW_ERROR_CODE                            ""
00094 
00095 
00096 
00097     /* Range Status */
00098     #define  VL53L0X_STRING_RANGESTATUS_NONE                             ""
00099     #define  VL53L0X_STRING_RANGESTATUS_RANGEVALID                       ""
00100     #define  VL53L0X_STRING_RANGESTATUS_SIGMA                            ""
00101     #define  VL53L0X_STRING_RANGESTATUS_SIGNAL                           ""
00102     #define  VL53L0X_STRING_RANGESTATUS_MINRANGE                         ""
00103     #define  VL53L0X_STRING_RANGESTATUS_PHASE                            ""
00104     #define  VL53L0X_STRING_RANGESTATUS_HW                               ""
00105 
00106 
00107     /* Range Status */
00108     #define  VL53L0X_STRING_STATE_POWERDOWN                              ""
00109     #define  VL53L0X_STRING_STATE_WAIT_STATICINIT                        ""
00110     #define  VL53L0X_STRING_STATE_STANDBY                                ""
00111     #define  VL53L0X_STRING_STATE_IDLE                                   ""
00112     #define  VL53L0X_STRING_STATE_RUNNING                                ""
00113     #define  VL53L0X_STRING_STATE_UNKNOWN                                ""
00114     #define  VL53L0X_STRING_STATE_ERROR                                  ""
00115 
00116 
00117     /* Device Specific */
00118     #define  VL53L0X_STRING_DEVICEERROR_NONE                             ""
00119     #define  VL53L0X_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE       ""
00120     #define  VL53L0X_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE         ""
00121     #define  VL53L0X_STRING_DEVICEERROR_NOVHVVALUEFOUND                  ""
00122     #define  VL53L0X_STRING_DEVICEERROR_MSRCNOTARGET                     ""
00123     #define  VL53L0X_STRING_DEVICEERROR_SNRCHECK                         ""
00124     #define  VL53L0X_STRING_DEVICEERROR_RANGEPHASECHECK                  ""
00125     #define  VL53L0X_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK              ""
00126     #define  VL53L0X_STRING_DEVICEERROR_TCC                              ""
00127     #define  VL53L0X_STRING_DEVICEERROR_PHASECONSISTENCY                 ""
00128     #define  VL53L0X_STRING_DEVICEERROR_MINCLIP                          ""
00129     #define  VL53L0X_STRING_DEVICEERROR_RANGECOMPLETE                    ""
00130     #define  VL53L0X_STRING_DEVICEERROR_ALGOUNDERFLOW                    ""
00131     #define  VL53L0X_STRING_DEVICEERROR_ALGOOVERFLOW                     ""
00132     #define  VL53L0X_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD             ""
00133     #define  VL53L0X_STRING_DEVICEERROR_UNKNOWN                          ""
00134 
00135     /* Check Enable */
00136     #define  VL53L0X_STRING_CHECKENABLE_SIGMA_FINAL_RANGE                ""
00137     #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE          ""
00138     #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_REF_CLIP                  ""
00139     #define  VL53L0X_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD           ""
00140 
00141     /* Sequence Step */
00142     #define  VL53L0X_STRING_SEQUENCESTEP_TCC                             ""
00143     #define  VL53L0X_STRING_SEQUENCESTEP_DSS                             ""
00144     #define  VL53L0X_STRING_SEQUENCESTEP_MSRC                            ""
00145     #define  VL53L0X_STRING_SEQUENCESTEP_PRE_RANGE                       ""
00146     #define  VL53L0X_STRING_SEQUENCESTEP_FINAL_RANGE                     ""
00147 #else
00148     #define  VL53L0X_STRING_DEVICE_INFO_NAME          "VL53L0X cut1.0"
00149     #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS0      "VL53L0X TS0"
00150     #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS1      "VL53L0X TS1"
00151     #define  VL53L0X_STRING_DEVICE_INFO_NAME_TS2      "VL53L0X TS2"
00152     #define  VL53L0X_STRING_DEVICE_INFO_NAME_ES1      "VL53L0X ES1 or later"
00153     #define  VL53L0X_STRING_DEVICE_INFO_TYPE          "VL53L0X"
00154 
00155     /* PAL ERROR strings */
00156     #define  VL53L0X_STRING_ERROR_NONE \
00157             "No Error"
00158     #define  VL53L0X_STRING_ERROR_CALIBRATION_WARNING \
00159             "Calibration Warning Error"
00160     #define  VL53L0X_STRING_ERROR_MIN_CLIPPED \
00161             "Min clipped error"
00162     #define  VL53L0X_STRING_ERROR_UNDEFINED \
00163             "Undefined error"
00164     #define  VL53L0X_STRING_ERROR_INVALID_PARAMS \
00165             "Invalid parameters error"
00166     #define  VL53L0X_STRING_ERROR_NOT_SUPPORTED \
00167             "Not supported error"
00168     #define  VL53L0X_STRING_ERROR_RANGE_ERROR \
00169             "Range error"
00170     #define  VL53L0X_STRING_ERROR_TIME_OUT \
00171             "Time out error"
00172     #define  VL53L0X_STRING_ERROR_MODE_NOT_SUPPORTED \
00173             "Mode not supported error"
00174     #define  VL53L0X_STRING_ERROR_BUFFER_TOO_SMALL \
00175             "Buffer too small"
00176     #define  VL53L0X_STRING_ERROR_GPIO_NOT_EXISTING \
00177             "GPIO not existing"
00178     #define  VL53L0X_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED \
00179             "GPIO funct not supported"
00180     #define  VL53L0X_STRING_ERROR_INTERRUPT_NOT_CLEARED \
00181             "Interrupt not Cleared"
00182     #define  VL53L0X_STRING_ERROR_CONTROL_INTERFACE \
00183             "Control Interface Error"
00184     #define  VL53L0X_STRING_ERROR_INVALID_COMMAND \
00185             "Invalid Command Error"
00186     #define  VL53L0X_STRING_ERROR_DIVISION_BY_ZERO \
00187             "Division by zero Error"
00188     #define  VL53L0X_STRING_ERROR_REF_SPAD_INIT \
00189             "Reference Spad Init Error"
00190     #define  VL53L0X_STRING_ERROR_NOT_IMPLEMENTED \
00191             "Not implemented error"
00192 
00193     #define  VL53L0X_STRING_UNKNOW_ERROR_CODE \
00194             "Unknown Error Code"
00195 
00196 
00197 
00198     /* Range Status */
00199     #define  VL53L0X_STRING_RANGESTATUS_NONE                 "No Update"
00200     #define  VL53L0X_STRING_RANGESTATUS_RANGEVALID           "Range Valid"
00201     #define  VL53L0X_STRING_RANGESTATUS_SIGMA                "Sigma Fail"
00202     #define  VL53L0X_STRING_RANGESTATUS_SIGNAL               "Signal Fail"
00203     #define  VL53L0X_STRING_RANGESTATUS_MINRANGE             "Min Range Fail"
00204     #define  VL53L0X_STRING_RANGESTATUS_PHASE                "Phase Fail"
00205     #define  VL53L0X_STRING_RANGESTATUS_HW                   "Hardware Fail"
00206 
00207 
00208     /* Range Status */
00209     #define  VL53L0X_STRING_STATE_POWERDOWN               "POWERDOWN State"
00210     #define  VL53L0X_STRING_STATE_WAIT_STATICINIT \
00211             "Wait for staticinit State"
00212     #define  VL53L0X_STRING_STATE_STANDBY                 "STANDBY State"
00213     #define  VL53L0X_STRING_STATE_IDLE                    "IDLE State"
00214     #define  VL53L0X_STRING_STATE_RUNNING                 "RUNNING State"
00215     #define  VL53L0X_STRING_STATE_UNKNOWN                 "UNKNOWN State"
00216     #define  VL53L0X_STRING_STATE_ERROR                   "ERROR State"
00217 
00218 
00219     /* Device Specific */
00220     #define  VL53L0X_STRING_DEVICEERROR_NONE                   "No Update"
00221     #define  VL53L0X_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE \
00222             "VCSEL Continuity Test Failure"
00223     #define  VL53L0X_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE \
00224             "VCSEL Watchdog Test Failure"
00225     #define  VL53L0X_STRING_DEVICEERROR_NOVHVVALUEFOUND \
00226             "No VHV Value found"
00227     #define  VL53L0X_STRING_DEVICEERROR_MSRCNOTARGET \
00228             "MSRC No Target Error"
00229     #define  VL53L0X_STRING_DEVICEERROR_SNRCHECK \
00230             "SNR Check Exit"
00231     #define  VL53L0X_STRING_DEVICEERROR_RANGEPHASECHECK \
00232             "Range Phase Check Error"
00233     #define  VL53L0X_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK \
00234             "Sigma Threshold Check Error"
00235     #define  VL53L0X_STRING_DEVICEERROR_TCC \
00236             "TCC Error"
00237     #define  VL53L0X_STRING_DEVICEERROR_PHASECONSISTENCY \
00238             "Phase Consistency Error"
00239     #define  VL53L0X_STRING_DEVICEERROR_MINCLIP \
00240             "Min Clip Error"
00241     #define  VL53L0X_STRING_DEVICEERROR_RANGECOMPLETE \
00242             "Range Complete"
00243     #define  VL53L0X_STRING_DEVICEERROR_ALGOUNDERFLOW \
00244             "Range Algo Underflow Error"
00245     #define  VL53L0X_STRING_DEVICEERROR_ALGOOVERFLOW \
00246             "Range Algo Overlow Error"
00247     #define  VL53L0X_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD \
00248             "Range Ignore Threshold Error"
00249     #define  VL53L0X_STRING_DEVICEERROR_UNKNOWN \
00250             "Unknown error code"
00251 
00252     /* Check Enable */
00253     #define  VL53L0X_STRING_CHECKENABLE_SIGMA_FINAL_RANGE \
00254             "SIGMA FINAL RANGE"
00255     #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE \
00256             "SIGNAL RATE FINAL RANGE"
00257     #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_REF_CLIP \
00258             "SIGNAL REF CLIP"
00259     #define  VL53L0X_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD \
00260             "RANGE IGNORE THRESHOLD"
00261     #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_MSRC \
00262             "SIGNAL RATE MSRC"
00263     #define  VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_PRE_RANGE \
00264             "SIGNAL RATE PRE RANGE"
00265 
00266     /* Sequence Step */
00267     #define  VL53L0X_STRING_SEQUENCESTEP_TCC                   "TCC"
00268     #define  VL53L0X_STRING_SEQUENCESTEP_DSS                   "DSS"
00269     #define  VL53L0X_STRING_SEQUENCESTEP_MSRC                  "MSRC"
00270     #define  VL53L0X_STRING_SEQUENCESTEP_PRE_RANGE             "PRE RANGE"
00271     #define  VL53L0X_STRING_SEQUENCESTEP_FINAL_RANGE           "FINAL RANGE"
00272 #endif /* USE_EMPTY_STRING */
00273 
00274 
00275 
00276 
00277 
00278 /* sensor operating modes */ 
00279 typedef enum
00280 {
00281    range_single_shot_polling=1,
00282    range_continuous_polling,
00283    range_continuous_interrupt,
00284    range_continuous_polling_low_threshold,
00285    range_continuous_polling_high_threshold,
00286    range_continuous_polling_out_of_window,
00287    range_continuous_interrupt_low_threshold,
00288    range_continuous_interrupt_high_threshold,
00289    range_continuous_interrupt_out_of_window,
00290 }OperatingMode;
00291 
00292 /** default device address */
00293 #define DEFAULT_DEVICE_ADDRESS      0x52 /* (8-bit) */
00294 
00295 /* Classes -------------------------------------------------------------------*/
00296 /** Class representing a VL53L0 sensor component
00297  */
00298 class VL53L0X : public RangeSensor
00299 {
00300  public:
00301     /** Constructor
00302      * @param[in] &i2c device I2C to be used for communication
00303      * @param[in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
00304      * @param[in] DevAddr device address, 0x29 by default  
00305      */
00306     VL53L0X(DevI2C &i2c, DigitalOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), dev_i2c(i2c), gpio0(&pin)
00307     {
00308        MyDevice.I2cDevAddr =DevAddr;      
00309        MyDevice.comms_type =1; // VL53L0X_COMMS_I2C
00310              MyDevice.comms_speed_khz =400;
00311        Device=&MyDevice;
00312        expgpio0=NULL;
00313        if (pin_gpio1 != NC) { gpio1Int = new InterruptIn(pin_gpio1); }
00314         else { gpio1Int = NULL; }
00315     }  
00316     
00317     /** Constructor 2 (STMPE1600DigiOut)
00318      * @param[in] i2c device I2C to be used for communication
00319      * @param[in] &pin Gpio Expander STMPE1600DigiOut pin to be used as component GPIO_0 CE
00320      * @param[in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
00321      * @param[in] device address, 0x29 by default  
00322      */     
00323     VL53L0X(DevI2C &i2c, STMPE1600DigiOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), dev_i2c(i2c), expgpio0(&pin)
00324     {
00325        MyDevice.I2cDevAddr =DevAddr;      
00326        MyDevice.comms_type =1; // VL53L0X_COMMS_I2C
00327              MyDevice.comms_speed_khz =400;
00328        Device=&MyDevice;
00329        gpio0=NULL;      
00330        if (pin_gpio1 != NC) { gpio1Int = new InterruptIn(pin_gpio1); }
00331         else { gpio1Int = NULL; }
00332     }    
00333     
00334    /** Destructor
00335     */
00336     virtual ~VL53L0X(){ 
00337         if (gpio1Int != NULL) delete gpio1Int;
00338     }     
00339     /* warning: VL53L0X class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor.
00340        The warning should request to introduce a virtual destructor to make sure to delete the object */
00341 
00342     /*** Interface Methods ***/ 
00343     /*** High level API ***/        
00344     /**
00345      * @brief       PowerOn the sensor
00346      * @return      void
00347      */     
00348     /* turns on the sensor */        
00349     void VL53L0X_On(void)
00350     {
00351         if (gpio0) 
00352               *gpio0 = 1;
00353         else if (expgpio0) 
00354             *expgpio0 = 1;
00355     } 
00356 
00357     /**
00358      * @brief       PowerOff the sensor
00359      * @return      void
00360      */     
00361     /* turns off the sensor */
00362     void VL53L0X_Off(void) 
00363     {
00364         if (gpio0) 
00365               *gpio0 = 0;
00366         else if (expgpio0) 
00367             *expgpio0 = 0;
00368     }
00369     
00370     /**
00371      * @brief       Initialize the sensor with default values
00372      * @return      0 on Success
00373      */
00374     int InitSensor(uint8_t NewAddr);
00375 
00376     /**
00377      * @brief       Start the measure indicated by operating mode
00378      * @param[in]   operating_mode specifies requested measure 
00379      * @param[in]   fptr specifies call back function must be !NULL in case of interrupt measure     
00380      * @return      0 on Success
00381      */                      
00382     int StartMeasurement(OperatingMode operating_mode, void (*fptr)(void));
00383 
00384     /**
00385      * @brief       Get results for the measure indicated by operating mode
00386      * @param[in]   operating_mode specifies requested measure results
00387      * @param[out]  Data pointer to the MeasureData_t structure to read data in to
00388      * @return      0 on Success
00389      */                          
00390     int GetMeasurement(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *Data);       
00391 
00392     /**
00393      * @brief       Stop the currently running measure indicate by operating_mode
00394      * @param[in]   operating_mode specifies requested measure to stop
00395      * @return      0 on Success
00396      */                              
00397     int StopMeasurement(OperatingMode operating_mode);
00398      
00399     /**
00400      * @brief       Interrupt handling func to be called by user after an INT is occourred
00401      * @param[in]   opeating_mode indicating the in progress measure
00402      * @param[out]  Data pointer to the MeasureData_t structure to read data in to
00403      * @return      0 on Success
00404      */                                 
00405     int HandleIRQ(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *Data);    
00406 
00407     /**
00408      * @brief       Enable interrupt measure IRQ
00409      * @return      0 on Success
00410      */                      
00411     void EnableInterruptMeasureDetectionIRQ(void) 
00412     {
00413        if (gpio1Int != NULL) gpio1Int->enable_irq();
00414     }
00415 
00416     /**
00417      * @brief       Disable interrupt measure IRQ
00418      * @return      0 on Success
00419      */                           
00420     void DisableInterruptMeasureDetectionIRQ(void) 
00421     {
00422        if (gpio1Int != NULL) gpio1Int->disable_irq();
00423     }
00424     /*** End High level API ***/              
00425     
00426     /**
00427      * @brief       Attach a function to call when an interrupt is detected, i.e. measurement is ready
00428      * @param[in]   fptr pointer to call back function to be called whenever an interrupt occours
00429      * @return      0 on Success
00430      */                                   
00431     void AttachInterruptMeasureDetectionIRQ(void (*fptr)(void))
00432     {
00433        if (gpio1Int != NULL) gpio1Int->rise(fptr);
00434     }
00435     
00436     /**
00437      * @brief       Check the sensor presence
00438      * @return      1 when device is present
00439      */                     
00440     unsigned Present()
00441     {
00442 //       return Device->Present;
00443        return 1;
00444     }
00445         
00446     /** Wrapper functions */    
00447 /** @defgroup api_init Init functions
00448  *  @brief    API init functions
00449  *  @ingroup api_hl
00450  *  @{  
00451  */
00452 /**
00453  * @brief Wait for device booted after chip enable (hardware standby)
00454  * @par Function Description
00455  * After Chip enable Application you can also simply wait at least 1ms to ensure device is ready
00456  * @warning After device chip enable (gpio0) de-asserted  user must wait gpio1 to get asserted (hardware standby).
00457  * or wait at least 400usec prior to do any low level access or api call .
00458  *
00459  * This function implements polling for standby but you must ensure 400usec from chip enable passed\n
00460  * @warning if device get prepared @a VL53L0X_Prepare() re-using these function can hold indefinitely\n
00461  *
00462  * @param       void
00463  * @return     0 on success
00464  */
00465     int WaitDeviceBooted()
00466     {
00467        return VL53L0X_WaitDeviceBooted(Device);
00468 //          return 1;
00469     }
00470 
00471 /**
00472  *
00473  * @brief One time device initialization
00474  *
00475  * To be called once and only once after device is brought out of reset (Chip enable) and booted see @a VL6180x_WaitDeviceBooted()
00476  *
00477  * @par Function Description
00478  * When not used after a fresh device "power up" or reset, it may return @a #CALIBRATION_WARNING
00479  * meaning wrong calibration data may have been fetched from device that can result in ranging offset error\n
00480  * If application cannot execute device reset or need to run VL6180x_InitData  multiple time
00481  * then it  must ensure proper offset calibration saving and restore on its own
00482  * by using @a VL6180x_GetOffsetCalibrationData() on first power up and then @a VL6180x_SetOffsetCalibrationData() all all subsequent init
00483  *
00484  * @param void
00485  * @return     0 on success,  @a #CALIBRATION_WARNING if failed
00486  */     
00487     virtual int Init(void * NewAddr)
00488     {
00489        return VL53L0X_DataInit(Device);
00490     }
00491 
00492 /**
00493  * @brief Configure GPIO1 function and set polarity.
00494  * @par Function Description
00495  * To be used prior to arm single shot measure or start  continuous mode.
00496  *
00497  * The function uses @a VL6180x_SetupGPIOx() for setting gpio 1.
00498  * @warning  changing polarity can generate a spurious interrupt on pins.
00499  * It sets an interrupt flags condition that must be cleared to avoid polling hangs. \n
00500  * It is safe to run VL6180x_ClearAllInterrupt() just after.
00501  *
00502  * @param IntFunction   The interrupt functionality to use one of :\n
00503  *  @a #GPIOx_SELECT_OFF \n
00504  *  @a #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT
00505  * @param ActiveHigh  The interrupt line polarity see ::IntrPol_e
00506  *      use @a #INTR_POL_LOW (falling edge) or @a #INTR_POL_HIGH (rising edge)
00507  * @return 0 on success
00508  */     
00509     int SetupGPIO1(uint8_t InitFunction, int ActiveHigh)
00510     {
00511 //       return VL6180x_SetupGPIO1(Device, InitFunction, ActiveHigh);
00512             return 1;
00513     }
00514 
00515 /**
00516   * @brief  Prepare device for operation
00517   * @par Function Description
00518   * Does static initialization and reprogram common default settings \n
00519   * Device is prepared for new measure, ready single shot ranging or ALS typical polling operation\n
00520   * After prepare user can : \n
00521   * @li Call other API function to set other settings\n
00522   * @li Configure the interrupt pins, etc... \n
00523   * @li Then start ranging or ALS operations in single shot or continuous mode
00524   *
00525   * @param void
00526   * @return      0 on success
00527   */        
00528     int Prepare()
00529     {
00530             // taken from rangingTest() in vl53l0x_SingleRanging_Example.c
00531         VL53L0X_Error Status = VL53L0X_ERROR_NONE;
00532         uint32_t refSpadCount;
00533         uint8_t isApertureSpads;
00534         uint8_t VhvSettings;
00535         uint8_t PhaseCal;
00536 
00537         if(Status == VL53L0X_ERROR_NONE)
00538         {
00539             printf ("Call of VL53L0X_StaticInit\n");
00540             Status = VL53L0X_StaticInit(Device); // Device Initialization
00541         }
00542     
00543         if(Status == VL53L0X_ERROR_NONE)
00544         {
00545             printf ("Call of VL53L0X_PerformRefCalibration\n");
00546            Status = VL53L0X_PerformRefCalibration(Device,
00547                                 &VhvSettings, &PhaseCal); // Device Initialization
00548         }
00549 
00550         if(Status == VL53L0X_ERROR_NONE)
00551         {
00552             printf ("Call of VL53L0X_PerformRefSpadManagement\n");
00553             Status = VL53L0X_PerformRefSpadManagement(Device,
00554                              &refSpadCount, &isApertureSpads); // Device Initialization
00555 //            printf ("refSpadCount = %d, isApertureSpads = %d\n", refSpadCount, isApertureSpads);
00556         }
00557             
00558         return Status;
00559     }
00560 
00561  /**
00562  * @brief Start continuous ranging mode
00563  *
00564  * @details End user should ensure device is in idle state and not already running
00565  * @return      0 on success
00566  */     
00567     int RangeStartContinuousMode()
00568     {
00569 //       return VL6180x_RangeStartContinuousMode(Device);
00570             return 1;
00571     }
00572 
00573 /**
00574  * @brief Start single shot ranging measure
00575  *
00576  * @details End user should ensure device is in idle state and not already running
00577  * @return      0 on success 
00578  */     
00579     int RangeStartSingleShot()
00580     {
00581 //       return VL6180x_RangeStartSingleShot(Device);
00582             return 1;
00583     }
00584 
00585 /**
00586  * @brief Set maximum convergence time
00587  *
00588  * @par Function Description
00589  * Setting a low convergence time can impact maximal detectable distance.
00590  * Refer to VL6180x Datasheet Table 7 : Typical range convergence time.
00591  * A typical value for up to x3 scaling is 50 ms
00592  *
00593  * @param MaxConTime_msec
00594  * @return 0 on success. <0 on error. >0 for calibration warning status
00595  */     
00596     int RangeSetMaxConvergenceTime(uint8_t MaxConTime_msec)
00597     {
00598 //       return VL6180x_RangeSetMaxConvergenceTime(Device, MaxConTime_msec);
00599             return 1;
00600     }
00601 
00602 /**
00603   * @brief Single shot Range measurement in polling mode.
00604   *
00605   * @par Function Description
00606   * Kick off a new single shot range  then wait for ready to retrieve it by polling interrupt status \n
00607   * Ranging must be prepared by a first call to  @a VL6180x_Prepare() and it is safer to clear  very first poll call \n
00608   * This function reference VL6180x_PollDelay(dev) porting macro/call on each polling loop,
00609   * but PollDelay(dev) may never be called if measure in ready on first poll loop \n
00610   * Should not be use in continuous mode operation as it will stop it and cause stop/start misbehaviour \n
00611   * \n This function clears Range Interrupt status , but not error one. For that uses  @a VL6180x_ClearErrorInterrupt() \n
00612   * This range error is not related VL6180x_RangeData_t::errorStatus that refer measure status \n
00613   * 
00614   * @param pRangeData   Will be populated with the result ranging data @a  VL6180x_RangeData_t
00615   * @return 0 on success , @a #RANGE_ERROR if device reports an error case in it status (not cleared) use
00616   *
00617   * \sa ::VL6180x_RangeData_t
00618   */        
00619     int RangePollMeasurement(VL53L0X_RangingMeasurementData_t *pRangeData)
00620     {
00621 //       return VL6180x_RangePollMeasurement(Device, pRangeData);
00622             return 1;
00623     }
00624 
00625 /**
00626  * @brief Check for measure readiness and get it if ready
00627  *
00628  * @par Function Description
00629  * Using this function is an alternative to @a VL6180x_RangePollMeasurement() to avoid polling operation. This is suitable for applications
00630  * where host CPU is triggered on a interrupt (not from VL6180X) to perform ranging operation. In this scenario, we assume that the very first ranging
00631  * operation is triggered by a call to @a VL6180x_RangeStartSingleShot(). Then, host CPU regularly calls @a VL6180x_RangeGetMeasurementIfReady() to
00632  * get a distance measure if ready. In case the distance is not ready, host may get it at the next call.\n
00633  *
00634  * @warning 
00635  * This function does not re-start a new measurement : this is up to the host CPU to do it.\n 
00636  * This function clears Range Interrupt for measure ready , but not error interrupts. For that, uses  @a VL6180x_ClearErrorInterrupt() \n
00637  *
00638  * @param pRangeData  Will be populated with the result ranging data if available
00639  * @return  0 when measure is ready pRange data is updated (untouched when not ready),  >0 for warning and @a #NOT_READY if measurement not yet ready, <0 for error @a #RANGE_ERROR if device report an error,
00640  */     
00641     int RangeGetMeasurementIfReady(VL53L0X_RangingMeasurementData_t *pRangeData)
00642     {
00643 //       return VL6180x_RangeGetMeasurementIfReady(Device, pRangeData);
00644             return 1;
00645     }
00646 
00647 /**
00648  * @brief Retrieve range measurements set  from device
00649  *
00650  * @par Function Description
00651  * The measurement is made of range_mm status and error code @a VL6180x_RangeData_t \n
00652  * Based on configuration selected extra measures are included.
00653  *
00654  * @warning should not be used in continuous if wrap around filter is active \n
00655  * Does not perform any wait nor check for result availability or validity.
00656  *\sa VL6180x_RangeGetResult for "range only" measurement
00657  *
00658  * @param pRangeData  Pointer to the data structure to fill up
00659  * @return            0 on success
00660  */     
00661     int RangeGetMeasurement(VL53L0X_RangingMeasurementData_t *pRangeData)
00662     {
00663 //       return VL6180x_RangeGetMeasurement(Device, pRangeData);
00664             return 1;
00665     }
00666 
00667 /**
00668  * @brief Get ranging result and only that
00669  *
00670  * @par Function Description
00671  * Unlike @a VL6180x_RangeGetMeasurement() this function only retrieves the range in millimeter \n
00672  * It does any required up-scale translation\n
00673  * It can be called after success status polling or in interrupt mode \n
00674  * @warning these function is not doing wrap around filtering \n
00675  * This function doesn't perform any data ready check!
00676  *
00677  * @param pRange_mm  Pointer to range distance
00678  * @return           0 on success
00679  */     
00680     virtual int GetDistance(uint32_t *piData)
00681     {
00682         int status=0;
00683         VL53L0X_RangingMeasurementData_t pRangingMeasurementData;
00684 
00685         status=StartMeasurement(range_single_shot_polling, NULL);
00686         if (!status) {
00687             status=GetMeasurement(range_single_shot_polling, &pRangingMeasurementData);
00688         }
00689         if (pRangingMeasurementData.RangeStatus == 0) {
00690         // we have a valid range.
00691             *piData = pRangingMeasurementData.RangeMilliMeter;
00692         }
00693         else {
00694             *piData = 0;
00695             status = VL53L0X_ERROR_RANGE_ERROR;
00696         }
00697         StopMeasurement(range_single_shot_polling);
00698         return status;
00699     }
00700         
00701 /**
00702  * @brief Configure ranging interrupt reported to application
00703  *
00704  * @param ConfigGpioInt  Select ranging report\n select one (and only one) of:\n
00705  *   @a #CONFIG_GPIO_INTERRUPT_DISABLED \n
00706  *   @a #CONFIG_GPIO_INTERRUPT_LEVEL_LOW \n
00707  *   @a #CONFIG_GPIO_INTERRUPT_LEVEL_HIGH \n
00708  *   @a #CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW \n
00709  *   @a #CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY
00710  * @return   0 on success
00711  */
00712     int RangeConfigInterrupt(uint8_t ConfigGpioInt)
00713     {
00714 //       return VL6180x_RangeConfigInterrupt(Device, ConfigGpioInt);
00715             return 1;
00716     }
00717 
00718 /**
00719  * @brief Return ranging error interrupt status
00720  *
00721  * @par Function Description
00722  * Appropriate Interrupt report must have been selected first by @a VL6180x_RangeConfigInterrupt() or @a  VL6180x_Prepare() \n
00723  *
00724  * Can be used in polling loop to wait for a given ranging event or in interrupt to read the trigger \n
00725  * Events triggers are : \n
00726  * @a #RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD \n
00727  * @a #RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD \n
00728  * @a #RES_INT_STAT_GPIO_OUT_OF_WINDOW \n (RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD|RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD)
00729  * @a #RES_INT_STAT_GPIO_NEW_SAMPLE_READY \n
00730  *
00731  * @sa IntrStatus_t
00732  * @param pIntStatus Pointer to status variable to update
00733  * @return           0 on success
00734  */     
00735     int RangeGetInterruptStatus(uint8_t *pIntStatus)
00736     {
00737 //       return VL6180x_RangeGetInterruptStatus(Device, pIntStatus);
00738             return 1;
00739     }
00740 
00741 /**
00742  * @brief Low level ranging and ALS register static settings (you should call @a VL6180x_Prepare() function instead)
00743  *
00744  * @return 0 on success
00745  */
00746     int StaticInit()
00747     {
00748 //       return VL6180x_StaticInit(Device);
00749             return 1;
00750     }
00751 
00752 /**
00753  * @brief Wait for device to be ready (before a new ranging command can be issued by application)
00754  * @param MaxLoop    Max Number of i2c polling loop see @a #msec_2_i2cloop
00755  * @return           0 on success. <0 when fail \n
00756  *                   @ref VL6180x_ErrCode_t::TIME_OUT for time out \n
00757  *                   @ref VL6180x_ErrCode_t::INVALID_PARAMS if MaxLop<1
00758  */     
00759     int RangeWaitDeviceReady(int MaxLoop )
00760     {
00761 //       return VL6180x_RangeWaitDeviceReady(Device, MaxLoop);
00762             return 1;
00763     }
00764 
00765 /**
00766  * @brief Program Inter measurement period (used only in continuous mode)
00767  *
00768  * @par Function Description
00769  * When trying to set too long time, it returns #INVALID_PARAMS
00770  *
00771  * @param InterMeasTime_msec Requires inter-measurement time in msec
00772  * @return 0 on success
00773  */     
00774     int RangeSetInterMeasPeriod(uint32_t  InterMeasTime_msec)
00775     {
00776 //       return VL6180x_RangeSetInterMeasPeriod(Device, InterMeasTime_msec);
00777             return 1;
00778     }
00779 
00780 /**
00781  * @brief Set device ranging scaling factor
00782  *
00783  * @par Function Description
00784  * The ranging scaling factor is applied on the raw distance measured by the device to increase operating ranging at the price of the precision.
00785  * Changing the scaling factor when device is not in f/w standby state (free running) is not safe.
00786  * It can be source of spurious interrupt, wrongly scaled range etc ...
00787  * @warning __This  function doesns't update high/low threshold and other programmed settings linked to scaling factor__.
00788  *  To ensure proper operation, threshold and scaling changes should be done following this procedure: \n
00789  *  @li Set Group hold  : @a VL6180x_SetGroupParamHold() \n
00790  *  @li Get Threshold @a VL6180x_RangeGetThresholds() \n
00791  *  @li Change scaling : @a VL6180x_UpscaleSetScaling() \n
00792  *  @li Set Threshold : @a VL6180x_RangeSetThresholds() \n
00793  *  @li Unset Group Hold : @a VL6180x_SetGroupParamHold()
00794  *
00795  * @param scaling  Scaling factor to apply (1,2 or 3)
00796  * @return          0 on success when up-scale support is not configured it fail for any
00797  *                  scaling than the one statically configured.
00798  */
00799     int UpscaleSetScaling(uint8_t scaling)
00800     {
00801 //       return VL6180x_UpscaleSetScaling(Device, scaling);
00802             return 1;
00803     }
00804 
00805 /**
00806  * @brief Get current ranging scaling factor
00807  *
00808  * @return    The current scaling factor
00809  */             
00810     int UpscaleGetScaling()
00811     {
00812 //       return VL6180x_UpscaleGetScaling(Device);
00813             return 1;
00814     }
00815 
00816 /**
00817  * @brief Get the maximal distance for actual scaling
00818  * @par Function Description
00819  * Do not use prior to @a VL6180x_Prepare() or at least @a VL6180x_InitData()
00820  *
00821  * Any range value more than the value returned by this function is to be considered as "no target detected"
00822  * or "no target in detectable range" \n
00823  * @warning The maximal distance depends on the scaling
00824  *
00825  * @return    The maximal range limit for actual mode and scaling
00826  */     
00827     uint16_t GetUpperLimit()
00828     {
00829 //       return VL6180x_GetUpperLimit(Device);
00830             return 1;
00831     }
00832 
00833 /**
00834  * @brief Apply low and high ranging thresholds that are considered only in continuous mode
00835  *
00836  * @par Function Description
00837  * This function programs low and high ranging thresholds that are considered in continuous mode : 
00838  * interrupt will be raised only when an object is detected at a distance inside this [low:high] range.  
00839  * The function takes care of applying current scaling factor if any.\n
00840  * To be safe, in continuous operation, thresholds must be changed under "group parameter hold" cover.
00841  * Group hold can be activated/deactivated directly in the function or externally (then set 0)
00842  * using /a VL6180x_SetGroupParamHold() function.
00843  *
00844  * @param low      Low threshold in mm
00845  * @param high     High threshold in mm
00846  * @param SafeHold  Use of group parameters hold to surround threshold programming.
00847  * @return  0 On success
00848  */     
00849     int RangeSetThresholds(uint16_t low, uint16_t high, int SafeHold)
00850     {
00851 //       return VL6180x_RangeSetThresholds(Device, low, high, SafeHold);
00852             return 1;
00853     }
00854 
00855 /**
00856  * @brief  Get scaled high and low threshold from device
00857  *
00858  * @par Function Description
00859  * Due to scaling factor, the returned value may be different from what has been programmed first (precision lost).
00860  * For instance VL6180x_RangeSetThresholds(dev,11,22) with scale 3
00861  * will read back 9 ((11/3)x3) and 21 ((22/3)x3).
00862  *
00863  * @param low  scaled low Threshold ptr  can be NULL if not needed
00864  * @param high scaled High Threshold ptr can be NULL if not needed
00865  * @return 0 on success, return value is undefined if both low and high are NULL
00866  * @warning return value is undefined if both low and high are NULL
00867  */
00868     int RangeGetThresholds(uint16_t *low, uint16_t *high)
00869     {
00870 //       return VL6180x_RangeGetThresholds(Device, low, high);
00871             return 1;
00872     }
00873 
00874 /**
00875  * @brief Set ranging raw thresholds (scaling not considered so not recommended to use it)
00876  *
00877  * @param low  raw low threshold set to raw register
00878  * @param high raw high threshold set to raw  register
00879  * @return 0 on success
00880  */         
00881     int RangeSetRawThresholds(uint8_t low, uint8_t high)
00882     {
00883 //       return VL6180x_RangeSetRawThresholds(Device, low, high);
00884             return 1;
00885     }
00886 
00887 /**
00888  * @brief Set Early Convergence Estimate ratio
00889  * @par Function Description
00890  * For more information on ECE check datasheet
00891  * @warning May return a calibration warning in some use cases
00892  *
00893  * @param FactorM    ECE factor M in M/D
00894  * @param FactorD    ECE factor D in M/D
00895  * @return           0 on success. <0 on error. >0 on warning
00896  */     
00897     int RangeSetEceFactor(uint16_t  FactorM, uint16_t FactorD)
00898     {
00899 //       return VL6180x_RangeSetEceFactor(Device, FactorM, FactorD);
00900             return 1;
00901     }
00902 
00903 /**
00904  * @brief Set Early Convergence Estimate state (See #SYSRANGE_RANGE_CHECK_ENABLES register)
00905  * @param enable    State to be set 0=disabled, otherwise enabled
00906  * @return          0 on success
00907  */     
00908     int RangeSetEceState(int enable)
00909     {
00910 //       return VL6180x_RangeSetEceState(Device, enable);
00911             return 1;
00912     }
00913 
00914 /**
00915  * @brief Set activation state of the wrap around filter
00916  * @param state New activation state (0=off,  otherwise on)
00917  * @return      0 on success
00918  */         
00919     int FilterSetState(int state)
00920     {
00921 //       return VL6180x_FilterSetState(Device, state);
00922             return 1;
00923     }
00924 
00925 /**
00926  * Get activation state of the wrap around filter
00927  * @return     Filter enabled or not, when filter is not supported it always returns 0S
00928  */         
00929     int FilterGetState()
00930     {
00931 //       return VL6180x_FilterGetState(Device);
00932             return 1;
00933     }
00934 
00935 /**
00936  * @brief Set activation state of  DMax computation
00937  * @param state New activation state (0=off,  otherwise on)
00938  * @return      0 on success
00939  */     
00940     int DMaxSetState(int state)
00941     {
00942 //       return VL6180x_DMaxSetState(Device, state);
00943             return 1;
00944     }
00945 
00946 /**
00947  * Get activation state of DMax computation
00948  * @return     Filter enabled or not, when filter is not supported it always returns 0S
00949  */     
00950     int DMaxGetState()
00951     {
00952 //       return VL6180x_DMaxGetState(Device);
00953             return 1;
00954     }
00955 
00956 /**
00957  * @brief Set ranging mode and start/stop measure (use high level functions instead : @a VL6180x_RangeStartSingleShot() or @a VL6180x_RangeStartContinuousMode())
00958  *
00959  * @par Function Description
00960  * When used outside scope of known polling single shot stopped state, \n
00961  * user must ensure the device state is "idle" before to issue a new command.
00962  *
00963  * @param mode  A combination of working mode (#MODE_SINGLESHOT or #MODE_CONTINUOUS) and start/stop condition (#MODE_START_STOP) \n
00964  * @return      0 on success
00965  */     
00966     int RangeSetSystemMode(uint8_t mode)
00967     {
00968 //       return VL6180x_RangeSetSystemMode(Device, mode);
00969             return 1;
00970     }
00971 
00972 /** @}  */ 
00973 
00974 /** @defgroup api_ll_range_calibration Ranging calibration functions
00975  *  @brief    Ranging calibration functions
00976  *  @ingroup api_ll
00977  *  @{  
00978  */
00979 /**
00980  * @brief Get part to part calibration offset
00981  *
00982  * @par Function Description
00983  * Should only be used after a successful call to @a VL6180x_InitData to backup device nvm value
00984  *
00985  * @return part to part calibration offset from device
00986  */     
00987     int8_t GetOffsetCalibrationData()
00988     {
00989 //       return VL6180x_GetOffsetCalibrationData(Device);
00990             return 1;
00991     }
00992 
00993 /**
00994  * Set or over-write part to part calibration offset
00995  * \sa VL6180x_InitData(), VL6180x_GetOffsetCalibrationData()
00996  * @param offset   Offset
00997  */     
00998     void SetOffsetCalibrationData(int8_t offset)
00999     {
01000 //       return VL6180x_SetOffsetCalibrationData(Device, offset);
01001             return;
01002     }
01003 
01004 /**
01005  * @brief Set Cross talk compensation rate
01006  *
01007  * @par Function Description
01008  * It programs register @a #SYSRANGE_CROSSTALK_COMPENSATION_RATE
01009  *
01010  * @param Rate Compensation rate (9.7 fix point) see datasheet for details
01011  * @return     0 on success
01012  */     
01013     int SetXTalkCompensationRate(uint16_t Rate)
01014     {
01015 //       return VL6180x_SetXTalkCompensationRate(Device, Rate);
01016             return 1;
01017     }
01018 /** @}  */
01019 
01020 /**
01021  * @brief Set new device i2c address
01022  *
01023  * After completion the device will answer to the new address programmed.
01024  *
01025  * @sa AN4478: Using multiple VL6180X's in a single design
01026  * @param NewAddr   The new i2c address (7bit)
01027  * @return          0 on success
01028  */     
01029     int SetDeviceAddress(int NewAddr)
01030     {
01031        int status;
01032             
01033        status=VL53L0X_SetDeviceAddress(Device, NewAddr);
01034        if(!status)
01035           Device->I2cDevAddr =NewAddr;
01036        return status;
01037             
01038 //          return 1;
01039     }
01040 
01041 /**
01042  * @brief Fully configure gpio 0/1 pin : polarity and functionality
01043  *
01044  * @param pin          gpio pin 0 or 1
01045  * @param IntFunction  Pin functionality : either #GPIOx_SELECT_OFF or #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT (refer to #SYSTEM_MODE_GPIO1 register definition)
01046  * @param ActiveHigh   Set active high polarity, or active low see @a ::IntrPol_e
01047  * @return             0 on success
01048  */     
01049     int SetupGPIOx(int pin, uint8_t IntFunction, int ActiveHigh)
01050     {
01051 //       return VL6180x_SetupGPIOx(Device, pin, IntFunction, ActiveHigh);
01052             return 1;
01053     }
01054 
01055 /**
01056  * @brief Set interrupt pin polarity for the given GPIO
01057  *
01058  * @param pin          Pin 0 or 1
01059  * @param active_high  select active high or low polarity using @ref IntrPol_e
01060  * @return             0 on success
01061  */     
01062     int SetGPIOxPolarity(int pin, int active_high)
01063     {
01064 //       return VL6180x_SetGPIOxPolarity(Device, pin, active_high);
01065             return 1;
01066     }
01067 
01068 /**
01069  * Select interrupt functionality for the given GPIO
01070  *
01071  * @par Function Description
01072  * Functionality refer to @a SYSTEM_MODE_GPIO0
01073  *
01074  * @param pin            Pin to configure 0 or 1 (gpio0 or gpio1)\nNote that gpio0 is chip enable at power up !
01075  * @param functionality  Pin functionality : either #GPIOx_SELECT_OFF or #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT (refer to #SYSTEM_MODE_GPIO1 register definition)
01076  * @return              0 on success
01077  */      
01078     int SetGPIOxFunctionality(int pin, uint8_t functionality)
01079     {
01080 //       return VL6180x_SetGPIOxFunctionality(Device, pin, functionality);
01081             return 1;
01082     }
01083 
01084 /**
01085  * #brief Disable and turn to Hi-Z gpio output pin
01086  *
01087  * @param pin  The pin number to disable 0 or 1
01088  * @return     0 on success
01089  */ 
01090     int DisableGPIOxOut(int pin)
01091     {
01092 //       return VL6180x_DisableGPIOxOut(Device, pin);
01093             return 1;
01094     }
01095 
01096 /** @}  */
01097 
01098 /** @defgroup api_ll_intr Interrupts management functions
01099  *  @brief    Interrupts management functions
01100  *  @ingroup api_ll
01101  *  @{  
01102  */
01103 
01104 /**
01105  * @brief     Get all interrupts cause
01106  *
01107  * @param status Ptr to interrupt status. You can use @a IntrStatus_t::val
01108  * @return 0 on success
01109  */     
01110     int GetInterruptStatus(uint8_t *status)
01111     {
01112 //       return VL6180x_GetInterruptStatus(Device, status);
01113             return 1;
01114     }
01115 
01116 /**
01117  * @brief Clear given system interrupt condition
01118  *
01119  * @par Function Description
01120  * Clear given interrupt cause by writing into register #SYSTEM_INTERRUPT_CLEAR register.
01121  * @param dev       The device 
01122  * @param IntClear  Which interrupt source to clear. Use any combinations of #INTERRUPT_CLEAR_RANGING , #INTERRUPT_CLEAR_ALS , #INTERRUPT_CLEAR_ERROR.
01123  * @return  0       On success
01124  */     
01125     int ClearInterrupt(uint8_t IntClear)
01126     {
01127 //       return VL6180x_ClearInterrupt(Device, IntClear );
01128             return 1;
01129     }
01130 
01131 /**
01132  * @brief Clear error interrupt
01133  *
01134  * @param dev    The device
01135  * @return  0    On success
01136  */
01137  #define VL6180x_ClearErrorInterrupt(dev) VL6180x_ClearInterrupt(dev, INTERRUPT_CLEAR_ERROR)
01138 
01139 /**
01140  * @brief Clear All interrupt causes (als+range+error)
01141  *
01142  * @param dev    The device
01143  * @return  0    On success
01144  */
01145 #define VL6180x_ClearAllInterrupt(dev) VL6180x_ClearInterrupt(dev, INTERRUPT_CLEAR_ERROR|INTERRUPT_CLEAR_RANGING|INTERRUPT_CLEAR_ALS)
01146     
01147 
01148  private:       
01149     /* api.h functions */
01150     VL53L0X_Error VL53L0X_DataInit(VL53L0X_DEV Dev);
01151     VL53L0X_Error VL53L0X_GetOffsetCalibrationDataMicroMeter(VL53L0X_DEV Dev, int32_t *pOffsetCalibrationDataMicroMeter);
01152     VL53L0X_Error VL53L0X_SetOffsetCalibrationDataMicroMeter(VL53L0X_DEV Dev,
01153         int32_t OffsetCalibrationDataMicroMeter);
01154     VL53L0X_Error VL53L0X_GetDeviceParameters(VL53L0X_DEV Dev,
01155         VL53L0X_DeviceParameters_t *pDeviceParameters);
01156     VL53L0X_Error VL53L0X_GetDeviceMode(VL53L0X_DEV Dev,
01157         VL53L0X_DeviceModes *pDeviceMode);
01158     VL53L0X_Error VL53L0X_GetInterMeasurementPeriodMilliSeconds(VL53L0X_DEV Dev,
01159         uint32_t *pInterMeasurementPeriodMilliSeconds);
01160     VL53L0X_Error VL53L0X_GetXTalkCompensationRateMegaCps(VL53L0X_DEV Dev,
01161         FixPoint1616_t *pXTalkCompensationRateMegaCps);
01162     VL53L0X_Error VL53L0X_GetLimitCheckValue(VL53L0X_DEV Dev, uint16_t LimitCheckId,
01163         FixPoint1616_t *pLimitCheckValue);
01164     VL53L0X_Error VL53L0X_GetLimitCheckEnable(VL53L0X_DEV Dev, uint16_t LimitCheckId,
01165         uint8_t *pLimitCheckEnable);
01166     VL53L0X_Error VL53L0X_GetWrapAroundCheckEnable(VL53L0X_DEV Dev,
01167         uint8_t *pWrapAroundCheckEnable);
01168     VL53L0X_Error VL53L0X_GetMeasurementTimingBudgetMicroSeconds(VL53L0X_DEV Dev,
01169         uint32_t *pMeasurementTimingBudgetMicroSeconds);
01170     VL53L0X_Error VL53L0X_GetSequenceStepEnables(VL53L0X_DEV Dev,
01171         VL53L0X_SchedulerSequenceSteps_t *pSchedulerSequenceSteps);
01172     VL53L0X_Error sequence_step_enabled(VL53L0X_DEV Dev,
01173         VL53L0X_SequenceStepId SequenceStepId, uint8_t SequenceConfig,
01174         uint8_t *pSequenceStepEnabled);
01175     VL53L0X_Error VL53L0X_GetVcselPulsePeriod(VL53L0X_DEV Dev,
01176         VL53L0X_VcselPeriod VcselPeriodType, uint8_t *pVCSELPulsePeriodPCLK);
01177     VL53L0X_Error VL53L0X_GetDeviceInfo(VL53L0X_DEV Dev,
01178         VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo);
01179     VL53L0X_Error VL53L0X_StaticInit(VL53L0X_DEV Dev);
01180     VL53L0X_Error VL53L0X_GetMeasurementDataReady(VL53L0X_DEV Dev,
01181         uint8_t *pMeasurementDataReady);
01182     VL53L0X_Error VL53L0X_GetInterruptMaskStatus(VL53L0X_DEV Dev,
01183         uint32_t *pInterruptMaskStatus);
01184     VL53L0X_Error VL53L0X_ClearInterruptMask(VL53L0X_DEV Dev, uint32_t InterruptMask);
01185     VL53L0X_Error VL53L0X_PerformSingleRangingMeasurement(VL53L0X_DEV Dev,
01186         VL53L0X_RangingMeasurementData_t *pRangingMeasurementData);
01187     VL53L0X_Error VL53L0X_SetDeviceMode(VL53L0X_DEV Dev, VL53L0X_DeviceModes DeviceMode);
01188     VL53L0X_Error VL53L0X_PerformSingleMeasurement(VL53L0X_DEV Dev);
01189     VL53L0X_Error VL53L0X_StartMeasurement(VL53L0X_DEV Dev);
01190     VL53L0X_Error VL53L0X_CheckAndLoadInterruptSettings(VL53L0X_DEV Dev,
01191         uint8_t StartNotStopFlag);
01192     VL53L0X_Error VL53L0X_GetInterruptThresholds(VL53L0X_DEV Dev,
01193         VL53L0X_DeviceModes DeviceMode, FixPoint1616_t *pThresholdLow,
01194         FixPoint1616_t *pThresholdHigh);
01195     VL53L0X_Error VL53L0X_GetRangingMeasurementData(VL53L0X_DEV Dev,
01196         VL53L0X_RangingMeasurementData_t *pRangingMeasurementData);
01197     VL53L0X_Error VL53L0X_GetXTalkCompensationEnable(VL53L0X_DEV Dev,
01198         uint8_t *pXTalkCompensationEnable);
01199     VL53L0X_Error VL53L0X_WaitDeviceBooted(VL53L0X_DEV Dev);
01200     VL53L0X_Error VL53L0X_PerformRefCalibration(VL53L0X_DEV Dev, uint8_t *pVhvSettings,
01201         uint8_t *pPhaseCal);
01202     VL53L0X_Error VL53L0X_PerformRefSpadManagement(VL53L0X_DEV Dev,
01203         uint32_t *refSpadCount, uint8_t *isApertureSpads);
01204     VL53L0X_Error VL53L0X_SetDeviceAddress(VL53L0X_DEV Dev, uint8_t DeviceAddress);
01205     VL53L0X_Error VL53L0X_SetGpioConfig(VL53L0X_DEV Dev, uint8_t Pin,
01206         VL53L0X_DeviceModes DeviceMode, VL53L0X_GpioFunctionality Functionality,
01207         VL53L0X_InterruptPolarity Polarity);
01208     VL53L0X_Error VL53L0X_GetFractionEnable(VL53L0X_DEV Dev, uint8_t *pEnabled);
01209     VL53L0X_Error VL53L0X_SetSequenceStepEnable(VL53L0X_DEV Dev,
01210         VL53L0X_SequenceStepId SequenceStepId, uint8_t SequenceStepEnabled);
01211     VL53L0X_Error VL53L0X_SetMeasurementTimingBudgetMicroSeconds(VL53L0X_DEV Dev,
01212         uint32_t MeasurementTimingBudgetMicroSeconds);
01213     VL53L0X_Error VL53L0X_SetLimitCheckEnable(VL53L0X_DEV Dev, uint16_t LimitCheckId,
01214         uint8_t LimitCheckEnable);
01215     VL53L0X_Error VL53L0X_SetLimitCheckValue(VL53L0X_DEV Dev, uint16_t LimitCheckId,
01216         FixPoint1616_t LimitCheckValue);
01217     VL53L0X_Error VL53L0X_StopMeasurement(VL53L0X_DEV Dev);
01218     VL53L0X_Error VL53L0X_GetStopCompletedStatus(VL53L0X_DEV Dev,
01219         uint32_t *pStopStatus);
01220     VL53L0X_Error VL53L0X_SetVcselPulsePeriod(VL53L0X_DEV Dev,
01221         VL53L0X_VcselPeriod VcselPeriodType, uint8_t VCSELPulsePeriod);
01222 
01223     /* api_core.h functions */
01224     VL53L0X_Error VL53L0X_get_info_from_device(VL53L0X_DEV Dev, uint8_t option);
01225     VL53L0X_Error VL53L0X_device_read_strobe(VL53L0X_DEV Dev);
01226     VL53L0X_Error VL53L0X_get_measurement_timing_budget_micro_seconds(VL53L0X_DEV Dev,
01227             uint32_t *pMeasurementTimingBudgetMicroSeconds);
01228     VL53L0X_Error VL53L0X_get_vcsel_pulse_period(VL53L0X_DEV Dev,
01229         VL53L0X_VcselPeriod VcselPeriodType, uint8_t *pVCSELPulsePeriodPCLK);
01230     uint8_t VL53L0X_decode_vcsel_period(uint8_t vcsel_period_reg);
01231     uint32_t VL53L0X_decode_timeout(uint16_t encoded_timeout);
01232     uint32_t VL53L0X_calc_timeout_us(VL53L0X_DEV Dev,
01233             uint16_t timeout_period_mclks,
01234             uint8_t vcsel_period_pclks);
01235     uint32_t VL53L0X_calc_macro_period_ps(VL53L0X_DEV Dev, uint8_t vcsel_period_pclks);
01236     VL53L0X_Error VL53L0X_measurement_poll_for_completion(VL53L0X_DEV Dev);
01237     VL53L0X_Error VL53L0X_load_tuning_settings(VL53L0X_DEV Dev,
01238             uint8_t *pTuningSettingBuffer);
01239     VL53L0X_Error VL53L0X_get_pal_range_status(VL53L0X_DEV Dev,
01240             uint8_t DeviceRangeStatus,
01241             FixPoint1616_t SignalRate,
01242             uint16_t EffectiveSpadRtnCount,
01243             VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
01244             uint8_t *pPalRangeStatus);
01245     VL53L0X_Error VL53L0X_calc_sigma_estimate(VL53L0X_DEV Dev,
01246         VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
01247         FixPoint1616_t *pSigmaEstimate,
01248         uint32_t *pDmax_mm);
01249     VL53L0X_Error VL53L0X_get_total_signal_rate(VL53L0X_DEV Dev,
01250         VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
01251         FixPoint1616_t *ptotal_signal_rate_mcps);
01252     VL53L0X_Error VL53L0X_get_total_xtalk_rate(VL53L0X_DEV Dev,
01253         VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
01254         FixPoint1616_t *ptotal_xtalk_rate_mcps);
01255     uint32_t VL53L0X_calc_timeout_mclks(VL53L0X_DEV Dev,
01256             uint32_t timeout_period_us,
01257             uint8_t vcsel_period_pclks);
01258     uint32_t VL53L0X_isqrt(uint32_t num);
01259     VL53L0X_Error VL53L0X_calc_dmax(
01260         VL53L0X_DEV Dev,
01261         FixPoint1616_t totalSignalRate_mcps,
01262         FixPoint1616_t totalCorrSignalRate_mcps,
01263         FixPoint1616_t pwMult,
01264         uint32_t sigmaEstimateP1,
01265         FixPoint1616_t sigmaEstimateP2,
01266         uint32_t peakVcselDuration_us,
01267         uint32_t *pdmax_mm);
01268     VL53L0X_Error VL53L0X_set_measurement_timing_budget_micro_seconds(VL53L0X_DEV Dev,
01269             uint32_t MeasurementTimingBudgetMicroSeconds);
01270     VL53L0X_Error get_sequence_step_timeout(VL53L0X_DEV Dev,
01271                     VL53L0X_SequenceStepId SequenceStepId,
01272                     uint32_t *pTimeOutMicroSecs);
01273     VL53L0X_Error set_sequence_step_timeout(VL53L0X_DEV Dev,
01274                         VL53L0X_SequenceStepId SequenceStepId,
01275                         uint32_t TimeOutMicroSecs);
01276     uint16_t VL53L0X_encode_timeout(uint32_t timeout_macro_clks);
01277     VL53L0X_Error VL53L0X_set_vcsel_pulse_period(VL53L0X_DEV Dev,
01278         VL53L0X_VcselPeriod VcselPeriodType, uint8_t VCSELPulsePeriodPCLK);
01279     uint8_t VL53L0X_encode_vcsel_period(uint8_t vcsel_period_pclks);
01280 
01281     /* api_calibration.h functions */
01282     VL53L0X_Error VL53L0X_apply_offset_adjustment(VL53L0X_DEV Dev);
01283     VL53L0X_Error VL53L0X_get_offset_calibration_data_micro_meter(VL53L0X_DEV Dev,
01284             int32_t *pOffsetCalibrationDataMicroMeter);
01285     VL53L0X_Error VL53L0X_set_offset_calibration_data_micro_meter(VL53L0X_DEV Dev,
01286             int32_t OffsetCalibrationDataMicroMeter);
01287     VL53L0X_Error VL53L0X_perform_ref_spad_management(VL53L0X_DEV Dev,
01288                     uint32_t *refSpadCount,
01289                     uint8_t *isApertureSpads);
01290     VL53L0X_Error VL53L0X_perform_ref_calibration(VL53L0X_DEV Dev,
01291         uint8_t *pVhvSettings, uint8_t *pPhaseCal, uint8_t get_data_enable);
01292     VL53L0X_Error VL53L0X_perform_vhv_calibration(VL53L0X_DEV Dev,
01293         uint8_t *pVhvSettings, const uint8_t get_data_enable,
01294         const uint8_t restore_config);
01295     VL53L0X_Error VL53L0X_perform_single_ref_calibration(VL53L0X_DEV Dev,
01296             uint8_t vhv_init_byte);
01297     VL53L0X_Error VL53L0X_ref_calibration_io(VL53L0X_DEV Dev, uint8_t read_not_write,
01298         uint8_t VhvSettings, uint8_t PhaseCal,
01299         uint8_t *pVhvSettings, uint8_t *pPhaseCal,
01300         const uint8_t vhv_enable, const uint8_t phase_enable);
01301     VL53L0X_Error VL53L0X_perform_phase_calibration(VL53L0X_DEV Dev,
01302         uint8_t *pPhaseCal, const uint8_t get_data_enable,
01303         const uint8_t restore_config);
01304     VL53L0X_Error enable_ref_spads(VL53L0X_DEV Dev,
01305                     uint8_t apertureSpads,
01306                     uint8_t goodSpadArray[],
01307                     uint8_t spadArray[],
01308                     uint32_t size,
01309                     uint32_t start,
01310                     uint32_t offset,
01311                     uint32_t spadCount,
01312                     uint32_t *lastSpad);
01313     void get_next_good_spad(uint8_t goodSpadArray[], uint32_t size,
01314                 uint32_t curr, int32_t *next);
01315     uint8_t is_aperture(uint32_t spadIndex);
01316     VL53L0X_Error enable_spad_bit(uint8_t spadArray[], uint32_t size,
01317         uint32_t spadIndex);
01318     VL53L0X_Error set_ref_spad_map(VL53L0X_DEV Dev, uint8_t *refSpadArray);
01319     VL53L0X_Error get_ref_spad_map(VL53L0X_DEV Dev, uint8_t *refSpadArray);
01320     VL53L0X_Error perform_ref_signal_measurement(VL53L0X_DEV Dev,
01321             uint16_t *refSignalRate);
01322     VL53L0X_Error VL53L0X_set_reference_spads(VL53L0X_DEV Dev,
01323                      uint32_t count, uint8_t isApertureSpads);
01324 
01325     /* api_strings.h functions */
01326     VL53L0X_Error VL53L0X_get_device_info(VL53L0X_DEV Dev,
01327                     VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo);
01328     VL53L0X_Error VL53L0X_check_part_used(VL53L0X_DEV Dev,
01329             uint8_t *Revision,
01330             VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo);
01331 
01332     /* Read function of the ID device */
01333     virtual int ReadID(uint8_t *id);
01334     
01335     VL53L0X_Error WaitMeasurementDataReady(VL53L0X_DEV Dev);
01336     VL53L0X_Error WaitStopCompleted(VL53L0X_DEV Dev);
01337 
01338     /* Write and read functions from I2C */
01339         
01340     VL53L0X_Error VL53L0X_WrByte(VL53L0X_DEV dev, uint8_t index, uint8_t data);
01341     VL53L0X_Error VL53L0X_WrWord(VL53L0X_DEV dev, uint8_t index, uint16_t data);
01342     VL53L0X_Error VL53L0X_WrDWord(VL53L0X_DEV dev, uint8_t index, uint32_t data);
01343     VL53L0X_Error VL53L0X_RdByte(VL53L0X_DEV dev, uint8_t index, uint8_t *data);
01344     VL53L0X_Error VL53L0X_RdWord(VL53L0X_DEV dev, uint8_t index, uint16_t *data);
01345     VL53L0X_Error VL53L0X_RdDWord(VL53L0X_DEV dev, uint8_t index, uint32_t *data);
01346     VL53L0X_Error VL53L0X_UpdateByte(VL53L0X_DEV dev, uint8_t index, uint8_t AndData, uint8_t OrData);
01347         
01348     VL53L0X_Error VL53L0X_WriteMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count);
01349     VL53L0X_Error VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count);
01350         
01351     VL53L0X_Error VL53L0X_I2CWrite(uint8_t dev, uint8_t index, uint8_t *data, uint16_t number_of_bytes);
01352     VL53L0X_Error VL53L0X_I2CRead(uint8_t dev, uint8_t index, uint8_t *data, uint16_t number_of_bytes);
01353         
01354     VL53L0X_Error VL53L0X_PollingDelay(VL53L0X_DEV Dev); /* usually best implemented as a real function */
01355         
01356     int IsPresent()
01357     {
01358        int status;
01359             
01360        status=ReadID((uint8_t *)MyDevice.I2cDevAddr );
01361        if(status)
01362           VL53L0X_ErrLog("Failed to read ID device. Device not present!\n\r");
01363        return status;
01364     }   
01365     int StopRangeMeasurement(OperatingMode operating_mode);
01366     int GetRangeMeas(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *Data); 
01367     int RangeSetLowThreshold(uint16_t threshold);
01368     int RangeSetHighThreshold(uint16_t threshold);
01369     int GetRangeError(VL53L0X_RangingMeasurementData_t *Data, VL53L0X_RangingMeasurementData_t RangeData);
01370     int RangeMeasPollSingleShot();
01371     int RangeMeasPollContinuousMode();  
01372     int RangeMeasIntContinuousMode(void (*fptr)(void));
01373 
01374 
01375     VL53L0X_DeviceInfo_t DeviceInfo;
01376         
01377     /* IO Device */
01378     DevI2C &dev_i2c;
01379     /* Digital out pin */
01380     DigitalOut *gpio0;
01381     /* GPIO expander */
01382     STMPE1600DigiOut *expgpio0;
01383     /* Measure detection IRQ */
01384     InterruptIn *gpio1Int;
01385     /* Device data */
01386     VL53L0X_Dev_t MyDevice;
01387     VL53L0X_DEV Device;  
01388 };
01389 
01390 
01391 #endif /* _VL53L0X_CLASS_H_ */
01392 
01393