#ifndef PWM_H #define PWM_H /* Includes ----------------------------------------------------------------- */ #include #include "bsp\bsp.h" /* Exported constants ------------------------------------------------------- */ /* Exported macro ----------------------------------------------------------- */ /* Exported types ----------------------------------------------------------- */ /* PWM通道 */ typedef enum { BSP_PWM_IMU_HEAT, BSP_PWM_BUZZER, } BSP_PWM_Channel_t; typedef enum { BUZZER_OFF, // 蜂鸣器关闭 BUZZER_SINGLE, // 单次鸣叫(滴) BUZZER_DOUBLE, // 双次鸣叫(滴-滴) BUZZER_TRIPLE, // 三次鸣叫(滴-滴-滴) BUZZER_CONTINUOUS,// 持续鸣叫(滴————) BUZZER_BEEPING // 间歇鸣叫(滴...滴...滴...) } BuzzerMode; typedef enum { STATE_IDLE, // 空闲状态(未激活) STATE_ON, // 鸣叫状态(PWM输出中) STATE_OFF // 静音间隔状态(等待下次鸣叫) } BuzzerState; static struct { BuzzerState state; // 当前状态 BuzzerMode mode; // 当前模式 uint32_t timer; // 时间记录器 uint8_t count; // 鸣叫次数计数器 float duty; // PWM占空比(0.0-1.0) uint16_t on_time; // 鸣叫持续时间(ms) uint16_t off_time; // 静音间隔时间(ms) } buzzer; /* Exported functions prototypes -------------------------------------------- */ int8_t BSP_PWM_Start(BSP_PWM_Channel_t ch); int8_t BSP_PWM_Set(BSP_PWM_Channel_t ch, float duty_cycle); int8_t BSP_PWM_Stop(BSP_PWM_Channel_t ch); void Buzzer_Init(void); void Buzzer_Update(BuzzerMode mode, float duty_cycle, uint16_t on_time_ms, uint16_t off_time_ms); #endif