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.
### 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
[![](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.
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.
```bash
@ -49,6 +48,9 @@ card 1: seeed2micvoicec [seeed-2mic-voicecard], device 0: bcm2835-i2s-wm8960-hif
Subdevice #0: subdevice #0
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
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.
```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.
```bash
@ -100,9 +93,9 @@ plughw:CARD=seeed4micvoicec,DEV=0
Hardware device with all software conversions
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
#for ReSpeaker 2-mic
#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.
```
pi@raspberrypi:~/seeed-voicecard $ sudo ./uninstall.sh 4mic
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
pi@raspberrypi:~/seeed-voicecard $ sudo ./uninstall.sh
...
------------------------------------------------------
Please reboot your raspberry pi to apply all settings
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 !

View file

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

View file

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

View file

@ -11,13 +11,8 @@ if [ "x${is_Raspberry}" != "xRaspberry" ] ; then
exit 1
fi
ver="0.2"
card=$1
ver="0.3"
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
# the sources during kernel updates
@ -51,21 +46,25 @@ function install_module {
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 dtbos
cp seeed-2mic-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 || \
echo "snd-soc-ac108" >> /etc/modules
grep -q "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 || \
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 || \
echo "dtparam=i2s=on" >> /boot/config.txt
has_2mic=$(grep seeed-2mic-voicecard /boot/config.txt)
has_4mic=$(grep seeed-4mic-voicecard /boot/config.txt)
case "${card}" in
"2mic")
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
#install config files
mkdir /etc/voicecard || true
cp *.conf /etc/voicecard
cp *.state /etc/voicecard
;;
"4mic")
echo "cp ac108_asound.state /var/lib/alsa/asound.state"
cp ac108_asound.state /var/lib/alsa/asound.state
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
cp seeed-voicecard /usr/bin/
cp seeed-voicecard.service /lib/systemd/system/
systemctl enable seeed-voicecard.service
echo "------------------------------------------------------"
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
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 snd-soc-wm8960.ko"
rm /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-wm8960.ko
fi
echo "remove dtbos"
rm /boot/overlays/seeed-2mic-voicecard.dtbo || true
rm /boot/overlays/seeed-4mic-voicecard.dtbo || true
rm /boot/overlays/seeed-6mic-voicecard.dtbo || true
if [ -d /var/lib/dkms/seeed-voicecard ] ; then
echo "remove seeed-voicecard dkms"
rm -rf /var/lib/dkms/seeed-voicecard
fi
echo "remove alsa configs"
rm -rf /etc/voicecard/ || true
echo "delete snd-soc-wm8960 in /etc/modules"
sed -i "s/snd-soc-wm8960//g" /etc/modules
echo "disabled seeed-voicecard.service "
systemctl disable seeed-voicecard.service
if [ -f /var/lib/alsa/asound.state ] ; then
echo "remove wm8960_asound.state"
rm /var/lib/alsa/asound.state
fi
echo "remove seeed-vocecard"
rm /usr/bin/seeed-voicecard || true
rm /lib/systemd/system/seeed-voicecard.service || true
if [ -f /etc/asound.conf ] ; then
echo "remove asound_2mic.conf"
rm /etc/asound.conf
fi
fi
echo "remove dkms"
rm -rf /var/lib/dkms/seeed-voicecard || true
if [ x${card} = "x4mic" ] ; then
echo "delete dtoverlay=seeed-4mic-voicecard in /boot/config.txt"
sed -i "s/dtoverlay=seeed-4mic-voicecard//g" /boot/config.txt
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 "remove kernel modules"
rm /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-wm8960.ko || true
rm /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-ac108.ko || true
echo "------------------------------------------------------"
echo "Please reboot your raspberry pi to apply all settings"