hh

Dependents:   VL53L0X-mbedOS-master VL53L0X-mbedOS-masterbb

Committer:
mohamedachour
Date:
Tue Apr 23 14:27:07 2019 +0000
Revision:
2:a1dffa1ff38a
Parent:
0:e6fcdb78a136
xc

Who changed what in which revision?

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