3 from copy
import deepcopy
4 from collections
import OrderedDict
8 def create_sv(fname
, pins
):
9 """unsophisticated drawer of an SVG
15 print ("WARNING, no SVG image, not producing image %s" % fname
)
19 width
= len(pins
['pads.north']) * scale
20 height
= len(pins
['pads.east']) * scale
21 woffs
= scale
*18#-width/2
22 hoffs
= scale
*18#-height/2
24 dwg
= svgwrite
.Drawing(fname
, profile
='full',
25 size
=(width
+scale
*40, height
+scale
*40))
26 dwg
.add(dwg
.rect((woffs
-scale
*2, hoffs
-scale
*2),
27 (woffs
+width
-scale
*12, hoffs
+height
-scale
*12),
28 stroke
=svgwrite
.rgb(16, 255, 16, '%'),
29 stroke_width
=scale
/10.0))
31 dwg
.add(dwg
.text("Libre-SOC ls180 QFP-128",
32 insert
=(woffs
+width
/2-scale
*5, woffs
+height
/2),
34 dwg
.add(dwg
.text("In collaboration with LIP6.fr",
35 insert
=(woffs
+width
/2-scale
*5, woffs
+height
/2+scale
),
37 dwg
.add(dwg
.text("Cell Libraries by Chips4Makers",
38 insert
=(woffs
+width
/2-scale
*5, woffs
+height
/2+scale
*2),
41 for i
, pin
in enumerate(pins
['pads.west']):
42 ht
= hoffs
+ height
- (i
* scale
) + scale
*0.5
43 dwg
.add(dwg
.line((woffs
-scale
*2, ht
-scale
*0.5),
44 (woffs
-scale
*4.5, ht
-scale
*0.5),
45 stroke
=svgwrite
.rgb(16, 255, 16, '%'),
46 stroke_width
=scale
/10.0))
47 dwg
.add(dwg
.text(pin
.upper(), insert
=(woffs
-scale
*14, ht
),
49 dwg
.add(dwg
.text("W%d" % (i
+1), insert
=(woffs
-scale
*1.5, ht
),
52 for i
, pin
in enumerate(pins
['pads.east']):
53 ht
= hoffs
+ height
- (i
* scale
) + scale
*0.5
54 wd
= width
+ woffs
+ scale
*2
55 dwg
.add(dwg
.line((wd
+scale
*2, ht
-scale
*0.5),
56 (wd
+scale
*4.5, ht
-scale
*0.5),
57 stroke
=svgwrite
.rgb(16, 255, 16, '%'),
58 stroke_width
=scale
/10.0))
59 dwg
.add(dwg
.text(pin
.upper(), insert
=(wd
+scale
*5, ht
-scale
*0.25),
61 dwg
.add(dwg
.text("E%d" % (i
+1), insert
=(wd
, ht
-scale
*0.25),
64 for i
, pin
in enumerate(pins
['pads.north']):
65 wd
= woffs
+ i
* scale
+ scale
*1.5
66 dwg
.add(dwg
.line((wd
, hoffs
-scale
*2),
67 (wd
, hoffs
-scale
*4.5),
68 stroke
=svgwrite
.rgb(16, 255, 16, '%'),
69 stroke_width
=scale
/10.0))
70 pos
=(wd
, hoffs
-scale
*5.0)
71 txt
= dwg
.text(pin
.upper(), insert
=pos
, fill
='black')
74 pos
=(wd
+scale
*0.25, hoffs
-scale
*0.25)
75 txt
= dwg
.text("N%d" % (i
+1), insert
=pos
, fill
='black')
79 for i
, pin
in enumerate(pins
['pads.south']):
80 wd
= woffs
+ i
* scale
+ scale
*1.5
81 ht
= hoffs
+ height
+ scale
*2
82 dwg
.add(dwg
.line((wd
, ht
+scale
*2),
84 stroke
=svgwrite
.rgb(16, 255, 16, '%'),
85 stroke_width
=scale
/10.0))
86 pos
=(wd
-scale
*0.25, ht
+scale
*5.0)
87 txt
= dwg
.text(pin
.upper(), insert
=pos
, fill
='black')
90 pos
=(wd
-scale
*0.25, ht
+scale
*0.25)
91 txt
= dwg
.text("S%d" % (i
+1), insert
=pos
, fill
='black')
98 def display(of
, pins
, banksel
=None, muxwidth
=4):
100 | Pin | Mux0 | Mux1 | Mux2 | Mux3 |
101 | --- | ----------- | ----------- | ----------- | ----------- |
103 pinidx
= sorted(pins
.keys())
105 pdata
= pins
.get(pin
)
108 for mux
in range(muxwidth
):
111 name
, bank
= pdata
[mux
]
116 res
= '| %3d |' % pin
117 for mux
in range(muxwidth
):
121 name
, bank
= pdata
[mux
]
122 res
+= " %s %-9s |" % (bank
, name
)
123 of
.write("%s\n" % res
)
129 if not f
.startswith('FB_'):
133 return f2
[0], int(f2
[1])
136 while f
and not f
[0].isdigit():
139 return a
, int(f
) if f
else None
151 def find_fn(fname
, names
):
153 if fname
.startswith(n
):
156 def map_name(pinmap
, fn
, fblower
, pin
, rename
):
158 if pin
[:-1].isdigit():
159 print "map name digit", pin
, fn
, fblower
160 if fn
in ['PWM', 'EINT', 'VDD', 'VSS']:
161 return fn
.lower() + pin
.lower()
163 return 'gpio' + pin
[1:].lower()
167 pk
= '%s%s_%s' % (fblower
, pin
[0], pin
[:-1])
168 elif pin
[:-1].isdigit() and fn
!= 'EINT':
169 pk
= '%s%s_out' % (fblower
, pin
[:-1])
171 pk
= '%s_%s' % (fblower
, pin
[:-1])
172 print "map name", pk
, fblower
, pinmap
.has_key(pk
)
173 if not pinmap
.has_key(pk
):
175 remapped
= pinmap
[pk
]
176 uscore
= remapped
.find('_')
179 fn
, pin
= remapped
[:uscore
], remapped
[uscore
+1:] + pin
[-1]
182 def python_pindict(of
, pinmap
, pins
, function_names
, dname
, remap
):
185 of
.write("\n%s = OrderedDict()\n" % dname
)
187 for k
, pingroup
in pins
.byspec
.items():
188 (a
, n
) = k
.split(":")
192 of
.write("%s['%s'] = [ " % (dname
, fblower
))
195 for i
, p
in enumerate(pingroup
):
196 name
= map_name(pinmap
, k
[0], fblower
, p
, remap
)
197 res
[fblower
].append(name
)
198 of
.write("'%s', " % name
)
200 if count
== 4 and i
!= len(pingroup
)-1:
204 print " dict %s" % dname
, a
, n
, pingroup
208 def python_dict_fns(of
, pinmap
, pins
, function_names
):
209 of
.write("# auto-generated by Libre-SOC pinmux program: do not edit\n")
210 of
.write("# python src/pinmux_generator.py -v -s {spec} -o {output}\n")
211 of
.write("# use OrderedDict to fix stable order for JTAG Boundary Scan\n")
212 of
.write("from collections import OrderedDict\n")
214 fn_names
= function_names
.keys()
217 fnidx
= list(fns
.keys())
218 fnidx
.sort(key
=fnsplit
)
220 print "python fnames", function_names
221 print "python speckeys", pins
.byspec
.keys()
222 print "python dict fns", dir(pins
.gpio
)
223 print pins
.gpio
.pinfn('', '')
224 print pins
.pwm
.pinfn('', '')
225 print pins
.sdmmc
.pinfn('', '')
226 print "by spec", pins
.byspec
229 pd
= python_pindict(of
, {}, pins
, function_names
, 'pindict', False)
230 ld
= python_pindict(of
, pinmap
, pins
, function_names
, 'litexdict', True)
234 # process results and create name map
235 litexmap
= OrderedDict()
239 for pname
, lname
in zip(pl
, ll
):
240 pname
= "%s_%s" % (k
, pname
[:-1]) # strip direction +/-/*
241 lname
= lname
[:-1] # strip direction +/-/*
242 if k
in ['eint', 'pwm', 'gpio', 'vdd', 'vss']: # sigh
243 lname
= "%s_%s" % (k
, lname
)
244 litexmap
[pname
] = lname
245 print "litexmap", litexmap
246 of
.write("litexmap = {\n")
247 for k
, v
in litexmap
.items():
248 of
.write("\t'%s': '%s',\n" % (k
, v
))
253 def display_fns(of
, bankspec
, pins
, function_names
):
254 fn_names
= function_names
.keys()
256 for (pin
, pdata
) in pins
.items():
257 for mux
in range(0, 4): # skip GPIO for now
260 name
, bank
= pdata
[mux
]
261 assert name
is not None, str(bank
)
264 fns
[name
].append((pin
- bankspec
[bank
], mux
, bank
))
266 fnidx
= list(fns
.keys())
267 fnidx
.sort(key
=fnsplit
)
270 fnbase
= find_fn(fname
, fn_names
)
271 #fblower = fnbase.lower()
272 assert fnbase
in function_names
, "fn %s not in descriptions %s" % \
273 (fname
, str(function_names
.keys()))
274 #print "name", fname, fnbase
275 if fnbase
!= current_fn
:
276 if current_fn
is not None:
278 of
.write("## %s\n\n%s\n\n" % (fnbase
, function_names
[fnbase
]))
280 of
.write("* %-9s :" % fname
)
281 for (pin
, mux
, bank
) in fns
[fname
]:
282 of
.write(" %s%d/%d" % (bank
, pin
, mux
))
288 def check_functions(of
, title
, bankspec
, fns
, pins
, required
, eint
, pwm
,
291 pins
= deepcopy(pins
)
292 if descriptions
is None:
299 of
.write("# Pinmap for %s\n\n" % title
)
301 print "fn_idx", fnidx
303 print "fnspec", pins
.fnspec
.keys()
304 print "required", required
305 for name
in required
:
306 of
.write("## %s\n\n" % name
)
307 if descriptions
and name
in descriptions
:
308 of
.write("%s\n\n" % descriptions
[name
])
310 name
= name
.split(':')
312 findbank
= name
[0][0]
313 findmux
= int(name
[0][1:])
319 name
= name
.split('/')
330 if not fname
.startswith(name
):
332 for k
in pins
.fnspec
.keys():
333 if fname
.startswith(k
):
334 fk
= list(pins
.fnspec
[k
].keys())
337 #print fname, fn, dir(fn)
339 count
= len(fn
.pingroup
)
340 for pin
, mux
, bank
in fns
[fname
]:
341 if findbank
is not None:
346 pin_
= pin
+ bankspec
[bank
]
348 pinfound
[pin_
] = (fname
, pin_
, bank
, pin
, mux
)
350 pinidx
= sorted(pinfound
.keys())
354 print ("pinidx", pinidx
)
356 fname
, pin_
, bank
, pin
, mux
= pinfound
[pin_
]
360 if len(found
) > count
:
364 of
.write("* %s %d %s%d/%d\n" % (fname
, pin_
, bank
, pin
, mux
))
367 if removedcount
!= count
:
369 print "no match between required and available pins"
371 print ("not all found", name
, removedcount
, count
, title
, found
,
373 print ("pins found", pinfound
)
380 for name
in descriptions
.keys():
381 if not name
.startswith('GPIO'):
389 of
.write("## GPIO\n\n")
395 if descriptions
and fname
in descriptions
:
396 desc
= ': %s' % descriptions
[fname
]
399 pin_
= pin
+ bankspec
[bank
]
404 of
.write("* %-8s %d %s%-2d %s\n" % (fname
, pin_
, bank
, pin
, desc
))
408 display_group(of
, bankspec
, "EINT", eint
, fns
, pins
, descriptions
)
410 display_group(of
, bankspec
, "PWM", pwm
, fns
, pins
, descriptions
)
412 of
.write("## Unused Pinouts (spare as GPIO) for '%s'\n\n" % title
)
413 if descriptions
and 'GPIO' in descriptions
:
414 of
.write("%s\n\n" % descriptions
['GPIO'])
421 def display_group(of
, bankspec
, title
, todisplay
, fns
, pins
, descriptions
):
422 of
.write("## %s\n\n" % title
)
425 for fname
in todisplay
:
427 if descriptions
and fname
in descriptions
:
428 desc
= ': %s' % descriptions
[fname
]
429 fname
= fname
.split(':')
431 findbank
= fname
[0][0]
432 findmux
= int(fname
[0][1:])
438 for (pin
, mux
, bank
) in fns
[fname
]:
439 if findbank
is not None:
446 pin_
= pin
+ bankspec
[bank
]
451 of
.write("* %s %d %s%d/%d %s\n" %
452 (fname
, pin_
, bank
, pin
, mux
, desc
))
456 def display_fixed(of
, fixed
, offs
):
458 fkeys
= sorted(fixed
.keys())
461 for pin
, k
in enumerate(fkeys
):
462 of
.write("## %s\n\n" % k
)
465 for name
in fixed
[k
]:
469 if prevname
[:2] == name
[:2] and linecount
!= 0:
470 of
.write(" %s" % name
)
475 of
.write("* %d: %d %s" % (pin_
, pin
, name
))
477 res
.append((pin_
, name
))