stronger autopep8 whitespace cleanup
[pinmux.git] / src / spec / gen.py
index 2f859eb278ef7a07977056c3ab3d6199e1e5f034..36b815e87c846e11f689ed68e14d7422d0749984 100644 (file)
@@ -2,13 +2,13 @@ import os
 import os.path
 from spec.interfaces import Pinouts
 
+
 def specgen(pth, pinouts, bankspec, fixedpins):
     """ generates a specification of pinouts (tsv files)
         for reading in by pinmux
     """
     pth = pth or ''
     #print bankspec.keys()
-    #print pinouts.keys()
     #print fixedpins.keys()
     if not os.path.exists(pth):
         os.makedirs(pth)
@@ -16,16 +16,45 @@ def specgen(pth, pinouts, bankspec, fixedpins):
         for k in pinouts.fnspec.keys():
             s = pinouts.fnspec[k]
             f.write("%s\t%d\n" % (k.lower(), len(s)))
-            s0 = s[s.keys()[0]] # hack, take first
+            s0 = s[s.keys()[0]]  # hack, take first
             with open(os.path.join(pth, '%s.txt' % k.lower()), 'w') as g:
-                if len(s0.pingroup) == 1: # only one function, grouped higher up
+                if len(s0.pingroup) == 1:  # only one function, grouped higher
                     for ks in s.keys():  # grouped by interface
-                        k = "%s_%s" % (s[ks].fname, s[ks].suffix)
+                        assert False, "TODO, single-function"
+                        fntype = 'inout'  # XXX TODO
+                        k = s[ks].suffix
                         k_ = k.lower()
                         g.write("%s\t%s\n" % (k_, fntype))
                 else:
                     for pinname in s0.pingroup:
                         fntype = s0.fntype.get(pinname, 'inout')
-                        k_ = k.lower()
                         pn = pinname.lower()
-                        g.write("%s_%s\t%s\n" % (k_, pn, fntype))
+                        g.write("%s\t%s\n" % (pn, fntype))
+
+    pks = sorted(pinouts.keys())
+
+    # truly dreadful way to work out the max mux size...
+    muxsz = 0
+    for k in pks:
+        for m in pinouts[k].keys():
+            muxsz = max(muxsz, m + 1)
+
+    # write out the mux...
+    with open(os.path.join(pth, 'pinmap.txt'), 'w') as g:
+        for k in pks:
+            res = [str(k)]
+            # append pin mux
+            for midx in range(muxsz):
+                if midx in pinouts[k]:
+                    fname = pinouts[k][midx][0]
+                else:
+                    fname = ''
+                res.append(fname.lower())
+            g.write('\t'.join(res) + '\n')
+
+    # ... and the dedicated pins
+    with open(os.path.join(pth, 'fixedpins.txt'), 'w') as g:
+        for p in fixedpins:
+            p = map(str, p)
+            p = map(str.lower, p)
+            g.write('\t'.join(p) + '\n')