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