Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
37 changes: 6 additions & 31 deletions chip_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'."
Expand All @@ -75,18 +50,18 @@ 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:
dim = 15 # 176+25
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
Expand Down
47 changes: 27 additions & 20 deletions chip_stm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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)
5 changes: 3 additions & 2 deletions stm_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)