aboutsummaryrefslogtreecommitdiffstats
path: root/support/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'support/scripts')
-rw-r--r--support/scripts/45-maple.rules5
-rwxr-xr-xsupport/scripts/copy-to-ide54
-rwxr-xr-xsupport/scripts/reset.py145
-rwxr-xr-xsupport/scripts/robotis-loader.py94
-rw-r--r--support/scripts/win-list-com-ports.py29
5 files changed, 327 insertions, 0 deletions
diff --git a/support/scripts/45-maple.rules b/support/scripts/45-maple.rules
new file mode 100644
index 0000000..d1bda5f
--- /dev/null
+++ b/support/scripts/45-maple.rules
@@ -0,0 +1,5 @@
+ATTRS{idProduct}=="1001", ATTRS{idVendor}=="0110", MODE="664", GROUP="plugdev"
+ATTRS{idProduct}=="1002", ATTRS{idVendor}=="0110", MODE="664", GROUP="plugdev"
+ATTRS{idProduct}=="0003", ATTRS{idVendor}=="1eaf", MODE="664", GROUP="plugdev" SYMLINK+="maple"
+ATTRS{idProduct}=="0004", ATTRS{idVendor}=="1eaf", MODE="664", GROUP="plugdev" SYMLINK+="maple"
+
diff --git a/support/scripts/copy-to-ide b/support/scripts/copy-to-ide
new file mode 100755
index 0000000..e68abca
--- /dev/null
+++ b/support/scripts/copy-to-ide
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+# This hack copies libmaple's source, linker scripts, and support
+# libraries into the Maple IDE repository (which is expected as its
+# first argument).
+
+DEST=$1
+
+DEST_CORES=$DEST/hardware/leaflabs/cores/maple
+DEST_LIBS=$DEST/libraries
+
+LMAPLE_SRC="LICENSE
+ ./libmaple/*.h
+ ./libmaple/*.c
+ ./libmaple/*.S
+ ./libmaple/usb/*.h
+ ./libmaple/usb/*.c
+ ./libmaple/usb/usb_lib/*.h
+ ./libmaple/usb/usb_lib/*.c
+ ./wirish/*.h
+ ./wirish/main.cxx
+ ./wirish/*.cpp
+ ./wirish/comm/*.cpp
+ ./wirish/comm/*.h
+ ./wirish/boards/*.h
+ ./wirish/boards/*.cpp
+ ./support/ld/common.inc
+ ./support/ld/maple
+ ./support/ld/maple_mini
+ ./support/ld/maple_native
+ ./support/ld/maple_RET6
+ ./support/ld/names.inc"
+
+echo "First make sure DEST exists: $DEST"
+if !(test -d $DEST)
+then
+ echo "Nope! Make sure you're doing this right?"
+ exit -1
+fi
+
+# source
+echo Copying libmaple source
+rm -rf $DEST_CORES/*.c $DEST_CORES/*.cpp $DEST_CORES/*.h $DEST_CORES/*.cxx $DEST_CORES/*.S
+rm -rf $DEST_CORES/*.inc $DEST_CORES/*.a $DEST_CORES/maple $DEST_CORES/maple_*
+cp -R $LMAPLE_SRC $DEST_CORES
+
+echo Copying over libraries
+cp -R libraries/* $DEST_LIBS
+
+# libmaple version
+echo Creating libmaple-version.txt
+git show-ref HEAD | cut -c 1-10 > $DEST/libmaple-version.txt
+
+echo Done.
diff --git a/support/scripts/reset.py b/support/scripts/reset.py
new file mode 100755
index 0000000..67a72c1
--- /dev/null
+++ b/support/scripts/reset.py
@@ -0,0 +1,145 @@
+#!/usr/bin/env python
+
+from __future__ import print_function
+
+import serial
+import os
+import platform
+import sys
+import time
+from struct import pack
+
+def unix_get_maple_path(file_prefix, dev_is_maple=lambda dev: True):
+ """Try to find the device file for the Maple on *nix.
+
+ This function works assuming that the device file globs like
+ '/dev/<file_prefix>*'. The caller may pass an additional
+ dev_is_maple predicate if the platform supports additional tests
+ to determine if a device is a Maple.
+
+ If there are multiple possibilities, ask the user what to do. If
+ the user chooses not to say, returns None."""
+ possible_paths = [os.path.join('/dev', x) for x in os.listdir('/dev') \
+ if x.startswith(file_prefix) and dev_is_maple(x)]
+ return choose_path(possible_paths)
+
+def linux_get_maple_path(file_prefix='ttyACM'):
+ """Specialized unix_get_maple_path() for Linux.
+
+ Attempts to check that a candidate device has the correct ID in
+ the /sys tree when deciding if it's a Maple."""
+ return unix_get_maple_path(file_prefix, linux_tty_is_maple)
+
+def linux_tty_is_maple(device):
+ try:
+ sysfile = open("/sys/class/tty/%s/device/uevent" % device, "r")
+ text = "".join(sysfile.readlines())
+ return "PRODUCT=1eaf/4" in text
+ except IOError: # no udev info available
+ return True
+
+def windows_get_maple_path():
+ """Similar to unix_get_maple_path(), but on Windows."""
+ import _winreg as reg
+ p = 'HARDWARE\\DEVICEMAP\\SERIALCOMM'
+ k = reg.OpenKey(reg.HKEY_LOCAL_MACHINE, p)
+ possible_paths = []
+ i = 0
+ while True:
+ try:
+ possible_paths.append(reg.EnumValue(k, i)[1])
+ i += 1
+ except WindowsError:
+ break
+ return choose_path(possible_paths)
+
+def choose_path(possible_paths):
+ if len(possible_paths) == 0:
+ return None
+ elif len(possible_paths) == 1:
+ return possible_paths[0]
+ else:
+ print('Found multiple candidates for the Maple device:')
+ return choose_among_options(possible_paths)
+
+def choose_among_options(options):
+ for (i,p) in enumerate(options):
+ print('\t%d. %s' % (i+1, p))
+
+ prompt = 'Enter a number to select one, or q to quit: '
+ while True:
+ resp = raw_input(prompt).strip().lower()
+ if resp == 'q': sys.exit()
+
+ try:
+ i = int(resp, 10)
+ except ValueError:
+ pass
+ else:
+ if 0 <= i-1 < len(options):
+ return options[i-1]
+
+ prompt = 'Please enter a number from the list, or q to quit: '
+
+plat_sys = platform.system()
+plat_bits = platform.architecture()[0]
+if plat_sys == 'Linux':
+ maple_path = linux_get_maple_path()
+ # fall back on /dev/maple if that doesn't work
+ if maple_path is None:
+ maple_path = '/dev/maple'
+ print('Could not find Maple serial port; defaulting to /dev/maple.')
+elif plat_sys == 'Darwin':
+ maple_path = unix_get_maple_path('tty.usbmodem')
+elif plat_sys == 'Windows':
+ maple_path = windows_get_maple_path()
+else:
+ maple_path = raw_input('Unrecognized platform. Please enter '
+ "the path to the Maple's serial port device file:")
+
+if maple_path is None:
+ print('Could not find the Maple serial port for reset.',
+ 'Perhaps this is your first upload, or the board is already',
+ 'in bootloader mode.')
+ print()
+ print("If your sketch doesn't upload, try putting your Maple",
+ 'into bootloader mode manually by pressing the RESET button',
+ 'then letting it go and quickly pressing button BUT',
+ '(hold for several seconds).')
+ sys.exit()
+
+print('Using %s as Maple serial port' % maple_path)
+
+try:
+ ser = serial.Serial(maple_path, baudrate=115200, xonxoff=1)
+
+ try:
+ # try to toggle DTR/RTS (old scheme)
+ ser.setRTS(0)
+ time.sleep(0.01)
+ ser.setDTR(0)
+ time.sleep(0.01)
+ ser.setDTR(1)
+ time.sleep(0.01)
+ ser.setDTR(0)
+
+ # try magic number
+ ser.setRTS(1)
+ time.sleep(0.01)
+ ser.setDTR(1)
+ time.sleep(0.01)
+ ser.setDTR(0)
+ time.sleep(0.01)
+ ser.write("1EAF".encode("ascii"))
+ ser.flush()
+
+ # Delay a bit before proceeding
+ time.sleep(0.1)
+ finally:
+ # ok we're done here
+ ser.close()
+
+except Exception as e:
+ print('Failed to open serial port %s for reset' % maple_path)
+ sys.exit()
+
diff --git a/support/scripts/robotis-loader.py b/support/scripts/robotis-loader.py
new file mode 100755
index 0000000..95d4e71
--- /dev/null
+++ b/support/scripts/robotis-loader.py
@@ -0,0 +1,94 @@
+#!/usr/bin/python
+
+# This script sends a program on a robotis board (OpenCM9.04 or CM900)
+# using the robotis bootloader (used in OpenCM IDE)
+#
+# Usage:
+# python robotis-loader.py <serial port> <binary>
+#
+# Example:
+# python robotis-loader.py /dev/ttyACM0 firmware.bin
+#
+# https://github.com/Gregwar/robotis-loader
+
+import serial, sys, os, time
+
+print('~~ Robotis loader ~~')
+print('')
+
+# Reading command line
+if len(sys.argv) != 3:
+ exit('! Usage: robotis-loader.py <serial-port> <binary>')
+pgm, port, binary = sys.argv
+
+# Helper to prints a progress bar
+def progressBar(percent, precision=65):
+ threshold=precision*percent/100.0
+ sys.stdout.write('[ ')
+ for x in xrange(0, precision):
+ if x < threshold: sys.stdout.write('#')
+ else: sys.stdout.write(' ')
+ sys.stdout.write(' ] ')
+ sys.stdout.flush()
+
+# Opening the firmware file
+try:
+ stat = os.stat(binary)
+ size = stat.st_size
+ firmware = file(binary, 'rb')
+ print('* Opening %s, size=%d' % (binary, size))
+except:
+ exit('! Unable to open file %s' % binary)
+
+# Opening serial port
+try:
+ s = serial.Serial(port, baudrate=115200)
+except:
+ exit('! Unable to open serial port %s' % port)
+
+print('* Resetting the board')
+s.setRTS(True)
+s.setDTR(False)
+time.sleep(0.1)
+s.setRTS(False)
+s.write('CM9X')
+s.close()
+time.sleep(1.0);
+
+print('* Connecting...')
+s = serial.Serial(port, baudrate=115200)
+s.write('AT&LD')
+print('* Download signal transmitted, waiting...')
+
+# Entering bootloader sequence
+while True:
+ line = s.readline().strip()
+ if line.endswith('Ready..'):
+ print('* Board ready, sending data')
+ cs = 0
+ pos = 0
+ while True:
+ c = firmware.read(2048)
+ if len(c):
+ pos += len(c)
+ sys.stdout.write("\r")
+ progressBar(100*float(pos)/float(size))
+ s.write(c)
+ for k in range(0,len(c)):
+ cs = (cs+ord(c[k]))%256
+ else:
+ break
+ print('')
+ s.setDTR(True)
+ print('* Checksum: %d' % (cs))
+ s.write(chr(cs))
+ print('* Firmware was sent')
+ else:
+ if line == 'Success..':
+ print('* Success, running the code')
+ print('')
+ s.write('AT&RST')
+ s.close()
+ exit()
+ else:
+ print('Board -> '+line)
diff --git a/support/scripts/win-list-com-ports.py b/support/scripts/win-list-com-ports.py
new file mode 100644
index 0000000..3e6ecb8
--- /dev/null
+++ b/support/scripts/win-list-com-ports.py
@@ -0,0 +1,29 @@
+# Windows program for listing COM (serial) ports.
+#
+# enumerate_serial_ports() is by Eli Bendersky:
+#
+# http://eli.thegreenplace.net/2009/07/31/listing-all-serial-ports-on-windows-with-python/
+
+import _winreg as winreg
+import itertools
+
+def enumerate_serial_ports():
+ """ Uses the Win32 registry to return an
+ iterator of serial (COM) ports
+ existing on this computer.
+ """
+ path = 'HARDWARE\\DEVICEMAP\\SERIALCOMM'
+ try:
+ key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path)
+ except WindowsError:
+ raise IterationError
+
+ for i in itertools.count():
+ try:
+ val = winreg.EnumValue(key, i)
+ yield str(val[1])
+ except EnvironmentError:
+ break
+
+for com in enumerate_serial_ports():
+ print com