The VL53L1CB proximity sensor, based on ST’s FlightSense™, Time-of-Flight technology.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: VL53L1CB_noshield_1sensor_polls_auton VL53L1CB_noshield_1sensor_interrupt_auton X_NUCLEO_53L1A2
Based on VL53L1 library, this is a library for the VL53L1CB ToF chip.
Diff: inc/VL53L1CB.h
- Revision:
- 18:0696efe39d08
- Parent:
- 17:ca0ce4daf573
--- a/inc/VL53L1CB.h Wed Jun 23 12:57:26 2021 +0000 +++ b/inc/VL53L1CB.h Wed Jul 21 17:06:38 2021 +0200 @@ -1,11 +1,11 @@ /******************************************************************************* - * @file vl53l1x_class.h + * @file vl53l1cb_class.h * @author JS * @version V0.0.1 * @date 15-January-2019 * @brief Header file for VL53L1 sensor component ****************************************************************************** - Copyright Ãâé 2019, STMicroelectronics International N.V. + Copyright © 2021, 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: @@ -35,13 +35,13 @@ #ifdef _MSC_VER -# ifdef VL53L1X_API_EXPORTS -# define VL53L1X_API __declspec(dllexport) +# ifdef VL53L1CB_API_EXPORTS +# define VL53L1CB_API __declspec(dllexport) # else -# define VL53L1X_API +# define VL53L1CB_API # endif #else -# define VL53L1X_API +# define VL53L1CB_API #endif @@ -56,93 +56,29 @@ #include "vl53l1_error_codes.h" #include "vl53l1_platform_user_data.h" -//#include "DevI2C.h" #include "ToF_I2C.h" /**********************************************************/ #include "vl53l1_def.h" /***********************************************************/ -#define VL53L1_IMPLEMENTATION_VER_MAJOR 1 -#define VL53L1_IMPLEMENTATION_VER_MINOR 0 -#define VL53L1_IMPLEMENTATION_VER_SUB 1 -#define VL53L1_IMPLEMENTATION_VER_REVISION 0000 +#define VL53L1CB_IMPLEMENTATION_VER_MAJOR 1 +#define VL53L1CB_IMPLEMENTATION_VER_MINOR 0 +#define VL53L1CB_IMPLEMENTATION_VER_SUB 2 +#define VL53L1CB_IMPLEMENTATION_VER_REVISION 0000 typedef int8_t VL53L1CB_ERROR; -//#define SOFT_RESET 0x0000 -#define VL53L1_I2C_SLAVE__DEVICE_ADDRESS 0x0001 -#define VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND 0x0008 -#define ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS 0x0016 -#define ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS 0x0018 -#define ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS 0x001A -#define ALGO__PART_TO_PART_RANGE_OFFSET_MM 0x001E -#define MM_CONFIG__INNER_OFFSET_MM 0x0020 -#define MM_CONFIG__OUTER_OFFSET_MM 0x0022 -#define GPIO_HV_MUX__CTRL 0x0030 -#define GPIO__TIO_HV_STATUS 0x0031 -#define SYSTEM__INTERRUPT_CONFIG_GPIO 0x0046 -#define PHASECAL_CONFIG__TIMEOUT_MACROP 0x004B -#define RANGE_CONFIG__TIMEOUT_MACROP_A_HI 0x005E -#define RANGE_CONFIG__VCSEL_PERIOD_A 0x0060 -#define RANGE_CONFIG__VCSEL_PERIOD_B 0x0063 -#define RANGE_CONFIG__TIMEOUT_MACROP_B_HI 0x0061 -#define RANGE_CONFIG__TIMEOUT_MACROP_B_LO 0x0062 -#define RANGE_CONFIG__SIGMA_THRESH 0x0064 -#define RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS 0x0066 -#define RANGE_CONFIG__VALID_PHASE_HIGH 0x0069 -#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD 0x006C -#define SYSTEM__THRESH_HIGH 0x0072 -#define SYSTEM__THRESH_LOW 0x0074 -#define SD_CONFIG__WOI_SD0 0x0078 -#define SD_CONFIG__INITIAL_PHASE_SD0 0x007A -#define ROI_CONFIG__USER_ROI_CENTRE_SPAD 0x007F -#define ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE 0x0080 -#define SYSTEM__SEQUENCE_CONFIG 0x0081 -#define VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD 0x0082 -#define SYSTEM__INTERRUPT_CLEAR 0x0086 -#define SYSTEM__MODE_START 0x0087 -#define VL53L1_RESULT__RANGE_STATUS 0x0089 -#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0 0x008C -#define RESULT__AMBIENT_COUNT_RATE_MCPS_SD 0x0090 -#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0 0x0096 -#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0 0x0098 -#define VL53L1_RESULT__OSC_CALIBRATE_VAL 0x00DE -#define VL53L1_FIRMWARE__SYSTEM_STATUS 0x00E5 -#define VL53L1_IDENTIFICATION__MODEL_ID 0x010F -#define VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD 0x013E - - -#define VL53L1_DEFAULT_DEVICE_ADDRESS 0x52 - -#define VL53L1_REG_IDENTIFICATION_MODEL_ID 0x010F - -/**************************************** - * PRIVATE define do not edit - ****************************************/ - -/** - * @brief defines SW Version - */ -//typedef struct { - // uint8_t major; /*!< major number */ -// uint8_t minor; /*!< minor number */ -// uint8_t build; /*!< build number */ -// uint32_t revision; /*!< revision number */ -//} VL53L1X_Version_t; - +#define VL53L1_DEFAULT_DEVICE_ADDRESS 0x52 +#define VL53L1_REG_IDENTIFICATION_MODEL_ID 0x010F /* Classes -------------------------------------------------------------------*/ /** Class representing a VL53L1 sensor component */ class VL53L1CB : public RangeSensor { - - - public: - #define VL53L1DevStructGetLLDriverHandle(Dev) (&Dev->Data.LLData) /** Constructor * @param[in] &i2c device I2C to be used for communication @@ -153,7 +89,8 @@ VL53L1CB(ToF_DevI2C *i2c, DigitalOut *pin, PinName pin_gpio1, uint8_t dev_addr = VL53L1_DEFAULT_DEVICE_ADDRESS) : RangeSensor(), dev_i2c(i2c), _gpio0(pin) { - MyDevice.i2c_slave_address=dev_addr; + MyDevice.i2c_slave_address = dev_addr; + MyDevice.dev_i2c = (void*) i2c; Device = &MyDevice; _expgpio0 = NULL; @@ -174,7 +111,8 @@ uint8_t dev_addr = VL53L1_DEFAULT_DEVICE_ADDRESS) : dev_i2c(i2c), _expgpio0(pin) { - MyDevice.i2c_slave_address=dev_addr; + MyDevice.i2c_slave_address = dev_addr; + MyDevice.dev_i2c = (void*) i2c; Device = &MyDevice; _gpio0 = NULL; @@ -219,7 +157,7 @@ *_expgpio0 = 1; } } -#if (MBED_VERSION > 60300) +#if (MBED_VERSION > 60300) thread_sleep_for(100); #else wait_ms(100); // NEEDS A DELAY BETWEEN SENSORS @@ -241,7 +179,7 @@ *_expgpio0 = 0; } } -#if (MBED_VERSION > 60300) +#if (MBED_VERSION > 60300) thread_sleep_for(100); #else wait_ms(100); // NEEDS A DELAY BETWEEN SENSORS @@ -267,23 +205,15 @@ VL53L1CB_ERROR InitSensor(uint8_t address){ VL53L1CB_ERROR status = 0; - uint8_t sensorState = 0; VL53L1CB_Off(); VL53L1CB_On(); - status = VL53L1CB_SetI2CAddress(address); + status = VL53L1CB_WaitDeviceBooted(); + if(!status){ + status = VL53L1CB_SetI2CAddress(address); + } if(!status){ status = VL53L1CB_SensorInit(); } - - while(!status && !sensorState) { - status = VL53L1CB_BootState(&sensorState); - -#if (MBED_VERSION > 60300) - thread_sleep_for(2); -#else - wait_ms(2); // NEEDS A DELAY BETWEEN SENSORS -#endif - } return status; } @@ -401,15 +331,13 @@ { int status; uint16_t distance; - status = VL53L1CB_GetDistance(&distance); + status = get_measurement(&distance); *piData = (uint32_t) distance; return status; } -/* VL53L1X_api.h functions */ - - +/* vl53l1_api.h functions */ /** * @brief This function returns the SW driver version @@ -429,58 +357,17 @@ VL53L1CB_ERROR VL53L1CB_SensorInit(); /** - * @brief This function clears the interrupt, to be called after a ranging data reading - * to arm the interrupt for the next data ready event. - */ - VL53L1CB_ERROR VL53L1CB_ClearInterrupt(); - - - /** - * @brief This function returns the current interrupt polarity\n - * 1=active high (default), 0=active low - */ - VL53L1CB_ERROR VL53L1CB_GetInterruptPolarity(uint8_t *pIntPol); - - /** - * @brief This function starts the ranging distance operation\n - * The ranging operation is continuous. The clear interrupt has to be done after each get data to allow the interrupt to raise when the next data is ready\n - * 1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required. - */ - VL53L1CB_ERROR VL53L1CB_StartRanging(); - - /** - * @brief This function stops the ranging. - */ - VL53L1CB_ERROR VL53L1CB_StopRanging(); - - - - /** * @brief This function returns the boot state of the device (1:booted, 0:not booted) */ VL53L1CB_ERROR VL53L1CB_BootState(uint8_t *state); - /** - * @brief This function returns the sensor id, sensor Id must be 0xEEAC - */ - // VL53L1CB_ERROR VL53L1X_GetSensorId(uint16_t *id); - - /** - * @brief This function returns the distance measured by the sensor in mm - */ - VL53L1CB_ERROR VL53L1CB_GetDistance(uint16_t *distance); - - - /**************************************************************************/ - VL53L1CB_ERROR VL53L1CB_WaitDeviceBooted(VL53L1_DEV Dev); - + + VL53L1CB_ERROR VL53L1CB_WaitDeviceBooted(); VL53L1CB_ERROR VL53L1CB_GetCalibrationData(VL53L1_CalibrationData_t *pCalibrationData); - - VL53L1_GPIO_Interrupt_Mode ConvertModeToLLD(VL53L1CB_ERROR *pStatus, VL53L1_ThresholdMode CrossMode); @@ -507,7 +394,7 @@ char *pPalStateString); - VL53L1CB_ERROR VL53L1CB_GetPalState(VL53L1_DEV Dev, VL53L1_State *pPalState); + VL53L1CB_ERROR VL53L1CB_GetPalState(VL53L1_State *pPalState); VL53L1CB_ERROR VL53L1CB_DataInit(); @@ -685,12 +572,6 @@ VL53L1CB_ERROR VL53L1CB_WaitValueMaskEx(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uint16_t index, uint8_t value, uint8_t mask, uint32_t poll_delay_ms); VL53L1CB_ERROR VL53L1CB_SetDeviceAddress(VL53L1_DEV Dev, uint8_t DeviceAddress); - - // from vl53l1_api_debug.c - - VL53L1CB_ERROR VL53L1CB_get_additional_data( - VL53L1_DEV Dev, - VL53L1_additional_data_t *pdata); protected: @@ -712,4 +593,4 @@ }; -#endif /* _VL53L1X_CLASS_H_ */ \ No newline at end of file +#endif /* _VL53L1CB_CLASS_H_ */