whoops, order of functions incorrect
[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
42 python_dict_fns(pyf, pinmap, self, self.function_names)
43
44 def write(self, of):
45
46 of.write("""# Pinouts (PinMux)
47 auto-generated by [[pinouts.py]]
48
49 [[!toc ]]
50
51 """)
52 bk = self.pinbanks.keys()
53 for bank in bk:
54 of.write(
55 "\n## Bank %s (%d pins, width %d)\n\n" %
56 (bank, self.pinbanks[bank], self.muxwidths[bank]))
57 display(of, self, bank, muxwidth=self.muxwidths[bank])
58
59 of.write("\n# Pinouts (Fixed function)\n\n")
60 fixedpins = display_fixed(of, self.fixedpins, len(self))
61
62 of.write("""# Functions (PinMux)
63
64 auto-generated by [[pinouts.py]]
65
66 """)
67 fns = display_fns(of, self.bankspec, self, self.function_names)
68 of.write('\n')
69
70 for scenario in self.scenarios:
71 name, needed, eint, pwm, descriptions = scenario
72 unused_pins = check_functions(of, name, self.bankspec, fns,
73 self,
74 needed, eint, pwm,
75 descriptions)
76
77 of.write("""# Reference Datasheets
78
79 datasheets and pinout links
80
81 * <http://datasheets.chipdb.org/AMD/8018x/80186/amd-80186.pdf>
82 * <http://hands.com/~lkcl/eoma/shenzen/frida/FRD144A2701.pdf>
83 * <http://pinouts.ru/Memory/sdcard_pinout.shtml>
84 * p8 <http://www.onfi.org/~/media/onfi/specs/onfi_2_0_gold.pdf?la=en>
85 * <https://www.heyrick.co.uk/blog/files/datasheets/dm9000aep.pdf>
86 * <http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4393.pdf>
87 * <https://www.nxp.com/docs/en/data-sheet/MCF54418.pdf>
88 * ULPI OTG PHY, ST <http://www.st.com/en/interfaces-and-transceivers/stulpi01a.html>
89 * ULPI OTG PHY, TI TUSB1210 <http://ti.com/product/TUSB1210/>
90
91 """)
92
93 return self, self.bankspec, self.pinbanks, fixedpins