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 assert fnbase
in function_names
, "fn %s not in descriptions %s" % \
84 (fname
, str(function_names
.keys()))
85 #print "name", fname, fnbase
86 if fnbase
!= current_fn
:
87 if current_fn
is not None:
89 of
.write("## %s\n\n%s\n\n" % (fnbase
, function_names
[fnbase
]))
91 of
.write("* %-9s :" % fname
)
92 for (pin
, mux
, bank
) in fns
[fname
]:
93 of
.write(" %s%d/%d" % (bank
, pin
, mux
))
99 def check_functions(of
, title
, bankspec
, fns
, pins
, required
, eint
, pwm
,
102 pins
= deepcopy(pins
)
103 if descriptions
is None:
110 of
.write("# Pinmap for %s\n\n" % title
)
112 for name
in required
:
113 of
.write("## %s\n\n" % name
)
114 if descriptions
and name
in descriptions
:
115 of
.write("%s\n\n" % descriptions
[name
])
117 name
= name
.split(':')
119 findbank
= name
[0][0]
120 findmux
= int(name
[0][1:])
126 name
= name
.split('/')
137 if not fname
.startswith(name
):
139 for k
in pins
.fnspec
.keys():
140 if fname
.startswith(k
):
141 fk
= list(pins
.fnspec
[k
].keys())
144 #print fname, fn, dir(fn)
146 count
= len(fn
.pingroup
)
147 for pin
, mux
, bank
in fns
[fname
]:
148 if findbank
is not None:
153 pin_
= pin
+ bankspec
[bank
]
155 pinfound
[pin_
] = (fname
, pin_
, bank
, pin
, mux
)
157 pinidx
= sorted(pinfound
.keys())
161 fname
, pin_
, bank
, pin
, mux
= pinfound
[pin_
]
165 if len(found
) > count
:
169 of
.write("* %s %d %s%d/%d\n" % (fname
, pin_
, bank
, pin
, mux
))
171 if removedcount
!= count
:
172 print ("not all found", name
, removedcount
, count
, title
, found
,
174 print ("pins found", pinfound
)
181 for name
in descriptions
.keys():
182 if not name
.startswith('GPIO'):
190 of
.write("## GPIO\n\n")
196 if descriptions
and fname
in descriptions
:
197 desc
= ': %s' % descriptions
[fname
]
200 pin_
= pin
+ bankspec
[bank
]
205 of
.write("* %-8s %d %s%-2d %s\n" % (fname
, pin_
, bank
, pin
, desc
))
209 display_group(of
, bankspec
, "EINT", eint
, fns
, pins
, descriptions
)
211 display_group(of
, bankspec
, "PWM", pwm
, fns
, pins
, descriptions
)
213 of
.write("## Unused Pinouts (spare as GPIO) for '%s'\n\n" % title
)
214 if descriptions
and 'GPIO' in descriptions
:
215 of
.write("%s\n\n" % descriptions
['GPIO'])
222 def display_group(of
, bankspec
, title
, todisplay
, fns
, pins
, descriptions
):
223 of
.write("## %s\n\n" % title
)
226 for fname
in todisplay
:
228 if descriptions
and fname
in descriptions
:
229 desc
= ': %s' % descriptions
[fname
]
230 fname
= fname
.split(':')
232 findbank
= fname
[0][0]
233 findmux
= int(fname
[0][1:])
239 for (pin
, mux
, bank
) in fns
[fname
]:
240 if findbank
is not None:
247 pin_
= pin
+ bankspec
[bank
]
252 of
.write("* %s %d %s%d/%d %s\n" %
253 (fname
, pin_
, bank
, pin
, mux
, desc
))
257 def display_fixed(of
, fixed
, offs
):
259 fkeys
= sorted(fixed
.keys())
262 for pin
, k
in enumerate(fkeys
):
263 of
.write("## %s\n\n" % k
)
266 for name
in fixed
[k
]:
270 if prevname
[:2] == name
[:2] and linecount
!= 0:
271 of
.write(" %s" % name
)
276 of
.write("* %d: %d %s" % (pin_
, pin
, name
))
278 res
.append((pin_
, name
))