Librairie adaptée au laboratoire 2
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_6180XA1 by
VL6180X.h
00001 /** 00002 ****************************************************************************** 00003 * @file VL6180X.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>© 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 00039 #ifndef __VL6180X_CLASS_H 00040 #define __VL6180X_CLASS_H 00041 00042 00043 /* Includes ------------------------------------------------------------------*/ 00044 00045 #include "RangeSensor.h" 00046 #include "LightSensor.h" 00047 #include "DevI2C.h" 00048 //#include "vl6180x_api.h" 00049 #include "vl6180x_cfg.h" 00050 #include "vl6180x_def.h" 00051 #include "vl6180x_types.h" 00052 #include "vl6180x_platform.h" 00053 #include "STMPE1600.h" 00054 00055 00056 /* Definitions ---------------------------------------------------------------*/ 00057 00058 /** 00059 * @brief Clear error interrupt 00060 * 00061 * @param dev The device 00062 * @return 0 On success 00063 */ 00064 #define VL6180X_ClearErrorInterrupt(dev) VL6180X_ClearInterrupt(dev, INTERRUPT_CLEAR_ERROR) 00065 00066 /** 00067 * @brief Clear All interrupt causes (als+range+error) 00068 * 00069 * @param dev The device 00070 * @return 0 On success 00071 */ 00072 #define VL6180X_ClearAllInterrupt(dev) VL6180X_ClearInterrupt(dev, INTERRUPT_CLEAR_ERROR|INTERRUPT_CLEAR_RANGING|INTERRUPT_CLEAR_ALS) 00073 00074 /** 00075 * Default device address 00076 */ 00077 #define DEFAULT_DEVICE_ADDRESS 0x29 00078 00079 /* Types ---------------------------------------------------------------------*/ 00080 00081 /* data struct containing range measure, light measure and type of error provided to the user 00082 in case of invalid data range_mm=0xFFFFFFFF and lux=0xFFFFFFFF */ 00083 typedef struct MeasureData 00084 { 00085 uint32_t range_mm; 00086 uint32_t lux; 00087 uint32_t range_error; 00088 uint32_t als_error; 00089 uint32_t int_error; 00090 } measure_data_t; 00091 00092 /* sensor operating modes */ 00093 typedef enum 00094 { 00095 range_single_shot_polling=1, 00096 als_single_shot_polling, 00097 range_continuous_polling, 00098 als_continuous_polling, 00099 range_continuous_interrupt, 00100 als_continuous_interrupt, 00101 interleaved_mode_interrupt, 00102 range_continuous_polling_low_threshold, 00103 range_continuous_polling_high_threshold, 00104 range_continuous_polling_out_of_window, 00105 als_continuous_polling_low_threshold, 00106 als_continuous_polling_high_threshold, 00107 als_continuous_polling_out_of_window, 00108 range_continuous_interrupt_low_threshold, 00109 range_continuous_interrupt_high_threshold, 00110 range_continuous_interrupt_out_of_window, 00111 als_continuous_interrupt_low_threshold, 00112 als_continuous_interrupt_high_threshold, 00113 als_continuous_interrupt_out_of_window, 00114 range_continuous_als_single_shot, 00115 range_single_shot_als_continuous, 00116 } operating_mode_t; 00117 00118 00119 /* Classes -------------------------------------------------------------------*/ 00120 00121 /** 00122 * Class representing a VL6180X sensor component 00123 */ 00124 class VL6180X : public RangeSensor, public LightSensor 00125 { 00126 public: 00127 /** Constructor 1 (DigitalOut) 00128 * @param[in] &i2c device I2C to be used for communication 00129 * @param[in] &pin Mbed DigitalOut pin to be used as component GPIO_0 CE 00130 * @param[in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT 00131 * @param[in] DevAddr device address, 0x29 by default 00132 */ 00133 VL6180X(DevI2C &i2c, DigitalOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), LightSensor(), _dev_i2c(&i2c), _gpio0(&pin) 00134 { 00135 _my_device.I2cAddr=DevAddr; 00136 _my_device.Present=0; 00137 _my_device.Ready=0; 00138 _device=&_my_device;; 00139 _expgpio0=NULL; 00140 if (pin_gpio1 != NC) { 00141 _gpio1Int = new InterruptIn(pin_gpio1); 00142 } else { 00143 _gpio1Int = NULL; 00144 } 00145 } 00146 /** Constructor 2 (STMPE1600DigiOut) 00147 * @param[in] i2c device I2C to be used for communication 00148 * @param[in] &pin Gpio Expander STMPE1600DigiOut pin to be used as component GPIO_0 CE 00149 * @param[in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT 00150 * @param[in] device address, 0x29 by default 00151 */ 00152 VL6180X(DevI2C &i2c, STMPE1600DigiOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), LightSensor(), _dev_i2c(&i2c), _expgpio0(&pin) 00153 { 00154 _my_device.I2cAddr=DevAddr; 00155 _my_device.Present=0; 00156 _my_device.Ready=0; 00157 _device=&_my_device; 00158 _gpio0=NULL; 00159 if (pin_gpio1 != NC) { 00160 _gpio1Int = new InterruptIn(pin_gpio1); 00161 } else { 00162 _gpio1Int = NULL; 00163 } 00164 } 00165 00166 /** Destructor 00167 */ 00168 virtual ~VL6180X() { 00169 if (_gpio1Int != NULL) { 00170 delete _gpio1Int; 00171 } 00172 } 00173 00174 /* warning: VL6180X class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor. 00175 The warning should request to introduce a virtual destructor to make sure to delete the object */ 00176 00177 /*** Interface Methods ***/ 00178 /*** High level API ***/ 00179 /** 00180 * @brief PowerOn the sensor 00181 * @return void 00182 */ 00183 /* turns on the sensor */ 00184 void on(void) 00185 { 00186 if (_gpio0) { 00187 *_gpio0=1; 00188 } else if(_expgpio0) { 00189 *_expgpio0=1; 00190 } 00191 _my_device.I2cAddr=DEFAULT_DEVICE_ADDRESS; 00192 _my_device.Ready=0; 00193 } 00194 00195 /** 00196 * @brief PowerOff the sensor 00197 * @return void 00198 */ 00199 /* turns off the sensor */ 00200 void off(void) 00201 { 00202 if (_gpio0) { 00203 *_gpio0=0; 00204 } else if(_expgpio0) { 00205 *_expgpio0=0; 00206 } 00207 _my_device.I2cAddr=DEFAULT_DEVICE_ADDRESS; 00208 _my_device.Ready=0; 00209 } 00210 00211 /** 00212 * @brief Start the measure indicated by operating mode 00213 * @param[in] operating_mode specifies requested measure 00214 * @param[in] fptr specifies call back function must be !NULL in case of interrupt measure 00215 * @param[in] low specifies measure low threashold in Lux or in mm according to measure 00216 * @param[in] high specifies measure high threashold in Lux or in mm according to measure 00217 * @return 0 on Success 00218 */ 00219 int start_measurement(operating_mode_t operating_mode, void (*fptr)(void), uint16_t low, uint16_t high); 00220 00221 /** 00222 * @brief Get results for the measure indicated by operating mode 00223 * @param[in] operating_mode specifies requested measure results 00224 * @param[out] Data pointer to the measure_data_t structure to read data in to 00225 * @return 0 on Success 00226 */ 00227 int get_measurement(operating_mode_t operating_mode, measure_data_t *Data); 00228 00229 /** 00230 * @brief Stop the currently running measure indicate by operating_mode 00231 * @param[in] operating_mode specifies requested measure to stop 00232 * @return 0 on Success 00233 */ 00234 int stop_measurement(operating_mode_t operating_mode); 00235 00236 /** 00237 * @brief Interrupt handling func to be called by user after an INT is occourred 00238 * @param[in] opeating_mode indicating the in progress measure 00239 * @param[out] Data pointer to the measure_data_t structure to read data in to 00240 * @return 0 on Success 00241 */ 00242 int handle_irq(operating_mode_t operating_mode, measure_data_t *Data); 00243 00244 /** 00245 * @brief Enable interrupt measure IRQ 00246 * @return 0 on Success 00247 */ 00248 void enable_interrupt_measure_detection_irq(void) 00249 { 00250 if (_gpio1Int != NULL) { 00251 _gpio1Int->enable_irq(); 00252 } 00253 } 00254 00255 /** 00256 * @brief Disable interrupt measure IRQ 00257 * @return 0 on Success 00258 */ 00259 void disable_interrupt_measure_detection_irq(void) 00260 { 00261 if (_gpio1Int != NULL) { 00262 _gpio1Int->disable_irq(); 00263 } 00264 } 00265 /*** End High level API ***/ 00266 00267 /** 00268 * @brief Attach a function to call when an interrupt is detected, i.e. measurement is ready 00269 * @param[in] fptr pointer to call back function to be called whenever an interrupt occours 00270 * @return 0 on Success 00271 */ 00272 void attach_interrupt_measure_detection_irq(void (*fptr)(void)) 00273 { 00274 if (_gpio1Int != NULL) { 00275 _gpio1Int->rise(fptr); 00276 } 00277 } 00278 00279 /** 00280 * @brief Check the sensor presence 00281 * @return 1 when device is present 00282 */ 00283 unsigned present() 00284 { 00285 return _device->Present; 00286 } 00287 00288 /** Wrapper functions */ 00289 /** @defgroup api_init Init functions 00290 * @brief API init functions 00291 * @ingroup api_hl 00292 * @{ 00293 */ 00294 /** 00295 * @brief Wait for device booted after chip enable (hardware standby) 00296 * @par Function Description 00297 * After Chip enable Application you can also simply wait at least 1ms to ensure device is ready 00298 * @warning After device chip enable (_gpio0) de-asserted user must wait gpio1 to get asserted (hardware standby). 00299 * or wait at least 400usec prior to do any low level access or api call . 00300 * 00301 * This function implements polling for standby but you must ensure 400usec from chip enable passed\n 00302 * @warning if device get prepared @a VL6180X_Prepare() re-using these function can hold indefinitely\n 00303 * 00304 * @param void 00305 * @return 0 on success 00306 */ 00307 int wait_device_booted() 00308 { 00309 return VL6180X_WaitDeviceBooted(_device); 00310 } 00311 00312 /** 00313 * 00314 * @brief One time device initialization 00315 * 00316 * To be called once and only once after device is brought out of reset (Chip enable) and booted see @a VL6180X_WaitDeviceBooted() 00317 * 00318 * @par Function Description 00319 * When not used after a fresh device "power up" or reset, it may return @a #CALIBRATION_WARNING 00320 * meaning wrong calibration data may have been fetched from device that can result in ranging offset error\n 00321 * If application cannot execute device reset or need to run VL6180X_InitData multiple time 00322 * then it must ensure proper offset calibration saving and restore on its own 00323 * by using @a VL6180X_GetOffsetCalibrationData() on first power up and then @a VL6180X_SetOffsetCalibrationData() all all subsequent init 00324 * 00325 * @param void 00326 * @return 0 on success, @a #CALIBRATION_WARNING if failed 00327 */ 00328 virtual int init(void * NewAddr) 00329 { 00330 int status; 00331 00332 off(); 00333 on(); 00334 00335 status=VL6180X_WaitDeviceBooted(_device); 00336 if(status) { 00337 VL6180X_ErrLog("WaitDeviceBooted fail\n\r"); 00338 } 00339 status=IsPresent(); 00340 if(!status) { 00341 _device->Present=1; 00342 VL6180X_InitData(_device); 00343 if(status) { 00344 printf("Failed to init VL6180X sensor!\n\r"); 00345 return status; 00346 } 00347 status=prepare(); 00348 if(status) { 00349 printf("Failed to prepare VL6180X!\n\r"); 00350 return status; 00351 } 00352 if(*(uint8_t*)NewAddr!=DEFAULT_DEVICE_ADDRESS) { 00353 status=set_i2c_address(*(uint8_t*)NewAddr); 00354 if(status) { 00355 printf("Failed to change I2C address!\n\r"); 00356 return status; 00357 } 00358 } 00359 _device->Ready=1; 00360 } 00361 return status; 00362 } 00363 00364 /** 00365 * @brief Configure GPIO1 function and set polarity. 00366 * @par Function Description 00367 * To be used prior to arm single shot measure or start continuous mode. 00368 * 00369 * The function uses @a VL6180X_SetupGPIOx() for setting gpio 1. 00370 * @warning changing polarity can generate a spurious interrupt on pins. 00371 * It sets an interrupt flags condition that must be cleared to avoid polling hangs. \n 00372 * It is safe to run VL6180X_ClearAllInterrupt() just after. 00373 * 00374 * @param IntFunction The interrupt functionality to use one of :\n 00375 * @a #GPIOx_SELECT_OFF \n 00376 * @a #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT 00377 * @param ActiveHigh The interrupt line polarity see ::IntrPol_e 00378 * use @a #INTR_POL_LOW (falling edge) or @a #INTR_POL_HIGH (rising edge) 00379 * @return 0 on success 00380 */ 00381 int setup_gpio_1(uint8_t InitFunction, int ActiveHigh) 00382 { 00383 return VL6180X_SetupGPIO1(_device, InitFunction, ActiveHigh); 00384 } 00385 00386 /** 00387 * @brief Prepare device for operation 00388 * @par Function Description 00389 * Does static initialization and reprogram common default settings \n 00390 * _device is prepared for new measure, ready single shot ranging or ALS typical polling operation\n 00391 * After prepare user can : \n 00392 * @li Call other API function to set other settings\n 00393 * @li Configure the interrupt pins, etc... \n 00394 * @li Then start ranging or ALS operations in single shot or continuous mode 00395 * 00396 * @param void 00397 * @return 0 on success 00398 */ 00399 int prepare() 00400 { 00401 return VL6180X_Prepare(_device); 00402 } 00403 00404 /** 00405 * @brief Start continuous ranging mode 00406 * 00407 * @details End user should ensure device is in idle state and not already running 00408 * @return 0 on success 00409 */ 00410 int range_start_continuous_mode() 00411 { 00412 return VL6180X_RangeStartContinuousMode(_device); 00413 } 00414 00415 /** 00416 * @brief Start single shot ranging measure 00417 * 00418 * @details End user should ensure device is in idle state and not already running 00419 * @return 0 on success 00420 */ 00421 int range_start_single_shot() 00422 { 00423 return VL6180X_RangeStartSingleShot(_device); 00424 } 00425 00426 /** 00427 * @brief Set maximum convergence time 00428 * 00429 * @par Function Description 00430 * Setting a low convergence time can impact maximal detectable distance. 00431 * Refer to VL6180X Datasheet Table 7 : Typical range convergence time. 00432 * A typical value for up to x3 scaling is 50 ms 00433 * 00434 * @param MaxConTime_msec 00435 * @return 0 on success. <0 on error. >0 for calibration warning status 00436 */ 00437 int range_set_max_convergence_time(uint8_t MaxConTime_msec) 00438 { 00439 return VL6180X_RangeSetMaxConvergenceTime(_device, MaxConTime_msec); 00440 } 00441 00442 /** 00443 * @brief Single shot Range measurement in polling mode. 00444 * 00445 * @par Function Description 00446 * Kick off a new single shot range then wait for ready to retrieve it by polling interrupt status \n 00447 * Ranging must be prepared by a first call to @a VL6180X_Prepare() and it is safer to clear very first poll call \n 00448 * This function reference VL6180X_PollDelay(dev) porting macro/call on each polling loop, 00449 * but PollDelay(dev) may never be called if measure in ready on first poll loop \n 00450 * Should not be use in continuous mode operation as it will stop it and cause stop/start misbehaviour \n 00451 * \n This function clears Range Interrupt status , but not error one. For that uses @a VL6180X_ClearErrorInterrupt() \n 00452 * This range error is not related VL6180X_RangeData_t::errorStatus that refer measure status \n 00453 * 00454 * @param pRangeData Will be populated with the result ranging data @a VL6180X_RangeData_t 00455 * @return 0 on success , @a #RANGE_ERROR if device reports an error case in it status (not cleared) use 00456 * 00457 * \sa ::VL6180X_RangeData_t 00458 */ 00459 int range_poll_measurement(VL6180X_RangeData_t *pRangeData) 00460 { 00461 return VL6180X_RangePollMeasurement(_device, pRangeData); 00462 } 00463 00464 /** 00465 * @brief Check for measure readiness and get it if ready 00466 * 00467 * @par Function Description 00468 * Using this function is an alternative to @a VL6180X_RangePollMeasurement() to avoid polling operation. This is suitable for applications 00469 * 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 00470 * operation is triggered by a call to @a VL6180X_RangeStartSingleShot(). Then, host CPU regularly calls @a VL6180X_RangeGetMeasurementIfReady() to 00471 * get a distance measure if ready. In case the distance is not ready, host may get it at the next call.\n 00472 * 00473 * @warning 00474 * This function does not re-start a new measurement : this is up to the host CPU to do it.\n 00475 * This function clears Range Interrupt for measure ready , but not error interrupts. For that, uses @a VL6180X_ClearErrorInterrupt() \n 00476 * 00477 * @param pRangeData Will be populated with the result ranging data if available 00478 * @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, 00479 */ 00480 int _range_get_measurement_if_ready(VL6180X_RangeData_t *pRangeData) 00481 { 00482 return VL6180X_RangeGetMeasurementIfReady(_device, pRangeData); 00483 } 00484 00485 /** 00486 * @brief Retrieve range measurements set from device 00487 * 00488 * @par Function Description 00489 * The measurement is made of range_mm status and error code @a VL6180X_RangeData_t \n 00490 * Based on configuration selected extra measures are included. 00491 * 00492 * @warning should not be used in continuous if wrap around filter is active \n 00493 * Does not perform any wait nor check for result availability or validity. 00494 *\sa VL6180X_RangeGetResult for "range only" measurement 00495 * 00496 * @param pRangeData Pointer to the data structure to fill up 00497 * @return 0 on success 00498 */ 00499 int range_get_measurement(VL6180X_RangeData_t *pRangeData) 00500 { 00501 return VL6180X_RangeGetMeasurement(_device, pRangeData); 00502 } 00503 00504 /** 00505 * @brief Get a single distance measure result 00506 * 00507 * @par Function Description 00508 * It can be called after having initialized a component. It start a single 00509 * distance measure in polling mode and wait until the measure is finisched. 00510 * The function block until the measure is finished, it can blocks indefinitely 00511 * in case the measure never ends for any reason \n 00512 * 00513 * @param pi_data Pointer to distance 00514 * @return 0 on success 00515 */ 00516 virtual int get_distance(uint32_t *pi_data) 00517 { 00518 int status=0; 00519 LOG_FUNCTION_START(""); 00520 status=start_measurement(range_single_shot_polling, NULL, NULL, NULL); 00521 if (!status) { 00522 range_wait_device_ready(2000); 00523 for (status=1; status!=0; status=VL6180X_RangeGetResult(_device, pi_data)); 00524 } 00525 stop_measurement(range_single_shot_polling); 00526 range_wait_device_ready(2000); 00527 LOG_FUNCTION_END(status); 00528 00529 return status; 00530 } 00531 00532 /** 00533 * @brief Configure ranging interrupt reported to application 00534 * 00535 * @param ConfigGpioInt Select ranging report\n select one (and only one) of:\n 00536 * @a #CONFIG_GPIO_INTERRUPT_DISABLED \n 00537 * @a #CONFIG_GPIO_INTERRUPT_LEVEL_LOW \n 00538 * @a #CONFIG_GPIO_INTERRUPT_LEVEL_HIGH \n 00539 * @a #CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW \n 00540 * @a #CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY 00541 * @return 0 on success 00542 */ 00543 int range_config_interrupt(uint8_t ConfigGpioInt) 00544 { 00545 return VL6180X_RangeConfigInterrupt(_device, ConfigGpioInt); 00546 } 00547 00548 /** 00549 * @brief Return ranging error interrupt status 00550 * 00551 * @par Function Description 00552 * Appropriate Interrupt report must have been selected first by @a VL6180X_RangeConfigInterrupt() or @a VL6180X_Prepare() \n 00553 * 00554 * Can be used in polling loop to wait for a given ranging event or in interrupt to read the trigger \n 00555 * Events triggers are : \n 00556 * @a #RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD \n 00557 * @a #RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD \n 00558 * @a #RES_INT_STAT_GPIO_OUT_OF_WINDOW \n (RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD|RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD) 00559 * @a #RES_INT_STAT_GPIO_NEW_SAMPLE_READY \n 00560 * 00561 * @sa IntrStatus_t 00562 * @param pIntStatus Pointer to status variable to update 00563 * @return 0 on success 00564 */ 00565 int range_get_interrupt_status(uint8_t *pIntStatus) 00566 { 00567 return VL6180X_RangeGetInterruptStatus(_device, pIntStatus); 00568 } 00569 00570 /** 00571 * @brief Run a single ALS measurement in single shot polling mode 00572 * 00573 * @par Function Description 00574 * Kick off a new single shot ALS then wait new measurement ready to retrieve it ( polling system interrupt status register for als) \n 00575 * ALS must be prepared by a first call to @a VL6180X_Prepare() \n 00576 * \n Should not be used in continuous or interrupt mode it will break it and create hazard in start/stop \n 00577 * 00578 * @param dev The device 00579 * @param pAlsData Als data structure to fill up @a VL6180X_AlsData_t 00580 * @return 0 on success 00581 */ 00582 int als_poll_measurement(VL6180X_AlsData_t *pAlsData) 00583 { 00584 return VL6180X_AlsPollMeasurement(_device, pAlsData); 00585 } 00586 00587 /** 00588 * @brief Get actual ALS measurement 00589 * 00590 * @par Function Description 00591 * Can be called after success status polling or in interrupt mode to retrieve ALS measurement from device \n 00592 * This function doesn't perform any data ready check ! 00593 * 00594 * @param pAlsData Pointer to measurement struct @a VL6180X_AlsData_t 00595 * @return 0 on success 00596 */ 00597 int als_get_measurement(VL6180X_AlsData_t *pAlsData) 00598 { 00599 return VL6180X_AlsGetMeasurement(_device, pAlsData); 00600 } 00601 00602 /** 00603 * @brief Configure ALS interrupts provide to application 00604 * 00605 * @param ConfigGpioInt Select one (and only one) of : \n 00606 * @a #CONFIG_GPIO_INTERRUPT_DISABLED \n 00607 * @a #CONFIG_GPIO_INTERRUPT_LEVEL_LOW \n 00608 * @a #CONFIG_GPIO_INTERRUPT_LEVEL_HIGH \n 00609 * @a #CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW \n 00610 * @a #CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY 00611 * @return 0 on success may return #INVALID_PARAMS for invalid mode 00612 */ 00613 int als_config_interrupt(uint8_t ConfigGpioInt) 00614 { 00615 return VL6180X_AlsConfigInterrupt(_device, ConfigGpioInt); 00616 } 00617 00618 /** 00619 * @brief Set ALS integration period 00620 * 00621 * @param period_ms Integration period in msec. Value in between 50 to 100 msec is recommended\n 00622 * @return 0 on success 00623 */ 00624 int als_set_integration_period(uint16_t period_ms) 00625 { 00626 return VL6180X_AlsSetIntegrationPeriod(_device, period_ms); 00627 } 00628 00629 /** 00630 * @brief Set ALS "inter-measurement period" 00631 * 00632 * @par Function Description 00633 * The so call data-sheet "inter measurement period" is actually an extra inter-measurement delay 00634 * 00635 * @param intermeasurement_period_ms Inter measurement time in milli second\n 00636 * @warning applied value is clipped to 2550 ms\n 00637 * @return 0 on success if value is 00638 */ 00639 int als_set_inter_measurement_period(uint16_t intermeasurement_period_ms) 00640 { 00641 return VL6180X_AlsSetInterMeasurementPeriod(_device, intermeasurement_period_ms); 00642 } 00643 00644 /** 00645 * @brief Set ALS analog gain code 00646 * 00647 * @par Function Description 00648 * ALS gain code value programmed in @a SYSALS_ANALOGUE_GAIN . 00649 * @param gain Gain code see datasheet or AlsGainLookUp for real value. Value is clipped to 7. 00650 * @return 0 on success 00651 */ 00652 int als_set_analogue_gain(uint8_t gain) 00653 { 00654 return VL6180X_AlsSetAnalogueGain(_device, gain); 00655 } 00656 00657 /** 00658 * @brief Set thresholds for ALS continuous mode 00659 * @warning Threshold are raw device value not lux! 00660 * 00661 * @par Function Description 00662 * Basically value programmed in @a SYSALS_THRESH_LOW and @a SYSALS_THRESH_HIGH registers 00663 * @param low ALS low raw threshold for @a SYSALS_THRESH_LOW 00664 * @param high ALS high raw threshold for @a SYSALS_THRESH_HIGH 00665 * @return 0 on success 00666 */ 00667 int als_set_thresholds(uint16_t lux_threshold_low, uint16_t lux_threshold_high); 00668 00669 /** 00670 * Read ALS interrupt status 00671 * @param pIntStatus Pointer to status 00672 * @return 0 on success 00673 */ 00674 int als_get_interrupt_status(uint8_t *pIntStatus) 00675 { 00676 return VL6180X_AlsGetInterruptStatus(_device, pIntStatus); 00677 } 00678 00679 /** 00680 * @brief Low level ranging and ALS register static settings (you should call @a VL6180X_Prepare() function instead) 00681 * 00682 * @return 0 on success 00683 */ 00684 int static_init() 00685 { 00686 return VL6180X_StaticInit(_device); 00687 } 00688 00689 /** 00690 * @brief Wait for device to be ready (before a new ranging command can be issued by application) 00691 * @param MaxLoop Max Number of i2c polling loop see @a #msec_2_i2cloop 00692 * @return 0 on success. <0 when fail \n 00693 * @ref VL6180X_ErrCode_t::TIME_OUT for time out \n 00694 * @ref VL6180X_ErrCode_t::INVALID_PARAMS if MaxLop<1 00695 */ 00696 int range_wait_device_ready(int MaxLoop) 00697 { 00698 return VL6180X_RangeWaitDeviceReady(_device, MaxLoop); 00699 } 00700 00701 /** 00702 * @brief Program Inter measurement period (used only in continuous mode) 00703 * 00704 * @par Function Description 00705 * When trying to set too long time, it returns #INVALID_PARAMS 00706 * 00707 * @param InterMeasTime_msec Requires inter-measurement time in msec 00708 * @return 0 on success 00709 */ 00710 int range_set_inter_meas_period(uint32_t InterMeasTime_msec) 00711 { 00712 return VL6180X_RangeSetInterMeasPeriod(_device, InterMeasTime_msec); 00713 } 00714 00715 /** 00716 * @brief Set device ranging scaling factor 00717 * 00718 * @par Function Description 00719 * The ranging scaling factor is applied on the raw distance measured by the device to increase operating ranging at the price of the precision. 00720 * Changing the scaling factor when device is not in f/w standby state (free running) is not safe. 00721 * It can be source of spurious interrupt, wrongly scaled range etc ... 00722 * @warning __This function doesns't update high/low threshold and other programmed settings linked to scaling factor__. 00723 * To ensure proper operation, threshold and scaling changes should be done following this procedure: \n 00724 * @li Set Group hold : @a VL6180X_SetGroupParamHold() \n 00725 * @li Get Threshold @a VL6180X_RangeGetThresholds() \n 00726 * @li Change scaling : @a VL6180X_UpscaleSetScaling() \n 00727 * @li Set Threshold : @a VL6180X_RangeSetThresholds() \n 00728 * @li Unset Group Hold : @a VL6180X_SetGroupParamHold() 00729 * 00730 * @param scaling Scaling factor to apply (1,2 or 3) 00731 * @return 0 on success when up-scale support is not configured it fail for any 00732 * scaling than the one statically configured. 00733 */ 00734 int upscale_set_scaling(uint8_t scaling) 00735 { 00736 return VL6180X_UpscaleSetScaling(_device, scaling); 00737 } 00738 00739 /** 00740 * @brief Get current ranging scaling factor 00741 * 00742 * @return The current scaling factor 00743 */ 00744 int upscale_get_scaling() 00745 { 00746 return VL6180X_UpscaleGetScaling(_device); 00747 } 00748 00749 /** 00750 * @brief Get the maximal distance for actual scaling 00751 * @par Function Description 00752 * Do not use prior to @a VL6180X_Prepare() or at least @a VL6180X_InitData() 00753 * 00754 * Any range value more than the value returned by this function is to be considered as "no target detected" 00755 * or "no target in detectable range" \n 00756 * @warning The maximal distance depends on the scaling 00757 * 00758 * @return The maximal range limit for actual mode and scaling 00759 */ 00760 uint16_t get_upper_limit() 00761 { 00762 return VL6180X_GetUpperLimit(_device); 00763 } 00764 00765 /** 00766 * @brief Apply low and high ranging thresholds that are considered only in continuous mode 00767 * 00768 * @par Function Description 00769 * This function programs low and high ranging thresholds that are considered in continuous mode : 00770 * interrupt will be raised only when an object is detected at a distance inside this [low:high] range. 00771 * The function takes care of applying current scaling factor if any.\n 00772 * To be safe, in continuous operation, thresholds must be changed under "group parameter hold" cover. 00773 * Group hold can be activated/deactivated directly in the function or externally (then set 0) 00774 * using /a VL6180X_SetGroupParamHold() function. 00775 * 00776 * @param low Low threshold in mm 00777 * @param high High threshold in mm 00778 * @param SafeHold Use of group parameters hold to surround threshold programming. 00779 * @return 0 On success 00780 */ 00781 int range_set_thresholds(uint16_t low, uint16_t high, int SafeHold) 00782 { 00783 return VL6180X_RangeSetThresholds(_device, low, high, SafeHold); 00784 } 00785 00786 /** 00787 * @brief Get scaled high and low threshold from device 00788 * 00789 * @par Function Description 00790 * Due to scaling factor, the returned value may be different from what has been programmed first (precision lost). 00791 * For instance VL6180X_RangeSetThresholds(dev,11,22) with scale 3 00792 * will read back 9 ((11/3)x3) and 21 ((22/3)x3). 00793 * 00794 * @param low scaled low Threshold ptr can be NULL if not needed 00795 * @param high scaled High Threshold ptr can be NULL if not needed 00796 * @return 0 on success, return value is undefined if both low and high are NULL 00797 * @warning return value is undefined if both low and high are NULL 00798 */ 00799 int range_get_thresholds(uint16_t *low, uint16_t *high) 00800 { 00801 return VL6180X_RangeGetThresholds(_device, low, high); 00802 } 00803 00804 /** 00805 * @brief Set ranging raw thresholds (scaling not considered so not recommended to use it) 00806 * 00807 * @param low raw low threshold set to raw register 00808 * @param high raw high threshold set to raw register 00809 * @return 0 on success 00810 */ 00811 int range_set_raw_thresholds(uint8_t low, uint8_t high) 00812 { 00813 return VL6180X_RangeSetRawThresholds(_device, low, high); 00814 } 00815 00816 /** 00817 * @brief Set Early Convergence Estimate ratio 00818 * @par Function Description 00819 * For more information on ECE check datasheet 00820 * @warning May return a calibration warning in some use cases 00821 * 00822 * @param FactorM ECE factor M in M/D 00823 * @param FactorD ECE factor D in M/D 00824 * @return 0 on success. <0 on error. >0 on warning 00825 */ 00826 int range_set_ece_factor(uint16_t FactorM, uint16_t FactorD) 00827 { 00828 return VL6180X_RangeSetEceFactor(_device, FactorM, FactorD); 00829 } 00830 00831 /** 00832 * @brief Set Early Convergence Estimate state (See #SYSRANGE_RANGE_CHECK_ENABLES register) 00833 * @param enable State to be set 0=disabled, otherwise enabled 00834 * @return 0 on success 00835 */ 00836 int range_set_ece_state(int enable) 00837 { 00838 return VL6180X_RangeSetEceState(_device, enable); 00839 } 00840 00841 /** 00842 * @brief Set activation state of the wrap around filter 00843 * @param state New activation state (0=off, otherwise on) 00844 * @return 0 on success 00845 */ 00846 int flter_set_state(int state) 00847 { 00848 return VL6180X_FilterSetState(_device, state); 00849 } 00850 00851 /** 00852 * Get activation state of the wrap around filter 00853 * @return Filter enabled or not, when filter is not supported it always returns 0S 00854 */ 00855 int filter_get_state() 00856 { 00857 return VL6180X_FilterGetState(_device); 00858 } 00859 00860 /** 00861 * @brief Set activation state of DMax computation 00862 * @param state New activation state (0=off, otherwise on) 00863 * @return 0 on success 00864 */ 00865 int d_max_set_state(int state) 00866 { 00867 return VL6180X_DMaxSetState(_device, state); 00868 } 00869 00870 /** 00871 * Get activation state of DMax computation 00872 * @return Filter enabled or not, when filter is not supported it always returns 0S 00873 */ 00874 int d_max_get_state() 00875 { 00876 return VL6180X_DMaxGetState(_device); 00877 } 00878 00879 /** 00880 * @brief Set ranging mode and start/stop measure (use high level functions instead : @a VL6180X_RangeStartSingleShot() or @a VL6180X_RangeStartContinuousMode()) 00881 * 00882 * @par Function Description 00883 * When used outside scope of known polling single shot stopped state, \n 00884 * user must ensure the device state is "idle" before to issue a new command. 00885 * 00886 * @param mode A combination of working mode (#MODE_SINGLESHOT or #MODE_CONTINUOUS) and start/stop condition (#MODE_START_STOP) \n 00887 * @return 0 on success 00888 */ 00889 int range_set_system_mode(uint8_t mode) 00890 { 00891 return VL6180X_RangeSetSystemMode(_device, mode); 00892 } 00893 00894 /** @} */ 00895 00896 /** @defgroup api_ll_range_calibration Ranging calibration functions 00897 * @brief Ranging calibration functions 00898 * @ingroup api_ll 00899 * @{ 00900 */ 00901 /** 00902 * @brief Get part to part calibration offset 00903 * 00904 * @par Function Description 00905 * Should only be used after a successful call to @a VL6180X_InitData to backup device nvm value 00906 * 00907 * @return part to part calibration offset from device 00908 */ 00909 int8_t get_offset_calibration_data() 00910 { 00911 return VL6180X_GetOffsetCalibrationData(_device); 00912 } 00913 00914 /** 00915 * Set or over-write part to part calibration offset 00916 * \sa VL6180X_InitData(), VL6180X_GetOffsetCalibrationData() 00917 * @param offset Offset 00918 */ 00919 void set_offset_calibration_data(int8_t offset) 00920 { 00921 return VL6180X_SetOffsetCalibrationData(_device, offset); 00922 } 00923 00924 /** 00925 * @brief Set Cross talk compensation rate 00926 * 00927 * @par Function Description 00928 * It programs register @a #SYSRANGE_CROSSTALK_COMPENSATION_RATE 00929 * 00930 * @param Rate Compensation rate (9.7 fix point) see datasheet for details 00931 * @return 0 on success 00932 */ 00933 int set_x_talk_compensation_rate(FixPoint97_t Rate) 00934 { 00935 return VL6180X_SetXTalkCompensationRate(_device, Rate); 00936 } 00937 /** @} */ 00938 00939 /** @defgroup api_ll_als ALS functions 00940 * @brief ALS functions 00941 * @ingroup api_ll 00942 * @{ 00943 */ 00944 00945 /** 00946 * @brief Wait for device to be ready for new als operation or max pollign loop (time out) 00947 * @param MaxLoop Max Number of i2c polling loop see @a #msec_2_i2cloop 00948 * @return 0 on success. <0 when @a VL6180X_ErrCode_t::TIME_OUT if timed out 00949 */ 00950 int als_wait_device_ready(int MaxLoop) 00951 { 00952 return VL6180X_AlsWaitDeviceReady(_device, MaxLoop); 00953 } 00954 00955 /** 00956 * @brief Set ALS system mode and start/stop measure 00957 * 00958 * @warning When used outside after single shot polling, \n 00959 * User must ensure the device state is ready before issuing a new command (using @a VL6180X_AlsWaitDeviceReady()). \n 00960 * Non respect of this, can cause loss of interrupt or device hanging. 00961 * 00962 * @param mode A combination of working mode (#MODE_SINGLESHOT or #MODE_CONTINUOUS) and start condition (#MODE_START_STOP) \n 00963 * @return 0 on success 00964 */ 00965 int als_set_system_mode(uint8_t mode) 00966 { 00967 return VL6180X_AlsSetSystemMode(_device, mode); 00968 } 00969 00970 /** @defgroup api_ll_misc Misc functions 00971 * @brief Misc functions 00972 * @ingroup api_ll 00973 * @{ 00974 */ 00975 00976 /** 00977 * Set Group parameter Hold state 00978 * 00979 * @par Function Description 00980 * Group parameter holds @a #SYSTEM_GROUPED_PARAMETER_HOLD enable safe update (non atomic across multiple measure) by host 00981 * \n The critical register group is composed of: \n 00982 * #SYSTEM_INTERRUPT_CONFIG_GPIO \n 00983 * #SYSRANGE_THRESH_HIGH \n 00984 * #SYSRANGE_THRESH_LOW \n 00985 * #SYSALS_INTEGRATION_PERIOD \n 00986 * #SYSALS_ANALOGUE_GAIN \n 00987 * #SYSALS_THRESH_HIGH \n 00988 * #SYSALS_THRESH_LOW 00989 * 00990 * 00991 * @param Hold Group parameter Hold state to be set (on/off) 00992 * @return 0 on success 00993 */ 00994 int set_group_param_hold(int Hold) 00995 { 00996 return VL6180X_SetGroupParamHold(_device, Hold); 00997 } 00998 00999 /** 01000 * @brief Set new device i2c address 01001 * 01002 * After completion the device will answer to the new address programmed. 01003 * 01004 * @sa AN4478: Using multiple VL6180X's in a single design 01005 * @param NewAddr The new i2c address (7bit) 01006 * @return 0 on success 01007 */ 01008 int set_i2c_address(int NewAddr) 01009 { 01010 int status; 01011 01012 status=VL6180X_SetI2CAddress(_device, NewAddr); 01013 if (!status) { 01014 _device->I2cAddr=NewAddr; 01015 } 01016 return status; 01017 } 01018 01019 /** 01020 * @brief Fully configure gpio 0/1 pin : polarity and functionality 01021 * 01022 * @param pin gpio pin 0 or 1 01023 * @param IntFunction Pin functionality : either #GPIOx_SELECT_OFF or #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT (refer to #SYSTEM_MODE_GPIO1 register definition) 01024 * @param ActiveHigh Set active high polarity, or active low see @a ::IntrPol_e 01025 * @return 0 on success 01026 */ 01027 int setup_gpio_x(int pin, uint8_t IntFunction, int ActiveHigh) 01028 { 01029 return VL6180X_SetupGPIOx(_device, pin, IntFunction, ActiveHigh); 01030 } 01031 01032 /** 01033 * @brief Set interrupt pin polarity for the given GPIO 01034 * 01035 * @param pin Pin 0 or 1 01036 * @param active_high select active high or low polarity using @ref IntrPol_e 01037 * @return 0 on success 01038 */ 01039 int set_gpio_x_polarity(int pin, int active_high) 01040 { 01041 return VL6180X_SetGPIOxPolarity(_device, pin, active_high); 01042 } 01043 01044 /** 01045 * Select interrupt functionality for the given GPIO 01046 * 01047 * @par Function Description 01048 * Functionality refer to @a SYSTEM_MODE_GPIO0 01049 * 01050 * @param pin Pin to configure 0 or 1 (_gpio0 or gpio1)\nNote that _gpio0 is chip enable at power up ! 01051 * @param functionality Pin functionality : either #GPIOx_SELECT_OFF or #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT (refer to #SYSTEM_MODE_GPIO1 register definition) 01052 * @return 0 on success 01053 */ 01054 int set_gpio_x_functionality(int pin, uint8_t functionality) 01055 { 01056 return VL6180X_SetGPIOxFunctionality(_device, pin, functionality); 01057 } 01058 01059 /** 01060 * #brief Disable and turn to Hi-Z gpio output pin 01061 * 01062 * @param pin The pin number to disable 0 or 1 01063 * @return 0 on success 01064 */ 01065 int disable_gpio_x_out(int pin) 01066 { 01067 return VL6180X_DisableGPIOxOut(_device, pin); 01068 } 01069 01070 /** @} */ 01071 01072 /** @defgroup api_ll_intr Interrupts management functions 01073 * @brief Interrupts management functions 01074 * @ingroup api_ll 01075 * @{ 01076 */ 01077 01078 /** 01079 * @brief Get all interrupts cause 01080 * 01081 * @param status Ptr to interrupt status. You can use @a IntrStatus_t::val 01082 * @return 0 on success 01083 */ 01084 int get_interrupt_status(uint8_t *status) 01085 { 01086 return VL6180X_GetInterruptStatus(_device, status); 01087 } 01088 01089 /** 01090 * @brief Clear given system interrupt condition 01091 * 01092 * @par Function Description 01093 * Clear given interrupt cause by writing into register #SYSTEM_INTERRUPT_CLEAR register. 01094 * @param dev The device 01095 * @param IntClear Which interrupt source to clear. Use any combinations of #INTERRUPT_CLEAR_RANGING , #INTERRUPT_CLEAR_ALS , #INTERRUPT_CLEAR_ERROR. 01096 * @return 0 On success 01097 */ 01098 int clear_interrupt(uint8_t IntClear) 01099 { 01100 return VL6180X_ClearInterrupt(_device, IntClear ); 01101 } 01102 01103 /** @} */ 01104 01105 /** 01106 * @brief Get a single light (in Lux) measure result 01107 * 01108 * @par Function Description 01109 * It can be called after having initialized a component. It start a single 01110 * light measure in polling mode and wait until the measure is finisched. 01111 * The function block until the measure is finished, it can blocks indefinitely 01112 * in case the measure never ends for any reason \n 01113 */ 01114 virtual int get_lux(uint32_t *pi_data) 01115 { 01116 int status=0; 01117 LOG_FUNCTION_START(""); 01118 status = start_measurement(als_single_shot_polling, NULL, NULL, NULL); 01119 if (!status) { 01120 als_wait_device_ready(2000); 01121 for (status=1; status!=0; status=VL6180X_AlsGetLux(_device, pi_data)); 01122 } 01123 stop_measurement(als_single_shot_polling); 01124 als_wait_device_ready(2000); 01125 LOG_FUNCTION_END(status); 01126 01127 return status; 01128 } 01129 01130 /** 01131 * @brief Start the ALS (light) measure in continous mode 01132 * 01133 * @par Function Description 01134 * Start the ALS (light) measure in continous mode 01135 * @return 0 On success 01136 */ 01137 int als_start_continuous_mode() 01138 { 01139 return VL6180X_AlsSetSystemMode(_device, MODE_START_STOP|MODE_CONTINUOUS); 01140 } 01141 01142 /** 01143 * @brief Start the ALS (light) measure in single shot mode 01144 * 01145 * @par Function Description 01146 * Start the ALS (light) measure in single shot mode 01147 * @return 0 On success 01148 */ 01149 int als_start_single_shot() 01150 { 01151 return VL6180X_AlsSetSystemMode(_device, MODE_START_STOP|MODE_SINGLESHOT); 01152 } 01153 01154 private: 01155 /* api.h functions */ 01156 int VL6180X_WaitDeviceBooted(VL6180XDev_t dev); 01157 int VL6180X_InitData(VL6180XDev_t dev ); 01158 int VL6180X_SetupGPIO1(VL6180XDev_t dev, uint8_t IntFunction, int ActiveHigh); 01159 int VL6180X_Prepare(VL6180XDev_t dev); 01160 int VL6180X_RangeStartContinuousMode(VL6180XDev_t dev); 01161 int VL6180X_RangeStartSingleShot(VL6180XDev_t dev); 01162 int VL6180X_RangeSetMaxConvergenceTime(VL6180XDev_t dev, uint8_t MaxConTime_msec); 01163 int VL6180X_RangePollMeasurement(VL6180XDev_t dev, VL6180X_RangeData_t *pRangeData); 01164 int VL6180X_RangeGetMeasurementIfReady(VL6180XDev_t dev, VL6180X_RangeData_t *pRangeData); 01165 int VL6180X_RangeGetMeasurement(VL6180XDev_t dev, VL6180X_RangeData_t *pRangeData); 01166 int VL6180X_RangeGetResult(VL6180XDev_t dev, uint32_t *pRange_mm); 01167 int VL6180X_RangeConfigInterrupt(VL6180XDev_t dev, uint8_t ConfigGpioInt); 01168 int VL6180X_RangeGetInterruptStatus(VL6180XDev_t dev, uint8_t *pIntStatus); 01169 int VL6180X_AlsPollMeasurement(VL6180XDev_t dev, VL6180X_AlsData_t *pAlsData); 01170 int VL6180X_AlsGetMeasurement(VL6180XDev_t dev, VL6180X_AlsData_t *pAlsData); 01171 int VL6180X_AlsConfigInterrupt(VL6180XDev_t dev, uint8_t ConfigGpioInt); 01172 int VL6180X_AlsSetIntegrationPeriod(VL6180XDev_t dev, uint16_t period_ms); 01173 int VL6180X_AlsSetInterMeasurementPeriod(VL6180XDev_t dev, uint16_t intermeasurement_period_ms); 01174 int VL6180X_AlsSetAnalogueGain(VL6180XDev_t dev, uint8_t gain); 01175 int VL6180X_AlsSetThresholds(VL6180XDev_t dev, uint16_t low, uint16_t high); 01176 int VL6180X_AlsGetInterruptStatus(VL6180XDev_t dev, uint8_t *pIntStatus); 01177 int VL6180X_StaticInit(VL6180XDev_t dev); 01178 int VL6180X_RangeWaitDeviceReady(VL6180XDev_t dev, int MaxLoop ); 01179 int VL6180X_RangeSetInterMeasPeriod(VL6180XDev_t dev, uint32_t InterMeasTime_msec); 01180 int VL6180X_UpscaleSetScaling(VL6180XDev_t dev, uint8_t scaling); 01181 int VL6180X_UpscaleGetScaling(VL6180XDev_t dev); 01182 uint16_t VL6180X_GetUpperLimit(VL6180XDev_t dev); 01183 int VL6180X_RangeSetThresholds(VL6180XDev_t dev, uint16_t low, uint16_t high, int SafeHold); 01184 int VL6180X_RangeGetThresholds(VL6180XDev_t dev, uint16_t *low, uint16_t *high); 01185 int VL6180X_RangeSetRawThresholds(VL6180XDev_t dev, uint8_t low, uint8_t high); 01186 int VL6180X_RangeSetEceFactor(VL6180XDev_t dev, uint16_t FactorM, uint16_t FactorD); 01187 int VL6180X_RangeSetEceState(VL6180XDev_t dev, int enable ); 01188 int VL6180X_FilterSetState(VL6180XDev_t dev, int state); 01189 int VL6180X_FilterGetState(VL6180XDev_t dev); 01190 int VL6180X_DMaxSetState(VL6180XDev_t dev, int state); 01191 int VL6180X_DMaxGetState(VL6180XDev_t dev); 01192 int VL6180X_RangeSetSystemMode(VL6180XDev_t dev, uint8_t mode); 01193 int8_t VL6180X_GetOffsetCalibrationData(VL6180XDev_t dev); 01194 void VL6180X_SetOffsetCalibrationData(VL6180XDev_t dev, int8_t offset); 01195 int VL6180X_SetXTalkCompensationRate(VL6180XDev_t dev, FixPoint97_t Rate); 01196 int VL6180X_AlsWaitDeviceReady(VL6180XDev_t dev, int MaxLoop ); 01197 int VL6180X_AlsSetSystemMode(VL6180XDev_t dev, uint8_t mode); 01198 int VL6180X_SetGroupParamHold(VL6180XDev_t dev, int Hold); 01199 int VL6180X_SetI2CAddress(VL6180XDev_t dev, uint8_t NewAddr); 01200 int VL6180X_SetupGPIOx(VL6180XDev_t dev, int pin, uint8_t IntFunction, int ActiveHigh); 01201 int VL6180X_SetGPIOxPolarity(VL6180XDev_t dev, int pin, int active_high); 01202 int VL6180X_SetGPIOxFunctionality(VL6180XDev_t dev, int pin, uint8_t functionality); 01203 int VL6180X_DisableGPIOxOut(VL6180XDev_t dev, int pin); 01204 int VL6180X_GetInterruptStatus(VL6180XDev_t dev, uint8_t *status); 01205 int VL6180X_ClearInterrupt(VL6180XDev_t dev, uint8_t IntClear ); 01206 01207 /* Other functions defined in api.c */ 01208 int VL6180X_RangeStaticInit(VL6180XDev_t dev); 01209 int VL6180X_UpscaleRegInit(VL6180XDev_t dev); 01210 int VL6180X_UpscaleStaticInit(VL6180XDev_t dev); 01211 int VL6180X_AlsGetLux(VL6180XDev_t dev, lux_t *pLux); 01212 int _UpscaleInitPatch0(VL6180XDev_t dev); 01213 int VL6180X_RangeGetDeviceReady(VL6180XDev_t dev, int * Ready); 01214 int VL6180X_RangeSetEarlyConvergenceEestimateThreshold(VL6180XDev_t dev); 01215 int32_t _GetAveTotalTime(VL6180XDev_t dev); 01216 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); 01217 int _filter_GetResult(VL6180XDev_t dev, VL6180X_RangeData_t *pRangeData); 01218 int _GetRateResult(VL6180XDev_t dev, VL6180X_RangeData_t *pRangeData); 01219 int _DMax_InitData(VL6180XDev_t dev); 01220 01221 /* Read function of the ID device */ 01222 virtual int read_id(uint8_t *id); 01223 01224 /* Write and read functions from I2C */ 01225 int VL6180X_WrByte(VL6180XDev_t dev, uint16_t index, uint8_t data); 01226 int VL6180X_WrWord(VL6180XDev_t dev, uint16_t index, uint16_t data); 01227 int VL6180X_WrDWord(VL6180XDev_t dev, uint16_t index, uint32_t data); 01228 int VL6180X_RdByte(VL6180XDev_t dev, uint16_t index, uint8_t *data); 01229 int VL6180X_RdWord(VL6180XDev_t dev, uint16_t index, uint16_t *data); 01230 int VL6180X_RdDWord(VL6180XDev_t dev, uint16_t index, uint32_t *data); 01231 int VL6180X_UpdateByte(VL6180XDev_t dev, uint16_t index, uint8_t AndData, uint8_t OrData); 01232 int VL6180X_I2CWrite(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t *pBuffer, uint16_t NumByteToWrite); 01233 int VL6180X_I2CRead(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t *pBuffer, uint16_t NumByteToRead); 01234 01235 int IsPresent(); 01236 int StopRangeMeasurement(operating_mode_t operating_mode); 01237 int StopAlsMeasurement(operating_mode_t operating_mode); 01238 int GetRangeMeas(operating_mode_t operating_mode, measure_data_t *Data); 01239 int GetAlsMeas(operating_mode_t operating_mode, measure_data_t *Data); 01240 int GetRangeAlsMeas(measure_data_t *Data); 01241 int RangeSetLowThreshold(uint16_t threshold); 01242 int RangeSetHighThreshold(uint16_t threshold); 01243 int AlsSetLowThreshold(uint16_t threshold); 01244 int AlsSetHighThreshold(uint16_t threshold); 01245 int GetRangeError(measure_data_t *Data, VL6180X_RangeData_t RangeData); 01246 int GetAlsError(measure_data_t *Data, VL6180X_AlsData_t AlsData); 01247 int RangeMeasPollSingleShot(); 01248 int AlsMeasPollSingleShot(); 01249 int RangeMeasPollContinuousMode(); 01250 int AlsMeasPollContinuousMode(); 01251 int AlsGetMeasurementIfReady(VL6180XDev_t dev, VL6180X_AlsData_t *pAlsData); 01252 int RangeMeasIntContinuousMode(void (*fptr)(void)); 01253 int AlsMeasIntContinuousMode(void (*fptr)(void)); 01254 int InterleavedMode(void (*fptr)(void)); 01255 int StartInterleavedMode(); 01256 int AlsGetThresholds(VL6180XDev_t dev, lux_t *low, lux_t *high); 01257 01258 /* IO _device */ 01259 DevI2C *_dev_i2c; 01260 /* Digital out pin */ 01261 DigitalOut *_gpio0; 01262 /* GPIO expander */ 01263 STMPE1600DigiOut *_expgpio0; 01264 /* Measure detection IRQ */ 01265 InterruptIn *_gpio1Int; 01266 /* _device data */ 01267 MyVL6180Dev_t _my_device; 01268 VL6180XDev_t _device; 01269 }; 01270 01271 #endif // __VL6180X_CLASS_H
Generated on Fri Jul 15 2022 16:10:34 by 1.7.2