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

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   VL53L1CB_noshield_1sensor_polls_auton VL53L1CB_noshield_1sensor_interrupt_auton X_NUCLEO_53L1A2

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

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

Who changed what in which revision?

UserRevisionLine numberNew contents of line
charlesmn 0:3ac96e360672 1
Charles MacNeill 7:1add29d51e72 2 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
Charles MacNeill 7:1add29d51e72 3 /******************************************************************************
charlesmn 0:3ac96e360672 4 * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
charlesmn 0:3ac96e360672 5
Charles MacNeill 7:1add29d51e72 6 This file is part of VL53L1 and is dual licensed,
Charles MacNeill 7:1add29d51e72 7 either GPL-2.0+
charlesmn 0:3ac96e360672 8 or 'BSD 3-clause "New" or "Revised" License' , at your option.
Charles MacNeill 7:1add29d51e72 9 ******************************************************************************
Charles MacNeill 7:1add29d51e72 10 */
charlesmn 0:3ac96e360672 11
charlesmn 0:3ac96e360672 12
charlesmn 0:3ac96e360672 13
charlesmn 0:3ac96e360672 14
charlesmn 0:3ac96e360672 15 #include "vl53l1_ll_def.h"
charlesmn 0:3ac96e360672 16 #include "vl53l1_ll_device.h"
charlesmn 0:3ac96e360672 17 #include "vl53l1_platform_log.h"
charlesmn 0:3ac96e360672 18 #include "vl53l1_zone_presets.h"
charlesmn 0:3ac96e360672 19
charlesmn 0:3ac96e360672 20
charlesmn 0:3ac96e360672 21 #define LOG_FUNCTION_START(fmt, ...) \
charlesmn 0:3ac96e360672 22 _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 23 #define LOG_FUNCTION_END(status, ...) \
charlesmn 0:3ac96e360672 24 _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 25 #define LOG_FUNCTION_END_FMT(status, fmt, ...) \
charlesmn 0:3ac96e360672 26 _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE,\
charlesmn 0:3ac96e360672 27 status, fmt, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 28
charlesmn 0:3ac96e360672 29
charlesmn 0:3ac96e360672 30 VL53L1_Error VL53L1_init_zone_config_structure(
charlesmn 0:3ac96e360672 31 uint8_t x_off,
charlesmn 0:3ac96e360672 32 uint8_t x_inc,
charlesmn 0:3ac96e360672 33 uint8_t x_zones,
charlesmn 0:3ac96e360672 34 uint8_t y_off,
charlesmn 0:3ac96e360672 35 uint8_t y_inc,
charlesmn 0:3ac96e360672 36 uint8_t y_zones,
charlesmn 0:3ac96e360672 37 uint8_t width,
charlesmn 0:3ac96e360672 38 uint8_t height,
charlesmn 0:3ac96e360672 39 VL53L1_zone_config_t *pdata)
charlesmn 0:3ac96e360672 40 {
charlesmn 0:3ac96e360672 41
charlesmn 0:3ac96e360672 42
charlesmn 0:3ac96e360672 43 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 44
charlesmn 0:3ac96e360672 45 uint8_t x = 0;
charlesmn 0:3ac96e360672 46 uint8_t y = 0;
charlesmn 0:3ac96e360672 47 uint16_t i = 0;
charlesmn 0:3ac96e360672 48
charlesmn 0:3ac96e360672 49 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 50
charlesmn 0:3ac96e360672 51 pdata->max_zones = VL53L1_MAX_USER_ZONES;
charlesmn 0:3ac96e360672 52
charlesmn 0:3ac96e360672 53 i = 0;
charlesmn 0:3ac96e360672 54
charlesmn 0:3ac96e360672 55 for (x = 0 ; x < x_zones ; x++) {
charlesmn 0:3ac96e360672 56 for (y = 0 ; y < y_zones ; y++) {
charlesmn 0:3ac96e360672 57
charlesmn 0:3ac96e360672 58 if (i < VL53L1_MAX_USER_ZONES) {
charlesmn 0:3ac96e360672 59
charlesmn 0:3ac96e360672 60 pdata->active_zones = (uint8_t)i;
charlesmn 0:3ac96e360672 61 pdata->user_zones[i].height = height;
charlesmn 0:3ac96e360672 62 pdata->user_zones[i].width = width;
charlesmn 0:3ac96e360672 63 pdata->user_zones[i].x_centre =
charlesmn 0:3ac96e360672 64 x_off + (x * x_inc);
charlesmn 0:3ac96e360672 65 pdata->user_zones[i].y_centre =
charlesmn 0:3ac96e360672 66 y_off + (y * y_inc);
charlesmn 0:3ac96e360672 67 }
charlesmn 0:3ac96e360672 68
charlesmn 0:3ac96e360672 69 i++;
charlesmn 0:3ac96e360672 70 }
charlesmn 0:3ac96e360672 71 }
charlesmn 0:3ac96e360672 72
charlesmn 0:3ac96e360672 73 status = VL53L1_init_zone_config_histogram_bins(pdata);
charlesmn 0:3ac96e360672 74
charlesmn 0:3ac96e360672 75
charlesmn 0:3ac96e360672 76 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 77
charlesmn 0:3ac96e360672 78 return status;
charlesmn 0:3ac96e360672 79 }
charlesmn 0:3ac96e360672 80
charlesmn 0:3ac96e360672 81
charlesmn 0:3ac96e360672 82 VL53L1_Error VL53L1_zone_preset_xtalk_planar(
charlesmn 0:3ac96e360672 83 VL53L1_general_config_t *pgeneral,
charlesmn 0:3ac96e360672 84 VL53L1_zone_config_t *pzone_cfg)
charlesmn 0:3ac96e360672 85 {
charlesmn 0:3ac96e360672 86
charlesmn 0:3ac96e360672 87
charlesmn 0:3ac96e360672 88 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 89
charlesmn 0:3ac96e360672 90 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 91
charlesmn 0:3ac96e360672 92
charlesmn 0:3ac96e360672 93 pgeneral->global_config__stream_divider = 0x05;
charlesmn 0:3ac96e360672 94
charlesmn 0:3ac96e360672 95
charlesmn 0:3ac96e360672 96 pzone_cfg->active_zones = 0x04;
charlesmn 0:3ac96e360672 97
charlesmn 0:3ac96e360672 98 pzone_cfg->user_zones[0].height = 15;
charlesmn 0:3ac96e360672 99 pzone_cfg->user_zones[0].width = 7;
charlesmn 0:3ac96e360672 100 pzone_cfg->user_zones[0].x_centre = 4;
charlesmn 0:3ac96e360672 101 pzone_cfg->user_zones[0].y_centre = 8;
charlesmn 0:3ac96e360672 102
charlesmn 0:3ac96e360672 103 pzone_cfg->user_zones[1].height = 15;
charlesmn 0:3ac96e360672 104 pzone_cfg->user_zones[1].width = 7;
charlesmn 0:3ac96e360672 105 pzone_cfg->user_zones[1].x_centre = 12;
charlesmn 0:3ac96e360672 106 pzone_cfg->user_zones[1].y_centre = 8;
charlesmn 0:3ac96e360672 107
charlesmn 0:3ac96e360672 108 pzone_cfg->user_zones[2].height = 7;
charlesmn 0:3ac96e360672 109 pzone_cfg->user_zones[2].width = 15;
charlesmn 0:3ac96e360672 110 pzone_cfg->user_zones[2].x_centre = 8;
charlesmn 0:3ac96e360672 111 pzone_cfg->user_zones[2].y_centre = 4;
charlesmn 0:3ac96e360672 112
charlesmn 0:3ac96e360672 113 pzone_cfg->user_zones[3].height = 7;
charlesmn 0:3ac96e360672 114 pzone_cfg->user_zones[3].width = 15;
charlesmn 0:3ac96e360672 115 pzone_cfg->user_zones[3].x_centre = 8;
charlesmn 0:3ac96e360672 116 pzone_cfg->user_zones[3].y_centre = 12;
charlesmn 0:3ac96e360672 117
charlesmn 0:3ac96e360672 118
charlesmn 0:3ac96e360672 119
charlesmn 0:3ac96e360672 120 pzone_cfg->user_zones[4].height = 15;
charlesmn 0:3ac96e360672 121 pzone_cfg->user_zones[4].width = 15;
charlesmn 0:3ac96e360672 122 pzone_cfg->user_zones[4].x_centre = 8;
charlesmn 0:3ac96e360672 123 pzone_cfg->user_zones[4].y_centre = 8;
charlesmn 0:3ac96e360672 124
charlesmn 0:3ac96e360672 125 status = VL53L1_init_zone_config_histogram_bins(pzone_cfg);
charlesmn 0:3ac96e360672 126
charlesmn 0:3ac96e360672 127
charlesmn 0:3ac96e360672 128 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 129
charlesmn 0:3ac96e360672 130 return status;
charlesmn 0:3ac96e360672 131 }
charlesmn 0:3ac96e360672 132
charlesmn 0:3ac96e360672 133
charlesmn 0:3ac96e360672 134 VL53L1_Error VL53L1_init_zone_config_histogram_bins(
charlesmn 0:3ac96e360672 135 VL53L1_zone_config_t *pdata)
charlesmn 0:3ac96e360672 136 {
charlesmn 0:3ac96e360672 137
charlesmn 0:3ac96e360672 138
charlesmn 0:3ac96e360672 139 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 140
charlesmn 0:3ac96e360672 141 uint8_t i;
charlesmn 0:3ac96e360672 142
charlesmn 0:3ac96e360672 143 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 144
charlesmn 0:3ac96e360672 145 for (i = 0; i < pdata->max_zones; i++)
charlesmn 0:3ac96e360672 146 pdata->bin_config[i] = VL53L1_ZONECONFIG_BINCONFIG__LOWAMB;
charlesmn 0:3ac96e360672 147
charlesmn 0:3ac96e360672 148 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 149
charlesmn 0:3ac96e360672 150 return status;
charlesmn 0:3ac96e360672 151 }
charlesmn 0:3ac96e360672 152