VL53L0X World smallest Time-of-Flight (ToF) ranging sensor

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   HelloWorld_ST_Sensors mbed-os-mqtt-client Multi_VL53L0X DISCO-IOT01_HomeEnv ... more

Fork of VL53L0X by Nicola Capovilla

Committer:
johnAlexander
Date:
Thu Jun 06 09:21:39 2019 +0000
Revision:
6:8ac15bf6d635
Publish mbed-certified sensor class.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnAlexander 6:8ac15bf6d635 1 /*******************************************************************************
johnAlexander 6:8ac15bf6d635 2 Copyright © 2015, STMicroelectronics International N.V.
johnAlexander 6:8ac15bf6d635 3 All rights reserved.
johnAlexander 6:8ac15bf6d635 4
johnAlexander 6:8ac15bf6d635 5 Redistribution and use in source and binary forms, with or without
johnAlexander 6:8ac15bf6d635 6 modification, are permitted provided that the following conditions are met:
johnAlexander 6:8ac15bf6d635 7 * Redistributions of source code must retain the above copyright
johnAlexander 6:8ac15bf6d635 8 notice, this list of conditions and the following disclaimer.
johnAlexander 6:8ac15bf6d635 9 * Redistributions in binary form must reproduce the above copyright
johnAlexander 6:8ac15bf6d635 10 notice, this list of conditions and the following disclaimer in the
johnAlexander 6:8ac15bf6d635 11 documentation and/or other materials provided with the distribution.
johnAlexander 6:8ac15bf6d635 12 * Neither the name of STMicroelectronics nor the
johnAlexander 6:8ac15bf6d635 13 names of its contributors may be used to endorse or promote products
johnAlexander 6:8ac15bf6d635 14 derived from this software without specific prior written permission.
johnAlexander 6:8ac15bf6d635 15
johnAlexander 6:8ac15bf6d635 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
johnAlexander 6:8ac15bf6d635 17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
johnAlexander 6:8ac15bf6d635 18 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
johnAlexander 6:8ac15bf6d635 19 NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
johnAlexander 6:8ac15bf6d635 20 IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
johnAlexander 6:8ac15bf6d635 21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
johnAlexander 6:8ac15bf6d635 22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
johnAlexander 6:8ac15bf6d635 23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
johnAlexander 6:8ac15bf6d635 24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
johnAlexander 6:8ac15bf6d635 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
johnAlexander 6:8ac15bf6d635 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
johnAlexander 6:8ac15bf6d635 27 ********************************************************************************/
johnAlexander 6:8ac15bf6d635 28
johnAlexander 6:8ac15bf6d635 29
johnAlexander 6:8ac15bf6d635 30 #ifndef _VL53L0X_PLATFORM_H_
johnAlexander 6:8ac15bf6d635 31 #define _VL53L0X_PLATFORM_H_
johnAlexander 6:8ac15bf6d635 32
johnAlexander 6:8ac15bf6d635 33 #include "VL53L0X_def.h"
johnAlexander 6:8ac15bf6d635 34 #include "VL53L0X_platform_log.h"
johnAlexander 6:8ac15bf6d635 35 #include "VL53L0X_i2c_platform.h"
johnAlexander 6:8ac15bf6d635 36
johnAlexander 6:8ac15bf6d635 37 #ifdef __cplusplus
johnAlexander 6:8ac15bf6d635 38 extern "C" {
johnAlexander 6:8ac15bf6d635 39 #endif
johnAlexander 6:8ac15bf6d635 40
johnAlexander 6:8ac15bf6d635 41 /**
johnAlexander 6:8ac15bf6d635 42 * @file vl53l0_platform.h
johnAlexander 6:8ac15bf6d635 43 *
johnAlexander 6:8ac15bf6d635 44 * @brief All end user OS/platform/application porting
johnAlexander 6:8ac15bf6d635 45 */
johnAlexander 6:8ac15bf6d635 46
johnAlexander 6:8ac15bf6d635 47 /**
johnAlexander 6:8ac15bf6d635 48 * @defgroup VL53L0X_platform_group VL53L0 Platform Functions
johnAlexander 6:8ac15bf6d635 49 * @brief VL53L0 Platform Functions
johnAlexander 6:8ac15bf6d635 50 * @{
johnAlexander 6:8ac15bf6d635 51 */
johnAlexander 6:8ac15bf6d635 52
johnAlexander 6:8ac15bf6d635 53 /**
johnAlexander 6:8ac15bf6d635 54 * @struct VL53L0X_Dev_t
johnAlexander 6:8ac15bf6d635 55 * @brief Generic PAL device type that does link between API and platform abstraction layer
johnAlexander 6:8ac15bf6d635 56 *
johnAlexander 6:8ac15bf6d635 57 */
johnAlexander 6:8ac15bf6d635 58 typedef struct {
johnAlexander 6:8ac15bf6d635 59 VL53L0X_DevData_t Data; /*!< embed ST Ewok Dev data as "Data"*/
johnAlexander 6:8ac15bf6d635 60
johnAlexander 6:8ac15bf6d635 61 /*!< user specific field */
johnAlexander 6:8ac15bf6d635 62 uint8_t I2cDevAddr; /*!< i2c device address user specific field */
johnAlexander 6:8ac15bf6d635 63 uint8_t comms_type; /*!< Type of comms : VL53L0X_COMMS_I2C or VL53L0X_COMMS_SPI */
johnAlexander 6:8ac15bf6d635 64 uint16_t comms_speed_khz; /*!< Comms speed [kHz] : typically 400kHz for I2C */
johnAlexander 6:8ac15bf6d635 65
johnAlexander 6:8ac15bf6d635 66 } VL53L0X_Dev_t;
johnAlexander 6:8ac15bf6d635 67
johnAlexander 6:8ac15bf6d635 68
johnAlexander 6:8ac15bf6d635 69 /**
johnAlexander 6:8ac15bf6d635 70 * @brief Declare the device Handle as a pointer of the structure @a VL53L0X_Dev_t.
johnAlexander 6:8ac15bf6d635 71 *
johnAlexander 6:8ac15bf6d635 72 */
johnAlexander 6:8ac15bf6d635 73 typedef VL53L0X_Dev_t *VL53L0X_DEV;
johnAlexander 6:8ac15bf6d635 74
johnAlexander 6:8ac15bf6d635 75 /**
johnAlexander 6:8ac15bf6d635 76 * @def PALDevDataGet
johnAlexander 6:8ac15bf6d635 77 * @brief Get ST private structure @a VL53L0X_DevData_t data access
johnAlexander 6:8ac15bf6d635 78 *
johnAlexander 6:8ac15bf6d635 79 * @param Dev Device Handle
johnAlexander 6:8ac15bf6d635 80 * @param field ST structure field name
johnAlexander 6:8ac15bf6d635 81 * It maybe used and as real data "ref" not just as "get" for sub-structure item
johnAlexander 6:8ac15bf6d635 82 * like PALDevDataGet(FilterData.field)[i] or PALDevDataGet(FilterData.MeasurementIndex)++
johnAlexander 6:8ac15bf6d635 83 */
johnAlexander 6:8ac15bf6d635 84 #define PALDevDataGet(Dev, field) (Dev->Data.field)
johnAlexander 6:8ac15bf6d635 85
johnAlexander 6:8ac15bf6d635 86 /**
johnAlexander 6:8ac15bf6d635 87 * @def PALDevDataSet(Dev, field, data)
johnAlexander 6:8ac15bf6d635 88 * @brief Set ST private structure @a VL53L0X_DevData_t data field
johnAlexander 6:8ac15bf6d635 89 * @param Dev Device Handle
johnAlexander 6:8ac15bf6d635 90 * @param field ST structure field name
johnAlexander 6:8ac15bf6d635 91 * @param data Data to be set
johnAlexander 6:8ac15bf6d635 92 */
johnAlexander 6:8ac15bf6d635 93 #define PALDevDataSet(Dev, field, data) (Dev->Data.field)=(data)
johnAlexander 6:8ac15bf6d635 94
johnAlexander 6:8ac15bf6d635 95
johnAlexander 6:8ac15bf6d635 96 /**
johnAlexander 6:8ac15bf6d635 97 * @defgroup VL53L0X_registerAccess_group PAL Register Access Functions
johnAlexander 6:8ac15bf6d635 98 * @brief PAL Register Access Functions
johnAlexander 6:8ac15bf6d635 99 * @{
johnAlexander 6:8ac15bf6d635 100 */
johnAlexander 6:8ac15bf6d635 101
johnAlexander 6:8ac15bf6d635 102 /**
johnAlexander 6:8ac15bf6d635 103 * Lock comms interface to serialize all commands to a shared I2C interface for a specific device
johnAlexander 6:8ac15bf6d635 104 * @param Dev Device Handle
johnAlexander 6:8ac15bf6d635 105 * @return VL53L0X_ERROR_NONE Success
johnAlexander 6:8ac15bf6d635 106 * @return "Other error code" See ::VL53L0X_Error
johnAlexander 6:8ac15bf6d635 107 */
johnAlexander 6:8ac15bf6d635 108 VL53L0X_Error VL53L0X_LockSequenceAccess(VL53L0X_DEV Dev);
johnAlexander 6:8ac15bf6d635 109
johnAlexander 6:8ac15bf6d635 110 /**
johnAlexander 6:8ac15bf6d635 111 * Unlock comms interface to serialize all commands to a shared I2C interface for a specific device
johnAlexander 6:8ac15bf6d635 112 * @param Dev Device Handle
johnAlexander 6:8ac15bf6d635 113 * @return VL53L0X_ERROR_NONE Success
johnAlexander 6:8ac15bf6d635 114 * @return "Other error code" See ::VL53L0X_Error
johnAlexander 6:8ac15bf6d635 115 */
johnAlexander 6:8ac15bf6d635 116 VL53L0X_Error VL53L0X_UnlockSequenceAccess(VL53L0X_DEV Dev);
johnAlexander 6:8ac15bf6d635 117
johnAlexander 6:8ac15bf6d635 118
johnAlexander 6:8ac15bf6d635 119 /**
johnAlexander 6:8ac15bf6d635 120 * Writes the supplied byte buffer to the device
johnAlexander 6:8ac15bf6d635 121 * @param Dev Device Handle
johnAlexander 6:8ac15bf6d635 122 * @param index The register index
johnAlexander 6:8ac15bf6d635 123 * @param pdata Pointer to uint8_t buffer containing the data to be written
johnAlexander 6:8ac15bf6d635 124 * @param count Number of bytes in the supplied byte buffer
johnAlexander 6:8ac15bf6d635 125 * @return VL53L0X_ERROR_NONE Success
johnAlexander 6:8ac15bf6d635 126 * @return "Other error code" See ::VL53L0X_Error
johnAlexander 6:8ac15bf6d635 127 */
johnAlexander 6:8ac15bf6d635 128 VL53L0X_Error VL53L0X_WriteMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count);
johnAlexander 6:8ac15bf6d635 129
johnAlexander 6:8ac15bf6d635 130 /**
johnAlexander 6:8ac15bf6d635 131 * Reads the requested number of bytes from the device
johnAlexander 6:8ac15bf6d635 132 * @param Dev Device Handle
johnAlexander 6:8ac15bf6d635 133 * @param index The register index
johnAlexander 6:8ac15bf6d635 134 * @param pdata Pointer to the uint8_t buffer to store read data
johnAlexander 6:8ac15bf6d635 135 * @param count Number of uint8_t's to read
johnAlexander 6:8ac15bf6d635 136 * @return VL53L0X_ERROR_NONE Success
johnAlexander 6:8ac15bf6d635 137 * @return "Other error code" See ::VL53L0X_Error
johnAlexander 6:8ac15bf6d635 138 */
johnAlexander 6:8ac15bf6d635 139 VL53L0X_Error VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count);
johnAlexander 6:8ac15bf6d635 140
johnAlexander 6:8ac15bf6d635 141 /**
johnAlexander 6:8ac15bf6d635 142 * Write single byte register
johnAlexander 6:8ac15bf6d635 143 * @param Dev Device Handle
johnAlexander 6:8ac15bf6d635 144 * @param index The register index
johnAlexander 6:8ac15bf6d635 145 * @param data 8 bit register data
johnAlexander 6:8ac15bf6d635 146 * @return VL53L0X_ERROR_NONE Success
johnAlexander 6:8ac15bf6d635 147 * @return "Other error code" See ::VL53L0X_Error
johnAlexander 6:8ac15bf6d635 148 */
johnAlexander 6:8ac15bf6d635 149 VL53L0X_Error VL53L0X_WrByte(VL53L0X_DEV Dev, uint8_t index, uint8_t data);
johnAlexander 6:8ac15bf6d635 150
johnAlexander 6:8ac15bf6d635 151 /**
johnAlexander 6:8ac15bf6d635 152 * Write word register
johnAlexander 6:8ac15bf6d635 153 * @param Dev Device Handle
johnAlexander 6:8ac15bf6d635 154 * @param index The register index
johnAlexander 6:8ac15bf6d635 155 * @param data 16 bit register data
johnAlexander 6:8ac15bf6d635 156 * @return VL53L0X_ERROR_NONE Success
johnAlexander 6:8ac15bf6d635 157 * @return "Other error code" See ::VL53L0X_Error
johnAlexander 6:8ac15bf6d635 158 */
johnAlexander 6:8ac15bf6d635 159 VL53L0X_Error VL53L0X_WrWord(VL53L0X_DEV Dev, uint8_t index, uint16_t data);
johnAlexander 6:8ac15bf6d635 160
johnAlexander 6:8ac15bf6d635 161 /**
johnAlexander 6:8ac15bf6d635 162 * Write double word (4 byte) register
johnAlexander 6:8ac15bf6d635 163 * @param Dev Device Handle
johnAlexander 6:8ac15bf6d635 164 * @param index The register index
johnAlexander 6:8ac15bf6d635 165 * @param data 32 bit register data
johnAlexander 6:8ac15bf6d635 166 * @return VL53L0X_ERROR_NONE Success
johnAlexander 6:8ac15bf6d635 167 * @return "Other error code" See ::VL53L0X_Error
johnAlexander 6:8ac15bf6d635 168 */
johnAlexander 6:8ac15bf6d635 169 VL53L0X_Error VL53L0X_WrDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t data);
johnAlexander 6:8ac15bf6d635 170
johnAlexander 6:8ac15bf6d635 171 /**
johnAlexander 6:8ac15bf6d635 172 * Read single byte register
johnAlexander 6:8ac15bf6d635 173 * @param Dev Device Handle
johnAlexander 6:8ac15bf6d635 174 * @param index The register index
johnAlexander 6:8ac15bf6d635 175 * @param data pointer to 8 bit data
johnAlexander 6:8ac15bf6d635 176 * @return VL53L0X_ERROR_NONE Success
johnAlexander 6:8ac15bf6d635 177 * @return "Other error code" See ::VL53L0X_Error
johnAlexander 6:8ac15bf6d635 178 */
johnAlexander 6:8ac15bf6d635 179 VL53L0X_Error VL53L0X_RdByte(VL53L0X_DEV Dev, uint8_t index, uint8_t *data);
johnAlexander 6:8ac15bf6d635 180
johnAlexander 6:8ac15bf6d635 181 /**
johnAlexander 6:8ac15bf6d635 182 * Read word (2byte) register
johnAlexander 6:8ac15bf6d635 183 * @param Dev Device Handle
johnAlexander 6:8ac15bf6d635 184 * @param index The register index
johnAlexander 6:8ac15bf6d635 185 * @param data pointer to 16 bit data
johnAlexander 6:8ac15bf6d635 186 * @return VL53L0X_ERROR_NONE Success
johnAlexander 6:8ac15bf6d635 187 * @return "Other error code" See ::VL53L0X_Error
johnAlexander 6:8ac15bf6d635 188 */
johnAlexander 6:8ac15bf6d635 189 VL53L0X_Error VL53L0X_RdWord(VL53L0X_DEV Dev, uint8_t index, uint16_t *data);
johnAlexander 6:8ac15bf6d635 190
johnAlexander 6:8ac15bf6d635 191 /**
johnAlexander 6:8ac15bf6d635 192 * Read dword (4byte) register
johnAlexander 6:8ac15bf6d635 193 * @param Dev Device Handle
johnAlexander 6:8ac15bf6d635 194 * @param index The register index
johnAlexander 6:8ac15bf6d635 195 * @param data pointer to 32 bit data
johnAlexander 6:8ac15bf6d635 196 * @return VL53L0X_ERROR_NONE Success
johnAlexander 6:8ac15bf6d635 197 * @return "Other error code" See ::VL53L0X_Error
johnAlexander 6:8ac15bf6d635 198 */
johnAlexander 6:8ac15bf6d635 199 VL53L0X_Error VL53L0X_RdDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t *data);
johnAlexander 6:8ac15bf6d635 200
johnAlexander 6:8ac15bf6d635 201 /**
johnAlexander 6:8ac15bf6d635 202 * Threat safe Update (read/modify/write) single byte register
johnAlexander 6:8ac15bf6d635 203 *
johnAlexander 6:8ac15bf6d635 204 * Final_reg = (Initial_reg & and_data) |or_data
johnAlexander 6:8ac15bf6d635 205 *
johnAlexander 6:8ac15bf6d635 206 * @param Dev Device Handle
johnAlexander 6:8ac15bf6d635 207 * @param index The register index
johnAlexander 6:8ac15bf6d635 208 * @param AndData 8 bit and data
johnAlexander 6:8ac15bf6d635 209 * @param OrData 8 bit or data
johnAlexander 6:8ac15bf6d635 210 * @return VL53L0X_ERROR_NONE Success
johnAlexander 6:8ac15bf6d635 211 * @return "Other error code" See ::VL53L0X_Error
johnAlexander 6:8ac15bf6d635 212 */
johnAlexander 6:8ac15bf6d635 213 VL53L0X_Error VL53L0X_UpdateByte(VL53L0X_DEV Dev, uint8_t index, uint8_t AndData, uint8_t OrData);
johnAlexander 6:8ac15bf6d635 214
johnAlexander 6:8ac15bf6d635 215 /** @} end of VL53L0X_registerAccess_group */
johnAlexander 6:8ac15bf6d635 216
johnAlexander 6:8ac15bf6d635 217
johnAlexander 6:8ac15bf6d635 218 /**
johnAlexander 6:8ac15bf6d635 219 * @brief execute delay in all polling API call
johnAlexander 6:8ac15bf6d635 220 *
johnAlexander 6:8ac15bf6d635 221 * A typical multi-thread or RTOs implementation is to sleep the task for some 5ms (with 100Hz max rate faster polling is not needed)
johnAlexander 6:8ac15bf6d635 222 * if nothing specific is need you can define it as an empty/void macro
johnAlexander 6:8ac15bf6d635 223 * @code
johnAlexander 6:8ac15bf6d635 224 * #define VL53L0X_PollingDelay(...) (void)0
johnAlexander 6:8ac15bf6d635 225 * @endcode
johnAlexander 6:8ac15bf6d635 226 * @param Dev Device Handle
johnAlexander 6:8ac15bf6d635 227 * @return VL53L0X_ERROR_NONE Success
johnAlexander 6:8ac15bf6d635 228 * @return "Other error code" See ::VL53L0X_Error
johnAlexander 6:8ac15bf6d635 229 */
johnAlexander 6:8ac15bf6d635 230 VL53L0X_Error VL53L0X_PollingDelay(VL53L0X_DEV Dev); /* usually best implemented as a real function */
johnAlexander 6:8ac15bf6d635 231
johnAlexander 6:8ac15bf6d635 232 /** @} end of VL53L0X_platform_group */
johnAlexander 6:8ac15bf6d635 233
johnAlexander 6:8ac15bf6d635 234 #ifdef __cplusplus
johnAlexander 6:8ac15bf6d635 235 }
johnAlexander 6:8ac15bf6d635 236 #endif
johnAlexander 6:8ac15bf6d635 237
johnAlexander 6:8ac15bf6d635 238 #endif /* _VL53L0X_PLATFORM_H_ */
johnAlexander 6:8ac15bf6d635 239
johnAlexander 6:8ac15bf6d635 240
johnAlexander 6:8ac15bf6d635 241
johnAlexander 6:8ac15bf6d635 242