Skip to content

Commit

Permalink
original files from STSW-IMG007 VL53L1X API 2.3.3, run through dos2un…
Browse files Browse the repository at this point in the history
…ix to ease merge
  • Loading branch information
hb020 committed Jul 1, 2019
1 parent 19445d9 commit 215c70d
Show file tree
Hide file tree
Showing 42 changed files with 131 additions and 59 deletions.
138 changes: 94 additions & 44 deletions vl53l1_api.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ static int32_t BDTable[VL53L1_TUNING_MAX_TUNABLE_KEY] = {
TUNING_SINGLE_TARGET_XTALK_SAMPLE_NUMBER,
TUNING_MIN_AMBIENT_DMAX_VALID,
TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER,
TUNING_XTALK_FULL_ROI_TARGET_DISTANCE_MM
TUNING_XTALK_FULL_ROI_TARGET_DISTANCE_MM,
TUNING_SIMPLE_OFFSET_CALIBRATION_REPEAT
};


#define VL53L1_NVM_POWER_UP_DELAY_US 50
#define VL53L1_NVM_READ_TRIGGER_DELAY_US 5

Expand Down Expand Up @@ -389,8 +391,8 @@ static VL53L1_Error SingleTargetXTalkCalibration(VL53L1_DEV Dev)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;

uint16_t sum_ranging = 0;
uint16_t sum_spads = 0;
uint32_t sum_ranging = 0;
uint32_t sum_spads = 0;
FixPoint1616_t sum_signalRate = 0;
FixPoint1616_t total_count = 0;
uint8_t xtalk_meas = 0;
Expand Down Expand Up @@ -452,10 +454,10 @@ static VL53L1_Error SingleTargetXTalkCalibration(VL53L1_DEV Dev)
if (total_count > 0) {
/* FixPoint1616_t / uint16_t = FixPoint1616_t */
xTalkStoredMeanSignalRate = sum_signalRate / total_count;
xTalkStoredMeanRange = (FixPoint1616_t)((uint32_t)(
sum_ranging << 16) / total_count);
xTalkStoredMeanRtnSpads = (FixPoint1616_t)((uint32_t)(
sum_spads << 16) / total_count);
xTalkStoredMeanRange = (FixPoint1616_t)(sum_ranging << 16);
xTalkStoredMeanRange /= total_count;
xTalkStoredMeanRtnSpads = (FixPoint1616_t)(sum_spads << 16);
xTalkStoredMeanRtnSpads /= total_count;

/* Round Mean Spads to Whole Number.
* Typically the calculated mean SPAD count is a whole number
Expand Down Expand Up @@ -511,7 +513,7 @@ static VL53L1_Error SingleTargetXTalkCalibration(VL53L1_DEV Dev)

pC->algo__crosstalk_compensation_plane_offset_kcps =
(uint32_t)(1000 * ((XTalkCompensationRateMegaCps +
(1<<6)) >> (16-9)));
((uint32_t)1<<6)) >> (16-9)));

Status = VL53L1_SetCalibrationData(Dev, &CalibrationData);
CHECK_ERROR_GO_ENDFUNC;
Expand Down Expand Up @@ -1314,11 +1316,16 @@ VL53L1_Error VL53L1_SetInterMeasurementPeriodMilliSeconds(VL53L1_DEV Dev,
uint32_t InterMeasurementPeriodMilliSeconds)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
uint32_t adjustedIMP;

LOG_FUNCTION_START("");

/* Fix for Ticket 468205 actual measurement period shorter than set */
adjustedIMP = InterMeasurementPeriodMilliSeconds;
adjustedIMP += (adjustedIMP * 64) / 1000;
/* End of fix for Ticket 468205 */
Status = VL53L1_set_inter_measurement_period_ms(Dev,
InterMeasurementPeriodMilliSeconds);
adjustedIMP);

LOG_FUNCTION_END(Status);
return Status;
Expand All @@ -1328,11 +1335,15 @@ VL53L1_Error VL53L1_GetInterMeasurementPeriodMilliSeconds(VL53L1_DEV Dev,
uint32_t *pInterMeasurementPeriodMilliSeconds)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
uint32_t adjustedIMP;

LOG_FUNCTION_START("");

Status = VL53L1_get_inter_measurement_period_ms(Dev,
pInterMeasurementPeriodMilliSeconds);
Status = VL53L1_get_inter_measurement_period_ms(Dev, &adjustedIMP);
/* Fix for Ticket 468205 actual measurement period shorter than set */
adjustedIMP -= (adjustedIMP * 64) / 1000;
*pInterMeasurementPeriodMilliSeconds = adjustedIMP;
/* End of fix for Ticket 468205 */

LOG_FUNCTION_END(Status);
return Status;
Expand Down Expand Up @@ -1720,9 +1731,12 @@ VL53L1_Error VL53L1_GetSequenceStepEnable(VL53L1_DEV Dev,

VL53L1_Error VL53L1_StartMeasurement(VL53L1_DEV Dev)
{
#define TIMED_MODE_TIMING_GUARD_MILLISECONDS 4
VL53L1_Error Status = VL53L1_ERROR_NONE;
uint8_t DeviceMeasurementMode;
VL53L1_State CurrPalState;
VL53L1_Error lStatus;
uint32_t MTBus, IMPms;

LOG_FUNCTION_START("");

Expand All @@ -1746,6 +1760,22 @@ VL53L1_Error VL53L1_StartMeasurement(VL53L1_DEV Dev)

DeviceMeasurementMode = VL53L1DevDataGet(Dev, LLData.measurement_mode);

/* Check timing configuration between timing budget and
* inter measurement period */
if ((Status == VL53L1_ERROR_NONE) &&
(DeviceMeasurementMode == VL53L1_DEVICEMEASUREMENTMODE_TIMED)) {
lStatus = VL53L1_GetMeasurementTimingBudgetMicroSeconds(Dev,
&MTBus);
/* convert timing budget in ms */
MTBus /= 1000;
lStatus = VL53L1_GetInterMeasurementPeriodMilliSeconds(Dev,
&IMPms);
/* trick to get rid of compiler "set but not used" warning */
SUPPRESS_UNUSED_WARNING(lStatus);
if (IMPms < MTBus + TIMED_MODE_TIMING_GUARD_MILLISECONDS)
Status = VL53L1_ERROR_INVALID_PARAMS;
}

if (Status == VL53L1_ERROR_NONE)
Status = VL53L1_init_and_start_range(
Dev,
Expand Down Expand Up @@ -2178,7 +2208,6 @@ VL53L1_Error VL53L1_SetTuningParameter(VL53L1_DEV Dev,
VL53L1_Error Status = VL53L1_ERROR_NONE;

LOG_FUNCTION_START("");

if (TuningParameterId >= 32768)
Status = VL53L1_set_tuning_parm(Dev,
TuningParameterId,
Expand Down Expand Up @@ -2431,12 +2460,14 @@ VL53L1_Error VL53L1_PerformOffsetSimpleCalibration(VL53L1_DEV Dev,
VL53L1_Error Status = VL53L1_ERROR_NONE;
int32_t sum_ranging;
uint8_t offset_meas;
uint8_t Max;
uint8_t total_count;
int16_t Max, UnderMax, OverMax, Repeat;
int32_t total_count, inloopcount;
int32_t IncRounding;
int16_t meanDistance_mm;
int16_t offset;
VL53L1_RangingMeasurementData_t RangingMeasurementData;
VL53L1_LLDriverData_t *pdev;
uint8_t goodmeas;

LOG_FUNCTION_START("");

Expand All @@ -2446,48 +2477,67 @@ VL53L1_Error VL53L1_PerformOffsetSimpleCalibration(VL53L1_DEV Dev,
pdev->customer.mm_config__inner_offset_mm = 0;
pdev->customer.mm_config__outer_offset_mm = 0;

Max = BDTable[VL53L1_TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER];

Status = VL53L1_StartMeasurement(Dev);
Repeat=BDTable[VL53L1_TUNING_SIMPLE_OFFSET_CALIBRATION_REPEAT];
Max=BDTable[VL53L1_TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER];
UnderMax = 1 + (Max / 2);
OverMax = Max + (Max / 2);
sum_ranging = 0;
offset_meas = 0;
total_count = 0;
while ((Status == VL53L1_ERROR_NONE) && (offset_meas < Max)) {
Status = VL53L1_WaitMeasurementDataReady(Dev);
if (Status == VL53L1_ERROR_NONE) {

while ((Repeat > 0) && (Status == VL53L1_ERROR_NONE)) {
Status = VL53L1_StartMeasurement(Dev);
/* Very first ranging completion interrupt must be ignored */
if (Status == VL53L1_ERROR_NONE)
Status = VL53L1_WaitMeasurementDataReady(Dev);
if (Status == VL53L1_ERROR_NONE)
Status = VL53L1_GetRangingMeasurementData(Dev,
&RangingMeasurementData);
}
if (Status == VL53L1_ERROR_NONE) {
if (RangingMeasurementData.RangeStatus ==
VL53L1_RANGESTATUS_RANGE_VALID) {
&RangingMeasurementData);
if (Status == VL53L1_ERROR_NONE)
Status = VL53L1_ClearInterruptAndStartMeasurement(Dev);
/* offset calibration main loop */
inloopcount = 0;
offset_meas = 0;
while ((Status == VL53L1_ERROR_NONE) && (inloopcount < Max) &&
(offset_meas < OverMax)) {
Status = VL53L1_WaitMeasurementDataReady(Dev);
if (Status == VL53L1_ERROR_NONE)
Status = VL53L1_GetRangingMeasurementData(Dev,
&RangingMeasurementData);
goodmeas = (RangingMeasurementData.RangeStatus ==
VL53L1_RANGESTATUS_RANGE_VALID);
if ((Status == VL53L1_ERROR_NONE) && goodmeas) {
sum_ranging = sum_ranging +
RangingMeasurementData.RangeMilliMeter;
total_count++;
inloopcount++;
}
if (Status == VL53L1_ERROR_NONE) {
Status = VL53L1_ClearInterruptAndStartMeasurement(
Dev);
}
offset_meas++;
}
if (Status == VL53L1_ERROR_NONE) {
Status = VL53L1_ClearInterruptAndStartMeasurement(
Dev);
total_count += inloopcount;

/* no enough valid values found */
if (inloopcount < UnderMax) {
Status = VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL;
}
offset_meas++;
}

VL53L1_StopMeasurement(Dev);
VL53L1_StopMeasurement(Dev);

/* no valid values found */
if (total_count == 0) {
Status = VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL;
}
Repeat--;

}
/* check overflow (unlikely if target is near to the device) */
if ((sum_ranging < 0) ||
(sum_ranging > ((int32_t) total_count * 0xffff))) {
Status = VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH;
}

if (Status == VL53L1_ERROR_NONE) {
meanDistance_mm = (int16_t)(sum_ranging / total_count);
if ((Status == VL53L1_ERROR_NONE) && (total_count > 0)) {
IncRounding = total_count / 2;
meanDistance_mm = (int16_t)((sum_ranging + IncRounding)
/ total_count);
offset = (int16_t)CalDistanceMilliMeter - meanDistance_mm;
pdev->customer.algo__part_to_part_range_offset_mm = 0;
pdev->customer.mm_config__inner_offset_mm = offset;
Expand Down Expand Up @@ -2730,11 +2780,11 @@ VL53L1_Error VL53L1_SetThresholdConfig(VL53L1_DEV Dev,
* Apply invert distance gain to thresholds */
g = pdev->gain_cal.standard_ranging_gain_factor;
/* gain is ufix 5.11, convert to 16.16 */
gain = (FixPoint1616_t) (g << 5);
high1616 = (FixPoint1616_t)
(pConfig->Distance.High << 16);
low1616 = (FixPoint1616_t)
(pConfig->Distance.Low << 16);
gain = (FixPoint1616_t) ((uint32_t)g << 5);
high1616 = (FixPoint1616_t) ((uint32_t)
pConfig->Distance.High << 16);
low1616 = (FixPoint1616_t) ((uint32_t)
pConfig->Distance.Low << 16);
/* +32768 to round the results*/
high1616 = (high1616 + 32768) / gain;
low1616 = (low1616 + 32768) / gain;
Expand Down
21 changes: 20 additions & 1 deletion vl53l1_api.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ extern "C"
{
#endif

#if !defined(VL53L1DevDataGet)
#warning "Usage of PALDevDataGet is deprecated define VL53L1DevDataGet instead\
in your vl53l1_platform_user_data.h file"
#define VL53L1DevDataGet(Dev, field) (Dev->Data.field)
#endif

#if !defined(VL53L1DevDataSet)
#warning "Usage of PALDevDataSet is deprecated define VL53L1DevDataSet instead\
in your vl53l1_platform_user_data.h file"
#define VL53L1DevDataSet(Dev, field, data) ((Dev->Data.field) = (data))
#endif

/** @defgroup VL53L1_cut11_group VL53L1 cut1.1 Function Definition
* @brief VL53L1 cut1.1 Function Definition
* @{
Expand Down Expand Up @@ -403,6 +415,9 @@ VL53L1_Error VL53L1_GetMeasurementTimingBudgetMicroSeconds(
*
* @param Dev Device Handle
* @param InterMeasurementPeriodMilliSeconds Inter-Measurement Period in ms.
* this value should be greater than the duration set in
* @a VL53L1_SetMeasurementTimingBudgetMicroSeconds() to ensure smooth ranging
* operation.
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/
Expand Down Expand Up @@ -761,8 +776,12 @@ VL53L1_Error VL53L1_GetSequenceStepEnable(VL53L1_DEV Dev,
* @return VL53L1_ERROR_NONE Success
* @return VL53L1_ERROR_MODE_NOT_SUPPORTED This error occurs when
* PresetMode programmed with @a VL53L1_SetPresetMode
*
* @return VL53L1_ERROR_TIME_OUT Time out on start measurement
* @return VL53L1_ERROR_INVALID_PARAMS This error might occur in timed mode
* when inter measurement period is smaller or too close to the timing budget.
* In such case measurements are not started and user must correct the timings
* passed to @a VL53L1_SetMeasurementTimingBudgetMicroSeconds() and
* @a VL53L1_SetInterMeasurementPeriodMilliSeconds() functions.
* @return "Other error code" See ::VL53L1_Error
*/
VL53L1_Error VL53L1_StartMeasurement(VL53L1_DEV Dev);
Expand Down
Empty file modified vl53l1_api_calibration.c
100644 → 100755
Empty file.
Empty file modified vl53l1_api_calibration.h
100644 → 100755
Empty file.
Empty file modified vl53l1_api_core.c
100644 → 100755
Empty file.
Empty file modified vl53l1_api_core.h
100644 → 100755
Empty file.
Empty file modified vl53l1_api_debug.c
100644 → 100755
Empty file.
Empty file modified vl53l1_api_debug.h
100644 → 100755
Empty file.
Empty file modified vl53l1_api_preset_modes.c
100644 → 100755
Empty file.
Empty file modified vl53l1_api_preset_modes.h
100644 → 100755
Empty file.
Empty file modified vl53l1_api_strings.c
100644 → 100755
Empty file.
Empty file modified vl53l1_api_strings.h
100644 → 100755
Empty file.
Empty file modified vl53l1_core.c
100644 → 100755
Empty file.
Empty file modified vl53l1_core.h
100644 → 100755
Empty file.
Empty file modified vl53l1_core_support.c
100644 → 100755
Empty file.
Empty file modified vl53l1_core_support.h
100644 → 100755
Empty file.
26 changes: 13 additions & 13 deletions vl53l1_def.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ extern "C" {
/** VL53L1 IMPLEMENTATION minor version */
#define VL53L1_IMPLEMENTATION_VER_MINOR 3
/** VL53L1 IMPLEMENTATION sub version */
#define VL53L1_IMPLEMENTATION_VER_SUB 1
#define VL53L1_IMPLEMENTATION_VER_SUB 3
/** VL53L1 IMPLEMENTATION sub version */
#define VL53L1_IMPLEMENTATION_VER_REVISION 1842
#define VL53L1_IMPLEMENTATION_VER_REVISION 1885

/****************************************
* PRIVATE define do not edit
Expand Down Expand Up @@ -588,57 +588,57 @@ typedef struct {
#define VL53L1_FIXPOINT1616TOFIXPOINT44(Value) \
(uint16_t)((Value>>12)&0xFFFF)
#define VL53L1_FIXPOINT44TOFIXPOINT1616(Value) \
(FixPoint1616_t)(Value<<12)
(FixPoint1616_t)((uint32_t)Value<<12)

#define VL53L1_FIXPOINT1616TOFIXPOINT72(Value) \
(uint16_t)((Value>>14)&0xFFFF)
#define VL53L1_FIXPOINT72TOFIXPOINT1616(Value) \
(FixPoint1616_t)(Value<<14)
(FixPoint1616_t)((uint32_t)Value<<14)

#define VL53L1_FIXPOINT1616TOFIXPOINT97(Value) \
(uint16_t)((Value>>9)&0xFFFF)
#define VL53L1_FIXPOINT97TOFIXPOINT1616(Value) \
(FixPoint1616_t)(Value<<9)
(FixPoint1616_t)((uint32_t)Value<<9)

#define VL53L1_FIXPOINT1616TOFIXPOINT88(Value) \
(uint16_t)((Value>>8)&0xFFFF)
#define VL53L1_FIXPOINT88TOFIXPOINT1616(Value) \
(FixPoint1616_t)(Value<<8)
(FixPoint1616_t)((uint32_t)Value<<8)

#define VL53L1_FIXPOINT1616TOFIXPOINT412(Value) \
(uint16_t)((Value>>4)&0xFFFF)
#define VL53L1_FIXPOINT412TOFIXPOINT1616(Value) \
(FixPoint1616_t)(Value<<4)
(FixPoint1616_t)((uint32_t)Value<<4)

#define VL53L1_FIXPOINT1616TOFIXPOINT313(Value) \
(uint16_t)((Value>>3)&0xFFFF)
#define VL53L1_FIXPOINT313TOFIXPOINT1616(Value) \
(FixPoint1616_t)(Value<<3)
(FixPoint1616_t)((uint32_t)Value<<3)

#define VL53L1_FIXPOINT1616TOFIXPOINT08(Value) \
(uint8_t)((Value>>8)&0x00FF)
#define VL53L1_FIXPOINT08TOFIXPOINT1616(Value) \
(FixPoint1616_t)(Value<<8)
(FixPoint1616_t)((uint32_t)Value<<8)

#define VL53L1_FIXPOINT1616TOFIXPOINT53(Value) \
(uint8_t)((Value>>13)&0x00FF)
#define VL53L1_FIXPOINT53TOFIXPOINT1616(Value) \
(FixPoint1616_t)(Value<<13)
(FixPoint1616_t)((uint32_t)Value<<13)

#define VL53L1_FIXPOINT1616TOFIXPOINT102(Value) \
(uint16_t)((Value>>14)&0x0FFF)
#define VL53L1_FIXPOINT102TOFIXPOINT1616(Value) \
(FixPoint1616_t)(Value<<14)
(FixPoint1616_t)((uint32_t)Value<<14)

#define VL53L1_FIXPOINT1616TOFIXPOINT142(Value) \
(uint16_t)((Value>>14)&0xFFFF)
#define VL53L1_FIXPOINT142TOFIXPOINT1616(Value) \
(FixPoint1616_t)(Value<<14)
(FixPoint1616_t)((uint32_t)Value<<14)

#define VL53L1_FIXPOINT1616TOFIXPOINT160(Value) \
(uint16_t)((Value>>16)&0xFFFF)
#define VL53L1_FIXPOINT160TOFIXPOINT1616(Value) \
(FixPoint1616_t)(Value<<16)
(FixPoint1616_t)((uint32_t)Value<<16)

#define VL53L1_MAKEUINT16(lsb, msb) (uint16_t)((((uint16_t)msb)<<8) + \
(uint16_t)lsb)
Expand Down
Empty file modified vl53l1_error_codes.h
100644 → 100755
Empty file.
Empty file modified vl53l1_error_exceptions.h
100644 → 100755
Empty file.
Empty file modified vl53l1_error_strings.c
100644 → 100755
Empty file.
Empty file modified vl53l1_error_strings.h
100644 → 100755
Empty file.
Empty file modified vl53l1_ll_def.h
100644 → 100755
Empty file.
Empty file modified vl53l1_ll_device.h
100644 → 100755
Empty file.
Empty file modified vl53l1_nvm_map.h
100644 → 100755
Empty file.
Empty file modified vl53l1_platform.c
100644 → 100755
Empty file.
Empty file modified vl53l1_platform.h
100644 → 100755
Empty file.
Empty file modified vl53l1_platform_log.h
100644 → 100755
Empty file.
Empty file modified vl53l1_platform_user_config.h
100644 → 100755
Empty file.
Empty file modified vl53l1_platform_user_data.h
100644 → 100755
Empty file.
Empty file modified vl53l1_platform_user_defines.h
100644 → 100755
Empty file.
Loading

0 comments on commit 215c70d

Please sign in to comment.