#ifndef VL53L0X_PLATFORM_H #define VL53L0X_PLATFORM_H #include #include #include "main.h" #ifndef VL53L0X_SINGLE_DEVICE_DRIVER #define VL53L0X_SINGLE_DEVICE_DRIVER 0 #endif #include "vl53l0x_def.h" #ifdef __cplusplus extern "C" { #endif #ifndef VL53_USE_FREERTOS_DELAY #define VL53_USE_FREERTOS_DELAY 1 #endif #ifndef VL53L0X_COPYSTRING #define VL53L0X_COPYSTRING(dst, src) strcpy((dst), (src)) #endif #ifndef VL53L0X_DEFAULT_ADDR_8BIT #define VL53L0X_DEFAULT_ADDR_8BIT 0x52u #endif typedef struct { VL53L0X_DevData_t Data; uint8_t I2cDevAddr; /* ST API expects 8-bit address, default 0x52 */ uint8_t comms_type; uint16_t comms_speed_khz; I2C_HandleTypeDef *hi2c; GPIO_TypeDef *xshut_port; uint16_t xshut_pin; GPIO_TypeDef *gpio1_port; /* optional */ uint16_t gpio1_pin; void *bus_lock; /* optional shared mutex/lock handle */ const char *name; uint8_t id; /* user label: 1=左上, 2=左下, 3=右上, 4=右下 */ uint8_t is_present; uint16_t io_timeout_ms; } VL53L0X_Dev_t; typedef VL53L0X_Dev_t* VL53L0X_DEV; #define PALDevDataGet(Dev, field) ((Dev)->Data.field) #define PALDevDataSet(Dev, field, data) ((Dev)->Data.field = (data)) VL53L0X_Error VL53L0X_LockSequenceAccess(VL53L0X_DEV Dev); VL53L0X_Error VL53L0X_UnlockSequenceAccess(VL53L0X_DEV Dev); VL53L0X_Error VL53L0X_WriteMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count); VL53L0X_Error VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count); VL53L0X_Error VL53L0X_WrByte(VL53L0X_DEV Dev, uint8_t index, uint8_t data); VL53L0X_Error VL53L0X_WrWord(VL53L0X_DEV Dev, uint8_t index, uint16_t data); VL53L0X_Error VL53L0X_WrDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t data); VL53L0X_Error VL53L0X_RdByte(VL53L0X_DEV Dev, uint8_t index, uint8_t *data); VL53L0X_Error VL53L0X_RdWord(VL53L0X_DEV Dev, uint8_t index, uint16_t *data); VL53L0X_Error VL53L0X_RdDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t *data); VL53L0X_Error VL53L0X_UpdateByte(VL53L0X_DEV Dev, uint8_t index, uint8_t AndData, uint8_t OrData); VL53L0X_Error VL53L0X_PollingDelay(VL53L0X_DEV Dev); void VL53L0X_PlatformAttachBus(VL53L0X_DEV Dev, I2C_HandleTypeDef *hi2c, uint8_t i2c_addr_8bit, uint16_t io_timeout_ms, void *bus_lock); void VL53L0X_PlatformAttachPins(VL53L0X_DEV Dev, GPIO_TypeDef *xshut_port, uint16_t xshut_pin, GPIO_TypeDef *gpio1_port, uint16_t gpio1_pin); VL53L0X_Error VL53L0X_PlatformSetXShut(VL53L0X_DEV Dev, GPIO_PinState state); VL53L0X_Error VL53L0X_PlatformBootDevice(VL53L0X_DEV Dev, uint32_t reset_low_ms, uint32_t boot_wait_ms); VL53L0X_Error VL53L0X_PlatformChangeAddress(VL53L0X_DEV Dev, uint8_t new_addr_8bit); uint32_t VL53L0X_PlatformGetTick(void); #ifdef __cplusplus } #endif #endif /* VL53L0X_PLATFORM_H */