convert to python3
[pinmux.git] / src / spec / interfaces.py
index 03d7a2a9b1ea35679d71ed90ebedeaa1b75fcd92..f5ecf4817ba439b607a1909a4fcb6aa2589e2afd 100644 (file)
@@ -30,7 +30,11 @@ class PinGen(object):
         mux   : which column in the multiplexer
         start : the start of a subset of pins to be inserted
         limit : the end of the subset (or the number if start also given)
-        spec  : *EXTRA* pins to be inserted.
+        spec  : *EXTRA* pins to be inserted (at different implicit positions)
+
+        the pins are inserted with the suffix, starting from the
+        offset position using offs as the row and mux as the column,
+        and working in a constant increment down the rows.
 
         spec is slightly complicated, basically there's extra
         functions that we want to be on the same pin (but a different mux)
@@ -60,16 +64,31 @@ class PinGen(object):
         self.fname = fname
 
     def __call__(self, suffix, offs, mux,
-                 start=None, limit=None, spec=None, origsuffix=None):
+                 start=None, limit=None, spec=None, origsuffix=None,
+                 rev=False):
         bank = offs[0]
-        pingroup, gangedgroup = self.pinfn(suffix, bank)
+        pf = self.pinfn(suffix, bank)
+        print ("pf", suffix, bank, pf)
+        pingroup, gangedgroup, clock = pf
+        if clock:
+            self.pinouts.clocks[self.fname] = clock
         if isinstance(pingroup, tuple):
             prefix, pingroup = pingroup
         else:
             prefix = self.fname
         if start and limit:  # limit turns into an offset from start
             limit = start + limit
+        sk = "%s:%s" % (self.fname, str(suffix))
+        print ("pingroup pre", sk, pingroup)
         pingroup = pingroup[start:limit]  # see comment in spec.pinfunctions
+        if rev:
+            # reverse order of pingroup
+            pingroup.reverse()
+        print ("pingroup post", sk, pingroup)
+        if sk in self.pinouts.byspec:
+            self.pinouts.byspec[sk] += pingroup
+        else:
+            self.pinouts.byspec[sk] = deepcopy(pingroup)
         pins = Pins(prefix, pingroup, self.bankspec,
                     suffix, offs, bank, mux,
                     spec, origsuffix=suffix, gangedgrp=gangedgroup)
@@ -85,15 +104,21 @@ class Pinouts(object):
         self.pins = {}
         self.fnspec = {}
         self.ganged = {}
+        self.clocks = {}
+        self.byspec = {}
         for fname, pinfn in pinspec:
             if isinstance(pinfn, tuple):
                 name, pinfn = pinfn
             else:
                 name = pinfn.__name__
-            setattr(self, name, PinGen(self, fname, pinfn, self.bankspec))
+            pin = PinGen(self, fname, pinfn, self.bankspec)
+            setattr(self, name, pin)
 
     def setganged(self, fname, grp):
-        self.ganged[fname] = map(lambda x: x[:-1], grp)
+        grp = map(lambda x: x[:-1], grp)
+        if fname not in self.ganged:
+            self.ganged[fname] = []
+        self.ganged[fname] += grp
 
     def __contains__(self, k):
         return k in self.pins