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]
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
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:
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:
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)