fix(iomux): Fix port signal length (given mux size non-power of 2)
[pinmux.git] / src / spec / base.py
1 from spec.interfaces import Pinouts
2
3 from spec.ifaceprint import display, display_fns, check_functions
4 from spec.ifaceprint import display_fixed, python_dict_fns
5 from collections import OrderedDict
6
7
8 class PinSpec(Pinouts):
9 def __init__(self, pinbanks, fixedpins, function_names, fast=None):
10 self.fastbus = fast or {}
11 self.pinbanks = OrderedDict()
12 self.muxwidths = {}
13 for bank, (sz, muxwidth) in pinbanks.items():
14 self.pinbanks[bank] = sz
15 self.muxwidths[bank] = muxwidth
16 self.fixedpins = fixedpins
17 self.function_names = function_names
18 bankspec = OrderedDict()
19 self.offs = 0
20 pkeys = self.pinbanks.keys()
21 print (self.pinbanks)
22 for kn in pkeys:
23 bankspec[kn] = self.offs
24 self.offs += self.pinbanks[kn]
25
26 self.scenarios = []
27
28 Pinouts.__init__(self, bankspec)
29
30 def add_scenario(self, name, needed, eint, pwm, descriptions):
31 # Scenarios below can be spec'd out as either "find first interface"
32 # by name/number e.g. SPI0, or as "find in bank/mux" which must be
33 # spec'd as "BM:Name" where B is bank (A-F), M is Mux (0-3)
34 # EINT and PWM are grouped together, specially, but may still be spec'd
35 # using "BM:Name". Pins are removed in-order as listed from
36 # lists (interfaces, EINTs, PWMs) from available pins.
37
38 self.scenarios.append((name, needed, eint, pwm, descriptions))
39
40 def pywrite(self, pyf, pinmap):
41 return python_dict_fns(pyf, pinmap, self, self.function_names)
42
43 def write(self, of):
44
45 of.write("""# Pinouts (PinMux)
46 auto-generated by [[pinouts.py]]
47
48 [[!toc ]]
49
50 """)
51 bk = self.pinbanks.keys()
52 for bank in bk:
53 of.write(
54 "\n## Bank %s (%d pins, width %d)\n\n" %
55 (bank, self.pinbanks[bank], self.muxwidths[bank]))
56 display(of, self, bank, muxwidth=self.muxwidths[bank])
57
58 of.write("\n# Pinouts (Fixed function)\n\n")
59 fixedpins = display_fixed(of, self.fixedpins, len(self))
60
61 of.write("""# Functions (PinMux)
62
63 auto-generated by [[pinouts.py]]
64
65 """)
66 fns = display_fns(of, self.bankspec, self, self.function_names)
67 of.write('\n')
68
69 for scenario in self.scenarios:
70 name, needed, eint, pwm, descriptions = scenario
71 unused_pins = check_functions(of, name, self.bankspec, fns,
72 self,
73 needed, eint, pwm,
74 descriptions)
75
76 of.write("""# Reference Datasheets
77
78 datasheets and pinout links
79 * <https://ftp.libre-soc.org/STULPI01BTBR.en.CD00201527.pdf>
80 * <https://ftp.libre-soc.org/3300db.pdf>
81 * <https://ftp.libre-soc.org/1912111437_Realtek-Semicon-RTL8211F-CG_C187932.pdf>
82
83 * <http://datasheets.chipdb.org/AMD/8018x/80186/amd-80186.pdf>
84 * <http://hands.com/~lkcl/eoma/shenzen/frida/FRD144A2701.pdf>
85 * <http://pinouts.ru/Memory/sdcard_pinout.shtml>
86 * p8 <http://www.onfi.org/~/media/onfi/specs/onfi_2_0_gold.pdf?la=en>
87 * <https://www.heyrick.co.uk/blog/files/datasheets/dm9000aep.pdf>
88 * <http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4393.pdf>
89 * <https://www.nxp.com/docs/en/data-sheet/MCF54418.pdf>
90 * ULPI OTG PHY, ST <http://www.st.com/en/interfaces-and-transceivers/stulpi01a.html>
91 * ULPI OTG PHY, TI TUSB1210 <http://ti.com/product/TUSB1210/>
92
93 """)
94
95 return self, self.bankspec, self.pinbanks, fixedpins