Skip to content

Commit

Permalink
Merge pull request #15 from lucianomartin/feature/use_hw_i2c
Browse files Browse the repository at this point in the history
Remove I2C driver use
  • Loading branch information
chrisc-xmos authored Jul 19, 2019
2 parents 1d5a172 + 1b3f1c5 commit f45e614
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 303 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# VocalFusion Raspberry Pi Setup Change Log

## 2.0.0

* Use default I2C hardware
* Add installation of Py3 packages

## 1.3.2

* Added audacity installation and setup for XVF3510
Expand Down
9 changes: 0 additions & 9 deletions i2c-gpio-param/Makefile

This file was deleted.

248 changes: 0 additions & 248 deletions i2c-gpio-param/i2c-gpio-param.c

This file was deleted.

74 changes: 28 additions & 46 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@ RPI_SETUP_DIR="$( pwd )"

# Disable the built-in audio output so there is only one audio
# device in the system
sudo sed -i -e 's/dtparam=audio=on/#dtparam=audio=on/' /boot/config.txt
sudo sed -i -e 's/^dtparam=audio=on/#dtparam=audio=on/' /boot/config.txt

# Enable the i2s device tree
sudo sed -i -e 's/#dtparam=i2s=on/dtparam=i2s=on/' /boot/config.txt

# Enable the I2C device tree
sudo raspi-config nonint do_i2c 1
sudo raspi-config nonint do_i2c 0

# Set the I2C baudrate to 100k
sudo sed -i -e '/^dtparam=i2c_arm_baudrate/d' /boot/config.txt
sudo sed -i -e 's/dtparam=i2c_arm=on$/dtparam=i2c_arm=on\ndtparam=i2c_arm_baudrate=100000/' /boot/config.txt

echo "Installing Raspberry Pi kernel headers"
sudo apt-get install -y raspberrypi-kernel-headers

echo "Installing the Python3 packages and related libs"
sudo apt-get install python3-matplotlib
sudo apt-get install python3-numpy
sudo apt-get install libatlas-base-dev


# Build loader and insert it into the kernel
Expand Down Expand Up @@ -58,25 +70,27 @@ sudo /etc/init.d/alsa-utils restart
# Create the script to run after each reboot and make the soundcard available
i2s_driver_script=$RPI_SETUP_DIR/resources/load_i2s_driver.sh
rm -f $i2s_driver_script
echo "cd $RPI_SETUP_DIR" >> $i2s_driver_script
echo "cd $RPI_SETUP_DIR" >> $i2s_driver_script
if [ $# -ge 1 ] && [ $1 = "xvf3510" ] ; then
echo "sudo insmod loader/i2s_master/loader.ko" >> $i2s_driver_script
echo "sudo insmod loader/i2s_master/loader.ko" >> $i2s_driver_script
else
echo "sudo insmod loader/i2s_slave/loader.ko" >> $i2s_driver_script
echo "sudo insmod loader/i2s_slave/loader.ko" >> $i2s_driver_script
fi


echo "# Run Alsa at startup so that alsamixer configures" >> $i2s_driver_script
echo "arecord -d 1 > /dev/null 2>&1" >> $i2s_driver_script
echo "aplay dummy > /dev/null 2>&1" >> $i2s_driver_script

if [ $# -ge 1 ] && [ $1 = "xvf3510" ] ; then
pushd $RPI_SETUP_DIR/resources/clk_dac_setup/ > /dev/null
make
popd > /dev/null
i2s_clk_dac_script=$RPI_SETUP_DIR/resources/init_i2s_clks.sh
rm -f $i2s_clk_dac_script
echo "sudo raspi-config nonint do_i2c 1" >> $i2s_clk_dac_script
echo "sudo raspi-config nonint do_i2c 0" >> $i2s_clk_dac_script
echo "sudo $RPI_SETUP_DIR/resources/clk_dac_setup/setup_mclk" >> $i2s_clk_dac_script
echo "sudo $RPI_SETUP_DIR/resources/clk_dac_setup/setup_bclk" >> $i2s_clk_dac_script
echo "python $RPI_SETUP_DIR/resources/clk_dac_setup/setup_dac.py" >> $i2s_clk_dac_script
echo "sudo $RPI_SETUP_DIR/resources/clk_dac_setup/setup_mclk" >> $i2s_clk_dac_script
echo "sudo $RPI_SETUP_DIR/resources/clk_dac_setup/setup_bclk" >> $i2s_clk_dac_script
echo "python $RPI_SETUP_DIR/resources/clk_dac_setup/setup_dac.py" >> $i2s_clk_dac_script
echo "python $RPI_SETUP_DIR/resources/clk_dac_setup/reset_xvf3510.py" >> $i2s_clk_dac_script
fi

Expand All @@ -87,52 +101,20 @@ if [ $# -ge 1 ] && [ $1 = "xvf3510" ] ; then
echo "#!/usr/bin/env bash" >> $audacity_script
echo "/usr/bin/audacity &" >> $audacity_script
echo "sleep 5" >> $audacity_script
echo "sudo $RPI_SETUP_DIR/resources/clk_dac_setup/setup_bclk >> /dev/null" >> $audacity_script
echo "sudo $RPI_SETUP_DIR/resources/clk_dac_setup/setup_bclk >> /dev/null" >> $audacity_script
sudo chmod +x $audacity_script
sudo mv $audacity_script /usr/local/bin/audacity
fi

# Configure the I2C - disable the default built-in driver
sudo sed -i -e 's/#\?dtparam=i2c_arm=on/dtparam=i2c_arm=off/' /boot/config.txt
if ! grep -q "i2c-bcm2708" /etc/modules-load.d/modules.conf; then
sudo sh -c 'echo i2c-bcm2708 >> /etc/modules-load.d/modules.conf'
fi
if ! grep -q "options i2c-bcm2708 combined=1" /etc/modprobe.d/i2c.conf; then
sudo sh -c 'echo "options i2c-bcm2708 combined=1" >> /etc/modprobe.d/i2c.conf'
fi


# Build a new I2C driver
pushd $RPI_SETUP_DIR/i2c-gpio-param > /dev/null
make || exit $?
popd > /dev/null


# Create script to insert module into the kernel
i2c_driver_script=$RPI_SETUP_DIR/resources/load_i2c_gpio_driver.sh
rm -f $i2c_driver_script
echo "cd $RPI_SETUP_DIR/i2c-gpio-param" >> $i2c_driver_script
echo "# Load the i2c bit banged driver" >> $i2c_driver_script
echo "sudo insmod i2c-gpio-param.ko" >> $i2c_driver_script
echo "# Instantiate a driver at bus id=1 on same pins as hw i2c with 1sec timeout" >> $i2c_driver_script
echo "sudo sh -c 'echo "1 2 3 5 100 0 0 0" > /sys/class/i2c-gpio/add_bus'" >> $i2c_driver_script
echo "# Remove the default i2c-gpio instance" >> $i2c_driver_script
echo "sudo sh -c 'echo 7 > /sys/class/i2c-gpio/remove_bus'" >> $i2c_driver_script

echo "# Run Alsa at startup so that alsamixer configures" >> $i2c_driver_script
echo "arecord -d 1 > /dev/null 2>&1" >> $i2c_driver_script
echo "aplay dummy > /dev/null 2>&1" >> $i2c_driver_script


# Setup the crontab to restart I2S/I2C at reboot
# Setup the crontab to restart I2S at reboot
rm -f $RPI_SETUP_DIR/resources/crontab
echo "@reboot sh $i2s_driver_script" >> $RPI_SETUP_DIR/resources/crontab
echo "@reboot sh $i2c_driver_script" >> $RPI_SETUP_DIR/resources/crontab
echo "@reboot sh $i2s_driver_script" >> $RPI_SETUP_DIR/resources/crontab
if [ $# -ge 1 ] && [ $1 = "xvf3510" ] ; then
echo "@reboot sh $i2s_clk_dac_script" >> $RPI_SETUP_DIR/resources/crontab
echo "@reboot sh $i2s_clk_dac_script" >> $RPI_SETUP_DIR/resources/crontab
fi
crontab $RPI_SETUP_DIR/resources/crontab

echo "To enable I2S, this Raspberry Pi must be rebooted."
echo "To enable I2S and I2C, this Raspberry Pi must be rebooted."

popd > /dev/null

0 comments on commit f45e614

Please sign in to comment.