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_hist_char.c@7:1add29d51e72, 2021-06-08 (annotated)
- Committer:
- Charles MacNeill
- Date:
- Tue Jun 08 10:34:47 2021 +0100
- Revision:
- 7:1add29d51e72
- Parent:
- 0:3ac96e360672
Update to v6.6.5 of bare_driver
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
charlesmn | 0:3ac96e360672 | 1 | |
Charles MacNeill |
7:1add29d51e72 | 2 | // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
Charles MacNeill |
7:1add29d51e72 | 3 | /****************************************************************************** |
charlesmn | 0:3ac96e360672 | 4 | * Copyright (c) 2020, STMicroelectronics - All Rights Reserved |
charlesmn | 0:3ac96e360672 | 5 | |
Charles MacNeill |
7:1add29d51e72 | 6 | This file is part of VL53L1 and is dual licensed, |
Charles MacNeill |
7:1add29d51e72 | 7 | either GPL-2.0+ |
charlesmn | 0:3ac96e360672 | 8 | or 'BSD 3-clause "New" or "Revised" License' , at your option. |
Charles MacNeill |
7:1add29d51e72 | 9 | ****************************************************************************** |
Charles MacNeill |
7:1add29d51e72 | 10 | */ |
charlesmn | 0:3ac96e360672 | 11 | |
charlesmn | 0:3ac96e360672 | 12 | |
charlesmn | 0:3ac96e360672 | 13 | |
charlesmn | 0:3ac96e360672 | 14 | |
charlesmn | 0:3ac96e360672 | 15 | |
charlesmn | 0:3ac96e360672 | 16 | #include <stdio.h> |
charlesmn | 0:3ac96e360672 | 17 | #include <stdlib.h> |
charlesmn | 0:3ac96e360672 | 18 | |
charlesmn | 0:3ac96e360672 | 19 | |
charlesmn | 0:3ac96e360672 | 20 | |
charlesmn | 0:3ac96e360672 | 21 | #include "vl53l1_core.h" |
charlesmn | 0:3ac96e360672 | 22 | #include "vl53l1_register_settings.h" |
charlesmn | 0:3ac96e360672 | 23 | #include "vl53l1_hist_char.h" |
charlesmn | 0:3ac96e360672 | 24 | |
charlesmn | 0:3ac96e360672 | 25 | #define LOG_FUNCTION_START(fmt, ...) \ |
charlesmn | 0:3ac96e360672 | 26 | _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_HISTOGRAM, fmt, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 27 | #define LOG_FUNCTION_END(status, ...) \ |
charlesmn | 0:3ac96e360672 | 28 | _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_HISTOGRAM, status, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 29 | #define LOG_FUNCTION_END_FMT(status, fmt, ...) \ |
charlesmn | 0:3ac96e360672 | 30 | _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_HISTOGRAM,\ |
charlesmn | 0:3ac96e360672 | 31 | status, fmt, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 32 | |
charlesmn | 0:3ac96e360672 | 33 | |
charlesmn | 0:3ac96e360672 | 34 | VL53L1_Error VL53L1_set_calib_config( |
charlesmn | 0:3ac96e360672 | 35 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 36 | uint8_t vcsel_delay__a0, |
charlesmn | 0:3ac96e360672 | 37 | uint8_t calib_1, |
charlesmn | 0:3ac96e360672 | 38 | uint8_t calib_2, |
charlesmn | 0:3ac96e360672 | 39 | uint8_t calib_3, |
charlesmn | 0:3ac96e360672 | 40 | uint8_t calib_2__a0, |
charlesmn | 0:3ac96e360672 | 41 | uint8_t spad_readout) |
charlesmn | 0:3ac96e360672 | 42 | { |
charlesmn | 0:3ac96e360672 | 43 | |
charlesmn | 0:3ac96e360672 | 44 | |
charlesmn | 0:3ac96e360672 | 45 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 46 | uint8_t comms_buffer[3]; |
charlesmn | 0:3ac96e360672 | 47 | |
charlesmn | 0:3ac96e360672 | 48 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 49 | |
charlesmn | 0:3ac96e360672 | 50 | |
charlesmn | 0:3ac96e360672 | 51 | |
charlesmn | 0:3ac96e360672 | 52 | status = VL53L1_enable_powerforce(Dev); |
charlesmn | 0:3ac96e360672 | 53 | |
charlesmn | 0:3ac96e360672 | 54 | |
charlesmn | 0:3ac96e360672 | 55 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 56 | status = VL53L1_disable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 57 | |
charlesmn | 0:3ac96e360672 | 58 | |
charlesmn | 0:3ac96e360672 | 59 | |
charlesmn | 0:3ac96e360672 | 60 | |
charlesmn | 0:3ac96e360672 | 61 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 62 | status = VL53L1_WrByte( |
charlesmn | 0:3ac96e360672 | 63 | Dev, |
charlesmn | 0:3ac96e360672 | 64 | VL53L1_RANGING_CORE__VCSEL_DELAY__A0, |
charlesmn | 0:3ac96e360672 | 65 | vcsel_delay__a0); |
charlesmn | 0:3ac96e360672 | 66 | } |
charlesmn | 0:3ac96e360672 | 67 | |
charlesmn | 0:3ac96e360672 | 68 | |
charlesmn | 0:3ac96e360672 | 69 | |
charlesmn | 0:3ac96e360672 | 70 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 71 | |
charlesmn | 0:3ac96e360672 | 72 | |
charlesmn | 0:3ac96e360672 | 73 | comms_buffer[0] = calib_1; |
charlesmn | 0:3ac96e360672 | 74 | comms_buffer[1] = calib_2; |
charlesmn | 0:3ac96e360672 | 75 | comms_buffer[2] = calib_3; |
charlesmn | 0:3ac96e360672 | 76 | |
charlesmn | 0:3ac96e360672 | 77 | status = VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 78 | Dev, |
charlesmn | 0:3ac96e360672 | 79 | VL53L1_RANGING_CORE__CALIB_1, |
charlesmn | 0:3ac96e360672 | 80 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 81 | 3); |
charlesmn | 0:3ac96e360672 | 82 | } |
charlesmn | 0:3ac96e360672 | 83 | |
charlesmn | 0:3ac96e360672 | 84 | |
charlesmn | 0:3ac96e360672 | 85 | |
charlesmn | 0:3ac96e360672 | 86 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 87 | status = VL53L1_WrByte( |
charlesmn | 0:3ac96e360672 | 88 | Dev, |
charlesmn | 0:3ac96e360672 | 89 | VL53L1_RANGING_CORE__CALIB_2__A0, |
charlesmn | 0:3ac96e360672 | 90 | calib_2__a0); |
charlesmn | 0:3ac96e360672 | 91 | |
charlesmn | 0:3ac96e360672 | 92 | |
charlesmn | 0:3ac96e360672 | 93 | |
charlesmn | 0:3ac96e360672 | 94 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 95 | status = VL53L1_WrByte( |
charlesmn | 0:3ac96e360672 | 96 | Dev, |
charlesmn | 0:3ac96e360672 | 97 | VL53L1_RANGING_CORE__SPAD_READOUT, |
charlesmn | 0:3ac96e360672 | 98 | spad_readout); |
charlesmn | 0:3ac96e360672 | 99 | |
charlesmn | 0:3ac96e360672 | 100 | |
charlesmn | 0:3ac96e360672 | 101 | |
charlesmn | 0:3ac96e360672 | 102 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 103 | status = VL53L1_enable_firmware(Dev); |
charlesmn | 0:3ac96e360672 | 104 | |
charlesmn | 0:3ac96e360672 | 105 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 106 | |
charlesmn | 0:3ac96e360672 | 107 | return status; |
charlesmn | 0:3ac96e360672 | 108 | } |
charlesmn | 0:3ac96e360672 | 109 | |
charlesmn | 0:3ac96e360672 | 110 | |
charlesmn | 0:3ac96e360672 | 111 | |
charlesmn | 0:3ac96e360672 | 112 | VL53L1_Error VL53L1_set_hist_calib_pulse_delay( |
charlesmn | 0:3ac96e360672 | 113 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 114 | uint8_t calib_delay) |
charlesmn | 0:3ac96e360672 | 115 | { |
charlesmn | 0:3ac96e360672 | 116 | |
charlesmn | 0:3ac96e360672 | 117 | |
charlesmn | 0:3ac96e360672 | 118 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 119 | |
charlesmn | 0:3ac96e360672 | 120 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 121 | |
charlesmn | 0:3ac96e360672 | 122 | status = |
charlesmn | 0:3ac96e360672 | 123 | VL53L1_set_calib_config( |
charlesmn | 0:3ac96e360672 | 124 | Dev, |
charlesmn | 0:3ac96e360672 | 125 | 0x01, |
charlesmn | 0:3ac96e360672 | 126 | calib_delay, |
charlesmn | 0:3ac96e360672 | 127 | 0x04, |
charlesmn | 0:3ac96e360672 | 128 | 0x08, |
charlesmn | 0:3ac96e360672 | 129 | 0x14, |
charlesmn | 0:3ac96e360672 | 130 | VL53L1_RANGING_CORE__SPAD_READOUT__CALIB_PULSES); |
charlesmn | 0:3ac96e360672 | 131 | |
charlesmn | 0:3ac96e360672 | 132 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 133 | |
charlesmn | 0:3ac96e360672 | 134 | return status; |
charlesmn | 0:3ac96e360672 | 135 | } |
charlesmn | 0:3ac96e360672 | 136 | |
charlesmn | 0:3ac96e360672 | 137 | |
charlesmn | 0:3ac96e360672 | 138 | VL53L1_Error VL53L1_disable_calib_pulse_delay( |
charlesmn | 0:3ac96e360672 | 139 | VL53L1_DEV Dev) |
charlesmn | 0:3ac96e360672 | 140 | { |
charlesmn | 0:3ac96e360672 | 141 | |
charlesmn | 0:3ac96e360672 | 142 | |
charlesmn | 0:3ac96e360672 | 143 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 144 | |
charlesmn | 0:3ac96e360672 | 145 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 146 | |
charlesmn | 0:3ac96e360672 | 147 | status = |
charlesmn | 0:3ac96e360672 | 148 | VL53L1_set_calib_config( |
charlesmn | 0:3ac96e360672 | 149 | Dev, |
charlesmn | 0:3ac96e360672 | 150 | 0x00, |
charlesmn | 0:3ac96e360672 | 151 | 0x00, |
charlesmn | 0:3ac96e360672 | 152 | 0x00, |
charlesmn | 0:3ac96e360672 | 153 | 0x00, |
charlesmn | 0:3ac96e360672 | 154 | 0x00, |
charlesmn | 0:3ac96e360672 | 155 | VL53L1_RANGING_CORE__SPAD_READOUT__STANDARD); |
charlesmn | 0:3ac96e360672 | 156 | |
charlesmn | 0:3ac96e360672 | 157 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 158 | |
charlesmn | 0:3ac96e360672 | 159 | return status; |
charlesmn | 0:3ac96e360672 | 160 | } |
charlesmn | 0:3ac96e360672 | 161 | |
charlesmn | 0:3ac96e360672 | 162 |