aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Goger <klaus.goger@theobroma-systems.com>2017-06-01 14:37:31 +0200
committerKlaus Goger <klaus.goger@theobroma-systems.com>2017-06-13 11:56:57 +0200
commit05cb122e6e7963a4a96a9f96112b68803a74888b (patch)
tree28ea56d7548d3d133376b19012e6818252268e15
parent15c965c129243e9e7899ab48a9e8495db19c11a5 (diff)
import haikou base board control script
The Q7 baseboard Haikou features a USB to UART Bridge. This Bridge allows to control the boot behaviour and the power button via USB. This script is a python based libusb interface to enable this feature cross-platform.
-rw-r--r--usb-control/README.md32
-rwxr-xr-xusb-control/haikou.py76
2 files changed, 108 insertions, 0 deletions
diff --git a/usb-control/README.md b/usb-control/README.md
new file mode 100644
index 0000000..0d62946
--- /dev/null
+++ b/usb-control/README.md
@@ -0,0 +1,32 @@
+# Haikou USB Control
+
+This tool allows to control the **BIOS Disable** and **Power** Button via USB.
+
+
+## Dependencies
+
+[Python](http://www.python.org/)
+[PyUSB](http://walac.github.io/pyusb/)
+[libusb](http://libusb.info/)
+
+
+# Usage
+
+To manipulate **BIOS Disable** via USB the slider has to be in the **Normal Boot**
+position.
+
+The script takes following parameters:
+
+ --list, -l list serial numbers of connected baseboards
+ --serial SERIALNUMBER, -s SERIALNUMBER
+ defines the serialnumber to use
+ --press-power, -p press power button
+ --bios-disable, -b activate BIOS Disable
+ --normal-boot, -n activate Normal Boot
+
+Each Haikou base board has a unique USB ID so they can be differentiated if more then
+one is connected to the host. Provide the serialnumber on the commandline to select
+a specific board, otherwise the first one found will be used.
+
+If called without `-p`, `-b` or `-n` a GUI with buttons for **Power** and **BIOS Disable**
+starts.
diff --git a/usb-control/haikou.py b/usb-control/haikou.py
new file mode 100755
index 0000000..84cf490
--- /dev/null
+++ b/usb-control/haikou.py
@@ -0,0 +1,76 @@
+# Copyright (C) 2017 Theobroma Systems Design und Consulting GmbH
+
+#!/usr/bin/env python
+import argparse
+import usb.core
+import usb.util
+import sys
+import time
+
+VENDOR_ID = 0x10c4
+PRODUCT_ID = 0xea60
+PRODUCT_STRING = "Haikou Baseboard"
+REQTYPE_HOST_TO_DEVICE = 0x40
+REQTYPE_DEVICE_TO_HOST = 0xc0
+CP210X_VENDOR_SPECIFIC = 0xFF
+CP210X_WRITE_LATCH = 0x37E1
+CP210X_READ_LATCH = 0x00C2
+
+def send_gpio_command(gpio,value):
+ data = 0
+ # the latch register has 16 bit. the upper 8 bits are the gpio value,
+ # the lower 8 bit are the write mask.
+ data = (value << (8+gpio)) | (1 << gpio);
+ dev.ctrl_transfer(REQTYPE_HOST_TO_DEVICE, CP210X_VENDOR_SPECIFIC, \
+ CP210X_WRITE_LATCH, data, 0)
+
+
+parser = argparse.ArgumentParser(description='Controls power button and BIOS \
+ Disable of the Haikou Baseboard')
+parser.add_argument('--list','-l', action='store_true', dest='list',
+ help='list serial numbers of connected baseboards')
+parser.add_argument('--serial','-s', action='store', dest='serialnumber', \
+ type=str, help='defines the serialnumber to use')
+parser.add_argument('--press-power','-p', action='store_true', \
+ dest='power', help='press power button')
+parsergroup = parser.add_mutually_exclusive_group()
+parsergroup.add_argument('--bios-disable','-b',action='store_true', \
+ dest='bios_disable', help='activate BIOS Disable')
+parsergroup.add_argument('--normal-boot','-n',action='store_true', \
+ dest='normal_boot', help='activate Normal Boot')
+
+args = parser.parse_args()
+
+if not args.list and not args.power and not args.bios_disable \
+ and not args.normal_boot:
+ parser.print_usage()
+ sys.exit()
+
+if args.list:
+ dev = list(usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID, \
+ product=PRODUCT_STRING, find_all=True))
+ print "Found %d Baseboard%s:" % (len(dev),"s"[len(dev)==1:])
+ for idx,cfg in enumerate(dev):
+ print "%d: %s" % (idx, cfg.serial_number)
+ sys.exit()
+
+if args.serialnumber:
+ dev = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID, \
+ serial_number=args.serialnumber)
+else:
+ dev = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
+
+if dev is None:
+ print "Device not found"
+ sys.exit()
+
+if args.bios_disable:
+ send_gpio_command(1,0)
+
+if args.normal_boot:
+ send_gpio_command(1,1)
+
+if args.power:
+ send_gpio_command(0,1)
+ time.sleep(0.3)
+ send_gpio_command(0,0)