Created
September 1, 2017 20:53
-
-
Save rpedde/7ac6ada5e974ae2c9bbf315232e8d43a to your computer and use it in GitHub Desktop.
keyboard firmware burner
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 | |
TOP=$(dirname $(readlink -f $0)) | |
declare -A pids | |
pids[at90usb1287]=2ffb | |
pids[at90usb1286]=2ffb | |
pids[at90usb647]=2ff9 | |
pids[at90usb646]=2ff9 | |
pids[at90usb162]=2ffa | |
pids[at90usb82]=2ff7 | |
pids[atmega32u4]=2ff4 | |
pids[atmega16u4]=2ff3 | |
function wait_for_usb_device { | |
vid=$1 | |
pid=$2 | |
echo "Waiting for ${vid}:${pid}" | |
while /bin/true; do | |
if $(lsusb | grep -i ${vid}:${pid} > /dev/null 2>&1); then | |
echo "Found device" | |
sleep 6 | |
return | |
else | |
echo "Still not present" | |
sleep 2 | |
fi | |
done | |
} | |
if [ $# -lt 1 ] && [ $# -gt 2]; then | |
echo "burn <firmware> [device]" | |
exit 1 | |
fi | |
fw=$1 | |
device=${2:-atmega32u4} | |
if [ ! -e ${fw} ]; then | |
if [ ! -e ${TOP}/${fw} ]; then | |
echo "Cannot find firmware file \"${fw}\"" | |
exit 1 | |
else | |
fw=${TOP}/${fw} | |
fi | |
fi | |
# wait for the keyboard to go into flip/dfu mode | |
wait_for_usb_device 03eb ${pids[${device}]} | |
echo "erasing" | |
dfu-programmer atmega32u4 erase | |
echo "flashing" | |
dfu-programmer atmega32u4 flash $fw | |
echo "restarting" | |
dfu-programmer atmega32u4 reset | |
echo "waiting for reboot" | |
wait_for_usb_device feed 6060 | |
xset r rate 250 30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment