40 lines
1.1 KiB
C
40 lines
1.1 KiB
C
#ifndef __BSP_HALL_H
|
|
#define __BSP_HALL_H
|
|
|
|
|
|
#include "main.h"
|
|
#include "bsp_motor.h" // 确保 motor_id_t 类型可见
|
|
#include "elog.h"
|
|
#include "cmsis_os.h"
|
|
|
|
/**
|
|
* @brief 霍尔周期/脉冲计数结构体
|
|
*/
|
|
typedef struct {
|
|
uint32_t pulse_count; // 总脉冲计数值
|
|
float speed_rpm; // 计算得到的转速 (RPM)
|
|
} hall_sensor_t;
|
|
|
|
/* 获取实时 RPM 接口 */
|
|
float hall_get_speed(motor_id_t motor_id);
|
|
|
|
/* 初始化霍尔传感器 (GPIO 外部中断模式) */
|
|
void hall_init(void);
|
|
|
|
/* 外部中断处理接口 (供 HAL 层调用,请勿在应用层直接调用) */
|
|
void hall_pulse_callback(uint16_t GPIO_Pin);
|
|
|
|
// /* 获取指定霍尔传感器的计数值 */
|
|
// uint32_t hall_get_count(motor_id_t motor_id);
|
|
|
|
/* 每隔固定时间调用此函数计算并更新转速 (例如在 100ms 任务中调用) */
|
|
float hall_update_speed(motor_id_t motor_id, uint32_t interval_ms);
|
|
|
|
// /* 清位计数值 */
|
|
// void hall_reset_count(motor_id_t motor_id);
|
|
|
|
// /* 计算转速的原始接口 (内部使用) */
|
|
// float hall_calculate_speed(motor_id_t motor_id, uint32_t interval_ms);
|
|
|
|
#endif /* __BSP_HALL_H */
|