From 8505bbde39fe44608a8ed7ca8925d16e79934436 Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Sun, 30 Aug 2020 11:32:24 +0200 Subject: [PATCH] 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. --- Makefile | 4 ++-- chip_db.py | 37 ++++++------------------------------- chip_stm.py | 47 +++++++++++++++++++++++++++-------------------- stm_layout.py | 5 +++-- 4 files changed, 38 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index c6fe6cc..689a819 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ tgcurses: modm-devices: - @git clone -b develop_with_gpio_xml https://github.com/tgree/modm-devices + @git clone https://github.com/modm-io/modm-devices .xml: modm-devices @@ -19,7 +19,7 @@ modm-devices: modm_devices: modm-devices - @ln -s modm-devices/tools/device/modm_devices + @ln -s modm-devices/modm_devices clean: diff --git a/chip_db.py b/chip_db.py index 376ec97..a6e57c5 100644 --- a/chip_db.py +++ b/chip_db.py @@ -34,38 +34,13 @@ def find(name): def pin_count(dev): # Unfortunately, sometimes R means 64 and sometimes it means 68. So, we # just count the pins. For some reason, counting the pins goes slower. - # Maybe modm-devices does some deferred loading? - return len(set(p['position'] for p in dev.properties['pin'])) - #return {'a' : 169, - # 'b' : 208, - # 'c' : 48, - # 'k' : 32, - # 'i' : 176, - # 'm' : 80.5, - # 'q' : 100, - # 'r' : 64, - # 'v' : 100, - # 'x' : 240, - # 'z' : 144, - # }[dev.identifier.pin] + # Maybe modm-devices does some deferred loading? Yes it does. -Niklas + return len(set(p['position'] for p in dev.get_driver("gpio")["package"][0]["pin"])) def package(dev): try: - return {'e' : 'EWLCSP', - 'f' : 'WLCSP', - 'h' : 'TFBGA', - 'i' : 'UFBGA', # 0.5 mm - 'j' : 'UFBGA', - 'k' : 'UFBGA', # 0.65 mm - 'm' : 'SO8N', - 'p' : 'TSSOP', - 'q' : 'UFBGA', - 't' : 'LQFP', - 'u' : 'UFQFPN', - 'v' : 'VFQFPN', - 'y' : 'WLCSP', - }[dev.identifier.package] + return dev.get_driver("gpio")["package"][0]["name"] except: pass raise Exception("Device %s has unknown package '%s'." @@ -75,7 +50,7 @@ def package(dev): def make_package(dev): p = package(dev) n = pin_count(dev) - if p in ('TFBGA', 'UFBGA', 'WLCSP', 'EWLCSP'): + if any(name in p for name in ('TFBGA', 'UFBGA', 'WLCSP', 'EWLCSP')): if n == 240: dim = 17 # 240+25 elif n == 176: @@ -83,10 +58,10 @@ def make_package(dev): else: dim = int(math.ceil(math.sqrt(float(n)))) return chip_package.BGA(dim, dim) - elif p in ('LQFP', 'UFQFPN', 'VFQFPN'): + elif any(name in p for name in ('LQFP', 'UFQFPN', 'VFQFPN')): dim = int(math.ceil(float(n)/4.)) return chip_package.LQFP(dim, dim) - elif p in ('TSSOP', 'SO8N'): + elif any(name in p for name in ('TSSOP', 'SO8N')): dim = int(math.ceil(float(n)/2.)) return chip_package.TSSOP(dim) raise KeyError diff --git a/chip_stm.py b/chip_stm.py index e06d843..d8006d1 100644 --- a/chip_stm.py +++ b/chip_stm.py @@ -165,7 +165,7 @@ def serialize_settings(self): continue if not hasattr(p, '_gpio'): continue - + port = p._gpio n = p._gpionum mask_1[port] &= ~(0x1 << n) @@ -207,15 +207,24 @@ def serialize_settings(self): def make_chip(part): pkg = chip_db.make_package(part) - pin_map = {} - for p in part.properties['pin']: - name = p['name'].split('-')[0] - name = name.split(' ')[0] - prefix = name.split('_')[0] - p['shortname'] = name - pin_map[p['position']] = p gpios = part.get_driver('gpio') + pinout = [] + for pin in gpios["package"][0]["pin"]: + name = shortname = pin["name"] + ptype = pin.get("type", "i/o").upper() + if "I/O" in ptype: + shortname = name[:4] + if len(shortname) > 3 and not shortname[3].isdigit(): + shortname = shortname[:3] + pinout.append({ + "short": shortname, + "position": pin["position"], + "name": pin["name"], + "type": ptype, + "remap": pin.get("variant", "") == "remap", + }) + pins = {} for gpio in gpios['gpio']: name = 'P%c%u' % (gpio['port'].upper(), int(gpio['pin'], 10)) @@ -239,17 +248,15 @@ def make_chip(part): # usually always just PA0 and then you select the alternate or # analog function for that pin - i.e. it's another level of # multiplexing to squash more functionality into a small pin - # count. For these types of devices, there will be multiple - # GPIOs that have the same 'position' field and when we populate - # pins[key] we will only hold the last one there. - key = gpio['position'] - pin = pin_map[key] - name = pin['shortname'] - fname = pin['name'] - pins[key] = GPIO(name, key, alt_fns, add_fns, fname, part) - - for p in part.properties['pin']: - key = p['position'] + # count. For these types of devices, there will only show the + # default configuration, i.e. the non-remapped pin. + pin = next(p for p in pinout if p["short"] == name) + if not pin["remap"]: + key = pin['position'] + pins[key] = GPIO(name, key, alt_fns, add_fns, pin['name'], part) + + for pin in pinout: + key = pin['position'] if key not in pins: - pins[key] = Pin(p['name'], key, [], [], p['name']) + pins[key] = Pin(pin["short"], key, [], [], pin['name']) return Chip(part, pkg, pins) diff --git a/stm_layout.py b/stm_layout.py index 552cb82..865179f 100755 --- a/stm_layout.py +++ b/stm_layout.py @@ -360,9 +360,10 @@ def main(screen, chip): rv = parser.parse_args() parts = chip_db.find(rv.chip) - if len(parts) > 1: + part = next( (p for p in parts if rv.chip == p.partname), None) + if part is None: for p in parts: - print('%s - %s%s' % (p, chip_db.package(p), chip_db.pin_count(p))) + print('%s - %s' % (p, chip_db.package(p))) else: chip = chip_stm.make_chip(parts[0]) tgcurses.wrapper(main, chip)