57 lines
1.8 KiB
C
57 lines
1.8 KiB
C
#ifndef VL53_BOARD_H
|
||
#define VL53_BOARD_H
|
||
|
||
#include <stdint.h>
|
||
#include <string.h>
|
||
#include "vl53l0x_api.h"
|
||
#include "vl53l0x_platform.h"
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#define VL53_MAX_DEVS_PER_BOARD 4
|
||
|
||
typedef struct {
|
||
I2C_HandleTypeDef *hi2c;
|
||
GPIO_TypeDef *xshut_port;
|
||
uint16_t xshut_pin;
|
||
uint8_t runtime_addr_8bit;
|
||
const char *name;
|
||
uint8_t id;
|
||
} Vl53BoardHwCfg_t;
|
||
|
||
/* ================= 内部EMA滤波器结构 ================= */
|
||
typedef struct {
|
||
float x; // 当前滤波值 (滤波后的距离)
|
||
float alpha; // 平滑系数 (0.0~1.0, 越大响应越快)
|
||
uint8_t initialized; // 防止第一次开机从0缓慢爬升
|
||
} Vl53EMA_t;
|
||
|
||
/* ================= 快照数据结构 (对外接口) ================= */
|
||
typedef struct {
|
||
uint32_t tick_ms;
|
||
uint16_t range_mm[VL53_MAX_DEVS_PER_BOARD]; /* 接口1:原始硬件数据 */
|
||
float range_mm_filtered[VL53_MAX_DEVS_PER_BOARD]; /* 接口2:EMA平滑数据 */
|
||
uint8_t range_status[VL53_MAX_DEVS_PER_BOARD];
|
||
uint8_t valid_mask;
|
||
} Vl53BoardSnapshot_t;
|
||
|
||
typedef struct {
|
||
VL53L0X_Dev_t dev[VL53_MAX_DEVS_PER_BOARD];
|
||
Vl53EMA_t ema[VL53_MAX_DEVS_PER_BOARD]; /* 每个传感器配备一个专属EMA滤波器 */
|
||
uint8_t init_mask;
|
||
uint8_t dev_count;
|
||
uint32_t timing_budget_us;
|
||
} Vl53Board_t;
|
||
|
||
VL53L0X_Error Vl53Board_Init(Vl53Board_t *board, const Vl53BoardHwCfg_t *hw_cfgs, uint8_t count, uint32_t timing_budget_us);
|
||
VL53L0X_Error Vl53Board_StartContinuous(Vl53Board_t *board);
|
||
VL53L0X_Error Vl53Board_StopContinuous(Vl53Board_t *board);
|
||
VL53L0X_Error Vl53Board_ReadAll(Vl53Board_t *board, Vl53BoardSnapshot_t *snapshot);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif /* VL53_BOARD_H */ |