add SVG generator
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 10 Jun 2021 20:51:57 +0000 (21:51 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 10 Jun 2021 20:51:57 +0000 (21:51 +0100)
src/pinmux_generator.py
src/spec/ifaceprint.py

index 52267f4870cfe536f181d37287b5fa5f7b01a889..859634eb4a76f1e83666d32945d20504ff9c8630 100644 (file)
@@ -21,6 +21,7 @@ import os.path
 import sys
 import json
 from spec import modules, specgen, dummytest
+from spec.ifaceprint import create_sv
 
 
 def printhelp():
@@ -99,10 +100,10 @@ if __name__ == '__main__':
                             ps.fastbus)
                 pm, chip = module.pinparse(ps, pinspec)
                 litexmap = ps.pywrite(pyf, pm)
-                chip = json.dumps(chip)
+                jchip = json.dumps(chip)
                 with open("%s/litex_pinpads.json" % pinspec, "w") as f:
-                    f.write(chip)
-
+                    f.write(jchip)
+                create_sv("%s/%s.svg" % (pinspec, pinspec), chip)
     else:
         if output_type == 'bsv':
             from bsv.pinmux_generator import pinmuxgen as gentypes
index 808985ce5f4fa884939bbb217e73672508f385dd..7ac7a26f9d03c56c7edc27806baf0866bb213545 100644 (file)
@@ -2,6 +2,82 @@
 
 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))
+    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):
     of.write("""\