vl5310x: St api library - initial commit
Signed-off-by: Thomas Klaehn <tkl@blackfinn.de>
This commit is contained in:
commit
d7a741f117
1950
Api/core/inc/vl53l0x_api.h
Normal file
1950
Api/core/inc/vl53l0x_api.h
Normal file
File diff suppressed because it is too large
Load Diff
85
Api/core/inc/vl53l0x_api_calibration.h
Normal file
85
Api/core/inc/vl53l0x_api_calibration.h
Normal file
@ -0,0 +1,85 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2016, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef _VL53L0X_API_CALIBRATION_H_
|
||||
#define _VL53L0X_API_CALIBRATION_H_
|
||||
|
||||
#include "vl53l0x_def.h"
|
||||
#include "vl53l0x_platform.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
VL53L0X_Error VL53L0X_perform_xtalk_calibration(VL53L0X_DEV Dev,
|
||||
FixPoint1616_t XTalkCalDistance,
|
||||
FixPoint1616_t *pXTalkCompensationRateMegaCps);
|
||||
|
||||
VL53L0X_Error VL53L0X_perform_offset_calibration(VL53L0X_DEV Dev,
|
||||
FixPoint1616_t CalDistanceMilliMeter,
|
||||
int32_t *pOffsetMicroMeter);
|
||||
|
||||
VL53L0X_Error VL53L0X_set_offset_calibration_data_micro_meter(VL53L0X_DEV Dev,
|
||||
int32_t OffsetCalibrationDataMicroMeter);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_offset_calibration_data_micro_meter(VL53L0X_DEV Dev,
|
||||
int32_t *pOffsetCalibrationDataMicroMeter);
|
||||
|
||||
VL53L0X_Error VL53L0X_apply_offset_adjustment(VL53L0X_DEV Dev);
|
||||
|
||||
VL53L0X_Error VL53L0X_perform_ref_spad_management(VL53L0X_DEV Dev,
|
||||
uint32_t *refSpadCount, uint8_t *isApertureSpads);
|
||||
|
||||
VL53L0X_Error VL53L0X_set_reference_spads(VL53L0X_DEV Dev,
|
||||
uint32_t count, uint8_t isApertureSpads);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_reference_spads(VL53L0X_DEV Dev,
|
||||
uint32_t *pSpadCount, uint8_t *pIsApertureSpads);
|
||||
|
||||
VL53L0X_Error VL53L0X_perform_phase_calibration(VL53L0X_DEV Dev,
|
||||
uint8_t *pPhaseCal, const uint8_t get_data_enable,
|
||||
const uint8_t restore_config);
|
||||
|
||||
VL53L0X_Error VL53L0X_perform_ref_calibration(VL53L0X_DEV Dev,
|
||||
uint8_t *pVhvSettings, uint8_t *pPhaseCal, uint8_t get_data_enable);
|
||||
|
||||
VL53L0X_Error VL53L0X_set_ref_calibration(VL53L0X_DEV Dev,
|
||||
uint8_t VhvSettings, uint8_t PhaseCal);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_ref_calibration(VL53L0X_DEV Dev,
|
||||
uint8_t *pVhvSettings, uint8_t *pPhaseCal);
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _VL53L0X_API_CALIBRATION_H_ */
|
108
Api/core/inc/vl53l0x_api_core.h
Normal file
108
Api/core/inc/vl53l0x_api_core.h
Normal file
@ -0,0 +1,108 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2016, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef _VL53L0X_API_CORE_H_
|
||||
#define _VL53L0X_API_CORE_H_
|
||||
|
||||
#include "vl53l0x_def.h"
|
||||
#include "vl53l0x_platform.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
VL53L0X_Error VL53L0X_reverse_bytes(uint8_t *data, uint32_t size);
|
||||
|
||||
VL53L0X_Error VL53L0X_measurement_poll_for_completion(VL53L0X_DEV Dev);
|
||||
|
||||
uint8_t VL53L0X_encode_vcsel_period(uint8_t vcsel_period_pclks);
|
||||
|
||||
uint8_t VL53L0X_decode_vcsel_period(uint8_t vcsel_period_reg);
|
||||
|
||||
uint32_t VL53L0X_isqrt(uint32_t num);
|
||||
|
||||
uint32_t VL53L0X_quadrature_sum(uint32_t a, uint32_t b);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_info_from_device(VL53L0X_DEV Dev, uint8_t option);
|
||||
|
||||
VL53L0X_Error VL53L0X_set_vcsel_pulse_period(VL53L0X_DEV Dev,
|
||||
VL53L0X_VcselPeriod VcselPeriodType, uint8_t VCSELPulsePeriodPCLK);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_vcsel_pulse_period(VL53L0X_DEV Dev,
|
||||
VL53L0X_VcselPeriod VcselPeriodType, uint8_t *pVCSELPulsePeriodPCLK);
|
||||
|
||||
uint32_t VL53L0X_decode_timeout(uint16_t encoded_timeout);
|
||||
|
||||
VL53L0X_Error get_sequence_step_timeout(VL53L0X_DEV Dev,
|
||||
VL53L0X_SequenceStepId SequenceStepId,
|
||||
uint32_t *pTimeOutMicroSecs);
|
||||
|
||||
VL53L0X_Error set_sequence_step_timeout(VL53L0X_DEV Dev,
|
||||
VL53L0X_SequenceStepId SequenceStepId,
|
||||
uint32_t TimeOutMicroSecs);
|
||||
|
||||
VL53L0X_Error VL53L0X_set_measurement_timing_budget_micro_seconds(VL53L0X_DEV Dev,
|
||||
uint32_t MeasurementTimingBudgetMicroSeconds);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_measurement_timing_budget_micro_seconds(VL53L0X_DEV Dev,
|
||||
uint32_t *pMeasurementTimingBudgetMicroSeconds);
|
||||
|
||||
VL53L0X_Error VL53L0X_load_tuning_settings(VL53L0X_DEV Dev,
|
||||
uint8_t *pTuningSettingBuffer);
|
||||
|
||||
VL53L0X_Error VL53L0X_calc_sigma_estimate(VL53L0X_DEV Dev,
|
||||
VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
|
||||
FixPoint1616_t *pSigmaEstimate, uint32_t *pDmax_mm);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_total_xtalk_rate(VL53L0X_DEV Dev,
|
||||
VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
|
||||
FixPoint1616_t *ptotal_xtalk_rate_mcps);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_total_signal_rate(VL53L0X_DEV Dev,
|
||||
VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
|
||||
FixPoint1616_t *ptotal_signal_rate_mcps);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_pal_range_status(VL53L0X_DEV Dev,
|
||||
uint8_t DeviceRangeStatus,
|
||||
FixPoint1616_t SignalRate,
|
||||
uint16_t EffectiveSpadRtnCount,
|
||||
VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
|
||||
uint8_t *pPalRangeStatus);
|
||||
|
||||
uint32_t VL53L0X_calc_timeout_mclks(VL53L0X_DEV Dev,
|
||||
uint32_t timeout_period_us, uint8_t vcsel_period_pclks);
|
||||
|
||||
uint16_t VL53L0X_encode_timeout(uint32_t timeout_macro_clks);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _VL53L0X_API_CORE_H_ */
|
47
Api/core/inc/vl53l0x_api_ranging.h
Normal file
47
Api/core/inc/vl53l0x_api_ranging.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2016, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef _VL53L0X_API_RANGING_H_
|
||||
#define _VL53L0X_API_RANGING_H_
|
||||
|
||||
#include "vl53l0x_def.h"
|
||||
#include "vl53l0x_platform.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _VL53L0X_API_RANGING_H_ */
|
277
Api/core/inc/vl53l0x_api_strings.h
Normal file
277
Api/core/inc/vl53l0x_api_strings.h
Normal file
@ -0,0 +1,277 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2016, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef VL53L0X_API_STRINGS_H_
|
||||
#define VL53L0X_API_STRINGS_H_
|
||||
|
||||
#include "vl53l0x_def.h"
|
||||
#include "vl53l0x_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
VL53L0X_Error VL53L0X_get_device_info(VL53L0X_DEV Dev,
|
||||
VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_device_error_string(VL53L0X_DeviceError ErrorCode,
|
||||
char *pDeviceErrorString);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_range_status_string(uint8_t RangeStatus,
|
||||
char *pRangeStatusString);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_pal_error_string(VL53L0X_Error PalErrorCode,
|
||||
char *pPalErrorString);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_pal_state_string(VL53L0X_State PalStateCode,
|
||||
char *pPalStateString);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_sequence_steps_info(
|
||||
VL53L0X_SequenceStepId SequenceStepId,
|
||||
char *pSequenceStepsString);
|
||||
|
||||
VL53L0X_Error VL53L0X_get_limit_check_info(VL53L0X_DEV Dev, uint16_t LimitCheckId,
|
||||
char *pLimitCheckString);
|
||||
|
||||
|
||||
#ifdef USE_EMPTY_STRING
|
||||
#define VL53L0X_STRING_DEVICE_INFO_NAME ""
|
||||
#define VL53L0X_STRING_DEVICE_INFO_NAME_TS0 ""
|
||||
#define VL53L0X_STRING_DEVICE_INFO_NAME_TS1 ""
|
||||
#define VL53L0X_STRING_DEVICE_INFO_NAME_TS2 ""
|
||||
#define VL53L0X_STRING_DEVICE_INFO_NAME_ES1 ""
|
||||
#define VL53L0X_STRING_DEVICE_INFO_TYPE ""
|
||||
|
||||
/* PAL ERROR strings */
|
||||
#define VL53L0X_STRING_ERROR_NONE ""
|
||||
#define VL53L0X_STRING_ERROR_CALIBRATION_WARNING ""
|
||||
#define VL53L0X_STRING_ERROR_MIN_CLIPPED ""
|
||||
#define VL53L0X_STRING_ERROR_UNDEFINED ""
|
||||
#define VL53L0X_STRING_ERROR_INVALID_PARAMS ""
|
||||
#define VL53L0X_STRING_ERROR_NOT_SUPPORTED ""
|
||||
#define VL53L0X_STRING_ERROR_RANGE_ERROR ""
|
||||
#define VL53L0X_STRING_ERROR_TIME_OUT ""
|
||||
#define VL53L0X_STRING_ERROR_MODE_NOT_SUPPORTED ""
|
||||
#define VL53L0X_STRING_ERROR_BUFFER_TOO_SMALL ""
|
||||
#define VL53L0X_STRING_ERROR_GPIO_NOT_EXISTING ""
|
||||
#define VL53L0X_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED ""
|
||||
#define VL53L0X_STRING_ERROR_CONTROL_INTERFACE ""
|
||||
#define VL53L0X_STRING_ERROR_INVALID_COMMAND ""
|
||||
#define VL53L0X_STRING_ERROR_DIVISION_BY_ZERO ""
|
||||
#define VL53L0X_STRING_ERROR_REF_SPAD_INIT ""
|
||||
#define VL53L0X_STRING_ERROR_NOT_IMPLEMENTED ""
|
||||
|
||||
#define VL53L0X_STRING_UNKNOW_ERROR_CODE ""
|
||||
|
||||
|
||||
|
||||
/* Range Status */
|
||||
#define VL53L0X_STRING_RANGESTATUS_NONE ""
|
||||
#define VL53L0X_STRING_RANGESTATUS_RANGEVALID ""
|
||||
#define VL53L0X_STRING_RANGESTATUS_SIGMA ""
|
||||
#define VL53L0X_STRING_RANGESTATUS_SIGNAL ""
|
||||
#define VL53L0X_STRING_RANGESTATUS_MINRANGE ""
|
||||
#define VL53L0X_STRING_RANGESTATUS_PHASE ""
|
||||
#define VL53L0X_STRING_RANGESTATUS_HW ""
|
||||
|
||||
|
||||
/* Range Status */
|
||||
#define VL53L0X_STRING_STATE_POWERDOWN ""
|
||||
#define VL53L0X_STRING_STATE_WAIT_STATICINIT ""
|
||||
#define VL53L0X_STRING_STATE_STANDBY ""
|
||||
#define VL53L0X_STRING_STATE_IDLE ""
|
||||
#define VL53L0X_STRING_STATE_RUNNING ""
|
||||
#define VL53L0X_STRING_STATE_UNKNOWN ""
|
||||
#define VL53L0X_STRING_STATE_ERROR ""
|
||||
|
||||
|
||||
/* Device Specific */
|
||||
#define VL53L0X_STRING_DEVICEERROR_NONE ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_NOVHVVALUEFOUND ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_MSRCNOTARGET ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_SNRCHECK ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_RANGEPHASECHECK ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_TCC ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_PHASECONSISTENCY ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_MINCLIP ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_RANGECOMPLETE ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_ALGOUNDERFLOW ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_ALGOOVERFLOW ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD ""
|
||||
#define VL53L0X_STRING_DEVICEERROR_UNKNOWN ""
|
||||
|
||||
/* Check Enable */
|
||||
#define VL53L0X_STRING_CHECKENABLE_SIGMA_FINAL_RANGE ""
|
||||
#define VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE ""
|
||||
#define VL53L0X_STRING_CHECKENABLE_SIGNAL_REF_CLIP ""
|
||||
#define VL53L0X_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD ""
|
||||
|
||||
/* Sequence Step */
|
||||
#define VL53L0X_STRING_SEQUENCESTEP_TCC ""
|
||||
#define VL53L0X_STRING_SEQUENCESTEP_DSS ""
|
||||
#define VL53L0X_STRING_SEQUENCESTEP_MSRC ""
|
||||
#define VL53L0X_STRING_SEQUENCESTEP_PRE_RANGE ""
|
||||
#define VL53L0X_STRING_SEQUENCESTEP_FINAL_RANGE ""
|
||||
#else
|
||||
#define VL53L0X_STRING_DEVICE_INFO_NAME "VL53L0X cut1.0"
|
||||
#define VL53L0X_STRING_DEVICE_INFO_NAME_TS0 "VL53L0X TS0"
|
||||
#define VL53L0X_STRING_DEVICE_INFO_NAME_TS1 "VL53L0X TS1"
|
||||
#define VL53L0X_STRING_DEVICE_INFO_NAME_TS2 "VL53L0X TS2"
|
||||
#define VL53L0X_STRING_DEVICE_INFO_NAME_ES1 "VL53L0X ES1 or later"
|
||||
#define VL53L0X_STRING_DEVICE_INFO_TYPE "VL53L0X"
|
||||
|
||||
/* PAL ERROR strings */
|
||||
#define VL53L0X_STRING_ERROR_NONE \
|
||||
"No Error"
|
||||
#define VL53L0X_STRING_ERROR_CALIBRATION_WARNING \
|
||||
"Calibration Warning Error"
|
||||
#define VL53L0X_STRING_ERROR_MIN_CLIPPED \
|
||||
"Min clipped error"
|
||||
#define VL53L0X_STRING_ERROR_UNDEFINED \
|
||||
"Undefined error"
|
||||
#define VL53L0X_STRING_ERROR_INVALID_PARAMS \
|
||||
"Invalid parameters error"
|
||||
#define VL53L0X_STRING_ERROR_NOT_SUPPORTED \
|
||||
"Not supported error"
|
||||
#define VL53L0X_STRING_ERROR_RANGE_ERROR \
|
||||
"Range error"
|
||||
#define VL53L0X_STRING_ERROR_TIME_OUT \
|
||||
"Time out error"
|
||||
#define VL53L0X_STRING_ERROR_MODE_NOT_SUPPORTED \
|
||||
"Mode not supported error"
|
||||
#define VL53L0X_STRING_ERROR_BUFFER_TOO_SMALL \
|
||||
"Buffer too small"
|
||||
#define VL53L0X_STRING_ERROR_GPIO_NOT_EXISTING \
|
||||
"GPIO not existing"
|
||||
#define VL53L0X_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED \
|
||||
"GPIO funct not supported"
|
||||
#define VL53L0X_STRING_ERROR_INTERRUPT_NOT_CLEARED \
|
||||
"Interrupt not Cleared"
|
||||
#define VL53L0X_STRING_ERROR_CONTROL_INTERFACE \
|
||||
"Control Interface Error"
|
||||
#define VL53L0X_STRING_ERROR_INVALID_COMMAND \
|
||||
"Invalid Command Error"
|
||||
#define VL53L0X_STRING_ERROR_DIVISION_BY_ZERO \
|
||||
"Division by zero Error"
|
||||
#define VL53L0X_STRING_ERROR_REF_SPAD_INIT \
|
||||
"Reference Spad Init Error"
|
||||
#define VL53L0X_STRING_ERROR_NOT_IMPLEMENTED \
|
||||
"Not implemented error"
|
||||
|
||||
#define VL53L0X_STRING_UNKNOW_ERROR_CODE \
|
||||
"Unknown Error Code"
|
||||
|
||||
|
||||
|
||||
/* Range Status */
|
||||
#define VL53L0X_STRING_RANGESTATUS_NONE "No Update"
|
||||
#define VL53L0X_STRING_RANGESTATUS_RANGEVALID "Range Valid"
|
||||
#define VL53L0X_STRING_RANGESTATUS_SIGMA "Sigma Fail"
|
||||
#define VL53L0X_STRING_RANGESTATUS_SIGNAL "Signal Fail"
|
||||
#define VL53L0X_STRING_RANGESTATUS_MINRANGE "Min Range Fail"
|
||||
#define VL53L0X_STRING_RANGESTATUS_PHASE "Phase Fail"
|
||||
#define VL53L0X_STRING_RANGESTATUS_HW "Hardware Fail"
|
||||
|
||||
|
||||
/* Range Status */
|
||||
#define VL53L0X_STRING_STATE_POWERDOWN "POWERDOWN State"
|
||||
#define VL53L0X_STRING_STATE_WAIT_STATICINIT \
|
||||
"Wait for staticinit State"
|
||||
#define VL53L0X_STRING_STATE_STANDBY "STANDBY State"
|
||||
#define VL53L0X_STRING_STATE_IDLE "IDLE State"
|
||||
#define VL53L0X_STRING_STATE_RUNNING "RUNNING State"
|
||||
#define VL53L0X_STRING_STATE_UNKNOWN "UNKNOWN State"
|
||||
#define VL53L0X_STRING_STATE_ERROR "ERROR State"
|
||||
|
||||
|
||||
/* Device Specific */
|
||||
#define VL53L0X_STRING_DEVICEERROR_NONE "No Update"
|
||||
#define VL53L0X_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE \
|
||||
"VCSEL Continuity Test Failure"
|
||||
#define VL53L0X_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE \
|
||||
"VCSEL Watchdog Test Failure"
|
||||
#define VL53L0X_STRING_DEVICEERROR_NOVHVVALUEFOUND \
|
||||
"No VHV Value found"
|
||||
#define VL53L0X_STRING_DEVICEERROR_MSRCNOTARGET \
|
||||
"MSRC No Target Error"
|
||||
#define VL53L0X_STRING_DEVICEERROR_SNRCHECK \
|
||||
"SNR Check Exit"
|
||||
#define VL53L0X_STRING_DEVICEERROR_RANGEPHASECHECK \
|
||||
"Range Phase Check Error"
|
||||
#define VL53L0X_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK \
|
||||
"Sigma Threshold Check Error"
|
||||
#define VL53L0X_STRING_DEVICEERROR_TCC \
|
||||
"TCC Error"
|
||||
#define VL53L0X_STRING_DEVICEERROR_PHASECONSISTENCY \
|
||||
"Phase Consistency Error"
|
||||
#define VL53L0X_STRING_DEVICEERROR_MINCLIP \
|
||||
"Min Clip Error"
|
||||
#define VL53L0X_STRING_DEVICEERROR_RANGECOMPLETE \
|
||||
"Range Complete"
|
||||
#define VL53L0X_STRING_DEVICEERROR_ALGOUNDERFLOW \
|
||||
"Range Algo Underflow Error"
|
||||
#define VL53L0X_STRING_DEVICEERROR_ALGOOVERFLOW \
|
||||
"Range Algo Overlow Error"
|
||||
#define VL53L0X_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD \
|
||||
"Range Ignore Threshold Error"
|
||||
#define VL53L0X_STRING_DEVICEERROR_UNKNOWN \
|
||||
"Unknown error code"
|
||||
|
||||
/* Check Enable */
|
||||
#define VL53L0X_STRING_CHECKENABLE_SIGMA_FINAL_RANGE \
|
||||
"SIGMA FINAL RANGE"
|
||||
#define VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE \
|
||||
"SIGNAL RATE FINAL RANGE"
|
||||
#define VL53L0X_STRING_CHECKENABLE_SIGNAL_REF_CLIP \
|
||||
"SIGNAL REF CLIP"
|
||||
#define VL53L0X_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD \
|
||||
"RANGE IGNORE THRESHOLD"
|
||||
#define VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_MSRC \
|
||||
"SIGNAL RATE MSRC"
|
||||
#define VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_PRE_RANGE \
|
||||
"SIGNAL RATE PRE RANGE"
|
||||
|
||||
/* Sequence Step */
|
||||
#define VL53L0X_STRING_SEQUENCESTEP_TCC "TCC"
|
||||
#define VL53L0X_STRING_SEQUENCESTEP_DSS "DSS"
|
||||
#define VL53L0X_STRING_SEQUENCESTEP_MSRC "MSRC"
|
||||
#define VL53L0X_STRING_SEQUENCESTEP_PRE_RANGE "PRE RANGE"
|
||||
#define VL53L0X_STRING_SEQUENCESTEP_FINAL_RANGE "FINAL RANGE"
|
||||
#endif /* USE_EMPTY_STRING */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
640
Api/core/inc/vl53l0x_def.h
Normal file
640
Api/core/inc/vl53l0x_def.h
Normal file
@ -0,0 +1,640 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2016, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file VL53L0X_def.h
|
||||
*
|
||||
* @brief Type definitions for VL53L0X API.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _VL53L0X_DEF_H_
|
||||
#define _VL53L0X_DEF_H_
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup VL53L0X_globaldefine_group VL53L0X Defines
|
||||
* @brief VL53L0X Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** PAL SPECIFICATION major version */
|
||||
#define VL53L0X10_SPECIFICATION_VER_MAJOR 1
|
||||
/** PAL SPECIFICATION minor version */
|
||||
#define VL53L0X10_SPECIFICATION_VER_MINOR 2
|
||||
/** PAL SPECIFICATION sub version */
|
||||
#define VL53L0X10_SPECIFICATION_VER_SUB 7
|
||||
/** PAL SPECIFICATION sub version */
|
||||
#define VL53L0X10_SPECIFICATION_VER_REVISION 1440
|
||||
|
||||
/** VL53L0X PAL IMPLEMENTATION major version */
|
||||
#define VL53L0X10_IMPLEMENTATION_VER_MAJOR 1
|
||||
/** VL53L0X PAL IMPLEMENTATION minor version */
|
||||
#define VL53L0X10_IMPLEMENTATION_VER_MINOR 0
|
||||
/** VL53L0X PAL IMPLEMENTATION sub version */
|
||||
#define VL53L0X10_IMPLEMENTATION_VER_SUB 9
|
||||
/** VL53L0X PAL IMPLEMENTATION sub version */
|
||||
#define VL53L0X10_IMPLEMENTATION_VER_REVISION 3673
|
||||
|
||||
/** PAL SPECIFICATION major version */
|
||||
#define VL53L0X_SPECIFICATION_VER_MAJOR 1
|
||||
/** PAL SPECIFICATION minor version */
|
||||
#define VL53L0X_SPECIFICATION_VER_MINOR 2
|
||||
/** PAL SPECIFICATION sub version */
|
||||
#define VL53L0X_SPECIFICATION_VER_SUB 7
|
||||
/** PAL SPECIFICATION sub version */
|
||||
#define VL53L0X_SPECIFICATION_VER_REVISION 1440
|
||||
|
||||
/** VL53L0X PAL IMPLEMENTATION major version */
|
||||
#define VL53L0X_IMPLEMENTATION_VER_MAJOR 1
|
||||
/** VL53L0X PAL IMPLEMENTATION minor version */
|
||||
#define VL53L0X_IMPLEMENTATION_VER_MINOR 0
|
||||
/** VL53L0X PAL IMPLEMENTATION sub version */
|
||||
#define VL53L0X_IMPLEMENTATION_VER_SUB 2
|
||||
/** VL53L0X PAL IMPLEMENTATION sub version */
|
||||
#define VL53L0X_IMPLEMENTATION_VER_REVISION 4823
|
||||
#define VL53L0X_DEFAULT_MAX_LOOP 2000
|
||||
#define VL53L0X_MAX_STRING_LENGTH 32
|
||||
|
||||
|
||||
#include "vl53l0x_device.h"
|
||||
#include "vl53l0x_types.h"
|
||||
|
||||
|
||||
/****************************************
|
||||
* PRIVATE define do not edit
|
||||
****************************************/
|
||||
|
||||
/** @brief Defines the parameters of the Get Version Functions
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t revision; /*!< revision number */
|
||||
uint8_t major; /*!< major number */
|
||||
uint8_t minor; /*!< minor number */
|
||||
uint8_t build; /*!< build number */
|
||||
} VL53L0X_Version_t;
|
||||
|
||||
|
||||
/** @brief Defines the parameters of the Get Device Info Functions
|
||||
*/
|
||||
typedef struct {
|
||||
char Name[VL53L0X_MAX_STRING_LENGTH];
|
||||
/*!< Name of the Device e.g. Left_Distance */
|
||||
char Type[VL53L0X_MAX_STRING_LENGTH];
|
||||
/*!< Type of the Device e.g VL53L0X */
|
||||
char ProductId[VL53L0X_MAX_STRING_LENGTH];
|
||||
/*!< Product Identifier String */
|
||||
uint8_t ProductType;
|
||||
/*!< Product Type, VL53L0X = 1, VL53L1 = 2 */
|
||||
uint8_t ProductRevisionMajor;
|
||||
/*!< Product revision major */
|
||||
uint8_t ProductRevisionMinor;
|
||||
/*!< Product revision minor */
|
||||
} VL53L0X_DeviceInfo_t;
|
||||
|
||||
|
||||
/** @defgroup VL53L0X_define_Error_group Error and Warning code returned by API
|
||||
* The following DEFINE are used to identify the PAL ERROR
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef int8_t VL53L0X_Error;
|
||||
|
||||
#define VL53L0X_ERROR_NONE ((VL53L0X_Error) 0)
|
||||
#define VL53L0X_ERROR_CALIBRATION_WARNING ((VL53L0X_Error) -1)
|
||||
/*!< Warning invalid calibration data may be in used
|
||||
\a VL53L0X_InitData()
|
||||
\a VL53L0X_GetOffsetCalibrationData
|
||||
\a VL53L0X_SetOffsetCalibrationData */
|
||||
#define VL53L0X_ERROR_MIN_CLIPPED ((VL53L0X_Error) -2)
|
||||
/*!< Warning parameter passed was clipped to min before to be applied */
|
||||
|
||||
#define VL53L0X_ERROR_UNDEFINED ((VL53L0X_Error) -3)
|
||||
/*!< Unqualified error */
|
||||
#define VL53L0X_ERROR_INVALID_PARAMS ((VL53L0X_Error) -4)
|
||||
/*!< Parameter passed is invalid or out of range */
|
||||
#define VL53L0X_ERROR_NOT_SUPPORTED ((VL53L0X_Error) -5)
|
||||
/*!< Function is not supported in current mode or configuration */
|
||||
#define VL53L0X_ERROR_RANGE_ERROR ((VL53L0X_Error) -6)
|
||||
/*!< Device report a ranging error interrupt status */
|
||||
#define VL53L0X_ERROR_TIME_OUT ((VL53L0X_Error) -7)
|
||||
/*!< Aborted due to time out */
|
||||
#define VL53L0X_ERROR_MODE_NOT_SUPPORTED ((VL53L0X_Error) -8)
|
||||
/*!< Asked mode is not supported by the device */
|
||||
#define VL53L0X_ERROR_BUFFER_TOO_SMALL ((VL53L0X_Error) -9)
|
||||
/*!< ... */
|
||||
#define VL53L0X_ERROR_GPIO_NOT_EXISTING ((VL53L0X_Error) -10)
|
||||
/*!< User tried to setup a non-existing GPIO pin */
|
||||
#define VL53L0X_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED ((VL53L0X_Error) -11)
|
||||
/*!< unsupported GPIO functionality */
|
||||
#define VL53L0X_ERROR_INTERRUPT_NOT_CLEARED ((VL53L0X_Error) -12)
|
||||
/*!< Error during interrupt clear */
|
||||
#define VL53L0X_ERROR_CONTROL_INTERFACE ((VL53L0X_Error) -20)
|
||||
/*!< error reported from IO functions */
|
||||
#define VL53L0X_ERROR_INVALID_COMMAND ((VL53L0X_Error) -30)
|
||||
/*!< The command is not allowed in the current device state
|
||||
* (power down) */
|
||||
#define VL53L0X_ERROR_DIVISION_BY_ZERO ((VL53L0X_Error) -40)
|
||||
/*!< In the function a division by zero occurs */
|
||||
#define VL53L0X_ERROR_REF_SPAD_INIT ((VL53L0X_Error) -50)
|
||||
/*!< Error during reference SPAD initialization */
|
||||
#define VL53L0X_ERROR_NOT_IMPLEMENTED ((VL53L0X_Error) -99)
|
||||
/*!< Tells requested functionality has not been implemented yet or
|
||||
* not compatible with the device */
|
||||
/** @} VL53L0X_define_Error_group */
|
||||
|
||||
|
||||
/** @defgroup VL53L0X_define_DeviceModes_group Defines Device modes
|
||||
* Defines all possible modes for the device
|
||||
* @{
|
||||
*/
|
||||
typedef uint8_t VL53L0X_DeviceModes;
|
||||
|
||||
#define VL53L0X_DEVICEMODE_SINGLE_RANGING ((VL53L0X_DeviceModes) 0)
|
||||
#define VL53L0X_DEVICEMODE_CONTINUOUS_RANGING ((VL53L0X_DeviceModes) 1)
|
||||
#define VL53L0X_DEVICEMODE_SINGLE_HISTOGRAM ((VL53L0X_DeviceModes) 2)
|
||||
#define VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING ((VL53L0X_DeviceModes) 3)
|
||||
#define VL53L0X_DEVICEMODE_SINGLE_ALS ((VL53L0X_DeviceModes) 10)
|
||||
#define VL53L0X_DEVICEMODE_GPIO_DRIVE ((VL53L0X_DeviceModes) 20)
|
||||
#define VL53L0X_DEVICEMODE_GPIO_OSC ((VL53L0X_DeviceModes) 21)
|
||||
/* ... Modes to be added depending on device */
|
||||
/** @} VL53L0X_define_DeviceModes_group */
|
||||
|
||||
|
||||
|
||||
/** @defgroup VL53L0X_define_HistogramModes_group Defines Histogram modes
|
||||
* Defines all possible Histogram modes for the device
|
||||
* @{
|
||||
*/
|
||||
typedef uint8_t VL53L0X_HistogramModes;
|
||||
|
||||
#define VL53L0X_HISTOGRAMMODE_DISABLED ((VL53L0X_HistogramModes) 0)
|
||||
/*!< Histogram Disabled */
|
||||
#define VL53L0X_HISTOGRAMMODE_REFERENCE_ONLY ((VL53L0X_HistogramModes) 1)
|
||||
/*!< Histogram Reference array only */
|
||||
#define VL53L0X_HISTOGRAMMODE_RETURN_ONLY ((VL53L0X_HistogramModes) 2)
|
||||
/*!< Histogram Return array only */
|
||||
#define VL53L0X_HISTOGRAMMODE_BOTH ((VL53L0X_HistogramModes) 3)
|
||||
/*!< Histogram both Reference and Return Arrays */
|
||||
/* ... Modes to be added depending on device */
|
||||
/** @} VL53L0X_define_HistogramModes_group */
|
||||
|
||||
|
||||
/** @defgroup VL53L0X_define_PowerModes_group List of available Power Modes
|
||||
* List of available Power Modes
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef uint8_t VL53L0X_PowerModes;
|
||||
|
||||
#define VL53L0X_POWERMODE_STANDBY_LEVEL1 ((VL53L0X_PowerModes) 0)
|
||||
/*!< Standby level 1 */
|
||||
#define VL53L0X_POWERMODE_STANDBY_LEVEL2 ((VL53L0X_PowerModes) 1)
|
||||
/*!< Standby level 2 */
|
||||
#define VL53L0X_POWERMODE_IDLE_LEVEL1 ((VL53L0X_PowerModes) 2)
|
||||
/*!< Idle level 1 */
|
||||
#define VL53L0X_POWERMODE_IDLE_LEVEL2 ((VL53L0X_PowerModes) 3)
|
||||
/*!< Idle level 2 */
|
||||
|
||||
/** @} VL53L0X_define_PowerModes_group */
|
||||
|
||||
|
||||
/** @brief Defines all parameters for the device
|
||||
*/
|
||||
typedef struct {
|
||||
VL53L0X_DeviceModes DeviceMode;
|
||||
/*!< Defines type of measurement to be done for the next measure */
|
||||
VL53L0X_HistogramModes HistogramMode;
|
||||
/*!< Defines type of histogram measurement to be done for the next
|
||||
* measure */
|
||||
uint32_t MeasurementTimingBudgetMicroSeconds;
|
||||
/*!< Defines the allowed total time for a single measurement */
|
||||
uint32_t InterMeasurementPeriodMilliSeconds;
|
||||
/*!< Defines time between two consecutive measurements (between two
|
||||
* measurement starts). If set to 0 means back-to-back mode */
|
||||
uint8_t XTalkCompensationEnable;
|
||||
/*!< Tells if Crosstalk compensation shall be enable or not */
|
||||
uint16_t XTalkCompensationRangeMilliMeter;
|
||||
/*!< CrossTalk compensation range in millimeter */
|
||||
FixPoint1616_t XTalkCompensationRateMegaCps;
|
||||
/*!< CrossTalk compensation rate in Mega counts per seconds.
|
||||
* Expressed in 16.16 fixed point format. */
|
||||
int32_t RangeOffsetMicroMeters;
|
||||
/*!< Range offset adjustment (mm). */
|
||||
|
||||
uint8_t LimitChecksEnable[VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS];
|
||||
/*!< This Array store all the Limit Check enable for this device. */
|
||||
uint8_t LimitChecksStatus[VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS];
|
||||
/*!< This Array store all the Status of the check linked to last
|
||||
* measurement. */
|
||||
FixPoint1616_t LimitChecksValue[VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS];
|
||||
/*!< This Array store all the Limit Check value for this device */
|
||||
|
||||
uint8_t WrapAroundCheckEnable;
|
||||
/*!< Tells if Wrap Around Check shall be enable or not */
|
||||
} VL53L0X_DeviceParameters_t;
|
||||
|
||||
|
||||
/** @defgroup VL53L0X_define_State_group Defines the current status of the device
|
||||
* Defines the current status of the device
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef uint8_t VL53L0X_State;
|
||||
|
||||
#define VL53L0X_STATE_POWERDOWN ((VL53L0X_State) 0)
|
||||
/*!< Device is in HW reset */
|
||||
#define VL53L0X_STATE_WAIT_STATICINIT ((VL53L0X_State) 1)
|
||||
/*!< Device is initialized and wait for static initialization */
|
||||
#define VL53L0X_STATE_STANDBY ((VL53L0X_State) 2)
|
||||
/*!< Device is in Low power Standby mode */
|
||||
#define VL53L0X_STATE_IDLE ((VL53L0X_State) 3)
|
||||
/*!< Device has been initialized and ready to do measurements */
|
||||
#define VL53L0X_STATE_RUNNING ((VL53L0X_State) 4)
|
||||
/*!< Device is performing measurement */
|
||||
#define VL53L0X_STATE_UNKNOWN ((VL53L0X_State) 98)
|
||||
/*!< Device is in unknown state and need to be rebooted */
|
||||
#define VL53L0X_STATE_ERROR ((VL53L0X_State) 99)
|
||||
/*!< Device is in error state and need to be rebooted */
|
||||
|
||||
/** @} VL53L0X_define_State_group */
|
||||
|
||||
|
||||
/** @brief Structure containing the Dmax computation parameters and data
|
||||
*/
|
||||
typedef struct {
|
||||
int32_t AmbTuningWindowFactor_K;
|
||||
/*!< internal algo tuning (*1000) */
|
||||
int32_t RetSignalAt0mm;
|
||||
/*!< intermediate dmax computation value caching */
|
||||
} VL53L0X_DMaxData_t;
|
||||
|
||||
/**
|
||||
* @struct VL53L0X_RangeData_t
|
||||
* @brief Range measurement data.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t TimeStamp; /*!< 32-bit time stamp. */
|
||||
uint32_t MeasurementTimeUsec;
|
||||
/*!< Give the Measurement time needed by the device to do the
|
||||
* measurement.*/
|
||||
|
||||
|
||||
uint16_t RangeMilliMeter; /*!< range distance in millimeter. */
|
||||
|
||||
uint16_t RangeDMaxMilliMeter;
|
||||
/*!< Tells what is the maximum detection distance of the device
|
||||
* in current setup and environment conditions (Filled when
|
||||
* applicable) */
|
||||
|
||||
FixPoint1616_t SignalRateRtnMegaCps;
|
||||
/*!< Return signal rate (MCPS)\n these is a 16.16 fix point
|
||||
* value, which is effectively a measure of target
|
||||
* reflectance.*/
|
||||
FixPoint1616_t AmbientRateRtnMegaCps;
|
||||
/*!< Return ambient rate (MCPS)\n these is a 16.16 fix point
|
||||
* value, which is effectively a measure of the ambien
|
||||
* t light.*/
|
||||
|
||||
uint16_t EffectiveSpadRtnCount;
|
||||
/*!< Return the effective SPAD count for the return signal.
|
||||
* To obtain Real value it should be divided by 256 */
|
||||
|
||||
uint8_t ZoneId;
|
||||
/*!< Denotes which zone and range scheduler stage the range
|
||||
* data relates to. */
|
||||
uint8_t RangeFractionalPart;
|
||||
/*!< Fractional part of range distance. Final value is a
|
||||
* FixPoint168 value. */
|
||||
uint8_t RangeStatus;
|
||||
/*!< Range Status for the current measurement. This is device
|
||||
* dependent. Value = 0 means value is valid.
|
||||
* See \ref RangeStatusPage */
|
||||
} VL53L0X_RangingMeasurementData_t;
|
||||
|
||||
|
||||
#define VL53L0X_HISTOGRAM_BUFFER_SIZE 24
|
||||
|
||||
/**
|
||||
* @struct VL53L0X_HistogramData_t
|
||||
* @brief Histogram measurement data.
|
||||
*/
|
||||
typedef struct {
|
||||
/* Histogram Measurement data */
|
||||
uint32_t HistogramData[VL53L0X_HISTOGRAM_BUFFER_SIZE];
|
||||
/*!< Histogram data */
|
||||
uint8_t HistogramType; /*!< Indicate the types of histogram data :
|
||||
Return only, Reference only, both Return and Reference */
|
||||
uint8_t FirstBin; /*!< First Bin value */
|
||||
uint8_t BufferSize; /*!< Buffer Size - Set by the user.*/
|
||||
uint8_t NumberOfBins;
|
||||
/*!< Number of bins filled by the histogram measurement */
|
||||
|
||||
VL53L0X_DeviceError ErrorStatus;
|
||||
/*!< Error status of the current measurement. \n
|
||||
see @a ::VL53L0X_DeviceError @a VL53L0X_GetStatusErrorString() */
|
||||
} VL53L0X_HistogramMeasurementData_t;
|
||||
|
||||
#define VL53L0X_REF_SPAD_BUFFER_SIZE 6
|
||||
|
||||
/**
|
||||
* @struct VL53L0X_SpadData_t
|
||||
* @brief Spad Configuration Data.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t RefSpadEnables[VL53L0X_REF_SPAD_BUFFER_SIZE];
|
||||
/*!< Reference Spad Enables */
|
||||
uint8_t RefGoodSpadMap[VL53L0X_REF_SPAD_BUFFER_SIZE];
|
||||
/*!< Reference Spad Good Spad Map */
|
||||
} VL53L0X_SpadData_t;
|
||||
|
||||
typedef struct {
|
||||
FixPoint1616_t OscFrequencyMHz; /* Frequency used */
|
||||
|
||||
uint16_t LastEncodedTimeout;
|
||||
/* last encoded Time out used for timing budget*/
|
||||
|
||||
VL53L0X_GpioFunctionality Pin0GpioFunctionality;
|
||||
/* store the functionality of the GPIO: pin0 */
|
||||
|
||||
uint32_t FinalRangeTimeoutMicroSecs;
|
||||
/*!< Execution time of the final range*/
|
||||
uint8_t FinalRangeVcselPulsePeriod;
|
||||
/*!< Vcsel pulse period (pll clocks) for the final range measurement*/
|
||||
uint32_t PreRangeTimeoutMicroSecs;
|
||||
/*!< Execution time of the final range*/
|
||||
uint8_t PreRangeVcselPulsePeriod;
|
||||
/*!< Vcsel pulse period (pll clocks) for the pre-range measurement*/
|
||||
|
||||
uint16_t SigmaEstRefArray;
|
||||
/*!< Reference array sigma value in 1/100th of [mm] e.g. 100 = 1mm */
|
||||
uint16_t SigmaEstEffPulseWidth;
|
||||
/*!< Effective Pulse width for sigma estimate in 1/100th
|
||||
* of ns e.g. 900 = 9.0ns */
|
||||
uint16_t SigmaEstEffAmbWidth;
|
||||
/*!< Effective Ambient width for sigma estimate in 1/100th of ns
|
||||
* e.g. 500 = 5.0ns */
|
||||
|
||||
|
||||
uint8_t ReadDataFromDeviceDone; /* Indicate if read from device has
|
||||
been done (==1) or not (==0) */
|
||||
uint8_t ModuleId; /* Module ID */
|
||||
uint8_t Revision; /* test Revision */
|
||||
char ProductId[VL53L0X_MAX_STRING_LENGTH];
|
||||
/* Product Identifier String */
|
||||
uint8_t ReferenceSpadCount; /* used for ref spad management */
|
||||
uint8_t ReferenceSpadType; /* used for ref spad management */
|
||||
uint8_t RefSpadsInitialised; /* reports if ref spads are initialised. */
|
||||
uint32_t PartUIDUpper; /*!< Unique Part ID Upper */
|
||||
uint32_t PartUIDLower; /*!< Unique Part ID Lower */
|
||||
FixPoint1616_t SignalRateMeasFixed400mm; /*!< Peek Signal rate
|
||||
at 400 mm*/
|
||||
|
||||
} VL53L0X_DeviceSpecificParameters_t;
|
||||
|
||||
/**
|
||||
* @struct VL53L0X_DevData_t
|
||||
*
|
||||
* @brief VL53L0X PAL device ST private data structure \n
|
||||
* End user should never access any of these field directly
|
||||
*
|
||||
* These must never access directly but only via macro
|
||||
*/
|
||||
typedef struct {
|
||||
VL53L0X_DMaxData_t DMaxData;
|
||||
/*!< Dmax Data */
|
||||
int32_t Part2PartOffsetNVMMicroMeter;
|
||||
/*!< backed up NVM value */
|
||||
int32_t Part2PartOffsetAdjustmentNVMMicroMeter;
|
||||
/*!< backed up NVM value representing additional offset adjustment */
|
||||
VL53L0X_DeviceParameters_t CurrentParameters;
|
||||
/*!< Current Device Parameter */
|
||||
VL53L0X_RangingMeasurementData_t LastRangeMeasure;
|
||||
/*!< Ranging Data */
|
||||
VL53L0X_HistogramMeasurementData_t LastHistogramMeasure;
|
||||
/*!< Histogram Data */
|
||||
VL53L0X_DeviceSpecificParameters_t DeviceSpecificParameters;
|
||||
/*!< Parameters specific to the device */
|
||||
VL53L0X_SpadData_t SpadData;
|
||||
/*!< Spad Data */
|
||||
uint8_t SequenceConfig;
|
||||
/*!< Internal value for the sequence config */
|
||||
uint8_t RangeFractionalEnable;
|
||||
/*!< Enable/Disable fractional part of ranging data */
|
||||
VL53L0X_State PalState;
|
||||
/*!< Current state of the PAL for this device */
|
||||
VL53L0X_PowerModes PowerMode;
|
||||
/*!< Current Power Mode */
|
||||
uint16_t SigmaEstRefArray;
|
||||
/*!< Reference array sigma value in 1/100th of [mm] e.g. 100 = 1mm */
|
||||
uint16_t SigmaEstEffPulseWidth;
|
||||
/*!< Effective Pulse width for sigma estimate in 1/100th
|
||||
* of ns e.g. 900 = 9.0ns */
|
||||
uint16_t SigmaEstEffAmbWidth;
|
||||
/*!< Effective Ambient width for sigma estimate in 1/100th of ns
|
||||
* e.g. 500 = 5.0ns */
|
||||
uint8_t StopVariable;
|
||||
/*!< StopVariable used during the stop sequence */
|
||||
uint16_t targetRefRate;
|
||||
/*!< Target Ambient Rate for Ref spad management */
|
||||
FixPoint1616_t SigmaEstimate;
|
||||
/*!< Sigma Estimate - based on ambient & VCSEL rates and
|
||||
* signal_total_events */
|
||||
FixPoint1616_t SignalEstimate;
|
||||
/*!< Signal Estimate - based on ambient & VCSEL rates and cross talk */
|
||||
FixPoint1616_t LastSignalRefMcps;
|
||||
/*!< Latest Signal ref in Mcps */
|
||||
uint8_t *pTuningSettingsPointer;
|
||||
/*!< Pointer for Tuning Settings table */
|
||||
uint8_t UseInternalTuningSettings;
|
||||
/*!< Indicate if we use Tuning Settings table */
|
||||
uint16_t LinearityCorrectiveGain;
|
||||
/*!< Linearity Corrective Gain value in x1000 */
|
||||
uint16_t DmaxCalRangeMilliMeter;
|
||||
/*!< Dmax Calibration Range millimeter */
|
||||
FixPoint1616_t DmaxCalSignalRateRtnMegaCps;
|
||||
/*!< Dmax Calibration Signal Rate Return MegaCps */
|
||||
|
||||
} VL53L0X_DevData_t;
|
||||
|
||||
|
||||
/** @defgroup VL53L0X_define_InterruptPolarity_group Defines the Polarity
|
||||
* of the Interrupt
|
||||
* Defines the Polarity of the Interrupt
|
||||
* @{
|
||||
*/
|
||||
typedef uint8_t VL53L0X_InterruptPolarity;
|
||||
|
||||
#define VL53L0X_INTERRUPTPOLARITY_LOW ((VL53L0X_InterruptPolarity) 0)
|
||||
/*!< Set active low polarity best setup for falling edge. */
|
||||
#define VL53L0X_INTERRUPTPOLARITY_HIGH ((VL53L0X_InterruptPolarity) 1)
|
||||
/*!< Set active high polarity best setup for rising edge. */
|
||||
|
||||
/** @} VL53L0X_define_InterruptPolarity_group */
|
||||
|
||||
|
||||
/** @defgroup VL53L0X_define_VcselPeriod_group Vcsel Period Defines
|
||||
* Defines the range measurement for which to access the vcsel period.
|
||||
* @{
|
||||
*/
|
||||
typedef uint8_t VL53L0X_VcselPeriod;
|
||||
|
||||
#define VL53L0X_VCSEL_PERIOD_PRE_RANGE ((VL53L0X_VcselPeriod) 0)
|
||||
/*!<Identifies the pre-range vcsel period. */
|
||||
#define VL53L0X_VCSEL_PERIOD_FINAL_RANGE ((VL53L0X_VcselPeriod) 1)
|
||||
/*!<Identifies the final range vcsel period. */
|
||||
|
||||
/** @} VL53L0X_define_VcselPeriod_group */
|
||||
|
||||
/** @defgroup VL53L0X_define_SchedulerSequence_group Defines the steps
|
||||
* carried out by the scheduler during a range measurement.
|
||||
* @{
|
||||
* Defines the states of all the steps in the scheduler
|
||||
* i.e. enabled/disabled.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t TccOn; /*!<Reports if Target Centre Check On */
|
||||
uint8_t MsrcOn; /*!<Reports if MSRC On */
|
||||
uint8_t DssOn; /*!<Reports if DSS On */
|
||||
uint8_t PreRangeOn; /*!<Reports if Pre-Range On */
|
||||
uint8_t FinalRangeOn; /*!<Reports if Final-Range On */
|
||||
} VL53L0X_SchedulerSequenceSteps_t;
|
||||
|
||||
/** @} VL53L0X_define_SchedulerSequence_group */
|
||||
|
||||
/** @defgroup VL53L0X_define_SequenceStepId_group Defines the Polarity
|
||||
* of the Interrupt
|
||||
* Defines the the sequence steps performed during ranging..
|
||||
* @{
|
||||
*/
|
||||
typedef uint8_t VL53L0X_SequenceStepId;
|
||||
|
||||
#define VL53L0X_SEQUENCESTEP_TCC ((VL53L0X_VcselPeriod) 0)
|
||||
/*!<Target CentreCheck identifier. */
|
||||
#define VL53L0X_SEQUENCESTEP_DSS ((VL53L0X_VcselPeriod) 1)
|
||||
/*!<Dynamic Spad Selection function Identifier. */
|
||||
#define VL53L0X_SEQUENCESTEP_MSRC ((VL53L0X_VcselPeriod) 2)
|
||||
/*!<Minimum Signal Rate Check function Identifier. */
|
||||
#define VL53L0X_SEQUENCESTEP_PRE_RANGE ((VL53L0X_VcselPeriod) 3)
|
||||
/*!<Pre-Range check Identifier. */
|
||||
#define VL53L0X_SEQUENCESTEP_FINAL_RANGE ((VL53L0X_VcselPeriod) 4)
|
||||
/*!<Final Range Check Identifier. */
|
||||
|
||||
#define VL53L0X_SEQUENCESTEP_NUMBER_OF_CHECKS 5
|
||||
/*!<Number of Sequence Step Managed by the API. */
|
||||
|
||||
/** @} VL53L0X_define_SequenceStepId_group */
|
||||
|
||||
|
||||
/* MACRO Definitions */
|
||||
/** @defgroup VL53L0X_define_GeneralMacro_group General Macro Defines
|
||||
* General Macro Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Defines */
|
||||
#define VL53L0X_SETPARAMETERFIELD(Dev, field, value) \
|
||||
PALDevDataSet(Dev, CurrentParameters.field, value)
|
||||
|
||||
#define VL53L0X_GETPARAMETERFIELD(Dev, field, variable) \
|
||||
variable = PALDevDataGet(Dev, CurrentParameters).field
|
||||
|
||||
|
||||
#define VL53L0X_SETARRAYPARAMETERFIELD(Dev, field, index, value) \
|
||||
PALDevDataSet(Dev, CurrentParameters.field[index], value)
|
||||
|
||||
#define VL53L0X_GETARRAYPARAMETERFIELD(Dev, field, index, variable) \
|
||||
variable = PALDevDataGet(Dev, CurrentParameters).field[index]
|
||||
|
||||
|
||||
#define VL53L0X_SETDEVICESPECIFICPARAMETER(Dev, field, value) \
|
||||
PALDevDataSet(Dev, DeviceSpecificParameters.field, value)
|
||||
|
||||
#define VL53L0X_GETDEVICESPECIFICPARAMETER(Dev, field) \
|
||||
PALDevDataGet(Dev, DeviceSpecificParameters).field
|
||||
|
||||
|
||||
#define VL53L0X_FIXPOINT1616TOFIXPOINT97(Value) \
|
||||
(uint16_t)((Value>>9)&0xFFFF)
|
||||
#define VL53L0X_FIXPOINT97TOFIXPOINT1616(Value) \
|
||||
(FixPoint1616_t)(Value<<9)
|
||||
|
||||
#define VL53L0X_FIXPOINT1616TOFIXPOINT88(Value) \
|
||||
(uint16_t)((Value>>8)&0xFFFF)
|
||||
#define VL53L0X_FIXPOINT88TOFIXPOINT1616(Value) \
|
||||
(FixPoint1616_t)(Value<<8)
|
||||
|
||||
#define VL53L0X_FIXPOINT1616TOFIXPOINT412(Value) \
|
||||
(uint16_t)((Value>>4)&0xFFFF)
|
||||
#define VL53L0X_FIXPOINT412TOFIXPOINT1616(Value) \
|
||||
(FixPoint1616_t)(Value<<4)
|
||||
|
||||
#define VL53L0X_FIXPOINT1616TOFIXPOINT313(Value) \
|
||||
(uint16_t)((Value>>3)&0xFFFF)
|
||||
#define VL53L0X_FIXPOINT313TOFIXPOINT1616(Value) \
|
||||
(FixPoint1616_t)(Value<<3)
|
||||
|
||||
#define VL53L0X_FIXPOINT1616TOFIXPOINT08(Value) \
|
||||
(uint8_t)((Value>>8)&0x00FF)
|
||||
#define VL53L0X_FIXPOINT08TOFIXPOINT1616(Value) \
|
||||
(FixPoint1616_t)(Value<<8)
|
||||
|
||||
#define VL53L0X_FIXPOINT1616TOFIXPOINT53(Value) \
|
||||
(uint8_t)((Value>>13)&0x00FF)
|
||||
#define VL53L0X_FIXPOINT53TOFIXPOINT1616(Value) \
|
||||
(FixPoint1616_t)(Value<<13)
|
||||
|
||||
#define VL53L0X_FIXPOINT1616TOFIXPOINT102(Value) \
|
||||
(uint16_t)((Value>>14)&0x0FFF)
|
||||
#define VL53L0X_FIXPOINT102TOFIXPOINT1616(Value) \
|
||||
(FixPoint1616_t)(Value<<12)
|
||||
|
||||
#define VL53L0X_MAKEUINT16(lsb, msb) (uint16_t)((((uint16_t)msb)<<8) + \
|
||||
(uint16_t)lsb)
|
||||
|
||||
/** @} VL53L0X_define_GeneralMacro_group */
|
||||
|
||||
/** @} VL53L0X_globaldefine_group */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _VL53L0X_DEF_H_ */
|
257
Api/core/inc/vl53l0x_device.h
Normal file
257
Api/core/inc/vl53l0x_device.h
Normal file
@ -0,0 +1,257 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2016, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* Device specific defines. To be adapted by implementer for the targeted
|
||||
* device.
|
||||
*/
|
||||
|
||||
#ifndef _VL53L0X_DEVICE_H_
|
||||
#define _VL53L0X_DEVICE_H_
|
||||
|
||||
#include "vl53l0x_types.h"
|
||||
|
||||
|
||||
/** @defgroup VL53L0X_DevSpecDefines_group VL53L0X cut1.1 Device Specific Defines
|
||||
* @brief VL53L0X cut1.1 Device Specific Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup VL53L0X_DeviceError_group Device Error
|
||||
* @brief Device Error code
|
||||
*
|
||||
* This enum is Device specific it should be updated in the implementation
|
||||
* Use @a VL53L0X_GetStatusErrorString() to get the string.
|
||||
* It is related to Status Register of the Device.
|
||||
* @{
|
||||
*/
|
||||
typedef uint8_t VL53L0X_DeviceError;
|
||||
|
||||
#define VL53L0X_DEVICEERROR_NONE ((VL53L0X_DeviceError) 0)
|
||||
/*!< 0 NoError */
|
||||
#define VL53L0X_DEVICEERROR_VCSELCONTINUITYTESTFAILURE ((VL53L0X_DeviceError) 1)
|
||||
#define VL53L0X_DEVICEERROR_VCSELWATCHDOGTESTFAILURE ((VL53L0X_DeviceError) 2)
|
||||
#define VL53L0X_DEVICEERROR_NOVHVVALUEFOUND ((VL53L0X_DeviceError) 3)
|
||||
#define VL53L0X_DEVICEERROR_MSRCNOTARGET ((VL53L0X_DeviceError) 4)
|
||||
#define VL53L0X_DEVICEERROR_SNRCHECK ((VL53L0X_DeviceError) 5)
|
||||
#define VL53L0X_DEVICEERROR_RANGEPHASECHECK ((VL53L0X_DeviceError) 6)
|
||||
#define VL53L0X_DEVICEERROR_SIGMATHRESHOLDCHECK ((VL53L0X_DeviceError) 7)
|
||||
#define VL53L0X_DEVICEERROR_TCC ((VL53L0X_DeviceError) 8)
|
||||
#define VL53L0X_DEVICEERROR_PHASECONSISTENCY ((VL53L0X_DeviceError) 9)
|
||||
#define VL53L0X_DEVICEERROR_MINCLIP ((VL53L0X_DeviceError) 10)
|
||||
#define VL53L0X_DEVICEERROR_RANGECOMPLETE ((VL53L0X_DeviceError) 11)
|
||||
#define VL53L0X_DEVICEERROR_ALGOUNDERFLOW ((VL53L0X_DeviceError) 12)
|
||||
#define VL53L0X_DEVICEERROR_ALGOOVERFLOW ((VL53L0X_DeviceError) 13)
|
||||
#define VL53L0X_DEVICEERROR_RANGEIGNORETHRESHOLD ((VL53L0X_DeviceError) 14)
|
||||
|
||||
/** @} end of VL53L0X_DeviceError_group */
|
||||
|
||||
|
||||
/** @defgroup VL53L0X_CheckEnable_group Check Enable list
|
||||
* @brief Check Enable code
|
||||
*
|
||||
* Define used to specify the LimitCheckId.
|
||||
* Use @a VL53L0X_GetLimitCheckInfo() to get the string.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE 0
|
||||
#define VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE 1
|
||||
#define VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP 2
|
||||
#define VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD 3
|
||||
#define VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC 4
|
||||
#define VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE 5
|
||||
|
||||
#define VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS 6
|
||||
|
||||
/** @} end of VL53L0X_CheckEnable_group */
|
||||
|
||||
|
||||
/** @defgroup VL53L0X_GpioFunctionality_group Gpio Functionality
|
||||
* @brief Defines the different functionalities for the device GPIO(s)
|
||||
* @{
|
||||
*/
|
||||
typedef uint8_t VL53L0X_GpioFunctionality;
|
||||
|
||||
#define VL53L0X_GPIOFUNCTIONALITY_OFF \
|
||||
((VL53L0X_GpioFunctionality) 0) /*!< NO Interrupt */
|
||||
#define VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW \
|
||||
((VL53L0X_GpioFunctionality) 1) /*!< Level Low (value < thresh_low) */
|
||||
#define VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH \
|
||||
((VL53L0X_GpioFunctionality) 2) /*!< Level High (value > thresh_high) */
|
||||
#define VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT \
|
||||
((VL53L0X_GpioFunctionality) 3)
|
||||
/*!< Out Of Window (value < thresh_low OR value > thresh_high) */
|
||||
#define VL53L0X_GPIOFUNCTIONALITY_NEW_MEASURE_READY \
|
||||
((VL53L0X_GpioFunctionality) 4) /*!< New Sample Ready */
|
||||
|
||||
/** @} end of VL53L0X_GpioFunctionality_group */
|
||||
|
||||
|
||||
/* Device register map */
|
||||
|
||||
/** @defgroup VL53L0X_DefineRegisters_group Define Registers
|
||||
* @brief List of all the defined registers
|
||||
* @{
|
||||
*/
|
||||
#define VL53L0X_REG_SYSRANGE_START 0x000
|
||||
/** mask existing bit in #VL53L0X_REG_SYSRANGE_START*/
|
||||
#define VL53L0X_REG_SYSRANGE_MODE_MASK 0x0F
|
||||
/** bit 0 in #VL53L0X_REG_SYSRANGE_START write 1 toggle state in
|
||||
* continuous mode and arm next shot in single shot mode */
|
||||
#define VL53L0X_REG_SYSRANGE_MODE_START_STOP 0x01
|
||||
/** bit 1 write 0 in #VL53L0X_REG_SYSRANGE_START set single shot mode */
|
||||
#define VL53L0X_REG_SYSRANGE_MODE_SINGLESHOT 0x00
|
||||
/** bit 1 write 1 in #VL53L0X_REG_SYSRANGE_START set back-to-back
|
||||
* operation mode */
|
||||
#define VL53L0X_REG_SYSRANGE_MODE_BACKTOBACK 0x02
|
||||
/** bit 2 write 1 in #VL53L0X_REG_SYSRANGE_START set timed operation
|
||||
* mode */
|
||||
#define VL53L0X_REG_SYSRANGE_MODE_TIMED 0x04
|
||||
/** bit 3 write 1 in #VL53L0X_REG_SYSRANGE_START set histogram operation
|
||||
* mode */
|
||||
#define VL53L0X_REG_SYSRANGE_MODE_HISTOGRAM 0x08
|
||||
|
||||
|
||||
#define VL53L0X_REG_SYSTEM_THRESH_HIGH 0x000C
|
||||
#define VL53L0X_REG_SYSTEM_THRESH_LOW 0x000E
|
||||
|
||||
|
||||
#define VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG 0x0001
|
||||
#define VL53L0X_REG_SYSTEM_RANGE_CONFIG 0x0009
|
||||
#define VL53L0X_REG_SYSTEM_INTERMEASUREMENT_PERIOD 0x0004
|
||||
|
||||
|
||||
#define VL53L0X_REG_SYSTEM_INTERRUPT_CONFIG_GPIO 0x000A
|
||||
#define VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_DISABLED 0x00
|
||||
#define VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_LEVEL_LOW 0x01
|
||||
#define VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_LEVEL_HIGH 0x02
|
||||
#define VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_OUT_OF_WINDOW 0x03
|
||||
#define VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY 0x04
|
||||
|
||||
#define VL53L0X_REG_GPIO_HV_MUX_ACTIVE_HIGH 0x0084
|
||||
|
||||
|
||||
#define VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR 0x000B
|
||||
|
||||
/* Result registers */
|
||||
#define VL53L0X_REG_RESULT_INTERRUPT_STATUS 0x0013
|
||||
#define VL53L0X_REG_RESULT_RANGE_STATUS 0x0014
|
||||
|
||||
#define VL53L0X_REG_RESULT_CORE_PAGE 1
|
||||
#define VL53L0X_REG_RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN 0x00BC
|
||||
#define VL53L0X_REG_RESULT_CORE_RANGING_TOTAL_EVENTS_RTN 0x00C0
|
||||
#define VL53L0X_REG_RESULT_CORE_AMBIENT_WINDOW_EVENTS_REF 0x00D0
|
||||
#define VL53L0X_REG_RESULT_CORE_RANGING_TOTAL_EVENTS_REF 0x00D4
|
||||
#define VL53L0X_REG_RESULT_PEAK_SIGNAL_RATE_REF 0x00B6
|
||||
|
||||
/* Algo register */
|
||||
|
||||
#define VL53L0X_REG_ALGO_PART_TO_PART_RANGE_OFFSET_MM 0x0028
|
||||
|
||||
#define VL53L0X_REG_I2C_SLAVE_DEVICE_ADDRESS 0x008a
|
||||
|
||||
/* Check Limit registers */
|
||||
#define VL53L0X_REG_MSRC_CONFIG_CONTROL 0x0060
|
||||
|
||||
#define VL53L0X_REG_PRE_RANGE_CONFIG_MIN_SNR 0X0027
|
||||
#define VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW 0x0056
|
||||
#define VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH 0x0057
|
||||
#define VL53L0X_REG_PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT 0x0064
|
||||
|
||||
#define VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_SNR 0X0067
|
||||
#define VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW 0x0047
|
||||
#define VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH 0x0048
|
||||
#define VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT 0x0044
|
||||
|
||||
|
||||
#define VL53L0X_REG_PRE_RANGE_CONFIG_SIGMA_THRESH_HI 0X0061
|
||||
#define VL53L0X_REG_PRE_RANGE_CONFIG_SIGMA_THRESH_LO 0X0062
|
||||
|
||||
/* PRE RANGE registers */
|
||||
#define VL53L0X_REG_PRE_RANGE_CONFIG_VCSEL_PERIOD 0x0050
|
||||
#define VL53L0X_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI 0x0051
|
||||
#define VL53L0X_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_LO 0x0052
|
||||
|
||||
#define VL53L0X_REG_SYSTEM_HISTOGRAM_BIN 0x0081
|
||||
#define VL53L0X_REG_HISTOGRAM_CONFIG_INITIAL_PHASE_SELECT 0x0033
|
||||
#define VL53L0X_REG_HISTOGRAM_CONFIG_READOUT_CTRL 0x0055
|
||||
|
||||
#define VL53L0X_REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD 0x0070
|
||||
#define VL53L0X_REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI 0x0071
|
||||
#define VL53L0X_REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_LO 0x0072
|
||||
#define VL53L0X_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MCPS 0x0020
|
||||
|
||||
#define VL53L0X_REG_MSRC_CONFIG_TIMEOUT_MACROP 0x0046
|
||||
|
||||
|
||||
#define VL53L0X_REG_SOFT_RESET_GO2_SOFT_RESET_N 0x00bf
|
||||
#define VL53L0X_REG_IDENTIFICATION_MODEL_ID 0x00c0
|
||||
#define VL53L0X_REG_IDENTIFICATION_REVISION_ID 0x00c2
|
||||
|
||||
#define VL53L0X_REG_OSC_CALIBRATE_VAL 0x00f8
|
||||
|
||||
|
||||
#define VL53L0X_SIGMA_ESTIMATE_MAX_VALUE 65535
|
||||
/* equivalent to a range sigma of 655.35mm */
|
||||
|
||||
#define VL53L0X_REG_GLOBAL_CONFIG_VCSEL_WIDTH 0x032
|
||||
#define VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0 0x0B0
|
||||
#define VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_1 0x0B1
|
||||
#define VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_2 0x0B2
|
||||
#define VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_3 0x0B3
|
||||
#define VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_4 0x0B4
|
||||
#define VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_5 0x0B5
|
||||
|
||||
#define VL53L0X_REG_GLOBAL_CONFIG_REF_EN_START_SELECT 0xB6
|
||||
#define VL53L0X_REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD 0x4E /* 0x14E */
|
||||
#define VL53L0X_REG_DYNAMIC_SPAD_REF_EN_START_OFFSET 0x4F /* 0x14F */
|
||||
#define VL53L0X_REG_POWER_MANAGEMENT_GO1_POWER_FORCE 0x80
|
||||
|
||||
/*
|
||||
* Speed of light in um per 1E-10 Seconds
|
||||
*/
|
||||
|
||||
#define VL53L0X_SPEED_OF_LIGHT_IN_AIR 2997
|
||||
|
||||
#define VL53L0X_REG_VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV 0x0089
|
||||
|
||||
#define VL53L0X_REG_ALGO_PHASECAL_LIM 0x0030 /* 0x130 */
|
||||
#define VL53L0X_REG_ALGO_PHASECAL_CONFIG_TIMEOUT 0x0030
|
||||
|
||||
/** @} VL53L0X_DefineRegisters_group */
|
||||
|
||||
/** @} VL53L0X_DevSpecDefines_group */
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/* _VL53L0X_DEVICE_H_ */
|
||||
|
||||
|
194
Api/core/inc/vl53l0x_interrupt_threshold_settings.h
Normal file
194
Api/core/inc/vl53l0x_interrupt_threshold_settings.h
Normal file
@ -0,0 +1,194 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2016, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
#ifndef _VL53L0X_INTERRUPT_THRESHOLD_SETTINGS_H_
|
||||
#define _VL53L0X_INTERRUPT_THRESHOLD_SETTINGS_H_
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
uint8_t InterruptThresholdSettings[] = {
|
||||
|
||||
/* Start of Interrupt Threshold Settings */
|
||||
0x1, 0xff, 0x00,
|
||||
0x1, 0x80, 0x01,
|
||||
0x1, 0xff, 0x01,
|
||||
0x1, 0x00, 0x00,
|
||||
0x1, 0xff, 0x01,
|
||||
0x1, 0x4f, 0x02,
|
||||
0x1, 0xFF, 0x0E,
|
||||
0x1, 0x00, 0x03,
|
||||
0x1, 0x01, 0x84,
|
||||
0x1, 0x02, 0x0A,
|
||||
0x1, 0x03, 0x03,
|
||||
0x1, 0x04, 0x08,
|
||||
0x1, 0x05, 0xC8,
|
||||
0x1, 0x06, 0x03,
|
||||
0x1, 0x07, 0x8D,
|
||||
0x1, 0x08, 0x08,
|
||||
0x1, 0x09, 0xC6,
|
||||
0x1, 0x0A, 0x01,
|
||||
0x1, 0x0B, 0x02,
|
||||
0x1, 0x0C, 0x00,
|
||||
0x1, 0x0D, 0xD5,
|
||||
0x1, 0x0E, 0x18,
|
||||
0x1, 0x0F, 0x12,
|
||||
0x1, 0x10, 0x01,
|
||||
0x1, 0x11, 0x82,
|
||||
0x1, 0x12, 0x00,
|
||||
0x1, 0x13, 0xD5,
|
||||
0x1, 0x14, 0x18,
|
||||
0x1, 0x15, 0x13,
|
||||
0x1, 0x16, 0x03,
|
||||
0x1, 0x17, 0x86,
|
||||
0x1, 0x18, 0x0A,
|
||||
0x1, 0x19, 0x09,
|
||||
0x1, 0x1A, 0x08,
|
||||
0x1, 0x1B, 0xC2,
|
||||
0x1, 0x1C, 0x03,
|
||||
0x1, 0x1D, 0x8F,
|
||||
0x1, 0x1E, 0x0A,
|
||||
0x1, 0x1F, 0x06,
|
||||
0x1, 0x20, 0x01,
|
||||
0x1, 0x21, 0x02,
|
||||
0x1, 0x22, 0x00,
|
||||
0x1, 0x23, 0xD5,
|
||||
0x1, 0x24, 0x18,
|
||||
0x1, 0x25, 0x22,
|
||||
0x1, 0x26, 0x01,
|
||||
0x1, 0x27, 0x82,
|
||||
0x1, 0x28, 0x00,
|
||||
0x1, 0x29, 0xD5,
|
||||
0x1, 0x2A, 0x18,
|
||||
0x1, 0x2B, 0x0B,
|
||||
0x1, 0x2C, 0x28,
|
||||
0x1, 0x2D, 0x78,
|
||||
0x1, 0x2E, 0x28,
|
||||
0x1, 0x2F, 0x91,
|
||||
0x1, 0x30, 0x00,
|
||||
0x1, 0x31, 0x0B,
|
||||
0x1, 0x32, 0x00,
|
||||
0x1, 0x33, 0x0B,
|
||||
0x1, 0x34, 0x00,
|
||||
0x1, 0x35, 0xA1,
|
||||
0x1, 0x36, 0x00,
|
||||
0x1, 0x37, 0xA0,
|
||||
0x1, 0x38, 0x00,
|
||||
0x1, 0x39, 0x04,
|
||||
0x1, 0x3A, 0x28,
|
||||
0x1, 0x3B, 0x30,
|
||||
0x1, 0x3C, 0x0C,
|
||||
0x1, 0x3D, 0x04,
|
||||
0x1, 0x3E, 0x0F,
|
||||
0x1, 0x3F, 0x79,
|
||||
0x1, 0x40, 0x28,
|
||||
0x1, 0x41, 0x1E,
|
||||
0x1, 0x42, 0x2F,
|
||||
0x1, 0x43, 0x87,
|
||||
0x1, 0x44, 0x00,
|
||||
0x1, 0x45, 0x0B,
|
||||
0x1, 0x46, 0x00,
|
||||
0x1, 0x47, 0x0B,
|
||||
0x1, 0x48, 0x00,
|
||||
0x1, 0x49, 0xA7,
|
||||
0x1, 0x4A, 0x00,
|
||||
0x1, 0x4B, 0xA6,
|
||||
0x1, 0x4C, 0x00,
|
||||
0x1, 0x4D, 0x04,
|
||||
0x1, 0x4E, 0x01,
|
||||
0x1, 0x4F, 0x00,
|
||||
0x1, 0x50, 0x00,
|
||||
0x1, 0x51, 0x80,
|
||||
0x1, 0x52, 0x09,
|
||||
0x1, 0x53, 0x08,
|
||||
0x1, 0x54, 0x01,
|
||||
0x1, 0x55, 0x00,
|
||||
0x1, 0x56, 0x0F,
|
||||
0x1, 0x57, 0x79,
|
||||
0x1, 0x58, 0x09,
|
||||
0x1, 0x59, 0x05,
|
||||
0x1, 0x5A, 0x00,
|
||||
0x1, 0x5B, 0x60,
|
||||
0x1, 0x5C, 0x05,
|
||||
0x1, 0x5D, 0xD1,
|
||||
0x1, 0x5E, 0x0C,
|
||||
0x1, 0x5F, 0x3C,
|
||||
0x1, 0x60, 0x00,
|
||||
0x1, 0x61, 0xD0,
|
||||
0x1, 0x62, 0x0B,
|
||||
0x1, 0x63, 0x03,
|
||||
0x1, 0x64, 0x28,
|
||||
0x1, 0x65, 0x10,
|
||||
0x1, 0x66, 0x2A,
|
||||
0x1, 0x67, 0x39,
|
||||
0x1, 0x68, 0x0B,
|
||||
0x1, 0x69, 0x02,
|
||||
0x1, 0x6A, 0x28,
|
||||
0x1, 0x6B, 0x10,
|
||||
0x1, 0x6C, 0x2A,
|
||||
0x1, 0x6D, 0x61,
|
||||
0x1, 0x6E, 0x0C,
|
||||
0x1, 0x6F, 0x00,
|
||||
0x1, 0x70, 0x0F,
|
||||
0x1, 0x71, 0x79,
|
||||
0x1, 0x72, 0x00,
|
||||
0x1, 0x73, 0x0B,
|
||||
0x1, 0x74, 0x00,
|
||||
0x1, 0x75, 0x0B,
|
||||
0x1, 0x76, 0x00,
|
||||
0x1, 0x77, 0xA1,
|
||||
0x1, 0x78, 0x00,
|
||||
0x1, 0x79, 0xA0,
|
||||
0x1, 0x7A, 0x00,
|
||||
0x1, 0x7B, 0x04,
|
||||
0x1, 0xFF, 0x04,
|
||||
0x1, 0x79, 0x1D,
|
||||
0x1, 0x7B, 0x27,
|
||||
0x1, 0x96, 0x0E,
|
||||
0x1, 0x97, 0xFE,
|
||||
0x1, 0x98, 0x03,
|
||||
0x1, 0x99, 0xEF,
|
||||
0x1, 0x9A, 0x02,
|
||||
0x1, 0x9B, 0x44,
|
||||
0x1, 0x73, 0x07,
|
||||
0x1, 0x70, 0x01,
|
||||
0x1, 0xff, 0x01,
|
||||
0x1, 0x00, 0x01,
|
||||
0x1, 0xff, 0x00,
|
||||
0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _VL53L0X_INTERRUPT_THRESHOLD_SETTINGS_H_ */
|
146
Api/core/inc/vl53l0x_tuning.h
Normal file
146
Api/core/inc/vl53l0x_tuning.h
Normal file
@ -0,0 +1,146 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2016, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
#ifndef _VL53L0X_TUNING_H_
|
||||
#define _VL53L0X_TUNING_H_
|
||||
|
||||
#include "vl53l0x_def.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
uint8_t DefaultTuningSettings[] = {
|
||||
|
||||
/* update 02/11/2015_v36 */
|
||||
0x01, 0xFF, 0x01,
|
||||
0x01, 0x00, 0x00,
|
||||
|
||||
0x01, 0xFF, 0x00,
|
||||
0x01, 0x09, 0x00,
|
||||
0x01, 0x10, 0x00,
|
||||
0x01, 0x11, 0x00,
|
||||
|
||||
0x01, 0x24, 0x01,
|
||||
0x01, 0x25, 0xff,
|
||||
0x01, 0x75, 0x00,
|
||||
|
||||
0x01, 0xFF, 0x01,
|
||||
0x01, 0x4e, 0x2c,
|
||||
0x01, 0x48, 0x00,
|
||||
0x01, 0x30, 0x20,
|
||||
|
||||
0x01, 0xFF, 0x00,
|
||||
0x01, 0x30, 0x09, /* mja changed from 0x64. */
|
||||
0x01, 0x54, 0x00,
|
||||
0x01, 0x31, 0x04,
|
||||
0x01, 0x32, 0x03,
|
||||
0x01, 0x40, 0x83,
|
||||
0x01, 0x46, 0x25,
|
||||
0x01, 0x60, 0x00,
|
||||
0x01, 0x27, 0x00,
|
||||
0x01, 0x50, 0x06,
|
||||
0x01, 0x51, 0x00,
|
||||
0x01, 0x52, 0x96,
|
||||
0x01, 0x56, 0x08,
|
||||
0x01, 0x57, 0x30,
|
||||
0x01, 0x61, 0x00,
|
||||
0x01, 0x62, 0x00,
|
||||
0x01, 0x64, 0x00,
|
||||
0x01, 0x65, 0x00,
|
||||
0x01, 0x66, 0xa0,
|
||||
|
||||
0x01, 0xFF, 0x01,
|
||||
0x01, 0x22, 0x32,
|
||||
0x01, 0x47, 0x14,
|
||||
0x01, 0x49, 0xff,
|
||||
0x01, 0x4a, 0x00,
|
||||
|
||||
0x01, 0xFF, 0x00,
|
||||
0x01, 0x7a, 0x0a,
|
||||
0x01, 0x7b, 0x00,
|
||||
0x01, 0x78, 0x21,
|
||||
|
||||
0x01, 0xFF, 0x01,
|
||||
0x01, 0x23, 0x34,
|
||||
0x01, 0x42, 0x00,
|
||||
0x01, 0x44, 0xff,
|
||||
0x01, 0x45, 0x26,
|
||||
0x01, 0x46, 0x05,
|
||||
0x01, 0x40, 0x40,
|
||||
0x01, 0x0E, 0x06,
|
||||
0x01, 0x20, 0x1a,
|
||||
0x01, 0x43, 0x40,
|
||||
|
||||
0x01, 0xFF, 0x00,
|
||||
0x01, 0x34, 0x03,
|
||||
0x01, 0x35, 0x44,
|
||||
|
||||
0x01, 0xFF, 0x01,
|
||||
0x01, 0x31, 0x04,
|
||||
0x01, 0x4b, 0x09,
|
||||
0x01, 0x4c, 0x05,
|
||||
0x01, 0x4d, 0x04,
|
||||
|
||||
|
||||
0x01, 0xFF, 0x00,
|
||||
0x01, 0x44, 0x00,
|
||||
0x01, 0x45, 0x20,
|
||||
0x01, 0x47, 0x08,
|
||||
0x01, 0x48, 0x28,
|
||||
0x01, 0x67, 0x00,
|
||||
0x01, 0x70, 0x04,
|
||||
0x01, 0x71, 0x01,
|
||||
0x01, 0x72, 0xfe,
|
||||
0x01, 0x76, 0x00,
|
||||
0x01, 0x77, 0x00,
|
||||
|
||||
0x01, 0xFF, 0x01,
|
||||
0x01, 0x0d, 0x01,
|
||||
|
||||
0x01, 0xFF, 0x00,
|
||||
0x01, 0x80, 0x01,
|
||||
0x01, 0x01, 0xF8,
|
||||
|
||||
0x01, 0xFF, 0x01,
|
||||
0x01, 0x8e, 0x01,
|
||||
0x01, 0x00, 0x01,
|
||||
0x01, 0xFF, 0x00,
|
||||
0x01, 0x80, 0x00,
|
||||
|
||||
0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _VL53L0X_TUNING_H_ */
|
3035
Api/core/src/vl53l0x_api.c
Normal file
3035
Api/core/src/vl53l0x_api.c
Normal file
File diff suppressed because it is too large
Load Diff
3048
Api/core/src/vl53l0x_api.c.bak
Normal file
3048
Api/core/src/vl53l0x_api.c.bak
Normal file
File diff suppressed because it is too large
Load Diff
1276
Api/core/src/vl53l0x_api_calibration.c
Normal file
1276
Api/core/src/vl53l0x_api_calibration.c
Normal file
File diff suppressed because it is too large
Load Diff
2239
Api/core/src/vl53l0x_api_core.c
Normal file
2239
Api/core/src/vl53l0x_api_core.c
Normal file
File diff suppressed because it is too large
Load Diff
42
Api/core/src/vl53l0x_api_ranging.c
Normal file
42
Api/core/src/vl53l0x_api_ranging.c
Normal file
@ -0,0 +1,42 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2016, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "vl53l0x_api.h"
|
||||
#include "vl53l0x_api_core.h"
|
||||
|
||||
|
||||
#ifndef __KERNEL__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#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__)
|
||||
|
462
Api/core/src/vl53l0x_api_strings.c
Normal file
462
Api/core/src/vl53l0x_api_strings.c
Normal file
@ -0,0 +1,462 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2016, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "vl53l0x_api.h"
|
||||
#include "vl53l0x_api_core.h"
|
||||
#include "vl53l0x_api_strings.h"
|
||||
|
||||
#ifndef __KERNEL__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#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__)
|
||||
|
||||
|
||||
VL53L0X_Error VL53L0X_check_part_used(VL53L0X_DEV Dev,
|
||||
uint8_t *Revision,
|
||||
VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo)
|
||||
{
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
uint8_t ModuleIdInt;
|
||||
char *ProductId_tmp;
|
||||
|
||||
LOG_FUNCTION_START("");
|
||||
|
||||
Status = VL53L0X_get_info_from_device(Dev, 2);
|
||||
|
||||
if (Status == VL53L0X_ERROR_NONE) {
|
||||
ModuleIdInt = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev, ModuleId);
|
||||
|
||||
if (ModuleIdInt == 0) {
|
||||
*Revision = 0;
|
||||
VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->ProductId, "");
|
||||
} else {
|
||||
*Revision = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev, Revision);
|
||||
ProductId_tmp = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev,
|
||||
ProductId);
|
||||
VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->ProductId, ProductId_tmp);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_FUNCTION_END(Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
VL53L0X_Error VL53L0X_get_device_info(VL53L0X_DEV Dev,
|
||||
VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo)
|
||||
{
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
uint8_t revision_id;
|
||||
uint8_t Revision;
|
||||
|
||||
Status = VL53L0X_check_part_used(Dev, &Revision, pVL53L0X_DeviceInfo);
|
||||
|
||||
if (Status == VL53L0X_ERROR_NONE) {
|
||||
if (Revision == 0) {
|
||||
VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->Name,
|
||||
VL53L0X_STRING_DEVICE_INFO_NAME_TS0);
|
||||
} else if ((Revision <= 34) && (Revision != 32)) {
|
||||
VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->Name,
|
||||
VL53L0X_STRING_DEVICE_INFO_NAME_TS1);
|
||||
} else if (Revision < 39) {
|
||||
VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->Name,
|
||||
VL53L0X_STRING_DEVICE_INFO_NAME_TS2);
|
||||
} else {
|
||||
VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->Name,
|
||||
VL53L0X_STRING_DEVICE_INFO_NAME_ES1);
|
||||
}
|
||||
|
||||
VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->Type,
|
||||
VL53L0X_STRING_DEVICE_INFO_TYPE);
|
||||
|
||||
}
|
||||
|
||||
if (Status == VL53L0X_ERROR_NONE) {
|
||||
Status = VL53L0X_RdByte(Dev, VL53L0X_REG_IDENTIFICATION_MODEL_ID,
|
||||
&pVL53L0X_DeviceInfo->ProductType);
|
||||
}
|
||||
|
||||
if (Status == VL53L0X_ERROR_NONE) {
|
||||
Status = VL53L0X_RdByte(Dev,
|
||||
VL53L0X_REG_IDENTIFICATION_REVISION_ID,
|
||||
&revision_id);
|
||||
pVL53L0X_DeviceInfo->ProductRevisionMajor = 1;
|
||||
pVL53L0X_DeviceInfo->ProductRevisionMinor =
|
||||
(revision_id & 0xF0) >> 4;
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
VL53L0X_Error VL53L0X_get_device_error_string(VL53L0X_DeviceError ErrorCode,
|
||||
char *pDeviceErrorString)
|
||||
{
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
|
||||
LOG_FUNCTION_START("");
|
||||
|
||||
switch (ErrorCode) {
|
||||
case VL53L0X_DEVICEERROR_NONE:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_NONE);
|
||||
break;
|
||||
case VL53L0X_DEVICEERROR_VCSELCONTINUITYTESTFAILURE:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE);
|
||||
break;
|
||||
case VL53L0X_DEVICEERROR_VCSELWATCHDOGTESTFAILURE:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE);
|
||||
break;
|
||||
case VL53L0X_DEVICEERROR_NOVHVVALUEFOUND:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_NOVHVVALUEFOUND);
|
||||
break;
|
||||
case VL53L0X_DEVICEERROR_MSRCNOTARGET:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_MSRCNOTARGET);
|
||||
break;
|
||||
case VL53L0X_DEVICEERROR_SNRCHECK:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_SNRCHECK);
|
||||
break;
|
||||
case VL53L0X_DEVICEERROR_RANGEPHASECHECK:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_RANGEPHASECHECK);
|
||||
break;
|
||||
case VL53L0X_DEVICEERROR_SIGMATHRESHOLDCHECK:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK);
|
||||
break;
|
||||
case VL53L0X_DEVICEERROR_TCC:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_TCC);
|
||||
break;
|
||||
case VL53L0X_DEVICEERROR_PHASECONSISTENCY:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_PHASECONSISTENCY);
|
||||
break;
|
||||
case VL53L0X_DEVICEERROR_MINCLIP:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_MINCLIP);
|
||||
break;
|
||||
case VL53L0X_DEVICEERROR_RANGECOMPLETE:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_RANGECOMPLETE);
|
||||
break;
|
||||
case VL53L0X_DEVICEERROR_ALGOUNDERFLOW:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_ALGOUNDERFLOW);
|
||||
break;
|
||||
case VL53L0X_DEVICEERROR_ALGOOVERFLOW:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_ALGOOVERFLOW);
|
||||
break;
|
||||
case VL53L0X_DEVICEERROR_RANGEIGNORETHRESHOLD:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD);
|
||||
break;
|
||||
|
||||
default:
|
||||
VL53L0X_COPYSTRING(pDeviceErrorString,
|
||||
VL53L0X_STRING_UNKNOW_ERROR_CODE);
|
||||
|
||||
}
|
||||
|
||||
LOG_FUNCTION_END(Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_get_range_status_string(uint8_t RangeStatus,
|
||||
char *pRangeStatusString)
|
||||
{
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
|
||||
LOG_FUNCTION_START("");
|
||||
|
||||
switch (RangeStatus) {
|
||||
case 0:
|
||||
VL53L0X_COPYSTRING(pRangeStatusString,
|
||||
VL53L0X_STRING_RANGESTATUS_RANGEVALID);
|
||||
break;
|
||||
case 1:
|
||||
VL53L0X_COPYSTRING(pRangeStatusString,
|
||||
VL53L0X_STRING_RANGESTATUS_SIGMA);
|
||||
break;
|
||||
case 2:
|
||||
VL53L0X_COPYSTRING(pRangeStatusString,
|
||||
VL53L0X_STRING_RANGESTATUS_SIGNAL);
|
||||
break;
|
||||
case 3:
|
||||
VL53L0X_COPYSTRING(pRangeStatusString,
|
||||
VL53L0X_STRING_RANGESTATUS_MINRANGE);
|
||||
break;
|
||||
case 4:
|
||||
VL53L0X_COPYSTRING(pRangeStatusString,
|
||||
VL53L0X_STRING_RANGESTATUS_PHASE);
|
||||
break;
|
||||
case 5:
|
||||
VL53L0X_COPYSTRING(pRangeStatusString,
|
||||
VL53L0X_STRING_RANGESTATUS_HW);
|
||||
break;
|
||||
|
||||
default: /**/
|
||||
VL53L0X_COPYSTRING(pRangeStatusString,
|
||||
VL53L0X_STRING_RANGESTATUS_NONE);
|
||||
}
|
||||
|
||||
LOG_FUNCTION_END(Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_get_pal_error_string(VL53L0X_Error PalErrorCode,
|
||||
char *pPalErrorString)
|
||||
{
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
|
||||
LOG_FUNCTION_START("");
|
||||
|
||||
switch (PalErrorCode) {
|
||||
case VL53L0X_ERROR_NONE:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_NONE);
|
||||
break;
|
||||
case VL53L0X_ERROR_CALIBRATION_WARNING:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_CALIBRATION_WARNING);
|
||||
break;
|
||||
case VL53L0X_ERROR_MIN_CLIPPED:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_MIN_CLIPPED);
|
||||
break;
|
||||
case VL53L0X_ERROR_UNDEFINED:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_UNDEFINED);
|
||||
break;
|
||||
case VL53L0X_ERROR_INVALID_PARAMS:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_INVALID_PARAMS);
|
||||
break;
|
||||
case VL53L0X_ERROR_NOT_SUPPORTED:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_NOT_SUPPORTED);
|
||||
break;
|
||||
case VL53L0X_ERROR_INTERRUPT_NOT_CLEARED:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_INTERRUPT_NOT_CLEARED);
|
||||
break;
|
||||
case VL53L0X_ERROR_RANGE_ERROR:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_RANGE_ERROR);
|
||||
break;
|
||||
case VL53L0X_ERROR_TIME_OUT:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_TIME_OUT);
|
||||
break;
|
||||
case VL53L0X_ERROR_MODE_NOT_SUPPORTED:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_MODE_NOT_SUPPORTED);
|
||||
break;
|
||||
case VL53L0X_ERROR_BUFFER_TOO_SMALL:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_BUFFER_TOO_SMALL);
|
||||
break;
|
||||
case VL53L0X_ERROR_GPIO_NOT_EXISTING:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_GPIO_NOT_EXISTING);
|
||||
break;
|
||||
case VL53L0X_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED);
|
||||
break;
|
||||
case VL53L0X_ERROR_CONTROL_INTERFACE:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_CONTROL_INTERFACE);
|
||||
break;
|
||||
case VL53L0X_ERROR_INVALID_COMMAND:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_INVALID_COMMAND);
|
||||
break;
|
||||
case VL53L0X_ERROR_DIVISION_BY_ZERO:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_DIVISION_BY_ZERO);
|
||||
break;
|
||||
case VL53L0X_ERROR_REF_SPAD_INIT:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_REF_SPAD_INIT);
|
||||
break;
|
||||
case VL53L0X_ERROR_NOT_IMPLEMENTED:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_ERROR_NOT_IMPLEMENTED);
|
||||
break;
|
||||
|
||||
default:
|
||||
VL53L0X_COPYSTRING(pPalErrorString,
|
||||
VL53L0X_STRING_UNKNOW_ERROR_CODE);
|
||||
}
|
||||
|
||||
LOG_FUNCTION_END(Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_get_pal_state_string(VL53L0X_State PalStateCode,
|
||||
char *pPalStateString)
|
||||
{
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
|
||||
LOG_FUNCTION_START("");
|
||||
|
||||
switch (PalStateCode) {
|
||||
case VL53L0X_STATE_POWERDOWN:
|
||||
VL53L0X_COPYSTRING(pPalStateString,
|
||||
VL53L0X_STRING_STATE_POWERDOWN);
|
||||
break;
|
||||
case VL53L0X_STATE_WAIT_STATICINIT:
|
||||
VL53L0X_COPYSTRING(pPalStateString,
|
||||
VL53L0X_STRING_STATE_WAIT_STATICINIT);
|
||||
break;
|
||||
case VL53L0X_STATE_STANDBY:
|
||||
VL53L0X_COPYSTRING(pPalStateString,
|
||||
VL53L0X_STRING_STATE_STANDBY);
|
||||
break;
|
||||
case VL53L0X_STATE_IDLE:
|
||||
VL53L0X_COPYSTRING(pPalStateString,
|
||||
VL53L0X_STRING_STATE_IDLE);
|
||||
break;
|
||||
case VL53L0X_STATE_RUNNING:
|
||||
VL53L0X_COPYSTRING(pPalStateString,
|
||||
VL53L0X_STRING_STATE_RUNNING);
|
||||
break;
|
||||
case VL53L0X_STATE_UNKNOWN:
|
||||
VL53L0X_COPYSTRING(pPalStateString,
|
||||
VL53L0X_STRING_STATE_UNKNOWN);
|
||||
break;
|
||||
case VL53L0X_STATE_ERROR:
|
||||
VL53L0X_COPYSTRING(pPalStateString,
|
||||
VL53L0X_STRING_STATE_ERROR);
|
||||
break;
|
||||
|
||||
default:
|
||||
VL53L0X_COPYSTRING(pPalStateString,
|
||||
VL53L0X_STRING_STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
LOG_FUNCTION_END(Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_get_sequence_steps_info(
|
||||
VL53L0X_SequenceStepId SequenceStepId,
|
||||
char *pSequenceStepsString)
|
||||
{
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
LOG_FUNCTION_START("");
|
||||
|
||||
switch (SequenceStepId) {
|
||||
case VL53L0X_SEQUENCESTEP_TCC:
|
||||
VL53L0X_COPYSTRING(pSequenceStepsString,
|
||||
VL53L0X_STRING_SEQUENCESTEP_TCC);
|
||||
break;
|
||||
case VL53L0X_SEQUENCESTEP_DSS:
|
||||
VL53L0X_COPYSTRING(pSequenceStepsString,
|
||||
VL53L0X_STRING_SEQUENCESTEP_DSS);
|
||||
break;
|
||||
case VL53L0X_SEQUENCESTEP_MSRC:
|
||||
VL53L0X_COPYSTRING(pSequenceStepsString,
|
||||
VL53L0X_STRING_SEQUENCESTEP_MSRC);
|
||||
break;
|
||||
case VL53L0X_SEQUENCESTEP_PRE_RANGE:
|
||||
VL53L0X_COPYSTRING(pSequenceStepsString,
|
||||
VL53L0X_STRING_SEQUENCESTEP_PRE_RANGE);
|
||||
break;
|
||||
case VL53L0X_SEQUENCESTEP_FINAL_RANGE:
|
||||
VL53L0X_COPYSTRING(pSequenceStepsString,
|
||||
VL53L0X_STRING_SEQUENCESTEP_FINAL_RANGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
Status = VL53L0X_ERROR_INVALID_PARAMS;
|
||||
}
|
||||
|
||||
LOG_FUNCTION_END(Status);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
VL53L0X_Error VL53L0X_get_limit_check_info(VL53L0X_DEV Dev, uint16_t LimitCheckId,
|
||||
char *pLimitCheckString)
|
||||
{
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
|
||||
LOG_FUNCTION_START("");
|
||||
|
||||
switch (LimitCheckId) {
|
||||
case VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE:
|
||||
VL53L0X_COPYSTRING(pLimitCheckString,
|
||||
VL53L0X_STRING_CHECKENABLE_SIGMA_FINAL_RANGE);
|
||||
break;
|
||||
case VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
|
||||
VL53L0X_COPYSTRING(pLimitCheckString,
|
||||
VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE);
|
||||
break;
|
||||
case VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP:
|
||||
VL53L0X_COPYSTRING(pLimitCheckString,
|
||||
VL53L0X_STRING_CHECKENABLE_SIGNAL_REF_CLIP);
|
||||
break;
|
||||
case VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
|
||||
VL53L0X_COPYSTRING(pLimitCheckString,
|
||||
VL53L0X_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD);
|
||||
break;
|
||||
|
||||
case VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC:
|
||||
VL53L0X_COPYSTRING(pLimitCheckString,
|
||||
VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_MSRC);
|
||||
break;
|
||||
|
||||
case VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE:
|
||||
VL53L0X_COPYSTRING(pLimitCheckString,
|
||||
VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_PRE_RANGE);
|
||||
break;
|
||||
|
||||
default:
|
||||
VL53L0X_COPYSTRING(pLimitCheckString,
|
||||
VL53L0X_STRING_UNKNOW_ERROR_CODE);
|
||||
|
||||
}
|
||||
|
||||
LOG_FUNCTION_END(Status);
|
||||
return Status;
|
||||
}
|
404
Api/platform/inc/vl53l0x_i2c_platform.h
Normal file
404
Api/platform/inc/vl53l0x_i2c_platform.h
Normal file
@ -0,0 +1,404 @@
|
||||
/*
|
||||
* COPYRIGHT (C) STMicroelectronics 2014. All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* STMicroelectronics ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license agreement you entered into
|
||||
* with STMicroelectronics
|
||||
*
|
||||
* Programming Golden Rule: Keep it Simple!
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file VL53L0X_platform.h
|
||||
* @brief Function prototype definitions for Ewok Platform layer.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _VL53L0X_I2C_PLATFORM_H_
|
||||
#define _VL53L0X_I2C_PLATFORM_H_
|
||||
|
||||
#include "vl53l0x_def.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Include uint8_t, unit16_t etc definitions
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
/**
|
||||
* @brief Typedef defining .\n
|
||||
* The developer shoud modify this to suit the platform being deployed.
|
||||
*
|
||||
*/
|
||||
|
||||
// enum {TRUE = true, FALSE = false};
|
||||
|
||||
/**
|
||||
* @brief Typedef defining 8 bit unsigned char type.\n
|
||||
* The developer shoud modify this to suit the platform being deployed.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef bool_t
|
||||
typedef unsigned char bool_t;
|
||||
#endif
|
||||
|
||||
|
||||
#define I2C 0x01
|
||||
#define SPI 0x00
|
||||
|
||||
#define COMMS_BUFFER_SIZE 64 // MUST be the same size as the SV task buffer
|
||||
|
||||
#define BYTES_PER_WORD 2
|
||||
#define BYTES_PER_DWORD 4
|
||||
|
||||
#define VL53L0X_MAX_STRING_LENGTH_PLT 256
|
||||
|
||||
/**
|
||||
* @brief Initialise platform comms.
|
||||
*
|
||||
* @param comms_type - selects between I2C and SPI
|
||||
* @param comms_speed_khz - unsigned short containing the I2C speed in kHz
|
||||
*
|
||||
* @return status - status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_comms_initialise(uint8_t comms_type,
|
||||
uint16_t comms_speed_khz);
|
||||
|
||||
/**
|
||||
* @brief Close platform comms.
|
||||
*
|
||||
* @return status - status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_comms_close(void);
|
||||
|
||||
/**
|
||||
* @brief Cycle Power to Device
|
||||
*
|
||||
* @return status - status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_cycle_power(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Writes the supplied byte buffer to the device
|
||||
*
|
||||
* Wrapper for SystemVerilog Write Multi task
|
||||
*
|
||||
* @code
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* uint8_t *spad_enables;
|
||||
*
|
||||
* int status = VL53L0X_write_multi(RET_SPAD_EN_0, spad_enables, 36);
|
||||
*
|
||||
* @endcode
|
||||
*
|
||||
* @param address - uint8_t device address value
|
||||
* @param index - uint8_t register index value
|
||||
* @param pdata - pointer to uint8_t buffer containing the data to be written
|
||||
* @param count - number of bytes in the supplied byte buffer
|
||||
*
|
||||
* @return status - SystemVerilog status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_write_multi(uint8_t address, uint8_t index, uint8_t *pdata, int32_t count);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reads the requested number of bytes from the device
|
||||
*
|
||||
* Wrapper for SystemVerilog Read Multi task
|
||||
*
|
||||
* @code
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* uint8_t buffer[COMMS_BUFFER_SIZE];
|
||||
*
|
||||
* int status = status = VL53L0X_read_multi(DEVICE_ID, buffer, 2)
|
||||
*
|
||||
* @endcode
|
||||
*
|
||||
* @param address - uint8_t device address value
|
||||
* @param index - uint8_t register index value
|
||||
* @param pdata - pointer to the uint8_t buffer to store read data
|
||||
* @param count - number of uint8_t's to read
|
||||
*
|
||||
* @return status - SystemVerilog status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_read_multi(uint8_t address, uint8_t index, uint8_t *pdata, int32_t count);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Writes a single byte to the device
|
||||
*
|
||||
* Wrapper for SystemVerilog Write Byte task
|
||||
*
|
||||
* @code
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* uint8_t page_number = MAIN_SELECT_PAGE;
|
||||
*
|
||||
* int status = VL53L0X_write_byte(PAGE_SELECT, page_number);
|
||||
*
|
||||
* @endcode
|
||||
*
|
||||
* @param address - uint8_t device address value
|
||||
* @param index - uint8_t register index value
|
||||
* @param data - uint8_t data value to write
|
||||
*
|
||||
* @return status - SystemVerilog status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_write_byte(uint8_t address, uint8_t index, uint8_t data);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Writes a single word (16-bit unsigned) to the device
|
||||
*
|
||||
* Manages the big-endian nature of the device (first byte written is the MS byte).
|
||||
* Uses SystemVerilog Write Multi task.
|
||||
*
|
||||
* @code
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* uint16_t nvm_ctrl_pulse_width = 0x0004;
|
||||
*
|
||||
* int status = VL53L0X_write_word(NVM_CTRL__PULSE_WIDTH_MSB, nvm_ctrl_pulse_width);
|
||||
*
|
||||
* @endcode
|
||||
*
|
||||
* @param address - uint8_t device address value
|
||||
* @param index - uint8_t register index value
|
||||
* @param data - uin16_t data value write
|
||||
*
|
||||
* @return status - SystemVerilog status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_write_word(uint8_t address, uint8_t index, uint16_t data);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Writes a single dword (32-bit unsigned) to the device
|
||||
*
|
||||
* Manages the big-endian nature of the device (first byte written is the MS byte).
|
||||
* Uses SystemVerilog Write Multi task.
|
||||
*
|
||||
* @code
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* uint32_t nvm_data = 0x0004;
|
||||
*
|
||||
* int status = VL53L0X_write_dword(NVM_CTRL__DATAIN_MMM, nvm_data);
|
||||
*
|
||||
* @endcode
|
||||
*
|
||||
* @param address - uint8_t device address value
|
||||
* @param index - uint8_t register index value
|
||||
* @param data - uint32_t data value to write
|
||||
*
|
||||
* @return status - SystemVerilog status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_write_dword(uint8_t address, uint8_t index, uint32_t data);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reads a single byte from the device
|
||||
*
|
||||
* Uses SystemVerilog Read Byte task.
|
||||
*
|
||||
* @code
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* uint8_t device_status = 0;
|
||||
*
|
||||
* int status = VL53L0X_read_byte(STATUS, &device_status);
|
||||
*
|
||||
* @endcode
|
||||
*
|
||||
* @param address - uint8_t device address value
|
||||
* @param index - uint8_t register index value
|
||||
* @param pdata - pointer to uint8_t data value
|
||||
*
|
||||
* @return status - SystemVerilog status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_read_byte(uint8_t address, uint8_t index, uint8_t *pdata);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reads a single word (16-bit unsigned) from the device
|
||||
*
|
||||
* Manages the big-endian nature of the device (first byte read is the MS byte).
|
||||
* Uses SystemVerilog Read Multi task.
|
||||
*
|
||||
* @code
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* uint16_t timeout = 0;
|
||||
*
|
||||
* int status = VL53L0X_read_word(TIMEOUT_OVERALL_PERIODS_MSB, &timeout);
|
||||
*
|
||||
* @endcode
|
||||
*
|
||||
* @param address - uint8_t device address value
|
||||
* @param index - uint8_t register index value
|
||||
* @param pdata - pointer to uint16_t data value
|
||||
*
|
||||
* @return status - SystemVerilog status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_read_word(uint8_t address, uint8_t index, uint16_t *pdata);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reads a single dword (32-bit unsigned) from the device
|
||||
*
|
||||
* Manages the big-endian nature of the device (first byte read is the MS byte).
|
||||
* Uses SystemVerilog Read Multi task.
|
||||
*
|
||||
* @code
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* uint32_t range_1 = 0;
|
||||
*
|
||||
* int status = VL53L0X_read_dword(RANGE_1_MMM, &range_1);
|
||||
*
|
||||
* @endcode
|
||||
*
|
||||
* @param address - uint8_t device address value
|
||||
* @param index - uint8_t register index value
|
||||
* @param pdata - pointer to uint32_t data value
|
||||
*
|
||||
* @return status - SystemVerilog status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_read_dword(uint8_t address, uint8_t index, uint32_t *pdata);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Implements a programmable wait in us
|
||||
*
|
||||
* Wrapper for SystemVerilog Wait in micro seconds task
|
||||
*
|
||||
* @param wait_us - integer wait in micro seconds
|
||||
*
|
||||
* @return status - SystemVerilog status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_platform_wait_us(int32_t wait_us);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Implements a programmable wait in ms
|
||||
*
|
||||
* Wrapper for SystemVerilog Wait in milli seconds task
|
||||
*
|
||||
* @param wait_ms - integer wait in milli seconds
|
||||
*
|
||||
* @return status - SystemVerilog status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_wait_ms(int32_t wait_ms);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set GPIO value
|
||||
*
|
||||
* @param level - input level - either 0 or 1
|
||||
*
|
||||
* @return status - SystemVerilog status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_set_gpio(uint8_t level);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get GPIO value
|
||||
*
|
||||
* @param plevel - uint8_t pointer to store GPIO level (0 or 1)
|
||||
*
|
||||
* @return status - SystemVerilog status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_get_gpio(uint8_t *plevel);
|
||||
|
||||
/**
|
||||
* @brief Release force on GPIO
|
||||
*
|
||||
* @return status - SystemVerilog status 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_release_gpio(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the frequency of the timer used for ranging results time stamps
|
||||
*
|
||||
* @param[out] ptimer_freq_hz : pointer for timer frequency
|
||||
*
|
||||
* @return status : 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_get_timer_frequency(int32_t *ptimer_freq_hz);
|
||||
|
||||
/**
|
||||
* @brief Get the timer value in units of timer_freq_hz (see VL53L0X_get_timestamp_frequency())
|
||||
*
|
||||
* @param[out] ptimer_count : pointer for timer count value
|
||||
*
|
||||
* @return status : 0 = ok, 1 = error
|
||||
*
|
||||
*/
|
||||
|
||||
int32_t VL53L0X_get_timer_value(int32_t *ptimer_count);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_VL53L0X_I2C_PLATFORM_H_
|
||||
|
241
Api/platform/inc/vl53l0x_platform.h
Normal file
241
Api/platform/inc/vl53l0x_platform.h
Normal file
@ -0,0 +1,241 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2015, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
#ifndef _VL53L0X_PLATFORM_H_
|
||||
#define _VL53L0X_PLATFORM_H_
|
||||
|
||||
#include "vl53l0x_def.h"
|
||||
#include "vl53l0x_platform_log.h"
|
||||
#include "vl53l0x_i2c_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file vl53l0x_platform.h
|
||||
*
|
||||
* @brief All end user OS/platform/application porting
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup VL53L0X_platform_group VL53L0X Platform Functions
|
||||
* @brief VL53L0X Platform Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @struct VL53L0X_Dev_t
|
||||
* @brief Generic PAL device type that does link between API and platform abstraction layer
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
VL53L0X_DevData_t Data; /*!< embed ST Ewok Dev data as "Data"*/
|
||||
|
||||
/*!< user specific field */
|
||||
uint8_t I2cDevAddr; /*!< i2c device address user specific field */
|
||||
uint8_t comms_type; /*!< Type of comms : VL53L0X_COMMS_I2C or VL53L0X_COMMS_SPI */
|
||||
uint16_t comms_speed_khz; /*!< Comms speed [kHz] : typically 400kHz for I2C */
|
||||
|
||||
} VL53L0X_Dev_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Declare the device Handle as a pointer of the structure @a VL53L0X_Dev_t.
|
||||
*
|
||||
*/
|
||||
typedef VL53L0X_Dev_t* VL53L0X_DEV;
|
||||
|
||||
/**
|
||||
* @def PALDevDataGet
|
||||
* @brief Get ST private structure @a VL53L0X_DevData_t data access
|
||||
*
|
||||
* @param Dev Device Handle
|
||||
* @param field ST structure field name
|
||||
* It maybe used and as real data "ref" not just as "get" for sub-structure item
|
||||
* like PALDevDataGet(FilterData.field)[i] or PALDevDataGet(FilterData.MeasurementIndex)++
|
||||
*/
|
||||
#define PALDevDataGet(Dev, field) (Dev->Data.field)
|
||||
|
||||
/**
|
||||
* @def PALDevDataSet(Dev, field, data)
|
||||
* @brief Set ST private structure @a VL53L0X_DevData_t data field
|
||||
* @param Dev Device Handle
|
||||
* @param field ST structure field name
|
||||
* @param data Data to be set
|
||||
*/
|
||||
#define PALDevDataSet(Dev, field, data) (Dev->Data.field)=(data)
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup VL53L0X_registerAccess_group PAL Register Access Functions
|
||||
* @brief PAL Register Access Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Lock comms interface to serialize all commands to a shared I2C interface for a specific device
|
||||
* @param Dev Device Handle
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_LockSequenceAccess(VL53L0X_DEV Dev);
|
||||
|
||||
/**
|
||||
* Unlock comms interface to serialize all commands to a shared I2C interface for a specific device
|
||||
* @param Dev Device Handle
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_UnlockSequenceAccess(VL53L0X_DEV Dev);
|
||||
|
||||
|
||||
/**
|
||||
* Writes the supplied byte buffer to the device
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param pdata Pointer to uint8_t buffer containing the data to be written
|
||||
* @param count Number of bytes in the supplied byte buffer
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_WriteMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count);
|
||||
|
||||
/**
|
||||
* Reads the requested number of bytes from the device
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param pdata Pointer to the uint8_t buffer to store read data
|
||||
* @param count Number of uint8_t's to read
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count);
|
||||
|
||||
/**
|
||||
* Write single byte register
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param data 8 bit register data
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_WrByte(VL53L0X_DEV Dev, uint8_t index, uint8_t data);
|
||||
|
||||
/**
|
||||
* Write word register
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param data 16 bit register data
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_WrWord(VL53L0X_DEV Dev, uint8_t index, uint16_t data);
|
||||
|
||||
/**
|
||||
* Write double word (4 byte) register
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param data 32 bit register data
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_WrDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t data);
|
||||
|
||||
/**
|
||||
* Read single byte register
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param data pointer to 8 bit data
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_RdByte(VL53L0X_DEV Dev, uint8_t index, uint8_t *data);
|
||||
|
||||
/**
|
||||
* Read word (2byte) register
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param data pointer to 16 bit data
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_RdWord(VL53L0X_DEV Dev, uint8_t index, uint16_t *data);
|
||||
|
||||
/**
|
||||
* Read dword (4byte) register
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param data pointer to 32 bit data
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_RdDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t *data);
|
||||
|
||||
/**
|
||||
* Threat safe Update (read/modify/write) single byte register
|
||||
*
|
||||
* Final_reg = (Initial_reg & and_data) |or_data
|
||||
*
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param AndData 8 bit and data
|
||||
* @param OrData 8 bit or data
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_UpdateByte(VL53L0X_DEV Dev, uint8_t index, uint8_t AndData, uint8_t OrData);
|
||||
|
||||
/** @} end of VL53L0X_registerAccess_group */
|
||||
|
||||
|
||||
/**
|
||||
* @brief execute delay in all polling API call
|
||||
*
|
||||
* A typical multi-thread or RTOs implementation is to sleep the task for some 5ms (with 100Hz max rate faster polling is not needed)
|
||||
* if nothing specific is need you can define it as an empty/void macro
|
||||
* @code
|
||||
* #define VL53L0X_PollingDelay(...) (void)0
|
||||
* @endcode
|
||||
* @param Dev Device Handle
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_PollingDelay(VL53L0X_DEV Dev); /* usually best implemented as a real function */
|
||||
|
||||
/** @} end of VL53L0X_platform_group */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _VL53L0X_PLATFORM_H_ */
|
||||
|
||||
|
||||
|
118
Api/platform/inc/vl53l0x_platform_log.h
Normal file
118
Api/platform/inc/vl53l0x_platform_log.h
Normal file
@ -0,0 +1,118 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2015, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
#ifndef _VL53L0X_PLATFORM_LOG_H_
|
||||
#define _VL53L0X_PLATFORM_LOG_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
/* LOG Functions */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file vl53l0x_platform_log.h
|
||||
*
|
||||
* @brief platform log function definition
|
||||
*/
|
||||
|
||||
//#define VL53L0X_LOG_ENABLE 0
|
||||
|
||||
enum {
|
||||
TRACE_LEVEL_NONE,
|
||||
TRACE_LEVEL_ERRORS,
|
||||
TRACE_LEVEL_WARNING,
|
||||
TRACE_LEVEL_INFO,
|
||||
TRACE_LEVEL_DEBUG,
|
||||
TRACE_LEVEL_ALL,
|
||||
TRACE_LEVEL_IGNORE
|
||||
};
|
||||
|
||||
enum {
|
||||
TRACE_FUNCTION_NONE = 0,
|
||||
TRACE_FUNCTION_I2C = 1,
|
||||
TRACE_FUNCTION_ALL = 0x7fffffff //all bits except sign
|
||||
};
|
||||
|
||||
enum {
|
||||
TRACE_MODULE_NONE = 0x0,
|
||||
TRACE_MODULE_API = 0x1,
|
||||
TRACE_MODULE_PLATFORM = 0x2,
|
||||
TRACE_MODULE_ALL = 0x7fffffff //all bits except sign
|
||||
};
|
||||
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
extern uint32_t _trace_level;
|
||||
|
||||
|
||||
|
||||
int32_t VL53L0X_trace_config(char *filename, uint32_t modules, uint32_t level, uint32_t functions);
|
||||
|
||||
void trace_print_module_function(uint32_t module, uint32_t level, uint32_t function, const char *format, ...);
|
||||
|
||||
|
||||
//extern FILE * log_file;
|
||||
|
||||
#define LOG_GET_TIME() (int)clock()
|
||||
|
||||
#define _LOG_FUNCTION_START(module, fmt, ... ) \
|
||||
trace_print_module_function(module, _trace_level, TRACE_FUNCTION_ALL, "%ld <START> %s "fmt"\n", LOG_GET_TIME(), __FUNCTION__, ##__VA_ARGS__);
|
||||
|
||||
#define _LOG_FUNCTION_END(module, status, ... )\
|
||||
trace_print_module_function(module, _trace_level, TRACE_FUNCTION_ALL, "%ld <END> %s %d\n", LOG_GET_TIME(), __FUNCTION__, (int)status, ##__VA_ARGS__)
|
||||
|
||||
#define _LOG_FUNCTION_END_FMT(module, status, fmt, ... )\
|
||||
trace_print_module_function(module, _trace_level, TRACE_FUNCTION_ALL, "%ld <END> %s %d "fmt"\n", LOG_GET_TIME(), __FUNCTION__, (int)status,##__VA_ARGS__)
|
||||
|
||||
// __func__ is gcc only
|
||||
//#define VL53L0X_ErrLog( fmt, ...) fprintf(stderr, "VL53L0X_ErrLog %s" fmt "\n", __func__, ##__VA_ARGS__)
|
||||
|
||||
#else /* VL53L0X_LOG_ENABLE no logging */
|
||||
#define VL53L0X_ErrLog(...) (void)0
|
||||
#define _LOG_FUNCTION_START(module, fmt, ... ) (void)0
|
||||
#define _LOG_FUNCTION_END(module, status, ... ) (void)0
|
||||
#define _LOG_FUNCTION_END_FMT(module, status, fmt, ... ) (void)0
|
||||
#endif /* else */
|
||||
|
||||
#define VL53L0X_COPYSTRING(str, ...) strcpy(str, ##__VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _VL53L0X_PLATFORM_LOG_H_ */
|
||||
|
||||
|
||||
|
111
Api/platform/inc/vl53l0x_types.h
Normal file
111
Api/platform/inc/vl53l0x_types.h
Normal file
@ -0,0 +1,111 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2015, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
/**
|
||||
* @file vl53l0x_types.h
|
||||
* @brief VL53L0X types definition
|
||||
*/
|
||||
|
||||
#ifndef VL53L0X_TYPES_H_
|
||||
#define VL53L0X_TYPES_H_
|
||||
|
||||
/** @defgroup porting_type Basic type definition
|
||||
* @ingroup VL53L0X_platform_group
|
||||
*
|
||||
* @brief file vl53l0x_types.h files hold basic type definition that may requires porting
|
||||
*
|
||||
* contains type that must be defined for the platform\n
|
||||
* when target platform and compiler provide stdint.h and stddef.h it is enough to include it.\n
|
||||
* If stdint.h is not available review and adapt all signed and unsigned 8/16/32 bits basic types. \n
|
||||
* If stddef.h is not available review and adapt NULL definition .
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef NULL
|
||||
#error "Error NULL definition should be done. Please add required include "
|
||||
#endif
|
||||
|
||||
|
||||
#if ! defined(STDINT_H) && !defined(_GCC_STDINT_H) &&!defined(__STDINT_DECLS) && !defined(_GCC_WRAP_STDINT_H)
|
||||
|
||||
#pragma message("Please review type definition of STDINT define for your platform and add to list above ")
|
||||
|
||||
/*
|
||||
* target platform do not provide stdint or use a different #define than above
|
||||
* to avoid seeing the message below addapt the #define list above or implement
|
||||
* all type and delete these pragma
|
||||
*/
|
||||
|
||||
/** \ingroup VL53L0X_portingType_group
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
typedef unsigned long long uint64_t;
|
||||
|
||||
|
||||
/** @brief Typedef defining 32 bit unsigned int type.\n
|
||||
* The developer should modify this to suit the platform being deployed.
|
||||
*/
|
||||
typedef unsigned int uint32_t;
|
||||
|
||||
/** @brief Typedef defining 32 bit int type.\n
|
||||
* The developer should modify this to suit the platform being deployed.
|
||||
*/
|
||||
typedef int int32_t;
|
||||
|
||||
/** @brief Typedef defining 16 bit unsigned short type.\n
|
||||
* The developer should modify this to suit the platform being deployed.
|
||||
*/
|
||||
typedef unsigned short uint16_t;
|
||||
|
||||
/** @brief Typedef defining 16 bit short type.\n
|
||||
* The developer should modify this to suit the platform being deployed.
|
||||
*/
|
||||
typedef short int16_t;
|
||||
|
||||
/** @brief Typedef defining 8 bit unsigned char type.\n
|
||||
* The developer should modify this to suit the platform being deployed.
|
||||
*/
|
||||
typedef unsigned char uint8_t;
|
||||
|
||||
/** @brief Typedef defining 8 bit char type.\n
|
||||
* The developer should modify this to suit the platform being deployed.
|
||||
*/
|
||||
typedef signed char int8_t;
|
||||
|
||||
/** @} */
|
||||
#endif /* _STDINT_H */
|
||||
|
||||
|
||||
/** use where fractional values are expected
|
||||
*
|
||||
* Given a floating point value f it's .16 bit point is (int)(f*(1<<16))*/
|
||||
typedef uint32_t FixPoint1616_t;
|
||||
|
||||
#endif /* VL53L0X_TYPES_H_ */
|
737
Api/platform/src/vl53l0x_i2c_win_serial_comms.c
Normal file
737
Api/platform/src/vl53l0x_i2c_win_serial_comms.c
Normal file
@ -0,0 +1,737 @@
|
||||
/*
|
||||
* COPYRIGHT (C) STMicroelectronics 2015. All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* STMicroelectronics ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license agreement you entered into
|
||||
* with STMicroelectronics
|
||||
*
|
||||
* Programming Golden Rule: Keep it Simple!
|
||||
*
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \file VL53L0X_platform.c
|
||||
* \brief Code function defintions for Doppler Testchip Platform Layer
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h> // sprintf(), vsnprintf(), printf()
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#include "vl53l0x_i2c_platform.h"
|
||||
#include "vl53l0x_def.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <time.h>
|
||||
#include "SERIAL_COMMS.h"
|
||||
//#include "comms_platform.h"
|
||||
|
||||
#include "vl53l0x_platform_log.h"
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
#define trace_print(level, ...) trace_print_module_function(TRACE_MODULE_PLATFORM, level, TRACE_FUNCTION_NONE, ##__VA_ARGS__)
|
||||
#define trace_i2c(...) trace_print_module_function(TRACE_MODULE_NONE, TRACE_LEVEL_NONE, TRACE_FUNCTION_I2C, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
char debug_string[VL53L0X_MAX_STRING_LENGTH_PLT];
|
||||
|
||||
uint8_t cached_page = 0;
|
||||
|
||||
#define MIN_COMMS_VERSION_MAJOR 1
|
||||
#define MIN_COMMS_VERSION_MINOR 8
|
||||
#define MIN_COMMS_VERSION_BUILD 1
|
||||
#define MIN_COMMS_VERSION_REVISION 0
|
||||
|
||||
|
||||
#define MAX_STR_SIZE 255
|
||||
#define MAX_MSG_SIZE 100
|
||||
#define MAX_DEVICES 4
|
||||
#define STATUS_OK 0x00
|
||||
#define STATUS_FAIL 0x01
|
||||
|
||||
static HANDLE ghMutex;
|
||||
|
||||
static unsigned char _dataBytes[MAX_MSG_SIZE];
|
||||
|
||||
bool_t _check_min_version(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int VL53L0X_i2c_init(char *comPortStr, unsigned int baudRate) // mja
|
||||
{
|
||||
const int cArgc = 7;
|
||||
int argc = cArgc;
|
||||
unsigned int deviceCount = 0;
|
||||
unsigned int comPortId = 0;
|
||||
char errorText[MAX_STR_SIZE];
|
||||
unsigned char devIds[MAX_DEVICES];
|
||||
unsigned int status = STATUS_FAIL;
|
||||
char comPortTmpStr[MAX_STR_SIZE] = "";
|
||||
char baudRateTmpStr[MAX_STR_SIZE] = "";
|
||||
//char tmpStr[MAX_STR_SIZE] = "";
|
||||
//static char argv[7][MAX_STR_SIZE];
|
||||
int i = 0;
|
||||
DWORD dwWaitResult;
|
||||
char **argv = NULL;
|
||||
int ownsMutex = 0;
|
||||
|
||||
|
||||
if(ghMutex == NULL)
|
||||
{
|
||||
ghMutex = CreateMutex(NULL, FALSE, NULL);
|
||||
}
|
||||
|
||||
dwWaitResult = WaitForSingleObject(ghMutex, INFINITE);
|
||||
|
||||
if(dwWaitResult == WAIT_OBJECT_0)
|
||||
{
|
||||
ownsMutex = 1;
|
||||
argv = (char **)malloc(cArgc * sizeof(char *));
|
||||
for(i=0; i < cArgc; i++)
|
||||
{
|
||||
argv[i] = (char *)malloc(MAX_STR_SIZE);
|
||||
argv[i][0] = (char)'\0';
|
||||
}
|
||||
|
||||
sscanf(comPortStr, "COM%d", &comPortId);
|
||||
|
||||
|
||||
status = SERIAL_COMMS_Enum_Devices(MAX_DEVICES, devIds, (DWORD*)&deviceCount);
|
||||
if(status != STATUS_OK)
|
||||
{
|
||||
SERIAL_COMMS_Get_Error_Text(errorText);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* sprintf(comPortTmpStr, MAX_STR_SIZE, "COM_PORT=%d", comPortId); */
|
||||
/* sprintf(baudRateTmpStr, MAX_STR_SIZE, "BAUD_RATE=%d", baudRate); */
|
||||
sprintf(comPortTmpStr, "COM_PORT=%d", comPortId);
|
||||
sprintf(baudRateTmpStr, "BAUD_RATE=%d", baudRate);
|
||||
|
||||
/* strncpy(argv[0], MAX_STR_SIZE, comPortTmpStr, MAX_STR_SIZE); */
|
||||
/* strncpy(argv[1], MAX_STR_SIZE, baudRateTmpStr, MAX_STR_SIZE); */
|
||||
/* strncpy(argv[2], MAX_STR_SIZE, "READ_TIMEOUT_PER_BYTE_MS=2000", MAX_STR_SIZE); */
|
||||
/* strncpy(argv[3], MAX_STR_SIZE, "REPLY_TIMEOUT_MS=2000", MAX_STR_SIZE); */
|
||||
/* strncpy(argv[4], MAX_STR_SIZE, "REPLY_TERMINATOR=u-boot> ", MAX_STR_SIZE); */
|
||||
/* strncpy(argv[5], MAX_STR_SIZE, "ALIGN_STRICT=0", MAX_STR_SIZE); */
|
||||
/* strncpy(argv[6], MAX_STR_SIZE, "FLUSH_ON_ERROR=1", MAX_STR_SIZE); */
|
||||
strncpy(argv[0], comPortTmpStr, MAX_STR_SIZE);
|
||||
strncpy(argv[1], baudRateTmpStr, MAX_STR_SIZE);
|
||||
strncpy(argv[2], "READ_TIMEOUT_PER_BYTE_MS=2000", MAX_STR_SIZE);
|
||||
strncpy(argv[3], "REPLY_TIMEOUT_MS=2000", MAX_STR_SIZE);
|
||||
strncpy(argv[4], "REPLY_TERMINATOR=u-boot> ", MAX_STR_SIZE);
|
||||
strncpy(argv[5], "ALIGN_STRICT=0", MAX_STR_SIZE);
|
||||
strncpy(argv[6], "FLUSH_ON_ERROR=1", MAX_STR_SIZE);
|
||||
|
||||
status = SERIAL_COMMS_Init_UBOOT((unsigned int)devIds[0], argc, argv);
|
||||
if(status != STATUS_OK)
|
||||
{
|
||||
SERIAL_COMMS_Get_Error_Text(errorText);
|
||||
ReleaseMutex(ghMutex);
|
||||
ownsMutex = 0;
|
||||
VL53L0X_comms_close();
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0; i < cArgc; i++)
|
||||
{
|
||||
free(argv[i]);
|
||||
}
|
||||
free(argv);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = STATUS_FAIL;
|
||||
}
|
||||
|
||||
if(ownsMutex)
|
||||
{
|
||||
ReleaseMutex(ghMutex);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
int32_t VL53L0X_comms_close(void)
|
||||
{
|
||||
DWORD dwWaitResult;
|
||||
unsigned int status = STATUS_FAIL;
|
||||
char errorText[MAX_STR_SIZE];
|
||||
|
||||
dwWaitResult = WaitForSingleObject(ghMutex, INFINITE);
|
||||
if(dwWaitResult == WAIT_OBJECT_0)
|
||||
{
|
||||
status = SERIAL_COMMS_Fini_UBOOT();
|
||||
if(status != STATUS_OK)
|
||||
{
|
||||
SERIAL_COMMS_Get_Error_Text(errorText);
|
||||
}
|
||||
ReleaseMutex(ghMutex);
|
||||
}
|
||||
|
||||
CloseHandle(ghMutex);
|
||||
ghMutex = NULL;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int32_t VL53L0X_write_multi(uint8_t address, uint8_t reg, uint8_t *pdata, int32_t count)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
|
||||
unsigned int retries = 3;
|
||||
uint8_t *pWriteData = pdata;
|
||||
uint8_t writeDataCount = count;
|
||||
uint8_t writeReg = reg;
|
||||
DWORD dwWaitResult;
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
int32_t i = 0;
|
||||
char value_as_str[VL53L0X_MAX_STRING_LENGTH_PLT];
|
||||
char *pvalue_as_str;
|
||||
#endif
|
||||
|
||||
/* For multi writes, the serial comms dll requires multiples 4 bytes or
|
||||
* anything less than 4 bytes. So if an irregular size is required, the
|
||||
* message is broken up into two writes.
|
||||
*/
|
||||
if((count > 4) && (count % 4 != 0))
|
||||
{
|
||||
writeDataCount = 4*(count/4);
|
||||
status = VL53L0X_write_multi(address, writeReg, pWriteData, writeDataCount);
|
||||
|
||||
if(status != STATUS_OK)
|
||||
{
|
||||
SERIAL_COMMS_Get_Error_Text(debug_string);
|
||||
}
|
||||
writeReg = reg + writeDataCount;
|
||||
pWriteData += writeDataCount;
|
||||
writeDataCount = count - writeDataCount;
|
||||
}
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
|
||||
pvalue_as_str = value_as_str;
|
||||
|
||||
for(i = 0 ; i < count ; i++)
|
||||
{
|
||||
sprintf(pvalue_as_str,"%02X", *(pdata+i));
|
||||
|
||||
pvalue_as_str += 2;
|
||||
}
|
||||
trace_i2c("Write reg : 0x%04X, Val : 0x%s\n", reg, value_as_str);
|
||||
#endif
|
||||
|
||||
if(status == STATUS_OK)
|
||||
{
|
||||
dwWaitResult = WaitForSingleObject(ghMutex, INFINITE);
|
||||
if(dwWaitResult == WAIT_OBJECT_0)
|
||||
{
|
||||
do
|
||||
{
|
||||
status = SERIAL_COMMS_Write_UBOOT(address, 0, writeReg, pWriteData, writeDataCount);
|
||||
// note : the field dwIndexHi is ignored. dwIndexLo will
|
||||
// contain the entire index (bits 0..15).
|
||||
if(status != STATUS_OK)
|
||||
{
|
||||
SERIAL_COMMS_Get_Error_Text(debug_string);
|
||||
}
|
||||
} while ((status != 0) && (retries-- > 0));
|
||||
ReleaseMutex(ghMutex);
|
||||
}
|
||||
|
||||
if(status != STATUS_OK)
|
||||
{
|
||||
SERIAL_COMMS_Get_Error_Text(debug_string);
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int32_t VL53L0X_read_multi(uint8_t address, uint8_t index, uint8_t *pdata, int32_t count)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
int32_t readDataCount = count;
|
||||
|
||||
unsigned int retries = 3;
|
||||
DWORD dwWaitResult;
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
int32_t i = 0;
|
||||
char value_as_str[VL53L0X_MAX_STRING_LENGTH_PLT];
|
||||
char *pvalue_as_str;
|
||||
#endif
|
||||
|
||||
dwWaitResult = WaitForSingleObject(ghMutex, INFINITE);
|
||||
if(dwWaitResult == WAIT_OBJECT_0)
|
||||
{
|
||||
/* The serial comms interface requires multiples of 4 bytes so we
|
||||
* must apply padding if required.
|
||||
*/
|
||||
if((count % 4) != 0)
|
||||
{
|
||||
readDataCount = (4*(count/4)) + 4;
|
||||
}
|
||||
|
||||
if(readDataCount > MAX_MSG_SIZE)
|
||||
{
|
||||
status = STATUS_FAIL;
|
||||
}
|
||||
|
||||
if(status == STATUS_OK)
|
||||
{
|
||||
do
|
||||
{
|
||||
status = SERIAL_COMMS_Read_UBOOT(address, 0, index, _dataBytes, readDataCount);
|
||||
if(status == STATUS_OK)
|
||||
{
|
||||
memcpy(pdata, &_dataBytes, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
SERIAL_COMMS_Get_Error_Text(debug_string);
|
||||
}
|
||||
|
||||
} while ((status != 0) && (retries-- > 0));
|
||||
}
|
||||
ReleaseMutex(ghMutex);
|
||||
}
|
||||
|
||||
if(status != STATUS_OK)
|
||||
{
|
||||
SERIAL_COMMS_Get_Error_Text(debug_string);
|
||||
}
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
|
||||
// Build value as string;
|
||||
pvalue_as_str = value_as_str;
|
||||
|
||||
for(i = 0 ; i < count ; i++)
|
||||
{
|
||||
sprintf(pvalue_as_str, "%02X", *(pdata+i));
|
||||
pvalue_as_str += 2;
|
||||
}
|
||||
|
||||
trace_i2c("Read reg : 0x%04X, Val : 0x%s\n", index, value_as_str);
|
||||
#endif
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_write_byte(uint8_t address, uint8_t index, uint8_t data)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
const int32_t cbyte_count = 1;
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
trace_print(TRACE_LEVEL_INFO,"Write reg : 0x%02X, Val : 0x%02X\n", index, data);
|
||||
#endif
|
||||
|
||||
status = VL53L0X_write_multi(address, index, &data, cbyte_count);
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_write_word(uint8_t address, uint8_t index, uint16_t data)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
|
||||
uint8_t buffer[BYTES_PER_WORD];
|
||||
|
||||
// Split 16-bit word into MS and LS uint8_t
|
||||
buffer[0] = (uint8_t)(data >> 8);
|
||||
buffer[1] = (uint8_t)(data & 0x00FF);
|
||||
|
||||
if(index%2 == 1)
|
||||
{
|
||||
status = VL53L0X_write_multi(address, index, &buffer[0], 1);
|
||||
status = VL53L0X_write_multi(address, index + 1, &buffer[1], 1);
|
||||
// serial comms cannot handle word writes to non 2-byte aligned registers.
|
||||
}
|
||||
else
|
||||
{
|
||||
status = VL53L0X_write_multi(address, index, buffer, BYTES_PER_WORD);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_write_dword(uint8_t address, uint8_t index, uint32_t data)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
uint8_t buffer[BYTES_PER_DWORD];
|
||||
|
||||
// Split 32-bit word into MS ... LS bytes
|
||||
buffer[0] = (uint8_t) (data >> 24);
|
||||
buffer[1] = (uint8_t)((data & 0x00FF0000) >> 16);
|
||||
buffer[2] = (uint8_t)((data & 0x0000FF00) >> 8);
|
||||
buffer[3] = (uint8_t) (data & 0x000000FF);
|
||||
|
||||
status = VL53L0X_write_multi(address, index, buffer, BYTES_PER_DWORD);
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_read_byte(uint8_t address, uint8_t index, uint8_t *pdata)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
int32_t cbyte_count = 1;
|
||||
|
||||
status = VL53L0X_read_multi(address, index, pdata, cbyte_count);
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
trace_print(TRACE_LEVEL_INFO,"Read reg : 0x%02X, Val : 0x%02X\n", index, *pdata);
|
||||
#endif
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_read_word(uint8_t address, uint8_t index, uint16_t *pdata)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
uint8_t buffer[BYTES_PER_WORD];
|
||||
|
||||
status = VL53L0X_read_multi(address, index, buffer, BYTES_PER_WORD);
|
||||
*pdata = ((uint16_t)buffer[0]<<8) + (uint16_t)buffer[1];
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
int32_t VL53L0X_read_dword(uint8_t address, uint8_t index, uint32_t *pdata)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
uint8_t buffer[BYTES_PER_DWORD];
|
||||
|
||||
status = VL53L0X_read_multi(address, index, buffer, BYTES_PER_DWORD);
|
||||
*pdata = ((uint32_t)buffer[0]<<24) + ((uint32_t)buffer[1]<<16) + ((uint32_t)buffer[2]<<8) + (uint32_t)buffer[3];
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 16 bit address functions
|
||||
|
||||
|
||||
int32_t VL53L0X_write_multi16(uint8_t address, uint16_t index, uint8_t *pdata, int32_t count)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
unsigned int retries = 3;
|
||||
DWORD dwWaitResult;
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
int32_t i = 0;
|
||||
|
||||
char value_as_str[VL53L0X_MAX_STRING_LENGTH_PLT];
|
||||
char *pvalue_as_str;
|
||||
|
||||
pvalue_as_str = value_as_str;
|
||||
|
||||
for(i = 0 ; i < count ; i++)
|
||||
{
|
||||
sprintf(pvalue_as_str,"%02X", *(pdata+i));
|
||||
|
||||
pvalue_as_str += 2;
|
||||
}
|
||||
trace_i2c("Write reg : 0x%04X, Val : 0x%s\n", index, value_as_str);
|
||||
#endif
|
||||
|
||||
dwWaitResult = WaitForSingleObject(ghMutex, INFINITE);
|
||||
if(dwWaitResult == WAIT_OBJECT_0)
|
||||
{
|
||||
do
|
||||
{
|
||||
status = SERIAL_COMMS_Write_UBOOT(address, 0, index, pdata, count);
|
||||
// note : the field dwIndexHi is ignored. dwIndexLo will
|
||||
// contain the entire index (bits 0..15).
|
||||
if(status != STATUS_OK)
|
||||
{
|
||||
SERIAL_COMMS_Get_Error_Text(debug_string);
|
||||
}
|
||||
} while ((status != 0) && (retries-- > 0));
|
||||
ReleaseMutex(ghMutex);
|
||||
}
|
||||
|
||||
// store the page from the high byte of the index
|
||||
cached_page = HIBYTE(index);
|
||||
|
||||
if(status != STATUS_OK)
|
||||
{
|
||||
SERIAL_COMMS_Get_Error_Text(debug_string);
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int32_t VL53L0X_read_multi16(uint8_t address, uint16_t index, uint8_t *pdata, int32_t count)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
unsigned int retries = 3;
|
||||
DWORD dwWaitResult;
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
int32_t i = 0;
|
||||
|
||||
char value_as_str[VL53L0X_MAX_STRING_LENGTH_PLT];
|
||||
char *pvalue_as_str;
|
||||
#endif
|
||||
|
||||
|
||||
dwWaitResult = WaitForSingleObject(ghMutex, INFINITE);
|
||||
if(dwWaitResult == WAIT_OBJECT_0)
|
||||
{
|
||||
do
|
||||
{
|
||||
status = SERIAL_COMMS_Read_UBOOT(address, 0, index, pdata, count);
|
||||
if(status != STATUS_OK)
|
||||
{
|
||||
SERIAL_COMMS_Get_Error_Text(debug_string);
|
||||
}
|
||||
} while ((status != 0) && (retries-- > 0));
|
||||
ReleaseMutex(ghMutex);
|
||||
}
|
||||
|
||||
// store the page from the high byte of the index
|
||||
cached_page = HIBYTE(index);
|
||||
|
||||
if(status != STATUS_OK)
|
||||
{
|
||||
SERIAL_COMMS_Get_Error_Text(debug_string);
|
||||
}
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
// Build value as string;
|
||||
pvalue_as_str = value_as_str;
|
||||
|
||||
for(i = 0 ; i < count ; i++)
|
||||
{
|
||||
sprintf(pvalue_as_str, "%02X", *(pdata+i));
|
||||
pvalue_as_str += 2;
|
||||
}
|
||||
|
||||
trace_i2c("Read reg : 0x%04X, Val : 0x%s\n", index, value_as_str);
|
||||
#endif
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int32_t VL53L0X_write_byte16(uint8_t address, uint16_t index, uint8_t data)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
const int32_t cbyte_count = 1;
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
trace_print(TRACE_LEVEL_INFO,"Write reg : 0x%02X, Val : 0x%02X\n", index, data);
|
||||
#endif
|
||||
|
||||
status = VL53L0X_write_multi16(address, index, &data, cbyte_count);
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_write_word16(uint8_t address, uint16_t index, uint16_t data)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
|
||||
uint8_t buffer[BYTES_PER_WORD];
|
||||
|
||||
// Split 16-bit word into MS and LS uint8_t
|
||||
buffer[0] = (uint8_t)(data >> 8);
|
||||
buffer[1] = (uint8_t)(data & 0x00FF);
|
||||
|
||||
if(index%2 == 1)
|
||||
{
|
||||
status = VL53L0X_write_multi16(address, index, &buffer[0], 1);
|
||||
status = VL53L0X_write_multi16(address, index + 1, &buffer[1], 1);
|
||||
// serial comms cannot handle word writes to non 2-byte aligned registers.
|
||||
}
|
||||
else
|
||||
{
|
||||
status = VL53L0X_write_multi16(address, index, buffer, BYTES_PER_WORD);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_write_dword16(uint8_t address, uint16_t index, uint32_t data)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
uint8_t buffer[BYTES_PER_DWORD];
|
||||
|
||||
// Split 32-bit word into MS ... LS bytes
|
||||
buffer[0] = (uint8_t) (data >> 24);
|
||||
buffer[1] = (uint8_t)((data & 0x00FF0000) > 16);
|
||||
buffer[2] = (uint8_t)((data & 0x0000FF00) > 8);
|
||||
buffer[3] = (uint8_t) (data & 0x000000FF);
|
||||
|
||||
status = VL53L0X_write_multi16(address, index, buffer, BYTES_PER_DWORD);
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_read_byte16(uint8_t address, uint16_t index, uint8_t *pdata)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
int32_t cbyte_count = 1;
|
||||
|
||||
status = VL53L0X_read_multi16(address, index, pdata, cbyte_count);
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
trace_print(TRACE_LEVEL_INFO,"Read reg : 0x%02X, Val : 0x%02X\n", index, *pdata);
|
||||
#endif
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_read_word16(uint8_t address, uint16_t index, uint16_t *pdata)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
uint8_t buffer[BYTES_PER_WORD];
|
||||
|
||||
status = VL53L0X_read_multi16(address, index, buffer, BYTES_PER_WORD);
|
||||
*pdata = ((uint16_t)buffer[0]<<8) + (uint16_t)buffer[1];
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
int32_t VL53L0X_read_dword16(uint8_t address, uint16_t index, uint32_t *pdata)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
uint8_t buffer[BYTES_PER_DWORD];
|
||||
|
||||
status = VL53L0X_read_multi16(address, index, buffer, BYTES_PER_DWORD);
|
||||
*pdata = ((uint32_t)buffer[0]<<24) + ((uint32_t)buffer[1]<<16) + ((uint32_t)buffer[2]<<8) + (uint32_t)buffer[3];
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int32_t VL53L0X_platform_wait_us(int32_t wait_us)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
float wait_ms = (float)wait_us/1000.0f;
|
||||
|
||||
/*
|
||||
* Use windows event handling to perform non-blocking wait.
|
||||
*/
|
||||
HANDLE hEvent = CreateEvent(0, TRUE, FALSE, 0);
|
||||
WaitForSingleObject(hEvent, (int)(wait_ms + 0.5f));
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
trace_i2c("Wait us : %6d\n", wait_us);
|
||||
#endif
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_wait_ms(int32_t wait_ms)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
|
||||
/*
|
||||
* Use windows event handling to perform non-blocking wait.
|
||||
*/
|
||||
HANDLE hEvent = CreateEvent(0, TRUE, FALSE, 0);
|
||||
WaitForSingleObject(hEvent, wait_ms);
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
trace_i2c("Wait ms : %6d\n", wait_ms);
|
||||
#endif
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_set_gpio(uint8_t level)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
//status = VL53L0X_set_gpio_sv(level);
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
trace_i2c("// Set GPIO = %d;\n", level);
|
||||
#endif
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_get_gpio(uint8_t *plevel)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
trace_i2c("// Get GPIO = %d;\n", *plevel);
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_release_gpio(void)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
trace_i2c("// Releasing force on GPIO\n");
|
||||
#endif
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
int32_t VL53L0X_cycle_power(void)
|
||||
{
|
||||
int32_t status = STATUS_OK;
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
trace_i2c("// cycle sensor power\n");
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_get_timer_frequency(int32_t *ptimer_freq_hz)
|
||||
{
|
||||
*ptimer_freq_hz = 0;
|
||||
return STATUS_FAIL;
|
||||
}
|
||||
|
||||
|
||||
int32_t VL53L0X_get_timer_value(int32_t *ptimer_count)
|
||||
{
|
||||
*ptimer_count = 0;
|
||||
return STATUS_FAIL;
|
||||
}
|
274
Api/platform/src/vl53l0x_platform.c
Normal file
274
Api/platform/src/vl53l0x_platform.c
Normal file
@ -0,0 +1,274 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2015, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* @file VL53L0X_i2c.c
|
||||
*
|
||||
* Copyright (C) 2014 ST MicroElectronics
|
||||
*
|
||||
* provide variable word size byte/Word/dword VL6180x register access via i2c
|
||||
*
|
||||
*/
|
||||
#include "vl53l0x_platform.h"
|
||||
#include "vl53l0x_i2c_platform.h"
|
||||
#include "vl53l0x_api.h"
|
||||
|
||||
#define LOG_FUNCTION_START(fmt, ... ) _LOG_FUNCTION_START(TRACE_MODULE_PLATFORM, fmt, ##__VA_ARGS__)
|
||||
#define LOG_FUNCTION_END(status, ... ) _LOG_FUNCTION_END(TRACE_MODULE_PLATFORM, status, ##__VA_ARGS__)
|
||||
#define LOG_FUNCTION_END_FMT(status, fmt, ... ) _LOG_FUNCTION_END_FMT(TRACE_MODULE_PLATFORM, status, fmt, ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @def I2C_BUFFER_CONFIG
|
||||
*
|
||||
* @brief Configure Device register I2C access
|
||||
*
|
||||
* @li 0 : one GLOBAL buffer \n
|
||||
* Use one global buffer of MAX_I2C_XFER_SIZE byte in data space \n
|
||||
* This solution is not multi-Device compliant nor multi-thread cpu safe \n
|
||||
* It can be the best option for small 8/16 bit MCU without stack and limited ram (STM8s, 80C51 ...)
|
||||
*
|
||||
* @li 1 : ON_STACK/local \n
|
||||
* Use local variable (on stack) buffer \n
|
||||
* This solution is multi-thread with use of i2c resource lock or mutex see VL6180x_GetI2CAccess() \n
|
||||
*
|
||||
* @li 2 : User defined \n
|
||||
* Per Device potentially dynamic allocated. Requires VL6180x_GetI2cBuffer() to be implemented.
|
||||
* @ingroup Configuration
|
||||
*/
|
||||
#define I2C_BUFFER_CONFIG 1
|
||||
/** Maximum buffer size to be used in i2c */
|
||||
#define VL53L0X_MAX_I2C_XFER_SIZE 64 /* Maximum buffer size to be used in i2c */
|
||||
|
||||
#if I2C_BUFFER_CONFIG == 0
|
||||
/* GLOBAL config buffer */
|
||||
uint8_t i2c_global_buffer[VL53L0X_MAX_I2C_XFER_SIZE];
|
||||
|
||||
#define DECL_I2C_BUFFER
|
||||
#define VL53L0X_GetLocalBuffer(Dev, n_byte) i2c_global_buffer
|
||||
|
||||
#elif I2C_BUFFER_CONFIG == 1
|
||||
/* ON STACK */
|
||||
#define DECL_I2C_BUFFER uint8_t LocBuffer[VL53L0X_MAX_I2C_XFER_SIZE];
|
||||
#define VL53L0X_GetLocalBuffer(Dev, n_byte) LocBuffer
|
||||
#elif I2C_BUFFER_CONFIG == 2
|
||||
/* user define buffer type declare DECL_I2C_BUFFER as access via VL53L0X_GetLocalBuffer */
|
||||
#define DECL_I2C_BUFFER
|
||||
#else
|
||||
#error "invalid I2C_BUFFER_CONFIG "
|
||||
#endif
|
||||
|
||||
|
||||
#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 VL53L0X_GetI2CAccess(Dev) /* todo mutex acquire */
|
||||
#define VL53L0X_DoneI2CAcces(Dev) /* todo mutex release */
|
||||
|
||||
|
||||
VL53L0X_Error VL53L0X_LockSequenceAccess(VL53L0X_DEV Dev){
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_UnlockSequenceAccess(VL53L0X_DEV Dev){
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
// the ranging_sensor_comms.dll will take care of the page selection
|
||||
VL53L0X_Error VL53L0X_WriteMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count){
|
||||
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
int32_t status_int = 0;
|
||||
uint8_t deviceAddress;
|
||||
|
||||
if (count>=VL53L0X_MAX_I2C_XFER_SIZE){
|
||||
Status = VL53L0X_ERROR_INVALID_PARAMS;
|
||||
}
|
||||
|
||||
deviceAddress = Dev->I2cDevAddr;
|
||||
|
||||
status_int = VL53L0X_write_multi(deviceAddress, index, pdata, count);
|
||||
|
||||
if (status_int != 0)
|
||||
Status = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
// the ranging_sensor_comms.dll will take care of the page selection
|
||||
VL53L0X_Error VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count){
|
||||
VL53L0X_I2C_USER_VAR
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
int32_t status_int;
|
||||
uint8_t deviceAddress;
|
||||
|
||||
if (count>=VL53L0X_MAX_I2C_XFER_SIZE){
|
||||
Status = VL53L0X_ERROR_INVALID_PARAMS;
|
||||
}
|
||||
|
||||
deviceAddress = Dev->I2cDevAddr;
|
||||
|
||||
status_int = VL53L0X_read_multi(deviceAddress, index, pdata, count);
|
||||
|
||||
if (status_int != 0)
|
||||
Status = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
VL53L0X_Error VL53L0X_WrByte(VL53L0X_DEV Dev, uint8_t index, uint8_t data){
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
int32_t status_int;
|
||||
uint8_t deviceAddress;
|
||||
|
||||
deviceAddress = Dev->I2cDevAddr;
|
||||
|
||||
status_int = VL53L0X_write_byte(deviceAddress, index, data);
|
||||
|
||||
if (status_int != 0)
|
||||
Status = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_WrWord(VL53L0X_DEV Dev, uint8_t index, uint16_t data){
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
int32_t status_int;
|
||||
uint8_t deviceAddress;
|
||||
|
||||
deviceAddress = Dev->I2cDevAddr;
|
||||
|
||||
status_int = VL53L0X_write_word(deviceAddress, index, data);
|
||||
|
||||
if (status_int != 0)
|
||||
Status = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_WrDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t data){
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
int32_t status_int;
|
||||
uint8_t deviceAddress;
|
||||
|
||||
deviceAddress = Dev->I2cDevAddr;
|
||||
|
||||
status_int = VL53L0X_write_dword(deviceAddress, index, data);
|
||||
|
||||
if (status_int != 0)
|
||||
Status = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_UpdateByte(VL53L0X_DEV Dev, uint8_t index, uint8_t AndData, uint8_t OrData){
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
int32_t status_int;
|
||||
uint8_t deviceAddress;
|
||||
uint8_t data;
|
||||
|
||||
deviceAddress = Dev->I2cDevAddr;
|
||||
|
||||
status_int = VL53L0X_read_byte(deviceAddress, index, &data);
|
||||
|
||||
if (status_int != 0)
|
||||
Status = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
|
||||
if (Status == VL53L0X_ERROR_NONE) {
|
||||
data = (data & AndData) | OrData;
|
||||
status_int = VL53L0X_write_byte(deviceAddress, index, data);
|
||||
|
||||
if (status_int != 0)
|
||||
Status = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_RdByte(VL53L0X_DEV Dev, uint8_t index, uint8_t *data){
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
int32_t status_int;
|
||||
uint8_t deviceAddress;
|
||||
|
||||
deviceAddress = Dev->I2cDevAddr;
|
||||
|
||||
status_int = VL53L0X_read_byte(deviceAddress, index, data);
|
||||
|
||||
if (status_int != 0)
|
||||
Status = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_RdWord(VL53L0X_DEV Dev, uint8_t index, uint16_t *data){
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
int32_t status_int;
|
||||
uint8_t deviceAddress;
|
||||
|
||||
deviceAddress = Dev->I2cDevAddr;
|
||||
|
||||
status_int = VL53L0X_read_word(deviceAddress, index, data);
|
||||
|
||||
if (status_int != 0)
|
||||
Status = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_RdDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t *data){
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
int32_t status_int;
|
||||
uint8_t deviceAddress;
|
||||
|
||||
deviceAddress = Dev->I2cDevAddr;
|
||||
|
||||
status_int = VL53L0X_read_dword(deviceAddress, index, data);
|
||||
|
||||
if (status_int != 0)
|
||||
Status = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
#define VL53L0X_POLLINGDELAY_LOOPNB 250
|
||||
VL53L0X_Error VL53L0X_PollingDelay(VL53L0X_DEV Dev){
|
||||
VL53L0X_Error status = VL53L0X_ERROR_NONE;
|
||||
LOG_FUNCTION_START("");
|
||||
|
||||
const DWORD cTimeout_ms = 1;
|
||||
HANDLE hEvent = CreateEvent(0, TRUE, FALSE, 0);
|
||||
if(hEvent != NULL)
|
||||
{
|
||||
WaitForSingleObject(hEvent,cTimeout_ms);
|
||||
}
|
||||
|
||||
LOG_FUNCTION_END(status);
|
||||
return status;
|
||||
}
|
100
Api/platform/src/vl53l0x_platform_log.c
Normal file
100
Api/platform/src/vl53l0x_platform_log.c
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* COPYRIGHT (C) STMicroelectronics 2015. All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* STMicroelectronics ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license agreement you entered into
|
||||
* with STMicroelectronics
|
||||
*
|
||||
* Programming Golden Rule: Keep it Simple!
|
||||
*
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \file VL53L0X_platform_log.c
|
||||
* \brief Code function defintions for Ewok Platform Layer
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h> // sprintf(), vsnprintf(), printf()
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#include "vl53l0x_i2c_platform.h"
|
||||
#include "vl53l0x_def.h"
|
||||
#include "vl53l0x_platform_log.h"
|
||||
|
||||
#define trace_print(level, ...) trace_print_module_function(TRACE_MODULE_PLATFORM, level, TRACE_FUNCTION_NONE, ##__VA_ARGS__)
|
||||
#define trace_i2c(...) trace_print_module_function(TRACE_MODULE_NONE, TRACE_LEVEL_NONE, TRACE_FUNCTION_I2C, ##__VA_ARGS__)
|
||||
|
||||
char debug_string[VL53L0X_MAX_STRING_LENGTH_PLT];
|
||||
|
||||
|
||||
char * _trace_filename = NULL;
|
||||
FILE *_tracefile = NULL;
|
||||
|
||||
uint32_t _trace_level = TRACE_LEVEL_WARNING;
|
||||
uint32_t _trace_modules = TRACE_MODULE_NONE;
|
||||
uint32_t _trace_functions = TRACE_FUNCTION_NONE;
|
||||
|
||||
|
||||
int32_t VL53L0X_trace_config(char *filename, uint32_t modules, uint32_t level, uint32_t functions)
|
||||
{
|
||||
int STATUS = 0;
|
||||
|
||||
if ((_trace_filename != NULL) && (_trace_filename != filename))
|
||||
{
|
||||
if ( _tracefile != NULL )
|
||||
{
|
||||
fclose(_tracefile);
|
||||
_tracefile = NULL;
|
||||
}
|
||||
free(_trace_filename);
|
||||
_trace_filename = NULL;
|
||||
}
|
||||
|
||||
if ((filename != NULL) && (_tracefile == NULL))
|
||||
{
|
||||
_tracefile = fopen(filename, "w+");
|
||||
|
||||
//TODO: Add time and header banner to the log file to indicate we've just opened a new log session
|
||||
|
||||
if ( _tracefile != NULL )
|
||||
{
|
||||
_trace_filename = (char*)malloc((strlen(filename) + 1) * sizeof(char));
|
||||
strcpy(_trace_filename, filename);
|
||||
} else
|
||||
STATUS = 1;
|
||||
}
|
||||
|
||||
_trace_functions = functions;
|
||||
_trace_level = level;
|
||||
_trace_modules = modules;
|
||||
|
||||
return STATUS;
|
||||
}
|
||||
|
||||
void trace_print_module_function(uint32_t module, uint32_t level, uint32_t function, const char *format, ...)
|
||||
{
|
||||
if ( ((level <=_trace_level) && ((module & _trace_modules) > 0))
|
||||
|| ((function & _trace_functions) > 0) )
|
||||
{
|
||||
va_list arg_list;
|
||||
char message[VL53L0X_MAX_STRING_LENGTH_PLT];
|
||||
|
||||
va_start(arg_list, format);
|
||||
vsnprintf(message, VL53L0X_MAX_STRING_LENGTH_PLT, format, arg_list);
|
||||
va_end(arg_list);
|
||||
|
||||
if (_tracefile != NULL)
|
||||
fprintf(_tracefile, message);
|
||||
else
|
||||
printf(message);
|
||||
}
|
||||
}
|
||||
|
59
Makefile
Normal file
59
Makefile
Normal file
@ -0,0 +1,59 @@
|
||||
CC ?= $(CROSS_COMPILE)gcc
|
||||
RM := rm
|
||||
|
||||
PREFIX ?= /usr
|
||||
|
||||
CFLAGS := -O2 -Wall -c -fPIC
|
||||
|
||||
OUT_DIR := bin
|
||||
OBJ_DIR := obj
|
||||
API_DIR := Api
|
||||
|
||||
TARGET_LIB := $(PWD)/$(OUT_DIR)/libvl53l0x.so
|
||||
|
||||
INCLUDES = \
|
||||
-I$(PWD)/$(API_DIR)/core/inc \
|
||||
-I$(PWD)/platform/inc
|
||||
|
||||
VPATH = \
|
||||
$(PWD)/$(API_DIR)/core/src \
|
||||
$(PWD)/platform/src/
|
||||
|
||||
LIB_SRCS = \
|
||||
vl53l0x_api_calibration.c \
|
||||
vl53l0x_api_core.c \
|
||||
vl53l0x_api_ranging.c \
|
||||
vl53l0x_api_strings.c \
|
||||
vl53l0x_api.c \
|
||||
vl53l0x_platform.c
|
||||
|
||||
LIB_OBJS = $(LIB_SRCS:%.c=$(OBJ_DIR)/%.o)
|
||||
|
||||
.PHONY: all
|
||||
all: ${TARGET_LIB}
|
||||
|
||||
$(TARGET_LIB): $(LIB_OBJS)
|
||||
mkdir -p $(dir $@)
|
||||
$(CC) -shared $^ $(INCLUDES) -lpthread -o $@
|
||||
|
||||
$(OBJ_DIR)/%.o:%.c
|
||||
mkdir -p $(dir $@)
|
||||
$(CC) $(CFLAGS) $(PYTHON_INCLUDES) $(INCLUDES) $< -o $@
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-${RM} -rf $(TARGET_LIB) $(LIB_OBJS)
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
install --directory $(PREFIX)/lib
|
||||
install $(TARGET_LIB) $(PREFIX)/lib
|
||||
install $(PWD)/$(API_DIR)/core/inc/vl53l0x_api.h $(PREFIX)/include/
|
||||
install $(PWD)/platform/inc/vl53l0x_platform.h $(PREFIX)/include/
|
||||
ldconfig -n $(PREFIX)/lib
|
||||
|
||||
.PHONY: uninstall
|
||||
uninstall:
|
||||
$(RM) $(PREFIX)/lib/$(TARGET_LIB) \
|
||||
$(PREFIX)/include/vl53l0x_api.h \
|
||||
$(PREFIX)/include/vl53l0x_platform.h
|
248
platform/inc/vl53l0x_platform.h
Normal file
248
platform/inc/vl53l0x_platform.h
Normal file
@ -0,0 +1,248 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2015, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
#ifndef _VL53L0X_PLATFORM_H_
|
||||
#define _VL53L0X_PLATFORM_H_
|
||||
|
||||
#include "vl53l0x_def.h"
|
||||
#include "vl53l0x_platform_log.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int VL53L0X_i2c_init(char * devPath, int devAddr);
|
||||
int32_t VL53L0X_i2c_close(void);
|
||||
|
||||
/**
|
||||
* @file vl53l0_platform.h
|
||||
*
|
||||
* @brief All end user OS/platform/application porting
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup VL53L0X_platform_group VL53L0 Platform Functions
|
||||
* @brief VL53L0 Platform Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @struct VL53L0X_Dev_t
|
||||
* @brief Generic PAL device type that does link between API and platform abstraction layer
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
VL53L0X_DevData_t Data; /*!< embed ST Ewok Dev data as "Data"*/
|
||||
|
||||
/*!< user specific field */
|
||||
uint8_t I2cDevAddr; /*!< i2c device address user specific field */
|
||||
uint8_t TCA9548A_Device; /*!< Device number on TCA9548A I2C Multiplexer or 255 if TCA9548A not being used */
|
||||
uint8_t TCA9548A_Address; /*!< Address of TCA9548A I2C Multiplexer or 255 if TCA9548A not being used */
|
||||
} VL53L0X_Dev_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Declare the device Handle as a pointer of the structure @a VL53L0X_Dev_t.
|
||||
*
|
||||
*/
|
||||
typedef VL53L0X_Dev_t* VL53L0X_DEV;
|
||||
|
||||
/**
|
||||
* @def PALDevDataGet
|
||||
* @brief Get ST private structure @a VL53L0X_DevData_t data access
|
||||
*
|
||||
* @param Dev Device Handle
|
||||
* @param field ST structure field name
|
||||
* It maybe used and as real data "ref" not just as "get" for sub-structure item
|
||||
* like PALDevDataGet(FilterData.field)[i] or PALDevDataGet(FilterData.MeasurementIndex)++
|
||||
*/
|
||||
#define PALDevDataGet(Dev, field) (Dev->Data.field)
|
||||
|
||||
/**
|
||||
* @def PALDevDataSet(Dev, field, data)
|
||||
* @brief Set ST private structure @a VL53L0X_DevData_t data field
|
||||
* @param Dev Device Handle
|
||||
* @param field ST structure field name
|
||||
* @param data Data to be set
|
||||
*/
|
||||
#define PALDevDataSet(Dev, field, data) (Dev->Data.field)=(data)
|
||||
|
||||
/**
|
||||
* Initialize PLatform Interface
|
||||
* @param Dev Device Handle
|
||||
* @return None
|
||||
*/
|
||||
void VL53L0X_init(VL53L0X_DEV Dev);
|
||||
|
||||
/**
|
||||
* @defgroup VL53L0X_registerAccess_group PAL Register Access Functions
|
||||
* @brief PAL Register Access Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Lock comms interface to serialize all commands to a shared I2C interface for a specific device
|
||||
* @param Dev Device Handle
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_LockSequenceAccess(VL53L0X_DEV Dev);
|
||||
|
||||
/**
|
||||
* Unlock comms interface to serialize all commands to a shared I2C interface for a specific device
|
||||
* @param Dev Device Handle
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_UnlockSequenceAccess(VL53L0X_DEV Dev);
|
||||
|
||||
|
||||
/**
|
||||
* Writes the supplied byte buffer to the device
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param pdata Pointer to uint8_t buffer containing the data to be written
|
||||
* @param count Number of bytes in the supplied byte buffer
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_WriteMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count);
|
||||
|
||||
/**
|
||||
* Reads the requested number of bytes from the device
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param pdata Pointer to the uint8_t buffer to store read data
|
||||
* @param count Number of uint8_t's to read
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count);
|
||||
|
||||
/**
|
||||
* Write single byte register
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param data 8 bit register data
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_WrByte(VL53L0X_DEV Dev, uint8_t index, uint8_t data);
|
||||
|
||||
/**
|
||||
* Write word register
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param data 16 bit register data
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_WrWord(VL53L0X_DEV Dev, uint8_t index, uint16_t data);
|
||||
|
||||
/**
|
||||
* Write double word (4 byte) register
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param data 32 bit register data
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_WrDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t data);
|
||||
|
||||
/**
|
||||
* Read single byte register
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param data pointer to 8 bit data
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_RdByte(VL53L0X_DEV Dev, uint8_t index, uint8_t *data);
|
||||
|
||||
/**
|
||||
* Read word (2byte) register
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param data pointer to 16 bit data
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_RdWord(VL53L0X_DEV Dev, uint8_t index, uint16_t *data);
|
||||
|
||||
/**
|
||||
* Read dword (4byte) register
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param data pointer to 32 bit data
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_RdDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t *data);
|
||||
|
||||
/**
|
||||
* Threat safe Update (read/modify/write) single byte register
|
||||
*
|
||||
* Final_reg = (Initial_reg & and_data) |or_data
|
||||
*
|
||||
* @param Dev Device Handle
|
||||
* @param index The register index
|
||||
* @param AndData 8 bit and data
|
||||
* @param OrData 8 bit or data
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_UpdateByte(VL53L0X_DEV Dev, uint8_t index, uint8_t AndData, uint8_t OrData);
|
||||
|
||||
/** @} end of VL53L0X_registerAccess_group */
|
||||
|
||||
|
||||
/**
|
||||
* @brief execute delay in all polling API call
|
||||
*
|
||||
* A typical multi-thread or RTOs implementation is to sleep the task for some 5ms (with 100Hz max rate faster polling is not needed)
|
||||
* if nothing specific is need you can define it as an empty/void macro
|
||||
* @code
|
||||
* #define VL53L0X_PollingDelay(...) (void)0
|
||||
* @endcode
|
||||
* @param Dev Device Handle
|
||||
* @return VL53L0X_ERROR_NONE Success
|
||||
* @return "Other error code" See ::VL53L0X_Error
|
||||
*/
|
||||
VL53L0X_Error VL53L0X_PollingDelay(VL53L0X_DEV Dev); /* usually best implemented as a real function */
|
||||
|
||||
/** @} end of VL53L0X_platform_group */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _VL53L0X_PLATFORM_H_ */
|
||||
|
||||
|
||||
|
118
platform/inc/vl53l0x_platform_log.h
Normal file
118
platform/inc/vl53l0x_platform_log.h
Normal file
@ -0,0 +1,118 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2015, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
#ifndef _VL53L0X_PLATFORM_LOG_H_
|
||||
#define _VL53L0X_PLATFORM_LOG_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
/* LOG Functions */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file vl53l0_platform_log.h
|
||||
*
|
||||
* @brief platform log function definition
|
||||
*/
|
||||
|
||||
//#define VL53L0X_LOG_ENABLE 0
|
||||
|
||||
enum {
|
||||
TRACE_LEVEL_NONE,
|
||||
TRACE_LEVEL_ERRORS,
|
||||
TRACE_LEVEL_WARNING,
|
||||
TRACE_LEVEL_INFO,
|
||||
TRACE_LEVEL_DEBUG,
|
||||
TRACE_LEVEL_ALL,
|
||||
TRACE_LEVEL_IGNORE
|
||||
};
|
||||
|
||||
enum {
|
||||
TRACE_FUNCTION_NONE = 0,
|
||||
TRACE_FUNCTION_I2C = 1,
|
||||
TRACE_FUNCTION_ALL = 0x7fffffff //all bits except sign
|
||||
};
|
||||
|
||||
enum {
|
||||
TRACE_MODULE_NONE = 0x0,
|
||||
TRACE_MODULE_API = 0x1,
|
||||
TRACE_MODULE_PLATFORM = 0x2,
|
||||
TRACE_MODULE_ALL = 0x7fffffff //all bits except sign
|
||||
};
|
||||
|
||||
|
||||
#ifdef VL53L0X_LOG_ENABLE
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
extern uint32_t _trace_level;
|
||||
|
||||
|
||||
|
||||
int32_t VL53L0X_trace_config(char *filename, uint32_t modules, uint32_t level, uint32_t functions);
|
||||
|
||||
void trace_print_module_function(uint32_t module, uint32_t level, uint32_t function, const char *format, ...);
|
||||
|
||||
|
||||
//extern FILE * log_file;
|
||||
|
||||
#define LOG_GET_TIME() (int)clock()
|
||||
|
||||
#define _LOG_FUNCTION_START(module, fmt, ... ) \
|
||||
trace_print_module_function(module, _trace_level, TRACE_FUNCTION_ALL, "%ld <START> %s "fmt"\n", LOG_GET_TIME(), __FUNCTION__, ##__VA_ARGS__);
|
||||
|
||||
#define _LOG_FUNCTION_END(module, status, ... )\
|
||||
trace_print_module_function(module, _trace_level, TRACE_FUNCTION_ALL, "%ld <END> %s %d\n", LOG_GET_TIME(), __FUNCTION__, (int)status, ##__VA_ARGS__)
|
||||
|
||||
#define _LOG_FUNCTION_END_FMT(module, status, fmt, ... )\
|
||||
trace_print_module_function(module, _trace_level, TRACE_FUNCTION_ALL, "%ld <END> %s %d "fmt"\n", LOG_GET_TIME(), __FUNCTION__, (int)status,##__VA_ARGS__)
|
||||
|
||||
// __func__ is gcc only
|
||||
//#define VL53L0X_ErrLog( fmt, ...) fprintf(stderr, "VL53L0X_ErrLog %s" fmt "\n", __func__, ##__VA_ARGS__)
|
||||
|
||||
#else /* VL53L0X_LOG_ENABLE no logging */
|
||||
#define VL53L0X_ErrLog(...) (void)0
|
||||
#define _LOG_FUNCTION_START(module, fmt, ... ) (void)0
|
||||
#define _LOG_FUNCTION_END(module, status, ... ) (void)0
|
||||
#define _LOG_FUNCTION_END_FMT(module, status, fmt, ... ) (void)0
|
||||
#endif /* else */
|
||||
|
||||
#define VL53L0X_COPYSTRING(str, ...) strcpy(str, ##__VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _VL53L0X_PLATFORM_LOG_H_ */
|
||||
|
||||
|
||||
|
111
platform/inc/vl53l0x_types.h
Normal file
111
platform/inc/vl53l0x_types.h
Normal file
@ -0,0 +1,111 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2015, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
/**
|
||||
* @file vl53l0_types.h
|
||||
* @brief VL53L0 types definition
|
||||
*/
|
||||
|
||||
#ifndef VL53L0X_TYPES_H_
|
||||
#define VL53L0X_TYPES_H_
|
||||
|
||||
/** @defgroup porting_type Basic type definition
|
||||
* @ingroup VL53L0X_platform_group
|
||||
*
|
||||
* @brief file vl53l0_types.h files hold basic type definition that may requires porting
|
||||
*
|
||||
* contains type that must be defined for the platform\n
|
||||
* when target platform and compiler provide stdint.h and stddef.h it is enough to include it.\n
|
||||
* If stdint.h is not available review and adapt all signed and unsigned 8/16/32 bits basic types. \n
|
||||
* If stddef.h is not available review and adapt NULL definition .
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef NULL
|
||||
#error "Error NULL definition should be done. Please add required include "
|
||||
#endif
|
||||
|
||||
|
||||
#if ! defined(STDINT_H) && !defined(_GCC_STDINT_H) &&!defined(__STDINT_DECLS) && !defined(_GCC_WRAP_STDINT_H)
|
||||
|
||||
#pragma message("Please review type definition of STDINT define for your platform and add to list above ")
|
||||
|
||||
/*
|
||||
* target platform do not provide stdint or use a different #define than above
|
||||
* to avoid seeing the message below addapt the #define list above or implement
|
||||
* all type and delete these pragma
|
||||
*/
|
||||
|
||||
/** \ingroup VL53L0X_portingType_group
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
typedef unsigned long long uint64_t;
|
||||
|
||||
|
||||
/** @brief Typedef defining 32 bit unsigned int type.\n
|
||||
* The developer should modify this to suit the platform being deployed.
|
||||
*/
|
||||
typedef unsigned int uint32_t;
|
||||
|
||||
/** @brief Typedef defining 32 bit int type.\n
|
||||
* The developer should modify this to suit the platform being deployed.
|
||||
*/
|
||||
typedef int int32_t;
|
||||
|
||||
/** @brief Typedef defining 16 bit unsigned short type.\n
|
||||
* The developer should modify this to suit the platform being deployed.
|
||||
*/
|
||||
typedef unsigned short uint16_t;
|
||||
|
||||
/** @brief Typedef defining 16 bit short type.\n
|
||||
* The developer should modify this to suit the platform being deployed.
|
||||
*/
|
||||
typedef short int16_t;
|
||||
|
||||
/** @brief Typedef defining 8 bit unsigned char type.\n
|
||||
* The developer should modify this to suit the platform being deployed.
|
||||
*/
|
||||
typedef unsigned char uint8_t;
|
||||
|
||||
/** @brief Typedef defining 8 bit char type.\n
|
||||
* The developer should modify this to suit the platform being deployed.
|
||||
*/
|
||||
typedef signed char int8_t;
|
||||
|
||||
/** @} */
|
||||
#endif /* _STDINT_H */
|
||||
|
||||
|
||||
/** use where fractional values are expected
|
||||
*
|
||||
* Given a floating point value f it's .16 bit point is (int)(f*(1<<16))*/
|
||||
typedef uint32_t FixPoint1616_t;
|
||||
|
||||
#endif /* VL53L0X_TYPES_H_ */
|
251
platform/src/vl53l0x_platform.c
Normal file
251
platform/src/vl53l0x_platform.c
Normal file
@ -0,0 +1,251 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 John Bryan Moore
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include "vl53l0x_platform.h"
|
||||
#include "vl53l0x_api.h"
|
||||
|
||||
// calls read_i2c_block_data(address, reg, length)
|
||||
static int (*i2c_read_func)(uint8_t address, uint8_t reg,
|
||||
uint8_t *list, uint8_t length) = NULL;
|
||||
|
||||
// calls write_i2c_block_data(address, reg, list)
|
||||
static int (*i2c_write_func)(uint8_t address, uint8_t reg,
|
||||
uint8_t *list, uint8_t length) = NULL;
|
||||
|
||||
static pthread_mutex_t i2c_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void VL53L0X_init(VL53L0X_DEV Dev)
|
||||
{
|
||||
}
|
||||
|
||||
void VL53L0X_set_i2c(void *read_func, void *write_func)
|
||||
{
|
||||
i2c_read_func = read_func;
|
||||
i2c_write_func = write_func;
|
||||
}
|
||||
|
||||
static int i2c_write(VL53L0X_DEV Dev, uint8_t cmd,
|
||||
uint8_t *data, uint8_t len)
|
||||
{
|
||||
int result = VL53L0X_ERROR_NONE;
|
||||
|
||||
if (i2c_write_func != NULL)
|
||||
{
|
||||
if (Dev->TCA9548A_Device < 8)
|
||||
{
|
||||
// Make sure that the call to set the bus on the TCA9548A is
|
||||
// synchronized with the write to the VL53L0X device to allow
|
||||
// to make the transaction thread-safe
|
||||
pthread_mutex_lock(&i2c_mutex);
|
||||
|
||||
// If the value is < 8 then a TCA9548A I2C Multiplexer
|
||||
// is being used so prefix each call with a call to
|
||||
// set the device at the multiplexer to the number
|
||||
// specified
|
||||
if (i2c_write_func(Dev->TCA9548A_Address, (1 << Dev->TCA9548A_Device), NULL, 0) < 0)
|
||||
{
|
||||
printf("TCA9548A write error\n");
|
||||
result = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
}
|
||||
}
|
||||
|
||||
if (result == VL53L0X_ERROR_NONE)
|
||||
{
|
||||
if (i2c_write_func(Dev->I2cDevAddr, cmd, data, len) < 0)
|
||||
{
|
||||
result = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
}
|
||||
}
|
||||
|
||||
if (Dev->TCA9548A_Device < 8)
|
||||
{
|
||||
pthread_mutex_unlock(&i2c_mutex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("i2c bus write not set.\n");
|
||||
result = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int i2c_read(VL53L0X_DEV Dev, uint8_t cmd,
|
||||
uint8_t * data, uint8_t len)
|
||||
{
|
||||
int result = VL53L0X_ERROR_NONE;
|
||||
|
||||
if (i2c_read_func != NULL)
|
||||
{
|
||||
if (Dev->TCA9548A_Device < 8)
|
||||
{
|
||||
// Make sure that the call to set the bus on the TCA9548A is
|
||||
// synchronized with the read of the VL53L0X device to allow
|
||||
// to make the transaction thread-safe
|
||||
pthread_mutex_lock(&i2c_mutex);
|
||||
|
||||
// If the value is < 8 then a TCA9548A I2C Multiplexer
|
||||
// is being used so prefix each call with a call to
|
||||
// set the device at the multiplexer to the number
|
||||
// specified
|
||||
if (i2c_write_func(Dev->TCA9548A_Address, (1 << Dev->TCA9548A_Device), NULL, 0) < 0)
|
||||
{
|
||||
printf("TCA9548A read error\n");
|
||||
result = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
}
|
||||
}
|
||||
|
||||
if (result == VL53L0X_ERROR_NONE)
|
||||
{
|
||||
if (i2c_read_func(Dev->I2cDevAddr, cmd, data, len) < 0)
|
||||
{
|
||||
result = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
}
|
||||
}
|
||||
|
||||
if (Dev->TCA9548A_Device < 8)
|
||||
{
|
||||
pthread_mutex_unlock(&i2c_mutex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("i2c bus read not set.\n");
|
||||
result = VL53L0X_ERROR_CONTROL_INTERFACE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_LockSequenceAccess(VL53L0X_DEV Dev)
|
||||
{
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
return Status;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_UnlockSequenceAccess(VL53L0X_DEV Dev)
|
||||
{
|
||||
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
|
||||
return Status;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_WriteMulti(VL53L0X_DEV Dev, uint8_t index,
|
||||
uint8_t *pdata, uint32_t count)
|
||||
{
|
||||
return i2c_write(Dev, index, pdata, count);
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index,
|
||||
uint8_t *pdata, uint32_t count)
|
||||
{
|
||||
return i2c_read(Dev, index, pdata, count);
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_WrByte(VL53L0X_DEV Dev, uint8_t index, uint8_t data)
|
||||
{
|
||||
return i2c_write(Dev, index, &data, 1);
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_WrWord(VL53L0X_DEV Dev, uint8_t index, uint16_t data)
|
||||
{
|
||||
uint8_t buf[4];
|
||||
buf[1] = data>>0&0xFF;
|
||||
buf[0] = data>>8&0xFF;
|
||||
return i2c_write(Dev, index, buf, 2);
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_WrDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t data)
|
||||
{
|
||||
uint8_t buf[4];
|
||||
buf[3] = data>>0&0xFF;
|
||||
buf[2] = data>>8&0xFF;
|
||||
buf[1] = data>>16&0xFF;
|
||||
buf[0] = data>>24&0xFF;
|
||||
return i2c_write(Dev, index, buf, 4);
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_UpdateByte(VL53L0X_DEV Dev, uint8_t index,
|
||||
uint8_t AndData, uint8_t OrData)
|
||||
{
|
||||
|
||||
int32_t status_int;
|
||||
uint8_t data;
|
||||
|
||||
status_int = i2c_read(Dev, index, &data, 1);
|
||||
|
||||
if (status_int != 0)
|
||||
{
|
||||
return status_int;
|
||||
}
|
||||
|
||||
data = (data & AndData) | OrData;
|
||||
return i2c_write(Dev, index, &data, 1);
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_RdByte(VL53L0X_DEV Dev, uint8_t index, uint8_t *data)
|
||||
{
|
||||
uint8_t tmp = 0;
|
||||
int ret = i2c_read(Dev, index, &tmp, 1);
|
||||
*data = tmp;
|
||||
// printf("%u\n", tmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_RdWord(VL53L0X_DEV Dev, uint8_t index, uint16_t *data)
|
||||
{
|
||||
uint8_t buf[2];
|
||||
int ret = i2c_read(Dev, index, buf, 2);
|
||||
uint16_t tmp = 0;
|
||||
tmp |= buf[1]<<0;
|
||||
tmp |= buf[0]<<8;
|
||||
// printf("%u\n", tmp);
|
||||
*data = tmp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_RdDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t *data)
|
||||
{
|
||||
uint8_t buf[4];
|
||||
int ret = i2c_read(Dev, index, buf, 4);
|
||||
uint32_t tmp = 0;
|
||||
tmp |= buf[3]<<0;
|
||||
tmp |= buf[2]<<8;
|
||||
tmp |= buf[1]<<16;
|
||||
tmp |= buf[0]<<24;
|
||||
*data = tmp;
|
||||
// printf("%zu\n", tmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
VL53L0X_Error VL53L0X_PollingDelay(VL53L0X_DEV Dev)
|
||||
{
|
||||
usleep(5000);
|
||||
return VL53L0X_ERROR_NONE;
|
||||
}
|
Loading…
Reference in New Issue
Block a user