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