Skip to content

Commit 1818f04

Browse files
committed
Adapt to new modm-devices pinout format
The pinout information is now stored in a separate list instead of being part of the GPIO table.
1 parent bf33d8d commit 1818f04

File tree

4 files changed

+35
-54
lines changed

4 files changed

+35
-54
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ tgcurses:
88

99

1010
modm-devices:
11-
@git clone -b develop_with_gpio_xml https://github.com/tgree/modm-devices
11+
@git clone -b feature/pinout https://github.com/salkinium/modm-devices
1212

1313

1414
.xml: modm-devices
@@ -19,7 +19,7 @@ modm-devices:
1919

2020

2121
modm_devices: modm-devices
22-
@ln -s modm-devices/tools/device/modm_devices
22+
@ln -s modm-devices/modm_devices
2323

2424

2525
clean:

chip_db.py

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,13 @@ def find(name):
3434
def pin_count(dev):
3535
# Unfortunately, sometimes R means 64 and sometimes it means 68. So, we
3636
# just count the pins. For some reason, counting the pins goes slower.
37-
# Maybe modm-devices does some deferred loading?
38-
return len(set(p['position'] for p in dev.properties['pin']))
39-
#return {'a' : 169,
40-
# 'b' : 208,
41-
# 'c' : 48,
42-
# 'k' : 32,
43-
# 'i' : 176,
44-
# 'm' : 80.5,
45-
# 'q' : 100,
46-
# 'r' : 64,
47-
# 'v' : 100,
48-
# 'x' : 240,
49-
# 'z' : 144,
50-
# }[dev.identifier.pin]
37+
# Maybe modm-devices does some deferred loading? Yes it does. -Niklas
38+
return len(set(p['position'] for p in dev.get_driver("gpio")["package"][0]["pin"]))
5139

5240

5341
def package(dev):
5442
try:
55-
return {'e' : 'EWLCSP',
56-
'f' : 'WLCSP',
57-
'h' : 'TFBGA',
58-
'i' : 'UFBGA', # 0.5 mm
59-
'j' : 'UFBGA',
60-
'k' : 'UFBGA', # 0.65 mm
61-
'm' : 'SO8N',
62-
'p' : 'TSSOP',
63-
'q' : 'UFBGA',
64-
't' : 'LQFP',
65-
'u' : 'UFQFPN',
66-
'v' : 'VFQFPN',
67-
'y' : 'WLCSP',
68-
}[dev.identifier.package]
43+
return dev.get_driver("gpio")["package"][0]["name"]
6944
except:
7045
pass
7146
raise Exception("Device %s has unknown package '%s'."
@@ -75,18 +50,18 @@ def package(dev):
7550
def make_package(dev):
7651
p = package(dev)
7752
n = pin_count(dev)
78-
if p in ('TFBGA', 'UFBGA', 'WLCSP', 'EWLCSP'):
53+
if any(name in p for name in ('TFBGA', 'UFBGA', 'WLCSP', 'EWLCSP')):
7954
if n == 240:
8055
dim = 17 # 240+25
8156
elif n == 176:
8257
dim = 15 # 176+25
8358
else:
8459
dim = int(math.ceil(math.sqrt(float(n))))
8560
return chip_package.BGA(dim, dim)
86-
elif p in ('LQFP', 'UFQFPN', 'VFQFPN'):
61+
elif any(name in p for name in ('LQFP', 'UFQFPN', 'VFQFPN')):
8762
dim = int(math.ceil(float(n)/4.))
8863
return chip_package.LQFP(dim, dim)
89-
elif p in ('TSSOP', 'SO8N'):
64+
elif any(name in p for name in ('TSSOP', 'SO8N')):
9065
dim = int(math.ceil(float(n)/2.))
9166
return chip_package.TSSOP(dim)
9267
raise KeyError

chip_stm.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

208208
def 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)

stm_layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def main(screen, chip):
362362
parts = chip_db.find(rv.chip)
363363
if len(parts) > 1:
364364
for p in parts:
365-
print('%s - %s%s' % (p, chip_db.package(p), chip_db.pin_count(p)))
365+
print('%s - %s' % (p, chip_db.package(p)))
366366
else:
367367
chip = chip_stm.make_chip(parts[0])
368368
tgcurses.wrapper(main, chip)

0 commit comments

Comments
 (0)