add naming and pin-order reverse option
[pinmux.git] / src / spec / ifaceprint.py
index 3d3cfb4b27662b58e348dacc8202eb8e2184c0bc..4a4104f41ded15c4acef89733e56dc6e62ec9909 100644 (file)
@@ -1,6 +1,93 @@
 #!/usr/bin/env python
 
 from copy import deepcopy
+from collections import OrderedDict
+import svgwrite
+from math import pi
+
+
+def create_sv(fname, pins):
+    """unsophisticated drawer of an SVG
+    """
+
+    scale = 15
+    width = len(pins['pads.north']) * scale
+    height = len(pins['pads.east']) * scale
+    woffs = scale*18#-width/2
+    hoffs = scale*18#-height/2
+
+    dwg = svgwrite.Drawing(fname, profile='full',
+                           size=(width+scale*40, height+scale*40))
+    dwg.add(dwg.rect((woffs-scale*2, hoffs-scale*2),
+                        (woffs+width-scale*12, hoffs+height-scale*12),
+            stroke=svgwrite.rgb(255, 255, 16, '%'),
+            stroke_width=scale/10.0))
+
+    dwg.add(dwg.text("Libre-SOC ls180",
+                       insert=(woffs+width/2-scale*5, woffs+height/2),
+                     fill='white'))
+    dwg.add(dwg.text("In collaboration with LIP6.fr",
+                       insert=(woffs+width/2-scale*5, woffs+height/2+scale),
+                     fill='white'))
+    dwg.add(dwg.text("Cell Libraries by Chips4Makers",
+                       insert=(woffs+width/2-scale*5, woffs+height/2+scale*2),
+                     fill='white'))
+
+    for i, pin in enumerate(pins['pads.west']):
+        ht = hoffs + height - (i * scale) + scale*0.5
+        dwg.add(dwg.line((woffs-scale*2, ht-scale*0.5),
+                         (woffs-scale*4.5, ht-scale*0.5),
+                         stroke=svgwrite.rgb(255, 255, 16, '%'),
+                         stroke_width=scale/10.0))
+        dwg.add(dwg.text(pin.upper(), insert=(woffs-scale*12, ht),
+                         fill='white'))
+        dwg.add(dwg.text("W%d" % (i+1), insert=(woffs-scale*1.5, ht),
+                            fill='white'))
+
+    for i, pin in enumerate(pins['pads.east']):
+        ht = hoffs + height - (i * scale) + scale*0.5
+        wd = width + woffs + scale*2
+        dwg.add(dwg.line((wd+scale*2, ht-scale*0.5),
+                         (wd+scale*4.5, ht-scale*0.5),
+                         stroke=svgwrite.rgb(255, 255, 16, '%'),
+                         stroke_width=scale/10.0))
+        dwg.add(dwg.text(pin.upper(), insert=(wd+scale*5, ht-scale*0.25),
+                         fill='white'))
+        dwg.add(dwg.text("E%d" % (i+1), insert=(wd, ht-scale*0.25),
+                            fill='white'))
+
+    for i, pin in enumerate(pins['pads.north']):
+        wd = woffs + i * scale + scale*1.5
+        dwg.add(dwg.line((wd, hoffs-scale*2),
+                         (wd, hoffs-scale*4.5),
+                         stroke=svgwrite.rgb(255, 255, 16, '%'),
+                         stroke_width=scale/10.0))
+        pos=(wd, hoffs-scale*5.0)
+        txt = dwg.text(pin.upper(), insert=pos, fill='white')
+        txt.rotate(-90, pos)
+        dwg.add(txt)
+        pos=(wd+scale*0.25, hoffs-scale*0.25)
+        txt = dwg.text("N%d" % (i+1), insert=pos, fill='white')
+        txt.rotate(-90, pos)
+        dwg.add(txt)
+
+    for i, pin in enumerate(pins['pads.south']):
+        wd = woffs + i * scale + scale*1.5
+        ht = hoffs + height + scale*2
+        dwg.add(dwg.line((wd, ht+scale*2),
+                         (wd, ht+scale*4.5),
+                         stroke=svgwrite.rgb(255, 255, 16, '%'),
+                         stroke_width=scale/10.0))
+        pos=(wd-scale*0.25, ht+scale*5.0)
+        txt = dwg.text(pin.upper(), insert=pos, fill='white')
+        txt.rotate(90, pos)
+        dwg.add(txt)
+        pos=(wd-scale*0.25, ht+scale*0.25)
+        txt = dwg.text("S%d" % (i+1), insert=pos, fill='white')
+        txt.rotate(90, pos)
+        dwg.add(txt)
+
+    dwg.save()
 
 
 def display(of, pins, banksel=None, muxwidth=4):
@@ -89,6 +176,7 @@ def map_name(pinmap, fn, fblower, pin, rename):
 
 def python_pindict(of, pinmap, pins, function_names, dname, remap):
 
+    res = OrderedDict()
     of.write("\n%s = OrderedDict()\n" % dname)
 
     for k, pingroup in pins.byspec.items():
@@ -97,9 +185,12 @@ def python_pindict(of, pinmap, pins, function_names, dname, remap):
             a = "%s%s" % (a, n)
         fblower = a.lower()
         of.write("%s['%s'] = [ " % (dname, fblower))
+        res[fblower] = []
         count = 0
         for i, p in enumerate(pingroup):
-            of.write("'%s', " % map_name(pinmap, k[0], fblower, p, remap))
+            name = map_name(pinmap, k[0], fblower, p, remap)
+            res[fblower].append(name)
+            of.write("'%s', " % name)
             count += 1
             if count == 4 and i != len(pingroup)-1:
                 of.write("\n                ")
@@ -107,6 +198,7 @@ def python_pindict(of, pinmap, pins, function_names, dname, remap):
         of.write("]\n")
         print "    dict %s" % dname, a, n, pingroup
     of.write("\n\n")
+    return res
 
 def python_dict_fns(of, pinmap, pins, function_names):
     of.write("# auto-generated by Libre-SOC pinmux program: do not edit\n")
@@ -129,8 +221,28 @@ def python_dict_fns(of, pinmap, pins, function_names):
     print "by spec", pins.byspec
     print pinmap
 
-    python_pindict(of, {}, pins, function_names, 'pindict', False)
-    python_pindict(of, pinmap, pins, function_names, 'litexdict', True)
+    pd = python_pindict(of, {}, pins, function_names, 'pindict', False)
+    ld = python_pindict(of, pinmap, pins, function_names, 'litexdict', True)
+
+    print "pd", pd
+    print "ld", ld
+    # process results and create name map
+    litexmap = OrderedDict()
+    for k in pd.keys():
+        pl = pd[k]
+        ll = ld[k]
+        for pname, lname in zip(pl, ll):
+            pname = "%s_%s" % (k, pname[:-1]) # strip direction +/-/*
+            lname = lname[:-1] # strip direction +/-/*
+            if k in ['eint', 'pwm', 'gpio', 'vdd', 'vss']: # sigh
+                lname = "%s_%s" % (k, lname)
+            litexmap[pname] = lname
+    print "litexmap", litexmap
+    of.write("litexmap = {\n")
+    for k, v in litexmap.items():
+        of.write("\t'%s': '%s',\n" % (k, v))
+    of.write("}\n")
+    return litexmap
 
 
 def display_fns(of, bankspec, pins, function_names):