software:firmware
MakAir Firmware
buzzer.cpp File Reference

Buzzer related functions. More...

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

Go to the source code of this file.

Macros

#define BZ_OFF   (0u)
 
#define BZ_ON   (1u)
 
#define BUZZER_HIGH_PRIO_SIZE   40
 High priority alarm buzzer pattern size. More...
 
#define BUZZER_MEDIUM_PRIO_SIZE   8
 Medium priority alarm buzzer pattern size. More...
 
#define BUZZER_LOW_PRIO_SIZE   8
 Low priority alarm buzzer pattern size. More...
 
#define BUZZER_BOOT_SIZE   8
 Boot buzzer pattern size. More...
 
Definition of bips durations

Internals

10 ticks = 1 ms

Warning
it is not possible to have 1 tick = 1 ms because prescaler is 16 bits and input STM32F411: frequency is 100Mhz STM32F401: frequency is 84Mhz

As waiting times defined below are greater than 2^16, the timer must be a 32 bits timer.

#define TIMER_TICK_PER_MS   10
 
#define BIP   (100 * TIMER_TICK_PER_MS)
 
#define BIP_PAUSE   BIP
 
#define BEEEEP   (250 * TIMER_TICK_PER_MS)
 
#define BEEEEP_PAUSE   BEEEEP
 
#define PAUSE_120S   (120 * 1000 * TIMER_TICK_PER_MS)
 
#define PAUSE_20S   (20 * 1000 * TIMER_TICK_PER_MS)
 
#define PAUSE_10S   (10 * 1000 * TIMER_TICK_PER_MS)
 
#define PAUSE_1S   (1 * 1000 * TIMER_TICK_PER_MS)
 

Functions

void Update_IT_callback (HardwareTimer *)
 When timer period expires, switch to next state in the pattern of the buzzer. More...
 
void Buzzer_Init ()
 Initialization of HardwareTimer for buzzer. More...
 
void Buzzer_Start (const uint32_t *Buzzer, uint32_t Size, bool RepeatBuzzer)
 Generic function to activate a buzzer. More...
 
void Buzzer_Mute ()
 Mute the buzzer for 120s. More...
 
void Buzzer_Resume ()
 Resume the muted alarm. More...
 
void Buzzer_High_Prio_Start (void)
 Activate the buzzer pattern for high priority alarms. More...
 
void Buzzer_Medium_Prio_Start (void)
 Activate the buzzer pattern for medium priority alarms. More...
 
void Buzzer_Low_Prio_Start (void)
 Activate the buzzer pattern for low priority alarms. More...
 
void Buzzer_Boot_Start (void)
 Activate boot bip. More...
 
void Buzzer_Stop (void)
 Stop Buzzer. More...
 

Variables

const uint32_t Buzzer_High_Prio [BUZZER_HIGH_PRIO_SIZE]
 High priority alarm buzzer pattern definition, composed of multiple couple of states (Actif/Inactif) and duration (miliseconds) More...
 
const uint32_t Buzzer_Medium_Prio [BUZZER_MEDIUM_PRIO_SIZE]
 Medium priority alarm buzzer pattern definition, composed of multiple couple of states (Actif/Inactif) and duration (miliseconds) More...
 
const uint32_t Buzzer_Low_Prio [BUZZER_LOW_PRIO_SIZE]
 Low priority alarm buzzer pattern definition, composed of multiple couple of states (Actif/Inactif) and duration (miliseconds) More...
 
const uint32_t Buzzer_Boot [BUZZER_BOOT_SIZE]
 Boot buzzer pattern definition, composed of multiple couple of states (Actif/Inactif) and duration (miliseconds) More...
 
const uint32_t * Active_Buzzer = nullptr
 
uint32_t Active_Buzzer_Index = 0
 
uint32_t Active_Buzzer_Size = 2
 
bool Active_Buzzer_Repeat = false
 
bool Active_Buzzer_Has_Begun = false
 
bool Buzzer_Muted = false
 
HardwareTimer * BuzzerTim
 
uint32_t BuzzerTimerChannel
 

Detailed Description

Buzzer related functions.

Author
Makers For Life

Definition in file buzzer.cpp.

Macro Definition Documentation

◆ BEEEEP

#define BEEEEP   (250 * TIMER_TICK_PER_MS)

Definition at line 36 of file buzzer.cpp.

◆ BEEEEP_PAUSE

#define BEEEEP_PAUSE   BEEEEP

Definition at line 37 of file buzzer.cpp.

◆ BIP

#define BIP   (100 * TIMER_TICK_PER_MS)

Definition at line 34 of file buzzer.cpp.

◆ BIP_PAUSE

#define BIP_PAUSE   BIP

Definition at line 35 of file buzzer.cpp.

◆ BUZZER_BOOT_SIZE

#define BUZZER_BOOT_SIZE   8

Boot buzzer pattern size.

Definition at line 75 of file buzzer.cpp.

◆ BUZZER_HIGH_PRIO_SIZE

#define BUZZER_HIGH_PRIO_SIZE   40

High priority alarm buzzer pattern size.

Definition at line 48 of file buzzer.cpp.

◆ BUZZER_LOW_PRIO_SIZE

#define BUZZER_LOW_PRIO_SIZE   8

Low priority alarm buzzer pattern size.

Definition at line 67 of file buzzer.cpp.

◆ BUZZER_MEDIUM_PRIO_SIZE

#define BUZZER_MEDIUM_PRIO_SIZE   8

Medium priority alarm buzzer pattern size.

Definition at line 59 of file buzzer.cpp.

◆ BZ_OFF

#define BZ_OFF   (0u)

Definition at line 44 of file buzzer.cpp.

◆ BZ_ON

#define BZ_ON   (1u)

Definition at line 45 of file buzzer.cpp.

◆ PAUSE_10S

#define PAUSE_10S   (10 * 1000 * TIMER_TICK_PER_MS)

Definition at line 40 of file buzzer.cpp.

◆ PAUSE_120S

#define PAUSE_120S   (120 * 1000 * TIMER_TICK_PER_MS)

Definition at line 38 of file buzzer.cpp.

◆ PAUSE_1S

#define PAUSE_1S   (1 * 1000 * TIMER_TICK_PER_MS)

Definition at line 41 of file buzzer.cpp.

◆ PAUSE_20S

#define PAUSE_20S   (20 * 1000 * TIMER_TICK_PER_MS)

Definition at line 39 of file buzzer.cpp.

◆ TIMER_TICK_PER_MS

#define TIMER_TICK_PER_MS   10

Definition at line 33 of file buzzer.cpp.

Function Documentation

◆ Buzzer_Boot_Start()

void Buzzer_Boot_Start ( void  )

Activate boot bip.

Definition at line 194 of file buzzer.cpp.

const uint32_t Buzzer_Boot[BUZZER_BOOT_SIZE]
Boot buzzer pattern definition, composed of multiple couple of states (Actif/Inactif) and duration (m...
Definition: buzzer.cpp:79
#define BUZZER_BOOT_SIZE
Boot buzzer pattern size.
Definition: buzzer.cpp:75
void Buzzer_Start(const uint32_t *Buzzer, uint32_t Size, bool RepeatBuzzer)
Generic function to activate a buzzer.
Definition: buzzer.cpp:140

◆ Buzzer_High_Prio_Start()

void Buzzer_High_Prio_Start ( void  )

Activate the buzzer pattern for high priority alarms.

Definition at line 186 of file buzzer.cpp.

const uint32_t Buzzer_High_Prio[BUZZER_HIGH_PRIO_SIZE]
High priority alarm buzzer pattern definition, composed of multiple couple of states (Actif/Inactif) ...
Definition: buzzer.cpp:52
#define BUZZER_HIGH_PRIO_SIZE
High priority alarm buzzer pattern size.
Definition: buzzer.cpp:48

◆ Buzzer_Init()

void Buzzer_Init ( )

Initialization of HardwareTimer for buzzer.

Definition at line 128 of file buzzer.cpp.

128  {
129  // Buzzer HardwareTimer object creation
130  BuzzerTim = new HardwareTimer(BUZZER_TIMER);
131 
133  // CPU Clock down to 10 kHz
134  BuzzerTim->setPrescaleFactor((BuzzerTim->getTimerClkFreq() / (TIMER_TICK_PER_MS * 1000)));
135  BuzzerTim->setOverflow(1); // don't care right now, timer is not started in init
136  BuzzerTim->setMode(BUZZER_TIM_CHANNEL, TIMER_OUTPUT_COMPARE, NC);
137  BuzzerTim->attachInterrupt(Update_IT_callback);
138 }
void Update_IT_callback(HardwareTimer *)
When timer period expires, switch to next state in the pattern of the buzzer.
Definition: buzzer.cpp:102
#define TIMER_TICK_PER_MS
Definition: buzzer.cpp:33
HardwareTimer * BuzzerTim
Definition: buzzer.cpp:91
#define BUZZER_TIMER
Hardware Timer to use for the buzzer.
Definition: buzzer.h:14
#define BUZZER_TIM_CHANNEL
Hardware Timer channel to use for the buzzer.
Definition: buzzer.h:17
void BuzzerControl_Off(void)
Switch buzzer OFF.

◆ Buzzer_Low_Prio_Start()

void Buzzer_Low_Prio_Start ( void  )

Activate the buzzer pattern for low priority alarms.

Definition at line 192 of file buzzer.cpp.

const uint32_t Buzzer_Low_Prio[BUZZER_LOW_PRIO_SIZE]
Low priority alarm buzzer pattern definition, composed of multiple couple of states (Actif/Inactif) a...
Definition: buzzer.cpp:71
#define BUZZER_LOW_PRIO_SIZE
Low priority alarm buzzer pattern size.
Definition: buzzer.cpp:67

◆ Buzzer_Medium_Prio_Start()

void Buzzer_Medium_Prio_Start ( void  )

Activate the buzzer pattern for medium priority alarms.

Definition at line 188 of file buzzer.cpp.

188  {
190 }
const uint32_t Buzzer_Medium_Prio[BUZZER_MEDIUM_PRIO_SIZE]
Medium priority alarm buzzer pattern definition, composed of multiple couple of states (Actif/Inactif...
Definition: buzzer.cpp:63
#define BUZZER_MEDIUM_PRIO_SIZE
Medium priority alarm buzzer pattern size.
Definition: buzzer.cpp:59

◆ Buzzer_Mute()

void Buzzer_Mute ( void  )

Mute the buzzer for 120s.

Definition at line 156 of file buzzer.cpp.

156  {
157  // If we are in Repeat and not muted, then an alarm is ringing
158  if ((Active_Buzzer_Repeat == true) && (Buzzer_Muted == false)) {
159  // Set the buzzer as muted
160  Buzzer_Muted = true;
161  // Reset the timer
162  BuzzerTim->setCount(0);
163  // Reset the index, so that we will restart after the mute period
165 
166  // Configuration of mute pattern
168  BuzzerTim->setOverflow(PAUSE_120S, TICK_FORMAT);
169 
170  // Timer starts. Required to configure output on GPIO
171  BuzzerTim->resume();
172  }
173 }
bool Active_Buzzer_Repeat
Definition: buzzer.cpp:87
bool Buzzer_Muted
Definition: buzzer.cpp:89
uint32_t Active_Buzzer_Index
Definition: buzzer.cpp:85
#define PAUSE_120S
Definition: buzzer.cpp:38

◆ Buzzer_Resume()

void Buzzer_Resume ( void  )

Resume the muted alarm.

Definition at line 175 of file buzzer.cpp.

175  {
176  BuzzerTim->setCount(0);
177  Buzzer_Muted = false;
179 
180  BuzzerTim->setOverflow(Active_Buzzer[Active_Buzzer_Index + 1u], TICK_FORMAT);
181 
182  // Timer starts. Required to configure output on GPIO
183  BuzzerTim->resume();
184 }
const uint32_t * Active_Buzzer
Definition: buzzer.cpp:84

◆ Buzzer_Start()

void Buzzer_Start ( const uint32_t *  Buzzer,
uint32_t  Size,
bool  RepeatBuzzer 
)

Generic function to activate a buzzer.

Parameters
BuzzerBuzzer pattern array
SizeSize of the buzzer pattern array
RepeatBuzzerIs pattern repeating after its end

Definition at line 140 of file buzzer.cpp.

140  {
141  BuzzerTim->setCount(0);
142  Active_Buzzer = Buzzer;
144  Active_Buzzer_Size = Size;
145  Active_Buzzer_Repeat = RepeatBuzzer;
146  Active_Buzzer_Has_Begun = false;
147  Buzzer_Muted = false;
148 
149  BuzzerTim->setPreloadEnable(false);
150  BuzzerTim->setOverflow(100, TICK_FORMAT);
151 
152  // Timer starts
153  BuzzerTim->resume();
154 }
bool Active_Buzzer_Has_Begun
Definition: buzzer.cpp:88
uint32_t Active_Buzzer_Size
Definition: buzzer.cpp:86

◆ Buzzer_Stop()

void Buzzer_Stop ( void  )

Stop Buzzer.

Definition at line 196 of file buzzer.cpp.

196  {
197  Active_Buzzer_Repeat = false;
198 
199  // Avoid unexpected infinite buzzing
201  BuzzerTim->pause();
202 }

◆ Update_IT_callback()

void Update_IT_callback ( HardwareTimer *  )

When timer period expires, switch to next state in the pattern of the buzzer.

Note
API update since version 1.9.0 of Arduino_Core_STM32

Definition at line 102 of file buzzer.cpp.

106 {
107  if (Buzzer_Muted == true) {
108  // If the buzzer was muted, then we must resume the previous alarm
109  Buzzer_Resume();
110  } else if ((Active_Buzzer_Index == 0u) && (Active_Buzzer_Repeat == false)
111  && (Active_Buzzer_Has_Begun == true)) {
112  // If we are at start of pattern, check for repeating mode
113  BuzzerTim->pause();
115  } else {
116  // Previous state is finished, switch to next one
119  } else {
121  }
122  BuzzerTim->setOverflow(Active_Buzzer[Active_Buzzer_Index + 1u], TICK_FORMAT);
125  }
126 }
void Buzzer_Resume()
Resume the muted alarm.
Definition: buzzer.cpp:175
#define BZ_ON
Definition: buzzer.cpp:45
void BuzzerControl_On(void)
Switch buzzer ON.

Variable Documentation

◆ Active_Buzzer

const uint32_t* Active_Buzzer = nullptr

Definition at line 84 of file buzzer.cpp.

◆ Active_Buzzer_Has_Begun

bool Active_Buzzer_Has_Begun = false

Definition at line 88 of file buzzer.cpp.

◆ Active_Buzzer_Index

uint32_t Active_Buzzer_Index = 0

Definition at line 85 of file buzzer.cpp.

◆ Active_Buzzer_Repeat

bool Active_Buzzer_Repeat = false

Definition at line 87 of file buzzer.cpp.

◆ Active_Buzzer_Size

uint32_t Active_Buzzer_Size = 2

Definition at line 86 of file buzzer.cpp.

◆ Buzzer_Boot

const uint32_t Buzzer_Boot[BUZZER_BOOT_SIZE]
Initial value:
#define BEEEEP_PAUSE
Definition: buzzer.cpp:37
#define BZ_OFF
Definition: buzzer.cpp:44
#define BEEEEP
Definition: buzzer.cpp:36

Boot buzzer pattern definition, composed of multiple couple of states (Actif/Inactif) and duration (miliseconds)

Definition at line 79 of file buzzer.cpp.

◆ Buzzer_High_Prio

const uint32_t Buzzer_High_Prio[BUZZER_HIGH_PRIO_SIZE]
Initial value:

High priority alarm buzzer pattern definition, composed of multiple couple of states (Actif/Inactif) and duration (miliseconds)

Definition at line 52 of file buzzer.cpp.

◆ Buzzer_Low_Prio

const uint32_t Buzzer_Low_Prio[BUZZER_LOW_PRIO_SIZE]
Initial value:

Low priority alarm buzzer pattern definition, composed of multiple couple of states (Actif/Inactif) and duration (miliseconds)

Definition at line 71 of file buzzer.cpp.

◆ Buzzer_Medium_Prio

const uint32_t Buzzer_Medium_Prio[BUZZER_MEDIUM_PRIO_SIZE]
Initial value:

Medium priority alarm buzzer pattern definition, composed of multiple couple of states (Actif/Inactif) and duration (miliseconds)

Definition at line 63 of file buzzer.cpp.

◆ Buzzer_Muted

bool Buzzer_Muted = false

Definition at line 89 of file buzzer.cpp.

◆ BuzzerTim

HardwareTimer* BuzzerTim

Definition at line 91 of file buzzer.cpp.

◆ BuzzerTimerChannel

uint32_t BuzzerTimerChannel

Definition at line 92 of file buzzer.cpp.