Fabio Brembilla / X_NUCLEO_6180XA1

Dependencies:   X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

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