add some documentation to the spec modules
[pinmux.git] / src / spec / pinfunctions.py
1 #!/usr/bin/env python
2
3 """ define functions here, with their pin names and the pin type.
4
5 each function returns a list (or an object with a __getitem__ function)
6 containing pin name plus type specifications.
7
8 the type is:
9
10 * "-" for an input pin,
11 * "+" for an output pin,
12 * "*" for an in/out pin
13
14 each function is then added to the pinspec tuple, below, as a ("NAME",
15 function) entry.
16
17 different functions may be added multiple times under the same NAME,
18 so that complex (or large) functions can be split into one or more
19 groups (and placed on different pinbanks).
20
21 eint, pwm and gpio are slightly odd in that instead of a fixed list
22 an object is returned with a __getitem__ function that accepts a
23 slice object. in this way the actual generation of the pin name
24 is delayed until it is known precisely how many pins are to be
25 generated, and that's not known immediately (or it would be if
26 every single one of the functions below had a start and end parameter
27 added). see spec.interfaces.PinGen class slice on pingroup
28 """
29
30 def i2s(suffix, bank):
31 return ['MCK+', 'BCK+', 'LRCK+', 'DI-', 'DO+']
32
33 def emmc(suffix, bank):
34 emmcpins = ['CMD+', 'CLK+']
35 for i in range(8):
36 emmcpins.append("D%d*" % i)
37 return emmcpins
38
39 def sdmmc(suffix, bank):
40 sdmmcpins = ['CMD+', 'CLK+']
41 for i in range(4):
42 sdmmcpins.append("D%d*" % i)
43 return sdmmcpins
44
45 def spi(suffix, bank):
46 return ['CLK*', 'NSS*', 'MOSI*', 'MISO*']
47
48 def quadspi(suffix, bank):
49 return ['CK*', 'NSS*', 'IO0*', 'IO1*', 'IO2*', 'IO3*']
50
51 def i2c(suffix, bank):
52 return ['SDA*', 'SCL*']
53
54 def jtag(suffix, bank):
55 return ['MS+', 'DI-', 'DO+', 'CK+']
56
57 def uart(suffix, bank):
58 return ['TX+', 'RX-']
59
60 def ulpi(suffix, bank):
61 ulpipins = ['CK+', 'DIR+', 'STP+', 'NXT+']
62 for i in range(8):
63 ulpipins.append('D%d*' % i)
64 return ulpipins
65
66 def uartfull(suffix, bank):
67 return ['TX+', 'RX-', 'CTS-', 'RTS+']
68
69 def rgbttl(suffix, bank):
70 ttlpins = ['CK+', 'DE+', 'HS+', 'VS+']
71 for i in range(24):
72 ttlpins.append("D%d+" % i)
73 return ttlpins
74
75 def rgmii(suffix, bank):
76 buspins = []
77 for i in range(4):
78 buspins.append("ERXD%d-" % i)
79 for i in range(4):
80 buspins.append("ETXD%d+" % i)
81 buspins += ['ERXCK-', 'ERXERR-', 'ERXDV-',
82 'EMDC+', 'EMDIO*',
83 'ETXEN+', 'ETXCK+', 'ECRS-',
84 'ECOL+', 'ETXERR+']
85 return buspins
86
87 def flexbus1(suffix, bank):
88 buspins = []
89 for i in range(8):
90 buspins.append("AD%d*" % i)
91 for i in range(2):
92 buspins.append("CS%d+" % i)
93 buspins += ['ALE', 'OE', 'RW', 'TA', 'CLK+',
94 'A0', 'A1', 'TS', 'TBST',
95 'TSIZ0', 'TSIZ1']
96 for i in range(4):
97 buspins.append("BWE%d" % i)
98 for i in range(2, 6):
99 buspins.append("CS%d+" % i)
100 return buspins
101
102 def flexbus2(suffix, bank):
103 buspins = []
104 for i in range(8, 32):
105 buspins.append("AD%d*" % i)
106 return buspins
107
108 def sdram1(suffix, bank):
109 buspins = []
110 for i in range(16):
111 buspins.append("SDRDQM%d*" % i)
112 for i in range(12):
113 buspins.append("SDRAD%d+" % i)
114 for i in range(8):
115 buspins.append("SDRDQ%d+" % i)
116 for i in range(3):
117 buspins.append("SDRCS%d#+" % i)
118 for i in range(2):
119 buspins.append("SDRDQ%d+" % i)
120 for i in range(2):
121 buspins.append("SDRBA%d+" % i)
122 buspins += ['SDRCKE+', 'SDRRAS#+', 'SDRCAS#+', 'SDRWE#+',
123 'SDRRST+']
124 return buspins
125
126 def sdram2(suffix, bank):
127 buspins = []
128 for i in range(3, 6):
129 buspins.append("SDRCS%d#+" % i)
130 for i in range(8, 32):
131 buspins.append("SDRDQ%d*" % i)
132 return buspins
133
134 def mcu8080(suffix, bank):
135 buspins = []
136 for i in range(8):
137 buspins.append("MCUD%d*" % i)
138 for i in range(8):
139 buspins.append("MCUAD%d+" % (i + 8))
140 for i in range(6):
141 buspins.append("MCUCS%d+" % i)
142 for i in range(2):
143 buspins.append("MCUNRB%d+" % i)
144 buspins += ['MCUCD+', 'MCURD+', 'MCUWR+', 'MCUCLE+', 'MCUALE+',
145 'MCURST+']
146 return buspins
147
148 class RangePin(object):
149 def __init__(self, suffix, prefix=None):
150 self.suffix = suffix
151 self.prefix = prefix or ''
152
153 def __getitem__(self, s):
154 res = []
155 for idx in range(s.start or 0, s.stop or -1, s.step or 1):
156 res.append("%s%d%s" % (self.prefix, idx, self.suffix))
157 return res
158
159 def eint(suffix, bank):
160 return RangePin("*")
161
162 def pwm(suffix, bank):
163 return RangePin("+")
164
165 def gpio(suffix, bank):
166 return ("GPIO%s" % bank, RangePin(prefix=bank, suffix="*"))
167
168
169 # list functions by name here
170
171 pinspec = (('IIS', i2s),
172 ('MMC', emmc),
173 ('SD', sdmmc),
174 ('SPI', spi),
175 ('QSPI', quadspi),
176 ('TWI', i2c),
177 ('JTAG', jtag),
178 ('UART', uart),
179 ('UARTQ', uartfull),
180 ('LCD', rgbttl),
181 ('ULPI', ulpi),
182 ('RG', rgmii),
183 ('FB', flexbus1),
184 ('FB', flexbus2),
185 ('SDR', sdram1),
186 ('SDR', sdram2),
187 ('EINT', eint),
188 ('PWM', pwm),
189 ('GPIO', gpio),
190 )
191