summaryrefslogtreecommitdiff
path: root/hidflash.py
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2013-10-26 15:08:03 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2013-10-26 15:08:03 +0200
commiteba00652c2fbdc8dfd954027f3e522e723f2a7a8 (patch)
tree3e4bd0e10ea6638a2d5d3baf3c5531b3a0b57ed2 /hidflash.py
parenta827babff1fc873c69ac94fd51dc440842a01699 (diff)
Enabled switching to bootloader from runtime mode.
Diffstat (limited to 'hidflash.py')
-rwxr-xr-xhidflash.py37
1 files changed, 33 insertions, 4 deletions
diff --git a/hidflash.py b/hidflash.py
index a7042ca..6ab4bf6 100755
--- a/hidflash.py
+++ b/hidflash.py
@@ -34,9 +34,27 @@ if len(buf) & (64 - 1):
dev = hidapi.hid_open(0x1d50, 0x6084, None)
if not dev:
- raise RuntimeError('Device not found.')
+ dev = hidapi.hid_open(0x1d50, 0x6080, None)
+
+ if not dev:
+ raise RuntimeError('Device not found.')
+
+ print 'Found runtime device, resetting to bootloader.'
+
+ # Reset bootloader
+ if hidapi.hid_send_feature_report(dev, ctypes.c_char_p('\x00\x10'), 2) != 2:
+ raise RuntimeError('Reset failed.')
+
+ time.sleep(1)
+
+ hidapi.hid_exit()
+
+ dev = hidapi.hid_open(0x1d50, 0x6084, None)
+
+ if not dev:
+ raise RuntimeError('Device not found.')
-print 'Found device, starting flashing.'
+print 'Found bootloader device, starting flashing.'
# Prepare
if hidapi.hid_send_feature_report(dev, ctypes.c_char_p('\x00\x20'), 2) != 2:
@@ -52,10 +70,21 @@ while buf:
if hidapi.hid_send_feature_report(dev, ctypes.c_char_p('\x00\x21'), 2) != 2:
raise RuntimeError('Finish failed.')
-print 'Flashing finished, resetting.'
+print 'Flashing finished, resetting to runtime.'
# Reset
if hidapi.hid_send_feature_report(dev, ctypes.c_char_p('\x00\x11'), 2) != 2:
raise RuntimeError('Reset failed.')
-print 'Done, everything ok.'
+time.sleep(1)
+
+hidapi.hid_exit()
+
+if hidapi.hid_open(0x1d50, 0x6080, None):
+ print 'Done, everything ok.'
+
+elif hidapi.hid_open(0x1d50, 0x6084, None):
+ print 'Still in bootloader mode.'
+
+else:
+ print 'Device disappeared.'