forked from LonelyWolf/stm32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeeper.h
128 lines (111 loc) · 2.39 KB
/
beeper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Define to prevent recursive inclusion -------------------------------------
#ifndef __BEEPER_H
#define __BEEPER_H
// Single tone definition
typedef struct {
uint16_t frequency;
uint8_t duration;
} Tone_TypeDef;
static const Tone_TypeDef tones_startup[] = {
{2000,3},
{ 0,3},
{3000,3},
{ 0,3},
{4000,3},
{ 0,3},
{1200,4},
{ 0,6},
{4500,6},
{ 0,0} // <-- tones end
};
static const Tone_TypeDef tones_3beep[] = {
{4000, 3},
{ 0,10},
{1000, 6},
{ 0,10},
{4000, 3},
{ 0, 0}
};
// "Super Mario bros." =)
static const Tone_TypeDef tones_SMB[] = {
{2637,18}, // E7 x2
{ 0, 9}, // x3
{2637, 9}, // E7
{ 0, 9}, // x3
{2093, 9}, // C7
{2637, 9}, // E7
{ 0, 9}, // x3
{3136, 9}, // G7
{ 0,27}, // x3
{1586, 9}, // G6
{ 0,27}, // x3
{2093, 9}, // C7
{ 0,18}, // x2
{1586, 9}, // G6
{ 0,18}, // x2
{1319, 9}, // E6
{ 0,18}, // x2
{1760, 9}, // A6
{ 0, 9}, // x1
{1976, 9}, // B6
{ 0, 9}, // x1
{1865, 9}, // AS6
{1760, 9}, // A6
{ 0, 9}, // x1
{1586,12}, // G6
{2637,12}, // E7
{3136,12}, // G7
{3520, 9}, // A7
{ 0, 9}, // x1
{2794, 9}, // F7
{3136, 9}, // G7
{ 0, 9}, // x1
{2637, 9}, // E7
{ 0, 9}, // x1
{2093, 9}, // C7
{2349, 9}, // D7
{1976, 9}, // B6
{ 0,18}, // x2
{2093, 9}, // C7
{ 0,18}, // x2
{1586, 9}, // G6
{ 0,18}, // x2
{1319, 9}, // E6
{ 0,18}, // x2
{1760, 9}, // A6
{ 0, 9}, // x1
{1976, 9}, // B6
{ 0, 9}, // x1
{1865, 9}, // AS6
{1760, 9}, // A6
{ 0, 9}, // x1
{1586,12}, // G6
{2637,12}, // E7
{3136,12}, // G7
{3520, 9}, // A7
{ 0, 9}, // x1
{2794, 9}, // F7
{3136, 9}, // G7
{ 0, 9}, // x1
{2637, 9}, // E7
{ 0, 9}, // x1
{2093, 9}, // C7
{2349, 9}, // D7
{1976, 9}, // B6
{ 0, 0}
};
// Buzzer on PB5 -> TIM3_CH2
#define BEEPER_PIN GPIO_Pin_7
#define BEEPER_GPIO GPIOA
#define BEEPER_PERIPH RCC_AHBPeriph_GPIOA
#define BEEPER_GPIO_AF GPIO_AF_TIM3
#define BEEPER_GPIO_PIN_SRC GPIO_PinSource7
#define BEEPER_TIM TIM3
#define BEEPER_TIM_PERIPH RCC_APB1Periph_TIM3
#define BEEPER_TIM_IRQN TIM3_IRQn
// Function prototypes
void BEEPER_Init(void);
void BEEPER_Enable(uint16_t freq, uint32_t duration);
void BEEPER_Disable(void);
void BEEPER_PlayTones(const Tone_TypeDef * melody);
#endif // __BEEPER_H