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.
src/vl53l1_register_funcs.c@18:0696efe39d08, 2021-07-21 (annotated)
- Committer:
- lugandc
- Date:
- Wed Jul 21 17:06:38 2021 +0200
- Revision:
- 18:0696efe39d08
- Parent:
- 7:1add29d51e72
Cleanup i2c functions, removed all bad references to L1X
Cleanup VL53L1CB class:
- i2c device object is passed in a consistent way in MyDevice structure
- removed useless functions
Updated VL53L1CB component driver with bare driver release 6.6.7 content
Who changed what in which revision?
User | Revision | Line number | New 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 | #include "vl53l1_ll_def.h" |
charlesmn | 0:3ac96e360672 | 16 | #include "vl53l1_platform.h" |
charlesmn | 0:3ac96e360672 | 17 | #include "vl53l1_platform_log.h" |
charlesmn | 0:3ac96e360672 | 18 | #include "vl53l1_core.h" |
charlesmn | 0:3ac96e360672 | 19 | #include "vl53l1_register_map.h" |
charlesmn | 0:3ac96e360672 | 20 | #include "vl53l1_register_structs.h" |
charlesmn | 0:3ac96e360672 | 21 | #include "vl53l1_register_funcs.h" |
charlesmn | 0:3ac96e360672 | 22 | |
charlesmn | 0:3ac96e360672 | 23 | #define LOG_FUNCTION_START(fmt, ...) \ |
charlesmn | 0:3ac96e360672 | 24 | _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_REGISTERS, fmt, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 25 | #define LOG_FUNCTION_END(status, ...) \ |
charlesmn | 0:3ac96e360672 | 26 | _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_REGISTERS, status, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 27 | #define LOG_FUNCTION_END_FMT(status, fmt, ...) \ |
charlesmn | 0:3ac96e360672 | 28 | _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_REGISTERS,\ |
charlesmn | 0:3ac96e360672 | 29 | status, fmt, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 30 | |
charlesmn | 0:3ac96e360672 | 31 | |
charlesmn | 0:3ac96e360672 | 32 | VL53L1_Error VL53L1_i2c_encode_static_nvm_managed( |
charlesmn | 0:3ac96e360672 | 33 | VL53L1_static_nvm_managed_t *pdata, |
charlesmn | 0:3ac96e360672 | 34 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 35 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 36 | { |
charlesmn | 0:3ac96e360672 | 37 | |
charlesmn | 0:3ac96e360672 | 38 | |
charlesmn | 0:3ac96e360672 | 39 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 40 | |
charlesmn | 0:3ac96e360672 | 41 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 42 | |
charlesmn | 0:3ac96e360672 | 43 | if (buf_size < VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 44 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 45 | |
charlesmn | 0:3ac96e360672 | 46 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 47 | pdata->i2c_slave__device_address & 0x7F; |
charlesmn | 0:3ac96e360672 | 48 | *(pbuffer + 1) = |
charlesmn | 0:3ac96e360672 | 49 | pdata->ana_config__vhv_ref_sel_vddpix & 0xF; |
charlesmn | 0:3ac96e360672 | 50 | *(pbuffer + 2) = |
charlesmn | 0:3ac96e360672 | 51 | pdata->ana_config__vhv_ref_sel_vquench & 0x7F; |
charlesmn | 0:3ac96e360672 | 52 | *(pbuffer + 3) = |
charlesmn | 0:3ac96e360672 | 53 | pdata->ana_config__reg_avdd1v2_sel & 0x3; |
charlesmn | 0:3ac96e360672 | 54 | *(pbuffer + 4) = |
charlesmn | 0:3ac96e360672 | 55 | pdata->ana_config__fast_osc__trim & 0x7F; |
charlesmn | 0:3ac96e360672 | 56 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 57 | pdata->osc_measured__fast_osc__frequency, |
charlesmn | 0:3ac96e360672 | 58 | 2, |
charlesmn | 0:3ac96e360672 | 59 | pbuffer + 5); |
charlesmn | 0:3ac96e360672 | 60 | *(pbuffer + 7) = |
charlesmn | 0:3ac96e360672 | 61 | pdata->vhv_config__timeout_macrop_loop_bound; |
charlesmn | 0:3ac96e360672 | 62 | *(pbuffer + 8) = |
charlesmn | 0:3ac96e360672 | 63 | pdata->vhv_config__count_thresh; |
charlesmn | 0:3ac96e360672 | 64 | *(pbuffer + 9) = |
charlesmn | 0:3ac96e360672 | 65 | pdata->vhv_config__offset & 0x3F; |
charlesmn | 0:3ac96e360672 | 66 | *(pbuffer + 10) = |
charlesmn | 0:3ac96e360672 | 67 | pdata->vhv_config__init; |
charlesmn | 0:3ac96e360672 | 68 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 69 | |
charlesmn | 0:3ac96e360672 | 70 | |
charlesmn | 0:3ac96e360672 | 71 | return status; |
charlesmn | 0:3ac96e360672 | 72 | } |
charlesmn | 0:3ac96e360672 | 73 | |
charlesmn | 0:3ac96e360672 | 74 | |
charlesmn | 0:3ac96e360672 | 75 | VL53L1_Error VL53L1_i2c_decode_static_nvm_managed( |
charlesmn | 0:3ac96e360672 | 76 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 77 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 78 | VL53L1_static_nvm_managed_t *pdata) |
charlesmn | 0:3ac96e360672 | 79 | { |
charlesmn | 0:3ac96e360672 | 80 | |
charlesmn | 0:3ac96e360672 | 81 | |
charlesmn | 0:3ac96e360672 | 82 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 83 | |
charlesmn | 0:3ac96e360672 | 84 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 85 | |
charlesmn | 0:3ac96e360672 | 86 | if (buf_size < VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 87 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 88 | |
charlesmn | 0:3ac96e360672 | 89 | pdata->i2c_slave__device_address = |
charlesmn | 0:3ac96e360672 | 90 | (*(pbuffer + 0)) & 0x7F; |
charlesmn | 0:3ac96e360672 | 91 | pdata->ana_config__vhv_ref_sel_vddpix = |
charlesmn | 0:3ac96e360672 | 92 | (*(pbuffer + 1)) & 0xF; |
charlesmn | 0:3ac96e360672 | 93 | pdata->ana_config__vhv_ref_sel_vquench = |
charlesmn | 0:3ac96e360672 | 94 | (*(pbuffer + 2)) & 0x7F; |
charlesmn | 0:3ac96e360672 | 95 | pdata->ana_config__reg_avdd1v2_sel = |
charlesmn | 0:3ac96e360672 | 96 | (*(pbuffer + 3)) & 0x3; |
charlesmn | 0:3ac96e360672 | 97 | pdata->ana_config__fast_osc__trim = |
charlesmn | 0:3ac96e360672 | 98 | (*(pbuffer + 4)) & 0x7F; |
charlesmn | 0:3ac96e360672 | 99 | pdata->osc_measured__fast_osc__frequency = |
charlesmn | 0:3ac96e360672 | 100 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 5)); |
charlesmn | 0:3ac96e360672 | 101 | pdata->vhv_config__timeout_macrop_loop_bound = |
charlesmn | 0:3ac96e360672 | 102 | (*(pbuffer + 7)); |
charlesmn | 0:3ac96e360672 | 103 | pdata->vhv_config__count_thresh = |
charlesmn | 0:3ac96e360672 | 104 | (*(pbuffer + 8)); |
charlesmn | 0:3ac96e360672 | 105 | pdata->vhv_config__offset = |
charlesmn | 0:3ac96e360672 | 106 | (*(pbuffer + 9)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 107 | pdata->vhv_config__init = |
charlesmn | 0:3ac96e360672 | 108 | (*(pbuffer + 10)); |
charlesmn | 0:3ac96e360672 | 109 | |
charlesmn | 0:3ac96e360672 | 110 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 111 | |
charlesmn | 0:3ac96e360672 | 112 | return status; |
charlesmn | 0:3ac96e360672 | 113 | } |
charlesmn | 0:3ac96e360672 | 114 | |
charlesmn | 0:3ac96e360672 | 115 | |
charlesmn | 0:3ac96e360672 | 116 | VL53L1_Error VL53L1_set_static_nvm_managed( |
charlesmn | 0:3ac96e360672 | 117 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 118 | VL53L1_static_nvm_managed_t *pdata) |
charlesmn | 0:3ac96e360672 | 119 | { |
charlesmn | 0:3ac96e360672 | 120 | |
charlesmn | 0:3ac96e360672 | 121 | |
charlesmn | 0:3ac96e360672 | 122 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 123 | uint8_t comms_buffer[VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 124 | |
charlesmn | 0:3ac96e360672 | 125 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 126 | |
charlesmn | 0:3ac96e360672 | 127 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 128 | status = VL53L1_i2c_encode_static_nvm_managed( |
charlesmn | 0:3ac96e360672 | 129 | pdata, |
charlesmn | 0:3ac96e360672 | 130 | VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 131 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 132 | |
charlesmn | 0:3ac96e360672 | 133 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 134 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 135 | Dev, |
charlesmn | 0:3ac96e360672 | 136 | VL53L1_I2C_SLAVE__DEVICE_ADDRESS, |
charlesmn | 0:3ac96e360672 | 137 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 138 | VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 139 | |
charlesmn | 0:3ac96e360672 | 140 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 141 | |
charlesmn | 0:3ac96e360672 | 142 | return status; |
charlesmn | 0:3ac96e360672 | 143 | } |
charlesmn | 0:3ac96e360672 | 144 | |
charlesmn | 0:3ac96e360672 | 145 | |
charlesmn | 0:3ac96e360672 | 146 | VL53L1_Error VL53L1_get_static_nvm_managed( |
charlesmn | 0:3ac96e360672 | 147 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 148 | VL53L1_static_nvm_managed_t *pdata) |
charlesmn | 0:3ac96e360672 | 149 | { |
charlesmn | 0:3ac96e360672 | 150 | |
charlesmn | 0:3ac96e360672 | 151 | |
charlesmn | 0:3ac96e360672 | 152 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 153 | uint8_t comms_buffer[VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 154 | |
charlesmn | 0:3ac96e360672 | 155 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 156 | |
charlesmn | 0:3ac96e360672 | 157 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 158 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 159 | Dev, |
charlesmn | 0:3ac96e360672 | 160 | VL53L1_I2C_SLAVE__DEVICE_ADDRESS, |
charlesmn | 0:3ac96e360672 | 161 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 162 | VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 163 | |
charlesmn | 0:3ac96e360672 | 164 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 165 | status = VL53L1_i2c_decode_static_nvm_managed( |
charlesmn | 0:3ac96e360672 | 166 | VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 167 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 168 | pdata); |
charlesmn | 0:3ac96e360672 | 169 | |
charlesmn | 0:3ac96e360672 | 170 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 171 | |
charlesmn | 0:3ac96e360672 | 172 | return status; |
charlesmn | 0:3ac96e360672 | 173 | } |
charlesmn | 0:3ac96e360672 | 174 | |
charlesmn | 0:3ac96e360672 | 175 | |
charlesmn | 0:3ac96e360672 | 176 | VL53L1_Error VL53L1_i2c_encode_customer_nvm_managed( |
charlesmn | 0:3ac96e360672 | 177 | VL53L1_customer_nvm_managed_t *pdata, |
charlesmn | 0:3ac96e360672 | 178 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 179 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 180 | { |
charlesmn | 0:3ac96e360672 | 181 | |
charlesmn | 0:3ac96e360672 | 182 | |
charlesmn | 0:3ac96e360672 | 183 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 184 | |
charlesmn | 0:3ac96e360672 | 185 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 186 | |
charlesmn | 0:3ac96e360672 | 187 | if (buf_size < VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 188 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 189 | |
charlesmn | 0:3ac96e360672 | 190 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 191 | pdata->global_config__spad_enables_ref_0; |
charlesmn | 0:3ac96e360672 | 192 | *(pbuffer + 1) = |
charlesmn | 0:3ac96e360672 | 193 | pdata->global_config__spad_enables_ref_1; |
charlesmn | 0:3ac96e360672 | 194 | *(pbuffer + 2) = |
charlesmn | 0:3ac96e360672 | 195 | pdata->global_config__spad_enables_ref_2; |
charlesmn | 0:3ac96e360672 | 196 | *(pbuffer + 3) = |
charlesmn | 0:3ac96e360672 | 197 | pdata->global_config__spad_enables_ref_3; |
charlesmn | 0:3ac96e360672 | 198 | *(pbuffer + 4) = |
charlesmn | 0:3ac96e360672 | 199 | pdata->global_config__spad_enables_ref_4; |
charlesmn | 0:3ac96e360672 | 200 | *(pbuffer + 5) = |
charlesmn | 0:3ac96e360672 | 201 | pdata->global_config__spad_enables_ref_5 & 0xF; |
charlesmn | 0:3ac96e360672 | 202 | *(pbuffer + 6) = |
charlesmn | 0:3ac96e360672 | 203 | pdata->global_config__ref_en_start_select; |
charlesmn | 0:3ac96e360672 | 204 | *(pbuffer + 7) = |
charlesmn | 0:3ac96e360672 | 205 | pdata->ref_spad_man__num_requested_ref_spads & 0x3F; |
charlesmn | 0:3ac96e360672 | 206 | *(pbuffer + 8) = |
charlesmn | 0:3ac96e360672 | 207 | pdata->ref_spad_man__ref_location & 0x3; |
charlesmn | 0:3ac96e360672 | 208 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 209 | pdata->algo__crosstalk_compensation_plane_offset_kcps, |
charlesmn | 0:3ac96e360672 | 210 | 2, |
charlesmn | 0:3ac96e360672 | 211 | pbuffer + 9); |
charlesmn | 0:3ac96e360672 | 212 | VL53L1_i2c_encode_int16_t( |
charlesmn | 0:3ac96e360672 | 213 | pdata->algo__crosstalk_compensation_x_plane_gradient_kcps, |
charlesmn | 0:3ac96e360672 | 214 | 2, |
charlesmn | 0:3ac96e360672 | 215 | pbuffer + 11); |
charlesmn | 0:3ac96e360672 | 216 | VL53L1_i2c_encode_int16_t( |
charlesmn | 0:3ac96e360672 | 217 | pdata->algo__crosstalk_compensation_y_plane_gradient_kcps, |
charlesmn | 0:3ac96e360672 | 218 | 2, |
charlesmn | 0:3ac96e360672 | 219 | pbuffer + 13); |
charlesmn | 0:3ac96e360672 | 220 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 221 | pdata->ref_spad_char__total_rate_target_mcps, |
charlesmn | 0:3ac96e360672 | 222 | 2, |
charlesmn | 0:3ac96e360672 | 223 | pbuffer + 15); |
charlesmn | 0:3ac96e360672 | 224 | VL53L1_i2c_encode_int16_t( |
charlesmn | 0:3ac96e360672 | 225 | pdata->algo__part_to_part_range_offset_mm & 0x1FFF, |
charlesmn | 0:3ac96e360672 | 226 | 2, |
charlesmn | 0:3ac96e360672 | 227 | pbuffer + 17); |
charlesmn | 0:3ac96e360672 | 228 | VL53L1_i2c_encode_int16_t( |
charlesmn | 0:3ac96e360672 | 229 | pdata->mm_config__inner_offset_mm, |
charlesmn | 0:3ac96e360672 | 230 | 2, |
charlesmn | 0:3ac96e360672 | 231 | pbuffer + 19); |
charlesmn | 0:3ac96e360672 | 232 | VL53L1_i2c_encode_int16_t( |
charlesmn | 0:3ac96e360672 | 233 | pdata->mm_config__outer_offset_mm, |
charlesmn | 0:3ac96e360672 | 234 | 2, |
charlesmn | 0:3ac96e360672 | 235 | pbuffer + 21); |
charlesmn | 0:3ac96e360672 | 236 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 237 | |
charlesmn | 0:3ac96e360672 | 238 | |
charlesmn | 0:3ac96e360672 | 239 | return status; |
charlesmn | 0:3ac96e360672 | 240 | } |
charlesmn | 0:3ac96e360672 | 241 | |
charlesmn | 0:3ac96e360672 | 242 | |
charlesmn | 0:3ac96e360672 | 243 | VL53L1_Error VL53L1_i2c_decode_customer_nvm_managed( |
charlesmn | 0:3ac96e360672 | 244 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 245 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 246 | VL53L1_customer_nvm_managed_t *pdata) |
charlesmn | 0:3ac96e360672 | 247 | { |
charlesmn | 0:3ac96e360672 | 248 | |
charlesmn | 0:3ac96e360672 | 249 | |
charlesmn | 0:3ac96e360672 | 250 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 251 | |
charlesmn | 0:3ac96e360672 | 252 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 253 | |
charlesmn | 0:3ac96e360672 | 254 | if (buf_size < VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 255 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 256 | |
charlesmn | 0:3ac96e360672 | 257 | pdata->global_config__spad_enables_ref_0 = |
charlesmn | 0:3ac96e360672 | 258 | (*(pbuffer + 0)); |
charlesmn | 0:3ac96e360672 | 259 | pdata->global_config__spad_enables_ref_1 = |
charlesmn | 0:3ac96e360672 | 260 | (*(pbuffer + 1)); |
charlesmn | 0:3ac96e360672 | 261 | pdata->global_config__spad_enables_ref_2 = |
charlesmn | 0:3ac96e360672 | 262 | (*(pbuffer + 2)); |
charlesmn | 0:3ac96e360672 | 263 | pdata->global_config__spad_enables_ref_3 = |
charlesmn | 0:3ac96e360672 | 264 | (*(pbuffer + 3)); |
charlesmn | 0:3ac96e360672 | 265 | pdata->global_config__spad_enables_ref_4 = |
charlesmn | 0:3ac96e360672 | 266 | (*(pbuffer + 4)); |
charlesmn | 0:3ac96e360672 | 267 | pdata->global_config__spad_enables_ref_5 = |
charlesmn | 0:3ac96e360672 | 268 | (*(pbuffer + 5)) & 0xF; |
charlesmn | 0:3ac96e360672 | 269 | pdata->global_config__ref_en_start_select = |
charlesmn | 0:3ac96e360672 | 270 | (*(pbuffer + 6)); |
charlesmn | 0:3ac96e360672 | 271 | pdata->ref_spad_man__num_requested_ref_spads = |
charlesmn | 0:3ac96e360672 | 272 | (*(pbuffer + 7)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 273 | pdata->ref_spad_man__ref_location = |
charlesmn | 0:3ac96e360672 | 274 | (*(pbuffer + 8)) & 0x3; |
charlesmn | 0:3ac96e360672 | 275 | pdata->algo__crosstalk_compensation_plane_offset_kcps = |
charlesmn | 0:3ac96e360672 | 276 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 9)); |
charlesmn | 0:3ac96e360672 | 277 | pdata->algo__crosstalk_compensation_x_plane_gradient_kcps = |
charlesmn | 0:3ac96e360672 | 278 | (VL53L1_i2c_decode_int16_t(2, pbuffer + 11)); |
charlesmn | 0:3ac96e360672 | 279 | pdata->algo__crosstalk_compensation_y_plane_gradient_kcps = |
charlesmn | 0:3ac96e360672 | 280 | (VL53L1_i2c_decode_int16_t(2, pbuffer + 13)); |
charlesmn | 0:3ac96e360672 | 281 | pdata->ref_spad_char__total_rate_target_mcps = |
charlesmn | 0:3ac96e360672 | 282 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 15)); |
charlesmn | 0:3ac96e360672 | 283 | pdata->algo__part_to_part_range_offset_mm = |
charlesmn | 0:3ac96e360672 | 284 | (VL53L1_i2c_decode_int16_t(2, pbuffer + 17)) & 0x1FFF; |
charlesmn | 0:3ac96e360672 | 285 | pdata->mm_config__inner_offset_mm = |
charlesmn | 0:3ac96e360672 | 286 | (VL53L1_i2c_decode_int16_t(2, pbuffer + 19)); |
charlesmn | 0:3ac96e360672 | 287 | pdata->mm_config__outer_offset_mm = |
charlesmn | 0:3ac96e360672 | 288 | (VL53L1_i2c_decode_int16_t(2, pbuffer + 21)); |
charlesmn | 0:3ac96e360672 | 289 | |
charlesmn | 0:3ac96e360672 | 290 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 291 | |
charlesmn | 0:3ac96e360672 | 292 | return status; |
charlesmn | 0:3ac96e360672 | 293 | } |
charlesmn | 0:3ac96e360672 | 294 | |
charlesmn | 0:3ac96e360672 | 295 | |
charlesmn | 0:3ac96e360672 | 296 | VL53L1_Error VL53L1_set_customer_nvm_managed( |
charlesmn | 0:3ac96e360672 | 297 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 298 | VL53L1_customer_nvm_managed_t *pdata) |
charlesmn | 0:3ac96e360672 | 299 | { |
charlesmn | 0:3ac96e360672 | 300 | |
charlesmn | 0:3ac96e360672 | 301 | |
charlesmn | 0:3ac96e360672 | 302 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 303 | uint8_t comms_buffer[VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 304 | |
charlesmn | 0:3ac96e360672 | 305 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 306 | |
charlesmn | 0:3ac96e360672 | 307 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 308 | status = VL53L1_i2c_encode_customer_nvm_managed( |
charlesmn | 0:3ac96e360672 | 309 | pdata, |
charlesmn | 0:3ac96e360672 | 310 | VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 311 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 312 | |
charlesmn | 0:3ac96e360672 | 313 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 314 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 315 | Dev, |
charlesmn | 0:3ac96e360672 | 316 | VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0, |
charlesmn | 0:3ac96e360672 | 317 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 318 | VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 319 | |
charlesmn | 0:3ac96e360672 | 320 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 321 | |
charlesmn | 0:3ac96e360672 | 322 | return status; |
charlesmn | 0:3ac96e360672 | 323 | } |
charlesmn | 0:3ac96e360672 | 324 | |
charlesmn | 0:3ac96e360672 | 325 | |
charlesmn | 0:3ac96e360672 | 326 | VL53L1_Error VL53L1_get_customer_nvm_managed( |
charlesmn | 0:3ac96e360672 | 327 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 328 | VL53L1_customer_nvm_managed_t *pdata) |
charlesmn | 0:3ac96e360672 | 329 | { |
charlesmn | 0:3ac96e360672 | 330 | |
charlesmn | 0:3ac96e360672 | 331 | |
charlesmn | 0:3ac96e360672 | 332 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 333 | uint8_t comms_buffer[VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 334 | |
charlesmn | 0:3ac96e360672 | 335 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 336 | |
charlesmn | 0:3ac96e360672 | 337 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 338 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 339 | Dev, |
charlesmn | 0:3ac96e360672 | 340 | VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0, |
charlesmn | 0:3ac96e360672 | 341 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 342 | VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 343 | |
charlesmn | 0:3ac96e360672 | 344 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 345 | status = VL53L1_i2c_decode_customer_nvm_managed( |
charlesmn | 0:3ac96e360672 | 346 | VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 347 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 348 | pdata); |
charlesmn | 0:3ac96e360672 | 349 | |
charlesmn | 0:3ac96e360672 | 350 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 351 | |
charlesmn | 0:3ac96e360672 | 352 | return status; |
charlesmn | 0:3ac96e360672 | 353 | } |
charlesmn | 0:3ac96e360672 | 354 | |
charlesmn | 0:3ac96e360672 | 355 | |
charlesmn | 0:3ac96e360672 | 356 | VL53L1_Error VL53L1_i2c_encode_static_config( |
charlesmn | 0:3ac96e360672 | 357 | VL53L1_static_config_t *pdata, |
charlesmn | 0:3ac96e360672 | 358 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 359 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 360 | { |
charlesmn | 0:3ac96e360672 | 361 | |
charlesmn | 0:3ac96e360672 | 362 | |
charlesmn | 0:3ac96e360672 | 363 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 364 | |
charlesmn | 0:3ac96e360672 | 365 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 366 | |
charlesmn | 0:3ac96e360672 | 367 | if (buf_size < VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 368 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 369 | |
charlesmn | 0:3ac96e360672 | 370 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 371 | pdata->dss_config__target_total_rate_mcps, |
charlesmn | 0:3ac96e360672 | 372 | 2, |
charlesmn | 0:3ac96e360672 | 373 | pbuffer + 0); |
charlesmn | 0:3ac96e360672 | 374 | *(pbuffer + 2) = |
charlesmn | 0:3ac96e360672 | 375 | pdata->debug__ctrl & 0x1; |
charlesmn | 0:3ac96e360672 | 376 | *(pbuffer + 3) = |
charlesmn | 0:3ac96e360672 | 377 | pdata->test_mode__ctrl & 0xF; |
charlesmn | 0:3ac96e360672 | 378 | *(pbuffer + 4) = |
charlesmn | 0:3ac96e360672 | 379 | pdata->clk_gating__ctrl & 0xF; |
charlesmn | 0:3ac96e360672 | 380 | *(pbuffer + 5) = |
charlesmn | 0:3ac96e360672 | 381 | pdata->nvm_bist__ctrl & 0x1F; |
charlesmn | 0:3ac96e360672 | 382 | *(pbuffer + 6) = |
charlesmn | 0:3ac96e360672 | 383 | pdata->nvm_bist__num_nvm_words & 0x7F; |
charlesmn | 0:3ac96e360672 | 384 | *(pbuffer + 7) = |
charlesmn | 0:3ac96e360672 | 385 | pdata->nvm_bist__start_address & 0x7F; |
charlesmn | 0:3ac96e360672 | 386 | *(pbuffer + 8) = |
charlesmn | 0:3ac96e360672 | 387 | pdata->host_if__status & 0x1; |
charlesmn | 0:3ac96e360672 | 388 | *(pbuffer + 9) = |
charlesmn | 0:3ac96e360672 | 389 | pdata->pad_i2c_hv__config; |
charlesmn | 0:3ac96e360672 | 390 | *(pbuffer + 10) = |
charlesmn | 0:3ac96e360672 | 391 | pdata->pad_i2c_hv__extsup_config & 0x1; |
charlesmn | 0:3ac96e360672 | 392 | *(pbuffer + 11) = |
charlesmn | 0:3ac96e360672 | 393 | pdata->gpio_hv_pad__ctrl & 0x3; |
charlesmn | 0:3ac96e360672 | 394 | *(pbuffer + 12) = |
charlesmn | 0:3ac96e360672 | 395 | pdata->gpio_hv_mux__ctrl & 0x1F; |
charlesmn | 0:3ac96e360672 | 396 | *(pbuffer + 13) = |
charlesmn | 0:3ac96e360672 | 397 | pdata->gpio__tio_hv_status & 0x3; |
charlesmn | 0:3ac96e360672 | 398 | *(pbuffer + 14) = |
charlesmn | 0:3ac96e360672 | 399 | pdata->gpio__fio_hv_status & 0x3; |
charlesmn | 0:3ac96e360672 | 400 | *(pbuffer + 15) = |
charlesmn | 0:3ac96e360672 | 401 | pdata->ana_config__spad_sel_pswidth & 0x7; |
charlesmn | 0:3ac96e360672 | 402 | *(pbuffer + 16) = |
charlesmn | 0:3ac96e360672 | 403 | pdata->ana_config__vcsel_pulse_width_offset & 0x1F; |
charlesmn | 0:3ac96e360672 | 404 | *(pbuffer + 17) = |
charlesmn | 0:3ac96e360672 | 405 | pdata->ana_config__fast_osc__config_ctrl & 0x1; |
charlesmn | 0:3ac96e360672 | 406 | *(pbuffer + 18) = |
charlesmn | 0:3ac96e360672 | 407 | pdata->sigma_estimator__effective_pulse_width_ns; |
charlesmn | 0:3ac96e360672 | 408 | *(pbuffer + 19) = |
charlesmn | 0:3ac96e360672 | 409 | pdata->sigma_estimator__effective_ambient_width_ns; |
charlesmn | 0:3ac96e360672 | 410 | *(pbuffer + 20) = |
charlesmn | 0:3ac96e360672 | 411 | pdata->sigma_estimator__sigma_ref_mm; |
charlesmn | 0:3ac96e360672 | 412 | *(pbuffer + 21) = |
charlesmn | 0:3ac96e360672 | 413 | pdata->algo__crosstalk_compensation_valid_height_mm; |
charlesmn | 0:3ac96e360672 | 414 | *(pbuffer + 22) = |
charlesmn | 0:3ac96e360672 | 415 | pdata->spare_host_config__static_config_spare_0; |
charlesmn | 0:3ac96e360672 | 416 | *(pbuffer + 23) = |
charlesmn | 0:3ac96e360672 | 417 | pdata->spare_host_config__static_config_spare_1; |
charlesmn | 0:3ac96e360672 | 418 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 419 | pdata->algo__range_ignore_threshold_mcps, |
charlesmn | 0:3ac96e360672 | 420 | 2, |
charlesmn | 0:3ac96e360672 | 421 | pbuffer + 24); |
charlesmn | 0:3ac96e360672 | 422 | *(pbuffer + 26) = |
charlesmn | 0:3ac96e360672 | 423 | pdata->algo__range_ignore_valid_height_mm; |
charlesmn | 0:3ac96e360672 | 424 | *(pbuffer + 27) = |
charlesmn | 0:3ac96e360672 | 425 | pdata->algo__range_min_clip; |
charlesmn | 0:3ac96e360672 | 426 | *(pbuffer + 28) = |
charlesmn | 0:3ac96e360672 | 427 | pdata->algo__consistency_check__tolerance & 0xF; |
charlesmn | 0:3ac96e360672 | 428 | *(pbuffer + 29) = |
charlesmn | 0:3ac96e360672 | 429 | pdata->spare_host_config__static_config_spare_2; |
charlesmn | 0:3ac96e360672 | 430 | *(pbuffer + 30) = |
charlesmn | 0:3ac96e360672 | 431 | pdata->sd_config__reset_stages_msb & 0xF; |
charlesmn | 0:3ac96e360672 | 432 | *(pbuffer + 31) = |
charlesmn | 0:3ac96e360672 | 433 | pdata->sd_config__reset_stages_lsb; |
charlesmn | 0:3ac96e360672 | 434 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 435 | |
charlesmn | 0:3ac96e360672 | 436 | |
charlesmn | 0:3ac96e360672 | 437 | return status; |
charlesmn | 0:3ac96e360672 | 438 | } |
charlesmn | 0:3ac96e360672 | 439 | |
charlesmn | 0:3ac96e360672 | 440 | |
charlesmn | 0:3ac96e360672 | 441 | VL53L1_Error VL53L1_i2c_decode_static_config( |
charlesmn | 0:3ac96e360672 | 442 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 443 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 444 | VL53L1_static_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 445 | { |
charlesmn | 0:3ac96e360672 | 446 | |
charlesmn | 0:3ac96e360672 | 447 | |
charlesmn | 0:3ac96e360672 | 448 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 449 | |
charlesmn | 0:3ac96e360672 | 450 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 451 | |
charlesmn | 0:3ac96e360672 | 452 | if (buf_size < VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 453 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 454 | |
charlesmn | 0:3ac96e360672 | 455 | pdata->dss_config__target_total_rate_mcps = |
charlesmn | 0:3ac96e360672 | 456 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 0)); |
charlesmn | 0:3ac96e360672 | 457 | pdata->debug__ctrl = |
charlesmn | 0:3ac96e360672 | 458 | (*(pbuffer + 2)) & 0x1; |
charlesmn | 0:3ac96e360672 | 459 | pdata->test_mode__ctrl = |
charlesmn | 0:3ac96e360672 | 460 | (*(pbuffer + 3)) & 0xF; |
charlesmn | 0:3ac96e360672 | 461 | pdata->clk_gating__ctrl = |
charlesmn | 0:3ac96e360672 | 462 | (*(pbuffer + 4)) & 0xF; |
charlesmn | 0:3ac96e360672 | 463 | pdata->nvm_bist__ctrl = |
charlesmn | 0:3ac96e360672 | 464 | (*(pbuffer + 5)) & 0x1F; |
charlesmn | 0:3ac96e360672 | 465 | pdata->nvm_bist__num_nvm_words = |
charlesmn | 0:3ac96e360672 | 466 | (*(pbuffer + 6)) & 0x7F; |
charlesmn | 0:3ac96e360672 | 467 | pdata->nvm_bist__start_address = |
charlesmn | 0:3ac96e360672 | 468 | (*(pbuffer + 7)) & 0x7F; |
charlesmn | 0:3ac96e360672 | 469 | pdata->host_if__status = |
charlesmn | 0:3ac96e360672 | 470 | (*(pbuffer + 8)) & 0x1; |
charlesmn | 0:3ac96e360672 | 471 | pdata->pad_i2c_hv__config = |
charlesmn | 0:3ac96e360672 | 472 | (*(pbuffer + 9)); |
charlesmn | 0:3ac96e360672 | 473 | pdata->pad_i2c_hv__extsup_config = |
charlesmn | 0:3ac96e360672 | 474 | (*(pbuffer + 10)) & 0x1; |
charlesmn | 0:3ac96e360672 | 475 | pdata->gpio_hv_pad__ctrl = |
charlesmn | 0:3ac96e360672 | 476 | (*(pbuffer + 11)) & 0x3; |
charlesmn | 0:3ac96e360672 | 477 | pdata->gpio_hv_mux__ctrl = |
charlesmn | 0:3ac96e360672 | 478 | (*(pbuffer + 12)) & 0x1F; |
charlesmn | 0:3ac96e360672 | 479 | pdata->gpio__tio_hv_status = |
charlesmn | 0:3ac96e360672 | 480 | (*(pbuffer + 13)) & 0x3; |
charlesmn | 0:3ac96e360672 | 481 | pdata->gpio__fio_hv_status = |
charlesmn | 0:3ac96e360672 | 482 | (*(pbuffer + 14)) & 0x3; |
charlesmn | 0:3ac96e360672 | 483 | pdata->ana_config__spad_sel_pswidth = |
charlesmn | 0:3ac96e360672 | 484 | (*(pbuffer + 15)) & 0x7; |
charlesmn | 0:3ac96e360672 | 485 | pdata->ana_config__vcsel_pulse_width_offset = |
charlesmn | 0:3ac96e360672 | 486 | (*(pbuffer + 16)) & 0x1F; |
charlesmn | 0:3ac96e360672 | 487 | pdata->ana_config__fast_osc__config_ctrl = |
charlesmn | 0:3ac96e360672 | 488 | (*(pbuffer + 17)) & 0x1; |
charlesmn | 0:3ac96e360672 | 489 | pdata->sigma_estimator__effective_pulse_width_ns = |
charlesmn | 0:3ac96e360672 | 490 | (*(pbuffer + 18)); |
charlesmn | 0:3ac96e360672 | 491 | pdata->sigma_estimator__effective_ambient_width_ns = |
charlesmn | 0:3ac96e360672 | 492 | (*(pbuffer + 19)); |
charlesmn | 0:3ac96e360672 | 493 | pdata->sigma_estimator__sigma_ref_mm = |
charlesmn | 0:3ac96e360672 | 494 | (*(pbuffer + 20)); |
charlesmn | 0:3ac96e360672 | 495 | pdata->algo__crosstalk_compensation_valid_height_mm = |
charlesmn | 0:3ac96e360672 | 496 | (*(pbuffer + 21)); |
charlesmn | 0:3ac96e360672 | 497 | pdata->spare_host_config__static_config_spare_0 = |
charlesmn | 0:3ac96e360672 | 498 | (*(pbuffer + 22)); |
charlesmn | 0:3ac96e360672 | 499 | pdata->spare_host_config__static_config_spare_1 = |
charlesmn | 0:3ac96e360672 | 500 | (*(pbuffer + 23)); |
charlesmn | 0:3ac96e360672 | 501 | pdata->algo__range_ignore_threshold_mcps = |
charlesmn | 0:3ac96e360672 | 502 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24)); |
charlesmn | 0:3ac96e360672 | 503 | pdata->algo__range_ignore_valid_height_mm = |
charlesmn | 0:3ac96e360672 | 504 | (*(pbuffer + 26)); |
charlesmn | 0:3ac96e360672 | 505 | pdata->algo__range_min_clip = |
charlesmn | 0:3ac96e360672 | 506 | (*(pbuffer + 27)); |
charlesmn | 0:3ac96e360672 | 507 | pdata->algo__consistency_check__tolerance = |
charlesmn | 0:3ac96e360672 | 508 | (*(pbuffer + 28)) & 0xF; |
charlesmn | 0:3ac96e360672 | 509 | pdata->spare_host_config__static_config_spare_2 = |
charlesmn | 0:3ac96e360672 | 510 | (*(pbuffer + 29)); |
charlesmn | 0:3ac96e360672 | 511 | pdata->sd_config__reset_stages_msb = |
charlesmn | 0:3ac96e360672 | 512 | (*(pbuffer + 30)) & 0xF; |
charlesmn | 0:3ac96e360672 | 513 | pdata->sd_config__reset_stages_lsb = |
charlesmn | 0:3ac96e360672 | 514 | (*(pbuffer + 31)); |
charlesmn | 0:3ac96e360672 | 515 | |
charlesmn | 0:3ac96e360672 | 516 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 517 | |
charlesmn | 0:3ac96e360672 | 518 | return status; |
charlesmn | 0:3ac96e360672 | 519 | } |
charlesmn | 0:3ac96e360672 | 520 | |
charlesmn | 0:3ac96e360672 | 521 | |
charlesmn | 0:3ac96e360672 | 522 | VL53L1_Error VL53L1_set_static_config( |
charlesmn | 0:3ac96e360672 | 523 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 524 | VL53L1_static_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 525 | { |
charlesmn | 0:3ac96e360672 | 526 | |
charlesmn | 0:3ac96e360672 | 527 | |
charlesmn | 0:3ac96e360672 | 528 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 529 | uint8_t comms_buffer[VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 530 | |
charlesmn | 0:3ac96e360672 | 531 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 532 | |
charlesmn | 0:3ac96e360672 | 533 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 534 | status = VL53L1_i2c_encode_static_config( |
charlesmn | 0:3ac96e360672 | 535 | pdata, |
charlesmn | 0:3ac96e360672 | 536 | VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 537 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 538 | |
charlesmn | 0:3ac96e360672 | 539 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 540 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 541 | Dev, |
charlesmn | 0:3ac96e360672 | 542 | VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS, |
charlesmn | 0:3ac96e360672 | 543 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 544 | VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 545 | |
charlesmn | 0:3ac96e360672 | 546 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 547 | |
charlesmn | 0:3ac96e360672 | 548 | return status; |
charlesmn | 0:3ac96e360672 | 549 | } |
charlesmn | 0:3ac96e360672 | 550 | |
charlesmn | 0:3ac96e360672 | 551 | |
charlesmn | 0:3ac96e360672 | 552 | VL53L1_Error VL53L1_get_static_config( |
charlesmn | 0:3ac96e360672 | 553 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 554 | VL53L1_static_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 555 | { |
charlesmn | 0:3ac96e360672 | 556 | |
charlesmn | 0:3ac96e360672 | 557 | |
charlesmn | 0:3ac96e360672 | 558 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 559 | uint8_t comms_buffer[VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 560 | |
charlesmn | 0:3ac96e360672 | 561 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 562 | |
charlesmn | 0:3ac96e360672 | 563 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 564 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 565 | Dev, |
charlesmn | 0:3ac96e360672 | 566 | VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS, |
charlesmn | 0:3ac96e360672 | 567 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 568 | VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 569 | |
charlesmn | 0:3ac96e360672 | 570 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 571 | status = VL53L1_i2c_decode_static_config( |
charlesmn | 0:3ac96e360672 | 572 | VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 573 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 574 | pdata); |
charlesmn | 0:3ac96e360672 | 575 | |
charlesmn | 0:3ac96e360672 | 576 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 577 | |
charlesmn | 0:3ac96e360672 | 578 | return status; |
charlesmn | 0:3ac96e360672 | 579 | } |
charlesmn | 0:3ac96e360672 | 580 | |
charlesmn | 0:3ac96e360672 | 581 | |
charlesmn | 0:3ac96e360672 | 582 | VL53L1_Error VL53L1_i2c_encode_general_config( |
charlesmn | 0:3ac96e360672 | 583 | VL53L1_general_config_t *pdata, |
charlesmn | 0:3ac96e360672 | 584 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 585 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 586 | { |
charlesmn | 0:3ac96e360672 | 587 | |
charlesmn | 0:3ac96e360672 | 588 | |
charlesmn | 0:3ac96e360672 | 589 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 590 | |
charlesmn | 0:3ac96e360672 | 591 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 592 | |
charlesmn | 0:3ac96e360672 | 593 | if (buf_size < VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 594 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 595 | |
charlesmn | 0:3ac96e360672 | 596 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 597 | pdata->gph_config__stream_count_update_value; |
charlesmn | 0:3ac96e360672 | 598 | *(pbuffer + 1) = |
charlesmn | 0:3ac96e360672 | 599 | pdata->global_config__stream_divider; |
charlesmn | 0:3ac96e360672 | 600 | *(pbuffer + 2) = |
charlesmn | 0:3ac96e360672 | 601 | pdata->system__interrupt_config_gpio; |
charlesmn | 0:3ac96e360672 | 602 | *(pbuffer + 3) = |
charlesmn | 0:3ac96e360672 | 603 | pdata->cal_config__vcsel_start & 0x7F; |
charlesmn | 0:3ac96e360672 | 604 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 605 | pdata->cal_config__repeat_rate & 0xFFF, |
charlesmn | 0:3ac96e360672 | 606 | 2, |
charlesmn | 0:3ac96e360672 | 607 | pbuffer + 4); |
charlesmn | 0:3ac96e360672 | 608 | *(pbuffer + 6) = |
charlesmn | 0:3ac96e360672 | 609 | pdata->global_config__vcsel_width & 0x7F; |
charlesmn | 0:3ac96e360672 | 610 | *(pbuffer + 7) = |
charlesmn | 0:3ac96e360672 | 611 | pdata->phasecal_config__timeout_macrop; |
charlesmn | 0:3ac96e360672 | 612 | *(pbuffer + 8) = |
charlesmn | 0:3ac96e360672 | 613 | pdata->phasecal_config__target; |
charlesmn | 0:3ac96e360672 | 614 | *(pbuffer + 9) = |
charlesmn | 0:3ac96e360672 | 615 | pdata->phasecal_config__override & 0x1; |
charlesmn | 0:3ac96e360672 | 616 | *(pbuffer + 11) = |
charlesmn | 0:3ac96e360672 | 617 | pdata->dss_config__roi_mode_control & 0x7; |
charlesmn | 0:3ac96e360672 | 618 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 619 | pdata->system__thresh_rate_high, |
charlesmn | 0:3ac96e360672 | 620 | 2, |
charlesmn | 0:3ac96e360672 | 621 | pbuffer + 12); |
charlesmn | 0:3ac96e360672 | 622 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 623 | pdata->system__thresh_rate_low, |
charlesmn | 0:3ac96e360672 | 624 | 2, |
charlesmn | 0:3ac96e360672 | 625 | pbuffer + 14); |
charlesmn | 0:3ac96e360672 | 626 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 627 | pdata->dss_config__manual_effective_spads_select, |
charlesmn | 0:3ac96e360672 | 628 | 2, |
charlesmn | 0:3ac96e360672 | 629 | pbuffer + 16); |
charlesmn | 0:3ac96e360672 | 630 | *(pbuffer + 18) = |
charlesmn | 0:3ac96e360672 | 631 | pdata->dss_config__manual_block_select; |
charlesmn | 0:3ac96e360672 | 632 | *(pbuffer + 19) = |
charlesmn | 0:3ac96e360672 | 633 | pdata->dss_config__aperture_attenuation; |
charlesmn | 0:3ac96e360672 | 634 | *(pbuffer + 20) = |
charlesmn | 0:3ac96e360672 | 635 | pdata->dss_config__max_spads_limit; |
charlesmn | 0:3ac96e360672 | 636 | *(pbuffer + 21) = |
charlesmn | 0:3ac96e360672 | 637 | pdata->dss_config__min_spads_limit; |
charlesmn | 0:3ac96e360672 | 638 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 639 | |
charlesmn | 0:3ac96e360672 | 640 | |
charlesmn | 0:3ac96e360672 | 641 | return status; |
charlesmn | 0:3ac96e360672 | 642 | } |
charlesmn | 0:3ac96e360672 | 643 | |
charlesmn | 0:3ac96e360672 | 644 | |
charlesmn | 0:3ac96e360672 | 645 | VL53L1_Error VL53L1_i2c_decode_general_config( |
charlesmn | 0:3ac96e360672 | 646 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 647 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 648 | VL53L1_general_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 649 | { |
charlesmn | 0:3ac96e360672 | 650 | |
charlesmn | 0:3ac96e360672 | 651 | |
charlesmn | 0:3ac96e360672 | 652 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 653 | |
charlesmn | 0:3ac96e360672 | 654 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 655 | |
charlesmn | 0:3ac96e360672 | 656 | if (buf_size < VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 657 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 658 | |
charlesmn | 0:3ac96e360672 | 659 | pdata->gph_config__stream_count_update_value = |
charlesmn | 0:3ac96e360672 | 660 | (*(pbuffer + 0)); |
charlesmn | 0:3ac96e360672 | 661 | pdata->global_config__stream_divider = |
charlesmn | 0:3ac96e360672 | 662 | (*(pbuffer + 1)); |
charlesmn | 0:3ac96e360672 | 663 | pdata->system__interrupt_config_gpio = |
charlesmn | 0:3ac96e360672 | 664 | (*(pbuffer + 2)); |
charlesmn | 0:3ac96e360672 | 665 | pdata->cal_config__vcsel_start = |
charlesmn | 0:3ac96e360672 | 666 | (*(pbuffer + 3)) & 0x7F; |
charlesmn | 0:3ac96e360672 | 667 | pdata->cal_config__repeat_rate = |
charlesmn | 0:3ac96e360672 | 668 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 4)) & 0xFFF; |
charlesmn | 0:3ac96e360672 | 669 | pdata->global_config__vcsel_width = |
charlesmn | 0:3ac96e360672 | 670 | (*(pbuffer + 6)) & 0x7F; |
charlesmn | 0:3ac96e360672 | 671 | pdata->phasecal_config__timeout_macrop = |
charlesmn | 0:3ac96e360672 | 672 | (*(pbuffer + 7)); |
charlesmn | 0:3ac96e360672 | 673 | pdata->phasecal_config__target = |
charlesmn | 0:3ac96e360672 | 674 | (*(pbuffer + 8)); |
charlesmn | 0:3ac96e360672 | 675 | pdata->phasecal_config__override = |
charlesmn | 0:3ac96e360672 | 676 | (*(pbuffer + 9)) & 0x1; |
charlesmn | 0:3ac96e360672 | 677 | pdata->dss_config__roi_mode_control = |
charlesmn | 0:3ac96e360672 | 678 | (*(pbuffer + 11)) & 0x7; |
charlesmn | 0:3ac96e360672 | 679 | pdata->system__thresh_rate_high = |
charlesmn | 0:3ac96e360672 | 680 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12)); |
charlesmn | 0:3ac96e360672 | 681 | pdata->system__thresh_rate_low = |
charlesmn | 0:3ac96e360672 | 682 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14)); |
charlesmn | 0:3ac96e360672 | 683 | pdata->dss_config__manual_effective_spads_select = |
charlesmn | 0:3ac96e360672 | 684 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16)); |
charlesmn | 0:3ac96e360672 | 685 | pdata->dss_config__manual_block_select = |
charlesmn | 0:3ac96e360672 | 686 | (*(pbuffer + 18)); |
charlesmn | 0:3ac96e360672 | 687 | pdata->dss_config__aperture_attenuation = |
charlesmn | 0:3ac96e360672 | 688 | (*(pbuffer + 19)); |
charlesmn | 0:3ac96e360672 | 689 | pdata->dss_config__max_spads_limit = |
charlesmn | 0:3ac96e360672 | 690 | (*(pbuffer + 20)); |
charlesmn | 0:3ac96e360672 | 691 | pdata->dss_config__min_spads_limit = |
charlesmn | 0:3ac96e360672 | 692 | (*(pbuffer + 21)); |
charlesmn | 0:3ac96e360672 | 693 | |
charlesmn | 0:3ac96e360672 | 694 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 695 | |
charlesmn | 0:3ac96e360672 | 696 | return status; |
charlesmn | 0:3ac96e360672 | 697 | } |
charlesmn | 0:3ac96e360672 | 698 | |
charlesmn | 0:3ac96e360672 | 699 | |
charlesmn | 0:3ac96e360672 | 700 | VL53L1_Error VL53L1_set_general_config( |
charlesmn | 0:3ac96e360672 | 701 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 702 | VL53L1_general_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 703 | { |
charlesmn | 0:3ac96e360672 | 704 | |
charlesmn | 0:3ac96e360672 | 705 | |
charlesmn | 0:3ac96e360672 | 706 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 707 | uint8_t comms_buffer[VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 708 | |
charlesmn | 0:3ac96e360672 | 709 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 710 | |
charlesmn | 0:3ac96e360672 | 711 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 712 | status = VL53L1_i2c_encode_general_config( |
charlesmn | 0:3ac96e360672 | 713 | pdata, |
charlesmn | 0:3ac96e360672 | 714 | VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 715 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 716 | |
charlesmn | 0:3ac96e360672 | 717 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 718 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 719 | Dev, |
charlesmn | 0:3ac96e360672 | 720 | VL53L1_GPH_CONFIG__STREAM_COUNT_UPDATE_VALUE, |
charlesmn | 0:3ac96e360672 | 721 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 722 | VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 723 | |
charlesmn | 0:3ac96e360672 | 724 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 725 | |
charlesmn | 0:3ac96e360672 | 726 | return status; |
charlesmn | 0:3ac96e360672 | 727 | } |
charlesmn | 0:3ac96e360672 | 728 | |
charlesmn | 0:3ac96e360672 | 729 | |
charlesmn | 0:3ac96e360672 | 730 | VL53L1_Error VL53L1_get_general_config( |
charlesmn | 0:3ac96e360672 | 731 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 732 | VL53L1_general_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 733 | { |
charlesmn | 0:3ac96e360672 | 734 | |
charlesmn | 0:3ac96e360672 | 735 | |
charlesmn | 0:3ac96e360672 | 736 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 737 | uint8_t comms_buffer[VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 738 | |
charlesmn | 0:3ac96e360672 | 739 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 740 | |
charlesmn | 0:3ac96e360672 | 741 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 742 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 743 | Dev, |
charlesmn | 0:3ac96e360672 | 744 | VL53L1_GPH_CONFIG__STREAM_COUNT_UPDATE_VALUE, |
charlesmn | 0:3ac96e360672 | 745 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 746 | VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 747 | |
charlesmn | 0:3ac96e360672 | 748 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 749 | status = VL53L1_i2c_decode_general_config( |
charlesmn | 0:3ac96e360672 | 750 | VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 751 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 752 | pdata); |
charlesmn | 0:3ac96e360672 | 753 | |
charlesmn | 0:3ac96e360672 | 754 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 755 | |
charlesmn | 0:3ac96e360672 | 756 | return status; |
charlesmn | 0:3ac96e360672 | 757 | } |
charlesmn | 0:3ac96e360672 | 758 | |
charlesmn | 0:3ac96e360672 | 759 | |
charlesmn | 0:3ac96e360672 | 760 | VL53L1_Error VL53L1_i2c_encode_timing_config( |
charlesmn | 0:3ac96e360672 | 761 | VL53L1_timing_config_t *pdata, |
charlesmn | 0:3ac96e360672 | 762 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 763 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 764 | { |
charlesmn | 0:3ac96e360672 | 765 | |
charlesmn | 0:3ac96e360672 | 766 | |
charlesmn | 0:3ac96e360672 | 767 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 768 | |
charlesmn | 0:3ac96e360672 | 769 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 770 | |
charlesmn | 0:3ac96e360672 | 771 | if (buf_size < VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 772 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 773 | |
charlesmn | 0:3ac96e360672 | 774 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 775 | pdata->mm_config__timeout_macrop_a_hi & 0xF; |
charlesmn | 0:3ac96e360672 | 776 | *(pbuffer + 1) = |
charlesmn | 0:3ac96e360672 | 777 | pdata->mm_config__timeout_macrop_a_lo; |
charlesmn | 0:3ac96e360672 | 778 | *(pbuffer + 2) = |
charlesmn | 0:3ac96e360672 | 779 | pdata->mm_config__timeout_macrop_b_hi & 0xF; |
charlesmn | 0:3ac96e360672 | 780 | *(pbuffer + 3) = |
charlesmn | 0:3ac96e360672 | 781 | pdata->mm_config__timeout_macrop_b_lo; |
charlesmn | 0:3ac96e360672 | 782 | *(pbuffer + 4) = |
charlesmn | 0:3ac96e360672 | 783 | pdata->range_config__timeout_macrop_a_hi & 0xF; |
charlesmn | 0:3ac96e360672 | 784 | *(pbuffer + 5) = |
charlesmn | 0:3ac96e360672 | 785 | pdata->range_config__timeout_macrop_a_lo; |
charlesmn | 0:3ac96e360672 | 786 | *(pbuffer + 6) = |
charlesmn | 0:3ac96e360672 | 787 | pdata->range_config__vcsel_period_a & 0x3F; |
charlesmn | 0:3ac96e360672 | 788 | *(pbuffer + 7) = |
charlesmn | 0:3ac96e360672 | 789 | pdata->range_config__timeout_macrop_b_hi & 0xF; |
charlesmn | 0:3ac96e360672 | 790 | *(pbuffer + 8) = |
charlesmn | 0:3ac96e360672 | 791 | pdata->range_config__timeout_macrop_b_lo; |
charlesmn | 0:3ac96e360672 | 792 | *(pbuffer + 9) = |
charlesmn | 0:3ac96e360672 | 793 | pdata->range_config__vcsel_period_b & 0x3F; |
charlesmn | 0:3ac96e360672 | 794 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 795 | pdata->range_config__sigma_thresh, |
charlesmn | 0:3ac96e360672 | 796 | 2, |
charlesmn | 0:3ac96e360672 | 797 | pbuffer + 10); |
charlesmn | 0:3ac96e360672 | 798 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 799 | pdata->range_config__min_count_rate_rtn_limit_mcps, |
charlesmn | 0:3ac96e360672 | 800 | 2, |
charlesmn | 0:3ac96e360672 | 801 | pbuffer + 12); |
charlesmn | 0:3ac96e360672 | 802 | *(pbuffer + 14) = |
charlesmn | 0:3ac96e360672 | 803 | pdata->range_config__valid_phase_low; |
charlesmn | 0:3ac96e360672 | 804 | *(pbuffer + 15) = |
charlesmn | 0:3ac96e360672 | 805 | pdata->range_config__valid_phase_high; |
charlesmn | 0:3ac96e360672 | 806 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 807 | pdata->system__intermeasurement_period, |
charlesmn | 0:3ac96e360672 | 808 | 4, |
charlesmn | 0:3ac96e360672 | 809 | pbuffer + 18); |
charlesmn | 0:3ac96e360672 | 810 | *(pbuffer + 22) = |
charlesmn | 0:3ac96e360672 | 811 | pdata->system__fractional_enable & 0x1; |
charlesmn | 0:3ac96e360672 | 812 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 813 | |
charlesmn | 0:3ac96e360672 | 814 | |
charlesmn | 0:3ac96e360672 | 815 | return status; |
charlesmn | 0:3ac96e360672 | 816 | } |
charlesmn | 0:3ac96e360672 | 817 | |
charlesmn | 0:3ac96e360672 | 818 | |
charlesmn | 0:3ac96e360672 | 819 | VL53L1_Error VL53L1_i2c_decode_timing_config( |
charlesmn | 0:3ac96e360672 | 820 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 821 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 822 | VL53L1_timing_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 823 | { |
charlesmn | 0:3ac96e360672 | 824 | |
charlesmn | 0:3ac96e360672 | 825 | |
charlesmn | 0:3ac96e360672 | 826 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 827 | |
charlesmn | 0:3ac96e360672 | 828 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 829 | |
charlesmn | 0:3ac96e360672 | 830 | if (buf_size < VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 831 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 832 | |
charlesmn | 0:3ac96e360672 | 833 | pdata->mm_config__timeout_macrop_a_hi = |
charlesmn | 0:3ac96e360672 | 834 | (*(pbuffer + 0)) & 0xF; |
charlesmn | 0:3ac96e360672 | 835 | pdata->mm_config__timeout_macrop_a_lo = |
charlesmn | 0:3ac96e360672 | 836 | (*(pbuffer + 1)); |
charlesmn | 0:3ac96e360672 | 837 | pdata->mm_config__timeout_macrop_b_hi = |
charlesmn | 0:3ac96e360672 | 838 | (*(pbuffer + 2)) & 0xF; |
charlesmn | 0:3ac96e360672 | 839 | pdata->mm_config__timeout_macrop_b_lo = |
charlesmn | 0:3ac96e360672 | 840 | (*(pbuffer + 3)); |
charlesmn | 0:3ac96e360672 | 841 | pdata->range_config__timeout_macrop_a_hi = |
charlesmn | 0:3ac96e360672 | 842 | (*(pbuffer + 4)) & 0xF; |
charlesmn | 0:3ac96e360672 | 843 | pdata->range_config__timeout_macrop_a_lo = |
charlesmn | 0:3ac96e360672 | 844 | (*(pbuffer + 5)); |
charlesmn | 0:3ac96e360672 | 845 | pdata->range_config__vcsel_period_a = |
charlesmn | 0:3ac96e360672 | 846 | (*(pbuffer + 6)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 847 | pdata->range_config__timeout_macrop_b_hi = |
charlesmn | 0:3ac96e360672 | 848 | (*(pbuffer + 7)) & 0xF; |
charlesmn | 0:3ac96e360672 | 849 | pdata->range_config__timeout_macrop_b_lo = |
charlesmn | 0:3ac96e360672 | 850 | (*(pbuffer + 8)); |
charlesmn | 0:3ac96e360672 | 851 | pdata->range_config__vcsel_period_b = |
charlesmn | 0:3ac96e360672 | 852 | (*(pbuffer + 9)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 853 | pdata->range_config__sigma_thresh = |
charlesmn | 0:3ac96e360672 | 854 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10)); |
charlesmn | 0:3ac96e360672 | 855 | pdata->range_config__min_count_rate_rtn_limit_mcps = |
charlesmn | 0:3ac96e360672 | 856 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12)); |
charlesmn | 0:3ac96e360672 | 857 | pdata->range_config__valid_phase_low = |
charlesmn | 0:3ac96e360672 | 858 | (*(pbuffer + 14)); |
charlesmn | 0:3ac96e360672 | 859 | pdata->range_config__valid_phase_high = |
charlesmn | 0:3ac96e360672 | 860 | (*(pbuffer + 15)); |
charlesmn | 0:3ac96e360672 | 861 | pdata->system__intermeasurement_period = |
charlesmn | 0:3ac96e360672 | 862 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 18)); |
charlesmn | 0:3ac96e360672 | 863 | pdata->system__fractional_enable = |
charlesmn | 0:3ac96e360672 | 864 | (*(pbuffer + 22)) & 0x1; |
charlesmn | 0:3ac96e360672 | 865 | |
charlesmn | 0:3ac96e360672 | 866 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 867 | |
charlesmn | 0:3ac96e360672 | 868 | return status; |
charlesmn | 0:3ac96e360672 | 869 | } |
charlesmn | 0:3ac96e360672 | 870 | |
charlesmn | 0:3ac96e360672 | 871 | |
charlesmn | 0:3ac96e360672 | 872 | VL53L1_Error VL53L1_set_timing_config( |
charlesmn | 0:3ac96e360672 | 873 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 874 | VL53L1_timing_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 875 | { |
charlesmn | 0:3ac96e360672 | 876 | |
charlesmn | 0:3ac96e360672 | 877 | |
charlesmn | 0:3ac96e360672 | 878 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 879 | uint8_t comms_buffer[VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 880 | |
charlesmn | 0:3ac96e360672 | 881 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 882 | |
charlesmn | 0:3ac96e360672 | 883 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 884 | status = VL53L1_i2c_encode_timing_config( |
charlesmn | 0:3ac96e360672 | 885 | pdata, |
charlesmn | 0:3ac96e360672 | 886 | VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 887 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 888 | |
charlesmn | 0:3ac96e360672 | 889 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 890 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 891 | Dev, |
charlesmn | 0:3ac96e360672 | 892 | VL53L1_MM_CONFIG__TIMEOUT_MACROP_A_HI, |
charlesmn | 0:3ac96e360672 | 893 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 894 | VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 895 | |
charlesmn | 0:3ac96e360672 | 896 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 897 | |
charlesmn | 0:3ac96e360672 | 898 | return status; |
charlesmn | 0:3ac96e360672 | 899 | } |
charlesmn | 0:3ac96e360672 | 900 | |
charlesmn | 0:3ac96e360672 | 901 | |
charlesmn | 0:3ac96e360672 | 902 | VL53L1_Error VL53L1_get_timing_config( |
charlesmn | 0:3ac96e360672 | 903 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 904 | VL53L1_timing_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 905 | { |
charlesmn | 0:3ac96e360672 | 906 | |
charlesmn | 0:3ac96e360672 | 907 | |
charlesmn | 0:3ac96e360672 | 908 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 909 | uint8_t comms_buffer[VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 910 | |
charlesmn | 0:3ac96e360672 | 911 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 912 | |
charlesmn | 0:3ac96e360672 | 913 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 914 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 915 | Dev, |
charlesmn | 0:3ac96e360672 | 916 | VL53L1_MM_CONFIG__TIMEOUT_MACROP_A_HI, |
charlesmn | 0:3ac96e360672 | 917 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 918 | VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 919 | |
charlesmn | 0:3ac96e360672 | 920 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 921 | status = VL53L1_i2c_decode_timing_config( |
charlesmn | 0:3ac96e360672 | 922 | VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 923 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 924 | pdata); |
charlesmn | 0:3ac96e360672 | 925 | |
charlesmn | 0:3ac96e360672 | 926 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 927 | |
charlesmn | 0:3ac96e360672 | 928 | return status; |
charlesmn | 0:3ac96e360672 | 929 | } |
charlesmn | 0:3ac96e360672 | 930 | |
charlesmn | 0:3ac96e360672 | 931 | |
charlesmn | 0:3ac96e360672 | 932 | VL53L1_Error VL53L1_i2c_encode_dynamic_config( |
charlesmn | 0:3ac96e360672 | 933 | VL53L1_dynamic_config_t *pdata, |
charlesmn | 0:3ac96e360672 | 934 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 935 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 936 | { |
charlesmn | 0:3ac96e360672 | 937 | |
charlesmn | 0:3ac96e360672 | 938 | |
charlesmn | 0:3ac96e360672 | 939 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 940 | |
charlesmn | 0:3ac96e360672 | 941 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 942 | |
charlesmn | 0:3ac96e360672 | 943 | if (buf_size < VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 944 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 945 | |
charlesmn | 0:3ac96e360672 | 946 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 947 | pdata->system__grouped_parameter_hold_0 & 0x3; |
charlesmn | 0:3ac96e360672 | 948 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 949 | pdata->system__thresh_high, |
charlesmn | 0:3ac96e360672 | 950 | 2, |
charlesmn | 0:3ac96e360672 | 951 | pbuffer + 1); |
charlesmn | 0:3ac96e360672 | 952 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 953 | pdata->system__thresh_low, |
charlesmn | 0:3ac96e360672 | 954 | 2, |
charlesmn | 0:3ac96e360672 | 955 | pbuffer + 3); |
charlesmn | 0:3ac96e360672 | 956 | *(pbuffer + 5) = |
charlesmn | 0:3ac96e360672 | 957 | pdata->system__enable_xtalk_per_quadrant & 0x1; |
charlesmn | 0:3ac96e360672 | 958 | *(pbuffer + 6) = |
charlesmn | 0:3ac96e360672 | 959 | pdata->system__seed_config & 0x7; |
charlesmn | 0:3ac96e360672 | 960 | *(pbuffer + 7) = |
charlesmn | 0:3ac96e360672 | 961 | pdata->sd_config__woi_sd0; |
charlesmn | 0:3ac96e360672 | 962 | *(pbuffer + 8) = |
charlesmn | 0:3ac96e360672 | 963 | pdata->sd_config__woi_sd1; |
charlesmn | 0:3ac96e360672 | 964 | *(pbuffer + 9) = |
charlesmn | 0:3ac96e360672 | 965 | pdata->sd_config__initial_phase_sd0 & 0x7F; |
charlesmn | 0:3ac96e360672 | 966 | *(pbuffer + 10) = |
charlesmn | 0:3ac96e360672 | 967 | pdata->sd_config__initial_phase_sd1 & 0x7F; |
charlesmn | 0:3ac96e360672 | 968 | *(pbuffer + 11) = |
charlesmn | 0:3ac96e360672 | 969 | pdata->system__grouped_parameter_hold_1 & 0x3; |
charlesmn | 0:3ac96e360672 | 970 | *(pbuffer + 12) = |
charlesmn | 0:3ac96e360672 | 971 | pdata->sd_config__first_order_select & 0x3; |
charlesmn | 0:3ac96e360672 | 972 | *(pbuffer + 13) = |
charlesmn | 0:3ac96e360672 | 973 | pdata->sd_config__quantifier & 0xF; |
charlesmn | 0:3ac96e360672 | 974 | *(pbuffer + 14) = |
charlesmn | 0:3ac96e360672 | 975 | pdata->roi_config__user_roi_centre_spad; |
charlesmn | 0:3ac96e360672 | 976 | *(pbuffer + 15) = |
charlesmn | 0:3ac96e360672 | 977 | pdata->roi_config__user_roi_requested_global_xy_size; |
charlesmn | 0:3ac96e360672 | 978 | *(pbuffer + 16) = |
charlesmn | 0:3ac96e360672 | 979 | pdata->system__sequence_config; |
charlesmn | 0:3ac96e360672 | 980 | *(pbuffer + 17) = |
charlesmn | 0:3ac96e360672 | 981 | pdata->system__grouped_parameter_hold & 0x3; |
charlesmn | 0:3ac96e360672 | 982 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 983 | |
charlesmn | 0:3ac96e360672 | 984 | |
charlesmn | 0:3ac96e360672 | 985 | return status; |
charlesmn | 0:3ac96e360672 | 986 | } |
charlesmn | 0:3ac96e360672 | 987 | |
charlesmn | 0:3ac96e360672 | 988 | |
charlesmn | 0:3ac96e360672 | 989 | VL53L1_Error VL53L1_i2c_decode_dynamic_config( |
charlesmn | 0:3ac96e360672 | 990 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 991 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 992 | VL53L1_dynamic_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 993 | { |
charlesmn | 0:3ac96e360672 | 994 | |
charlesmn | 0:3ac96e360672 | 995 | |
charlesmn | 0:3ac96e360672 | 996 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 997 | |
charlesmn | 0:3ac96e360672 | 998 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 999 | |
charlesmn | 0:3ac96e360672 | 1000 | if (buf_size < VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 1001 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 1002 | |
charlesmn | 0:3ac96e360672 | 1003 | pdata->system__grouped_parameter_hold_0 = |
charlesmn | 0:3ac96e360672 | 1004 | (*(pbuffer + 0)) & 0x3; |
charlesmn | 0:3ac96e360672 | 1005 | pdata->system__thresh_high = |
charlesmn | 0:3ac96e360672 | 1006 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 1)); |
charlesmn | 0:3ac96e360672 | 1007 | pdata->system__thresh_low = |
charlesmn | 0:3ac96e360672 | 1008 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 3)); |
charlesmn | 0:3ac96e360672 | 1009 | pdata->system__enable_xtalk_per_quadrant = |
charlesmn | 0:3ac96e360672 | 1010 | (*(pbuffer + 5)) & 0x1; |
charlesmn | 0:3ac96e360672 | 1011 | pdata->system__seed_config = |
charlesmn | 0:3ac96e360672 | 1012 | (*(pbuffer + 6)) & 0x7; |
charlesmn | 0:3ac96e360672 | 1013 | pdata->sd_config__woi_sd0 = |
charlesmn | 0:3ac96e360672 | 1014 | (*(pbuffer + 7)); |
charlesmn | 0:3ac96e360672 | 1015 | pdata->sd_config__woi_sd1 = |
charlesmn | 0:3ac96e360672 | 1016 | (*(pbuffer + 8)); |
charlesmn | 0:3ac96e360672 | 1017 | pdata->sd_config__initial_phase_sd0 = |
charlesmn | 0:3ac96e360672 | 1018 | (*(pbuffer + 9)) & 0x7F; |
charlesmn | 0:3ac96e360672 | 1019 | pdata->sd_config__initial_phase_sd1 = |
charlesmn | 0:3ac96e360672 | 1020 | (*(pbuffer + 10)) & 0x7F; |
charlesmn | 0:3ac96e360672 | 1021 | pdata->system__grouped_parameter_hold_1 = |
charlesmn | 0:3ac96e360672 | 1022 | (*(pbuffer + 11)) & 0x3; |
charlesmn | 0:3ac96e360672 | 1023 | pdata->sd_config__first_order_select = |
charlesmn | 0:3ac96e360672 | 1024 | (*(pbuffer + 12)) & 0x3; |
charlesmn | 0:3ac96e360672 | 1025 | pdata->sd_config__quantifier = |
charlesmn | 0:3ac96e360672 | 1026 | (*(pbuffer + 13)) & 0xF; |
charlesmn | 0:3ac96e360672 | 1027 | pdata->roi_config__user_roi_centre_spad = |
charlesmn | 0:3ac96e360672 | 1028 | (*(pbuffer + 14)); |
charlesmn | 0:3ac96e360672 | 1029 | pdata->roi_config__user_roi_requested_global_xy_size = |
charlesmn | 0:3ac96e360672 | 1030 | (*(pbuffer + 15)); |
charlesmn | 0:3ac96e360672 | 1031 | pdata->system__sequence_config = |
charlesmn | 0:3ac96e360672 | 1032 | (*(pbuffer + 16)); |
charlesmn | 0:3ac96e360672 | 1033 | pdata->system__grouped_parameter_hold = |
charlesmn | 0:3ac96e360672 | 1034 | (*(pbuffer + 17)) & 0x3; |
charlesmn | 0:3ac96e360672 | 1035 | |
charlesmn | 0:3ac96e360672 | 1036 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1037 | |
charlesmn | 0:3ac96e360672 | 1038 | return status; |
charlesmn | 0:3ac96e360672 | 1039 | } |
charlesmn | 0:3ac96e360672 | 1040 | |
charlesmn | 0:3ac96e360672 | 1041 | |
charlesmn | 0:3ac96e360672 | 1042 | VL53L1_Error VL53L1_set_dynamic_config( |
charlesmn | 0:3ac96e360672 | 1043 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1044 | VL53L1_dynamic_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 1045 | { |
charlesmn | 0:3ac96e360672 | 1046 | |
charlesmn | 0:3ac96e360672 | 1047 | |
charlesmn | 0:3ac96e360672 | 1048 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1049 | uint8_t comms_buffer[VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 1050 | |
charlesmn | 0:3ac96e360672 | 1051 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1052 | |
charlesmn | 0:3ac96e360672 | 1053 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1054 | status = VL53L1_i2c_encode_dynamic_config( |
charlesmn | 0:3ac96e360672 | 1055 | pdata, |
charlesmn | 0:3ac96e360672 | 1056 | VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 1057 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 1058 | |
charlesmn | 0:3ac96e360672 | 1059 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1060 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 1061 | Dev, |
charlesmn | 0:3ac96e360672 | 1062 | VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD_0, |
charlesmn | 0:3ac96e360672 | 1063 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1064 | VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 1065 | |
charlesmn | 0:3ac96e360672 | 1066 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1067 | |
charlesmn | 0:3ac96e360672 | 1068 | return status; |
charlesmn | 0:3ac96e360672 | 1069 | } |
charlesmn | 0:3ac96e360672 | 1070 | |
charlesmn | 0:3ac96e360672 | 1071 | |
charlesmn | 0:3ac96e360672 | 1072 | VL53L1_Error VL53L1_get_dynamic_config( |
charlesmn | 0:3ac96e360672 | 1073 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1074 | VL53L1_dynamic_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 1075 | { |
charlesmn | 0:3ac96e360672 | 1076 | |
charlesmn | 0:3ac96e360672 | 1077 | |
charlesmn | 0:3ac96e360672 | 1078 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1079 | uint8_t comms_buffer[VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 1080 | |
charlesmn | 0:3ac96e360672 | 1081 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1082 | |
charlesmn | 0:3ac96e360672 | 1083 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1084 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 1085 | Dev, |
charlesmn | 0:3ac96e360672 | 1086 | VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD_0, |
charlesmn | 0:3ac96e360672 | 1087 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1088 | VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 1089 | |
charlesmn | 0:3ac96e360672 | 1090 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1091 | status = VL53L1_i2c_decode_dynamic_config( |
charlesmn | 0:3ac96e360672 | 1092 | VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 1093 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1094 | pdata); |
charlesmn | 0:3ac96e360672 | 1095 | |
charlesmn | 0:3ac96e360672 | 1096 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1097 | |
charlesmn | 0:3ac96e360672 | 1098 | return status; |
charlesmn | 0:3ac96e360672 | 1099 | } |
charlesmn | 0:3ac96e360672 | 1100 | |
charlesmn | 0:3ac96e360672 | 1101 | |
charlesmn | 0:3ac96e360672 | 1102 | VL53L1_Error VL53L1_i2c_encode_system_control( |
charlesmn | 0:3ac96e360672 | 1103 | VL53L1_system_control_t *pdata, |
charlesmn | 0:3ac96e360672 | 1104 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 1105 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 1106 | { |
charlesmn | 0:3ac96e360672 | 1107 | |
charlesmn | 0:3ac96e360672 | 1108 | |
charlesmn | 0:3ac96e360672 | 1109 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1110 | |
charlesmn | 0:3ac96e360672 | 1111 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1112 | |
charlesmn | 0:3ac96e360672 | 1113 | if (buf_size < VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 1114 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 1115 | |
charlesmn | 0:3ac96e360672 | 1116 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 1117 | pdata->power_management__go1_power_force & 0x1; |
charlesmn | 0:3ac96e360672 | 1118 | *(pbuffer + 1) = |
charlesmn | 0:3ac96e360672 | 1119 | pdata->system__stream_count_ctrl & 0x1; |
charlesmn | 0:3ac96e360672 | 1120 | *(pbuffer + 2) = |
charlesmn | 0:3ac96e360672 | 1121 | pdata->firmware__enable & 0x1; |
charlesmn | 0:3ac96e360672 | 1122 | *(pbuffer + 3) = |
charlesmn | 0:3ac96e360672 | 1123 | pdata->system__interrupt_clear & 0x3; |
charlesmn | 0:3ac96e360672 | 1124 | *(pbuffer + 4) = |
charlesmn | 0:3ac96e360672 | 1125 | pdata->system__mode_start; |
charlesmn | 0:3ac96e360672 | 1126 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1127 | |
charlesmn | 0:3ac96e360672 | 1128 | |
charlesmn | 0:3ac96e360672 | 1129 | return status; |
charlesmn | 0:3ac96e360672 | 1130 | } |
charlesmn | 0:3ac96e360672 | 1131 | |
charlesmn | 0:3ac96e360672 | 1132 | |
charlesmn | 0:3ac96e360672 | 1133 | VL53L1_Error VL53L1_i2c_decode_system_control( |
charlesmn | 0:3ac96e360672 | 1134 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 1135 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 1136 | VL53L1_system_control_t *pdata) |
charlesmn | 0:3ac96e360672 | 1137 | { |
charlesmn | 0:3ac96e360672 | 1138 | |
charlesmn | 0:3ac96e360672 | 1139 | |
charlesmn | 0:3ac96e360672 | 1140 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1141 | |
charlesmn | 0:3ac96e360672 | 1142 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1143 | |
charlesmn | 0:3ac96e360672 | 1144 | if (buf_size < VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 1145 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 1146 | |
charlesmn | 0:3ac96e360672 | 1147 | pdata->power_management__go1_power_force = |
charlesmn | 0:3ac96e360672 | 1148 | (*(pbuffer + 0)) & 0x1; |
charlesmn | 0:3ac96e360672 | 1149 | pdata->system__stream_count_ctrl = |
charlesmn | 0:3ac96e360672 | 1150 | (*(pbuffer + 1)) & 0x1; |
charlesmn | 0:3ac96e360672 | 1151 | pdata->firmware__enable = |
charlesmn | 0:3ac96e360672 | 1152 | (*(pbuffer + 2)) & 0x1; |
charlesmn | 0:3ac96e360672 | 1153 | pdata->system__interrupt_clear = |
charlesmn | 0:3ac96e360672 | 1154 | (*(pbuffer + 3)) & 0x3; |
charlesmn | 0:3ac96e360672 | 1155 | pdata->system__mode_start = |
charlesmn | 0:3ac96e360672 | 1156 | (*(pbuffer + 4)); |
charlesmn | 0:3ac96e360672 | 1157 | |
charlesmn | 0:3ac96e360672 | 1158 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1159 | |
charlesmn | 0:3ac96e360672 | 1160 | return status; |
charlesmn | 0:3ac96e360672 | 1161 | } |
charlesmn | 0:3ac96e360672 | 1162 | |
charlesmn | 0:3ac96e360672 | 1163 | |
charlesmn | 0:3ac96e360672 | 1164 | VL53L1_Error VL53L1_set_system_control( |
charlesmn | 0:3ac96e360672 | 1165 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1166 | VL53L1_system_control_t *pdata) |
charlesmn | 0:3ac96e360672 | 1167 | { |
charlesmn | 0:3ac96e360672 | 1168 | |
charlesmn | 0:3ac96e360672 | 1169 | |
charlesmn | 0:3ac96e360672 | 1170 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1171 | uint8_t comms_buffer[VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 1172 | |
charlesmn | 0:3ac96e360672 | 1173 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1174 | |
charlesmn | 0:3ac96e360672 | 1175 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1176 | status = VL53L1_i2c_encode_system_control( |
charlesmn | 0:3ac96e360672 | 1177 | pdata, |
charlesmn | 0:3ac96e360672 | 1178 | VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 1179 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 1180 | |
charlesmn | 0:3ac96e360672 | 1181 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1182 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 1183 | Dev, |
charlesmn | 0:3ac96e360672 | 1184 | VL53L1_POWER_MANAGEMENT__GO1_POWER_FORCE, |
charlesmn | 0:3ac96e360672 | 1185 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1186 | VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 1187 | |
charlesmn | 0:3ac96e360672 | 1188 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1189 | |
charlesmn | 0:3ac96e360672 | 1190 | return status; |
charlesmn | 0:3ac96e360672 | 1191 | } |
charlesmn | 0:3ac96e360672 | 1192 | |
charlesmn | 0:3ac96e360672 | 1193 | |
charlesmn | 0:3ac96e360672 | 1194 | VL53L1_Error VL53L1_get_system_control( |
charlesmn | 0:3ac96e360672 | 1195 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1196 | VL53L1_system_control_t *pdata) |
charlesmn | 0:3ac96e360672 | 1197 | { |
charlesmn | 0:3ac96e360672 | 1198 | |
charlesmn | 0:3ac96e360672 | 1199 | |
charlesmn | 0:3ac96e360672 | 1200 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1201 | uint8_t comms_buffer[VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 1202 | |
charlesmn | 0:3ac96e360672 | 1203 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1204 | |
charlesmn | 0:3ac96e360672 | 1205 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1206 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 1207 | Dev, |
charlesmn | 0:3ac96e360672 | 1208 | VL53L1_POWER_MANAGEMENT__GO1_POWER_FORCE, |
charlesmn | 0:3ac96e360672 | 1209 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1210 | VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 1211 | |
charlesmn | 0:3ac96e360672 | 1212 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1213 | status = VL53L1_i2c_decode_system_control( |
charlesmn | 0:3ac96e360672 | 1214 | VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 1215 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1216 | pdata); |
charlesmn | 0:3ac96e360672 | 1217 | |
charlesmn | 0:3ac96e360672 | 1218 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1219 | |
charlesmn | 0:3ac96e360672 | 1220 | return status; |
charlesmn | 0:3ac96e360672 | 1221 | } |
charlesmn | 0:3ac96e360672 | 1222 | |
charlesmn | 0:3ac96e360672 | 1223 | |
charlesmn | 0:3ac96e360672 | 1224 | VL53L1_Error VL53L1_i2c_encode_system_results( |
charlesmn | 0:3ac96e360672 | 1225 | VL53L1_system_results_t *pdata, |
charlesmn | 0:3ac96e360672 | 1226 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 1227 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 1228 | { |
charlesmn | 0:3ac96e360672 | 1229 | |
charlesmn | 0:3ac96e360672 | 1230 | |
charlesmn | 0:3ac96e360672 | 1231 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1232 | |
charlesmn | 0:3ac96e360672 | 1233 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1234 | |
charlesmn | 0:3ac96e360672 | 1235 | if (buf_size < VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 1236 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 1237 | |
charlesmn | 0:3ac96e360672 | 1238 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 1239 | pdata->result__interrupt_status & 0x3F; |
charlesmn | 0:3ac96e360672 | 1240 | *(pbuffer + 1) = |
charlesmn | 0:3ac96e360672 | 1241 | pdata->result__range_status; |
charlesmn | 0:3ac96e360672 | 1242 | *(pbuffer + 2) = |
charlesmn | 0:3ac96e360672 | 1243 | pdata->result__report_status & 0xF; |
charlesmn | 0:3ac96e360672 | 1244 | *(pbuffer + 3) = |
charlesmn | 0:3ac96e360672 | 1245 | pdata->result__stream_count; |
charlesmn | 0:3ac96e360672 | 1246 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1247 | pdata->result__dss_actual_effective_spads_sd0, |
charlesmn | 0:3ac96e360672 | 1248 | 2, |
charlesmn | 0:3ac96e360672 | 1249 | pbuffer + 4); |
charlesmn | 0:3ac96e360672 | 1250 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1251 | pdata->result__peak_signal_count_rate_mcps_sd0, |
charlesmn | 0:3ac96e360672 | 1252 | 2, |
charlesmn | 0:3ac96e360672 | 1253 | pbuffer + 6); |
charlesmn | 0:3ac96e360672 | 1254 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1255 | pdata->result__ambient_count_rate_mcps_sd0, |
charlesmn | 0:3ac96e360672 | 1256 | 2, |
charlesmn | 0:3ac96e360672 | 1257 | pbuffer + 8); |
charlesmn | 0:3ac96e360672 | 1258 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1259 | pdata->result__sigma_sd0, |
charlesmn | 0:3ac96e360672 | 1260 | 2, |
charlesmn | 0:3ac96e360672 | 1261 | pbuffer + 10); |
charlesmn | 0:3ac96e360672 | 1262 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1263 | pdata->result__phase_sd0, |
charlesmn | 0:3ac96e360672 | 1264 | 2, |
charlesmn | 0:3ac96e360672 | 1265 | pbuffer + 12); |
charlesmn | 0:3ac96e360672 | 1266 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1267 | pdata->result__final_crosstalk_corrected_range_mm_sd0, |
charlesmn | 0:3ac96e360672 | 1268 | 2, |
charlesmn | 0:3ac96e360672 | 1269 | pbuffer + 14); |
charlesmn | 0:3ac96e360672 | 1270 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1271 | pdata->result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0, |
charlesmn | 0:3ac96e360672 | 1272 | 2, |
charlesmn | 0:3ac96e360672 | 1273 | pbuffer + 16); |
charlesmn | 0:3ac96e360672 | 1274 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1275 | pdata->result__mm_inner_actual_effective_spads_sd0, |
charlesmn | 0:3ac96e360672 | 1276 | 2, |
charlesmn | 0:3ac96e360672 | 1277 | pbuffer + 18); |
charlesmn | 0:3ac96e360672 | 1278 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1279 | pdata->result__mm_outer_actual_effective_spads_sd0, |
charlesmn | 0:3ac96e360672 | 1280 | 2, |
charlesmn | 0:3ac96e360672 | 1281 | pbuffer + 20); |
charlesmn | 0:3ac96e360672 | 1282 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1283 | pdata->result__avg_signal_count_rate_mcps_sd0, |
charlesmn | 0:3ac96e360672 | 1284 | 2, |
charlesmn | 0:3ac96e360672 | 1285 | pbuffer + 22); |
charlesmn | 0:3ac96e360672 | 1286 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1287 | pdata->result__dss_actual_effective_spads_sd1, |
charlesmn | 0:3ac96e360672 | 1288 | 2, |
charlesmn | 0:3ac96e360672 | 1289 | pbuffer + 24); |
charlesmn | 0:3ac96e360672 | 1290 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1291 | pdata->result__peak_signal_count_rate_mcps_sd1, |
charlesmn | 0:3ac96e360672 | 1292 | 2, |
charlesmn | 0:3ac96e360672 | 1293 | pbuffer + 26); |
charlesmn | 0:3ac96e360672 | 1294 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1295 | pdata->result__ambient_count_rate_mcps_sd1, |
charlesmn | 0:3ac96e360672 | 1296 | 2, |
charlesmn | 0:3ac96e360672 | 1297 | pbuffer + 28); |
charlesmn | 0:3ac96e360672 | 1298 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1299 | pdata->result__sigma_sd1, |
charlesmn | 0:3ac96e360672 | 1300 | 2, |
charlesmn | 0:3ac96e360672 | 1301 | pbuffer + 30); |
charlesmn | 0:3ac96e360672 | 1302 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1303 | pdata->result__phase_sd1, |
charlesmn | 0:3ac96e360672 | 1304 | 2, |
charlesmn | 0:3ac96e360672 | 1305 | pbuffer + 32); |
charlesmn | 0:3ac96e360672 | 1306 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1307 | pdata->result__final_crosstalk_corrected_range_mm_sd1, |
charlesmn | 0:3ac96e360672 | 1308 | 2, |
charlesmn | 0:3ac96e360672 | 1309 | pbuffer + 34); |
charlesmn | 0:3ac96e360672 | 1310 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1311 | pdata->result__spare_0_sd1, |
charlesmn | 0:3ac96e360672 | 1312 | 2, |
charlesmn | 0:3ac96e360672 | 1313 | pbuffer + 36); |
charlesmn | 0:3ac96e360672 | 1314 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1315 | pdata->result__spare_1_sd1, |
charlesmn | 0:3ac96e360672 | 1316 | 2, |
charlesmn | 0:3ac96e360672 | 1317 | pbuffer + 38); |
charlesmn | 0:3ac96e360672 | 1318 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1319 | pdata->result__spare_2_sd1, |
charlesmn | 0:3ac96e360672 | 1320 | 2, |
charlesmn | 0:3ac96e360672 | 1321 | pbuffer + 40); |
charlesmn | 0:3ac96e360672 | 1322 | *(pbuffer + 42) = |
charlesmn | 0:3ac96e360672 | 1323 | pdata->result__spare_3_sd1; |
charlesmn | 0:3ac96e360672 | 1324 | *(pbuffer + 43) = |
charlesmn | 0:3ac96e360672 | 1325 | pdata->result__thresh_info; |
charlesmn | 0:3ac96e360672 | 1326 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1327 | |
charlesmn | 0:3ac96e360672 | 1328 | |
charlesmn | 0:3ac96e360672 | 1329 | return status; |
charlesmn | 0:3ac96e360672 | 1330 | } |
charlesmn | 0:3ac96e360672 | 1331 | |
charlesmn | 0:3ac96e360672 | 1332 | |
charlesmn | 0:3ac96e360672 | 1333 | VL53L1_Error VL53L1_i2c_decode_system_results( |
charlesmn | 0:3ac96e360672 | 1334 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 1335 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 1336 | VL53L1_system_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 1337 | { |
charlesmn | 0:3ac96e360672 | 1338 | |
charlesmn | 0:3ac96e360672 | 1339 | |
charlesmn | 0:3ac96e360672 | 1340 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1341 | |
charlesmn | 0:3ac96e360672 | 1342 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1343 | |
charlesmn | 0:3ac96e360672 | 1344 | if (buf_size < VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 1345 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 1346 | |
charlesmn | 0:3ac96e360672 | 1347 | pdata->result__interrupt_status = |
charlesmn | 0:3ac96e360672 | 1348 | (*(pbuffer + 0)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 1349 | pdata->result__range_status = |
charlesmn | 0:3ac96e360672 | 1350 | (*(pbuffer + 1)); |
charlesmn | 0:3ac96e360672 | 1351 | pdata->result__report_status = |
charlesmn | 0:3ac96e360672 | 1352 | (*(pbuffer + 2)) & 0xF; |
charlesmn | 0:3ac96e360672 | 1353 | pdata->result__stream_count = |
charlesmn | 0:3ac96e360672 | 1354 | (*(pbuffer + 3)); |
charlesmn | 0:3ac96e360672 | 1355 | pdata->result__dss_actual_effective_spads_sd0 = |
charlesmn | 0:3ac96e360672 | 1356 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 4)); |
charlesmn | 0:3ac96e360672 | 1357 | pdata->result__peak_signal_count_rate_mcps_sd0 = |
charlesmn | 0:3ac96e360672 | 1358 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 6)); |
charlesmn | 0:3ac96e360672 | 1359 | pdata->result__ambient_count_rate_mcps_sd0 = |
charlesmn | 0:3ac96e360672 | 1360 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8)); |
charlesmn | 0:3ac96e360672 | 1361 | pdata->result__sigma_sd0 = |
charlesmn | 0:3ac96e360672 | 1362 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10)); |
charlesmn | 0:3ac96e360672 | 1363 | pdata->result__phase_sd0 = |
charlesmn | 0:3ac96e360672 | 1364 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12)); |
charlesmn | 0:3ac96e360672 | 1365 | pdata->result__final_crosstalk_corrected_range_mm_sd0 = |
charlesmn | 0:3ac96e360672 | 1366 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14)); |
charlesmn | 0:3ac96e360672 | 1367 | pdata->result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0 = |
charlesmn | 0:3ac96e360672 | 1368 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16)); |
charlesmn | 0:3ac96e360672 | 1369 | pdata->result__mm_inner_actual_effective_spads_sd0 = |
charlesmn | 0:3ac96e360672 | 1370 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18)); |
charlesmn | 0:3ac96e360672 | 1371 | pdata->result__mm_outer_actual_effective_spads_sd0 = |
charlesmn | 0:3ac96e360672 | 1372 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 20)); |
charlesmn | 0:3ac96e360672 | 1373 | pdata->result__avg_signal_count_rate_mcps_sd0 = |
charlesmn | 0:3ac96e360672 | 1374 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22)); |
charlesmn | 0:3ac96e360672 | 1375 | pdata->result__dss_actual_effective_spads_sd1 = |
charlesmn | 0:3ac96e360672 | 1376 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24)); |
charlesmn | 0:3ac96e360672 | 1377 | pdata->result__peak_signal_count_rate_mcps_sd1 = |
charlesmn | 0:3ac96e360672 | 1378 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 26)); |
charlesmn | 0:3ac96e360672 | 1379 | pdata->result__ambient_count_rate_mcps_sd1 = |
charlesmn | 0:3ac96e360672 | 1380 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 28)); |
charlesmn | 0:3ac96e360672 | 1381 | pdata->result__sigma_sd1 = |
charlesmn | 0:3ac96e360672 | 1382 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 30)); |
charlesmn | 0:3ac96e360672 | 1383 | pdata->result__phase_sd1 = |
charlesmn | 0:3ac96e360672 | 1384 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 32)); |
charlesmn | 0:3ac96e360672 | 1385 | pdata->result__final_crosstalk_corrected_range_mm_sd1 = |
charlesmn | 0:3ac96e360672 | 1386 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 34)); |
charlesmn | 0:3ac96e360672 | 1387 | pdata->result__spare_0_sd1 = |
charlesmn | 0:3ac96e360672 | 1388 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 36)); |
charlesmn | 0:3ac96e360672 | 1389 | pdata->result__spare_1_sd1 = |
charlesmn | 0:3ac96e360672 | 1390 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 38)); |
charlesmn | 0:3ac96e360672 | 1391 | pdata->result__spare_2_sd1 = |
charlesmn | 0:3ac96e360672 | 1392 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 40)); |
charlesmn | 0:3ac96e360672 | 1393 | pdata->result__spare_3_sd1 = |
charlesmn | 0:3ac96e360672 | 1394 | (*(pbuffer + 42)); |
charlesmn | 0:3ac96e360672 | 1395 | pdata->result__thresh_info = |
charlesmn | 0:3ac96e360672 | 1396 | (*(pbuffer + 43)); |
charlesmn | 0:3ac96e360672 | 1397 | |
charlesmn | 0:3ac96e360672 | 1398 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1399 | |
charlesmn | 0:3ac96e360672 | 1400 | return status; |
charlesmn | 0:3ac96e360672 | 1401 | } |
charlesmn | 0:3ac96e360672 | 1402 | |
charlesmn | 0:3ac96e360672 | 1403 | |
charlesmn | 0:3ac96e360672 | 1404 | VL53L1_Error VL53L1_set_system_results( |
charlesmn | 0:3ac96e360672 | 1405 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1406 | VL53L1_system_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 1407 | { |
charlesmn | 0:3ac96e360672 | 1408 | |
charlesmn | 0:3ac96e360672 | 1409 | |
charlesmn | 0:3ac96e360672 | 1410 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1411 | uint8_t comms_buffer[VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 1412 | |
charlesmn | 0:3ac96e360672 | 1413 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1414 | |
charlesmn | 0:3ac96e360672 | 1415 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1416 | status = VL53L1_i2c_encode_system_results( |
charlesmn | 0:3ac96e360672 | 1417 | pdata, |
charlesmn | 0:3ac96e360672 | 1418 | VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 1419 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 1420 | |
charlesmn | 0:3ac96e360672 | 1421 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1422 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 1423 | Dev, |
charlesmn | 0:3ac96e360672 | 1424 | VL53L1_RESULT__INTERRUPT_STATUS, |
charlesmn | 0:3ac96e360672 | 1425 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1426 | VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 1427 | |
charlesmn | 0:3ac96e360672 | 1428 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1429 | |
charlesmn | 0:3ac96e360672 | 1430 | return status; |
charlesmn | 0:3ac96e360672 | 1431 | } |
charlesmn | 0:3ac96e360672 | 1432 | |
charlesmn | 0:3ac96e360672 | 1433 | |
charlesmn | 0:3ac96e360672 | 1434 | VL53L1_Error VL53L1_get_system_results( |
charlesmn | 0:3ac96e360672 | 1435 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1436 | VL53L1_system_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 1437 | { |
charlesmn | 0:3ac96e360672 | 1438 | |
charlesmn | 0:3ac96e360672 | 1439 | |
charlesmn | 0:3ac96e360672 | 1440 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1441 | uint8_t comms_buffer[VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 1442 | |
charlesmn | 0:3ac96e360672 | 1443 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1444 | |
charlesmn | 0:3ac96e360672 | 1445 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1446 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 1447 | Dev, |
charlesmn | 0:3ac96e360672 | 1448 | VL53L1_RESULT__INTERRUPT_STATUS, |
charlesmn | 0:3ac96e360672 | 1449 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1450 | VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 1451 | |
charlesmn | 0:3ac96e360672 | 1452 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1453 | status = VL53L1_i2c_decode_system_results( |
charlesmn | 0:3ac96e360672 | 1454 | VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 1455 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1456 | pdata); |
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_i2c_encode_core_results( |
charlesmn | 0:3ac96e360672 | 1465 | VL53L1_core_results_t *pdata, |
charlesmn | 0:3ac96e360672 | 1466 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 1467 | uint8_t *pbuffer) |
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 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1474 | |
charlesmn | 0:3ac96e360672 | 1475 | if (buf_size < VL53L1_CORE_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 1476 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 1477 | |
charlesmn | 0:3ac96e360672 | 1478 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 1479 | pdata->result_core__ambient_window_events_sd0, |
charlesmn | 0:3ac96e360672 | 1480 | 4, |
charlesmn | 0:3ac96e360672 | 1481 | pbuffer + 0); |
charlesmn | 0:3ac96e360672 | 1482 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 1483 | pdata->result_core__ranging_total_events_sd0, |
charlesmn | 0:3ac96e360672 | 1484 | 4, |
charlesmn | 0:3ac96e360672 | 1485 | pbuffer + 4); |
charlesmn | 0:3ac96e360672 | 1486 | VL53L1_i2c_encode_int32_t( |
charlesmn | 0:3ac96e360672 | 1487 | pdata->result_core__signal_total_events_sd0, |
charlesmn | 0:3ac96e360672 | 1488 | 4, |
charlesmn | 0:3ac96e360672 | 1489 | pbuffer + 8); |
charlesmn | 0:3ac96e360672 | 1490 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 1491 | pdata->result_core__total_periods_elapsed_sd0, |
charlesmn | 0:3ac96e360672 | 1492 | 4, |
charlesmn | 0:3ac96e360672 | 1493 | pbuffer + 12); |
charlesmn | 0:3ac96e360672 | 1494 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 1495 | pdata->result_core__ambient_window_events_sd1, |
charlesmn | 0:3ac96e360672 | 1496 | 4, |
charlesmn | 0:3ac96e360672 | 1497 | pbuffer + 16); |
charlesmn | 0:3ac96e360672 | 1498 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 1499 | pdata->result_core__ranging_total_events_sd1, |
charlesmn | 0:3ac96e360672 | 1500 | 4, |
charlesmn | 0:3ac96e360672 | 1501 | pbuffer + 20); |
charlesmn | 0:3ac96e360672 | 1502 | VL53L1_i2c_encode_int32_t( |
charlesmn | 0:3ac96e360672 | 1503 | pdata->result_core__signal_total_events_sd1, |
charlesmn | 0:3ac96e360672 | 1504 | 4, |
charlesmn | 0:3ac96e360672 | 1505 | pbuffer + 24); |
charlesmn | 0:3ac96e360672 | 1506 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 1507 | pdata->result_core__total_periods_elapsed_sd1, |
charlesmn | 0:3ac96e360672 | 1508 | 4, |
charlesmn | 0:3ac96e360672 | 1509 | pbuffer + 28); |
charlesmn | 0:3ac96e360672 | 1510 | *(pbuffer + 32) = |
charlesmn | 0:3ac96e360672 | 1511 | pdata->result_core__spare_0; |
charlesmn | 0:3ac96e360672 | 1512 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1513 | |
charlesmn | 0:3ac96e360672 | 1514 | |
charlesmn | 0:3ac96e360672 | 1515 | return status; |
charlesmn | 0:3ac96e360672 | 1516 | } |
charlesmn | 0:3ac96e360672 | 1517 | |
charlesmn | 0:3ac96e360672 | 1518 | |
charlesmn | 0:3ac96e360672 | 1519 | VL53L1_Error VL53L1_i2c_decode_core_results( |
charlesmn | 0:3ac96e360672 | 1520 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 1521 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 1522 | VL53L1_core_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 1523 | { |
charlesmn | 0:3ac96e360672 | 1524 | |
charlesmn | 0:3ac96e360672 | 1525 | |
charlesmn | 0:3ac96e360672 | 1526 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1527 | |
charlesmn | 0:3ac96e360672 | 1528 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1529 | |
charlesmn | 0:3ac96e360672 | 1530 | if (buf_size < VL53L1_CORE_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 1531 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 1532 | |
charlesmn | 0:3ac96e360672 | 1533 | pdata->result_core__ambient_window_events_sd0 = |
charlesmn | 0:3ac96e360672 | 1534 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 0)); |
charlesmn | 0:3ac96e360672 | 1535 | pdata->result_core__ranging_total_events_sd0 = |
charlesmn | 0:3ac96e360672 | 1536 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 4)); |
charlesmn | 0:3ac96e360672 | 1537 | pdata->result_core__signal_total_events_sd0 = |
charlesmn | 0:3ac96e360672 | 1538 | (VL53L1_i2c_decode_int32_t(4, pbuffer + 8)); |
charlesmn | 0:3ac96e360672 | 1539 | pdata->result_core__total_periods_elapsed_sd0 = |
charlesmn | 0:3ac96e360672 | 1540 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 12)); |
charlesmn | 0:3ac96e360672 | 1541 | pdata->result_core__ambient_window_events_sd1 = |
charlesmn | 0:3ac96e360672 | 1542 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 16)); |
charlesmn | 0:3ac96e360672 | 1543 | pdata->result_core__ranging_total_events_sd1 = |
charlesmn | 0:3ac96e360672 | 1544 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 20)); |
charlesmn | 0:3ac96e360672 | 1545 | pdata->result_core__signal_total_events_sd1 = |
charlesmn | 0:3ac96e360672 | 1546 | (VL53L1_i2c_decode_int32_t(4, pbuffer + 24)); |
charlesmn | 0:3ac96e360672 | 1547 | pdata->result_core__total_periods_elapsed_sd1 = |
charlesmn | 0:3ac96e360672 | 1548 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 28)); |
charlesmn | 0:3ac96e360672 | 1549 | pdata->result_core__spare_0 = |
charlesmn | 0:3ac96e360672 | 1550 | (*(pbuffer + 32)); |
charlesmn | 0:3ac96e360672 | 1551 | |
charlesmn | 0:3ac96e360672 | 1552 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1553 | |
charlesmn | 0:3ac96e360672 | 1554 | return status; |
charlesmn | 0:3ac96e360672 | 1555 | } |
charlesmn | 0:3ac96e360672 | 1556 | |
charlesmn | 0:3ac96e360672 | 1557 | |
charlesmn | 0:3ac96e360672 | 1558 | VL53L1_Error VL53L1_set_core_results( |
charlesmn | 0:3ac96e360672 | 1559 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1560 | VL53L1_core_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 1561 | { |
charlesmn | 0:3ac96e360672 | 1562 | |
charlesmn | 0:3ac96e360672 | 1563 | |
charlesmn | 0:3ac96e360672 | 1564 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1565 | uint8_t comms_buffer[VL53L1_CORE_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 1566 | |
charlesmn | 0:3ac96e360672 | 1567 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1568 | |
charlesmn | 0:3ac96e360672 | 1569 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1570 | status = VL53L1_i2c_encode_core_results( |
charlesmn | 0:3ac96e360672 | 1571 | pdata, |
charlesmn | 0:3ac96e360672 | 1572 | VL53L1_CORE_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 1573 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 1574 | |
charlesmn | 0:3ac96e360672 | 1575 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1576 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 1577 | |
charlesmn | 0:3ac96e360672 | 1578 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1579 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 1580 | Dev, |
charlesmn | 0:3ac96e360672 | 1581 | VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0, |
charlesmn | 0:3ac96e360672 | 1582 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1583 | VL53L1_CORE_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 1584 | |
charlesmn | 0:3ac96e360672 | 1585 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1586 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 1587 | |
charlesmn | 0:3ac96e360672 | 1588 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1589 | |
charlesmn | 0:3ac96e360672 | 1590 | return status; |
charlesmn | 0:3ac96e360672 | 1591 | } |
charlesmn | 0:3ac96e360672 | 1592 | |
charlesmn | 0:3ac96e360672 | 1593 | |
charlesmn | 0:3ac96e360672 | 1594 | VL53L1_Error VL53L1_get_core_results( |
charlesmn | 0:3ac96e360672 | 1595 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1596 | VL53L1_core_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 1597 | { |
charlesmn | 0:3ac96e360672 | 1598 | |
charlesmn | 0:3ac96e360672 | 1599 | |
charlesmn | 0:3ac96e360672 | 1600 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1601 | uint8_t comms_buffer[VL53L1_CORE_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 1602 | |
charlesmn | 0:3ac96e360672 | 1603 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1604 | |
charlesmn | 0:3ac96e360672 | 1605 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1606 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 1607 | Dev, |
charlesmn | 0:3ac96e360672 | 1608 | VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0, |
charlesmn | 0:3ac96e360672 | 1609 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1610 | VL53L1_CORE_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 1611 | |
charlesmn | 0:3ac96e360672 | 1612 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1613 | status = VL53L1_i2c_decode_core_results( |
charlesmn | 0:3ac96e360672 | 1614 | VL53L1_CORE_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 1615 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1616 | pdata); |
charlesmn | 0:3ac96e360672 | 1617 | |
charlesmn | 0:3ac96e360672 | 1618 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1619 | |
charlesmn | 0:3ac96e360672 | 1620 | return status; |
charlesmn | 0:3ac96e360672 | 1621 | } |
charlesmn | 0:3ac96e360672 | 1622 | |
charlesmn | 0:3ac96e360672 | 1623 | |
charlesmn | 0:3ac96e360672 | 1624 | VL53L1_Error VL53L1_i2c_encode_debug_results( |
charlesmn | 0:3ac96e360672 | 1625 | VL53L1_debug_results_t *pdata, |
charlesmn | 0:3ac96e360672 | 1626 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 1627 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 1628 | { |
charlesmn | 0:3ac96e360672 | 1629 | |
charlesmn | 0:3ac96e360672 | 1630 | |
charlesmn | 0:3ac96e360672 | 1631 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1632 | |
charlesmn | 0:3ac96e360672 | 1633 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1634 | |
charlesmn | 0:3ac96e360672 | 1635 | if (buf_size < VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 1636 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 1637 | |
charlesmn | 0:3ac96e360672 | 1638 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1639 | pdata->phasecal_result__reference_phase, |
charlesmn | 0:3ac96e360672 | 1640 | 2, |
charlesmn | 0:3ac96e360672 | 1641 | pbuffer + 0); |
charlesmn | 0:3ac96e360672 | 1642 | *(pbuffer + 2) = |
charlesmn | 0:3ac96e360672 | 1643 | pdata->phasecal_result__vcsel_start & 0x7F; |
charlesmn | 0:3ac96e360672 | 1644 | *(pbuffer + 3) = |
charlesmn | 0:3ac96e360672 | 1645 | pdata->ref_spad_char_result__num_actual_ref_spads & 0x3F; |
charlesmn | 0:3ac96e360672 | 1646 | *(pbuffer + 4) = |
charlesmn | 0:3ac96e360672 | 1647 | pdata->ref_spad_char_result__ref_location & 0x3; |
charlesmn | 0:3ac96e360672 | 1648 | *(pbuffer + 5) = |
charlesmn | 0:3ac96e360672 | 1649 | pdata->vhv_result__coldboot_status & 0x1; |
charlesmn | 0:3ac96e360672 | 1650 | *(pbuffer + 6) = |
charlesmn | 0:3ac96e360672 | 1651 | pdata->vhv_result__search_result & 0x3F; |
charlesmn | 0:3ac96e360672 | 1652 | *(pbuffer + 7) = |
charlesmn | 0:3ac96e360672 | 1653 | pdata->vhv_result__latest_setting & 0x3F; |
charlesmn | 0:3ac96e360672 | 1654 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1655 | pdata->result__osc_calibrate_val & 0x3FF, |
charlesmn | 0:3ac96e360672 | 1656 | 2, |
charlesmn | 0:3ac96e360672 | 1657 | pbuffer + 8); |
charlesmn | 0:3ac96e360672 | 1658 | *(pbuffer + 10) = |
charlesmn | 0:3ac96e360672 | 1659 | pdata->ana_config__powerdown_go1 & 0x3; |
charlesmn | 0:3ac96e360672 | 1660 | *(pbuffer + 11) = |
charlesmn | 0:3ac96e360672 | 1661 | pdata->ana_config__ref_bg_ctrl & 0x3; |
charlesmn | 0:3ac96e360672 | 1662 | *(pbuffer + 12) = |
charlesmn | 0:3ac96e360672 | 1663 | pdata->ana_config__regdvdd1v2_ctrl & 0xF; |
charlesmn | 0:3ac96e360672 | 1664 | *(pbuffer + 13) = |
charlesmn | 0:3ac96e360672 | 1665 | pdata->ana_config__osc_slow_ctrl & 0x7; |
charlesmn | 0:3ac96e360672 | 1666 | *(pbuffer + 14) = |
charlesmn | 0:3ac96e360672 | 1667 | pdata->test_mode__status & 0x1; |
charlesmn | 0:3ac96e360672 | 1668 | *(pbuffer + 15) = |
charlesmn | 0:3ac96e360672 | 1669 | pdata->firmware__system_status & 0x3; |
charlesmn | 0:3ac96e360672 | 1670 | *(pbuffer + 16) = |
charlesmn | 0:3ac96e360672 | 1671 | pdata->firmware__mode_status; |
charlesmn | 0:3ac96e360672 | 1672 | *(pbuffer + 17) = |
charlesmn | 0:3ac96e360672 | 1673 | pdata->firmware__secondary_mode_status; |
charlesmn | 0:3ac96e360672 | 1674 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1675 | pdata->firmware__cal_repeat_rate_counter & 0xFFF, |
charlesmn | 0:3ac96e360672 | 1676 | 2, |
charlesmn | 0:3ac96e360672 | 1677 | pbuffer + 18); |
charlesmn | 0:3ac96e360672 | 1678 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1679 | pdata->gph__system__thresh_high, |
charlesmn | 0:3ac96e360672 | 1680 | 2, |
charlesmn | 0:3ac96e360672 | 1681 | pbuffer + 22); |
charlesmn | 0:3ac96e360672 | 1682 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1683 | pdata->gph__system__thresh_low, |
charlesmn | 0:3ac96e360672 | 1684 | 2, |
charlesmn | 0:3ac96e360672 | 1685 | pbuffer + 24); |
charlesmn | 0:3ac96e360672 | 1686 | *(pbuffer + 26) = |
charlesmn | 0:3ac96e360672 | 1687 | pdata->gph__system__enable_xtalk_per_quadrant & 0x1; |
charlesmn | 0:3ac96e360672 | 1688 | *(pbuffer + 27) = |
charlesmn | 0:3ac96e360672 | 1689 | pdata->gph__spare_0 & 0x7; |
charlesmn | 0:3ac96e360672 | 1690 | *(pbuffer + 28) = |
charlesmn | 0:3ac96e360672 | 1691 | pdata->gph__sd_config__woi_sd0; |
charlesmn | 0:3ac96e360672 | 1692 | *(pbuffer + 29) = |
charlesmn | 0:3ac96e360672 | 1693 | pdata->gph__sd_config__woi_sd1; |
charlesmn | 0:3ac96e360672 | 1694 | *(pbuffer + 30) = |
charlesmn | 0:3ac96e360672 | 1695 | pdata->gph__sd_config__initial_phase_sd0 & 0x7F; |
charlesmn | 0:3ac96e360672 | 1696 | *(pbuffer + 31) = |
charlesmn | 0:3ac96e360672 | 1697 | pdata->gph__sd_config__initial_phase_sd1 & 0x7F; |
charlesmn | 0:3ac96e360672 | 1698 | *(pbuffer + 32) = |
charlesmn | 0:3ac96e360672 | 1699 | pdata->gph__sd_config__first_order_select & 0x3; |
charlesmn | 0:3ac96e360672 | 1700 | *(pbuffer + 33) = |
charlesmn | 0:3ac96e360672 | 1701 | pdata->gph__sd_config__quantifier & 0xF; |
charlesmn | 0:3ac96e360672 | 1702 | *(pbuffer + 34) = |
charlesmn | 0:3ac96e360672 | 1703 | pdata->gph__roi_config__user_roi_centre_spad; |
charlesmn | 0:3ac96e360672 | 1704 | *(pbuffer + 35) = |
charlesmn | 0:3ac96e360672 | 1705 | pdata->gph__roi_config__user_roi_requested_global_xy_size; |
charlesmn | 0:3ac96e360672 | 1706 | *(pbuffer + 36) = |
charlesmn | 0:3ac96e360672 | 1707 | pdata->gph__system__sequence_config; |
charlesmn | 0:3ac96e360672 | 1708 | *(pbuffer + 37) = |
charlesmn | 0:3ac96e360672 | 1709 | pdata->gph__gph_id & 0x1; |
charlesmn | 0:3ac96e360672 | 1710 | *(pbuffer + 38) = |
charlesmn | 0:3ac96e360672 | 1711 | pdata->system__interrupt_set & 0x3; |
charlesmn | 0:3ac96e360672 | 1712 | *(pbuffer + 39) = |
charlesmn | 0:3ac96e360672 | 1713 | pdata->interrupt_manager__enables & 0x1F; |
charlesmn | 0:3ac96e360672 | 1714 | *(pbuffer + 40) = |
charlesmn | 0:3ac96e360672 | 1715 | pdata->interrupt_manager__clear & 0x1F; |
charlesmn | 0:3ac96e360672 | 1716 | *(pbuffer + 41) = |
charlesmn | 0:3ac96e360672 | 1717 | pdata->interrupt_manager__status & 0x1F; |
charlesmn | 0:3ac96e360672 | 1718 | *(pbuffer + 42) = |
charlesmn | 0:3ac96e360672 | 1719 | pdata->mcu_to_host_bank__wr_access_en & 0x1; |
charlesmn | 0:3ac96e360672 | 1720 | *(pbuffer + 43) = |
charlesmn | 0:3ac96e360672 | 1721 | pdata->power_management__go1_reset_status & 0x1; |
charlesmn | 0:3ac96e360672 | 1722 | *(pbuffer + 44) = |
charlesmn | 0:3ac96e360672 | 1723 | pdata->pad_startup_mode__value_ro & 0x3; |
charlesmn | 0:3ac96e360672 | 1724 | *(pbuffer + 45) = |
charlesmn | 0:3ac96e360672 | 1725 | pdata->pad_startup_mode__value_ctrl & 0x3F; |
charlesmn | 0:3ac96e360672 | 1726 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 1727 | pdata->pll_period_us & 0x3FFFF, |
charlesmn | 0:3ac96e360672 | 1728 | 4, |
charlesmn | 0:3ac96e360672 | 1729 | pbuffer + 46); |
charlesmn | 0:3ac96e360672 | 1730 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 1731 | pdata->interrupt_scheduler__data_out, |
charlesmn | 0:3ac96e360672 | 1732 | 4, |
charlesmn | 0:3ac96e360672 | 1733 | pbuffer + 50); |
charlesmn | 0:3ac96e360672 | 1734 | *(pbuffer + 54) = |
charlesmn | 0:3ac96e360672 | 1735 | pdata->nvm_bist__complete & 0x1; |
charlesmn | 0:3ac96e360672 | 1736 | *(pbuffer + 55) = |
charlesmn | 0:3ac96e360672 | 1737 | pdata->nvm_bist__status & 0x1; |
charlesmn | 0:3ac96e360672 | 1738 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1739 | |
charlesmn | 0:3ac96e360672 | 1740 | |
charlesmn | 0:3ac96e360672 | 1741 | return status; |
charlesmn | 0:3ac96e360672 | 1742 | } |
charlesmn | 0:3ac96e360672 | 1743 | |
charlesmn | 0:3ac96e360672 | 1744 | |
charlesmn | 0:3ac96e360672 | 1745 | VL53L1_Error VL53L1_i2c_decode_debug_results( |
charlesmn | 0:3ac96e360672 | 1746 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 1747 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 1748 | VL53L1_debug_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 1749 | { |
charlesmn | 0:3ac96e360672 | 1750 | |
charlesmn | 0:3ac96e360672 | 1751 | |
charlesmn | 0:3ac96e360672 | 1752 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1753 | |
charlesmn | 0:3ac96e360672 | 1754 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1755 | |
charlesmn | 0:3ac96e360672 | 1756 | if (buf_size < VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 1757 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 1758 | |
charlesmn | 0:3ac96e360672 | 1759 | pdata->phasecal_result__reference_phase = |
charlesmn | 0:3ac96e360672 | 1760 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 0)); |
charlesmn | 0:3ac96e360672 | 1761 | pdata->phasecal_result__vcsel_start = |
charlesmn | 0:3ac96e360672 | 1762 | (*(pbuffer + 2)) & 0x7F; |
charlesmn | 0:3ac96e360672 | 1763 | pdata->ref_spad_char_result__num_actual_ref_spads = |
charlesmn | 0:3ac96e360672 | 1764 | (*(pbuffer + 3)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 1765 | pdata->ref_spad_char_result__ref_location = |
charlesmn | 0:3ac96e360672 | 1766 | (*(pbuffer + 4)) & 0x3; |
charlesmn | 0:3ac96e360672 | 1767 | pdata->vhv_result__coldboot_status = |
charlesmn | 0:3ac96e360672 | 1768 | (*(pbuffer + 5)) & 0x1; |
charlesmn | 0:3ac96e360672 | 1769 | pdata->vhv_result__search_result = |
charlesmn | 0:3ac96e360672 | 1770 | (*(pbuffer + 6)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 1771 | pdata->vhv_result__latest_setting = |
charlesmn | 0:3ac96e360672 | 1772 | (*(pbuffer + 7)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 1773 | pdata->result__osc_calibrate_val = |
charlesmn | 0:3ac96e360672 | 1774 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8)) & 0x3FF; |
charlesmn | 0:3ac96e360672 | 1775 | pdata->ana_config__powerdown_go1 = |
charlesmn | 0:3ac96e360672 | 1776 | (*(pbuffer + 10)) & 0x3; |
charlesmn | 0:3ac96e360672 | 1777 | pdata->ana_config__ref_bg_ctrl = |
charlesmn | 0:3ac96e360672 | 1778 | (*(pbuffer + 11)) & 0x3; |
charlesmn | 0:3ac96e360672 | 1779 | pdata->ana_config__regdvdd1v2_ctrl = |
charlesmn | 0:3ac96e360672 | 1780 | (*(pbuffer + 12)) & 0xF; |
charlesmn | 0:3ac96e360672 | 1781 | pdata->ana_config__osc_slow_ctrl = |
charlesmn | 0:3ac96e360672 | 1782 | (*(pbuffer + 13)) & 0x7; |
charlesmn | 0:3ac96e360672 | 1783 | pdata->test_mode__status = |
charlesmn | 0:3ac96e360672 | 1784 | (*(pbuffer + 14)) & 0x1; |
charlesmn | 0:3ac96e360672 | 1785 | pdata->firmware__system_status = |
charlesmn | 0:3ac96e360672 | 1786 | (*(pbuffer + 15)) & 0x3; |
charlesmn | 0:3ac96e360672 | 1787 | pdata->firmware__mode_status = |
charlesmn | 0:3ac96e360672 | 1788 | (*(pbuffer + 16)); |
charlesmn | 0:3ac96e360672 | 1789 | pdata->firmware__secondary_mode_status = |
charlesmn | 0:3ac96e360672 | 1790 | (*(pbuffer + 17)); |
charlesmn | 0:3ac96e360672 | 1791 | pdata->firmware__cal_repeat_rate_counter = |
charlesmn | 0:3ac96e360672 | 1792 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18)) & 0xFFF; |
charlesmn | 0:3ac96e360672 | 1793 | pdata->gph__system__thresh_high = |
charlesmn | 0:3ac96e360672 | 1794 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22)); |
charlesmn | 0:3ac96e360672 | 1795 | pdata->gph__system__thresh_low = |
charlesmn | 0:3ac96e360672 | 1796 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24)); |
charlesmn | 0:3ac96e360672 | 1797 | pdata->gph__system__enable_xtalk_per_quadrant = |
charlesmn | 0:3ac96e360672 | 1798 | (*(pbuffer + 26)) & 0x1; |
charlesmn | 0:3ac96e360672 | 1799 | pdata->gph__spare_0 = |
charlesmn | 0:3ac96e360672 | 1800 | (*(pbuffer + 27)) & 0x7; |
charlesmn | 0:3ac96e360672 | 1801 | pdata->gph__sd_config__woi_sd0 = |
charlesmn | 0:3ac96e360672 | 1802 | (*(pbuffer + 28)); |
charlesmn | 0:3ac96e360672 | 1803 | pdata->gph__sd_config__woi_sd1 = |
charlesmn | 0:3ac96e360672 | 1804 | (*(pbuffer + 29)); |
charlesmn | 0:3ac96e360672 | 1805 | pdata->gph__sd_config__initial_phase_sd0 = |
charlesmn | 0:3ac96e360672 | 1806 | (*(pbuffer + 30)) & 0x7F; |
charlesmn | 0:3ac96e360672 | 1807 | pdata->gph__sd_config__initial_phase_sd1 = |
charlesmn | 0:3ac96e360672 | 1808 | (*(pbuffer + 31)) & 0x7F; |
charlesmn | 0:3ac96e360672 | 1809 | pdata->gph__sd_config__first_order_select = |
charlesmn | 0:3ac96e360672 | 1810 | (*(pbuffer + 32)) & 0x3; |
charlesmn | 0:3ac96e360672 | 1811 | pdata->gph__sd_config__quantifier = |
charlesmn | 0:3ac96e360672 | 1812 | (*(pbuffer + 33)) & 0xF; |
charlesmn | 0:3ac96e360672 | 1813 | pdata->gph__roi_config__user_roi_centre_spad = |
charlesmn | 0:3ac96e360672 | 1814 | (*(pbuffer + 34)); |
charlesmn | 0:3ac96e360672 | 1815 | pdata->gph__roi_config__user_roi_requested_global_xy_size = |
charlesmn | 0:3ac96e360672 | 1816 | (*(pbuffer + 35)); |
charlesmn | 0:3ac96e360672 | 1817 | pdata->gph__system__sequence_config = |
charlesmn | 0:3ac96e360672 | 1818 | (*(pbuffer + 36)); |
charlesmn | 0:3ac96e360672 | 1819 | pdata->gph__gph_id = |
charlesmn | 0:3ac96e360672 | 1820 | (*(pbuffer + 37)) & 0x1; |
charlesmn | 0:3ac96e360672 | 1821 | pdata->system__interrupt_set = |
charlesmn | 0:3ac96e360672 | 1822 | (*(pbuffer + 38)) & 0x3; |
charlesmn | 0:3ac96e360672 | 1823 | pdata->interrupt_manager__enables = |
charlesmn | 0:3ac96e360672 | 1824 | (*(pbuffer + 39)) & 0x1F; |
charlesmn | 0:3ac96e360672 | 1825 | pdata->interrupt_manager__clear = |
charlesmn | 0:3ac96e360672 | 1826 | (*(pbuffer + 40)) & 0x1F; |
charlesmn | 0:3ac96e360672 | 1827 | pdata->interrupt_manager__status = |
charlesmn | 0:3ac96e360672 | 1828 | (*(pbuffer + 41)) & 0x1F; |
charlesmn | 0:3ac96e360672 | 1829 | pdata->mcu_to_host_bank__wr_access_en = |
charlesmn | 0:3ac96e360672 | 1830 | (*(pbuffer + 42)) & 0x1; |
charlesmn | 0:3ac96e360672 | 1831 | pdata->power_management__go1_reset_status = |
charlesmn | 0:3ac96e360672 | 1832 | (*(pbuffer + 43)) & 0x1; |
charlesmn | 0:3ac96e360672 | 1833 | pdata->pad_startup_mode__value_ro = |
charlesmn | 0:3ac96e360672 | 1834 | (*(pbuffer + 44)) & 0x3; |
charlesmn | 0:3ac96e360672 | 1835 | pdata->pad_startup_mode__value_ctrl = |
charlesmn | 0:3ac96e360672 | 1836 | (*(pbuffer + 45)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 1837 | pdata->pll_period_us = |
charlesmn | 0:3ac96e360672 | 1838 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 46)) & 0x3FFFF; |
charlesmn | 0:3ac96e360672 | 1839 | pdata->interrupt_scheduler__data_out = |
charlesmn | 0:3ac96e360672 | 1840 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 50)); |
charlesmn | 0:3ac96e360672 | 1841 | pdata->nvm_bist__complete = |
charlesmn | 0:3ac96e360672 | 1842 | (*(pbuffer + 54)) & 0x1; |
charlesmn | 0:3ac96e360672 | 1843 | pdata->nvm_bist__status = |
charlesmn | 0:3ac96e360672 | 1844 | (*(pbuffer + 55)) & 0x1; |
charlesmn | 0:3ac96e360672 | 1845 | |
charlesmn | 0:3ac96e360672 | 1846 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1847 | |
charlesmn | 0:3ac96e360672 | 1848 | return status; |
charlesmn | 0:3ac96e360672 | 1849 | } |
charlesmn | 0:3ac96e360672 | 1850 | |
charlesmn | 0:3ac96e360672 | 1851 | |
charlesmn | 0:3ac96e360672 | 1852 | VL53L1_Error VL53L1_set_debug_results( |
charlesmn | 0:3ac96e360672 | 1853 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1854 | VL53L1_debug_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 1855 | { |
charlesmn | 0:3ac96e360672 | 1856 | |
charlesmn | 0:3ac96e360672 | 1857 | |
charlesmn | 0:3ac96e360672 | 1858 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1859 | uint8_t comms_buffer[VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 1860 | |
charlesmn | 0:3ac96e360672 | 1861 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1862 | |
charlesmn | 0:3ac96e360672 | 1863 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1864 | status = VL53L1_i2c_encode_debug_results( |
charlesmn | 0:3ac96e360672 | 1865 | pdata, |
charlesmn | 0:3ac96e360672 | 1866 | VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 1867 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 1868 | |
charlesmn | 0:3ac96e360672 | 1869 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1870 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 1871 | |
charlesmn | 0:3ac96e360672 | 1872 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1873 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 1874 | Dev, |
charlesmn | 0:3ac96e360672 | 1875 | VL53L1_PHASECAL_RESULT__REFERENCE_PHASE, |
charlesmn | 0:3ac96e360672 | 1876 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1877 | VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 1878 | |
charlesmn | 0:3ac96e360672 | 1879 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1880 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 1881 | |
charlesmn | 0:3ac96e360672 | 1882 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1883 | |
charlesmn | 0:3ac96e360672 | 1884 | return status; |
charlesmn | 0:3ac96e360672 | 1885 | } |
charlesmn | 0:3ac96e360672 | 1886 | |
charlesmn | 0:3ac96e360672 | 1887 | |
charlesmn | 0:3ac96e360672 | 1888 | VL53L1_Error VL53L1_get_debug_results( |
charlesmn | 0:3ac96e360672 | 1889 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1890 | VL53L1_debug_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 1891 | { |
charlesmn | 0:3ac96e360672 | 1892 | |
charlesmn | 0:3ac96e360672 | 1893 | |
charlesmn | 0:3ac96e360672 | 1894 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1895 | uint8_t comms_buffer[VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 1896 | |
charlesmn | 0:3ac96e360672 | 1897 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1898 | |
charlesmn | 0:3ac96e360672 | 1899 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1900 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 1901 | Dev, |
charlesmn | 0:3ac96e360672 | 1902 | VL53L1_PHASECAL_RESULT__REFERENCE_PHASE, |
charlesmn | 0:3ac96e360672 | 1903 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1904 | VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 1905 | |
charlesmn | 0:3ac96e360672 | 1906 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1907 | status = VL53L1_i2c_decode_debug_results( |
charlesmn | 0:3ac96e360672 | 1908 | VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 1909 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1910 | pdata); |
charlesmn | 0:3ac96e360672 | 1911 | |
charlesmn | 0:3ac96e360672 | 1912 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1913 | |
charlesmn | 0:3ac96e360672 | 1914 | return status; |
charlesmn | 0:3ac96e360672 | 1915 | } |
charlesmn | 0:3ac96e360672 | 1916 | |
charlesmn | 0:3ac96e360672 | 1917 | |
charlesmn | 0:3ac96e360672 | 1918 | VL53L1_Error VL53L1_i2c_encode_nvm_copy_data( |
charlesmn | 0:3ac96e360672 | 1919 | VL53L1_nvm_copy_data_t *pdata, |
charlesmn | 0:3ac96e360672 | 1920 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 1921 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 1922 | { |
charlesmn | 0:3ac96e360672 | 1923 | |
charlesmn | 0:3ac96e360672 | 1924 | |
charlesmn | 0:3ac96e360672 | 1925 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1926 | |
charlesmn | 0:3ac96e360672 | 1927 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1928 | |
charlesmn | 0:3ac96e360672 | 1929 | if (buf_size < VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 1930 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 1931 | |
charlesmn | 0:3ac96e360672 | 1932 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 1933 | pdata->identification__model_id; |
charlesmn | 0:3ac96e360672 | 1934 | *(pbuffer + 1) = |
charlesmn | 0:3ac96e360672 | 1935 | pdata->identification__module_type; |
charlesmn | 0:3ac96e360672 | 1936 | *(pbuffer + 2) = |
charlesmn | 0:3ac96e360672 | 1937 | pdata->identification__revision_id; |
charlesmn | 0:3ac96e360672 | 1938 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 1939 | pdata->identification__module_id, |
charlesmn | 0:3ac96e360672 | 1940 | 2, |
charlesmn | 0:3ac96e360672 | 1941 | pbuffer + 3); |
charlesmn | 0:3ac96e360672 | 1942 | *(pbuffer + 5) = |
charlesmn | 0:3ac96e360672 | 1943 | pdata->ana_config__fast_osc__trim_max & 0x7F; |
charlesmn | 0:3ac96e360672 | 1944 | *(pbuffer + 6) = |
charlesmn | 0:3ac96e360672 | 1945 | pdata->ana_config__fast_osc__freq_set & 0x7; |
charlesmn | 0:3ac96e360672 | 1946 | *(pbuffer + 7) = |
charlesmn | 0:3ac96e360672 | 1947 | pdata->ana_config__vcsel_trim & 0x7; |
charlesmn | 0:3ac96e360672 | 1948 | *(pbuffer + 8) = |
charlesmn | 0:3ac96e360672 | 1949 | pdata->ana_config__vcsel_selion & 0x3F; |
charlesmn | 0:3ac96e360672 | 1950 | *(pbuffer + 9) = |
charlesmn | 0:3ac96e360672 | 1951 | pdata->ana_config__vcsel_selion_max & 0x3F; |
charlesmn | 0:3ac96e360672 | 1952 | *(pbuffer + 10) = |
charlesmn | 0:3ac96e360672 | 1953 | pdata->protected_laser_safety__lock_bit & 0x1; |
charlesmn | 0:3ac96e360672 | 1954 | *(pbuffer + 11) = |
charlesmn | 0:3ac96e360672 | 1955 | pdata->laser_safety__key & 0x7F; |
charlesmn | 0:3ac96e360672 | 1956 | *(pbuffer + 12) = |
charlesmn | 0:3ac96e360672 | 1957 | pdata->laser_safety__key_ro & 0x1; |
charlesmn | 0:3ac96e360672 | 1958 | *(pbuffer + 13) = |
charlesmn | 0:3ac96e360672 | 1959 | pdata->laser_safety__clip & 0x3F; |
charlesmn | 0:3ac96e360672 | 1960 | *(pbuffer + 14) = |
charlesmn | 0:3ac96e360672 | 1961 | pdata->laser_safety__mult & 0x3F; |
charlesmn | 0:3ac96e360672 | 1962 | *(pbuffer + 15) = |
charlesmn | 0:3ac96e360672 | 1963 | pdata->global_config__spad_enables_rtn_0; |
charlesmn | 0:3ac96e360672 | 1964 | *(pbuffer + 16) = |
charlesmn | 0:3ac96e360672 | 1965 | pdata->global_config__spad_enables_rtn_1; |
charlesmn | 0:3ac96e360672 | 1966 | *(pbuffer + 17) = |
charlesmn | 0:3ac96e360672 | 1967 | pdata->global_config__spad_enables_rtn_2; |
charlesmn | 0:3ac96e360672 | 1968 | *(pbuffer + 18) = |
charlesmn | 0:3ac96e360672 | 1969 | pdata->global_config__spad_enables_rtn_3; |
charlesmn | 0:3ac96e360672 | 1970 | *(pbuffer + 19) = |
charlesmn | 0:3ac96e360672 | 1971 | pdata->global_config__spad_enables_rtn_4; |
charlesmn | 0:3ac96e360672 | 1972 | *(pbuffer + 20) = |
charlesmn | 0:3ac96e360672 | 1973 | pdata->global_config__spad_enables_rtn_5; |
charlesmn | 0:3ac96e360672 | 1974 | *(pbuffer + 21) = |
charlesmn | 0:3ac96e360672 | 1975 | pdata->global_config__spad_enables_rtn_6; |
charlesmn | 0:3ac96e360672 | 1976 | *(pbuffer + 22) = |
charlesmn | 0:3ac96e360672 | 1977 | pdata->global_config__spad_enables_rtn_7; |
charlesmn | 0:3ac96e360672 | 1978 | *(pbuffer + 23) = |
charlesmn | 0:3ac96e360672 | 1979 | pdata->global_config__spad_enables_rtn_8; |
charlesmn | 0:3ac96e360672 | 1980 | *(pbuffer + 24) = |
charlesmn | 0:3ac96e360672 | 1981 | pdata->global_config__spad_enables_rtn_9; |
charlesmn | 0:3ac96e360672 | 1982 | *(pbuffer + 25) = |
charlesmn | 0:3ac96e360672 | 1983 | pdata->global_config__spad_enables_rtn_10; |
charlesmn | 0:3ac96e360672 | 1984 | *(pbuffer + 26) = |
charlesmn | 0:3ac96e360672 | 1985 | pdata->global_config__spad_enables_rtn_11; |
charlesmn | 0:3ac96e360672 | 1986 | *(pbuffer + 27) = |
charlesmn | 0:3ac96e360672 | 1987 | pdata->global_config__spad_enables_rtn_12; |
charlesmn | 0:3ac96e360672 | 1988 | *(pbuffer + 28) = |
charlesmn | 0:3ac96e360672 | 1989 | pdata->global_config__spad_enables_rtn_13; |
charlesmn | 0:3ac96e360672 | 1990 | *(pbuffer + 29) = |
charlesmn | 0:3ac96e360672 | 1991 | pdata->global_config__spad_enables_rtn_14; |
charlesmn | 0:3ac96e360672 | 1992 | *(pbuffer + 30) = |
charlesmn | 0:3ac96e360672 | 1993 | pdata->global_config__spad_enables_rtn_15; |
charlesmn | 0:3ac96e360672 | 1994 | *(pbuffer + 31) = |
charlesmn | 0:3ac96e360672 | 1995 | pdata->global_config__spad_enables_rtn_16; |
charlesmn | 0:3ac96e360672 | 1996 | *(pbuffer + 32) = |
charlesmn | 0:3ac96e360672 | 1997 | pdata->global_config__spad_enables_rtn_17; |
charlesmn | 0:3ac96e360672 | 1998 | *(pbuffer + 33) = |
charlesmn | 0:3ac96e360672 | 1999 | pdata->global_config__spad_enables_rtn_18; |
charlesmn | 0:3ac96e360672 | 2000 | *(pbuffer + 34) = |
charlesmn | 0:3ac96e360672 | 2001 | pdata->global_config__spad_enables_rtn_19; |
charlesmn | 0:3ac96e360672 | 2002 | *(pbuffer + 35) = |
charlesmn | 0:3ac96e360672 | 2003 | pdata->global_config__spad_enables_rtn_20; |
charlesmn | 0:3ac96e360672 | 2004 | *(pbuffer + 36) = |
charlesmn | 0:3ac96e360672 | 2005 | pdata->global_config__spad_enables_rtn_21; |
charlesmn | 0:3ac96e360672 | 2006 | *(pbuffer + 37) = |
charlesmn | 0:3ac96e360672 | 2007 | pdata->global_config__spad_enables_rtn_22; |
charlesmn | 0:3ac96e360672 | 2008 | *(pbuffer + 38) = |
charlesmn | 0:3ac96e360672 | 2009 | pdata->global_config__spad_enables_rtn_23; |
charlesmn | 0:3ac96e360672 | 2010 | *(pbuffer + 39) = |
charlesmn | 0:3ac96e360672 | 2011 | pdata->global_config__spad_enables_rtn_24; |
charlesmn | 0:3ac96e360672 | 2012 | *(pbuffer + 40) = |
charlesmn | 0:3ac96e360672 | 2013 | pdata->global_config__spad_enables_rtn_25; |
charlesmn | 0:3ac96e360672 | 2014 | *(pbuffer + 41) = |
charlesmn | 0:3ac96e360672 | 2015 | pdata->global_config__spad_enables_rtn_26; |
charlesmn | 0:3ac96e360672 | 2016 | *(pbuffer + 42) = |
charlesmn | 0:3ac96e360672 | 2017 | pdata->global_config__spad_enables_rtn_27; |
charlesmn | 0:3ac96e360672 | 2018 | *(pbuffer + 43) = |
charlesmn | 0:3ac96e360672 | 2019 | pdata->global_config__spad_enables_rtn_28; |
charlesmn | 0:3ac96e360672 | 2020 | *(pbuffer + 44) = |
charlesmn | 0:3ac96e360672 | 2021 | pdata->global_config__spad_enables_rtn_29; |
charlesmn | 0:3ac96e360672 | 2022 | *(pbuffer + 45) = |
charlesmn | 0:3ac96e360672 | 2023 | pdata->global_config__spad_enables_rtn_30; |
charlesmn | 0:3ac96e360672 | 2024 | *(pbuffer + 46) = |
charlesmn | 0:3ac96e360672 | 2025 | pdata->global_config__spad_enables_rtn_31; |
charlesmn | 0:3ac96e360672 | 2026 | *(pbuffer + 47) = |
charlesmn | 0:3ac96e360672 | 2027 | pdata->roi_config__mode_roi_centre_spad; |
charlesmn | 0:3ac96e360672 | 2028 | *(pbuffer + 48) = |
charlesmn | 0:3ac96e360672 | 2029 | pdata->roi_config__mode_roi_xy_size; |
charlesmn | 0:3ac96e360672 | 2030 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2031 | |
charlesmn | 0:3ac96e360672 | 2032 | |
charlesmn | 0:3ac96e360672 | 2033 | return status; |
charlesmn | 0:3ac96e360672 | 2034 | } |
charlesmn | 0:3ac96e360672 | 2035 | |
charlesmn | 0:3ac96e360672 | 2036 | |
charlesmn | 0:3ac96e360672 | 2037 | VL53L1_Error VL53L1_i2c_decode_nvm_copy_data( |
charlesmn | 0:3ac96e360672 | 2038 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 2039 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 2040 | VL53L1_nvm_copy_data_t *pdata) |
charlesmn | 0:3ac96e360672 | 2041 | { |
charlesmn | 0:3ac96e360672 | 2042 | |
charlesmn | 0:3ac96e360672 | 2043 | |
charlesmn | 0:3ac96e360672 | 2044 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2045 | |
charlesmn | 0:3ac96e360672 | 2046 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2047 | |
charlesmn | 0:3ac96e360672 | 2048 | if (buf_size < VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 2049 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 2050 | |
charlesmn | 0:3ac96e360672 | 2051 | pdata->identification__model_id = |
charlesmn | 0:3ac96e360672 | 2052 | (*(pbuffer + 0)); |
charlesmn | 0:3ac96e360672 | 2053 | pdata->identification__module_type = |
charlesmn | 0:3ac96e360672 | 2054 | (*(pbuffer + 1)); |
charlesmn | 0:3ac96e360672 | 2055 | pdata->identification__revision_id = |
charlesmn | 0:3ac96e360672 | 2056 | (*(pbuffer + 2)); |
charlesmn | 0:3ac96e360672 | 2057 | pdata->identification__module_id = |
charlesmn | 0:3ac96e360672 | 2058 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 3)); |
charlesmn | 0:3ac96e360672 | 2059 | pdata->ana_config__fast_osc__trim_max = |
charlesmn | 0:3ac96e360672 | 2060 | (*(pbuffer + 5)) & 0x7F; |
charlesmn | 0:3ac96e360672 | 2061 | pdata->ana_config__fast_osc__freq_set = |
charlesmn | 0:3ac96e360672 | 2062 | (*(pbuffer + 6)) & 0x7; |
charlesmn | 0:3ac96e360672 | 2063 | pdata->ana_config__vcsel_trim = |
charlesmn | 0:3ac96e360672 | 2064 | (*(pbuffer + 7)) & 0x7; |
charlesmn | 0:3ac96e360672 | 2065 | pdata->ana_config__vcsel_selion = |
charlesmn | 0:3ac96e360672 | 2066 | (*(pbuffer + 8)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 2067 | pdata->ana_config__vcsel_selion_max = |
charlesmn | 0:3ac96e360672 | 2068 | (*(pbuffer + 9)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 2069 | pdata->protected_laser_safety__lock_bit = |
charlesmn | 0:3ac96e360672 | 2070 | (*(pbuffer + 10)) & 0x1; |
charlesmn | 0:3ac96e360672 | 2071 | pdata->laser_safety__key = |
charlesmn | 0:3ac96e360672 | 2072 | (*(pbuffer + 11)) & 0x7F; |
charlesmn | 0:3ac96e360672 | 2073 | pdata->laser_safety__key_ro = |
charlesmn | 0:3ac96e360672 | 2074 | (*(pbuffer + 12)) & 0x1; |
charlesmn | 0:3ac96e360672 | 2075 | pdata->laser_safety__clip = |
charlesmn | 0:3ac96e360672 | 2076 | (*(pbuffer + 13)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 2077 | pdata->laser_safety__mult = |
charlesmn | 0:3ac96e360672 | 2078 | (*(pbuffer + 14)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 2079 | pdata->global_config__spad_enables_rtn_0 = |
charlesmn | 0:3ac96e360672 | 2080 | (*(pbuffer + 15)); |
charlesmn | 0:3ac96e360672 | 2081 | pdata->global_config__spad_enables_rtn_1 = |
charlesmn | 0:3ac96e360672 | 2082 | (*(pbuffer + 16)); |
charlesmn | 0:3ac96e360672 | 2083 | pdata->global_config__spad_enables_rtn_2 = |
charlesmn | 0:3ac96e360672 | 2084 | (*(pbuffer + 17)); |
charlesmn | 0:3ac96e360672 | 2085 | pdata->global_config__spad_enables_rtn_3 = |
charlesmn | 0:3ac96e360672 | 2086 | (*(pbuffer + 18)); |
charlesmn | 0:3ac96e360672 | 2087 | pdata->global_config__spad_enables_rtn_4 = |
charlesmn | 0:3ac96e360672 | 2088 | (*(pbuffer + 19)); |
charlesmn | 0:3ac96e360672 | 2089 | pdata->global_config__spad_enables_rtn_5 = |
charlesmn | 0:3ac96e360672 | 2090 | (*(pbuffer + 20)); |
charlesmn | 0:3ac96e360672 | 2091 | pdata->global_config__spad_enables_rtn_6 = |
charlesmn | 0:3ac96e360672 | 2092 | (*(pbuffer + 21)); |
charlesmn | 0:3ac96e360672 | 2093 | pdata->global_config__spad_enables_rtn_7 = |
charlesmn | 0:3ac96e360672 | 2094 | (*(pbuffer + 22)); |
charlesmn | 0:3ac96e360672 | 2095 | pdata->global_config__spad_enables_rtn_8 = |
charlesmn | 0:3ac96e360672 | 2096 | (*(pbuffer + 23)); |
charlesmn | 0:3ac96e360672 | 2097 | pdata->global_config__spad_enables_rtn_9 = |
charlesmn | 0:3ac96e360672 | 2098 | (*(pbuffer + 24)); |
charlesmn | 0:3ac96e360672 | 2099 | pdata->global_config__spad_enables_rtn_10 = |
charlesmn | 0:3ac96e360672 | 2100 | (*(pbuffer + 25)); |
charlesmn | 0:3ac96e360672 | 2101 | pdata->global_config__spad_enables_rtn_11 = |
charlesmn | 0:3ac96e360672 | 2102 | (*(pbuffer + 26)); |
charlesmn | 0:3ac96e360672 | 2103 | pdata->global_config__spad_enables_rtn_12 = |
charlesmn | 0:3ac96e360672 | 2104 | (*(pbuffer + 27)); |
charlesmn | 0:3ac96e360672 | 2105 | pdata->global_config__spad_enables_rtn_13 = |
charlesmn | 0:3ac96e360672 | 2106 | (*(pbuffer + 28)); |
charlesmn | 0:3ac96e360672 | 2107 | pdata->global_config__spad_enables_rtn_14 = |
charlesmn | 0:3ac96e360672 | 2108 | (*(pbuffer + 29)); |
charlesmn | 0:3ac96e360672 | 2109 | pdata->global_config__spad_enables_rtn_15 = |
charlesmn | 0:3ac96e360672 | 2110 | (*(pbuffer + 30)); |
charlesmn | 0:3ac96e360672 | 2111 | pdata->global_config__spad_enables_rtn_16 = |
charlesmn | 0:3ac96e360672 | 2112 | (*(pbuffer + 31)); |
charlesmn | 0:3ac96e360672 | 2113 | pdata->global_config__spad_enables_rtn_17 = |
charlesmn | 0:3ac96e360672 | 2114 | (*(pbuffer + 32)); |
charlesmn | 0:3ac96e360672 | 2115 | pdata->global_config__spad_enables_rtn_18 = |
charlesmn | 0:3ac96e360672 | 2116 | (*(pbuffer + 33)); |
charlesmn | 0:3ac96e360672 | 2117 | pdata->global_config__spad_enables_rtn_19 = |
charlesmn | 0:3ac96e360672 | 2118 | (*(pbuffer + 34)); |
charlesmn | 0:3ac96e360672 | 2119 | pdata->global_config__spad_enables_rtn_20 = |
charlesmn | 0:3ac96e360672 | 2120 | (*(pbuffer + 35)); |
charlesmn | 0:3ac96e360672 | 2121 | pdata->global_config__spad_enables_rtn_21 = |
charlesmn | 0:3ac96e360672 | 2122 | (*(pbuffer + 36)); |
charlesmn | 0:3ac96e360672 | 2123 | pdata->global_config__spad_enables_rtn_22 = |
charlesmn | 0:3ac96e360672 | 2124 | (*(pbuffer + 37)); |
charlesmn | 0:3ac96e360672 | 2125 | pdata->global_config__spad_enables_rtn_23 = |
charlesmn | 0:3ac96e360672 | 2126 | (*(pbuffer + 38)); |
charlesmn | 0:3ac96e360672 | 2127 | pdata->global_config__spad_enables_rtn_24 = |
charlesmn | 0:3ac96e360672 | 2128 | (*(pbuffer + 39)); |
charlesmn | 0:3ac96e360672 | 2129 | pdata->global_config__spad_enables_rtn_25 = |
charlesmn | 0:3ac96e360672 | 2130 | (*(pbuffer + 40)); |
charlesmn | 0:3ac96e360672 | 2131 | pdata->global_config__spad_enables_rtn_26 = |
charlesmn | 0:3ac96e360672 | 2132 | (*(pbuffer + 41)); |
charlesmn | 0:3ac96e360672 | 2133 | pdata->global_config__spad_enables_rtn_27 = |
charlesmn | 0:3ac96e360672 | 2134 | (*(pbuffer + 42)); |
charlesmn | 0:3ac96e360672 | 2135 | pdata->global_config__spad_enables_rtn_28 = |
charlesmn | 0:3ac96e360672 | 2136 | (*(pbuffer + 43)); |
charlesmn | 0:3ac96e360672 | 2137 | pdata->global_config__spad_enables_rtn_29 = |
charlesmn | 0:3ac96e360672 | 2138 | (*(pbuffer + 44)); |
charlesmn | 0:3ac96e360672 | 2139 | pdata->global_config__spad_enables_rtn_30 = |
charlesmn | 0:3ac96e360672 | 2140 | (*(pbuffer + 45)); |
charlesmn | 0:3ac96e360672 | 2141 | pdata->global_config__spad_enables_rtn_31 = |
charlesmn | 0:3ac96e360672 | 2142 | (*(pbuffer + 46)); |
charlesmn | 0:3ac96e360672 | 2143 | pdata->roi_config__mode_roi_centre_spad = |
charlesmn | 0:3ac96e360672 | 2144 | (*(pbuffer + 47)); |
charlesmn | 0:3ac96e360672 | 2145 | pdata->roi_config__mode_roi_xy_size = |
charlesmn | 0:3ac96e360672 | 2146 | (*(pbuffer + 48)); |
charlesmn | 0:3ac96e360672 | 2147 | |
charlesmn | 0:3ac96e360672 | 2148 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2149 | |
charlesmn | 0:3ac96e360672 | 2150 | return status; |
charlesmn | 0:3ac96e360672 | 2151 | } |
charlesmn | 0:3ac96e360672 | 2152 | |
charlesmn | 0:3ac96e360672 | 2153 | |
charlesmn | 0:3ac96e360672 | 2154 | VL53L1_Error VL53L1_set_nvm_copy_data( |
charlesmn | 0:3ac96e360672 | 2155 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2156 | VL53L1_nvm_copy_data_t *pdata) |
charlesmn | 0:3ac96e360672 | 2157 | { |
charlesmn | 0:3ac96e360672 | 2158 | |
charlesmn | 0:3ac96e360672 | 2159 | |
charlesmn | 0:3ac96e360672 | 2160 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2161 | uint8_t comms_buffer[VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 2162 | |
charlesmn | 0:3ac96e360672 | 2163 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2164 | |
charlesmn | 0:3ac96e360672 | 2165 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2166 | status = VL53L1_i2c_encode_nvm_copy_data( |
charlesmn | 0:3ac96e360672 | 2167 | pdata, |
charlesmn | 0:3ac96e360672 | 2168 | VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 2169 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 2170 | |
charlesmn | 0:3ac96e360672 | 2171 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2172 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2173 | |
charlesmn | 0:3ac96e360672 | 2174 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2175 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 2176 | Dev, |
charlesmn | 0:3ac96e360672 | 2177 | VL53L1_IDENTIFICATION__MODEL_ID, |
charlesmn | 0:3ac96e360672 | 2178 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2179 | VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 2180 | |
charlesmn | 0:3ac96e360672 | 2181 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2182 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2183 | |
charlesmn | 0:3ac96e360672 | 2184 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2185 | |
charlesmn | 0:3ac96e360672 | 2186 | return status; |
charlesmn | 0:3ac96e360672 | 2187 | } |
charlesmn | 0:3ac96e360672 | 2188 | |
charlesmn | 0:3ac96e360672 | 2189 | |
charlesmn | 0:3ac96e360672 | 2190 | VL53L1_Error VL53L1_get_nvm_copy_data( |
charlesmn | 0:3ac96e360672 | 2191 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2192 | VL53L1_nvm_copy_data_t *pdata) |
charlesmn | 0:3ac96e360672 | 2193 | { |
charlesmn | 0:3ac96e360672 | 2194 | |
charlesmn | 0:3ac96e360672 | 2195 | |
charlesmn | 0:3ac96e360672 | 2196 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2197 | uint8_t comms_buffer[VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 2198 | |
charlesmn | 0:3ac96e360672 | 2199 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2200 | |
charlesmn | 0:3ac96e360672 | 2201 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2202 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 2203 | Dev, |
charlesmn | 0:3ac96e360672 | 2204 | VL53L1_IDENTIFICATION__MODEL_ID, |
charlesmn | 0:3ac96e360672 | 2205 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2206 | VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 2207 | |
charlesmn | 0:3ac96e360672 | 2208 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2209 | status = VL53L1_i2c_decode_nvm_copy_data( |
charlesmn | 0:3ac96e360672 | 2210 | VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 2211 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2212 | pdata); |
charlesmn | 0:3ac96e360672 | 2213 | |
charlesmn | 0:3ac96e360672 | 2214 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2215 | |
charlesmn | 0:3ac96e360672 | 2216 | return status; |
charlesmn | 0:3ac96e360672 | 2217 | } |
charlesmn | 0:3ac96e360672 | 2218 | |
charlesmn | 0:3ac96e360672 | 2219 | |
charlesmn | 0:3ac96e360672 | 2220 | VL53L1_Error VL53L1_i2c_encode_prev_shadow_system_results( |
charlesmn | 0:3ac96e360672 | 2221 | VL53L1_prev_shadow_system_results_t *pdata, |
charlesmn | 0:3ac96e360672 | 2222 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 2223 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 2224 | { |
charlesmn | 0:3ac96e360672 | 2225 | |
charlesmn | 0:3ac96e360672 | 2226 | |
charlesmn | 0:3ac96e360672 | 2227 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2228 | |
charlesmn | 0:3ac96e360672 | 2229 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2230 | |
charlesmn | 0:3ac96e360672 | 2231 | if (buf_size < VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 2232 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 2233 | |
charlesmn | 0:3ac96e360672 | 2234 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 2235 | pdata->prev_shadow_result__interrupt_status & 0x3F; |
charlesmn | 0:3ac96e360672 | 2236 | *(pbuffer + 1) = |
charlesmn | 0:3ac96e360672 | 2237 | pdata->prev_shadow_result__range_status; |
charlesmn | 0:3ac96e360672 | 2238 | *(pbuffer + 2) = |
charlesmn | 0:3ac96e360672 | 2239 | pdata->prev_shadow_result__report_status & 0xF; |
charlesmn | 0:3ac96e360672 | 2240 | *(pbuffer + 3) = |
charlesmn | 0:3ac96e360672 | 2241 | pdata->prev_shadow_result__stream_count; |
charlesmn | 0:3ac96e360672 | 2242 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2243 | pdata->prev_shadow_result__dss_actual_effective_spads_sd0, |
charlesmn | 0:3ac96e360672 | 2244 | 2, |
charlesmn | 0:3ac96e360672 | 2245 | pbuffer + 4); |
charlesmn | 0:3ac96e360672 | 2246 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2247 | pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd0, |
charlesmn | 0:3ac96e360672 | 2248 | 2, |
charlesmn | 0:3ac96e360672 | 2249 | pbuffer + 6); |
charlesmn | 0:3ac96e360672 | 2250 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2251 | pdata->prev_shadow_result__ambient_count_rate_mcps_sd0, |
charlesmn | 0:3ac96e360672 | 2252 | 2, |
charlesmn | 0:3ac96e360672 | 2253 | pbuffer + 8); |
charlesmn | 0:3ac96e360672 | 2254 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2255 | pdata->prev_shadow_result__sigma_sd0, |
charlesmn | 0:3ac96e360672 | 2256 | 2, |
charlesmn | 0:3ac96e360672 | 2257 | pbuffer + 10); |
charlesmn | 0:3ac96e360672 | 2258 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2259 | pdata->prev_shadow_result__phase_sd0, |
charlesmn | 0:3ac96e360672 | 2260 | 2, |
charlesmn | 0:3ac96e360672 | 2261 | pbuffer + 12); |
charlesmn | 0:3ac96e360672 | 2262 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2263 | pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd0, |
charlesmn | 0:3ac96e360672 | 2264 | 2, |
charlesmn | 0:3ac96e360672 | 2265 | pbuffer + 14); |
charlesmn | 0:3ac96e360672 | 2266 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2267 | pdata->psr__peak_signal_count_rate_crosstalk_corrected_mcps_sd0, |
charlesmn | 0:3ac96e360672 | 2268 | 2, |
charlesmn | 0:3ac96e360672 | 2269 | pbuffer + 16); |
charlesmn | 0:3ac96e360672 | 2270 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2271 | pdata->prev_shadow_result__mm_inner_actual_effective_spads_sd0, |
charlesmn | 0:3ac96e360672 | 2272 | 2, |
charlesmn | 0:3ac96e360672 | 2273 | pbuffer + 18); |
charlesmn | 0:3ac96e360672 | 2274 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2275 | pdata->prev_shadow_result__mm_outer_actual_effective_spads_sd0, |
charlesmn | 0:3ac96e360672 | 2276 | 2, |
charlesmn | 0:3ac96e360672 | 2277 | pbuffer + 20); |
charlesmn | 0:3ac96e360672 | 2278 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2279 | pdata->prev_shadow_result__avg_signal_count_rate_mcps_sd0, |
charlesmn | 0:3ac96e360672 | 2280 | 2, |
charlesmn | 0:3ac96e360672 | 2281 | pbuffer + 22); |
charlesmn | 0:3ac96e360672 | 2282 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2283 | pdata->prev_shadow_result__dss_actual_effective_spads_sd1, |
charlesmn | 0:3ac96e360672 | 2284 | 2, |
charlesmn | 0:3ac96e360672 | 2285 | pbuffer + 24); |
charlesmn | 0:3ac96e360672 | 2286 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2287 | pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd1, |
charlesmn | 0:3ac96e360672 | 2288 | 2, |
charlesmn | 0:3ac96e360672 | 2289 | pbuffer + 26); |
charlesmn | 0:3ac96e360672 | 2290 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2291 | pdata->prev_shadow_result__ambient_count_rate_mcps_sd1, |
charlesmn | 0:3ac96e360672 | 2292 | 2, |
charlesmn | 0:3ac96e360672 | 2293 | pbuffer + 28); |
charlesmn | 0:3ac96e360672 | 2294 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2295 | pdata->prev_shadow_result__sigma_sd1, |
charlesmn | 0:3ac96e360672 | 2296 | 2, |
charlesmn | 0:3ac96e360672 | 2297 | pbuffer + 30); |
charlesmn | 0:3ac96e360672 | 2298 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2299 | pdata->prev_shadow_result__phase_sd1, |
charlesmn | 0:3ac96e360672 | 2300 | 2, |
charlesmn | 0:3ac96e360672 | 2301 | pbuffer + 32); |
charlesmn | 0:3ac96e360672 | 2302 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2303 | pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd1, |
charlesmn | 0:3ac96e360672 | 2304 | 2, |
charlesmn | 0:3ac96e360672 | 2305 | pbuffer + 34); |
charlesmn | 0:3ac96e360672 | 2306 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2307 | pdata->prev_shadow_result__spare_0_sd1, |
charlesmn | 0:3ac96e360672 | 2308 | 2, |
charlesmn | 0:3ac96e360672 | 2309 | pbuffer + 36); |
charlesmn | 0:3ac96e360672 | 2310 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2311 | pdata->prev_shadow_result__spare_1_sd1, |
charlesmn | 0:3ac96e360672 | 2312 | 2, |
charlesmn | 0:3ac96e360672 | 2313 | pbuffer + 38); |
charlesmn | 0:3ac96e360672 | 2314 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2315 | pdata->prev_shadow_result__spare_2_sd1, |
charlesmn | 0:3ac96e360672 | 2316 | 2, |
charlesmn | 0:3ac96e360672 | 2317 | pbuffer + 40); |
charlesmn | 0:3ac96e360672 | 2318 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2319 | pdata->prev_shadow_result__spare_3_sd1, |
charlesmn | 0:3ac96e360672 | 2320 | 2, |
charlesmn | 0:3ac96e360672 | 2321 | pbuffer + 42); |
charlesmn | 0:3ac96e360672 | 2322 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2323 | |
charlesmn | 0:3ac96e360672 | 2324 | |
charlesmn | 0:3ac96e360672 | 2325 | return status; |
charlesmn | 0:3ac96e360672 | 2326 | } |
charlesmn | 0:3ac96e360672 | 2327 | |
charlesmn | 0:3ac96e360672 | 2328 | |
charlesmn | 0:3ac96e360672 | 2329 | VL53L1_Error VL53L1_i2c_decode_prev_shadow_system_results( |
charlesmn | 0:3ac96e360672 | 2330 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 2331 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 2332 | VL53L1_prev_shadow_system_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 2333 | { |
charlesmn | 0:3ac96e360672 | 2334 | |
charlesmn | 0:3ac96e360672 | 2335 | |
charlesmn | 0:3ac96e360672 | 2336 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2337 | |
charlesmn | 0:3ac96e360672 | 2338 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2339 | |
charlesmn | 0:3ac96e360672 | 2340 | if (buf_size < VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 2341 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 2342 | |
charlesmn | 0:3ac96e360672 | 2343 | pdata->prev_shadow_result__interrupt_status = |
charlesmn | 0:3ac96e360672 | 2344 | (*(pbuffer + 0)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 2345 | pdata->prev_shadow_result__range_status = |
charlesmn | 0:3ac96e360672 | 2346 | (*(pbuffer + 1)); |
charlesmn | 0:3ac96e360672 | 2347 | pdata->prev_shadow_result__report_status = |
charlesmn | 0:3ac96e360672 | 2348 | (*(pbuffer + 2)) & 0xF; |
charlesmn | 0:3ac96e360672 | 2349 | pdata->prev_shadow_result__stream_count = |
charlesmn | 0:3ac96e360672 | 2350 | (*(pbuffer + 3)); |
charlesmn | 0:3ac96e360672 | 2351 | pdata->prev_shadow_result__dss_actual_effective_spads_sd0 = |
charlesmn | 0:3ac96e360672 | 2352 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 4)); |
charlesmn | 0:3ac96e360672 | 2353 | pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd0 = |
charlesmn | 0:3ac96e360672 | 2354 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 6)); |
charlesmn | 0:3ac96e360672 | 2355 | pdata->prev_shadow_result__ambient_count_rate_mcps_sd0 = |
charlesmn | 0:3ac96e360672 | 2356 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8)); |
charlesmn | 0:3ac96e360672 | 2357 | pdata->prev_shadow_result__sigma_sd0 = |
charlesmn | 0:3ac96e360672 | 2358 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10)); |
charlesmn | 0:3ac96e360672 | 2359 | pdata->prev_shadow_result__phase_sd0 = |
charlesmn | 0:3ac96e360672 | 2360 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12)); |
charlesmn | 0:3ac96e360672 | 2361 | pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd0 = |
charlesmn | 0:3ac96e360672 | 2362 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14)); |
charlesmn | 0:3ac96e360672 | 2363 | pdata->psr__peak_signal_count_rate_crosstalk_corrected_mcps_sd0 = |
charlesmn | 0:3ac96e360672 | 2364 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16)); |
charlesmn | 0:3ac96e360672 | 2365 | pdata->prev_shadow_result__mm_inner_actual_effective_spads_sd0 = |
charlesmn | 0:3ac96e360672 | 2366 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18)); |
charlesmn | 0:3ac96e360672 | 2367 | pdata->prev_shadow_result__mm_outer_actual_effective_spads_sd0 = |
charlesmn | 0:3ac96e360672 | 2368 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 20)); |
charlesmn | 0:3ac96e360672 | 2369 | pdata->prev_shadow_result__avg_signal_count_rate_mcps_sd0 = |
charlesmn | 0:3ac96e360672 | 2370 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22)); |
charlesmn | 0:3ac96e360672 | 2371 | pdata->prev_shadow_result__dss_actual_effective_spads_sd1 = |
charlesmn | 0:3ac96e360672 | 2372 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24)); |
charlesmn | 0:3ac96e360672 | 2373 | pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd1 = |
charlesmn | 0:3ac96e360672 | 2374 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 26)); |
charlesmn | 0:3ac96e360672 | 2375 | pdata->prev_shadow_result__ambient_count_rate_mcps_sd1 = |
charlesmn | 0:3ac96e360672 | 2376 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 28)); |
charlesmn | 0:3ac96e360672 | 2377 | pdata->prev_shadow_result__sigma_sd1 = |
charlesmn | 0:3ac96e360672 | 2378 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 30)); |
charlesmn | 0:3ac96e360672 | 2379 | pdata->prev_shadow_result__phase_sd1 = |
charlesmn | 0:3ac96e360672 | 2380 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 32)); |
charlesmn | 0:3ac96e360672 | 2381 | pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd1 = |
charlesmn | 0:3ac96e360672 | 2382 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 34)); |
charlesmn | 0:3ac96e360672 | 2383 | pdata->prev_shadow_result__spare_0_sd1 = |
charlesmn | 0:3ac96e360672 | 2384 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 36)); |
charlesmn | 0:3ac96e360672 | 2385 | pdata->prev_shadow_result__spare_1_sd1 = |
charlesmn | 0:3ac96e360672 | 2386 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 38)); |
charlesmn | 0:3ac96e360672 | 2387 | pdata->prev_shadow_result__spare_2_sd1 = |
charlesmn | 0:3ac96e360672 | 2388 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 40)); |
charlesmn | 0:3ac96e360672 | 2389 | pdata->prev_shadow_result__spare_3_sd1 = |
charlesmn | 0:3ac96e360672 | 2390 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 42)); |
charlesmn | 0:3ac96e360672 | 2391 | |
charlesmn | 0:3ac96e360672 | 2392 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2393 | |
charlesmn | 0:3ac96e360672 | 2394 | return status; |
charlesmn | 0:3ac96e360672 | 2395 | } |
charlesmn | 0:3ac96e360672 | 2396 | |
charlesmn | 0:3ac96e360672 | 2397 | |
charlesmn | 0:3ac96e360672 | 2398 | VL53L1_Error VL53L1_set_prev_shadow_system_results( |
charlesmn | 0:3ac96e360672 | 2399 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2400 | VL53L1_prev_shadow_system_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 2401 | { |
charlesmn | 0:3ac96e360672 | 2402 | |
charlesmn | 0:3ac96e360672 | 2403 | |
charlesmn | 0:3ac96e360672 | 2404 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2405 | uint8_t comms_buffer[VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 2406 | |
charlesmn | 0:3ac96e360672 | 2407 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2408 | |
charlesmn | 0:3ac96e360672 | 2409 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2410 | status = VL53L1_i2c_encode_prev_shadow_system_results( |
charlesmn | 0:3ac96e360672 | 2411 | pdata, |
charlesmn | 0:3ac96e360672 | 2412 | VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 2413 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 2414 | |
charlesmn | 0:3ac96e360672 | 2415 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2416 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2417 | |
charlesmn | 0:3ac96e360672 | 2418 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2419 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 2420 | Dev, |
charlesmn | 0:3ac96e360672 | 2421 | VL53L1_PREV_SHADOW_RESULT__INTERRUPT_STATUS, |
charlesmn | 0:3ac96e360672 | 2422 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2423 | VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 2424 | |
charlesmn | 0:3ac96e360672 | 2425 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2426 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2427 | |
charlesmn | 0:3ac96e360672 | 2428 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2429 | |
charlesmn | 0:3ac96e360672 | 2430 | return status; |
charlesmn | 0:3ac96e360672 | 2431 | } |
charlesmn | 0:3ac96e360672 | 2432 | |
charlesmn | 0:3ac96e360672 | 2433 | |
charlesmn | 0:3ac96e360672 | 2434 | VL53L1_Error VL53L1_get_prev_shadow_system_results( |
charlesmn | 0:3ac96e360672 | 2435 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2436 | VL53L1_prev_shadow_system_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 2437 | { |
charlesmn | 0:3ac96e360672 | 2438 | |
charlesmn | 0:3ac96e360672 | 2439 | |
charlesmn | 0:3ac96e360672 | 2440 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2441 | uint8_t comms_buffer[VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 2442 | |
charlesmn | 0:3ac96e360672 | 2443 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2444 | |
charlesmn | 0:3ac96e360672 | 2445 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2446 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2447 | |
charlesmn | 0:3ac96e360672 | 2448 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2449 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 2450 | Dev, |
charlesmn | 0:3ac96e360672 | 2451 | VL53L1_PREV_SHADOW_RESULT__INTERRUPT_STATUS, |
charlesmn | 0:3ac96e360672 | 2452 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2453 | VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 2454 | |
charlesmn | 0:3ac96e360672 | 2455 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2456 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2457 | |
charlesmn | 0:3ac96e360672 | 2458 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2459 | status = VL53L1_i2c_decode_prev_shadow_system_results( |
charlesmn | 0:3ac96e360672 | 2460 | VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 2461 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2462 | pdata); |
charlesmn | 0:3ac96e360672 | 2463 | |
charlesmn | 0:3ac96e360672 | 2464 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2465 | |
charlesmn | 0:3ac96e360672 | 2466 | return status; |
charlesmn | 0:3ac96e360672 | 2467 | } |
charlesmn | 0:3ac96e360672 | 2468 | |
charlesmn | 0:3ac96e360672 | 2469 | |
charlesmn | 0:3ac96e360672 | 2470 | VL53L1_Error VL53L1_i2c_encode_prev_shadow_core_results( |
charlesmn | 0:3ac96e360672 | 2471 | VL53L1_prev_shadow_core_results_t *pdata, |
charlesmn | 0:3ac96e360672 | 2472 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 2473 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 2474 | { |
charlesmn | 0:3ac96e360672 | 2475 | |
charlesmn | 0:3ac96e360672 | 2476 | |
charlesmn | 0:3ac96e360672 | 2477 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2478 | |
charlesmn | 0:3ac96e360672 | 2479 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2480 | |
charlesmn | 0:3ac96e360672 | 2481 | if (buf_size < VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 2482 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 2483 | |
charlesmn | 0:3ac96e360672 | 2484 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 2485 | pdata->prev_shadow_result_core__ambient_window_events_sd0, |
charlesmn | 0:3ac96e360672 | 2486 | 4, |
charlesmn | 0:3ac96e360672 | 2487 | pbuffer + 0); |
charlesmn | 0:3ac96e360672 | 2488 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 2489 | pdata->prev_shadow_result_core__ranging_total_events_sd0, |
charlesmn | 0:3ac96e360672 | 2490 | 4, |
charlesmn | 0:3ac96e360672 | 2491 | pbuffer + 4); |
charlesmn | 0:3ac96e360672 | 2492 | VL53L1_i2c_encode_int32_t( |
charlesmn | 0:3ac96e360672 | 2493 | pdata->prev_shadow_result_core__signal_total_events_sd0, |
charlesmn | 0:3ac96e360672 | 2494 | 4, |
charlesmn | 0:3ac96e360672 | 2495 | pbuffer + 8); |
charlesmn | 0:3ac96e360672 | 2496 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 2497 | pdata->prev_shadow_result_core__total_periods_elapsed_sd0, |
charlesmn | 0:3ac96e360672 | 2498 | 4, |
charlesmn | 0:3ac96e360672 | 2499 | pbuffer + 12); |
charlesmn | 0:3ac96e360672 | 2500 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 2501 | pdata->prev_shadow_result_core__ambient_window_events_sd1, |
charlesmn | 0:3ac96e360672 | 2502 | 4, |
charlesmn | 0:3ac96e360672 | 2503 | pbuffer + 16); |
charlesmn | 0:3ac96e360672 | 2504 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 2505 | pdata->prev_shadow_result_core__ranging_total_events_sd1, |
charlesmn | 0:3ac96e360672 | 2506 | 4, |
charlesmn | 0:3ac96e360672 | 2507 | pbuffer + 20); |
charlesmn | 0:3ac96e360672 | 2508 | VL53L1_i2c_encode_int32_t( |
charlesmn | 0:3ac96e360672 | 2509 | pdata->prev_shadow_result_core__signal_total_events_sd1, |
charlesmn | 0:3ac96e360672 | 2510 | 4, |
charlesmn | 0:3ac96e360672 | 2511 | pbuffer + 24); |
charlesmn | 0:3ac96e360672 | 2512 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 2513 | pdata->prev_shadow_result_core__total_periods_elapsed_sd1, |
charlesmn | 0:3ac96e360672 | 2514 | 4, |
charlesmn | 0:3ac96e360672 | 2515 | pbuffer + 28); |
charlesmn | 0:3ac96e360672 | 2516 | *(pbuffer + 32) = |
charlesmn | 0:3ac96e360672 | 2517 | pdata->prev_shadow_result_core__spare_0; |
charlesmn | 0:3ac96e360672 | 2518 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2519 | |
charlesmn | 0:3ac96e360672 | 2520 | |
charlesmn | 0:3ac96e360672 | 2521 | return status; |
charlesmn | 0:3ac96e360672 | 2522 | } |
charlesmn | 0:3ac96e360672 | 2523 | |
charlesmn | 0:3ac96e360672 | 2524 | |
charlesmn | 0:3ac96e360672 | 2525 | VL53L1_Error VL53L1_i2c_decode_prev_shadow_core_results( |
charlesmn | 0:3ac96e360672 | 2526 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 2527 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 2528 | VL53L1_prev_shadow_core_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 2529 | { |
charlesmn | 0:3ac96e360672 | 2530 | |
charlesmn | 0:3ac96e360672 | 2531 | |
charlesmn | 0:3ac96e360672 | 2532 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2533 | |
charlesmn | 0:3ac96e360672 | 2534 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2535 | |
charlesmn | 0:3ac96e360672 | 2536 | if (buf_size < VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 2537 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 2538 | |
charlesmn | 0:3ac96e360672 | 2539 | pdata->prev_shadow_result_core__ambient_window_events_sd0 = |
charlesmn | 0:3ac96e360672 | 2540 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 0)); |
charlesmn | 0:3ac96e360672 | 2541 | pdata->prev_shadow_result_core__ranging_total_events_sd0 = |
charlesmn | 0:3ac96e360672 | 2542 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 4)); |
charlesmn | 0:3ac96e360672 | 2543 | pdata->prev_shadow_result_core__signal_total_events_sd0 = |
charlesmn | 0:3ac96e360672 | 2544 | (VL53L1_i2c_decode_int32_t(4, pbuffer + 8)); |
charlesmn | 0:3ac96e360672 | 2545 | pdata->prev_shadow_result_core__total_periods_elapsed_sd0 = |
charlesmn | 0:3ac96e360672 | 2546 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 12)); |
charlesmn | 0:3ac96e360672 | 2547 | pdata->prev_shadow_result_core__ambient_window_events_sd1 = |
charlesmn | 0:3ac96e360672 | 2548 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 16)); |
charlesmn | 0:3ac96e360672 | 2549 | pdata->prev_shadow_result_core__ranging_total_events_sd1 = |
charlesmn | 0:3ac96e360672 | 2550 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 20)); |
charlesmn | 0:3ac96e360672 | 2551 | pdata->prev_shadow_result_core__signal_total_events_sd1 = |
charlesmn | 0:3ac96e360672 | 2552 | (VL53L1_i2c_decode_int32_t(4, pbuffer + 24)); |
charlesmn | 0:3ac96e360672 | 2553 | pdata->prev_shadow_result_core__total_periods_elapsed_sd1 = |
charlesmn | 0:3ac96e360672 | 2554 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 28)); |
charlesmn | 0:3ac96e360672 | 2555 | pdata->prev_shadow_result_core__spare_0 = |
charlesmn | 0:3ac96e360672 | 2556 | (*(pbuffer + 32)); |
charlesmn | 0:3ac96e360672 | 2557 | |
charlesmn | 0:3ac96e360672 | 2558 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2559 | |
charlesmn | 0:3ac96e360672 | 2560 | return status; |
charlesmn | 0:3ac96e360672 | 2561 | } |
charlesmn | 0:3ac96e360672 | 2562 | |
charlesmn | 0:3ac96e360672 | 2563 | |
charlesmn | 0:3ac96e360672 | 2564 | VL53L1_Error VL53L1_set_prev_shadow_core_results( |
charlesmn | 0:3ac96e360672 | 2565 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2566 | VL53L1_prev_shadow_core_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 2567 | { |
charlesmn | 0:3ac96e360672 | 2568 | |
charlesmn | 0:3ac96e360672 | 2569 | |
charlesmn | 0:3ac96e360672 | 2570 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2571 | uint8_t comms_buffer[VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 2572 | |
charlesmn | 0:3ac96e360672 | 2573 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2574 | |
charlesmn | 0:3ac96e360672 | 2575 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2576 | status = VL53L1_i2c_encode_prev_shadow_core_results( |
charlesmn | 0:3ac96e360672 | 2577 | pdata, |
charlesmn | 0:3ac96e360672 | 2578 | VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 2579 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 2580 | |
charlesmn | 0:3ac96e360672 | 2581 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2582 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2583 | |
charlesmn | 0:3ac96e360672 | 2584 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2585 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 2586 | Dev, |
charlesmn | 0:3ac96e360672 | 2587 | VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0, |
charlesmn | 0:3ac96e360672 | 2588 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2589 | VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 2590 | |
charlesmn | 0:3ac96e360672 | 2591 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2592 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2593 | |
charlesmn | 0:3ac96e360672 | 2594 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2595 | |
charlesmn | 0:3ac96e360672 | 2596 | return status; |
charlesmn | 0:3ac96e360672 | 2597 | } |
charlesmn | 0:3ac96e360672 | 2598 | |
charlesmn | 0:3ac96e360672 | 2599 | |
charlesmn | 0:3ac96e360672 | 2600 | VL53L1_Error VL53L1_get_prev_shadow_core_results( |
charlesmn | 0:3ac96e360672 | 2601 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2602 | VL53L1_prev_shadow_core_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 2603 | { |
charlesmn | 0:3ac96e360672 | 2604 | |
charlesmn | 0:3ac96e360672 | 2605 | |
charlesmn | 0:3ac96e360672 | 2606 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2607 | uint8_t comms_buffer[VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 2608 | |
charlesmn | 0:3ac96e360672 | 2609 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2610 | |
charlesmn | 0:3ac96e360672 | 2611 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2612 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2613 | |
charlesmn | 0:3ac96e360672 | 2614 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2615 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 2616 | Dev, |
charlesmn | 0:3ac96e360672 | 2617 | VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0, |
charlesmn | 0:3ac96e360672 | 2618 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2619 | VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 2620 | |
charlesmn | 0:3ac96e360672 | 2621 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2622 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2623 | |
charlesmn | 0:3ac96e360672 | 2624 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2625 | status = VL53L1_i2c_decode_prev_shadow_core_results( |
charlesmn | 0:3ac96e360672 | 2626 | VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 2627 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2628 | pdata); |
charlesmn | 0:3ac96e360672 | 2629 | |
charlesmn | 0:3ac96e360672 | 2630 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2631 | |
charlesmn | 0:3ac96e360672 | 2632 | return status; |
charlesmn | 0:3ac96e360672 | 2633 | } |
charlesmn | 0:3ac96e360672 | 2634 | |
charlesmn | 0:3ac96e360672 | 2635 | |
charlesmn | 0:3ac96e360672 | 2636 | VL53L1_Error VL53L1_i2c_encode_patch_debug( |
charlesmn | 0:3ac96e360672 | 2637 | VL53L1_patch_debug_t *pdata, |
charlesmn | 0:3ac96e360672 | 2638 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 2639 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 2640 | { |
charlesmn | 0:3ac96e360672 | 2641 | |
charlesmn | 0:3ac96e360672 | 2642 | |
charlesmn | 0:3ac96e360672 | 2643 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2644 | |
charlesmn | 0:3ac96e360672 | 2645 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2646 | |
charlesmn | 0:3ac96e360672 | 2647 | if (buf_size < VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 2648 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 2649 | |
charlesmn | 0:3ac96e360672 | 2650 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 2651 | pdata->result__debug_status; |
charlesmn | 0:3ac96e360672 | 2652 | *(pbuffer + 1) = |
charlesmn | 0:3ac96e360672 | 2653 | pdata->result__debug_stage; |
charlesmn | 0:3ac96e360672 | 2654 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2655 | |
charlesmn | 0:3ac96e360672 | 2656 | |
charlesmn | 0:3ac96e360672 | 2657 | return status; |
charlesmn | 0:3ac96e360672 | 2658 | } |
charlesmn | 0:3ac96e360672 | 2659 | |
charlesmn | 0:3ac96e360672 | 2660 | |
charlesmn | 0:3ac96e360672 | 2661 | VL53L1_Error VL53L1_i2c_decode_patch_debug( |
charlesmn | 0:3ac96e360672 | 2662 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 2663 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 2664 | VL53L1_patch_debug_t *pdata) |
charlesmn | 0:3ac96e360672 | 2665 | { |
charlesmn | 0:3ac96e360672 | 2666 | |
charlesmn | 0:3ac96e360672 | 2667 | |
charlesmn | 0:3ac96e360672 | 2668 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2669 | |
charlesmn | 0:3ac96e360672 | 2670 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2671 | |
charlesmn | 0:3ac96e360672 | 2672 | if (buf_size < VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 2673 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 2674 | |
charlesmn | 0:3ac96e360672 | 2675 | pdata->result__debug_status = |
charlesmn | 0:3ac96e360672 | 2676 | (*(pbuffer + 0)); |
charlesmn | 0:3ac96e360672 | 2677 | pdata->result__debug_stage = |
charlesmn | 0:3ac96e360672 | 2678 | (*(pbuffer + 1)); |
charlesmn | 0:3ac96e360672 | 2679 | |
charlesmn | 0:3ac96e360672 | 2680 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2681 | |
charlesmn | 0:3ac96e360672 | 2682 | return status; |
charlesmn | 0:3ac96e360672 | 2683 | } |
charlesmn | 0:3ac96e360672 | 2684 | |
charlesmn | 0:3ac96e360672 | 2685 | |
charlesmn | 0:3ac96e360672 | 2686 | VL53L1_Error VL53L1_set_patch_debug( |
charlesmn | 0:3ac96e360672 | 2687 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2688 | VL53L1_patch_debug_t *pdata) |
charlesmn | 0:3ac96e360672 | 2689 | { |
charlesmn | 0:3ac96e360672 | 2690 | |
charlesmn | 0:3ac96e360672 | 2691 | |
charlesmn | 0:3ac96e360672 | 2692 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2693 | uint8_t comms_buffer[VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 2694 | |
charlesmn | 0:3ac96e360672 | 2695 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2696 | |
charlesmn | 0:3ac96e360672 | 2697 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2698 | status = VL53L1_i2c_encode_patch_debug( |
charlesmn | 0:3ac96e360672 | 2699 | pdata, |
charlesmn | 0:3ac96e360672 | 2700 | VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 2701 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 2702 | |
charlesmn | 0:3ac96e360672 | 2703 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2704 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2705 | |
charlesmn | 0:3ac96e360672 | 2706 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2707 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 2708 | Dev, |
charlesmn | 0:3ac96e360672 | 2709 | VL53L1_RESULT__DEBUG_STATUS, |
charlesmn | 0:3ac96e360672 | 2710 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2711 | VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 2712 | |
charlesmn | 0:3ac96e360672 | 2713 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2714 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2715 | |
charlesmn | 0:3ac96e360672 | 2716 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2717 | |
charlesmn | 0:3ac96e360672 | 2718 | return status; |
charlesmn | 0:3ac96e360672 | 2719 | } |
charlesmn | 0:3ac96e360672 | 2720 | |
charlesmn | 0:3ac96e360672 | 2721 | |
charlesmn | 0:3ac96e360672 | 2722 | VL53L1_Error VL53L1_get_patch_debug( |
charlesmn | 0:3ac96e360672 | 2723 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2724 | VL53L1_patch_debug_t *pdata) |
charlesmn | 0:3ac96e360672 | 2725 | { |
charlesmn | 0:3ac96e360672 | 2726 | |
charlesmn | 0:3ac96e360672 | 2727 | |
charlesmn | 0:3ac96e360672 | 2728 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2729 | uint8_t comms_buffer[VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 2730 | |
charlesmn | 0:3ac96e360672 | 2731 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2732 | |
charlesmn | 0:3ac96e360672 | 2733 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2734 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2735 | |
charlesmn | 0:3ac96e360672 | 2736 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2737 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 2738 | Dev, |
charlesmn | 0:3ac96e360672 | 2739 | VL53L1_RESULT__DEBUG_STATUS, |
charlesmn | 0:3ac96e360672 | 2740 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2741 | VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 2742 | |
charlesmn | 0:3ac96e360672 | 2743 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2744 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2745 | |
charlesmn | 0:3ac96e360672 | 2746 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2747 | status = VL53L1_i2c_decode_patch_debug( |
charlesmn | 0:3ac96e360672 | 2748 | VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 2749 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2750 | pdata); |
charlesmn | 0:3ac96e360672 | 2751 | |
charlesmn | 0:3ac96e360672 | 2752 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2753 | |
charlesmn | 0:3ac96e360672 | 2754 | return status; |
charlesmn | 0:3ac96e360672 | 2755 | } |
charlesmn | 0:3ac96e360672 | 2756 | |
charlesmn | 0:3ac96e360672 | 2757 | |
charlesmn | 0:3ac96e360672 | 2758 | VL53L1_Error VL53L1_i2c_encode_gph_general_config( |
charlesmn | 0:3ac96e360672 | 2759 | VL53L1_gph_general_config_t *pdata, |
charlesmn | 0:3ac96e360672 | 2760 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 2761 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 2762 | { |
charlesmn | 0:3ac96e360672 | 2763 | |
charlesmn | 0:3ac96e360672 | 2764 | |
charlesmn | 0:3ac96e360672 | 2765 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2766 | |
charlesmn | 0:3ac96e360672 | 2767 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2768 | |
charlesmn | 0:3ac96e360672 | 2769 | if (buf_size < VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 2770 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 2771 | |
charlesmn | 0:3ac96e360672 | 2772 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2773 | pdata->gph__system__thresh_rate_high, |
charlesmn | 0:3ac96e360672 | 2774 | 2, |
charlesmn | 0:3ac96e360672 | 2775 | pbuffer + 0); |
charlesmn | 0:3ac96e360672 | 2776 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2777 | pdata->gph__system__thresh_rate_low, |
charlesmn | 0:3ac96e360672 | 2778 | 2, |
charlesmn | 0:3ac96e360672 | 2779 | pbuffer + 2); |
charlesmn | 0:3ac96e360672 | 2780 | *(pbuffer + 4) = |
charlesmn | 0:3ac96e360672 | 2781 | pdata->gph__system__interrupt_config_gpio; |
charlesmn | 0:3ac96e360672 | 2782 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2783 | |
charlesmn | 0:3ac96e360672 | 2784 | |
charlesmn | 0:3ac96e360672 | 2785 | return status; |
charlesmn | 0:3ac96e360672 | 2786 | } |
charlesmn | 0:3ac96e360672 | 2787 | |
charlesmn | 0:3ac96e360672 | 2788 | |
charlesmn | 0:3ac96e360672 | 2789 | VL53L1_Error VL53L1_i2c_decode_gph_general_config( |
charlesmn | 0:3ac96e360672 | 2790 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 2791 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 2792 | VL53L1_gph_general_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 2793 | { |
charlesmn | 0:3ac96e360672 | 2794 | |
charlesmn | 0:3ac96e360672 | 2795 | |
charlesmn | 0:3ac96e360672 | 2796 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2797 | |
charlesmn | 0:3ac96e360672 | 2798 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2799 | |
charlesmn | 0:3ac96e360672 | 2800 | if (buf_size < VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 2801 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 2802 | |
charlesmn | 0:3ac96e360672 | 2803 | pdata->gph__system__thresh_rate_high = |
charlesmn | 0:3ac96e360672 | 2804 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 0)); |
charlesmn | 0:3ac96e360672 | 2805 | pdata->gph__system__thresh_rate_low = |
charlesmn | 0:3ac96e360672 | 2806 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 2)); |
charlesmn | 0:3ac96e360672 | 2807 | pdata->gph__system__interrupt_config_gpio = |
charlesmn | 0:3ac96e360672 | 2808 | (*(pbuffer + 4)); |
charlesmn | 0:3ac96e360672 | 2809 | |
charlesmn | 0:3ac96e360672 | 2810 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2811 | |
charlesmn | 0:3ac96e360672 | 2812 | return status; |
charlesmn | 0:3ac96e360672 | 2813 | } |
charlesmn | 0:3ac96e360672 | 2814 | |
charlesmn | 0:3ac96e360672 | 2815 | |
charlesmn | 0:3ac96e360672 | 2816 | VL53L1_Error VL53L1_set_gph_general_config( |
charlesmn | 0:3ac96e360672 | 2817 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2818 | VL53L1_gph_general_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 2819 | { |
charlesmn | 0:3ac96e360672 | 2820 | |
charlesmn | 0:3ac96e360672 | 2821 | |
charlesmn | 0:3ac96e360672 | 2822 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2823 | uint8_t comms_buffer[VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 2824 | |
charlesmn | 0:3ac96e360672 | 2825 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2826 | |
charlesmn | 0:3ac96e360672 | 2827 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2828 | status = VL53L1_i2c_encode_gph_general_config( |
charlesmn | 0:3ac96e360672 | 2829 | pdata, |
charlesmn | 0:3ac96e360672 | 2830 | VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 2831 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 2832 | |
charlesmn | 0:3ac96e360672 | 2833 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2834 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2835 | |
charlesmn | 0:3ac96e360672 | 2836 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2837 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 2838 | Dev, |
charlesmn | 0:3ac96e360672 | 2839 | VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH, |
charlesmn | 0:3ac96e360672 | 2840 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2841 | VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 2842 | |
charlesmn | 0:3ac96e360672 | 2843 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2844 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2845 | |
charlesmn | 0:3ac96e360672 | 2846 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2847 | |
charlesmn | 0:3ac96e360672 | 2848 | return status; |
charlesmn | 0:3ac96e360672 | 2849 | } |
charlesmn | 0:3ac96e360672 | 2850 | |
charlesmn | 0:3ac96e360672 | 2851 | |
charlesmn | 0:3ac96e360672 | 2852 | VL53L1_Error VL53L1_get_gph_general_config( |
charlesmn | 0:3ac96e360672 | 2853 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2854 | VL53L1_gph_general_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 2855 | { |
charlesmn | 0:3ac96e360672 | 2856 | |
charlesmn | 0:3ac96e360672 | 2857 | |
charlesmn | 0:3ac96e360672 | 2858 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2859 | uint8_t comms_buffer[VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 2860 | |
charlesmn | 0:3ac96e360672 | 2861 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2862 | |
charlesmn | 0:3ac96e360672 | 2863 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2864 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2865 | |
charlesmn | 0:3ac96e360672 | 2866 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2867 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 2868 | Dev, |
charlesmn | 0:3ac96e360672 | 2869 | VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH, |
charlesmn | 0:3ac96e360672 | 2870 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2871 | VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 2872 | |
charlesmn | 0:3ac96e360672 | 2873 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2874 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2875 | |
charlesmn | 0:3ac96e360672 | 2876 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2877 | status = VL53L1_i2c_decode_gph_general_config( |
charlesmn | 0:3ac96e360672 | 2878 | VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 2879 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2880 | pdata); |
charlesmn | 0:3ac96e360672 | 2881 | |
charlesmn | 0:3ac96e360672 | 2882 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2883 | |
charlesmn | 0:3ac96e360672 | 2884 | return status; |
charlesmn | 0:3ac96e360672 | 2885 | } |
charlesmn | 0:3ac96e360672 | 2886 | |
charlesmn | 0:3ac96e360672 | 2887 | |
charlesmn | 0:3ac96e360672 | 2888 | VL53L1_Error VL53L1_i2c_encode_gph_static_config( |
charlesmn | 0:3ac96e360672 | 2889 | VL53L1_gph_static_config_t *pdata, |
charlesmn | 0:3ac96e360672 | 2890 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 2891 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 2892 | { |
charlesmn | 0:3ac96e360672 | 2893 | |
charlesmn | 0:3ac96e360672 | 2894 | |
charlesmn | 0:3ac96e360672 | 2895 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2896 | |
charlesmn | 0:3ac96e360672 | 2897 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2898 | |
charlesmn | 0:3ac96e360672 | 2899 | if (buf_size < VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 2900 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 2901 | |
charlesmn | 0:3ac96e360672 | 2902 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 2903 | pdata->gph__dss_config__roi_mode_control & 0x7; |
charlesmn | 0:3ac96e360672 | 2904 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 2905 | pdata->gph__dss_config__manual_effective_spads_select, |
charlesmn | 0:3ac96e360672 | 2906 | 2, |
charlesmn | 0:3ac96e360672 | 2907 | pbuffer + 1); |
charlesmn | 0:3ac96e360672 | 2908 | *(pbuffer + 3) = |
charlesmn | 0:3ac96e360672 | 2909 | pdata->gph__dss_config__manual_block_select; |
charlesmn | 0:3ac96e360672 | 2910 | *(pbuffer + 4) = |
charlesmn | 0:3ac96e360672 | 2911 | pdata->gph__dss_config__max_spads_limit; |
charlesmn | 0:3ac96e360672 | 2912 | *(pbuffer + 5) = |
charlesmn | 0:3ac96e360672 | 2913 | pdata->gph__dss_config__min_spads_limit; |
charlesmn | 0:3ac96e360672 | 2914 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2915 | |
charlesmn | 0:3ac96e360672 | 2916 | |
charlesmn | 0:3ac96e360672 | 2917 | return status; |
charlesmn | 0:3ac96e360672 | 2918 | } |
charlesmn | 0:3ac96e360672 | 2919 | |
charlesmn | 0:3ac96e360672 | 2920 | |
charlesmn | 0:3ac96e360672 | 2921 | VL53L1_Error VL53L1_i2c_decode_gph_static_config( |
charlesmn | 0:3ac96e360672 | 2922 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 2923 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 2924 | VL53L1_gph_static_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 2925 | { |
charlesmn | 0:3ac96e360672 | 2926 | |
charlesmn | 0:3ac96e360672 | 2927 | |
charlesmn | 0:3ac96e360672 | 2928 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2929 | |
charlesmn | 0:3ac96e360672 | 2930 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2931 | |
charlesmn | 0:3ac96e360672 | 2932 | if (buf_size < VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 2933 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 2934 | |
charlesmn | 0:3ac96e360672 | 2935 | pdata->gph__dss_config__roi_mode_control = |
charlesmn | 0:3ac96e360672 | 2936 | (*(pbuffer + 0)) & 0x7; |
charlesmn | 0:3ac96e360672 | 2937 | pdata->gph__dss_config__manual_effective_spads_select = |
charlesmn | 0:3ac96e360672 | 2938 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 1)); |
charlesmn | 0:3ac96e360672 | 2939 | pdata->gph__dss_config__manual_block_select = |
charlesmn | 0:3ac96e360672 | 2940 | (*(pbuffer + 3)); |
charlesmn | 0:3ac96e360672 | 2941 | pdata->gph__dss_config__max_spads_limit = |
charlesmn | 0:3ac96e360672 | 2942 | (*(pbuffer + 4)); |
charlesmn | 0:3ac96e360672 | 2943 | pdata->gph__dss_config__min_spads_limit = |
charlesmn | 0:3ac96e360672 | 2944 | (*(pbuffer + 5)); |
charlesmn | 0:3ac96e360672 | 2945 | |
charlesmn | 0:3ac96e360672 | 2946 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2947 | |
charlesmn | 0:3ac96e360672 | 2948 | return status; |
charlesmn | 0:3ac96e360672 | 2949 | } |
charlesmn | 0:3ac96e360672 | 2950 | |
charlesmn | 0:3ac96e360672 | 2951 | |
charlesmn | 0:3ac96e360672 | 2952 | VL53L1_Error VL53L1_set_gph_static_config( |
charlesmn | 0:3ac96e360672 | 2953 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2954 | VL53L1_gph_static_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 2955 | { |
charlesmn | 0:3ac96e360672 | 2956 | |
charlesmn | 0:3ac96e360672 | 2957 | |
charlesmn | 0:3ac96e360672 | 2958 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2959 | uint8_t comms_buffer[VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 2960 | |
charlesmn | 0:3ac96e360672 | 2961 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2962 | |
charlesmn | 0:3ac96e360672 | 2963 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2964 | status = VL53L1_i2c_encode_gph_static_config( |
charlesmn | 0:3ac96e360672 | 2965 | pdata, |
charlesmn | 0:3ac96e360672 | 2966 | VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 2967 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 2968 | |
charlesmn | 0:3ac96e360672 | 2969 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2970 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2971 | |
charlesmn | 0:3ac96e360672 | 2972 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2973 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 2974 | Dev, |
charlesmn | 0:3ac96e360672 | 2975 | VL53L1_GPH__DSS_CONFIG__ROI_MODE_CONTROL, |
charlesmn | 0:3ac96e360672 | 2976 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 2977 | VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 2978 | |
charlesmn | 0:3ac96e360672 | 2979 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2980 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 2981 | |
charlesmn | 0:3ac96e360672 | 2982 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2983 | |
charlesmn | 0:3ac96e360672 | 2984 | return status; |
charlesmn | 0:3ac96e360672 | 2985 | } |
charlesmn | 0:3ac96e360672 | 2986 | |
charlesmn | 0:3ac96e360672 | 2987 | |
charlesmn | 0:3ac96e360672 | 2988 | VL53L1_Error VL53L1_get_gph_static_config( |
charlesmn | 0:3ac96e360672 | 2989 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2990 | VL53L1_gph_static_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 2991 | { |
charlesmn | 0:3ac96e360672 | 2992 | |
charlesmn | 0:3ac96e360672 | 2993 | |
charlesmn | 0:3ac96e360672 | 2994 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2995 | uint8_t comms_buffer[VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 2996 | |
charlesmn | 0:3ac96e360672 | 2997 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2998 | |
charlesmn | 0:3ac96e360672 | 2999 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3000 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3001 | |
charlesmn | 0:3ac96e360672 | 3002 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3003 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 3004 | Dev, |
charlesmn | 0:3ac96e360672 | 3005 | VL53L1_GPH__DSS_CONFIG__ROI_MODE_CONTROL, |
charlesmn | 0:3ac96e360672 | 3006 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 3007 | VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 3008 | |
charlesmn | 0:3ac96e360672 | 3009 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3010 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3011 | |
charlesmn | 0:3ac96e360672 | 3012 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3013 | status = VL53L1_i2c_decode_gph_static_config( |
charlesmn | 0:3ac96e360672 | 3014 | VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 3015 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 3016 | pdata); |
charlesmn | 0:3ac96e360672 | 3017 | |
charlesmn | 0:3ac96e360672 | 3018 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3019 | |
charlesmn | 0:3ac96e360672 | 3020 | return status; |
charlesmn | 0:3ac96e360672 | 3021 | } |
charlesmn | 0:3ac96e360672 | 3022 | |
charlesmn | 0:3ac96e360672 | 3023 | |
charlesmn | 0:3ac96e360672 | 3024 | VL53L1_Error VL53L1_i2c_encode_gph_timing_config( |
charlesmn | 0:3ac96e360672 | 3025 | VL53L1_gph_timing_config_t *pdata, |
charlesmn | 0:3ac96e360672 | 3026 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 3027 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 3028 | { |
charlesmn | 0:3ac96e360672 | 3029 | |
charlesmn | 0:3ac96e360672 | 3030 | |
charlesmn | 0:3ac96e360672 | 3031 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3032 | |
charlesmn | 0:3ac96e360672 | 3033 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3034 | |
charlesmn | 0:3ac96e360672 | 3035 | if (buf_size < VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 3036 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 3037 | |
charlesmn | 0:3ac96e360672 | 3038 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 3039 | pdata->gph__mm_config__timeout_macrop_a_hi & 0xF; |
charlesmn | 0:3ac96e360672 | 3040 | *(pbuffer + 1) = |
charlesmn | 0:3ac96e360672 | 3041 | pdata->gph__mm_config__timeout_macrop_a_lo; |
charlesmn | 0:3ac96e360672 | 3042 | *(pbuffer + 2) = |
charlesmn | 0:3ac96e360672 | 3043 | pdata->gph__mm_config__timeout_macrop_b_hi & 0xF; |
charlesmn | 0:3ac96e360672 | 3044 | *(pbuffer + 3) = |
charlesmn | 0:3ac96e360672 | 3045 | pdata->gph__mm_config__timeout_macrop_b_lo; |
charlesmn | 0:3ac96e360672 | 3046 | *(pbuffer + 4) = |
charlesmn | 0:3ac96e360672 | 3047 | pdata->gph__range_config__timeout_macrop_a_hi & 0xF; |
charlesmn | 0:3ac96e360672 | 3048 | *(pbuffer + 5) = |
charlesmn | 0:3ac96e360672 | 3049 | pdata->gph__range_config__timeout_macrop_a_lo; |
charlesmn | 0:3ac96e360672 | 3050 | *(pbuffer + 6) = |
charlesmn | 0:3ac96e360672 | 3051 | pdata->gph__range_config__vcsel_period_a & 0x3F; |
charlesmn | 0:3ac96e360672 | 3052 | *(pbuffer + 7) = |
charlesmn | 0:3ac96e360672 | 3053 | pdata->gph__range_config__vcsel_period_b & 0x3F; |
charlesmn | 0:3ac96e360672 | 3054 | *(pbuffer + 8) = |
charlesmn | 0:3ac96e360672 | 3055 | pdata->gph__range_config__timeout_macrop_b_hi & 0xF; |
charlesmn | 0:3ac96e360672 | 3056 | *(pbuffer + 9) = |
charlesmn | 0:3ac96e360672 | 3057 | pdata->gph__range_config__timeout_macrop_b_lo; |
charlesmn | 0:3ac96e360672 | 3058 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3059 | pdata->gph__range_config__sigma_thresh, |
charlesmn | 0:3ac96e360672 | 3060 | 2, |
charlesmn | 0:3ac96e360672 | 3061 | pbuffer + 10); |
charlesmn | 0:3ac96e360672 | 3062 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3063 | pdata->gph__range_config__min_count_rate_rtn_limit_mcps, |
charlesmn | 0:3ac96e360672 | 3064 | 2, |
charlesmn | 0:3ac96e360672 | 3065 | pbuffer + 12); |
charlesmn | 0:3ac96e360672 | 3066 | *(pbuffer + 14) = |
charlesmn | 0:3ac96e360672 | 3067 | pdata->gph__range_config__valid_phase_low; |
charlesmn | 0:3ac96e360672 | 3068 | *(pbuffer + 15) = |
charlesmn | 0:3ac96e360672 | 3069 | pdata->gph__range_config__valid_phase_high; |
charlesmn | 0:3ac96e360672 | 3070 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3071 | |
charlesmn | 0:3ac96e360672 | 3072 | |
charlesmn | 0:3ac96e360672 | 3073 | return status; |
charlesmn | 0:3ac96e360672 | 3074 | } |
charlesmn | 0:3ac96e360672 | 3075 | |
charlesmn | 0:3ac96e360672 | 3076 | |
charlesmn | 0:3ac96e360672 | 3077 | VL53L1_Error VL53L1_i2c_decode_gph_timing_config( |
charlesmn | 0:3ac96e360672 | 3078 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 3079 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 3080 | VL53L1_gph_timing_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 3081 | { |
charlesmn | 0:3ac96e360672 | 3082 | |
charlesmn | 0:3ac96e360672 | 3083 | |
charlesmn | 0:3ac96e360672 | 3084 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3085 | |
charlesmn | 0:3ac96e360672 | 3086 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3087 | |
charlesmn | 0:3ac96e360672 | 3088 | if (buf_size < VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 3089 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 3090 | |
charlesmn | 0:3ac96e360672 | 3091 | pdata->gph__mm_config__timeout_macrop_a_hi = |
charlesmn | 0:3ac96e360672 | 3092 | (*(pbuffer + 0)) & 0xF; |
charlesmn | 0:3ac96e360672 | 3093 | pdata->gph__mm_config__timeout_macrop_a_lo = |
charlesmn | 0:3ac96e360672 | 3094 | (*(pbuffer + 1)); |
charlesmn | 0:3ac96e360672 | 3095 | pdata->gph__mm_config__timeout_macrop_b_hi = |
charlesmn | 0:3ac96e360672 | 3096 | (*(pbuffer + 2)) & 0xF; |
charlesmn | 0:3ac96e360672 | 3097 | pdata->gph__mm_config__timeout_macrop_b_lo = |
charlesmn | 0:3ac96e360672 | 3098 | (*(pbuffer + 3)); |
charlesmn | 0:3ac96e360672 | 3099 | pdata->gph__range_config__timeout_macrop_a_hi = |
charlesmn | 0:3ac96e360672 | 3100 | (*(pbuffer + 4)) & 0xF; |
charlesmn | 0:3ac96e360672 | 3101 | pdata->gph__range_config__timeout_macrop_a_lo = |
charlesmn | 0:3ac96e360672 | 3102 | (*(pbuffer + 5)); |
charlesmn | 0:3ac96e360672 | 3103 | pdata->gph__range_config__vcsel_period_a = |
charlesmn | 0:3ac96e360672 | 3104 | (*(pbuffer + 6)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 3105 | pdata->gph__range_config__vcsel_period_b = |
charlesmn | 0:3ac96e360672 | 3106 | (*(pbuffer + 7)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 3107 | pdata->gph__range_config__timeout_macrop_b_hi = |
charlesmn | 0:3ac96e360672 | 3108 | (*(pbuffer + 8)) & 0xF; |
charlesmn | 0:3ac96e360672 | 3109 | pdata->gph__range_config__timeout_macrop_b_lo = |
charlesmn | 0:3ac96e360672 | 3110 | (*(pbuffer + 9)); |
charlesmn | 0:3ac96e360672 | 3111 | pdata->gph__range_config__sigma_thresh = |
charlesmn | 0:3ac96e360672 | 3112 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10)); |
charlesmn | 0:3ac96e360672 | 3113 | pdata->gph__range_config__min_count_rate_rtn_limit_mcps = |
charlesmn | 0:3ac96e360672 | 3114 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12)); |
charlesmn | 0:3ac96e360672 | 3115 | pdata->gph__range_config__valid_phase_low = |
charlesmn | 0:3ac96e360672 | 3116 | (*(pbuffer + 14)); |
charlesmn | 0:3ac96e360672 | 3117 | pdata->gph__range_config__valid_phase_high = |
charlesmn | 0:3ac96e360672 | 3118 | (*(pbuffer + 15)); |
charlesmn | 0:3ac96e360672 | 3119 | |
charlesmn | 0:3ac96e360672 | 3120 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3121 | |
charlesmn | 0:3ac96e360672 | 3122 | return status; |
charlesmn | 0:3ac96e360672 | 3123 | } |
charlesmn | 0:3ac96e360672 | 3124 | |
charlesmn | 0:3ac96e360672 | 3125 | |
charlesmn | 0:3ac96e360672 | 3126 | VL53L1_Error VL53L1_set_gph_timing_config( |
charlesmn | 0:3ac96e360672 | 3127 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3128 | VL53L1_gph_timing_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 3129 | { |
charlesmn | 0:3ac96e360672 | 3130 | |
charlesmn | 0:3ac96e360672 | 3131 | |
charlesmn | 0:3ac96e360672 | 3132 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3133 | uint8_t comms_buffer[VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 3134 | |
charlesmn | 0:3ac96e360672 | 3135 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3136 | |
charlesmn | 0:3ac96e360672 | 3137 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3138 | status = VL53L1_i2c_encode_gph_timing_config( |
charlesmn | 0:3ac96e360672 | 3139 | pdata, |
charlesmn | 0:3ac96e360672 | 3140 | VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 3141 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 3142 | |
charlesmn | 0:3ac96e360672 | 3143 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3144 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3145 | |
charlesmn | 0:3ac96e360672 | 3146 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3147 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 3148 | Dev, |
charlesmn | 0:3ac96e360672 | 3149 | VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_A_HI, |
charlesmn | 0:3ac96e360672 | 3150 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 3151 | VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 3152 | |
charlesmn | 0:3ac96e360672 | 3153 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3154 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3155 | |
charlesmn | 0:3ac96e360672 | 3156 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3157 | |
charlesmn | 0:3ac96e360672 | 3158 | return status; |
charlesmn | 0:3ac96e360672 | 3159 | } |
charlesmn | 0:3ac96e360672 | 3160 | |
charlesmn | 0:3ac96e360672 | 3161 | |
charlesmn | 0:3ac96e360672 | 3162 | VL53L1_Error VL53L1_get_gph_timing_config( |
charlesmn | 0:3ac96e360672 | 3163 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3164 | VL53L1_gph_timing_config_t *pdata) |
charlesmn | 0:3ac96e360672 | 3165 | { |
charlesmn | 0:3ac96e360672 | 3166 | |
charlesmn | 0:3ac96e360672 | 3167 | |
charlesmn | 0:3ac96e360672 | 3168 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3169 | uint8_t comms_buffer[VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 3170 | |
charlesmn | 0:3ac96e360672 | 3171 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3172 | |
charlesmn | 0:3ac96e360672 | 3173 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3174 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3175 | |
charlesmn | 0:3ac96e360672 | 3176 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3177 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 3178 | Dev, |
charlesmn | 0:3ac96e360672 | 3179 | VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_A_HI, |
charlesmn | 0:3ac96e360672 | 3180 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 3181 | VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 3182 | |
charlesmn | 0:3ac96e360672 | 3183 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3184 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3185 | |
charlesmn | 0:3ac96e360672 | 3186 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3187 | status = VL53L1_i2c_decode_gph_timing_config( |
charlesmn | 0:3ac96e360672 | 3188 | VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 3189 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 3190 | pdata); |
charlesmn | 0:3ac96e360672 | 3191 | |
charlesmn | 0:3ac96e360672 | 3192 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3193 | |
charlesmn | 0:3ac96e360672 | 3194 | return status; |
charlesmn | 0:3ac96e360672 | 3195 | } |
charlesmn | 0:3ac96e360672 | 3196 | |
charlesmn | 0:3ac96e360672 | 3197 | |
charlesmn | 0:3ac96e360672 | 3198 | VL53L1_Error VL53L1_i2c_encode_fw_internal( |
charlesmn | 0:3ac96e360672 | 3199 | VL53L1_fw_internal_t *pdata, |
charlesmn | 0:3ac96e360672 | 3200 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 3201 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 3202 | { |
charlesmn | 0:3ac96e360672 | 3203 | |
charlesmn | 0:3ac96e360672 | 3204 | |
charlesmn | 0:3ac96e360672 | 3205 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3206 | |
charlesmn | 0:3ac96e360672 | 3207 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3208 | |
charlesmn | 0:3ac96e360672 | 3209 | if (buf_size < VL53L1_FW_INTERNAL_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 3210 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 3211 | |
charlesmn | 0:3ac96e360672 | 3212 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 3213 | pdata->firmware__internal_stream_count_div; |
charlesmn | 0:3ac96e360672 | 3214 | *(pbuffer + 1) = |
charlesmn | 0:3ac96e360672 | 3215 | pdata->firmware__internal_stream_counter_val; |
charlesmn | 0:3ac96e360672 | 3216 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3217 | |
charlesmn | 0:3ac96e360672 | 3218 | |
charlesmn | 0:3ac96e360672 | 3219 | return status; |
charlesmn | 0:3ac96e360672 | 3220 | } |
charlesmn | 0:3ac96e360672 | 3221 | |
charlesmn | 0:3ac96e360672 | 3222 | |
charlesmn | 0:3ac96e360672 | 3223 | VL53L1_Error VL53L1_i2c_decode_fw_internal( |
charlesmn | 0:3ac96e360672 | 3224 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 3225 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 3226 | VL53L1_fw_internal_t *pdata) |
charlesmn | 0:3ac96e360672 | 3227 | { |
charlesmn | 0:3ac96e360672 | 3228 | |
charlesmn | 0:3ac96e360672 | 3229 | |
charlesmn | 0:3ac96e360672 | 3230 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3231 | |
charlesmn | 0:3ac96e360672 | 3232 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3233 | |
charlesmn | 0:3ac96e360672 | 3234 | if (buf_size < VL53L1_FW_INTERNAL_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 3235 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 3236 | |
charlesmn | 0:3ac96e360672 | 3237 | pdata->firmware__internal_stream_count_div = |
charlesmn | 0:3ac96e360672 | 3238 | (*(pbuffer + 0)); |
charlesmn | 0:3ac96e360672 | 3239 | pdata->firmware__internal_stream_counter_val = |
charlesmn | 0:3ac96e360672 | 3240 | (*(pbuffer + 1)); |
charlesmn | 0:3ac96e360672 | 3241 | |
charlesmn | 0:3ac96e360672 | 3242 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3243 | |
charlesmn | 0:3ac96e360672 | 3244 | return status; |
charlesmn | 0:3ac96e360672 | 3245 | } |
charlesmn | 0:3ac96e360672 | 3246 | |
charlesmn | 0:3ac96e360672 | 3247 | |
charlesmn | 0:3ac96e360672 | 3248 | VL53L1_Error VL53L1_set_fw_internal( |
charlesmn | 0:3ac96e360672 | 3249 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3250 | VL53L1_fw_internal_t *pdata) |
charlesmn | 0:3ac96e360672 | 3251 | { |
charlesmn | 0:3ac96e360672 | 3252 | |
charlesmn | 0:3ac96e360672 | 3253 | |
charlesmn | 0:3ac96e360672 | 3254 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3255 | uint8_t comms_buffer[VL53L1_FW_INTERNAL_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 3256 | |
charlesmn | 0:3ac96e360672 | 3257 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3258 | |
charlesmn | 0:3ac96e360672 | 3259 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3260 | status = VL53L1_i2c_encode_fw_internal( |
charlesmn | 0:3ac96e360672 | 3261 | pdata, |
charlesmn | 0:3ac96e360672 | 3262 | VL53L1_FW_INTERNAL_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 3263 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 3264 | |
charlesmn | 0:3ac96e360672 | 3265 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3266 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3267 | |
charlesmn | 0:3ac96e360672 | 3268 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3269 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 3270 | Dev, |
charlesmn | 0:3ac96e360672 | 3271 | VL53L1_FIRMWARE__INTERNAL_STREAM_COUNT_DIV, |
charlesmn | 0:3ac96e360672 | 3272 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 3273 | VL53L1_FW_INTERNAL_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 3274 | |
charlesmn | 0:3ac96e360672 | 3275 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3276 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3277 | |
charlesmn | 0:3ac96e360672 | 3278 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3279 | |
charlesmn | 0:3ac96e360672 | 3280 | return status; |
charlesmn | 0:3ac96e360672 | 3281 | } |
charlesmn | 0:3ac96e360672 | 3282 | |
charlesmn | 0:3ac96e360672 | 3283 | |
charlesmn | 0:3ac96e360672 | 3284 | VL53L1_Error VL53L1_get_fw_internal( |
charlesmn | 0:3ac96e360672 | 3285 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3286 | VL53L1_fw_internal_t *pdata) |
charlesmn | 0:3ac96e360672 | 3287 | { |
charlesmn | 0:3ac96e360672 | 3288 | |
charlesmn | 0:3ac96e360672 | 3289 | |
charlesmn | 0:3ac96e360672 | 3290 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3291 | uint8_t comms_buffer[VL53L1_FW_INTERNAL_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 3292 | |
charlesmn | 0:3ac96e360672 | 3293 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3294 | |
charlesmn | 0:3ac96e360672 | 3295 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3296 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3297 | |
charlesmn | 0:3ac96e360672 | 3298 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3299 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 3300 | Dev, |
charlesmn | 0:3ac96e360672 | 3301 | VL53L1_FIRMWARE__INTERNAL_STREAM_COUNT_DIV, |
charlesmn | 0:3ac96e360672 | 3302 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 3303 | VL53L1_FW_INTERNAL_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 3304 | |
charlesmn | 0:3ac96e360672 | 3305 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3306 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3307 | |
charlesmn | 0:3ac96e360672 | 3308 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3309 | status = VL53L1_i2c_decode_fw_internal( |
charlesmn | 0:3ac96e360672 | 3310 | VL53L1_FW_INTERNAL_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 3311 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 3312 | pdata); |
charlesmn | 0:3ac96e360672 | 3313 | |
charlesmn | 0:3ac96e360672 | 3314 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3315 | |
charlesmn | 0:3ac96e360672 | 3316 | return status; |
charlesmn | 0:3ac96e360672 | 3317 | } |
charlesmn | 0:3ac96e360672 | 3318 | |
charlesmn | 0:3ac96e360672 | 3319 | |
charlesmn | 0:3ac96e360672 | 3320 | VL53L1_Error VL53L1_i2c_encode_patch_results( |
charlesmn | 0:3ac96e360672 | 3321 | VL53L1_patch_results_t *pdata, |
charlesmn | 0:3ac96e360672 | 3322 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 3323 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 3324 | { |
charlesmn | 0:3ac96e360672 | 3325 | |
charlesmn | 0:3ac96e360672 | 3326 | |
charlesmn | 0:3ac96e360672 | 3327 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3328 | |
charlesmn | 0:3ac96e360672 | 3329 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3330 | |
charlesmn | 0:3ac96e360672 | 3331 | if (buf_size < VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 3332 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 3333 | |
charlesmn | 0:3ac96e360672 | 3334 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 3335 | pdata->dss_calc__roi_ctrl & 0x3; |
charlesmn | 0:3ac96e360672 | 3336 | *(pbuffer + 1) = |
charlesmn | 0:3ac96e360672 | 3337 | pdata->dss_calc__spare_1; |
charlesmn | 0:3ac96e360672 | 3338 | *(pbuffer + 2) = |
charlesmn | 0:3ac96e360672 | 3339 | pdata->dss_calc__spare_2; |
charlesmn | 0:3ac96e360672 | 3340 | *(pbuffer + 3) = |
charlesmn | 0:3ac96e360672 | 3341 | pdata->dss_calc__spare_3; |
charlesmn | 0:3ac96e360672 | 3342 | *(pbuffer + 4) = |
charlesmn | 0:3ac96e360672 | 3343 | pdata->dss_calc__spare_4; |
charlesmn | 0:3ac96e360672 | 3344 | *(pbuffer + 5) = |
charlesmn | 0:3ac96e360672 | 3345 | pdata->dss_calc__spare_5; |
charlesmn | 0:3ac96e360672 | 3346 | *(pbuffer + 6) = |
charlesmn | 0:3ac96e360672 | 3347 | pdata->dss_calc__spare_6; |
charlesmn | 0:3ac96e360672 | 3348 | *(pbuffer + 7) = |
charlesmn | 0:3ac96e360672 | 3349 | pdata->dss_calc__spare_7; |
charlesmn | 0:3ac96e360672 | 3350 | *(pbuffer + 8) = |
charlesmn | 0:3ac96e360672 | 3351 | pdata->dss_calc__user_roi_spad_en_0; |
charlesmn | 0:3ac96e360672 | 3352 | *(pbuffer + 9) = |
charlesmn | 0:3ac96e360672 | 3353 | pdata->dss_calc__user_roi_spad_en_1; |
charlesmn | 0:3ac96e360672 | 3354 | *(pbuffer + 10) = |
charlesmn | 0:3ac96e360672 | 3355 | pdata->dss_calc__user_roi_spad_en_2; |
charlesmn | 0:3ac96e360672 | 3356 | *(pbuffer + 11) = |
charlesmn | 0:3ac96e360672 | 3357 | pdata->dss_calc__user_roi_spad_en_3; |
charlesmn | 0:3ac96e360672 | 3358 | *(pbuffer + 12) = |
charlesmn | 0:3ac96e360672 | 3359 | pdata->dss_calc__user_roi_spad_en_4; |
charlesmn | 0:3ac96e360672 | 3360 | *(pbuffer + 13) = |
charlesmn | 0:3ac96e360672 | 3361 | pdata->dss_calc__user_roi_spad_en_5; |
charlesmn | 0:3ac96e360672 | 3362 | *(pbuffer + 14) = |
charlesmn | 0:3ac96e360672 | 3363 | pdata->dss_calc__user_roi_spad_en_6; |
charlesmn | 0:3ac96e360672 | 3364 | *(pbuffer + 15) = |
charlesmn | 0:3ac96e360672 | 3365 | pdata->dss_calc__user_roi_spad_en_7; |
charlesmn | 0:3ac96e360672 | 3366 | *(pbuffer + 16) = |
charlesmn | 0:3ac96e360672 | 3367 | pdata->dss_calc__user_roi_spad_en_8; |
charlesmn | 0:3ac96e360672 | 3368 | *(pbuffer + 17) = |
charlesmn | 0:3ac96e360672 | 3369 | pdata->dss_calc__user_roi_spad_en_9; |
charlesmn | 0:3ac96e360672 | 3370 | *(pbuffer + 18) = |
charlesmn | 0:3ac96e360672 | 3371 | pdata->dss_calc__user_roi_spad_en_10; |
charlesmn | 0:3ac96e360672 | 3372 | *(pbuffer + 19) = |
charlesmn | 0:3ac96e360672 | 3373 | pdata->dss_calc__user_roi_spad_en_11; |
charlesmn | 0:3ac96e360672 | 3374 | *(pbuffer + 20) = |
charlesmn | 0:3ac96e360672 | 3375 | pdata->dss_calc__user_roi_spad_en_12; |
charlesmn | 0:3ac96e360672 | 3376 | *(pbuffer + 21) = |
charlesmn | 0:3ac96e360672 | 3377 | pdata->dss_calc__user_roi_spad_en_13; |
charlesmn | 0:3ac96e360672 | 3378 | *(pbuffer + 22) = |
charlesmn | 0:3ac96e360672 | 3379 | pdata->dss_calc__user_roi_spad_en_14; |
charlesmn | 0:3ac96e360672 | 3380 | *(pbuffer + 23) = |
charlesmn | 0:3ac96e360672 | 3381 | pdata->dss_calc__user_roi_spad_en_15; |
charlesmn | 0:3ac96e360672 | 3382 | *(pbuffer + 24) = |
charlesmn | 0:3ac96e360672 | 3383 | pdata->dss_calc__user_roi_spad_en_16; |
charlesmn | 0:3ac96e360672 | 3384 | *(pbuffer + 25) = |
charlesmn | 0:3ac96e360672 | 3385 | pdata->dss_calc__user_roi_spad_en_17; |
charlesmn | 0:3ac96e360672 | 3386 | *(pbuffer + 26) = |
charlesmn | 0:3ac96e360672 | 3387 | pdata->dss_calc__user_roi_spad_en_18; |
charlesmn | 0:3ac96e360672 | 3388 | *(pbuffer + 27) = |
charlesmn | 0:3ac96e360672 | 3389 | pdata->dss_calc__user_roi_spad_en_19; |
charlesmn | 0:3ac96e360672 | 3390 | *(pbuffer + 28) = |
charlesmn | 0:3ac96e360672 | 3391 | pdata->dss_calc__user_roi_spad_en_20; |
charlesmn | 0:3ac96e360672 | 3392 | *(pbuffer + 29) = |
charlesmn | 0:3ac96e360672 | 3393 | pdata->dss_calc__user_roi_spad_en_21; |
charlesmn | 0:3ac96e360672 | 3394 | *(pbuffer + 30) = |
charlesmn | 0:3ac96e360672 | 3395 | pdata->dss_calc__user_roi_spad_en_22; |
charlesmn | 0:3ac96e360672 | 3396 | *(pbuffer + 31) = |
charlesmn | 0:3ac96e360672 | 3397 | pdata->dss_calc__user_roi_spad_en_23; |
charlesmn | 0:3ac96e360672 | 3398 | *(pbuffer + 32) = |
charlesmn | 0:3ac96e360672 | 3399 | pdata->dss_calc__user_roi_spad_en_24; |
charlesmn | 0:3ac96e360672 | 3400 | *(pbuffer + 33) = |
charlesmn | 0:3ac96e360672 | 3401 | pdata->dss_calc__user_roi_spad_en_25; |
charlesmn | 0:3ac96e360672 | 3402 | *(pbuffer + 34) = |
charlesmn | 0:3ac96e360672 | 3403 | pdata->dss_calc__user_roi_spad_en_26; |
charlesmn | 0:3ac96e360672 | 3404 | *(pbuffer + 35) = |
charlesmn | 0:3ac96e360672 | 3405 | pdata->dss_calc__user_roi_spad_en_27; |
charlesmn | 0:3ac96e360672 | 3406 | *(pbuffer + 36) = |
charlesmn | 0:3ac96e360672 | 3407 | pdata->dss_calc__user_roi_spad_en_28; |
charlesmn | 0:3ac96e360672 | 3408 | *(pbuffer + 37) = |
charlesmn | 0:3ac96e360672 | 3409 | pdata->dss_calc__user_roi_spad_en_29; |
charlesmn | 0:3ac96e360672 | 3410 | *(pbuffer + 38) = |
charlesmn | 0:3ac96e360672 | 3411 | pdata->dss_calc__user_roi_spad_en_30; |
charlesmn | 0:3ac96e360672 | 3412 | *(pbuffer + 39) = |
charlesmn | 0:3ac96e360672 | 3413 | pdata->dss_calc__user_roi_spad_en_31; |
charlesmn | 0:3ac96e360672 | 3414 | *(pbuffer + 40) = |
charlesmn | 0:3ac96e360672 | 3415 | pdata->dss_calc__user_roi_0; |
charlesmn | 0:3ac96e360672 | 3416 | *(pbuffer + 41) = |
charlesmn | 0:3ac96e360672 | 3417 | pdata->dss_calc__user_roi_1; |
charlesmn | 0:3ac96e360672 | 3418 | *(pbuffer + 42) = |
charlesmn | 0:3ac96e360672 | 3419 | pdata->dss_calc__mode_roi_0; |
charlesmn | 0:3ac96e360672 | 3420 | *(pbuffer + 43) = |
charlesmn | 0:3ac96e360672 | 3421 | pdata->dss_calc__mode_roi_1; |
charlesmn | 0:3ac96e360672 | 3422 | *(pbuffer + 44) = |
charlesmn | 0:3ac96e360672 | 3423 | pdata->sigma_estimator_calc__spare_0; |
charlesmn | 0:3ac96e360672 | 3424 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3425 | pdata->vhv_result__peak_signal_rate_mcps, |
charlesmn | 0:3ac96e360672 | 3426 | 2, |
charlesmn | 0:3ac96e360672 | 3427 | pbuffer + 46); |
charlesmn | 0:3ac96e360672 | 3428 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 3429 | pdata->vhv_result__signal_total_events_ref, |
charlesmn | 0:3ac96e360672 | 3430 | 4, |
charlesmn | 0:3ac96e360672 | 3431 | pbuffer + 48); |
charlesmn | 0:3ac96e360672 | 3432 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3433 | pdata->phasecal_result__phase_output_ref, |
charlesmn | 0:3ac96e360672 | 3434 | 2, |
charlesmn | 0:3ac96e360672 | 3435 | pbuffer + 52); |
charlesmn | 0:3ac96e360672 | 3436 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3437 | pdata->dss_result__total_rate_per_spad, |
charlesmn | 0:3ac96e360672 | 3438 | 2, |
charlesmn | 0:3ac96e360672 | 3439 | pbuffer + 54); |
charlesmn | 0:3ac96e360672 | 3440 | *(pbuffer + 56) = |
charlesmn | 0:3ac96e360672 | 3441 | pdata->dss_result__enabled_blocks; |
charlesmn | 0:3ac96e360672 | 3442 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3443 | pdata->dss_result__num_requested_spads, |
charlesmn | 0:3ac96e360672 | 3444 | 2, |
charlesmn | 0:3ac96e360672 | 3445 | pbuffer + 58); |
charlesmn | 0:3ac96e360672 | 3446 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3447 | pdata->mm_result__inner_intersection_rate, |
charlesmn | 0:3ac96e360672 | 3448 | 2, |
charlesmn | 0:3ac96e360672 | 3449 | pbuffer + 62); |
charlesmn | 0:3ac96e360672 | 3450 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3451 | pdata->mm_result__outer_complement_rate, |
charlesmn | 0:3ac96e360672 | 3452 | 2, |
charlesmn | 0:3ac96e360672 | 3453 | pbuffer + 64); |
charlesmn | 0:3ac96e360672 | 3454 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3455 | pdata->mm_result__total_offset, |
charlesmn | 0:3ac96e360672 | 3456 | 2, |
charlesmn | 0:3ac96e360672 | 3457 | pbuffer + 66); |
charlesmn | 0:3ac96e360672 | 3458 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 3459 | pdata->xtalk_calc__xtalk_for_enabled_spads & 0xFFFFFF, |
charlesmn | 0:3ac96e360672 | 3460 | 4, |
charlesmn | 0:3ac96e360672 | 3461 | pbuffer + 68); |
charlesmn | 0:3ac96e360672 | 3462 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 3463 | pdata->xtalk_result__avg_xtalk_user_roi_kcps & 0xFFFFFF, |
charlesmn | 0:3ac96e360672 | 3464 | 4, |
charlesmn | 0:3ac96e360672 | 3465 | pbuffer + 72); |
charlesmn | 0:3ac96e360672 | 3466 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 3467 | pdata->xtalk_result__avg_xtalk_mm_inner_roi_kcps & 0xFFFFFF, |
charlesmn | 0:3ac96e360672 | 3468 | 4, |
charlesmn | 0:3ac96e360672 | 3469 | pbuffer + 76); |
charlesmn | 0:3ac96e360672 | 3470 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 3471 | pdata->xtalk_result__avg_xtalk_mm_outer_roi_kcps & 0xFFFFFF, |
charlesmn | 0:3ac96e360672 | 3472 | 4, |
charlesmn | 0:3ac96e360672 | 3473 | pbuffer + 80); |
charlesmn | 0:3ac96e360672 | 3474 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 3475 | pdata->range_result__accum_phase, |
charlesmn | 0:3ac96e360672 | 3476 | 4, |
charlesmn | 0:3ac96e360672 | 3477 | pbuffer + 84); |
charlesmn | 0:3ac96e360672 | 3478 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3479 | pdata->range_result__offset_corrected_range, |
charlesmn | 0:3ac96e360672 | 3480 | 2, |
charlesmn | 0:3ac96e360672 | 3481 | pbuffer + 88); |
charlesmn | 0:3ac96e360672 | 3482 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3483 | |
charlesmn | 0:3ac96e360672 | 3484 | |
charlesmn | 0:3ac96e360672 | 3485 | return status; |
charlesmn | 0:3ac96e360672 | 3486 | } |
charlesmn | 0:3ac96e360672 | 3487 | |
charlesmn | 0:3ac96e360672 | 3488 | |
charlesmn | 0:3ac96e360672 | 3489 | VL53L1_Error VL53L1_i2c_decode_patch_results( |
charlesmn | 0:3ac96e360672 | 3490 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 3491 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 3492 | VL53L1_patch_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 3493 | { |
charlesmn | 0:3ac96e360672 | 3494 | |
charlesmn | 0:3ac96e360672 | 3495 | |
charlesmn | 0:3ac96e360672 | 3496 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3497 | |
charlesmn | 0:3ac96e360672 | 3498 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3499 | |
charlesmn | 0:3ac96e360672 | 3500 | if (buf_size < VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 3501 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 3502 | |
charlesmn | 0:3ac96e360672 | 3503 | pdata->dss_calc__roi_ctrl = |
charlesmn | 0:3ac96e360672 | 3504 | (*(pbuffer + 0)) & 0x3; |
charlesmn | 0:3ac96e360672 | 3505 | pdata->dss_calc__spare_1 = |
charlesmn | 0:3ac96e360672 | 3506 | (*(pbuffer + 1)); |
charlesmn | 0:3ac96e360672 | 3507 | pdata->dss_calc__spare_2 = |
charlesmn | 0:3ac96e360672 | 3508 | (*(pbuffer + 2)); |
charlesmn | 0:3ac96e360672 | 3509 | pdata->dss_calc__spare_3 = |
charlesmn | 0:3ac96e360672 | 3510 | (*(pbuffer + 3)); |
charlesmn | 0:3ac96e360672 | 3511 | pdata->dss_calc__spare_4 = |
charlesmn | 0:3ac96e360672 | 3512 | (*(pbuffer + 4)); |
charlesmn | 0:3ac96e360672 | 3513 | pdata->dss_calc__spare_5 = |
charlesmn | 0:3ac96e360672 | 3514 | (*(pbuffer + 5)); |
charlesmn | 0:3ac96e360672 | 3515 | pdata->dss_calc__spare_6 = |
charlesmn | 0:3ac96e360672 | 3516 | (*(pbuffer + 6)); |
charlesmn | 0:3ac96e360672 | 3517 | pdata->dss_calc__spare_7 = |
charlesmn | 0:3ac96e360672 | 3518 | (*(pbuffer + 7)); |
charlesmn | 0:3ac96e360672 | 3519 | pdata->dss_calc__user_roi_spad_en_0 = |
charlesmn | 0:3ac96e360672 | 3520 | (*(pbuffer + 8)); |
charlesmn | 0:3ac96e360672 | 3521 | pdata->dss_calc__user_roi_spad_en_1 = |
charlesmn | 0:3ac96e360672 | 3522 | (*(pbuffer + 9)); |
charlesmn | 0:3ac96e360672 | 3523 | pdata->dss_calc__user_roi_spad_en_2 = |
charlesmn | 0:3ac96e360672 | 3524 | (*(pbuffer + 10)); |
charlesmn | 0:3ac96e360672 | 3525 | pdata->dss_calc__user_roi_spad_en_3 = |
charlesmn | 0:3ac96e360672 | 3526 | (*(pbuffer + 11)); |
charlesmn | 0:3ac96e360672 | 3527 | pdata->dss_calc__user_roi_spad_en_4 = |
charlesmn | 0:3ac96e360672 | 3528 | (*(pbuffer + 12)); |
charlesmn | 0:3ac96e360672 | 3529 | pdata->dss_calc__user_roi_spad_en_5 = |
charlesmn | 0:3ac96e360672 | 3530 | (*(pbuffer + 13)); |
charlesmn | 0:3ac96e360672 | 3531 | pdata->dss_calc__user_roi_spad_en_6 = |
charlesmn | 0:3ac96e360672 | 3532 | (*(pbuffer + 14)); |
charlesmn | 0:3ac96e360672 | 3533 | pdata->dss_calc__user_roi_spad_en_7 = |
charlesmn | 0:3ac96e360672 | 3534 | (*(pbuffer + 15)); |
charlesmn | 0:3ac96e360672 | 3535 | pdata->dss_calc__user_roi_spad_en_8 = |
charlesmn | 0:3ac96e360672 | 3536 | (*(pbuffer + 16)); |
charlesmn | 0:3ac96e360672 | 3537 | pdata->dss_calc__user_roi_spad_en_9 = |
charlesmn | 0:3ac96e360672 | 3538 | (*(pbuffer + 17)); |
charlesmn | 0:3ac96e360672 | 3539 | pdata->dss_calc__user_roi_spad_en_10 = |
charlesmn | 0:3ac96e360672 | 3540 | (*(pbuffer + 18)); |
charlesmn | 0:3ac96e360672 | 3541 | pdata->dss_calc__user_roi_spad_en_11 = |
charlesmn | 0:3ac96e360672 | 3542 | (*(pbuffer + 19)); |
charlesmn | 0:3ac96e360672 | 3543 | pdata->dss_calc__user_roi_spad_en_12 = |
charlesmn | 0:3ac96e360672 | 3544 | (*(pbuffer + 20)); |
charlesmn | 0:3ac96e360672 | 3545 | pdata->dss_calc__user_roi_spad_en_13 = |
charlesmn | 0:3ac96e360672 | 3546 | (*(pbuffer + 21)); |
charlesmn | 0:3ac96e360672 | 3547 | pdata->dss_calc__user_roi_spad_en_14 = |
charlesmn | 0:3ac96e360672 | 3548 | (*(pbuffer + 22)); |
charlesmn | 0:3ac96e360672 | 3549 | pdata->dss_calc__user_roi_spad_en_15 = |
charlesmn | 0:3ac96e360672 | 3550 | (*(pbuffer + 23)); |
charlesmn | 0:3ac96e360672 | 3551 | pdata->dss_calc__user_roi_spad_en_16 = |
charlesmn | 0:3ac96e360672 | 3552 | (*(pbuffer + 24)); |
charlesmn | 0:3ac96e360672 | 3553 | pdata->dss_calc__user_roi_spad_en_17 = |
charlesmn | 0:3ac96e360672 | 3554 | (*(pbuffer + 25)); |
charlesmn | 0:3ac96e360672 | 3555 | pdata->dss_calc__user_roi_spad_en_18 = |
charlesmn | 0:3ac96e360672 | 3556 | (*(pbuffer + 26)); |
charlesmn | 0:3ac96e360672 | 3557 | pdata->dss_calc__user_roi_spad_en_19 = |
charlesmn | 0:3ac96e360672 | 3558 | (*(pbuffer + 27)); |
charlesmn | 0:3ac96e360672 | 3559 | pdata->dss_calc__user_roi_spad_en_20 = |
charlesmn | 0:3ac96e360672 | 3560 | (*(pbuffer + 28)); |
charlesmn | 0:3ac96e360672 | 3561 | pdata->dss_calc__user_roi_spad_en_21 = |
charlesmn | 0:3ac96e360672 | 3562 | (*(pbuffer + 29)); |
charlesmn | 0:3ac96e360672 | 3563 | pdata->dss_calc__user_roi_spad_en_22 = |
charlesmn | 0:3ac96e360672 | 3564 | (*(pbuffer + 30)); |
charlesmn | 0:3ac96e360672 | 3565 | pdata->dss_calc__user_roi_spad_en_23 = |
charlesmn | 0:3ac96e360672 | 3566 | (*(pbuffer + 31)); |
charlesmn | 0:3ac96e360672 | 3567 | pdata->dss_calc__user_roi_spad_en_24 = |
charlesmn | 0:3ac96e360672 | 3568 | (*(pbuffer + 32)); |
charlesmn | 0:3ac96e360672 | 3569 | pdata->dss_calc__user_roi_spad_en_25 = |
charlesmn | 0:3ac96e360672 | 3570 | (*(pbuffer + 33)); |
charlesmn | 0:3ac96e360672 | 3571 | pdata->dss_calc__user_roi_spad_en_26 = |
charlesmn | 0:3ac96e360672 | 3572 | (*(pbuffer + 34)); |
charlesmn | 0:3ac96e360672 | 3573 | pdata->dss_calc__user_roi_spad_en_27 = |
charlesmn | 0:3ac96e360672 | 3574 | (*(pbuffer + 35)); |
charlesmn | 0:3ac96e360672 | 3575 | pdata->dss_calc__user_roi_spad_en_28 = |
charlesmn | 0:3ac96e360672 | 3576 | (*(pbuffer + 36)); |
charlesmn | 0:3ac96e360672 | 3577 | pdata->dss_calc__user_roi_spad_en_29 = |
charlesmn | 0:3ac96e360672 | 3578 | (*(pbuffer + 37)); |
charlesmn | 0:3ac96e360672 | 3579 | pdata->dss_calc__user_roi_spad_en_30 = |
charlesmn | 0:3ac96e360672 | 3580 | (*(pbuffer + 38)); |
charlesmn | 0:3ac96e360672 | 3581 | pdata->dss_calc__user_roi_spad_en_31 = |
charlesmn | 0:3ac96e360672 | 3582 | (*(pbuffer + 39)); |
charlesmn | 0:3ac96e360672 | 3583 | pdata->dss_calc__user_roi_0 = |
charlesmn | 0:3ac96e360672 | 3584 | (*(pbuffer + 40)); |
charlesmn | 0:3ac96e360672 | 3585 | pdata->dss_calc__user_roi_1 = |
charlesmn | 0:3ac96e360672 | 3586 | (*(pbuffer + 41)); |
charlesmn | 0:3ac96e360672 | 3587 | pdata->dss_calc__mode_roi_0 = |
charlesmn | 0:3ac96e360672 | 3588 | (*(pbuffer + 42)); |
charlesmn | 0:3ac96e360672 | 3589 | pdata->dss_calc__mode_roi_1 = |
charlesmn | 0:3ac96e360672 | 3590 | (*(pbuffer + 43)); |
charlesmn | 0:3ac96e360672 | 3591 | pdata->sigma_estimator_calc__spare_0 = |
charlesmn | 0:3ac96e360672 | 3592 | (*(pbuffer + 44)); |
charlesmn | 0:3ac96e360672 | 3593 | pdata->vhv_result__peak_signal_rate_mcps = |
charlesmn | 0:3ac96e360672 | 3594 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 46)); |
charlesmn | 0:3ac96e360672 | 3595 | pdata->vhv_result__signal_total_events_ref = |
charlesmn | 0:3ac96e360672 | 3596 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 48)); |
charlesmn | 0:3ac96e360672 | 3597 | pdata->phasecal_result__phase_output_ref = |
charlesmn | 0:3ac96e360672 | 3598 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 52)); |
charlesmn | 0:3ac96e360672 | 3599 | pdata->dss_result__total_rate_per_spad = |
charlesmn | 0:3ac96e360672 | 3600 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 54)); |
charlesmn | 0:3ac96e360672 | 3601 | pdata->dss_result__enabled_blocks = |
charlesmn | 0:3ac96e360672 | 3602 | (*(pbuffer + 56)); |
charlesmn | 0:3ac96e360672 | 3603 | pdata->dss_result__num_requested_spads = |
charlesmn | 0:3ac96e360672 | 3604 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 58)); |
charlesmn | 0:3ac96e360672 | 3605 | pdata->mm_result__inner_intersection_rate = |
charlesmn | 0:3ac96e360672 | 3606 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 62)); |
charlesmn | 0:3ac96e360672 | 3607 | pdata->mm_result__outer_complement_rate = |
charlesmn | 0:3ac96e360672 | 3608 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 64)); |
charlesmn | 0:3ac96e360672 | 3609 | pdata->mm_result__total_offset = |
charlesmn | 0:3ac96e360672 | 3610 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 66)); |
charlesmn | 0:3ac96e360672 | 3611 | pdata->xtalk_calc__xtalk_for_enabled_spads = |
charlesmn | 0:3ac96e360672 | 3612 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 68)) & 0xFFFFFF; |
charlesmn | 0:3ac96e360672 | 3613 | pdata->xtalk_result__avg_xtalk_user_roi_kcps = |
charlesmn | 0:3ac96e360672 | 3614 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 72)) & 0xFFFFFF; |
charlesmn | 0:3ac96e360672 | 3615 | pdata->xtalk_result__avg_xtalk_mm_inner_roi_kcps = |
charlesmn | 0:3ac96e360672 | 3616 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 76)) & 0xFFFFFF; |
charlesmn | 0:3ac96e360672 | 3617 | pdata->xtalk_result__avg_xtalk_mm_outer_roi_kcps = |
charlesmn | 0:3ac96e360672 | 3618 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 80)) & 0xFFFFFF; |
charlesmn | 0:3ac96e360672 | 3619 | pdata->range_result__accum_phase = |
charlesmn | 0:3ac96e360672 | 3620 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 84)); |
charlesmn | 0:3ac96e360672 | 3621 | pdata->range_result__offset_corrected_range = |
charlesmn | 0:3ac96e360672 | 3622 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 88)); |
charlesmn | 0:3ac96e360672 | 3623 | |
charlesmn | 0:3ac96e360672 | 3624 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3625 | |
charlesmn | 0:3ac96e360672 | 3626 | return status; |
charlesmn | 0:3ac96e360672 | 3627 | } |
charlesmn | 0:3ac96e360672 | 3628 | |
charlesmn | 0:3ac96e360672 | 3629 | |
charlesmn | 0:3ac96e360672 | 3630 | VL53L1_Error VL53L1_set_patch_results( |
charlesmn | 0:3ac96e360672 | 3631 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3632 | VL53L1_patch_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 3633 | { |
charlesmn | 0:3ac96e360672 | 3634 | |
charlesmn | 0:3ac96e360672 | 3635 | |
charlesmn | 0:3ac96e360672 | 3636 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3637 | uint8_t comms_buffer[VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 3638 | |
charlesmn | 0:3ac96e360672 | 3639 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3640 | |
charlesmn | 0:3ac96e360672 | 3641 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3642 | status = VL53L1_i2c_encode_patch_results( |
charlesmn | 0:3ac96e360672 | 3643 | pdata, |
charlesmn | 0:3ac96e360672 | 3644 | VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 3645 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 3646 | |
charlesmn | 0:3ac96e360672 | 3647 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3648 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3649 | |
charlesmn | 0:3ac96e360672 | 3650 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3651 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 3652 | Dev, |
charlesmn | 0:3ac96e360672 | 3653 | VL53L1_DSS_CALC__ROI_CTRL, |
charlesmn | 0:3ac96e360672 | 3654 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 3655 | VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 3656 | |
charlesmn | 0:3ac96e360672 | 3657 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3658 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3659 | |
charlesmn | 0:3ac96e360672 | 3660 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3661 | |
charlesmn | 0:3ac96e360672 | 3662 | return status; |
charlesmn | 0:3ac96e360672 | 3663 | } |
charlesmn | 0:3ac96e360672 | 3664 | |
charlesmn | 0:3ac96e360672 | 3665 | |
charlesmn | 0:3ac96e360672 | 3666 | VL53L1_Error VL53L1_get_patch_results( |
charlesmn | 0:3ac96e360672 | 3667 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3668 | VL53L1_patch_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 3669 | { |
charlesmn | 0:3ac96e360672 | 3670 | |
charlesmn | 0:3ac96e360672 | 3671 | |
charlesmn | 0:3ac96e360672 | 3672 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3673 | uint8_t comms_buffer[VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 3674 | |
charlesmn | 0:3ac96e360672 | 3675 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3676 | |
charlesmn | 0:3ac96e360672 | 3677 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3678 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3679 | |
charlesmn | 0:3ac96e360672 | 3680 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3681 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 3682 | Dev, |
charlesmn | 0:3ac96e360672 | 3683 | VL53L1_DSS_CALC__ROI_CTRL, |
charlesmn | 0:3ac96e360672 | 3684 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 3685 | VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 3686 | |
charlesmn | 0:3ac96e360672 | 3687 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3688 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3689 | |
charlesmn | 0:3ac96e360672 | 3690 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3691 | status = VL53L1_i2c_decode_patch_results( |
charlesmn | 0:3ac96e360672 | 3692 | VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 3693 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 3694 | pdata); |
charlesmn | 0:3ac96e360672 | 3695 | |
charlesmn | 0:3ac96e360672 | 3696 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3697 | |
charlesmn | 0:3ac96e360672 | 3698 | return status; |
charlesmn | 0:3ac96e360672 | 3699 | } |
charlesmn | 0:3ac96e360672 | 3700 | |
charlesmn | 0:3ac96e360672 | 3701 | |
charlesmn | 0:3ac96e360672 | 3702 | VL53L1_Error VL53L1_i2c_encode_shadow_system_results( |
charlesmn | 0:3ac96e360672 | 3703 | VL53L1_shadow_system_results_t *pdata, |
charlesmn | 0:3ac96e360672 | 3704 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 3705 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 3706 | { |
charlesmn | 0:3ac96e360672 | 3707 | |
charlesmn | 0:3ac96e360672 | 3708 | |
charlesmn | 0:3ac96e360672 | 3709 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3710 | |
charlesmn | 0:3ac96e360672 | 3711 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3712 | |
charlesmn | 0:3ac96e360672 | 3713 | if (buf_size < VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 3714 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 3715 | |
charlesmn | 0:3ac96e360672 | 3716 | *(pbuffer + 0) = |
charlesmn | 0:3ac96e360672 | 3717 | pdata->shadow_phasecal_result__vcsel_start; |
charlesmn | 0:3ac96e360672 | 3718 | *(pbuffer + 2) = |
charlesmn | 0:3ac96e360672 | 3719 | pdata->shadow_result__interrupt_status & 0x3F; |
charlesmn | 0:3ac96e360672 | 3720 | *(pbuffer + 3) = |
charlesmn | 0:3ac96e360672 | 3721 | pdata->shadow_result__range_status; |
charlesmn | 0:3ac96e360672 | 3722 | *(pbuffer + 4) = |
charlesmn | 0:3ac96e360672 | 3723 | pdata->shadow_result__report_status & 0xF; |
charlesmn | 0:3ac96e360672 | 3724 | *(pbuffer + 5) = |
charlesmn | 0:3ac96e360672 | 3725 | pdata->shadow_result__stream_count; |
charlesmn | 0:3ac96e360672 | 3726 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3727 | pdata->shadow_result__dss_actual_effective_spads_sd0, |
charlesmn | 0:3ac96e360672 | 3728 | 2, |
charlesmn | 0:3ac96e360672 | 3729 | pbuffer + 6); |
charlesmn | 0:3ac96e360672 | 3730 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3731 | pdata->shadow_result__peak_signal_count_rate_mcps_sd0, |
charlesmn | 0:3ac96e360672 | 3732 | 2, |
charlesmn | 0:3ac96e360672 | 3733 | pbuffer + 8); |
charlesmn | 0:3ac96e360672 | 3734 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3735 | pdata->shadow_result__ambient_count_rate_mcps_sd0, |
charlesmn | 0:3ac96e360672 | 3736 | 2, |
charlesmn | 0:3ac96e360672 | 3737 | pbuffer + 10); |
charlesmn | 0:3ac96e360672 | 3738 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3739 | pdata->shadow_result__sigma_sd0, |
charlesmn | 0:3ac96e360672 | 3740 | 2, |
charlesmn | 0:3ac96e360672 | 3741 | pbuffer + 12); |
charlesmn | 0:3ac96e360672 | 3742 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3743 | pdata->shadow_result__phase_sd0, |
charlesmn | 0:3ac96e360672 | 3744 | 2, |
charlesmn | 0:3ac96e360672 | 3745 | pbuffer + 14); |
charlesmn | 0:3ac96e360672 | 3746 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3747 | pdata->shadow_result__final_crosstalk_corrected_range_mm_sd0, |
charlesmn | 0:3ac96e360672 | 3748 | 2, |
charlesmn | 0:3ac96e360672 | 3749 | pbuffer + 16); |
charlesmn | 0:3ac96e360672 | 3750 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3751 | pdata->shr__peak_signal_count_rate_crosstalk_corrected_mcps_sd0, |
charlesmn | 0:3ac96e360672 | 3752 | 2, |
charlesmn | 0:3ac96e360672 | 3753 | pbuffer + 18); |
charlesmn | 0:3ac96e360672 | 3754 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3755 | pdata->shadow_result__mm_inner_actual_effective_spads_sd0, |
charlesmn | 0:3ac96e360672 | 3756 | 2, |
charlesmn | 0:3ac96e360672 | 3757 | pbuffer + 20); |
charlesmn | 0:3ac96e360672 | 3758 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3759 | pdata->shadow_result__mm_outer_actual_effective_spads_sd0, |
charlesmn | 0:3ac96e360672 | 3760 | 2, |
charlesmn | 0:3ac96e360672 | 3761 | pbuffer + 22); |
charlesmn | 0:3ac96e360672 | 3762 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3763 | pdata->shadow_result__avg_signal_count_rate_mcps_sd0, |
charlesmn | 0:3ac96e360672 | 3764 | 2, |
charlesmn | 0:3ac96e360672 | 3765 | pbuffer + 24); |
charlesmn | 0:3ac96e360672 | 3766 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3767 | pdata->shadow_result__dss_actual_effective_spads_sd1, |
charlesmn | 0:3ac96e360672 | 3768 | 2, |
charlesmn | 0:3ac96e360672 | 3769 | pbuffer + 26); |
charlesmn | 0:3ac96e360672 | 3770 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3771 | pdata->shadow_result__peak_signal_count_rate_mcps_sd1, |
charlesmn | 0:3ac96e360672 | 3772 | 2, |
charlesmn | 0:3ac96e360672 | 3773 | pbuffer + 28); |
charlesmn | 0:3ac96e360672 | 3774 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3775 | pdata->shadow_result__ambient_count_rate_mcps_sd1, |
charlesmn | 0:3ac96e360672 | 3776 | 2, |
charlesmn | 0:3ac96e360672 | 3777 | pbuffer + 30); |
charlesmn | 0:3ac96e360672 | 3778 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3779 | pdata->shadow_result__sigma_sd1, |
charlesmn | 0:3ac96e360672 | 3780 | 2, |
charlesmn | 0:3ac96e360672 | 3781 | pbuffer + 32); |
charlesmn | 0:3ac96e360672 | 3782 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3783 | pdata->shadow_result__phase_sd1, |
charlesmn | 0:3ac96e360672 | 3784 | 2, |
charlesmn | 0:3ac96e360672 | 3785 | pbuffer + 34); |
charlesmn | 0:3ac96e360672 | 3786 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3787 | pdata->shadow_result__final_crosstalk_corrected_range_mm_sd1, |
charlesmn | 0:3ac96e360672 | 3788 | 2, |
charlesmn | 0:3ac96e360672 | 3789 | pbuffer + 36); |
charlesmn | 0:3ac96e360672 | 3790 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3791 | pdata->shadow_result__spare_0_sd1, |
charlesmn | 0:3ac96e360672 | 3792 | 2, |
charlesmn | 0:3ac96e360672 | 3793 | pbuffer + 38); |
charlesmn | 0:3ac96e360672 | 3794 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3795 | pdata->shadow_result__spare_1_sd1, |
charlesmn | 0:3ac96e360672 | 3796 | 2, |
charlesmn | 0:3ac96e360672 | 3797 | pbuffer + 40); |
charlesmn | 0:3ac96e360672 | 3798 | VL53L1_i2c_encode_uint16_t( |
charlesmn | 0:3ac96e360672 | 3799 | pdata->shadow_result__spare_2_sd1, |
charlesmn | 0:3ac96e360672 | 3800 | 2, |
charlesmn | 0:3ac96e360672 | 3801 | pbuffer + 42); |
charlesmn | 0:3ac96e360672 | 3802 | *(pbuffer + 44) = |
charlesmn | 0:3ac96e360672 | 3803 | pdata->shadow_result__spare_3_sd1; |
charlesmn | 0:3ac96e360672 | 3804 | *(pbuffer + 45) = |
charlesmn | 0:3ac96e360672 | 3805 | pdata->shadow_result__thresh_info; |
charlesmn | 0:3ac96e360672 | 3806 | *(pbuffer + 80) = |
charlesmn | 0:3ac96e360672 | 3807 | pdata->shadow_phasecal_result__reference_phase_hi; |
charlesmn | 0:3ac96e360672 | 3808 | *(pbuffer + 81) = |
charlesmn | 0:3ac96e360672 | 3809 | pdata->shadow_phasecal_result__reference_phase_lo; |
charlesmn | 0:3ac96e360672 | 3810 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3811 | |
charlesmn | 0:3ac96e360672 | 3812 | |
charlesmn | 0:3ac96e360672 | 3813 | return status; |
charlesmn | 0:3ac96e360672 | 3814 | } |
charlesmn | 0:3ac96e360672 | 3815 | |
charlesmn | 0:3ac96e360672 | 3816 | |
charlesmn | 0:3ac96e360672 | 3817 | VL53L1_Error VL53L1_i2c_decode_shadow_system_results( |
charlesmn | 0:3ac96e360672 | 3818 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 3819 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 3820 | VL53L1_shadow_system_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 3821 | { |
charlesmn | 0:3ac96e360672 | 3822 | |
charlesmn | 0:3ac96e360672 | 3823 | |
charlesmn | 0:3ac96e360672 | 3824 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3825 | |
charlesmn | 0:3ac96e360672 | 3826 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3827 | |
charlesmn | 0:3ac96e360672 | 3828 | if (buf_size < VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 3829 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 3830 | |
charlesmn | 0:3ac96e360672 | 3831 | pdata->shadow_phasecal_result__vcsel_start = |
charlesmn | 0:3ac96e360672 | 3832 | (*(pbuffer + 0)); |
charlesmn | 0:3ac96e360672 | 3833 | pdata->shadow_result__interrupt_status = |
charlesmn | 0:3ac96e360672 | 3834 | (*(pbuffer + 2)) & 0x3F; |
charlesmn | 0:3ac96e360672 | 3835 | pdata->shadow_result__range_status = |
charlesmn | 0:3ac96e360672 | 3836 | (*(pbuffer + 3)); |
charlesmn | 0:3ac96e360672 | 3837 | pdata->shadow_result__report_status = |
charlesmn | 0:3ac96e360672 | 3838 | (*(pbuffer + 4)) & 0xF; |
charlesmn | 0:3ac96e360672 | 3839 | pdata->shadow_result__stream_count = |
charlesmn | 0:3ac96e360672 | 3840 | (*(pbuffer + 5)); |
charlesmn | 0:3ac96e360672 | 3841 | pdata->shadow_result__dss_actual_effective_spads_sd0 = |
charlesmn | 0:3ac96e360672 | 3842 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 6)); |
charlesmn | 0:3ac96e360672 | 3843 | pdata->shadow_result__peak_signal_count_rate_mcps_sd0 = |
charlesmn | 0:3ac96e360672 | 3844 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8)); |
charlesmn | 0:3ac96e360672 | 3845 | pdata->shadow_result__ambient_count_rate_mcps_sd0 = |
charlesmn | 0:3ac96e360672 | 3846 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10)); |
charlesmn | 0:3ac96e360672 | 3847 | pdata->shadow_result__sigma_sd0 = |
charlesmn | 0:3ac96e360672 | 3848 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12)); |
charlesmn | 0:3ac96e360672 | 3849 | pdata->shadow_result__phase_sd0 = |
charlesmn | 0:3ac96e360672 | 3850 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14)); |
charlesmn | 0:3ac96e360672 | 3851 | pdata->shadow_result__final_crosstalk_corrected_range_mm_sd0 = |
charlesmn | 0:3ac96e360672 | 3852 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16)); |
charlesmn | 0:3ac96e360672 | 3853 | pdata->shr__peak_signal_count_rate_crosstalk_corrected_mcps_sd0 = |
charlesmn | 0:3ac96e360672 | 3854 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18)); |
charlesmn | 0:3ac96e360672 | 3855 | pdata->shadow_result__mm_inner_actual_effective_spads_sd0 = |
charlesmn | 0:3ac96e360672 | 3856 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 20)); |
charlesmn | 0:3ac96e360672 | 3857 | pdata->shadow_result__mm_outer_actual_effective_spads_sd0 = |
charlesmn | 0:3ac96e360672 | 3858 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22)); |
charlesmn | 0:3ac96e360672 | 3859 | pdata->shadow_result__avg_signal_count_rate_mcps_sd0 = |
charlesmn | 0:3ac96e360672 | 3860 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24)); |
charlesmn | 0:3ac96e360672 | 3861 | pdata->shadow_result__dss_actual_effective_spads_sd1 = |
charlesmn | 0:3ac96e360672 | 3862 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 26)); |
charlesmn | 0:3ac96e360672 | 3863 | pdata->shadow_result__peak_signal_count_rate_mcps_sd1 = |
charlesmn | 0:3ac96e360672 | 3864 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 28)); |
charlesmn | 0:3ac96e360672 | 3865 | pdata->shadow_result__ambient_count_rate_mcps_sd1 = |
charlesmn | 0:3ac96e360672 | 3866 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 30)); |
charlesmn | 0:3ac96e360672 | 3867 | pdata->shadow_result__sigma_sd1 = |
charlesmn | 0:3ac96e360672 | 3868 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 32)); |
charlesmn | 0:3ac96e360672 | 3869 | pdata->shadow_result__phase_sd1 = |
charlesmn | 0:3ac96e360672 | 3870 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 34)); |
charlesmn | 0:3ac96e360672 | 3871 | pdata->shadow_result__final_crosstalk_corrected_range_mm_sd1 = |
charlesmn | 0:3ac96e360672 | 3872 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 36)); |
charlesmn | 0:3ac96e360672 | 3873 | pdata->shadow_result__spare_0_sd1 = |
charlesmn | 0:3ac96e360672 | 3874 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 38)); |
charlesmn | 0:3ac96e360672 | 3875 | pdata->shadow_result__spare_1_sd1 = |
charlesmn | 0:3ac96e360672 | 3876 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 40)); |
charlesmn | 0:3ac96e360672 | 3877 | pdata->shadow_result__spare_2_sd1 = |
charlesmn | 0:3ac96e360672 | 3878 | (VL53L1_i2c_decode_uint16_t(2, pbuffer + 42)); |
charlesmn | 0:3ac96e360672 | 3879 | pdata->shadow_result__spare_3_sd1 = |
charlesmn | 0:3ac96e360672 | 3880 | (*(pbuffer + 44)); |
charlesmn | 0:3ac96e360672 | 3881 | pdata->shadow_result__thresh_info = |
charlesmn | 0:3ac96e360672 | 3882 | (*(pbuffer + 45)); |
charlesmn | 0:3ac96e360672 | 3883 | pdata->shadow_phasecal_result__reference_phase_hi = |
charlesmn | 0:3ac96e360672 | 3884 | (*(pbuffer + 80)); |
charlesmn | 0:3ac96e360672 | 3885 | pdata->shadow_phasecal_result__reference_phase_lo = |
charlesmn | 0:3ac96e360672 | 3886 | (*(pbuffer + 81)); |
charlesmn | 0:3ac96e360672 | 3887 | |
charlesmn | 0:3ac96e360672 | 3888 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3889 | |
charlesmn | 0:3ac96e360672 | 3890 | return status; |
charlesmn | 0:3ac96e360672 | 3891 | } |
charlesmn | 0:3ac96e360672 | 3892 | |
charlesmn | 0:3ac96e360672 | 3893 | |
charlesmn | 0:3ac96e360672 | 3894 | VL53L1_Error VL53L1_set_shadow_system_results( |
charlesmn | 0:3ac96e360672 | 3895 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3896 | VL53L1_shadow_system_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 3897 | { |
charlesmn | 0:3ac96e360672 | 3898 | |
charlesmn | 0:3ac96e360672 | 3899 | |
charlesmn | 0:3ac96e360672 | 3900 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3901 | uint8_t comms_buffer[VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 3902 | |
charlesmn | 0:3ac96e360672 | 3903 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3904 | |
charlesmn | 0:3ac96e360672 | 3905 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3906 | status = VL53L1_i2c_encode_shadow_system_results( |
charlesmn | 0:3ac96e360672 | 3907 | pdata, |
charlesmn | 0:3ac96e360672 | 3908 | VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 3909 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 3910 | |
charlesmn | 0:3ac96e360672 | 3911 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3912 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3913 | |
charlesmn | 0:3ac96e360672 | 3914 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3915 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 3916 | Dev, |
charlesmn | 0:3ac96e360672 | 3917 | VL53L1_SHADOW_PHASECAL_RESULT__VCSEL_START, |
charlesmn | 0:3ac96e360672 | 3918 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 3919 | VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 3920 | |
charlesmn | 0:3ac96e360672 | 3921 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3922 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3923 | |
charlesmn | 0:3ac96e360672 | 3924 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3925 | |
charlesmn | 0:3ac96e360672 | 3926 | return status; |
charlesmn | 0:3ac96e360672 | 3927 | } |
charlesmn | 0:3ac96e360672 | 3928 | |
charlesmn | 0:3ac96e360672 | 3929 | |
charlesmn | 0:3ac96e360672 | 3930 | VL53L1_Error VL53L1_get_shadow_system_results( |
charlesmn | 0:3ac96e360672 | 3931 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3932 | VL53L1_shadow_system_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 3933 | { |
charlesmn | 0:3ac96e360672 | 3934 | |
charlesmn | 0:3ac96e360672 | 3935 | |
charlesmn | 0:3ac96e360672 | 3936 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3937 | uint8_t comms_buffer[VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 3938 | |
charlesmn | 0:3ac96e360672 | 3939 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3940 | |
charlesmn | 0:3ac96e360672 | 3941 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3942 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3943 | |
charlesmn | 0:3ac96e360672 | 3944 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3945 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 3946 | Dev, |
charlesmn | 0:3ac96e360672 | 3947 | VL53L1_SHADOW_PHASECAL_RESULT__VCSEL_START, |
charlesmn | 0:3ac96e360672 | 3948 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 3949 | VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 3950 | |
charlesmn | 0:3ac96e360672 | 3951 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3952 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 3953 | |
charlesmn | 0:3ac96e360672 | 3954 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3955 | status = VL53L1_i2c_decode_shadow_system_results( |
charlesmn | 0:3ac96e360672 | 3956 | VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 3957 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 3958 | pdata); |
charlesmn | 0:3ac96e360672 | 3959 | |
charlesmn | 0:3ac96e360672 | 3960 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 3961 | |
charlesmn | 0:3ac96e360672 | 3962 | return status; |
charlesmn | 0:3ac96e360672 | 3963 | } |
charlesmn | 0:3ac96e360672 | 3964 | |
charlesmn | 0:3ac96e360672 | 3965 | |
charlesmn | 0:3ac96e360672 | 3966 | VL53L1_Error VL53L1_i2c_encode_shadow_core_results( |
charlesmn | 0:3ac96e360672 | 3967 | VL53L1_shadow_core_results_t *pdata, |
charlesmn | 0:3ac96e360672 | 3968 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 3969 | uint8_t *pbuffer) |
charlesmn | 0:3ac96e360672 | 3970 | { |
charlesmn | 0:3ac96e360672 | 3971 | |
charlesmn | 0:3ac96e360672 | 3972 | |
charlesmn | 0:3ac96e360672 | 3973 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3974 | |
charlesmn | 0:3ac96e360672 | 3975 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3976 | |
charlesmn | 0:3ac96e360672 | 3977 | if (buf_size < VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 3978 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 3979 | |
charlesmn | 0:3ac96e360672 | 3980 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 3981 | pdata->shadow_result_core__ambient_window_events_sd0, |
charlesmn | 0:3ac96e360672 | 3982 | 4, |
charlesmn | 0:3ac96e360672 | 3983 | pbuffer + 0); |
charlesmn | 0:3ac96e360672 | 3984 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 3985 | pdata->shadow_result_core__ranging_total_events_sd0, |
charlesmn | 0:3ac96e360672 | 3986 | 4, |
charlesmn | 0:3ac96e360672 | 3987 | pbuffer + 4); |
charlesmn | 0:3ac96e360672 | 3988 | VL53L1_i2c_encode_int32_t( |
charlesmn | 0:3ac96e360672 | 3989 | pdata->shadow_result_core__signal_total_events_sd0, |
charlesmn | 0:3ac96e360672 | 3990 | 4, |
charlesmn | 0:3ac96e360672 | 3991 | pbuffer + 8); |
charlesmn | 0:3ac96e360672 | 3992 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 3993 | pdata->shadow_result_core__total_periods_elapsed_sd0, |
charlesmn | 0:3ac96e360672 | 3994 | 4, |
charlesmn | 0:3ac96e360672 | 3995 | pbuffer + 12); |
charlesmn | 0:3ac96e360672 | 3996 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 3997 | pdata->shadow_result_core__ambient_window_events_sd1, |
charlesmn | 0:3ac96e360672 | 3998 | 4, |
charlesmn | 0:3ac96e360672 | 3999 | pbuffer + 16); |
charlesmn | 0:3ac96e360672 | 4000 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 4001 | pdata->shadow_result_core__ranging_total_events_sd1, |
charlesmn | 0:3ac96e360672 | 4002 | 4, |
charlesmn | 0:3ac96e360672 | 4003 | pbuffer + 20); |
charlesmn | 0:3ac96e360672 | 4004 | VL53L1_i2c_encode_int32_t( |
charlesmn | 0:3ac96e360672 | 4005 | pdata->shadow_result_core__signal_total_events_sd1, |
charlesmn | 0:3ac96e360672 | 4006 | 4, |
charlesmn | 0:3ac96e360672 | 4007 | pbuffer + 24); |
charlesmn | 0:3ac96e360672 | 4008 | VL53L1_i2c_encode_uint32_t( |
charlesmn | 0:3ac96e360672 | 4009 | pdata->shadow_result_core__total_periods_elapsed_sd1, |
charlesmn | 0:3ac96e360672 | 4010 | 4, |
charlesmn | 0:3ac96e360672 | 4011 | pbuffer + 28); |
charlesmn | 0:3ac96e360672 | 4012 | *(pbuffer + 32) = |
charlesmn | 0:3ac96e360672 | 4013 | pdata->shadow_result_core__spare_0; |
charlesmn | 0:3ac96e360672 | 4014 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 4015 | |
charlesmn | 0:3ac96e360672 | 4016 | |
charlesmn | 0:3ac96e360672 | 4017 | return status; |
charlesmn | 0:3ac96e360672 | 4018 | } |
charlesmn | 0:3ac96e360672 | 4019 | |
charlesmn | 0:3ac96e360672 | 4020 | |
charlesmn | 0:3ac96e360672 | 4021 | VL53L1_Error VL53L1_i2c_decode_shadow_core_results( |
charlesmn | 0:3ac96e360672 | 4022 | uint16_t buf_size, |
charlesmn | 0:3ac96e360672 | 4023 | uint8_t *pbuffer, |
charlesmn | 0:3ac96e360672 | 4024 | VL53L1_shadow_core_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 4025 | { |
charlesmn | 0:3ac96e360672 | 4026 | |
charlesmn | 0:3ac96e360672 | 4027 | |
charlesmn | 0:3ac96e360672 | 4028 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 4029 | |
charlesmn | 0:3ac96e360672 | 4030 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 4031 | |
charlesmn | 0:3ac96e360672 | 4032 | if (buf_size < VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES) |
charlesmn | 0:3ac96e360672 | 4033 | return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; |
charlesmn | 0:3ac96e360672 | 4034 | |
charlesmn | 0:3ac96e360672 | 4035 | pdata->shadow_result_core__ambient_window_events_sd0 = |
charlesmn | 0:3ac96e360672 | 4036 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 0)); |
charlesmn | 0:3ac96e360672 | 4037 | pdata->shadow_result_core__ranging_total_events_sd0 = |
charlesmn | 0:3ac96e360672 | 4038 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 4)); |
charlesmn | 0:3ac96e360672 | 4039 | pdata->shadow_result_core__signal_total_events_sd0 = |
charlesmn | 0:3ac96e360672 | 4040 | (VL53L1_i2c_decode_int32_t(4, pbuffer + 8)); |
charlesmn | 0:3ac96e360672 | 4041 | pdata->shadow_result_core__total_periods_elapsed_sd0 = |
charlesmn | 0:3ac96e360672 | 4042 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 12)); |
charlesmn | 0:3ac96e360672 | 4043 | pdata->shadow_result_core__ambient_window_events_sd1 = |
charlesmn | 0:3ac96e360672 | 4044 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 16)); |
charlesmn | 0:3ac96e360672 | 4045 | pdata->shadow_result_core__ranging_total_events_sd1 = |
charlesmn | 0:3ac96e360672 | 4046 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 20)); |
charlesmn | 0:3ac96e360672 | 4047 | pdata->shadow_result_core__signal_total_events_sd1 = |
charlesmn | 0:3ac96e360672 | 4048 | (VL53L1_i2c_decode_int32_t(4, pbuffer + 24)); |
charlesmn | 0:3ac96e360672 | 4049 | pdata->shadow_result_core__total_periods_elapsed_sd1 = |
charlesmn | 0:3ac96e360672 | 4050 | (VL53L1_i2c_decode_uint32_t(4, pbuffer + 28)); |
charlesmn | 0:3ac96e360672 | 4051 | pdata->shadow_result_core__spare_0 = |
charlesmn | 0:3ac96e360672 | 4052 | (*(pbuffer + 32)); |
charlesmn | 0:3ac96e360672 | 4053 | |
charlesmn | 0:3ac96e360672 | 4054 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 4055 | |
charlesmn | 0:3ac96e360672 | 4056 | return status; |
charlesmn | 0:3ac96e360672 | 4057 | } |
charlesmn | 0:3ac96e360672 | 4058 | |
charlesmn | 0:3ac96e360672 | 4059 | |
charlesmn | 0:3ac96e360672 | 4060 | VL53L1_Error VL53L1_set_shadow_core_results( |
charlesmn | 0:3ac96e360672 | 4061 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 4062 | VL53L1_shadow_core_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 4063 | { |
charlesmn | 0:3ac96e360672 | 4064 | |
charlesmn | 0:3ac96e360672 | 4065 | |
charlesmn | 0:3ac96e360672 | 4066 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 4067 | uint8_t comms_buffer[VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 4068 | |
charlesmn | 0:3ac96e360672 | 4069 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 4070 | |
charlesmn | 0:3ac96e360672 | 4071 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 4072 | status = VL53L1_i2c_encode_shadow_core_results( |
charlesmn | 0:3ac96e360672 | 4073 | pdata, |
charlesmn | 0:3ac96e360672 | 4074 | VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 4075 | comms_buffer); |
charlesmn | 0:3ac96e360672 | 4076 | |
charlesmn | 0:3ac96e360672 | 4077 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 4078 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 4079 | |
charlesmn | 0:3ac96e360672 | 4080 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 4081 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 4082 | Dev, |
charlesmn | 0:3ac96e360672 | 4083 | VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0, |
charlesmn | 0:3ac96e360672 | 4084 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 4085 | VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 4086 | |
charlesmn | 0:3ac96e360672 | 4087 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 4088 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 4089 | |
charlesmn | 0:3ac96e360672 | 4090 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 4091 | |
charlesmn | 0:3ac96e360672 | 4092 | return status; |
charlesmn | 0:3ac96e360672 | 4093 | } |
charlesmn | 0:3ac96e360672 | 4094 | |
charlesmn | 0:3ac96e360672 | 4095 | |
charlesmn | 0:3ac96e360672 | 4096 | VL53L1_Error VL53L1_get_shadow_core_results( |
charlesmn | 0:3ac96e360672 | 4097 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 4098 | VL53L1_shadow_core_results_t *pdata) |
charlesmn | 0:3ac96e360672 | 4099 | { |
charlesmn | 0:3ac96e360672 | 4100 | |
charlesmn | 0:3ac96e360672 | 4101 | |
charlesmn | 0:3ac96e360672 | 4102 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 4103 | uint8_t comms_buffer[VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES]; |
charlesmn | 0:3ac96e360672 | 4104 | |
charlesmn | 0:3ac96e360672 | 4105 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 4106 | |
charlesmn | 0:3ac96e360672 | 4107 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 4108 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 4109 | |
charlesmn | 0:3ac96e360672 | 4110 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 4111 | status = VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 4112 | Dev, |
charlesmn | 0:3ac96e360672 | 4113 | VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0, |
charlesmn | 0:3ac96e360672 | 4114 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 4115 | VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES); |
charlesmn | 0:3ac96e360672 | 4116 | |
charlesmn | 0:3ac96e360672 | 4117 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 4118 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 4119 | |
charlesmn | 0:3ac96e360672 | 4120 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 4121 | status = VL53L1_i2c_decode_shadow_core_results( |
charlesmn | 0:3ac96e360672 | 4122 | VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES, |
charlesmn | 0:3ac96e360672 | 4123 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 4124 | pdata); |
charlesmn | 0:3ac96e360672 | 4125 | |
charlesmn | 0:3ac96e360672 | 4126 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 4127 | |
charlesmn | 0:3ac96e360672 | 4128 | return status; |
charlesmn | 0:3ac96e360672 | 4129 | } |
charlesmn | 0:3ac96e360672 | 4130 | |
charlesmn | 0:3ac96e360672 | 4131 |