diff --git a/02-stage-audiodriver-2michat-v2/01-driver/01-packages b/02-stage-audiodriver-2michat-v2/01-driver/01-packages deleted file mode 100644 index 775d501..0000000 --- a/02-stage-audiodriver-2michat-v2/01-driver/01-packages +++ /dev/null @@ -1,4 +0,0 @@ -git -build-essential -device-tree-compiler -alsa-utils diff --git a/02-stage-audiodriver-2michat-v2/01-driver/02-run.sh b/02-stage-audiodriver-2michat-v2/01-driver/02-run.sh deleted file mode 100755 index 16159f3..0000000 --- a/02-stage-audiodriver-2michat-v2/01-driver/02-run.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -e - -# disable acp -mkdir -p "${ROOTFS_DIR}/etc/wireplumber/wireplumber.conf.d" -install -v -m 644 files/51-disable-acp.conf "${ROOTFS_DIR}/etc/wireplumber/wireplumber.conf.d/51-disable-acp.conf" diff --git a/02-stage-audiodriver-2michat-v2/01-driver/03-run-chroot.sh b/02-stage-audiodriver-2michat-v2/01-driver/03-run-chroot.sh deleted file mode 100755 index a9160c6..0000000 --- a/02-stage-audiodriver-2michat-v2/01-driver/03-run-chroot.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -e - -# ReSpeaker 2-Mics Pi HAT **V2.0** uses a TLV320AIC3104 codec on I2C 0x18 — -# NOT the WM8960 codec (0x1a) used on V1. No out-of-tree DKMS module is -# needed: the mainline `snd-soc-tlv320aic3x` driver already ships in the -# kernel. We just need the device-tree overlay that wires it up to the Pi's -# I2S pins. The overlay source is maintained by Seeed in their -# seeed-linux-dtoverlays repo. - -echo "Building ReSpeaker 2-Mic HAT V2.0 device-tree overlay..." - -SRC=/tmp/seeed-linux-dtoverlays -rm -rf "$SRC" -git clone --depth 1 https://github.com/Seeed-Studio/seeed-linux-dtoverlays.git "$SRC" - -cd "$SRC" -make overlays/rpi/respeaker-2mic-v2_0-overlay.dtbo - -# detect boot config + overlays location -OVERLAYS_DIR=/boot/overlays -CONFIG=/boot/config.txt -if [ -d /boot/firmware/overlays ]; then - OVERLAYS_DIR=/boot/firmware/overlays -fi -if [ -f /boot/firmware/config.txt ]; then - CONFIG=/boot/firmware/config.txt -fi -if [ -f /boot/firmware/usercfg.txt ]; then - CONFIG=/boot/firmware/usercfg.txt -fi - -install -v -m 644 overlays/rpi/respeaker-2mic-v2_0-overlay.dtbo \ - "${OVERLAYS_DIR}/respeaker-2mic-v2_0.dtbo" - -# set boot params: enable I2C and load the v2 overlay -sed -i -e 's:#dtparam=i2c_arm=on:dtparam=i2c_arm=on:g' "$CONFIG" || true -grep -q "^dtparam=i2c_arm=on$" "$CONFIG" || echo "dtparam=i2c_arm=on" >> "$CONFIG" -grep -q "^dtoverlay=respeaker-2mic-v2_0$" "$CONFIG" || \ - echo "dtoverlay=respeaker-2mic-v2_0" >> "$CONFIG" - -cd / -rm -rf "$SRC" - -echo "Done. After boot the card appears as 'seeed2micvoicec' (bcm2835-i2s-tlv320aic3x-hifi)." diff --git a/02-stage-audiodriver-2michat-v2/01-driver/files/51-disable-acp.conf b/02-stage-audiodriver-2michat-v2/01-driver/files/51-disable-acp.conf deleted file mode 100644 index 98ce8bd..0000000 --- a/02-stage-audiodriver-2michat-v2/01-driver/files/51-disable-acp.conf +++ /dev/null @@ -1,14 +0,0 @@ -monitor.alsa.rules = [ - { - matches = [ - { - device.name = "~alsa_card.*" - } - ] - actions = { - update-props = { - api.alsa.use-acp = false - } - } - } -] diff --git a/02-stage-audiodriver-2michat-v2/01-install-driver-package/01-run.sh b/02-stage-audiodriver-2michat-v2/01-install-driver-package/01-run.sh new file mode 100755 index 0000000..1100dc7 --- /dev/null +++ b/02-stage-audiodriver-2michat-v2/01-install-driver-package/01-run.sh @@ -0,0 +1,7 @@ +#!/bin/bash -e + +# The package brings the device tree overlay and the boot configuration for the ReSpeaker 2-Mics Pi HAT V2.0 +on_chroot << EOF2 +apt-get update +apt-get install -y picompose-driver-2michat-v2 +EOF2 diff --git a/02-stage-audiodriver-2michat-v2/02-set-audio-volume/01-run.sh b/02-stage-audiodriver-2michat-v2/02-set-audio-volume/01-run.sh deleted file mode 100755 index fc50a65..0000000 --- a/02-stage-audiodriver-2michat-v2/02-set-audio-volume/01-run.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -e - -install -v -m 755 files/configure_audio.sh "${ROOTFS_DIR}/usr/bin/configure_audio.sh" -install -v -m 644 files/configure_audio.service "${ROOTFS_DIR}/etc/systemd/system/configure_audio.service" - -on_chroot << EOF -echo "Enable audio services" -systemctl daemon-reload -systemctl enable configure_audio.service -EOF diff --git a/02-stage-audiodriver-2michat-v2/02-set-audio-volume/files/configure_audio.service b/02-stage-audiodriver-2michat-v2/02-set-audio-volume/files/configure_audio.service deleted file mode 100644 index 945f217..0000000 --- a/02-stage-audiodriver-2michat-v2/02-set-audio-volume/files/configure_audio.service +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description=PiCompose - Configure Audio volume setting (ReSpeaker 2-Mic HAT V2.0) -After=user@1000.service sound.target alsa-restore.service -Wants=user@1000.service sound.target alsa-restore.service - -[Service] -Type=oneshot -Environment=XDG_RUNTIME_DIR=/run/user/1000 -ExecStart=/usr/bin/configure_audio.sh -RemainAfterExit=yes -Restart=on-failure -RestartSec=30s - -[Install] -WantedBy=multi-user.target diff --git a/02-stage-audiodriver-2michat-v2/02-set-audio-volume/files/configure_audio.sh b/02-stage-audiodriver-2michat-v2/02-set-audio-volume/files/configure_audio.sh deleted file mode 100755 index 3821f66..0000000 --- a/02-stage-audiodriver-2michat-v2/02-set-audio-volume/files/configure_audio.sh +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/bash -set -u - - -set_volume_safe() { - local volume="${1:-1.0}" - - if wpctl get-volume @DEFAULT_AUDIO_SINK@ >/dev/null 2>&1; then - wpctl set-volume @DEFAULT_AUDIO_SINK@ "$volume" - echo "Volume set to $volume" - return 0 - else - echo "No default audio sink available" - exit 1 - fi -} - -wait_for_audio() { - local max_tries="${1:-30}" - local sleep_time="${2:-1}" - - local i=0 - while [ $i -lt $max_tries ]; do - if wpctl get-volume @DEFAULT_AUDIO_SINK@ >/dev/null 2>&1; then - echo "Audio ready" - return 0 - fi - - echo "Waiting for audio... ($i/$max_tries)" - sleep "$sleep_time" - i=$((i+1)) - done - - echo "Timeout: Audio not ready" - exit 1 -} - -wait_for_card_and_control() { - local card="$1" - local control="$2" - local max_tries=30 - local sleep_sec=1 - local count=0 - - while [ "$count" -lt "$max_tries" ]; do - count=$((count + 1)) - - if amixer -c "$card" info >/dev/null 2>&1; then - if amixer -c "$card" scontrols | grep -Fq "'$control'"; then - echo "Card $card with control '$control' is ready ($count/$max_tries)" - return 0 - fi - echo "Card $card found, but control '$control' not ready yet ($count/$max_tries)" - else - echo "Card $card not ready yet ($count/$max_tries)" - fi - - sleep "$sleep_sec" - done - - echo "Card $card with control '$control' did not become ready" - return 1 -} - -set_control_if_exists() { - local card="$1" - local control="$2" - local value="$3" - - if amixer -c "$card" scontrols | grep -Fq "'$control'"; then - echo "Setting $control on $card to $value" - amixer -c "$card" set "$control" "$value" - return 0 - fi - - echo "Control '$control' not found on $card, skipping" - return 0 -} - -# Wait for audio system to be ready -wait_for_audio 30 1 - -# Same kernel alias as V1 (`seeed2micvoicec`); the PCM control distinguishes -# V2's tlv320aic3x from V1's wm8960. -if ! wait_for_card_and_control seeed2micvoicec PCM; then - echo "No TLV320AIC3104-based card became ready; is the V2.0 overlay loaded?" - exit 1 -fi -CARD="seeed2micvoicec" - -FAIL=0 -set_control_if_exists "$CARD" "HP DAC" 100% || FAIL=1 -set_control_if_exists "$CARD" "Line DAC" 100% || FAIL=1 -set_control_if_exists "$CARD" "HP" 100% unmute || FAIL=1 -set_control_if_exists "$CARD" "Line" 100% unmute || FAIL=1 -set_control_if_exists "$CARD" "PGA" 80% cap || FAIL=1 - -if [ "$FAIL" -ne 0 ]; then - echo "One or more amixer set calls failed; not storing state." >&2 - exit 1 -fi - -# Set pipewire sink volume -set_volume_safe 1.0 - -# Alsa save -alsactl store diff --git a/CLAUDE.md b/CLAUDE.md index 6b3edf9..ac02d29 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -74,7 +74,7 @@ Preinstalled projects: `example` (hello-world) from the package `picompose-core` ## Audio setup - The package `picompose-core` ships the PipeWire drop-in config (clock rate, real-time scheduling module) and the WirePlumber rule for ALSA outputs (volume, no suspend). `01-stage-base/04-install-pipewire-audio` installs the PipeWire packages and sets the ALSA bridge, `pi` in the `pipewire` group for rtprio, and lingering for `pi` so services run without a login session. -- Hardware stages add a `configure_audio.service` plus script that waits (with a retry limit) for the card/control and sets the hardware volume through `wpctl`/`amixer`. The ReSpeaker Lite stage adds a keep-audio-alive service as a workaround for connectivity problems on the Pi Zero 2W. +- The hardware stages install their driver as a package from the APT repository and do not set the hardware volume themselves. The default volume of a sound card without a stored state comes from `picompose-core`. The package of the 2-Mic HAT V2.0 maps the sink volume to the DAC controls of the codec through an ACP profile set. The ReSpeaker Lite stage adds a keep-audio-alive service as a workaround for connectivity problems on the Pi Zero 2W. - Some earlier file names in git history differ (for example `50-volume.conf`). Check `git log` before assuming a file never existed. - Debugging notes for users: `docs/pipewire_debugging.md`. diff --git a/breaking_changes.md b/breaking_changes.md index af640f1..dd56829 100644 --- a/breaking_changes.md +++ b/breaking_changes.md @@ -7,6 +7,8 @@ If you use the homeassistant image please also follow the snapcast and satellite ## Unreleased The stage `02-stage-audiodriver-other` is removed, the images `PiCompose` and `PiCompose_Linux-Voice-Assistant` are built without a hardware stage and the package `picompose-driver-other` is no longer published. `configure_audio.service` and `/usr/bin/configure_audio.sh` are gone, which set the volume of the default sink to 100 % and ran `alsactl store` at every start. The default volume of a sound card without a stored state is now 100 % through `picompose-core` (`51-default-volume.conf`), a volume that WirePlumber has already stored for the card is kept. On an existing image, `apt upgrade` leaves a dangling `configure_audio.service` symlink behind. +The driver of the ReSpeaker 2-Mics Pi HAT V2.0 image is installed by the package `picompose-driver-2michat-v2` instead of the image build. The package brings the device tree overlay, the boot configuration and an ACP profile set for the sound card, which no longer turns ACP off (`51-disable-acp.conf` is gone). `configure_audio.service` and `/usr/bin/configure_audio.sh` are gone, which set the outputs of the TLV320 codec to 100 %, the input gain to 80 %, the volume of the default sink to 100 % and ran `alsactl store` at every start. The profile set of the package now puts `HP DAC` and `Line DAC` at 0 dB at a sink volume of 100 % and lets the sink volume change them. The other controls (`HP`, `HPCOM DAC`, and the input gain `PGA`, which was 80 % and is now left at the 27 % of the codec) are no longer set. On an existing image, `apt upgrade` leaves a dangling `configure_audio.service` symlink behind. + The audio setup of the Satellite1 image is installed from the APT repository instead of being downloaded from GitHub: the packages `satellite1-rpi-setup-trixie` and `satellite1-rpi-sdk` of FutureProofHomes are republished unchanged by PiCompose-Package-Driver-Satellite1. The image build no longer copies `51-disable-acp.conf`, `configure_audio.service` and `/usr/bin/configure_audio.sh`, and it no longer installs the custom kernel `linux-image-6.18.34-fusb302-rpi-v8`, the Satellite1 relies on the fusb302 driver of the Raspberry Pi kernel since 6.18. The microphone works with the ACP profile set of `satellite1-rpi-setup-trixie` 1.5-1, which replaces `51-disable-acp.conf`. On an existing image, `apt upgrade` does not remove the old `51-disable-acp.conf` and the dangling `configure_audio.service` symlink. The audio setup of the ReSpeaker Lite image is installed by the package `picompose-driver-respeaker-lite` instead of the image build. `keep-audio-alive.service` stays. `configure_audio.service` and `/usr/bin/configure_audio.sh` are gone, which set the volume of the default sink to 100 % at every start. The default volume of a sound card without a stored state is now 100 % through `picompose-core` (`51-default-volume.conf`), a volume that WirePlumber has already stored for the card is kept. On an existing image, `apt upgrade` leaves a dangling `configure_audio.service` symlink behind. diff --git a/docs/hardware_2mic_v2.md b/docs/hardware_2mic_v2.md index dbc6c0b..07b6e0a 100644 --- a/docs/hardware_2mic_v2.md +++ b/docs/hardware_2mic_v2.md @@ -31,9 +31,9 @@ Unlike v1 — which needs an out-of-tree DKMS kernel module — v2 uses the main 1. The device-tree overlay `respeaker-2mic-v2_0.dtbo` (built from [Seeed-Studio/seeed-linux-dtoverlays](https://github.com/Seeed-Studio/seeed-linux-dtoverlays)), enabled via `dtoverlay=respeaker-2mic-v2_0` in `/boot/firmware/config.txt`. 2. `dtparam=i2c_arm=on` in `/boot/firmware/config.txt`. -3. Per-boot mixer tuning — the TLV320 ships with several attenuators well below 100 % (`HP DAC` at -23.5 dB in particular), producing a card that appears to work but is inaudible at typical application volumes. +3. Mixer tuning — the TLV320 ships with several attenuators well below 100 % (`HP DAC` at -23.5 dB in particular), producing a card that appears to work but is inaudible at typical application volumes. -The PiCompose `02-stage-audiodriver-2michat-v2` stage performs all three steps automatically. The mixer tuning is applied by `configure_audio.service` on every boot, the same pattern other audiodriver stages follow after #42: amixer on the codec-specific controls, then `wpctl set-volume @DEFAULT_AUDIO_SINK@ 1.0` to keep the PipeWire sink at unity. PipeWire / WirePlumber manage ALSA state per session and can reset the mixer between reboots, so a first-boot-only guard would let users end up stuck at 0%. Customization via `amixer` is still possible at runtime — it just won't survive a reboot. +The PiCompose `02-stage-audiodriver-2michat-v2` stage installs the package `picompose-driver-2michat-v2` from the APT repository ([PiCompose-Package-Driver-2MicHat-V2](https://github.com/florian-asche/PiCompose-Package-Driver-2MicHat-V2)), which does the first two steps. The package also does the mixer tuning of step 3. `configure_audio.service` is gone. Instead the package (version 0.2.0 and later) ships an ACP profile set for the sound card, selected by a udev rule. It merges `HP DAC` and `Line DAC` into the volume of the PipeWire sink, so the default volume of 100 % (`51-default-volume.conf` of `picompose-core`) puts both at 0 dB, and a lower sink volume lowers `HP DAC`. Checked on one device after a reboot: both controls at 100 %, and the sink volume changes `HP DAC`. How loud the card is has not been checked, and the other controls (`HP`, `HPCOM DAC`, the input gain `PGA`) are left as the codec starts. Raise them with `amixer` or `alsamixer` if you need more. ## Additional information