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