diff python/devices.py @ 128:51cc127648e4

Splitup in interface and device
author Windel Bouwman
date Sun, 13 Jan 2013 17:31:35 +0100
parents
children 9e350a7dde98
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/devices.py	Sun Jan 13 17:31:35 2013 +0100
@@ -0,0 +1,43 @@
+import sys
+
+
+# Global device list to which devices are registered.
+deviceList = {}
+
+def registerDevice(chipId):
+   """ Decorator to register a device """
+   def wrapper(dev):
+      deviceList[chipId] = dev
+      return dev
+   return wrapper
+
+# Global interface dictionary.
+interfaces = {}
+
+def registerInterface(vid_pid):
+   def wrapper(iface):
+      interfaces[vid_pid] = iface
+      return iface
+   return wrapper
+
+class Device:
+   """
+      Base class for a device possibly connected via an interface.
+   """
+   pass
+
+class Interface:
+   """
+      Generic interface class. Connected via Usb to a JTAG interface.
+      Possibly is connected with a certain chip.
+   """
+   def getDevice(self):
+      """ Try to get the device connected to this interface """
+      if self.ChipId in deviceList:
+         return deviceList[self.ChipId](self)
+      raise STLinkException('No device found!')
+
+class STLinkException(Exception):
+   """ Exception used for interfaces and devices """
+   pass
+