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:
18:0696efe39d08
Parent:
7:1add29d51e72
--- a/src/vl53l1_core.c	Wed Jun 23 12:57:26 2021 +0000
+++ b/src/vl53l1_core.c	Wed Jul 21 17:06:38 2021 +0200
@@ -1222,7 +1222,10 @@
 
 	LOG_FUNCTION_START("");
 
-	timeout_mclks   =
+	if (macro_period_us == 0)
+		timeout_mclks = 0;
+	else
+		timeout_mclks =
 			((timeout_us << 12) + (macro_period_us>>1)) /
 			macro_period_us;
 
@@ -2395,27 +2398,36 @@
 
 
 
-	if (pxtalk_data->signal_events_sum > 0) {
+
+
+	tmp64_1 =
+		(uint64_t)pxtalk_data->effective_spad_count_sum *
+		(uint64_t)pxtalk_data->peak_duration_us_sum;
+
+	if (pxtalk_data->signal_events_sum < 0) {
+		pxtalk_data->signal_events_sum = 0;
+
 		tmp64_0 =
-			((uint64_t)pxtalk_data->signal_events_sum *
-			 (uint64_t)pxtalk_data->sample_count *
-			 (uint64_t)pxtalk_data->event_scaler_avg * 256U) << 9U;
-		tmp64_1 =
-			(uint64_t)pxtalk_data->effective_spad_count_sum *
-			(uint64_t)pxtalk_data->peak_duration_us_sum;
-
-
-
-		if (tmp64_1 > 0U) {
-
-			tmp64_0 = tmp64_0 + (tmp64_1 >> 1U);
-			xtalk_per_spad = do_division_u(tmp64_0, tmp64_1);
-		} else {
-			xtalk_per_spad = (uint64_t)tmp64_0;
+		((uint64_t)pxtalk_data->sample_count *
+		 (uint64_t)pxtalk_data->event_scaler_avg * 256U) << 9U;
+		if (tmp64_0 > 0) {
+			pxtalk_data->signal_events_sum = (int32_t)
+			do_division_u((50U * tmp64_1), tmp64_0);
 		}
-
+	}
+	tmp64_0 =
+		((uint64_t)pxtalk_data->signal_events_sum *
+		 (uint64_t)pxtalk_data->sample_count *
+		 (uint64_t)pxtalk_data->event_scaler_avg * 256U) << 9U;
+
+
+
+	if (tmp64_1 > 0U) {
+
+		tmp64_0 = tmp64_0 + (tmp64_1 >> 1U);
+		xtalk_per_spad = do_division_u(tmp64_0, tmp64_1);
 	} else {
-		status = VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL;
+		xtalk_per_spad = (uint64_t)tmp64_0;
 	}
 
 	pxtalk_data->xtalk_rate_kcps_per_spad = (uint32_t)xtalk_per_spad;
@@ -3622,6 +3634,8 @@
 		VL53L1_calc_macro_period_us(
 			fast_osc_frequency,
 			vcsel_period_a);
+	if (macro_period_us == 0)
+		macro_period_us = 1;