software:firmware
MakAir Firmware
buzzer_control.h File Reference

Abstraction to switch buzzer ON or OFF. More...

Go to the source code of this file.

Functions

void BuzzerControl_Init (void)
 Initialization of HardwareTimer for buzzer. More...
 
void BuzzerControl_On (void)
 Switch buzzer ON. More...
 
void BuzzerControl_Off (void)
 Switch buzzer OFF. More...
 

Detailed Description

Abstraction to switch buzzer ON or OFF.

Author
Makers For Life

Definition in file buzzer_control.h.

Function Documentation

◆ BuzzerControl_Init()

void BuzzerControl_Init ( void  )

Initialization of HardwareTimer for buzzer.

Definition at line 27 of file buzzer_control.cpp.

27  {
28  TIM_TypeDef* Buzzer_Timer_Number = reinterpret_cast<TIM_TypeDef*>(
29  pinmap_peripheral(digitalPinToPinName(PIN_BUZZER), PinMap_PWM));
31  STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(PIN_BUZZER), PinMap_PWM));
32 
33  // Hardware 2: the buzzer has no internal oscillator. uC must generate a 4khz square on
34  // PIN_BUZZER (timer 2, channel 1)
35  Buzzer_Hw_Timer = new HardwareTimer(Buzzer_Timer_Number);
36  Buzzer_Hw_Timer->setMode(Buzzer_Timer_Channel, TIMER_OUTPUT_COMPARE_PWM1, PIN_BUZZER);
37  Buzzer_Hw_Timer->setOverflow(PERIOD_BUZZER_US, MICROSEC_FORMAT);
39  MICROSEC_COMPARE_FORMAT);
40  digitalWrite(PIN_BUZZER, LOW);
41 }
#define PERIOD_BUZZER_US
HardwareTimer * Buzzer_Hw_Timer
uint32_t Buzzer_Timer_Channel
#define PIN_BUZZER
Definition: parameters.h:274

◆ BuzzerControl_Off()

void BuzzerControl_Off ( void  )

Switch buzzer OFF.

Definition at line 45 of file buzzer_control.cpp.

45  {
46  Buzzer_Hw_Timer->pause();
47  digitalWrite(PIN_BUZZER, LOW); // Stops current consumption in the buzzer
48 }

◆ BuzzerControl_On()

void BuzzerControl_On ( void  )

Switch buzzer ON.

Definition at line 43 of file buzzer_control.cpp.

43 { Buzzer_Hw_Timer->resume(); }