0d6d25039ecb38be3c7afbacbd6a4f2b81ee036b
4 from UserDict
import UserDict
6 from collections
import UserDict
9 class InterfacesBase(UserDict
):
10 """ contains a list of interface definitions
13 def __init__(self
, ifacekls
, pth
=None):
16 UserDict
.__init
__(self
, {})
19 ift
= 'interfaces.txt'
21 ift
= os
.path
.join(pth
, ift
)
22 with
open(ift
, 'r') as ifile
:
23 for ln
in ifile
.readlines():
26 name
= ln
[0] # will have uart
27 count
= int(ln
[1]) # will have count of uart
28 # spec looks like this:
30 [{'name': 'sda', 'outen': True},
31 {'name': 'scl', 'outen': True},
34 spec
, ganged
= self
.read_spec(pth
, name
)
35 # XXX HORRIBLE hack!!!
36 if name
== 'pwm' and count
== 1 and len(spec
) != 1:
37 #print "read", name, count, spec, ganged
38 #print "multi pwm", spec[:1], len(spec)
39 spec
[0]['name'] = 'out'
40 iface
= ifacekls(name
, spec
[:1], ganged
, False)
41 self
.ifaceadd(name
, len(spec
), iface
)
43 iface
= ifacekls(name
, spec
, ganged
, count
== 1)
44 self
.ifaceadd(name
, count
, iface
)
46 def getifacetype(self
, fname
):
47 # finds the interface type, e.g sd_d0 returns "inout"
48 for iface
in self
.values():
49 typ
= iface
.getifacetype(fname
)
50 # if fname.startswith('pwm'):
51 # print fname, iface.ifacename, typ
56 def ifaceadd(self
, name
, count
, iface
, at
=None):
58 at
= len(self
.ifacecount
) # ifacecount is a list
59 self
.ifacecount
.insert(at
, (name
, count
)) # appends the list
60 # with (name,count) *at* times
64 will check specific files of kind peripheral.txt like spi.txt,
65 uart.txt in test directory
68 def read_spec(self
, pth
, name
):
71 fname
= '%s.txt' % name
73 ift
= os
.path
.join(pth
, fname
)
74 with
open(ift
, 'r') as sfile
:
75 for ln
in sfile
.readlines():
79 d
= {'name': name
, # here we start to make the dictionary
82 d
['action'] = True # adding element to the dict
83 elif ln
[1] == 'inout':
89 ganged
[bus
].append(name
)