aboutsummaryrefslogtreecommitdiff
path: root/quantum/audio
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/audio')
-rw-r--r--quantum/audio/audio.h1
-rw-r--r--quantum/audio/audio_avr.c2
-rw-r--r--quantum/audio/audio_chibios.c33
-rw-r--r--quantum/audio/audio_pwm.c11
-rw-r--r--quantum/audio/musical_notes.h9
5 files changed, 46 insertions, 10 deletions
diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h
index bc00cd19e..dccf03d5f 100644
--- a/quantum/audio/audio.h
+++ b/quantum/audio/audio.h
@@ -83,6 +83,7 @@ void increase_tempo(uint8_t tempo_change);
83void decrease_tempo(uint8_t tempo_change); 83void decrease_tempo(uint8_t tempo_change);
84 84
85void audio_init(void); 85void audio_init(void);
86void audio_startup(void);
86 87
87#ifdef PWM_AUDIO 88#ifdef PWM_AUDIO
88void play_sample(uint8_t* s, uint16_t l, bool r); 89void play_sample(uint8_t* s, uint16_t l, bool r);
diff --git a/quantum/audio/audio_avr.c b/quantum/audio/audio_avr.c
index 5a96bf643..1bac43bb4 100644
--- a/quantum/audio/audio_avr.c
+++ b/quantum/audio/audio_avr.c
@@ -227,7 +227,9 @@ void audio_init() {
227 227
228 audio_initialized = true; 228 audio_initialized = true;
229 } 229 }
230}
230 231
232void audio_startup() {
231 if (audio_config.enable) { 233 if (audio_config.enable) {
232 PLAY_SONG(startup_song); 234 PLAY_SONG(startup_song);
233 } 235 }
diff --git a/quantum/audio/audio_chibios.c b/quantum/audio/audio_chibios.c
index 1f147f2c9..dddb8f135 100644
--- a/quantum/audio/audio_chibios.c
+++ b/quantum/audio/audio_chibios.c
@@ -86,13 +86,21 @@ static void gpt_cb8(GPTDriver *gptp);
86 86
87#define START_CHANNEL_1() \ 87#define START_CHANNEL_1() \
88 gptStart(&GPTD6, &gpt6cfg1); \ 88 gptStart(&GPTD6, &gpt6cfg1); \
89 gptStartContinuous(&GPTD6, 2U) 89 gptStartContinuous(&GPTD6, 2U); \
90 palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG)
90#define START_CHANNEL_2() \ 91#define START_CHANNEL_2() \
91 gptStart(&GPTD7, &gpt7cfg1); \ 92 gptStart(&GPTD7, &gpt7cfg1); \
92 gptStartContinuous(&GPTD7, 2U) 93 gptStartContinuous(&GPTD7, 2U); \
93#define STOP_CHANNEL_1() gptStopTimer(&GPTD6) 94 palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG)
94#define STOP_CHANNEL_2() gptStopTimer(&GPTD7) 95#define STOP_CHANNEL_1() \
95#define RESTART_CHANNEL_1() \ 96 gptStopTimer(&GPTD6); \
97 palSetPadMode(GPIOA, 4, PAL_MODE_OUTPUT_PUSHPULL); \
98 palSetPad(GPIOA, 4)
99#define STOP_CHANNEL_2() \
100 gptStopTimer(&GPTD7); \
101 palSetPadMode(GPIOA, 5, PAL_MODE_OUTPUT_PUSHPULL); \
102 palSetPad(GPIOA, 5)
103 #define RESTART_CHANNEL_1() \
96 STOP_CHANNEL_1(); \ 104 STOP_CHANNEL_1(); \
97 START_CHANNEL_1() 105 START_CHANNEL_1()
98#define RESTART_CHANNEL_2() \ 106#define RESTART_CHANNEL_2() \
@@ -274,6 +282,12 @@ void audio_init() {
274 dacStart(&DACD2, &dac1cfg2); 282 dacStart(&DACD2, &dac1cfg2);
275 283
276 /* 284 /*
285 * Start the note timer
286 */
287 gptStart(&GPTD8, &gpt8cfg1);
288 gptStartContinuous(&GPTD8, 2U);
289
290 /*
277 * Starting GPT6/7 driver, it is used for triggering the DAC. 291 * Starting GPT6/7 driver, it is used for triggering the DAC.
278 */ 292 */
279 START_CHANNEL_1(); 293 START_CHANNEL_1();
@@ -287,10 +301,12 @@ void audio_init() {
287 301
288 audio_initialized = true; 302 audio_initialized = true;
289 303
304 stop_all_notes();
305}
306
307void audio_startup() {
290 if (audio_config.enable) { 308 if (audio_config.enable) {
291 PLAY_SONG(startup_song); 309 PLAY_SONG(startup_song);
292 } else {
293 stop_all_notes();
294 } 310 }
295} 311}
296 312
@@ -630,6 +646,9 @@ bool is_playing_notes(void) { return playing_notes; }
630bool is_audio_on(void) { return (audio_config.enable != 0); } 646bool is_audio_on(void) { return (audio_config.enable != 0); }
631 647
632void audio_toggle(void) { 648void audio_toggle(void) {
649 if (audio_config.enable) {
650 stop_all_notes();
651 }
633 audio_config.enable ^= 1; 652 audio_config.enable ^= 1;
634 eeconfig_update_audio(audio_config.raw); 653 eeconfig_update_audio(audio_config.raw);
635 if (audio_config.enable) { 654 if (audio_config.enable) {
diff --git a/quantum/audio/audio_pwm.c b/quantum/audio/audio_pwm.c
index 545aef6dd..d93ac4bb4 100644
--- a/quantum/audio/audio_pwm.c
+++ b/quantum/audio/audio_pwm.c
@@ -29,6 +29,11 @@
29 29
30#define CPU_PRESCALER 8 30#define CPU_PRESCALER 8
31 31
32#ifndef STARTUP_SONG
33# define STARTUP_SONG SONG(STARTUP_SOUND)
34#endif
35float startup_song[][2] = STARTUP_SONG;
36
32// Timer Abstractions 37// Timer Abstractions
33 38
34// TIMSK3 - Timer/Counter #3 Interrupt Mask Register 39// TIMSK3 - Timer/Counter #3 Interrupt Mask Register
@@ -155,6 +160,12 @@ void audio_init() {
155 audio_initialized = true; 160 audio_initialized = true;
156} 161}
157 162
163void audio_startup() {
164 if (audio_config.enable) {
165 PLAY_SONG(startup_song);
166 }
167}
168
158void stop_all_notes() { 169void stop_all_notes() {
159 if (!audio_initialized) { 170 if (!audio_initialized) {
160 audio_init(); 171 audio_init();
diff --git a/quantum/audio/musical_notes.h b/quantum/audio/musical_notes.h
index 8ac6aafd3..0ba572c34 100644
--- a/quantum/audio/musical_notes.h
+++ b/quantum/audio/musical_notes.h
@@ -17,7 +17,9 @@
17#pragma once 17#pragma once
18 18
19// Tempo Placeholder 19// Tempo Placeholder
20#define TEMPO_DEFAULT 100 20#ifndef TEMPO_DEFAULT
21# define TEMPO_DEFAULT 100
22#endif
21 23
22#define SONG(notes...) \ 24#define SONG(notes...) \
23 { notes } 25 { notes }
@@ -60,8 +62,9 @@
60#define TIMBRE_25 0.250f 62#define TIMBRE_25 0.250f
61#define TIMBRE_50 0.500f 63#define TIMBRE_50 0.500f
62#define TIMBRE_75 0.750f 64#define TIMBRE_75 0.750f
63#define TIMBRE_DEFAULT TIMBRE_50 65#ifndef TIMBRE_DEFAULT
64 66# define TIMBRE_DEFAULT TIMBRE_50
67#endif
65// Notes - # = Octave 68// Notes - # = Octave
66 69
67#ifdef __arm__ 70#ifdef __arm__