convert to python3
[pinmux.git] / src / spec / ifaceprint.py
index 810ed6bf555e479810ce2dd213d39ab4acd10713..8440ee5156e2b99455cd8389ac419307ec89ef82 100644 (file)
@@ -10,6 +10,7 @@ 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
@@ -87,13 +88,13 @@ def create_sv(fname, pins):
     woffs = scale*40#-width/2
     hoffs = scale*40#-height/2
 
-    nepads = bondmap['N'].keys()
+    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
@@ -129,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'))
@@ -265,6 +266,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()
@@ -284,55 +294,71 @@ def create_sv(fname, pins):
 
 
     # 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*0.0, hoffs+height-scale*1.5)
+    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, woffs+height/2+scale*4),
+                       insert=(woffs+width/2-scale*5, scale*8),
                      fill='black'))
 
     # add package marking circles
@@ -416,7 +442,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':
@@ -429,8 +455,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('_')
@@ -461,7 +487,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
 
@@ -477,20 +503,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():
@@ -502,7 +528,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))
@@ -558,10 +584,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:
@@ -623,10 +649,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])