The VL53L1CB proximity sensor, based on ST’s FlightSense™, Time-of-Flight technology.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   VL53L1CB_noshield_1sensor_polls_auton VL53L1CB_noshield_1sensor_interrupt_auton X_NUCLEO_53L1A2

Based on VL53L1 library, this is a library for the VL53L1CB ToF chip.

Committer:
Charles MacNeill
Date:
Tue Jun 08 10:34:47 2021 +0100
Revision:
7:1add29d51e72
Parent:
0:3ac96e360672
Update to v6.6.5 of bare_driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
charlesmn 0:3ac96e360672 1
Charles MacNeill 7:1add29d51e72 2 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
Charles MacNeill 7:1add29d51e72 3 /******************************************************************************
charlesmn 0:3ac96e360672 4 * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
charlesmn 0:3ac96e360672 5
Charles MacNeill 7:1add29d51e72 6 This file is part of VL53L1 and is dual licensed,
Charles MacNeill 7:1add29d51e72 7 either GPL-2.0+
charlesmn 0:3ac96e360672 8 or 'BSD 3-clause "New" or "Revised" License' , at your option.
Charles MacNeill 7:1add29d51e72 9 ******************************************************************************
Charles MacNeill 7:1add29d51e72 10 */
charlesmn 0:3ac96e360672 11
charlesmn 0:3ac96e360672 12
charlesmn 0:3ac96e360672 13
charlesmn 0:3ac96e360672 14
charlesmn 0:3ac96e360672 15
charlesmn 0:3ac96e360672 16 #ifdef _MSC_VER
charlesmn 0:3ac96e360672 17 #define snprintf _snprintf
charlesmn 0:3ac96e360672 18 #endif
charlesmn 0:3ac96e360672 19
charlesmn 0:3ac96e360672 20
charlesmn 0:3ac96e360672 21
charlesmn 0:3ac96e360672 22 #include "vl53l1_ll_def.h"
charlesmn 0:3ac96e360672 23 #include "vl53l1_platform.h"
charlesmn 0:3ac96e360672 24 #include "vl53l1_platform_log.h"
charlesmn 0:3ac96e360672 25 #include "vl53l1_register_map.h"
charlesmn 0:3ac96e360672 26 #include "vl53l1_core.h"
charlesmn 0:3ac96e360672 27 #include "vl53l1_nvm_structs.h"
charlesmn 0:3ac96e360672 28 #include "vl53l1_nvm_map.h"
charlesmn 0:3ac96e360672 29 #include "vl53l1_nvm.h"
charlesmn 0:3ac96e360672 30
charlesmn 0:3ac96e360672 31
charlesmn 0:3ac96e360672 32
charlesmn 0:3ac96e360672 33 #define LOG_FUNCTION_START(fmt, ...) \
charlesmn 0:3ac96e360672 34 _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_NVM, fmt, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 35 #define LOG_FUNCTION_END(status, ...) \
charlesmn 0:3ac96e360672 36 _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_NVM, status, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 37 #define LOG_FUNCTION_END_FMT(status, fmt, ...) \
charlesmn 0:3ac96e360672 38 _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_NVM,\
charlesmn 0:3ac96e360672 39 status, fmt, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 40
charlesmn 0:3ac96e360672 41 #define trace_print(level, ...) \
charlesmn 0:3ac96e360672 42 _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_NVM, \
charlesmn 0:3ac96e360672 43 level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 44
charlesmn 0:3ac96e360672 45
charlesmn 0:3ac96e360672 46 VL53L1_Error VL53L1_nvm_enable(
charlesmn 0:3ac96e360672 47 VL53L1_DEV Dev,
charlesmn 0:3ac96e360672 48 uint16_t nvm_ctrl_pulse_width,
charlesmn 0:3ac96e360672 49 int32_t nvm_power_up_delay_us)
charlesmn 0:3ac96e360672 50 {
charlesmn 0:3ac96e360672 51
charlesmn 0:3ac96e360672 52
charlesmn 0:3ac96e360672 53 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 54
charlesmn 0:3ac96e360672 55 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 56
charlesmn 0:3ac96e360672 57
charlesmn 0:3ac96e360672 58
charlesmn 0:3ac96e360672 59
charlesmn 0:3ac96e360672 60 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 61 status = VL53L1_disable_firmware(Dev);
charlesmn 0:3ac96e360672 62
charlesmn 0:3ac96e360672 63
charlesmn 0:3ac96e360672 64
charlesmn 0:3ac96e360672 65
charlesmn 0:3ac96e360672 66 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 67 status = VL53L1_enable_powerforce(Dev);
charlesmn 0:3ac96e360672 68
charlesmn 0:3ac96e360672 69
charlesmn 0:3ac96e360672 70
charlesmn 0:3ac96e360672 71 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 72 status = VL53L1_WaitUs(
charlesmn 0:3ac96e360672 73 Dev,
charlesmn 0:3ac96e360672 74 VL53L1_ENABLE_POWERFORCE_SETTLING_TIME_US);
charlesmn 0:3ac96e360672 75
charlesmn 0:3ac96e360672 76
charlesmn 0:3ac96e360672 77
charlesmn 0:3ac96e360672 78 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 79 status = VL53L1_WrByte(
charlesmn 0:3ac96e360672 80 Dev,
charlesmn 0:3ac96e360672 81 VL53L1_RANGING_CORE__NVM_CTRL__PDN,
charlesmn 0:3ac96e360672 82 0x01);
charlesmn 0:3ac96e360672 83
charlesmn 0:3ac96e360672 84
charlesmn 0:3ac96e360672 85
charlesmn 0:3ac96e360672 86 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 87 status = VL53L1_WrByte(
charlesmn 0:3ac96e360672 88 Dev,
charlesmn 0:3ac96e360672 89 VL53L1_RANGING_CORE__CLK_CTRL1,
charlesmn 0:3ac96e360672 90 0x05);
charlesmn 0:3ac96e360672 91
charlesmn 0:3ac96e360672 92
charlesmn 0:3ac96e360672 93
charlesmn 0:3ac96e360672 94 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 95 status = VL53L1_WaitUs(
charlesmn 0:3ac96e360672 96 Dev,
charlesmn 0:3ac96e360672 97 nvm_power_up_delay_us);
charlesmn 0:3ac96e360672 98
charlesmn 0:3ac96e360672 99
charlesmn 0:3ac96e360672 100
charlesmn 0:3ac96e360672 101 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 102 status = VL53L1_WrByte(
charlesmn 0:3ac96e360672 103 Dev,
charlesmn 0:3ac96e360672 104 VL53L1_RANGING_CORE__NVM_CTRL__MODE,
charlesmn 0:3ac96e360672 105 0x01);
charlesmn 0:3ac96e360672 106
charlesmn 0:3ac96e360672 107 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 108 status = VL53L1_WrWord(
charlesmn 0:3ac96e360672 109 Dev,
charlesmn 0:3ac96e360672 110 VL53L1_RANGING_CORE__NVM_CTRL__PULSE_WIDTH_MSB,
charlesmn 0:3ac96e360672 111 nvm_ctrl_pulse_width);
charlesmn 0:3ac96e360672 112
charlesmn 0:3ac96e360672 113 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 114
charlesmn 0:3ac96e360672 115 return status;
charlesmn 0:3ac96e360672 116
charlesmn 0:3ac96e360672 117 }
charlesmn 0:3ac96e360672 118
charlesmn 0:3ac96e360672 119
charlesmn 0:3ac96e360672 120 VL53L1_Error VL53L1_nvm_read(
charlesmn 0:3ac96e360672 121 VL53L1_DEV Dev,
charlesmn 0:3ac96e360672 122 uint8_t start_address,
charlesmn 0:3ac96e360672 123 uint8_t count,
charlesmn 0:3ac96e360672 124 uint8_t *pdata)
charlesmn 0:3ac96e360672 125 {
charlesmn 0:3ac96e360672 126
charlesmn 0:3ac96e360672 127
charlesmn 0:3ac96e360672 128 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 129 uint8_t nvm_addr = 0;
charlesmn 0:3ac96e360672 130
charlesmn 0:3ac96e360672 131 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 132
charlesmn 0:3ac96e360672 133 trace_print(
charlesmn 0:3ac96e360672 134 VL53L1_TRACE_LEVEL_INFO,
charlesmn 0:3ac96e360672 135 "%-12s = 0x%02X (%3u)\n",
charlesmn 0:3ac96e360672 136 "nvm_addr", nvm_addr, nvm_addr);
charlesmn 0:3ac96e360672 137
charlesmn 0:3ac96e360672 138 trace_print(
charlesmn 0:3ac96e360672 139 VL53L1_TRACE_LEVEL_INFO,
charlesmn 0:3ac96e360672 140 "%-12s = 0x%02X (%3u)\n",
charlesmn 0:3ac96e360672 141 "count", count, count);
charlesmn 0:3ac96e360672 142
charlesmn 0:3ac96e360672 143 for (nvm_addr = start_address;
charlesmn 0:3ac96e360672 144 nvm_addr < (start_address+count) ; nvm_addr++) {
charlesmn 0:3ac96e360672 145
charlesmn 0:3ac96e360672 146
charlesmn 0:3ac96e360672 147
charlesmn 0:3ac96e360672 148 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 149 status = VL53L1_WrByte(
charlesmn 0:3ac96e360672 150 Dev,
charlesmn 0:3ac96e360672 151 VL53L1_RANGING_CORE__NVM_CTRL__ADDR,
charlesmn 0:3ac96e360672 152 nvm_addr);
charlesmn 0:3ac96e360672 153
charlesmn 0:3ac96e360672 154
charlesmn 0:3ac96e360672 155
charlesmn 0:3ac96e360672 156 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 157 status = VL53L1_WrByte(
charlesmn 0:3ac96e360672 158 Dev,
charlesmn 0:3ac96e360672 159 VL53L1_RANGING_CORE__NVM_CTRL__READN,
charlesmn 0:3ac96e360672 160 0x00);
charlesmn 0:3ac96e360672 161
charlesmn 0:3ac96e360672 162
charlesmn 0:3ac96e360672 163
charlesmn 0:3ac96e360672 164 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 165 status = VL53L1_WaitUs(
charlesmn 0:3ac96e360672 166 Dev,
charlesmn 0:3ac96e360672 167 VL53L1_NVM_READ_TRIGGER_DELAY_US);
charlesmn 0:3ac96e360672 168
charlesmn 0:3ac96e360672 169 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 170 status = VL53L1_WrByte(
charlesmn 0:3ac96e360672 171 Dev,
charlesmn 0:3ac96e360672 172 VL53L1_RANGING_CORE__NVM_CTRL__READN,
charlesmn 0:3ac96e360672 173 0x01);
charlesmn 0:3ac96e360672 174
charlesmn 0:3ac96e360672 175
charlesmn 0:3ac96e360672 176 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 177 status = VL53L1_ReadMulti(
charlesmn 0:3ac96e360672 178 Dev,
charlesmn 0:3ac96e360672 179 VL53L1_RANGING_CORE__NVM_CTRL__DATAOUT_MMM,
charlesmn 0:3ac96e360672 180 pdata,
charlesmn 0:3ac96e360672 181 4);
charlesmn 0:3ac96e360672 182
charlesmn 0:3ac96e360672 183 trace_print(
charlesmn 0:3ac96e360672 184 VL53L1_TRACE_LEVEL_INFO,
charlesmn 0:3ac96e360672 185 "NVM address : 0x%02X = 0x%02X%02X%02X%02X\n",
charlesmn 0:3ac96e360672 186 nvm_addr, *pdata, *(pdata+1), *(pdata+2), *(pdata+3));
charlesmn 0:3ac96e360672 187
charlesmn 0:3ac96e360672 188
charlesmn 0:3ac96e360672 189
charlesmn 0:3ac96e360672 190 pdata = pdata + 4;
charlesmn 0:3ac96e360672 191
charlesmn 0:3ac96e360672 192
charlesmn 0:3ac96e360672 193 }
charlesmn 0:3ac96e360672 194
charlesmn 0:3ac96e360672 195 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 196
charlesmn 0:3ac96e360672 197 return status;
charlesmn 0:3ac96e360672 198 }
charlesmn 0:3ac96e360672 199
charlesmn 0:3ac96e360672 200
charlesmn 0:3ac96e360672 201 VL53L1_Error VL53L1_nvm_disable(
charlesmn 0:3ac96e360672 202 VL53L1_DEV Dev)
charlesmn 0:3ac96e360672 203 {
charlesmn 0:3ac96e360672 204
charlesmn 0:3ac96e360672 205
charlesmn 0:3ac96e360672 206 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 207
charlesmn 0:3ac96e360672 208 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 209
charlesmn 0:3ac96e360672 210 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 211 status = VL53L1_WrByte(
charlesmn 0:3ac96e360672 212 Dev,
charlesmn 0:3ac96e360672 213 VL53L1_RANGING_CORE__NVM_CTRL__READN,
charlesmn 0:3ac96e360672 214 0x01);
charlesmn 0:3ac96e360672 215
charlesmn 0:3ac96e360672 216
charlesmn 0:3ac96e360672 217
charlesmn 0:3ac96e360672 218 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 219 status = VL53L1_WrByte(
charlesmn 0:3ac96e360672 220 Dev,
charlesmn 0:3ac96e360672 221 VL53L1_RANGING_CORE__NVM_CTRL__PDN,
charlesmn 0:3ac96e360672 222 0x00);
charlesmn 0:3ac96e360672 223
charlesmn 0:3ac96e360672 224
charlesmn 0:3ac96e360672 225
charlesmn 0:3ac96e360672 226 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 227 status = VL53L1_disable_powerforce(Dev);
charlesmn 0:3ac96e360672 228
charlesmn 0:3ac96e360672 229
charlesmn 0:3ac96e360672 230
charlesmn 0:3ac96e360672 231 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 232 status = VL53L1_enable_firmware(Dev);
charlesmn 0:3ac96e360672 233
charlesmn 0:3ac96e360672 234 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 235
charlesmn 0:3ac96e360672 236 return status;
charlesmn 0:3ac96e360672 237
charlesmn 0:3ac96e360672 238 }
charlesmn 0:3ac96e360672 239
charlesmn 0:3ac96e360672 240
charlesmn 0:3ac96e360672 241 VL53L1_Error VL53L1_nvm_format_decode(
charlesmn 0:3ac96e360672 242 uint16_t buf_size,
charlesmn 0:3ac96e360672 243 uint8_t *pbuffer,
charlesmn 0:3ac96e360672 244 VL53L1_decoded_nvm_data_t *pdata)
charlesmn 0:3ac96e360672 245 {
charlesmn 0:3ac96e360672 246
charlesmn 0:3ac96e360672 247
charlesmn 0:3ac96e360672 248
charlesmn 0:3ac96e360672 249 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 250
charlesmn 0:3ac96e360672 251 uint8_t i = 0;
charlesmn 0:3ac96e360672 252 uint8_t *ptmp = NULL;
charlesmn 0:3ac96e360672 253 int pptmp[VL53L1_NVM_MAX_FMT_RANGE_DATA];
charlesmn 0:3ac96e360672 254
charlesmn 0:3ac96e360672 255 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 256
charlesmn 0:3ac96e360672 257 if (buf_size < VL53L1_NVM_SIZE_IN_BYTES)
charlesmn 0:3ac96e360672 258 return VL53L1_ERROR_BUFFER_TOO_SMALL;
charlesmn 0:3ac96e360672 259
charlesmn 0:3ac96e360672 260 pdata->nvm__identification_model_id =
charlesmn 0:3ac96e360672 261 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 262 1,
charlesmn 0:3ac96e360672 263 pbuffer + VL53L1_NVM__IDENTIFICATION__MODEL_ID,
charlesmn 0:3ac96e360672 264 0x000000FF,
charlesmn 0:3ac96e360672 265 0,
charlesmn 0:3ac96e360672 266 0);
charlesmn 0:3ac96e360672 267 pdata->nvm__identification_module_type =
charlesmn 0:3ac96e360672 268 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 269 1,
charlesmn 0:3ac96e360672 270 pbuffer + VL53L1_NVM__IDENTIFICATION__MODULE_TYPE,
charlesmn 0:3ac96e360672 271 0x000000FF,
charlesmn 0:3ac96e360672 272 0,
charlesmn 0:3ac96e360672 273 0);
charlesmn 0:3ac96e360672 274 pdata->nvm__identification_revision_id =
charlesmn 0:3ac96e360672 275 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 276 1,
charlesmn 0:3ac96e360672 277 pbuffer + VL53L1_NVM__IDENTIFICATION__REVISION_ID,
charlesmn 0:3ac96e360672 278 0x0000000F,
charlesmn 0:3ac96e360672 279 0,
charlesmn 0:3ac96e360672 280 0);
charlesmn 0:3ac96e360672 281 pdata->nvm__identification_module_id =
charlesmn 0:3ac96e360672 282 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 283 2,
charlesmn 0:3ac96e360672 284 pbuffer + VL53L1_NVM__IDENTIFICATION__MODULE_ID,
charlesmn 0:3ac96e360672 285 0x0000FFFF,
charlesmn 0:3ac96e360672 286 0,
charlesmn 0:3ac96e360672 287 0);
charlesmn 0:3ac96e360672 288 pdata->nvm__i2c_valid =
charlesmn 0:3ac96e360672 289 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 290 1,
charlesmn 0:3ac96e360672 291 pbuffer + VL53L1_NVM__I2C_VALID,
charlesmn 0:3ac96e360672 292 0x000000FF,
charlesmn 0:3ac96e360672 293 0,
charlesmn 0:3ac96e360672 294 0);
charlesmn 0:3ac96e360672 295 pdata->nvm__i2c_device_address_ews =
charlesmn 0:3ac96e360672 296 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 297 1,
charlesmn 0:3ac96e360672 298 pbuffer + VL53L1_NVM__I2C_SLAVE__DEVICE_ADDRESS,
charlesmn 0:3ac96e360672 299 0x000000FF,
charlesmn 0:3ac96e360672 300 0,
charlesmn 0:3ac96e360672 301 0);
charlesmn 0:3ac96e360672 302 pdata->nvm__ews__fast_osc_frequency =
charlesmn 0:3ac96e360672 303 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 304 2,
charlesmn 0:3ac96e360672 305 pbuffer +
charlesmn 0:3ac96e360672 306 VL53L1_NVM__EWS__OSC_MEASURED__FAST_OSC_FREQUENCY,
charlesmn 0:3ac96e360672 307 0x0000FFFF,
charlesmn 0:3ac96e360672 308 0,
charlesmn 0:3ac96e360672 309 0);
charlesmn 0:3ac96e360672 310 pdata->nvm__ews__fast_osc_trim_max =
charlesmn 0:3ac96e360672 311 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 312 1,
charlesmn 0:3ac96e360672 313 pbuffer + VL53L1_NVM__EWS__FAST_OSC_TRIM_MAX,
charlesmn 0:3ac96e360672 314 0x0000007F,
charlesmn 0:3ac96e360672 315 0,
charlesmn 0:3ac96e360672 316 0);
charlesmn 0:3ac96e360672 317 pdata->nvm__ews__fast_osc_freq_set =
charlesmn 0:3ac96e360672 318 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 319 1,
charlesmn 0:3ac96e360672 320 pbuffer + VL53L1_NVM__EWS__FAST_OSC_FREQ_SET,
charlesmn 0:3ac96e360672 321 0x00000007,
charlesmn 0:3ac96e360672 322 0,
charlesmn 0:3ac96e360672 323 0);
charlesmn 0:3ac96e360672 324 pdata->nvm__ews__slow_osc_calibration =
charlesmn 0:3ac96e360672 325 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 326 2,
charlesmn 0:3ac96e360672 327 pbuffer + VL53L1_NVM__EWS__SLOW_OSC_CALIBRATION,
charlesmn 0:3ac96e360672 328 0x000003FF,
charlesmn 0:3ac96e360672 329 0,
charlesmn 0:3ac96e360672 330 0);
charlesmn 0:3ac96e360672 331 pdata->nvm__fmt__fast_osc_frequency =
charlesmn 0:3ac96e360672 332 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 333 2,
charlesmn 0:3ac96e360672 334 pbuffer +
charlesmn 0:3ac96e360672 335 VL53L1_NVM__FMT__OSC_MEASURED__FAST_OSC_FREQUENCY,
charlesmn 0:3ac96e360672 336 0x0000FFFF,
charlesmn 0:3ac96e360672 337 0,
charlesmn 0:3ac96e360672 338 0);
charlesmn 0:3ac96e360672 339 pdata->nvm__fmt__fast_osc_trim_max =
charlesmn 0:3ac96e360672 340 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 341 1,
charlesmn 0:3ac96e360672 342 pbuffer + VL53L1_NVM__FMT__FAST_OSC_TRIM_MAX,
charlesmn 0:3ac96e360672 343 0x0000007F,
charlesmn 0:3ac96e360672 344 0,
charlesmn 0:3ac96e360672 345 0);
charlesmn 0:3ac96e360672 346 pdata->nvm__fmt__fast_osc_freq_set =
charlesmn 0:3ac96e360672 347 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 348 1,
charlesmn 0:3ac96e360672 349 pbuffer + VL53L1_NVM__FMT__FAST_OSC_FREQ_SET,
charlesmn 0:3ac96e360672 350 0x00000007,
charlesmn 0:3ac96e360672 351 0,
charlesmn 0:3ac96e360672 352 0);
charlesmn 0:3ac96e360672 353 pdata->nvm__fmt__slow_osc_calibration =
charlesmn 0:3ac96e360672 354 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 355 2,
charlesmn 0:3ac96e360672 356 pbuffer + VL53L1_NVM__FMT__SLOW_OSC_CALIBRATION,
charlesmn 0:3ac96e360672 357 0x000003FF,
charlesmn 0:3ac96e360672 358 0,
charlesmn 0:3ac96e360672 359 0);
charlesmn 0:3ac96e360672 360 pdata->nvm__vhv_config_unlock =
charlesmn 0:3ac96e360672 361 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 362 1,
charlesmn 0:3ac96e360672 363 pbuffer + VL53L1_NVM__VHV_CONFIG_UNLOCK,
charlesmn 0:3ac96e360672 364 0x000000FF,
charlesmn 0:3ac96e360672 365 0,
charlesmn 0:3ac96e360672 366 0);
charlesmn 0:3ac96e360672 367 pdata->nvm__ref_selvddpix =
charlesmn 0:3ac96e360672 368 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 369 1,
charlesmn 0:3ac96e360672 370 pbuffer + VL53L1_NVM__REF_SELVDDPIX,
charlesmn 0:3ac96e360672 371 0x0000000F,
charlesmn 0:3ac96e360672 372 0,
charlesmn 0:3ac96e360672 373 0);
charlesmn 0:3ac96e360672 374 pdata->nvm__ref_selvquench =
charlesmn 0:3ac96e360672 375 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 376 1,
charlesmn 0:3ac96e360672 377 pbuffer + VL53L1_NVM__REF_SELVQUENCH,
charlesmn 0:3ac96e360672 378 0x00000078,
charlesmn 0:3ac96e360672 379 3,
charlesmn 0:3ac96e360672 380 0);
charlesmn 0:3ac96e360672 381 pdata->nvm__regavdd1v2_sel =
charlesmn 0:3ac96e360672 382 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 383 1,
charlesmn 0:3ac96e360672 384 pbuffer + VL53L1_NVM__REGAVDD1V2_SEL_REGDVDD1V2_SEL,
charlesmn 0:3ac96e360672 385 0x0000000C,
charlesmn 0:3ac96e360672 386 2,
charlesmn 0:3ac96e360672 387 0);
charlesmn 0:3ac96e360672 388 pdata->nvm__regdvdd1v2_sel =
charlesmn 0:3ac96e360672 389 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 390 1,
charlesmn 0:3ac96e360672 391 pbuffer + VL53L1_NVM__REGAVDD1V2_SEL_REGDVDD1V2_SEL,
charlesmn 0:3ac96e360672 392 0x00000003,
charlesmn 0:3ac96e360672 393 0,
charlesmn 0:3ac96e360672 394 0);
charlesmn 0:3ac96e360672 395 pdata->nvm__vhv_timeout__macrop =
charlesmn 0:3ac96e360672 396 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 397 1,
charlesmn 0:3ac96e360672 398 pbuffer +
charlesmn 0:3ac96e360672 399 VL53L1_NVM__VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND,
charlesmn 0:3ac96e360672 400 0x00000003,
charlesmn 0:3ac96e360672 401 0,
charlesmn 0:3ac96e360672 402 0);
charlesmn 0:3ac96e360672 403 pdata->nvm__vhv_loop_bound =
charlesmn 0:3ac96e360672 404 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 405 1,
charlesmn 0:3ac96e360672 406 pbuffer +
charlesmn 0:3ac96e360672 407 VL53L1_NVM__VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND,
charlesmn 0:3ac96e360672 408 0x000000FC,
charlesmn 0:3ac96e360672 409 2,
charlesmn 0:3ac96e360672 410 0);
charlesmn 0:3ac96e360672 411 pdata->nvm__vhv_count_threshold =
charlesmn 0:3ac96e360672 412 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 413 1,
charlesmn 0:3ac96e360672 414 pbuffer + VL53L1_NVM__VHV_CONFIG__COUNT_THRESH,
charlesmn 0:3ac96e360672 415 0x000000FF,
charlesmn 0:3ac96e360672 416 0,
charlesmn 0:3ac96e360672 417 0);
charlesmn 0:3ac96e360672 418 pdata->nvm__vhv_offset =
charlesmn 0:3ac96e360672 419 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 420 1,
charlesmn 0:3ac96e360672 421 pbuffer + VL53L1_NVM__VHV_CONFIG__OFFSET,
charlesmn 0:3ac96e360672 422 0x0000003F,
charlesmn 0:3ac96e360672 423 0,
charlesmn 0:3ac96e360672 424 0);
charlesmn 0:3ac96e360672 425 pdata->nvm__vhv_init_enable =
charlesmn 0:3ac96e360672 426 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 427 1,
charlesmn 0:3ac96e360672 428 pbuffer + VL53L1_NVM__VHV_CONFIG__INIT,
charlesmn 0:3ac96e360672 429 0x00000080,
charlesmn 0:3ac96e360672 430 7,
charlesmn 0:3ac96e360672 431 0);
charlesmn 0:3ac96e360672 432 pdata->nvm__vhv_init_value =
charlesmn 0:3ac96e360672 433 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 434 1,
charlesmn 0:3ac96e360672 435 pbuffer + VL53L1_NVM__VHV_CONFIG__INIT,
charlesmn 0:3ac96e360672 436 0x0000003F,
charlesmn 0:3ac96e360672 437 0,
charlesmn 0:3ac96e360672 438 0);
charlesmn 0:3ac96e360672 439 pdata->nvm__laser_safety_vcsel_trim_ll =
charlesmn 0:3ac96e360672 440 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 441 1,
charlesmn 0:3ac96e360672 442 pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_TRIM_LL,
charlesmn 0:3ac96e360672 443 0x00000007,
charlesmn 0:3ac96e360672 444 0,
charlesmn 0:3ac96e360672 445 0);
charlesmn 0:3ac96e360672 446 pdata->nvm__laser_safety_vcsel_selion_ll =
charlesmn 0:3ac96e360672 447 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 448 1,
charlesmn 0:3ac96e360672 449 pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_LL,
charlesmn 0:3ac96e360672 450 0x0000003F,
charlesmn 0:3ac96e360672 451 0,
charlesmn 0:3ac96e360672 452 0);
charlesmn 0:3ac96e360672 453 pdata->nvm__laser_safety_vcsel_selion_max_ll =
charlesmn 0:3ac96e360672 454 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 455 1,
charlesmn 0:3ac96e360672 456 pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_MAX_LL,
charlesmn 0:3ac96e360672 457 0x0000003F,
charlesmn 0:3ac96e360672 458 0,
charlesmn 0:3ac96e360672 459 0);
charlesmn 0:3ac96e360672 460 pdata->nvm__laser_safety_mult_ll =
charlesmn 0:3ac96e360672 461 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 462 1,
charlesmn 0:3ac96e360672 463 pbuffer + VL53L1_NVM__LASER_SAFETY__MULT_LL,
charlesmn 0:3ac96e360672 464 0x0000003F,
charlesmn 0:3ac96e360672 465 0,
charlesmn 0:3ac96e360672 466 0);
charlesmn 0:3ac96e360672 467 pdata->nvm__laser_safety_clip_ll =
charlesmn 0:3ac96e360672 468 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 469 1,
charlesmn 0:3ac96e360672 470 pbuffer + VL53L1_NVM__LASER_SAFETY__CLIP_LL,
charlesmn 0:3ac96e360672 471 0x0000003F,
charlesmn 0:3ac96e360672 472 0,
charlesmn 0:3ac96e360672 473 0);
charlesmn 0:3ac96e360672 474 pdata->nvm__laser_safety_vcsel_trim_ld =
charlesmn 0:3ac96e360672 475 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 476 1,
charlesmn 0:3ac96e360672 477 pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_TRIM_LD,
charlesmn 0:3ac96e360672 478 0x00000007,
charlesmn 0:3ac96e360672 479 0,
charlesmn 0:3ac96e360672 480 0);
charlesmn 0:3ac96e360672 481 pdata->nvm__laser_safety_vcsel_selion_ld =
charlesmn 0:3ac96e360672 482 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 483 1,
charlesmn 0:3ac96e360672 484 pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_LD,
charlesmn 0:3ac96e360672 485 0x0000003F,
charlesmn 0:3ac96e360672 486 0,
charlesmn 0:3ac96e360672 487 0);
charlesmn 0:3ac96e360672 488 pdata->nvm__laser_safety_vcsel_selion_max_ld =
charlesmn 0:3ac96e360672 489 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 490 1,
charlesmn 0:3ac96e360672 491 pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_MAX_LD,
charlesmn 0:3ac96e360672 492 0x0000003F,
charlesmn 0:3ac96e360672 493 0,
charlesmn 0:3ac96e360672 494 0);
charlesmn 0:3ac96e360672 495 pdata->nvm__laser_safety_mult_ld =
charlesmn 0:3ac96e360672 496 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 497 1,
charlesmn 0:3ac96e360672 498 pbuffer + VL53L1_NVM__LASER_SAFETY__MULT_LD,
charlesmn 0:3ac96e360672 499 0x0000003F,
charlesmn 0:3ac96e360672 500 0,
charlesmn 0:3ac96e360672 501 0);
charlesmn 0:3ac96e360672 502 pdata->nvm__laser_safety_clip_ld =
charlesmn 0:3ac96e360672 503 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 504 1,
charlesmn 0:3ac96e360672 505 pbuffer + VL53L1_NVM__LASER_SAFETY__CLIP_LD,
charlesmn 0:3ac96e360672 506 0x0000003F,
charlesmn 0:3ac96e360672 507 0,
charlesmn 0:3ac96e360672 508 0);
charlesmn 0:3ac96e360672 509 pdata->nvm__laser_safety_lock_byte =
charlesmn 0:3ac96e360672 510 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 511 1,
charlesmn 0:3ac96e360672 512 pbuffer + VL53L1_NVM__LASER_SAFETY_LOCK_BYTE,
charlesmn 0:3ac96e360672 513 0x000000FF,
charlesmn 0:3ac96e360672 514 0,
charlesmn 0:3ac96e360672 515 0);
charlesmn 0:3ac96e360672 516 pdata->nvm__laser_safety_unlock_byte =
charlesmn 0:3ac96e360672 517 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 518 1,
charlesmn 0:3ac96e360672 519 pbuffer + VL53L1_NVM__LASER_SAFETY_UNLOCK_BYTE,
charlesmn 0:3ac96e360672 520 0x000000FF,
charlesmn 0:3ac96e360672 521 0,
charlesmn 0:3ac96e360672 522 0);
charlesmn 0:3ac96e360672 523
charlesmn 0:3ac96e360672 524
charlesmn 0:3ac96e360672 525
charlesmn 0:3ac96e360672 526 ptmp = pbuffer + VL53L1_NVM__EWS__SPAD_ENABLES_RTN_0_;
charlesmn 0:3ac96e360672 527 for (i = 0 ; i < VL53L1_RTN_SPAD_BUFFER_SIZE ; i++)
charlesmn 0:3ac96e360672 528 pdata->nvm__ews__spad_enables_rtn[i] = *ptmp++;
charlesmn 0:3ac96e360672 529
charlesmn 0:3ac96e360672 530 ptmp = pbuffer + VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_0_;
charlesmn 0:3ac96e360672 531 for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
charlesmn 0:3ac96e360672 532 pdata->nvm__ews__spad_enables_ref__loc1[i] = *ptmp++;
charlesmn 0:3ac96e360672 533
charlesmn 0:3ac96e360672 534 ptmp = pbuffer + VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_0_;
charlesmn 0:3ac96e360672 535 for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
charlesmn 0:3ac96e360672 536 pdata->nvm__ews__spad_enables_ref__loc2[i] = *ptmp++;
charlesmn 0:3ac96e360672 537
charlesmn 0:3ac96e360672 538 ptmp = pbuffer + VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_0_;
charlesmn 0:3ac96e360672 539 for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
charlesmn 0:3ac96e360672 540 pdata->nvm__ews__spad_enables_ref__loc3[i] = *ptmp++;
charlesmn 0:3ac96e360672 541
charlesmn 0:3ac96e360672 542
charlesmn 0:3ac96e360672 543
charlesmn 0:3ac96e360672 544 ptmp = pbuffer + VL53L1_NVM__FMT__SPAD_ENABLES_RTN_0_;
charlesmn 0:3ac96e360672 545 for (i = 0 ; i < VL53L1_RTN_SPAD_BUFFER_SIZE ; i++)
charlesmn 0:3ac96e360672 546 pdata->nvm__fmt__spad_enables_rtn[i] = *ptmp++;
charlesmn 0:3ac96e360672 547
charlesmn 0:3ac96e360672 548 ptmp = pbuffer + VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_0_;
charlesmn 0:3ac96e360672 549 for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
charlesmn 0:3ac96e360672 550 pdata->nvm__fmt__spad_enables_ref__loc1[i] = *ptmp++;
charlesmn 0:3ac96e360672 551
charlesmn 0:3ac96e360672 552 ptmp = pbuffer + VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_0_;
charlesmn 0:3ac96e360672 553 for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
charlesmn 0:3ac96e360672 554 pdata->nvm__fmt__spad_enables_ref__loc2[i] = *ptmp++;
charlesmn 0:3ac96e360672 555
charlesmn 0:3ac96e360672 556 ptmp = pbuffer + VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_0_;
charlesmn 0:3ac96e360672 557 for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
charlesmn 0:3ac96e360672 558 pdata->nvm__fmt__spad_enables_ref__loc3[i] = *ptmp++;
charlesmn 0:3ac96e360672 559
charlesmn 0:3ac96e360672 560
charlesmn 0:3ac96e360672 561 pdata->nvm__fmt__roi_config__mode_roi_centre_spad =
charlesmn 0:3ac96e360672 562 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 563 1,
charlesmn 0:3ac96e360672 564 pbuffer +
charlesmn 0:3ac96e360672 565 VL53L1_NVM__FMT__ROI_CONFIG__MODE_ROI_CENTRE_SPAD,
charlesmn 0:3ac96e360672 566 0x000000FF,
charlesmn 0:3ac96e360672 567 0,
charlesmn 0:3ac96e360672 568 0);
charlesmn 0:3ac96e360672 569 pdata->nvm__fmt__roi_config__mode_roi_x_size =
charlesmn 0:3ac96e360672 570 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 571 1,
charlesmn 0:3ac96e360672 572 pbuffer +
charlesmn 0:3ac96e360672 573 VL53L1_NVM__FMT__ROI_CONFIG__MODE_ROI_XY_SIZE,
charlesmn 0:3ac96e360672 574 0x000000F0,
charlesmn 0:3ac96e360672 575 4,
charlesmn 0:3ac96e360672 576 0);
charlesmn 0:3ac96e360672 577 pdata->nvm__fmt__roi_config__mode_roi_y_size =
charlesmn 0:3ac96e360672 578 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 579 1,
charlesmn 0:3ac96e360672 580 pbuffer + VL53L1_NVM__FMT__ROI_CONFIG__MODE_ROI_XY_SIZE,
charlesmn 0:3ac96e360672 581 0x0000000F,
charlesmn 0:3ac96e360672 582 0,
charlesmn 0:3ac96e360672 583 0);
charlesmn 0:3ac96e360672 584 pdata->nvm__fmt__ref_spad_apply__num_requested_ref_spad =
charlesmn 0:3ac96e360672 585 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 586 1,
charlesmn 0:3ac96e360672 587 pbuffer +
charlesmn 0:3ac96e360672 588 VL53L1_NVM__FMT__REF_SPAD_APPLY__NUM_REQUESTED_REF_SPAD,
charlesmn 0:3ac96e360672 589 0x000000FF,
charlesmn 0:3ac96e360672 590 0,
charlesmn 0:3ac96e360672 591 0);
charlesmn 0:3ac96e360672 592 pdata->nvm__fmt__ref_spad_man__ref_location =
charlesmn 0:3ac96e360672 593 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 594 1,
charlesmn 0:3ac96e360672 595 pbuffer + VL53L1_NVM__FMT__REF_SPAD_MAN__REF_LOCATION,
charlesmn 0:3ac96e360672 596 0x00000003,
charlesmn 0:3ac96e360672 597 0,
charlesmn 0:3ac96e360672 598 0);
charlesmn 0:3ac96e360672 599 pdata->nvm__fmt__mm_config__inner_offset_mm =
charlesmn 0:3ac96e360672 600 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 601 2,
charlesmn 0:3ac96e360672 602 pbuffer + VL53L1_NVM__FMT__MM_CONFIG__INNER_OFFSET_MM,
charlesmn 0:3ac96e360672 603 0x0000FFFF,
charlesmn 0:3ac96e360672 604 0,
charlesmn 0:3ac96e360672 605 0);
charlesmn 0:3ac96e360672 606 pdata->nvm__fmt__mm_config__outer_offset_mm =
charlesmn 0:3ac96e360672 607 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 608 2,
charlesmn 0:3ac96e360672 609 pbuffer + VL53L1_NVM__FMT__MM_CONFIG__OUTER_OFFSET_MM,
charlesmn 0:3ac96e360672 610 0x0000FFFF,
charlesmn 0:3ac96e360672 611 0,
charlesmn 0:3ac96e360672 612 0);
charlesmn 0:3ac96e360672 613 pdata->nvm__fmt__algo_part_to_part_range_offset_mm =
charlesmn 0:3ac96e360672 614 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 615 2,
charlesmn 0:3ac96e360672 616 pbuffer +
charlesmn 0:3ac96e360672 617 VL53L1_NVM__FMT__ALGO__PART_TO_PART_RANGE_OFFSET_MM,
charlesmn 0:3ac96e360672 618 0x00000FFF,
charlesmn 0:3ac96e360672 619 0,
charlesmn 0:3ac96e360672 620 0);
charlesmn 0:3ac96e360672 621 pdata->nvm__fmt__algo__crosstalk_compensation_plane_offset_kcps =
charlesmn 0:3ac96e360672 622 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 623 2,
charlesmn 0:3ac96e360672 624 pbuffer +
charlesmn 0:3ac96e360672 625 VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS,
charlesmn 0:3ac96e360672 626 0x0000FFFF,
charlesmn 0:3ac96e360672 627 0,
charlesmn 0:3ac96e360672 628 0);
charlesmn 0:3ac96e360672 629 pdata->nvm__fmt__algo__crosstalk_compensation_x_plane_gradient_kcps =
charlesmn 0:3ac96e360672 630 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 631 2,
charlesmn 0:3ac96e360672 632 pbuffer +
charlesmn 0:3ac96e360672 633 VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS,
charlesmn 0:3ac96e360672 634 0x0000FFFF,
charlesmn 0:3ac96e360672 635 0,
charlesmn 0:3ac96e360672 636 0);
charlesmn 0:3ac96e360672 637 pdata->nvm__fmt__algo__crosstalk_compensation_y_plane_gradient_kcps =
charlesmn 0:3ac96e360672 638 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 639 2,
charlesmn 0:3ac96e360672 640 pbuffer +
charlesmn 0:3ac96e360672 641 VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS,
charlesmn 0:3ac96e360672 642 0x0000FFFF,
charlesmn 0:3ac96e360672 643 0,
charlesmn 0:3ac96e360672 644 0);
charlesmn 0:3ac96e360672 645 pdata->nvm__fmt__spare__host_config__nvm_config_spare_0 =
charlesmn 0:3ac96e360672 646 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 647 1,
charlesmn 0:3ac96e360672 648 pbuffer +
charlesmn 0:3ac96e360672 649 VL53L1_NVM__FMT__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_0,
charlesmn 0:3ac96e360672 650 0x000000FF,
charlesmn 0:3ac96e360672 651 0,
charlesmn 0:3ac96e360672 652 0);
charlesmn 0:3ac96e360672 653 pdata->nvm__fmt__spare__host_config__nvm_config_spare_1 =
charlesmn 0:3ac96e360672 654 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 655 1,
charlesmn 0:3ac96e360672 656 pbuffer +
charlesmn 0:3ac96e360672 657 VL53L1_NVM__FMT__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_1,
charlesmn 0:3ac96e360672 658 0x000000FF,
charlesmn 0:3ac96e360672 659 0,
charlesmn 0:3ac96e360672 660 0);
charlesmn 0:3ac96e360672 661 pdata->nvm__customer_space_programmed =
charlesmn 0:3ac96e360672 662 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 663 1,
charlesmn 0:3ac96e360672 664 pbuffer + VL53L1_NVM__CUSTOMER_NVM_SPACE_PROGRAMMED,
charlesmn 0:3ac96e360672 665 0x000000FF,
charlesmn 0:3ac96e360672 666 0,
charlesmn 0:3ac96e360672 667 0);
charlesmn 0:3ac96e360672 668 pdata->nvm__cust__i2c_device_address =
charlesmn 0:3ac96e360672 669 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 670 1,
charlesmn 0:3ac96e360672 671 pbuffer + VL53L1_NVM__CUST__I2C_SLAVE__DEVICE_ADDRESS,
charlesmn 0:3ac96e360672 672 0x000000FF,
charlesmn 0:3ac96e360672 673 0,
charlesmn 0:3ac96e360672 674 0);
charlesmn 0:3ac96e360672 675 pdata->nvm__cust__ref_spad_apply__num_requested_ref_spad =
charlesmn 0:3ac96e360672 676 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 677 1,
charlesmn 0:3ac96e360672 678 pbuffer +
charlesmn 0:3ac96e360672 679 VL53L1_NVM__CUST__REF_SPAD_APPLY__NUM_REQUESTED_REF_SPAD,
charlesmn 0:3ac96e360672 680 0x000000FF,
charlesmn 0:3ac96e360672 681 0,
charlesmn 0:3ac96e360672 682 0);
charlesmn 0:3ac96e360672 683 pdata->nvm__cust__ref_spad_man__ref_location =
charlesmn 0:3ac96e360672 684 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 685 1,
charlesmn 0:3ac96e360672 686 pbuffer + VL53L1_NVM__CUST__REF_SPAD_MAN__REF_LOCATION,
charlesmn 0:3ac96e360672 687 0x00000003,
charlesmn 0:3ac96e360672 688 0,
charlesmn 0:3ac96e360672 689 0);
charlesmn 0:3ac96e360672 690 pdata->nvm__cust__mm_config__inner_offset_mm =
charlesmn 0:3ac96e360672 691 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 692 2,
charlesmn 0:3ac96e360672 693 pbuffer + VL53L1_NVM__CUST__MM_CONFIG__INNER_OFFSET_MM,
charlesmn 0:3ac96e360672 694 0x0000FFFF,
charlesmn 0:3ac96e360672 695 0,
charlesmn 0:3ac96e360672 696 0);
charlesmn 0:3ac96e360672 697 pdata->nvm__cust__mm_config__outer_offset_mm =
charlesmn 0:3ac96e360672 698 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 699 2,
charlesmn 0:3ac96e360672 700 pbuffer + VL53L1_NVM__CUST__MM_CONFIG__OUTER_OFFSET_MM,
charlesmn 0:3ac96e360672 701 0x0000FFFF,
charlesmn 0:3ac96e360672 702 0,
charlesmn 0:3ac96e360672 703 0);
charlesmn 0:3ac96e360672 704 pdata->nvm__cust__algo_part_to_part_range_offset_mm =
charlesmn 0:3ac96e360672 705 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 706 2,
charlesmn 0:3ac96e360672 707 pbuffer +
charlesmn 0:3ac96e360672 708 VL53L1_NVM__CUST__ALGO__PART_TO_PART_RANGE_OFFSET_MM,
charlesmn 0:3ac96e360672 709 0x00000FFF,
charlesmn 0:3ac96e360672 710 0,
charlesmn 0:3ac96e360672 711 0);
charlesmn 0:3ac96e360672 712 pdata->nvm__cust__algo__crosstalk_compensation_plane_offset_kcps =
charlesmn 0:3ac96e360672 713 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 714 2,
charlesmn 0:3ac96e360672 715 pbuffer +
charlesmn 0:3ac96e360672 716 VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS,
charlesmn 0:3ac96e360672 717 0x0000FFFF,
charlesmn 0:3ac96e360672 718 0,
charlesmn 0:3ac96e360672 719 0);
charlesmn 0:3ac96e360672 720 pdata->nvm__cust__algo__crosstalk_compensation_x_plane_gradient_kcps =
charlesmn 0:3ac96e360672 721 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 722 2,
charlesmn 0:3ac96e360672 723 pbuffer +
charlesmn 0:3ac96e360672 724 VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS,
charlesmn 0:3ac96e360672 725 0x0000FFFF,
charlesmn 0:3ac96e360672 726 0,
charlesmn 0:3ac96e360672 727 0);
charlesmn 0:3ac96e360672 728 pdata->nvm__cust__algo__crosstalk_compensation_y_plane_gradient_kcps =
charlesmn 0:3ac96e360672 729 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 730 2,
charlesmn 0:3ac96e360672 731 pbuffer +
charlesmn 0:3ac96e360672 732 VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS,
charlesmn 0:3ac96e360672 733 0x0000FFFF,
charlesmn 0:3ac96e360672 734 0,
charlesmn 0:3ac96e360672 735 0);
charlesmn 0:3ac96e360672 736 pdata->nvm__cust__spare__host_config__nvm_config_spare_0 =
charlesmn 0:3ac96e360672 737 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 738 1,
charlesmn 0:3ac96e360672 739 pbuffer + VL53L1_NVM__CUST__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_0,
charlesmn 0:3ac96e360672 740 0x000000FF,
charlesmn 0:3ac96e360672 741 0,
charlesmn 0:3ac96e360672 742 0);
charlesmn 0:3ac96e360672 743 pdata->nvm__cust__spare__host_config__nvm_config_spare_1 =
charlesmn 0:3ac96e360672 744 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 745 1,
charlesmn 0:3ac96e360672 746 pbuffer +
charlesmn 0:3ac96e360672 747 VL53L1_NVM__CUST__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_1,
charlesmn 0:3ac96e360672 748 0x000000FF,
charlesmn 0:3ac96e360672 749 0,
charlesmn 0:3ac96e360672 750 0);
charlesmn 0:3ac96e360672 751
charlesmn 0:3ac96e360672 752
charlesmn 0:3ac96e360672 753
charlesmn 0:3ac96e360672 754 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 755 status =
charlesmn 0:3ac96e360672 756 VL53L1_nvm_decode_optical_centre(
charlesmn 0:3ac96e360672 757 buf_size,
charlesmn 0:3ac96e360672 758 pbuffer + VL53L1_NVM__FMT__OPTICAL_CENTRE_DATA_INDEX,
charlesmn 0:3ac96e360672 759 &(pdata->fmt_optical_centre));
charlesmn 0:3ac96e360672 760
charlesmn 0:3ac96e360672 761
charlesmn 0:3ac96e360672 762
charlesmn 0:3ac96e360672 763 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 764 status =
charlesmn 0:3ac96e360672 765 VL53L1_nvm_decode_cal_peak_rate_map(
charlesmn 0:3ac96e360672 766 buf_size,
charlesmn 0:3ac96e360672 767 pbuffer + VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_INDEX,
charlesmn 0:3ac96e360672 768 &(pdata->fmt_peak_rate_map));
charlesmn 0:3ac96e360672 769
charlesmn 0:3ac96e360672 770
charlesmn 0:3ac96e360672 771
charlesmn 0:3ac96e360672 772 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 773 status =
charlesmn 0:3ac96e360672 774 VL53L1_nvm_decode_additional_offset_cal_data(
charlesmn 0:3ac96e360672 775 buf_size,
charlesmn 0:3ac96e360672 776 pbuffer +
charlesmn 0:3ac96e360672 777 VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_INDEX,
charlesmn 0:3ac96e360672 778 &(pdata->fmt_add_offset_data));
charlesmn 0:3ac96e360672 779
charlesmn 0:3ac96e360672 780
charlesmn 0:3ac96e360672 781
charlesmn 0:3ac96e360672 782 pptmp[0] = VL53L1_NVM__FMT__RANGE_RESULTS__140MM_MM_PRE_RANGE;
charlesmn 0:3ac96e360672 783 pptmp[1] = VL53L1_NVM__FMT__RANGE_RESULTS__140MM_DARK;
charlesmn 0:3ac96e360672 784 pptmp[2] = VL53L1_NVM__FMT__RANGE_RESULTS__400MM_DARK;
charlesmn 0:3ac96e360672 785 pptmp[3] = VL53L1_NVM__FMT__RANGE_RESULTS__400MM_AMBIENT;
charlesmn 0:3ac96e360672 786
charlesmn 0:3ac96e360672 787 for (i = 0 ; i < VL53L1_NVM_MAX_FMT_RANGE_DATA ; i++) {
charlesmn 0:3ac96e360672 788 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 789 status =
charlesmn 0:3ac96e360672 790 VL53L1_nvm_decode_fmt_range_results_data(
charlesmn 0:3ac96e360672 791 buf_size,
charlesmn 0:3ac96e360672 792 pbuffer + pptmp[i],
charlesmn 0:3ac96e360672 793 &(pdata->fmt_range_data[i]));
charlesmn 0:3ac96e360672 794 }
charlesmn 0:3ac96e360672 795
charlesmn 0:3ac96e360672 796
charlesmn 0:3ac96e360672 797 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 798 status =
charlesmn 0:3ac96e360672 799 VL53L1_nvm_decode_fmt_info(
charlesmn 0:3ac96e360672 800 buf_size,
charlesmn 0:3ac96e360672 801 pbuffer,
charlesmn 0:3ac96e360672 802 &(pdata->fmt_info));
charlesmn 0:3ac96e360672 803
charlesmn 0:3ac96e360672 804 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 805 status =
charlesmn 0:3ac96e360672 806 VL53L1_nvm_decode_ews_info(
charlesmn 0:3ac96e360672 807 buf_size,
charlesmn 0:3ac96e360672 808 pbuffer,
charlesmn 0:3ac96e360672 809 &(pdata->ews_info));
charlesmn 0:3ac96e360672 810
charlesmn 0:3ac96e360672 811 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 812
charlesmn 0:3ac96e360672 813 return status;
charlesmn 0:3ac96e360672 814
charlesmn 0:3ac96e360672 815 }
charlesmn 0:3ac96e360672 816
charlesmn 0:3ac96e360672 817
charlesmn 0:3ac96e360672 818 VL53L1_Error VL53L1_nvm_decode_optical_centre(
charlesmn 0:3ac96e360672 819 uint16_t buf_size,
charlesmn 0:3ac96e360672 820 uint8_t *pbuffer,
charlesmn 0:3ac96e360672 821 VL53L1_optical_centre_t *pdata)
charlesmn 0:3ac96e360672 822 {
charlesmn 0:3ac96e360672 823
charlesmn 0:3ac96e360672 824 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 825
charlesmn 0:3ac96e360672 826 uint16_t tmp = 0;
charlesmn 0:3ac96e360672 827
charlesmn 0:3ac96e360672 828 if (buf_size < VL53L1_NVM__FMT__OPTICAL_CENTRE_DATA_SIZE)
charlesmn 0:3ac96e360672 829 return VL53L1_ERROR_BUFFER_TOO_SMALL;
charlesmn 0:3ac96e360672 830
charlesmn 0:3ac96e360672 831
charlesmn 0:3ac96e360672 832 tmp = 0x0100;
charlesmn 0:3ac96e360672 833 tmp -= (uint16_t)*(pbuffer + 2);
charlesmn 0:3ac96e360672 834 if (tmp > 0x0FF)
charlesmn 0:3ac96e360672 835 tmp = 0;
charlesmn 0:3ac96e360672 836
charlesmn 0:3ac96e360672 837 pdata->x_centre = (uint8_t)tmp;
charlesmn 0:3ac96e360672 838 pdata->y_centre = *(pbuffer + 3);
charlesmn 0:3ac96e360672 839
charlesmn 0:3ac96e360672 840 return status;
charlesmn 0:3ac96e360672 841 }
charlesmn 0:3ac96e360672 842
charlesmn 0:3ac96e360672 843
charlesmn 0:3ac96e360672 844 VL53L1_Error VL53L1_nvm_decode_cal_peak_rate_map(
charlesmn 0:3ac96e360672 845 uint16_t buf_size,
charlesmn 0:3ac96e360672 846 uint8_t *pbuffer,
charlesmn 0:3ac96e360672 847 VL53L1_cal_peak_rate_map_t *pdata)
charlesmn 0:3ac96e360672 848 {
charlesmn 0:3ac96e360672 849
charlesmn 0:3ac96e360672 850 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 851
charlesmn 0:3ac96e360672 852 uint8_t *ptmp = NULL;
charlesmn 0:3ac96e360672 853 uint8_t i = 0;
charlesmn 0:3ac96e360672 854
charlesmn 0:3ac96e360672 855 if (buf_size < VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_SIZE)
charlesmn 0:3ac96e360672 856 return VL53L1_ERROR_BUFFER_TOO_SMALL;
charlesmn 0:3ac96e360672 857
charlesmn 0:3ac96e360672 858 pdata->cal_distance_mm =
charlesmn 0:3ac96e360672 859 (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer);
charlesmn 0:3ac96e360672 860
charlesmn 0:3ac96e360672 861 pdata->cal_reflectance_pc =
charlesmn 0:3ac96e360672 862 (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 2);
charlesmn 0:3ac96e360672 863 pdata->cal_reflectance_pc =
charlesmn 0:3ac96e360672 864 pdata->cal_reflectance_pc >> 6;
charlesmn 0:3ac96e360672 865
charlesmn 0:3ac96e360672 866 pdata->max_samples = VL53L1_NVM_PEAK_RATE_MAP_SAMPLES;
charlesmn 0:3ac96e360672 867 pdata->width = VL53L1_NVM_PEAK_RATE_MAP_WIDTH;
charlesmn 0:3ac96e360672 868 pdata->height = VL53L1_NVM_PEAK_RATE_MAP_HEIGHT;
charlesmn 0:3ac96e360672 869
charlesmn 0:3ac96e360672 870 ptmp = pbuffer + 4;
charlesmn 0:3ac96e360672 871 for (i = 0 ; i < VL53L1_NVM_PEAK_RATE_MAP_SAMPLES ; i++) {
charlesmn 0:3ac96e360672 872 pdata->peak_rate_mcps[i] =
charlesmn 0:3ac96e360672 873 (uint16_t)VL53L1_i2c_decode_uint16_t(2, ptmp);
charlesmn 0:3ac96e360672 874 ptmp += 2;
charlesmn 0:3ac96e360672 875 }
charlesmn 0:3ac96e360672 876
charlesmn 0:3ac96e360672 877 return status;
charlesmn 0:3ac96e360672 878 }
charlesmn 0:3ac96e360672 879
charlesmn 0:3ac96e360672 880
charlesmn 0:3ac96e360672 881 VL53L1_Error VL53L1_nvm_decode_additional_offset_cal_data(
charlesmn 0:3ac96e360672 882 uint16_t buf_size,
charlesmn 0:3ac96e360672 883 uint8_t *pbuffer,
charlesmn 0:3ac96e360672 884 VL53L1_additional_offset_cal_data_t *pdata)
charlesmn 0:3ac96e360672 885 {
charlesmn 0:3ac96e360672 886
charlesmn 0:3ac96e360672 887 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 888
charlesmn 0:3ac96e360672 889 if (buf_size < VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_SIZE)
charlesmn 0:3ac96e360672 890 return VL53L1_ERROR_BUFFER_TOO_SMALL;
charlesmn 0:3ac96e360672 891
charlesmn 0:3ac96e360672 892 pdata->result__mm_inner_actual_effective_spads =
charlesmn 0:3ac96e360672 893 (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer);
charlesmn 0:3ac96e360672 894
charlesmn 0:3ac96e360672 895 pdata->result__mm_outer_actual_effective_spads =
charlesmn 0:3ac96e360672 896 (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 2);
charlesmn 0:3ac96e360672 897
charlesmn 0:3ac96e360672 898 pdata->result__mm_inner_peak_signal_count_rtn_mcps =
charlesmn 0:3ac96e360672 899 (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 4);
charlesmn 0:3ac96e360672 900
charlesmn 0:3ac96e360672 901 pdata->result__mm_outer_peak_signal_count_rtn_mcps =
charlesmn 0:3ac96e360672 902 (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 6);
charlesmn 0:3ac96e360672 903
charlesmn 0:3ac96e360672 904 return status;
charlesmn 0:3ac96e360672 905 }
charlesmn 0:3ac96e360672 906
charlesmn 0:3ac96e360672 907
charlesmn 0:3ac96e360672 908 VL53L1_Error VL53L1_nvm_decode_fmt_range_results_data(
charlesmn 0:3ac96e360672 909 uint16_t buf_size,
charlesmn 0:3ac96e360672 910 uint8_t *pbuffer,
charlesmn 0:3ac96e360672 911 VL53L1_decoded_nvm_fmt_range_data_t *pdata)
charlesmn 0:3ac96e360672 912 {
charlesmn 0:3ac96e360672 913
charlesmn 0:3ac96e360672 914 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 915
charlesmn 0:3ac96e360672 916 if (buf_size < VL53L1_NVM__FMT__RANGE_RESULTS__SIZE_BYTES)
charlesmn 0:3ac96e360672 917 return VL53L1_ERROR_BUFFER_TOO_SMALL;
charlesmn 0:3ac96e360672 918
charlesmn 0:3ac96e360672 919 pdata->result__actual_effective_rtn_spads =
charlesmn 0:3ac96e360672 920 (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer);
charlesmn 0:3ac96e360672 921
charlesmn 0:3ac96e360672 922 pdata->ref_spad_array__num_requested_ref_spads =
charlesmn 0:3ac96e360672 923 *(pbuffer+2);
charlesmn 0:3ac96e360672 924
charlesmn 0:3ac96e360672 925 pdata->ref_spad_array__ref_location =
charlesmn 0:3ac96e360672 926 *(pbuffer+3);
charlesmn 0:3ac96e360672 927
charlesmn 0:3ac96e360672 928 pdata->result__peak_signal_count_rate_rtn_mcps =
charlesmn 0:3ac96e360672 929 (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 4);
charlesmn 0:3ac96e360672 930
charlesmn 0:3ac96e360672 931 pdata->result__ambient_count_rate_rtn_mcps =
charlesmn 0:3ac96e360672 932 (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 6);
charlesmn 0:3ac96e360672 933
charlesmn 0:3ac96e360672 934 pdata->result__peak_signal_count_rate_ref_mcps =
charlesmn 0:3ac96e360672 935 (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 8);
charlesmn 0:3ac96e360672 936
charlesmn 0:3ac96e360672 937 pdata->result__ambient_count_rate_ref_mcps =
charlesmn 0:3ac96e360672 938 (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 10);
charlesmn 0:3ac96e360672 939
charlesmn 0:3ac96e360672 940 pdata->measured_distance_mm =
charlesmn 0:3ac96e360672 941 (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 12);
charlesmn 0:3ac96e360672 942
charlesmn 0:3ac96e360672 943 pdata->measured_distance_stdev_mm =
charlesmn 0:3ac96e360672 944 (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 14);
charlesmn 0:3ac96e360672 945
charlesmn 0:3ac96e360672 946 return status;
charlesmn 0:3ac96e360672 947 }
charlesmn 0:3ac96e360672 948
charlesmn 0:3ac96e360672 949
charlesmn 0:3ac96e360672 950 VL53L1_Error VL53L1_nvm_decode_fmt_info(
charlesmn 0:3ac96e360672 951 uint16_t buf_size,
charlesmn 0:3ac96e360672 952 uint8_t *pbuffer,
charlesmn 0:3ac96e360672 953 VL53L1_decoded_nvm_fmt_info_t *pdata)
charlesmn 0:3ac96e360672 954 {
charlesmn 0:3ac96e360672 955
charlesmn 0:3ac96e360672 956 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 957
charlesmn 0:3ac96e360672 958 if (buf_size < VL53L1_NVM_SIZE_IN_BYTES)
charlesmn 0:3ac96e360672 959 return VL53L1_ERROR_BUFFER_TOO_SMALL;
charlesmn 0:3ac96e360672 960
charlesmn 0:3ac96e360672 961 pdata->nvm__fmt__fgc[0] =
charlesmn 0:3ac96e360672 962 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 963 1,
charlesmn 0:3ac96e360672 964 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_0,
charlesmn 0:3ac96e360672 965 0x000000FE,
charlesmn 0:3ac96e360672 966 1,
charlesmn 0:3ac96e360672 967 0);
charlesmn 0:3ac96e360672 968 pdata->nvm__fmt__fgc[1] =
charlesmn 0:3ac96e360672 969 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 970 1,
charlesmn 0:3ac96e360672 971 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_1,
charlesmn 0:3ac96e360672 972 0x000001FC,
charlesmn 0:3ac96e360672 973 2,
charlesmn 0:3ac96e360672 974 0);
charlesmn 0:3ac96e360672 975 pdata->nvm__fmt__fgc[2] =
charlesmn 0:3ac96e360672 976 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 977 1,
charlesmn 0:3ac96e360672 978 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_2 - 1,
charlesmn 0:3ac96e360672 979 0x000003F8,
charlesmn 0:3ac96e360672 980 3,
charlesmn 0:3ac96e360672 981 0);
charlesmn 0:3ac96e360672 982 pdata->nvm__fmt__fgc[3] =
charlesmn 0:3ac96e360672 983 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 984 1,
charlesmn 0:3ac96e360672 985 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_3 - 1,
charlesmn 0:3ac96e360672 986 0x000007F0,
charlesmn 0:3ac96e360672 987 4,
charlesmn 0:3ac96e360672 988 0);
charlesmn 0:3ac96e360672 989 pdata->nvm__fmt__fgc[4] =
charlesmn 0:3ac96e360672 990 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 991 1,
charlesmn 0:3ac96e360672 992 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_4 - 1,
charlesmn 0:3ac96e360672 993 0x00000FE0,
charlesmn 0:3ac96e360672 994 5,
charlesmn 0:3ac96e360672 995 0);
charlesmn 0:3ac96e360672 996 pdata->nvm__fmt__fgc[5] =
charlesmn 0:3ac96e360672 997 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 998 1,
charlesmn 0:3ac96e360672 999 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_5 - 1,
charlesmn 0:3ac96e360672 1000 0x00001FC0,
charlesmn 0:3ac96e360672 1001 6,
charlesmn 0:3ac96e360672 1002 0);
charlesmn 0:3ac96e360672 1003 pdata->nvm__fmt__fgc[6] =
charlesmn 0:3ac96e360672 1004 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1005 1,
charlesmn 0:3ac96e360672 1006 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_6 - 1,
charlesmn 0:3ac96e360672 1007 0x00003F80,
charlesmn 0:3ac96e360672 1008 7,
charlesmn 0:3ac96e360672 1009 0);
charlesmn 0:3ac96e360672 1010 pdata->nvm__fmt__fgc[7] =
charlesmn 0:3ac96e360672 1011 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1012 1,
charlesmn 0:3ac96e360672 1013 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_6,
charlesmn 0:3ac96e360672 1014 0x0000007F,
charlesmn 0:3ac96e360672 1015 0,
charlesmn 0:3ac96e360672 1016 0);
charlesmn 0:3ac96e360672 1017 pdata->nvm__fmt__fgc[8] =
charlesmn 0:3ac96e360672 1018 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1019 1,
charlesmn 0:3ac96e360672 1020 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_7,
charlesmn 0:3ac96e360672 1021 0x000000FE,
charlesmn 0:3ac96e360672 1022 1,
charlesmn 0:3ac96e360672 1023 0);
charlesmn 0:3ac96e360672 1024 pdata->nvm__fmt__fgc[9] =
charlesmn 0:3ac96e360672 1025 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1026 1,
charlesmn 0:3ac96e360672 1027 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_8,
charlesmn 0:3ac96e360672 1028 0x000001FC,
charlesmn 0:3ac96e360672 1029 2,
charlesmn 0:3ac96e360672 1030 0);
charlesmn 0:3ac96e360672 1031 pdata->nvm__fmt__fgc[10] =
charlesmn 0:3ac96e360672 1032 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1033 1,
charlesmn 0:3ac96e360672 1034 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_9 - 1,
charlesmn 0:3ac96e360672 1035 0x000003F8,
charlesmn 0:3ac96e360672 1036 3,
charlesmn 0:3ac96e360672 1037 0);
charlesmn 0:3ac96e360672 1038 pdata->nvm__fmt__fgc[11] =
charlesmn 0:3ac96e360672 1039 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1040 1,
charlesmn 0:3ac96e360672 1041 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_10 - 1,
charlesmn 0:3ac96e360672 1042 0x000007F0,
charlesmn 0:3ac96e360672 1043 4,
charlesmn 0:3ac96e360672 1044 0);
charlesmn 0:3ac96e360672 1045 pdata->nvm__fmt__fgc[12] =
charlesmn 0:3ac96e360672 1046 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1047 1,
charlesmn 0:3ac96e360672 1048 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_11 - 1,
charlesmn 0:3ac96e360672 1049 0x00000FE0,
charlesmn 0:3ac96e360672 1050 5,
charlesmn 0:3ac96e360672 1051 0);
charlesmn 0:3ac96e360672 1052 pdata->nvm__fmt__fgc[13] =
charlesmn 0:3ac96e360672 1053 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1054 1,
charlesmn 0:3ac96e360672 1055 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_12 - 1,
charlesmn 0:3ac96e360672 1056 0x00001FC0,
charlesmn 0:3ac96e360672 1057 6,
charlesmn 0:3ac96e360672 1058 0);
charlesmn 0:3ac96e360672 1059 pdata->nvm__fmt__fgc[14] =
charlesmn 0:3ac96e360672 1060 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1061 1,
charlesmn 0:3ac96e360672 1062 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_13 - 1,
charlesmn 0:3ac96e360672 1063 0x00003F80,
charlesmn 0:3ac96e360672 1064 7,
charlesmn 0:3ac96e360672 1065 0);
charlesmn 0:3ac96e360672 1066 pdata->nvm__fmt__fgc[15] =
charlesmn 0:3ac96e360672 1067 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1068 1,
charlesmn 0:3ac96e360672 1069 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_13,
charlesmn 0:3ac96e360672 1070 0x0000007F,
charlesmn 0:3ac96e360672 1071 0,
charlesmn 0:3ac96e360672 1072 0);
charlesmn 0:3ac96e360672 1073 pdata->nvm__fmt__fgc[16] =
charlesmn 0:3ac96e360672 1074 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1075 1,
charlesmn 0:3ac96e360672 1076 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_14,
charlesmn 0:3ac96e360672 1077 0x000000FE,
charlesmn 0:3ac96e360672 1078 1,
charlesmn 0:3ac96e360672 1079 0);
charlesmn 0:3ac96e360672 1080 pdata->nvm__fmt__fgc[17] =
charlesmn 0:3ac96e360672 1081 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1082 1,
charlesmn 0:3ac96e360672 1083 pbuffer + VL53L1_NVM__FMT__FGC__BYTE_15,
charlesmn 0:3ac96e360672 1084 0x000001FC,
charlesmn 0:3ac96e360672 1085 2,
charlesmn 0:3ac96e360672 1086 0);
charlesmn 0:3ac96e360672 1087 pdata->nvm__fmt__fgc[18] = 0x00;
charlesmn 0:3ac96e360672 1088
charlesmn 0:3ac96e360672 1089 pdata->nvm__fmt__test_program_major =
charlesmn 0:3ac96e360672 1090 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1091 1,
charlesmn 0:3ac96e360672 1092 pbuffer + VL53L1_NVM__FMT__TEST_PROGRAM_MAJOR_MINOR,
charlesmn 0:3ac96e360672 1093 0x000000E0,
charlesmn 0:3ac96e360672 1094 5,
charlesmn 0:3ac96e360672 1095 0);
charlesmn 0:3ac96e360672 1096 pdata->nvm__fmt__test_program_minor =
charlesmn 0:3ac96e360672 1097 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1098 1,
charlesmn 0:3ac96e360672 1099 pbuffer + VL53L1_NVM__FMT__TEST_PROGRAM_MAJOR_MINOR,
charlesmn 0:3ac96e360672 1100 0x0000001F,
charlesmn 0:3ac96e360672 1101 0,
charlesmn 0:3ac96e360672 1102 0);
charlesmn 0:3ac96e360672 1103 pdata->nvm__fmt__map_major =
charlesmn 0:3ac96e360672 1104 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1105 1,
charlesmn 0:3ac96e360672 1106 pbuffer + VL53L1_NVM__FMT__MAP_MAJOR_MINOR,
charlesmn 0:3ac96e360672 1107 0x000000E0,
charlesmn 0:3ac96e360672 1108 5,
charlesmn 0:3ac96e360672 1109 0);
charlesmn 0:3ac96e360672 1110 pdata->nvm__fmt__map_minor =
charlesmn 0:3ac96e360672 1111 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1112 1,
charlesmn 0:3ac96e360672 1113 pbuffer + VL53L1_NVM__FMT__MAP_MAJOR_MINOR,
charlesmn 0:3ac96e360672 1114 0x0000001F,
charlesmn 0:3ac96e360672 1115 0,
charlesmn 0:3ac96e360672 1116 0);
charlesmn 0:3ac96e360672 1117 pdata->nvm__fmt__year =
charlesmn 0:3ac96e360672 1118 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1119 1,
charlesmn 0:3ac96e360672 1120 pbuffer + VL53L1_NVM__FMT__YEAR_MONTH,
charlesmn 0:3ac96e360672 1121 0x000000F0,
charlesmn 0:3ac96e360672 1122 4,
charlesmn 0:3ac96e360672 1123 0);
charlesmn 0:3ac96e360672 1124 pdata->nvm__fmt__month =
charlesmn 0:3ac96e360672 1125 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1126 1,
charlesmn 0:3ac96e360672 1127 pbuffer + VL53L1_NVM__FMT__YEAR_MONTH,
charlesmn 0:3ac96e360672 1128 0x0000000F,
charlesmn 0:3ac96e360672 1129 0,
charlesmn 0:3ac96e360672 1130 0);
charlesmn 0:3ac96e360672 1131 pdata->nvm__fmt__day =
charlesmn 0:3ac96e360672 1132 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1133 1,
charlesmn 0:3ac96e360672 1134 pbuffer + VL53L1_NVM__FMT__DAY_MODULE_DATE_PHASE,
charlesmn 0:3ac96e360672 1135 0x000000F8,
charlesmn 0:3ac96e360672 1136 3,
charlesmn 0:3ac96e360672 1137 0);
charlesmn 0:3ac96e360672 1138 pdata->nvm__fmt__module_date_phase =
charlesmn 0:3ac96e360672 1139 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1140 1,
charlesmn 0:3ac96e360672 1141 pbuffer + VL53L1_NVM__FMT__DAY_MODULE_DATE_PHASE,
charlesmn 0:3ac96e360672 1142 0x00000007,
charlesmn 0:3ac96e360672 1143 0,
charlesmn 0:3ac96e360672 1144 0);
charlesmn 0:3ac96e360672 1145 pdata->nvm__fmt__time =
charlesmn 0:3ac96e360672 1146 (uint16_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1147 2,
charlesmn 0:3ac96e360672 1148 pbuffer + VL53L1_NVM__FMT__TIME,
charlesmn 0:3ac96e360672 1149 0x0000FFFF,
charlesmn 0:3ac96e360672 1150 0,
charlesmn 0:3ac96e360672 1151 0);
charlesmn 0:3ac96e360672 1152 pdata->nvm__fmt__tester_id =
charlesmn 0:3ac96e360672 1153 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1154 1,
charlesmn 0:3ac96e360672 1155 pbuffer + VL53L1_NVM__FMT__TESTER_ID,
charlesmn 0:3ac96e360672 1156 0x000000FF,
charlesmn 0:3ac96e360672 1157 0,
charlesmn 0:3ac96e360672 1158 0);
charlesmn 0:3ac96e360672 1159 pdata->nvm__fmt__site_id =
charlesmn 0:3ac96e360672 1160 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1161 1,
charlesmn 0:3ac96e360672 1162 pbuffer + VL53L1_NVM__FMT__SITE_ID,
charlesmn 0:3ac96e360672 1163 0x000000FF,
charlesmn 0:3ac96e360672 1164 0,
charlesmn 0:3ac96e360672 1165 0);
charlesmn 0:3ac96e360672 1166
charlesmn 0:3ac96e360672 1167 return status;
charlesmn 0:3ac96e360672 1168 }
charlesmn 0:3ac96e360672 1169
charlesmn 0:3ac96e360672 1170
charlesmn 0:3ac96e360672 1171 VL53L1_Error VL53L1_nvm_decode_ews_info(
charlesmn 0:3ac96e360672 1172 uint16_t buf_size,
charlesmn 0:3ac96e360672 1173 uint8_t *pbuffer,
charlesmn 0:3ac96e360672 1174 VL53L1_decoded_nvm_ews_info_t *pdata)
charlesmn 0:3ac96e360672 1175 {
charlesmn 0:3ac96e360672 1176
charlesmn 0:3ac96e360672 1177 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 1178
charlesmn 0:3ac96e360672 1179 if (buf_size < VL53L1_NVM_SIZE_IN_BYTES)
charlesmn 0:3ac96e360672 1180 return VL53L1_ERROR_BUFFER_TOO_SMALL;
charlesmn 0:3ac96e360672 1181
charlesmn 0:3ac96e360672 1182 pdata->nvm__ews__test_program_major =
charlesmn 0:3ac96e360672 1183 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1184 1,
charlesmn 0:3ac96e360672 1185 pbuffer + VL53L1_NVM__EWS__TEST_PROGRAM_MAJOR_MINOR,
charlesmn 0:3ac96e360672 1186 0x000000E0,
charlesmn 0:3ac96e360672 1187 5,
charlesmn 0:3ac96e360672 1188 0);
charlesmn 0:3ac96e360672 1189 pdata->nvm__ews__test_program_minor =
charlesmn 0:3ac96e360672 1190 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1191 1,
charlesmn 0:3ac96e360672 1192 pbuffer + VL53L1_NVM__EWS__TEST_PROGRAM_MAJOR_MINOR,
charlesmn 0:3ac96e360672 1193 0x0000001F,
charlesmn 0:3ac96e360672 1194 0,
charlesmn 0:3ac96e360672 1195 0);
charlesmn 0:3ac96e360672 1196 pdata->nvm__ews__probe_card_major =
charlesmn 0:3ac96e360672 1197 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1198 1,
charlesmn 0:3ac96e360672 1199 pbuffer + VL53L1_NVM__EWS__PROBE_CARD_MAJOR_MINOR,
charlesmn 0:3ac96e360672 1200 0x000000F0,
charlesmn 0:3ac96e360672 1201 4,
charlesmn 0:3ac96e360672 1202 0);
charlesmn 0:3ac96e360672 1203 pdata->nvm__ews__probe_card_minor =
charlesmn 0:3ac96e360672 1204 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1205 1,
charlesmn 0:3ac96e360672 1206 pbuffer + VL53L1_NVM__EWS__PROBE_CARD_MAJOR_MINOR,
charlesmn 0:3ac96e360672 1207 0x0000000F,
charlesmn 0:3ac96e360672 1208 0,
charlesmn 0:3ac96e360672 1209 0);
charlesmn 0:3ac96e360672 1210 pdata->nvm__ews__tester_id =
charlesmn 0:3ac96e360672 1211 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1212 1,
charlesmn 0:3ac96e360672 1213 pbuffer + VL53L1_NVM__EWS__TESTER_ID,
charlesmn 0:3ac96e360672 1214 0x000000FF,
charlesmn 0:3ac96e360672 1215 0,
charlesmn 0:3ac96e360672 1216 0);
charlesmn 0:3ac96e360672 1217 pdata->nvm__ews__lot[0] =
charlesmn 0:3ac96e360672 1218 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1219 1,
charlesmn 0:3ac96e360672 1220 pbuffer + VL53L1_NVM__EWS__LOT__BYTE_0,
charlesmn 0:3ac96e360672 1221 0x000000FC,
charlesmn 0:3ac96e360672 1222 2,
charlesmn 0:3ac96e360672 1223 32);
charlesmn 0:3ac96e360672 1224 pdata->nvm__ews__lot[1] =
charlesmn 0:3ac96e360672 1225 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1226 2,
charlesmn 0:3ac96e360672 1227 pbuffer + VL53L1_NVM__EWS__LOT__BYTE_1 - 1,
charlesmn 0:3ac96e360672 1228 0x000003F0,
charlesmn 0:3ac96e360672 1229 4,
charlesmn 0:3ac96e360672 1230 32);
charlesmn 0:3ac96e360672 1231 pdata->nvm__ews__lot[2] =
charlesmn 0:3ac96e360672 1232 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1233 2,
charlesmn 0:3ac96e360672 1234 pbuffer + VL53L1_NVM__EWS__LOT__BYTE_2 - 1,
charlesmn 0:3ac96e360672 1235 0x00000FC0,
charlesmn 0:3ac96e360672 1236 6,
charlesmn 0:3ac96e360672 1237 32);
charlesmn 0:3ac96e360672 1238 pdata->nvm__ews__lot[3] =
charlesmn 0:3ac96e360672 1239 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1240 1,
charlesmn 0:3ac96e360672 1241 pbuffer + VL53L1_NVM__EWS__LOT__BYTE_2,
charlesmn 0:3ac96e360672 1242 0x0000003F,
charlesmn 0:3ac96e360672 1243 0,
charlesmn 0:3ac96e360672 1244 32);
charlesmn 0:3ac96e360672 1245 pdata->nvm__ews__lot[4] =
charlesmn 0:3ac96e360672 1246 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1247 1,
charlesmn 0:3ac96e360672 1248 pbuffer + VL53L1_NVM__EWS__LOT__BYTE_3,
charlesmn 0:3ac96e360672 1249 0x000000FC,
charlesmn 0:3ac96e360672 1250 2,
charlesmn 0:3ac96e360672 1251 32);
charlesmn 0:3ac96e360672 1252 pdata->nvm__ews__lot[5] =
charlesmn 0:3ac96e360672 1253 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1254 2,
charlesmn 0:3ac96e360672 1255 pbuffer + VL53L1_NVM__EWS__LOT__BYTE_4 - 1,
charlesmn 0:3ac96e360672 1256 0x000003F0,
charlesmn 0:3ac96e360672 1257 4,
charlesmn 0:3ac96e360672 1258 32);
charlesmn 0:3ac96e360672 1259 pdata->nvm__ews__lot[6] =
charlesmn 0:3ac96e360672 1260 (char)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1261 2,
charlesmn 0:3ac96e360672 1262 pbuffer + VL53L1_NVM__EWS__LOT__BYTE_5 - 1,
charlesmn 0:3ac96e360672 1263 0x00000FC0,
charlesmn 0:3ac96e360672 1264 6,
charlesmn 0:3ac96e360672 1265 32);
charlesmn 0:3ac96e360672 1266
charlesmn 0:3ac96e360672 1267 pdata->nvm__ews__lot[7] = 0x00;
charlesmn 0:3ac96e360672 1268
charlesmn 0:3ac96e360672 1269 pdata->nvm__ews__wafer =
charlesmn 0:3ac96e360672 1270 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1271 1,
charlesmn 0:3ac96e360672 1272 pbuffer + VL53L1_NVM__EWS__WAFER,
charlesmn 0:3ac96e360672 1273 0x0000001F,
charlesmn 0:3ac96e360672 1274 0,
charlesmn 0:3ac96e360672 1275 0);
charlesmn 0:3ac96e360672 1276 pdata->nvm__ews__xcoord =
charlesmn 0:3ac96e360672 1277 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1278 1,
charlesmn 0:3ac96e360672 1279 pbuffer + VL53L1_NVM__EWS__XCOORD,
charlesmn 0:3ac96e360672 1280 0x000000FF,
charlesmn 0:3ac96e360672 1281 0,
charlesmn 0:3ac96e360672 1282 0);
charlesmn 0:3ac96e360672 1283 pdata->nvm__ews__ycoord =
charlesmn 0:3ac96e360672 1284 (uint8_t)VL53L1_i2c_decode_with_mask(
charlesmn 0:3ac96e360672 1285 1,
charlesmn 0:3ac96e360672 1286 pbuffer + VL53L1_NVM__EWS__YCOORD,
charlesmn 0:3ac96e360672 1287 0x000000FF,
charlesmn 0:3ac96e360672 1288 0,
charlesmn 0:3ac96e360672 1289 0);
charlesmn 0:3ac96e360672 1290
charlesmn 0:3ac96e360672 1291 return status;
charlesmn 0:3ac96e360672 1292
charlesmn 0:3ac96e360672 1293 }
charlesmn 0:3ac96e360672 1294
charlesmn 0:3ac96e360672 1295
charlesmn 0:3ac96e360672 1296 void VL53L1_nvm_format_encode(
charlesmn 0:3ac96e360672 1297 VL53L1_decoded_nvm_data_t *pnvm_info,
charlesmn 0:3ac96e360672 1298 uint8_t *pnvm_data)
charlesmn 0:3ac96e360672 1299 {
charlesmn 0:3ac96e360672 1300 SUPPRESS_UNUSED_WARNING(pnvm_info);
charlesmn 0:3ac96e360672 1301 SUPPRESS_UNUSED_WARNING(pnvm_data);
charlesmn 0:3ac96e360672 1302 }
charlesmn 0:3ac96e360672 1303
charlesmn 0:3ac96e360672 1304
charlesmn 0:3ac96e360672 1305 VL53L1_Error VL53L1_read_nvm_raw_data(
charlesmn 0:3ac96e360672 1306 VL53L1_DEV Dev,
charlesmn 0:3ac96e360672 1307 uint8_t start_address,
charlesmn 0:3ac96e360672 1308 uint8_t count,
charlesmn 0:3ac96e360672 1309 uint8_t *pnvm_raw_data)
charlesmn 0:3ac96e360672 1310 {
charlesmn 0:3ac96e360672 1311
charlesmn 0:3ac96e360672 1312
charlesmn 0:3ac96e360672 1313
charlesmn 0:3ac96e360672 1314 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 1315
charlesmn 0:3ac96e360672 1316 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 1317
charlesmn 0:3ac96e360672 1318
charlesmn 0:3ac96e360672 1319
charlesmn 0:3ac96e360672 1320 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 1321 status = VL53L1_nvm_enable(
charlesmn 0:3ac96e360672 1322 Dev,
charlesmn 0:3ac96e360672 1323 0x0004,
charlesmn 0:3ac96e360672 1324 VL53L1_NVM_POWER_UP_DELAY_US);
charlesmn 0:3ac96e360672 1325
charlesmn 0:3ac96e360672 1326
charlesmn 0:3ac96e360672 1327
charlesmn 0:3ac96e360672 1328 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 1329 status = VL53L1_nvm_read(
charlesmn 0:3ac96e360672 1330 Dev,
charlesmn 0:3ac96e360672 1331 start_address,
charlesmn 0:3ac96e360672 1332 count,
charlesmn 0:3ac96e360672 1333 pnvm_raw_data);
charlesmn 0:3ac96e360672 1334
charlesmn 0:3ac96e360672 1335
charlesmn 0:3ac96e360672 1336
charlesmn 0:3ac96e360672 1337 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 1338 status = VL53L1_nvm_disable(Dev);
charlesmn 0:3ac96e360672 1339
charlesmn 0:3ac96e360672 1340 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 1341
charlesmn 0:3ac96e360672 1342 return status;
charlesmn 0:3ac96e360672 1343
charlesmn 0:3ac96e360672 1344 }
charlesmn 0:3ac96e360672 1345
charlesmn 0:3ac96e360672 1346
charlesmn 0:3ac96e360672 1347 VL53L1_Error VL53L1_read_nvm(
charlesmn 0:3ac96e360672 1348 VL53L1_DEV Dev,
charlesmn 0:3ac96e360672 1349 uint8_t nvm_format,
charlesmn 0:3ac96e360672 1350 VL53L1_decoded_nvm_data_t *pnvm_info)
charlesmn 0:3ac96e360672 1351 {
charlesmn 0:3ac96e360672 1352
charlesmn 0:3ac96e360672 1353
charlesmn 0:3ac96e360672 1354
charlesmn 0:3ac96e360672 1355 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 1356
charlesmn 0:3ac96e360672 1357 uint8_t nvm_data[VL53L1_NVM_SIZE_IN_BYTES];
charlesmn 0:3ac96e360672 1358
charlesmn 0:3ac96e360672 1359 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 1360
charlesmn 0:3ac96e360672 1361 SUPPRESS_UNUSED_WARNING(nvm_format);
charlesmn 0:3ac96e360672 1362
charlesmn 0:3ac96e360672 1363
charlesmn 0:3ac96e360672 1364
charlesmn 0:3ac96e360672 1365 status = VL53L1_read_nvm_raw_data(
charlesmn 0:3ac96e360672 1366 Dev,
charlesmn 0:3ac96e360672 1367 0,
charlesmn 0:3ac96e360672 1368 VL53L1_NVM_SIZE_IN_BYTES >> 2,
charlesmn 0:3ac96e360672 1369 nvm_data);
charlesmn 0:3ac96e360672 1370
charlesmn 0:3ac96e360672 1371
charlesmn 0:3ac96e360672 1372
charlesmn 0:3ac96e360672 1373
charlesmn 0:3ac96e360672 1374
charlesmn 0:3ac96e360672 1375 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 1376 status = VL53L1_nvm_format_decode(
charlesmn 0:3ac96e360672 1377 VL53L1_NVM_SIZE_IN_BYTES,
charlesmn 0:3ac96e360672 1378 nvm_data,
charlesmn 0:3ac96e360672 1379 pnvm_info);
charlesmn 0:3ac96e360672 1380
charlesmn 0:3ac96e360672 1381 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 1382
charlesmn 0:3ac96e360672 1383 return status;
charlesmn 0:3ac96e360672 1384
charlesmn 0:3ac96e360672 1385 }
charlesmn 0:3ac96e360672 1386
charlesmn 0:3ac96e360672 1387
charlesmn 0:3ac96e360672 1388 VL53L1_Error VL53L1_read_nvm_optical_centre(
charlesmn 0:3ac96e360672 1389 VL53L1_DEV Dev,
charlesmn 0:3ac96e360672 1390 VL53L1_optical_centre_t *pcentre)
charlesmn 0:3ac96e360672 1391 {
charlesmn 0:3ac96e360672 1392
charlesmn 0:3ac96e360672 1393
charlesmn 0:3ac96e360672 1394 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 1395
charlesmn 0:3ac96e360672 1396 uint8_t nvm_data[VL53L1_NVM__FMT__OPTICAL_CENTRE_DATA_SIZE];
charlesmn 0:3ac96e360672 1397
charlesmn 0:3ac96e360672 1398 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 1399
charlesmn 0:3ac96e360672 1400
charlesmn 0:3ac96e360672 1401
charlesmn 0:3ac96e360672 1402 status =
charlesmn 0:3ac96e360672 1403 VL53L1_read_nvm_raw_data(
charlesmn 0:3ac96e360672 1404 Dev,
charlesmn 0:3ac96e360672 1405 (uint8_t)(VL53L1_NVM__FMT__OPTICAL_CENTRE_DATA_INDEX
charlesmn 0:3ac96e360672 1406 >> 2),
charlesmn 0:3ac96e360672 1407 (uint8_t)(VL53L1_NVM__FMT__OPTICAL_CENTRE_DATA_SIZE
charlesmn 0:3ac96e360672 1408 >> 2),
charlesmn 0:3ac96e360672 1409 nvm_data);
charlesmn 0:3ac96e360672 1410
charlesmn 0:3ac96e360672 1411
charlesmn 0:3ac96e360672 1412
charlesmn 0:3ac96e360672 1413 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 1414 status =
charlesmn 0:3ac96e360672 1415 VL53L1_nvm_decode_optical_centre(
charlesmn 0:3ac96e360672 1416 VL53L1_NVM__FMT__OPTICAL_CENTRE_DATA_SIZE,
charlesmn 0:3ac96e360672 1417 nvm_data,
charlesmn 0:3ac96e360672 1418 pcentre);
charlesmn 0:3ac96e360672 1419
charlesmn 0:3ac96e360672 1420 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 1421
charlesmn 0:3ac96e360672 1422 return status;
charlesmn 0:3ac96e360672 1423 }
charlesmn 0:3ac96e360672 1424
charlesmn 0:3ac96e360672 1425
charlesmn 0:3ac96e360672 1426 VL53L1_Error VL53L1_read_nvm_cal_peak_rate_map(
charlesmn 0:3ac96e360672 1427 VL53L1_DEV Dev,
charlesmn 0:3ac96e360672 1428 VL53L1_cal_peak_rate_map_t *pcal_data)
charlesmn 0:3ac96e360672 1429 {
charlesmn 0:3ac96e360672 1430
charlesmn 0:3ac96e360672 1431
charlesmn 0:3ac96e360672 1432 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 1433
charlesmn 0:3ac96e360672 1434 uint8_t nvm_data[VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_SIZE];
charlesmn 0:3ac96e360672 1435
charlesmn 0:3ac96e360672 1436 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 1437
charlesmn 0:3ac96e360672 1438
charlesmn 0:3ac96e360672 1439
charlesmn 0:3ac96e360672 1440 status =
charlesmn 0:3ac96e360672 1441 VL53L1_read_nvm_raw_data(
charlesmn 0:3ac96e360672 1442 Dev,
charlesmn 0:3ac96e360672 1443 (uint8_t)(VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_INDEX
charlesmn 0:3ac96e360672 1444 >> 2),
charlesmn 0:3ac96e360672 1445 (uint8_t)(VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_SIZE
charlesmn 0:3ac96e360672 1446 >> 2),
charlesmn 0:3ac96e360672 1447 nvm_data);
charlesmn 0:3ac96e360672 1448
charlesmn 0:3ac96e360672 1449
charlesmn 0:3ac96e360672 1450
charlesmn 0:3ac96e360672 1451 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 1452 status =
charlesmn 0:3ac96e360672 1453 VL53L1_nvm_decode_cal_peak_rate_map(
charlesmn 0:3ac96e360672 1454 VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_SIZE,
charlesmn 0:3ac96e360672 1455 nvm_data,
charlesmn 0:3ac96e360672 1456 pcal_data);
charlesmn 0:3ac96e360672 1457
charlesmn 0:3ac96e360672 1458 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 1459
charlesmn 0:3ac96e360672 1460 return status;
charlesmn 0:3ac96e360672 1461 }
charlesmn 0:3ac96e360672 1462
charlesmn 0:3ac96e360672 1463
charlesmn 0:3ac96e360672 1464 VL53L1_Error VL53L1_read_nvm_additional_offset_cal_data(
charlesmn 0:3ac96e360672 1465 VL53L1_DEV Dev,
charlesmn 0:3ac96e360672 1466 VL53L1_additional_offset_cal_data_t *pcal_data)
charlesmn 0:3ac96e360672 1467 {
charlesmn 0:3ac96e360672 1468
charlesmn 0:3ac96e360672 1469
charlesmn 0:3ac96e360672 1470
charlesmn 0:3ac96e360672 1471 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 1472
charlesmn 0:3ac96e360672 1473 uint8_t nvm_data[VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_SIZE];
charlesmn 0:3ac96e360672 1474
charlesmn 0:3ac96e360672 1475 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 1476
charlesmn 0:3ac96e360672 1477
charlesmn 0:3ac96e360672 1478
charlesmn 0:3ac96e360672 1479 status =
charlesmn 0:3ac96e360672 1480 VL53L1_read_nvm_raw_data(
charlesmn 0:3ac96e360672 1481 Dev,
charlesmn 0:3ac96e360672 1482 (uint8_t)(
charlesmn 0:3ac96e360672 1483 VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_INDEX >> 2),
charlesmn 0:3ac96e360672 1484 (uint8_t)(
charlesmn 0:3ac96e360672 1485 VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_SIZE >> 2),
charlesmn 0:3ac96e360672 1486 nvm_data);
charlesmn 0:3ac96e360672 1487
charlesmn 0:3ac96e360672 1488
charlesmn 0:3ac96e360672 1489
charlesmn 0:3ac96e360672 1490 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 1491 status = VL53L1_nvm_decode_additional_offset_cal_data(
charlesmn 0:3ac96e360672 1492 VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_SIZE,
charlesmn 0:3ac96e360672 1493 nvm_data,
charlesmn 0:3ac96e360672 1494 pcal_data);
charlesmn 0:3ac96e360672 1495
charlesmn 0:3ac96e360672 1496 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 1497
charlesmn 0:3ac96e360672 1498 return status;
charlesmn 0:3ac96e360672 1499
charlesmn 0:3ac96e360672 1500 }
charlesmn 0:3ac96e360672 1501
charlesmn 0:3ac96e360672 1502
charlesmn 0:3ac96e360672 1503 VL53L1_Error VL53L1_read_nvm_fmt_range_results_data(
charlesmn 0:3ac96e360672 1504 VL53L1_DEV Dev,
charlesmn 0:3ac96e360672 1505 uint16_t range_results_select,
charlesmn 0:3ac96e360672 1506 VL53L1_decoded_nvm_fmt_range_data_t *prange_data)
charlesmn 0:3ac96e360672 1507 {
charlesmn 0:3ac96e360672 1508
charlesmn 0:3ac96e360672 1509
charlesmn 0:3ac96e360672 1510
charlesmn 0:3ac96e360672 1511 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 1512
charlesmn 0:3ac96e360672 1513 uint8_t nvm_data[VL53L1_NVM__FMT__RANGE_RESULTS__SIZE_BYTES];
charlesmn 0:3ac96e360672 1514
charlesmn 0:3ac96e360672 1515 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 1516
charlesmn 0:3ac96e360672 1517
charlesmn 0:3ac96e360672 1518
charlesmn 0:3ac96e360672 1519 status = VL53L1_read_nvm_raw_data(
charlesmn 0:3ac96e360672 1520 Dev,
charlesmn 0:3ac96e360672 1521 (uint8_t)(range_results_select >> 2),
charlesmn 0:3ac96e360672 1522 (uint8_t)(VL53L1_NVM__FMT__RANGE_RESULTS__SIZE_BYTES >> 2),
charlesmn 0:3ac96e360672 1523 nvm_data);
charlesmn 0:3ac96e360672 1524
charlesmn 0:3ac96e360672 1525
charlesmn 0:3ac96e360672 1526
charlesmn 0:3ac96e360672 1527 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 1528 status =
charlesmn 0:3ac96e360672 1529 VL53L1_nvm_decode_fmt_range_results_data(
charlesmn 0:3ac96e360672 1530 VL53L1_NVM__FMT__RANGE_RESULTS__SIZE_BYTES,
charlesmn 0:3ac96e360672 1531 nvm_data,
charlesmn 0:3ac96e360672 1532 prange_data);
charlesmn 0:3ac96e360672 1533
charlesmn 0:3ac96e360672 1534 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 1535
charlesmn 0:3ac96e360672 1536 return status;
charlesmn 0:3ac96e360672 1537
charlesmn 0:3ac96e360672 1538 }
charlesmn 0:3ac96e360672 1539
charlesmn 0:3ac96e360672 1540