Yilin Sun
1bddb7e404
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Yilin Sun <imi415@imi.moe>
38 lines
1.0 KiB
C
38 lines
1.0 KiB
C
#include "app_ranging_impl.h"
|
|
|
|
#define APP_I2C_READ(addr) ((addr << 1U) | 0x01U)
|
|
#define APP_I2C_WRITE(addr) ((addr << 1U) & (~0x01U))
|
|
|
|
VL53L1_Error app_ranging_delay_us(void *pdev, uint32_t delay_usec) {
|
|
HAL_Delay(1);
|
|
|
|
return VL53L1_ERROR_NONE;
|
|
}
|
|
|
|
VL53L1_Error app_ranging_delay_ms(void *pdev, uint32_t delay_msec) {
|
|
HAL_Delay(delay_msec);
|
|
|
|
return VL53L1_ERROR_NONE;
|
|
}
|
|
|
|
VL53L1_Error app_ranging_i2c_xfer(void *pdev, VL53L1_Dev_Xfer_Desc_t *xfer) {
|
|
app_ranging_impl_t *impl = pdev;
|
|
|
|
HAL_StatusTypeDef ret;
|
|
|
|
if (xfer->TxSize) {
|
|
ret = HAL_I2C_Master_Transmit(impl->hi2c, APP_I2C_WRITE(impl->dev_addr), xfer->TxData, xfer->TxSize, 1000);
|
|
if (ret != HAL_OK) {
|
|
return VL53L1_ERROR_CONTROL_INTERFACE;
|
|
}
|
|
}
|
|
|
|
if (xfer->RxSize) {
|
|
ret = HAL_I2C_Master_Receive(impl->hi2c, APP_I2C_READ(impl->dev_addr), xfer->RxData, xfer->RxSize, 1000);
|
|
if (ret != HAL_OK) {
|
|
return VL53L1_ERROR_CONTROL_INTERFACE;
|
|
}
|
|
}
|
|
|
|
return VL53L1_ERROR_NONE;
|
|
} |