hh
Dependents: VL53L0X-mbedOS-master VL53L0X-mbedOS-masterbb
vl53l0x_platform.cpp@0:e6fcdb78a136, 2016-08-23 (annotated)
- Committer:
- mjarvisal
- Date:
- Tue Aug 23 05:14:05 2016 +0000
- Revision:
- 0:e6fcdb78a136
Initial release
Who changed what in which revision?
User | Revision | Line number | New 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 | * @file VL53L0X_i2c.c |
mjarvisal | 0:e6fcdb78a136 | 31 | * |
mjarvisal | 0:e6fcdb78a136 | 32 | * Copyright (C) 2014 ST MicroElectronics |
mjarvisal | 0:e6fcdb78a136 | 33 | * |
mjarvisal | 0:e6fcdb78a136 | 34 | * provide variable word size byte/Word/dword VL6180x register access via i2c |
mjarvisal | 0:e6fcdb78a136 | 35 | * |
mjarvisal | 0:e6fcdb78a136 | 36 | */ |
mjarvisal | 0:e6fcdb78a136 | 37 | |
mjarvisal | 0:e6fcdb78a136 | 38 | #include "vl53l0x_platform.h" |
mjarvisal | 0:e6fcdb78a136 | 39 | #include "vl53l0x_i2c_platform.h" |
mjarvisal | 0:e6fcdb78a136 | 40 | #include "vl53l0x_api.h" |
mjarvisal | 0:e6fcdb78a136 | 41 | |
mjarvisal | 0:e6fcdb78a136 | 42 | #define LOG_FUNCTION_START(fmt, ... ) _LOG_FUNCTION_START(TRACE_MODULE_PLATFORM, fmt, ##__VA_ARGS__) |
mjarvisal | 0:e6fcdb78a136 | 43 | #define LOG_FUNCTION_END(status, ... ) _LOG_FUNCTION_END(TRACE_MODULE_PLATFORM, status, ##__VA_ARGS__) |
mjarvisal | 0:e6fcdb78a136 | 44 | #define LOG_FUNCTION_END_FMT(status, fmt, ... ) _LOG_FUNCTION_END_FMT(TRACE_MODULE_PLATFORM, status, fmt, ##__VA_ARGS__) |
mjarvisal | 0:e6fcdb78a136 | 45 | |
mjarvisal | 0:e6fcdb78a136 | 46 | /** |
mjarvisal | 0:e6fcdb78a136 | 47 | * @def I2C_BUFFER_CONFIG |
mjarvisal | 0:e6fcdb78a136 | 48 | * |
mjarvisal | 0:e6fcdb78a136 | 49 | * @brief Configure Device register I2C access |
mjarvisal | 0:e6fcdb78a136 | 50 | * |
mjarvisal | 0:e6fcdb78a136 | 51 | * @li 0 : one GLOBAL buffer \n |
mjarvisal | 0:e6fcdb78a136 | 52 | * Use one global buffer of MAX_I2C_XFER_SIZE byte in data space \n |
mjarvisal | 0:e6fcdb78a136 | 53 | * This solution is not multi-Device compliant nor multi-thread cpu safe \n |
mjarvisal | 0:e6fcdb78a136 | 54 | * It can be the best option for small 8/16 bit MCU without stack and limited ram (STM8s, 80C51 ...) |
mjarvisal | 0:e6fcdb78a136 | 55 | * |
mjarvisal | 0:e6fcdb78a136 | 56 | * @li 1 : ON_STACK/local \n |
mjarvisal | 0:e6fcdb78a136 | 57 | * Use local variable (on stack) buffer \n |
mjarvisal | 0:e6fcdb78a136 | 58 | * This solution is multi-thread with use of i2c resource lock or mutex see VL6180x_GetI2CAccess() \n |
mjarvisal | 0:e6fcdb78a136 | 59 | * |
mjarvisal | 0:e6fcdb78a136 | 60 | * @li 2 : User defined \n |
mjarvisal | 0:e6fcdb78a136 | 61 | * Per Device potentially dynamic allocated. Requires VL6180x_GetI2cBuffer() to be implemented. |
mjarvisal | 0:e6fcdb78a136 | 62 | * @ingroup Configuration |
mjarvisal | 0:e6fcdb78a136 | 63 | */ |
mjarvisal | 0:e6fcdb78a136 | 64 | #define I2C_BUFFER_CONFIG 1 |
mjarvisal | 0:e6fcdb78a136 | 65 | /** Maximum buffer size to be used in i2c */ |
mjarvisal | 0:e6fcdb78a136 | 66 | #define VL53L0X_MAX_I2C_XFER_SIZE 64 /* Maximum buffer size to be used in i2c */ |
mjarvisal | 0:e6fcdb78a136 | 67 | |
mjarvisal | 0:e6fcdb78a136 | 68 | #if I2C_BUFFER_CONFIG == 0 |
mjarvisal | 0:e6fcdb78a136 | 69 | /* GLOBAL config buffer */ |
mjarvisal | 0:e6fcdb78a136 | 70 | uint8_t i2c_global_buffer[VL53L0X_MAX_I2C_XFER_SIZE]; |
mjarvisal | 0:e6fcdb78a136 | 71 | |
mjarvisal | 0:e6fcdb78a136 | 72 | #define DECL_I2C_BUFFER |
mjarvisal | 0:e6fcdb78a136 | 73 | #define VL53L0X_GetLocalBuffer(Dev, n_byte) i2c_global_buffer |
mjarvisal | 0:e6fcdb78a136 | 74 | |
mjarvisal | 0:e6fcdb78a136 | 75 | #elif I2C_BUFFER_CONFIG == 1 |
mjarvisal | 0:e6fcdb78a136 | 76 | /* ON STACK */ |
mjarvisal | 0:e6fcdb78a136 | 77 | #define DECL_I2C_BUFFER uint8_t LocBuffer[VL53L0X_MAX_I2C_XFER_SIZE]; |
mjarvisal | 0:e6fcdb78a136 | 78 | #define VL53L0X_GetLocalBuffer(Dev, n_byte) LocBuffer |
mjarvisal | 0:e6fcdb78a136 | 79 | #elif I2C_BUFFER_CONFIG == 2 |
mjarvisal | 0:e6fcdb78a136 | 80 | /* user define buffer type declare DECL_I2C_BUFFER as access via VL53L0X_GetLocalBuffer */ |
mjarvisal | 0:e6fcdb78a136 | 81 | #define DECL_I2C_BUFFER |
mjarvisal | 0:e6fcdb78a136 | 82 | #else |
mjarvisal | 0:e6fcdb78a136 | 83 | #error "invalid I2C_BUFFER_CONFIG " |
mjarvisal | 0:e6fcdb78a136 | 84 | #endif |
mjarvisal | 0:e6fcdb78a136 | 85 | |
mjarvisal | 0:e6fcdb78a136 | 86 | |
mjarvisal | 0:e6fcdb78a136 | 87 | #define VL53L0X_I2C_USER_VAR /* none but could be for a flag var to get/pass to mutex interruptible return flags and try again */ |
mjarvisal | 0:e6fcdb78a136 | 88 | #define VL53L0X_GetI2CAccess(Dev) /* todo mutex acquire */ |
mjarvisal | 0:e6fcdb78a136 | 89 | #define VL53L0X_DoneI2CAcces(Dev) /* todo mutex release */ |
mjarvisal | 0:e6fcdb78a136 | 90 | |
mjarvisal | 0:e6fcdb78a136 | 91 | VL53L0X_Error VL53L0X_LockSequenceAccess(VL53L0X_DEV Dev){ |
mjarvisal | 0:e6fcdb78a136 | 92 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
mjarvisal | 0:e6fcdb78a136 | 93 | |
mjarvisal | 0:e6fcdb78a136 | 94 | return Status; |
mjarvisal | 0:e6fcdb78a136 | 95 | } |
mjarvisal | 0:e6fcdb78a136 | 96 | |
mjarvisal | 0:e6fcdb78a136 | 97 | VL53L0X_Error VL53L0X_UnlockSequenceAccess(VL53L0X_DEV Dev){ |
mjarvisal | 0:e6fcdb78a136 | 98 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
mjarvisal | 0:e6fcdb78a136 | 99 | |
mjarvisal | 0:e6fcdb78a136 | 100 | return Status; |
mjarvisal | 0:e6fcdb78a136 | 101 | } |
mjarvisal | 0:e6fcdb78a136 | 102 | |
mjarvisal | 0:e6fcdb78a136 | 103 | // the ranging_sensor_comms.dll will take care of the page selection |
mjarvisal | 0:e6fcdb78a136 | 104 | VL53L0X_Error VL53L0X_WriteMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count){ |
mjarvisal | 0:e6fcdb78a136 | 105 | |
mjarvisal | 0:e6fcdb78a136 | 106 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
mjarvisal | 0:e6fcdb78a136 | 107 | int32_t status_int = 0; |
mjarvisal | 0:e6fcdb78a136 | 108 | uint8_t deviceAddress; |
mjarvisal | 0:e6fcdb78a136 | 109 | |
mjarvisal | 0:e6fcdb78a136 | 110 | if (count>=VL53L0X_MAX_I2C_XFER_SIZE){ |
mjarvisal | 0:e6fcdb78a136 | 111 | Status = VL53L0X_ERROR_INVALID_PARAMS; |
mjarvisal | 0:e6fcdb78a136 | 112 | } |
mjarvisal | 0:e6fcdb78a136 | 113 | |
mjarvisal | 0:e6fcdb78a136 | 114 | deviceAddress = Dev->I2cDevAddr; |
mjarvisal | 0:e6fcdb78a136 | 115 | |
mjarvisal | 0:e6fcdb78a136 | 116 | status_int = VL53L0X_write_multi(deviceAddress, index, pdata, count); |
mjarvisal | 0:e6fcdb78a136 | 117 | |
mjarvisal | 0:e6fcdb78a136 | 118 | if (status_int != 0) |
mjarvisal | 0:e6fcdb78a136 | 119 | Status = VL53L0X_ERROR_CONTROL_INTERFACE; |
mjarvisal | 0:e6fcdb78a136 | 120 | |
mjarvisal | 0:e6fcdb78a136 | 121 | return Status; |
mjarvisal | 0:e6fcdb78a136 | 122 | } |
mjarvisal | 0:e6fcdb78a136 | 123 | |
mjarvisal | 0:e6fcdb78a136 | 124 | // the ranging_sensor_comms.dll will take care of the page selection |
mjarvisal | 0:e6fcdb78a136 | 125 | VL53L0X_Error VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count){ |
mjarvisal | 0:e6fcdb78a136 | 126 | VL53L0X_I2C_USER_VAR |
mjarvisal | 0:e6fcdb78a136 | 127 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
mjarvisal | 0:e6fcdb78a136 | 128 | int32_t status_int; |
mjarvisal | 0:e6fcdb78a136 | 129 | uint8_t deviceAddress; |
mjarvisal | 0:e6fcdb78a136 | 130 | |
mjarvisal | 0:e6fcdb78a136 | 131 | if (count>=VL53L0X_MAX_I2C_XFER_SIZE){ |
mjarvisal | 0:e6fcdb78a136 | 132 | Status = VL53L0X_ERROR_INVALID_PARAMS; |
mjarvisal | 0:e6fcdb78a136 | 133 | } |
mjarvisal | 0:e6fcdb78a136 | 134 | |
mjarvisal | 0:e6fcdb78a136 | 135 | deviceAddress = Dev->I2cDevAddr; |
mjarvisal | 0:e6fcdb78a136 | 136 | |
mjarvisal | 0:e6fcdb78a136 | 137 | status_int = VL53L0X_read_multi(deviceAddress, index, pdata, count); |
mjarvisal | 0:e6fcdb78a136 | 138 | |
mjarvisal | 0:e6fcdb78a136 | 139 | if (status_int != 0) |
mjarvisal | 0:e6fcdb78a136 | 140 | Status = VL53L0X_ERROR_CONTROL_INTERFACE; |
mjarvisal | 0:e6fcdb78a136 | 141 | |
mjarvisal | 0:e6fcdb78a136 | 142 | return Status; |
mjarvisal | 0:e6fcdb78a136 | 143 | } |
mjarvisal | 0:e6fcdb78a136 | 144 | |
mjarvisal | 0:e6fcdb78a136 | 145 | |
mjarvisal | 0:e6fcdb78a136 | 146 | VL53L0X_Error VL53L0X_WrByte(VL53L0X_DEV Dev, uint8_t index, uint8_t data){ |
mjarvisal | 0:e6fcdb78a136 | 147 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
mjarvisal | 0:e6fcdb78a136 | 148 | int32_t status_int; |
mjarvisal | 0:e6fcdb78a136 | 149 | uint8_t deviceAddress; |
mjarvisal | 0:e6fcdb78a136 | 150 | |
mjarvisal | 0:e6fcdb78a136 | 151 | deviceAddress = Dev->I2cDevAddr; |
mjarvisal | 0:e6fcdb78a136 | 152 | |
mjarvisal | 0:e6fcdb78a136 | 153 | status_int = VL53L0X_write_byte(deviceAddress, index, data); |
mjarvisal | 0:e6fcdb78a136 | 154 | |
mjarvisal | 0:e6fcdb78a136 | 155 | if (status_int != 0) |
mjarvisal | 0:e6fcdb78a136 | 156 | Status = VL53L0X_ERROR_CONTROL_INTERFACE; |
mjarvisal | 0:e6fcdb78a136 | 157 | |
mjarvisal | 0:e6fcdb78a136 | 158 | return Status; |
mjarvisal | 0:e6fcdb78a136 | 159 | } |
mjarvisal | 0:e6fcdb78a136 | 160 | |
mjarvisal | 0:e6fcdb78a136 | 161 | VL53L0X_Error VL53L0X_WrWord(VL53L0X_DEV Dev, uint8_t index, uint16_t data){ |
mjarvisal | 0:e6fcdb78a136 | 162 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
mjarvisal | 0:e6fcdb78a136 | 163 | int32_t status_int; |
mjarvisal | 0:e6fcdb78a136 | 164 | uint8_t deviceAddress; |
mjarvisal | 0:e6fcdb78a136 | 165 | |
mjarvisal | 0:e6fcdb78a136 | 166 | deviceAddress = Dev->I2cDevAddr; |
mjarvisal | 0:e6fcdb78a136 | 167 | |
mjarvisal | 0:e6fcdb78a136 | 168 | status_int = VL53L0X_write_word(deviceAddress, index, data); |
mjarvisal | 0:e6fcdb78a136 | 169 | |
mjarvisal | 0:e6fcdb78a136 | 170 | if (status_int != 0) |
mjarvisal | 0:e6fcdb78a136 | 171 | Status = VL53L0X_ERROR_CONTROL_INTERFACE; |
mjarvisal | 0:e6fcdb78a136 | 172 | |
mjarvisal | 0:e6fcdb78a136 | 173 | return Status; |
mjarvisal | 0:e6fcdb78a136 | 174 | } |
mjarvisal | 0:e6fcdb78a136 | 175 | |
mjarvisal | 0:e6fcdb78a136 | 176 | VL53L0X_Error VL53L0X_WrDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t data){ |
mjarvisal | 0:e6fcdb78a136 | 177 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
mjarvisal | 0:e6fcdb78a136 | 178 | int32_t status_int; |
mjarvisal | 0:e6fcdb78a136 | 179 | uint8_t deviceAddress; |
mjarvisal | 0:e6fcdb78a136 | 180 | |
mjarvisal | 0:e6fcdb78a136 | 181 | deviceAddress = Dev->I2cDevAddr; |
mjarvisal | 0:e6fcdb78a136 | 182 | |
mjarvisal | 0:e6fcdb78a136 | 183 | status_int = VL53L0X_write_dword(deviceAddress, index, data); |
mjarvisal | 0:e6fcdb78a136 | 184 | |
mjarvisal | 0:e6fcdb78a136 | 185 | if (status_int != 0) |
mjarvisal | 0:e6fcdb78a136 | 186 | Status = VL53L0X_ERROR_CONTROL_INTERFACE; |
mjarvisal | 0:e6fcdb78a136 | 187 | |
mjarvisal | 0:e6fcdb78a136 | 188 | return Status; |
mjarvisal | 0:e6fcdb78a136 | 189 | } |
mjarvisal | 0:e6fcdb78a136 | 190 | |
mjarvisal | 0:e6fcdb78a136 | 191 | VL53L0X_Error VL53L0X_UpdateByte(VL53L0X_DEV Dev, uint8_t index, uint8_t AndData, uint8_t OrData){ |
mjarvisal | 0:e6fcdb78a136 | 192 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
mjarvisal | 0:e6fcdb78a136 | 193 | int32_t status_int; |
mjarvisal | 0:e6fcdb78a136 | 194 | uint8_t deviceAddress; |
mjarvisal | 0:e6fcdb78a136 | 195 | uint8_t data; |
mjarvisal | 0:e6fcdb78a136 | 196 | |
mjarvisal | 0:e6fcdb78a136 | 197 | deviceAddress = Dev->I2cDevAddr; |
mjarvisal | 0:e6fcdb78a136 | 198 | |
mjarvisal | 0:e6fcdb78a136 | 199 | status_int = VL53L0X_read_byte(deviceAddress, index, &data); |
mjarvisal | 0:e6fcdb78a136 | 200 | |
mjarvisal | 0:e6fcdb78a136 | 201 | if (status_int != 0) |
mjarvisal | 0:e6fcdb78a136 | 202 | Status = VL53L0X_ERROR_CONTROL_INTERFACE; |
mjarvisal | 0:e6fcdb78a136 | 203 | |
mjarvisal | 0:e6fcdb78a136 | 204 | if (Status == VL53L0X_ERROR_NONE) { |
mjarvisal | 0:e6fcdb78a136 | 205 | data = (data & AndData) | OrData; |
mjarvisal | 0:e6fcdb78a136 | 206 | status_int = VL53L0X_write_byte(deviceAddress, index, data); |
mjarvisal | 0:e6fcdb78a136 | 207 | |
mjarvisal | 0:e6fcdb78a136 | 208 | if (status_int != 0) |
mjarvisal | 0:e6fcdb78a136 | 209 | Status = VL53L0X_ERROR_CONTROL_INTERFACE; |
mjarvisal | 0:e6fcdb78a136 | 210 | } |
mjarvisal | 0:e6fcdb78a136 | 211 | |
mjarvisal | 0:e6fcdb78a136 | 212 | return Status; |
mjarvisal | 0:e6fcdb78a136 | 213 | } |
mjarvisal | 0:e6fcdb78a136 | 214 | |
mjarvisal | 0:e6fcdb78a136 | 215 | VL53L0X_Error VL53L0X_RdByte(VL53L0X_DEV Dev, uint8_t index, uint8_t *data){ |
mjarvisal | 0:e6fcdb78a136 | 216 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
mjarvisal | 0:e6fcdb78a136 | 217 | int32_t status_int; |
mjarvisal | 0:e6fcdb78a136 | 218 | uint8_t deviceAddress; |
mjarvisal | 0:e6fcdb78a136 | 219 | |
mjarvisal | 0:e6fcdb78a136 | 220 | deviceAddress = Dev->I2cDevAddr; |
mjarvisal | 0:e6fcdb78a136 | 221 | |
mjarvisal | 0:e6fcdb78a136 | 222 | status_int = VL53L0X_read_byte(deviceAddress, index, data); |
mjarvisal | 0:e6fcdb78a136 | 223 | |
mjarvisal | 0:e6fcdb78a136 | 224 | if (status_int != 0) |
mjarvisal | 0:e6fcdb78a136 | 225 | Status = VL53L0X_ERROR_CONTROL_INTERFACE; |
mjarvisal | 0:e6fcdb78a136 | 226 | |
mjarvisal | 0:e6fcdb78a136 | 227 | return Status; |
mjarvisal | 0:e6fcdb78a136 | 228 | } |
mjarvisal | 0:e6fcdb78a136 | 229 | |
mjarvisal | 0:e6fcdb78a136 | 230 | VL53L0X_Error VL53L0X_RdWord(VL53L0X_DEV Dev, uint8_t index, uint16_t *data){ |
mjarvisal | 0:e6fcdb78a136 | 231 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
mjarvisal | 0:e6fcdb78a136 | 232 | int32_t status_int; |
mjarvisal | 0:e6fcdb78a136 | 233 | uint8_t deviceAddress; |
mjarvisal | 0:e6fcdb78a136 | 234 | |
mjarvisal | 0:e6fcdb78a136 | 235 | deviceAddress = Dev->I2cDevAddr; |
mjarvisal | 0:e6fcdb78a136 | 236 | |
mjarvisal | 0:e6fcdb78a136 | 237 | status_int = VL53L0X_read_word(deviceAddress, index, data); |
mjarvisal | 0:e6fcdb78a136 | 238 | |
mjarvisal | 0:e6fcdb78a136 | 239 | if (status_int != 0) |
mjarvisal | 0:e6fcdb78a136 | 240 | Status = VL53L0X_ERROR_CONTROL_INTERFACE; |
mjarvisal | 0:e6fcdb78a136 | 241 | |
mjarvisal | 0:e6fcdb78a136 | 242 | return Status; |
mjarvisal | 0:e6fcdb78a136 | 243 | } |
mjarvisal | 0:e6fcdb78a136 | 244 | |
mjarvisal | 0:e6fcdb78a136 | 245 | VL53L0X_Error VL53L0X_RdDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t *data){ |
mjarvisal | 0:e6fcdb78a136 | 246 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
mjarvisal | 0:e6fcdb78a136 | 247 | int32_t status_int; |
mjarvisal | 0:e6fcdb78a136 | 248 | uint8_t deviceAddress; |
mjarvisal | 0:e6fcdb78a136 | 249 | |
mjarvisal | 0:e6fcdb78a136 | 250 | deviceAddress = Dev->I2cDevAddr; |
mjarvisal | 0:e6fcdb78a136 | 251 | |
mjarvisal | 0:e6fcdb78a136 | 252 | status_int = VL53L0X_read_dword(deviceAddress, index, data); |
mjarvisal | 0:e6fcdb78a136 | 253 | |
mjarvisal | 0:e6fcdb78a136 | 254 | if (status_int != 0) |
mjarvisal | 0:e6fcdb78a136 | 255 | Status = VL53L0X_ERROR_CONTROL_INTERFACE; |
mjarvisal | 0:e6fcdb78a136 | 256 | |
mjarvisal | 0:e6fcdb78a136 | 257 | return Status; |
mjarvisal | 0:e6fcdb78a136 | 258 | } |
mjarvisal | 0:e6fcdb78a136 | 259 | |
mjarvisal | 0:e6fcdb78a136 | 260 | #define VL53L0X_POLLINGDELAY_LOOPNB 250 |
mjarvisal | 0:e6fcdb78a136 | 261 | VL53L0X_Error VL53L0X_PollingDelay(VL53L0X_DEV Dev){ |
mjarvisal | 0:e6fcdb78a136 | 262 | VL53L0X_Error status = VL53L0X_ERROR_NONE; |
mjarvisal | 0:e6fcdb78a136 | 263 | volatile uint32_t i; |
mjarvisal | 0:e6fcdb78a136 | 264 | LOG_FUNCTION_START(""); |
mjarvisal | 0:e6fcdb78a136 | 265 | |
mjarvisal | 0:e6fcdb78a136 | 266 | for(i=0;i<VL53L0X_POLLINGDELAY_LOOPNB;i++){ |
mjarvisal | 0:e6fcdb78a136 | 267 | //Do nothing |
mjarvisal | 0:e6fcdb78a136 | 268 | asm("nop"); |
mjarvisal | 0:e6fcdb78a136 | 269 | } |
mjarvisal | 0:e6fcdb78a136 | 270 | |
mjarvisal | 0:e6fcdb78a136 | 271 | LOG_FUNCTION_END(status); |
mjarvisal | 0:e6fcdb78a136 | 272 | return status; |
mjarvisal | 0:e6fcdb78a136 | 273 | } |