view program @ 8:1969a435a7a2

Change to using 16c0:05e1 shared CDC USB ID Enumerate devices using "udevadm info" (lsusb does not show strings) Randomize serial numbers Add domain name to manufacturer string
author Frank Kingswood <frank@kingswood-consulting.co.uk>
date Mon, 21 Apr 2014 11:03:21 +0100
parents acbd0ddd002b
children 16a338171c99
line wrap: on
line source
1 #!/bin/sh
2 set -e
4 if [ $# -lt 3 ] || [ "$1" = "--help" ] ; then
5 echo "Called from Makefile to program USB-GPIB"
6 exit 1
7 fi
9 DASHV=
10 DASHQ=-q
11 if [ "$1" = "-v" ] ; then
12 shift
13 DASHV=-v
14 DASHQ=
15 fi
17 find_device() {
18 for F in /dev/ttyACM* ; do udevadm info --name $F ;done | awk '
19 BEGIN { name="";state=0 }
20 /^P:/ { if(state==111) state+=1000 }
21 /^E: ID_VENDOR_ID='$1'$/ { state+=1 }
22 /^E: ID_MODEL_ID='$2'$/ { state+=10 }
23 /^E: DEVNAME=/ { name=substr($2,9); print " found " name >"/dev/stderr"; state+=100; }
24 END { if(state==111) { print name } else { exit 2 }}
25 '
26 }
28 MODE=
29 if [ "$(lsusb -d 2341:8036 | wc -l)" = "1" ] ; then
30 DEV=$(find_device 2341 8036)
31 MODE=AVR109
33 elif [ "$(lsusb -d 16c0:0478 | wc -l)" = "1" ] ; then
34 DEV=$(find_device 16c0 0478)
35 MODE=Teensy
37 elif lsusb -d 16c0:05e1 >/dev/null ; then
38 echo "Detecting USB-GPIB on shared CDC USB ID"
40 DEV=$(
41 for F in /dev/ttyACM* ; do udevadm info --name $F ;done | awk '
42 BEGIN { name="";state=0 }
43 /^P:/ { if(state==111) state+=10000 }
44 /^N:/ { name=$2; state+=1; }
45 /^E: ID_MODEL=USB-GPIB-32U4/ { state+=10; }
46 /^E: ID_VENDOR=Frank_Kingswood__kingswood-consulting.co.uk$/ { state+=100; }
47 /^E: DEVNAME=/ { name=substr($2,9); print " found " name >"/dev/stderr"; state+=1000; }
48 END { if(state==1111) { print name }}
49 '
50 )
52 trap "true" ALRM
53 exec 3<>$DEV
55 set +e
56 for I in $(seq 3) ; do
57 (
58 sleep 0.3
59 kill -ALRM $$
60 ) &
61 while read X ; do echo $X ; done
62 done
64 V=
65 for I in $(seq 5) ; do
66 (
67 sleep 0.3
68 kill -ALRM $$
69 ) &
70 echo "++ver" >&3
71 read V <&3
73 case "$V" in
74 *USB-GPIB-32U4*)
75 echo "Found USB-GPIB"
76 break
77 ;;
78 *)
79 ;;
80 esac
81 done
82 set -e
84 # call the boot loader
85 case "$V" in
86 *Teensy*)
87 echo "++DEBUG 0x7e00" >&3
88 MODE=Teensy
89 ;;
90 *MicroPro*)
91 echo "++DEBUG 0x7800" >&3
92 MODE=AVR109
93 ;;
94 *)
95 exit 2
96 ;;
97 esac
99 exec 3>&-
100 sleep 0.5
101 trap - ALRM
103 else
104 echo "No device or multiple devices found:"
105 echo
106 lsusb | grep -Pv "Linux Foundation .+ root hub"
107 exit 1
108 fi
110 echo "$MODE boot loader"
112 if [ "$1" != "--program" ] ; then
113 exit 1
114 fi
116 sleep 0.5
117 set -x
118 case "$MODE" in
119 Teensy)
120 teensy_loader_cli -mmcu="$2" -w -v $DASHV "$3"
121 ;;
122 AVR109)
123 avrdude -c avr109 -P $DEV -p "$2" -q $DASHQ -U flash:w:"$3"
124 ;;
125 esac