[RPI] Switch to function based i2csound system
Many thanks to @BohdanBuinich https://github.com/OpenVoiceOS/raspOVOS/pull/113
This commit is contained in:
parent
3dfb784cc1
commit
3face078ca
|
@ -15,58 +15,55 @@
|
|||
# limitations under the License.
|
||||
##########################################################################
|
||||
|
||||
# Scanning the I2C bus for know addresses
|
||||
is_1a=$(i2cdetect -y 1 0x1a 0x1a | grep -E "(1a|UU)" | awk '{print $2}') # WM8xxx based
|
||||
if [ "${is_1a}" == "1a" ] || [ "${is_1a}" == "UU" ] ; then
|
||||
echo "WM8xxx based HAT found"
|
||||
# Define a list of device names and their I2C addresses
|
||||
declare -A devices=(
|
||||
[WM8XXX]=1a
|
||||
[RESPEAKER4]=3b
|
||||
[RESPEAKER6]=35
|
||||
[ADAFRUIT]=4b
|
||||
[TAS5806]=2f
|
||||
[SJ201LED]=04
|
||||
[AIYVOICEBONNET]=52
|
||||
)
|
||||
|
||||
declare -A detection_results
|
||||
|
||||
# Detects the presence of an I2C device at the specified address range
|
||||
detect_i2c_device() {
|
||||
local address="0x$1"
|
||||
if i2cdetect -y -a 1 "$address" "$address" | grep -qE "($1|UU)"; then
|
||||
return 0 # true
|
||||
else
|
||||
return 1 # false
|
||||
fi
|
||||
}
|
||||
|
||||
# Main execution
|
||||
main() {
|
||||
# Detecting I2C devices
|
||||
for device in "${!devices[@]}"; do
|
||||
address="${devices[$device]}"
|
||||
if detect_i2c_device "$address"; then
|
||||
detection_results[$device]=true
|
||||
else
|
||||
detection_results[$device]=false
|
||||
fi
|
||||
echo "$device detection result: ${detection_results[$device]}"
|
||||
done
|
||||
|
||||
# Handling hardware-specific configurations
|
||||
if [[ ${detection_results[WM8XXX]} == true ]] ; then
|
||||
echo "WM8XXX based HAT found"
|
||||
atmega328p=$(avrdude -p atmega328p -C /etc/avrdude-gpio.conf -c linuxgpio -U signature:r:-:i -F 2>/dev/null | head -n1)
|
||||
if [ "${atmega328p}" == ":030000001E950F3B" ] ; then
|
||||
MARK1=found
|
||||
detection_results[MARK1]=true
|
||||
echo "Mark-1 enclosure $MARK1"
|
||||
else
|
||||
WM8960=found
|
||||
echo "WM8960 based 2-mic $WM8960"
|
||||
echo "WM8960 based 2-mic $WM8XXX"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
is_35=$(i2cdetect -y 1 0x35 0x35 | grep -E "(35|UU)" | awk '{print $2}') # ReSpeaker 4-mic squared
|
||||
if [ "${is_35}" == "35" ] || [ "${is_35}" == "UU" ] ; then
|
||||
RESPEAKER4=found
|
||||
echo "ReSpeaker 4-mic $RESPEAKER4"
|
||||
fi
|
||||
|
||||
is_3b=$(i2cdetect -y 1 0x3b 0x3b | grep -E "(3b|UU)" | awk '{print $2}') # ReSpeaker 4-mic lineair / 6-mic
|
||||
if [ "${is_3b}" == "3b" ] || [ "${is_3b}" == "UU" ] ; then
|
||||
RESPEAKER6=found
|
||||
echo "ReSpeaker 6-mic $RESPEAKER6"
|
||||
fi
|
||||
|
||||
is_4b=$(i2cdetect -y 1 0x4b 0x4b | grep -E "(4b|UU)" | awk '{print $2}') # Adafruit
|
||||
if [ "${is_4b}" == "4b" ] || [ "${is_4b}" == "UU" ] ; then
|
||||
ADAFRUIT=found
|
||||
echo "Adafruit $ADAFRUIT"
|
||||
fi
|
||||
|
||||
is_2f=$(i2cdetect -y 1 0x2c 0x2c | grep -E "(2c|UU)" | awk '{print $2}') # TAS5806
|
||||
if [ "${is_2c}" == "2c" ] || [ "${is_2c}" == "UU" ] ; then
|
||||
XMOS=found
|
||||
echo "XMOS Chip $XMOS"
|
||||
fi
|
||||
|
||||
is_2f=$(i2cdetect -y 1 0x2f 0x2f | grep -E "(2f|UU)" | awk '{print $2}') # TAS5806
|
||||
if [ "${is_2f}" == "2f" ] || [ "${is_2f}" == "UU" ] ; then
|
||||
TAS5806=found
|
||||
echo "Texas Instruments 5806 $TAS5806"
|
||||
fi
|
||||
|
||||
is_04=$(i2cdetect -y -a 1 0x04 0x04 | grep -E "(04|UU)" | awk '{print $2}') # SJ201 Led Ring
|
||||
if [ "${is_04}" == "04" ] || [ "${is_04}" == "UU" ] ; then
|
||||
SJ201LED=found
|
||||
echo "Mark2-Devkit SJ201 Leds $SJ201LED"
|
||||
fi
|
||||
|
||||
# Configure found devices
|
||||
if [ "$WM8960" == "found" ] && [ "$RESPEAKER4" != "found" ] ; then
|
||||
if [[ ${detection_results[WM8XXX]} == true ]] && [[ ${detection_results[RESPEAKER4]} == false ]] ; then
|
||||
echo "Installing and configuring WM8960 based 2-mic HAT"
|
||||
dtoverlay wm8960-soundcard
|
||||
echo "Configuring board"
|
||||
|
@ -93,9 +90,9 @@ if [ "$WM8960" == "found" ] && [ "$RESPEAKER4" != "found" ] ; then
|
|||
amixer -c "wm8960soundcard" cset numid=15 4
|
||||
echo "Configuring button"
|
||||
dtoverlay wm8960-button-overlay
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$MARK1" == "found" ] ; then
|
||||
if [[ ${detection_results[MARK1]} == true ]] ; then
|
||||
echo "Installing and configuring WM8731 based sound HAT"
|
||||
dtoverlay proto-codec
|
||||
echo "Configuring board"
|
||||
|
@ -110,10 +107,10 @@ if [ "$MARK1" == "found" ] ; then
|
|||
echo "Resetting Mark-1 faceplate"
|
||||
echo "eyes.color=7365993" > /dev/ttyAMA0 # color=soft gray, #706569
|
||||
echo "mouth.text=" > /dev/ttyAMA0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${RESPEAKER6}" == "found" ] && [ "${RESPEAKER4}" != "found" ] ; then
|
||||
echo "Installing and configuring ReSpeaker 4-mic HAT"
|
||||
if [[ ${detection_results[RESPEAKER4]} == true ]] && [[ ${detection_results[RESPEAKER6]} == false ]] ; then
|
||||
echo "Installing and configuring ReSpeaker 4-mic"
|
||||
dtoverlay seeed-4mic-voicecard
|
||||
echo "Configuring board"
|
||||
sleep 3 # Allow some time to fully initialise the hardware / driver
|
||||
|
@ -125,26 +122,44 @@ if [ "${RESPEAKER6}" == "found" ] && [ "${RESPEAKER4}" != "found" ] ; then
|
|||
amixer -c "seeed4micvoicec" cset numid=6 13
|
||||
amixer -c "seeed4micvoicec" cset numid=7 13
|
||||
amixer -c "seeed4micvoicec" cset numid=8 13
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "{$RESPEAKER6}" == "found" ] && [ "${RESPEAKER4}" == "found" ] ; then
|
||||
echo "Installing and configuring ReSpeaker 6mic HAT"
|
||||
if [[ ${detection_results[RESPEAKER6]} == true ]] && [[ ${detection_results[RESPEAKER4]} == true ]] ; then
|
||||
echo "Installing and configuring ReSpeaker 6mic"
|
||||
dtoverlay seeed-8mic-voicecard
|
||||
fi
|
||||
echo "Configuring board"
|
||||
sleep 3 # Allow some time to fully initialise the hardware / driver
|
||||
amixer -c "seeed8micvoicec" cset numid=1 208
|
||||
amixer -c "seeed8micvoicec" cset numid=2 208
|
||||
amixer -c "seeed8micvoicec" cset numid=3 208
|
||||
amixer -c "seeed8micvoicec" cset numid=4 208
|
||||
amixer -c "seeed8micvoicec" cset numid=5 13
|
||||
amixer -c "seeed8micvoicec" cset numid=6 13
|
||||
amixer -c "seeed8micvoicec" cset numid=7 13
|
||||
amixer -c "seeed8micvoicec" cset numid=8 13
|
||||
amixer -c "seeed8micvoicec" cset numid=9 208
|
||||
amixer -c "seeed8micvoicec" cset numid=10 208
|
||||
amixer -c "seeed8micvoicec" cset numid=11 208
|
||||
amixer -c "seeed8micvoicec" cset numid=12 208
|
||||
amixer -c "seeed8micvoicec" cset numid=13 13
|
||||
amixer -c "seeed8micvoicec" cset numid=14 13
|
||||
amixer -c "seeed8micvoicec" cset numid=15 13
|
||||
amixer -c "seeed8micvoicec" cset numid=16 13
|
||||
fi
|
||||
|
||||
if [ "$ADAFRUIT" ] ; then
|
||||
if [[ ${detection_results[ADAFRUIT]} == true ]] ; then
|
||||
echo "Installing and configuring Adafruit"
|
||||
/usr/sbin/i2cset -y 1 0x4b 30 # Set maximum volume to 30
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$TAS5806" ] ; then
|
||||
if [[ ${detection_results[TAS5806]} == true ]] ; then
|
||||
echo "Installing and configuring SJ-201 HAT"
|
||||
# Initializing XMOS xvf3510
|
||||
dtoverlay xvf3510
|
||||
xvf3510-flash --direct "/usr/lib/firmware/xvf3510/app_xvf3510_int_spi_boot_v4_1_0.bin"
|
||||
# Initializing Texas Instruments 5806 Amplifier
|
||||
/usr/bin/tas5806-init
|
||||
if [ "$SJ201LED" ] ; then
|
||||
if [[ ${detection_results[SJ201LED]} == true ]] ; then
|
||||
echo "Found revision-6 SJ-201 board"
|
||||
# Initializing and resetting LED ring
|
||||
/usr/bin/sj201-reset-led
|
||||
|
@ -156,4 +171,13 @@ if [ "$TAS5806" ] ; then
|
|||
fi
|
||||
echo "Configuring buttons"
|
||||
dtoverlay sj201-buttons-overlay
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ${detection_results[AIYVOICEBONNET]} == true ]] ; then
|
||||
echo "Installing and configuring AIY VoiceBonnet"
|
||||
# TODO by someone that has that HAT
|
||||
fi
|
||||
}
|
||||
|
||||
# Run the main function
|
||||
main
|
||||
|
|
Loading…
Reference in New Issue