add not-connected pads to ls180
[pinmux.git] / src / spec / ifaceprint.py
index d0f50d7e3d09653ffb8ccc27c72c2415966830f2..dba37e651a426fea980a2d4783d293fe3682d7f5 100644 (file)
@@ -61,12 +61,81 @@ def find_fn(fname, names):
         if fname.startswith(n):
             return n
 
+def map_name(pinmap, fn, fblower, pin, rename):
+    if not rename:
+        if pin[:-1].isdigit():
+            print "map name digit", pin, fn, fblower
+            if fn in ['PWM', 'EINT', 'VDD', 'VSS']:
+                return fn.lower() + pin.lower()
+        if fn == 'GPIO':
+            return 'gpio' + pin[1:].lower()
+        return pin.lower()
+    pin = pin.lower()
+    if fn == 'GPIO':
+        pk = '%s%s_%s' % (fblower, pin[0], pin[:-1])
+    elif pin[:-1].isdigit() and fn != 'EINT':
+        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):
+        return pin.lower()
+    remapped = pinmap[pk]
+    uscore = remapped.find('_')
+    if uscore == -1:
+        return pin.lower()
+    fn, pin = remapped[:uscore], remapped[uscore+1:] + pin[-1]
+    return pin.lower()
+
+def python_pindict(of, pinmap, pins, function_names, dname, remap):
+
+    of.write("%s = {\n" % dname)
+
+    for k, pingroup in pins.byspec.items():
+        (a, n) = k.split(":")
+        if n.isdigit():
+            a = "%s%s" % (a, n)
+        fblower = a.lower()
+        of.write("    '%s': [ " % fblower)
+        count = 0
+        for i, p in enumerate(pingroup):
+            of.write("'%s', " % map_name(pinmap, k[0], fblower, p, remap))
+            count += 1
+            if count == 4 and i != len(pingroup)-1:
+                of.write("\n                ")
+                count = 0
+        of.write("],\n")
+        print "    dict %s" % dname, a, n, pingroup
+    of.write("}\n\n")
+
+def python_dict_fns(of, pinmap, pins, function_names):
+    of.write("# auto-generated by Libre-SOC pinmux program: do not edit\n")
+    of.write("# python src/pinmux_generator.py -v -s {spec} -o {output}\n")
+
+    fn_names = function_names.keys()
+    fns = {}
+
+    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
+
+    python_pindict(of, {}, pins, function_names, 'pindict', False)
+    python_pindict(of, pinmap, pins, function_names, 'litexdict', True)
+
 
 def display_fns(of, bankspec, pins, function_names):
     fn_names = function_names.keys()
     fns = {}
     for (pin, pdata) in pins.items():
-        for mux in range(1, 4):  # skip GPIO for now
+        for mux in range(0, 4):  # skip GPIO for now
             if mux not in pdata:
                 continue
             name, bank = pdata[mux]
@@ -80,6 +149,7 @@ def display_fns(of, bankspec, pins, function_names):
     current_fn = None
     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()))
         #print "name", fname, fnbase
@@ -110,7 +180,9 @@ 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
     for name in required:
         of.write("## %s\n\n" % name)
         if descriptions and name in descriptions:
@@ -158,7 +230,9 @@ def check_functions(of, title, bankspec, fns, pins, required, eint, pwm,
 
         pinidx = sorted(pinfound.keys())
 
+        fname = None
         removedcount = 0
+        print ("pinidx", pinidx)
         for pin_ in pinidx:
             fname, pin_, bank, pin, mux = pinfound[pin_]
             if fname in found:
@@ -172,7 +246,10 @@ def check_functions(of, title, bankspec, fns, pins, required, eint, pwm,
 
         print fns
         if removedcount != count:
-            print ("not all found", name, removedcount, count, title, found,
+            if fname is None:
+                print "no match between required and available pins"
+            else:
+                print ("not all found", name, removedcount, count, title, found,
                    fns[fname])
             print ("pins found", pinfound)