summaryrefslogtreecommitdiff
path: root/digital/dev2/src/usb_serial_isp/dev2ctl.py
diff options
context:
space:
mode:
authorNicolas Schodet2009-04-10 01:16:50 +0200
committerNicolas Schodet2009-04-10 01:16:50 +0200
commit72ed993e982d1a2484ef9d54d93757f2f9094547 (patch)
tree440c2b1ddbbca4a36c686b3f3e20f8dd6a2a85c3 /digital/dev2/src/usb_serial_isp/dev2ctl.py
parentefdeb17f51de00aade6ea3ec4d3ddf1404d56855 (diff)
* digital/dev2:
- added usb_serial_isp, no isp yet.
Diffstat (limited to 'digital/dev2/src/usb_serial_isp/dev2ctl.py')
-rwxr-xr-xdigital/dev2/src/usb_serial_isp/dev2ctl.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/digital/dev2/src/usb_serial_isp/dev2ctl.py b/digital/dev2/src/usb_serial_isp/dev2ctl.py
new file mode 100755
index 00000000..00097521
--- /dev/null
+++ b/digital/dev2/src/usb_serial_isp/dev2ctl.py
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+# dev2 - Multi-purpose development board using USB and Ethernet. {{{
+#
+# Copyright (C) 2009 Nicolas Schodet
+#
+# APBTeam:
+# Web: http://apbteam.org/
+# Email: team AT apbteam DOT org
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# }}}
+"""Control dev2 board using USB."""
+import sys
+from optparse import OptionParser
+import usb
+
+# Parse options.
+opt = OptionParser (description = __doc__)
+opt.add_option ('-s', '--select', type = 'int',
+ help = 'select specified OUTPUT (1 to 4)', metavar = 'OUTPUT')
+opt.add_option ('-u', '--unselect', action = 'store_true', default = False,
+ help = 'unselect outputs')
+opt.add_option ('-d', '--dfu', action = 'store_true', default = False,
+ help = 'go to DFU boot loader')
+
+(options, args) = opt.parse_args ()
+if args:
+ opt.error ('too many arguments')
+if (options.select is not None) + options.unselect + options.dfu != 1:
+ opt.error ('choose one of available options')
+if options.select is not None and (options.select < 1 or options.select > 4):
+ opt.error ('output out of bound')
+if options.unselect:
+ options.select = 0
+
+# Open device.
+d = None
+for bus in usb.busses ():
+ for dev in bus.devices:
+ if dev.idVendor == 0x03eb and dev.idProduct == 0x204e:
+ d = dev.open ()
+if d is None:
+ print >> sys.stderr, 'device not found'
+ sys.exit (1)
+
+# Send control message.
+if options.dfu:
+ d.controlMsg (usb.TYPE_VENDOR | usb.RECIP_DEVICE, 0, 0)
+elif options.select is not None:
+ d.controlMsg (usb.TYPE_VENDOR | usb.RECIP_DEVICE, 1, 0,
+ value = options.select)
+else:
+ assert 0