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