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(1, 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 #print "name", fname, fnbase
84 if fnbase
!= current_fn
:
85 if current_fn
is not None:
87 of
.write("## %s\n\n%s\n\n" % (fnbase
, function_names
[fnbase
]))
89 of
.write("* %-9s :" % fname
)
90 for (pin
, mux
, bank
) in fns
[fname
]:
91 of
.write(" %s%d/%d" % (bank
, pin
, mux
))
97 def check_functions(of
, title
, bankspec
, fns
, pins
, required
, eint
, pwm
,
100 pins
= deepcopy(pins
)
101 if descriptions
is None:
108 of
.write("# Pinmap for %s\n\n" % title
)
110 for name
in required
:
111 of
.write("## %s\n\n" % name
)
112 if descriptions
and name
in descriptions
:
113 of
.write("%s\n\n" % descriptions
[name
])
115 name
= name
.split(':')
117 findbank
= name
[0][0]
118 findmux
= int(name
[0][1:])
124 name
= name
.split('/')
135 if not fname
.startswith(name
):
137 for k
in pins
.fnspec
.keys():
138 if fname
.startswith(k
):
139 fk
= list(pins
.fnspec
[k
].keys())
142 #print fname, fn, dir(fn)
144 count
= len(fn
.pingroup
)
145 for pin
, mux
, bank
in fns
[fname
]:
146 if findbank
is not None:
151 pin_
= pin
+ bankspec
[bank
]
153 pinfound
[pin_
] = (fname
, pin_
, bank
, pin
, mux
)
155 pinidx
= sorted(pinfound
.keys())
159 fname
, pin_
, bank
, pin
, mux
= pinfound
[pin_
]
163 if len(found
) > count
:
167 of
.write("* %s %d %s%d/%d\n" % (fname
, pin_
, bank
, pin
, mux
))
169 if removedcount
!= count
:
170 print ("not all found", name
, removedcount
, count
, title
, found
,
172 print ("pins found", pinfound
)
179 for name
in descriptions
.keys():
180 if not name
.startswith('GPIO'):
188 of
.write("## GPIO\n\n")
194 if descriptions
and fname
in descriptions
:
195 desc
= ': %s' % descriptions
[fname
]
198 pin_
= pin
+ bankspec
[bank
]
203 of
.write("* %-8s %d %s%-2d %s\n" % (fname
, pin_
, bank
, pin
, desc
))
207 display_group(of
, bankspec
, "EINT", eint
, fns
, pins
, descriptions
)
209 display_group(of
, bankspec
, "PWM", pwm
, fns
, pins
, descriptions
)
211 of
.write("## Unused Pinouts (spare as GPIO) for '%s'\n\n" % title
)
212 if descriptions
and 'GPIO' in descriptions
:
213 of
.write("%s\n\n" % descriptions
['GPIO'])
220 def display_group(of
, bankspec
, title
, todisplay
, fns
, pins
, descriptions
):
221 of
.write("## %s\n\n" % title
)
224 for fname
in todisplay
:
226 if descriptions
and fname
in descriptions
:
227 desc
= ': %s' % descriptions
[fname
]
228 fname
= fname
.split(':')
230 findbank
= fname
[0][0]
231 findmux
= int(fname
[0][1:])
237 for (pin
, mux
, bank
) in fns
[fname
]:
238 if findbank
is not None:
245 pin_
= pin
+ bankspec
[bank
]
250 of
.write("* %s %d %s%d/%d %s\n" %
251 (fname
, pin_
, bank
, pin
, mux
, desc
))
255 def display_fixed(of
, fixed
, offs
):
257 fkeys
= sorted(fixed
.keys())
260 for pin
, k
in enumerate(fkeys
):
261 of
.write("## %s\n\n" % k
)
264 for name
in fixed
[k
]:
268 if prevname
[:2] == name
[:2] and linecount
!= 0:
269 of
.write(" %s" % name
)
274 of
.write("* %d: %d %s" % (pin_
, pin
, name
))
276 res
.append((pin_
, name
))