From 92963e35f7d764643b6c21d16bd68138082ae5b0 Mon Sep 17 00:00:00 2001 From: Howard Huang Date: Thu, 18 Jun 2026 00:54:54 -0500 Subject: [PATCH] CHORE: fix LED flicker in setup-pi (disable sound, isolate core) Two provisioning tweaks that eliminate visible panel flicker, both idempotent and applied on the next reboot: - Blacklist snd_bcm2835 and set dtparam=audio=off. The Adafruit HAT drives the panel PWM on the same hardware the sound module uses, so onboard sound is the most common flicker source. - Append isolcpus=3 to the kernel cmdline so the matrix refresh thread (pinned to core 3) is not interrupted by the scheduler. The completion message now notes a reboot is needed to apply them. --- bin/setup-pi.sh | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/bin/setup-pi.sh b/bin/setup-pi.sh index 2e01d68..c455760 100755 --- a/bin/setup-pi.sh +++ b/bin/setup-pi.sh @@ -77,7 +77,34 @@ sudo mkdir -p /var/lib/jetset/logos sudo chown "$(whoami):$(whoami)" /var/lib/jetset/logos uv run python scripts/download_logos.py || echo "(logo download incomplete — re-run later)" -# 7. Install + enable the systemd service (runs on boot) +# 7. Reduce LED panel flicker. Two causes, both fixed here (idempotent; both +# take effect on the next reboot): +# a) Onboard sound: the Adafruit HAT drives the panel's PWM timing on the +# same hardware snd_bcm2835 uses, so leaving sound enabled is the most +# common flicker source. Blacklist the module and turn audio off. +# b) CPU contention: the matrix refresh thread runs on core 3; isolating it +# (isolcpus=3) stops the scheduler from interrupting it with other work. +echo "=== Reducing LED flicker (disable sound, isolate core 3) ===" +echo "blacklist snd_bcm2835" | sudo tee /etc/modprobe.d/blacklist-rgb-matrix.conf >/dev/null + +BOOT_CONFIG=/boot/firmware/config.txt +[ -f "$BOOT_CONFIG" ] || BOOT_CONFIG=/boot/config.txt +if [ -f "$BOOT_CONFIG" ]; then + if grep -q "^dtparam=audio=on" "$BOOT_CONFIG"; then + sudo sed -i "s/^dtparam=audio=on/dtparam=audio=off/" "$BOOT_CONFIG" + elif ! grep -q "^dtparam=audio=off" "$BOOT_CONFIG"; then + echo "dtparam=audio=off" | sudo tee -a "$BOOT_CONFIG" >/dev/null + fi +fi + +# cmdline.txt must stay a single line; append isolcpus to line 1 only if absent. +BOOT_CMDLINE=/boot/firmware/cmdline.txt +[ -f "$BOOT_CMDLINE" ] || BOOT_CMDLINE=/boot/cmdline.txt +if [ -f "$BOOT_CMDLINE" ] && ! grep -q "isolcpus=" "$BOOT_CMDLINE"; then + sudo sed -i "1 s/\$/ isolcpus=3/" "$BOOT_CMDLINE" +fi + +# 8. Install + enable the systemd service (runs on boot) echo "=== Installing jetset systemd service ===" bash bin/install-service.sh sudo systemctl restart jetset @@ -85,3 +112,4 @@ sudo systemctl restart jetset echo "=== Setup complete! The jetset service is enabled and running. ===" echo " Logs: journalctl -u jetset -f" echo " (foreground debug run: \`make debug-pi\` — stop the service first)" +echo " NOTE: reboot once to apply the sound/flicker fix: sudo reboot"