From 3f79599b45c655ae24007caef07a875f3637de2b Mon Sep 17 00:00:00 2001 From: wangdw10 Date: Tue, 2 Jul 2019 17:56:18 +0800 Subject: [PATCH] vl53l0: improve offset/xtalk calibration time reduce vl53l0 calibration time to less than 1s Change-Id: Ia7ce65797e5b88d46ed883bb2e360be0d66a86b2 Signed-off-by: wangdw10 Reviewed-on: https://gerrit.mot.com/1380167 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Dawei Wang Reviewed-by: Reviewed-by: Chuanxin Guo Reviewed-by: Jianqi Yang Submit-Approved: Jira Key --- .../misc/vl53L0/src/vl53l0_api_calibration.c | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/input/misc/vl53L0/src/vl53l0_api_calibration.c b/drivers/input/misc/vl53L0/src/vl53l0_api_calibration.c index 57bf47999df4..8f4d0ccf882a 100644 --- a/drivers/input/misc/vl53L0/src/vl53l0_api_calibration.c +++ b/drivers/input/misc/vl53L0/src/vl53l0_api_calibration.c @@ -80,13 +80,13 @@ VL53L0_Error VL53L0_perform_xtalk_calibration(VL53L0_DEV Dev, VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 0); } - /* Perform 50 measurements and compute the averages */ + /* Perform 12 measurements and compute the averages */ if (Status == VL53L0_ERROR_NONE) { sum_ranging = 0; sum_spads = 0; sum_signalRate = 0; total_count = 0; - for (xtalk_meas = 0; xtalk_meas < 50; xtalk_meas++) { + for (xtalk_meas = 0; xtalk_meas < 12; xtalk_meas++) { Status = VL53L0_PerformSingleRangingMeasurement(Dev, &RangingMeasurementData); @@ -203,6 +203,8 @@ VL53L0_Error VL53L0_perform_offset_calibration(VL53L0_DEV Dev, uint32_t CalDistanceAsInt_mm; uint8_t SequenceStepEnabled; int meas = 0; + uint32_t oldMeasurementTimingBudgetMicroSeconds; + uint32_t MeasurementTimingBudgetMicroSeconds = 100000; if (CalDistanceMilliMeter <= 0) Status = VL53L0_ERROR_INVALID_PARAMS; @@ -228,11 +230,19 @@ VL53L0_Error VL53L0_perform_offset_calibration(VL53L0_DEV Dev, Status = VL53L0_SetLimitCheckEnable(Dev, VL53L0_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 0); - /* Perform 50 measurements and compute the averages */ + if (Status == VL53L0_ERROR_NONE) + Status = VL53L0_GetMeasurementTimingBudgetMicroSeconds(Dev, + &oldMeasurementTimingBudgetMicroSeconds); + + if (Status == VL53L0_ERROR_NONE) + Status = VL53L0_SetMeasurementTimingBudgetMicroSeconds(Dev, + MeasurementTimingBudgetMicroSeconds); + + /* Perform 3 measurements and compute the averages */ if (Status == VL53L0_ERROR_NONE) { sum_ranging = 0; total_count = 0; - for (meas = 0; meas < 50; meas++) { + for (meas = 0; meas < 3; meas++) { Status = VL53L0_PerformSingleRangingMeasurement(Dev, &RangingMeasurementData); @@ -252,6 +262,9 @@ VL53L0_Error VL53L0_perform_offset_calibration(VL53L0_DEV Dev, Status = VL53L0_ERROR_RANGE_ERROR; } + if (Status == VL53L0_ERROR_NONE) + Status = VL53L0_SetMeasurementTimingBudgetMicroSeconds(Dev, + oldMeasurementTimingBudgetMicroSeconds); if (Status == VL53L0_ERROR_NONE) { /* FixPoint1616_t / uint16_t = FixPoint1616_t */