Merge tracking branch 'install' to probe drivers by appliation.

This commit is contained in:
peter.yang 2018-02-10 15:18:47 +08:00
commit 1c1643003f
7 changed files with 153 additions and 155 deletions

View file

@ -4,22 +4,21 @@
The drivers of [ReSpeaker Mic Hat](https://www.seeedstudio.com/ReSpeaker-2-Mics-Pi-HAT-p-2874.html) and [ReSpeaker 4 Mic Array](https://www.seeedstudio.com/ReSpeaker-4-Mic-Array-for-Raspberry-Pi-p-2941.html) for Raspberry Pi. The drivers of [ReSpeaker Mic Hat](https://www.seeedstudio.com/ReSpeaker-2-Mics-Pi-HAT-p-2874.html) and [ReSpeaker 4 Mic Array](https://www.seeedstudio.com/ReSpeaker-4-Mic-Array-for-Raspberry-Pi-p-2941.html) for Raspberry Pi.
### Install seeed-voicecard
Get the seeed voice card source code. and install all linux kernel drivers
```bash
git clone https://github.com/respeaker/seeed-voicecard
cd seeed-voicecard
sudo ./install.sh
sudo reboot
```
## ReSpeaker Mic Hat ## ReSpeaker Mic Hat
[![](https://github.com/SeeedDocument/MIC_HATv1.0_for_raspberrypi/blob/master/img/mic_hatv1.0.png?raw=true)](https://www.seeedstudio.com/ReSpeaker-2-Mics-Pi-HAT-p-2874.html) [![](https://github.com/SeeedDocument/MIC_HATv1.0_for_raspberrypi/blob/master/img/mic_hatv1.0.png?raw=true)](https://www.seeedstudio.com/ReSpeaker-2-Mics-Pi-HAT-p-2874.html)
While the upstream wm8960 codec is not currently supported by current Pi kernel builds, upstream wm8960 has some bugs, we had fixed it. we must it build manually. While the upstream wm8960 codec is not currently supported by current Pi kernel builds, upstream wm8960 has some bugs, we had fixed it. we must it build manually.
Get the seeed voice card source code.
```bash
git clone https://github.com/respeaker/seeed-voicecard
cd seeed-voicecard
#for ReSpeaker 2-mic
sudo ./install.sh 2mic
sudo reboot
```
Check that the sound card name matches the source code seeed-voicecard. Check that the sound card name matches the source code seeed-voicecard.
```bash ```bash
@ -49,6 +48,9 @@ card 1: seeed2micvoicec [seeed-2mic-voicecard], device 0: bcm2835-i2s-wm8960-hif
Subdevice #0: subdevice #0 Subdevice #0: subdevice #0
pi@raspberrypi:~/seeed-voicecard $ pi@raspberrypi:~/seeed-voicecard $
``` ```
If you want to change the alsa settings, You can use `sudo alsactl --file=/etc/voicecard/wm8960_asound.state store` to save it.
#### Next step #### Next step
Go to https://github.com/respeaker/mic_hat to build voice enabled projects with Google Assistant SDK or Alexa Voice Service. Go to https://github.com/respeaker/mic_hat to build voice enabled projects with Google Assistant SDK or Alexa Voice Service.
@ -59,15 +61,6 @@ Go to https://github.com/respeaker/mic_hat to build voice enabled projects with
The 4 Mic Array uses ac108 which includes 4 ADCs, we also write ac108 rapberry pi linux kernel driver. The 4 Mic Array uses ac108 which includes 4 ADCs, we also write ac108 rapberry pi linux kernel driver.
```bash
git clone https://github.com/respeaker/seeed-voicecard
cd seeed-voicecard
sudo ./install.sh 4mic
#reboot your Raspbian OS
sudo reboot
```
Check that the sound card name matches the source code seeed-voicecard. Check that the sound card name matches the source code seeed-voicecard.
```bash ```bash
@ -100,9 +93,9 @@ plughw:CARD=seeed4micvoicec,DEV=0
Hardware device with all software conversions Hardware device with all software conversions
pi@raspberrypi:~ $ pi@raspberrypi:~ $
``` ```
If you want to change the alsa settings, You can use `sudo alsactl --file=asound.state store` to save it. If you want to change the alsa settings, You can use `sudo alsactl --file=/etc/voicecard/ac108_asound.state store` to save it.
Test: #### Test:
```bash ```bash
#for ReSpeaker 2-mic #for ReSpeaker 2-mic
#It will capture sound an playback on hw:1 #It will capture sound an playback on hw:1
@ -118,32 +111,15 @@ arecord -Dac108 -f S32_LE -r 16000 -c 4 a.wav
If you want to upgrade the driver , you need uninstall the driver first. If you want to upgrade the driver , you need uninstall the driver first.
``` ```
pi@raspberrypi:~/seeed-voicecard $ sudo ./uninstall.sh 4mic pi@raspberrypi:~/seeed-voicecard $ sudo ./uninstall.sh
delete dtoverlay=seeed-4mic-voicecard in /boot/config.txt ...
delete snd-soc-ac108 in /etc/modules
------------------------------------------------------
Please reboot your raspberry pi to apply all settings
Thank you!
------------------------------------------------------
pi@raspberrypi:~/seeed-voicecard $ sudo ./uninstall.sh 2mic
delete dtoverlay=seeed-2mic-voicecard in /boot/config.txt
remove seeed-2mic-voicecard.dtbo in /boot/overlays
remove snd-soc-wm8960.ko
delete snd-soc-wm8960 in /etc/modules
------------------------------------------------------ ------------------------------------------------------
Please reboot your raspberry pi to apply all settings Please reboot your raspberry pi to apply all settings
Thank you! Thank you!
------------------------------------------------------ ------------------------------------------------------
``` ```
### with Google Assistant
if you run the assistant but the playback is speed up considerably, try to configure alsa:
```bash
sudo cp asound.conf /etc/asound.conf
```
If the alsa configuration doesn't solve the issue, try to use pulseaudio. See [#4](https://github.com/respeaker/seeed-voicecard/issues/4)
Enjoy ! Enjoy !

View file

@ -9,7 +9,7 @@ pcm.!default {
pcm.playback { pcm.playback {
type plug type plug
slave.pcm "dmixed" slave.pcm "hw:0,0"
} }

View file

@ -1,5 +1,5 @@
PACKAGE_NAME="seeed-voicecard" PACKAGE_NAME="seeed-voicecard"
PACKAGE_VERSION="0.2" PACKAGE_VERSION="0.3"
BUILT_MODULE_NAME[0]="snd-soc-wm8960" BUILT_MODULE_NAME[0]="snd-soc-wm8960"
BUILT_MODULE_NAME[1]="snd-soc-ac108" BUILT_MODULE_NAME[1]="snd-soc-ac108"
BUILT_MODULE_NAME[2]="snd-soc-simple-card" BUILT_MODULE_NAME[2]="snd-soc-simple-card"

View file

@ -11,13 +11,8 @@ if [ "x${is_Raspberry}" != "xRaspberry" ] ; then
exit 1 exit 1
fi fi
ver="0.2" ver="0.3"
card=$1
if [ "x${card}" = "x" ] ; then
echo "Usage: ./install 2mic|4mic"
exit 1
fi
# we create a dir with this version to ensure that 'dkms remove' won't delete # we create a dir with this version to ensure that 'dkms remove' won't delete
# the sources during kernel updates # the sources during kernel updates
@ -51,21 +46,25 @@ function install_module {
mkdir -p /var/lib/dkms/$mod/$ver/$marker mkdir -p /var/lib/dkms/$mod/$ver/$marker
} }
if [ ! -f "/boot/overlays/seeed-4mic-voicecard.dtbo" ] && [ ! -f "/lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-ac108.ko" ] ; then
install_module "./" "seeed-voicecard" install_module "./" "seeed-voicecard"
# install dtbos
cp seeed-2mic-voicecard.dtbo /boot/overlays cp seeed-2mic-voicecard.dtbo /boot/overlays
cp seeed-4mic-voicecard.dtbo /boot/overlays cp seeed-4mic-voicecard.dtbo /boot/overlays
install -D ac108_plugin/libasound_module_pcm_ac108.so /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so
else
echo "card driver already installed"
fi
#install alsa plugins
install -D ac108_plugin/libasound_module_pcm_ac108.so /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so
#set kernel moduels
grep -q "snd-soc-ac108" /etc/modules || \ grep -q "snd-soc-ac108" /etc/modules || \
echo "snd-soc-ac108" >> /etc/modules echo "snd-soc-ac108" >> /etc/modules
grep -q "snd-soc-wm8960" /etc/modules || \ grep -q "snd-soc-wm8960" /etc/modules || \
echo "snd-soc-wm8960" >> /etc/modules echo "snd-soc-wm8960" >> /etc/modules
#set dtoverlays
sed -i -e 's:#dtparam=i2c_arm=on:dtparam=i2c_arm=on:g' /boot/config.txt || true
grep -q "dtoverlay=i2s-mmap" /boot/config.txt || \ grep -q "dtoverlay=i2s-mmap" /boot/config.txt || \
echo "dtoverlay=i2s-mmap" >> /boot/config.txt echo "dtoverlay=i2s-mmap" >> /boot/config.txt
@ -73,36 +72,15 @@ grep -q "dtoverlay=i2s-mmap" /boot/config.txt || \
grep -q "dtparam=i2s=on" /boot/config.txt || \ grep -q "dtparam=i2s=on" /boot/config.txt || \
echo "dtparam=i2s=on" >> /boot/config.txt echo "dtparam=i2s=on" >> /boot/config.txt
has_2mic=$(grep seeed-2mic-voicecard /boot/config.txt) #install config files
has_4mic=$(grep seeed-4mic-voicecard /boot/config.txt) mkdir /etc/voicecard || true
case "${card}" in cp *.conf /etc/voicecard
"2mic") cp *.state /etc/voicecard
echo "cp wm8960_asound.state /var/lib/alsa/asound.state"
cp wm8960_asound.state /var/lib/alsa/asound.state
cp asound_2mic.conf /etc/asound.conf
if [ "x${has_4mic}" != x ] ; then
echo "has 4mic before, now remove it"
sed -i "s/dtoverlay=seeed-4mic-voicecard//g" /boot/config.txt
fi
grep -q "dtoverlay=seeed-2mic-voicecard" /boot/config.txt || \
echo "dtoverlay=seeed-2mic-voicecard" >> /boot/config.txt
;;
"4mic") cp seeed-voicecard /usr/bin/
echo "cp ac108_asound.state /var/lib/alsa/asound.state" cp seeed-voicecard.service /lib/systemd/system/
cp ac108_asound.state /var/lib/alsa/asound.state systemctl enable seeed-voicecard.service
cp asound_4mic.conf /etc/asound.conf
if [ "x${has_2mic}" != x ] ; then
echo "has 2mic before, now remove it"
sed -i "s/dtoverlay=seeed-2mic-voicecard//g" /boot/config.txt
fi
grep -q "dtoverlay=seeed-4mic-voicecard" /boot/config.txt || \
echo "dtoverlay=seeed-4mic-voicecard" >> /boot/config.txt
;;
*)
echo "Please use 2mic or 4mic"
;;
esac
echo "------------------------------------------------------" echo "------------------------------------------------------"
echo "Please reboot your raspberry pi to apply all settings" echo "Please reboot your raspberry pi to apply all settings"

84
seeed-voicecard Executable file
View file

@ -0,0 +1,84 @@
#!/bin/bash
#
# Copyright (c) 2018 Baozhu Zuo <zuobaozhu@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
is_1a=$(i2cdetect -y 1 0x1a 0x1a | grep 1a | awk '{print $2}')
is_35=$(i2cdetect -y 1 0x35 0x35 | grep 35 | awk '{print $2}')
is_3b=$(i2cdetect -y 1 0x3b 0x3b | grep 3b | awk '{print $2}')
if [ "x${is_1a}" == "x1a" ] && [ "x${is_35}" == "x" ] ; then
echo "install 2mic"
dtoverlay seeed-2mic-voicecard
sleep 1
hw=$(aplay -l | grep seeed2micvoicec | awk '{print $2}' | sed 's/://')
cp /etc/voicecard/asound_2mic.conf /etc/asound.conf
echo "get old hw number"
old=$(cat /etc/asound.conf | grep hw: | awk 'NR==1 {print $2}' | sed 's/\"//g')
echo "replace new hw:${hw},0"
sed -i -e "s/${old}/hw:${hw},0/g" /etc/asound.conf
cp /etc/voicecard/wm8960_asound.state /var/lib/alsa/asound.state
fi
if [ "x${is_3b}" == "x3b" ] && [ "x${is_35}" == "x" ] ; then
echo "install 4mic"
dtoverlay seeed-4mic-voicecard
sleep 1
hw=$(arecord -l | grep seeed4micvoicec | awk '{print $2}' | sed 's/://')
cp /etc/voicecard/asound_4mic.conf /etc/asound.conf
echo "get slavepcm line number"
line=$(grep -n slavepcm /etc/asound.conf | awk '{print $1}' | sed 's/://')
echo "delete ${line} slavepcm hw number"
sed -i -e "${line}d" /etc/asound.conf
echo "inset slavepcm hw:${hw},0"
sed -i "${line}i slavepcm \"hw:${hw},0\"" /etc/asound.conf
cp /etc/voicecard/ac108_asound.state /var/lib/alsa/asound.state
fi
if [ "x${is_3b}" == "x3b" ] && [ "x${is_35}" == "x35" ] ; then
echo "install 6mic"
dtoverlay seeed-8mic-voicecard
sleep 1
hw=$(aplay -l | grep seeed8micvoicec | awk '{print $2}' | sed 's/://')
cp /etc/voicecard/asound_6mic.conf /etc/asound.conf
old=$(cat /etc/asound.conf | grep hw: | awk 'NR==1 {print $2}' | sed 's/\"//g')
sed -i -e "s/${old}/hw:${hw},0/g" /etc/asound.conf
cp /etc/voicecard/ac101-ok-20180119.state /var/lib/alsa/asound.state
fi
alsactl restore
#Fore 3.5mm ('headphone') jack
amixer cset numid=3 1

12
seeed-voicecard.service Normal file
View file

@ -0,0 +1,12 @@
[Unit]
Description=Seeed Voicecard service
After=alsa-restore.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/seeed-voicecard
User=root
[Install]
WantedBy=sysinit.target

View file

@ -12,81 +12,29 @@ if [ "x${is_Raspberry}" != "xRaspberry" ] ; then
fi fi
uname_r=$(uname -r) uname_r=$(uname -r)
card=$1
if [ x${card} = "x" ] ; then
echo "Usage: ./uninstall 2mic|4mic"
exit 1
fi
if [ x${card} = "x2mic" ] ; then
echo "delete dtoverlay=seeed-2mic-voicecard in /boot/config.txt"
sed -i "s/dtoverlay=seeed-2mic-voicecard//g" /boot/config.txt
if [ -f /boot/overlays/seeed-2mic-voicecard.dtbo ] ; then
echo "remove seeed-2mic-voicecard.dtbo in /boot/overlays"
rm /boot/overlays/seeed-2mic-voicecard.dtbo
fi
if [ -f /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-wm8960.ko ] ; then echo "remove dtbos"
echo "remove snd-soc-wm8960.ko" rm /boot/overlays/seeed-2mic-voicecard.dtbo || true
rm /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-wm8960.ko rm /boot/overlays/seeed-4mic-voicecard.dtbo || true
fi rm /boot/overlays/seeed-6mic-voicecard.dtbo || true
if [ -d /var/lib/dkms/seeed-voicecard ] ; then echo "remove alsa configs"
echo "remove seeed-voicecard dkms" rm -rf /etc/voicecard/ || true
rm -rf /var/lib/dkms/seeed-voicecard
fi
echo "delete snd-soc-wm8960 in /etc/modules" echo "disabled seeed-voicecard.service "
sed -i "s/snd-soc-wm8960//g" /etc/modules systemctl disable seeed-voicecard.service
if [ -f /var/lib/alsa/asound.state ] ; then echo "remove seeed-vocecard"
echo "remove wm8960_asound.state" rm /usr/bin/seeed-voicecard || true
rm /var/lib/alsa/asound.state rm /lib/systemd/system/seeed-voicecard.service || true
fi
if [ -f /etc/asound.conf ] ; then echo "remove dkms"
echo "remove asound_2mic.conf" rm -rf /var/lib/dkms/seeed-voicecard || true
rm /etc/asound.conf
fi
fi
if [ x${card} = "x4mic" ] ; then echo "remove kernel modules"
echo "delete dtoverlay=seeed-4mic-voicecard in /boot/config.txt" rm /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-wm8960.ko || true
sed -i "s/dtoverlay=seeed-4mic-voicecard//g" /boot/config.txt rm /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-ac108.ko || true
if [ -f /boot/overlays/seeed-4mic-voicecard.dtbo ] ; then
echo "remove seeed-4mic-voicecard.dtbo in /boot/overlays"
rm /boot/overlays/seeed-4mic-voicecard.dtbo
fi
if [ -f /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-ac108.ko ] ; then
echo "remove snd-soc-ac108.ko"
rm /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-ac108.ko
fi
if [ -d /var/lib/dkms/seeed-voicecard ] ; then
echo "remove seeed-voicecard dkms"
rm -rf /var/lib/dkms/seeed-voicecard
fi
echo "delete snd-soc-ac108 in /etc/modules"
sed -i "s/snd-soc-ac108//g" /etc/modules
if [ -f /var/lib/alsa/asound.state ] ; then
echo "remove ac108_asound.state"
rm /var/lib/alsa/asound.state
fi
if [ -f /etc/asound.conf ] ; then
echo "remove asound_4mic.conf"
rm /etc/asound.conf
fi
if [ -f /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so ] ; then
echo "remove libasound_module_pcm_ac108.so in /usr/lib/arm-linux-gnueabihf/alsa-lib/ "
rm /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so
fi
fi
echo "------------------------------------------------------" echo "------------------------------------------------------"
echo "Please reboot your raspberry pi to apply all settings" echo "Please reboot your raspberry pi to apply all settings"