+ def gen_pinmux_dict(self, ps):
+ #print("---------------------------------")
+ #with open("test.mdwn", "w") as of:
+ # pinout, bankspec, pin_spec, fixedpins = ps.write(of)
+ #print("---------------------------------")
+ #print(ps.items())
+ #print(ps.byspec)
+ #print(ps.fnspec)
+ # TODO: get from ps
+ self.requested = {}
+ self.n_ports = 4
+ self.port = Signal(log2_int(self.n_ports))
+ self.pads = {}
+ self.muxes = {}
+
+ # Create local list of peripheral names defined in pinfunctions.py
+ defined_func = []
+ for pfunc in pinspec:
+ defined_func.append(pfunc[0])
+
+ for pin in ps.items():
+ pin_no = pin[0]
+ for mux in pin[1].keys():
+ bank = pin[1][mux][1]
+ signal_str = pin[1][mux][0]
+ pad = "%s%d" % (bank, pin_no)
+ # Get the signal name prefix
+ index_under = signal_str.find('_')
+ """
+ periph format: [periph+suffix]
+ GPIO periph format: [periph+bank+suffix]
+ Problem is that GPIO has a different suffix to UART/TWI.
+ Assuming that other peripherals may have their own name formats.
+ keep stripping last chars from string until remainder matches
+ one of the existing peripheral names
+ probably very inefficient...
+ NO ERROR CHECKING
+ """
+ periph = signal_str[:index_under]
+ func = signal_str[index_under+1:]
+ while periph != '':
+ if periph in defined_func:
+ break # Found valid periph
+ periph = periph.rstrip(periph[-1])
+
+ # flag for peripheral string, needed as GPIO has a diff format
+ # to UART and TWI, TODO: may need to check for other periph
+ if periph == "GPIO":
+ check_string = periph + bank
+ else:
+ check_string = periph
+
+ # Find the suffix for the specified periph/pin
+ suffix = ''
+ for a in ps.fnspec.items():
+ for key in a[1]:
+ if check_string in key:
+ print(key, a[1][key])
+ suffix = a[1][key].suffix
+ else:
+ continue
+
+ # key to use in PinSpec.byspec has format: [perith+':'+suffix]
+ # need to get the suffix from Pin object
+ #index = len(periph)
+ #print(signal_str[index:index_under])
+ signal = ''
+ for sig_spec in ps.byspec[periph+':'+suffix]:
+ if func in sig_spec:
+ signal = sig_spec
+ #suffix = ps.fnspec[fnspec_key][fnspec_key]
+ print(pad, signal_str, signal_str[:index_under],
+ periph, func, suffix, signal, mux)
+ print("Now adding to internal pinmux dict")
+ if not (pad in self.requested.keys()):
+ self.requested[pad] = {}
+ self.requested[pad][mux] = {"periph":periph, "suffix":suffix,
+ "signal":signal}
+ print(self.requested)
+