From 5b92e4274d98414b1e8a3b50e2c4a9c31bc9fe72 Mon Sep 17 00:00:00 2001 From: ro8inmorgan Date: Tue, 20 May 2025 13:34:53 +0200 Subject: [PATCH 1/4] Added back alsa store and restore, seems to indeed help with restoring audio --- skeleton/SYSTEM/tg5040/bin/suspend | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/skeleton/SYSTEM/tg5040/bin/suspend b/skeleton/SYSTEM/tg5040/bin/suspend index 10fcd34fe..4e0d1f66d 100755 --- a/skeleton/SYSTEM/tg5040/bin/suspend +++ b/skeleton/SYSTEM/tg5040/bin/suspend @@ -16,9 +16,9 @@ before() { echo disabled > "$f" done - # >&2 echo "Saving mixer state..." - # mkdir -p "$asound_state_dir" - # alsactl --file "$asound_state_dir/asound.state.pre" store || true + >&2 echo "Saving mixer state..." + mkdir -p "$asound_state_dir" + alsactl --file "$asound_state_dir/asound.state.pre" store || true # if pgrep wpa_supplicant; then # wpa_running=1 @@ -51,9 +51,9 @@ after() { echo enabled > "$f" done # /mnt/SDCARD/Emus/tg5040/PORTS.pak/bin/i2cset -yfr 6 0x34 0x25 0x20 - # >&2 echo "Restoring mixer state..." - # alsactl --file "$asound_state_dir/asound.state.post" store || true - # alsactl --file "$asound_state_dir/asound.state.pre" restore || true + >&2 echo "Restoring mixer state..." + alsactl --file "$asound_state_dir/asound.state.post" store || true + alsactl --file "$asound_state_dir/asound.state.pre" restore || true # >&2 echo "Unblocking wireless..." # echo 1 >/sys/class/rfkill/rfkill0/state || true From 2704a57a82a04ee0e6a7da1151837f105b2c4f2f Mon Sep 17 00:00:00 2001 From: ro8inmorgan Date: Tue, 20 May 2025 14:43:49 +0200 Subject: [PATCH 2/4] Ok no audio bug is fixed too, just needed to reinitialize audio after suspending really --- skeleton/SYSTEM/tg5040/bin/suspend | 24 ++++++++++++------------ workspace/all/common/api.c | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/skeleton/SYSTEM/tg5040/bin/suspend b/skeleton/SYSTEM/tg5040/bin/suspend index 4e0d1f66d..67ca9aa2a 100755 --- a/skeleton/SYSTEM/tg5040/bin/suspend +++ b/skeleton/SYSTEM/tg5040/bin/suspend @@ -2,23 +2,23 @@ set -euo pipefail exec 0<&- -wpa_running= -hciattach_running= -bluetoothd_running= +# wpa_running= +# hciattach_running= +# bluetoothd_running= -asound_state_dir=/tmp/asound-suspend +# asound_state_dir=/tmp/asound-suspend before() { >&2 echo "Preparing for suspend..." - # /mnt/SDCARD/Emus/tg5040/PORTS.pak/bin/i2cset -yfr 6 0x34 0x25 0x21 + for f in $(find /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/ -name wakeup); do echo "Disabling wakeup in $f" echo disabled > "$f" done - >&2 echo "Saving mixer state..." - mkdir -p "$asound_state_dir" - alsactl --file "$asound_state_dir/asound.state.pre" store || true + # >&2 echo "Saving mixer state..." + # mkdir -p "$asound_state_dir" + # alsactl --file "$asound_state_dir/asound.state.pre" store || true # if pgrep wpa_supplicant; then # wpa_running=1 @@ -50,10 +50,10 @@ after() { echo "Disabling wakeup in $f" echo enabled > "$f" done - # /mnt/SDCARD/Emus/tg5040/PORTS.pak/bin/i2cset -yfr 6 0x34 0x25 0x20 - >&2 echo "Restoring mixer state..." - alsactl --file "$asound_state_dir/asound.state.post" store || true - alsactl --file "$asound_state_dir/asound.state.pre" restore || true + + # >&2 echo "Restoring mixer state..." + # alsactl --file "$asound_state_dir/asound.state.post" store || true + # alsactl --file "$asound_state_dir/asound.state.pre" restore || true # >&2 echo "Unblocking wireless..." # echo 1 >/sys/class/rfkill/rfkill0/state || true diff --git a/workspace/all/common/api.c b/workspace/all/common/api.c index 0a4ac041f..d40c6fd7e 100644 --- a/workspace/all/common/api.c +++ b/workspace/all/common/api.c @@ -2854,6 +2854,22 @@ static void PWR_exitSleep(void) { PLAT_enableBacklight(1); SetVolume(GetVolume()); } + // reinitialize audio after sleep otherwise it doesnt come back on sometimes + LOG_info("Reinitialize audio after sleep\n"); + SDL_CloseAudio(); + + SDL_AudioSpec spec_in; + SDL_AudioSpec spec_out; + + spec_in.freq = PLAT_pickSampleRate(snd.sample_rate_in, MAX_SAMPLE_RATE); + spec_in.format = AUDIO_S16; + spec_in.channels = 2; + spec_in.samples = SAMPLES; + spec_in.callback = SND_audioCallback; + + if (SDL_OpenAudio(&spec_in, &spec_out)<0) LOG_info("SDL_OpenAudio error: %s\n", SDL_GetError()); + snd.sample_rate_out = spec_out.freq; + SDL_PauseAudio(0); sync(); From 1d45e5b5fd4939585b134e2063b0c5306ceffdd0 Mon Sep 17 00:00:00 2001 From: ro8inmorgan Date: Tue, 20 May 2025 14:46:41 +0200 Subject: [PATCH 3/4] Fixed log message in suspend script --- skeleton/SYSTEM/tg5040/bin/suspend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skeleton/SYSTEM/tg5040/bin/suspend b/skeleton/SYSTEM/tg5040/bin/suspend index 67ca9aa2a..a9fafa187 100755 --- a/skeleton/SYSTEM/tg5040/bin/suspend +++ b/skeleton/SYSTEM/tg5040/bin/suspend @@ -47,7 +47,7 @@ after() { >&2 echo "Resumed from suspend." for f in $(find /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/ -name wakeup); do - echo "Disabling wakeup in $f" + echo "Enabling wakeup in $f" echo enabled > "$f" done From 612378fddaab91c7b0817293f1d3d7873353eee9 Mon Sep 17 00:00:00 2001 From: ro8inmorgan Date: Tue, 20 May 2025 14:53:27 +0200 Subject: [PATCH 4/4] removed 2 logs not needed --- workspace/all/minarch/minarch.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/workspace/all/minarch/minarch.c b/workspace/all/minarch/minarch.c index 42e6c1ec7..323362e7d 100644 --- a/workspace/all/minarch/minarch.c +++ b/workspace/all/minarch/minarch.c @@ -4804,7 +4804,6 @@ void Menu_quit(void) { SDL_FreeSurface(menu.overlay); } void Menu_beforeSleep() { - LOG_info("beforeSleep\n"); SRAM_write(); RTC_write(); State_autosave(); @@ -4812,7 +4811,6 @@ void Menu_beforeSleep() { PWR_setCPUSpeed(CPU_SPEED_MENU); } void Menu_afterSleep() { - LOG_info("beforeSleep\n"); unlink(AUTO_RESUME_PATH); setOverclock(overclock); }