convert to class style for peripheral gen
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 5 Aug 2018 14:41:13 +0000 (15:41 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 5 Aug 2018 14:41:13 +0000 (15:41 +0100)
src/bsv/peripheral_gen/base.py
src/bsv/peripheral_gen/gpio.py

index 6127a4e855494e0d9745b8258f19a9aeafc09f5f..1ac32c3a12edbe3188da0359ed0a174eb8101ef4 100644 (file)
@@ -851,7 +851,7 @@ class PeripheralInterfaces(object):
             for i in range(count):
                 if self.is_on_fastbus(name, i):
                     continue
-                res = self.data[name].mk_cellconn(cellcount, name, i)
+                res = self.data[name].mk_cellconn(name, i, cellcount)
                 if not res:
                     continue
                 (txt, cellcount) = res
@@ -868,12 +868,8 @@ class PeripheralInterfaces(object):
     def _mk_pincon(self, typ):
         ret = []
         for (name, count) in self.ifacecount:
-            for i in range(count):
-                if self.is_on_fastbus(name, i):
-                    continue
-                txt = self.data[name]._mk_pincon(name, i, typ)
-                ret.append(txt)
-        return '\n'.join(li(list(filter(None, ret)), 4))
+            ret += list(MkPinCon(self, name, count, typ))
+        return '\n'.join(li(list(ret), 4))
 
     def mk_dma_irq(self):
         ret = []
@@ -973,6 +969,44 @@ class PeripheralInterfaces(object):
             return iname not in self.fastbus
         return iname in self.fastbus
 
+class IfaceIter(object):
+
+    def __init__(self, name, count, *args):
+        self.i = 0
+        self.name = name
+        self.maxcount = count
+        self.args = args
+
+    def __iter__(self):
+        return self
+
+    def __next__(self):
+        while True:
+            if self.i > self.maxcount:
+                raise StopIteration
+            if self.check(self.name, self.i):
+                res = self.item(self.name, self.i, *self.args)
+                if res:
+                    self.i += 1
+                    return res
+            self.i += 1
+
+    def next(self):
+        return self.__next__()
+
+
+class MkPinCon(IfaceIter):
+
+    def __init__(self, ifaces, name, count, *args):
+        self.ifaces = ifaces
+        IfaceIter.__init__(self, name, count, *args)
+
+    def check(self, name, i):
+        return not self.ifaces.is_on_fastbus(name, i)
+
+    def item(self, name, i, typ):
+        return self.ifaces.data[name]._mk_pincon(name, i, typ)
+
 
 class PFactory(object):
     def getcls(self, name):
index d67ab8ffe93e50607e925b29341c79a55e5918df..73fd2a3efd4d8bb0d99e89cc44b9c8125c7b656f 100644 (file)
@@ -63,7 +63,7 @@ class gpio(PBase):
             return name[3:]
         return name[4:]
 
-    def mk_cellconn(self, cellnum, name, count):
+    def mk_cellconn(self, name, count, cellnum):
         ret = []
         bank = self.mksuffix(name, count)
         txt = "pinmux.mux_lines.cell{0}_mux(mux{1}.mux_config.mux[{2}]);"