From 746192140701f3f8c1af0669887e18a9ea4606f6 Mon Sep 17 00:00:00 2001 From: turmary Date: Mon, 28 Sep 2020 08:45:45 +0100 Subject: [PATCH 1/9] Add: clear title for each install/uninstall steps --- install.sh | 25 +++++++++++++++++-------- uninstall.sh | 41 +++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/install.sh b/install.sh index e806c40..fad8cbf 100755 --- a/install.sh +++ b/install.sh @@ -164,12 +164,12 @@ done if [ "X$keep_kernel" != "X" ]; then FORCE_KERNEL=$(dpkg -s raspberrypi-kernel | awk '/^Version:/{printf "%s\n",$2;}') - echo "Keep current system kernel not to change" + echo -e "\n### Keep current system kernel not to change" elif [ "X$compat_kernel" != "X" ]; then - echo "will compile with a compatible kernel..." + echo -e "\n### will compile with a compatible kernel..." else FORCE_KERNEL="" - echo "will compile with the latest kernel..." + echo -e "\n### will compile with the latest kernel..." fi [ "X$FORCE_KERNEL" != "X" ] && { echo -e "The kernel & headers use package version: $FORCE_KERNEL\r\n\r\n" @@ -202,6 +202,7 @@ which apt &>/dev/null if [[ $? -eq 0 ]]; then apt update -y apt-get -y install dkms git i2c-tools libasound2-plugins + echo -e "\n### Install required kernel package" install_kernel # rpi-update checker check_kernel_headers @@ -253,13 +254,15 @@ function install_module { mkdir -p /var/lib/dkms/$mod/$ver/$marker } +echo -e "\n### Install sound card driver" install_module "./" "seeed-voicecard" # install dtbos -cp seeed-2mic-voicecard.dtbo $OVERLAYS -cp seeed-4mic-voicecard.dtbo $OVERLAYS -cp seeed-8mic-voicecard.dtbo $OVERLAYS +echo -e "\n### Install device tree overlays" +cp -v seeed-2mic-voicecard.dtbo $OVERLAYS +cp -v seeed-4mic-voicecard.dtbo $OVERLAYS +cp -v seeed-8mic-voicecard.dtbo $OVERLAYS # install alsa plugins # we don't need this plugin now @@ -267,6 +270,7 @@ cp seeed-8mic-voicecard.dtbo $OVERLAYS rm -f /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so #set kernel modules +echo -e "\n### Install startup modules in /etc/modules" grep -q "^snd-soc-seeed-voicecard$" /etc/modules || \ echo "snd-soc-seeed-voicecard" >> /etc/modules grep -q "^snd-soc-ac108$" /etc/modules || \ @@ -277,6 +281,7 @@ grep -q "^snd-soc-wm8960$" /etc/modules || \ #set dtoverlays CONFIG=/boot/config.txt [ -f /boot/firmware/usercfg.txt ] && CONFIG=/boot/firmware/usercfg.txt +echo -e "\n### Found boot configuration file $CONFIG" sed -i -e 's:#dtparam=i2c_arm=on:dtparam=i2c_arm=on:g' $CONFIG || true grep -q "^dtoverlay=i2s-mmap$" $CONFIG || \ @@ -287,11 +292,13 @@ grep -q "^dtparam=i2s=on$" $CONFIG || \ echo "dtparam=i2s=on" >> $CONFIG #install config files +echo -e "\n### Install alsa and widget configuration" mkdir /etc/voicecard || true -cp *.conf /etc/voicecard -cp *.state /etc/voicecard +cp -v *.conf /etc/voicecard +cp -v *.state /etc/voicecard #create git repo +echo -e "\n### Manage alsa configuration by git" git_email=$(git config --global --get user.email) git_name=$(git config --global --get user.name) if [ "x${git_email}" == "x" ] || [ "x${git_name}" == "x" ] ; then @@ -306,6 +313,8 @@ git --git-dir=/etc/voicecard/.git --work-tree=/etc/voicecard/ add --all echo "git commit -m \"origin configures\"" git --git-dir=/etc/voicecard/.git --work-tree=/etc/voicecard/ commit -m "origin configures" +echo -e "\n### Start service seeed-voicecard" +echo -e " see /var/log/seeed-voicecard.log for more service information" cp seeed-voicecard /usr/bin/ cp seeed-voicecard.service /lib/systemd/system/ systemctl enable seeed-voicecard.service diff --git a/uninstall.sh b/uninstall.sh index a00f7a1..b1292fc 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -54,39 +54,40 @@ do_overlay() { RPI_HATS="seeed-2mic-voicecard seeed-4mic-voicecard seeed-8mic-voicecard" PATH=$PATH:/opt/vc/bin -echo "remove dtbos" +echo -e "\n### Remove dtbos" for i in $RPI_HATS; do dtoverlay -r $i done OVERLAYS=/boot/overlays [ -d /boot/firmware/overlays ] && OVERLAYS=/boot/firmware/overlays -rm ${OVERLAYS}/seeed-2mic-voicecard.dtbo || true -rm ${OVERLAYS}/seeed-4mic-voicecard.dtbo || true -rm ${OVERLAYS}/seeed-8mic-voicecard.dtbo || true +rm -v ${OVERLAYS}/seeed-2mic-voicecard.dtbo || true +rm -v ${OVERLAYS}/seeed-4mic-voicecard.dtbo || true +rm -v ${OVERLAYS}/seeed-8mic-voicecard.dtbo || true -echo "remove alsa configs" -rm -rf /etc/voicecard/ || true +echo -e "\n### Remove alsa configs" +rm -rfv /etc/voicecard/ || true -echo "disabled seeed-voicecard.service " +echo -e "\n### Disable seeed-voicecard.service " +systemctl stop seeed-voicecard.service systemctl disable seeed-voicecard.service -echo "remove seeed-voicecard" -rm /usr/bin/seeed-voicecard || true -rm /lib/systemd/system/seeed-voicecard.service || true +echo -e "\n### Remove seeed-voicecard" +rm -v /usr/bin/seeed-voicecard || true +rm -v /lib/systemd/system/seeed-voicecard.service || true -echo "remove dkms" -rm -rf /var/lib/dkms/seeed-voicecard || true +echo -e "\n### Remove dkms" +rm -rfv /var/lib/dkms/seeed-voicecard || true -echo "remove kernel modules" -rm /lib/modules/*/kernel/sound/soc/codecs/snd-soc-wm8960.ko || true -rm /lib/modules/*/kernel/sound/soc/codecs/snd-soc-ac108.ko || true -rm /lib/modules/*/kernel/sound/soc/bcm/snd-soc-seeed-voicecard.ko || true -rm /lib/modules/*/updates/dkms/snd-soc-wm8960.ko || true -rm /lib/modules/*/updates/dkms/snd-soc-ac108.ko || true -rm /lib/modules/*/updates/dkms/snd-soc-seeed-voicecard.ko || true +echo -e "\n### Remove kernel modules" +rm -v /lib/modules/*/kernel/sound/soc/codecs/snd-soc-wm8960.ko || true +rm -v /lib/modules/*/kernel/sound/soc/codecs/snd-soc-ac108.ko || true +rm -v /lib/modules/*/kernel/sound/soc/bcm/snd-soc-seeed-voicecard.ko || true +rm -v /lib/modules/*/updates/dkms/snd-soc-wm8960.ko || true +rm -v /lib/modules/*/updates/dkms/snd-soc-ac108.ko || true +rm -v /lib/modules/*/updates/dkms/snd-soc-seeed-voicecard.ko || true -echo "remove $CONFIG configuration" +echo -e "\n### Remove $CONFIG configuration" for i in $RPI_HATS; do echo Uninstall $i ... do_overlay $i 1 From 7e635f5d5714ed347b0a1a955b202ddd6f96a542 Mon Sep 17 00:00:00 2001 From: turmary Date: Mon, 28 Sep 2020 18:03:18 +0800 Subject: [PATCH 2/9] Remove: debug only or wrong widget --- ac101.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ac101.c b/ac101.c index 92b2583..2499bc1 100644 --- a/ac101.c +++ b/ac101.c @@ -772,16 +772,18 @@ static int snd_ac101_put_volsw(struct snd_kcontrol *kcontrol, static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -11925, 75, 0); +/* static const DECLARE_TLV_DB_SCALE(dac_mix_vol_tlv, -600, 600, 0); static const DECLARE_TLV_DB_SCALE(dig_vol_tlv, -7308, 116, 0); +*/ static const DECLARE_TLV_DB_SCALE(speaker_vol_tlv, -4800, 150, 0); static const DECLARE_TLV_DB_SCALE(headphone_vol_tlv, -6300, 100, 0); static struct snd_kcontrol_new ac101_controls[] = { /*DAC*/ SOC_DOUBLE_TLV("DAC volume", DAC_VOL_CTRL, DAC_VOL_L, DAC_VOL_R, 0xff, 0, dac_vol_tlv), - SOC_DOUBLE_TLV("DAC mixer gain", DAC_MXR_GAIN, DACL_MXR_GAIN, DACR_MXR_GAIN, 0xf, 0, dac_mix_vol_tlv), - SOC_SINGLE_TLV("digital volume", DAC_DBG_CTRL, DVC, 0x3f, 1, dig_vol_tlv), + /* SOC_DOUBLE_TLV("DAC Mix Gain", DAC_MXR_GAIN, DACL_MXR_GAIN, DACR_MXR_GAIN, 0xf, 0, dac_mix_vol_tlv), */ + /* SOC_SINGLE_TLV("DAC Debug Volume", DAC_DBG_CTRL, DVC, 0x3f, 1, dig_vol_tlv), */ SOC_SINGLE_TLV("speaker volume", SPKOUT_CTRL, SPK_VOL, 0x1f, 0, speaker_vol_tlv), SOC_SINGLE_TLV("headphone volume", HPOUT_CTRL, HP_VOL, 0x3f, 0, headphone_vol_tlv), }; From 1a7fbee50e7382463b17f31bac2249ceace5e627 Mon Sep 17 00:00:00 2001 From: turmary Date: Mon, 28 Sep 2020 18:04:40 +0800 Subject: [PATCH 3/9] Move: volume widget name to ALSA tradition style --- ac101.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ac101.c b/ac101.c index 2499bc1..eaa8831 100644 --- a/ac101.c +++ b/ac101.c @@ -781,11 +781,11 @@ static const DECLARE_TLV_DB_SCALE(headphone_vol_tlv, -6300, 100, 0); static struct snd_kcontrol_new ac101_controls[] = { /*DAC*/ - SOC_DOUBLE_TLV("DAC volume", DAC_VOL_CTRL, DAC_VOL_L, DAC_VOL_R, 0xff, 0, dac_vol_tlv), + SOC_DOUBLE_TLV("DAC Playback Volume", DAC_VOL_CTRL, DAC_VOL_L, DAC_VOL_R, 0xff, 0, dac_vol_tlv), /* SOC_DOUBLE_TLV("DAC Mix Gain", DAC_MXR_GAIN, DACL_MXR_GAIN, DACR_MXR_GAIN, 0xf, 0, dac_mix_vol_tlv), */ /* SOC_SINGLE_TLV("DAC Debug Volume", DAC_DBG_CTRL, DVC, 0x3f, 1, dig_vol_tlv), */ - SOC_SINGLE_TLV("speaker volume", SPKOUT_CTRL, SPK_VOL, 0x1f, 0, speaker_vol_tlv), - SOC_SINGLE_TLV("headphone volume", HPOUT_CTRL, HP_VOL, 0x3f, 0, headphone_vol_tlv), + SOC_SINGLE_TLV("Speaker Playback Volume", SPKOUT_CTRL, SPK_VOL, 0x1f, 0, speaker_vol_tlv), + SOC_SINGLE_TLV("Headphone Playback Volume", HPOUT_CTRL, HP_VOL, 0x3f, 0, headphone_vol_tlv), }; /* PLL divisors */ From 06e054aa06241d7cbd8999409fc3d68f1ab53063 Mon Sep 17 00:00:00 2001 From: turmary Date: Mon, 28 Sep 2020 18:14:32 +0800 Subject: [PATCH 4/9] Move: volume name in state configuration --- ac108_6mic.state | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) diff --git a/ac108_6mic.state b/ac108_6mic.state index bdbe64a..0920cdb 100644 --- a/ac108_6mic.state +++ b/ac108_6mic.state @@ -292,7 +292,7 @@ state.seeed8micvoicec { } control.17 { iface MIXER - name 'DAC volume' + name 'DAC Playback Volume' value.0 0 value.1 0 comment { @@ -308,37 +308,7 @@ state.seeed8micvoicec { } control.18 { iface MIXER - name 'DAC mixer gain' - value.0 0 - value.1 0 - comment { - access 'read write' - type INTEGER - count 2 - range '0 - 15' - dbmin -600 - dbmax 8400 - dbvalue.0 -600 - dbvalue.1 -600 - } - } - control.19 { - iface MIXER - name 'digital volume' - value 51 - comment { - access 'read write' - type INTEGER - count 1 - range '0 - 63' - dbmin -7308 - dbmax 0 - dbvalue.0 -1392 - } - } - control.20 { - iface MIXER - name 'speaker volume' + name 'Speaker Playback Volume' value 25 comment { access 'read write' @@ -350,9 +320,9 @@ state.seeed8micvoicec { dbvalue.0 -1050 } } - control.21 { + control.19 { iface MIXER - name 'headphone volume' + name 'Headphone Playback Volume' value 52 comment { access 'read write' From 6fb0c63581b502fb97580a0e7a6693db0c25394e Mon Sep 17 00:00:00 2001 From: turmary Date: Tue, 29 Sep 2020 11:06:23 +0800 Subject: [PATCH 5/9] Add: unload codec driver when uninstall --- uninstall.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/uninstall.sh b/uninstall.sh index b1292fc..56e5415 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -79,6 +79,11 @@ rm -v /lib/systemd/system/seeed-voicecard.service || true echo -e "\n### Remove dkms" rm -rfv /var/lib/dkms/seeed-voicecard || true +echo -e "\n### Unload codec driver by modprobe -r" +modprobe -r snd_soc_ac108 +modprobe -r snd_soc_wm8960 +modprobe -r snd_soc_seeed_voicecard + echo -e "\n### Remove kernel modules" rm -v /lib/modules/*/kernel/sound/soc/codecs/snd-soc-wm8960.ko || true rm -v /lib/modules/*/kernel/sound/soc/codecs/snd-soc-ac108.ko || true From 526d0ddef93d7109f96cce41121ba9bed295a8e8 Mon Sep 17 00:00:00 2001 From: turmary Date: Tue, 29 Sep 2020 11:07:29 +0800 Subject: [PATCH 6/9] Add: error message if old kernel package install failed --- install.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index fad8cbf..4e76a45 100755 --- a/install.sh +++ b/install.sh @@ -192,8 +192,12 @@ function install_kernel() { _url=$(apt-get download --print-uris raspberrypi-kernel | sed -nre "s/'([^']+)'.*$/\1/g;p") _prefix=$(echo $_url | sed -nre 's/^(.*)raspberrypi-kernel_.*$/\1/g;p') - download_install_debpkg "$_prefix" "$KERN_NAME" - download_install_debpkg "$_prefix" "$HDR_NAME" + download_install_debpkg "$_prefix" "$KERN_NAME" && { + download_install_debpkg "$_prefix" "$HDR_NAME" + } || { + echo "Error: Install kernel or header failed" + exit 2 + } } } @@ -270,7 +274,7 @@ cp -v seeed-8mic-voicecard.dtbo $OVERLAYS rm -f /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so #set kernel modules -echo -e "\n### Install startup modules in /etc/modules" +echo -e "\n### Codec driver loading at startup (in /etc/modules)" grep -q "^snd-soc-seeed-voicecard$" /etc/modules || \ echo "snd-soc-seeed-voicecard" >> /etc/modules grep -q "^snd-soc-ac108$" /etc/modules || \ From ac2bf5f638e470c60b812b20af54b296aab8ab27 Mon Sep 17 00:00:00 2001 From: turmary Date: Wed, 30 Sep 2020 10:39:23 +0800 Subject: [PATCH 7/9] Move: dkms module removing to the position before kernel update --- install.sh | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/install.sh b/install.sh index 4e76a45..ac6ebc7 100755 --- a/install.sh +++ b/install.sh @@ -201,11 +201,34 @@ function install_kernel() { } } +function uninstall_module { + src=$1 + mod=$2 + + if [[ -d /var/lib/dkms/$mod/$ver/$marker ]]; then + rmdir /var/lib/dkms/$mod/$ver/$marker + fi + + if [[ -e /usr/src/$mod-$ver || -e /var/lib/dkms/$mod/$ver ]]; then + dkms remove --force -m $mod -v $ver --all + rm -rf /usr/src/$mod-$ver + fi + + return 0 +} + # update and install required packages -which apt &>/dev/null -if [[ $? -eq 0 ]]; then +which apt &>/dev/null; r=$? +if [[ $r -eq 0 ]]; then + echo -e "\n### Install required tool packages" apt update -y apt-get -y install dkms git i2c-tools libasound2-plugins +fi + +echo -e "\n### Uninstall previous dkms module" +uninstall_module "./" "seeed-voicecard" + +if [[ $r -eq 0 ]]; then echo -e "\n### Install required kernel package" install_kernel # rpi-update checker @@ -232,15 +255,6 @@ function install_module { src=$1 mod=$2 - if [[ -d /var/lib/dkms/$mod/$ver/$marker ]]; then - rmdir /var/lib/dkms/$mod/$ver/$marker - fi - - if [[ -e /usr/src/$mod-$ver || -e /var/lib/dkms/$mod/$ver ]]; then - dkms remove --force -m $mod -v $ver --all - rm -rf /usr/src/$mod-$ver - fi - mkdir -p /usr/src/$mod-$ver cp -a $src/* /usr/src/$mod-$ver/ @@ -261,7 +275,6 @@ function install_module { echo -e "\n### Install sound card driver" install_module "./" "seeed-voicecard" - # install dtbos echo -e "\n### Install device tree overlays" cp -v seeed-2mic-voicecard.dtbo $OVERLAYS From 8cce4e8ffa77e1e2b89812e5e2ccf6cfbc1086cf Mon Sep 17 00:00:00 2001 From: turmary Date: Wed, 30 Sep 2020 15:04:47 +0800 Subject: [PATCH 8/9] Add: document about "query sound card number" --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index dcd158e..e884227 100644 --- a/README.md +++ b/README.md @@ -196,7 +196,22 @@ plughw:CARD=seeed8micvoicec,DEV=0 In contrast to 6-Mics Circular Array Kit for Raspberry Pi, the difference is only first 4 input channels are valid capture data. + ### Usage: + +```bash +#Query sound card number +# The sound card number used as arecord/aplay argument, +# ( like '-D hw:N' and '-D plughw:N', where N is the number ) +# could be found by command: + aplay -l +#or + arecord -l +# Find the line in the command output which near below form: +card 1: seeed2micvoicec [seeed-2mic-voicecard], device 0: ... +# The number between first word `card` and char `:` is the Sound Card Number, here it's 1. +``` + ```bash #for ReSpeaker 2-mic #It will capture sound an playback on hw:1 From 87f42ed64dcf6f218b6f0a3d582e94ddf01f9bbc Mon Sep 17 00:00:00 2001 From: turmary Date: Wed, 30 Sep 2020 15:04:47 +0800 Subject: [PATCH 9/9] Add: document about "query sound card number" --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index dcd158e..e884227 100644 --- a/README.md +++ b/README.md @@ -196,7 +196,22 @@ plughw:CARD=seeed8micvoicec,DEV=0 In contrast to 6-Mics Circular Array Kit for Raspberry Pi, the difference is only first 4 input channels are valid capture data. + ### Usage: + +```bash +#Query sound card number +# The sound card number used as arecord/aplay argument, +# ( like '-D hw:N' and '-D plughw:N', where N is the number ) +# could be found by command: + aplay -l +#or + arecord -l +# Find the line in the command output which near below form: +card 1: seeed2micvoicec [seeed-2mic-voicecard], device 0: ... +# The number between first word `card` and char `:` is the Sound Card Number, here it's 1. +``` + ```bash #for ReSpeaker 2-mic #It will capture sound an playback on hw:1