Greatly simplified Architecture, Identical Functions Removed: Platform Interfaces, STP6001 interface
Diff: VL53L0X.cpp
- Revision:
- 13:253cb4ea3fcc
- Parent:
- 12:81f37e50f8f8
--- a/VL53L0X.cpp Mon Jul 08 14:07:22 2019 +0000 +++ b/VL53L0X.cpp Sat Jul 20 08:48:49 2019 +0000 @@ -68,102 +68,102 @@ #include <stdlib.h> #include "VL53L0X.h" -void Report_Range_Infos(VL53L0X_RangingMeasurementData_t RangeResults) +void Report_Range_Infos(VL53L0X_RangingMeasurementData_t RangeResults, Serial *aSerial ) { - printf("\n\r Reporting All Fields of VL53L0X_RangingMeasurementData_t structure \n\r" ); - printf(" .Range_mm = %dmm; Ranged distance. \n\r", RangeResults.Range_mm ); - printf(" .RangeDMax_mm = %dmm; maximum detection distance in current setup and environment conditions \n\r", RangeResults.RangeDMax_mm ); - printf(" .SignalRateRtn_MHz = %3.3fMHz; effectively a measure of target reflectance \n\r", RangeResults.SignalRateRtn_MHz / 65535.01); - printf(" .AmbientRateRtn_MHz = %3.3fMHz; effectively a measure of the ambient light \n\r", RangeResults.AmbientRateRtn_MHz / 65535.01 ); - printf(" .EffectiveSpadRtnCount = %3.3f; effective SPAD count for the return signal \n\r", RangeResults.EffectiveSpadRtnCount / 256.001 ); - printf(" .RangeFractionalPart = %d; Fractional part of range distance. \n\r", RangeResults.RangeFractionalPart >> 6 ); - printf(" .RangeStatus = %d[u8]; Status for the current measurement, 0 = value is valid \n\r", RangeResults.RangeStatus ); - printf(" .SigmaEstimate = %3.2f; Estimated Sigma - based on ambient & VCSEL rates and signal_total_events \n\r", RangeResults.SigmaEstimate/ 65535.01 ); + aSerial->printf("\n\r Reporting All Fields of VL53L0X_RangingMeasurementData_t structure \n\r" ); + aSerial->printf(" .Range_mm = %dmm; Ranged distance. \n\r", RangeResults.Range_mm ); + aSerial->printf(" .RangeDMax_mm = %dmm; maximum detection distance in current setup and environment conditions \n\r", RangeResults.RangeDMax_mm ); + aSerial->printf(" .SignalRateRtn_MHz = %3.3fMHz; effectively a measure of target reflectance \n\r", RangeResults.SignalRateRtn_MHz / 65535.01); + aSerial->printf(" .AmbientRateRtn_MHz = %3.3fMHz; effectively a measure of the ambient light \n\r", RangeResults.AmbientRateRtn_MHz / 65535.01 ); + aSerial->printf(" .EffectiveSpadRtnCount = %3.3f; effective SPAD count for the return signal \n\r", RangeResults.EffectiveSpadRtnCount / 256.001 ); + aSerial->printf(" .RangeFractionalPart = %d; Fractional part of range distance. \n\r", RangeResults.RangeFractionalPart >> 6 ); + aSerial->printf(" .RangeStatus = %d[u8]; Status for the current measurement, 0 = value is valid \n\r", RangeResults.RangeStatus ); + aSerial->printf(" .SigmaEstimate = %3.2f; Estimated Sigma - based on ambient & VCSEL rates and signal_total_events \n\r", RangeResults.SigmaEstimate/ 65535.01 ); }; -void Report_Deep_Infos(VL53L0X TOF1) +void Report_Deep_Infos(VL53L0X TOF1, Serial *aSerial) { - printf("\n\r Reporting All Top Level Infos of the class \n\r" ); - printf("I2cDevAddr = %d. \n\r", TOF1.I2cDevAddr ); - printf("comms_type = %d. Type of comms: 1=VL53L0X_COMMS_I2C or VL53L0X_COMMS_SPI \n\r", TOF1.comms_type ); - printf("comms_speed = %d. Communication speed [kHz] : typically 400kHz for I2C \n\r", TOF1.comms_speed_khz ); + aSerial->printf("\n\r Reporting All Top Level Infos of the class \n\r" ); + aSerial->printf("I2cDevAddr = %d. \n\r", TOF1.I2cDevAddr ); + aSerial->printf("comms_type = %d. Type of comms: 1=VL53L0X_COMMS_I2C or VL53L0X_COMMS_SPI \n\r", TOF1.comms_type ); + aSerial->printf("comms_speed = %d. Communication speed [kHz] : typically 400kHz for I2C \n\r", TOF1.comms_speed_khz ); - printf("\n\r Reporting All Infos of the Device_Info structure: \n\r" ); - printf("Device_Info.ProductType = 0x%2X. VL53L0X = 1, VL53L1 = 2 \n\r", TOF1.Device_Info.ProductType ); - printf("Device_Info.ProductRevision = %d.%d. Revision NR, major.minor \n\r", + aSerial->printf("\n\r Reporting All Infos of the Device_Info structure: \n\r" ); + aSerial->printf("Device_Info.ProductType = 0x%2X. VL53L0X = 1, VL53L1 = 2 \n\r", TOF1.Device_Info.ProductType ); + aSerial->printf("Device_Info.ProductRevision = %d.%d. Revision NR, major.minor \n\r", TOF1.Device_Info.ProductRevisionMajor, TOF1.Device_Info.ProductRevisionMinor ); - printf("Device_Info.Name = %s. Name of Device e.g. Left_Distance\n\r", TOF1.Device_Info.Name ); - printf("Device_Info.Type = %s. Type of Device e.g VL53L0X \n\r", TOF1.Device_Info.Type ); - printf("Device_Info.ProductId = %s. Product Identifier String \n\r", TOF1.Device_Info.ProductId ); - - printf("\n\r Reporting All Fields of CurrentParameters \n\r" ); - printf(" .DeviceMode = %d. Defines type of measurement to be done for the next measurement \n\r", + aSerial->printf("Device_Info.Name = %s. Name of Device e.g. Left_Distance\n\r", TOF1.Device_Info.Name ); + aSerial->printf("Device_Info.Type = %s. Type of Device e.g VL53L0X \n\r", TOF1.Device_Info.Type ); + aSerial->printf("Device_Info.ProductId = %s. Product Identifier String \n\r", TOF1.Device_Info.ProductId ); + + aSerial->printf("\n\r Reporting All Fields of CurrentParameters \n\r" ); + aSerial->printf(" .DeviceMode = %d. Defines type of measurement to be done for the next measurement \n\r", TOF1.CurrentParameters.DeviceMode ); - printf(" .Measure_Time_Budget_us= %dus. Allowed total time for a single measurement \n\r", + aSerial->printf(" .Measure_Time_Budget_us= %dus. Allowed total time for a single measurement \n\r", TOF1.CurrentParameters.MeasurementTimingBudget_us ); - printf(" .Measure_Period_ms = %dms. Time between two consecutive measurements \n\r", + aSerial->printf(" .Measure_Period_ms = %dms. Time between two consecutive measurements \n\r", TOF1.CurrentParameters.InterMeasurementPeriod_ms ); - printf(" .XTalk_Compens_En = %d. Crosstalk compensation enable or not (0, default) \n\r", + aSerial->printf(" .XTalk_Compens_En = %d. Crosstalk compensation enable or not (0, default) \n\r", TOF1.CurrentParameters.XTalkCompensationEnable ); - printf(" .XTalk_CompRange_mm = %dmm. CrossTalk compensation range, seems never used \n\r", + aSerial->printf(" .XTalk_CompRange_mm = %dmm. CrossTalk compensation range, seems never used \n\r", TOF1.CurrentParameters.XTalkCompensationRange_mm ); - printf(" .XTalk_CompRate_MHz = %3.2fMHz. CrossTalk compensation rate . \n\r", + aSerial->printf(" .XTalk_CompRate_MHz = %3.2fMHz. CrossTalk compensation rate . \n\r", (float) TOF1.CurrentParameters.XTalkCompensationRate_MHz / 65536); - printf(" .RangeOffset_um = %d. Range offset adjustment (um) last programmed.\n\r", + aSerial->printf(" .RangeOffset_um = %d. Range offset adjustment (um) last programmed.\n\r", TOF1.CurrentParameters.RangeOffset_um ); - printf(" .LimitChecks ... = SIGMA_FINAL, SIGNAL_RATE_FINAL, SIGNAL_REF_CLIP, IGNORE_THRESHOLD, SIGNAL_RATE_MSRC, SIGNAL_RATE_PRE.\n\r"); - printf(" .LimitChecksEnable[x] = %d %d %d %d %d %d. The Limit Checks enabled or not.\n\r", + aSerial->printf(" .LimitChecks ... = SIGMA_FINAL, SIGNAL_RATE_FINAL, SIGNAL_REF_CLIP, IGNORE_THRESHOLD, SIGNAL_RATE_MSRC, SIGNAL_RATE_PRE.\n\r"); + aSerial->printf(" .LimitChecksEnable[x] = %d %d %d %d %d %d. The Limit Checks enabled or not.\n\r", TOF1.CurrentParameters.LimitChecksEnable[0],TOF1.CurrentParameters.LimitChecksEnable[1] ,TOF1.CurrentParameters.LimitChecksEnable[2], TOF1.CurrentParameters.LimitChecksEnable[3],TOF1.CurrentParameters.LimitChecksEnable[4] ,TOF1.CurrentParameters.LimitChecksEnable[5] ); - printf(" .LimitChecksStatus[x] = %d %d %d %d %d %d. Status of checks of last measurement.\n\r", + aSerial->printf(" .LimitChecksStatus[x] = %d %d %d %d %d %d. Status of checks of last measurement.\n\r", TOF1.CurrentParameters.LimitChecksStatus[0],TOF1.CurrentParameters.LimitChecksStatus[1] ,TOF1.CurrentParameters.LimitChecksStatus[2], TOF1.CurrentParameters.LimitChecksStatus[3],TOF1.CurrentParameters.LimitChecksStatus[4] ,TOF1.CurrentParameters.LimitChecksStatus[5] ); - printf(" .LimitChecksValue[x] = %d %d %d %d %d %d [FP1616]. The Limit Check values \n\r", + aSerial->printf(" .LimitChecksValue[x] = %d %d %d %d %d %d [FP1616]. The Limit Check values \n\r", TOF1.CurrentParameters.LimitChecksValue[0],TOF1.CurrentParameters.LimitChecksValue[1] ,TOF1.CurrentParameters.LimitChecksValue[2], TOF1.CurrentParameters.LimitChecksValue[3],TOF1.CurrentParameters.LimitChecksValue[4] ,TOF1.CurrentParameters.LimitChecksValue[5] ); - printf(" .WrapAroundCheckEnable = %d. Wrap Around Check enabled or not \n\r", + aSerial->printf(" .WrapAroundCheckEnable = %d. Wrap Around Check enabled or not \n\r", TOF1.CurrentParameters.WrapAroundCheckEnable ); - printf("\n\r Reporting All Fields of VL53L0X_DevData_t Data structure \n\r" ); - printf(" .OscFrequency_MHz = %3.2fMHz; Frequency used \n\r", (float) TOF1.Data.OscFrequency_MHz/65536 ); - printf(" .LastEncodedTimeout = %d[u16]; Last encoded Time out used for timing budget \n\r", TOF1.Data.LastEncodedTimeout ); - printf(" .Pin0GpioFunctionality = %d[u8]; functionality of the GPIO: pin0 \n\r", TOF1.Data.Pin0GpioFunctionality ); - printf(" .FinalRangeTimeout_us = %d[u32]; Execution time of the final ranging \n\r", TOF1.Data.FinalRangeTimeout_us ); - printf(" .FinalRangeVcselPulsePeriod= %d[u8]; Vcsel pulse period (pll clocks) for the final range measurement \n\r", TOF1.Data.FinalRangeVcselPulsePeriod ); - printf(" .PreRangeTimeout_us = %d[u32]; Execution time of the final range \n\r", TOF1.Data.PreRangeTimeout_us ); - printf(" .PreRangeVcselPulsePeriod = %d[u8]; Vcsel pulse period (pll clocks) for the pre-range measurement \n\r", TOF1.Data.PreRangeVcselPulsePeriod ); - printf(" .ReadDataFromDeviceDone = %2d; reads from device has been done (>0) or not. \n\r", TOF1.Data.ReadDataFromDeviceDone ); - printf(" .ModuleId = %X; Module ID \n\r", TOF1.Data.ModuleId ); - printf(" .Revision = %d[u8]; test Revision \n\r", TOF1.Data.Revision ); - printf(" .ProductId = %s[char*]; Product Identifier String \n\r", TOF1.Data.ProductId ); - printf(" .ReferenceSpadCount = %d[u8]; used for ref spad management \n\r", TOF1.Data.ReferenceSpadCount ); - printf(" .ReferenceSpadType = %d[u8]; used for ref spad management \n\r", TOF1.Data.ReferenceSpadType ); - printf(" .RefSpadsInitialised = %d[u8]; reports if ref spads are initialised. \n\r", TOF1.Data.RefSpadsInitialised ); - printf(" .PartUIDUpper = %d[u32]; Unique Part ID Upper \n\r", TOF1.Data.PartUIDUpper ); - printf(" .PartUIDLower = %d[u32]; Unique Part ID Lower \n\r", TOF1.Data.PartUIDLower ); - printf(" .SignalRateMeasFixed400mm = %3.3f; Peak Signal rate at 400 mm \n\r", 1.0 / 65535.0 * TOF1.Data.SignalRateMeasFixed400mm ); - printf(" .RefSpadEnables[x] = %X %X %X %X %X %X[hex8]; Reference Spad Enables \n\r", + aSerial->printf("\n\r Reporting All Fields of VL53L0X_DevData_t Data structure \n\r" ); + aSerial->printf(" .OscFrequency_MHz = %3.2fMHz; Frequency used \n\r", (float) TOF1.Data.OscFrequency_MHz/65536 ); + aSerial->printf(" .LastEncodedTimeout = %d[u16]; Last encoded Time out used for timing budget \n\r", TOF1.Data.LastEncodedTimeout ); + aSerial->printf(" .Pin0GpioFunctionality = %d[u8]; functionality of the GPIO: pin0 \n\r", TOF1.Data.Pin0GpioFunctionality ); + aSerial->printf(" .FinalRangeTimeout_us = %d[u32]; Execution time of the final ranging \n\r", TOF1.Data.FinalRangeTimeout_us ); + aSerial->printf(" .FinalRangeVcselPulsePeriod= %d[u8]; Vcsel pulse period (pll clocks) for the final range measurement \n\r", TOF1.Data.FinalRangeVcselPulsePeriod ); + aSerial->printf(" .PreRangeTimeout_us = %d[u32]; Execution time of the final range \n\r", TOF1.Data.PreRangeTimeout_us ); + aSerial->printf(" .PreRangeVcselPulsePeriod = %d[u8]; Vcsel pulse period (pll clocks) for the pre-range measurement \n\r", TOF1.Data.PreRangeVcselPulsePeriod ); + aSerial->printf(" .ReadDataFromDeviceDone = %2d; reads from device has been done (>0) or not. \n\r", TOF1.Data.ReadDataFromDeviceDone ); + aSerial->printf(" .ModuleId = %X; Module ID \n\r", TOF1.Data.ModuleId ); + aSerial->printf(" .Revision = %d[u8]; test Revision \n\r", TOF1.Data.Revision ); + aSerial->printf(" .ProductId = %s[char*]; Product Identifier String \n\r", TOF1.Data.ProductId ); + aSerial->printf(" .ReferenceSpadCount = %d[u8]; used for ref spad management \n\r", TOF1.Data.ReferenceSpadCount ); + aSerial->printf(" .ReferenceSpadType = %d[u8]; used for ref spad management \n\r", TOF1.Data.ReferenceSpadType ); + aSerial->printf(" .RefSpadsInitialised = %d[u8]; reports if ref spads are initialised. \n\r", TOF1.Data.RefSpadsInitialised ); + aSerial->printf(" .PartUIDUpper = %d[u32]; Unique Part ID Upper \n\r", TOF1.Data.PartUIDUpper ); + aSerial->printf(" .PartUIDLower = %d[u32]; Unique Part ID Lower \n\r", TOF1.Data.PartUIDLower ); + aSerial->printf(" .SignalRateMeasFixed400mm = %3.3f; Peak Signal rate at 400 mm \n\r", 1.0 / 65535.0 * TOF1.Data.SignalRateMeasFixed400mm ); + aSerial->printf(" .RefSpadEnables[x] = %X %X %X %X %X %X[hex8]; Reference Spad Enables \n\r", TOF1.Data.RefSpadEnables[0], TOF1.Data.RefSpadEnables[1], TOF1.Data.RefSpadEnables[2], TOF1.Data.RefSpadEnables[3], TOF1.Data.RefSpadEnables[4], TOF1.Data.RefSpadEnables[5] ); - printf(" .RefGoodSpadMap[x] = %X %X %X %X %X %X[hex8]; Reference Spad Good Spad Map\n\r", + aSerial->printf(" .RefGoodSpadMap[x] = %X %X %X %X %X %X[hex8]; Reference Spad Good Spad Map\n\r", TOF1.Data.RefGoodSpadMap[0], TOF1.Data.RefGoodSpadMap[1], TOF1.Data.RefGoodSpadMap[2], TOF1.Data.RefGoodSpadMap[3], TOF1.Data.RefGoodSpadMap[4], TOF1.Data.RefGoodSpadMap[5] ); - printf(" .Part2PartOffsetNVM_um = %d[i32]; backed up NVM value \n\r", TOF1.Data.Part2PartOffsetNVM_um ); - printf(" .Part2PartOffsetAdjustNVM_um= %d[i32]; backed up NVM value of additional offset adjustment \n\r", TOF1.Data.Part2PartOffsetAdjustNVM_um ); - printf(" .SequenceConfig = %d[u8]; Internal value for the sequence config \n\r", TOF1.Data.SequenceConfig ); - printf(" .RangeFractionalEnable = %d[u8]; Enable/Disable fractional part of range data \n\r", TOF1.Data.RangeFractionalEnable); - printf(" .PalState = %d[u8]; Current state of the PAL \n\r", TOF1.Data.PalState ); - printf(" .PowerMode = %d[u8]; Current Power Mode; Stdby1/2, Idle1/2 \n\r", TOF1.Data.PowerMode ); - printf(" .SigmaEstRefArray = %d[u16]; Reference array sigma value in 1/100th of [mm] \n\r", TOF1.Data.SigmaEstRefArray ); - printf(" .SigmaEstEffPulseWidth = %d[u16]; Effective Pulse width for sigma estimate in 1/100th of ns \n\r", TOF1.Data.SigmaEstEffPulseWidth ); - printf(" .SigmaEstEffAmbWidth = %d. Effective Ambient width for sigma estimate in 1/100th of ns \n\r", TOF1.Data.SigmaEstEffAmbWidth ); - printf(" .StopVariable = %d[u8]; StopVariable used during the stop sequence \n\r", TOF1.Data.StopVariable ); - printf(" .targetRefRate = %d. Target Ambient Rate for Ref spad management \n\r", TOF1.Data.targetRefRate ); - printf(" .LastSignalRef_MHz = %3.3fMHz; Latest Signal ref \n\r", TOF1.Data.LastSignalRef_MHz / 65535.01 ); - printf(" .UseInternalTuningSetting = %d[u8]; Indicate if we use Tuning Settings table \n\r", TOF1.Data.UseInternalTuningSettings ); - printf(" .LinearityCorrectiveGain = %d[u8]; Linearity Corrective Gain value in x1000 \n\r", TOF1.Data.LinearityCorrectiveGain ); - printf(" .DmaxCalRange_mm = %dmm; Dmax Calibration Range \n\r", TOF1.Data.DmaxCalRange_mm ); - printf(" .DmaxCalSignalRateRtn_MHz = %3.3fMHz; Dmax Calibration Signal Rate Return \n\r", TOF1.Data.DmaxCalSignalRateRtn_MHz / 65535.01 ); + aSerial->printf(" .Part2PartOffsetNVM_um = %d[i32]; backed up NVM value \n\r", TOF1.Data.Part2PartOffsetNVM_um ); + aSerial->printf(" .Part2PartOffsetAdjustNVM_um= %d[i32]; backed up NVM value of additional offset adjustment \n\r", TOF1.Data.Part2PartOffsetAdjustNVM_um ); + aSerial->printf(" .SequenceConfig = %d[u8]; Internal value for the sequence config \n\r", TOF1.Data.SequenceConfig ); + aSerial->printf(" .RangeFractionalEnable = %d[u8]; Enable/Disable fractional part of range data \n\r", TOF1.Data.RangeFractionalEnable); + aSerial->printf(" .PalState = %d[u8]; Current state of the PAL \n\r", TOF1.Data.PalState ); + aSerial->printf(" .PowerMode = %d[u8]; Current Power Mode; Stdby1/2, Idle1/2 \n\r", TOF1.Data.PowerMode ); + aSerial->printf(" .SigmaEstRefArray = %d[u16]; Reference array sigma value in 1/100th of [mm] \n\r", TOF1.Data.SigmaEstRefArray ); + aSerial->printf(" .SigmaEstEffPulseWidth = %d[u16]; Effective Pulse width for sigma estimate in 1/100th of ns \n\r", TOF1.Data.SigmaEstEffPulseWidth ); + aSerial->printf(" .SigmaEstEffAmbWidth = %d. Effective Ambient width for sigma estimate in 1/100th of ns \n\r", TOF1.Data.SigmaEstEffAmbWidth ); + aSerial->printf(" .StopVariable = %d[u8]; StopVariable used during the stop sequence \n\r", TOF1.Data.StopVariable ); + aSerial->printf(" .targetRefRate = %d. Target Ambient Rate for Ref spad management \n\r", TOF1.Data.targetRefRate ); + aSerial->printf(" .LastSignalRef_MHz = %3.3fMHz; Latest Signal ref \n\r", TOF1.Data.LastSignalRef_MHz / 65535.01 ); + aSerial->printf(" .UseInternalTuningSetting = %d[u8]; Indicate if we use Tuning Settings table \n\r", TOF1.Data.UseInternalTuningSettings ); + aSerial->printf(" .LinearityCorrectiveGain = %d[u8]; Linearity Corrective Gain value in x1000 \n\r", TOF1.Data.LinearityCorrectiveGain ); + aSerial->printf(" .DmaxCalRange_mm = %dmm; Dmax Calibration Range \n\r", TOF1.Data.DmaxCalRange_mm ); + aSerial->printf(" .DmaxCalSignalRateRtn_MHz = %3.3fMHz; Dmax Calibration Signal Rate Return \n\r", TOF1.Data.DmaxCalSignalRateRtn_MHz / 65535.01 ); } int VL53L0X::read_id(uint8_t *id) @@ -187,12 +187,12 @@ uint8_t id = 0; status = read_id(&id); if (status != 0) { - printf("VL53L0X sensor is not present!\n\r"); + //aSerial->printf("VL53L0X sensor is not present!\n\r"); return 99; } // device is not present status = VL53L0X_data_init(); if (status != VL53L0X_ERROR_NONE) { - printf("Failed to init VL53L0X sensor!\n\r"); + //aSerial->printf("Failed to init VL53L0X sensor!\n\r"); return status; } @@ -201,14 +201,14 @@ status = prepare(); if (status != VL53L0X_ERROR_NONE) { - printf("Failed to prepare VL53L0X!\n\r"); + //aSerial->printf("Failed to prepare VL53L0X!\n\r"); return status; } if (new_addr != VL53L0X_DEFAULT_ADDRESS) { status = set_device_address(new_addr); if (status) { - printf("Failed to change I2C address!\n\r"); + //aSerial->printf("Failed to change I2C address!\n\r"); return status; } } @@ -366,14 +366,14 @@ uint8_t PhaseCal; // default settings, for normal range. FixPoint1616_t signalLimit = (FixPoint1616_t)(0.25 * 65536); - FixPoint1616_t sigmaLimit = (FixPoint1616_t)(18 * 65536); + FixPoint1616_t sigmaLimit = (FixPoint1616_t)(25 * 65536); uint32_t timingBudget = 33000; uint8_t preRangeVcselPeriod = 14; uint8_t finalRangeVcselPeriod = 10; if (operating_mode == range_continuous_interrupt) { if (_gpio1Int == NULL) { - printf("GPIO1 Error\r\n"); + //aSerial->printf("GPIO1 Error\r\n"); return 1; } @@ -394,10 +394,7 @@ if (ClrStatus) { Status = 97; } // VL53L0X_ClearErrorInterrupt fail if (Status == VL53L0X_ERROR_NONE) { - Status = VL53L0X_set_device_mode(VL53L0X_DEVICEMODE_CONTINUOUS_RANGING); // Setup in continuous ranging mode - } - - if (Status == VL53L0X_ERROR_NONE) { + CurrentParameters.DeviceMode = VL53L0X_DEVICEMODE_CONTINUOUS_RANGING; // Setup in continuous ranging mode Status = VL53L0X_start_measurement(); } } @@ -406,11 +403,8 @@ // singelshot, polled ranging if (Status == VL53L0X_ERROR_NONE) { // no need to do this when we use VL53L0X_PerformSingleRangingMeasurement - Status = VL53L0X_set_device_mode( VL53L0X_DEVICEMODE_SINGLE_RANGING); // Setup in single ranging mode - } - - // Enable/Disable Sigma and Signal check - if (Status == VL53L0X_ERROR_NONE) { + CurrentParameters.DeviceMode = VL53L0X_DEVICEMODE_SINGLE_RANGING; // Setup in single ranging mode + // Enable/Disable Sigma and Signal check Status = VL53L0X_set_limit_check_enable(VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, 1); } if (Status == VL53L0X_ERROR_NONE) { @@ -422,7 +416,7 @@ case Range_Config_DEFAULT: // default settings, for normal range. signalLimit = (FixPoint1616_t)(0.25 * 65536); - sigmaLimit = (FixPoint1616_t)(18 * 65536); + sigmaLimit = (FixPoint1616_t)(16 * 65536); timingBudget = 33000; preRangeVcselPeriod = 14; finalRangeVcselPeriod = 10; @@ -443,7 +437,7 @@ break; case Range_Config_HIGH_SPEED: signalLimit = (FixPoint1616_t)(0.25*65536); - sigmaLimit = (FixPoint1616_t)(32*65536); + sigmaLimit = (FixPoint1616_t)(60*65536); timingBudget = 20000; preRangeVcselPeriod = 14; finalRangeVcselPeriod = 10; @@ -474,12 +468,7 @@ if (operating_mode == range_continuous_polling) { if (Status == VL53L0X_ERROR_NONE) { - //printf("Call of VL53L0X_SetDeviceMode\n"); - Status = VL53L0X_set_device_mode( VL53L0X_DEVICEMODE_CONTINUOUS_RANGING); // Setup in continuous ranging mode - } - - if (Status == VL53L0X_ERROR_NONE) { - //printf("Call of VL53L0X_StartMeasurement\n"); + CurrentParameters.DeviceMode = VL53L0X_DEVICEMODE_CONTINUOUS_RANGING; // Setup in continuous ranging mode Status = VL53L0X_start_measurement(); } } @@ -494,8 +483,7 @@ // status = VL53L0X_SetInterruptThresholds(Device, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING, 0, 300); status = VL53L0X_set_gpio_config( 0, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING, - VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY, - VL53L0X_INTERRUPTPOLARITY_HIGH); + VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY, VL53L0X_INTERRUPTPOLARITY_HIGH); if (!status) { attach_interrupt_measure_detection_irq(fptr); @@ -542,7 +530,7 @@ int status = 0; VL53L0X_RangingMeasurementData_t p_ranging_measurement_data; - status = start_measurement(range_single_shot_polling, NULL); + status = start_measurement(range_single_shot_polling, NULL, Range_Config_DEFAULT); if (!status) { status = get_measurement(range_single_shot_polling, &p_ranging_measurement_data); } @@ -621,12 +609,12 @@ if (operating_mode == range_continuous_interrupt || operating_mode == range_continuous_polling) { // continuous mode if (status == VL53L0X_ERROR_NONE) { - //printf("Call of VL53L0X_StopMeasurement\n"); + //aSerial->printf("Call of VL53L0X_StopMeasurement\n"); status = VL53L0X_stop_measurement(); } if (status == VL53L0X_ERROR_NONE) { - //printf("Wait Stop to be competed\n"); + //aSerial->printf("Wait Stop to be competed\n"); status = wait_stop_completed(); } @@ -645,13 +633,10 @@ } int VL53L0X::range_start_continuous_mode() -{ int status; - status = VL53L0X_set_device_mode( VL53L0X_DEVICEMODE_CONTINUOUS_RANGING); - - if (status == VL53L0X_ERROR_NONE) - { status = VL53L0X_start_measurement(); } - - return status; +{ CurrentParameters.DeviceMode = VL53L0X_DEVICEMODE_CONTINUOUS_RANGING; + + return VL53L0X_start_measurement(); + } VL53L0X_Error VL53L0X::VL53L0X_device_read_strobe(void) @@ -824,7 +809,6 @@ status |= VL53L0X_write_byte( 0x94, 0x7B); status |= VL53L0X_device_read_strobe(); status |= VL53L0X_read_dword( 0x90, &part_uid_upper); - status |= VL53L0X_write_byte( 0x94, 0x7C); status |= VL53L0X_device_read_strobe(); status |= VL53L0X_read_dword( 0x90, &part_uid_lower); @@ -832,25 +816,21 @@ status |= VL53L0X_write_byte( 0x94, 0x73); status |= VL53L0X_device_read_strobe(); status |= VL53L0X_read_dword( 0x90, &tmp_dword); - signal_rate_meas_fixed1104_400_mm = (tmp_dword & 0x0000000ff) << 8; status |= VL53L0X_write_byte( 0x94, 0x74); status |= VL53L0X_device_read_strobe(); status |= VL53L0X_read_dword( 0x90, &tmp_dword); - signal_rate_meas_fixed1104_400_mm |= ((tmp_dword & 0xff000000) >> 24); status |= VL53L0X_write_byte( 0x94, 0x75); status |= VL53L0X_device_read_strobe(); status |= VL53L0X_read_dword( 0x90, &tmp_dword); - dist_meas_fixed1104_400_mm = (tmp_dword & 0x0000000ff) << 8; status |= VL53L0X_write_byte( 0x94, 0x76); status |= VL53L0X_device_read_strobe(); status |= VL53L0X_read_dword( 0x90, &tmp_dword); - dist_meas_fixed1104_400_mm |= ((tmp_dword & 0xff000000) >> 24); } @@ -860,7 +840,6 @@ status |= VL53L0X_write_byte( 0x83, byte & 0xfb); status |= VL53L0X_write_byte( 0xFF, 0x01); status |= VL53L0X_write_byte( 0x00, 0x01); - status |= VL53L0X_write_byte( 0xFF, 0x00); status |= VL53L0X_write_byte( 0x80, 0x00); } @@ -913,14 +892,13 @@ return status; } -VL53L0X_Error VL53L0X::wrapped_VL53L0X_get_offset_calibration_data_micro_meter(int32_t *p_offset_calibration_data_micro_meter) +VL53L0X_Error VL53L0X::VL53L0X_get_offset_calibration_data_micro_meter(int32_t *p_offset_calibration_data_micro_meter) { VL53L0X_Error status = VL53L0X_ERROR_NONE; uint16_t range_offset_register; int16_t c_max_offset = 2047; int16_t c_offset_range = 4096; - /* Note that offset has 10.2 format */ - + /* Note, that offset has 10.2 format */ status = VL53L0X_read_word(VL53L0X_REG_ALGO_PART_TO_PART_RANGE_OFFSET_MM, &range_offset_register); @@ -930,37 +908,22 @@ /* Apply 12 bit 2's compliment conversion */ if (range_offset_register > c_max_offset) { *p_offset_calibration_data_micro_meter = - (int16_t)(range_offset_register - c_offset_range) - * 250; + (int16_t)(range_offset_register - c_offset_range) * 250; } else { *p_offset_calibration_data_micro_meter = - (int16_t)range_offset_register * 250; - } - + (int16_t)range_offset_register * 250; } } return status; } -VL53L0X_Error VL53L0X::VL53L0X_get_offset_calibration_data_micro_meter(int32_t *p_offset_calibration_data_micro_meter) -{ VL53L0X_Error status = VL53L0X_ERROR_NONE; - - - status = wrapped_VL53L0X_get_offset_calibration_data_micro_meter(p_offset_calibration_data_micro_meter); - - - return status; -} - -VL53L0X_Error VL53L0X::wrapped_VL53L0X_set_offset_calibration_data_micro_meter(int32_t offset_calibration_data_micro_meter) +VL53L0X_Error VL53L0X::VL53L0X_set_offset_calibration_data_micro_meter(int32_t offset_calibration_data_micro_meter) { VL53L0X_Error status = VL53L0X_ERROR_NONE; int32_t c_max_offset_micro_meter = 511000; int32_t c_min_offset_micro_meter = -512000; int16_t c_offset_range = 4096; uint32_t encoded_offset_val; - - if (offset_calibration_data_micro_meter > c_max_offset_micro_meter) { offset_calibration_data_micro_meter = c_max_offset_micro_meter; } else { @@ -970,32 +933,16 @@ } /* The offset register is 10.2 format and units are mm - * therefore conversion is applied by a division of - * 250. - */ + * therefore conversion is applied by a division of 250. */ if (offset_calibration_data_micro_meter >= 0) { - encoded_offset_val = - offset_calibration_data_micro_meter / 250; + encoded_offset_val = offset_calibration_data_micro_meter / 250; } else { encoded_offset_val = - c_offset_range + - offset_calibration_data_micro_meter / 250; + c_offset_range + offset_calibration_data_micro_meter / 250; } status = VL53L0X_write_word(VL53L0X_REG_ALGO_PART_TO_PART_RANGE_OFFSET_MM, encoded_offset_val); - - - return status; -} - -VL53L0X_Error VL53L0X::VL53L0X_set_offset_calibration_data_micro_meter(int32_t offset_calibration_data_micro_meter) -{ VL53L0X_Error status = VL53L0X_ERROR_NONE; - - - status = wrapped_VL53L0X_set_offset_calibration_data_micro_meter(offset_calibration_data_micro_meter); - - return status; } @@ -1028,17 +975,6 @@ CurrentParameters.RangeOffset_um = corrected_offset_micro_meters; } } - - return status; -} - -VL53L0X_Error VL53L0X::VL53L0X_get_device_mode(VL53L0X_DeviceModes *p_device_mode) -{ VL53L0X_Error status = VL53L0X_ERROR_NONE; - - - *p_device_mode = CurrentParameters.DeviceMode ; - - return status; } @@ -1064,7 +1000,6 @@ } CurrentParameters.InterMeasurementPeriod_ms = *p_inter_measurement_period_ms; } - return status; } @@ -1074,8 +1009,6 @@ uint16_t value; FixPoint1616_t temp_fix1616; - - status = VL53L0X_read_word(VL53L0X_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MHz, (uint16_t *)&value); if (status == VL53L0X_ERROR_NONE) { if (value == 0) { @@ -1091,7 +1024,6 @@ } } - return status; } @@ -1102,8 +1034,6 @@ uint16_t temp16; FixPoint1616_t temp_fix1616; - - switch (limit_check_id) { case VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE: @@ -1113,12 +1043,10 @@ break; case VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE: - status = VL53L0X_read_word(VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT, - &temp16); + status = VL53L0X_read_word(VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT, &temp16); if (status == VL53L0X_ERROR_NONE) { temp_fix1616 = VL53L0X_FP97TOFP1616(temp16); } - enable_zero_value = 1; break; @@ -1151,7 +1079,6 @@ } if (status == VL53L0X_ERROR_NONE) { - if (enable_zero_value == 1) { if (temp_fix1616 == 0) { @@ -1164,14 +1091,10 @@ CurrentParameters.LimitChecksValue[limit_check_id] = temp_fix1616; CurrentParameters.LimitChecksEnable[limit_check_id] = 1; } - } else { - *p_limit_check_value = temp_fix1616; - } + } else { *p_limit_check_value = temp_fix1616; } } - return status; - } VL53L0X_Error VL53L0X::VL53L0X_get_limit_check_enable( uint16_t limit_check_id, @@ -1179,8 +1102,6 @@ { VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t temp8; - - if (limit_check_id >= VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS) { status = VL53L0X_ERROR_INVALID_PARAMS; *p_limit_check_enable = 0; @@ -1189,7 +1110,6 @@ *p_limit_check_enable = temp8; } - return status; } @@ -1197,8 +1117,6 @@ { VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t data; - - status = VL53L0X_read_byte( VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, &data); if (status == VL53L0X_ERROR_NONE) { Data.SequenceConfig = data; @@ -1212,7 +1130,6 @@ CurrentParameters.WrapAroundCheckEnable = *p_wrap_around_check_enable; } - return status; } @@ -1221,7 +1138,6 @@ { VL53L0X_Error Status = VL53L0X_ERROR_NONE; *p_sequence_step_enabled = 0; - switch (sequence_step_id) { case VL53L0X_SEQUENCESTEP_TCC: *p_sequence_step_enabled = (sequence_config & 0x10) >> 4; @@ -1241,8 +1157,6 @@ default: Status = VL53L0X_ERROR_INVALID_PARAMS; } - - return Status; } @@ -1250,7 +1164,6 @@ { VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t sequence_config = 0; - status = VL53L0X_read_byte( VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, &sequence_config); @@ -1274,17 +1187,11 @@ status = sequence_step_enabled(VL53L0X_SEQUENCESTEP_FINAL_RANGE, sequence_config, &p_scheduler_sequence_steps->FinalRangeOn); } - - return status; } uint8_t VL53L0X::VL53L0X_decode_vcsel_period(uint8_t vcsel_period_reg) -{ /*! - * Converts the encoded VCSEL period register value into the real - * period in PLL clocks - */ - +{ /*! Converts the encoded VCSEL period register value into the real period in PLL clocks */ uint8_t vcsel_period_pclks = 0; vcsel_period_pclks = (vcsel_period_reg + 1) << 1; @@ -1293,10 +1200,7 @@ } uint8_t VL53L0X::lv53l0x_encode_vcsel_period(uint8_t vcsel_period_pclks) -{ /*! - * Converts the encoded VCSEL period register value into the real period - * in PLL clocks - */ +{ /*! Converts the encoded VCSEL period register value into the real period in PLL clocks */ uint8_t vcsel_period_reg = 0; @@ -1336,9 +1240,7 @@ /* Apply specific settings for the requested clock period */ - if (status != VL53L0X_ERROR_NONE) { - return status; - } + if (status != VL53L0X_ERROR_NONE) { return status; } if (vcsel_period_type == VL53L0X_VCSEL_PERIOD_PRE_RANGE) { @@ -1369,52 +1271,35 @@ 0x08); } } else if (vcsel_period_type == VL53L0X_VCSEL_PERIOD_FINAL_RANGE) { - if (vcsel_pulse_period_pclk == 8) { - status = VL53L0X_write_byte(VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,0x10); status = VL53L0X_write_byte(VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,0x08); - status |= VL53L0X_write_byte(VL53L0X_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x02); status |= VL53L0X_write_byte(VL53L0X_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x0C); - status |= VL53L0X_write_byte( 0xff, 0x01); status |= VL53L0X_write_byte(VL53L0X_REG_ALGO_PHASECAL_LIM,0x30); status |= VL53L0X_write_byte( 0xff, 0x00); } else if (vcsel_pulse_period_pclk == 10) { - status = VL53L0X_write_byte(VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,0x28); status = VL53L0X_write_byte(VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,0x08); - status |= VL53L0X_write_byte(VL53L0X_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x03); status |= VL53L0X_write_byte(VL53L0X_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x09); - status |= VL53L0X_write_byte( 0xff, 0x01); status |= VL53L0X_write_byte(VL53L0X_REG_ALGO_PHASECAL_LIM,0x20); status |= VL53L0X_write_byte( 0xff, 0x00); } else if (vcsel_pulse_period_pclk == 12) { - - status = VL53L0X_write_byte(VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH, - 0x38); - status = VL53L0X_write_byte(VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW, - 0x08); - + status = VL53L0X_write_byte(VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH, 0x38); + status = VL53L0X_write_byte(VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW, 0x08); status |= VL53L0X_write_byte(VL53L0X_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x03); status |= VL53L0X_write_byte(VL53L0X_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x08); - status |= VL53L0X_write_byte( 0xff, 0x01); - status |= VL53L0X_write_byte(VL53L0X_REG_ALGO_PHASECAL_LIM, - 0x20); + status |= VL53L0X_write_byte(VL53L0X_REG_ALGO_PHASECAL_LIM,0x20); status |= VL53L0X_write_byte( 0xff, 0x00); } else if (vcsel_pulse_period_pclk == 14) { - - status = VL53L0X_write_byte(VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH, - 0x048); + status = VL53L0X_write_byte(VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,0x048); status = VL53L0X_write_byte(VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,0x08); - status |= VL53L0X_write_byte(VL53L0X_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x03); status |= VL53L0X_write_byte(VL53L0X_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x07); - status |= VL53L0X_write_byte( 0xff, 0x01); status |= VL53L0X_write_byte(VL53L0X_REG_ALGO_PHASECAL_LIM,0x20); status |= VL53L0X_write_byte( 0xff, 0x00); @@ -1424,8 +1309,7 @@ /* Re-calculate and apply timeouts, in macro periods */ if (status == VL53L0X_ERROR_NONE) { - vcsel_period_reg = lv53l0x_encode_vcsel_period((uint8_t) - vcsel_pulse_period_pclk); + vcsel_period_reg = lv53l0x_encode_vcsel_period((uint8_t) vcsel_pulse_period_pclk); /* When the VCSEL period for the pre or final range is changed, * the corresponding timeout must be read from the device using @@ -1481,13 +1365,11 @@ /* Finally, the timing budget must be re-applied */ if (status == VL53L0X_ERROR_NONE) { measurement_timing_budget_us = CurrentParameters.MeasurementTimingBudget_us ; - status = VL53L0X_set_measurement_timing_budget_us(measurement_timing_budget_us); } /* Perform the phase calibration. This is needed after changing on - * vcsel period. - * get_data_enable = 0, restore_config = 1 */ + * vcsel period. get_data_enable = 0, restore_config = 1 */ if (status == VL53L0X_ERROR_NONE) status = VL53L0X_perform_phase_calibration(&phase_cal_int, 0, 1); @@ -1496,16 +1378,13 @@ VL53L0X_Error VL53L0X::VL53L0X_set_vcsel_pulse_period(VL53L0X_VcselPeriod vcsel_period_type, uint8_t vcsel_pulse_period) { VL53L0X_Error status = VL53L0X_ERROR_NONE; - - - status = wrapped_VL53L0X_set_vcsel_pulse_period( vcsel_period_type, - vcsel_pulse_period); - - + + status = wrapped_VL53L0X_set_vcsel_pulse_period( vcsel_period_type, vcsel_pulse_period); + return status; } -VL53L0X_Error VL53L0X::wrapped_VL53L0X_get_vcsel_pulse_period(VL53L0X_VcselPeriod vcsel_period_type, uint8_t *p_vcsel_pulse_period_pclk) +VL53L0X_Error VL53L0X::VL53L0X_get_vcsel_pulse_period(VL53L0X_VcselPeriod vcsel_period_type, uint8_t *p_vcsel_pulse_period_pclk) { VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t vcsel_period_reg; @@ -1523,28 +1402,13 @@ } if (status == VL53L0X_ERROR_NONE) - *p_vcsel_pulse_period_pclk = - VL53L0X_decode_vcsel_period(vcsel_period_reg); - - return status; -} - -VL53L0X_Error VL53L0X::VL53L0X_get_vcsel_pulse_period(VL53L0X_VcselPeriod vcsel_period_type, uint8_t *p_vcsel_pulse_period_pclk) -{ VL53L0X_Error status = VL53L0X_ERROR_NONE; - - - status = wrapped_VL53L0X_get_vcsel_pulse_period( vcsel_period_type, - p_vcsel_pulse_period_pclk); - - + *p_vcsel_pulse_period_pclk = VL53L0X_decode_vcsel_period(vcsel_period_reg); + return status; } uint32_t VL53L0X::VL53L0X_decode_timeout(uint16_t encoded_timeout) -{ /*! - * Decode 16-bit timeout register value - format (LSByte * 2^MSByte) + 1 - */ - +{ /*! Decode 16-bit timeout register value - format (LSByte * 2^MSByte) + 1 */ uint32_t timeout_macro_clks = 0; timeout_macro_clks = ((uint32_t)(encoded_timeout & 0x00FF) @@ -1558,17 +1422,11 @@ uint32_t macro_period_vclks; uint32_t macro_period_ps; - - - /* The above calculation will produce rounding errors, - therefore set fixed value - */ + /* The above calculation will produce rounding errors, therefore set fixed value*/ pll_period_ps = 1655; - macro_period_vclks = 2304; macro_period_ps = (uint32_t)(macro_period_vclks * vcsel_period_pclks * pll_period_ps); - return macro_period_ps; } @@ -1679,7 +1537,7 @@ return status; } -VL53L0X_Error VL53L0X::wrapped_VL53L0X_get_measurement_timing_budget_us(uint32_t *p_measurement_timing_budget_us) +VL53L0X_Error VL53L0X::VL53L0X_get_measurement_timing_budget_us(uint32_t *p_measurement_timing_budget_us) { VL53L0X_Error status = VL53L0X_ERROR_NONE; VL53L0X_SchedulerSequenceSteps_t scheduler_sequence_steps; uint32_t final_range_timeout_us; @@ -1693,18 +1551,13 @@ uint32_t final_range_overhead_us = 550; uint32_t pre_range_timeout_us = 0; - - /* Start and end overhead times always present */ *p_measurement_timing_budget_us = start_overhead_us + end_overhead_us; status = VL53L0X_get_sequence_step_enables( &scheduler_sequence_steps); - if (status != VL53L0X_ERROR_NONE) { - - return status; - } + if (status != VL53L0X_ERROR_NONE) { return status; } if (scheduler_sequence_steps.TccOn || scheduler_sequence_steps.MsrcOn || @@ -1716,18 +1569,15 @@ if (status == VL53L0X_ERROR_NONE) { if (scheduler_sequence_steps.TccOn) { *p_measurement_timing_budget_us += - msrc_dcc_tcc_timeout_us + - tcc_overhead_us; + msrc_dcc_tcc_timeout_us + tcc_overhead_us; } if (scheduler_sequence_steps.DssOn) { *p_measurement_timing_budget_us += - 2 * (msrc_dcc_tcc_timeout_us + - dss_overhead_us); + 2 * (msrc_dcc_tcc_timeout_us + dss_overhead_us); } else if (scheduler_sequence_steps.MsrcOn) { *p_measurement_timing_budget_us += - msrc_dcc_tcc_timeout_us + - msrc_overhead_us; + msrc_dcc_tcc_timeout_us + msrc_overhead_us; } } } @@ -1737,8 +1587,7 @@ status = get_sequence_step_timeout(VL53L0X_SEQUENCESTEP_PRE_RANGE, &pre_range_timeout_us); *p_measurement_timing_budget_us += - pre_range_timeout_us + - pre_range_overhead_us; + pre_range_timeout_us + pre_range_overhead_us; } } @@ -1747,26 +1596,13 @@ status = get_sequence_step_timeout(VL53L0X_SEQUENCESTEP_FINAL_RANGE, &final_range_timeout_us); *p_measurement_timing_budget_us += - (final_range_timeout_us + - final_range_overhead_us); + (final_range_timeout_us + final_range_overhead_us); } } if (status == VL53L0X_ERROR_NONE) { - CurrentParameters.MeasurementTimingBudget_us = *p_measurement_timing_budget_us; - } - - - return status; -} - -VL53L0X_Error VL53L0X::VL53L0X_get_measurement_timing_budget_us(uint32_t *p_measurement_timing_budget_us) -{ VL53L0X_Error status = VL53L0X_ERROR_NONE; - - - status = wrapped_VL53L0X_get_measurement_timing_budget_us(p_measurement_timing_budget_us); - - + CurrentParameters.MeasurementTimingBudget_us = *p_measurement_timing_budget_us;} + return status; } @@ -1774,9 +1610,7 @@ { VL53L0X_Error status = VL53L0X_ERROR_NONE; int i; - - - status = VL53L0X_get_device_mode( &(p_device_parameters->DeviceMode)); + p_device_parameters->DeviceMode = CurrentParameters.DeviceMode; if (status == VL53L0X_ERROR_NONE) status = VL53L0X_get_inter_measurement_period_ms(&(p_device_parameters->InterMeasurementPeriod_ms)); @@ -1830,8 +1664,6 @@ { VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t temp8; - - temp8 = CurrentParameters.LimitChecksEnable[limit_check_id]; if (temp8 == 0) { /* disabled write only internal value */ @@ -1840,27 +1672,20 @@ switch (limit_check_id) { - case VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE: - /* internal computation: */ + case VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE:/* internal computation: */ CurrentParameters.LimitChecksValue[VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE] = limit_check_value; break; case VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE: - status = VL53L0X_write_word(VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT, VL53L0X_FP1616TOFP97(limit_check_value)); - break; - case VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP: - - /* internal computation: */ + case VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP:/* internal computation: */ CurrentParameters.LimitChecksValue[VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP] = limit_check_value; break; - case VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD: - - /* internal computation: */ + case VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD:/* internal computation: */ CurrentParameters.LimitChecksValue[VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD] = limit_check_value; break; @@ -2554,7 +2379,7 @@ /* Get Current DeviceMode */ - VL53L0X_get_device_mode( &device_mode); + device_mode = CurrentParameters.DeviceMode; status = VL53L0X_write_byte( 0x80, 0x01); status = VL53L0X_write_byte( 0xFF, 0x01); @@ -2626,7 +2451,7 @@ VL53L0X_DeviceModes device_mode; /* Get Current DeviceMode */ - status = VL53L0X_get_device_mode( &device_mode); + device_mode = CurrentParameters.DeviceMode; /* Start immediately to run a single ranging measurement in case of * single ranging or single histogram */ @@ -3521,7 +3346,7 @@ /* This function will do a complete single ranging * Here we fix the mode! */ - status = VL53L0X_set_device_mode( VL53L0X_DEVICEMODE_SINGLE_RANGING); + CurrentParameters.DeviceMode = VL53L0X_DEVICEMODE_SINGLE_RANGING; if (status == VL53L0X_ERROR_NONE) { status = VL53L0X_perform_single_measurement(); } @@ -4157,8 +3982,7 @@ } final_range_timing_budget_us = - measurement_timing_budget_us - - (start_overhead_us + end_overhead_us); + measurement_timing_budget_us - (start_overhead_us + end_overhead_us); status = VL53L0X_get_sequence_step_enables( &scheduler_sequence_steps);