From b50cdc5fcd9669b0a302319ad566313f2fab9253 Mon Sep 17 00:00:00 2001 From: Terry Greeniaus Date: Tue, 15 Feb 2022 01:48:55 -0800 Subject: [PATCH 01/10] tk/tk_elems.py: Record top, left, bottom and right x and y coordinates. --- stm_layout/tk/tk_elems.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stm_layout/tk/tk_elems.py b/stm_layout/tk/tk_elems.py index 08d0439..aa05fb8 100644 --- a/stm_layout/tk/tk_elems.py +++ b/stm_layout/tk/tk_elems.py @@ -14,8 +14,12 @@ def __init__(self, canvas, elem_id, x, y, width=None, height=None): self.y = y if width is not None: self.width = width + self.lx = x + self.rx = x + width if height is not None: self.height = height + self.ty = y + self.by = y + height def bbox(self): return self._canvas._bbox(self) From e05f8ccd31d2e9e379aee05ff6430b4b9a5ff7e9 Mon Sep 17 00:00:00 2001 From: Terry Greeniaus Date: Tue, 15 Feb 2022 01:48:55 -0800 Subject: [PATCH 02/10] tk/tk_elems.py: Set DPI awareness and scaling factor to work around some Windows bluriness. --- stm_layout/tk/tk_elems.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/stm_layout/tk/tk_elems.py b/stm_layout/tk/tk_elems.py index aa05fb8..a6eb46c 100644 --- a/stm_layout/tk/tk_elems.py +++ b/stm_layout/tk/tk_elems.py @@ -1,4 +1,5 @@ import tkinter +import ctypes class Elem: @@ -117,8 +118,16 @@ def add_entry(self, **kwargs): class TKBase: def __init__(self): + # Windows hack #1. + try: + ctypes.windll.shcore.SetProcessDpiAwareness(1) + except AttributeError: + pass self._root = tkinter.Tk() + # Windows hack #2. + self._root.tk.call('tk', 'scaling', 1.0) + def set_geometry(self, x, y, width, height): self._root.geometry('%ux%u+%u+%u' % (width, height, x, y)) From cf8e1aedd28728af667b3c51c6ac9d2d4b29a935 Mon Sep 17 00:00:00 2001 From: Terry Greeniaus Date: Tue, 15 Feb 2022 01:48:55 -0800 Subject: [PATCH 03/10] tk/xplat.py: Add xplat module to do cross-platform constants. --- stm_layout/tk/xplat.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 stm_layout/tk/xplat.py diff --git a/stm_layout/tk/xplat.py b/stm_layout/tk/xplat.py new file mode 100644 index 0000000..39b0697 --- /dev/null +++ b/stm_layout/tk/xplat.py @@ -0,0 +1,14 @@ +import platform + + +SYSTEM = platform.system().lower() +CONFIG = {} + + +def register(**kwargs): + global CONFIG + CONFIG = kwargs[SYSTEM] + + +def get(key): + return CONFIG[key] From 8d8264d4d3ddced632b57c4b95933c4535784272 Mon Sep 17 00:00:00 2001 From: Terry Greeniaus Date: Tue, 15 Feb 2022 01:48:55 -0800 Subject: [PATCH 04/10] stm_layout_tk: Factor platform-specific twiddle values into xplat parameters. --- .pylintrc | 3 ++ stm_layout/stm_layout_tk.py | 43 ++++++++++++++++-- stm_layout/tk/tk_bga.py | 7 ++- stm_layout/tk/tk_edgy.py | 66 +++++++++++++++++++++++++++ stm_layout/tk/tk_lqfp.py | 86 ++++++----------------------------- stm_layout/tk/tk_tssop.py | 47 ++++--------------- stm_layout/tk/tk_workspace.py | 16 +++---- stm_layout/tk/xplat.py | 15 +++--- 8 files changed, 150 insertions(+), 133 deletions(-) create mode 100644 stm_layout/tk/tk_edgy.py diff --git a/.pylintrc b/.pylintrc index bede79f..46dc10e 100644 --- a/.pylintrc +++ b/.pylintrc @@ -17,3 +17,6 @@ disable=bad-whitespace, useless-super-delegation, consider-using-f-string, R0801 + +[TYPECHECK] +generated-members=xplat.* diff --git a/stm_layout/stm_layout_tk.py b/stm_layout/stm_layout_tk.py index 639a478..4120716 100644 --- a/stm_layout/stm_layout_tk.py +++ b/stm_layout/stm_layout_tk.py @@ -6,9 +6,43 @@ import stm_layout.tk -FONT = ('Monaco', 10) -FONT_PIN_NUM = ('Monaco', 9) -FONT_INFO = ('Monaco', 10) +stm_layout.tk.xplat.register( + windows={ + 'LABEL_FONT' : ('Courier New', 10), + 'INFO_FONT' : ('Courier New', 10), + 'PIN_FONT' : ('Courier New', 9), + 'EDGE_PIN_H_KEY_DX' : 0, + 'EDGE_PIN_H_KEY_DY' : 1, + 'EDGE_PIN_V_KEY_DX' : 1, + 'BGA_PIN_NAME_DY' : 1, + 'BGA_PIN_KEY_DX' : 0, + 'BGA_PIN_KEY_DY' : 1, + }, + darwin={ + 'LABEL_FONT' : ('Monaco', 10), + 'INFO_FONT' : ('Monaco', 10), + 'PIN_FONT' : ('Monaco', 9), + 'EDGE_PIN_H_KEY_DX' : 1, + 'EDGE_PIN_H_KEY_DY' : 0, + 'EDGE_PIN_V_KEY_DX' : 0, + 'BGA_PIN_NAME_DY' : 0, + 'BGA_PIN_KEY_DX' : 1, + 'BGA_PIN_KEY_DY' : 0, + }, + linux={ + # TBD. + 'LABEL_FONT' : ('Courier', 10), + 'INFO_FONT' : ('Courier', 10), + 'PIN_FONT' : ('Courier', 9), + 'EDGE_PIN_H_KEY_DX' : 0, + 'EDGE_PIN_H_KEY_DY' : 1, + 'EDGE_PIN_V_KEY_DX' : 1, + 'BGA_PIN_NAME_DY' : 1, + 'BGA_PIN_KEY_DX' : 0, + 'BGA_PIN_KEY_DY' : 1, + }, +) + RECT_FILL = 'white' HILITE_FILL = 'lightblue' SELECT_FILL = 'yellow' @@ -25,8 +59,7 @@ def main(chip, regex): else: raise Exception('Unsupported chip package.') - ws = cls(chip, FONT, FONT_PIN_NUM, FONT_INFO, RECT_FILL, HILITE_FILL, - SELECT_FILL, RE_FILL) + ws = cls(chip, RECT_FILL, HILITE_FILL, SELECT_FILL, RE_FILL) if regex: ws.set_regex(regex) diff --git a/stm_layout/tk/tk_bga.py b/stm_layout/tk/tk_bga.py index 86831fa..0cdb8b1 100644 --- a/stm_layout/tk/tk_bga.py +++ b/stm_layout/tk/tk_bga.py @@ -1,4 +1,5 @@ from . import tk_workspace +from . import xplat PIN_DIAM = 30 @@ -36,9 +37,11 @@ def __init__(self, *args): fill=self.elem_fill) self.pin_elems.append(o) c.add_text( - o.x + o.width / 2, o.y + o.height, + o.x + o.width / 2, + o.y + o.height + xplat.BGA_PIN_NAME_DY, font=self.label_font, text=p.name, anchor='n') c.add_text( - o.x + o.width / 2 + 1, o.y + o.height / 2, + o.x + o.width / 2 + xplat.BGA_PIN_KEY_DX, + o.y + o.height / 2 + xplat.BGA_PIN_KEY_DY, font=self.pin_font, text=p.key, anchor='c') o.pin = p diff --git a/stm_layout/tk/tk_edgy.py b/stm_layout/tk/tk_edgy.py new file mode 100644 index 0000000..0591526 --- /dev/null +++ b/stm_layout/tk/tk_edgy.py @@ -0,0 +1,66 @@ +from . import tk_workspace +from . import xplat + + +PIN_WIDTH = 12 +PIN_DELTA = 2*PIN_WIDTH +PIN_LENGTH = 20 +PIN_LABEL_OFFSET = 2 + + +def pin_d(t0, t1, i): + if t0 < t1: + return t0 + PIN_WIDTH + i*PIN_DELTA + return t0 - (i + 1)*PIN_DELTA + + +class Workspace(tk_workspace.Workspace): + def __init__(self, *args): + super().__init__(*args) + self.pin_width = PIN_WIDTH + self.pin_length = PIN_LENGTH + self.pin_label_offset = PIN_LABEL_OFFSET + + def add_h_pin(self, p, x, y): + c = self.mcu_canvas + r = c.add_rectangle(x, y, PIN_LENGTH, PIN_WIDTH, fill=self.elem_fill) + c.add_text(x + PIN_LENGTH / 2 + xplat.EDGE_PIN_H_KEY_DX, + y + PIN_WIDTH / 2 + xplat.EDGE_PIN_H_KEY_DY, + font=self.pin_font, text=p.key, anchor='c') + return r + + def add_v_pin(self, p, x, y): + c = self.mcu_canvas + r = c.add_rectangle(x, y, PIN_WIDTH, PIN_LENGTH, fill=self.elem_fill) + c.add_text(x + PIN_WIDTH / 2 + xplat.EDGE_PIN_V_KEY_DX, + y + PIN_LENGTH / 2, font=self.pin_font, text=p.key, + anchor='c', angle=90) + return r + + def add_l_pin(self, p, x, y0, y1, i): + y = pin_d(y0, y1, i) + self.mcu_canvas.add_text(x - PIN_LABEL_OFFSET, y + PIN_WIDTH / 2, + font=self.label_font, text=p.name, anchor='e') + return self.add_h_pin(p, x, y) + + def add_r_pin(self, p, x, y0, y1, i): + y = pin_d(y0, y1, i) + self.mcu_canvas.add_text(x + PIN_LENGTH + 1 + PIN_LABEL_OFFSET, + y + PIN_WIDTH / 2, font=self.label_font, + text=p.name, anchor='w') + return self.add_h_pin(p, x, y) + + def add_t_pin(self, p, x0, x1, i, y): + x = pin_d(x0, x1, i) + self.mcu_canvas.add_text(x + PIN_WIDTH / 2, y - PIN_LABEL_OFFSET, + font=self.label_font, text=p.name, anchor='w', + angle=90) + return self.add_v_pin(p, x, y) + + def add_b_pin(self, p, x0, x1, i, y): + x = pin_d(x0, x1, i) + self.mcu_canvas.add_text(x + PIN_WIDTH / 2, + y + PIN_LENGTH + 1 + PIN_LABEL_OFFSET, + font=self.label_font, text=p.name, anchor='e', + angle=90) + return self.add_v_pin(p, x, y) diff --git a/stm_layout/tk/tk_lqfp.py b/stm_layout/tk/tk_lqfp.py index a09fc7b..81a5c2a 100644 --- a/stm_layout/tk/tk_lqfp.py +++ b/stm_layout/tk/tk_lqfp.py @@ -1,25 +1,20 @@ -from . import tk_workspace +from . import tk_edgy from .. import chip_db -PIN_WIDTH = 12 -PIN_LENGTH = 20 -PIN_LABEL_OFFSET = 2 - - -class LQFPWorkspace(tk_workspace.Workspace): +class LQFPWorkspace(tk_edgy.Workspace): def __init__(self, *args): super().__init__(*args) cw = self.chip.width - 2 ch = self.chip.height - 2 - w = 2*PIN_WIDTH*cw + PIN_WIDTH - h = 2*PIN_WIDTH*ch + PIN_WIDTH + w = 2*self.pin_width*cw + self.pin_width + h = 2*self.pin_width*ch + self.pin_width pad = 0 for _, p in self.chip.pins.items(): pad = max(pad, self.label_font.measure(p.name)) - pad += PIN_LENGTH + 5 + PIN_LABEL_OFFSET + pad += self.pin_length + 5 + self.pin_label_offset self.set_geometry(50, 50, w + 2*pad + self.info_width, max(h + 2*pad, self.info_height)) @@ -32,71 +27,18 @@ def __init__(self, *args): r0 = b0 + cw t0 = r0 + ch m = c.add_rectangle(pad, pad, w, h, fill=self.elem_fill) - for i, p in self.chip.pins.items(): - i = int(i) + for _, p in self.chip.pins.items(): + i = int(p.key) if l0 <= i < b0: - # Left row. - r = c.add_rectangle( - m.x - PIN_LENGTH, - m.y + PIN_WIDTH*(2*(i - l0) + 1), - PIN_LENGTH, PIN_WIDTH, fill=self.elem_fill) - c.add_text( - r.x - PIN_LABEL_OFFSET, r.y + r.height / 2, - font=self.label_font, text=p.name, anchor='e') - c.add_text( - r.x + r.width / 2 + 1, r.y + r.height / 2, - font=self.pin_font, text='%u' % i, anchor='c') - self.pin_elems.append(r) - + r = self.add_l_pin(p, m.x - self.pin_length, m.ty, m.by, i - l0) elif b0 <= i < r0: - # Bottom row. - r = c.add_rectangle( - m.x + PIN_WIDTH*(2*(i - b0) + 1), - m.y + m.height, - PIN_WIDTH, PIN_LENGTH, fill=self.elem_fill) - c.add_text( - r.x + r.width / 2, - r.y + r.height + 1 + PIN_LABEL_OFFSET, - font=self.label_font, text=p.name, anchor='e', - angle=90) - c.add_text( - r.x + r.width / 2, r.y + r.height / 2, - font=self.pin_font, text='%u' % i, - anchor='c', angle=90) - self.pin_elems.append(r) - + r = self.add_b_pin(p, m.lx, m.rx, i - b0, m.y + m.height) elif r0 <= i < t0: - # Right row. - r = c.add_rectangle( - m.x + m.width, - m.y + m.height - PIN_WIDTH*(2*(i - r0) + 2), - PIN_LENGTH, PIN_WIDTH, fill=self.elem_fill) - c.add_text( - r.x + r.width + 1 + PIN_LABEL_OFFSET, - r.y + r.height / 2, - font=self.label_font, text=p.name, anchor='w') - c.add_text( - r.x + r.width / 2, r.y + r.height / 2, - font=self.pin_font, text='%u' % i, - anchor='c') - self.pin_elems.append(r) - + r = self.add_r_pin(p, m.x + m.width, m.by, m.ty, i - r0) else: - # Top row. - r = c.add_rectangle( - m.x + m.width - PIN_WIDTH*(2*(i - t0) + 2), - m.y - PIN_LENGTH, - PIN_WIDTH, PIN_LENGTH, fill=self.elem_fill) - c.add_text( - r.x + r.width / 2, r.y - PIN_LABEL_OFFSET, - font=self.label_font, - text=p.name, anchor='w', angle=90) - c.add_text( - r.x + r.width / 2, r.y + r.height / 2, - font=self.pin_font, text='%u' % i, - anchor='c', angle=90) - self.pin_elems.append(r) + r = self.add_t_pin(p, m.rx, m.lx, i - t0, m.y - self.pin_length) + self.pin_elems.append(r) r.pin = p package_name = chip_db.package(self.chip.part) @@ -107,5 +49,5 @@ def __init__(self, *args): anchor='c') if 'LQFP' not in package_name: - m.resize(pad - PIN_LENGTH, pad - PIN_LENGTH, - w + 2*PIN_LENGTH, h + 2*PIN_LENGTH) + m.resize(pad - self.pin_length, pad - self.pin_length, + w + 2*self.pin_length, h + 2*self.pin_length) diff --git a/stm_layout/tk/tk_tssop.py b/stm_layout/tk/tk_tssop.py index b26ae37..5573118 100644 --- a/stm_layout/tk/tk_tssop.py +++ b/stm_layout/tk/tk_tssop.py @@ -1,25 +1,22 @@ -from . import tk_workspace +from . import tk_edgy from .. import chip_db -PKG_WIDTH = 100 -PIN_WIDTH = 12 -PIN_LENGTH = 20 -PIN_LABEL_OFFSET = 2 +PKG_WIDTH = 100 -class TSSOPWorkspace(tk_workspace.Workspace): +class TSSOPWorkspace(tk_edgy.Workspace): def __init__(self, *args): super().__init__(*args) ch = self.chip.height w = PKG_WIDTH - h = 2*PIN_WIDTH*ch + PIN_WIDTH + h = 2*self.pin_width*ch + self.pin_width pad = 0 for _, p in self.chip.pins.items(): pad = max(pad, self.label_font.measure(p.name)) - pad += PIN_LENGTH + 5 + PIN_LABEL_OFFSET + pad += self.pin_length + 5 + self.pin_label_offset self.set_geometry(50, 50, w + 2*pad + self.info_width, max(h + 2*pad, self.info_height)) @@ -30,38 +27,14 @@ def __init__(self, *args): l0 = 1 r0 = l0 + ch m = c.add_rectangle(pad, pad, w, h, fill=self.elem_fill) - for k, p in self.chip.pins.items(): - i = int(k) + for _, p in self.chip.pins.items(): + i = int(p.key) if l0 <= i < r0: - # Left row. - r = c.add_rectangle( - m.x - PIN_LENGTH, - m.y + PIN_WIDTH*(2*(i - l0) + 1), - PIN_LENGTH, PIN_WIDTH, fill=self.elem_fill) - c.add_text( - r.x - PIN_LABEL_OFFSET, r.y + r.height / 2, - font=self.label_font, text=p.name, anchor='e') - c.add_text( - r.x + r.width / 2 + 1, r.y + r.height / 2, - font=self.pin_font, text='%u' % i, anchor='c') - self.pin_elems.append(r) - + r = self.add_l_pin(p, m.x - self.pin_length, m.ty, m.by, i - l0) else: - # Right row. - r = c.add_rectangle( - m.x + m.width, - m.y + m.height - PIN_WIDTH*(2*(i - r0) + 2), - PIN_LENGTH, PIN_WIDTH, fill=self.elem_fill) - c.add_text( - r.x + r.width + 1 + PIN_LABEL_OFFSET, - r.y + r.height / 2, - font=self.label_font, text=p.name, anchor='w') - c.add_text( - r.x + r.width / 2, r.y + r.height / 2, - font=self.pin_font, text='%u' % i, - anchor='c') - self.pin_elems.append(r) + r = self.add_r_pin(p, m.x + m.width, m.by, m.ty, i - r0) + self.pin_elems.append(r) r.pin = p package_name = chip_db.package(self.chip.part) diff --git a/stm_layout/tk/tk_workspace.py b/stm_layout/tk/tk_workspace.py index d0f209b..244f3c2 100644 --- a/stm_layout/tk/tk_workspace.py +++ b/stm_layout/tk/tk_workspace.py @@ -2,6 +2,7 @@ import tkinter.font from .tk_elems import TKBase +from . import xplat class InfoText: @@ -22,8 +23,7 @@ def set_bg(self, bg_color): class Workspace(TKBase): - def __init__(self, chip, label_font, pin_font, info_font, elem_fill, - hilite_fill, select_fill, re_fill): + def __init__(self, chip, elem_fill, hilite_fill, select_fill, re_fill): super().__init__() self.chip = chip @@ -37,12 +37,12 @@ def __init__(self, chip, label_font, pin_font, info_font, elem_fill, self.pin_elems = [] self.regex = None - self.label_font = tkinter.font.Font(family=label_font[0], - size=label_font[1]) - self.pin_font = tkinter.font.Font(family=pin_font[0], - size=pin_font[1]) - self.info_font = tkinter.font.Font(family=info_font[0], - size=info_font[1]) + self.label_font = tkinter.font.Font(family=xplat.LABEL_FONT[0], + size=xplat.LABEL_FONT[1]) + self.pin_font = tkinter.font.Font(family=xplat.PIN_FONT[0], + size=xplat.PIN_FONT[1]) + self.info_font = tkinter.font.Font(family=xplat.INFO_FONT[0], + size=xplat.INFO_FONT[1]) dy = self.info_font.metrics('linespace') w = 300 diff --git a/stm_layout/tk/xplat.py b/stm_layout/tk/xplat.py index 39b0697..c2acab2 100644 --- a/stm_layout/tk/xplat.py +++ b/stm_layout/tk/xplat.py @@ -1,14 +1,11 @@ import platform - - -SYSTEM = platform.system().lower() -CONFIG = {} +import sys def register(**kwargs): - global CONFIG - CONFIG = kwargs[SYSTEM] - + module = sys.modules[__name__] + del module.register -def get(key): - return CONFIG[key] + config = kwargs[platform.system().lower()] + for k, v in config.items(): + setattr(module, k, v) From 6f6a471015bee090115812f4abf06e3426677659 Mon Sep 17 00:00:00 2001 From: Terry Greeniaus Date: Tue, 15 Feb 2022 01:48:55 -0800 Subject: [PATCH 05/10] tk/tk_bga.py: Add chip name and form factor to display. --- stm_layout/tk/tk_bga.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/stm_layout/tk/tk_bga.py b/stm_layout/tk/tk_bga.py index 0cdb8b1..a685c8a 100644 --- a/stm_layout/tk/tk_bga.py +++ b/stm_layout/tk/tk_bga.py @@ -1,5 +1,6 @@ from . import tk_workspace from . import xplat +from .. import chip_db PIN_DIAM = 30 @@ -11,19 +12,20 @@ class BGAWorkspace(tk_workspace.Workspace): def __init__(self, *args): super().__init__(*args) + dy = self.label_font.metrics('linespace') cw = self.chip.width ch = self.chip.height w = cw*PIN_DELTA + PIN_SPACE h = ch*PIN_DELTA + PIN_SPACE + self.label_font.metrics('ascent') pad = 15 self.set_geometry(50, 50, w + 2*pad + self.info_width, - max(h + 2*pad, self.info_height)) + max(h + 2*pad + dy, self.info_height)) - c = self.mcu_canvas = self.add_canvas(w + 2*pad, h + 2*pad) + c = self.mcu_canvas = self.add_canvas(w + 2*pad, h + 2*pad + dy) self._root.columnconfigure(0, weight=1) self._root.rowconfigure(0, weight=1) - m = c.add_rectangle(pad, pad, w, h, fill=self.elem_fill) + m = c.add_rectangle(pad, pad + dy, w, h, fill=self.elem_fill) for x in range(cw): for y in range(ch): p = self.chip.chip.pins[x][y] @@ -45,3 +47,9 @@ def __init__(self, *args): o.y + o.height / 2 + xplat.BGA_PIN_KEY_DY, font=self.pin_font, text=p.key, anchor='c') o.pin = p + + package_name = chip_db.package(self.chip.part) + c.add_text(m.x, m.y, font=self.label_font, text=self.chip.name, + anchor='sw') + c.add_text(m.rx, m.y, font=self.label_font, text=package_name, + anchor='se') From 503e40500f8f708b931879abf6ce821f50fda089 Mon Sep 17 00:00:00 2001 From: Terry Greeniaus Date: Tue, 15 Feb 2022 01:48:55 -0800 Subject: [PATCH 06/10] tk/tk_workspace.py: Add extra space below regex field. --- stm_layout/tk/tk_workspace.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stm_layout/tk/tk_workspace.py b/stm_layout/tk/tk_workspace.py index 244f3c2..a61b923 100644 --- a/stm_layout/tk/tk_workspace.py +++ b/stm_layout/tk/tk_workspace.py @@ -54,7 +54,7 @@ def __init__(self, chip, elem_fill, hilite_fill, select_fill, re_fill): w = max(w, self.info_font.measure(f)) h = max(h, len(p.add_fns)) self.info_width = w + 5 - self.info_height = 15 + 30 + (h + 24) * dy + 15 + self.info_height = 15 + 30 + (h + 25) * dy + 15 self.info_canvas = self.add_canvas(self.info_width, self.info_height, 1, 0, sticky='nes') @@ -73,6 +73,7 @@ def __init__(self, chip, elem_fill, hilite_fill, select_fill, re_fill): e.focus_set() y += 30 + y += dy self.info_canvas.add_text( 15, y, font=self.info_font, text='Pin Info', anchor='nw') y += dy From 7b7d165f3253c9fc7d32b25756bb9bbbef37b845 Mon Sep 17 00:00:00 2001 From: Terry Greeniaus Date: Tue, 15 Feb 2022 01:48:55 -0800 Subject: [PATCH 07/10] tk/tk_workspace.py: Properly unhilite regex matches when changing pins. --- stm_layout/tk/tk_workspace.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/stm_layout/tk/tk_workspace.py b/stm_layout/tk/tk_workspace.py index a61b923..7290cc8 100644 --- a/stm_layout/tk/tk_workspace.py +++ b/stm_layout/tk/tk_workspace.py @@ -93,16 +93,16 @@ def __init__(self, chip, elem_fill, hilite_fill, select_fill, re_fill): self.info_af_texts.append(InfoText( self.info_canvas, 15, y, font=self.info_font, anchor='nw')) - max_add_fns = 0 + self.max_add_fns = 0 for _, p in chip.pins.items(): - max_add_fns = max(max_add_fns, len(p.add_fns)) + self.max_add_fns = max(self.max_add_fns, len(p.add_fns)) y += 2*dy self.info_canvas.add_text( 15, y, font=self.info_font, text='Additional Functions', anchor='nw') self.info_add_fns_texts = [] - for _ in range(max_add_fns): + for _ in range(self.max_add_fns): y += dy self.info_add_fns_texts.append(InfoText( self.info_canvas, 15, y, font=self.info_font, anchor='nw')) @@ -137,24 +137,25 @@ def update_info(self, pin_elem): else: self.pin_pos_text.set_bg('') - for t in self.info_af_texts: - t.set_text('') for i, f in enumerate(pin_elem.pin.alt_fns): self.info_af_texts[i].set_text(' %2u: %s' % (i, f)) if self.regex and self.regex.search(f): self.info_af_texts[i].set_bg(self.re_fill) else: self.info_af_texts[i].set_bg('') + for i in range(len(pin_elem.pin.alt_fns), 16): + self.info_af_texts[i].set_text('') + self.info_af_texts[i].set_bg('') - for t in self.info_add_fns_texts: - t.set_text('') - t.set_bg('') for i, f in enumerate(pin_elem.pin.add_fns): self.info_add_fns_texts[i].set_text(' %s' % f) if self.regex and self.regex.search(f): self.info_add_fns_texts[i].set_bg(self.re_fill) else: self.info_add_fns_texts[i].set_bg('') + for i in range(len(pin_elem.pin.add_fns), self.max_add_fns): + self.info_add_fns_texts[i].set_text('') + self.info_add_fns_texts[i].set_bg('') def color_pin(self, pin_elem): if self.hilited_pin == pin_elem: From f75c755d5237c0d5c14ee0e1d2b620be01ac5902 Mon Sep 17 00:00:00 2001 From: Terry Greeniaus Date: Tue, 15 Feb 2022 01:48:55 -0800 Subject: [PATCH 08/10] stm_layout/chip_stm.py: Document example chips for each of the weird full pin name formats. --- stm_layout/chip_stm.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stm_layout/chip_stm.py b/stm_layout/chip_stm.py index 68c6b34..7ce5e38 100644 --- a/stm_layout/chip_stm.py +++ b/stm_layout/chip_stm.py @@ -234,10 +234,10 @@ def make_chip(part): # full names: # # PA0 - # PA11 [PA9] - # PC14-OSC32_IN (PC14) - # PC14/OSC32_IN - # PC2_C + # PA11 [PA9] (stm32g050f6p6) + # PC14-OSC32_IN (PC14) (stm32u585qii3) + # PC14/OSC32_IN (stm32f767zit6) + # PC2_C (stm32h745xgh6 has PC2 and PC2_C) # # The short name is the initial prefix except in the case of an "_C" # suffix, in which case the short name includes the suffix. The GPIO From be8d8af2896ed70dc3700a0111430d6e1292afc1 Mon Sep 17 00:00:00 2001 From: Terry Greeniaus Date: Tue, 15 Feb 2022 01:48:55 -0800 Subject: [PATCH 09/10] stm_layout/chip_stm.py: Handle quirky full pin names that omit any type of separate between the pin name and OSC32 or BOOT0. --- stm_layout/chip_stm.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stm_layout/chip_stm.py b/stm_layout/chip_stm.py index 7ce5e38..b64ddde 100644 --- a/stm_layout/chip_stm.py +++ b/stm_layout/chip_stm.py @@ -237,6 +237,9 @@ def make_chip(part): # PA11 [PA9] (stm32g050f6p6) # PC14-OSC32_IN (PC14) (stm32u585qii3) # PC14/OSC32_IN (stm32f767zit6) + # PC14OSC32_IN (stm32f091rch6) + # PC15OSC32_OUT (stm32f091rch6) + # PF11BOOT0 (stm32f091rch6) # PC2_C (stm32h745xgh6 has PC2 and PC2_C) # # The short name is the initial prefix except in the case of an "_C" @@ -245,6 +248,8 @@ def make_chip(part): short_name = full_name.split('-')[0] short_name = short_name.split('/')[0] short_name = short_name.split(' ')[0] + short_name = short_name.split('OSC32_')[0] + short_name = short_name.split('BOOT0')[0] gpio_key = short_name.split('_')[0] # Extract the alternate (digital) functions and additional (analog) From 66d56be7d9acd7c5d7b7f2d3605aecf22a91602c Mon Sep 17 00:00:00 2001 From: Terry Greeniaus Date: Tue, 15 Feb 2022 01:48:55 -0800 Subject: [PATCH 10/10] stm_layout_tk: Include max frequency in the display. --- stm_layout/tk/tk_bga.py | 2 ++ stm_layout/tk/tk_lqfp.py | 3 ++- stm_layout/tk/tk_tssop.py | 3 ++- stm_layout/tk/tk_workspace.py | 6 ++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/stm_layout/tk/tk_bga.py b/stm_layout/tk/tk_bga.py index a685c8a..e271295 100644 --- a/stm_layout/tk/tk_bga.py +++ b/stm_layout/tk/tk_bga.py @@ -51,5 +51,7 @@ def __init__(self, *args): package_name = chip_db.package(self.chip.part) c.add_text(m.x, m.y, font=self.label_font, text=self.chip.name, anchor='sw') + c.add_text(m.x + m.width / 2, m.y, font=self.label_font, + text=self.max_freq_mhz, anchor='s') c.add_text(m.rx, m.y, font=self.label_font, text=package_name, anchor='se') diff --git a/stm_layout/tk/tk_lqfp.py b/stm_layout/tk/tk_lqfp.py index 81a5c2a..3d47325 100644 --- a/stm_layout/tk/tk_lqfp.py +++ b/stm_layout/tk/tk_lqfp.py @@ -45,7 +45,8 @@ def __init__(self, *args): c.add_text( m.x + m.width / 2, m.y + m.height / 2, font=self.label_font, - text='%s\n%s' % (self.chip.name, package_name), + text='%s\n%s\n%s' % (self.chip.name, package_name, + self.max_freq_mhz), anchor='c') if 'LQFP' not in package_name: diff --git a/stm_layout/tk/tk_tssop.py b/stm_layout/tk/tk_tssop.py index 5573118..07a46c1 100644 --- a/stm_layout/tk/tk_tssop.py +++ b/stm_layout/tk/tk_tssop.py @@ -41,5 +41,6 @@ def __init__(self, *args): c.add_text( m.x + m.width / 2, m.y + m.height / 2, font=self.label_font, - text='%s\n%s' % (self.chip.name, package_name), + text='%s\n%s\n%s' % (self.chip.name, package_name, + self.max_freq_mhz), anchor='c') diff --git a/stm_layout/tk/tk_workspace.py b/stm_layout/tk/tk_workspace.py index 7290cc8..ccf276b 100644 --- a/stm_layout/tk/tk_workspace.py +++ b/stm_layout/tk/tk_workspace.py @@ -37,6 +37,12 @@ def __init__(self, chip, elem_fill, hilite_fill, select_fill, re_fill): self.pin_elems = [] self.regex = None + d = chip.part.get_driver('rcc') + if d and 'max-frequency' in d: + self.max_freq_mhz = '%.0f MHz' % (int(d['max-frequency'][-1]) / 1e6) + else: + self.max_freq_mhz = '' + self.label_font = tkinter.font.Font(family=xplat.LABEL_FONT[0], size=xplat.LABEL_FONT[1]) self.pin_font = tkinter.font.Font(family=xplat.PIN_FONT[0],