@@ -165,7 +165,7 @@ def serialize_settings(self):
165165 continue
166166 if not hasattr (p , '_gpio' ):
167167 continue
168-
168+
169169 port = p ._gpio
170170 n = p ._gpionum
171171 mask_1 [port ] &= ~ (0x1 << n )
@@ -207,15 +207,24 @@ def serialize_settings(self):
207207
208208def make_chip (part ):
209209 pkg = chip_db .make_package (part )
210- pin_map = {}
211- for p in part .properties ['pin' ]:
212- name = p ['name' ].split ('-' )[0 ]
213- name = name .split (' ' )[0 ]
214- prefix = name .split ('_' )[0 ]
215- p ['shortname' ] = name
216- pin_map [p ['position' ]] = p
217210
218211 gpios = part .get_driver ('gpio' )
212+ pinout = []
213+ for pin in gpios ["package" ][0 ]["pin" ]:
214+ name = shortname = pin ["name" ]
215+ ptype = pin .get ("type" , "i/o" ).upper ()
216+ if "I/O" in ptype :
217+ shortname = name [:4 ]
218+ if len (shortname ) > 3 and not shortname [3 ].isdigit ():
219+ shortname = shortname [:3 ]
220+ pinout .append ({
221+ "short" : shortname ,
222+ "position" : pin ["position" ],
223+ "name" : pin ["name" ],
224+ "type" : ptype ,
225+ "remap" : pin .get ("variant" , "" ) == "remap" ,
226+ })
227+
219228 pins = {}
220229 for gpio in gpios ['gpio' ]:
221230 name = 'P%c%u' % (gpio ['port' ].upper (), int (gpio ['pin' ], 10 ))
@@ -239,17 +248,14 @@ def make_chip(part):
239248 # usually always just PA0 and then you select the alternate or
240249 # analog function for that pin - i.e. it's another level of
241250 # multiplexing to squash more functionality into a small pin
242- # count. For these types of devices, there will be multiple
243- # GPIOs that have the same 'position' field and when we populate
244- # pins[key] we will only hold the last one there.
245- key = gpio ['position' ]
246- pin = pin_map [key ]
247- name = pin ['shortname' ]
248- fname = pin ['name' ]
249- pins [key ] = GPIO (name , key , alt_fns , add_fns , fname , part )
250-
251- for p in part .properties ['pin' ]:
252- key = p ['position' ]
251+ # count. For these types of devices, there will only show the
252+ # default configuration, i.e. the non-remapped pin.
253+ pin = next (p for p in pinout if p ["short" ] == name and not p ["remap" ])
254+ key = pin ['position' ]
255+ pins [key ] = GPIO (name , key , alt_fns , add_fns , pin ['name' ], part )
256+
257+ for pin in pinout :
258+ key = pin ['position' ]
253259 if key not in pins :
254- pins [key ] = Pin (p [ 'name' ], key , [], [], p ['name' ])
260+ pins [key ] = Pin (pin [ "short" ], key , [], [], pin ['name' ])
255261 return Chip (part , pkg , pins )
0 commit comments