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

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   VL53L1CB_noshield_1sensor_polls_auton VL53L1CB_noshield_1sensor_interrupt_auton X_NUCLEO_53L1A2

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

Committer:
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?

UserRevisionLine numberNew 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_ll_device.h"
charlesmn 0:3ac96e360672 70 #include "vl53l1_platform_log.h"
charlesmn 0:3ac96e360672 71 #include "vl53l1_zone_presets.h"
charlesmn 0:3ac96e360672 72
charlesmn 0:3ac96e360672 73
charlesmn 0:3ac96e360672 74 #define LOG_FUNCTION_START(fmt, ...) \
charlesmn 0:3ac96e360672 75 _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 76 #define LOG_FUNCTION_END(status, ...) \
charlesmn 0:3ac96e360672 77 _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 78 #define LOG_FUNCTION_END_FMT(status, fmt, ...) \
charlesmn 0:3ac96e360672 79 _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE,\
charlesmn 0:3ac96e360672 80 status, fmt, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 81
charlesmn 0:3ac96e360672 82
charlesmn 0:3ac96e360672 83 VL53L1_Error VL53L1_init_zone_config_structure(
charlesmn 0:3ac96e360672 84 uint8_t x_off,
charlesmn 0:3ac96e360672 85 uint8_t x_inc,
charlesmn 0:3ac96e360672 86 uint8_t x_zones,
charlesmn 0:3ac96e360672 87 uint8_t y_off,
charlesmn 0:3ac96e360672 88 uint8_t y_inc,
charlesmn 0:3ac96e360672 89 uint8_t y_zones,
charlesmn 0:3ac96e360672 90 uint8_t width,
charlesmn 0:3ac96e360672 91 uint8_t height,
charlesmn 0:3ac96e360672 92 VL53L1_zone_config_t *pdata)
charlesmn 0:3ac96e360672 93 {
charlesmn 0:3ac96e360672 94
charlesmn 0:3ac96e360672 95
charlesmn 0:3ac96e360672 96 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 97
charlesmn 0:3ac96e360672 98 uint8_t x = 0;
charlesmn 0:3ac96e360672 99 uint8_t y = 0;
charlesmn 0:3ac96e360672 100 uint16_t i = 0;
charlesmn 0:3ac96e360672 101
charlesmn 0:3ac96e360672 102 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 103
charlesmn 0:3ac96e360672 104 pdata->max_zones = VL53L1_MAX_USER_ZONES;
charlesmn 0:3ac96e360672 105
charlesmn 0:3ac96e360672 106 i = 0;
charlesmn 0:3ac96e360672 107
charlesmn 0:3ac96e360672 108 for (x = 0 ; x < x_zones ; x++) {
charlesmn 0:3ac96e360672 109 for (y = 0 ; y < y_zones ; y++) {
charlesmn 0:3ac96e360672 110
charlesmn 0:3ac96e360672 111 if (i < VL53L1_MAX_USER_ZONES) {
charlesmn 0:3ac96e360672 112
charlesmn 0:3ac96e360672 113 pdata->active_zones = (uint8_t)i;
charlesmn 0:3ac96e360672 114 pdata->user_zones[i].height = height;
charlesmn 0:3ac96e360672 115 pdata->user_zones[i].width = width;
charlesmn 0:3ac96e360672 116 pdata->user_zones[i].x_centre =
charlesmn 0:3ac96e360672 117 x_off + (x * x_inc);
charlesmn 0:3ac96e360672 118 pdata->user_zones[i].y_centre =
charlesmn 0:3ac96e360672 119 y_off + (y * y_inc);
charlesmn 0:3ac96e360672 120 }
charlesmn 0:3ac96e360672 121
charlesmn 0:3ac96e360672 122 i++;
charlesmn 0:3ac96e360672 123 }
charlesmn 0:3ac96e360672 124 }
charlesmn 0:3ac96e360672 125
charlesmn 0:3ac96e360672 126 status = VL53L1_init_zone_config_histogram_bins(pdata);
charlesmn 0:3ac96e360672 127
charlesmn 0:3ac96e360672 128
charlesmn 0:3ac96e360672 129 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 130
charlesmn 0:3ac96e360672 131 return status;
charlesmn 0:3ac96e360672 132 }
charlesmn 0:3ac96e360672 133
charlesmn 0:3ac96e360672 134
charlesmn 0:3ac96e360672 135 VL53L1_Error VL53L1_zone_preset_xtalk_planar(
charlesmn 0:3ac96e360672 136 VL53L1_general_config_t *pgeneral,
charlesmn 0:3ac96e360672 137 VL53L1_zone_config_t *pzone_cfg)
charlesmn 0:3ac96e360672 138 {
charlesmn 0:3ac96e360672 139
charlesmn 0:3ac96e360672 140
charlesmn 0:3ac96e360672 141 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 142
charlesmn 0:3ac96e360672 143 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 144
charlesmn 0:3ac96e360672 145
charlesmn 0:3ac96e360672 146 pgeneral->global_config__stream_divider = 0x05;
charlesmn 0:3ac96e360672 147
charlesmn 0:3ac96e360672 148
charlesmn 0:3ac96e360672 149 pzone_cfg->active_zones = 0x04;
charlesmn 0:3ac96e360672 150
charlesmn 0:3ac96e360672 151 pzone_cfg->user_zones[0].height = 15;
charlesmn 0:3ac96e360672 152 pzone_cfg->user_zones[0].width = 7;
charlesmn 0:3ac96e360672 153 pzone_cfg->user_zones[0].x_centre = 4;
charlesmn 0:3ac96e360672 154 pzone_cfg->user_zones[0].y_centre = 8;
charlesmn 0:3ac96e360672 155
charlesmn 0:3ac96e360672 156 pzone_cfg->user_zones[1].height = 15;
charlesmn 0:3ac96e360672 157 pzone_cfg->user_zones[1].width = 7;
charlesmn 0:3ac96e360672 158 pzone_cfg->user_zones[1].x_centre = 12;
charlesmn 0:3ac96e360672 159 pzone_cfg->user_zones[1].y_centre = 8;
charlesmn 0:3ac96e360672 160
charlesmn 0:3ac96e360672 161 pzone_cfg->user_zones[2].height = 7;
charlesmn 0:3ac96e360672 162 pzone_cfg->user_zones[2].width = 15;
charlesmn 0:3ac96e360672 163 pzone_cfg->user_zones[2].x_centre = 8;
charlesmn 0:3ac96e360672 164 pzone_cfg->user_zones[2].y_centre = 4;
charlesmn 0:3ac96e360672 165
charlesmn 0:3ac96e360672 166 pzone_cfg->user_zones[3].height = 7;
charlesmn 0:3ac96e360672 167 pzone_cfg->user_zones[3].width = 15;
charlesmn 0:3ac96e360672 168 pzone_cfg->user_zones[3].x_centre = 8;
charlesmn 0:3ac96e360672 169 pzone_cfg->user_zones[3].y_centre = 12;
charlesmn 0:3ac96e360672 170
charlesmn 0:3ac96e360672 171
charlesmn 0:3ac96e360672 172
charlesmn 0:3ac96e360672 173 pzone_cfg->user_zones[4].height = 15;
charlesmn 0:3ac96e360672 174 pzone_cfg->user_zones[4].width = 15;
charlesmn 0:3ac96e360672 175 pzone_cfg->user_zones[4].x_centre = 8;
charlesmn 0:3ac96e360672 176 pzone_cfg->user_zones[4].y_centre = 8;
charlesmn 0:3ac96e360672 177
charlesmn 0:3ac96e360672 178 status = VL53L1_init_zone_config_histogram_bins(pzone_cfg);
charlesmn 0:3ac96e360672 179
charlesmn 0:3ac96e360672 180
charlesmn 0:3ac96e360672 181 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 182
charlesmn 0:3ac96e360672 183 return status;
charlesmn 0:3ac96e360672 184 }
charlesmn 0:3ac96e360672 185
charlesmn 0:3ac96e360672 186
charlesmn 0:3ac96e360672 187 VL53L1_Error VL53L1_init_zone_config_histogram_bins(
charlesmn 0:3ac96e360672 188 VL53L1_zone_config_t *pdata)
charlesmn 0:3ac96e360672 189 {
charlesmn 0:3ac96e360672 190
charlesmn 0:3ac96e360672 191
charlesmn 0:3ac96e360672 192 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 193
charlesmn 0:3ac96e360672 194 uint8_t i;
charlesmn 0:3ac96e360672 195
charlesmn 0:3ac96e360672 196 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 197
charlesmn 0:3ac96e360672 198 for (i = 0; i < pdata->max_zones; i++)
charlesmn 0:3ac96e360672 199 pdata->bin_config[i] = VL53L1_ZONECONFIG_BINCONFIG__LOWAMB;
charlesmn 0:3ac96e360672 200
charlesmn 0:3ac96e360672 201 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 202
charlesmn 0:3ac96e360672 203 return status;
charlesmn 0:3ac96e360672 204 }
charlesmn 0:3ac96e360672 205
charlesmn 0:3ac96e360672 206