laser library

Committer:
mwilkens241
Date:
Fri Mar 31 15:49:47 2017 +0000
Revision:
2:40f590e28101
Parent:
1:af4be6eecff0
stole some things out of here, not much changed

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