Condensed Version of Public VL53L0X
Diff: VL53L0X.cpp
- Revision:
- 5:b95f6951f7d5
- Parent:
- 3:e9269ff624ed
- Child:
- 6:1976f4afed97
--- a/VL53L0X.cpp Mon Dec 18 08:27:21 2017 +0000 +++ b/VL53L0X.cpp Sat Mar 23 21:28:30 2019 +0000 @@ -39,53 +39,20 @@ #include <stdlib.h> #include "VL53L0X.h" - -//#include "VL53L0X_api_core.h" -//#include "VL53L0X_api_calibration.h" -//#include "VL53L0X_api_strings.h" -#include "VL53L0X_interrupt_threshold_settings.h" #include "VL53L0X_tuning.h" -#include "VL53L0X_types.h" - - -/****************** define for i2c configuration *******************************/ - -#define TEMP_BUF_SIZE 64 - -/** Maximum buffer size to be used in i2c */ -#define VL53L0X_MAX_I2C_XFER_SIZE 64 /* Maximum buffer size to be used in i2c */ -#define VL53L0X_I2C_USER_VAR /* none but could be for a flag var to get/pass to mutex interruptible return flags and try again */ - - -#define LOG_FUNCTION_START(fmt, ...) \ - _LOG_FUNCTION_START(TRACE_MODULE_API, fmt, ##__VA_ARGS__) -#define LOG_FUNCTION_END(status, ...) \ - _LOG_FUNCTION_END(TRACE_MODULE_API, status, ##__VA_ARGS__) -#define LOG_FUNCTION_END_FMT(status, fmt, ...) \ - _LOG_FUNCTION_END_FMT(TRACE_MODULE_API, status, fmt, ##__VA_ARGS__) - -#ifdef VL53L0X_LOG_ENABLE -#define trace_print(level, ...) trace_print_module_function(TRACE_MODULE_API, \ - level, TRACE_FUNCTION_NONE, ##__VA_ARGS__) -#endif #define REF_ARRAY_SPAD_0 0 #define REF_ARRAY_SPAD_5 5 #define REF_ARRAY_SPAD_10 10 uint32_t refArrayQuadrants[4] = {REF_ARRAY_SPAD_10, REF_ARRAY_SPAD_5, - REF_ARRAY_SPAD_0, REF_ARRAY_SPAD_5 - }; - - - + REF_ARRAY_SPAD_0, REF_ARRAY_SPAD_5 }; VL53L0X_Error VL53L0X::VL53L0X_device_read_strobe(VL53L0X_DEV dev) { VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t strobe; uint32_t loop_nb; - LOG_FUNCTION_START(""); status |= VL53L0X_write_byte(dev, 0x83, 0x00); @@ -109,7 +76,6 @@ status |= VL53L0X_write_byte(dev, 0x83, 0x01); - LOG_FUNCTION_END(status); return status; } @@ -135,9 +101,7 @@ FixPoint1616_t signal_rate_meas_fixed400_mm_fix = 0; uint8_t nvm_ref_good_spad_map[VL53L0X_REF_SPAD_BUFFER_SIZE]; int i; - - - LOG_FUNCTION_START(""); + read_data_from_device_done = VL53L0X_GETDEVICESPECIFICPARAMETER(dev, ReadDataFromDeviceDone); @@ -320,7 +284,7 @@ ReferenceSpadType, reference_spad_type); for (i = 0; i < VL53L0X_REF_SPAD_BUFFER_SIZE; i++) { - dev->Data.SpadData.RefGoodSpadMap[i] = + dev->SpadData.RefGoodSpadMap[i] = nvm_ref_good_spad_map[i]; } } @@ -335,7 +299,7 @@ product_id_tmp = VL53L0X_GETDEVICESPECIFICPARAMETER(dev, ProductId); - VL53L0X_COPYSTRING(product_id_tmp, product_id); + strcpy(product_id_tmp, product_id); } @@ -374,7 +338,7 @@ byte); } - LOG_FUNCTION_END(status); + return status; } @@ -414,12 +378,12 @@ int32_t *p_offset_calibration_data_micro_meter) { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); + status = wrapped_VL53L0X_get_offset_calibration_data_micro_meter(dev, p_offset_calibration_data_micro_meter); - LOG_FUNCTION_END(status); + return status; } @@ -432,7 +396,7 @@ int16_t c_offset_range = 4096; uint32_t encoded_offset_val; - LOG_FUNCTION_START(""); + if (offset_calibration_data_micro_meter > c_max_offset_micro_meter) { offset_calibration_data_micro_meter = c_max_offset_micro_meter; @@ -459,7 +423,7 @@ VL53L0X_REG_ALGO_PART_TO_PART_RANGE_OFFSET_MM, encoded_offset_val); - LOG_FUNCTION_END(status); + return status; } @@ -467,12 +431,12 @@ int32_t offset_calibration_data_micro_meter) { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); + status = wrapped_VL53L0X_set_offset_calibration_data_micro_meter(dev, offset_calibration_data_micro_meter); - LOG_FUNCTION_END(status); + return status; } @@ -520,11 +484,11 @@ VL53L0X_DeviceModes *p_device_mode) { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); + VL53L0X_GETPARAMETERFIELD(dev, DeviceMode, *p_device_mode); - LOG_FUNCTION_END(status); + return status; } @@ -535,7 +499,7 @@ uint16_t osc_calibrate_val; uint32_t im_period_milli_seconds; - LOG_FUNCTION_START(""); + status = VL53L0X_read_word(dev, VL53L0X_REG_OSC_CALIBRATE_VAL, &osc_calibrate_val); @@ -556,7 +520,7 @@ *p_inter_measurement_period_milli_seconds); } - LOG_FUNCTION_END(status); + return status; } @@ -567,7 +531,7 @@ uint16_t value; FixPoint1616_t temp_fix1616; - LOG_FUNCTION_START(""); + status = VL53L0X_read_word(dev, VL53L0X_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MCPS, (uint16_t *)&value); @@ -589,7 +553,7 @@ } } - LOG_FUNCTION_END(status); + return status; } @@ -601,7 +565,7 @@ uint16_t temp16; FixPoint1616_t temp_fix1616; - LOG_FUNCTION_START(""); + switch (limit_check_id) { @@ -681,7 +645,7 @@ } } - LOG_FUNCTION_END(status); + return status; } @@ -692,7 +656,7 @@ VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t temp8; - LOG_FUNCTION_START(""); + if (limit_check_id >= VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS) { status = VL53L0X_ERROR_INVALID_PARAMS; @@ -703,7 +667,7 @@ *p_limit_check_enable = temp8; } - LOG_FUNCTION_END(status); + return status; } @@ -713,7 +677,7 @@ VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t data; - LOG_FUNCTION_START(""); + status = VL53L0X_read_byte(dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, &data); if (status == VL53L0X_ERROR_NONE) { @@ -729,7 +693,7 @@ *p_wrap_around_check_enable); } - LOG_FUNCTION_END(status); + return status; } @@ -739,7 +703,7 @@ { VL53L0X_Error Status = VL53L0X_ERROR_NONE; *p_sequence_step_enabled = 0; - LOG_FUNCTION_START(""); + switch (sequence_step_id) { case VL53L0X_SEQUENCESTEP_TCC: @@ -761,7 +725,7 @@ Status = VL53L0X_ERROR_INVALID_PARAMS; } - LOG_FUNCTION_END(status); + return Status; } @@ -770,7 +734,7 @@ { VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t sequence_config = 0; - LOG_FUNCTION_START(""); + status = VL53L0X_read_byte(dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, &sequence_config); @@ -801,7 +765,7 @@ &p_scheduler_sequence_steps->FinalRangeOn); } - LOG_FUNCTION_END(status); + return status; } @@ -1088,12 +1052,12 @@ VL53L0X_VcselPeriod vcsel_period_type, uint8_t vcsel_pulse_period) { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); + status = wrapped_VL53L0X_set_vcsel_pulse_period(dev, vcsel_period_type, vcsel_pulse_period); - LOG_FUNCTION_END(status); + return status; } @@ -1129,12 +1093,12 @@ VL53L0X_VcselPeriod vcsel_period_type, uint8_t *p_vcsel_pulse_period_pclk) { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); + status = wrapped_VL53L0X_get_vcsel_pulse_period(dev, vcsel_period_type, p_vcsel_pulse_period_pclk); - LOG_FUNCTION_END(status); + return status; } @@ -1158,7 +1122,7 @@ uint32_t macro_period_vclks; uint32_t macro_period_ps; - LOG_FUNCTION_START(""); + /* The above calculation will produce rounding errors, therefore set fixed value @@ -1168,8 +1132,6 @@ macro_period_vclks = 2304; macro_period_ps = (uint32_t)(macro_period_vclks * vcsel_period_pclks * pll_period_ps); - - LOG_FUNCTION_END(""); return macro_period_ps; } @@ -1315,7 +1277,7 @@ uint32_t final_range_overhead_micro_seconds = 550; uint32_t pre_range_timeout_micro_seconds = 0; - LOG_FUNCTION_START(""); + /* Start and end overhead times always present */ *p_measurement_timing_budget_micro_seconds @@ -1324,7 +1286,7 @@ status = VL53L0X_get_sequence_step_enables(dev, &scheduler_sequence_steps); if (status != VL53L0X_ERROR_NONE) { - LOG_FUNCTION_END(status); + return status; } @@ -1384,7 +1346,7 @@ *p_measurement_timing_budget_micro_seconds); } - LOG_FUNCTION_END(status); + return status; } @@ -1392,12 +1354,12 @@ uint32_t *p_measurement_timing_budget_micro_seconds) { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); + status = wrapped_VL53L0X_get_measurement_timing_budget_micro_seconds(dev, p_measurement_timing_budget_micro_seconds); - LOG_FUNCTION_END(status); + return status; } @@ -1407,7 +1369,7 @@ VL53L0X_Error status = VL53L0X_ERROR_NONE; int i; - LOG_FUNCTION_START(""); + status = VL53L0X_get_device_mode(dev, &(p_device_parameters->DeviceMode)); @@ -1462,7 +1424,7 @@ &(p_device_parameters->MeasurementTimingBudgetMicroSeconds)); } - LOG_FUNCTION_END(status); + return status; } @@ -1472,7 +1434,7 @@ VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t temp8; - LOG_FUNCTION_START(""); + VL53L0X_GETARRAYPARAMETERFIELD(dev, LimitChecksEnable, limit_check_id, temp8); @@ -1539,7 +1501,7 @@ } } - LOG_FUNCTION_END(status); + return status; } @@ -1550,7 +1512,7 @@ int i; uint8_t StopVariable; - LOG_FUNCTION_START(""); + /* by default the I2C is running at 1V8 if you want to change it you * need to include this define at compilation level. */ @@ -1684,7 +1646,7 @@ } - LOG_FUNCTION_END(status); + return status; } @@ -1696,7 +1658,7 @@ uint8_t module_id_int; char *product_id_tmp; - LOG_FUNCTION_START(""); + status = VL53L0X_get_info_from_device(dev, 2); @@ -1705,16 +1667,16 @@ if (module_id_int == 0) { *revision = 0; - VL53L0X_COPYSTRING(p_VL53L0X_device_info->ProductId, ""); + strcpy(p_VL53L0X_device_info->ProductId, ""); } else { *revision = VL53L0X_GETDEVICESPECIFICPARAMETER(dev, Revision); product_id_tmp = VL53L0X_GETDEVICESPECIFICPARAMETER(dev, ProductId); - VL53L0X_COPYSTRING(p_VL53L0X_device_info->ProductId, product_id_tmp); + strcpy(p_VL53L0X_device_info->ProductId, product_id_tmp); } } - LOG_FUNCTION_END(status); + return status; } @@ -1729,20 +1691,20 @@ if (status == VL53L0X_ERROR_NONE) { if (revision == 0) { - VL53L0X_COPYSTRING(p_VL53L0X_device_info->Name, + strcpy(p_VL53L0X_device_info->Name, VL53L0X_STRING_DEVICE_INFO_NAME_TS0); } else if ((revision <= 34) && (revision != 32)) { - VL53L0X_COPYSTRING(p_VL53L0X_device_info->Name, + strcpy(p_VL53L0X_device_info->Name, VL53L0X_STRING_DEVICE_INFO_NAME_TS1); } else if (revision < 39) { - VL53L0X_COPYSTRING(p_VL53L0X_device_info->Name, + strcpy(p_VL53L0X_device_info->Name, VL53L0X_STRING_DEVICE_INFO_NAME_TS2); } else { - VL53L0X_COPYSTRING(p_VL53L0X_device_info->Name, + strcpy(p_VL53L0X_device_info->Name, VL53L0X_STRING_DEVICE_INFO_NAME_ES1); } - VL53L0X_COPYSTRING(p_VL53L0X_device_info->Type, + strcpy(p_VL53L0X_device_info->Type, VL53L0X_STRING_DEVICE_INFO_TYPE); } @@ -1768,11 +1730,9 @@ VL53L0X_DeviceInfo_t *p_VL53L0X_device_info) { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); status = wrapped_VL53L0X_get_device_info(dev, p_VL53L0X_device_info); - LOG_FUNCTION_END(status); return status; } @@ -1781,7 +1741,7 @@ { VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t byte; - LOG_FUNCTION_START(""); + status = VL53L0X_read_byte(dev, VL53L0X_REG_RESULT_INTERRUPT_STATUS, &byte); *p_interrupt_mask_status = byte & 0x07; @@ -1790,7 +1750,7 @@ status = VL53L0X_ERROR_RANGE_ERROR; } - LOG_FUNCTION_END(status); + return status; } @@ -1801,7 +1761,7 @@ uint8_t sys_range_status_register; uint8_t interrupt_config; uint32_t interrupt_mask; - LOG_FUNCTION_START(""); + interrupt_config = VL53L0X_GETDEVICESPECIFICPARAMETER(dev, Pin0GpioFunctionality); @@ -1827,16 +1787,7 @@ } } - LOG_FUNCTION_END(status); - return status; -} - -VL53L0X_Error VL53L0X::VL53L0X_polling_delay(VL53L0X_DEV dev) -{ - VL53L0X_Error status = VL53L0X_ERROR_NONE; - - // do nothing - VL53L0X_OsDelay(); + return status; } @@ -1846,31 +1797,20 @@ uint8_t new_data_ready = 0; uint32_t loop_nb; - LOG_FUNCTION_START(""); - loop_nb = 0; - - do { + + status = VL53L0X_get_measurement_data_ready(dev, &new_data_ready); + + while ( (status==0) && (new_data_ready != 1) && + (loop_nb < VL53L0X_DEFAULT_MAX_LOOP) ) + { + VL53L0X_polling_delay(dev); status = VL53L0X_get_measurement_data_ready(dev, &new_data_ready); - if (status != 0) { - break; /* the error is set */ - } - - if (new_data_ready == 1) { - break; /* done note that status == 0 */ - } - - loop_nb++; - if (loop_nb >= VL53L0X_DEFAULT_MAX_LOOP) { - status = VL53L0X_ERROR_TIME_OUT; - break; - } - - VL53L0X_polling_delay(dev); - } while (1); - - LOG_FUNCTION_END(status); - + loop_nb++; + } // while ; + + if (loop_nb >= VL53L0X_DEFAULT_MAX_LOOP) status = VL53L0X_ERROR_TIME_OUT; + return status; } @@ -1880,7 +1820,7 @@ VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t loop_count; uint8_t byte; - LOG_FUNCTION_START(""); + /* clear bit 0 range interrupt, bit 1 error interrupt */ loop_count = 0; @@ -1901,7 +1841,7 @@ status = VL53L0X_ERROR_INTERRUPT_NOT_CLEARED; } - LOG_FUNCTION_END(status); + return status; } @@ -2286,8 +2226,6 @@ { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START("%d", (int)DeviceMode); - switch (device_mode) { case VL53L0X_DEVICEMODE_SINGLE_RANGING: case VL53L0X_DEVICEMODE_CONTINUOUS_RANGING: @@ -2302,7 +2240,7 @@ status = VL53L0X_ERROR_MODE_NOT_SUPPORTED; } - LOG_FUNCTION_END(status); + return status; } @@ -2312,9 +2250,9 @@ { VL53L0X_Error status = VL53L0X_ERROR_NONE; uint16_t threshold16; - LOG_FUNCTION_START(""); - - /* no dependency on DeviceMode for Ewok */ + + + /* no dependency on DeviceMode for FlightSense */ /* Need to divide by 2 because the FW will apply a x2 */ threshold16 = (uint16_t)((threshold_low >> 17) & 0x00fff); status = VL53L0X_write_word(dev, VL53L0X_REG_SYSTEM_THRESH_LOW, threshold16); @@ -2326,7 +2264,7 @@ threshold16); } - LOG_FUNCTION_END(status); + return status; } @@ -2336,9 +2274,9 @@ { VL53L0X_Error status = VL53L0X_ERROR_NONE; uint16_t threshold16; - LOG_FUNCTION_START(""); - - /* no dependency on DeviceMode for Ewok */ + + + /* no dependency on DeviceMode for FlightSense */ status = VL53L0X_read_word(dev, VL53L0X_REG_SYSTEM_THRESH_LOW, &threshold16); /* Need to multiply by 2 because the FW will apply a x2 */ @@ -2352,7 +2290,7 @@ (FixPoint1616_t)((0x00fff & threshold16) << 17); } - LOG_FUNCTION_END(status); + return status; } @@ -2370,7 +2308,7 @@ uint8_t local_buffer[4]; /* max */ uint16_t temp16; - LOG_FUNCTION_START(""); + index = 0; @@ -2438,7 +2376,7 @@ } } - LOG_FUNCTION_END(status); + return status; } @@ -2494,7 +2432,7 @@ uint8_t byte; uint8_t start_stop_byte = VL53L0X_REG_SYSRANGE_MODE_START_STOP; uint32_t loop_nb; - LOG_FUNCTION_START(""); + /* Get Current DeviceMode */ VL53L0X_get_device_mode(dev, &device_mode); @@ -2569,7 +2507,7 @@ } - LOG_FUNCTION_END(status); + return status; } @@ -2579,7 +2517,7 @@ VL53L0X_Error status = VL53L0X_ERROR_NONE; VL53L0X_DeviceModes device_mode; - LOG_FUNCTION_START(""); + /* Get Current DeviceMode */ status = VL53L0X_get_device_mode(dev, &device_mode); @@ -2604,7 +2542,7 @@ } - LOG_FUNCTION_END(status); + return status; } @@ -2613,12 +2551,12 @@ { VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t temp8; - LOG_FUNCTION_START(""); + VL53L0X_GETPARAMETERFIELD(dev, XTalkCompensationEnable, temp8); *p_x_talk_compensation_enable = temp8; - LOG_FUNCTION_END(status); + return status; } @@ -2665,7 +2603,7 @@ VL53L0X_Error status = VL53L0X_ERROR_NONE; FixPoint1616_t total_xtalk_mega_cps; - LOG_FUNCTION_START(""); + *p_total_signal_rate_mcps = p_ranging_measurement_data->SignalRateRtnMegaCps; @@ -2766,7 +2704,7 @@ VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); + dmax_cal_range_mm = PALDevDataGet(dev, DmaxCalRangeMilliMeter); @@ -2921,7 +2859,7 @@ *pd_max_mm = dmax_ambient; } - LOG_FUNCTION_END(status); + return status; } @@ -2986,7 +2924,7 @@ * Estimates the range sigma */ - LOG_FUNCTION_START(""); + VL53L0X_GETPARAMETERFIELD(dev, XTalkCompensationRateMegaCps, x_talk_comp_rate_mcps); @@ -3070,7 +3008,7 @@ } if (status != VL53L0X_ERROR_NONE) { - LOG_FUNCTION_END(status); + return status; } @@ -3249,7 +3187,7 @@ p_dmax_mm); } - LOG_FUNCTION_END(status); + return status; } @@ -3280,7 +3218,7 @@ uint32_t dmax_mm = 0; FixPoint1616_t last_signal_ref_mcps; - LOG_FUNCTION_START(""); + /* @@ -3494,7 +3432,7 @@ temp8); } - LOG_FUNCTION_END(status); + return status; } @@ -3517,7 +3455,7 @@ uint8_t localBuffer[12]; VL53L0X_RangingMeasurementData_t last_range_data_buffer; - LOG_FUNCTION_START(""); + /* * use multi read even if some registers are not useful, result will @@ -3651,7 +3589,7 @@ PALDevDataSet(dev, LastRangeMeasure, last_range_data_buffer); } - LOG_FUNCTION_END(status); + return status; } @@ -3660,7 +3598,7 @@ { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); + /* This function will do a complete single ranging * Here we fix the mode! */ @@ -3679,7 +3617,7 @@ status = VL53L0X_clear_interrupt_mask(dev, 0); } - LOG_FUNCTION_END(status); + return status; } @@ -3793,7 +3731,7 @@ * represent spads. */ for (index = 0; index < spad_array_size; index++) { - dev->Data.SpadData.RefSpadEnables[index] = 0; + dev->SpadData.RefSpadEnables[index] = 0; } @@ -3837,8 +3775,8 @@ need_apt_spads = 0; status = enable_ref_spads(dev, need_apt_spads, - dev->Data.SpadData.RefGoodSpadMap, - dev->Data.SpadData.RefSpadEnables, + dev->SpadData.RefGoodSpadMap, + dev->SpadData.RefSpadEnables, spad_array_size, start_select, current_spad_index, @@ -3857,7 +3795,7 @@ * switch to APERTURE SPADs */ for (index = 0; index < spad_array_size; index++) { - dev->Data.SpadData.RefSpadEnables[index] = 0; + dev->SpadData.RefSpadEnables[index] = 0; } @@ -3871,8 +3809,8 @@ status = enable_ref_spads(dev, need_apt_spads, - dev->Data.SpadData.RefGoodSpadMap, - dev->Data.SpadData.RefSpadEnables, + dev->SpadData.RefGoodSpadMap, + dev->SpadData.RefSpadEnables, spad_array_size, start_select, current_spad_index, @@ -3911,7 +3849,7 @@ is_aperture_spads_int = need_apt_spads; ref_spad_count_int = minimum_spad_count; - memcpy(last_spad_array, dev->Data.SpadData.RefSpadEnables, + memcpy(last_spad_array, dev->SpadData.RefSpadEnables, spad_array_size); last_signal_rate_diff = abs(peak_signal_rate_ref - target_ref_rate); @@ -3919,7 +3857,7 @@ while (!complete) { get_next_good_spad( - dev->Data.SpadData.RefGoodSpadMap, + dev->SpadData.RefGoodSpadMap, spad_array_size, current_spad_index, &next_good_spad); @@ -3944,7 +3882,7 @@ current_spad_index = next_good_spad; status = enable_spad_bit( - dev->Data.SpadData.RefSpadEnables, + dev->SpadData.RefSpadEnables, spad_array_size, current_spad_index); if (status == VL53L0X_ERROR_NONE) { @@ -3952,7 +3890,7 @@ /* Proceed to apply the additional spad and * perform measurement. */ status = set_ref_spad_map(dev, - dev->Data.SpadData.RefSpadEnables); + dev->SpadData.RefSpadEnables); } if (status != VL53L0X_ERROR_NONE) { @@ -3979,7 +3917,7 @@ status = set_ref_spad_map(dev, last_spad_array); memcpy( - dev->Data.SpadData.RefSpadEnables, + dev->SpadData.RefSpadEnables, last_spad_array, spad_array_size); (ref_spad_count_int)--; @@ -3989,7 +3927,7 @@ /* Continue to add spads */ last_signal_rate_diff = signal_rate_diff; memcpy(last_spad_array, - dev->Data.SpadData.RefSpadEnables, + dev->SpadData.RefSpadEnables, spad_array_size); } @@ -4051,7 +3989,7 @@ } for (index = 0; index < spad_array_size; index++) { - dev->Data.SpadData.RefSpadEnables[index] = 0; + dev->SpadData.RefSpadEnables[index] = 0; } if (is_aperture_spads) { @@ -4063,8 +4001,8 @@ } status = enable_ref_spads(dev, is_aperture_spads, - dev->Data.SpadData.RefGoodSpadMap, - dev->Data.SpadData.RefSpadEnables, + dev->SpadData.RefGoodSpadMap, + dev->SpadData.RefSpadEnables, spad_array_size, start_select, current_spad_index, @@ -4085,11 +4023,11 @@ VL53L0X_Error VL53L0X::VL53L0X_wait_device_booted(VL53L0X_DEV dev) { VL53L0X_Error status = VL53L0X_ERROR_NOT_IMPLEMENTED; - LOG_FUNCTION_START(""); + /* not implemented on VL53L0X */ - LOG_FUNCTION_END(status); + return status; } @@ -4097,12 +4035,12 @@ uint8_t *p_phase_cal) { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); + status = VL53L0X_perform_ref_calibration(dev, p_vhv_settings, p_phase_cal, 1); - LOG_FUNCTION_END(status); + return status; } @@ -4110,12 +4048,12 @@ uint32_t *ref_spad_count, uint8_t *is_aperture_spads) { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); + status = wrapped_VL53L0X_perform_ref_spad_management(dev, ref_spad_count, is_aperture_spads); - LOG_FUNCTION_END(status); + return status; } @@ -4124,12 +4062,12 @@ VL53L0X_Error VL53L0X::VL53L0X_set_device_address(VL53L0X_DEV dev, uint8_t device_address) { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); + status = VL53L0X_write_byte(dev, VL53L0X_REG_I2C_SLAVE_DEVICE_ADDRESS, device_address / 2); - LOG_FUNCTION_END(status); + return status; } @@ -4140,7 +4078,7 @@ VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t data; - LOG_FUNCTION_START(""); + if (pin != 0) { status = VL53L0X_ERROR_GPIO_NOT_EXISTING; @@ -4228,14 +4166,14 @@ } } } - LOG_FUNCTION_END(status); + return status; } VL53L0X_Error VL53L0X::VL53L0X_get_fraction_enable(VL53L0X_DEV dev, uint8_t *p_enabled) { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); + status = VL53L0X_read_byte(dev, VL53L0X_REG_SYSTEM_RANGE_CONFIG, p_enabled); @@ -4243,7 +4181,7 @@ *p_enabled = (*p_enabled & 1); } - LOG_FUNCTION_END(status); + return status; } @@ -4435,7 +4373,7 @@ uint32_t c_min_timing_budget_micro_seconds = 20000; uint32_t sub_timeout = 0; - LOG_FUNCTION_START(""); + if (measurement_timing_budget_micro_seconds < c_min_timing_budget_micro_seconds) { @@ -4483,7 +4421,7 @@ } if (status != VL53L0X_ERROR_NONE) { - LOG_FUNCTION_END(status); + return status; } @@ -4517,7 +4455,7 @@ } if (status != VL53L0X_ERROR_NONE) { - LOG_FUNCTION_END(status); + return status; } @@ -4563,7 +4501,7 @@ measurement_timing_budget_micro_seconds); } - LOG_FUNCTION_END(status); + return status; } @@ -4572,12 +4510,12 @@ uint32_t measurement_timing_budget_micro_seconds) { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); + status = wrapped_VL53L0X_set_measurement_timing_budget_micro_seconds(dev, measurement_timing_budget_micro_seconds); - LOG_FUNCTION_END(status); + return status; } @@ -4589,7 +4527,7 @@ uint8_t sequence_config = 0; uint8_t sequence_config_new = 0; uint32_t measurement_timing_budget_micro_seconds; - LOG_FUNCTION_START(""); + status = VL53L0X_read_byte(dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, &sequence_config); @@ -4667,7 +4605,7 @@ } } - LOG_FUNCTION_END(status); + return status; } @@ -4681,7 +4619,7 @@ uint8_t limit_check_disable = 0; uint8_t temp8; - LOG_FUNCTION_START(""); + if (limit_check_id >= VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS) { status = VL53L0X_ERROR_INVALID_PARAMS; @@ -4771,7 +4709,7 @@ } } - LOG_FUNCTION_END(status); + return status; } @@ -4790,7 +4728,7 @@ uint8_t vcsel_pulse_period_pclk; uint32_t seq_timeout_micro_secs; - LOG_FUNCTION_START(""); + status = VL53L0X_get_info_from_device(dev, 1); @@ -4955,7 +4893,7 @@ seq_timeout_micro_secs); } - LOG_FUNCTION_END(status); + return status; } @@ -4963,7 +4901,7 @@ VL53L0X_Error VL53L0X::VL53L0X_stop_measurement(VL53L0X_DEV dev) { VL53L0X_Error status = VL53L0X_ERROR_NONE; - LOG_FUNCTION_START(""); + status = VL53L0X_write_byte(dev, VL53L0X_REG_SYSRANGE_START, VL53L0X_REG_SYSRANGE_MODE_SINGLESHOT); @@ -4984,7 +4922,7 @@ status = VL53L0X_check_and_load_interrupt_settings(dev, 0); } - LOG_FUNCTION_END(status); + return status; } @@ -4993,7 +4931,7 @@ { VL53L0X_Error status = VL53L0X_ERROR_NONE; uint8_t byte = 0; - LOG_FUNCTION_START(""); + status = VL53L0X_write_byte(dev, 0xFF, 0x01); @@ -5018,7 +4956,7 @@ status = VL53L0X_write_byte(dev, 0x80, 0x00); } - LOG_FUNCTION_END(status); + return status; } @@ -5271,7 +5209,7 @@ int VL53L0X::range_meas_int_continuous_mode(void (*fptr)(void)) { - int status, clr_status; + int status; status = VL53L0X_stop_measurement(_device); // it is safer to do this while sensor is stopped @@ -5286,10 +5224,8 @@ enable_interrupt_measure_detection_irq(); } - clr_status = clear_interrupt(VL53L0X_REG_RESULT_INTERRUPT_STATUS | VL53L0X_REG_RESULT_RANGE_STATUS); - if (clr_status) { - VL53L0X_ErrLog("VL53L0X_ClearErrorInterrupt fail\r\n"); - } + clear_interrupt(VL53L0X_REG_RESULT_INTERRUPT_STATUS | VL53L0X_REG_RESULT_RANGE_STATUS); + // NB: return value was previously only passed to logging macro, but did not get passed back if (!status) { status = range_start_continuous_mode(); @@ -5301,7 +5237,6 @@ int VL53L0X::start_measurement(OperatingMode operating_mode, void (*fptr)(void)) { int Status = VL53L0X_ERROR_NONE; - int ClrStatus; uint8_t VhvSettings; uint8_t PhaseCal; @@ -5332,10 +5267,8 @@ enable_interrupt_measure_detection_irq(); } - ClrStatus = clear_interrupt(VL53L0X_REG_RESULT_INTERRUPT_STATUS | VL53L0X_REG_RESULT_RANGE_STATUS); - if (ClrStatus) { - VL53L0X_ErrLog("VL53L0X_ClearErrorInterrupt fail\r\n"); - } + clear_interrupt(VL53L0X_REG_RESULT_INTERRUPT_STATUS | VL53L0X_REG_RESULT_RANGE_STATUS); + // NB: return value was previously only passed to logging macro, but did not get passed back if (Status == VL53L0X_ERROR_NONE) { Status = VL53L0X_set_device_mode(_device, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING); // Setup in continuous ranging mode