stronger autopep8 whitespace cleanup
[pinmux.git] / src / bsv / actual_pinmux.py
index 76a0e2e0ca686f5bf7e132e30b88d501b1d775f9..7dd36655726aced033a5ccb76f26c495e61a5112 100644 (file)
@@ -5,23 +5,6 @@ except ImportError:
     maketrans = str.maketrans
 
 
-# dictionary of properties of signals that are supported.
-dictionary = {
-    "uart_rx"  : "input",
-    "uart_tx"  : "output",
-    "spi_sclk" : "output",
-    "spi_mosi" : "output",
-    "spi_ss"   : "output",
-    "spi_miso" : "input",
-    "twi_sda"  : "inout",
-    "twi_scl"  : "inout",
-    "sd_clk": "output",
-    "sd_cmd": "output",
-    "sd_d": "inout",
-    "pwm_pwm": "output"
-}
-
-
 # ============== common bsv templates ============ #
 # first argument is the io-cell number being assigned.
 # second argument is the mux value.
@@ -44,7 +27,15 @@ def cn(idx):
     return "cell%s_mux" % str(idx)
 
 
-def init(p):
+def transfn(temp):
+    temp = temp.split('_')
+    if len(temp) == 2:
+        temp[0] = temp[0].translate(digits)
+        temp[0] = temp[0] .replace(' ', '')
+    return '_'.join(temp)
+
+
+def init(p, ifaces):
     p.pinmux = ' '
     global dedicated_wire
     for cell in p.muxed_cells:
@@ -62,28 +53,28 @@ def init(p):
         # since the interfaces are always standard and cannot change from
         # user-to-user. Plus this also reduces human-error as well :)
         for i in range(0, len(cell) - 1):
-            temp = cell[i + 1].translate(digits)
-            temp = temp.replace(' ', '')
-            x = dictionary.get(temp)
+            cname = cell[i + 1]
+            temp = transfn(cname)
+            x = ifaces.getifacetype(temp)
+            print cname, temp, x
             assert x is not None, "ERROR: The signal : " + \
-                str(cell[i + 1]) + \
+                str(cname) + \
                 " of pinmap.txt isn't present \nin the current" + \
                 " dictionary. Update dictionary or fix-typo."
             if x == "input":
                 p.pinmux += \
-                    mux_wire.format(cell[0], i, "wr" + cell[i + 1]) + "\n"
+                    mux_wire.format(cell[0], i, "wr" + cname) + "\n"
             elif x == "inout":
                 p.pinmux += \
-                    mux_wire.format(cell[0], i, "wr" + cell[i + 1] +
+                    mux_wire.format(cell[0], i, "wr" + cname +
                                                 "_in") + "\n"
     # ============================================================ #
 
     # ==================  Logic for dedicated pins ========= #
     for cell in p.dedicated_cells:
-        p.pinmux += "      %s" % cn(cell[0]) + \
-            "_out=" + cell[1] + "_io;\n"
+        p.pinmux += "      %s_out=%s_io;\n" % (cn(cell[0]), cell[1])
         temp = cell[1].translate(digits)
-        x = dictionary.get(temp)
+        x = ifaces.getifacetype(temp)
         if x == "input":
             pinmux = pinmux + \
                 dedicated_wire.format(cell[0], "wr" + cell[1]) + "\n"