stronger autopep8 whitespace cleanup
[pinmux.git] / src / spec / gen.py
1 import os
2 import os.path
3 from spec.interfaces import Pinouts
4
5
6 def specgen(pth, pinouts, bankspec, fixedpins):
7 """ generates a specification of pinouts (tsv files)
8 for reading in by pinmux
9 """
10 pth = pth or ''
11 #print bankspec.keys()
12 #print fixedpins.keys()
13 if not os.path.exists(pth):
14 os.makedirs(pth)
15 with open(os.path.join(pth, 'interfaces.txt'), 'w') as f:
16 for k in pinouts.fnspec.keys():
17 s = pinouts.fnspec[k]
18 f.write("%s\t%d\n" % (k.lower(), len(s)))
19 s0 = s[s.keys()[0]] # hack, take first
20 with open(os.path.join(pth, '%s.txt' % k.lower()), 'w') as g:
21 if len(s0.pingroup) == 1: # only one function, grouped higher
22 for ks in s.keys(): # grouped by interface
23 assert False, "TODO, single-function"
24 fntype = 'inout' # XXX TODO
25 k = s[ks].suffix
26 k_ = k.lower()
27 g.write("%s\t%s\n" % (k_, fntype))
28 else:
29 for pinname in s0.pingroup:
30 fntype = s0.fntype.get(pinname, 'inout')
31 pn = pinname.lower()
32 g.write("%s\t%s\n" % (pn, fntype))
33
34 pks = sorted(pinouts.keys())
35
36 # truly dreadful way to work out the max mux size...
37 muxsz = 0
38 for k in pks:
39 for m in pinouts[k].keys():
40 muxsz = max(muxsz, m + 1)
41
42 # write out the mux...
43 with open(os.path.join(pth, 'pinmap.txt'), 'w') as g:
44 for k in pks:
45 res = [str(k)]
46 # append pin mux
47 for midx in range(muxsz):
48 if midx in pinouts[k]:
49 fname = pinouts[k][midx][0]
50 else:
51 fname = ''
52 res.append(fname.lower())
53 g.write('\t'.join(res) + '\n')
54
55 # ... and the dedicated pins
56 with open(os.path.join(pth, 'fixedpins.txt'), 'w') as g:
57 for p in fixedpins:
58 p = map(str, p)
59 p = map(str.lower, p)
60 g.write('\t'.join(p) + '\n')