convert to python3
[pinmux.git] / src / spec / interfaces.py
index 77086f246bf7d0b5caca608e26027710d45b1e5b..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,20 +64,36 @@ 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 = 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)
-        self.pinouts.pinmerge(pins)
+                    spec, origsuffix=suffix, gangedgrp=gangedgroup)
+        fname = self.pinouts.pinmerge(pins)
+        self.pinouts.setganged(fname, gangedgroup)
 
 # pinouts class
 
@@ -83,12 +103,22 @@ class Pinouts(object):
         self.bankspec = bankspec
         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):
+        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
@@ -164,11 +194,13 @@ class Pinouts(object):
         for (pinidx, v) in fn.pins.items():
             self.update(pinidx, v)
 
+        return fname
+
 
 class Pins(object):
 
     def __init__(self, fname, pingroup, bankspec, suffix, offs, bank, mux,
-                 spec=None, limit=None, origsuffix=None):
+                 spec=None, limit=None, origsuffix=None, gangedgrp=None):
 
         # function type can be in, out or inout, represented by - + *
         # strip function type out of each pin name
@@ -187,6 +219,7 @@ class Pins(object):
 
         self.fname = fname
         self.pingroup = pingroup
+        self.gangedgroup = gangedgrp
         self.bankspec = bankspec
         self.suffix = suffix
         self.origsuffix = origsuffix or suffix