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:
18:0696efe39d08
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 This file is part of VL53L1 Platform
charlesmn 0:3ac96e360672 4
charlesmn 0:3ac96e360672 5 Copyright (c) 2020, STMicroelectronics - All Rights Reserved
charlesmn 0:3ac96e360672 6
charlesmn 0:3ac96e360672 7 License terms: BSD 3-clause "New" or "Revised" License.
charlesmn 0:3ac96e360672 8
charlesmn 0:3ac96e360672 9 Redistribution and use in source and binary forms, with or without
charlesmn 0:3ac96e360672 10 modification, are permitted provided that the following conditions are met:
charlesmn 0:3ac96e360672 11
charlesmn 0:3ac96e360672 12 1. Redistributions of source code must retain the above copyright notice, this
charlesmn 0:3ac96e360672 13 list of conditions and the following disclaimer.
charlesmn 0:3ac96e360672 14
charlesmn 0:3ac96e360672 15 2. Redistributions in binary form must reproduce the above copyright notice,
charlesmn 0:3ac96e360672 16 this list of conditions and the following disclaimer in the documentation
charlesmn 0:3ac96e360672 17 and/or other materials provided with the distribution.
charlesmn 0:3ac96e360672 18
charlesmn 0:3ac96e360672 19 3. Neither the name of the copyright holder nor the names of its contributors
charlesmn 0:3ac96e360672 20 may be used to endorse or promote products derived from this software
charlesmn 0:3ac96e360672 21 without specific prior written permission.
charlesmn 0:3ac96e360672 22
charlesmn 0:3ac96e360672 23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
charlesmn 0:3ac96e360672 24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
charlesmn 0:3ac96e360672 25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
charlesmn 0:3ac96e360672 26 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
charlesmn 0:3ac96e360672 27 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
charlesmn 0:3ac96e360672 28 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
charlesmn 0:3ac96e360672 29 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
charlesmn 0:3ac96e360672 30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
charlesmn 0:3ac96e360672 31 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
charlesmn 0:3ac96e360672 32 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
charlesmn 0:3ac96e360672 33
charlesmn 0:3ac96e360672 34 */
charlesmn 0:3ac96e360672 35
charlesmn 0:3ac96e360672 36
charlesmn 0:3ac96e360672 37
charlesmn 0:3ac96e360672 38
charlesmn 0:3ac96e360672 39 #include <stdio.h>
charlesmn 0:3ac96e360672 40 #include <string.h>
charlesmn 0:3ac96e360672 41 #include <stdarg.h>
charlesmn 0:3ac96e360672 42 //#include <malloc.h>
charlesmn 0:3ac96e360672 43
charlesmn 0:3ac96e360672 44 #include "vl53l1_platform_log.h"
charlesmn 0:3ac96e360672 45 #include "vl53l1_platform_user_config.h"
charlesmn 0:3ac96e360672 46
charlesmn 0:3ac96e360672 47 #ifdef VL53L1_LOG_ENABLE
charlesmn 0:3ac96e360672 48
charlesmn 0:3ac96e360672 49 char * _trace_filename = NULL;
charlesmn 0:3ac96e360672 50 FILE *_tracefile = NULL;
charlesmn 0:3ac96e360672 51
charlesmn 0:3ac96e360672 52 uint32_t _trace_level = VL53L1_TRACE_LEVEL_WARNING;
charlesmn 0:3ac96e360672 53 uint32_t _trace_modules = VL53L1_TRACE_MODULE_NONE;
charlesmn 0:3ac96e360672 54 uint32_t _trace_functions = VL53L1_TRACE_FUNCTION_ALL;
charlesmn 0:3ac96e360672 55
charlesmn 0:3ac96e360672 56 int8_t VL53L1_trace_config(
charlesmn 0:3ac96e360672 57 char *filename,
charlesmn 0:3ac96e360672 58 uint32_t modules,
charlesmn 0:3ac96e360672 59 uint32_t level,
charlesmn 0:3ac96e360672 60 uint32_t functions)
charlesmn 0:3ac96e360672 61 {
charlesmn 0:3ac96e360672 62 int8_t status = 0;
charlesmn 0:3ac96e360672 63
charlesmn 0:3ac96e360672 64
charlesmn 0:3ac96e360672 65
charlesmn 0:3ac96e360672 66
charlesmn 0:3ac96e360672 67
charlesmn 0:3ac96e360672 68
charlesmn 0:3ac96e360672 69
charlesmn 0:3ac96e360672 70
charlesmn 0:3ac96e360672 71
charlesmn 0:3ac96e360672 72
charlesmn 0:3ac96e360672 73
charlesmn 0:3ac96e360672 74
charlesmn 0:3ac96e360672 75
charlesmn 0:3ac96e360672 76
charlesmn 0:3ac96e360672 77
charlesmn 0:3ac96e360672 78 if (((filename != NULL) && (_tracefile == NULL)) && strcmp(filename,""))
charlesmn 0:3ac96e360672 79 {
charlesmn 0:3ac96e360672 80 _tracefile = fopen(filename, "w+");
charlesmn 0:3ac96e360672 81
charlesmn 0:3ac96e360672 82
charlesmn 0:3ac96e360672 83
charlesmn 0:3ac96e360672 84 if ( _tracefile != NULL )
charlesmn 0:3ac96e360672 85 {
charlesmn 0:3ac96e360672 86 _trace_filename = (char*)malloc((strlen(filename) + 1) * sizeof(char));
charlesmn 0:3ac96e360672 87 strcpy(_trace_filename, filename);
charlesmn 0:3ac96e360672 88 }
charlesmn 0:3ac96e360672 89 else
charlesmn 0:3ac96e360672 90 {
charlesmn 0:3ac96e360672 91 printf("VL53L1_trace_config(): failed to open log file (%s)\n", filename);
charlesmn 0:3ac96e360672 92 status = 1;
charlesmn 0:3ac96e360672 93 }
charlesmn 0:3ac96e360672 94 }
charlesmn 0:3ac96e360672 95
charlesmn 0:3ac96e360672 96 _trace_modules = modules;
charlesmn 0:3ac96e360672 97 _trace_level = level;
charlesmn 0:3ac96e360672 98 _trace_functions = functions;
charlesmn 0:3ac96e360672 99
charlesmn 0:3ac96e360672 100 return status;
charlesmn 0:3ac96e360672 101 }
charlesmn 0:3ac96e360672 102
charlesmn 0:3ac96e360672 103 void VL53L1_trace_print_module_function(uint32_t module, uint32_t level, uint32_t function, const char *format, ...)
charlesmn 0:3ac96e360672 104 {
charlesmn 0:3ac96e360672 105 if ( ((level <=_trace_level) && ((module & _trace_modules) > 0))
charlesmn 0:3ac96e360672 106 || ((function & _trace_functions) > 0) )
charlesmn 0:3ac96e360672 107 {
charlesmn 0:3ac96e360672 108 va_list arg_list;
charlesmn 0:3ac96e360672 109 char message[VL53L1_MAX_STRING_LENGTH];
charlesmn 0:3ac96e360672 110
charlesmn 0:3ac96e360672 111 va_start(arg_list, format);
charlesmn 0:3ac96e360672 112 vsnprintf(message, VL53L1_MAX_STRING_LENGTH-1, format, arg_list);
charlesmn 0:3ac96e360672 113 va_end(arg_list);
charlesmn 0:3ac96e360672 114
charlesmn 0:3ac96e360672 115 if (_tracefile != NULL)
charlesmn 0:3ac96e360672 116 {
charlesmn 0:3ac96e360672 117 fprintf(_tracefile, message);
charlesmn 0:3ac96e360672 118 }
charlesmn 0:3ac96e360672 119 else
charlesmn 0:3ac96e360672 120 {
charlesmn 0:3ac96e360672 121 printf(message);
charlesmn 0:3ac96e360672 122 }
charlesmn 0:3ac96e360672 123
charlesmn 0:3ac96e360672 124
charlesmn 0:3ac96e360672 125
charlesmn 0:3ac96e360672 126
charlesmn 0:3ac96e360672 127
charlesmn 0:3ac96e360672 128 }
charlesmn 0:3ac96e360672 129 }
charlesmn 0:3ac96e360672 130
charlesmn 0:3ac96e360672 131
charlesmn 0:3ac96e360672 132 uint32_t VL53L1_get_trace_functions(void)
charlesmn 0:3ac96e360672 133 {
charlesmn 0:3ac96e360672 134 return _trace_functions;
charlesmn 0:3ac96e360672 135 }
charlesmn 0:3ac96e360672 136
charlesmn 0:3ac96e360672 137
charlesmn 0:3ac96e360672 138 void VL53L1_set_trace_functions(uint32_t function)
charlesmn 0:3ac96e360672 139 {
charlesmn 0:3ac96e360672 140 _trace_functions = function;
charlesmn 0:3ac96e360672 141 }
charlesmn 0:3ac96e360672 142
charlesmn 0:3ac96e360672 143
charlesmn 0:3ac96e360672 144 uint32_t VL53L1_clock(void)
charlesmn 0:3ac96e360672 145 {
charlesmn 0:3ac96e360672 146
charlesmn 0:3ac96e360672 147 uint32_t tick_count_ms = (uint32_t)clock();
charlesmn 0:3ac96e360672 148 return tick_count_ms;
charlesmn 0:3ac96e360672 149 }
charlesmn 0:3ac96e360672 150 #endif
charlesmn 0:3ac96e360672 151
charlesmn 0:3ac96e360672 152