3 from copy
import deepcopy
6 def display(of
, pins
, banksel
=None, muxwidth
=4):
8 | Pin | Mux0 | Mux1 | Mux2 | Mux3 |
9 | --- | ----------- | ----------- | ----------- | ----------- |
11 pinidx
= sorted(pins
.keys())
16 for mux
in range(muxwidth
):
19 name
, bank
= pdata
[mux
]
25 for mux
in range(muxwidth
):
29 name
, bank
= pdata
[mux
]
30 res
+= " %s %-9s |" % (bank
, name
)
31 of
.write("%s\n" % res
)
37 if not f
.startswith('FB_'):
41 return f2
[0], int(f2
[1])
44 while f
and not f
[0].isdigit():
47 return a
, int(f
) if f
else None
59 def find_fn(fname
, names
):
61 if fname
.startswith(n
):
65 def display_fns(of
, bankspec
, pins
, function_names
):
66 fn_names
= function_names
.keys()
68 for (pin
, pdata
) in pins
.items():
69 for mux
in range(0, 4): # skip GPIO for now
72 name
, bank
= pdata
[mux
]
73 assert name
is not None, str(bank
)
76 fns
[name
].append((pin
- bankspec
[bank
], mux
, bank
))
78 fnidx
= list(fns
.keys())
79 fnidx
.sort(key
=fnsplit
)
82 fnbase
= find_fn(fname
, fn_names
)
83 #fblower = fnbase.lower()
84 assert fnbase
in function_names
, "fn %s not in descriptions %s" % \
85 (fname
, str(function_names
.keys()))
86 #print "name", fname, fnbase
87 if fnbase
!= current_fn
:
88 if current_fn
is not None:
90 of
.write("## %s\n\n%s\n\n" % (fnbase
, function_names
[fnbase
]))
92 of
.write("* %-9s :" % fname
)
93 for (pin
, mux
, bank
) in fns
[fname
]:
94 of
.write(" %s%d/%d" % (bank
, pin
, mux
))
100 def check_functions(of
, title
, bankspec
, fns
, pins
, required
, eint
, pwm
,
103 pins
= deepcopy(pins
)
104 if descriptions
is None:
111 of
.write("# Pinmap for %s\n\n" % title
)
113 print "fn_idx", fnidx
115 print "fnspec", pins
.fnspec
.keys()
116 print "required", required
117 for name
in required
:
118 of
.write("## %s\n\n" % name
)
119 if descriptions
and name
in descriptions
:
120 of
.write("%s\n\n" % descriptions
[name
])
122 name
= name
.split(':')
124 findbank
= name
[0][0]
125 findmux
= int(name
[0][1:])
131 name
= name
.split('/')
142 if not fname
.startswith(name
):
144 for k
in pins
.fnspec
.keys():
145 if fname
.startswith(k
):
146 fk
= list(pins
.fnspec
[k
].keys())
149 #print fname, fn, dir(fn)
151 count
= len(fn
.pingroup
)
152 for pin
, mux
, bank
in fns
[fname
]:
153 if findbank
is not None:
158 pin_
= pin
+ bankspec
[bank
]
160 pinfound
[pin_
] = (fname
, pin_
, bank
, pin
, mux
)
162 pinidx
= sorted(pinfound
.keys())
166 print ("pinidx", pinidx
)
168 fname
, pin_
, bank
, pin
, mux
= pinfound
[pin_
]
172 if len(found
) > count
:
176 of
.write("* %s %d %s%d/%d\n" % (fname
, pin_
, bank
, pin
, mux
))
179 if removedcount
!= count
:
181 print "no match between required and available pins"
183 print ("not all found", name
, removedcount
, count
, title
, found
,
185 print ("pins found", pinfound
)
192 for name
in descriptions
.keys():
193 if not name
.startswith('GPIO'):
201 of
.write("## GPIO\n\n")
207 if descriptions
and fname
in descriptions
:
208 desc
= ': %s' % descriptions
[fname
]
211 pin_
= pin
+ bankspec
[bank
]
216 of
.write("* %-8s %d %s%-2d %s\n" % (fname
, pin_
, bank
, pin
, desc
))
220 display_group(of
, bankspec
, "EINT", eint
, fns
, pins
, descriptions
)
222 display_group(of
, bankspec
, "PWM", pwm
, fns
, pins
, descriptions
)
224 of
.write("## Unused Pinouts (spare as GPIO) for '%s'\n\n" % title
)
225 if descriptions
and 'GPIO' in descriptions
:
226 of
.write("%s\n\n" % descriptions
['GPIO'])
233 def display_group(of
, bankspec
, title
, todisplay
, fns
, pins
, descriptions
):
234 of
.write("## %s\n\n" % title
)
237 for fname
in todisplay
:
239 if descriptions
and fname
in descriptions
:
240 desc
= ': %s' % descriptions
[fname
]
241 fname
= fname
.split(':')
243 findbank
= fname
[0][0]
244 findmux
= int(fname
[0][1:])
250 for (pin
, mux
, bank
) in fns
[fname
]:
251 if findbank
is not None:
258 pin_
= pin
+ bankspec
[bank
]
263 of
.write("* %s %d %s%d/%d %s\n" %
264 (fname
, pin_
, bank
, pin
, mux
, desc
))
268 def display_fixed(of
, fixed
, offs
):
270 fkeys
= sorted(fixed
.keys())
273 for pin
, k
in enumerate(fkeys
):
274 of
.write("## %s\n\n" % k
)
277 for name
in fixed
[k
]:
281 if prevname
[:2] == name
[:2] and linecount
!= 0:
282 of
.write(" %s" % name
)
287 of
.write("* %d: %d %s" % (pin_
, pin
, name
))
289 res
.append((pin_
, name
))