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