Initial release.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: X_NUCLEO_53L1A1_mbed X_NUCLEO_53L1A1_mbed VL53L1X_Ranging_With_Standalone_Satellite_MbedOS X_NUCLEO_53L1A1
VL53L1X_Class.h@9:1d4f91c8df4b, 2021-05-12 (annotated)
- Committer:
- johnAlexander
- Date:
- Wed May 12 10:04:06 2021 +0000
- Revision:
- 9:1d4f91c8df4b
- Parent:
- 8:744e8b1b9837
Add MbedOS v6.x support.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
johnAlexander | 7:6d3ab15363a2 | 1 | /******************************************************************************* |
johnAlexander | 7:6d3ab15363a2 | 2 | * @file VL53L1X_Class.h |
johnAlexander | 7:6d3ab15363a2 | 3 | * @author JS |
johnAlexander | 7:6d3ab15363a2 | 4 | * @version V0.0.1 |
johnAlexander | 7:6d3ab15363a2 | 5 | * @date 15-January-2019 |
johnAlexander | 7:6d3ab15363a2 | 6 | * @brief Header file for VL53L1 sensor component |
johnAlexander | 7:6d3ab15363a2 | 7 | ****************************************************************************** |
johnAlexander | 7:6d3ab15363a2 | 8 | * @attention |
johnAlexander | 7:6d3ab15363a2 | 9 | * |
johnAlexander | 7:6d3ab15363a2 | 10 | * <h2><center>© COPYRIGHT(c) 2019 STMicroelectronics</center></h2> |
johnAlexander | 7:6d3ab15363a2 | 11 | * |
johnAlexander | 7:6d3ab15363a2 | 12 | * Redistribution and use in source and binary forms, with or without modification, |
johnAlexander | 7:6d3ab15363a2 | 13 | * are permitted provided that the following conditions are met: |
johnAlexander | 7:6d3ab15363a2 | 14 | * 1. Redistributions of source code must retain the above copyright notice, |
johnAlexander | 7:6d3ab15363a2 | 15 | * this list of conditions and the following disclaimer. |
johnAlexander | 7:6d3ab15363a2 | 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
johnAlexander | 7:6d3ab15363a2 | 17 | * this list of conditions and the following disclaimer in the documentation |
johnAlexander | 7:6d3ab15363a2 | 18 | * and/or other materials provided with the distribution. |
johnAlexander | 7:6d3ab15363a2 | 19 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
johnAlexander | 7:6d3ab15363a2 | 20 | * may be used to endorse or promote products derived from this software |
johnAlexander | 7:6d3ab15363a2 | 21 | * without specific prior written permission. |
johnAlexander | 7:6d3ab15363a2 | 22 | * |
johnAlexander | 7:6d3ab15363a2 | 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
johnAlexander | 7:6d3ab15363a2 | 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
johnAlexander | 7:6d3ab15363a2 | 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
johnAlexander | 7:6d3ab15363a2 | 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
johnAlexander | 7:6d3ab15363a2 | 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
johnAlexander | 7:6d3ab15363a2 | 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
johnAlexander | 7:6d3ab15363a2 | 29 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
johnAlexander | 7:6d3ab15363a2 | 30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
johnAlexander | 7:6d3ab15363a2 | 31 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
johnAlexander | 7:6d3ab15363a2 | 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
johnAlexander | 7:6d3ab15363a2 | 33 | * |
johnAlexander | 7:6d3ab15363a2 | 34 | *****************************************************************************/ |
johnAlexander | 7:6d3ab15363a2 | 35 | |
johnAlexander | 7:6d3ab15363a2 | 36 | #ifndef __VL53L1X_CLASS_H |
johnAlexander | 7:6d3ab15363a2 | 37 | #define __VL53L1X_CLASS_H |
johnAlexander | 7:6d3ab15363a2 | 38 | |
johnAlexander | 7:6d3ab15363a2 | 39 | |
johnAlexander | 7:6d3ab15363a2 | 40 | #ifdef _MSC_VER |
johnAlexander | 7:6d3ab15363a2 | 41 | # ifdef VL53L1X_API_EXPORTS |
johnAlexander | 7:6d3ab15363a2 | 42 | # define VL53L1X_API __declspec(dllexport) |
johnAlexander | 7:6d3ab15363a2 | 43 | # else |
johnAlexander | 7:6d3ab15363a2 | 44 | # define VL53L1X_API |
johnAlexander | 7:6d3ab15363a2 | 45 | # endif |
johnAlexander | 7:6d3ab15363a2 | 46 | #else |
johnAlexander | 7:6d3ab15363a2 | 47 | # define VL53L1X_API |
johnAlexander | 7:6d3ab15363a2 | 48 | #endif |
johnAlexander | 7:6d3ab15363a2 | 49 | |
johnAlexander | 7:6d3ab15363a2 | 50 | |
johnAlexander | 7:6d3ab15363a2 | 51 | /* Includes ------------------------------------------------------------------*/ |
johnAlexander | 7:6d3ab15363a2 | 52 | #include "mbed.h" |
johnAlexander | 7:6d3ab15363a2 | 53 | #include "PinNames.h" |
johnAlexander | 7:6d3ab15363a2 | 54 | #include "RangeSensor.h" |
johnAlexander | 7:6d3ab15363a2 | 55 | #include "vl53l1x_error_codes.h" |
johnAlexander | 7:6d3ab15363a2 | 56 | #include "VL53L1X_I2C.h" |
johnAlexander | 7:6d3ab15363a2 | 57 | #include "Stmpe1600.h" |
johnAlexander | 7:6d3ab15363a2 | 58 | |
johnAlexander | 7:6d3ab15363a2 | 59 | |
johnAlexander | 7:6d3ab15363a2 | 60 | #define VL53L1X_IMPLEMENTATION_VER_MAJOR 1 |
johnAlexander | 7:6d3ab15363a2 | 61 | #define VL53L1X_IMPLEMENTATION_VER_MINOR 0 |
johnAlexander | 7:6d3ab15363a2 | 62 | #define VL53L1X_IMPLEMENTATION_VER_SUB 1 |
johnAlexander | 7:6d3ab15363a2 | 63 | #define VL53L1X_IMPLEMENTATION_VER_REVISION 0000 |
johnAlexander | 7:6d3ab15363a2 | 64 | |
johnAlexander | 7:6d3ab15363a2 | 65 | typedef int8_t VL53L1X_ERROR; |
johnAlexander | 7:6d3ab15363a2 | 66 | |
johnAlexander | 7:6d3ab15363a2 | 67 | #define VL53L1_I2C_SLAVE__DEVICE_ADDRESS 0x0001 |
johnAlexander | 7:6d3ab15363a2 | 68 | #define VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND 0x0008 |
johnAlexander | 7:6d3ab15363a2 | 69 | #define ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS 0x0016 |
johnAlexander | 7:6d3ab15363a2 | 70 | #define ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS 0x0018 |
johnAlexander | 7:6d3ab15363a2 | 71 | #define ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS 0x001A |
johnAlexander | 7:6d3ab15363a2 | 72 | #define ALGO__PART_TO_PART_RANGE_OFFSET_MM 0x001E |
johnAlexander | 7:6d3ab15363a2 | 73 | #define MM_CONFIG__INNER_OFFSET_MM 0x0020 |
johnAlexander | 7:6d3ab15363a2 | 74 | #define MM_CONFIG__OUTER_OFFSET_MM 0x0022 |
johnAlexander | 7:6d3ab15363a2 | 75 | #define GPIO_HV_MUX__CTRL 0x0030 |
johnAlexander | 7:6d3ab15363a2 | 76 | #define GPIO__TIO_HV_STATUS 0x0031 |
johnAlexander | 7:6d3ab15363a2 | 77 | #define SYSTEM__INTERRUPT_CONFIG_GPIO 0x0046 |
johnAlexander | 7:6d3ab15363a2 | 78 | #define PHASECAL_CONFIG__TIMEOUT_MACROP 0x004B |
johnAlexander | 7:6d3ab15363a2 | 79 | #define RANGE_CONFIG__TIMEOUT_MACROP_A_HI 0x005E |
johnAlexander | 7:6d3ab15363a2 | 80 | #define RANGE_CONFIG__VCSEL_PERIOD_A 0x0060 |
johnAlexander | 7:6d3ab15363a2 | 81 | #define RANGE_CONFIG__VCSEL_PERIOD_B 0x0063 |
johnAlexander | 7:6d3ab15363a2 | 82 | #define RANGE_CONFIG__TIMEOUT_MACROP_B_HI 0x0061 |
johnAlexander | 7:6d3ab15363a2 | 83 | #define RANGE_CONFIG__TIMEOUT_MACROP_B_LO 0x0062 |
johnAlexander | 7:6d3ab15363a2 | 84 | #define RANGE_CONFIG__SIGMA_THRESH 0x0064 |
johnAlexander | 7:6d3ab15363a2 | 85 | #define RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS 0x0066 |
johnAlexander | 7:6d3ab15363a2 | 86 | #define RANGE_CONFIG__VALID_PHASE_HIGH 0x0069 |
johnAlexander | 7:6d3ab15363a2 | 87 | #define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD 0x006C |
johnAlexander | 7:6d3ab15363a2 | 88 | #define SYSTEM__THRESH_HIGH 0x0072 |
johnAlexander | 7:6d3ab15363a2 | 89 | #define SYSTEM__THRESH_LOW 0x0074 |
johnAlexander | 7:6d3ab15363a2 | 90 | #define SD_CONFIG__WOI_SD0 0x0078 |
johnAlexander | 7:6d3ab15363a2 | 91 | #define SD_CONFIG__INITIAL_PHASE_SD0 0x007A |
johnAlexander | 7:6d3ab15363a2 | 92 | #define ROI_CONFIG__USER_ROI_CENTRE_SPAD 0x007F |
johnAlexander | 7:6d3ab15363a2 | 93 | #define ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE 0x0080 |
johnAlexander | 7:6d3ab15363a2 | 94 | #define SYSTEM__SEQUENCE_CONFIG 0x0081 |
johnAlexander | 7:6d3ab15363a2 | 95 | #define VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD 0x0082 |
johnAlexander | 7:6d3ab15363a2 | 96 | #define SYSTEM__INTERRUPT_CLEAR 0x0086 |
johnAlexander | 7:6d3ab15363a2 | 97 | #define SYSTEM__MODE_START 0x0087 |
johnAlexander | 7:6d3ab15363a2 | 98 | #define VL53L1_RESULT__RANGE_STATUS 0x0089 |
johnAlexander | 7:6d3ab15363a2 | 99 | #define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0 0x008C |
johnAlexander | 7:6d3ab15363a2 | 100 | #define RESULT__AMBIENT_COUNT_RATE_MCPS_SD 0x0090 |
johnAlexander | 7:6d3ab15363a2 | 101 | #define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0 0x0096 |
johnAlexander | 7:6d3ab15363a2 | 102 | #define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0 0x0098 |
johnAlexander | 7:6d3ab15363a2 | 103 | #define VL53L1_RESULT__OSC_CALIBRATE_VAL 0x00DE |
johnAlexander | 7:6d3ab15363a2 | 104 | #define VL53L1_FIRMWARE__SYSTEM_STATUS 0x00E5 |
johnAlexander | 7:6d3ab15363a2 | 105 | #define VL53L1_IDENTIFICATION__MODEL_ID 0x010F |
johnAlexander | 7:6d3ab15363a2 | 106 | #define VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD 0x013E |
johnAlexander | 7:6d3ab15363a2 | 107 | |
johnAlexander | 7:6d3ab15363a2 | 108 | |
johnAlexander | 7:6d3ab15363a2 | 109 | #define VL53L1X_DEFAULT_DEVICE_ADDRESS 0x52 |
johnAlexander | 7:6d3ab15363a2 | 110 | |
johnAlexander | 7:6d3ab15363a2 | 111 | #define VL53L1X_REG_IDENTIFICATION_MODEL_ID 0x010F |
johnAlexander | 7:6d3ab15363a2 | 112 | /**************************************** |
johnAlexander | 7:6d3ab15363a2 | 113 | * PRIVATE define do not edit |
johnAlexander | 7:6d3ab15363a2 | 114 | ****************************************/ |
johnAlexander | 7:6d3ab15363a2 | 115 | |
johnAlexander | 7:6d3ab15363a2 | 116 | /** |
johnAlexander | 7:6d3ab15363a2 | 117 | * @brief defines SW Version |
johnAlexander | 7:6d3ab15363a2 | 118 | */ |
johnAlexander | 7:6d3ab15363a2 | 119 | typedef struct { |
johnAlexander | 7:6d3ab15363a2 | 120 | uint8_t major; /*!< major number */ |
johnAlexander | 7:6d3ab15363a2 | 121 | uint8_t minor; /*!< minor number */ |
johnAlexander | 7:6d3ab15363a2 | 122 | uint8_t build; /*!< build number */ |
johnAlexander | 7:6d3ab15363a2 | 123 | uint32_t revision; /*!< revision number */ |
johnAlexander | 7:6d3ab15363a2 | 124 | } VL53L1X_Version_t; |
johnAlexander | 7:6d3ab15363a2 | 125 | |
johnAlexander | 7:6d3ab15363a2 | 126 | |
johnAlexander | 7:6d3ab15363a2 | 127 | typedef struct { |
johnAlexander | 7:6d3ab15363a2 | 128 | |
johnAlexander | 7:6d3ab15363a2 | 129 | uint8_t I2cDevAddr; |
johnAlexander | 7:6d3ab15363a2 | 130 | |
johnAlexander | 7:6d3ab15363a2 | 131 | } VL53L1_Dev_t; |
johnAlexander | 7:6d3ab15363a2 | 132 | |
johnAlexander | 7:6d3ab15363a2 | 133 | typedef VL53L1_Dev_t *VL53L1_DEV; |
johnAlexander | 7:6d3ab15363a2 | 134 | |
johnAlexander | 7:6d3ab15363a2 | 135 | |
johnAlexander | 7:6d3ab15363a2 | 136 | /* Classes -------------------------------------------------------------------*/ |
johnAlexander | 7:6d3ab15363a2 | 137 | /** Class representing a VL53L1 sensor component |
johnAlexander | 7:6d3ab15363a2 | 138 | */ |
johnAlexander | 7:6d3ab15363a2 | 139 | class VL53L1X : public RangeSensor |
johnAlexander | 7:6d3ab15363a2 | 140 | { |
johnAlexander | 7:6d3ab15363a2 | 141 | public: |
johnAlexander | 7:6d3ab15363a2 | 142 | /** Constructor |
johnAlexander | 7:6d3ab15363a2 | 143 | * @param[in] &i2c device I2C to be used for communication |
johnAlexander | 7:6d3ab15363a2 | 144 | * @param[in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT |
johnAlexander | 7:6d3ab15363a2 | 145 | * @param[in] DevAddr device address, 0x52 by default |
johnAlexander | 7:6d3ab15363a2 | 146 | */ |
johnAlexander | 7:6d3ab15363a2 | 147 | VL53L1X(VL53L1X_DevI2C *i2c, DigitalOut *pin, PinName pin_gpio1, uint8_t dev_addr = VL53L1X_DEFAULT_DEVICE_ADDRESS) |
johnAlexander | 7:6d3ab15363a2 | 148 | : RangeSensor(), dev_i2c(i2c), _gpio0(pin) |
johnAlexander | 7:6d3ab15363a2 | 149 | { |
johnAlexander | 7:6d3ab15363a2 | 150 | MyDevice.I2cDevAddr=dev_addr; |
johnAlexander | 7:6d3ab15363a2 | 151 | Device = &MyDevice; |
johnAlexander | 7:6d3ab15363a2 | 152 | |
johnAlexander | 7:6d3ab15363a2 | 153 | _expgpio0 = NULL; |
johnAlexander | 7:6d3ab15363a2 | 154 | if (pin_gpio1 != NC) { |
johnAlexander | 7:6d3ab15363a2 | 155 | _gpio1Int = new InterruptIn(pin_gpio1); |
johnAlexander | 7:6d3ab15363a2 | 156 | } else { |
johnAlexander | 7:6d3ab15363a2 | 157 | _gpio1Int = NULL; |
johnAlexander | 7:6d3ab15363a2 | 158 | } |
johnAlexander | 7:6d3ab15363a2 | 159 | } |
johnAlexander | 7:6d3ab15363a2 | 160 | |
johnAlexander | 7:6d3ab15363a2 | 161 | /** Constructor 2 (STMPE1600DigiOut) |
johnAlexander | 7:6d3ab15363a2 | 162 | * @param[in] i2c device I2C to be used for communication |
johnAlexander | 7:6d3ab15363a2 | 163 | * @param[in] &pin Gpio Expander STMPE1600DigiOut pin to be used as component GPIO_0 CE |
johnAlexander | 7:6d3ab15363a2 | 164 | * @param[in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT |
johnAlexander | 7:6d3ab15363a2 | 165 | * @param[in] device address, 0x29 by default |
johnAlexander | 7:6d3ab15363a2 | 166 | */ |
johnAlexander | 7:6d3ab15363a2 | 167 | VL53L1X(VL53L1X_DevI2C *i2c, Stmpe1600DigiOut *pin, PinName pin_gpio1, |
johnAlexander | 7:6d3ab15363a2 | 168 | uint8_t dev_addr = VL53L1X_DEFAULT_DEVICE_ADDRESS) |
johnAlexander | 7:6d3ab15363a2 | 169 | : dev_i2c(i2c), _expgpio0(pin) |
johnAlexander | 7:6d3ab15363a2 | 170 | { |
johnAlexander | 7:6d3ab15363a2 | 171 | MyDevice.I2cDevAddr=dev_addr; |
johnAlexander | 7:6d3ab15363a2 | 172 | Device = &MyDevice; |
johnAlexander | 7:6d3ab15363a2 | 173 | |
johnAlexander | 7:6d3ab15363a2 | 174 | _gpio0 = NULL; |
johnAlexander | 7:6d3ab15363a2 | 175 | if (pin_gpio1 != NC) { |
johnAlexander | 7:6d3ab15363a2 | 176 | _gpio1Int = new InterruptIn(pin_gpio1); |
johnAlexander | 7:6d3ab15363a2 | 177 | } else { |
johnAlexander | 7:6d3ab15363a2 | 178 | _gpio1Int = NULL; |
johnAlexander | 7:6d3ab15363a2 | 179 | } |
johnAlexander | 7:6d3ab15363a2 | 180 | } |
johnAlexander | 7:6d3ab15363a2 | 181 | |
johnAlexander | 7:6d3ab15363a2 | 182 | /** Destructor |
johnAlexander | 7:6d3ab15363a2 | 183 | */ |
johnAlexander | 7:6d3ab15363a2 | 184 | virtual ~VL53L1X() |
johnAlexander | 7:6d3ab15363a2 | 185 | { |
johnAlexander | 7:6d3ab15363a2 | 186 | if (_gpio1Int != NULL) { |
johnAlexander | 7:6d3ab15363a2 | 187 | delete _gpio1Int; |
johnAlexander | 7:6d3ab15363a2 | 188 | } |
johnAlexander | 7:6d3ab15363a2 | 189 | } |
johnAlexander | 7:6d3ab15363a2 | 190 | |
johnAlexander | 7:6d3ab15363a2 | 191 | |
johnAlexander | 7:6d3ab15363a2 | 192 | |
johnAlexander | 7:6d3ab15363a2 | 193 | VL53L1_DEV getDevicePtr() { return Device; } |
johnAlexander | 7:6d3ab15363a2 | 194 | |
johnAlexander | 7:6d3ab15363a2 | 195 | |
johnAlexander | 7:6d3ab15363a2 | 196 | /* warning: VL53L1 class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor. |
johnAlexander | 7:6d3ab15363a2 | 197 | The warning should request to introduce a virtual destructor to make sure to delete the object */ |
johnAlexander | 7:6d3ab15363a2 | 198 | |
johnAlexander | 7:6d3ab15363a2 | 199 | /*** Interface Methods ***/ |
johnAlexander | 7:6d3ab15363a2 | 200 | /*** High level API ***/ |
johnAlexander | 7:6d3ab15363a2 | 201 | /** |
johnAlexander | 7:6d3ab15363a2 | 202 | * @brief PowerOn the sensor |
johnAlexander | 7:6d3ab15363a2 | 203 | * @return void |
johnAlexander | 7:6d3ab15363a2 | 204 | */ |
johnAlexander | 7:6d3ab15363a2 | 205 | /* turns on the sensor */ |
johnAlexander | 7:6d3ab15363a2 | 206 | virtual void vl53l1_on(void) |
johnAlexander | 7:6d3ab15363a2 | 207 | { |
johnAlexander | 7:6d3ab15363a2 | 208 | printf("VL53L1_On\r\n"); |
johnAlexander | 7:6d3ab15363a2 | 209 | if (_gpio0) { |
johnAlexander | 7:6d3ab15363a2 | 210 | *_gpio0 = 1; |
johnAlexander | 7:6d3ab15363a2 | 211 | } else { |
johnAlexander | 7:6d3ab15363a2 | 212 | if (_expgpio0) { |
johnAlexander | 7:6d3ab15363a2 | 213 | *_expgpio0 = 1; |
johnAlexander | 7:6d3ab15363a2 | 214 | } |
johnAlexander | 7:6d3ab15363a2 | 215 | } |
johnAlexander | 9:1d4f91c8df4b | 216 | // wait_ms(10); |
johnAlexander | 9:1d4f91c8df4b | 217 | #if (MBED_VERSION > 60300) |
johnAlexander | 9:1d4f91c8df4b | 218 | thread_sleep_for(10); |
johnAlexander | 9:1d4f91c8df4b | 219 | #else |
johnAlexander | 9:1d4f91c8df4b | 220 | wait_ms(10); // NEEDS A DELAY BETWEEN SENSORS |
johnAlexander | 9:1d4f91c8df4b | 221 | #endif |
johnAlexander | 7:6d3ab15363a2 | 222 | } |
johnAlexander | 7:6d3ab15363a2 | 223 | |
johnAlexander | 7:6d3ab15363a2 | 224 | /** |
johnAlexander | 7:6d3ab15363a2 | 225 | * @brief PowerOff the sensor |
johnAlexander | 7:6d3ab15363a2 | 226 | * @return void |
johnAlexander | 7:6d3ab15363a2 | 227 | */ |
johnAlexander | 7:6d3ab15363a2 | 228 | /* turns off the sensor */ |
johnAlexander | 7:6d3ab15363a2 | 229 | virtual void vl53l1_off(void) |
johnAlexander | 7:6d3ab15363a2 | 230 | { |
johnAlexander | 7:6d3ab15363a2 | 231 | printf("VL53L1_Off\r\n"); |
johnAlexander | 7:6d3ab15363a2 | 232 | if (_gpio0) { |
johnAlexander | 7:6d3ab15363a2 | 233 | *_gpio0 = 0; |
johnAlexander | 7:6d3ab15363a2 | 234 | } else { |
johnAlexander | 7:6d3ab15363a2 | 235 | if (_expgpio0) { |
johnAlexander | 7:6d3ab15363a2 | 236 | *_expgpio0 = 0; |
johnAlexander | 7:6d3ab15363a2 | 237 | } |
johnAlexander | 7:6d3ab15363a2 | 238 | } |
johnAlexander | 9:1d4f91c8df4b | 239 | // wait_ms(10); |
johnAlexander | 9:1d4f91c8df4b | 240 | #if (MBED_VERSION > 60300) |
johnAlexander | 9:1d4f91c8df4b | 241 | thread_sleep_for(10); |
johnAlexander | 9:1d4f91c8df4b | 242 | #else |
johnAlexander | 9:1d4f91c8df4b | 243 | wait_ms(10); // NEEDS A DELAY BETWEEN SENSORS |
johnAlexander | 9:1d4f91c8df4b | 244 | #endif |
johnAlexander | 7:6d3ab15363a2 | 245 | } |
johnAlexander | 7:6d3ab15363a2 | 246 | |
johnAlexander | 7:6d3ab15363a2 | 247 | int is_present() |
johnAlexander | 7:6d3ab15363a2 | 248 | { |
johnAlexander | 7:6d3ab15363a2 | 249 | int status; |
johnAlexander | 7:6d3ab15363a2 | 250 | uint8_t id = 0; |
johnAlexander | 7:6d3ab15363a2 | 251 | |
johnAlexander | 7:6d3ab15363a2 | 252 | status = read_id(&id); |
johnAlexander | 7:6d3ab15363a2 | 253 | if (status) { |
johnAlexander | 7:6d3ab15363a2 | 254 | printf("Failed to read ID device. Device not present!\n\r"); |
johnAlexander | 7:6d3ab15363a2 | 255 | } |
johnAlexander | 7:6d3ab15363a2 | 256 | return status; |
johnAlexander | 7:6d3ab15363a2 | 257 | } |
johnAlexander | 7:6d3ab15363a2 | 258 | |
johnAlexander | 7:6d3ab15363a2 | 259 | /** |
johnAlexander | 7:6d3ab15363a2 | 260 | * @brief Initialize the sensor with default values |
johnAlexander | 7:6d3ab15363a2 | 261 | * @return 0 on Success |
johnAlexander | 7:6d3ab15363a2 | 262 | */ |
johnAlexander | 7:6d3ab15363a2 | 263 | |
johnAlexander | 8:744e8b1b9837 | 264 | VL53L1X_ERROR init_sensor(uint8_t address){ |
johnAlexander | 7:6d3ab15363a2 | 265 | VL53L1X_ERROR status = 0; |
johnAlexander | 7:6d3ab15363a2 | 266 | uint8_t sensorState = 0; |
johnAlexander | 7:6d3ab15363a2 | 267 | vl53l1_off(); |
johnAlexander | 7:6d3ab15363a2 | 268 | vl53l1_on(); |
johnAlexander | 7:6d3ab15363a2 | 269 | status = vl53l1x_set_i2c_address(address); |
johnAlexander | 7:6d3ab15363a2 | 270 | |
johnAlexander | 7:6d3ab15363a2 | 271 | if(!status){ |
johnAlexander | 7:6d3ab15363a2 | 272 | status = vl53l1x_sensor_init(); |
johnAlexander | 7:6d3ab15363a2 | 273 | } |
johnAlexander | 7:6d3ab15363a2 | 274 | |
johnAlexander | 7:6d3ab15363a2 | 275 | while(!status && !sensorState) { |
johnAlexander | 7:6d3ab15363a2 | 276 | status = vl53l1x_boot_state(&sensorState); |
johnAlexander | 9:1d4f91c8df4b | 277 | // wait_ms(2); |
johnAlexander | 9:1d4f91c8df4b | 278 | #if (MBED_VERSION > 60300) |
johnAlexander | 9:1d4f91c8df4b | 279 | thread_sleep_for(2); |
johnAlexander | 9:1d4f91c8df4b | 280 | #else |
johnAlexander | 9:1d4f91c8df4b | 281 | wait_ms(2); // NEEDS A DELAY BETWEEN SENSORS |
johnAlexander | 9:1d4f91c8df4b | 282 | #endif |
johnAlexander | 7:6d3ab15363a2 | 283 | } |
johnAlexander | 7:6d3ab15363a2 | 284 | |
johnAlexander | 7:6d3ab15363a2 | 285 | return status; |
johnAlexander | 7:6d3ab15363a2 | 286 | } |
johnAlexander | 7:6d3ab15363a2 | 287 | |
johnAlexander | 7:6d3ab15363a2 | 288 | |
johnAlexander | 7:6d3ab15363a2 | 289 | |
johnAlexander | 7:6d3ab15363a2 | 290 | /** |
johnAlexander | 7:6d3ab15363a2 | 291 | * |
johnAlexander | 7:6d3ab15363a2 | 292 | * @brief One time device initialization |
johnAlexander | 7:6d3ab15363a2 | 293 | * @param void |
johnAlexander | 7:6d3ab15363a2 | 294 | * @return 0 on success, @a #CALIBRATION_WARNING if failed |
johnAlexander | 7:6d3ab15363a2 | 295 | */ |
johnAlexander | 7:6d3ab15363a2 | 296 | virtual int init(void *init) |
johnAlexander | 7:6d3ab15363a2 | 297 | { |
johnAlexander | 7:6d3ab15363a2 | 298 | return vl53l1x_sensor_init(); |
johnAlexander | 7:6d3ab15363a2 | 299 | |
johnAlexander | 7:6d3ab15363a2 | 300 | } |
johnAlexander | 7:6d3ab15363a2 | 301 | |
johnAlexander | 7:6d3ab15363a2 | 302 | /* Read function of the ID device */ |
johnAlexander | 7:6d3ab15363a2 | 303 | virtual int read_id(uint8_t *id){ |
johnAlexander | 7:6d3ab15363a2 | 304 | int status = 0; |
johnAlexander | 7:6d3ab15363a2 | 305 | uint16_t rl_id = 0; |
johnAlexander | 7:6d3ab15363a2 | 306 | |
johnAlexander | 7:6d3ab15363a2 | 307 | uint8_t ExpanderData[2]; |
johnAlexander | 7:6d3ab15363a2 | 308 | |
johnAlexander | 7:6d3ab15363a2 | 309 | ExpanderData[0] = 0; |
johnAlexander | 7:6d3ab15363a2 | 310 | ExpanderData[1] = 0; |
johnAlexander | 7:6d3ab15363a2 | 311 | rl_id = 0; |
johnAlexander | 7:6d3ab15363a2 | 312 | dev_i2c->v53l1x_i2c_read(&ExpanderData[0], Device->I2cDevAddr, VL53L1X_REG_IDENTIFICATION_MODEL_ID, 2); |
johnAlexander | 7:6d3ab15363a2 | 313 | |
johnAlexander | 7:6d3ab15363a2 | 314 | rl_id = (ExpanderData[0] << 8) + ExpanderData[1]; |
johnAlexander | 7:6d3ab15363a2 | 315 | printf("Model ID is: %d (%X) \r\n",rl_id, rl_id); |
johnAlexander | 7:6d3ab15363a2 | 316 | |
johnAlexander | 7:6d3ab15363a2 | 317 | uint8_t tmp = 0; |
johnAlexander | 7:6d3ab15363a2 | 318 | ExpanderData[0] = VL53L1_FIRMWARE__SYSTEM_STATUS >> 8; |
johnAlexander | 7:6d3ab15363a2 | 319 | ExpanderData[1] = VL53L1_FIRMWARE__SYSTEM_STATUS & 0x0FF; |
johnAlexander | 7:6d3ab15363a2 | 320 | dev_i2c->v53l1x_i2c_read(&tmp, Device->I2cDevAddr, VL53L1_FIRMWARE__SYSTEM_STATUS, 1); |
johnAlexander | 7:6d3ab15363a2 | 321 | |
johnAlexander | 7:6d3ab15363a2 | 322 | printf("Firmware system is: %d\r\n",tmp); |
johnAlexander | 7:6d3ab15363a2 | 323 | |
johnAlexander | 7:6d3ab15363a2 | 324 | if (rl_id == 0xEACC) { |
johnAlexander | 7:6d3ab15363a2 | 325 | printf("Device is present %d:\r\n", rl_id); |
johnAlexander | 7:6d3ab15363a2 | 326 | return status; |
johnAlexander | 7:6d3ab15363a2 | 327 | } |
johnAlexander | 7:6d3ab15363a2 | 328 | return -1; |
johnAlexander | 7:6d3ab15363a2 | 329 | } |
johnAlexander | 7:6d3ab15363a2 | 330 | |
johnAlexander | 7:6d3ab15363a2 | 331 | /** |
johnAlexander | 7:6d3ab15363a2 | 332 | * @brief Interrupt handling func to be called by user after an INT is occurred |
johnAlexander | 7:6d3ab15363a2 | 333 | * @param[out] Data pointer to the distance to read data in to |
johnAlexander | 7:6d3ab15363a2 | 334 | * @return 0 on Success |
johnAlexander | 7:6d3ab15363a2 | 335 | */ |
johnAlexander | 7:6d3ab15363a2 | 336 | int handle_irq(uint16_t *distance); |
johnAlexander | 7:6d3ab15363a2 | 337 | |
johnAlexander | 7:6d3ab15363a2 | 338 | /** |
johnAlexander | 7:6d3ab15363a2 | 339 | * @brief Start the measure indicated by operating mode |
johnAlexander | 7:6d3ab15363a2 | 340 | * @param[in] fptr specifies call back function must be !NULL in case of interrupt measure |
johnAlexander | 7:6d3ab15363a2 | 341 | * @return 0 on Success |
johnAlexander | 7:6d3ab15363a2 | 342 | */ |
johnAlexander | 7:6d3ab15363a2 | 343 | int start_measurement(void (*fptr)(void)); |
johnAlexander | 7:6d3ab15363a2 | 344 | /** |
johnAlexander | 7:6d3ab15363a2 | 345 | * @brief Stop the currently running measure indicate by operating_mode |
johnAlexander | 7:6d3ab15363a2 | 346 | * @return 0 on Success |
johnAlexander | 7:6d3ab15363a2 | 347 | */ |
johnAlexander | 7:6d3ab15363a2 | 348 | int stop_measurement(); |
johnAlexander | 7:6d3ab15363a2 | 349 | /** |
johnAlexander | 7:6d3ab15363a2 | 350 | * @brief Get results for the measure |
johnAlexander | 7:6d3ab15363a2 | 351 | * @param[out] Data pointer to the distance_data to read data in to |
johnAlexander | 7:6d3ab15363a2 | 352 | * @return 0 on Success |
johnAlexander | 7:6d3ab15363a2 | 353 | */ |
johnAlexander | 7:6d3ab15363a2 | 354 | int get_measurement(uint16_t *distance); |
johnAlexander | 7:6d3ab15363a2 | 355 | /** |
johnAlexander | 7:6d3ab15363a2 | 356 | * @brief Enable interrupt measure IRQ |
johnAlexander | 7:6d3ab15363a2 | 357 | * @return 0 on Success |
johnAlexander | 7:6d3ab15363a2 | 358 | */ |
johnAlexander | 7:6d3ab15363a2 | 359 | void enable_interrupt_measure_detection_irq(void) |
johnAlexander | 7:6d3ab15363a2 | 360 | { |
johnAlexander | 7:6d3ab15363a2 | 361 | if (_gpio1Int != NULL) |
johnAlexander | 7:6d3ab15363a2 | 362 | _gpio1Int->enable_irq(); |
johnAlexander | 7:6d3ab15363a2 | 363 | } |
johnAlexander | 7:6d3ab15363a2 | 364 | |
johnAlexander | 7:6d3ab15363a2 | 365 | /** |
johnAlexander | 7:6d3ab15363a2 | 366 | * @brief Disable interrupt measure IRQ |
johnAlexander | 7:6d3ab15363a2 | 367 | * @return 0 on Success |
johnAlexander | 7:6d3ab15363a2 | 368 | */ |
johnAlexander | 7:6d3ab15363a2 | 369 | void disable_interrupt_measure_detection_irq(void) |
johnAlexander | 7:6d3ab15363a2 | 370 | { |
johnAlexander | 7:6d3ab15363a2 | 371 | if (_gpio1Int != NULL) |
johnAlexander | 7:6d3ab15363a2 | 372 | _gpio1Int->disable_irq(); |
johnAlexander | 7:6d3ab15363a2 | 373 | } |
johnAlexander | 7:6d3ab15363a2 | 374 | /** |
johnAlexander | 7:6d3ab15363a2 | 375 | * @brief Attach a function to call when an interrupt is detected, i.e. measurement is ready |
johnAlexander | 7:6d3ab15363a2 | 376 | * @param[in] fptr pointer to call back function to be called whenever an interrupt occours |
johnAlexander | 7:6d3ab15363a2 | 377 | * @return 0 on Success |
johnAlexander | 7:6d3ab15363a2 | 378 | */ |
johnAlexander | 7:6d3ab15363a2 | 379 | void attach_interrupt_measure_detection_irq(void (*fptr)(void)) |
johnAlexander | 7:6d3ab15363a2 | 380 | { |
johnAlexander | 7:6d3ab15363a2 | 381 | if (_gpio1Int != NULL) |
johnAlexander | 7:6d3ab15363a2 | 382 | _gpio1Int->rise(fptr); |
johnAlexander | 7:6d3ab15363a2 | 383 | } |
johnAlexander | 7:6d3ab15363a2 | 384 | /** |
johnAlexander | 7:6d3ab15363a2 | 385 | * @brief Get ranging result and only that |
johnAlexander | 7:6d3ab15363a2 | 386 | * @param pRange_mm Pointer to range distance |
johnAlexander | 7:6d3ab15363a2 | 387 | * @return 0 on success |
johnAlexander | 7:6d3ab15363a2 | 388 | */ |
johnAlexander | 7:6d3ab15363a2 | 389 | virtual int get_distance(uint32_t *piData) |
johnAlexander | 7:6d3ab15363a2 | 390 | { |
johnAlexander | 7:6d3ab15363a2 | 391 | int status; |
johnAlexander | 7:6d3ab15363a2 | 392 | uint16_t distance; |
johnAlexander | 7:6d3ab15363a2 | 393 | status = vl53l1x_get_distance(&distance); |
johnAlexander | 7:6d3ab15363a2 | 394 | *piData = (uint32_t) distance; |
johnAlexander | 7:6d3ab15363a2 | 395 | return status; |
johnAlexander | 7:6d3ab15363a2 | 396 | } |
johnAlexander | 7:6d3ab15363a2 | 397 | |
johnAlexander | 7:6d3ab15363a2 | 398 | |
johnAlexander | 7:6d3ab15363a2 | 399 | /* VL53L1X_api.h functions */ |
johnAlexander | 7:6d3ab15363a2 | 400 | |
johnAlexander | 7:6d3ab15363a2 | 401 | /** |
johnAlexander | 7:6d3ab15363a2 | 402 | * @brief This function returns the SW driver version |
johnAlexander | 7:6d3ab15363a2 | 403 | */ |
johnAlexander | 7:6d3ab15363a2 | 404 | VL53L1X_ERROR vl53l1x_get_sw_version(VL53L1X_Version_t *pVersion); |
johnAlexander | 7:6d3ab15363a2 | 405 | |
johnAlexander | 7:6d3ab15363a2 | 406 | /** |
johnAlexander | 7:6d3ab15363a2 | 407 | * @brief This function sets the sensor I2C address used in case multiple devices application, default address 0x52 |
johnAlexander | 7:6d3ab15363a2 | 408 | */ |
johnAlexander | 7:6d3ab15363a2 | 409 | VL53L1X_ERROR vl53l1x_set_i2c_address(uint8_t new_address); |
johnAlexander | 7:6d3ab15363a2 | 410 | |
johnAlexander | 7:6d3ab15363a2 | 411 | /** |
johnAlexander | 7:6d3ab15363a2 | 412 | * @brief This function loads the 135 bytes default values to initialize the sensor. |
johnAlexander | 7:6d3ab15363a2 | 413 | * @param dev Device address |
johnAlexander | 7:6d3ab15363a2 | 414 | * @return 0:success, != 0:failed |
johnAlexander | 7:6d3ab15363a2 | 415 | */ |
johnAlexander | 7:6d3ab15363a2 | 416 | VL53L1X_ERROR vl53l1x_sensor_init(); |
johnAlexander | 7:6d3ab15363a2 | 417 | |
johnAlexander | 7:6d3ab15363a2 | 418 | /** |
johnAlexander | 7:6d3ab15363a2 | 419 | * @brief This function clears the interrupt, to be called after a ranging data reading |
johnAlexander | 7:6d3ab15363a2 | 420 | * to arm the interrupt for the next data ready event. |
johnAlexander | 7:6d3ab15363a2 | 421 | */ |
johnAlexander | 7:6d3ab15363a2 | 422 | VL53L1X_ERROR vl53l1x_clear_interrupt(); |
johnAlexander | 7:6d3ab15363a2 | 423 | |
johnAlexander | 7:6d3ab15363a2 | 424 | /** |
johnAlexander | 7:6d3ab15363a2 | 425 | * @brief This function programs the interrupt polarity\n |
johnAlexander | 7:6d3ab15363a2 | 426 | * 1=active high (default), 0=active low |
johnAlexander | 7:6d3ab15363a2 | 427 | */ |
johnAlexander | 7:6d3ab15363a2 | 428 | VL53L1X_ERROR vl53l1x_set_interrupt_polarity(uint8_t IntPol); |
johnAlexander | 7:6d3ab15363a2 | 429 | |
johnAlexander | 7:6d3ab15363a2 | 430 | /** |
johnAlexander | 7:6d3ab15363a2 | 431 | * @brief This function returns the current interrupt polarity\n |
johnAlexander | 7:6d3ab15363a2 | 432 | * 1=active high (default), 0=active low |
johnAlexander | 7:6d3ab15363a2 | 433 | */ |
johnAlexander | 7:6d3ab15363a2 | 434 | VL53L1X_ERROR vl53l1x_get_interrupt_polarity(uint8_t *pIntPol); |
johnAlexander | 7:6d3ab15363a2 | 435 | |
johnAlexander | 7:6d3ab15363a2 | 436 | /** |
johnAlexander | 7:6d3ab15363a2 | 437 | * @brief This function starts the ranging distance operation\n |
johnAlexander | 7:6d3ab15363a2 | 438 | * 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 |
johnAlexander | 7:6d3ab15363a2 | 439 | * 1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required. |
johnAlexander | 7:6d3ab15363a2 | 440 | */ |
johnAlexander | 7:6d3ab15363a2 | 441 | VL53L1X_ERROR vl53l1x_start_ranging(); |
johnAlexander | 7:6d3ab15363a2 | 442 | |
johnAlexander | 7:6d3ab15363a2 | 443 | /** |
johnAlexander | 7:6d3ab15363a2 | 444 | * @brief This function stops the ranging. |
johnAlexander | 7:6d3ab15363a2 | 445 | */ |
johnAlexander | 7:6d3ab15363a2 | 446 | VL53L1X_ERROR vl53l1x_stop_ranging(); |
johnAlexander | 7:6d3ab15363a2 | 447 | |
johnAlexander | 7:6d3ab15363a2 | 448 | /** |
johnAlexander | 7:6d3ab15363a2 | 449 | * @brief This function checks if the new ranging data is available by polling the dedicated register. |
johnAlexander | 7:6d3ab15363a2 | 450 | * @param : isDataReady==0 -> not ready; isDataReady==1 -> ready |
johnAlexander | 7:6d3ab15363a2 | 451 | */ |
johnAlexander | 7:6d3ab15363a2 | 452 | VL53L1X_ERROR vl53l1x_check_for_data_ready(uint8_t *isDataReady); |
johnAlexander | 7:6d3ab15363a2 | 453 | |
johnAlexander | 7:6d3ab15363a2 | 454 | /** |
johnAlexander | 7:6d3ab15363a2 | 455 | * @brief This function programs the timing budget in ms. |
johnAlexander | 7:6d3ab15363a2 | 456 | * Predefined values = 15, 20, 33, 50, 100(default), 200, 500. |
johnAlexander | 7:6d3ab15363a2 | 457 | */ |
johnAlexander | 7:6d3ab15363a2 | 458 | VL53L1X_ERROR vl53l1x_set_timing_budget_in_ms(uint16_t TimingBudgetInMs); |
johnAlexander | 7:6d3ab15363a2 | 459 | |
johnAlexander | 7:6d3ab15363a2 | 460 | /** |
johnAlexander | 7:6d3ab15363a2 | 461 | * @brief This function returns the current timing budget in ms. |
johnAlexander | 7:6d3ab15363a2 | 462 | */ |
johnAlexander | 7:6d3ab15363a2 | 463 | VL53L1X_ERROR vl53l1x_get_timing_budget_in_ms(uint16_t *pTimingBudgetInMs); |
johnAlexander | 7:6d3ab15363a2 | 464 | |
johnAlexander | 7:6d3ab15363a2 | 465 | /** |
johnAlexander | 7:6d3ab15363a2 | 466 | * @brief This function programs the distance mode (1=short, 2=long(default)). |
johnAlexander | 7:6d3ab15363a2 | 467 | * Short mode max distance is limited to 1.3 m but better ambient immunity.\n |
johnAlexander | 7:6d3ab15363a2 | 468 | * Long mode can range up to 4 m in the dark with 200 ms timing budget. |
johnAlexander | 7:6d3ab15363a2 | 469 | */ |
johnAlexander | 7:6d3ab15363a2 | 470 | VL53L1X_ERROR vl53l1x_set_distance_mode(uint16_t DistanceMode); |
johnAlexander | 7:6d3ab15363a2 | 471 | |
johnAlexander | 7:6d3ab15363a2 | 472 | /** |
johnAlexander | 7:6d3ab15363a2 | 473 | * @brief This function returns the current distance mode (1=short, 2=long). |
johnAlexander | 7:6d3ab15363a2 | 474 | */ |
johnAlexander | 7:6d3ab15363a2 | 475 | VL53L1X_ERROR vl53l1x_get_distance_mode(uint16_t *pDistanceMode); |
johnAlexander | 7:6d3ab15363a2 | 476 | |
johnAlexander | 7:6d3ab15363a2 | 477 | /** |
johnAlexander | 7:6d3ab15363a2 | 478 | * @brief This function programs the Intermeasurement period in ms\n |
johnAlexander | 7:6d3ab15363a2 | 479 | * Intermeasurement period must be >/= timing budget. This condition is not checked by the API, |
johnAlexander | 7:6d3ab15363a2 | 480 | * the customer has the duty to check the condition. Default = 100 ms |
johnAlexander | 7:6d3ab15363a2 | 481 | */ |
johnAlexander | 7:6d3ab15363a2 | 482 | VL53L1X_ERROR vl53l1x_set_inter_measurement_in_ms(uint16_t InterMeasurementInMs); |
johnAlexander | 7:6d3ab15363a2 | 483 | |
johnAlexander | 7:6d3ab15363a2 | 484 | /** |
johnAlexander | 7:6d3ab15363a2 | 485 | * @brief This function returns the Intermeasurement period in ms. |
johnAlexander | 7:6d3ab15363a2 | 486 | */ |
johnAlexander | 7:6d3ab15363a2 | 487 | VL53L1X_ERROR vl53l1x_get_inter_measurement_in_ms(uint16_t * pIM); |
johnAlexander | 7:6d3ab15363a2 | 488 | |
johnAlexander | 7:6d3ab15363a2 | 489 | /** |
johnAlexander | 7:6d3ab15363a2 | 490 | * @brief This function returns the boot state of the device (1:booted, 0:not booted) |
johnAlexander | 7:6d3ab15363a2 | 491 | */ |
johnAlexander | 7:6d3ab15363a2 | 492 | VL53L1X_ERROR vl53l1x_boot_state(uint8_t *state); |
johnAlexander | 7:6d3ab15363a2 | 493 | |
johnAlexander | 7:6d3ab15363a2 | 494 | /** |
johnAlexander | 7:6d3ab15363a2 | 495 | * @brief This function returns the sensor id, sensor Id must be 0xEEAC |
johnAlexander | 7:6d3ab15363a2 | 496 | */ |
johnAlexander | 7:6d3ab15363a2 | 497 | VL53L1X_ERROR vl53l1x_get_sensor_id(uint16_t *id); |
johnAlexander | 7:6d3ab15363a2 | 498 | |
johnAlexander | 7:6d3ab15363a2 | 499 | /** |
johnAlexander | 7:6d3ab15363a2 | 500 | * @brief This function returns the distance measured by the sensor in mm |
johnAlexander | 7:6d3ab15363a2 | 501 | */ |
johnAlexander | 7:6d3ab15363a2 | 502 | VL53L1X_ERROR vl53l1x_get_distance(uint16_t *distance); |
johnAlexander | 7:6d3ab15363a2 | 503 | |
johnAlexander | 7:6d3ab15363a2 | 504 | /** |
johnAlexander | 7:6d3ab15363a2 | 505 | * @brief This function returns the returned signal per SPAD in kcps/SPAD. |
johnAlexander | 7:6d3ab15363a2 | 506 | * With kcps stands for Kilo Count Per Second |
johnAlexander | 7:6d3ab15363a2 | 507 | */ |
johnAlexander | 7:6d3ab15363a2 | 508 | VL53L1X_ERROR vl53l1x_get_signal_per_spad(uint16_t *signalPerSp); |
johnAlexander | 7:6d3ab15363a2 | 509 | |
johnAlexander | 7:6d3ab15363a2 | 510 | /** |
johnAlexander | 7:6d3ab15363a2 | 511 | * @brief This function returns the ambient per SPAD in kcps/SPAD |
johnAlexander | 7:6d3ab15363a2 | 512 | */ |
johnAlexander | 7:6d3ab15363a2 | 513 | VL53L1X_ERROR vl53l1x_get_ambient_per_spad(uint16_t *amb); |
johnAlexander | 7:6d3ab15363a2 | 514 | |
johnAlexander | 7:6d3ab15363a2 | 515 | /** |
johnAlexander | 7:6d3ab15363a2 | 516 | * @brief This function returns the returned signal in kcps. |
johnAlexander | 7:6d3ab15363a2 | 517 | */ |
johnAlexander | 7:6d3ab15363a2 | 518 | VL53L1X_ERROR vl53l1x_get_signal_rate(uint16_t *signalRate); |
johnAlexander | 7:6d3ab15363a2 | 519 | |
johnAlexander | 7:6d3ab15363a2 | 520 | /** |
johnAlexander | 7:6d3ab15363a2 | 521 | * @brief This function returns the current number of enabled SPADs |
johnAlexander | 7:6d3ab15363a2 | 522 | */ |
johnAlexander | 7:6d3ab15363a2 | 523 | VL53L1X_ERROR vl53l1x_get_spad_nb(uint16_t *spNb); |
johnAlexander | 7:6d3ab15363a2 | 524 | |
johnAlexander | 7:6d3ab15363a2 | 525 | /** |
johnAlexander | 7:6d3ab15363a2 | 526 | * @brief This function returns the ambient rate in kcps |
johnAlexander | 7:6d3ab15363a2 | 527 | */ |
johnAlexander | 7:6d3ab15363a2 | 528 | VL53L1X_ERROR vl53l1x_get_ambient_rate(uint16_t *ambRate); |
johnAlexander | 7:6d3ab15363a2 | 529 | |
johnAlexander | 7:6d3ab15363a2 | 530 | /** |
johnAlexander | 7:6d3ab15363a2 | 531 | * @brief This function returns the ranging status error \n |
johnAlexander | 7:6d3ab15363a2 | 532 | * (0:no error, 1:sigma failed, 2:signal failed, ..., 7:wrap-around) |
johnAlexander | 7:6d3ab15363a2 | 533 | */ |
johnAlexander | 7:6d3ab15363a2 | 534 | VL53L1X_ERROR vl53l1x_get_range_status(uint8_t *rangeStatus); |
johnAlexander | 7:6d3ab15363a2 | 535 | |
johnAlexander | 7:6d3ab15363a2 | 536 | /** |
johnAlexander | 7:6d3ab15363a2 | 537 | * @brief This function programs the offset correction in mm |
johnAlexander | 7:6d3ab15363a2 | 538 | * @param OffsetValue:the offset correction value to program in mm |
johnAlexander | 7:6d3ab15363a2 | 539 | */ |
johnAlexander | 7:6d3ab15363a2 | 540 | VL53L1X_ERROR vl53l1x_set_offset(int16_t OffsetValue); |
johnAlexander | 7:6d3ab15363a2 | 541 | |
johnAlexander | 7:6d3ab15363a2 | 542 | /** |
johnAlexander | 7:6d3ab15363a2 | 543 | * @brief This function returns the programmed offset correction value in mm |
johnAlexander | 7:6d3ab15363a2 | 544 | */ |
johnAlexander | 7:6d3ab15363a2 | 545 | VL53L1X_ERROR vl53l1x_get_offset(int16_t *Offset); |
johnAlexander | 7:6d3ab15363a2 | 546 | |
johnAlexander | 7:6d3ab15363a2 | 547 | /** |
johnAlexander | 7:6d3ab15363a2 | 548 | * @brief This function programs the xtalk correction value in cps (Count Per Second).\n |
johnAlexander | 7:6d3ab15363a2 | 549 | * This is the number of photons reflected back from the cover glass in cps. |
johnAlexander | 7:6d3ab15363a2 | 550 | */ |
johnAlexander | 7:6d3ab15363a2 | 551 | VL53L1X_ERROR vl53l1x_set_xtalk(uint16_t XtalkValue); |
johnAlexander | 7:6d3ab15363a2 | 552 | |
johnAlexander | 7:6d3ab15363a2 | 553 | /** |
johnAlexander | 7:6d3ab15363a2 | 554 | * @brief This function returns the current programmed xtalk correction value in cps |
johnAlexander | 7:6d3ab15363a2 | 555 | */ |
johnAlexander | 7:6d3ab15363a2 | 556 | VL53L1X_ERROR vl53l1x_get_xtalk(uint16_t *Xtalk); |
johnAlexander | 7:6d3ab15363a2 | 557 | |
johnAlexander | 7:6d3ab15363a2 | 558 | /** |
johnAlexander | 7:6d3ab15363a2 | 559 | * @brief This function programs the threshold detection mode\n |
johnAlexander | 7:6d3ab15363a2 | 560 | * Example:\n |
johnAlexander | 7:6d3ab15363a2 | 561 | * vl53l1x_set_distance_threshold(dev,100,300,0,1): Below 100 \n |
johnAlexander | 7:6d3ab15363a2 | 562 | * vl53l1x_set_distance_threshold(dev,100,300,1,1): Above 300 \n |
johnAlexander | 7:6d3ab15363a2 | 563 | * vl53l1x_set_distance_threshold(dev,100,300,2,1): Out of window \n |
johnAlexander | 7:6d3ab15363a2 | 564 | * vl53l1x_set_distance_threshold(dev,100,300,3,1): In window \n |
johnAlexander | 7:6d3ab15363a2 | 565 | * @param dev : device address |
johnAlexander | 7:6d3ab15363a2 | 566 | * @param ThreshLow(in mm) : the threshold under which one the device raises an interrupt if Window = 0 |
johnAlexander | 7:6d3ab15363a2 | 567 | * @param ThreshHigh(in mm) : the threshold above which one the device raises an interrupt if Window = 1 |
johnAlexander | 7:6d3ab15363a2 | 568 | * @param Window detection mode : 0=below, 1=above, 2=out, 3=in |
johnAlexander | 7:6d3ab15363a2 | 569 | * @param IntOnNoTarget = 1 (No longer used - just use 1) |
johnAlexander | 7:6d3ab15363a2 | 570 | */ |
johnAlexander | 7:6d3ab15363a2 | 571 | VL53L1X_ERROR vl53l1x_set_distance_threshold(uint16_t ThreshLow, |
johnAlexander | 7:6d3ab15363a2 | 572 | uint16_t ThreshHigh, uint8_t Window, |
johnAlexander | 7:6d3ab15363a2 | 573 | uint8_t IntOnNoTarget); |
johnAlexander | 7:6d3ab15363a2 | 574 | |
johnAlexander | 7:6d3ab15363a2 | 575 | /** |
johnAlexander | 7:6d3ab15363a2 | 576 | * @brief This function returns the window detection mode (0=below; 1=above; 2=out; 3=in) |
johnAlexander | 7:6d3ab15363a2 | 577 | */ |
johnAlexander | 7:6d3ab15363a2 | 578 | VL53L1X_ERROR vl53l1x_get_distance_threshold_window(uint16_t *window); |
johnAlexander | 7:6d3ab15363a2 | 579 | |
johnAlexander | 7:6d3ab15363a2 | 580 | /** |
johnAlexander | 7:6d3ab15363a2 | 581 | * @brief This function returns the low threshold in mm |
johnAlexander | 7:6d3ab15363a2 | 582 | */ |
johnAlexander | 7:6d3ab15363a2 | 583 | VL53L1X_ERROR vl53l1x_get_distance_threshold_low(uint16_t *low); |
johnAlexander | 7:6d3ab15363a2 | 584 | |
johnAlexander | 7:6d3ab15363a2 | 585 | /** |
johnAlexander | 7:6d3ab15363a2 | 586 | * @brief This function returns the high threshold in mm |
johnAlexander | 7:6d3ab15363a2 | 587 | */ |
johnAlexander | 7:6d3ab15363a2 | 588 | VL53L1X_ERROR vl53l1x_get_distance_threshold_high(uint16_t *high); |
johnAlexander | 7:6d3ab15363a2 | 589 | |
johnAlexander | 7:6d3ab15363a2 | 590 | /** |
johnAlexander | 7:6d3ab15363a2 | 591 | * @brief This function programs the ROI (Region of Interest)\n |
johnAlexander | 7:6d3ab15363a2 | 592 | * The ROI position is centered, only the ROI size can be reprogrammed.\n |
johnAlexander | 7:6d3ab15363a2 | 593 | * The smallest acceptable ROI size = 4\n |
johnAlexander | 7:6d3ab15363a2 | 594 | * @param X:ROI Width; Y=ROI Height |
johnAlexander | 7:6d3ab15363a2 | 595 | */ |
johnAlexander | 7:6d3ab15363a2 | 596 | VL53L1X_ERROR vl53l1x_set_roi(uint16_t X, uint16_t Y); |
johnAlexander | 7:6d3ab15363a2 | 597 | |
johnAlexander | 7:6d3ab15363a2 | 598 | /** |
johnAlexander | 7:6d3ab15363a2 | 599 | *@brief This function returns width X and height Y |
johnAlexander | 7:6d3ab15363a2 | 600 | */ |
johnAlexander | 7:6d3ab15363a2 | 601 | VL53L1X_ERROR vl53l1x_get_roi_xy(uint16_t *ROI_X, uint16_t *ROI_Y); |
johnAlexander | 7:6d3ab15363a2 | 602 | |
johnAlexander | 7:6d3ab15363a2 | 603 | /** |
johnAlexander | 7:6d3ab15363a2 | 604 | * @brief This function programs a new signal threshold in kcps (default=1024 kcps\n |
johnAlexander | 7:6d3ab15363a2 | 605 | */ |
johnAlexander | 7:6d3ab15363a2 | 606 | VL53L1X_ERROR vl53l1x_set_signal_threshold(uint16_t signal); |
johnAlexander | 7:6d3ab15363a2 | 607 | |
johnAlexander | 7:6d3ab15363a2 | 608 | /** |
johnAlexander | 7:6d3ab15363a2 | 609 | * @brief This function returns the current signal threshold in kcps |
johnAlexander | 7:6d3ab15363a2 | 610 | */ |
johnAlexander | 7:6d3ab15363a2 | 611 | VL53L1X_ERROR vl53l1x_get_signal_threshold(uint16_t *signal); |
johnAlexander | 7:6d3ab15363a2 | 612 | |
johnAlexander | 7:6d3ab15363a2 | 613 | /** |
johnAlexander | 7:6d3ab15363a2 | 614 | * @brief This function programs a new sigma threshold in mm (default=15 mm) |
johnAlexander | 7:6d3ab15363a2 | 615 | */ |
johnAlexander | 7:6d3ab15363a2 | 616 | VL53L1X_ERROR vl53l1x_set_sigma_threshold(uint16_t sigma); |
johnAlexander | 7:6d3ab15363a2 | 617 | |
johnAlexander | 7:6d3ab15363a2 | 618 | /** |
johnAlexander | 7:6d3ab15363a2 | 619 | * @brief This function returns the current sigma threshold in mm |
johnAlexander | 7:6d3ab15363a2 | 620 | */ |
johnAlexander | 7:6d3ab15363a2 | 621 | VL53L1X_ERROR vl53l1x_get_sigma_threshold(uint16_t *signal); |
johnAlexander | 7:6d3ab15363a2 | 622 | |
johnAlexander | 7:6d3ab15363a2 | 623 | /** |
johnAlexander | 7:6d3ab15363a2 | 624 | * @brief This function performs the temperature calibration. |
johnAlexander | 7:6d3ab15363a2 | 625 | * It is recommended to call this function any time the temperature might have changed by more than 8 deg C |
johnAlexander | 7:6d3ab15363a2 | 626 | * without sensor ranging activity for an extended period. |
johnAlexander | 7:6d3ab15363a2 | 627 | */ |
johnAlexander | 7:6d3ab15363a2 | 628 | VL53L1X_ERROR vl53l1x_start_temperature_update(); |
johnAlexander | 7:6d3ab15363a2 | 629 | |
johnAlexander | 7:6d3ab15363a2 | 630 | |
johnAlexander | 7:6d3ab15363a2 | 631 | /* VL53L1X_calibration.h functions */ |
johnAlexander | 7:6d3ab15363a2 | 632 | |
johnAlexander | 7:6d3ab15363a2 | 633 | /** |
johnAlexander | 7:6d3ab15363a2 | 634 | * @brief This function performs the offset calibration.\n |
johnAlexander | 7:6d3ab15363a2 | 635 | * The function returns the offset value found and programs the offset compensation into the device. |
johnAlexander | 7:6d3ab15363a2 | 636 | * @param TargetDistInMm target distance in mm, ST recommended 100 mm |
johnAlexander | 7:6d3ab15363a2 | 637 | * Target reflectance = grey17% |
johnAlexander | 7:6d3ab15363a2 | 638 | * @return 0:success, !=0: failed |
johnAlexander | 7:6d3ab15363a2 | 639 | * @return offset pointer contains the offset found in mm |
johnAlexander | 7:6d3ab15363a2 | 640 | */ |
johnAlexander | 7:6d3ab15363a2 | 641 | int8_t vl53l1x_calibrate_offset(uint16_t TargetDistInMm, int16_t *offset); |
johnAlexander | 7:6d3ab15363a2 | 642 | |
johnAlexander | 7:6d3ab15363a2 | 643 | /** |
johnAlexander | 7:6d3ab15363a2 | 644 | * @brief This function performs the xtalk calibration.\n |
johnAlexander | 7:6d3ab15363a2 | 645 | * The function returns the xtalk value found and programs the xtalk compensation to the device |
johnAlexander | 7:6d3ab15363a2 | 646 | * @param TargetDistInMm target distance in mm\n |
johnAlexander | 7:6d3ab15363a2 | 647 | * The target distance : the distance where the sensor start to "under range"\n |
johnAlexander | 7:6d3ab15363a2 | 648 | * due to the influence of the photons reflected back from the cover glass becoming strong\n |
johnAlexander | 7:6d3ab15363a2 | 649 | * It's also called inflection point\n |
johnAlexander | 7:6d3ab15363a2 | 650 | * Target reflectance = grey 17% |
johnAlexander | 7:6d3ab15363a2 | 651 | * @return 0: success, !=0: failed |
johnAlexander | 7:6d3ab15363a2 | 652 | * @return xtalk pointer contains the xtalk value found in cps (number of photons in count per second) |
johnAlexander | 7:6d3ab15363a2 | 653 | */ |
johnAlexander | 7:6d3ab15363a2 | 654 | int8_t vl53l1x_calibrate_xtalk(uint16_t TargetDistInMm, uint16_t *xtalk); |
johnAlexander | 7:6d3ab15363a2 | 655 | |
johnAlexander | 7:6d3ab15363a2 | 656 | |
johnAlexander | 7:6d3ab15363a2 | 657 | /* Write and read functions from I2C */ |
johnAlexander | 7:6d3ab15363a2 | 658 | |
johnAlexander | 7:6d3ab15363a2 | 659 | VL53L1X_ERROR vl53l1_wr_byte(VL53L1_DEV dev, uint16_t index, uint8_t data); |
johnAlexander | 7:6d3ab15363a2 | 660 | VL53L1X_ERROR vl53l1_wr_word(VL53L1_DEV dev, uint16_t index, uint16_t data); |
johnAlexander | 7:6d3ab15363a2 | 661 | VL53L1X_ERROR vl53l1_wr_double_word(VL53L1_DEV dev, uint16_t index, uint32_t data); |
johnAlexander | 7:6d3ab15363a2 | 662 | VL53L1X_ERROR vl53l1_rd_byte(VL53L1_DEV dev, uint16_t index, uint8_t *data); |
johnAlexander | 7:6d3ab15363a2 | 663 | VL53L1X_ERROR vl53l1_rd_word(VL53L1_DEV dev, uint16_t index, uint16_t *data); |
johnAlexander | 7:6d3ab15363a2 | 664 | VL53L1X_ERROR vl53l1_rd_double_word(VL53L1_DEV dev, uint16_t index, uint32_t *data); |
johnAlexander | 7:6d3ab15363a2 | 665 | VL53L1X_ERROR vl53l1_update_byte(VL53L1_DEV dev, uint16_t index, uint8_t AndData, uint8_t OrData); |
johnAlexander | 7:6d3ab15363a2 | 666 | |
johnAlexander | 7:6d3ab15363a2 | 667 | VL53L1X_ERROR vl53l1_write_multi(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count); |
johnAlexander | 7:6d3ab15363a2 | 668 | VL53L1X_ERROR vl53l1_read_multi(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count); |
johnAlexander | 7:6d3ab15363a2 | 669 | |
johnAlexander | 7:6d3ab15363a2 | 670 | VL53L1X_ERROR vl53l1_i2c_write(uint8_t dev, uint16_t index, uint8_t *data, uint16_t number_of_bytes); |
johnAlexander | 7:6d3ab15363a2 | 671 | VL53L1X_ERROR vl53l1_i2c_read(uint8_t dev, uint16_t index, uint8_t *data, uint16_t number_of_bytes); |
johnAlexander | 7:6d3ab15363a2 | 672 | VL53L1X_ERROR vl53l1_get_tick_count(uint32_t *ptick_count_ms); |
johnAlexander | 7:6d3ab15363a2 | 673 | VL53L1X_ERROR vl53l1_wait_us(VL53L1_Dev_t *pdev, int32_t wait_us); |
johnAlexander | 7:6d3ab15363a2 | 674 | VL53L1X_ERROR vl53l1_wait_ms(VL53L1_Dev_t *pdev, int32_t wait_ms); |
johnAlexander | 7:6d3ab15363a2 | 675 | |
johnAlexander | 7:6d3ab15363a2 | 676 | VL53L1X_ERROR vl53l1_wait_value_mask_ex(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uint16_t index, uint8_t value, uint8_t mask, uint32_t poll_delay_ms); |
johnAlexander | 7:6d3ab15363a2 | 677 | |
johnAlexander | 7:6d3ab15363a2 | 678 | protected: |
johnAlexander | 7:6d3ab15363a2 | 679 | |
johnAlexander | 7:6d3ab15363a2 | 680 | /* IO Device */ |
johnAlexander | 7:6d3ab15363a2 | 681 | VL53L1X_DevI2C *dev_i2c; |
johnAlexander | 7:6d3ab15363a2 | 682 | |
johnAlexander | 7:6d3ab15363a2 | 683 | /* Digital out pin */ |
johnAlexander | 7:6d3ab15363a2 | 684 | DigitalOut *_gpio0; |
johnAlexander | 7:6d3ab15363a2 | 685 | /* GPIO expander */ |
johnAlexander | 7:6d3ab15363a2 | 686 | Stmpe1600DigiOut *_expgpio0; |
johnAlexander | 7:6d3ab15363a2 | 687 | /* Measure detection IRQ */ |
johnAlexander | 7:6d3ab15363a2 | 688 | InterruptIn *_gpio1Int; |
johnAlexander | 7:6d3ab15363a2 | 689 | |
johnAlexander | 7:6d3ab15363a2 | 690 | /* Device data */ |
johnAlexander | 7:6d3ab15363a2 | 691 | VL53L1_Dev_t MyDevice; |
johnAlexander | 7:6d3ab15363a2 | 692 | VL53L1_DEV Device; |
johnAlexander | 7:6d3ab15363a2 | 693 | }; |
johnAlexander | 7:6d3ab15363a2 | 694 | |
johnAlexander | 7:6d3ab15363a2 | 695 | |
johnAlexander | 7:6d3ab15363a2 | 696 | #endif /* _VL53L1X_CLASS_H_ */ |