sentry_chassis_hzz/bsp/bsp_buzzer.c

26 lines
530 B
C
Raw Normal View History

2022-10-20 17:13:02 +08:00
#include "bsp_buzzer.h"
#include "main.h"
2022-11-13 14:40:21 +08:00
2022-10-20 17:13:02 +08:00
extern TIM_HandleTypeDef htim4;
static uint8_t tmp_warning_level = 0;
2022-10-20 17:13:02 +08:00
void BuzzerInit()
2022-11-13 21:46:52 +08:00
{
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3);
2022-11-13 21:46:52 +08:00
}
void BuzzerOn(uint16_t psc, uint16_t pwm, uint8_t level)
2022-11-13 14:40:21 +08:00
{
if (level > tmp_warning_level)
2022-11-13 14:40:21 +08:00
{
tmp_warning_level = level;
2022-11-13 14:40:21 +08:00
__HAL_TIM_PRESCALER(&htim4, psc);
__HAL_TIM_SetCompare(&htim4, TIM_CHANNEL_3, pwm);
}
2022-10-20 17:13:02 +08:00
}
void BuzzerOff(void)
2022-10-20 17:13:02 +08:00
{
__HAL_TIM_SetCompare(&htim4, TIM_CHANNEL_3, 0);
tmp_warning_level = 0;
2022-10-20 17:13:02 +08:00
}