The VL53L1CB proximity sensor, based on ST’s FlightSense™, Time-of-Flight technology.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: VL53L1CB_noshield_1sensor_polls_auton VL53L1CB_noshield_1sensor_interrupt_auton X_NUCLEO_53L1A2
Based on VL53L1 library, this is a library for the VL53L1CB ToF chip.
inc/VL53l1CB.h@10:3687b5e79f98, 2021-06-09 (annotated)
- Committer:
- Charles MacNeill
- Date:
- Wed Jun 09 10:09:49 2021 +0100
- Revision:
- 10:3687b5e79f98
- Parent:
- 9:66969b9016ad
change vl53l1 to VBL53L1CB
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Charles MacNeill |
9:66969b9016ad | 1 | /******************************************************************************* |
Charles MacNeill |
9:66969b9016ad | 2 | * @file vl53l1x_class.h |
Charles MacNeill |
9:66969b9016ad | 3 | * @author JS |
Charles MacNeill |
9:66969b9016ad | 4 | * @version V0.0.1 |
Charles MacNeill |
9:66969b9016ad | 5 | * @date 15-January-2019 |
Charles MacNeill |
9:66969b9016ad | 6 | * @brief Header file for VL53L1 sensor component |
Charles MacNeill |
9:66969b9016ad | 7 | ****************************************************************************** |
Charles MacNeill |
9:66969b9016ad | 8 | Copyright © 2019, STMicroelectronics International N.V. |
Charles MacNeill |
9:66969b9016ad | 9 | All rights reserved. |
Charles MacNeill |
9:66969b9016ad | 10 | Redistribution and use in source and binary forms, with or without |
Charles MacNeill |
9:66969b9016ad | 11 | modification, are permitted provided that the following conditions are met: |
Charles MacNeill |
9:66969b9016ad | 12 | * Redistributions of source code must retain the above copyright |
Charles MacNeill |
9:66969b9016ad | 13 | notice, this list of conditions and the following disclaimer. |
Charles MacNeill |
9:66969b9016ad | 14 | * Redistributions in binary form must reproduce the above copyright |
Charles MacNeill |
9:66969b9016ad | 15 | notice, this list of conditions and the following disclaimer in the |
Charles MacNeill |
9:66969b9016ad | 16 | documentation and/or other materials provided with the distribution. |
Charles MacNeill |
9:66969b9016ad | 17 | * Neither the name of STMicroelectronics nor the |
Charles MacNeill |
9:66969b9016ad | 18 | names of its contributors may be used to endorse or promote products |
Charles MacNeill |
9:66969b9016ad | 19 | derived from this software without specific prior written permission. |
Charles MacNeill |
9:66969b9016ad | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Charles MacNeill |
9:66969b9016ad | 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Charles MacNeill |
9:66969b9016ad | 22 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND |
Charles MacNeill |
9:66969b9016ad | 23 | NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED. |
Charles MacNeill |
9:66969b9016ad | 24 | IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY |
Charles MacNeill |
9:66969b9016ad | 25 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Charles MacNeill |
9:66969b9016ad | 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Charles MacNeill |
9:66969b9016ad | 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
Charles MacNeill |
9:66969b9016ad | 28 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Charles MacNeill |
9:66969b9016ad | 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Charles MacNeill |
9:66969b9016ad | 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Charles MacNeill |
9:66969b9016ad | 31 | *****************************************************************************/ |
Charles MacNeill |
9:66969b9016ad | 32 | |
Charles MacNeill |
9:66969b9016ad | 33 | #ifndef __VL53L1X_CLASS_H |
Charles MacNeill |
9:66969b9016ad | 34 | #define __VL53L1X_CLASS_H |
Charles MacNeill |
9:66969b9016ad | 35 | |
Charles MacNeill |
9:66969b9016ad | 36 | |
Charles MacNeill |
9:66969b9016ad | 37 | |
Charles MacNeill |
9:66969b9016ad | 38 | /* Includes ------------------------------------------------------------------*/ |
Charles MacNeill |
9:66969b9016ad | 39 | |
Charles MacNeill |
9:66969b9016ad | 40 | #include "mbed.h" |
Charles MacNeill |
9:66969b9016ad | 41 | #include "PinNames.h" |
Charles MacNeill |
9:66969b9016ad | 42 | |
Charles MacNeill |
9:66969b9016ad | 43 | #include "RangeSensor.h" |
Charles MacNeill |
9:66969b9016ad | 44 | #include "Stmpe1600.h" |
Charles MacNeill |
9:66969b9016ad | 45 | |
Charles MacNeill |
9:66969b9016ad | 46 | #include "vl53l1_error_codes.h" |
Charles MacNeill |
9:66969b9016ad | 47 | #include "vl53l1_platform_user_data.h" |
Charles MacNeill |
9:66969b9016ad | 48 | |
Charles MacNeill |
9:66969b9016ad | 49 | //#include "DevI2C.h" |
Charles MacNeill |
9:66969b9016ad | 50 | #include "ToF_I2C.h" |
Charles MacNeill |
9:66969b9016ad | 51 | /**********************************************************/ |
Charles MacNeill |
9:66969b9016ad | 52 | #include "vl53l1_def.h" |
Charles MacNeill |
9:66969b9016ad | 53 | /***********************************************************/ |
Charles MacNeill |
9:66969b9016ad | 54 | |
Charles MacNeill |
9:66969b9016ad | 55 | |
Charles MacNeill |
10:3687b5e79f98 | 56 | #define VL53L1CB_IMPLEMENTATION_VER_MAJOR 1 |
Charles MacNeill |
10:3687b5e79f98 | 57 | #define VL53L1CB_IMPLEMENTATION_VER_MINOR 0 |
Charles MacNeill |
10:3687b5e79f98 | 58 | #define VL53L1CB_IMPLEMENTATION_VER_SUB 1 |
Charles MacNeill |
10:3687b5e79f98 | 59 | #define VL53L1CB_IMPLEMENTATION_VER_REVISION 0000 |
Charles MacNeill |
9:66969b9016ad | 60 | |
Charles MacNeill |
10:3687b5e79f98 | 61 | typedef int8_t VL53L1CB_ERROR; |
Charles MacNeill |
9:66969b9016ad | 62 | |
Charles MacNeill |
9:66969b9016ad | 63 | //#define SOFT_RESET 0x0000 |
Charles MacNeill |
10:3687b5e79f98 | 64 | #define VL53L1CB_I2C_SLAVE__DEVICE_ADDRESS 0x0001 |
Charles MacNeill |
10:3687b5e79f98 | 65 | #define VL53L1CB_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND 0x0008 |
Charles MacNeill |
9:66969b9016ad | 66 | #define ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS 0x0016 |
Charles MacNeill |
9:66969b9016ad | 67 | #define ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS 0x0018 |
Charles MacNeill |
9:66969b9016ad | 68 | #define ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS 0x001A |
Charles MacNeill |
9:66969b9016ad | 69 | #define ALGO__PART_TO_PART_RANGE_OFFSET_MM 0x001E |
Charles MacNeill |
9:66969b9016ad | 70 | #define MM_CONFIG__INNER_OFFSET_MM 0x0020 |
Charles MacNeill |
9:66969b9016ad | 71 | #define MM_CONFIG__OUTER_OFFSET_MM 0x0022 |
Charles MacNeill |
9:66969b9016ad | 72 | #define GPIO_HV_MUX__CTRL 0x0030 |
Charles MacNeill |
9:66969b9016ad | 73 | #define GPIO__TIO_HV_STATUS 0x0031 |
Charles MacNeill |
9:66969b9016ad | 74 | #define SYSTEM__INTERRUPT_CONFIG_GPIO 0x0046 |
Charles MacNeill |
9:66969b9016ad | 75 | #define PHASECAL_CONFIG__TIMEOUT_MACROP 0x004B |
Charles MacNeill |
9:66969b9016ad | 76 | #define RANGE_CONFIG__TIMEOUT_MACROP_A_HI 0x005E |
Charles MacNeill |
9:66969b9016ad | 77 | #define RANGE_CONFIG__VCSEL_PERIOD_A 0x0060 |
Charles MacNeill |
9:66969b9016ad | 78 | #define RANGE_CONFIG__VCSEL_PERIOD_B 0x0063 |
Charles MacNeill |
9:66969b9016ad | 79 | #define RANGE_CONFIG__TIMEOUT_MACROP_B_HI 0x0061 |
Charles MacNeill |
9:66969b9016ad | 80 | #define RANGE_CONFIG__TIMEOUT_MACROP_B_LO 0x0062 |
Charles MacNeill |
9:66969b9016ad | 81 | #define RANGE_CONFIG__SIGMA_THRESH 0x0064 |
Charles MacNeill |
9:66969b9016ad | 82 | #define RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS 0x0066 |
Charles MacNeill |
9:66969b9016ad | 83 | #define RANGE_CONFIG__VALID_PHASE_HIGH 0x0069 |
Charles MacNeill |
9:66969b9016ad | 84 | #define SYSTEM__THRESH_HIGH 0x0072 |
Charles MacNeill |
9:66969b9016ad | 85 | #define SYSTEM__THRESH_LOW 0x0074 |
Charles MacNeill |
9:66969b9016ad | 86 | #define SD_CONFIG__WOI_SD0 0x0078 |
Charles MacNeill |
9:66969b9016ad | 87 | #define SD_CONFIG__INITIAL_PHASE_SD0 0x007A |
Charles MacNeill |
9:66969b9016ad | 88 | #define ROI_CONFIG__USER_ROI_CENTRE_SPAD 0x007F |
Charles MacNeill |
9:66969b9016ad | 89 | #define ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE 0x0080 |
Charles MacNeill |
9:66969b9016ad | 90 | #define SYSTEM__SEQUENCE_CONFIG 0x0081 |
Charles MacNeill |
9:66969b9016ad | 91 | #define SYSTEM__INTERRUPT_CLEAR 0x0086 |
Charles MacNeill |
9:66969b9016ad | 92 | #define SYSTEM__MODE_START 0x0087 |
Charles MacNeill |
9:66969b9016ad | 93 | #define RESULT__AMBIENT_COUNT_RATE_MCPS_SD 0x0090 |
Charles MacNeill |
10:3687b5e79f98 | 94 | #define VL53L1CB_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0 0x0096 |
Charles MacNeill |
10:3687b5e79f98 | 95 | #define VL53L1CB_FIRMWARE__SYSTEM_STATUS 0x00E5 |
Charles MacNeill |
9:66969b9016ad | 96 | |
Charles MacNeill |
9:66969b9016ad | 97 | |
Charles MacNeill |
9:66969b9016ad | 98 | |
Charles MacNeill |
10:3687b5e79f98 | 99 | #define VL53L1CB_DEFAULT_DEVICE_ADDRESS 0x52 |
Charles MacNeill |
10:3687b5e79f98 | 100 | |
Charles MacNeill |
10:3687b5e79f98 | 101 | #define VL53L1CB_REG_IDENTIFICATION_MODEL_ID 0x010F |
Charles MacNeill |
9:66969b9016ad | 102 | |
Charles MacNeill |
9:66969b9016ad | 103 | /**************************************** |
Charles MacNeill |
9:66969b9016ad | 104 | * PRIVATE define do not edit |
Charles MacNeill |
9:66969b9016ad | 105 | ****************************************/ |
Charles MacNeill |
9:66969b9016ad | 106 | |
Charles MacNeill |
9:66969b9016ad | 107 | /** |
Charles MacNeill |
9:66969b9016ad | 108 | * @brief defines SW Version |
Charles MacNeill |
9:66969b9016ad | 109 | */ |
Charles MacNeill |
9:66969b9016ad | 110 | //typedef struct { |
Charles MacNeill |
9:66969b9016ad | 111 | // uint8_t major; /*!< major number */ |
Charles MacNeill |
9:66969b9016ad | 112 | // uint8_t minor; /*!< minor number */ |
Charles MacNeill |
9:66969b9016ad | 113 | // uint8_t build; /*!< build number */ |
Charles MacNeill |
9:66969b9016ad | 114 | // uint32_t revision; /*!< revision number */ |
Charles MacNeill |
9:66969b9016ad | 115 | //} VL53L1X_Version_t; |
Charles MacNeill |
9:66969b9016ad | 116 | |
Charles MacNeill |
9:66969b9016ad | 117 | |
Charles MacNeill |
9:66969b9016ad | 118 | /* Classes -------------------------------------------------------------------*/ |
Charles MacNeill |
10:3687b5e79f98 | 119 | /** Class representing a VL53L1CB sensor component |
Charles MacNeill |
9:66969b9016ad | 120 | */ |
Charles MacNeill |
10:3687b5e79f98 | 121 | class VL53L1CB : public RangeSensor |
Charles MacNeill |
9:66969b9016ad | 122 | { |
Charles MacNeill |
9:66969b9016ad | 123 | |
Charles MacNeill |
9:66969b9016ad | 124 | |
Charles MacNeill |
9:66969b9016ad | 125 | |
Charles MacNeill |
9:66969b9016ad | 126 | public: |
Charles MacNeill |
9:66969b9016ad | 127 | |
Charles MacNeill |
9:66969b9016ad | 128 | |
Charles MacNeill |
9:66969b9016ad | 129 | #define VL53L1DevStructGetLLDriverHandle(Dev) (&Dev->Data.LLData) |
Charles MacNeill |
9:66969b9016ad | 130 | /** Constructor |
Charles MacNeill |
9:66969b9016ad | 131 | * @param[in] &i2c device I2C to be used for communication |
Charles MacNeill |
9:66969b9016ad | 132 | * @param[in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT |
Charles MacNeill |
9:66969b9016ad | 133 | * @param[in] DevAddr device address, 0x52 by default |
Charles MacNeill |
9:66969b9016ad | 134 | */ |
Charles MacNeill |
9:66969b9016ad | 135 | |
Charles MacNeill |
10:3687b5e79f98 | 136 | VL53L1CB(ToF_DevI2C *i2c, DigitalOut *pin, PinName pin_gpio1, uint8_t dev_addr = VL53L1CB_DEFAULT_DEVICE_ADDRESS) |
Charles MacNeill |
9:66969b9016ad | 137 | : RangeSensor(), dev_i2c(i2c), _gpio0(pin) |
Charles MacNeill |
9:66969b9016ad | 138 | { |
Charles MacNeill |
9:66969b9016ad | 139 | MyDevice.i2c_slave_address=dev_addr; |
Charles MacNeill |
9:66969b9016ad | 140 | Device = &MyDevice; |
Charles MacNeill |
9:66969b9016ad | 141 | |
Charles MacNeill |
9:66969b9016ad | 142 | _expgpio0 = NULL; |
Charles MacNeill |
9:66969b9016ad | 143 | if (pin_gpio1 != NC) { |
Charles MacNeill |
9:66969b9016ad | 144 | _gpio1Int = new InterruptIn(pin_gpio1); |
Charles MacNeill |
9:66969b9016ad | 145 | } else { |
Charles MacNeill |
9:66969b9016ad | 146 | _gpio1Int = NULL; |
Charles MacNeill |
9:66969b9016ad | 147 | } |
Charles MacNeill |
9:66969b9016ad | 148 | } |
Charles MacNeill |
9:66969b9016ad | 149 | |
Charles MacNeill |
9:66969b9016ad | 150 | |
Charles MacNeill |
9:66969b9016ad | 151 | /** Constructor 2 (STMPE1600DigiOut) |
Charles MacNeill |
9:66969b9016ad | 152 | * @param[in] i2c device I2C to be used for communication |
Charles MacNeill |
9:66969b9016ad | 153 | * @param[in] &pin Gpio Expander STMPE1600DigiOut pin to be used as component GPIO_0 CE |
Charles MacNeill |
9:66969b9016ad | 154 | * @param[in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT |
Charles MacNeill |
9:66969b9016ad | 155 | * @param[in] device address, 0x29 by default |
Charles MacNeill |
9:66969b9016ad | 156 | */ |
Charles MacNeill |
10:3687b5e79f98 | 157 | VL53L1CB(ToF_DevI2C *i2c, Stmpe1600DigiOut *pin, PinName pin_gpio1, |
Charles MacNeill |
10:3687b5e79f98 | 158 | uint8_t dev_addr = VL53L1CB_DEFAULT_DEVICE_ADDRESS) |
Charles MacNeill |
9:66969b9016ad | 159 | : dev_i2c(i2c), _expgpio0(pin) |
Charles MacNeill |
9:66969b9016ad | 160 | { |
Charles MacNeill |
9:66969b9016ad | 161 | MyDevice.i2c_slave_address=dev_addr; |
Charles MacNeill |
9:66969b9016ad | 162 | Device = &MyDevice; |
Charles MacNeill |
9:66969b9016ad | 163 | |
Charles MacNeill |
9:66969b9016ad | 164 | _gpio0 = NULL; |
Charles MacNeill |
9:66969b9016ad | 165 | if (pin_gpio1 != NC) { |
Charles MacNeill |
9:66969b9016ad | 166 | _gpio1Int = new InterruptIn(pin_gpio1); |
Charles MacNeill |
9:66969b9016ad | 167 | } else { |
Charles MacNeill |
9:66969b9016ad | 168 | _gpio1Int = NULL; |
Charles MacNeill |
9:66969b9016ad | 169 | } |
Charles MacNeill |
9:66969b9016ad | 170 | } |
Charles MacNeill |
9:66969b9016ad | 171 | |
Charles MacNeill |
9:66969b9016ad | 172 | /** Destructor |
Charles MacNeill |
9:66969b9016ad | 173 | */ |
Charles MacNeill |
10:3687b5e79f98 | 174 | virtual ~VL53L1CB() |
Charles MacNeill |
9:66969b9016ad | 175 | { |
Charles MacNeill |
9:66969b9016ad | 176 | if (_gpio1Int != NULL) { |
Charles MacNeill |
9:66969b9016ad | 177 | delete _gpio1Int; |
Charles MacNeill |
9:66969b9016ad | 178 | } |
Charles MacNeill |
9:66969b9016ad | 179 | } |
Charles MacNeill |
9:66969b9016ad | 180 | |
Charles MacNeill |
9:66969b9016ad | 181 | |
Charles MacNeill |
9:66969b9016ad | 182 | |
Charles MacNeill |
9:66969b9016ad | 183 | VL53L1_DEV getDevicePtr() { return Device; } |
Charles MacNeill |
9:66969b9016ad | 184 | |
Charles MacNeill |
9:66969b9016ad | 185 | |
Charles MacNeill |
10:3687b5e79f98 | 186 | /* warning: VL53L1CB class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor. |
Charles MacNeill |
9:66969b9016ad | 187 | The warning should request to introduce a virtual destructor to make sure to delete the object */ |
Charles MacNeill |
9:66969b9016ad | 188 | |
Charles MacNeill |
9:66969b9016ad | 189 | /*** Interface Methods ***/ |
Charles MacNeill |
9:66969b9016ad | 190 | /*** High level API ***/ |
Charles MacNeill |
9:66969b9016ad | 191 | /** |
Charles MacNeill |
9:66969b9016ad | 192 | * @brief PowerOn the sensor |
Charles MacNeill |
9:66969b9016ad | 193 | * @return void |
Charles MacNeill |
9:66969b9016ad | 194 | */ |
Charles MacNeill |
9:66969b9016ad | 195 | /* turns on the sensor */ |
Charles MacNeill |
10:3687b5e79f98 | 196 | virtual void VL53L1CB_On(void) |
Charles MacNeill |
9:66969b9016ad | 197 | { |
Charles MacNeill |
10:3687b5e79f98 | 198 | printf("VL53L1CB_On\r\n"); |
Charles MacNeill |
9:66969b9016ad | 199 | if (_gpio0) { |
Charles MacNeill |
9:66969b9016ad | 200 | *_gpio0 = 1; |
Charles MacNeill |
9:66969b9016ad | 201 | } else { |
Charles MacNeill |
9:66969b9016ad | 202 | if (_expgpio0) { |
Charles MacNeill |
9:66969b9016ad | 203 | *_expgpio0 = 1; |
Charles MacNeill |
9:66969b9016ad | 204 | } |
Charles MacNeill |
9:66969b9016ad | 205 | } |
Charles MacNeill |
9:66969b9016ad | 206 | #if (MBED_VERSION > 60300) |
Charles MacNeill |
9:66969b9016ad | 207 | thread_sleep_for(100); |
Charles MacNeill |
9:66969b9016ad | 208 | #else |
Charles MacNeill |
9:66969b9016ad | 209 | wait_ms(100); // NEEDS A DELAY BETWEEN SENSORS |
Charles MacNeill |
9:66969b9016ad | 210 | #endif |
Charles MacNeill |
9:66969b9016ad | 211 | } |
Charles MacNeill |
9:66969b9016ad | 212 | |
Charles MacNeill |
9:66969b9016ad | 213 | /** |
Charles MacNeill |
9:66969b9016ad | 214 | * @brief PowerOff the sensor |
Charles MacNeill |
9:66969b9016ad | 215 | * @return void |
Charles MacNeill |
9:66969b9016ad | 216 | */ |
Charles MacNeill |
9:66969b9016ad | 217 | /* turns off the sensor */ |
Charles MacNeill |
10:3687b5e79f98 | 218 | virtual void VL53L1CB_Off(void) |
Charles MacNeill |
9:66969b9016ad | 219 | { |
Charles MacNeill |
9:66969b9016ad | 220 | printf("VL53L1_Off\r\n"); |
Charles MacNeill |
9:66969b9016ad | 221 | if (_gpio0) { |
Charles MacNeill |
9:66969b9016ad | 222 | *_gpio0 = 0; |
Charles MacNeill |
9:66969b9016ad | 223 | } else { |
Charles MacNeill |
9:66969b9016ad | 224 | if (_expgpio0) { |
Charles MacNeill |
9:66969b9016ad | 225 | *_expgpio0 = 0; |
Charles MacNeill |
9:66969b9016ad | 226 | } |
Charles MacNeill |
9:66969b9016ad | 227 | } |
Charles MacNeill |
9:66969b9016ad | 228 | #if (MBED_VERSION > 60300) |
Charles MacNeill |
9:66969b9016ad | 229 | thread_sleep_for(100); |
Charles MacNeill |
9:66969b9016ad | 230 | #else |
Charles MacNeill |
9:66969b9016ad | 231 | wait_ms(100); // NEEDS A DELAY BETWEEN SENSORS |
Charles MacNeill |
9:66969b9016ad | 232 | #endif |
Charles MacNeill |
9:66969b9016ad | 233 | } |
Charles MacNeill |
9:66969b9016ad | 234 | |
Charles MacNeill |
9:66969b9016ad | 235 | int is_present() |
Charles MacNeill |
9:66969b9016ad | 236 | { |
Charles MacNeill |
9:66969b9016ad | 237 | int status; |
Charles MacNeill |
9:66969b9016ad | 238 | uint8_t id = 0; |
Charles MacNeill |
9:66969b9016ad | 239 | |
Charles MacNeill |
9:66969b9016ad | 240 | status = read_id(&id); |
Charles MacNeill |
9:66969b9016ad | 241 | if (status) { |
Charles MacNeill |
9:66969b9016ad | 242 | printf("Failed to read ID device. Device not present!\n\r"); |
Charles MacNeill |
9:66969b9016ad | 243 | } |
Charles MacNeill |
9:66969b9016ad | 244 | return status; |
Charles MacNeill |
9:66969b9016ad | 245 | } |
Charles MacNeill |
9:66969b9016ad | 246 | |
Charles MacNeill |
9:66969b9016ad | 247 | /** |
Charles MacNeill |
9:66969b9016ad | 248 | * @brief Initialize the sensor with default values |
Charles MacNeill |
9:66969b9016ad | 249 | * @return 0 on Success |
Charles MacNeill |
9:66969b9016ad | 250 | */ |
Charles MacNeill |
9:66969b9016ad | 251 | |
Charles MacNeill |
10:3687b5e79f98 | 252 | VL53L1CB_ERROR InitSensor(uint8_t address){ |
Charles MacNeill |
10:3687b5e79f98 | 253 | VL53L1CB_ERROR status = 0; |
Charles MacNeill |
9:66969b9016ad | 254 | uint8_t sensorState = 0; |
Charles MacNeill |
10:3687b5e79f98 | 255 | VL53L1CB_Off(); |
Charles MacNeill |
10:3687b5e79f98 | 256 | VL53L1CB_On(); |
Charles MacNeill |
10:3687b5e79f98 | 257 | status = VL53L1CB_SetI2CAddress(address); |
Charles MacNeill |
9:66969b9016ad | 258 | if(!status){ |
Charles MacNeill |
10:3687b5e79f98 | 259 | status = VL53L1CB_SensorInit(); |
Charles MacNeill |
9:66969b9016ad | 260 | } |
Charles MacNeill |
9:66969b9016ad | 261 | |
Charles MacNeill |
9:66969b9016ad | 262 | while(!status && !sensorState) { |
Charles MacNeill |
10:3687b5e79f98 | 263 | status = VL53L1CB_BootState(&sensorState); |
Charles MacNeill |
9:66969b9016ad | 264 | |
Charles MacNeill |
9:66969b9016ad | 265 | #if (MBED_VERSION > 60300) |
Charles MacNeill |
9:66969b9016ad | 266 | thread_sleep_for(2); |
Charles MacNeill |
9:66969b9016ad | 267 | #else |
Charles MacNeill |
9:66969b9016ad | 268 | wait_ms(2); // NEEDS A DELAY BETWEEN SENSORS |
Charles MacNeill |
9:66969b9016ad | 269 | #endif |
Charles MacNeill |
9:66969b9016ad | 270 | } |
Charles MacNeill |
9:66969b9016ad | 271 | return status; |
Charles MacNeill |
9:66969b9016ad | 272 | } |
Charles MacNeill |
9:66969b9016ad | 273 | |
Charles MacNeill |
9:66969b9016ad | 274 | |
Charles MacNeill |
9:66969b9016ad | 275 | |
Charles MacNeill |
9:66969b9016ad | 276 | /** |
Charles MacNeill |
9:66969b9016ad | 277 | * |
Charles MacNeill |
9:66969b9016ad | 278 | * @brief One time device initialization |
Charles MacNeill |
9:66969b9016ad | 279 | * @param void |
Charles MacNeill |
9:66969b9016ad | 280 | * @return 0 on success, @a #CALIBRATION_WARNING if failed |
Charles MacNeill |
9:66969b9016ad | 281 | */ |
Charles MacNeill |
9:66969b9016ad | 282 | virtual int init(void *init) |
Charles MacNeill |
9:66969b9016ad | 283 | { |
Charles MacNeill |
10:3687b5e79f98 | 284 | return VL53L1CB_SensorInit(); |
Charles MacNeill |
9:66969b9016ad | 285 | return 0; |
Charles MacNeill |
9:66969b9016ad | 286 | } |
Charles MacNeill |
9:66969b9016ad | 287 | |
Charles MacNeill |
9:66969b9016ad | 288 | |
Charles MacNeill |
9:66969b9016ad | 289 | /** |
Charles MacNeill |
9:66969b9016ad | 290 | * @brief Initialize the sensor with default values |
Charles MacNeill |
9:66969b9016ad | 291 | * @return "0" on success |
Charles MacNeill |
9:66969b9016ad | 292 | */ |
Charles MacNeill |
9:66969b9016ad | 293 | int init_sensor(uint8_t new_addr); |
Charles MacNeill |
9:66969b9016ad | 294 | |
Charles MacNeill |
9:66969b9016ad | 295 | /* Read function of the ID device */ |
Charles MacNeill |
9:66969b9016ad | 296 | virtual int read_id(uint8_t *id){ |
Charles MacNeill |
9:66969b9016ad | 297 | int status = 0; |
Charles MacNeill |
9:66969b9016ad | 298 | uint16_t rl_id = 0; |
Charles MacNeill |
9:66969b9016ad | 299 | |
Charles MacNeill |
9:66969b9016ad | 300 | uint8_t ExpanderData[2]; |
Charles MacNeill |
9:66969b9016ad | 301 | |
Charles MacNeill |
9:66969b9016ad | 302 | ExpanderData[0] = 0; |
Charles MacNeill |
9:66969b9016ad | 303 | ExpanderData[1] = 0; |
Charles MacNeill |
9:66969b9016ad | 304 | rl_id = 0; |
Charles MacNeill |
10:3687b5e79f98 | 305 | dev_i2c->ToF_i2c_read(&ExpanderData[0], Device->i2c_slave_address, VL53L1CB_REG_IDENTIFICATION_MODEL_ID, 2); |
Charles MacNeill |
9:66969b9016ad | 306 | |
Charles MacNeill |
9:66969b9016ad | 307 | rl_id = (ExpanderData[0] << 8) + ExpanderData[1]; |
Charles MacNeill |
9:66969b9016ad | 308 | printf("Model ID is: %d (%X) \r\n",rl_id, rl_id); |
Charles MacNeill |
9:66969b9016ad | 309 | |
Charles MacNeill |
9:66969b9016ad | 310 | uint8_t tmp = 0; |
Charles MacNeill |
10:3687b5e79f98 | 311 | ExpanderData[0] = VL53L1CB_FIRMWARE__SYSTEM_STATUS >> 8; |
Charles MacNeill |
10:3687b5e79f98 | 312 | ExpanderData[1] = VL53L1CB_FIRMWARE__SYSTEM_STATUS & 0x0FF; |
Charles MacNeill |
10:3687b5e79f98 | 313 | dev_i2c->ToF_i2c_read(&tmp, Device->i2c_slave_address, VL53L1CB_FIRMWARE__SYSTEM_STATUS, 1); |
Charles MacNeill |
9:66969b9016ad | 314 | |
Charles MacNeill |
9:66969b9016ad | 315 | printf("Firmware system is: %d\r\n",tmp); |
Charles MacNeill |
9:66969b9016ad | 316 | |
Charles MacNeill |
9:66969b9016ad | 317 | if (rl_id == 0xEACC) { |
Charles MacNeill |
9:66969b9016ad | 318 | printf("Device is present %d:\r\n", rl_id); |
Charles MacNeill |
9:66969b9016ad | 319 | return status; |
Charles MacNeill |
9:66969b9016ad | 320 | } |
Charles MacNeill |
9:66969b9016ad | 321 | return -1; |
Charles MacNeill |
9:66969b9016ad | 322 | } |
Charles MacNeill |
9:66969b9016ad | 323 | |
Charles MacNeill |
9:66969b9016ad | 324 | |
Charles MacNeill |
9:66969b9016ad | 325 | /** |
Charles MacNeill |
9:66969b9016ad | 326 | * @brief Interrupt handling func to be called by user after an INT is occurred |
Charles MacNeill |
9:66969b9016ad | 327 | * @param[out] Data pointer to the distance to read data in to |
Charles MacNeill |
9:66969b9016ad | 328 | * @return 0 on Success |
Charles MacNeill |
9:66969b9016ad | 329 | */ |
Charles MacNeill |
9:66969b9016ad | 330 | int handle_irq(uint16_t *distance); |
Charles MacNeill |
9:66969b9016ad | 331 | |
Charles MacNeill |
9:66969b9016ad | 332 | /** |
Charles MacNeill |
9:66969b9016ad | 333 | * @brief Start the measure indicated by operating mode |
Charles MacNeill |
9:66969b9016ad | 334 | * @param[in] fptr specifies call back function must be !NULL in case of interrupt measure |
Charles MacNeill |
9:66969b9016ad | 335 | * @return 0 on Success |
Charles MacNeill |
9:66969b9016ad | 336 | */ |
Charles MacNeill |
9:66969b9016ad | 337 | int start_measurement(void (*fptr)(void)); |
Charles MacNeill |
9:66969b9016ad | 338 | /** |
Charles MacNeill |
9:66969b9016ad | 339 | * @brief Stop the currently running measure indicate by operating_mode |
Charles MacNeill |
9:66969b9016ad | 340 | * @return 0 on Success |
Charles MacNeill |
9:66969b9016ad | 341 | */ |
Charles MacNeill |
9:66969b9016ad | 342 | int stop_measurement(); |
Charles MacNeill |
9:66969b9016ad | 343 | /** |
Charles MacNeill |
9:66969b9016ad | 344 | * @brief Get results for the measure |
Charles MacNeill |
9:66969b9016ad | 345 | * @param[out] Data pointer to the distance_data to read data in to |
Charles MacNeill |
9:66969b9016ad | 346 | * @return 0 on Success |
Charles MacNeill |
9:66969b9016ad | 347 | */ |
Charles MacNeill |
9:66969b9016ad | 348 | int get_measurement(uint16_t *distance); |
Charles MacNeill |
9:66969b9016ad | 349 | /** |
Charles MacNeill |
9:66969b9016ad | 350 | * @brief Enable interrupt measure IRQ |
Charles MacNeill |
9:66969b9016ad | 351 | * @return 0 on Success |
Charles MacNeill |
9:66969b9016ad | 352 | */ |
Charles MacNeill |
9:66969b9016ad | 353 | void enable_interrupt_measure_detection_irq(void) |
Charles MacNeill |
9:66969b9016ad | 354 | { |
Charles MacNeill |
9:66969b9016ad | 355 | if (_gpio1Int != NULL) |
Charles MacNeill |
9:66969b9016ad | 356 | _gpio1Int->enable_irq(); |
Charles MacNeill |
9:66969b9016ad | 357 | } |
Charles MacNeill |
9:66969b9016ad | 358 | |
Charles MacNeill |
9:66969b9016ad | 359 | /** |
Charles MacNeill |
9:66969b9016ad | 360 | * @brief Disable interrupt measure IRQ |
Charles MacNeill |
9:66969b9016ad | 361 | * @return 0 on Success |
Charles MacNeill |
9:66969b9016ad | 362 | */ |
Charles MacNeill |
9:66969b9016ad | 363 | void disable_interrupt_measure_detection_irq(void) |
Charles MacNeill |
9:66969b9016ad | 364 | { |
Charles MacNeill |
9:66969b9016ad | 365 | if (_gpio1Int != NULL) |
Charles MacNeill |
9:66969b9016ad | 366 | _gpio1Int->disable_irq(); |
Charles MacNeill |
9:66969b9016ad | 367 | } |
Charles MacNeill |
9:66969b9016ad | 368 | /** |
Charles MacNeill |
9:66969b9016ad | 369 | * @brief Attach a function to call when an interrupt is detected, i.e. measurement is ready |
Charles MacNeill |
9:66969b9016ad | 370 | * @param[in] fptr pointer to call back function to be called whenever an interrupt occours |
Charles MacNeill |
9:66969b9016ad | 371 | * @return 0 on Success |
Charles MacNeill |
9:66969b9016ad | 372 | */ |
Charles MacNeill |
9:66969b9016ad | 373 | void attach_interrupt_measure_detection_irq(void (*fptr)(void)) |
Charles MacNeill |
9:66969b9016ad | 374 | { |
Charles MacNeill |
9:66969b9016ad | 375 | if (_gpio1Int != NULL) |
Charles MacNeill |
9:66969b9016ad | 376 | _gpio1Int->rise(fptr); |
Charles MacNeill |
9:66969b9016ad | 377 | } |
Charles MacNeill |
9:66969b9016ad | 378 | |
Charles MacNeill |
9:66969b9016ad | 379 | /** |
Charles MacNeill |
9:66969b9016ad | 380 | * @brief Get ranging result and only that |
Charles MacNeill |
9:66969b9016ad | 381 | * @param pRange_mm Pointer to range distance |
Charles MacNeill |
9:66969b9016ad | 382 | * @return 0 on success |
Charles MacNeill |
9:66969b9016ad | 383 | */ |
Charles MacNeill |
9:66969b9016ad | 384 | virtual int get_distance(uint32_t *piData) |
Charles MacNeill |
9:66969b9016ad | 385 | { |
Charles MacNeill |
9:66969b9016ad | 386 | int status; |
Charles MacNeill |
9:66969b9016ad | 387 | uint16_t distance; |
Charles MacNeill |
10:3687b5e79f98 | 388 | status = VL53L1CB_GetDistance(&distance); |
Charles MacNeill |
9:66969b9016ad | 389 | *piData = (uint32_t) distance; |
Charles MacNeill |
9:66969b9016ad | 390 | return status; |
Charles MacNeill |
9:66969b9016ad | 391 | } |
Charles MacNeill |
9:66969b9016ad | 392 | |
Charles MacNeill |
9:66969b9016ad | 393 | |
Charles MacNeill |
9:66969b9016ad | 394 | /* VL53L1X_api.h functions */ |
Charles MacNeill |
9:66969b9016ad | 395 | |
Charles MacNeill |
9:66969b9016ad | 396 | |
Charles MacNeill |
9:66969b9016ad | 397 | |
Charles MacNeill |
9:66969b9016ad | 398 | /** |
Charles MacNeill |
9:66969b9016ad | 399 | * @brief This function returns the SW driver version |
Charles MacNeill |
9:66969b9016ad | 400 | */ |
Charles MacNeill |
10:3687b5e79f98 | 401 | VL53L1CB_ERROR VL53L1CB_GetSWVersion(VL53L1_Version_t *pVersion); |
Charles MacNeill |
9:66969b9016ad | 402 | |
Charles MacNeill |
9:66969b9016ad | 403 | /** |
Charles MacNeill |
9:66969b9016ad | 404 | * @brief This function sets the sensor I2C address used in case multiple devices application, default address 0x52 |
Charles MacNeill |
9:66969b9016ad | 405 | */ |
Charles MacNeill |
10:3687b5e79f98 | 406 | VL53L1CB_ERROR VL53L1CB_SetI2CAddress(uint8_t new_address); |
Charles MacNeill |
9:66969b9016ad | 407 | |
Charles MacNeill |
9:66969b9016ad | 408 | /** |
Charles MacNeill |
9:66969b9016ad | 409 | * @brief This function loads the 135 bytes default values to initialize the sensor. |
Charles MacNeill |
9:66969b9016ad | 410 | * @param dev Device address |
Charles MacNeill |
9:66969b9016ad | 411 | * @return 0:success, != 0:failed |
Charles MacNeill |
9:66969b9016ad | 412 | */ |
Charles MacNeill |
10:3687b5e79f98 | 413 | VL53L1CB_ERROR VL53L1CB_SensorInit(); |
Charles MacNeill |
9:66969b9016ad | 414 | |
Charles MacNeill |
9:66969b9016ad | 415 | /** |
Charles MacNeill |
9:66969b9016ad | 416 | * @brief This function clears the interrupt, to be called after a ranging data reading |
Charles MacNeill |
9:66969b9016ad | 417 | * to arm the interrupt for the next data ready event. |
Charles MacNeill |
9:66969b9016ad | 418 | */ |
Charles MacNeill |
10:3687b5e79f98 | 419 | VL53L1CB_ERROR VL53L1CB_ClearInterrupt(); |
Charles MacNeill |
9:66969b9016ad | 420 | |
Charles MacNeill |
9:66969b9016ad | 421 | |
Charles MacNeill |
9:66969b9016ad | 422 | /** |
Charles MacNeill |
9:66969b9016ad | 423 | * @brief This function returns the current interrupt polarity\n |
Charles MacNeill |
9:66969b9016ad | 424 | * 1=active high (default), 0=active low |
Charles MacNeill |
9:66969b9016ad | 425 | */ |
Charles MacNeill |
10:3687b5e79f98 | 426 | VL53L1CB_ERROR VL53L1CB_GetInterruptPolarity(uint8_t *pIntPol); |
Charles MacNeill |
9:66969b9016ad | 427 | |
Charles MacNeill |
9:66969b9016ad | 428 | /** |
Charles MacNeill |
9:66969b9016ad | 429 | * @brief This function starts the ranging distance operation\n |
Charles MacNeill |
9:66969b9016ad | 430 | * The ranging operation is continuous. The clear interrupt has to be done after each get data to allow the interrupt to raise when the next data is ready\n |
Charles MacNeill |
9:66969b9016ad | 431 | * 1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required. |
Charles MacNeill |
9:66969b9016ad | 432 | */ |
Charles MacNeill |
10:3687b5e79f98 | 433 | VL53L1CB_ERROR VL53L1CB_StartRanging(); |
Charles MacNeill |
9:66969b9016ad | 434 | |
Charles MacNeill |
9:66969b9016ad | 435 | /** |
Charles MacNeill |
9:66969b9016ad | 436 | * @brief This function stops the ranging. |
Charles MacNeill |
9:66969b9016ad | 437 | */ |
Charles MacNeill |
10:3687b5e79f98 | 438 | VL53L1CB_ERROR VL53L1CB_StopRanging(); |
Charles MacNeill |
9:66969b9016ad | 439 | |
Charles MacNeill |
9:66969b9016ad | 440 | |
Charles MacNeill |
9:66969b9016ad | 441 | |
Charles MacNeill |
9:66969b9016ad | 442 | /** |
Charles MacNeill |
9:66969b9016ad | 443 | * @brief This function returns the boot state of the device (1:booted, 0:not booted) |
Charles MacNeill |
9:66969b9016ad | 444 | */ |
Charles MacNeill |
10:3687b5e79f98 | 445 | VL53L1CB_ERROR VL53L1CB_BootState(uint8_t *state); |
Charles MacNeill |
9:66969b9016ad | 446 | |
Charles MacNeill |
9:66969b9016ad | 447 | /** |
Charles MacNeill |
9:66969b9016ad | 448 | * @brief This function returns the sensor id, sensor Id must be 0xEEAC |
Charles MacNeill |
9:66969b9016ad | 449 | */ |
Charles MacNeill |
10:3687b5e79f98 | 450 | // VL53L1CB_ERROR VL53L1X_GetSensorId(uint16_t *id); |
Charles MacNeill |
9:66969b9016ad | 451 | |
Charles MacNeill |
9:66969b9016ad | 452 | /** |
Charles MacNeill |
9:66969b9016ad | 453 | * @brief This function returns the distance measured by the sensor in mm |
Charles MacNeill |
9:66969b9016ad | 454 | */ |
Charles MacNeill |
10:3687b5e79f98 | 455 | VL53L1CB_ERROR VL53L1CB_GetDistance(uint16_t *distance); |
Charles MacNeill |
9:66969b9016ad | 456 | |
Charles MacNeill |
9:66969b9016ad | 457 | |
Charles MacNeill |
9:66969b9016ad | 458 | |
Charles MacNeill |
9:66969b9016ad | 459 | |
Charles MacNeill |
9:66969b9016ad | 460 | /**************************************************************************/ |
Charles MacNeill |
10:3687b5e79f98 | 461 | VL53L1CB_ERROR VL53L1CB_WaitDeviceBooted(VL53L1_DEV Dev); |
Charles MacNeill |
9:66969b9016ad | 462 | |
Charles MacNeill |
9:66969b9016ad | 463 | |
Charles MacNeill |
10:3687b5e79f98 | 464 | VL53L1CB_ERROR VL53L1CB_GetCalibrationData(VL53L1_CalibrationData_t *pCalibrationData); |
Charles MacNeill |
9:66969b9016ad | 465 | |
Charles MacNeill |
9:66969b9016ad | 466 | |
Charles MacNeill |
9:66969b9016ad | 467 | |
Charles MacNeill |
10:3687b5e79f98 | 468 | VL53L1_GPIO_Interrupt_Mode ConvertModeToLLD(VL53L1CB_ERROR *pStatus, |
Charles MacNeill |
9:66969b9016ad | 469 | VL53L1_ThresholdMode CrossMode); |
Charles MacNeill |
9:66969b9016ad | 470 | |
Charles MacNeill |
10:3687b5e79f98 | 471 | VL53L1CB_ERROR VL53L1CB_GetVersion(VL53L1_Version_t *pVersion); |
Charles MacNeill |
9:66969b9016ad | 472 | |
Charles MacNeill |
10:3687b5e79f98 | 473 | VL53L1CB_ERROR VL53L1CB_GetProductRevision( |
Charles MacNeill |
9:66969b9016ad | 474 | uint8_t *pProductRevisionMajor, uint8_t *pProductRevisionMinor); |
Charles MacNeill |
9:66969b9016ad | 475 | |
Charles MacNeill |
9:66969b9016ad | 476 | |
Charles MacNeill |
10:3687b5e79f98 | 477 | VL53L1CB_ERROR VL53L1CB_GetDeviceInfo( |
Charles MacNeill |
9:66969b9016ad | 478 | VL53L1_DeviceInfo_t *pVL53L1_DeviceInfo); |
Charles MacNeill |
9:66969b9016ad | 479 | |
Charles MacNeill |
10:3687b5e79f98 | 480 | VL53L1CB_ERROR VL53L1CB_GetUID( uint64_t *pUid); |
Charles MacNeill |
9:66969b9016ad | 481 | |
Charles MacNeill |
10:3687b5e79f98 | 482 | VL53L1CB_ERROR VL53L1CB_GetRangeStatusString(uint8_t RangeStatus, |
Charles MacNeill |
9:66969b9016ad | 483 | char *pRangeStatusString); |
Charles MacNeill |
9:66969b9016ad | 484 | |
Charles MacNeill |
9:66969b9016ad | 485 | |
Charles MacNeill |
10:3687b5e79f98 | 486 | VL53L1CB_ERROR VL53L1CB_GetPalErrorString(VL53L1CB_ERROR PalErrorCode, |
Charles MacNeill |
9:66969b9016ad | 487 | char *pPalErrorString); |
Charles MacNeill |
9:66969b9016ad | 488 | |
Charles MacNeill |
9:66969b9016ad | 489 | |
Charles MacNeill |
10:3687b5e79f98 | 490 | VL53L1CB_ERROR VL53L1CB_GetPalStateString(VL53L1_State PalStateCode, |
Charles MacNeill |
9:66969b9016ad | 491 | char *pPalStateString); |
Charles MacNeill |
9:66969b9016ad | 492 | |
Charles MacNeill |
9:66969b9016ad | 493 | |
Charles MacNeill |
10:3687b5e79f98 | 494 | VL53L1CB_ERROR VL53L1CB_GetPalState(VL53L1_DEV Dev, VL53L1_State *pPalState); |
Charles MacNeill |
9:66969b9016ad | 495 | |
Charles MacNeill |
10:3687b5e79f98 | 496 | VL53L1CB_ERROR VL53L1CB_DataInit(); |
Charles MacNeill |
9:66969b9016ad | 497 | |
Charles MacNeill |
10:3687b5e79f98 | 498 | VL53L1CB_ERROR VL53L1CB_StaticInit(); |
Charles MacNeill |
9:66969b9016ad | 499 | |
Charles MacNeill |
10:3687b5e79f98 | 500 | VL53L1CB_ERROR VL53L1CB_ClearInterruptAndStartMeasurement(); |
Charles MacNeill |
9:66969b9016ad | 501 | |
Charles MacNeill |
10:3687b5e79f98 | 502 | VL53L1CB_ERROR VL53L1CB_GetRangingMeasurementData( |
Charles MacNeill |
9:66969b9016ad | 503 | VL53L1_RangingMeasurementData_t *pRangingMeasurementData); |
Charles MacNeill |
9:66969b9016ad | 504 | |
Charles MacNeill |
10:3687b5e79f98 | 505 | VL53L1CB_ERROR VL53L1CB_GetMultiRangingData( |
Charles MacNeill |
9:66969b9016ad | 506 | VL53L1_MultiRangingData_t *pMultiRangingData); |
Charles MacNeill |
9:66969b9016ad | 507 | |
Charles MacNeill |
10:3687b5e79f98 | 508 | VL53L1CB_ERROR VL53L1CB_GetAdditionalData( |
Charles MacNeill |
9:66969b9016ad | 509 | VL53L1_AdditionalData_t *pAdditionalData); |
Charles MacNeill |
9:66969b9016ad | 510 | |
Charles MacNeill |
10:3687b5e79f98 | 511 | VL53L1CB_ERROR VL53L1CB_SetTuningParameter( |
Charles MacNeill |
9:66969b9016ad | 512 | uint16_t TuningParameterId, int32_t TuningParameterValue); |
Charles MacNeill |
9:66969b9016ad | 513 | |
Charles MacNeill |
10:3687b5e79f98 | 514 | VL53L1CB_ERROR VL53L1CB_GetTuningParameter( |
Charles MacNeill |
9:66969b9016ad | 515 | uint16_t TuningParameterId, int32_t *pTuningParameterValue); |
Charles MacNeill |
9:66969b9016ad | 516 | |
Charles MacNeill |
10:3687b5e79f98 | 517 | VL53L1CB_ERROR VL53L1CB_SetXTalkCompensationEnable( |
Charles MacNeill |
9:66969b9016ad | 518 | uint8_t XTalkCompensationEnable); |
Charles MacNeill |
9:66969b9016ad | 519 | |
Charles MacNeill |
9:66969b9016ad | 520 | |
Charles MacNeill |
10:3687b5e79f98 | 521 | VL53L1CB_ERROR VL53L1CB_GetXTalkCompensationEnable( |
Charles MacNeill |
9:66969b9016ad | 522 | uint8_t *pXTalkCompensationEnable); |
Charles MacNeill |
9:66969b9016ad | 523 | |
Charles MacNeill |
10:3687b5e79f98 | 524 | VL53L1CB_ERROR VL53L1CB_PerformXTalkCalibration( |
Charles MacNeill |
9:66969b9016ad | 525 | uint8_t CalibrationOption); |
Charles MacNeill |
9:66969b9016ad | 526 | |
Charles MacNeill |
10:3687b5e79f98 | 527 | VL53L1CB_ERROR VL53L1CB_SetOffsetCalibrationMode( |
Charles MacNeill |
9:66969b9016ad | 528 | VL53L1_OffsetCalibrationModes OffsetCalibrationMode); |
Charles MacNeill |
9:66969b9016ad | 529 | |
Charles MacNeill |
9:66969b9016ad | 530 | |
Charles MacNeill |
10:3687b5e79f98 | 531 | VL53L1CB_ERROR VL53L1CB_SetOffsetCorrectionMode( |
Charles MacNeill |
9:66969b9016ad | 532 | VL53L1_OffsetCorrectionModes OffsetCorrectionMode); |
Charles MacNeill |
9:66969b9016ad | 533 | |
Charles MacNeill |
10:3687b5e79f98 | 534 | VL53L1CB_ERROR VL53L1CB_PerformOffsetCalibration( |
Charles MacNeill |
9:66969b9016ad | 535 | int32_t CalDistanceMilliMeter, FixPoint1616_t CalReflectancePercent); |
Charles MacNeill |
9:66969b9016ad | 536 | |
Charles MacNeill |
10:3687b5e79f98 | 537 | VL53L1CB_ERROR VL53L1CB_PerformOffsetSimpleCalibration( |
Charles MacNeill |
9:66969b9016ad | 538 | int32_t CalDistanceMilliMeter); |
Charles MacNeill |
9:66969b9016ad | 539 | |
Charles MacNeill |
10:3687b5e79f98 | 540 | VL53L1CB_ERROR VL53L1CB_PerformOffsetZeroDistanceCalibration(); |
Charles MacNeill |
9:66969b9016ad | 541 | |
Charles MacNeill |
10:3687b5e79f98 | 542 | VL53L1CB_ERROR VL53L1CB_SetCalibrationData( |
Charles MacNeill |
9:66969b9016ad | 543 | VL53L1_CalibrationData_t *pCalibrationData); |
Charles MacNeill |
9:66969b9016ad | 544 | |
Charles MacNeill |
10:3687b5e79f98 | 545 | VL53L1CB_ERROR VL53L1CB_SetZoneCalibrationData( |
Charles MacNeill |
9:66969b9016ad | 546 | VL53L1_ZoneCalibrationData_t *pZoneCalibrationData); |
Charles MacNeill |
9:66969b9016ad | 547 | |
Charles MacNeill |
10:3687b5e79f98 | 548 | VL53L1CB_ERROR VL53L1CB_GetZoneCalibrationData( |
Charles MacNeill |
9:66969b9016ad | 549 | VL53L1_ZoneCalibrationData_t *pZoneCalibrationData); |
Charles MacNeill |
9:66969b9016ad | 550 | |
Charles MacNeill |
10:3687b5e79f98 | 551 | VL53L1CB_ERROR VL53L1CB_GetOpticalCenter( |
Charles MacNeill |
9:66969b9016ad | 552 | FixPoint1616_t *pOpticalCenterX, |
Charles MacNeill |
9:66969b9016ad | 553 | FixPoint1616_t *pOpticalCenterY); |
Charles MacNeill |
9:66969b9016ad | 554 | |
Charles MacNeill |
10:3687b5e79f98 | 555 | VL53L1CB_ERROR VL53L1CB_SetThresholdConfig(VL53L1_DetectionConfig_t *pConfig); |
Charles MacNeill |
9:66969b9016ad | 556 | |
Charles MacNeill |
9:66969b9016ad | 557 | |
Charles MacNeill |
10:3687b5e79f98 | 558 | VL53L1CB_ERROR VL53L1CB_GetLimitCheckStatus( uint16_t LimitCheckId, |
Charles MacNeill |
9:66969b9016ad | 559 | uint8_t *pLimitCheckStatus); |
Charles MacNeill |
9:66969b9016ad | 560 | |
Charles MacNeill |
9:66969b9016ad | 561 | |
Charles MacNeill |
10:3687b5e79f98 | 562 | VL53L1CB_ERROR VL53L1CB_SetLimitCheckEnable( uint16_t LimitCheckId, |
Charles MacNeill |
9:66969b9016ad | 563 | uint8_t LimitCheckEnable); |
Charles MacNeill |
9:66969b9016ad | 564 | |
Charles MacNeill |
10:3687b5e79f98 | 565 | VL53L1CB_ERROR VL53L1CB_GetLimitCheckEnable(uint16_t LimitCheckId, |
Charles MacNeill |
9:66969b9016ad | 566 | uint8_t *pLimitCheckEnable); |
Charles MacNeill |
9:66969b9016ad | 567 | |
Charles MacNeill |
10:3687b5e79f98 | 568 | VL53L1CB_ERROR VL53L1CB_GetThresholdConfig(VL53L1_DetectionConfig_t *pConfig); |
Charles MacNeill |
9:66969b9016ad | 569 | |
Charles MacNeill |
9:66969b9016ad | 570 | |
Charles MacNeill |
10:3687b5e79f98 | 571 | VL53L1CB_ERROR VL53L1CB_PerformOffsetPerVcselCalibration(int32_t CalDistanceMilliMeter); |
Charles MacNeill |
9:66969b9016ad | 572 | |
Charles MacNeill |
10:3687b5e79f98 | 573 | VL53L1CB_ERROR VL53L1CB_GetNumberOfLimitCheck(uint16_t *pNumberOfLimitCheck); |
Charles MacNeill |
9:66969b9016ad | 574 | |
Charles MacNeill |
10:3687b5e79f98 | 575 | VL53L1CB_ERROR VL53L1CB_GetLimitCheckInfo(uint16_t LimitCheckId, |
Charles MacNeill |
9:66969b9016ad | 576 | char *pLimitCheckString); |
Charles MacNeill |
9:66969b9016ad | 577 | |
Charles MacNeill |
10:3687b5e79f98 | 578 | VL53L1CB_ERROR VL53L1CB_SetPresetMode(VL53L1_PresetModes PresetMode); |
Charles MacNeill |
9:66969b9016ad | 579 | |
Charles MacNeill |
10:3687b5e79f98 | 580 | VL53L1CB_ERROR VL53L1CB_GetPresetMode( VL53L1_PresetModes *pPresetMode); |
Charles MacNeill |
9:66969b9016ad | 581 | |
Charles MacNeill |
10:3687b5e79f98 | 582 | VL53L1CB_ERROR VL53L1CB_SetDistanceMode( VL53L1_DistanceModes DistanceMode); |
Charles MacNeill |
9:66969b9016ad | 583 | |
Charles MacNeill |
10:3687b5e79f98 | 584 | VL53L1CB_ERROR VL53L1CB_GetDistanceMode(VL53L1_DistanceModes *pDistanceMode); |
Charles MacNeill |
9:66969b9016ad | 585 | |
Charles MacNeill |
10:3687b5e79f98 | 586 | VL53L1CB_ERROR VL53L1CB_SetOutputMode(VL53L1_OutputModes OutputMode); |
Charles MacNeill |
9:66969b9016ad | 587 | |
Charles MacNeill |
10:3687b5e79f98 | 588 | VL53L1CB_ERROR VL53L1CB_GetOutputMode(VL53L1_OutputModes *pOutputMode); |
Charles MacNeill |
9:66969b9016ad | 589 | |
Charles MacNeill |
10:3687b5e79f98 | 590 | VL53L1CB_ERROR VL53L1CB_SetMeasurementTimingBudgetMicroSeconds(uint32_t MeasurementTimingBudgetMicroSeconds); |
Charles MacNeill |
9:66969b9016ad | 591 | |
Charles MacNeill |
10:3687b5e79f98 | 592 | VL53L1CB_ERROR VL53L1CB_SetInterMeasurementPeriodMilliSeconds(uint32_t InterMeasurementPeriodMilliSeconds); |
Charles MacNeill |
9:66969b9016ad | 593 | |
Charles MacNeill |
9:66969b9016ad | 594 | |
Charles MacNeill |
10:3687b5e79f98 | 595 | VL53L1CB_ERROR VL53L1CB_GetInterMeasurementPeriodMilliSeconds( |
Charles MacNeill |
9:66969b9016ad | 596 | uint32_t *pInterMeasurementPeriodMilliSeconds); |
Charles MacNeill |
9:66969b9016ad | 597 | |
Charles MacNeill |
9:66969b9016ad | 598 | |
Charles MacNeill |
10:3687b5e79f98 | 599 | VL53L1CB_ERROR VL53L1CB_SetDmaxReflectance( FixPoint1616_t DmaxReflectance); |
Charles MacNeill |
9:66969b9016ad | 600 | |
Charles MacNeill |
10:3687b5e79f98 | 601 | VL53L1CB_ERROR VL53L1CB_GetDmaxReflectance(FixPoint1616_t *pDmaxReflectance); |
Charles MacNeill |
9:66969b9016ad | 602 | |
Charles MacNeill |
9:66969b9016ad | 603 | |
Charles MacNeill |
10:3687b5e79f98 | 604 | VL53L1CB_ERROR VL53L1CB_GetDmaxMode( VL53L1_DeviceDmaxModes *pDmaxMode); |
Charles MacNeill |
9:66969b9016ad | 605 | |
Charles MacNeill |
10:3687b5e79f98 | 606 | VL53L1CB_ERROR VL53L1CB_GetMeasurementTimingBudgetMicroSeconds( |
Charles MacNeill |
9:66969b9016ad | 607 | uint32_t *pMeasurementTimingBudgetMicroSeconds); |
Charles MacNeill |
9:66969b9016ad | 608 | |
Charles MacNeill |
10:3687b5e79f98 | 609 | VL53L1CB_ERROR VL53L1CB_SetDmaxMode(VL53L1_DeviceDmaxModes DmaxMode); |
Charles MacNeill |
9:66969b9016ad | 610 | |
Charles MacNeill |
10:3687b5e79f98 | 611 | VL53L1CB_ERROR VL53L1CB_SetLimitCheckValue( uint16_t LimitCheckId, |
Charles MacNeill |
9:66969b9016ad | 612 | FixPoint1616_t LimitCheckValue); |
Charles MacNeill |
9:66969b9016ad | 613 | |
Charles MacNeill |
10:3687b5e79f98 | 614 | VL53L1CB_ERROR VL53L1CB_GetLimitCheckValue(uint16_t LimitCheckId, |
Charles MacNeill |
9:66969b9016ad | 615 | FixPoint1616_t *pLimitCheckValue); |
Charles MacNeill |
9:66969b9016ad | 616 | |
Charles MacNeill |
10:3687b5e79f98 | 617 | VL53L1CB_ERROR VL53L1CB_GetLimitCheckCurrent( uint16_t LimitCheckId, |
Charles MacNeill |
9:66969b9016ad | 618 | FixPoint1616_t *pLimitCheckCurrent); |
Charles MacNeill |
9:66969b9016ad | 619 | |
Charles MacNeill |
10:3687b5e79f98 | 620 | VL53L1CB_ERROR VL53L1CB_GetMaxNumberOfROI( uint8_t *pMaxNumberOfROI); |
Charles MacNeill |
9:66969b9016ad | 621 | |
Charles MacNeill |
10:3687b5e79f98 | 622 | VL53L1CB_ERROR VL53L1CB_SetROI(VL53L1_RoiConfig_t *pRoiConfig); |
Charles MacNeill |
9:66969b9016ad | 623 | |
Charles MacNeill |
10:3687b5e79f98 | 624 | VL53L1CB_ERROR VL53L1CB_GetROI(VL53L1_RoiConfig_t *pRoiConfig); |
Charles MacNeill |
9:66969b9016ad | 625 | |
Charles MacNeill |
10:3687b5e79f98 | 626 | VL53L1CB_ERROR VL53L1CB_GetNumberOfSequenceSteps(uint8_t *pNumberOfSequenceSteps); |
Charles MacNeill |
9:66969b9016ad | 627 | |
Charles MacNeill |
10:3687b5e79f98 | 628 | VL53L1CB_ERROR VL53L1CB_GetSequenceStepsInfo(VL53L1_SequenceStepId SequenceStepId, |
Charles MacNeill |
9:66969b9016ad | 629 | char *pSequenceStepsString); |
Charles MacNeill |
9:66969b9016ad | 630 | |
Charles MacNeill |
9:66969b9016ad | 631 | |
Charles MacNeill |
10:3687b5e79f98 | 632 | VL53L1CB_ERROR VL53L1CB_SetSequenceStepEnable(VL53L1_SequenceStepId SequenceStepId, uint8_t SequenceStepEnabled); |
Charles MacNeill |
9:66969b9016ad | 633 | |
Charles MacNeill |
9:66969b9016ad | 634 | |
Charles MacNeill |
10:3687b5e79f98 | 635 | VL53L1CB_ERROR VL53L1CB_GetSequenceStepEnable(VL53L1_SequenceStepId SequenceStepId, uint8_t *pSequenceStepEnabled); |
Charles MacNeill |
9:66969b9016ad | 636 | |
Charles MacNeill |
9:66969b9016ad | 637 | |
Charles MacNeill |
10:3687b5e79f98 | 638 | VL53L1CB_ERROR VL53L1CB_StartMeasurement(); |
Charles MacNeill |
9:66969b9016ad | 639 | |
Charles MacNeill |
10:3687b5e79f98 | 640 | VL53L1CB_ERROR VL53L1CB_StopMeasurement(); |
Charles MacNeill |
9:66969b9016ad | 641 | |
Charles MacNeill |
9:66969b9016ad | 642 | |
Charles MacNeill |
10:3687b5e79f98 | 643 | VL53L1CB_ERROR VL53L1CB_GetMeasurementDataReady(uint8_t *pMeasurementDataReady); |
Charles MacNeill |
9:66969b9016ad | 644 | |
Charles MacNeill |
10:3687b5e79f98 | 645 | VL53L1CB_ERROR VL53L1CB_WaitMeasurementDataReady(); |
Charles MacNeill |
9:66969b9016ad | 646 | |
Charles MacNeill |
10:3687b5e79f98 | 647 | VL53L1CB_ERROR VL53L1CB_SmudgeCorrectionEnable(VL53L1_SmudgeCorrectionModes Mode); |
Charles MacNeill |
9:66969b9016ad | 648 | /***************************************************************************/ |
Charles MacNeill |
9:66969b9016ad | 649 | |
Charles MacNeill |
9:66969b9016ad | 650 | |
Charles MacNeill |
9:66969b9016ad | 651 | /* Write and read functions from I2C */ |
Charles MacNeill |
9:66969b9016ad | 652 | |
Charles MacNeill |
10:3687b5e79f98 | 653 | VL53L1CB_ERROR VL53L1CB_WrByte(VL53L1_DEV dev, uint16_t index, uint8_t data); |
Charles MacNeill |
10:3687b5e79f98 | 654 | VL53L1CB_ERROR VL53L1CB_WrWord(VL53L1_DEV dev, uint16_t index, uint16_t data); |
Charles MacNeill |
10:3687b5e79f98 | 655 | VL53L1CB_ERROR VL53L1CB_WrDWord(VL53L1_DEV dev, uint16_t index, uint32_t data); |
Charles MacNeill |
10:3687b5e79f98 | 656 | VL53L1CB_ERROR VL53L1CB_RdByte(VL53L1_DEV dev, uint16_t index, uint8_t *data); |
Charles MacNeill |
10:3687b5e79f98 | 657 | VL53L1CB_ERROR VL53L1CB_RdWord(VL53L1_DEV dev, uint16_t index, uint16_t *data); |
Charles MacNeill |
10:3687b5e79f98 | 658 | VL53L1CB_ERROR VL53L1CB_RdDWord(VL53L1_DEV dev, uint16_t index, uint32_t *data); |
Charles MacNeill |
10:3687b5e79f98 | 659 | VL53L1CB_ERROR VL53L1CB_UpdateByte(VL53L1_DEV dev, uint16_t index, uint8_t AndData, uint8_t OrData); |
Charles MacNeill |
9:66969b9016ad | 660 | |
Charles MacNeill |
10:3687b5e79f98 | 661 | VL53L1CB_ERROR VL53L1CB_WriteMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count); |
Charles MacNeill |
10:3687b5e79f98 | 662 | VL53L1CB_ERROR VL53L1CB_ReadMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count); |
Charles MacNeill |
9:66969b9016ad | 663 | |
Charles MacNeill |
10:3687b5e79f98 | 664 | VL53L1CB_ERROR VL53L1CB_I2CWrite(uint8_t dev, uint16_t index, uint8_t *data, uint16_t number_of_bytes); |
Charles MacNeill |
10:3687b5e79f98 | 665 | VL53L1CB_ERROR VL53L1CB_I2CRead(uint8_t dev, uint16_t index, uint8_t *data, uint16_t number_of_bytes); |
Charles MacNeill |
10:3687b5e79f98 | 666 | VL53L1CB_ERROR VL53L1CB_GetTickCount(uint32_t *ptick_count_ms); |
Charles MacNeill |
10:3687b5e79f98 | 667 | VL53L1CB_ERROR VL53L1CB_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us); |
Charles MacNeill |
10:3687b5e79f98 | 668 | VL53L1CB_ERROR VL53L1CB_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms); |
Charles MacNeill |
9:66969b9016ad | 669 | |
Charles MacNeill |
10:3687b5e79f98 | 670 | VL53L1CB_ERROR VL53L1CB_WaitValueMaskEx(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uint16_t index, uint8_t value, uint8_t mask, uint32_t poll_delay_ms); |
Charles MacNeill |
10:3687b5e79f98 | 671 | VL53L1CB_ERROR VL53L1CB_SetDeviceAddress(VL53L1_DEV Dev, uint8_t DeviceAddress); |
Charles MacNeill |
9:66969b9016ad | 672 | |
Charles MacNeill |
9:66969b9016ad | 673 | // from vl53l1_api_debug.c |
Charles MacNeill |
9:66969b9016ad | 674 | |
Charles MacNeill |
10:3687b5e79f98 | 675 | VL53L1CB_ERROR VL53L1CB_get_additional_data( |
Charles MacNeill |
9:66969b9016ad | 676 | VL53L1_DEV Dev, |
Charles MacNeill |
9:66969b9016ad | 677 | VL53L1_additional_data_t *pdata); |
Charles MacNeill |
9:66969b9016ad | 678 | |
Charles MacNeill |
9:66969b9016ad | 679 | |
Charles MacNeill |
9:66969b9016ad | 680 | protected: |
Charles MacNeill |
9:66969b9016ad | 681 | |
Charles MacNeill |
9:66969b9016ad | 682 | /* IO Device */ |
Charles MacNeill |
9:66969b9016ad | 683 | ToF_DevI2C *dev_i2c; |
Charles MacNeill |
9:66969b9016ad | 684 | |
Charles MacNeill |
9:66969b9016ad | 685 | /* Digital out pin */ |
Charles MacNeill |
9:66969b9016ad | 686 | DigitalOut *_gpio0; |
Charles MacNeill |
9:66969b9016ad | 687 | /* GPIO expander */ |
Charles MacNeill |
9:66969b9016ad | 688 | Stmpe1600DigiOut *_expgpio0; |
Charles MacNeill |
9:66969b9016ad | 689 | /* Measure detection IRQ */ |
Charles MacNeill |
9:66969b9016ad | 690 | InterruptIn *_gpio1Int; |
Charles MacNeill |
9:66969b9016ad | 691 | |
Charles MacNeill |
9:66969b9016ad | 692 | ///* Digital out pin */ |
Charles MacNeill |
9:66969b9016ad | 693 | /* Device data */ |
Charles MacNeill |
9:66969b9016ad | 694 | VL53L1_Dev_t MyDevice; |
Charles MacNeill |
9:66969b9016ad | 695 | VL53L1_DEV Device; |
Charles MacNeill |
9:66969b9016ad | 696 | }; |
Charles MacNeill |
9:66969b9016ad | 697 | |
Charles MacNeill |
9:66969b9016ad | 698 | |
Charles MacNeill |
9:66969b9016ad | 699 | #endif /* _VL53L1X_CLASS_H_ */ |