diff options
| -rw-r--r-- | quantum/audio/audio.h | 1 | ||||
| -rw-r--r-- | quantum/audio/audio_avr.c | 2 | ||||
| -rw-r--r-- | quantum/audio/audio_chibios.c | 15 | ||||
| -rw-r--r-- | quantum/audio/audio_pwm.c | 11 | ||||
| -rw-r--r-- | quantum/quantum.c | 20 | ||||
| -rw-r--r-- | tmk_core/common/avr/suspend.c | 4 | ||||
| -rw-r--r-- | tmk_core/common/chibios/suspend.c | 7 |
7 files changed, 56 insertions, 4 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); | |||
| 83 | void decrease_tempo(uint8_t tempo_change); | 83 | void decrease_tempo(uint8_t tempo_change); |
| 84 | 84 | ||
| 85 | void audio_init(void); | 85 | void audio_init(void); |
| 86 | void audio_startup(void); | ||
| 86 | 87 | ||
| 87 | #ifdef PWM_AUDIO | 88 | #ifdef PWM_AUDIO |
| 88 | void play_sample(uint8_t* s, uint16_t l, bool r); | 89 | void 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 | ||
| 232 | void 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 1863ae140..dddb8f135 100644 --- a/quantum/audio/audio_chibios.c +++ b/quantum/audio/audio_chibios.c | |||
| @@ -282,6 +282,12 @@ void audio_init() { | |||
| 282 | dacStart(&DACD2, &dac1cfg2); | 282 | dacStart(&DACD2, &dac1cfg2); |
| 283 | 283 | ||
| 284 | /* | 284 | /* |
| 285 | * Start the note timer | ||
| 286 | */ | ||
| 287 | gptStart(&GPTD8, &gpt8cfg1); | ||
| 288 | gptStartContinuous(&GPTD8, 2U); | ||
| 289 | |||
| 290 | /* | ||
| 285 | * Starting GPT6/7 driver, it is used for triggering the DAC. | 291 | * Starting GPT6/7 driver, it is used for triggering the DAC. |
| 286 | */ | 292 | */ |
| 287 | START_CHANNEL_1(); | 293 | START_CHANNEL_1(); |
| @@ -295,10 +301,12 @@ void audio_init() { | |||
| 295 | 301 | ||
| 296 | audio_initialized = true; | 302 | audio_initialized = true; |
| 297 | 303 | ||
| 304 | stop_all_notes(); | ||
| 305 | } | ||
| 306 | |||
| 307 | void audio_startup() { | ||
| 298 | if (audio_config.enable) { | 308 | if (audio_config.enable) { |
| 299 | PLAY_SONG(startup_song); | 309 | PLAY_SONG(startup_song); |
| 300 | } else { | ||
| 301 | stop_all_notes(); | ||
| 302 | } | 310 | } |
| 303 | } | 311 | } |
| 304 | 312 | ||
| @@ -638,6 +646,9 @@ bool is_playing_notes(void) { return playing_notes; } | |||
| 638 | bool is_audio_on(void) { return (audio_config.enable != 0); } | 646 | bool is_audio_on(void) { return (audio_config.enable != 0); } |
| 639 | 647 | ||
| 640 | void audio_toggle(void) { | 648 | void audio_toggle(void) { |
| 649 | if (audio_config.enable) { | ||
| 650 | stop_all_notes(); | ||
| 651 | } | ||
| 641 | audio_config.enable ^= 1; | 652 | audio_config.enable ^= 1; |
| 642 | eeconfig_update_audio(audio_config.raw); | 653 | eeconfig_update_audio(audio_config.raw); |
| 643 | 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 | ||
| 35 | float 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 | ||
| 163 | void audio_startup() { | ||
| 164 | if (audio_config.enable) { | ||
| 165 | PLAY_SONG(startup_song); | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 158 | void stop_all_notes() { | 169 | void stop_all_notes() { |
| 159 | if (!audio_initialized) { | 170 | if (!audio_initialized) { |
| 160 | audio_init(); | 171 | audio_init(); |
diff --git a/quantum/quantum.c b/quantum/quantum.c index 22aa52838..5e0cde8a2 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -656,6 +656,26 @@ void matrix_init_quantum() { | |||
| 656 | } | 656 | } |
| 657 | 657 | ||
| 658 | void matrix_scan_quantum() { | 658 | void matrix_scan_quantum() { |
| 659 | #if defined(AUDIO_ENABLE) | ||
| 660 | // There are some tasks that need to be run a little bit | ||
| 661 | // after keyboard startup, or else they will not work correctly | ||
| 662 | // because of interaction with the USB device state, which | ||
| 663 | // may still be in flux... | ||
| 664 | // | ||
| 665 | // At the moment the only feature that needs this is the | ||
| 666 | // startup song. | ||
| 667 | static bool delayed_tasks_run = false; | ||
| 668 | static uint16_t delayed_task_timer = 0; | ||
| 669 | if (!delayed_tasks_run) { | ||
| 670 | if (!delayed_task_timer) { | ||
| 671 | delayed_task_timer = timer_read(); | ||
| 672 | } else if (timer_elapsed(delayed_task_timer) > 300) { | ||
| 673 | audio_startup(); | ||
| 674 | delayed_tasks_run = true; | ||
| 675 | } | ||
| 676 | } | ||
| 677 | #endif | ||
| 678 | |||
| 659 | #if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE) | 679 | #if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE) |
| 660 | matrix_scan_music(); | 680 | matrix_scan_music(); |
| 661 | #endif | 681 | #endif |
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 86c3df040..9db0e0064 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c | |||
| @@ -97,8 +97,7 @@ static void power_down(uint8_t wdto) { | |||
| 97 | led_set(leds_off); | 97 | led_set(leds_off); |
| 98 | 98 | ||
| 99 | # ifdef AUDIO_ENABLE | 99 | # ifdef AUDIO_ENABLE |
| 100 | // This sometimes disables the start-up noise, so it's been disabled | 100 | stop_all_notes(); |
| 101 | // stop_all_notes(); | ||
| 102 | # endif /* AUDIO_ENABLE */ | 101 | # endif /* AUDIO_ENABLE */ |
| 103 | # if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | 102 | # if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) |
| 104 | rgblight_suspend(); | 103 | rgblight_suspend(); |
| @@ -157,6 +156,7 @@ __attribute__((weak)) void suspend_wakeup_init_user(void) {} | |||
| 157 | * FIXME: needs doc | 156 | * FIXME: needs doc |
| 158 | */ | 157 | */ |
| 159 | __attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); } | 158 | __attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); } |
| 159 | |||
| 160 | /** \brief run immediately after wakeup | 160 | /** \brief run immediately after wakeup |
| 161 | * | 161 | * |
| 162 | * FIXME: needs doc | 162 | * FIXME: needs doc |
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c index 796056019..49e20641f 100644 --- a/tmk_core/common/chibios/suspend.c +++ b/tmk_core/common/chibios/suspend.c | |||
| @@ -12,6 +12,10 @@ | |||
| 12 | #include "led.h" | 12 | #include "led.h" |
| 13 | #include "wait.h" | 13 | #include "wait.h" |
| 14 | 14 | ||
| 15 | #ifdef AUDIO_ENABLE | ||
| 16 | # include "audio.h" | ||
| 17 | #endif /* AUDIO_ENABLE */ | ||
| 18 | |||
| 15 | #ifdef BACKLIGHT_ENABLE | 19 | #ifdef BACKLIGHT_ENABLE |
| 16 | # include "backlight.h" | 20 | # include "backlight.h" |
| 17 | #endif | 21 | #endif |
| @@ -65,6 +69,9 @@ void suspend_power_down(void) { | |||
| 65 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | 69 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) |
| 66 | rgblight_suspend(); | 70 | rgblight_suspend(); |
| 67 | #endif | 71 | #endif |
| 72 | #ifdef AUDIO_ENABLE | ||
| 73 | stop_all_notes(); | ||
| 74 | #endif /* AUDIO_ENABLE */ | ||
| 68 | 75 | ||
| 69 | suspend_power_down_kb(); | 76 | suspend_power_down_kb(); |
| 70 | // on AVR, this enables the watchdog for 15ms (max), and goes to | 77 | // on AVR, this enables the watchdog for 15ms (max), and goes to |
