Initial release. Mbed library for VL53L1CB

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers vl53l1_zone_presets.c Source File

vl53l1_zone_presets.c

00001 
00002 /*******************************************************************************
00003  * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
00004 
00005  This file is part of VL53L1 Core and is dual licensed,
00006  either 'STMicroelectronics
00007  Proprietary license'
00008  or 'BSD 3-clause "New" or "Revised" License' , at your option.
00009 
00010 ********************************************************************************
00011 
00012  'STMicroelectronics Proprietary license'
00013 
00014 ********************************************************************************
00015 
00016  License terms: STMicroelectronics Proprietary in accordance with licensing
00017  terms at www.st.com/sla0081
00018 
00019  STMicroelectronics confidential
00020  Reproduction and Communication of this document is strictly prohibited unless
00021  specifically authorized in writing by STMicroelectronics.
00022 
00023 
00024 ********************************************************************************
00025 
00026  Alternatively, VL53L1 Core may be distributed under the terms of
00027  'BSD 3-clause "New" or "Revised" License', in which case the following
00028  provisions apply instead of the ones
00029  mentioned above :
00030 
00031 ********************************************************************************
00032 
00033  License terms: BSD 3-clause "New" or "Revised" License.
00034 
00035  Redistribution and use in source and binary forms, with or without
00036  modification, are permitted provided that the following conditions are met:
00037 
00038  1. Redistributions of source code must retain the above copyright notice, this
00039  list of conditions and the following disclaimer.
00040 
00041  2. Redistributions in binary form must reproduce the above copyright notice,
00042  this list of conditions and the following disclaimer in the documentation
00043  and/or other materials provided with the distribution.
00044 
00045  3. Neither the name of the copyright holder nor the names of its contributors
00046  may be used to endorse or promote products derived from this software
00047  without specific prior written permission.
00048 
00049  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00050  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00051  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00052  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00053  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00054  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00055  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00056  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00057  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00058  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00059 
00060 
00061 ********************************************************************************
00062 
00063 */
00064 
00065 
00066 
00067 
00068 #include "vl53l1_ll_def.h"
00069 #include "vl53l1_ll_device.h"
00070 #include "vl53l1_platform_log.h"
00071 #include "vl53l1_zone_presets.h"
00072 
00073 
00074 #define LOG_FUNCTION_START(fmt, ...) \
00075     _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
00076 #define LOG_FUNCTION_END(status, ...) \
00077     _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
00078 #define LOG_FUNCTION_END_FMT(status, fmt, ...) \
00079     _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE,\
00080             status, fmt, ##__VA_ARGS__)
00081 
00082 
00083 VL53L1_Error VL53L1_init_zone_config_structure(
00084     uint8_t x_off,
00085     uint8_t x_inc,
00086     uint8_t x_zones,
00087     uint8_t y_off,
00088     uint8_t y_inc,
00089     uint8_t y_zones,
00090     uint8_t width,
00091     uint8_t height,
00092     VL53L1_zone_config_t   *pdata)
00093 {
00094 
00095 
00096     VL53L1_Error  status = VL53L1_ERROR_NONE;
00097 
00098     uint8_t  x  = 0;
00099     uint8_t  y  = 0;
00100     uint16_t  i  = 0;
00101 
00102     LOG_FUNCTION_START("");
00103 
00104     pdata->max_zones = VL53L1_MAX_USER_ZONES;
00105 
00106     i = 0;
00107 
00108     for (x = 0 ; x < x_zones ; x++) {
00109         for (y = 0 ; y <  y_zones ; y++) {
00110 
00111             if (i < VL53L1_MAX_USER_ZONES) {
00112 
00113                 pdata->active_zones = (uint8_t)i;
00114                 pdata->user_zones[i].height   = height;
00115                 pdata->user_zones[i].width    = width;
00116                 pdata->user_zones[i].x_centre =
00117                         x_off + (x * x_inc);
00118                 pdata->user_zones[i].y_centre =
00119                         y_off + (y * y_inc);
00120             }
00121 
00122             i++;
00123         }
00124     }
00125 
00126     status = VL53L1_init_zone_config_histogram_bins(pdata);
00127 
00128 
00129     LOG_FUNCTION_END(status);
00130 
00131     return status;
00132 }
00133 
00134 
00135 VL53L1_Error VL53L1_zone_preset_xtalk_planar(
00136     VL53L1_general_config_t *pgeneral,
00137     VL53L1_zone_config_t    *pzone_cfg)
00138 {
00139 
00140 
00141     VL53L1_Error  status = VL53L1_ERROR_NONE;
00142 
00143     LOG_FUNCTION_START("");
00144 
00145 
00146     pgeneral->global_config__stream_divider = 0x05;
00147 
00148 
00149     pzone_cfg->active_zones                 = 0x04;
00150 
00151     pzone_cfg->user_zones[0].height         = 15;
00152     pzone_cfg->user_zones[0].width          = 7;
00153     pzone_cfg->user_zones[0].x_centre       = 4;
00154     pzone_cfg->user_zones[0].y_centre       = 8;
00155 
00156     pzone_cfg->user_zones[1].height         = 15;
00157     pzone_cfg->user_zones[1].width          = 7;
00158     pzone_cfg->user_zones[1].x_centre       = 12;
00159     pzone_cfg->user_zones[1].y_centre       = 8;
00160 
00161     pzone_cfg->user_zones[2].height         = 7;
00162     pzone_cfg->user_zones[2].width          = 15;
00163     pzone_cfg->user_zones[2].x_centre       = 8;
00164     pzone_cfg->user_zones[2].y_centre       = 4;
00165 
00166     pzone_cfg->user_zones[3].height         = 7;
00167     pzone_cfg->user_zones[3].width          = 15;
00168     pzone_cfg->user_zones[3].x_centre       = 8;
00169     pzone_cfg->user_zones[3].y_centre       = 12;
00170 
00171 
00172 
00173     pzone_cfg->user_zones[4].height         = 15;
00174     pzone_cfg->user_zones[4].width          = 15;
00175     pzone_cfg->user_zones[4].x_centre       = 8;
00176     pzone_cfg->user_zones[4].y_centre       = 8;
00177 
00178     status = VL53L1_init_zone_config_histogram_bins(pzone_cfg);
00179 
00180 
00181     LOG_FUNCTION_END(status);
00182 
00183     return status;
00184 }
00185 
00186 
00187 VL53L1_Error VL53L1_init_zone_config_histogram_bins(
00188     VL53L1_zone_config_t   *pdata)
00189 {
00190 
00191 
00192     VL53L1_Error  status = VL53L1_ERROR_NONE;
00193 
00194     uint8_t i;
00195 
00196     LOG_FUNCTION_START("");
00197 
00198     for (i = 0; i < pdata->max_zones; i++)
00199         pdata->bin_config[i] = VL53L1_ZONECONFIG_BINCONFIG__LOWAMB;
00200 
00201     LOG_FUNCTION_END(status);
00202 
00203     return status;
00204 }
00205 
00206