Line Health / VL6180
Committer:
mwilkens241
Date:
Wed Mar 22 20:55:05 2017 +0000
Revision:
1:af4be6eecff0
Parent:
0:15e49005d54e
Child:
2:40f590e28101
beginning to add mux

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