annotate 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
rev   line source
128
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
1 import sys
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
2
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
3
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
4 # Global device list to which devices are registered.
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
5 deviceList = {}
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
6
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
7 def registerDevice(chipId):
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
8 """ Decorator to register a device """
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
9 def wrapper(dev):
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
10 deviceList[chipId] = dev
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
11 return dev
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
12 return wrapper
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
13
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
14 # Global interface dictionary.
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
15 interfaces = {}
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
16
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
17 def registerInterface(vid_pid):
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
18 def wrapper(iface):
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
19 interfaces[vid_pid] = iface
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
20 return iface
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
21 return wrapper
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
22
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
23 class Device:
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
24 """
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
25 Base class for a device possibly connected via an interface.
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
26 """
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
27 pass
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
28
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
29 class Interface:
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
30 """
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
31 Generic interface class. Connected via Usb to a JTAG interface.
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
32 Possibly is connected with a certain chip.
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
33 """
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
34 def getDevice(self):
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
35 """ Try to get the device connected to this interface """
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
36 if self.ChipId in deviceList:
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
37 return deviceList[self.ChipId](self)
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
38 raise STLinkException('No device found!')
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
39
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
40 class STLinkException(Exception):
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
41 """ Exception used for interfaces and devices """
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
42 pass
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents:
diff changeset
43