Skip to content

Commit

Permalink
stm_layout_tk: Factor platform-specific twiddle values into xplat par…
Browse files Browse the repository at this point in the history
…ameters.
  • Loading branch information
tgree committed Feb 15, 2022
1 parent cf8e1ae commit 8d8264d
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 133 deletions.
3 changes: 3 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ disable=bad-whitespace,
useless-super-delegation,
consider-using-f-string,
R0801

[TYPECHECK]
generated-members=xplat.*
43 changes: 38 additions & 5 deletions stm_layout/stm_layout_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)

Expand Down
7 changes: 5 additions & 2 deletions stm_layout/tk/tk_bga.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import tk_workspace
from . import xplat


PIN_DIAM = 30
Expand Down Expand Up @@ -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
66 changes: 66 additions & 0 deletions stm_layout/tk/tk_edgy.py
Original file line number Diff line number Diff line change
@@ -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)
86 changes: 14 additions & 72 deletions stm_layout/tk/tk_lqfp.py
Original file line number Diff line number Diff line change
@@ -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))

Expand All @@ -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)
Expand All @@ -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)
47 changes: 10 additions & 37 deletions stm_layout/tk/tk_tssop.py
Original file line number Diff line number Diff line change
@@ -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))

Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions stm_layout/tk/tk_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import tkinter.font

from .tk_elems import TKBase
from . import xplat


class InfoText:
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 8d8264d

Please sign in to comment.