Files
bf_original_balance_chassis/modules/alarm/buzzer.c

32 lines
590 B
C
Raw Normal View History

2023-06-23 17:11:10 +08:00
#include "buzzer.h"
2024-05-20 22:22:24 +08:00
#include "main.h"
2024-05-20 22:22:24 +08:00
extern TIM_HandleTypeDef htim4;
static uint8_t tmp_warning_level = 0;
2023-06-23 17:11:10 +08:00
void BuzzerInit()
2023-06-23 17:11:10 +08:00
{
2024-05-20 22:22:24 +08:00
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3);
__HAL_TIM_SetCompare(&htim4, TIM_CHANNEL_3, 0);
2023-06-23 17:11:10 +08:00
}
2023-07-07 19:27:24 +08:00
2024-05-20 22:22:24 +08:00
void BuzzerOn( )
2023-07-07 19:27:24 +08:00
{
2024-05-20 22:22:24 +08:00
static int16_t temp = 4000 ;
if(temp < 1000)
{
BuzzerOff();
return;
}
__HAL_TIM_PRESCALER(&htim4,(int)(temp/1000));
__HAL_TIM_SetCompare(&htim4, TIM_CHANNEL_3, 10000);
temp -= 5 ;
2023-07-07 19:27:24 +08:00
}
2024-05-20 22:22:24 +08:00
void BuzzerOff(void)
2023-07-07 19:27:24 +08:00
{
2024-05-20 22:22:24 +08:00
__HAL_TIM_SetCompare(&htim4, TIM_CHANNEL_3, 0);
tmp_warning_level = 0;
2023-07-07 19:27:24 +08:00
}