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