Car/Peripheral/Src/buzzer.c

33 lines
947 B
C
Raw Normal View History

2024-07-18 11:29:28 +08:00
#include "buzzer.h"
2024-07-20 10:44:59 +08:00
2024-07-18 11:29:28 +08:00
#include "timer.h"
2024-07-20 10:44:59 +08:00
int timed_beep_event_id = -1;
int times_beep_event_id = -1;
2024-07-18 11:29:28 +08:00
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);
}
2024-07-20 10:44:59 +08:00
/// @brief 启动蜂鸣器鸣叫
/// @param time 鸣叫时间单位1毫秒
void BUZZER_StartTimed(uint16_t time)
2024-07-18 11:29:28 +08:00
{
BUZZER_Start();
2024-07-20 10:44:59 +08:00
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);
2024-07-18 11:29:28 +08:00
}