Car/Peripheral/Src/buzzer.c
2024-07-20 10:44:59 +08:00

33 lines
947 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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);
}