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.

Revision:
7:1add29d51e72
Parent:
0:3ac96e360672
Child:
18:0696efe39d08
diff -r e6ab11fe9df8 -r 1add29d51e72 src/vl53l1_hist_algos_gen3.c
--- a/src/vl53l1_hist_algos_gen3.c	Thu May 13 08:29:16 2021 +0000
+++ b/src/vl53l1_hist_algos_gen3.c	Tue Jun 08 10:34:47 2021 +0100
@@ -1,17 +1,23 @@
 
-/*******************************************************************************
- This file is part of VL53L1 Protected
+// SPDX-License-Identifier: BSD-3-Clause
+/******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
 
- Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+ This file is part of VL53L1 Protected and is dual licensed,
+ either 'STMicroelectronics Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+ ******************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+ ******************************************************************************
 
  License terms: STMicroelectronics Proprietary in accordance with licensing
  terms at www.st.com/sla0081
 
- STMicroelectronics confidential
- Reproduction and Communication of this document is strictly prohibited unless
- specifically authorized in writing by STMicroelectronics.
-
-*/
+ ******************************************************************************
+ */
 
 
 
@@ -597,24 +603,22 @@
 
 	for (lb = VL53L1_p_022; lb <= VL53L1_p_026; lb++) {
 
-
 		if (lb < 0)
-			i =  lb + (int16_t)VL53L1_p_031;
+			i = lb + (int16_t)VL53L1_p_031;
 		else
-			i =  lb % (int16_t)VL53L1_p_031;
+			i = lb % (int16_t)VL53L1_p_031;
 
-		VL53L1_p_008 =
-			(int64_t)pbins->bin_data[i] -
-			(int64_t)pbins->VL53L1_p_004;
-
+		if ((i >= 0) && (i < VL53L1_HISTOGRAM_BUFFER_SIZE)) {
+			VL53L1_p_008 =
+				(int64_t)pbins->bin_data[i] -
+				(int64_t)pbins->VL53L1_p_004;
 
-		if (clip_events > 0 && VL53L1_p_008 < 0)
-			VL53L1_p_008 = 0;
-
-		event_sum += VL53L1_p_008;
-
-		weighted_sum +=
-			(VL53L1_p_008 * (1024 + (2048*(int64_t)lb)));
+			if (clip_events > 0 && VL53L1_p_008 < 0)
+				VL53L1_p_008 = 0;
+			event_sum += VL53L1_p_008;
+			weighted_sum +=
+				(VL53L1_p_008 * (1024 + (2048*(int64_t)lb)));
+		}
 
 		trace_print(
 			VL53L1_TRACE_LEVEL_INFO,
@@ -628,13 +632,10 @@
 	}
 
 	if (event_sum  > 0) {
-
 		weighted_sum += do_division_s(event_sum, 2);
 		weighted_sum = do_division_s(weighted_sum, event_sum);
-
 		if (weighted_sum < 0)
 			weighted_sum = 0;
-
 		*pphase = (uint32_t)weighted_sum;
 	}
 
@@ -849,4 +850,3 @@
 }
 
 
-