Last active
May 23, 2021 22:18
-
-
Save sanchox/45d080a7576315aad9398a802530561e to your computer and use it in GitHub Desktop.
Bash script to program Silabs SI53xx devices via I2C bus using txt file exported from ClockBuilder tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
I2CBUS="1" | |
I2CADDR="0x6a" | |
current_page="-1" | |
function set_page { | |
if [ "x$current_page" == "x$1" ]; then return; fi | |
echo "Setting current page to $1" | |
i2cset -y $I2CBUS $I2CADDR 0x1 "0x$1" | |
current_page=$1 | |
} | |
if [[ $# -eq 0 ]]; | |
then | |
exit; | |
fi | |
cmd_regex="0x([0-9a-zA-Z]{2})?([0-9a-zA-Z]{2}),0x([0-9a-zA-Z]{2})" | |
delay_regex="# Delay 300 msec" | |
while read line | |
do | |
if [[ $line =~ $delay_regex ]]; then | |
sleep 1; | |
fi | |
if [[ $line =~ $cmd_regex ]]; then | |
page=${BASH_REMATCH[1]} | |
addr=${BASH_REMATCH[2]} | |
data=${BASH_REMATCH[3]} | |
if [ "x$page" != "x" ]; then | |
set_page $page | |
fi | |
i2cset -y $I2CBUS $I2CADDR "0x$addr" "0x$data" | |
echo "$page $addr $data" | |
fi | |
done < $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment