aboutsummaryrefslogtreecommitdiff
path: root/usb-control/cp2102_simple.py
diff options
context:
space:
mode:
authorChristoph Muellner <christoph.muellner@theobroma-systems.com>2019-10-07 15:23:58 +0200
committerChristoph Muellner <christoph.muellner@theobroma-systems.com>2019-10-07 16:52:59 +0200
commitb603f1df0a912b9a397c18911946535ae421de5d (patch)
tree6c91f888468b641cf455285ad7ecfa780faea9ed /usb-control/cp2102_simple.py
parentb9b547d5a508757abb5052b24c59adecc1dda54a (diff)
Add support for cp2102 simple control cicuits.
This patch factors out the low-level routines to control a CP2102 to cp210x_controller.py. command_processor.py provides a framework for defining commands and to specify options. It represents the board independet boilerplate code. cp2102_haikou.py contains the commands to control a Haikou-like circuit. cp2102_simple.py contains the commands to control a simple control circuit. The board files cp2102-mini-evk.py, haikou.py, and telaviv.py are the front-ends to control the specified boards. Signed-off-by: Christoph Muellner <christoph.muellner@theobroma-systems.com>
Diffstat (limited to 'usb-control/cp2102_simple.py')
-rw-r--r--usb-control/cp2102_simple.py113
1 files changed, 113 insertions, 0 deletions
diff --git a/usb-control/cp2102_simple.py b/usb-control/cp2102_simple.py
new file mode 100644
index 0000000..c4b2924
--- /dev/null
+++ b/usb-control/cp2102_simple.py
@@ -0,0 +1,113 @@
+#!/usr/bin/env python
+
+"""
+Abstraction layer for simple control circuits.
+The simple control circuit can control the reset
+signal via GPIO.0 and the maskrom signal via GPIO.1.
+"""
+
+__copyright__ = 'Copyright (C) 2019 Theobroma Systems Design und Consulting GmbH'
+__license__ = 'MIT'
+
+import sys
+import time
+import command_processor
+import cp210x_controller
+
+# Power supply GPIO
+GPIO_RESET = 0
+VALUE_RESET_DEASSERT = 0
+VALUE_RESET_ASSERT = 1
+
+# Maskrom (BIOS disable) GPIO
+GPIO_MASKROM = 1
+VALUE_MASKROM_DEASSERT = 0
+VALUE_MASKROM_ASSERT = 1
+
+def invert_reset():
+ global VALUE_RESET_DEASSERT
+ global VALUE_RESET_ASSERT
+ VALUE_RESET_DEASSERT = 1
+ VALUE_RESET_ASSERT = 0
+
+def invert_maskrom():
+ global VALUE_MASKROM_DEASSERT
+ global VALUE_MASKROM_ASSERT
+ VALUE_MASKROM_DEASSERT = 1
+ VALUE_MASKROM_ASSERT = 0
+
+def do_status(dev):
+ resetstate = cp210x_controller.get_gpio(dev, GPIO_RESET)
+ bootmode = cp210x_controller.get_gpio(dev, GPIO_MASKROM)
+ print "Board is {} ({})".format(
+ ("running" if reset == RESETSTATE_DEASSERTED else "in reset"),
+ ("normal boot" if bootmode == VALUE_MASKROM_DEASSERTED else "boot to maskrom"))
+
+def do_reset_assert(dev):
+ cp210x_controller.set_gpio(dev, GPIO_RESET, VALUE_RESET_ASSERT)
+
+def do_reset_deassert(dev):
+ cp210x_controller.set_gpio(dev, GPIO_RESET, VALUE_RESET_DEASSERT)
+
+def do_reset(dev):
+ cp210x_controller.set_gpio(dev, GPIO_RESET, VALUE_RESET_ASSERT)
+ time.sleep(0.3)
+ cp210x_controller.set_gpio(dev, GPIO_RESET, VALUE_RESET_DEASSERT)
+
+def do_normalboot(dev):
+ cp210x_controller.set_gpio(dev, GPIO_MASKROM, VALUE_MASKROM_DEASSERT)
+
+def do_maskrom(dev):
+ cp210x_controller.set_gpio(dev, GPIO_MASKROM, VALUE_MASKROM_ASSERT)
+
+def do_reset_to_normal(dev):
+ cp210x_controller.set_gpio(dev, GPIO_MASKROM, VALUE_MASKROM_DEASSERT)
+ cp210x_controller.set_gpio(dev, GPIO_RESET, VALUE_RESET_ASSERT)
+ time.sleep(0.3)
+ cp210x_controller.set_gpio(dev, GPIO_RESET, VALUE_RESET_DEASSERT)
+
+def do_reset_to_maskrom(dev):
+ cp210x_controller.set_gpio(dev, GPIO_MASKROM, VALUE_MASKROM_ASSERT)
+ cp210x_controller.set_gpio(dev, GPIO_RESET, VALUE_RESET_ASSERT)
+ time.sleep(0.3)
+ cp210x_controller.set_gpio(dev, GPIO_RESET, VALUE_RESET_DEASSERT)
+ time.sleep(0.3)
+ cp210x_controller.set_gpio(dev, GPIO_MASKROM, VALUE_MASKROM_DEASSERT)
+
+def main(product_string):
+ options_dict = {
+ '--invert-reset': (invert_reset,
+ 'invert voltage level of reset line'),
+ '--invert-maskrom': (invert_maskrom,
+ 'invert voltage level of maskrom line')
+ }
+
+ command_dict = {
+ 'status': (do_status,
+ 'show status of attached board'),
+ 'reset-assert': (do_reset_assert,
+ 'assert the reset line'),
+ 'reset-deassert': (do_reset_deassert,
+ 'deassert the reset line'),
+ 'reset': (do_reset,
+ 'assert the reset line for 300 ms'),
+ 'normalboot': (do_normalboot,
+ 'set bootmode to normal boot'),
+ 'maskrom': (do_maskrom,
+ 'set bootmode to maskrom'),
+ 'reset-to-normal': (do_reset_to_normal,
+ 'reset with normal boot target'),
+ 'reset-to-maskrom': (do_reset_to_maskrom,
+ 'reset to maskrom')
+ }
+
+ # Create argparser object
+ cp = command_processor.CommandProcessor(product_string, options_dict,
+ command_dict)
+
+ # Valiate command line arguments and commands
+ cp.validate_commandline(sys.argv[1:])
+
+ # Start executing the commands
+ cp.run()
+