Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches
buzzer.h
Go to the documentation of this file.
1
13#ifndef BUZZER_H_
14#define BUZZER_H_
15
16#include "stm32h7xx_hal.h" // Use the main HAL header for type definitions
17
26// --- Data Structures ---
27
31typedef struct {
32 uint16_t frequency;
33 uint16_t duration_ms;
34} note_t;
35
39typedef struct {
40 TIM_HandleTypeDef *htim;
41 uint32_t tim_channel;
42} buzzer_t;
43
44// --- Global Variables ---
45
46extern buzzer_t buzzer;
47
48// --- Note and Tempo Definitions ---
49
54#define REST 0
55#define NOTE_Gb5 740
56#define NOTE_D6 1175
57#define NOTE_Db6 1109
58#define NOTE_B5 988
59#define NOTE_A5 880
60
61#define TEMPO_BASE_MS 100
62#define DURATION_QUARTER (TEMPO_BASE_MS)
63#define DURATION_EIGHTH (TEMPO_BASE_MS / 2)
64#define DURATION_HALF (TEMPO_BASE_MS * 2)
67// --- Function Prototypes ---
68
78void buzzer_init(buzzer_t *bz, TIM_HandleTypeDef *htim, uint32_t channel);
79
89void musica_maestro(buzzer_t *bz, const note_t *partition, uint16_t melody_length);
90 // End of Buzzer Driver group
92
93#endif /* BUZZER_H_ */
buzzer_t buzzer
Global instance of the buzzer object.
Definition buzzer.c:17
void musica_maestro(buzzer_t *bz, const note_t *partition, uint16_t melody_length)
Plays a melody by iterating through an array of notes.
Definition buzzer.c:38
void buzzer_init(buzzer_t *bz, TIM_HandleTypeDef *htim, uint32_t channel)
Initializes the buzzer object and its associated timer hardware.
Definition buzzer.c:23
buzzer_t * bz
Definition main.c:121
Represents the buzzer device handle.
Definition buzzer.h:39
uint32_t tim_channel
The specific timer channel connected to the buzzer.
Definition buzzer.h:41
TIM_HandleTypeDef * htim
Pointer to the HAL timer handle controlling the buzzer.
Definition buzzer.h:40
Represents a single musical note with a frequency and duration.
Definition buzzer.h:31
uint16_t duration_ms
The duration to play the note in milliseconds (ms).
Definition buzzer.h:33
uint16_t frequency
The frequency of the note in Hertz (Hz). Use REST for silence.
Definition buzzer.h:32