Browse Source

Move shutdown delay to audio feature (#25859)

Joel Challis 7 months ago
parent
commit
10faca0b85
3 changed files with 30 additions and 13 deletions
  1. 21 0
      quantum/audio/audio.c
  2. 2 0
      quantum/audio/audio.h
  3. 7 13
      quantum/quantum.c

+ 21 - 0
quantum/audio/audio.c

@@ -71,6 +71,10 @@
 #    define AUDIO_DEFAULT_CLICKY_ON true
 #endif
 
+#ifndef AUDIO_SHUTDOWN_DELAY
+#    define AUDIO_SHUTDOWN_DELAY 250
+#endif
+
 #ifndef AUDIO_TONE_STACKSIZE
 #    define AUDIO_TONE_STACKSIZE 8
 #endif
@@ -114,9 +118,14 @@ extern uint16_t voices_timer;
 #ifndef AUDIO_OFF_SONG
 #    define AUDIO_OFF_SONG SONG(AUDIO_OFF_SOUND)
 #endif
+#ifndef GOODBYE_SONG
+#    define GOODBYE_SONG SONG(GOODBYE_SOUND)
+#endif
+
 float startup_song[][2]   = STARTUP_SONG;
 float audio_on_song[][2]  = AUDIO_ON_SONG;
 float audio_off_song[][2] = AUDIO_OFF_SONG;
+float goodbye_song[][2]   = GOODBYE_SONG;
 
 static bool    audio_initialized    = false;
 static bool    audio_driver_stopped = true;
@@ -210,6 +219,18 @@ void audio_startup(void) {
     last_timestamp = timer_read();
 }
 
+void audio_shutdown(void) {
+    uint16_t timer_start = timer_read();
+
+    PLAY_SONG(goodbye_song);
+
+    while (timer_elapsed(timer_start) < AUDIO_SHUTDOWN_DELAY) {
+        wait_ms(1);
+    }
+
+    stop_all_notes();
+}
+
 void audio_toggle(void) {
     if (audio_config.enable) {
         stop_all_notes();

+ 2 - 0
quantum/audio/audio.h

@@ -218,6 +218,8 @@ uint16_t audio_ms_to_duration(uint16_t duration_ms);
 
 void audio_startup(void);
 
+void audio_shutdown(void);
+
 // hardware interface
 
 // implementation in the driver_avr/arm_* respective parts

+ 7 - 13
quantum/quantum.c

@@ -94,10 +94,6 @@
 #endif
 
 #ifdef AUDIO_ENABLE
-#    ifndef GOODBYE_SONG
-#        define GOODBYE_SONG SONG(GOODBYE_SOUND)
-#    endif
-float goodbye_song[][2] = GOODBYE_SONG;
 #    ifdef DEFAULT_LAYER_SONGS
 float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS;
 #    endif
@@ -218,18 +214,16 @@ void shutdown_quantum(bool jump_to_bootloader) {
 #    ifndef NO_MUSIC_MODE
     music_all_notes_off();
 #    endif
-    uint16_t timer_start = timer_read();
-    PLAY_SONG(goodbye_song);
-    shutdown_modules(jump_to_bootloader);
-    shutdown_kb(jump_to_bootloader);
-    while (timer_elapsed(timer_start) < 250)
-        wait_ms(1);
-    stop_all_notes();
-#else
+    audio_shutdown();
+#endif
+
     shutdown_modules(jump_to_bootloader);
     shutdown_kb(jump_to_bootloader);
-    wait_ms(250);
+
+#if SHUTDOWN_DELAY > 0
+    wait_ms(SHUTDOWN_DELAY);
 #endif
+
 #ifdef HAPTIC_ENABLE
     haptic_shutdown();
 #endif