Line Health / VL6180
Committer:
mwilkens241
Date:
Thu Mar 09 18:43:54 2017 +0000
Revision:
0:15e49005d54e
Child:
1:af4be6eecff0
working vl6180x library based off x_nucleo library; lacks proper wake detection...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mwilkens241 0:15e49005d54e 1 /**
mwilkens241 0:15e49005d54e 2 ******************************************************************************
mwilkens241 0:15e49005d54e 3 * @file vl6180x_class.h
mwilkens241 0:15e49005d54e 4 * @author AST / EST
mwilkens241 0:15e49005d54e 5 * @version V0.0.1
mwilkens241 0:15e49005d54e 6 * @date 9-November-2015
mwilkens241 0:15e49005d54e 7 * @brief Header file for component VL6180X
mwilkens241 0:15e49005d54e 8 ******************************************************************************
mwilkens241 0:15e49005d54e 9 * @attention
mwilkens241 0:15e49005d54e 10 *
mwilkens241 0:15e49005d54e 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mwilkens241 0:15e49005d54e 12 *
mwilkens241 0:15e49005d54e 13 * Redistribution and use in source and binary forms, with or without modification,
mwilkens241 0:15e49005d54e 14 * are permitted provided that the following conditions are met:
mwilkens241 0:15e49005d54e 15 * 1. Redistributions of source code must retain the above copyright notice,
mwilkens241 0:15e49005d54e 16 * this list of conditions and the following disclaimer.
mwilkens241 0:15e49005d54e 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
mwilkens241 0:15e49005d54e 18 * this list of conditions and the following disclaimer in the documentation
mwilkens241 0:15e49005d54e 19 * and/or other materials provided with the distribution.
mwilkens241 0:15e49005d54e 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mwilkens241 0:15e49005d54e 21 * may be used to endorse or promote products derived from this software
mwilkens241 0:15e49005d54e 22 * without specific prior written permission.
mwilkens241 0:15e49005d54e 23 *
mwilkens241 0:15e49005d54e 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mwilkens241 0:15e49005d54e 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mwilkens241 0:15e49005d54e 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mwilkens241 0:15e49005d54e 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mwilkens241 0:15e49005d54e 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mwilkens241 0:15e49005d54e 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mwilkens241 0:15e49005d54e 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mwilkens241 0:15e49005d54e 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mwilkens241 0:15e49005d54e 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mwilkens241 0:15e49005d54e 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mwilkens241 0:15e49005d54e 34 *
mwilkens241 0:15e49005d54e 35 ******************************************************************************
mwilkens241 0:15e49005d54e 36 */
mwilkens241 0:15e49005d54e 37
mwilkens241 0:15e49005d54e 38 #ifndef __VL6180X_CLASS_H
mwilkens241 0:15e49005d54e 39 #define __VL6180X_CLASS_H
mwilkens241 0:15e49005d54e 40
mwilkens241 0:15e49005d54e 41 /* Includes ------------------------------------------------------------------*/
mwilkens241 0:15e49005d54e 42 #include "DevI2C.h"
mwilkens241 0:15e49005d54e 43 //#include "vl6180x_api.h"
mwilkens241 0:15e49005d54e 44 #include "vl6180x_cfg.h"
mwilkens241 0:15e49005d54e 45 #include "vl6180x_def.h"
mwilkens241 0:15e49005d54e 46 #include "vl6180x_types.h"
mwilkens241 0:15e49005d54e 47 #include "vl6180x_platform.h"
mwilkens241 0:15e49005d54e 48
mwilkens241 0:15e49005d54e 49
mwilkens241 0:15e49005d54e 50 /* data struct containing range measure, light measure and type of error provided to the user
mwilkens241 0:15e49005d54e 51 in case of invalid data range_mm=0xFFFFFFFF and lux=0xFFFFFFFF */
mwilkens241 0:15e49005d54e 52 typedef struct MeasureData
mwilkens241 0:15e49005d54e 53 {
mwilkens241 0:15e49005d54e 54 uint32_t range_mm;
mwilkens241 0:15e49005d54e 55 uint32_t lux;
mwilkens241 0:15e49005d54e 56 uint32_t range_error;
mwilkens241 0:15e49005d54e 57 uint32_t als_error;
mwilkens241 0:15e49005d54e 58 uint32_t int_error;
mwilkens241 0:15e49005d54e 59 }MeasureData_t;
mwilkens241 0:15e49005d54e 60
mwilkens241 0:15e49005d54e 61 /* sensor operating modes */
mwilkens241 0:15e49005d54e 62 typedef enum
mwilkens241 0:15e49005d54e 63 {
mwilkens241 0:15e49005d54e 64 range_single_shot_polling=1,
mwilkens241 0:15e49005d54e 65 als_single_shot_polling,
mwilkens241 0:15e49005d54e 66 range_continuous_polling,
mwilkens241 0:15e49005d54e 67 als_continuous_polling,
mwilkens241 0:15e49005d54e 68 range_continuous_interrupt,
mwilkens241 0:15e49005d54e 69 als_continuous_interrupt,
mwilkens241 0:15e49005d54e 70 interleaved_mode_interrupt,
mwilkens241 0:15e49005d54e 71 range_continuous_polling_low_threshold,
mwilkens241 0:15e49005d54e 72 range_continuous_polling_high_threshold,
mwilkens241 0:15e49005d54e 73 range_continuous_polling_out_of_window,
mwilkens241 0:15e49005d54e 74 als_continuous_polling_low_threshold,
mwilkens241 0:15e49005d54e 75 als_continuous_polling_high_threshold,
mwilkens241 0:15e49005d54e 76 als_continuous_polling_out_of_window,
mwilkens241 0:15e49005d54e 77 range_continuous_interrupt_low_threshold,
mwilkens241 0:15e49005d54e 78 range_continuous_interrupt_high_threshold,
mwilkens241 0:15e49005d54e 79 range_continuous_interrupt_out_of_window,
mwilkens241 0:15e49005d54e 80 als_continuous_interrupt_low_threshold,
mwilkens241 0:15e49005d54e 81 als_continuous_interrupt_high_threshold,
mwilkens241 0:15e49005d54e 82 als_continuous_interrupt_out_of_window,
mwilkens241 0:15e49005d54e 83 range_continuous_als_single_shot,
mwilkens241 0:15e49005d54e 84 range_single_shot_als_continuous,
mwilkens241 0:15e49005d54e 85 }OperatingMode;
mwilkens241 0:15e49005d54e 86
mwilkens241 0:15e49005d54e 87 /** default device address */
mwilkens241 0:15e49005d54e 88 #define DEFAULT_DEVICE_ADDRESS (0x29)
mwilkens241 0:15e49005d54e 89
mwilkens241 0:15e49005d54e 90 /* Classes -------------------------------------------------------------------*/
mwilkens241 0:15e49005d54e 91 /** Class representing a VL6180X sensor component
mwilkens241 0:15e49005d54e 92 */
mwilkens241 0:15e49005d54e 93 class VL6180X
mwilkens241 0:15e49005d54e 94 {
mwilkens241 0:15e49005d54e 95 public:
mwilkens241 0:15e49005d54e 96 /** Constructor 1 (DigitalOut)
mwilkens241 0:15e49005d54e 97 * @param[in] &i2c device I2C to be used for communication
mwilkens241 0:15e49005d54e 98 * @param[in] &pin Mbed DigitalOut pin to be used as component GPIO_0 CE
mwilkens241 0:15e49005d54e 99 * @param[in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
mwilkens241 0:15e49005d54e 100 * @param[in] DevAddr device address, 0x29 by default
mwilkens241 0:15e49005d54e 101 */
mwilkens241 0:15e49005d54e 102 VL6180X(DevI2C &i2c, DigitalOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : dev_i2c(i2c), gpio0(&pin)
mwilkens241 0:15e49005d54e 103 {
mwilkens241 0:15e49005d54e 104
mwilkens241 0:15e49005d54e 105 MyDevice.I2cAddr=DevAddr;
mwilkens241 0:15e49005d54e 106 MyDevice.Present=0;
mwilkens241 0:15e49005d54e 107 MyDevice.Ready=0;
mwilkens241 0:15e49005d54e 108 Device=&MyDevice;;
mwilkens241 0:15e49005d54e 109 if (pin_gpio1 != NC) { gpio1Int = new InterruptIn(pin_gpio1); }
mwilkens241 0:15e49005d54e 110 else { gpio1Int = NULL; }
mwilkens241 0:15e49005d54e 111 }
mwilkens241 0:15e49005d54e 112 /** Constructor 2 (STMPE1600DigiOut)
mwilkens241 0:15e49005d54e 113 * @param[in] i2c device I2C to be used for communication
mwilkens241 0:15e49005d54e 114 * @param[in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
mwilkens241 0:15e49005d54e 115 * @param[in] device address, 0x29 by default
mwilkens241 0:15e49005d54e 116 */
mwilkens241 0:15e49005d54e 117 VL6180X(DevI2C &i2c, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : dev_i2c(i2c)
mwilkens241 0:15e49005d54e 118 {
mwilkens241 0:15e49005d54e 119 MyDevice.I2cAddr=DevAddr;
mwilkens241 0:15e49005d54e 120 MyDevice.Present=0;
mwilkens241 0:15e49005d54e 121 MyDevice.Ready=0;
mwilkens241 0:15e49005d54e 122 Device=&MyDevice;
mwilkens241 0:15e49005d54e 123 gpio0=NULL;
mwilkens241 0:15e49005d54e 124 if (pin_gpio1 != NC) { gpio1Int = new InterruptIn(pin_gpio1); }
mwilkens241 0:15e49005d54e 125 else { gpio1Int = NULL; }
mwilkens241 0:15e49005d54e 126 }
mwilkens241 0:15e49005d54e 127
mwilkens241 0:15e49005d54e 128 /** Destructor
mwilkens241 0:15e49005d54e 129 */
mwilkens241 0:15e49005d54e 130 virtual ~VL6180X(){
mwilkens241 0:15e49005d54e 131 if (gpio1Int != NULL) delete gpio1Int;
mwilkens241 0:15e49005d54e 132 }
mwilkens241 0:15e49005d54e 133
mwilkens241 0:15e49005d54e 134 /* warning: VL6180X class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor.
mwilkens241 0:15e49005d54e 135 The warning should request to introduce a virtual destructor to make sure to delete the object */
mwilkens241 0:15e49005d54e 136
mwilkens241 0:15e49005d54e 137 /*** Interface Methods ***/
mwilkens241 0:15e49005d54e 138 /*** High level API ***/
mwilkens241 0:15e49005d54e 139 /**
mwilkens241 0:15e49005d54e 140 * @brief PowerOn the sensor
mwilkens241 0:15e49005d54e 141 * @return void
mwilkens241 0:15e49005d54e 142 */
mwilkens241 0:15e49005d54e 143 /* turns on the sensor */
mwilkens241 0:15e49005d54e 144 void VL6180x_On(void)
mwilkens241 0:15e49005d54e 145 {
mwilkens241 0:15e49005d54e 146 if(gpio0)
mwilkens241 0:15e49005d54e 147 *gpio0=1;
mwilkens241 0:15e49005d54e 148
mwilkens241 0:15e49005d54e 149 MyDevice.I2cAddr=DEFAULT_DEVICE_ADDRESS;
mwilkens241 0:15e49005d54e 150 MyDevice.Ready=0;
mwilkens241 0:15e49005d54e 151 }
mwilkens241 0:15e49005d54e 152
mwilkens241 0:15e49005d54e 153 /**
mwilkens241 0:15e49005d54e 154 * @brief PowerOff the sensor
mwilkens241 0:15e49005d54e 155 * @return void
mwilkens241 0:15e49005d54e 156 */
mwilkens241 0:15e49005d54e 157 /* turns off the sensor */
mwilkens241 0:15e49005d54e 158 void VL6180x_Off(void)
mwilkens241 0:15e49005d54e 159 {
mwilkens241 0:15e49005d54e 160 if(gpio0)
mwilkens241 0:15e49005d54e 161 *gpio0=0;
mwilkens241 0:15e49005d54e 162
mwilkens241 0:15e49005d54e 163 MyDevice.I2cAddr=DEFAULT_DEVICE_ADDRESS;
mwilkens241 0:15e49005d54e 164 MyDevice.Ready=0;
mwilkens241 0:15e49005d54e 165 }
mwilkens241 0:15e49005d54e 166
mwilkens241 0:15e49005d54e 167 /**
mwilkens241 0:15e49005d54e 168 * @brief Start the measure indicated by operating mode
mwilkens241 0:15e49005d54e 169 * @param[in] operating_mode specifies requested measure
mwilkens241 0:15e49005d54e 170 * @param[in] fptr specifies call back function must be !NULL in case of interrupt measure
mwilkens241 0:15e49005d54e 171 * @param[in] low specifies measure low threashold in Lux or in mm according to measure
mwilkens241 0:15e49005d54e 172 * @param[in] high specifies measure high threashold in Lux or in mm according to measure
mwilkens241 0:15e49005d54e 173 * @return 0 on Success
mwilkens241 0:15e49005d54e 174 */
mwilkens241 0:15e49005d54e 175 int StartMeasurement(OperatingMode operating_mode, void (*fptr)(void), uint16_t low, uint16_t high);
mwilkens241 0:15e49005d54e 176
mwilkens241 0:15e49005d54e 177 /**
mwilkens241 0:15e49005d54e 178 * @brief Get results for the measure indicated by operating mode
mwilkens241 0:15e49005d54e 179 * @param[in] operating_mode specifies requested measure results
mwilkens241 0:15e49005d54e 180 * @param[out] Data pointer to the MeasureData_t structure to read data in to
mwilkens241 0:15e49005d54e 181 * @return 0 on Success
mwilkens241 0:15e49005d54e 182 */
mwilkens241 0:15e49005d54e 183 int GetMeasurement(OperatingMode operating_mode, MeasureData_t *Data);
mwilkens241 0:15e49005d54e 184
mwilkens241 0:15e49005d54e 185 /**
mwilkens241 0:15e49005d54e 186 * @brief Stop the currently running measure indicate by operating_mode
mwilkens241 0:15e49005d54e 187 * @param[in] operating_mode specifies requested measure to stop
mwilkens241 0:15e49005d54e 188 * @return 0 on Success
mwilkens241 0:15e49005d54e 189 */
mwilkens241 0:15e49005d54e 190 int StopMeasurement(OperatingMode operating_mode);
mwilkens241 0:15e49005d54e 191
mwilkens241 0:15e49005d54e 192 /**
mwilkens241 0:15e49005d54e 193 * @brief Interrupt handling func to be called by user after an INT is occourred
mwilkens241 0:15e49005d54e 194 * @param[in] opeating_mode indicating the in progress measure
mwilkens241 0:15e49005d54e 195 * @param[out] Data pointer to the MeasureData_t structure to read data in to
mwilkens241 0:15e49005d54e 196 * @return 0 on Success
mwilkens241 0:15e49005d54e 197 */
mwilkens241 0:15e49005d54e 198 int HandleIRQ(OperatingMode operating_mode, MeasureData_t *Data);
mwilkens241 0:15e49005d54e 199
mwilkens241 0:15e49005d54e 200 /**
mwilkens241 0:15e49005d54e 201 * @brief Enable interrupt measure IRQ
mwilkens241 0:15e49005d54e 202 * @return 0 on Success
mwilkens241 0:15e49005d54e 203 */
mwilkens241 0:15e49005d54e 204 void EnableInterruptMeasureDetectionIRQ(void)
mwilkens241 0:15e49005d54e 205 {
mwilkens241 0:15e49005d54e 206 if (gpio1Int != NULL) gpio1Int->enable_irq();
mwilkens241 0:15e49005d54e 207 }
mwilkens241 0:15e49005d54e 208
mwilkens241 0:15e49005d54e 209 /**
mwilkens241 0:15e49005d54e 210 * @brief Disable interrupt measure IRQ
mwilkens241 0:15e49005d54e 211 * @return 0 on Success
mwilkens241 0:15e49005d54e 212 */
mwilkens241 0:15e49005d54e 213 void DisableInterruptMeasureDetectionIRQ(void)
mwilkens241 0:15e49005d54e 214 {
mwilkens241 0:15e49005d54e 215 if (gpio1Int != NULL) gpio1Int->disable_irq();
mwilkens241 0:15e49005d54e 216 }
mwilkens241 0:15e49005d54e 217 /*** End High level API ***/
mwilkens241 0:15e49005d54e 218
mwilkens241 0:15e49005d54e 219 /**
mwilkens241 0:15e49005d54e 220 * @brief Attach a function to call when an interrupt is detected, i.e. measurement is ready
mwilkens241 0:15e49005d54e 221 * @param[in] fptr pointer to call back function to be called whenever an interrupt occours
mwilkens241 0:15e49005d54e 222 * @return 0 on Success
mwilkens241 0:15e49005d54e 223 */
mwilkens241 0:15e49005d54e 224 void AttachInterruptMeasureDetectionIRQ(void (*fptr)(void))
mwilkens241 0:15e49005d54e 225 {
mwilkens241 0:15e49005d54e 226 if (gpio1Int != NULL) gpio1Int->rise(fptr);
mwilkens241 0:15e49005d54e 227 }
mwilkens241 0:15e49005d54e 228
mwilkens241 0:15e49005d54e 229 /**
mwilkens241 0:15e49005d54e 230 * @brief Check the sensor presence
mwilkens241 0:15e49005d54e 231 * @return 1 when device is present
mwilkens241 0:15e49005d54e 232 */
mwilkens241 0:15e49005d54e 233 unsigned Present()
mwilkens241 0:15e49005d54e 234 {
mwilkens241 0:15e49005d54e 235 return Device->Present;
mwilkens241 0:15e49005d54e 236 }
mwilkens241 0:15e49005d54e 237
mwilkens241 0:15e49005d54e 238 /** Wrapper functions */
mwilkens241 0:15e49005d54e 239 /** @defgroup api_init Init functions
mwilkens241 0:15e49005d54e 240 * @brief API init functions
mwilkens241 0:15e49005d54e 241 * @ingroup api_hl
mwilkens241 0:15e49005d54e 242 * @{
mwilkens241 0:15e49005d54e 243 */
mwilkens241 0:15e49005d54e 244 /**
mwilkens241 0:15e49005d54e 245 * @brief Wait for device booted after chip enable (hardware standby)
mwilkens241 0:15e49005d54e 246 * @par Function Description
mwilkens241 0:15e49005d54e 247 * After Chip enable Application you can also simply wait at least 1ms to ensure device is ready
mwilkens241 0:15e49005d54e 248 * @warning After device chip enable (gpio0) de-asserted user must wait gpio1 to get asserted (hardware standby).
mwilkens241 0:15e49005d54e 249 * or wait at least 400usec prior to do any low level access or api call .
mwilkens241 0:15e49005d54e 250 *
mwilkens241 0:15e49005d54e 251 * This function implements polling for standby but you must ensure 400usec from chip enable passed\n
mwilkens241 0:15e49005d54e 252 * @warning if device get prepared @a VL6180x_Prepare() re-using these function can hold indefinitely\n
mwilkens241 0:15e49005d54e 253 *
mwilkens241 0:15e49005d54e 254 * @param void
mwilkens241 0:15e49005d54e 255 * @return 0 on success
mwilkens241 0:15e49005d54e 256 */
mwilkens241 0:15e49005d54e 257 int WaitDeviceBooted()
mwilkens241 0:15e49005d54e 258 {
mwilkens241 0:15e49005d54e 259 return VL6180x_WaitDeviceBooted(Device);
mwilkens241 0:15e49005d54e 260 }
mwilkens241 0:15e49005d54e 261
mwilkens241 0:15e49005d54e 262 /**
mwilkens241 0:15e49005d54e 263 *
mwilkens241 0:15e49005d54e 264 * @brief One time device initialization
mwilkens241 0:15e49005d54e 265 *
mwilkens241 0:15e49005d54e 266 * To be called once and only once after device is brought out of reset (Chip enable) and booted see @a VL6180x_WaitDeviceBooted()
mwilkens241 0:15e49005d54e 267 *
mwilkens241 0:15e49005d54e 268 * @par Function Description
mwilkens241 0:15e49005d54e 269 * When not used after a fresh device "power up" or reset, it may return @a #CALIBRATION_WARNING
mwilkens241 0:15e49005d54e 270 * meaning wrong calibration data may have been fetched from device that can result in ranging offset error\n
mwilkens241 0:15e49005d54e 271 * If application cannot execute device reset or need to run VL6180x_InitData multiple time
mwilkens241 0:15e49005d54e 272 * then it must ensure proper offset calibration saving and restore on its own
mwilkens241 0:15e49005d54e 273 * by using @a VL6180x_GetOffsetCalibrationData() on first power up and then @a VL6180x_SetOffsetCalibrationData() all all subsequent init
mwilkens241 0:15e49005d54e 274 *
mwilkens241 0:15e49005d54e 275 * @param void
mwilkens241 0:15e49005d54e 276 * @return 0 on success, @a #CALIBRATION_WARNING if failed
mwilkens241 0:15e49005d54e 277 */
mwilkens241 0:15e49005d54e 278 virtual int Init()
mwilkens241 0:15e49005d54e 279 {
mwilkens241 0:15e49005d54e 280 int status;
mwilkens241 0:15e49005d54e 281
mwilkens241 0:15e49005d54e 282 VL6180x_Off();
mwilkens241 0:15e49005d54e 283 VL6180x_On();
mwilkens241 0:15e49005d54e 284
mwilkens241 0:15e49005d54e 285 status=VL6180x_WaitDeviceBooted(Device);
mwilkens241 0:15e49005d54e 286 if(status) {
mwilkens241 0:15e49005d54e 287 VL6180x_ErrLog("WaitDeviceBooted fail\n\r");
mwilkens241 0:15e49005d54e 288 }
mwilkens241 0:15e49005d54e 289 status=IsPresent();
mwilkens241 0:15e49005d54e 290 if(!status)
mwilkens241 0:15e49005d54e 291 {
mwilkens241 0:15e49005d54e 292 Device->Present=1;
mwilkens241 0:15e49005d54e 293 VL6180x_InitData(Device);
mwilkens241 0:15e49005d54e 294 if(status)
mwilkens241 0:15e49005d54e 295 {
mwilkens241 0:15e49005d54e 296 printf("Failed to init VL6180X sensor!\n\r");
mwilkens241 0:15e49005d54e 297 return 1;
mwilkens241 0:15e49005d54e 298 }
mwilkens241 0:15e49005d54e 299 status=Prepare();
mwilkens241 0:15e49005d54e 300 if(status)
mwilkens241 0:15e49005d54e 301 {
mwilkens241 0:15e49005d54e 302 printf("Failed to prepare VL6180X!\n\r");
mwilkens241 0:15e49005d54e 303 return 2;
mwilkens241 0:15e49005d54e 304 }
mwilkens241 0:15e49005d54e 305 Device->Ready=1;
mwilkens241 0:15e49005d54e 306 }
mwilkens241 0:15e49005d54e 307 return status;
mwilkens241 0:15e49005d54e 308 }
mwilkens241 0:15e49005d54e 309
mwilkens241 0:15e49005d54e 310
mwilkens241 0:15e49005d54e 311 /**
mwilkens241 0:15e49005d54e 312 * @brief Configure GPIO1 function and set polarity.
mwilkens241 0:15e49005d54e 313 * @par Function Description
mwilkens241 0:15e49005d54e 314 * To be used prior to arm single shot measure or start continuous mode.
mwilkens241 0:15e49005d54e 315 *
mwilkens241 0:15e49005d54e 316 * The function uses @a VL6180x_SetupGPIOx() for setting gpio 1.
mwilkens241 0:15e49005d54e 317 * @warning changing polarity can generate a spurious interrupt on pins.
mwilkens241 0:15e49005d54e 318 * It sets an interrupt flags condition that must be cleared to avoid polling hangs. \n
mwilkens241 0:15e49005d54e 319 * It is safe to run VL6180x_ClearAllInterrupt() just after.
mwilkens241 0:15e49005d54e 320 *
mwilkens241 0:15e49005d54e 321 * @param IntFunction The interrupt functionality to use one of :\n
mwilkens241 0:15e49005d54e 322 * @a #GPIOx_SELECT_OFF \n
mwilkens241 0:15e49005d54e 323 * @a #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT
mwilkens241 0:15e49005d54e 324 * @param ActiveHigh The interrupt line polarity see ::IntrPol_e
mwilkens241 0:15e49005d54e 325 * use @a #INTR_POL_LOW (falling edge) or @a #INTR_POL_HIGH (rising edge)
mwilkens241 0:15e49005d54e 326 * @return 0 on success
mwilkens241 0:15e49005d54e 327 */
mwilkens241 0:15e49005d54e 328 int SetupGPIO1(uint8_t InitFunction, int ActiveHigh)
mwilkens241 0:15e49005d54e 329 {
mwilkens241 0:15e49005d54e 330 return VL6180x_SetupGPIO1(Device, InitFunction, ActiveHigh);
mwilkens241 0:15e49005d54e 331 }
mwilkens241 0:15e49005d54e 332
mwilkens241 0:15e49005d54e 333 /**
mwilkens241 0:15e49005d54e 334 * @brief Prepare device for operation
mwilkens241 0:15e49005d54e 335 * @par Function Description
mwilkens241 0:15e49005d54e 336 * Does static initialization and reprogram common default settings \n
mwilkens241 0:15e49005d54e 337 * Device is prepared for new measure, ready single shot ranging or ALS typical polling operation\n
mwilkens241 0:15e49005d54e 338 * After prepare user can : \n
mwilkens241 0:15e49005d54e 339 * @li Call other API function to set other settings\n
mwilkens241 0:15e49005d54e 340 * @li Configure the interrupt pins, etc... \n
mwilkens241 0:15e49005d54e 341 * @li Then start ranging or ALS operations in single shot or continuous mode
mwilkens241 0:15e49005d54e 342 *
mwilkens241 0:15e49005d54e 343 * @param void
mwilkens241 0:15e49005d54e 344 * @return 0 on success
mwilkens241 0:15e49005d54e 345 */
mwilkens241 0:15e49005d54e 346 int Prepare()
mwilkens241 0:15e49005d54e 347 {
mwilkens241 0:15e49005d54e 348 return VL6180x_Prepare(Device);
mwilkens241 0:15e49005d54e 349 }
mwilkens241 0:15e49005d54e 350
mwilkens241 0:15e49005d54e 351 /**
mwilkens241 0:15e49005d54e 352 * @brief Start continuous ranging mode
mwilkens241 0:15e49005d54e 353 *
mwilkens241 0:15e49005d54e 354 * @details End user should ensure device is in idle state and not already running
mwilkens241 0:15e49005d54e 355 * @return 0 on success
mwilkens241 0:15e49005d54e 356 */
mwilkens241 0:15e49005d54e 357 int RangeStartContinuousMode()
mwilkens241 0:15e49005d54e 358 {
mwilkens241 0:15e49005d54e 359 return VL6180x_RangeStartContinuousMode(Device);
mwilkens241 0:15e49005d54e 360 }
mwilkens241 0:15e49005d54e 361
mwilkens241 0:15e49005d54e 362 /**
mwilkens241 0:15e49005d54e 363 * @brief Start single shot ranging measure
mwilkens241 0:15e49005d54e 364 *
mwilkens241 0:15e49005d54e 365 * @details End user should ensure device is in idle state and not already running
mwilkens241 0:15e49005d54e 366 * @return 0 on success
mwilkens241 0:15e49005d54e 367 */
mwilkens241 0:15e49005d54e 368 int RangeStartSingleShot()
mwilkens241 0:15e49005d54e 369 {
mwilkens241 0:15e49005d54e 370 return VL6180x_RangeStartSingleShot(Device);
mwilkens241 0:15e49005d54e 371 }
mwilkens241 0:15e49005d54e 372
mwilkens241 0:15e49005d54e 373 /**
mwilkens241 0:15e49005d54e 374 * @brief Set maximum convergence time
mwilkens241 0:15e49005d54e 375 *
mwilkens241 0:15e49005d54e 376 * @par Function Description
mwilkens241 0:15e49005d54e 377 * Setting a low convergence time can impact maximal detectable distance.
mwilkens241 0:15e49005d54e 378 * Refer to VL6180x Datasheet Table 7 : Typical range convergence time.
mwilkens241 0:15e49005d54e 379 * A typical value for up to x3 scaling is 50 ms
mwilkens241 0:15e49005d54e 380 *
mwilkens241 0:15e49005d54e 381 * @param MaxConTime_msec
mwilkens241 0:15e49005d54e 382 * @return 0 on success. <0 on error. >0 for calibration warning status
mwilkens241 0:15e49005d54e 383 */
mwilkens241 0:15e49005d54e 384 int RangeSetMaxConvergenceTime(uint8_t MaxConTime_msec)
mwilkens241 0:15e49005d54e 385 {
mwilkens241 0:15e49005d54e 386 return VL6180x_RangeSetMaxConvergenceTime(Device, MaxConTime_msec);
mwilkens241 0:15e49005d54e 387 }
mwilkens241 0:15e49005d54e 388
mwilkens241 0:15e49005d54e 389 /**
mwilkens241 0:15e49005d54e 390 * @brief Single shot Range measurement in polling mode.
mwilkens241 0:15e49005d54e 391 *
mwilkens241 0:15e49005d54e 392 * @par Function Description
mwilkens241 0:15e49005d54e 393 * Kick off a new single shot range then wait for ready to retrieve it by polling interrupt status \n
mwilkens241 0:15e49005d54e 394 * Ranging must be prepared by a first call to @a VL6180x_Prepare() and it is safer to clear very first poll call \n
mwilkens241 0:15e49005d54e 395 * This function reference VL6180x_PollDelay(dev) porting macro/call on each polling loop,
mwilkens241 0:15e49005d54e 396 * but PollDelay(dev) may never be called if measure in ready on first poll loop \n
mwilkens241 0:15e49005d54e 397 * Should not be use in continuous mode operation as it will stop it and cause stop/start misbehaviour \n
mwilkens241 0:15e49005d54e 398 * \n This function clears Range Interrupt status , but not error one. For that uses @a VL6180x_ClearErrorInterrupt() \n
mwilkens241 0:15e49005d54e 399 * This range error is not related VL6180x_RangeData_t::errorStatus that refer measure status \n
mwilkens241 0:15e49005d54e 400 *
mwilkens241 0:15e49005d54e 401 * @param pRangeData Will be populated with the result ranging data @a VL6180x_RangeData_t
mwilkens241 0:15e49005d54e 402 * @return 0 on success , @a #RANGE_ERROR if device reports an error case in it status (not cleared) use
mwilkens241 0:15e49005d54e 403 *
mwilkens241 0:15e49005d54e 404 * \sa ::VL6180x_RangeData_t
mwilkens241 0:15e49005d54e 405 */
mwilkens241 0:15e49005d54e 406 int RangePollMeasurement(VL6180x_RangeData_t *pRangeData)
mwilkens241 0:15e49005d54e 407 {
mwilkens241 0:15e49005d54e 408 return VL6180x_RangePollMeasurement(Device, pRangeData);
mwilkens241 0:15e49005d54e 409 }
mwilkens241 0:15e49005d54e 410
mwilkens241 0:15e49005d54e 411 /**
mwilkens241 0:15e49005d54e 412 * @brief Check for measure readiness and get it if ready
mwilkens241 0:15e49005d54e 413 *
mwilkens241 0:15e49005d54e 414 * @par Function Description
mwilkens241 0:15e49005d54e 415 * Using this function is an alternative to @a VL6180x_RangePollMeasurement() to avoid polling operation. This is suitable for applications
mwilkens241 0:15e49005d54e 416 * 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
mwilkens241 0:15e49005d54e 417 * operation is triggered by a call to @a VL6180x_RangeStartSingleShot(). Then, host CPU regularly calls @a VL6180x_RangeGetMeasurementIfReady() to
mwilkens241 0:15e49005d54e 418 * get a distance measure if ready. In case the distance is not ready, host may get it at the next call.\n
mwilkens241 0:15e49005d54e 419 *
mwilkens241 0:15e49005d54e 420 * @warning
mwilkens241 0:15e49005d54e 421 * This function does not re-start a new measurement : this is up to the host CPU to do it.\n
mwilkens241 0:15e49005d54e 422 * This function clears Range Interrupt for measure ready , but not error interrupts. For that, uses @a VL6180x_ClearErrorInterrupt() \n
mwilkens241 0:15e49005d54e 423 *
mwilkens241 0:15e49005d54e 424 * @param pRangeData Will be populated with the result ranging data if available
mwilkens241 0:15e49005d54e 425 * @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,
mwilkens241 0:15e49005d54e 426 */
mwilkens241 0:15e49005d54e 427 int RangeGetMeasurementIfReady(VL6180x_RangeData_t *pRangeData)
mwilkens241 0:15e49005d54e 428 {
mwilkens241 0:15e49005d54e 429 return VL6180x_RangeGetMeasurementIfReady(Device, pRangeData);
mwilkens241 0:15e49005d54e 430 }
mwilkens241 0:15e49005d54e 431
mwilkens241 0:15e49005d54e 432 /**
mwilkens241 0:15e49005d54e 433 * @brief Retrieve range measurements set from device
mwilkens241 0:15e49005d54e 434 *
mwilkens241 0:15e49005d54e 435 * @par Function Description
mwilkens241 0:15e49005d54e 436 * The measurement is made of range_mm status and error code @a VL6180x_RangeData_t \n
mwilkens241 0:15e49005d54e 437 * Based on configuration selected extra measures are included.
mwilkens241 0:15e49005d54e 438 *
mwilkens241 0:15e49005d54e 439 * @warning should not be used in continuous if wrap around filter is active \n
mwilkens241 0:15e49005d54e 440 * Does not perform any wait nor check for result availability or validity.
mwilkens241 0:15e49005d54e 441 *\sa VL6180x_RangeGetResult for "range only" measurement
mwilkens241 0:15e49005d54e 442 *
mwilkens241 0:15e49005d54e 443 * @param pRangeData Pointer to the data structure to fill up
mwilkens241 0:15e49005d54e 444 * @return 0 on success
mwilkens241 0:15e49005d54e 445 */
mwilkens241 0:15e49005d54e 446 int RangeGetMeasurement(VL6180x_RangeData_t *pRangeData)
mwilkens241 0:15e49005d54e 447 {
mwilkens241 0:15e49005d54e 448 return VL6180x_RangeGetMeasurement(Device, pRangeData);
mwilkens241 0:15e49005d54e 449 }
mwilkens241 0:15e49005d54e 450
mwilkens241 0:15e49005d54e 451 /**
mwilkens241 0:15e49005d54e 452 * @brief Get a single distance measure result
mwilkens241 0:15e49005d54e 453 *
mwilkens241 0:15e49005d54e 454 * @par Function Description
mwilkens241 0:15e49005d54e 455 * It can be called after having initialized a component. It start a single
mwilkens241 0:15e49005d54e 456 * distance measure in polling mode and wait until the measure is finisched.
mwilkens241 0:15e49005d54e 457 * The function block until the measure is finished, it can blocks indefinitely
mwilkens241 0:15e49005d54e 458 * in case the measure never ends for any reason \n
mwilkens241 0:15e49005d54e 459 *
mwilkens241 0:15e49005d54e 460 * @param piData Pointer to distance
mwilkens241 0:15e49005d54e 461 * @return 0 on success
mwilkens241 0:15e49005d54e 462 */
mwilkens241 0:15e49005d54e 463 virtual int GetDistance(uint32_t *piData)
mwilkens241 0:15e49005d54e 464 {
mwilkens241 0:15e49005d54e 465 int status=0;
mwilkens241 0:15e49005d54e 466 LOG_FUNCTION_START("");
mwilkens241 0:15e49005d54e 467 status=StartMeasurement(range_single_shot_polling, NULL, NULL, NULL);
mwilkens241 0:15e49005d54e 468 if (!status) {
mwilkens241 0:15e49005d54e 469 RangeWaitDeviceReady(2000);
mwilkens241 0:15e49005d54e 470 for (status=1;
mwilkens241 0:15e49005d54e 471 status!=0;
mwilkens241 0:15e49005d54e 472 status=VL6180x_RangeGetResult(Device, piData));
mwilkens241 0:15e49005d54e 473 }
mwilkens241 0:15e49005d54e 474 StopMeasurement(range_single_shot_polling);
mwilkens241 0:15e49005d54e 475 RangeWaitDeviceReady(2000);
mwilkens241 0:15e49005d54e 476 LOG_FUNCTION_END(status);
mwilkens241 0:15e49005d54e 477 return status;
mwilkens241 0:15e49005d54e 478 }
mwilkens241 0:15e49005d54e 479
mwilkens241 0:15e49005d54e 480 /**
mwilkens241 0:15e49005d54e 481 * @brief Configure ranging interrupt reported to application
mwilkens241 0:15e49005d54e 482 *
mwilkens241 0:15e49005d54e 483 * @param ConfigGpioInt Select ranging report\n select one (and only one) of:\n
mwilkens241 0:15e49005d54e 484 * @a #CONFIG_GPIO_INTERRUPT_DISABLED \n
mwilkens241 0:15e49005d54e 485 * @a #CONFIG_GPIO_INTERRUPT_LEVEL_LOW \n
mwilkens241 0:15e49005d54e 486 * @a #CONFIG_GPIO_INTERRUPT_LEVEL_HIGH \n
mwilkens241 0:15e49005d54e 487 * @a #CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW \n
mwilkens241 0:15e49005d54e 488 * @a #CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY
mwilkens241 0:15e49005d54e 489 * @return 0 on success
mwilkens241 0:15e49005d54e 490 */
mwilkens241 0:15e49005d54e 491 int RangeConfigInterrupt(uint8_t ConfigGpioInt)
mwilkens241 0:15e49005d54e 492 {
mwilkens241 0:15e49005d54e 493 return VL6180x_RangeConfigInterrupt(Device, ConfigGpioInt);
mwilkens241 0:15e49005d54e 494 }
mwilkens241 0:15e49005d54e 495
mwilkens241 0:15e49005d54e 496 /**
mwilkens241 0:15e49005d54e 497 * @brief Return ranging error interrupt status
mwilkens241 0:15e49005d54e 498 *
mwilkens241 0:15e49005d54e 499 * @par Function Description
mwilkens241 0:15e49005d54e 500 * Appropriate Interrupt report must have been selected first by @a VL6180x_RangeConfigInterrupt() or @a VL6180x_Prepare() \n
mwilkens241 0:15e49005d54e 501 *
mwilkens241 0:15e49005d54e 502 * Can be used in polling loop to wait for a given ranging event or in interrupt to read the trigger \n
mwilkens241 0:15e49005d54e 503 * Events triggers are : \n
mwilkens241 0:15e49005d54e 504 * @a #RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD \n
mwilkens241 0:15e49005d54e 505 * @a #RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD \n
mwilkens241 0:15e49005d54e 506 * @a #RES_INT_STAT_GPIO_OUT_OF_WINDOW \n (RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD|RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD)
mwilkens241 0:15e49005d54e 507 * @a #RES_INT_STAT_GPIO_NEW_SAMPLE_READY \n
mwilkens241 0:15e49005d54e 508 *
mwilkens241 0:15e49005d54e 509 * @sa IntrStatus_t
mwilkens241 0:15e49005d54e 510 * @param pIntStatus Pointer to status variable to update
mwilkens241 0:15e49005d54e 511 * @return 0 on success
mwilkens241 0:15e49005d54e 512 */
mwilkens241 0:15e49005d54e 513 int RangeGetInterruptStatus(uint8_t *pIntStatus)
mwilkens241 0:15e49005d54e 514 {
mwilkens241 0:15e49005d54e 515 return VL6180x_RangeGetInterruptStatus(Device, pIntStatus);
mwilkens241 0:15e49005d54e 516 }
mwilkens241 0:15e49005d54e 517
mwilkens241 0:15e49005d54e 518 /**
mwilkens241 0:15e49005d54e 519 * @brief Run a single ALS measurement in single shot polling mode
mwilkens241 0:15e49005d54e 520 *
mwilkens241 0:15e49005d54e 521 * @par Function Description
mwilkens241 0:15e49005d54e 522 * Kick off a new single shot ALS then wait new measurement ready to retrieve it ( polling system interrupt status register for als) \n
mwilkens241 0:15e49005d54e 523 * ALS must be prepared by a first call to @a VL6180x_Prepare() \n
mwilkens241 0:15e49005d54e 524 * \n Should not be used in continuous or interrupt mode it will break it and create hazard in start/stop \n
mwilkens241 0:15e49005d54e 525 *
mwilkens241 0:15e49005d54e 526 * @param dev The device
mwilkens241 0:15e49005d54e 527 * @param pAlsData Als data structure to fill up @a VL6180x_AlsData_t
mwilkens241 0:15e49005d54e 528 * @return 0 on success
mwilkens241 0:15e49005d54e 529 */
mwilkens241 0:15e49005d54e 530 int AlsPollMeasurement(VL6180x_AlsData_t *pAlsData)
mwilkens241 0:15e49005d54e 531 {
mwilkens241 0:15e49005d54e 532 return VL6180x_AlsPollMeasurement(Device, pAlsData);
mwilkens241 0:15e49005d54e 533 }
mwilkens241 0:15e49005d54e 534
mwilkens241 0:15e49005d54e 535 /**
mwilkens241 0:15e49005d54e 536 * @brief Get actual ALS measurement
mwilkens241 0:15e49005d54e 537 *
mwilkens241 0:15e49005d54e 538 * @par Function Description
mwilkens241 0:15e49005d54e 539 * Can be called after success status polling or in interrupt mode to retrieve ALS measurement from device \n
mwilkens241 0:15e49005d54e 540 * This function doesn't perform any data ready check !
mwilkens241 0:15e49005d54e 541 *
mwilkens241 0:15e49005d54e 542 * @param pAlsData Pointer to measurement struct @a VL6180x_AlsData_t
mwilkens241 0:15e49005d54e 543 * @return 0 on success
mwilkens241 0:15e49005d54e 544 */
mwilkens241 0:15e49005d54e 545 int AlsGetMeasurement(VL6180x_AlsData_t *pAlsData)
mwilkens241 0:15e49005d54e 546 {
mwilkens241 0:15e49005d54e 547 return VL6180x_AlsGetMeasurement(Device, pAlsData);
mwilkens241 0:15e49005d54e 548 }
mwilkens241 0:15e49005d54e 549
mwilkens241 0:15e49005d54e 550 /**
mwilkens241 0:15e49005d54e 551 * @brief Configure ALS interrupts provide to application
mwilkens241 0:15e49005d54e 552 *
mwilkens241 0:15e49005d54e 553 * @param ConfigGpioInt Select one (and only one) of : \n
mwilkens241 0:15e49005d54e 554 * @a #CONFIG_GPIO_INTERRUPT_DISABLED \n
mwilkens241 0:15e49005d54e 555 * @a #CONFIG_GPIO_INTERRUPT_LEVEL_LOW \n
mwilkens241 0:15e49005d54e 556 * @a #CONFIG_GPIO_INTERRUPT_LEVEL_HIGH \n
mwilkens241 0:15e49005d54e 557 * @a #CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW \n
mwilkens241 0:15e49005d54e 558 * @a #CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY
mwilkens241 0:15e49005d54e 559 * @return 0 on success may return #INVALID_PARAMS for invalid mode
mwilkens241 0:15e49005d54e 560 */
mwilkens241 0:15e49005d54e 561 int AlsConfigInterrupt(uint8_t ConfigGpioInt)
mwilkens241 0:15e49005d54e 562 {
mwilkens241 0:15e49005d54e 563 return VL6180x_AlsConfigInterrupt(Device, ConfigGpioInt);
mwilkens241 0:15e49005d54e 564 }
mwilkens241 0:15e49005d54e 565
mwilkens241 0:15e49005d54e 566 /**
mwilkens241 0:15e49005d54e 567 * @brief Set ALS integration period
mwilkens241 0:15e49005d54e 568 *
mwilkens241 0:15e49005d54e 569 * @param period_ms Integration period in msec. Value in between 50 to 100 msec is recommended\n
mwilkens241 0:15e49005d54e 570 * @return 0 on success
mwilkens241 0:15e49005d54e 571 */
mwilkens241 0:15e49005d54e 572 int AlsSetIntegrationPeriod(uint16_t period_ms)
mwilkens241 0:15e49005d54e 573 {
mwilkens241 0:15e49005d54e 574 return VL6180x_AlsSetIntegrationPeriod(Device, period_ms);
mwilkens241 0:15e49005d54e 575 }
mwilkens241 0:15e49005d54e 576
mwilkens241 0:15e49005d54e 577 /**
mwilkens241 0:15e49005d54e 578 * @brief Set ALS "inter-measurement period"
mwilkens241 0:15e49005d54e 579 *
mwilkens241 0:15e49005d54e 580 * @par Function Description
mwilkens241 0:15e49005d54e 581 * The so call data-sheet "inter measurement period" is actually an extra inter-measurement delay
mwilkens241 0:15e49005d54e 582 *
mwilkens241 0:15e49005d54e 583 * @param intermeasurement_period_ms Inter measurement time in milli second\n
mwilkens241 0:15e49005d54e 584 * @warning applied value is clipped to 2550 ms\n
mwilkens241 0:15e49005d54e 585 * @return 0 on success if value is
mwilkens241 0:15e49005d54e 586 */
mwilkens241 0:15e49005d54e 587 int AlsSetInterMeasurementPeriod(uint16_t intermeasurement_period_ms)
mwilkens241 0:15e49005d54e 588 {
mwilkens241 0:15e49005d54e 589 return VL6180x_AlsSetInterMeasurementPeriod(Device, intermeasurement_period_ms);
mwilkens241 0:15e49005d54e 590 }
mwilkens241 0:15e49005d54e 591
mwilkens241 0:15e49005d54e 592 /**
mwilkens241 0:15e49005d54e 593 * @brief Set ALS analog gain code
mwilkens241 0:15e49005d54e 594 *
mwilkens241 0:15e49005d54e 595 * @par Function Description
mwilkens241 0:15e49005d54e 596 * ALS gain code value programmed in @a SYSALS_ANALOGUE_GAIN .
mwilkens241 0:15e49005d54e 597 * @param gain Gain code see datasheet or AlsGainLookUp for real value. Value is clipped to 7.
mwilkens241 0:15e49005d54e 598 * @return 0 on success
mwilkens241 0:15e49005d54e 599 */
mwilkens241 0:15e49005d54e 600 int AlsSetAnalogueGain(uint8_t gain)
mwilkens241 0:15e49005d54e 601 {
mwilkens241 0:15e49005d54e 602 return VL6180x_AlsSetAnalogueGain(Device, gain);
mwilkens241 0:15e49005d54e 603 }
mwilkens241 0:15e49005d54e 604
mwilkens241 0:15e49005d54e 605 /**
mwilkens241 0:15e49005d54e 606 * @brief Set thresholds for ALS continuous mode
mwilkens241 0:15e49005d54e 607 * @warning Threshold are raw device value not lux!
mwilkens241 0:15e49005d54e 608 *
mwilkens241 0:15e49005d54e 609 * @par Function Description
mwilkens241 0:15e49005d54e 610 * Basically value programmed in @a SYSALS_THRESH_LOW and @a SYSALS_THRESH_HIGH registers
mwilkens241 0:15e49005d54e 611 * @param low ALS low raw threshold for @a SYSALS_THRESH_LOW
mwilkens241 0:15e49005d54e 612 * @param high ALS high raw threshold for @a SYSALS_THRESH_HIGH
mwilkens241 0:15e49005d54e 613 * @return 0 on success
mwilkens241 0:15e49005d54e 614 */
mwilkens241 0:15e49005d54e 615 int AlsSetThresholds(uint16_t lux_threshold_low, uint16_t lux_threshold_high);
mwilkens241 0:15e49005d54e 616
mwilkens241 0:15e49005d54e 617 /**
mwilkens241 0:15e49005d54e 618 * Read ALS interrupt status
mwilkens241 0:15e49005d54e 619 * @param pIntStatus Pointer to status
mwilkens241 0:15e49005d54e 620 * @return 0 on success
mwilkens241 0:15e49005d54e 621 */
mwilkens241 0:15e49005d54e 622 int AlsGetInterruptStatus(uint8_t *pIntStatus)
mwilkens241 0:15e49005d54e 623 {
mwilkens241 0:15e49005d54e 624 return VL6180x_AlsGetInterruptStatus(Device, pIntStatus);
mwilkens241 0:15e49005d54e 625 }
mwilkens241 0:15e49005d54e 626
mwilkens241 0:15e49005d54e 627 /**
mwilkens241 0:15e49005d54e 628 * @brief Low level ranging and ALS register static settings (you should call @a VL6180x_Prepare() function instead)
mwilkens241 0:15e49005d54e 629 *
mwilkens241 0:15e49005d54e 630 * @return 0 on success
mwilkens241 0:15e49005d54e 631 */
mwilkens241 0:15e49005d54e 632 int StaticInit()
mwilkens241 0:15e49005d54e 633 {
mwilkens241 0:15e49005d54e 634 return VL6180x_StaticInit(Device);
mwilkens241 0:15e49005d54e 635 }
mwilkens241 0:15e49005d54e 636
mwilkens241 0:15e49005d54e 637 /**
mwilkens241 0:15e49005d54e 638 * @brief Wait for device to be ready (before a new ranging command can be issued by application)
mwilkens241 0:15e49005d54e 639 * @param MaxLoop Max Number of i2c polling loop see @a #msec_2_i2cloop
mwilkens241 0:15e49005d54e 640 * @return 0 on success. <0 when fail \n
mwilkens241 0:15e49005d54e 641 * @ref VL6180x_ErrCode_t::TIME_OUT for time out \n
mwilkens241 0:15e49005d54e 642 * @ref VL6180x_ErrCode_t::INVALID_PARAMS if MaxLop<1
mwilkens241 0:15e49005d54e 643 */
mwilkens241 0:15e49005d54e 644 int RangeWaitDeviceReady(int MaxLoop )
mwilkens241 0:15e49005d54e 645 {
mwilkens241 0:15e49005d54e 646 return VL6180x_RangeWaitDeviceReady(Device, MaxLoop);
mwilkens241 0:15e49005d54e 647 }
mwilkens241 0:15e49005d54e 648
mwilkens241 0:15e49005d54e 649 /**
mwilkens241 0:15e49005d54e 650 * @brief Program Inter measurement period (used only in continuous mode)
mwilkens241 0:15e49005d54e 651 *
mwilkens241 0:15e49005d54e 652 * @par Function Description
mwilkens241 0:15e49005d54e 653 * When trying to set too long time, it returns #INVALID_PARAMS
mwilkens241 0:15e49005d54e 654 *
mwilkens241 0:15e49005d54e 655 * @param InterMeasTime_msec Requires inter-measurement time in msec
mwilkens241 0:15e49005d54e 656 * @return 0 on success
mwilkens241 0:15e49005d54e 657 */
mwilkens241 0:15e49005d54e 658 int RangeSetInterMeasPeriod(uint32_t InterMeasTime_msec)
mwilkens241 0:15e49005d54e 659 {
mwilkens241 0:15e49005d54e 660 return VL6180x_RangeSetInterMeasPeriod(Device, InterMeasTime_msec);
mwilkens241 0:15e49005d54e 661 }
mwilkens241 0:15e49005d54e 662
mwilkens241 0:15e49005d54e 663 /**
mwilkens241 0:15e49005d54e 664 * @brief Set device ranging scaling factor
mwilkens241 0:15e49005d54e 665 *
mwilkens241 0:15e49005d54e 666 * @par Function Description
mwilkens241 0:15e49005d54e 667 * The ranging scaling factor is applied on the raw distance measured by the device to increase operating ranging at the price of the precision.
mwilkens241 0:15e49005d54e 668 * Changing the scaling factor when device is not in f/w standby state (free running) is not safe.
mwilkens241 0:15e49005d54e 669 * It can be source of spurious interrupt, wrongly scaled range etc ...
mwilkens241 0:15e49005d54e 670 * @warning __This function doesns't update high/low threshold and other programmed settings linked to scaling factor__.
mwilkens241 0:15e49005d54e 671 * To ensure proper operation, threshold and scaling changes should be done following this procedure: \n
mwilkens241 0:15e49005d54e 672 * @li Set Group hold : @a VL6180x_SetGroupParamHold() \n
mwilkens241 0:15e49005d54e 673 * @li Get Threshold @a VL6180x_RangeGetThresholds() \n
mwilkens241 0:15e49005d54e 674 * @li Change scaling : @a VL6180x_UpscaleSetScaling() \n
mwilkens241 0:15e49005d54e 675 * @li Set Threshold : @a VL6180x_RangeSetThresholds() \n
mwilkens241 0:15e49005d54e 676 * @li Unset Group Hold : @a VL6180x_SetGroupParamHold()
mwilkens241 0:15e49005d54e 677 *
mwilkens241 0:15e49005d54e 678 * @param scaling Scaling factor to apply (1,2 or 3)
mwilkens241 0:15e49005d54e 679 * @return 0 on success when up-scale support is not configured it fail for any
mwilkens241 0:15e49005d54e 680 * scaling than the one statically configured.
mwilkens241 0:15e49005d54e 681 */
mwilkens241 0:15e49005d54e 682 int UpscaleSetScaling(uint8_t scaling)
mwilkens241 0:15e49005d54e 683 {
mwilkens241 0:15e49005d54e 684 return VL6180x_UpscaleSetScaling(Device, scaling);
mwilkens241 0:15e49005d54e 685 }
mwilkens241 0:15e49005d54e 686
mwilkens241 0:15e49005d54e 687 /**
mwilkens241 0:15e49005d54e 688 * @brief Get current ranging scaling factor
mwilkens241 0:15e49005d54e 689 *
mwilkens241 0:15e49005d54e 690 * @return The current scaling factor
mwilkens241 0:15e49005d54e 691 */
mwilkens241 0:15e49005d54e 692 int UpscaleGetScaling()
mwilkens241 0:15e49005d54e 693 {
mwilkens241 0:15e49005d54e 694 return VL6180x_UpscaleGetScaling(Device);
mwilkens241 0:15e49005d54e 695 }
mwilkens241 0:15e49005d54e 696
mwilkens241 0:15e49005d54e 697 /**
mwilkens241 0:15e49005d54e 698 * @brief Get the maximal distance for actual scaling
mwilkens241 0:15e49005d54e 699 * @par Function Description
mwilkens241 0:15e49005d54e 700 * Do not use prior to @a VL6180x_Prepare() or at least @a VL6180x_InitData()
mwilkens241 0:15e49005d54e 701 *
mwilkens241 0:15e49005d54e 702 * Any range value more than the value returned by this function is to be considered as "no target detected"
mwilkens241 0:15e49005d54e 703 * or "no target in detectable range" \n
mwilkens241 0:15e49005d54e 704 * @warning The maximal distance depends on the scaling
mwilkens241 0:15e49005d54e 705 *
mwilkens241 0:15e49005d54e 706 * @return The maximal range limit for actual mode and scaling
mwilkens241 0:15e49005d54e 707 */
mwilkens241 0:15e49005d54e 708 uint16_t GetUpperLimit()
mwilkens241 0:15e49005d54e 709 {
mwilkens241 0:15e49005d54e 710 return VL6180x_GetUpperLimit(Device);
mwilkens241 0:15e49005d54e 711 }
mwilkens241 0:15e49005d54e 712
mwilkens241 0:15e49005d54e 713 /**
mwilkens241 0:15e49005d54e 714 * @brief Apply low and high ranging thresholds that are considered only in continuous mode
mwilkens241 0:15e49005d54e 715 *
mwilkens241 0:15e49005d54e 716 * @par Function Description
mwilkens241 0:15e49005d54e 717 * This function programs low and high ranging thresholds that are considered in continuous mode :
mwilkens241 0:15e49005d54e 718 * interrupt will be raised only when an object is detected at a distance inside this [low:high] range.
mwilkens241 0:15e49005d54e 719 * The function takes care of applying current scaling factor if any.\n
mwilkens241 0:15e49005d54e 720 * To be safe, in continuous operation, thresholds must be changed under "group parameter hold" cover.
mwilkens241 0:15e49005d54e 721 * Group hold can be activated/deactivated directly in the function or externally (then set 0)
mwilkens241 0:15e49005d54e 722 * using /a VL6180x_SetGroupParamHold() function.
mwilkens241 0:15e49005d54e 723 *
mwilkens241 0:15e49005d54e 724 * @param low Low threshold in mm
mwilkens241 0:15e49005d54e 725 * @param high High threshold in mm
mwilkens241 0:15e49005d54e 726 * @param SafeHold Use of group parameters hold to surround threshold programming.
mwilkens241 0:15e49005d54e 727 * @return 0 On success
mwilkens241 0:15e49005d54e 728 */
mwilkens241 0:15e49005d54e 729 int RangeSetThresholds(uint16_t low, uint16_t high, int SafeHold)
mwilkens241 0:15e49005d54e 730 {
mwilkens241 0:15e49005d54e 731 return VL6180x_RangeSetThresholds(Device, low, high, SafeHold);
mwilkens241 0:15e49005d54e 732 }
mwilkens241 0:15e49005d54e 733
mwilkens241 0:15e49005d54e 734 /**
mwilkens241 0:15e49005d54e 735 * @brief Get scaled high and low threshold from device
mwilkens241 0:15e49005d54e 736 *
mwilkens241 0:15e49005d54e 737 * @par Function Description
mwilkens241 0:15e49005d54e 738 * Due to scaling factor, the returned value may be different from what has been programmed first (precision lost).
mwilkens241 0:15e49005d54e 739 * For instance VL6180x_RangeSetThresholds(dev,11,22) with scale 3
mwilkens241 0:15e49005d54e 740 * will read back 9 ((11/3)x3) and 21 ((22/3)x3).
mwilkens241 0:15e49005d54e 741 *
mwilkens241 0:15e49005d54e 742 * @param low scaled low Threshold ptr can be NULL if not needed
mwilkens241 0:15e49005d54e 743 * @param high scaled High Threshold ptr can be NULL if not needed
mwilkens241 0:15e49005d54e 744 * @return 0 on success, return value is undefined if both low and high are NULL
mwilkens241 0:15e49005d54e 745 * @warning return value is undefined if both low and high are NULL
mwilkens241 0:15e49005d54e 746 */
mwilkens241 0:15e49005d54e 747 int RangeGetThresholds(uint16_t *low, uint16_t *high)
mwilkens241 0:15e49005d54e 748 {
mwilkens241 0:15e49005d54e 749 return VL6180x_RangeGetThresholds(Device, low, high);
mwilkens241 0:15e49005d54e 750 }
mwilkens241 0:15e49005d54e 751
mwilkens241 0:15e49005d54e 752 /**
mwilkens241 0:15e49005d54e 753 * @brief Set ranging raw thresholds (scaling not considered so not recommended to use it)
mwilkens241 0:15e49005d54e 754 *
mwilkens241 0:15e49005d54e 755 * @param low raw low threshold set to raw register
mwilkens241 0:15e49005d54e 756 * @param high raw high threshold set to raw register
mwilkens241 0:15e49005d54e 757 * @return 0 on success
mwilkens241 0:15e49005d54e 758 */
mwilkens241 0:15e49005d54e 759 int RangeSetRawThresholds(uint8_t low, uint8_t high)
mwilkens241 0:15e49005d54e 760 {
mwilkens241 0:15e49005d54e 761 return VL6180x_RangeSetRawThresholds(Device, low, high);
mwilkens241 0:15e49005d54e 762 }
mwilkens241 0:15e49005d54e 763
mwilkens241 0:15e49005d54e 764 /**
mwilkens241 0:15e49005d54e 765 * @brief Set Early Convergence Estimate ratio
mwilkens241 0:15e49005d54e 766 * @par Function Description
mwilkens241 0:15e49005d54e 767 * For more information on ECE check datasheet
mwilkens241 0:15e49005d54e 768 * @warning May return a calibration warning in some use cases
mwilkens241 0:15e49005d54e 769 *
mwilkens241 0:15e49005d54e 770 * @param FactorM ECE factor M in M/D
mwilkens241 0:15e49005d54e 771 * @param FactorD ECE factor D in M/D
mwilkens241 0:15e49005d54e 772 * @return 0 on success. <0 on error. >0 on warning
mwilkens241 0:15e49005d54e 773 */
mwilkens241 0:15e49005d54e 774 int RangeSetEceFactor(uint16_t FactorM, uint16_t FactorD)
mwilkens241 0:15e49005d54e 775 {
mwilkens241 0:15e49005d54e 776 return VL6180x_RangeSetEceFactor(Device, FactorM, FactorD);
mwilkens241 0:15e49005d54e 777 }
mwilkens241 0:15e49005d54e 778
mwilkens241 0:15e49005d54e 779 /**
mwilkens241 0:15e49005d54e 780 * @brief Set Early Convergence Estimate state (See #SYSRANGE_RANGE_CHECK_ENABLES register)
mwilkens241 0:15e49005d54e 781 * @param enable State to be set 0=disabled, otherwise enabled
mwilkens241 0:15e49005d54e 782 * @return 0 on success
mwilkens241 0:15e49005d54e 783 */
mwilkens241 0:15e49005d54e 784 int RangeSetEceState(int enable)
mwilkens241 0:15e49005d54e 785 {
mwilkens241 0:15e49005d54e 786 return VL6180x_RangeSetEceState(Device, enable);
mwilkens241 0:15e49005d54e 787 }
mwilkens241 0:15e49005d54e 788
mwilkens241 0:15e49005d54e 789 /**
mwilkens241 0:15e49005d54e 790 * @brief Set activation state of the wrap around filter
mwilkens241 0:15e49005d54e 791 * @param state New activation state (0=off, otherwise on)
mwilkens241 0:15e49005d54e 792 * @return 0 on success
mwilkens241 0:15e49005d54e 793 */
mwilkens241 0:15e49005d54e 794 int FilterSetState(int state)
mwilkens241 0:15e49005d54e 795 {
mwilkens241 0:15e49005d54e 796 return VL6180x_FilterSetState(Device, state);
mwilkens241 0:15e49005d54e 797 }
mwilkens241 0:15e49005d54e 798
mwilkens241 0:15e49005d54e 799 /**
mwilkens241 0:15e49005d54e 800 * Get activation state of the wrap around filter
mwilkens241 0:15e49005d54e 801 * @return Filter enabled or not, when filter is not supported it always returns 0S
mwilkens241 0:15e49005d54e 802 */
mwilkens241 0:15e49005d54e 803 int FilterGetState()
mwilkens241 0:15e49005d54e 804 {
mwilkens241 0:15e49005d54e 805 return VL6180x_FilterGetState(Device);
mwilkens241 0:15e49005d54e 806 }
mwilkens241 0:15e49005d54e 807
mwilkens241 0:15e49005d54e 808 /**
mwilkens241 0:15e49005d54e 809 * @brief Set activation state of DMax computation
mwilkens241 0:15e49005d54e 810 * @param state New activation state (0=off, otherwise on)
mwilkens241 0:15e49005d54e 811 * @return 0 on success
mwilkens241 0:15e49005d54e 812 */
mwilkens241 0:15e49005d54e 813 int DMaxSetState(int state)
mwilkens241 0:15e49005d54e 814 {
mwilkens241 0:15e49005d54e 815 return VL6180x_DMaxSetState(Device, state);
mwilkens241 0:15e49005d54e 816 }
mwilkens241 0:15e49005d54e 817
mwilkens241 0:15e49005d54e 818 /**
mwilkens241 0:15e49005d54e 819 * Get activation state of DMax computation
mwilkens241 0:15e49005d54e 820 * @return Filter enabled or not, when filter is not supported it always returns 0S
mwilkens241 0:15e49005d54e 821 */
mwilkens241 0:15e49005d54e 822 int DMaxGetState()
mwilkens241 0:15e49005d54e 823 {
mwilkens241 0:15e49005d54e 824 return VL6180x_DMaxGetState(Device);
mwilkens241 0:15e49005d54e 825 }
mwilkens241 0:15e49005d54e 826
mwilkens241 0:15e49005d54e 827 /**
mwilkens241 0:15e49005d54e 828 * @brief Set ranging mode and start/stop measure (use high level functions instead : @a VL6180x_RangeStartSingleShot() or @a VL6180x_RangeStartContinuousMode())
mwilkens241 0:15e49005d54e 829 *
mwilkens241 0:15e49005d54e 830 * @par Function Description
mwilkens241 0:15e49005d54e 831 * When used outside scope of known polling single shot stopped state, \n
mwilkens241 0:15e49005d54e 832 * user must ensure the device state is "idle" before to issue a new command.
mwilkens241 0:15e49005d54e 833 *
mwilkens241 0:15e49005d54e 834 * @param mode A combination of working mode (#MODE_SINGLESHOT or #MODE_CONTINUOUS) and start/stop condition (#MODE_START_STOP) \n
mwilkens241 0:15e49005d54e 835 * @return 0 on success
mwilkens241 0:15e49005d54e 836 */
mwilkens241 0:15e49005d54e 837 int RangeSetSystemMode(uint8_t mode)
mwilkens241 0:15e49005d54e 838 {
mwilkens241 0:15e49005d54e 839 return VL6180x_RangeSetSystemMode(Device, mode);
mwilkens241 0:15e49005d54e 840 }
mwilkens241 0:15e49005d54e 841
mwilkens241 0:15e49005d54e 842 /** @} */
mwilkens241 0:15e49005d54e 843
mwilkens241 0:15e49005d54e 844 /** @defgroup api_ll_range_calibration Ranging calibration functions
mwilkens241 0:15e49005d54e 845 * @brief Ranging calibration functions
mwilkens241 0:15e49005d54e 846 * @ingroup api_ll
mwilkens241 0:15e49005d54e 847 * @{
mwilkens241 0:15e49005d54e 848 */
mwilkens241 0:15e49005d54e 849 /**
mwilkens241 0:15e49005d54e 850 * @brief Get part to part calibration offset
mwilkens241 0:15e49005d54e 851 *
mwilkens241 0:15e49005d54e 852 * @par Function Description
mwilkens241 0:15e49005d54e 853 * Should only be used after a successful call to @a VL6180x_InitData to backup device nvm value
mwilkens241 0:15e49005d54e 854 *
mwilkens241 0:15e49005d54e 855 * @return part to part calibration offset from device
mwilkens241 0:15e49005d54e 856 */
mwilkens241 0:15e49005d54e 857 int8_t GetOffsetCalibrationData()
mwilkens241 0:15e49005d54e 858 {
mwilkens241 0:15e49005d54e 859 return VL6180x_GetOffsetCalibrationData(Device);
mwilkens241 0:15e49005d54e 860 }
mwilkens241 0:15e49005d54e 861
mwilkens241 0:15e49005d54e 862 /**
mwilkens241 0:15e49005d54e 863 * Set or over-write part to part calibration offset
mwilkens241 0:15e49005d54e 864 * \sa VL6180x_InitData(), VL6180x_GetOffsetCalibrationData()
mwilkens241 0:15e49005d54e 865 * @param offset Offset
mwilkens241 0:15e49005d54e 866 */
mwilkens241 0:15e49005d54e 867 void SetOffsetCalibrationData(int8_t offset)
mwilkens241 0:15e49005d54e 868 {
mwilkens241 0:15e49005d54e 869 return VL6180x_SetOffsetCalibrationData(Device, offset);
mwilkens241 0:15e49005d54e 870 }
mwilkens241 0:15e49005d54e 871
mwilkens241 0:15e49005d54e 872 /**
mwilkens241 0:15e49005d54e 873 * @brief Set Cross talk compensation rate
mwilkens241 0:15e49005d54e 874 *
mwilkens241 0:15e49005d54e 875 * @par Function Description
mwilkens241 0:15e49005d54e 876 * It programs register @a #SYSRANGE_CROSSTALK_COMPENSATION_RATE
mwilkens241 0:15e49005d54e 877 *
mwilkens241 0:15e49005d54e 878 * @param Rate Compensation rate (9.7 fix point) see datasheet for details
mwilkens241 0:15e49005d54e 879 * @return 0 on success
mwilkens241 0:15e49005d54e 880 */
mwilkens241 0:15e49005d54e 881 int SetXTalkCompensationRate(FixPoint97_t Rate)
mwilkens241 0:15e49005d54e 882 {
mwilkens241 0:15e49005d54e 883 return VL6180x_SetXTalkCompensationRate(Device, Rate);
mwilkens241 0:15e49005d54e 884 }
mwilkens241 0:15e49005d54e 885 /** @} */
mwilkens241 0:15e49005d54e 886
mwilkens241 0:15e49005d54e 887 /** @defgroup api_ll_als ALS functions
mwilkens241 0:15e49005d54e 888 * @brief ALS functions
mwilkens241 0:15e49005d54e 889 * @ingroup api_ll
mwilkens241 0:15e49005d54e 890 * @{
mwilkens241 0:15e49005d54e 891 */
mwilkens241 0:15e49005d54e 892
mwilkens241 0:15e49005d54e 893 /**
mwilkens241 0:15e49005d54e 894 * @brief Wait for device to be ready for new als operation or max pollign loop (time out)
mwilkens241 0:15e49005d54e 895 * @param MaxLoop Max Number of i2c polling loop see @a #msec_2_i2cloop
mwilkens241 0:15e49005d54e 896 * @return 0 on success. <0 when @a VL6180x_ErrCode_t::TIME_OUT if timed out
mwilkens241 0:15e49005d54e 897 */
mwilkens241 0:15e49005d54e 898 int AlsWaitDeviceReady(int MaxLoop)
mwilkens241 0:15e49005d54e 899 {
mwilkens241 0:15e49005d54e 900 return VL6180x_AlsWaitDeviceReady(Device, MaxLoop);
mwilkens241 0:15e49005d54e 901 }
mwilkens241 0:15e49005d54e 902
mwilkens241 0:15e49005d54e 903 /**
mwilkens241 0:15e49005d54e 904 * @brief Set ALS system mode and start/stop measure
mwilkens241 0:15e49005d54e 905 *
mwilkens241 0:15e49005d54e 906 * @warning When used outside after single shot polling, \n
mwilkens241 0:15e49005d54e 907 * User must ensure the device state is ready before issuing a new command (using @a VL6180x_AlsWaitDeviceReady()). \n
mwilkens241 0:15e49005d54e 908 * Non respect of this, can cause loss of interrupt or device hanging.
mwilkens241 0:15e49005d54e 909 *
mwilkens241 0:15e49005d54e 910 * @param mode A combination of working mode (#MODE_SINGLESHOT or #MODE_CONTINUOUS) and start condition (#MODE_START_STOP) \n
mwilkens241 0:15e49005d54e 911 * @return 0 on success
mwilkens241 0:15e49005d54e 912 */
mwilkens241 0:15e49005d54e 913 int AlsSetSystemMode(uint8_t mode)
mwilkens241 0:15e49005d54e 914 {
mwilkens241 0:15e49005d54e 915 return VL6180x_AlsSetSystemMode(Device, mode);
mwilkens241 0:15e49005d54e 916 }
mwilkens241 0:15e49005d54e 917
mwilkens241 0:15e49005d54e 918 /** @defgroup api_ll_misc Misc functions
mwilkens241 0:15e49005d54e 919 * @brief Misc functions
mwilkens241 0:15e49005d54e 920 * @ingroup api_ll
mwilkens241 0:15e49005d54e 921 * @{
mwilkens241 0:15e49005d54e 922 */
mwilkens241 0:15e49005d54e 923
mwilkens241 0:15e49005d54e 924 /**
mwilkens241 0:15e49005d54e 925 * Set Group parameter Hold state
mwilkens241 0:15e49005d54e 926 *
mwilkens241 0:15e49005d54e 927 * @par Function Description
mwilkens241 0:15e49005d54e 928 * Group parameter holds @a #SYSTEM_GROUPED_PARAMETER_HOLD enable safe update (non atomic across multiple measure) by host
mwilkens241 0:15e49005d54e 929 * \n The critical register group is composed of: \n
mwilkens241 0:15e49005d54e 930 * #SYSTEM_INTERRUPT_CONFIG_GPIO \n
mwilkens241 0:15e49005d54e 931 * #SYSRANGE_THRESH_HIGH \n
mwilkens241 0:15e49005d54e 932 * #SYSRANGE_THRESH_LOW \n
mwilkens241 0:15e49005d54e 933 * #SYSALS_INTEGRATION_PERIOD \n
mwilkens241 0:15e49005d54e 934 * #SYSALS_ANALOGUE_GAIN \n
mwilkens241 0:15e49005d54e 935 * #SYSALS_THRESH_HIGH \n
mwilkens241 0:15e49005d54e 936 * #SYSALS_THRESH_LOW
mwilkens241 0:15e49005d54e 937 *
mwilkens241 0:15e49005d54e 938 *
mwilkens241 0:15e49005d54e 939 * @param Hold Group parameter Hold state to be set (on/off)
mwilkens241 0:15e49005d54e 940 * @return 0 on success
mwilkens241 0:15e49005d54e 941 */
mwilkens241 0:15e49005d54e 942 int SetGroupParamHold(int Hold)
mwilkens241 0:15e49005d54e 943 {
mwilkens241 0:15e49005d54e 944 return VL6180x_SetGroupParamHold(Device, Hold);
mwilkens241 0:15e49005d54e 945 }
mwilkens241 0:15e49005d54e 946
mwilkens241 0:15e49005d54e 947 /**
mwilkens241 0:15e49005d54e 948 * @brief Set new device i2c address
mwilkens241 0:15e49005d54e 949 *
mwilkens241 0:15e49005d54e 950 * After completion the device will answer to the new address programmed.
mwilkens241 0:15e49005d54e 951 *
mwilkens241 0:15e49005d54e 952 * @sa AN4478: Using multiple VL6180X's in a single design
mwilkens241 0:15e49005d54e 953 * @param NewAddr The new i2c address (7bit)
mwilkens241 0:15e49005d54e 954 * @return 0 on success
mwilkens241 0:15e49005d54e 955 */
mwilkens241 0:15e49005d54e 956 int SetI2CAddress(int NewAddr)
mwilkens241 0:15e49005d54e 957 {
mwilkens241 0:15e49005d54e 958 int status;
mwilkens241 0:15e49005d54e 959
mwilkens241 0:15e49005d54e 960 status=VL6180x_SetI2CAddress(Device, NewAddr);
mwilkens241 0:15e49005d54e 961 if(!status)
mwilkens241 0:15e49005d54e 962 Device->I2cAddr=NewAddr;
mwilkens241 0:15e49005d54e 963 return status;
mwilkens241 0:15e49005d54e 964 }
mwilkens241 0:15e49005d54e 965
mwilkens241 0:15e49005d54e 966 /**
mwilkens241 0:15e49005d54e 967 * @brief Fully configure gpio 0/1 pin : polarity and functionality
mwilkens241 0:15e49005d54e 968 *
mwilkens241 0:15e49005d54e 969 * @param pin gpio pin 0 or 1
mwilkens241 0:15e49005d54e 970 * @param IntFunction Pin functionality : either #GPIOx_SELECT_OFF or #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT (refer to #SYSTEM_MODE_GPIO1 register definition)
mwilkens241 0:15e49005d54e 971 * @param ActiveHigh Set active high polarity, or active low see @a ::IntrPol_e
mwilkens241 0:15e49005d54e 972 * @return 0 on success
mwilkens241 0:15e49005d54e 973 */
mwilkens241 0:15e49005d54e 974 int SetupGPIOx(int pin, uint8_t IntFunction, int ActiveHigh)
mwilkens241 0:15e49005d54e 975 {
mwilkens241 0:15e49005d54e 976 return VL6180x_SetupGPIOx(Device, pin, IntFunction, ActiveHigh);
mwilkens241 0:15e49005d54e 977 }
mwilkens241 0:15e49005d54e 978
mwilkens241 0:15e49005d54e 979 /**
mwilkens241 0:15e49005d54e 980 * @brief Set interrupt pin polarity for the given GPIO
mwilkens241 0:15e49005d54e 981 *
mwilkens241 0:15e49005d54e 982 * @param pin Pin 0 or 1
mwilkens241 0:15e49005d54e 983 * @param active_high select active high or low polarity using @ref IntrPol_e
mwilkens241 0:15e49005d54e 984 * @return 0 on success
mwilkens241 0:15e49005d54e 985 */
mwilkens241 0:15e49005d54e 986 int SetGPIOxPolarity(int pin, int active_high)
mwilkens241 0:15e49005d54e 987 {
mwilkens241 0:15e49005d54e 988 return VL6180x_SetGPIOxPolarity(Device, pin, active_high);
mwilkens241 0:15e49005d54e 989 }
mwilkens241 0:15e49005d54e 990
mwilkens241 0:15e49005d54e 991 /**
mwilkens241 0:15e49005d54e 992 * Select interrupt functionality for the given GPIO
mwilkens241 0:15e49005d54e 993 *
mwilkens241 0:15e49005d54e 994 * @par Function Description
mwilkens241 0:15e49005d54e 995 * Functionality refer to @a SYSTEM_MODE_GPIO0
mwilkens241 0:15e49005d54e 996 *
mwilkens241 0:15e49005d54e 997 * @param pin Pin to configure 0 or 1 (gpio0 or gpio1)\nNote that gpio0 is chip enable at power up !
mwilkens241 0:15e49005d54e 998 * @param functionality Pin functionality : either #GPIOx_SELECT_OFF or #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT (refer to #SYSTEM_MODE_GPIO1 register definition)
mwilkens241 0:15e49005d54e 999 * @return 0 on success
mwilkens241 0:15e49005d54e 1000 */
mwilkens241 0:15e49005d54e 1001 int SetGPIOxFunctionality(int pin, uint8_t functionality)
mwilkens241 0:15e49005d54e 1002 {
mwilkens241 0:15e49005d54e 1003 return VL6180x_SetGPIOxFunctionality(Device, pin, functionality);
mwilkens241 0:15e49005d54e 1004 }
mwilkens241 0:15e49005d54e 1005
mwilkens241 0:15e49005d54e 1006 /**
mwilkens241 0:15e49005d54e 1007 * #brief Disable and turn to Hi-Z gpio output pin
mwilkens241 0:15e49005d54e 1008 *
mwilkens241 0:15e49005d54e 1009 * @param pin The pin number to disable 0 or 1
mwilkens241 0:15e49005d54e 1010 * @return 0 on success
mwilkens241 0:15e49005d54e 1011 */
mwilkens241 0:15e49005d54e 1012 int DisableGPIOxOut(int pin)
mwilkens241 0:15e49005d54e 1013 {
mwilkens241 0:15e49005d54e 1014 return VL6180x_DisableGPIOxOut(Device, pin);
mwilkens241 0:15e49005d54e 1015 }
mwilkens241 0:15e49005d54e 1016
mwilkens241 0:15e49005d54e 1017 /** @} */
mwilkens241 0:15e49005d54e 1018
mwilkens241 0:15e49005d54e 1019 /** @defgroup api_ll_intr Interrupts management functions
mwilkens241 0:15e49005d54e 1020 * @brief Interrupts management functions
mwilkens241 0:15e49005d54e 1021 * @ingroup api_ll
mwilkens241 0:15e49005d54e 1022 * @{
mwilkens241 0:15e49005d54e 1023 */
mwilkens241 0:15e49005d54e 1024
mwilkens241 0:15e49005d54e 1025 /**
mwilkens241 0:15e49005d54e 1026 * @brief Get all interrupts cause
mwilkens241 0:15e49005d54e 1027 *
mwilkens241 0:15e49005d54e 1028 * @param status Ptr to interrupt status. You can use @a IntrStatus_t::val
mwilkens241 0:15e49005d54e 1029 * @return 0 on success
mwilkens241 0:15e49005d54e 1030 */
mwilkens241 0:15e49005d54e 1031 int GetInterruptStatus(uint8_t *status)
mwilkens241 0:15e49005d54e 1032 {
mwilkens241 0:15e49005d54e 1033 return VL6180x_GetInterruptStatus(Device, status);
mwilkens241 0:15e49005d54e 1034 }
mwilkens241 0:15e49005d54e 1035
mwilkens241 0:15e49005d54e 1036 /**
mwilkens241 0:15e49005d54e 1037 * @brief Clear given system interrupt condition
mwilkens241 0:15e49005d54e 1038 *
mwilkens241 0:15e49005d54e 1039 * @par Function Description
mwilkens241 0:15e49005d54e 1040 * Clear given interrupt cause by writing into register #SYSTEM_INTERRUPT_CLEAR register.
mwilkens241 0:15e49005d54e 1041 * @param dev The device
mwilkens241 0:15e49005d54e 1042 * @param IntClear Which interrupt source to clear. Use any combinations of #INTERRUPT_CLEAR_RANGING , #INTERRUPT_CLEAR_ALS , #INTERRUPT_CLEAR_ERROR.
mwilkens241 0:15e49005d54e 1043 * @return 0 On success
mwilkens241 0:15e49005d54e 1044 */
mwilkens241 0:15e49005d54e 1045 int ClearInterrupt(uint8_t IntClear)
mwilkens241 0:15e49005d54e 1046 {
mwilkens241 0:15e49005d54e 1047 return VL6180x_ClearInterrupt(Device, IntClear );
mwilkens241 0:15e49005d54e 1048 }
mwilkens241 0:15e49005d54e 1049
mwilkens241 0:15e49005d54e 1050 /**
mwilkens241 0:15e49005d54e 1051 * @brief Clear error interrupt
mwilkens241 0:15e49005d54e 1052 *
mwilkens241 0:15e49005d54e 1053 * @param dev The device
mwilkens241 0:15e49005d54e 1054 * @return 0 On success
mwilkens241 0:15e49005d54e 1055 */
mwilkens241 0:15e49005d54e 1056 #define VL6180x_ClearErrorInterrupt(dev) VL6180x_ClearInterrupt(dev, INTERRUPT_CLEAR_ERROR)
mwilkens241 0:15e49005d54e 1057
mwilkens241 0:15e49005d54e 1058 /**
mwilkens241 0:15e49005d54e 1059 * @brief Clear All interrupt causes (als+range+error)
mwilkens241 0:15e49005d54e 1060 *
mwilkens241 0:15e49005d54e 1061 * @param dev The device
mwilkens241 0:15e49005d54e 1062 * @return 0 On success
mwilkens241 0:15e49005d54e 1063 */
mwilkens241 0:15e49005d54e 1064 #define VL6180x_ClearAllInterrupt(dev) VL6180x_ClearInterrupt(dev, INTERRUPT_CLEAR_ERROR|INTERRUPT_CLEAR_RANGING|INTERRUPT_CLEAR_ALS)
mwilkens241 0:15e49005d54e 1065
mwilkens241 0:15e49005d54e 1066 /** @} */
mwilkens241 0:15e49005d54e 1067
mwilkens241 0:15e49005d54e 1068 /**
mwilkens241 0:15e49005d54e 1069 * @brief Get a single light (in Lux) measure result
mwilkens241 0:15e49005d54e 1070 *
mwilkens241 0:15e49005d54e 1071 * @par Function Description
mwilkens241 0:15e49005d54e 1072 * It can be called after having initialized a component. It start a single
mwilkens241 0:15e49005d54e 1073 * light measure in polling mode and wait until the measure is finisched.
mwilkens241 0:15e49005d54e 1074 * The function block until the measure is finished, it can blocks indefinitely
mwilkens241 0:15e49005d54e 1075 * in case the measure never ends for any reason \n
mwilkens241 0:15e49005d54e 1076 */
mwilkens241 0:15e49005d54e 1077 virtual int GetLux(uint32_t *piData)
mwilkens241 0:15e49005d54e 1078 {
mwilkens241 0:15e49005d54e 1079 int status=0;
mwilkens241 0:15e49005d54e 1080 LOG_FUNCTION_START("");
mwilkens241 0:15e49005d54e 1081 status=StartMeasurement(als_single_shot_polling, NULL, NULL, NULL);
mwilkens241 0:15e49005d54e 1082 if (!status) {
mwilkens241 0:15e49005d54e 1083 AlsWaitDeviceReady(2000);
mwilkens241 0:15e49005d54e 1084 for (status=1;
mwilkens241 0:15e49005d54e 1085 status!=0;
mwilkens241 0:15e49005d54e 1086 status=VL6180x_AlsGetLux(Device, piData));
mwilkens241 0:15e49005d54e 1087 }
mwilkens241 0:15e49005d54e 1088 StopMeasurement(als_single_shot_polling);
mwilkens241 0:15e49005d54e 1089 AlsWaitDeviceReady(2000);
mwilkens241 0:15e49005d54e 1090 LOG_FUNCTION_END(status);
mwilkens241 0:15e49005d54e 1091 return status;
mwilkens241 0:15e49005d54e 1092 }
mwilkens241 0:15e49005d54e 1093
mwilkens241 0:15e49005d54e 1094 /**
mwilkens241 0:15e49005d54e 1095 * @brief Start the ALS (light) measure in continous mode
mwilkens241 0:15e49005d54e 1096 *
mwilkens241 0:15e49005d54e 1097 * @par Function Description
mwilkens241 0:15e49005d54e 1098 * Start the ALS (light) measure in continous mode
mwilkens241 0:15e49005d54e 1099 * @return 0 On success
mwilkens241 0:15e49005d54e 1100 */
mwilkens241 0:15e49005d54e 1101 int AlsStartContinuousMode()
mwilkens241 0:15e49005d54e 1102 {
mwilkens241 0:15e49005d54e 1103 return VL6180x_AlsSetSystemMode(Device, MODE_START_STOP|MODE_CONTINUOUS);
mwilkens241 0:15e49005d54e 1104 }
mwilkens241 0:15e49005d54e 1105
mwilkens241 0:15e49005d54e 1106 /**
mwilkens241 0:15e49005d54e 1107 * @brief Start the ALS (light) measure in single shot mode
mwilkens241 0:15e49005d54e 1108 *
mwilkens241 0:15e49005d54e 1109 * @par Function Description
mwilkens241 0:15e49005d54e 1110 * Start the ALS (light) measure in single shot mode
mwilkens241 0:15e49005d54e 1111 * @return 0 On success
mwilkens241 0:15e49005d54e 1112 */
mwilkens241 0:15e49005d54e 1113 int AlsStartSingleShot()
mwilkens241 0:15e49005d54e 1114 {
mwilkens241 0:15e49005d54e 1115 return VL6180x_AlsSetSystemMode(Device, MODE_START_STOP|MODE_SINGLESHOT);
mwilkens241 0:15e49005d54e 1116 }
mwilkens241 0:15e49005d54e 1117
mwilkens241 0:15e49005d54e 1118 private:
mwilkens241 0:15e49005d54e 1119 /* api.h functions */
mwilkens241 0:15e49005d54e 1120 int VL6180x_WaitDeviceBooted(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1121 int VL6180x_InitData(VL6180xDev_t dev );
mwilkens241 0:15e49005d54e 1122 int VL6180x_SetupGPIO1(VL6180xDev_t dev, uint8_t IntFunction, int ActiveHigh);
mwilkens241 0:15e49005d54e 1123 int VL6180x_Prepare(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1124 int VL6180x_RangeStartContinuousMode(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1125 int VL6180x_RangeStartSingleShot(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1126 int VL6180x_RangeSetMaxConvergenceTime(VL6180xDev_t dev, uint8_t MaxConTime_msec);
mwilkens241 0:15e49005d54e 1127 int VL6180x_RangePollMeasurement(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
mwilkens241 0:15e49005d54e 1128 int VL6180x_RangeGetMeasurementIfReady(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
mwilkens241 0:15e49005d54e 1129 int VL6180x_RangeGetMeasurement(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
mwilkens241 0:15e49005d54e 1130 int VL6180x_RangeGetResult(VL6180xDev_t dev, uint32_t *pRange_mm);
mwilkens241 0:15e49005d54e 1131 int VL6180x_RangeConfigInterrupt(VL6180xDev_t dev, uint8_t ConfigGpioInt);
mwilkens241 0:15e49005d54e 1132 int VL6180x_RangeGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus);
mwilkens241 0:15e49005d54e 1133 int VL6180x_AlsPollMeasurement(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData);
mwilkens241 0:15e49005d54e 1134 int VL6180x_AlsGetMeasurement(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData);
mwilkens241 0:15e49005d54e 1135 int VL6180x_AlsConfigInterrupt(VL6180xDev_t dev, uint8_t ConfigGpioInt);
mwilkens241 0:15e49005d54e 1136 int VL6180x_AlsSetIntegrationPeriod(VL6180xDev_t dev, uint16_t period_ms);
mwilkens241 0:15e49005d54e 1137 int VL6180x_AlsSetInterMeasurementPeriod(VL6180xDev_t dev, uint16_t intermeasurement_period_ms);
mwilkens241 0:15e49005d54e 1138 int VL6180x_AlsSetAnalogueGain(VL6180xDev_t dev, uint8_t gain);
mwilkens241 0:15e49005d54e 1139 int VL6180x_AlsSetThresholds(VL6180xDev_t dev, uint16_t low, uint16_t high);
mwilkens241 0:15e49005d54e 1140 int VL6180x_AlsGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus);
mwilkens241 0:15e49005d54e 1141 int VL6180x_StaticInit(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1142 int VL6180x_RangeWaitDeviceReady(VL6180xDev_t dev, int MaxLoop );
mwilkens241 0:15e49005d54e 1143 int VL6180x_RangeSetInterMeasPeriod(VL6180xDev_t dev, uint32_t InterMeasTime_msec);
mwilkens241 0:15e49005d54e 1144 int VL6180x_UpscaleSetScaling(VL6180xDev_t dev, uint8_t scaling);
mwilkens241 0:15e49005d54e 1145 int VL6180x_UpscaleGetScaling(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1146 uint16_t VL6180x_GetUpperLimit(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1147 int VL6180x_RangeSetThresholds(VL6180xDev_t dev, uint16_t low, uint16_t high, int SafeHold);
mwilkens241 0:15e49005d54e 1148 int VL6180x_RangeGetThresholds(VL6180xDev_t dev, uint16_t *low, uint16_t *high);
mwilkens241 0:15e49005d54e 1149 int VL6180x_RangeSetRawThresholds(VL6180xDev_t dev, uint8_t low, uint8_t high);
mwilkens241 0:15e49005d54e 1150 int VL6180x_RangeSetEceFactor(VL6180xDev_t dev, uint16_t FactorM, uint16_t FactorD);
mwilkens241 0:15e49005d54e 1151 int VL6180x_RangeSetEceState(VL6180xDev_t dev, int enable );
mwilkens241 0:15e49005d54e 1152 int VL6180x_FilterSetState(VL6180xDev_t dev, int state);
mwilkens241 0:15e49005d54e 1153 int VL6180x_FilterGetState(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1154 int VL6180x_DMaxSetState(VL6180xDev_t dev, int state);
mwilkens241 0:15e49005d54e 1155 int VL6180x_DMaxGetState(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1156 int VL6180x_RangeSetSystemMode(VL6180xDev_t dev, uint8_t mode);
mwilkens241 0:15e49005d54e 1157 int8_t VL6180x_GetOffsetCalibrationData(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1158 void VL6180x_SetOffsetCalibrationData(VL6180xDev_t dev, int8_t offset);
mwilkens241 0:15e49005d54e 1159 int VL6180x_SetXTalkCompensationRate(VL6180xDev_t dev, FixPoint97_t Rate);
mwilkens241 0:15e49005d54e 1160 int VL6180x_AlsWaitDeviceReady(VL6180xDev_t dev, int MaxLoop );
mwilkens241 0:15e49005d54e 1161 int VL6180x_AlsSetSystemMode(VL6180xDev_t dev, uint8_t mode);
mwilkens241 0:15e49005d54e 1162 int VL6180x_SetGroupParamHold(VL6180xDev_t dev, int Hold);
mwilkens241 0:15e49005d54e 1163 int VL6180x_SetI2CAddress(VL6180xDev_t dev, uint8_t NewAddr);
mwilkens241 0:15e49005d54e 1164 int VL6180x_SetupGPIOx(VL6180xDev_t dev, int pin, uint8_t IntFunction, int ActiveHigh);
mwilkens241 0:15e49005d54e 1165 int VL6180x_SetGPIOxPolarity(VL6180xDev_t dev, int pin, int active_high);
mwilkens241 0:15e49005d54e 1166 int VL6180x_SetGPIOxFunctionality(VL6180xDev_t dev, int pin, uint8_t functionality);
mwilkens241 0:15e49005d54e 1167 int VL6180x_DisableGPIOxOut(VL6180xDev_t dev, int pin);
mwilkens241 0:15e49005d54e 1168 int VL6180x_GetInterruptStatus(VL6180xDev_t dev, uint8_t *status);
mwilkens241 0:15e49005d54e 1169 int VL6180x_ClearInterrupt(VL6180xDev_t dev, uint8_t IntClear );
mwilkens241 0:15e49005d54e 1170
mwilkens241 0:15e49005d54e 1171 /* Other functions defined in api.c */
mwilkens241 0:15e49005d54e 1172 int VL6180x_RangeStaticInit(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1173 int VL6180x_UpscaleRegInit(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1174 int VL6180x_UpscaleStaticInit(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1175 int VL6180x_AlsGetLux(VL6180xDev_t dev, lux_t *pLux);
mwilkens241 0:15e49005d54e 1176 int _UpscaleInitPatch0(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1177 int VL6180x_RangeGetDeviceReady(VL6180xDev_t dev, int * Ready);
mwilkens241 0:15e49005d54e 1178 int VL6180x_RangeSetEarlyConvergenceEestimateThreshold(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1179 int32_t _GetAveTotalTime(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1180 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);
mwilkens241 0:15e49005d54e 1181 int _filter_GetResult(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
mwilkens241 0:15e49005d54e 1182 int _GetRateResult(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
mwilkens241 0:15e49005d54e 1183 int _DMax_InitData(VL6180xDev_t dev);
mwilkens241 0:15e49005d54e 1184
mwilkens241 0:15e49005d54e 1185 /* Read function of the ID device */
mwilkens241 0:15e49005d54e 1186 virtual int ReadID(uint8_t *id);
mwilkens241 0:15e49005d54e 1187
mwilkens241 0:15e49005d54e 1188 /* Write and read functions from I2C */
mwilkens241 0:15e49005d54e 1189 int VL6180x_WrByte(VL6180xDev_t dev, uint16_t index, uint8_t data);
mwilkens241 0:15e49005d54e 1190 int VL6180x_WrWord(VL6180xDev_t dev, uint16_t index, uint16_t data);
mwilkens241 0:15e49005d54e 1191 int VL6180x_WrDWord(VL6180xDev_t dev, uint16_t index, uint32_t data);
mwilkens241 0:15e49005d54e 1192 int VL6180x_RdByte(VL6180xDev_t dev, uint16_t index, uint8_t *data);
mwilkens241 0:15e49005d54e 1193 int VL6180x_RdWord(VL6180xDev_t dev, uint16_t index, uint16_t *data);
mwilkens241 0:15e49005d54e 1194 int VL6180x_RdDWord(VL6180xDev_t dev, uint16_t index, uint32_t *data);
mwilkens241 0:15e49005d54e 1195 int VL6180x_UpdateByte(VL6180xDev_t dev, uint16_t index, uint8_t AndData, uint8_t OrData);
mwilkens241 0:15e49005d54e 1196 int VL6180x_I2CWrite(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t *pBuffer, uint16_t NumByteToWrite);
mwilkens241 0:15e49005d54e 1197 int VL6180x_I2CRead(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t *pBuffer, uint16_t NumByteToRead);
mwilkens241 0:15e49005d54e 1198
mwilkens241 0:15e49005d54e 1199 int IsPresent();
mwilkens241 0:15e49005d54e 1200 int StopRangeMeasurement(OperatingMode operating_mode);
mwilkens241 0:15e49005d54e 1201 int StopAlsMeasurement(OperatingMode operating_mode);
mwilkens241 0:15e49005d54e 1202 int GetRangeMeas(OperatingMode operating_mode, MeasureData_t *Data);
mwilkens241 0:15e49005d54e 1203 int GetAlsMeas(OperatingMode operating_mode, MeasureData_t *Data);
mwilkens241 0:15e49005d54e 1204 int GetRangeAlsMeas(MeasureData_t *Data);
mwilkens241 0:15e49005d54e 1205 int RangeSetLowThreshold(uint16_t threshold);
mwilkens241 0:15e49005d54e 1206 int RangeSetHighThreshold(uint16_t threshold);
mwilkens241 0:15e49005d54e 1207 int AlsSetLowThreshold(uint16_t threshold);
mwilkens241 0:15e49005d54e 1208 int AlsSetHighThreshold(uint16_t threshold);
mwilkens241 0:15e49005d54e 1209 int GetRangeError(MeasureData_t *Data, VL6180x_RangeData_t RangeData);
mwilkens241 0:15e49005d54e 1210 int GetAlsError(MeasureData_t *Data, VL6180x_AlsData_t AlsData);
mwilkens241 0:15e49005d54e 1211 int RangeMeasPollSingleShot();
mwilkens241 0:15e49005d54e 1212 int AlsMeasPollSingleShot();
mwilkens241 0:15e49005d54e 1213 int RangeMeasPollContinuousMode();
mwilkens241 0:15e49005d54e 1214 int AlsMeasPollContinuousMode();
mwilkens241 0:15e49005d54e 1215 int AlsGetMeasurementIfReady(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData);
mwilkens241 0:15e49005d54e 1216 int RangeMeasIntContinuousMode(void (*fptr)(void));
mwilkens241 0:15e49005d54e 1217 int AlsMeasIntContinuousMode(void (*fptr)(void));
mwilkens241 0:15e49005d54e 1218 int InterleavedMode(void (*fptr)(void));
mwilkens241 0:15e49005d54e 1219 int StartInterleavedMode();
mwilkens241 0:15e49005d54e 1220 int AlsGetThresholds(VL6180xDev_t dev, lux_t *low, lux_t *high);
mwilkens241 0:15e49005d54e 1221
mwilkens241 0:15e49005d54e 1222
mwilkens241 0:15e49005d54e 1223 /* IO Device */
mwilkens241 0:15e49005d54e 1224 DevI2C &dev_i2c;
mwilkens241 0:15e49005d54e 1225 /* Digital out pin */
mwilkens241 0:15e49005d54e 1226 DigitalOut *gpio0;
mwilkens241 0:15e49005d54e 1227 /* Measure detection IRQ */
mwilkens241 0:15e49005d54e 1228 InterruptIn *gpio1Int;
mwilkens241 0:15e49005d54e 1229 /* Device data */
mwilkens241 0:15e49005d54e 1230 MyVL6180Dev_t MyDevice;
mwilkens241 0:15e49005d54e 1231 VL6180xDev_t Device;
mwilkens241 0:15e49005d54e 1232 };
mwilkens241 0:15e49005d54e 1233
mwilkens241 0:15e49005d54e 1234 #endif // __VL6180X_CLASS_H