software:firmware
MakAir Firmware
buzzer_control.cpp File Reference

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

#include "../includes/buzzer_control.h"
#include "../includes/config.h"
#include "../includes/parameters.h"
#include "Arduino.h"

Go to the source code of this file.

Macros

#define BUZZER_FREQ   4000
 Buzzer frequency in Hz. More...
 
#define PERIOD_BUZZER_US   (1000000 / BUZZER_FREQ)
 

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...
 

Variables

HardwareTimer * Buzzer_Hw_Timer
 
uint32_t Buzzer_Timer_Channel
 

Detailed Description

Abstraction to switch buzzer ON or OFF.

Author
Makers For Life

Definition in file buzzer_control.cpp.

Macro Definition Documentation

◆ BUZZER_FREQ

#define BUZZER_FREQ   4000

Buzzer frequency in Hz.

Definition at line 18 of file buzzer_control.cpp.

◆ PERIOD_BUZZER_US

#define PERIOD_BUZZER_US   (1000000 / BUZZER_FREQ)

Definition at line 20 of file buzzer_control.cpp.

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

Variable Documentation

◆ Buzzer_Hw_Timer

HardwareTimer* Buzzer_Hw_Timer

Definition at line 22 of file buzzer_control.cpp.

◆ Buzzer_Timer_Channel

uint32_t Buzzer_Timer_Channel

Definition at line 23 of file buzzer_control.cpp.