AddingPeripherals.mdwn
[pinmux.git] / src / bsv / peripheral_gen / twi.py
index 4c0d815b3a9032334e4ad3ebe5fa7b0ff450f89a..02d3718acf40904e02a7ca5448dca109a2257294 100644 (file)
@@ -1,19 +1,23 @@
 from bsv.peripheral_gen.base import PBase
 
+
 class twi(PBase):
 
     def slowimport(self):
-        return "    import I2C_top           :: *;"
+        return "import I2C_top           :: *;"
+
+    def irq_name(self):
+        return "twi{0}_isint"
 
     def slowifdecl(self):
-        return "            interface I2C_out twi{0}_out;\n" + \
-               "            method Bit#(1) twi{0}_isint;"
+        return "interface I2C_out twi{0}_out;\n" + \
+               "method Bit#(1) %s;" % self.irq_name()
 
     def num_axi_regs32(self):
         return 8
 
     def mkslow_peripheral(self, size=0):
-        return "        I2C_IFC twi{0} <- mkI2CController();"
+        return "I2C_IFC twi{0} <- mkI2CController();"
 
     def _mk_connection(self, name=None, count=0):
         return "twi{0}.slave_i2c_axi"
@@ -30,11 +34,6 @@ class twi(PBase):
         return {'sda': 'out.sda_out_en',
                 'scl': 'out.scl_out_en'}.get(pname, '')
 
-    def pinname_tweak(self, pname, typ, txt):
-        if typ == 'outen':
-            return "pack({0})".format(txt)
-        return txt
-
     def num_irqs(self):
         return 3
 
@@ -42,13 +41,12 @@ class twi(PBase):
         return ["{0}.isint()",
                 "{0}.timerint()",
                 "{0}.isber()"
-               ][idx].format(pname)
+                ][idx].format(pname)
 
     def mk_ext_ifacedef(self, iname, inum):
         name = self.get_iname(inum)
-        return "        method {0}_isint = {0}.isint;".format(name)
-
-    def slowifdeclmux(self):
-        return "        method Bit#(1) {1}{0}_isint;"
-
+        return "method {0}_isint = {0}.isint;".format(name)
 
+    def slowifdeclmux(self, name, inum):
+        sname = self.get_iname(inum)
+        return "method Bit#(1) %s_isint;" % sname