Code petit robot

Dependencies:   X_NUCLEO_COMMON X_NUCLEO_IHM01A1 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers vl6180x_class.h Source File

vl6180x_class.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    vl6180x_class.h
00004  * @author  AST / EST
00005  * @version V0.0.1
00006  * @date    9-November-2015
00007  * @brief   Header file for component VL6180X
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
00012  *
00013  * Redistribution and use in source and binary forms, with or without modification,
00014  * are permitted provided that the following conditions are met:
00015  *   1. Redistributions of source code must retain the above copyright notice,
00016  *      this list of conditions and the following disclaimer.
00017  *   2. Redistributions in binary form must reproduce the above copyright notice,
00018  *      this list of conditions and the following disclaimer in the documentation
00019  *      and/or other materials provided with the distribution.
00020  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021  *      may be used to endorse or promote products derived from this software
00022  *       without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  ******************************************************************************
00036 */
00037 
00038 #ifndef __VL6180X_CLASS_H
00039 #define __VL6180X_CLASS_H
00040 
00041 /* Includes ------------------------------------------------------------------*/
00042 #include "RangeSensor.h"
00043 #include "LightSensor.h"
00044 #include "DevI2C.h" 
00045 //#include "vl6180x_api.h"
00046 #include "vl6180x_cfg.h"
00047 #include "vl6180x_def.h"
00048 #include "vl6180x_types.h"
00049 #include "vl6180x_platform.h"
00050 
00051 
00052  
00053 /* data struct containing range measure, light measure and type of error provided to the user
00054    in case of invalid data range_mm=0xFFFFFFFF and lux=0xFFFFFFFF */    
00055 typedef struct MeasureData 
00056 {
00057    uint32_t range_mm;
00058    uint32_t lux;
00059    uint32_t range_error;
00060    uint32_t als_error;
00061    uint32_t int_error;
00062 }MeasureData_t;
00063 
00064 /* sensor operating modes */ 
00065 typedef enum
00066 {
00067    range_single_shot_polling=1,
00068    als_single_shot_polling,
00069    range_continuous_polling,
00070    als_continuous_polling,
00071    range_continuous_interrupt,
00072    als_continuous_interrupt,
00073    interleaved_mode_interrupt,
00074    range_continuous_polling_low_threshold,
00075    range_continuous_polling_high_threshold,
00076    range_continuous_polling_out_of_window,
00077    als_continuous_polling_low_threshold,
00078    als_continuous_polling_high_threshold,
00079    als_continuous_polling_out_of_window,
00080    range_continuous_interrupt_low_threshold,
00081    range_continuous_interrupt_high_threshold,
00082    range_continuous_interrupt_out_of_window,
00083    als_continuous_interrupt_low_threshold,
00084    als_continuous_interrupt_high_threshold,
00085    als_continuous_interrupt_out_of_window,
00086    range_continuous_als_single_shot,
00087    range_single_shot_als_continuous,
00088 }OperatingMode;
00089 
00090 /** default device address */
00091 #define DEFAULT_DEVICE_ADDRESS      0x29
00092 
00093 /* Classes -------------------------------------------------------------------*/
00094 /** Class representing a VL6180X sensor component
00095  */
00096 class VL6180X : public RangeSensor, public LightSensor
00097 {
00098  public:
00099     /** Constructor 1
00100      * @param[in] &i2c device I2C to be used for communication
00101      * @param[in] &pin Mbed DigitalOut pin to be used as component GPIO_0 CE
00102      * @param[in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
00103      * @param[in] DevAddr device address, 0x29 by default  
00104      */
00105     VL6180X(DevI2C &i2c, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), LightSensor(), dev_i2c(i2c)
00106     {
00107        MyDevice.I2cAddr=DevAddr;         
00108        MyDevice.Present=0;
00109        MyDevice.Ready=0;
00110        Device=&MyDevice;;
00111     }  
00112     
00113    /** Destructor
00114     */
00115     virtual ~VL6180X(){}     
00116     /* warning: VL6180X class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor.
00117        The warning should request to introduce a virtual destructor to make sure to delete the object */
00118 
00119     /*** Interface Methods ***/ 
00120     /*** High level API ***/        
00121     /**
00122      * @brief       PowerOn the sensor
00123      * @return      void
00124      */     
00125     /* turns on the sensor */        
00126     void VL6180x_On(void)
00127     {
00128     } 
00129 
00130     /**
00131      * @brief       PowerOff the sensor
00132      * @return      void
00133      */     
00134     /* turns off the sensor */
00135     void VL6180x_Off(void) 
00136     {
00137     }
00138     
00139     /**
00140      * @brief       Initialize the sensor with default values
00141      * @return      0 on Success
00142      */                  
00143     int InitSensor(uint8_t NewAddr);
00144     
00145     /**
00146      * @brief       Start the measure indicated by operating mode
00147      * @param[in]   operating_mode specifies requested measure 
00148      * @param[in]   fptr specifies call back function must be !NULL in case of interrupt measure     
00149      * @param[in]   low specifies measure low threashold in Lux or in mm according to measure
00150      * @param[in]   high specifies measure high threashold in Lux or in mm according to measure
00151      * @return      0 on Success
00152      */                      
00153     int StartMeasurement(OperatingMode operating_mode, void (*fptr)(void), uint16_t low, uint16_t high);
00154 
00155     /**
00156      * @brief       Get results for the measure indicated by operating mode
00157      * @param[in]   operating_mode specifies requested measure results
00158      * @param[out]  Data pointer to the MeasureData_t structure to read data in to
00159      * @return      0 on Success
00160      */                          
00161     int GetMeasurement(OperatingMode operating_mode, MeasureData_t *Data);      
00162 
00163     /**
00164      * @brief       Stop the currently running measure indicate by operating_mode
00165      * @param[in]   operating_mode specifies requested measure to stop
00166      * @return      0 on Success
00167      */                              
00168     int StopMeasurement(OperatingMode operating_mode);
00169      
00170     /**
00171      * @brief       Interrupt handling func to be called by user after an INT is occourred
00172      * @param[in]   opeating_mode indicating the in progress measure
00173      * @param[out]  Data pointer to the MeasureData_t structure to read data in to
00174      * @return      0 on Success
00175      */                                 
00176     int HandleIRQ(OperatingMode operating_mode, MeasureData_t *Data);    
00177 
00178     /**
00179      * @brief       Enable interrupt measure IRQ
00180      * @return      0 on Success
00181      */                      
00182     void EnableInterruptMeasureDetectionIRQ(void) 
00183     {
00184     }
00185 
00186     /**
00187      * @brief       Disable interrupt measure IRQ
00188      * @return      0 on Success
00189      */                           
00190     void DisableInterruptMeasureDetectionIRQ(void) 
00191     {
00192     }
00193     /*** End High level API ***/              
00194     
00195     /**
00196      * @brief       Attach a function to call when an interrupt is detected, i.e. measurement is ready
00197      * @param[in]   fptr pointer to call back function to be called whenever an interrupt occours
00198      * @return      0 on Success
00199      */                                   
00200     void AttachInterruptMeasureDetectionIRQ(void (*fptr)(void))
00201     {
00202     }
00203     
00204     /**
00205      * @brief       Check the sensor presence
00206      * @return      1 when device is present
00207      */                     
00208     unsigned Present()
00209     {
00210        return Device->Present;
00211     }
00212         
00213     /** Wrapper functions */    
00214 /** @defgroup api_init Init functions
00215  *  @brief    API init functions
00216  *  @ingroup api_hl
00217  *  @{  
00218  */
00219 /**
00220  * @brief Wait for device booted after chip enable (hardware standby)
00221  * @par Function Description
00222  * After Chip enable Application you can also simply wait at least 1ms to ensure device is ready
00223  * @warning After device chip enable (gpio0) de-asserted  user must wait gpio1 to get asserted (hardware standby).
00224  * or wait at least 400usec prior to do any low level access or api call .
00225  *
00226  * This function implements polling for standby but you must ensure 400usec from chip enable passed\n
00227  * @warning if device get prepared @a VL6180x_Prepare() re-using these function can hold indefinitely\n
00228  *
00229  * @param       void
00230  * @return     0 on success
00231  */
00232     int WaitDeviceBooted()
00233     {
00234        return VL6180x_WaitDeviceBooted(Device);
00235     }
00236 
00237 /**
00238  *
00239  * @brief One time device initialization
00240  *
00241  * To be called once and only once after device is brought out of reset (Chip enable) and booted see @a VL6180x_WaitDeviceBooted()
00242  *
00243  * @par Function Description
00244  * When not used after a fresh device "power up" or reset, it may return @a #CALIBRATION_WARNING
00245  * meaning wrong calibration data may have been fetched from device that can result in ranging offset error\n
00246  * If application cannot execute device reset or need to run VL6180x_InitData  multiple time
00247  * then it  must ensure proper offset calibration saving and restore on its own
00248  * by using @a VL6180x_GetOffsetCalibrationData() on first power up and then @a VL6180x_SetOffsetCalibrationData() all all subsequent init
00249  *
00250  * @param void
00251  * @return     0 on success,  @a #CALIBRATION_WARNING if failed
00252  */     
00253     virtual int Init() 
00254     {
00255        return VL6180x_InitData(Device);
00256     }
00257 
00258 /**
00259  * @brief Configure GPIO1 function and set polarity.
00260  * @par Function Description
00261  * To be used prior to arm single shot measure or start  continuous mode.
00262  *
00263  * The function uses @a VL6180x_SetupGPIOx() for setting gpio 1.
00264  * @warning  changing polarity can generate a spurious interrupt on pins.
00265  * It sets an interrupt flags condition that must be cleared to avoid polling hangs. \n
00266  * It is safe to run VL6180x_ClearAllInterrupt() just after.
00267  *
00268  * @param IntFunction   The interrupt functionality to use one of :\n
00269  *  @a #GPIOx_SELECT_OFF \n
00270  *  @a #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT
00271  * @param ActiveHigh  The interrupt line polarity see ::IntrPol_e
00272  *      use @a #INTR_POL_LOW (falling edge) or @a #INTR_POL_HIGH (rising edge)
00273  * @return 0 on success
00274  */     
00275     int SetupGPIO1(uint8_t InitFunction, int ActiveHigh)
00276     {
00277        return VL6180x_SetupGPIO1(Device, InitFunction, ActiveHigh);
00278     }
00279 
00280 /**
00281   * @brief  Prepare device for operation
00282   * @par Function Description
00283   * Does static initialization and reprogram common default settings \n
00284   * Device is prepared for new measure, ready single shot ranging or ALS typical polling operation\n
00285   * After prepare user can : \n
00286   * @li Call other API function to set other settings\n
00287   * @li Configure the interrupt pins, etc... \n
00288   * @li Then start ranging or ALS operations in single shot or continuous mode
00289   *
00290   * @param void
00291   * @return      0 on success
00292   */        
00293     int Prepare()
00294     {
00295        return VL6180x_Prepare(Device);
00296     }
00297 
00298  /**
00299  * @brief Start continuous ranging mode
00300  *
00301  * @details End user should ensure device is in idle state and not already running
00302  * @return      0 on success
00303  */     
00304     int RangeStartContinuousMode()
00305     {
00306        return VL6180x_RangeStartContinuousMode(Device);
00307     }
00308 
00309 /**
00310  * @brief Start single shot ranging measure
00311  *
00312  * @details End user should ensure device is in idle state and not already running
00313  * @return      0 on success 
00314  */     
00315     int RangeStartSingleShot()
00316     {
00317        return VL6180x_RangeStartSingleShot(Device);
00318     }
00319 
00320 /**
00321  * @brief Set maximum convergence time
00322  *
00323  * @par Function Description
00324  * Setting a low convergence time can impact maximal detectable distance.
00325  * Refer to VL6180x Datasheet Table 7 : Typical range convergence time.
00326  * A typical value for up to x3 scaling is 50 ms
00327  *
00328  * @param MaxConTime_msec
00329  * @return 0 on success. <0 on error. >0 for calibration warning status
00330  */     
00331     int RangeSetMaxConvergenceTime(uint8_t MaxConTime_msec)
00332     {
00333        return VL6180x_RangeSetMaxConvergenceTime(Device, MaxConTime_msec);
00334     }
00335 
00336 /**
00337   * @brief Single shot Range measurement in polling mode.
00338   *
00339   * @par Function Description
00340   * Kick off a new single shot range  then wait for ready to retrieve it by polling interrupt status \n
00341   * Ranging must be prepared by a first call to  @a VL6180x_Prepare() and it is safer to clear  very first poll call \n
00342   * This function reference VL6180x_PollDelay(dev) porting macro/call on each polling loop,
00343   * but PollDelay(dev) may never be called if measure in ready on first poll loop \n
00344   * Should not be use in continuous mode operation as it will stop it and cause stop/start misbehaviour \n
00345   * \n This function clears Range Interrupt status , but not error one. For that uses  @a VL6180x_ClearErrorInterrupt() \n
00346   * This range error is not related VL6180x_RangeData_t::errorStatus that refer measure status \n
00347   * 
00348   * @param pRangeData   Will be populated with the result ranging data @a  VL6180x_RangeData_t
00349   * @return 0 on success , @a #RANGE_ERROR if device reports an error case in it status (not cleared) use
00350   *
00351   * \sa ::VL6180x_RangeData_t
00352   */        
00353     int RangePollMeasurement(VL6180x_RangeData_t *pRangeData)
00354     {
00355        return VL6180x_RangePollMeasurement(Device, pRangeData);
00356     }
00357 
00358 /**
00359  * @brief Check for measure readiness and get it if ready
00360  *
00361  * @par Function Description
00362  * Using this function is an alternative to @a VL6180x_RangePollMeasurement() to avoid polling operation. This is suitable for applications
00363  * 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
00364  * operation is triggered by a call to @a VL6180x_RangeStartSingleShot(). Then, host CPU regularly calls @a VL6180x_RangeGetMeasurementIfReady() to
00365  * get a distance measure if ready. In case the distance is not ready, host may get it at the next call.\n
00366  *
00367  * @warning 
00368  * This function does not re-start a new measurement : this is up to the host CPU to do it.\n 
00369  * This function clears Range Interrupt for measure ready , but not error interrupts. For that, uses  @a VL6180x_ClearErrorInterrupt() \n
00370  *
00371  * @param pRangeData  Will be populated with the result ranging data if available
00372  * @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,
00373  */     
00374     int RangeGetMeasurementIfReady(VL6180x_RangeData_t *pRangeData)
00375     {
00376        return VL6180x_RangeGetMeasurementIfReady(Device, pRangeData);
00377     }
00378 
00379 /**
00380  * @brief Retrieve range measurements set  from device
00381  *
00382  * @par Function Description
00383  * The measurement is made of range_mm status and error code @a VL6180x_RangeData_t \n
00384  * Based on configuration selected extra measures are included.
00385  *
00386  * @warning should not be used in continuous if wrap around filter is active \n
00387  * Does not perform any wait nor check for result availability or validity.
00388  *\sa VL6180x_RangeGetResult for "range only" measurement
00389  *
00390  * @param pRangeData  Pointer to the data structure to fill up
00391  * @return            0 on success
00392  */     
00393     int RangeGetMeasurement(VL6180x_RangeData_t *pRangeData)
00394     {
00395        return VL6180x_RangeGetMeasurement(Device, pRangeData);
00396     }
00397 
00398 /**
00399  * @brief Get ranging result and only that
00400  *
00401  * @par Function Description
00402  * Unlike @a VL6180x_RangeGetMeasurement() this function only retrieves the range in millimeter \n
00403  * It does any required up-scale translation\n
00404  * It can be called after success status polling or in interrupt mode \n
00405  * @warning these function is not doing wrap around filtering \n
00406  * This function doesn't perform any data ready check!
00407  *
00408  * @param pRange_mm  Pointer to range distance
00409  * @return           0 on success
00410  */     
00411     virtual int GetRange(int32_t *piData)
00412     {
00413        return VL6180x_RangeGetResult(Device, piData);
00414     }
00415         
00416 /**
00417  * @brief Configure ranging interrupt reported to application
00418  *
00419  * @param ConfigGpioInt  Select ranging report\n select one (and only one) of:\n
00420  *   @a #CONFIG_GPIO_INTERRUPT_DISABLED \n
00421  *   @a #CONFIG_GPIO_INTERRUPT_LEVEL_LOW \n
00422  *   @a #CONFIG_GPIO_INTERRUPT_LEVEL_HIGH \n
00423  *   @a #CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW \n
00424  *   @a #CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY
00425  * @return   0 on success
00426  */
00427     int RangeConfigInterrupt(uint8_t ConfigGpioInt)
00428     {
00429        return VL6180x_RangeConfigInterrupt(Device, ConfigGpioInt);
00430     }
00431 
00432 /**
00433  * @brief Return ranging error interrupt status
00434  *
00435  * @par Function Description
00436  * Appropriate Interrupt report must have been selected first by @a VL6180x_RangeConfigInterrupt() or @a  VL6180x_Prepare() \n
00437  *
00438  * Can be used in polling loop to wait for a given ranging event or in interrupt to read the trigger \n
00439  * Events triggers are : \n
00440  * @a #RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD \n
00441  * @a #RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD \n
00442  * @a #RES_INT_STAT_GPIO_OUT_OF_WINDOW \n (RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD|RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD)
00443  * @a #RES_INT_STAT_GPIO_NEW_SAMPLE_READY \n
00444  *
00445  * @sa IntrStatus_t
00446  * @param pIntStatus Pointer to status variable to update
00447  * @return           0 on success
00448  */     
00449     int RangeGetInterruptStatus(uint8_t *pIntStatus)
00450     {
00451        return VL6180x_RangeGetInterruptStatus(Device, pIntStatus);
00452     }
00453 
00454 /**
00455  * @brief   Run a single ALS measurement in single shot polling mode
00456  *
00457  * @par Function Description
00458  * Kick off a new single shot ALS then wait new measurement ready to retrieve it ( polling system interrupt status register for als) \n
00459  * ALS must be prepared by a first call to @a VL6180x_Prepare() \n
00460  * \n Should not be used in continuous or interrupt mode it will break it and create hazard in start/stop \n
00461  *
00462  * @param dev          The device
00463  * @param pAlsData     Als data structure to fill up @a VL6180x_AlsData_t
00464  * @return             0 on success
00465  */     
00466     int AlsPollMeasurement(VL6180x_AlsData_t *pAlsData)
00467     {
00468        return VL6180x_AlsPollMeasurement(Device, pAlsData);
00469     }
00470 
00471 /**
00472  * @brief  Get actual ALS measurement
00473  *
00474  * @par Function Description
00475  * Can be called after success status polling or in interrupt mode to retrieve ALS measurement from device \n
00476  * This function doesn't perform any data ready check !
00477  *
00478  * @param pAlsData   Pointer to measurement struct @a VL6180x_AlsData_t
00479  * @return  0 on success
00480  */     
00481     int AlsGetMeasurement(VL6180x_AlsData_t *pAlsData)
00482     {
00483        return VL6180x_AlsGetMeasurement(Device, pAlsData);
00484     }
00485 
00486 /**
00487  * @brief  Configure ALS interrupts provide to application
00488  *
00489  * @param ConfigGpioInt  Select one (and only one) of : \n
00490  *   @a #CONFIG_GPIO_INTERRUPT_DISABLED \n
00491  *   @a #CONFIG_GPIO_INTERRUPT_LEVEL_LOW \n
00492  *   @a #CONFIG_GPIO_INTERRUPT_LEVEL_HIGH \n
00493  *   @a #CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW \n
00494  *   @a #CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY
00495  * @return               0 on success may return #INVALID_PARAMS for invalid mode
00496  */ 
00497     int AlsConfigInterrupt(uint8_t ConfigGpioInt)
00498     {
00499        return VL6180x_AlsConfigInterrupt(Device, ConfigGpioInt);
00500     }
00501 
00502 /**
00503  * @brief Set ALS integration period
00504  *
00505  * @param period_ms  Integration period in msec. Value in between 50 to 100 msec is recommended\n
00506  * @return           0 on success
00507  */     
00508     int AlsSetIntegrationPeriod(uint16_t period_ms)
00509     {
00510        return VL6180x_AlsSetIntegrationPeriod(Device, period_ms);   
00511     }
00512 
00513 /**
00514  * @brief Set ALS "inter-measurement period"
00515  *
00516  * @par Function Description
00517  * The so call data-sheet "inter measurement period" is actually an extra inter-measurement delay
00518  *
00519  * @param intermeasurement_period_ms Inter measurement time in milli second\n
00520  *        @warning applied value is clipped to 2550 ms\n
00521  * @return           0 on success if value is
00522  */     
00523     int AlsSetInterMeasurementPeriod(uint16_t intermeasurement_period_ms)
00524     {
00525        return VL6180x_AlsSetInterMeasurementPeriod(Device, intermeasurement_period_ms);
00526     }
00527 
00528 /**
00529  * @brief Set ALS analog gain code
00530  *
00531  * @par Function Description
00532  * ALS gain code value programmed in @a SYSALS_ANALOGUE_GAIN .
00533  * @param gain  Gain code see datasheet or AlsGainLookUp for real value. Value is clipped to 7.
00534  * @return  0 on success
00535  */
00536     int AlsSetAnalogueGain(uint8_t gain)
00537     {
00538        return VL6180x_AlsSetAnalogueGain(Device, gain);
00539     }
00540 
00541 /**
00542  * @brief Set thresholds for ALS continuous mode 
00543  * @warning Threshold are raw device value not lux!
00544  *
00545  * @par Function Description
00546  * Basically value programmed in @a SYSALS_THRESH_LOW and @a SYSALS_THRESH_HIGH registers
00547  * @param low   ALS low raw threshold for @a SYSALS_THRESH_LOW
00548  * @param high  ALS high raw threshold for  @a SYSALS_THRESH_HIGH
00549  * @return  0 on success
00550  */     
00551     int AlsSetThresholds(uint16_t lux_threshold_low, uint16_t lux_threshold_high);
00552 
00553 /**
00554  * Read ALS interrupt status
00555  * @param pIntStatus  Pointer to status
00556  * @return            0 on success
00557  */
00558     int AlsGetInterruptStatus(uint8_t *pIntStatus)
00559     {
00560        return VL6180x_AlsGetInterruptStatus(Device, pIntStatus);
00561     }
00562 
00563 /**
00564  * @brief Low level ranging and ALS register static settings (you should call @a VL6180x_Prepare() function instead)
00565  *
00566  * @return 0 on success
00567  */
00568     int StaticInit()
00569     {
00570        return VL6180x_StaticInit(Device);
00571     }
00572 
00573 /**
00574  * @brief Wait for device to be ready (before a new ranging command can be issued by application)
00575  * @param MaxLoop    Max Number of i2c polling loop see @a #msec_2_i2cloop
00576  * @return           0 on success. <0 when fail \n
00577  *                   @ref VL6180x_ErrCode_t::TIME_OUT for time out \n
00578  *                   @ref VL6180x_ErrCode_t::INVALID_PARAMS if MaxLop<1
00579  */     
00580     int RangeWaitDeviceReady(int MaxLoop )
00581     {
00582        return VL6180x_RangeWaitDeviceReady(Device, MaxLoop);
00583     }
00584 
00585 /**
00586  * @brief Program Inter measurement period (used only in continuous mode)
00587  *
00588  * @par Function Description
00589  * When trying to set too long time, it returns #INVALID_PARAMS
00590  *
00591  * @param InterMeasTime_msec Requires inter-measurement time in msec
00592  * @return 0 on success
00593  */     
00594     int RangeSetInterMeasPeriod(uint32_t  InterMeasTime_msec)
00595     {
00596        return VL6180x_RangeSetInterMeasPeriod(Device, InterMeasTime_msec);
00597     }
00598 
00599 /**
00600  * @brief Set device ranging scaling factor
00601  *
00602  * @par Function Description
00603  * The ranging scaling factor is applied on the raw distance measured by the device to increase operating ranging at the price of the precision.
00604  * Changing the scaling factor when device is not in f/w standby state (free running) is not safe.
00605  * It can be source of spurious interrupt, wrongly scaled range etc ...
00606  * @warning __This  function doesns't update high/low threshold and other programmed settings linked to scaling factor__.
00607  *  To ensure proper operation, threshold and scaling changes should be done following this procedure: \n
00608  *  @li Set Group hold  : @a VL6180x_SetGroupParamHold() \n
00609  *  @li Get Threshold @a VL6180x_RangeGetThresholds() \n
00610  *  @li Change scaling : @a VL6180x_UpscaleSetScaling() \n
00611  *  @li Set Threshold : @a VL6180x_RangeSetThresholds() \n
00612  *  @li Unset Group Hold : @a VL6180x_SetGroupParamHold()
00613  *
00614  * @param scaling  Scaling factor to apply (1,2 or 3)
00615  * @return          0 on success when up-scale support is not configured it fail for any
00616  *                  scaling than the one statically configured.
00617  */
00618     int UpscaleSetScaling(uint8_t scaling)
00619     {
00620        return VL6180x_UpscaleSetScaling(Device, scaling);
00621     }
00622 
00623 /**
00624  * @brief Get current ranging scaling factor
00625  *
00626  * @return    The current scaling factor
00627  */             
00628     int UpscaleGetScaling()
00629     {
00630        return VL6180x_UpscaleGetScaling(Device);
00631     }
00632 
00633 /**
00634  * @brief Get the maximal distance for actual scaling
00635  * @par Function Description
00636  * Do not use prior to @a VL6180x_Prepare() or at least @a VL6180x_InitData()
00637  *
00638  * Any range value more than the value returned by this function is to be considered as "no target detected"
00639  * or "no target in detectable range" \n
00640  * @warning The maximal distance depends on the scaling
00641  *
00642  * @return    The maximal range limit for actual mode and scaling
00643  */     
00644     uint16_t GetUpperLimit()
00645     {
00646        return VL6180x_GetUpperLimit(Device);
00647     }
00648 
00649 /**
00650  * @brief Apply low and high ranging thresholds that are considered only in continuous mode
00651  *
00652  * @par Function Description
00653  * This function programs low and high ranging thresholds that are considered in continuous mode : 
00654  * interrupt will be raised only when an object is detected at a distance inside this [low:high] range.  
00655  * The function takes care of applying current scaling factor if any.\n
00656  * To be safe, in continuous operation, thresholds must be changed under "group parameter hold" cover.
00657  * Group hold can be activated/deactivated directly in the function or externally (then set 0)
00658  * using /a VL6180x_SetGroupParamHold() function.
00659  *
00660  * @param low      Low threshold in mm
00661  * @param high     High threshold in mm
00662  * @param SafeHold  Use of group parameters hold to surround threshold programming.
00663  * @return  0 On success
00664  */     
00665     int RangeSetThresholds(uint16_t low, uint16_t high, int SafeHold)
00666     {
00667        return VL6180x_RangeSetThresholds(Device, low, high, SafeHold);
00668     }
00669 
00670 /**
00671  * @brief  Get scaled high and low threshold from device
00672  *
00673  * @par Function Description
00674  * Due to scaling factor, the returned value may be different from what has been programmed first (precision lost).
00675  * For instance VL6180x_RangeSetThresholds(dev,11,22) with scale 3
00676  * will read back 9 ((11/3)x3) and 21 ((22/3)x3).
00677  *
00678  * @param low  scaled low Threshold ptr  can be NULL if not needed
00679  * @param high scaled High Threshold ptr can be NULL if not needed
00680  * @return 0 on success, return value is undefined if both low and high are NULL
00681  * @warning return value is undefined if both low and high are NULL
00682  */
00683     int RangeGetThresholds(uint16_t *low, uint16_t *high)
00684     {
00685        return VL6180x_RangeGetThresholds(Device, low, high);
00686     }
00687 
00688 /**
00689  * @brief Set ranging raw thresholds (scaling not considered so not recommended to use it)
00690  *
00691  * @param low  raw low threshold set to raw register
00692  * @param high raw high threshold set to raw  register
00693  * @return 0 on success
00694  */         
00695     int RangeSetRawThresholds(uint8_t low, uint8_t high)
00696     {
00697        return VL6180x_RangeSetRawThresholds(Device, low, high);
00698     }
00699 
00700 /**
00701  * @brief Set Early Convergence Estimate ratio
00702  * @par Function Description
00703  * For more information on ECE check datasheet
00704  * @warning May return a calibration warning in some use cases
00705  *
00706  * @param FactorM    ECE factor M in M/D
00707  * @param FactorD    ECE factor D in M/D
00708  * @return           0 on success. <0 on error. >0 on warning
00709  */     
00710     int RangeSetEceFactor(uint16_t  FactorM, uint16_t FactorD)
00711     {
00712        return VL6180x_RangeSetEceFactor(Device, FactorM, FactorD);
00713     }
00714 
00715 /**
00716  * @brief Set Early Convergence Estimate state (See #SYSRANGE_RANGE_CHECK_ENABLES register)
00717  * @param enable    State to be set 0=disabled, otherwise enabled
00718  * @return          0 on success
00719  */     
00720     int RangeSetEceState(int enable)
00721     {
00722        return VL6180x_RangeSetEceState(Device, enable);
00723     }
00724 
00725 /**
00726  * @brief Set activation state of the wrap around filter
00727  * @param state New activation state (0=off,  otherwise on)
00728  * @return      0 on success
00729  */         
00730     int FilterSetState(int state)
00731     {
00732        return VL6180x_FilterSetState(Device, state);
00733     }
00734 
00735 /**
00736  * Get activation state of the wrap around filter
00737  * @return     Filter enabled or not, when filter is not supported it always returns 0S
00738  */         
00739     int FilterGetState()
00740     {
00741        return VL6180x_FilterGetState(Device);
00742     }
00743 
00744 /**
00745  * @brief Set activation state of  DMax computation
00746  * @param state New activation state (0=off,  otherwise on)
00747  * @return      0 on success
00748  */     
00749     int DMaxSetState(int state)
00750     {
00751        return VL6180x_DMaxSetState(Device, state);
00752     }
00753 
00754 /**
00755  * Get activation state of DMax computation
00756  * @return     Filter enabled or not, when filter is not supported it always returns 0S
00757  */     
00758     int DMaxGetState()
00759     {
00760        return VL6180x_DMaxGetState(Device);
00761     }
00762 
00763 /**
00764  * @brief Set ranging mode and start/stop measure (use high level functions instead : @a VL6180x_RangeStartSingleShot() or @a VL6180x_RangeStartContinuousMode())
00765  *
00766  * @par Function Description
00767  * When used outside scope of known polling single shot stopped state, \n
00768  * user must ensure the device state is "idle" before to issue a new command.
00769  *
00770  * @param mode  A combination of working mode (#MODE_SINGLESHOT or #MODE_CONTINUOUS) and start/stop condition (#MODE_START_STOP) \n
00771  * @return      0 on success
00772  */     
00773     int RangeSetSystemMode(uint8_t mode)
00774     {
00775        return VL6180x_RangeSetSystemMode(Device, mode);
00776     }
00777 
00778 /** @}  */ 
00779 
00780 /** @defgroup api_ll_range_calibration Ranging calibration functions
00781  *  @brief    Ranging calibration functions
00782  *  @ingroup api_ll
00783  *  @{  
00784  */
00785 /**
00786  * @brief Get part to part calibration offset
00787  *
00788  * @par Function Description
00789  * Should only be used after a successful call to @a VL6180x_InitData to backup device nvm value
00790  *
00791  * @return part to part calibration offset from device
00792  */     
00793     int8_t GetOffsetCalibrationData()
00794     {
00795        return VL6180x_GetOffsetCalibrationData(Device);
00796     }
00797 
00798 /**
00799  * Set or over-write part to part calibration offset
00800  * \sa VL6180x_InitData(), VL6180x_GetOffsetCalibrationData()
00801  * @param offset   Offset
00802  */     
00803     void SetOffsetCalibrationData(int8_t offset)
00804     {
00805        return VL6180x_SetOffsetCalibrationData(Device, offset);
00806     }
00807 
00808 /**
00809  * @brief Set Cross talk compensation rate
00810  *
00811  * @par Function Description
00812  * It programs register @a #SYSRANGE_CROSSTALK_COMPENSATION_RATE
00813  *
00814  * @param Rate Compensation rate (9.7 fix point) see datasheet for details
00815  * @return     0 on success
00816  */     
00817     int SetXTalkCompensationRate(FixPoint97_t Rate)
00818     {
00819        return VL6180x_SetXTalkCompensationRate(Device, Rate);
00820     }
00821 /** @}  */
00822 
00823 /** @defgroup api_ll_als ALS functions
00824  *  @brief    ALS functions
00825  *  @ingroup api_ll
00826  *  @{  
00827  */
00828 
00829 /**
00830  * @brief Wait for device to be ready for new als operation or max pollign loop (time out)
00831  * @param MaxLoop    Max Number of i2c polling loop see @a #msec_2_i2cloop
00832  * @return           0 on success. <0 when @a VL6180x_ErrCode_t::TIME_OUT if timed out
00833  */     
00834     int AlsWaitDeviceReady(int MaxLoop)
00835     {
00836        return VL6180x_AlsWaitDeviceReady(Device, MaxLoop);
00837     }
00838         
00839 /**
00840  * @brief Set ALS system mode and start/stop measure
00841  *
00842  * @warning When used outside after single shot polling, \n
00843  * User must ensure  the device state is ready before issuing a new command (using @a VL6180x_AlsWaitDeviceReady()). \n
00844  * Non respect of this, can cause loss of interrupt or device hanging.
00845  *
00846  * @param mode  A combination of working mode (#MODE_SINGLESHOT or #MODE_CONTINUOUS) and start condition (#MODE_START_STOP) \n
00847  * @return      0 on success
00848  */     
00849     int AlsSetSystemMode(uint8_t mode)
00850     {
00851        return VL6180x_AlsSetSystemMode(Device, mode);
00852     }
00853 
00854 /** @defgroup api_ll_misc Misc functions
00855  *  @brief    Misc functions
00856  *  @ingroup api_ll
00857  *  @{  
00858  */
00859 
00860 /**
00861  * Set Group parameter Hold state
00862  *
00863  * @par Function Description
00864  * Group parameter holds @a #SYSTEM_GROUPED_PARAMETER_HOLD enable safe update (non atomic across multiple measure) by host
00865  * \n The critical register group is composed of: \n
00866  * #SYSTEM_INTERRUPT_CONFIG_GPIO \n
00867  * #SYSRANGE_THRESH_HIGH \n
00868  * #SYSRANGE_THRESH_LOW \n
00869  * #SYSALS_INTEGRATION_PERIOD \n
00870  * #SYSALS_ANALOGUE_GAIN \n
00871  * #SYSALS_THRESH_HIGH \n
00872  * #SYSALS_THRESH_LOW
00873  *
00874  *
00875  * @param Hold  Group parameter Hold state to be set (on/off)
00876  * @return      0 on success
00877  */
00878     int SetGroupParamHold(int Hold)
00879     {
00880        return VL6180x_SetGroupParamHold(Device, Hold);
00881     }       
00882 
00883 /**
00884  * @brief Set new device i2c address
00885  *
00886  * After completion the device will answer to the new address programmed.
00887  *
00888  * @sa AN4478: Using multiple VL6180X's in a single design
00889  * @param NewAddr   The new i2c address (7bit)
00890  * @return          0 on success
00891  */     
00892     int SetI2CAddress(int NewAddr)
00893     {
00894        int status;
00895             
00896        status=VL6180x_SetI2CAddress(Device, NewAddr);
00897        if(!status)
00898           Device->I2cAddr=NewAddr;
00899        return status;
00900     }
00901 
00902 /**
00903  * @brief Fully configure gpio 0/1 pin : polarity and functionality
00904  *
00905  * @param pin          gpio pin 0 or 1
00906  * @param IntFunction  Pin functionality : either #GPIOx_SELECT_OFF or #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT (refer to #SYSTEM_MODE_GPIO1 register definition)
00907  * @param ActiveHigh   Set active high polarity, or active low see @a ::IntrPol_e
00908  * @return             0 on success
00909  */     
00910     int SetupGPIOx(int pin, uint8_t IntFunction, int ActiveHigh)
00911     {
00912        return VL6180x_SetupGPIOx(Device, pin, IntFunction, ActiveHigh);
00913     }
00914 
00915 /**
00916  * @brief Set interrupt pin polarity for the given GPIO
00917  *
00918  * @param pin          Pin 0 or 1
00919  * @param active_high  select active high or low polarity using @ref IntrPol_e
00920  * @return             0 on success
00921  */     
00922     int SetGPIOxPolarity(int pin, int active_high)
00923     {
00924        return VL6180x_SetGPIOxPolarity(Device, pin, active_high);
00925     }
00926 
00927 /**
00928  * Select interrupt functionality for the given GPIO
00929  *
00930  * @par Function Description
00931  * Functionality refer to @a SYSTEM_MODE_GPIO0
00932  *
00933  * @param pin            Pin to configure 0 or 1 (gpio0 or gpio1)\nNote that gpio0 is chip enable at power up !
00934  * @param functionality  Pin functionality : either #GPIOx_SELECT_OFF or #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT (refer to #SYSTEM_MODE_GPIO1 register definition)
00935  * @return              0 on success
00936  */      
00937     int SetGPIOxFunctionality(int pin, uint8_t functionality)
00938     {
00939        return VL6180x_SetGPIOxFunctionality(Device, pin, functionality);
00940     }
00941 
00942 /**
00943  * #brief Disable and turn to Hi-Z gpio output pin
00944  *
00945  * @param pin  The pin number to disable 0 or 1
00946  * @return     0 on success
00947  */ 
00948     int DisableGPIOxOut(int pin)
00949     {
00950        return VL6180x_DisableGPIOxOut(Device, pin);
00951     }
00952 
00953 /** @}  */
00954 
00955 /** @defgroup api_ll_intr Interrupts management functions
00956  *  @brief    Interrupts management functions
00957  *  @ingroup api_ll
00958  *  @{  
00959  */
00960 
00961 /**
00962  * @brief     Get all interrupts cause
00963  *
00964  * @param status Ptr to interrupt status. You can use @a IntrStatus_t::val
00965  * @return 0 on success
00966  */     
00967     int GetInterruptStatus(uint8_t *status)
00968     {
00969        return VL6180x_GetInterruptStatus(Device, status);
00970     }
00971 
00972 /**
00973  * @brief Clear given system interrupt condition
00974  *
00975  * @par Function Description
00976  * Clear given interrupt cause by writing into register #SYSTEM_INTERRUPT_CLEAR register.
00977  * @param dev       The device 
00978  * @param IntClear  Which interrupt source to clear. Use any combinations of #INTERRUPT_CLEAR_RANGING , #INTERRUPT_CLEAR_ALS , #INTERRUPT_CLEAR_ERROR.
00979  * @return  0       On success
00980  */     
00981     int ClearInterrupt(uint8_t IntClear)
00982     {
00983        return VL6180x_ClearInterrupt(Device, IntClear );
00984     }
00985 
00986 /**
00987  * @brief Clear error interrupt
00988  *
00989  * @param dev    The device
00990  * @return  0    On success
00991  */
00992  #define VL6180x_ClearErrorInterrupt(dev) VL6180x_ClearInterrupt(dev, INTERRUPT_CLEAR_ERROR)
00993 
00994 /**
00995  * @brief Clear All interrupt causes (als+range+error)
00996  *
00997  * @param dev    The device
00998  * @return  0    On success
00999  */
01000 #define VL6180x_ClearAllInterrupt(dev) VL6180x_ClearInterrupt(dev, INTERRUPT_CLEAR_ERROR|INTERRUPT_CLEAR_RANGING|INTERRUPT_CLEAR_ALS)
01001     
01002 /** @}  */
01003 
01004 /**
01005  * @brief Get the ALS (light in Lux) level
01006  *
01007  * @par Function Description
01008  * Get the ALS (light in Lux) level 
01009  * @param *piData The pointer to variable to write in the measure in Lux
01010  * @return  0       On success
01011  */             
01012     virtual int GetLight(uint32_t *piData)
01013     {
01014        return VL6180x_AlsGetLux(Device, piData);
01015     }
01016 
01017 /**
01018  * @brief Start the ALS (light) measure in continous mode
01019  *
01020  * @par Function Description
01021  * Start the ALS (light) measure in continous mode
01022  * @return  0       On success
01023  */                     
01024     int AlsStartContinuousMode()
01025     {
01026        return VL6180x_AlsSetSystemMode(Device, MODE_START_STOP|MODE_CONTINUOUS);
01027     }
01028 
01029 /**
01030  * @brief Start the ALS (light) measure in single shot mode
01031  *
01032  * @par Function Description
01033  * Start the ALS (light) measure in single shot mode
01034  * @return  0       On success
01035  */                         
01036     int AlsStartSingleShot()
01037     {
01038        return VL6180x_AlsSetSystemMode(Device, MODE_START_STOP|MODE_SINGLESHOT);
01039     }
01040         
01041  private:       
01042     /* api.h functions */
01043     int VL6180x_WaitDeviceBooted(VL6180xDev_t dev);
01044     int VL6180x_InitData(VL6180xDev_t dev );
01045     int VL6180x_SetupGPIO1(VL6180xDev_t dev, uint8_t IntFunction, int ActiveHigh);
01046     int VL6180x_Prepare(VL6180xDev_t dev);
01047     int VL6180x_RangeStartContinuousMode(VL6180xDev_t dev);
01048     int VL6180x_RangeStartSingleShot(VL6180xDev_t dev);
01049     int VL6180x_RangeSetMaxConvergenceTime(VL6180xDev_t dev, uint8_t  MaxConTime_msec);
01050     int VL6180x_RangePollMeasurement(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
01051     int VL6180x_RangeGetMeasurementIfReady(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
01052     int VL6180x_RangeGetMeasurement(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
01053     int VL6180x_RangeGetResult(VL6180xDev_t dev, int32_t *pRange_mm);
01054     int VL6180x_RangeConfigInterrupt(VL6180xDev_t dev, uint8_t ConfigGpioInt);
01055     int VL6180x_RangeGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus);
01056     int VL6180x_AlsPollMeasurement(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData);
01057     int VL6180x_AlsGetMeasurement(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData);
01058     int VL6180x_AlsConfigInterrupt(VL6180xDev_t dev, uint8_t ConfigGpioInt);
01059     int VL6180x_AlsSetIntegrationPeriod(VL6180xDev_t dev, uint16_t period_ms);
01060     int VL6180x_AlsSetInterMeasurementPeriod(VL6180xDev_t dev,  uint16_t intermeasurement_period_ms);
01061     int VL6180x_AlsSetAnalogueGain(VL6180xDev_t dev, uint8_t gain);
01062     int VL6180x_AlsSetThresholds(VL6180xDev_t dev, uint16_t low, uint16_t high);
01063     int VL6180x_AlsGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus);
01064     int VL6180x_StaticInit(VL6180xDev_t dev);
01065     int VL6180x_RangeWaitDeviceReady(VL6180xDev_t dev, int MaxLoop );
01066     int VL6180x_RangeSetInterMeasPeriod(VL6180xDev_t dev, uint32_t  InterMeasTime_msec);
01067     int VL6180x_UpscaleSetScaling(VL6180xDev_t dev, uint8_t scaling);
01068     int VL6180x_UpscaleGetScaling(VL6180xDev_t dev);
01069     uint16_t VL6180x_GetUpperLimit(VL6180xDev_t dev);
01070     int VL6180x_RangeSetThresholds(VL6180xDev_t dev, uint16_t low, uint16_t high, int SafeHold);
01071     int VL6180x_RangeGetThresholds(VL6180xDev_t dev, uint16_t *low, uint16_t *high);
01072     int VL6180x_RangeSetRawThresholds(VL6180xDev_t dev, uint8_t low, uint8_t high);
01073     int VL6180x_RangeSetEceFactor(VL6180xDev_t dev, uint16_t  FactorM, uint16_t FactorD);
01074     int VL6180x_RangeSetEceState(VL6180xDev_t dev, int enable );
01075     int VL6180x_FilterSetState(VL6180xDev_t dev, int state);
01076     int VL6180x_FilterGetState(VL6180xDev_t dev);
01077     int VL6180x_DMaxSetState(VL6180xDev_t dev, int state);
01078     int VL6180x_DMaxGetState(VL6180xDev_t dev);
01079     int VL6180x_RangeSetSystemMode(VL6180xDev_t dev, uint8_t mode);
01080     int8_t VL6180x_GetOffsetCalibrationData(VL6180xDev_t dev);
01081     void VL6180x_SetOffsetCalibrationData(VL6180xDev_t dev, int8_t offset);
01082     int VL6180x_SetXTalkCompensationRate(VL6180xDev_t dev, FixPoint97_t Rate);
01083     int VL6180x_AlsWaitDeviceReady(VL6180xDev_t dev, int MaxLoop );
01084     int VL6180x_AlsSetSystemMode(VL6180xDev_t dev, uint8_t mode); 
01085     int VL6180x_SetGroupParamHold(VL6180xDev_t dev, int Hold);
01086     int VL6180x_SetI2CAddress(VL6180xDev_t dev, uint8_t NewAddr);
01087     int VL6180x_SetupGPIOx(VL6180xDev_t dev, int pin, uint8_t IntFunction, int ActiveHigh);
01088     int VL6180x_SetGPIOxPolarity(VL6180xDev_t dev, int pin, int active_high);
01089     int VL6180x_SetGPIOxFunctionality(VL6180xDev_t dev, int pin, uint8_t functionality);
01090     int VL6180x_DisableGPIOxOut(VL6180xDev_t dev, int pin);
01091     int VL6180x_GetInterruptStatus(VL6180xDev_t dev, uint8_t *status);
01092     int VL6180x_ClearInterrupt(VL6180xDev_t dev, uint8_t IntClear );
01093         
01094     /*  Other functions defined in api.c */
01095     int VL6180x_RangeStaticInit(VL6180xDev_t dev); 
01096     int VL6180x_UpscaleRegInit(VL6180xDev_t dev);
01097     int VL6180x_UpscaleStaticInit(VL6180xDev_t dev); 
01098     int VL6180x_AlsGetLux(VL6180xDev_t dev, lux_t *pLux);
01099     int _UpscaleInitPatch0(VL6180xDev_t dev); 
01100     int VL6180x_RangeGetDeviceReady(VL6180xDev_t dev, int * Ready);
01101     int VL6180x_RangeSetEarlyConvergenceEestimateThreshold(VL6180xDev_t dev);
01102     int32_t _GetAveTotalTime(VL6180xDev_t dev); 
01103     int32_t _filter_Start(VL6180xDev_t dev, uint16_t m_trueRange_mm, uint16_t m_rawRange_mm, uint32_t m_rtnSignalRate, uint32_t m_rtnAmbientRate, uint16_t errorCode);
01104     int _filter_GetResult(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
01105     int _GetRateResult(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData); 
01106     int _DMax_InitData(VL6180xDev_t dev);
01107         
01108     /* Read function of the ID device */
01109     virtual int ReadID();
01110     
01111     /* Write and read functions from I2C */
01112     int VL6180x_WrByte(VL6180xDev_t dev, uint16_t index, uint8_t data);
01113     int VL6180x_WrWord(VL6180xDev_t dev, uint16_t index, uint16_t data);
01114     int VL6180x_WrDWord(VL6180xDev_t dev, uint16_t index, uint32_t data);
01115     int VL6180x_RdByte(VL6180xDev_t dev, uint16_t index, uint8_t *data);
01116     int VL6180x_RdWord(VL6180xDev_t dev, uint16_t index, uint16_t *data);
01117     int VL6180x_RdDWord(VL6180xDev_t dev, uint16_t index, uint32_t *data);
01118     int VL6180x_UpdateByte(VL6180xDev_t dev, uint16_t index, uint8_t AndData, uint8_t OrData);
01119     int VL6180x_I2CWrite(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t *pBuffer, uint16_t NumByteToWrite);
01120     int VL6180x_I2CRead(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t *pBuffer, uint16_t NumByteToRead);
01121         
01122         
01123     int IsPresent()
01124     {
01125        int status;
01126             
01127        status=ReadID();
01128        if(status)
01129           VL6180x_ErrLog("Failed to read ID device. Device not present!\n\r");
01130        return status;
01131     }   
01132     int StopRangeMeasurement(OperatingMode operating_mode);
01133     int StopAlsMeasurement(OperatingMode operating_mode);
01134     int GetRangeMeas(OperatingMode operating_mode, MeasureData_t *Data);    
01135     int GetAlsMeas(OperatingMode operating_mode, MeasureData_t *Data);
01136     int GetRangeAlsMeas(MeasureData_t *Data);
01137     int RangeSetLowThreshold(uint16_t threshold);
01138     int RangeSetHighThreshold(uint16_t threshold);
01139     int AlsSetLowThreshold(uint16_t threshold); 
01140     int AlsSetHighThreshold(uint16_t threshold);
01141     int GetRangeError(MeasureData_t *Data, VL6180x_RangeData_t RangeData);
01142     int GetAlsError(MeasureData_t *Data, VL6180x_AlsData_t AlsData);
01143     int RangeMeasPollSingleShot();
01144     int AlsMeasPollSingleShot();        
01145     int RangeMeasPollContinuousMode();  
01146     int AlsMeasPollContinuousMode();
01147     int AlsGetMeasurementIfReady(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData);
01148     int RangeMeasIntContinuousMode(void (*fptr)(void));
01149     int AlsMeasIntContinuousMode(void (*fptr)(void));
01150     int InterleavedMode(void (*fptr)(void));
01151     int StartInterleavedMode();
01152     int AlsGetThresholds(VL6180xDev_t dev, lux_t *low, lux_t *high);
01153 
01154         
01155     /* IO Device */
01156     DevI2C &dev_i2c;
01157     /* Device data */
01158     MyVL6180Dev_t MyDevice;
01159     VL6180xDev_t Device;  
01160 };
01161 
01162 #endif // __VL6180X_CLASS_H