You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
942 B
48 lines
942 B
6 months ago
|
#include "buzzer.h"
|
||
|
#include "sw_timer.h"
|
||
|
|
||
|
|
||
|
static bool isBuzzerOn;
|
||
|
static uint32_t BuzzerStartTick;
|
||
|
static uint32_t BuzzerOnTimeCount;
|
||
|
|
||
|
static void Buzzer_Output_Process(void);
|
||
|
|
||
|
void Buzzer_Initialization(void)
|
||
|
{
|
||
|
HAL_GPIO_ConfigOutput(GPIO_BUZZER_PORT, GPIO_BUZZER_PIN_NUM, PUSH_PULL_OUTPUT);
|
||
|
HAL_GPIO_ConfigPullup(GPIO_BUZZER_PORT, GPIO_BUZZER_PIN_NUM, PUPDx_EnablePU);
|
||
|
|
||
|
SW_Timer_Callback_Register(SW_TIMER_RUN_CONTINUE, 1, Buzzer_Output_Process);
|
||
|
}
|
||
|
|
||
|
void Buzzer_On(uint32_t BuzzerOnTime)
|
||
|
{
|
||
|
isBuzzerOn = true;
|
||
|
BuzzerStartTick = millis();
|
||
|
BuzzerOnTimeCount = BuzzerOnTime;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
static void Buzzer_Output_Process(void)
|
||
|
{
|
||
|
if(isBuzzerOn == true)
|
||
|
{
|
||
|
if((millis() - BuzzerStartTick) <= BuzzerOnTimeCount)
|
||
|
{
|
||
|
GPIO_BUZZER_ON;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
isBuzzerOn = false;
|
||
|
GPIO_BUZZER_OFF;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
GPIO_BUZZER_OFF;;
|
||
|
}
|
||
|
}
|
||
|
|