#include "buzzer.h" #include "timer.h" int timed_beep_event_id = -1; int times_beep_event_id = -1; inline void BUZZER_Start() { HAL_GPIO_WritePin(FM_K2_POWERC_GPIO_Port, FM_K2_POWERC_Pin, GPIO_PIN_RESET); } inline void BUZZER_Stop() { HAL_GPIO_WritePin(FM_K2_POWERC_GPIO_Port, FM_K2_POWERC_Pin, GPIO_PIN_SET); } /// @brief 启动蜂鸣器鸣叫 /// @param time 鸣叫时间,单位1毫秒 void BUZZER_StartTimed(uint16_t time) { BUZZER_Start(); timed_beep_event_id = TIMER_AddDelayEvent(timed_beep_event_id, BUZZER_Stop, time); } /// @brief 启动蜂鸣器鸣叫n次,每次叫on_time毫秒,停off_time毫秒 /// @param on_time 鸣叫时间,单位1毫秒 /// @param off_time 停止鸣叫时间,单位1毫秒 void BUZZER_StartNTimes(uint8_t n, uint16_t on_time, uint16_t off_time) { times_beep_event_id = TIMER_AddFiniteLoopEventWithParam(times_beep_event_id, BUZZER_StartTimed, on_time + off_time, n, on_time); }