Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
buzzer_tunes.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Tomaso De Ponti <tomaso@aerogriduav.com>
3 *
4 * This file is part of paparazzi
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
28#include "mcu_periph/sys_time.h"
29#include "generated/airframe.h"
30
32#ifndef BUZZER_TUNES_STARTUP_TUNE
33#define BUZZER_TUNES_STARTUP_TUNE BUZZER_TUNES_STARTUP
34#endif
35
37#define BUZZER_TUNES_GAP_MS 30
38
40#define REST 0
41#define C5 523
42#define Cs5 554
43#define D5 587
44#define Ds5 622
45#define E5 659
46#define F5 698
47#define Fs5 740
48#define G5 784
49#define Gs5 831
50#define A5 880
51#define As5 932
52#define B5 988
53#define C6 1047
54#define Cs6 1109
55#define D6 1175
56#define Ds6 1245
57#define E6 1319
58#define F6 1397
59#define Fs6 1480
60#define G6 1568
61#define Gs6 1661
62#define A6 1760
63#define As6 1865
64#define B6 1976
65#define C7 2093
66#define Cs7 2217
67#define D7 2349
68#define Ds7 2489
69#define E7 2637
70#define F7 2794
71#define Fs7 2960
72#define G7 3136
73#define Gs7 3322
74#define A7 3520
75#define As7 3729
76#define B7 3951
77
79#define BEATS(_b, _bpm) ((uint16_t)((_b) * 60000.0 / (_bpm)))
80
85
86#define TUNE_END {0, 0}
87
89#ifndef BUZZER_TUNES_RTTTL_1
90#define BUZZER_TUNES_RTTTL_1 ""
91#endif
92#ifndef BUZZER_TUNES_RTTTL_2
93#define BUZZER_TUNES_RTTTL_2 ""
94#endif
95#ifndef BUZZER_TUNES_RTTTL_3
96#define BUZZER_TUNES_RTTTL_3 ""
97#endif
98
100static const struct buzzer_note tune_startup[] = {
101 {C6, 120}, {E6, 120}, {G6, 120}, {C7, 360}, TUNE_END
102};
103
105static const struct buzzer_note tune_ode_to_joy[] = {
106 {E6, 300}, {E6, 300}, {F6, 300}, {G6, 300}, {G6, 300}, {F6, 300}, {E6, 300}, {D6, 300},
107 {C6, 300}, {C6, 300}, {D6, 300}, {E6, 300}, {E6, 450}, {D6, 150}, {D6, 600},
108 {E6, 300}, {E6, 300}, {F6, 300}, {G6, 300}, {G6, 300}, {F6, 300}, {E6, 300}, {D6, 300},
109 {C6, 300}, {C6, 300}, {D6, 300}, {E6, 300}, {D6, 450}, {C6, 150}, {C6, 600},
110 {D6, 300}, {D6, 300}, {E6, 300}, {C6, 300}, {D6, 300}, {E6, 150}, {F6, 150}, {E6, 300}, {C6, 300},
111 {D6, 300}, {E6, 150}, {F6, 150}, {E6, 300}, {D6, 300}, {C6, 300}, {D6, 300}, {G5, 600},
112 {E6, 300}, {E6, 300}, {F6, 300}, {G6, 300}, {G6, 300}, {F6, 300}, {E6, 300}, {D6, 300},
113 {C6, 300}, {C6, 300}, {D6, 300}, {E6, 300}, {D6, 450}, {C6, 150}, {C6, 600}, TUNE_END
114};
115
117static const struct buzzer_note tune_twinkle[] = {
118 {C6, 300}, {C6, 300}, {G6, 300}, {G6, 300}, {A6, 300}, {A6, 300}, {G6, 600},
119 {F6, 300}, {F6, 300}, {E6, 300}, {E6, 300}, {D6, 300}, {D6, 300}, {C6, 600},
120 {G6, 300}, {G6, 300}, {F6, 300}, {F6, 300}, {E6, 300}, {E6, 300}, {D6, 600},
121 {G6, 300}, {G6, 300}, {F6, 300}, {F6, 300}, {E6, 300}, {E6, 300}, {D6, 600},
122 {C6, 300}, {C6, 300}, {G6, 300}, {G6, 300}, {A6, 300}, {A6, 300}, {G6, 600},
123 {F6, 300}, {F6, 300}, {E6, 300}, {E6, 300}, {D6, 300}, {D6, 300}, {C6, 600}, TUNE_END
124};
125
127#define IT_BPM 112
128static const struct buzzer_note tune_anthem_italy[] = {
129 {F5, BEATS(1, IT_BPM)}, {F5, BEATS(0.75, IT_BPM)}, {G5, BEATS(0.25, IT_BPM)}, {F5, BEATS(1, IT_BPM)},
130 {REST, BEATS(1, IT_BPM)}, {D6, BEATS(1, IT_BPM)}, {D6, BEATS(0.75, IT_BPM)}, {Ds6, BEATS(0.25, IT_BPM)},
131 {D6, BEATS(1, IT_BPM)}, {REST, BEATS(1, IT_BPM)}, {D6, BEATS(1, IT_BPM)}, {F6, BEATS(0.75, IT_BPM)},
132 {Ds6, BEATS(0.25, IT_BPM)}, {D6, BEATS(2, IT_BPM)}, {C6, BEATS(1, IT_BPM)}, {D6, BEATS(0.75, IT_BPM)},
133 {C6, BEATS(0.25, IT_BPM)}, {As5, BEATS(1, IT_BPM)}, {REST, BEATS(1, IT_BPM)}, {D6, BEATS(1, IT_BPM)},
134 {D6, BEATS(1, IT_BPM)}, {A5, BEATS(2, IT_BPM)}, {As5, BEATS(0.75, IT_BPM)}, {C6, BEATS(0.25, IT_BPM)},
135 {As5, BEATS(0.75, IT_BPM)}, {A5, BEATS(0.25, IT_BPM)}, {G5, BEATS(1, IT_BPM)}, {REST, BEATS(1, IT_BPM)},
136 {As5, BEATS(1, IT_BPM)}, {A5, BEATS(0.75, IT_BPM)}, {As5, BEATS(0.25, IT_BPM)}, {C6, BEATS(1, IT_BPM)},
137 {REST, BEATS(1, IT_BPM)}, {D5, BEATS(1, IT_BPM)}, {D6, BEATS(2, IT_BPM)}, {Ds6, BEATS(1, IT_BPM)},
138 {F5, BEATS(1, IT_BPM)}, {F5, BEATS(0.75, IT_BPM)}, {G5, BEATS(0.25, IT_BPM)}, {F5, BEATS(0.5, IT_BPM)},
139 {REST, BEATS(1.5, IT_BPM)}, {D6, BEATS(1, IT_BPM)}, {D6, BEATS(0.75, IT_BPM)}, {Ds6, BEATS(0.25, IT_BPM)},
140 {D6, BEATS(2, IT_BPM)}, {D6, BEATS(1, IT_BPM)}, {F6, BEATS(0.75, IT_BPM)}, {Ds6, BEATS(0.25, IT_BPM)},
141 {D6, BEATS(1.5, IT_BPM)}, {F6, BEATS(0.5, IT_BPM)}, {C6, BEATS(0.5, IT_BPM)}, {F6, BEATS(0.5, IT_BPM)},
142 {As5, BEATS(2, IT_BPM)}, TUNE_END
143};
144
146#define NL_BPM 90
147static const struct buzzer_note tune_anthem_netherlands[] = {
148 {D5, BEATS(1, NL_BPM)}, {G5, BEATS(1, NL_BPM)}, {G5, BEATS(1, NL_BPM)}, {A5, BEATS(0.5, NL_BPM)},
149 {B5, BEATS(0.5, NL_BPM)}, {C6, BEATS(0.5, NL_BPM)}, {A5, BEATS(0.5, NL_BPM)}, {B5, BEATS(1, NL_BPM)},
150 {A5, BEATS(0.5, NL_BPM)}, {B5, BEATS(0.5, NL_BPM)}, {C6, BEATS(1, NL_BPM)}, {B5, BEATS(1, NL_BPM)},
151 {A5, BEATS(0.5, NL_BPM)}, {G5, BEATS(0.5, NL_BPM)}, {A5, BEATS(1, NL_BPM)}, {G5, BEATS(3, NL_BPM)},
152 {B5, BEATS(0.5, NL_BPM)}, {C6, BEATS(0.5, NL_BPM)}, {D6, BEATS(2, NL_BPM)}, {E6, BEATS(1, NL_BPM)},
153 {D6, BEATS(2, NL_BPM)}, {C6, BEATS(1, NL_BPM)}, {B5, BEATS(1, NL_BPM)}, {A5, BEATS(0.5, NL_BPM)},
154 {B5, BEATS(0.5, NL_BPM)}, {C6, BEATS(1, NL_BPM)}, {B5, BEATS(1, NL_BPM)}, {A5, BEATS(1, NL_BPM)},
155 {G5, BEATS(1, NL_BPM)}, {A5, BEATS(3, NL_BPM)}, {D5, BEATS(1, NL_BPM)}, {G5, BEATS(0.5, NL_BPM)},
156 {Fs5, BEATS(0.5, NL_BPM)}, {G5, BEATS(0.5, NL_BPM)}, {A5, BEATS(0.5, NL_BPM)}, {B5, BEATS(1, NL_BPM)},
157 {A5, BEATS(2, NL_BPM)}, {G5, BEATS(1, NL_BPM)}, {Fs5, BEATS(1, NL_BPM)}, {D5, BEATS(1, NL_BPM)},
158 {E5, BEATS(0.5, NL_BPM)}, {Fs5, BEATS(0.5, NL_BPM)}, {G5, BEATS(1, NL_BPM)}, {G5, BEATS(1, NL_BPM)},
159 {Fs5, BEATS(1, NL_BPM)}, {G5, BEATS(3, NL_BPM)}, TUNE_END
160};
161
163#define FR_BPM 105
164static const struct buzzer_note tune_anthem_france[] = {
165 {D5, BEATS(0.25, FR_BPM)}, {D5, BEATS(0.75, FR_BPM)}, {D5, BEATS(0.25, FR_BPM)}, {G5, BEATS(1, FR_BPM)},
166 {G5, BEATS(1, FR_BPM)}, {A5, BEATS(1, FR_BPM)}, {A5, BEATS(1, FR_BPM)}, {D6, BEATS(1.5, FR_BPM)},
167 {B5, BEATS(0.5, FR_BPM)}, {G5, BEATS(0.75, FR_BPM)}, {G5, BEATS(0.25, FR_BPM)}, {B5, BEATS(0.75, FR_BPM)},
168 {G5, BEATS(0.25, FR_BPM)}, {E5, BEATS(1, FR_BPM)}, {C6, BEATS(1, FR_BPM)}, {REST, BEATS(1, FR_BPM)},
169 {A5, BEATS(0.75, FR_BPM)}, {Fs5, BEATS(0.25, FR_BPM)}, {G5, BEATS(1, FR_BPM)}, {REST, BEATS(2, FR_BPM)},
170 {G5, BEATS(0.75, FR_BPM)}, {A5, BEATS(0.25, FR_BPM)}, {B5, BEATS(1, FR_BPM)}, {B5, BEATS(1, FR_BPM)},
171 {B5, BEATS(1, FR_BPM)}, {C6, BEATS(0.75, FR_BPM)}, {B5, BEATS(0.25, FR_BPM)}, {B5, BEATS(1, FR_BPM)},
172 {A5, BEATS(1, FR_BPM)}, {REST, BEATS(1, FR_BPM)}, {A5, BEATS(0.75, FR_BPM)}, {B5, BEATS(0.25, FR_BPM)},
173 {C6, BEATS(1, FR_BPM)}, {C6, BEATS(1, FR_BPM)}, {C6, BEATS(1, FR_BPM)}, {D6, BEATS(0.75, FR_BPM)},
174 {C6, BEATS(0.25, FR_BPM)}, {B5, BEATS(1, FR_BPM)}, {REST, BEATS(2, FR_BPM)}, {D6, BEATS(0.75, FR_BPM)},
175 {D6, BEATS(0.25, FR_BPM)}, {D6, BEATS(1, FR_BPM)}, {B5, BEATS(0.75, FR_BPM)}, {G5, BEATS(0.25, FR_BPM)},
176 {D6, BEATS(1, FR_BPM)}, {B5, BEATS(0.75, FR_BPM)}, {G5, BEATS(0.25, FR_BPM)}, {D5, BEATS(3, FR_BPM)}, TUNE_END
177};
178
180static const struct buzzer_note tune_happy_birthday[] = {
181 {G5, 300}, {G5, 100}, {A5, 400}, {G5, 400}, {C6, 400}, {B5, 800},
182 {G5, 300}, {G5, 100}, {A5, 400}, {G5, 400}, {D6, 400}, {C6, 800},
183 {G5, 300}, {G5, 100}, {G6, 400}, {E6, 400}, {C6, 400}, {B5, 400}, {A5, 800},
184 {F6, 300}, {F6, 100}, {E6, 400}, {C6, 400}, {D6, 400}, {C6, 800}, TUNE_END
185};
186
187
189static const struct buzzer_note tune_mushroom[] = {
190 {E7, 150}, {E7, 150}, {REST, 150}, {E7, 150}, {REST, 150}, {C7, 150}, {E7, 150}, {REST, 150},
191 {G7, 300}, {REST, 300}, {G6, 300}, {REST, 300}, {C7, 450}, {G6, 150}, {REST, 300}, {E6, 450},
192 {A6, 300}, {B6, 300}, {As6, 150}, {A6, 300}, {G6, 200}, {E7, 200}, {G7, 200}, {A7, 300},
193 {F7, 150}, {G7, 150}, {REST, 150}, {E7, 300}, {C7, 150}, {D7, 150}, {B6, 450}, {C7, 450},
194 {G6, 150}, {REST, 300}, {E6, 450}, {A6, 300}, {B6, 300}, {As6, 150}, {A6, 300}, {G6, 200},
195 {E7, 200}, {G7, 200}, {A7, 300}, {F7, 150}, {G7, 150}, {REST, 150}, {E7, 300}, {C7, 150},
196 {D7, 150}, {B6, 450}, {REST, 300}, {G7, 150}, {Fs7, 150}, {F7, 150}, {D7, 300}, {E7, 150},
197 {REST, 150}, {G6, 150}, {A6, 150}, {C7, 150}, {REST, 150}, {A6, 150}, {C7, 150}, {D7, 150},
198 {REST, 300}, {G7, 150}, {Fs7, 150}, {F7, 150}, {D7, 300}, {E7, 150}, {REST, 150}, {C5, 300},
199 {C5, 150}, {C5, 300}, {REST, 300}, {REST, 300}, {G7, 150}, {Fs7, 150}, {F7, 150}, {D7, 300},
200 {E7, 150}, {REST, 150}, {G6, 150}, {A6, 150}, {C7, 150}, {REST, 150}, {A6, 150}, {C7, 150},
201 {D7, 150}, {REST, 300}, {Ds7, 300}, {REST, 150}, {D7, 450}, {C7, 600}, {REST, 600}, {C7, 150},
202 {C7, 300}, {C7, 150}, {REST, 150}, {C7, 150}, {D7, 300}, {E7, 150}, {C7, 300}, {A6, 150},
203 {G6, 600}, {C7, 150}, {C7, 300}, {C7, 150}, {REST, 150}, {C7, 150}, {D7, 150}, {E7, 150},
204 {REST, 1200}, {C7, 150}, {C7, 300}, {C7, 150}, {REST, 150}, {C7, 150}, {D7, 300}, {E7, 150},
205 {C7, 300}, {A6, 150}, {G6, 600}, {E7, 150}, {E7, 150}, {REST, 150}, {E7, 150}, {REST, 150},
206 {C7, 150}, {E7, 300}, {G7, 300}, {REST, 300}, {G6, 300}, {REST, 300}, {C7, 450}, {G6, 150},
207 {REST, 300}, {E6, 450}, {A6, 300}, {B6, 300}, {As6, 150}, {A6, 300}, {G6, 200}, {E7, 200},
208 {G7, 200}, {A7, 300}, {F7, 150}, {G7, 150}, {REST, 150}, {E7, 300}, {C7, 150}, {D7, 150},
209 {B6, 450}, {C7, 450}, {G6, 150}, {REST, 300}, {E6, 450}, {A6, 300}, {B6, 300}, {As6, 150},
210 {A6, 300}, {G6, 200}, {E7, 200}, {G7, 200}, {A7, 300}, {F7, 150}, {G7, 150}, {REST, 150},
211 {E7, 300}, {C7, 150}, {D7, 150}, {B6, 450}, {E7, 150}, {C7, 300}, {G6, 150}, {REST, 300},
212 {G6, 300}, {A6, 150}, {F7, 300}, {F7, 150}, {A6, 600}, {B6, 200}, {A7, 200}, {A7, 200},
213 {A7, 200}, {G7, 200}, {F7, 200}, {E7, 150}, {C7, 300}, {A6, 150}, {G6, 600}, {E7, 150},
214 {C7, 300}, {G6, 150}, {REST, 300}, {G6, 300}, {A6, 150}, {F7, 300}, {F7, 150}, {A6, 600},
215 {B6, 150}, {F7, 300}, {F7, 150}, {F7, 200}, {E7, 200}, {D7, 200}, {C7, 150}, {G6, 300},
216 {E6, 150}, {C6, 600}, {C7, 450}, {G6, 450}, {E6, 300}, {A6, 200}, {B6, 200}, {A6, 200},
217 {Gs6, 200}, {As6, 200}, {Gs6, 200}, {G6, 150}, {Fs6, 150}, {G6, 900},
219};
220
221
223static const struct buzzer_note tune_gran_vals[] = {
224 {E6, 160}, {D6, 160}, {Fs5, 320}, {Gs5, 320}, {Cs6, 160}, {B5, 160}, {D5, 320}, {E5, 320},
225 {B5, 160}, {A5, 160}, {Cs5, 320}, {E5, 320}, {A5, 960}, TUNE_END
226};
227
229static const struct buzzer_note tune_fur_elise[] = {
230 {E6, 150}, {Ds6, 150}, {E6, 150}, {Ds6, 150}, {E6, 150}, {B5, 150}, {D6, 150}, {C6, 150},
231 {A5, 300}, {REST, 150}, {C5, 150}, {E5, 150}, {A5, 150}, {B5, 300}, {REST, 150},
232 {E5, 150}, {Gs5, 150}, {B5, 150}, {C6, 300}, {REST, 150}, {E5, 150}, {E6, 150}, {Ds6, 150},
233 {E6, 150}, {Ds6, 150}, {E6, 150}, {B5, 150}, {D6, 150}, {C6, 150},
234 {A5, 300}, {REST, 150}, {C5, 150}, {E5, 150}, {A5, 150}, {B5, 300}, {REST, 150},
235 {E5, 150}, {C6, 150}, {B5, 150}, {A5, 600}, TUNE_END
236};
237
239static const struct buzzer_note tune_la_cucaracha[] = {
240 {C6, 150}, {C6, 150}, {C6, 150}, {F6, 450}, {A6, 300},
241 {C6, 150}, {C6, 150}, {C6, 150}, {F6, 450}, {A6, 600},
242 {F6, 300}, {F6, 150}, {E6, 150}, {E6, 150}, {D6, 150}, {D6, 150}, {C6, 600},
243 {C6, 150}, {C6, 150}, {C6, 150}, {E6, 450}, {G6, 300},
244 {C6, 150}, {C6, 150}, {C6, 150}, {E6, 450}, {G6, 600},
245 {C7, 300}, {D7, 150}, {C7, 150}, {As6, 150}, {A6, 150}, {G6, 150}, {F6, 600}, TUNE_END
246};
247
249static const struct buzzer_note tune_william_tell[] = {
250 {G6, 100}, {G6, 100}, {G6, 200}, {G6, 100}, {G6, 100}, {G6, 200},
251 {G6, 100}, {G6, 100}, {C7, 200}, {D7, 200}, {E7, 400}, {REST, 200},
252 {G6, 100}, {G6, 100}, {G6, 200}, {G6, 100}, {G6, 100}, {G6, 200},
253 {G6, 100}, {G6, 100}, {C7, 200}, {D7, 200}, {E7, 400}, {C7, 600}, TUNE_END
254};
255
271
276
278
279static const struct buzzer_note *tune_notes = NULL;
280static const char *rtttl = NULL;
281static uint8_t rtttl_d = 4, rtttl_o = 6;
282static uint16_t rtttl_bpm = 63;
283static struct buzzer_note note;
284static bool playing = false;
286static bool note_gap = false;
287
288static uint16_t rtttl_number(const char **p)
289{
290 uint16_t n = 0;
291 while (**p >= '0' && **p <= '9') {
292 n = n * 10 + (*(*p)++ - '0');
293 }
294 return n;
295}
296
298static bool rtttl_start(const char *str)
299{
300 const char *p = str;
301 while (*p && *p != ':') { p++; } // skip name
302 if (*p != ':') { return false; }
303 p++;
304 rtttl_d = 4; rtttl_o = 6; rtttl_bpm = 63;
305 while (*p && *p != ':') {
306 char key = *p;
307 if (key == 'd' || key == 'o' || key == 'b') {
308 p += 2; // skip "x="
309 uint16_t v = rtttl_number(&p);
310 if (key == 'd' && v > 0) { rtttl_d = v; }
311 if (key == 'o' && v > 0) { rtttl_o = v; }
312 if (key == 'b' && v > 0) { rtttl_bpm = v; }
313 } else {
314 p++;
315 }
316 }
317 if (*p != ':') { return false; }
318 rtttl = p + 1;
319 return true;
320}
321
323static bool rtttl_next(struct buzzer_note *n)
324{
325 // semitone frequencies of octave 4 [Hz], C to B
326 static const uint16_t octave4[12] = {262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494};
327 static const int8_t semitone['h' - 'a' + 1] = {9, 11, 0, 2, 4, 5, 7, 11}; // a b c d e f g h(=b)
328 const char *p = rtttl;
329 while (*p == ' ' || *p == ',') { p++; }
330 if (*p == '\0') { return false; }
331 uint16_t d = rtttl_number(&p);
332 if (d == 0) { d = rtttl_d; }
333 char c = *p | 0x20; // lower case
334 if (c != 'p' && (c < 'a' || c > 'h')) { return false; }
335 p++;
336 int8_t semi = (c == 'p') ? -1 : semitone[c - 'a'];
337 if (*p == '#') { semi++; p++; }
338 bool dotted = false;
339 if (*p == '.') { dotted = true; p++; }
340 uint8_t o = rtttl_o;
341 if (*p >= '0' && *p <= '9') { o = *p++ - '0'; }
342 if (*p == '.') { dotted = true; p++; }
343 while (*p && *p != ',') { p++; } // ignore anything else
344 rtttl = p;
345
346 uint32_t ms = (240000UL / rtttl_bpm) / d; // whole note = 4 beats
347 if (dotted) { ms = ms * 3 / 2; }
348 n->ms = Min(ms, 65535);
349 if (semi < 0) {
350 n->freq = REST;
351 } else {
352 uint8_t oct = o + semi / 12; // B# goes to the next octave
353 uint32_t f = octave4[semi % 12];
354 n->freq = (oct >= 4) ? (f << (oct - 4)) : (f >> (4 - oct));
355 }
356 return true;
357}
358
360static bool next_note(struct buzzer_note *n)
361{
362 if (tune_notes != NULL) {
363 if (tune_notes->ms == 0) { return false; }
364 *n = *tune_notes++;
365 return true;
366 }
367 if (rtttl != NULL) {
368 return rtttl_next(n);
369 }
370 return false;
371}
372
373static void start_next_note(void)
374{
375 if (!next_note(&note)) {
376 buzzer_tunes_play(BUZZER_TUNES_NONE); // end of tune
377 return;
378 }
380 note_gap = false;
382}
383
385{
386 playing = false;
388 rtttl = NULL;
392 return;
393 }
396 return; // empty or invalid custom tune
397 }
398 } else {
400 }
402 playing = true;
404}
405
411
413{
414 if (!playing) {
415 return;
416 }
418 if (!note_gap && elapsed + BUZZER_TUNES_GAP_MS >= note.ms) {
420 note_gap = true;
421 }
422 if (elapsed >= note.ms) {
424 }
425}
void buzzer_arch_init(void)
Definition buzzer_arch.c:49
void buzzer_arch_tone(uint16_t freq)
Play a square wave at freq Hz, 0 for silence.
Definition buzzer_arch.c:57
Piezo buzzer tone output with a ChibiOS PWM driver.
#define BUZZER_TUNES_RTTTL_1
Custom tunes (Custom 1..3) in RTTTL format ("name:d=4,o=6,b=120:c,e,g"), set in the airframe,...
static bool playing
static const struct buzzer_note tune_startup[]
Short rising arpeggio.
static struct buzzer_note note
note being played
#define G5
#define Fs6
#define BUZZER_TUNES_GAP_MS
Silence at the end of each note, so repeated notes are heard separately [ms].
static const struct buzzer_note tune_twinkle[]
Twinkle Twinkle Little Star, full song (public domain)
static const struct buzzer_note tune_william_tell[]
Rossini, William Tell Overture, galop opening, played twice (public domain)
#define D7
void buzzer_tunes_init(void)
#define D5
#define F5
#define TUNE_END
#define Cs5
#define C5
#define C6
static uint8_t rtttl_d
#define A7
#define Fs7
static const struct buzzer_note tune_anthem_netherlands[]
#define Fs5
#define Cs6
static bool note_gap
in the silent gap at the end of the note
#define FR_BPM
France, La Marseillaise, opening to "l'étendard sanglant est levé" (Rouget de Lisle 1792,...
#define BUZZER_TUNES_RTTTL_3
static const struct buzzer_note tune_la_cucaracha[]
La Cucaracha, chorus (traditional, public domain)
static const char * rtttl
next note of a RTTTL tune
#define A5
#define NL_BPM
Netherlands, Wilhelmus, first verse (16th century, public domain)
#define E7
static const char *const buzzer_tunes_custom[]
Custom tunes, RTTTL strings.
void buzzer_tunes_periodic(void)
#define D6
#define F7
#define B6
static const struct buzzer_note tune_ode_to_joy[]
Beethoven, Ode to Joy, full theme (public domain)
static uint8_t rtttl_o
RTTTL default duration and octave.
static uint32_t note_start_ms
start time of the note
static const struct buzzer_note tune_gran_vals[]
Tarrega, Gran Vals, the phrase known as the Nokia ringtone (public domain)
#define Gs5
#define A6
static bool next_note(struct buzzer_note *n)
Get the next note of the tune, false at the end.
uint8_t buzzer_tunes_tune
tune being played, BUZZER_TUNES_NONE when silent
#define BUZZER_TUNES_STARTUP_TUNE
Tune played at startup, BUZZER_TUNES_NONE for silence.
#define E6
#define BUZZER_TUNES_RTTTL_2
static bool rtttl_next(struct buzzer_note *n)
Parse the next RTTTL note "[duration]note[#][.][octave][.]", false at the end.
#define Gs6
#define Ds7
#define E5
#define IT_BPM
Italy, Il Canto degli Italiani, first verse (Novaro 1847, public domain)
static const struct buzzer_note tune_mushroom[]
Mushroom Song.
#define B5
static const struct buzzer_note *const buzzer_tunes_list[BUZZER_TUNES_CUSTOM_1]
static bool rtttl_start(const char *str)
Parse the RTTTL header "name:d=4,o=6,b=120:", false if invalid.
#define BEATS(_b, _bpm)
Duration of a number of beats at a tempo [ms].
void buzzer_tunes_play(uint8_t tune)
Start a tune (BUZZER_TUNES_NONE stops), also the settings handler.
static uint16_t rtttl_bpm
RTTTL tempo.
#define Ds6
#define G7
#define G6
static const struct buzzer_note tune_anthem_france[]
static uint16_t rtttl_number(const char **p)
#define As5
#define As6
static const struct buzzer_note tune_fur_elise[]
Beethoven, Fur Elise, first section (public domain)
static const struct buzzer_note tune_anthem_italy[]
static void start_next_note(void)
#define F6
uint16_t ms
duration [ms]
static const struct buzzer_note * tune_notes
next note of a built-in tune
static const struct buzzer_note tune_happy_birthday[]
Happy Birthday (public domain)
uint16_t freq
[Hz], REST for silence
#define C7
#define REST
Note frequencies [Hz], s for sharp, octaves 5 to 7 sound loudest on a piezo.
Play tunes on a passive piezo buzzer (e.g.
@ BUZZER_TUNES_TWINKLE
@ BUZZER_TUNES_CUSTOM_1
custom RTTTL tunes, see BUZZER_TUNES_RTTTL_x
@ BUZZER_TUNES_STARTUP
@ BUZZER_TUNES_MUSHROOM
@ BUZZER_TUNES_FUR_ELISE
@ BUZZER_TUNES_ODE_TO_JOY
@ BUZZER_TUNES_WILLIAM_TELL
@ BUZZER_TUNES_ANTHEM_NETHERLANDS
@ BUZZER_TUNES_HAPPY_BIRTHDAY
@ BUZZER_TUNES_ANTHEM_ITALY
@ BUZZER_TUNES_NONE
@ BUZZER_TUNES_NB
@ BUZZER_TUNES_ANTHEM_FRANCE
@ BUZZER_TUNES_GRAN_VALS
@ BUZZER_TUNES_LA_CUCARACHA
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
#define Min(x, y)
Definition esc_dshot.c:110
static float p[2][2]
uint16_t foo
Definition main_demo5.c:58
Architecture independent timing functions.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.
uint16_t f
Camera baseline, in meters (i.e. horizontal distance between the two cameras of the stereo setup)
Definition wedgebug.c:204