add internal-to-external bond number conversion
[pinmux.git] / src / spec / ifaceprint.py
index b4a499bbf0c02933b458e3c5e05a0909725b538b..f8ba09d4e2bc20aae985946699d895afb9059d5e 100644 (file)
@@ -4,6 +4,47 @@ from copy import deepcopy
 from collections import OrderedDict
 from math import pi
 
+def bond_int_to_ext(pin, bank):
+    """ note that internal numbering is 0-31 whereas the DISPLAY internal
+        numbering is 1-32.  this uses the INTERNAL numbering.
+
+        side: N S E W
+
+        outer ring numbers: the python list order of the outer pads
+        middle numbers: the package number wires (plus side they are on)
+        inner numbers:  the IO pad *python internal (0-31)* numbers plus side
+
+       0     1   2      3   N  34     35   36   37
+      N102 N101 N100    99  N  68    N67  N66  N65
+      W29  W30  W31     N0  N N31    E29  E30  E31
+
+    25  103 W28                       E28  64 25
+     W    W  W                         E  E   E
+     0  128 W3                        E3  39  0
+
+      W2  W1   W0      S0   S S31    E0   E1   E2
+      S1  S2   S3       4   S  35    S36  S37  S38
+       0     1   2      3   S  34     35   36   37
+
+    """
+    # returns side, order-on-the-side, pin number
+    if bank == 'N':
+        return 'N', pin+3, 99-pin
+    if bank == 'S':
+        return 'S', pin+3, 4+pin
+    if bank == 'W':
+        if pin >= 29: # 29, 30, 31
+            return 'N', pin-29, 100+(31-pin)
+        if pin <= 2:
+            return 'S', 2-pin, 3-pin
+        return 'W', pin-3, 103+(28-pin)
+    if bank == 'E':
+        if pin >= 29:
+            return 'N', pin+6, 67-(pin-29)
+        if pin <= 2:
+            return 'S', pin+35, 36+pin
+        return 'E', pin-3, 39+(pin-3)
+
 
 def create_sv(fname, pins):
     """unsophisticated drawer of an SVG
@@ -15,16 +56,30 @@ def create_sv(fname, pins):
         print ("WARNING, no SVG image, not producing image %s" % fname)
         return
 
+    # create internal to external map
+    bondmap = {'N': {}, 'S': {},  'E': {},  'W': {} }
+    padside = {'pads.north': 'N', 'pads.east': 'E', 'pads.south': 'S',
+               'pads.west': 'W'}
+    for pinpad, bank in padside.items():
+        for ipin in range(len(pins[pinpad])):
+            eside, enum, epinnum = bond_int_to_ext(ipin, bank)
+            bondmap[eside][enum] = (epinnum, ipin, bank)
+    with open("/tmp/bondmap.txt", "w") as f:
+        for k,v in bondmap.items():
+            f.write("%s\n" % k)
+            for enum, (epinnum, ipin, bank) in v.items():
+                f.write("    %d %d  -> %s %d\n" % (enum, epinnum, bank, ipin))
+
     scale = 15
     width = len(pins['pads.north']) * scale
     height = len(pins['pads.east']) * scale
-    woffs = scale*18#-width/2
-    hoffs = scale*18#-height/2
+    woffs = scale*40#-width/2
+    hoffs = scale*40#-height/2
 
     dwg = svgwrite.Drawing(fname, profile='full',
-                           size=(width+scale*40, height+scale*40))
+                           size=(width+scale*80, height+scale*80))
     dwg.add(dwg.rect((woffs-scale*2, hoffs-scale*2),
-                        (woffs+width-scale*12, hoffs+height-scale*12),
+                        (woffs+width-scale*34, hoffs+height-scale*34),
             stroke=svgwrite.rgb(16, 255, 16, '%'),
             stroke_width=scale/10.0))
 
@@ -38,33 +93,37 @@ def create_sv(fname, pins):
                        insert=(woffs+width/2-scale*5, woffs+height/2+scale*2),
                      fill='white'))
 
+    outerpos = {'N': {}, 'S': {},  'E': {},  'W': {} }
     for i, pin in enumerate(pins['pads.west']):
         ht = hoffs + height - (i * scale) + scale*0.5
+        endline = (woffs-scale*4.5, ht-scale*0.5)
         dwg.add(dwg.line((woffs-scale*2, ht-scale*0.5),
-                         (woffs-scale*4.5, ht-scale*0.5),
+                         endline,
                          stroke=svgwrite.rgb(16, 255, 16, '%'),
                          stroke_width=scale/10.0))
-        dwg.add(dwg.text(pin.upper(), insert=(woffs-scale*12, ht),
+        dwg.add(dwg.text(pin.upper(), insert=(woffs-scale*14, ht),
                          fill='black'))
         dwg.add(dwg.text("W%d" % (i+1), insert=(woffs-scale*1.5, ht),
-                            fill='black'))
+                            fill='white'))
 
     for i, pin in enumerate(pins['pads.east']):
         ht = hoffs + height - (i * scale) + scale*0.5
         wd = width + woffs + scale*2
+        endline = (wd+scale*4.5, ht-scale*0.5)
         dwg.add(dwg.line((wd+scale*2, ht-scale*0.5),
-                         (wd+scale*4.5, ht-scale*0.5),
+                         endline,
                          stroke=svgwrite.rgb(16, 255, 16, '%'),
                          stroke_width=scale/10.0))
         dwg.add(dwg.text(pin.upper(), insert=(wd+scale*5, ht-scale*0.25),
                          fill='black'))
         dwg.add(dwg.text("E%d" % (i+1), insert=(wd, ht-scale*0.25),
-                            fill='black'))
+                            fill='white'))
 
     for i, pin in enumerate(pins['pads.north']):
         wd = woffs + i * scale + scale*1.5
+        endline = (wd, hoffs-scale*4.5)
         dwg.add(dwg.line((wd, hoffs-scale*2),
-                         (wd, hoffs-scale*4.5),
+                         endline,
                          stroke=svgwrite.rgb(16, 255, 16, '%'),
                          stroke_width=scale/10.0))
         pos=(wd, hoffs-scale*5.0)
@@ -72,15 +131,16 @@ def create_sv(fname, pins):
         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='black')
+        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
+        endline = (wd, ht+scale*4.5)
         dwg.add(dwg.line((wd, ht+scale*2),
-                         (wd, ht+scale*4.5),
+                         endline,
                          stroke=svgwrite.rgb(16, 255, 16, '%'),
                          stroke_width=scale/10.0))
         pos=(wd-scale*0.25, ht+scale*5.0)
@@ -88,7 +148,7 @@ def create_sv(fname, pins):
         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='black')
+        txt = dwg.text("S%d" % (i+1), insert=pos, fill='white')
         txt.rotate(90, pos)
         dwg.add(txt)