sort out JSON function missing and get mapping working
[pinmux.git] / src / spec / ifaceprint.py
index cb012660c3bc1ac9f8cacd58a59413f8682a221f..51f622a8aaf24c9ad1d40cf9ebf5d3ee78a7e761 100644 (file)
@@ -9,6 +9,8 @@ import base64
 cwd = os.path.split(os.path.abspath(__file__))[0]
 lead_drawing = cwd + "/greatek_qfp_128L.png"
 pack_drawing = cwd + "/greatek_qfp_128_fp.png"
+c4m_drawing = cwd + "/c4mlogo.png"
+ls180_drawing = cwd + "/ls180-img.png"
 
 def bond_int_to_ext(pin, bank):
     """ note that internal numbering is 0-31 whereas the DISPLAY internal
@@ -41,7 +43,7 @@ def bond_int_to_ext(pin, bank):
     if bank == 'W':
         if pin >= 29: # 29, 30, 31
             return 'N', pin-29, 100+(31-pin)
-        if pin <= 2:
+        if pin <= 2: # 0, 1, 2
             return 'S', 2-pin, 3-pin
         return 'W', 28-pin, 103+(28-pin)
     if bank == 'E':
@@ -49,7 +51,7 @@ def bond_int_to_ext(pin, bank):
             return 'N', 35+(31-pin), 67-(31-pin)
         if pin <= 2:
             return 'S', pin+35, 36+pin
-        return 'E', 28-pin, 39+(28-pin)
+        return 'E', 28-pin, 39+(pin-3)
 
 
 def create_sv(fname, pins):
@@ -86,10 +88,32 @@ def create_sv(fname, pins):
     woffs = scale*40#-width/2
     hoffs = scale*40#-height/2
 
+    nepads = list(bondmap['N'].keys())
+    nepads.sort()
+    wepads = list(bondmap['W'].keys())
+    wepads.sort()
+    eepads = list(bondmap['E'].keys())
+    eepads.sort()
+    sepads = list(bondmap['S'].keys())
+    sepads.sort()
+
+    owoffs = woffs + (width/2) - len(nepads)/2 * outerscale
+    ohoffs = hoffs + (height/2) - len(wepads)/2 * outerscale
+
     dwg = svgwrite.Drawing(fname, profile='full',
-                           size=(width+scale*80, height+scale*80))
+                           size=(width+scale*85, height+scale*80))
+
+    # outer QFP rect
+    dwg.add(dwg.rect((owoffs-scale*2.5, ohoffs-scale*4.5),
+                        (len(nepads)*outerscale+scale*9,
+                         len(wepads)*outerscale+scale*13),
+            fill='white',
+            stroke=svgwrite.rgb(0, 128, 0, '%'),
+            stroke_width=scale/5.0))
+
+    # inner lead rect
     dwg.add(dwg.rect((woffs-scale*2, hoffs-scale*2),
-                        (woffs+width-scale*34, hoffs+height-scale*34),
+                        (width+scale*6, height+scale*6),
             stroke=svgwrite.rgb(16, 255, 16, '%'),
             stroke_width=scale/10.0))
 
@@ -106,7 +130,7 @@ def create_sv(fname, pins):
                          endline,
                          stroke=svgwrite.rgb(16, 255, 16, '%'),
                          stroke_width=scale/10.0))
-        dwg.add(dwg.text(pin.upper(), insert=(woffs-scale*14, ht),
+        dwg.add(dwg.text(pin.upper(), insert=(woffs-scale*12, ht),
                          fill='black'))
         dwg.add(dwg.text("W%d" % (i+1), insert=(woffs-scale*1.5, ht),
                             fill='white'))
@@ -160,18 +184,333 @@ def create_sv(fname, pins):
         txt.rotate(90, pos)
         dwg.add(txt)
 
-    nepads = bondmap['N'].keys()
+    # north outer pads
+    for i in nepads:
+        (epinnum, ipin, bank) = pad = bondmap['N'][i]
+        wd = owoffs + i * outerscale + outerscale*1.5
+        endline = (wd, ohoffs-outerscale*2)
+        startline = innerpos[bank][ipin]
+        dwg.add(dwg.line(startline,
+                         endline,
+                         stroke=svgwrite.rgb(255, 16, 16, '%'),
+                         stroke_width=scale/10.0))
+        pin = pins[sidepad[bank]][ipin]
+        pos=(wd, ohoffs-outerscale*4.0)
+        txt = dwg.text("%s (%s%d)" % (pin.upper(), bank, ipin+1),
+                        insert=pos, fill='black')
+        txt.rotate(-90, pos)
+        dwg.add(txt)
+        pos=(wd, ohoffs-outerscale*2.5)
+        txt = dwg.text("%d N" % epinnum, insert=pos, fill='blue')
+        txt.rotate(-90, pos)
+        dwg.add(txt)
+
+    # west outer pads
+    for i in wepads:
+        (epinnum, ipin, bank) = pad = bondmap['W'][i]
+        ht = ohoffs + (i * outerscale) + outerscale*1.5
+        endline = (owoffs+outerscale*0.5, ht)
+        startline = innerpos[bank][ipin]
+        dwg.add(dwg.line(startline,
+                         endline,
+                         stroke=svgwrite.rgb(255, 16, 16, '%'),
+                         stroke_width=scale/10.0))
+        pin = pins[sidepad[bank]][ipin]
+        pos = (owoffs-outerscale*6.0, ht)
+        dwg.add(dwg.text("%s (%s%d)" % (pin.upper(), bank, ipin+1),
+                         pos,
+                         fill='black'))
+        pos = (owoffs-outerscale*1.0, ht)
+        dwg.add(dwg.text("%d W" % epinnum, insert=pos,
+                            fill='blue'))
+
+    # south outer pads
+    for i in sepads:
+        (epinnum, ipin, bank) = pad = bondmap['S'][i]
+        wd = owoffs + i * outerscale + outerscale*1.5
+        ht = ohoffs + len(wepads)*outerscale + outerscale*4
+        endline = (wd, ht)
+        startline = innerpos[bank][ipin]
+        dwg.add(dwg.line(startline,
+                         endline,
+                         stroke=svgwrite.rgb(255, 16, 16, '%'),
+                         stroke_width=scale/10.0))
+        pin = pins[sidepad[bank]][ipin]
+        pos=(wd-outerscale*0.25, ht+outerscale*1.5)
+        txt = dwg.text("%s (%s%d)" % (pin.upper(), bank, ipin+1),
+                        insert=pos, fill='black')
+        txt.rotate(90, pos)
+        dwg.add(txt)
+        pos=(wd-outerscale*0.25, ht+outerscale*0.5)
+        txt = dwg.text("%d S" % epinnum, insert=pos, fill='blue')
+        txt.rotate(90, pos)
+        dwg.add(txt)
+
+    # east outer pads
+    for i in eepads:
+        (epinnum, ipin, bank) = pad = bondmap['E'][i]
+        ht = ohoffs + (i * outerscale) + outerscale*1.5
+        wd = owoffs+len(nepads)*outerscale + outerscale*1
+        endline = (wd+outerscale*0.5, ht)
+        startline = innerpos[bank][ipin]
+        dwg.add(dwg.line(startline,
+                         endline,
+                         stroke=svgwrite.rgb(255, 16, 16, '%'),
+                         stroke_width=scale/10.0))
+        pin = pins[sidepad[bank]][ipin]
+        pos = (wd+outerscale*2.5, ht)
+        dwg.add(dwg.text("%s (%s%d)" % (pin.upper(), bank, ipin+1),
+                         pos,
+                         fill='black'))
+        pos = (wd+outerscale*1.0, ht)
+        dwg.add(dwg.text("%d E" % epinnum, insert=pos,
+                            fill='blue'))
+
+    # add ls180 image
+    image_data = open(ls180_drawing, "rb").read()
+    encoded = base64.b64encode(image_data).decode()
+    data = 'data:image/png;base64,{}'.format(encoded)
+    pos=(width/2+woffs-225, height/2+hoffs-225)
+    leads = svgwrite.image.Image(data, pos,
+                                       size=(480,480))
+    dwg.add(leads)
+
+    # add QFP pack image in top-right
+    image_data = open(pack_drawing, "rb").read()
+    encoded = base64.b64encode(image_data).decode()
+    data = 'data:image/png;base64,{}'.format(encoded)
+    pos=(0, 0)
+    leads = svgwrite.image.Image(data, pos,
+                                       size=(327,300))
+    dwg.add(leads)
+    dwg.add(dwg.text("GREATEK QFP128L",
+                       insert=(50,150),
+                        font_size=20,
+                     fill='black'))
+    dwg.add(dwg.text("D/W J1-03128-001",
+                       insert=(50,180),
+                        font_size=20,
+                     fill='black'))
+
+
+    # add QFP lead image in centre
+    sz=320
+    image_data = open(lead_drawing, "rb").read()
+    encoded = base64.b64encode(image_data).decode()
+    data = 'data:image/png;base64,{}'.format(encoded)
+    pos=(woffs+width+scale*23.5, 0)
+    leads = svgwrite.image.Image(data, pos,
+                                       size=(sz,sz))
+    leads.rotate(-90, (pos[0]+sz/2, pos[1]+sz/2))
+    dwg.add(leads)
+
+    dwg.add(dwg.text("GREATEK ELECTRONICS INC.",
+                       insert=(woffs+width+scale*29, scale*8),
+                     fill='black'))
+    dwg.add(dwg.text("INNER LEAD DRAWING",
+                       insert=(woffs+width+scale*29, scale*9),
+                     fill='black'))
+    dwg.add(dwg.text("QFP 128L OPEN STAMPING",
+                       insert=(woffs+width+scale*29, scale*10),
+                     fill='black'))
+    dwg.add(dwg.text("BODY 14x20x2.75mm",
+                       insert=(woffs+width+scale*29, scale*11),
+                     fill='black'))
+    dwg.add(dwg.text("L/F PAD SIZE 236x236mil^2",
+                       insert=(woffs+width+scale*29, scale*12),
+                     fill='black'))
+
+    # add C4M Logo
+    image_data = open(c4m_drawing, "rb").read()
+    encoded = base64.b64encode(image_data).decode()
+    data = 'data:image/png;base64,{}'.format(encoded)
+    pos=(woffs+scale*5.0, hoffs+height-scale*5.0)
+    leads = svgwrite.image.Image(data, pos,
+                                       size=(50,50))
+    dwg.add(leads)
+
+    if False:
+        # add SRAMs
+        for i in range(4):
+            dwg.add(dwg.rect((woffs+scale+75*i, hoffs+scale),
+                            (70,50),
+                fill='white',
+                stroke=svgwrite.rgb(16, 255, 16, '%'),
+                stroke_width=scale/10.0))
+        # add PLL
+        dwg.add(dwg.rect((woffs+width-scale, hoffs+scale),
+                            (25,20),
+                fill='white',
+                stroke=svgwrite.rgb(16, 255, 16, '%'),
+                stroke_width=scale/10.0))
+
+    # add attribution
+    dwg.add(dwg.text("Libre-SOC ls180 QFP-128",
+                       insert=(woffs+width/2-scale*5, scale*4),
+                     fill='black'))
+    dwg.add(dwg.text("In collaboration with LIP6.fr",
+                       insert=(woffs+width/2-scale*5, scale*5),
+                     fill='black'))
+    dwg.add(dwg.text("Cell Libraries by Chips4Makers",
+                       insert=(woffs+width/2-scale*5, scale*6),
+                     fill='black'))
+    dwg.add(dwg.text("IMEC TSMC 180nm",
+                       insert=(woffs+width/2-scale*5, scale*7),
+                     fill='black'))
+    dwg.add(dwg.text("RED Semiconductor",
+                       insert=(woffs+width/2-scale*5, scale*8),
+                     fill='black'))
+
+    # add package marking circles
+    pos = (owoffs-outerscale*0, ohoffs+len(wepads)*outerscale+outerscale*2.5)
+    dwg.add(dwg.circle(pos, scale*2,
+                         fill='white',
+                         stroke=svgwrite.rgb(16, 16, 16, '%'),
+                         stroke_width=scale/5.0))
+    dwg.add(dwg.circle(pos, scale*1,
+                         fill='black',
+                         stroke=svgwrite.rgb(255, 16, 16, '%'),
+                         stroke_width=scale/5.0))
+    pos = (owoffs+len(nepads)*outerscale+outerscale*2, ohoffs-outerscale*0.5)
+    dwg.add(dwg.circle(pos, scale*2,
+                         fill='white',
+                         stroke=svgwrite.rgb(16, 16, 16, '%'),
+                         stroke_width=scale/5.0))
+
+
+    dwg.save()
+
+def temp_create_sv(fname, pins):
+    """unsophisticated drawer of an SVG
+    """
+
+    try:
+        import svgwrite
+    except ImportError:
+        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'}
+    sidepad = {}
+    for pinpad, bank in padside.items():
+        sidepad[bank] = pinpad
+        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
+    outerscale = scale * 2.0
+
+    width = len(pins['pads.north']) * scale
+    height = len(pins['pads.east']) * scale
+    woffs = scale*40#-width/2
+    hoffs = scale*40#-height/2
+
+    nepads = list(bondmap['N'].keys())
     nepads.sort()
-    wepads = bondmap['W'].keys()
+    wepads = list(bondmap['W'].keys())
     wepads.sort()
-    eepads = bondmap['E'].keys()
+    eepads = list(bondmap['E'].keys())
     eepads.sort()
-    sepads = bondmap['S'].keys()
+    sepads = list(bondmap['S'].keys())
     sepads.sort()
 
     owoffs = woffs + (width/2) - len(nepads)/2 * outerscale
     ohoffs = hoffs + (height/2) - len(wepads)/2 * outerscale
 
+    dwg = svgwrite.Drawing(fname, profile='full',
+                           size=(width+scale*85, height+scale*80))
+
+    # outer QFP rect
+    # dwg.add(dwg.rect((owoffs-scale*2.5, ohoffs-scale*4.5),
+    dwg.add(dwg.rect((owoffs-scale*2.5, ohoffs-scale*4.5),
+                        (len(nepads)*outerscale+scale*9,
+                         len(wepads)*outerscale+scale*13),
+            fill='white',
+            stroke=svgwrite.rgb(0, 128, 0, '%'),
+            stroke_width=scale/5.0))
+
+    # inner lead rect
+    dwg.add(dwg.rect((woffs-scale*2, hoffs-scale*2),
+                        (width+scale*6, height+scale*6),
+            stroke=svgwrite.rgb(16, 255, 16, '%'),
+            stroke_width=scale/10.0))
+
+    # record the inner line (iopad) position so that the outer one can
+    # match with it
+    innerpos = {'N': {}, 'S': {},  'E': {},  'W': {} }
+
+    # create the inner diagram
+    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)
+        innerpos['W'][i] = endline
+        dwg.add(dwg.line((woffs-scale*2, 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),
+                         fill='black'))
+        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
+        endline = (wd+scale*4.5, ht-scale*0.5)
+        innerpos['E'][i] = endline
+        dwg.add(dwg.line((wd+scale*2, 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='white'))
+
+    for i, pin in enumerate(pins['pads.north']):
+        wd = woffs + i * scale + scale*1.5
+        endline = (wd, hoffs-scale*4.5)
+        innerpos['N'][i] = endline
+        dwg.add(dwg.line((wd, hoffs-scale*2),
+                         endline,
+                         stroke=svgwrite.rgb(16, 255, 16, '%'),
+                         stroke_width=scale/10.0))
+        pos=(wd, hoffs-scale*5.0)
+        txt = dwg.text(pin.upper(), insert=pos, fill='black')
+        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
+        endline = (wd, ht+scale*4.5)
+        innerpos['S'][i] = endline
+        dwg.add(dwg.line((wd, ht+scale*2),
+                         endline,
+                         stroke=svgwrite.rgb(16, 255, 16, '%'),
+                         stroke_width=scale/10.0))
+        pos=(wd-scale*0.25, ht+scale*5.0)
+        txt = dwg.text(pin.upper(), insert=pos, fill='black')
+        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)
+
     # north outer pads
     for i in nepads:
         (epinnum, ipin, bank) = pad = bondmap['N'][i]
@@ -238,7 +577,7 @@ def create_sv(fname, pins):
     for i in eepads:
         (epinnum, ipin, bank) = pad = bondmap['E'][i]
         ht = ohoffs + (i * outerscale) + outerscale*1.5
-        wd = owoffs+len(nepads)*outerscale
+        wd = owoffs+len(nepads)*outerscale + outerscale*1
         endline = (wd+outerscale*0.5, ht)
         startline = innerpos[bank][ipin]
         dwg.add(dwg.line(startline,
@@ -254,6 +593,15 @@ def create_sv(fname, pins):
         dwg.add(dwg.text("%d E" % epinnum, insert=pos,
                             fill='blue'))
 
+    # add ls180 image
+    image_data = open(ls180_drawing, "rb").read()
+    encoded = base64.b64encode(image_data).decode()
+    data = 'data:image/png;base64,{}'.format(encoded)
+    pos=(width/2+woffs-225, height/2+hoffs-225)
+    leads = svgwrite.image.Image(data, pos,
+                                       size=(480,480))
+    dwg.add(leads)
+
     # add QFP pack image in top-right
     image_data = open(pack_drawing, "rb").read()
     encoded = base64.b64encode(image_data).decode()
@@ -262,47 +610,101 @@ def create_sv(fname, pins):
     leads = svgwrite.image.Image(data, pos,
                                        size=(327,300))
     dwg.add(leads)
+    dwg.add(dwg.text("GREATEK QFP128L",
+                       insert=(50,150),
+                        font_size=20,
+                     fill='black'))
+    dwg.add(dwg.text("D/W J1-03128-001",
+                       insert=(50,180),
+                        font_size=20,
+                     fill='black'))
+
 
     # add QFP lead image in centre
+    sz=320
     image_data = open(lead_drawing, "rb").read()
     encoded = base64.b64encode(image_data).decode()
     data = 'data:image/png;base64,{}'.format(encoded)
-    pos=(woffs+scale*3.5, hoffs+scale*3.5)
+    pos=(woffs+width+scale*23.5, 0)
     leads = svgwrite.image.Image(data, pos,
-                                       size=(400,400))
-    leads.rotate(-90, (pos[0]+200, pos[1]+200))
+                                       size=(sz,sz))
+    leads.rotate(-90, (pos[0]+sz/2, pos[1]+sz/2))
     dwg.add(leads)
 
     dwg.add(dwg.text("GREATEK ELECTRONICS INC.",
-                       insert=(woffs+width/2-scale*5, woffs+height/2-scale*6),
+                       insert=(woffs+width+scale*29, scale*8),
                      fill='black'))
     dwg.add(dwg.text("INNER LEAD DRAWING",
-                       insert=(woffs+width/2-scale*5, woffs+height/2-scale*5),
+                       insert=(woffs+width+scale*29, scale*9),
                      fill='black'))
     dwg.add(dwg.text("QFP 128L OPEN STAMPING",
-                       insert=(woffs+width/2-scale*5, woffs+height/2-scale*4),
+                       insert=(woffs+width+scale*29, scale*10),
                      fill='black'))
     dwg.add(dwg.text("BODY 14x20x2.75mm",
-                       insert=(woffs+width/2-scale*5, woffs+height/2-scale*3),
+                       insert=(woffs+width+scale*29, scale*11),
                      fill='black'))
     dwg.add(dwg.text("L/F PAD SIZE 236x236mil^2",
-                       insert=(woffs+width/2-scale*5, woffs+height/2-scale*2),
+                       insert=(woffs+width+scale*29, scale*12),
                      fill='black'))
 
+    # add C4M Logo
+    image_data = open(c4m_drawing, "rb").read()
+    encoded = base64.b64encode(image_data).decode()
+    data = 'data:image/png;base64,{}'.format(encoded)
+    pos=(woffs+scale*5.0, hoffs+height-scale*5.0)
+    leads = svgwrite.image.Image(data, pos,
+                                       size=(50,50))
+    dwg.add(leads)
+
+    if False:
+        # add SRAMs
+        for i in range(4):
+            dwg.add(dwg.rect((woffs+scale+75*i, hoffs+scale),
+                            (70,50),
+                fill='white',
+                stroke=svgwrite.rgb(16, 255, 16, '%'),
+                stroke_width=scale/10.0))
+        # add PLL
+        dwg.add(dwg.rect((woffs+width-scale, hoffs+scale),
+                            (25,20),
+                fill='white',
+                stroke=svgwrite.rgb(16, 255, 16, '%'),
+                stroke_width=scale/10.0))
+
     # add attribution
     dwg.add(dwg.text("Libre-SOC ls180 QFP-128",
-                       insert=(woffs+width/2-scale*5, woffs+height/2),
+                       insert=(woffs+width/2-scale*5, scale*4),
                      fill='black'))
     dwg.add(dwg.text("In collaboration with LIP6.fr",
-                       insert=(woffs+width/2-scale*5, woffs+height/2+scale),
+                       insert=(woffs+width/2-scale*5, scale*5),
                      fill='black'))
     dwg.add(dwg.text("Cell Libraries by Chips4Makers",
-                       insert=(woffs+width/2-scale*5, woffs+height/2+scale*2),
+                       insert=(woffs+width/2-scale*5, scale*6),
                      fill='black'))
     dwg.add(dwg.text("IMEC TSMC 180nm",
-                       insert=(woffs+width/2-scale*5, woffs+height/2+scale*3),
+                       insert=(woffs+width/2-scale*5, scale*7),
+                     fill='black'))
+    dwg.add(dwg.text("RED Semiconductor",
+                       insert=(woffs+width/2-scale*5, scale*8),
                      fill='black'))
 
+    # add package marking circles
+    pos = (owoffs-outerscale*0, ohoffs+len(wepads)*outerscale+outerscale*2.5)
+    dwg.add(dwg.circle(pos, scale*2,
+                         fill='white',
+                         stroke=svgwrite.rgb(16, 16, 16, '%'),
+                         stroke_width=scale/5.0))
+    dwg.add(dwg.circle(pos, scale*1,
+                         fill='black',
+                         stroke=svgwrite.rgb(255, 16, 16, '%'),
+                         stroke_width=scale/5.0))
+    pos = (owoffs+len(nepads)*outerscale+outerscale*2, ohoffs-outerscale*0.5)
+    dwg.add(dwg.circle(pos, scale*2,
+                         fill='white',
+                         stroke=svgwrite.rgb(16, 16, 16, '%'),
+                         stroke_width=scale/5.0))
+
+
     dwg.save()
 
 
@@ -367,7 +769,7 @@ def find_fn(fname, names):
 def map_name(pinmap, fn, fblower, pin, rename):
     if not rename:
         if pin[:-1].isdigit():
-            print "map name digit", pin, fn, fblower
+            print ("map name digit", pin, fn, fblower)
             if fn in ['PWM', 'EINT', 'VDD', 'VSS']:
                 return fn.lower() + pin.lower()
         if fn == 'GPIO':
@@ -380,8 +782,8 @@ def map_name(pinmap, fn, fblower, pin, rename):
         pk = '%s%s_out' % (fblower, pin[:-1])
     else:
         pk = '%s_%s' % (fblower, pin[:-1])
-    print "map name", pk, fblower, pinmap.has_key(pk)
-    if not pinmap.has_key(pk):
+    print ("map name", pk, fblower, pk in pinmap)
+    if not pk in pinmap:
         return pin.lower()
     remapped = pinmap[pk]
     uscore = remapped.find('_')
@@ -412,7 +814,7 @@ def python_pindict(of, pinmap, pins, function_names, dname, remap):
                 of.write("\n                ")
                 count = 0
         of.write("]\n")
-        print "    dict %s" % dname, a, n, pingroup
+        print ("    dict %s" % dname, a, n, pingroup)
     of.write("\n\n")
     return res
 
@@ -428,20 +830,20 @@ def python_dict_fns(of, pinmap, pins, function_names):
     fnidx = list(fns.keys())
     fnidx.sort(key=fnsplit)
 
-    print "python fnames", function_names
-    print "python speckeys", pins.byspec.keys()
-    print "python dict fns", dir(pins.gpio)
-    print pins.gpio.pinfn('', '')
-    print pins.pwm.pinfn('', '')
-    print pins.sdmmc.pinfn('', '')
-    print "by spec", pins.byspec
-    print pinmap
+    print ("python fnames", function_names)
+    print ("python speckeys", pins.byspec.keys())
+    print ("python dict fns", dir(pins.gpio))
+    print (pins.gpio.pinfn('', ''))
+    print (pins.pwm.pinfn('', ''))
+    print (pins.sdmmc.pinfn('', ''))
+    print ("by spec", pins.byspec)
+    print (pinmap)
 
     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
+    print ("pd", pd)
+    print ("ld", ld)
     # process results and create name map
     litexmap = OrderedDict()
     for k in pd.keys():
@@ -453,7 +855,7 @@ def python_dict_fns(of, pinmap, pins, function_names):
             if k in ['eint', 'pwm', 'gpio', 'vdd', 'vss']: # sigh
                 lname = "%s_%s" % (k, lname)
             litexmap[pname] = lname
-    print "litexmap", litexmap
+    print ("litexmap", litexmap)
     of.write("litexmap = {\n")
     for k, v in litexmap.items():
         of.write("\t'%s': '%s',\n" % (k, v))
@@ -480,8 +882,10 @@ def display_fns(of, bankspec, pins, function_names):
     for fname in fnidx:
         fnbase = find_fn(fname, fn_names)
         #fblower = fnbase.lower()
-        assert fnbase in function_names, "fn %s not in descriptions %s" % \
-            (fname, str(function_names.keys()))
+        if fnbase not in function_names:
+            print ("fn %s not in descriptions %s" % \
+                (fname, str(function_names.keys())))
+            continue
         #print "name", fname, fnbase
         if fnbase != current_fn:
             if current_fn is not None:
@@ -509,10 +913,10 @@ def check_functions(of, title, bankspec, fns, pins, required, eint, pwm,
 
     of.write("# Pinmap for %s\n\n" % title)
 
-    print "fn_idx", fnidx
-    print "fns", fns
-    print "fnspec", pins.fnspec.keys()
-    print "required", required
+    print ("fn_idx", fnidx)
+    print ("fns", fns)
+    print ("fnspec", pins.fnspec.keys())
+    print ("required", required)
     for name in required:
         of.write("## %s\n\n" % name)
         if descriptions and name in descriptions:
@@ -574,10 +978,10 @@ def check_functions(of, title, bankspec, fns, pins, required, eint, pwm,
             removedcount += 1
             of.write("* %s %d %s%d/%d\n" % (fname, pin_, bank, pin, mux))
 
-        print fns
+        print (fns)
         if removedcount != count:
             if fname is None:
-                print "no match between required and available pins"
+                print ("no match between required and available pins")
             else:
                 print ("not all found", name, removedcount, count, title, found,
                    fns[fname])