-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_card.py
280 lines (237 loc) · 8.19 KB
/
test_card.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/env python
"""Generates a bunch of sample footprints into an SVG.
This is mostly used during development, to sanity-check many
footprints one one shot.
"""
import sys
from kidraw import ipc
from kidraw.ipc import library as lib
class Node:
def __init__(self, x=0, y=0, w=800, h=None):
self.x, self.y = x, y
self.w, self.h = w, h
self.drawing = None
self.down = None
self.right = None
def __iter__(self):
if self.drawing is not None:
yield self.drawing, self.x, self.y
if self.right is not None:
for r in self.right:
yield r
if self.down is not None:
for r in self.down:
yield r
def find_node(self, w, h):
if self.drawing is not None:
d = self.down.find_node(w, h) if self.down is not None else None
r = self.right.find_node(w, h) if self.right is not None else None
return r or d
if w > self.w:
return None
if self.h is not None and h > self.h:
return None
return self
def allocate(self, drawing, w, h):
self.drawing = drawing
self.down = Node(self.x,
self.y + h,
self.w,
self.h - h if self.h is not None else None)
self.right = Node(self.x + w,
self.y,
self.w - w,
h)
def binpack(drawings, w):
def k(d):
return -d[1].length * d[1].width
drawings = sorted(drawings, key=k)
t = Node(w=w)
for n, d in drawings:
w, h = d.length + 10, d.width + 30
t.find_node(w, h).allocate((n, d), w, h)
w, h = 0, 0
for (_, d), x, y in t:
w = max(w, x + d.length)
h = max(h, y + d.width + 30)
out = [
f'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="{w}" height="{h}">',
]
out.append(f'<rect width="{w}" height="{h}" fill="black" />')
for (n, d), x, y in t:
out.extend([
f'<g transform="translate({x}, {y})">',
d.svg(background_color="rgba(0, 0, 0, 0)"),
f'<text x="{d.length / 2}" y="{d.width + 20}" fill="green" stroke="green" text-anchor="middle" font-size="16">{n}</text>',
"</g>",
])
out.append("</svg>")
return "\n".join(out)
def drawing(f):
def run(*args, **kwargs):
try:
return f(*args, **kwargs)
except ipc.InfeasibleFootprint as e:
print(e, file=sys.stderr)
r = ipc.Drawing()
r.features += [
ipc.Drawing.Line(
layer=ipc.Drawing.Layer.Documentation,
points=[(-1.5, -1.5), (1.5, 1.5)],
width=ipc.PenWidth),
ipc.Drawing.Line(
layer=ipc.Drawing.Layer.Documentation,
points=[(-1.5, 1.5), (1.5, -1.5)],
width=ipc.PenWidth),
ipc.Drawing.Line(
layer=ipc.Drawing.Layer.Courtyard,
points=[(-1.5, -1.5), (-1.5, 1.5), (1.5, 1.5), (1.5, -1.5), (-1.5, -1.5)],
width=ipc.PenWidth),
]
return r
return run
@drawing
def tqfp(profile):
"""STM32F042K6T6 microcontroller"""
A = ipc.Dimension(6.8, 7.2)
L = ipc.Dimension(8.8, 9.2)
T = ipc.Dimension(0.450, 0.750)
W = ipc.Dimension(0.3, 0.45)
pitch = 0.8
return lib.QFP(profile, A, L, T, W, pitch, 32)
@drawing
def qfn(profile):
"""MAX3738 laser driver"""
A = ipc.Dimension(3.9, 4.1)
T = ipc.Dimension(0.3, 0.5)
W = ipc.Dimension(0.18, 0.30)
pitch = 0.5
return lib.QFN(profile, A, T, W, pitch, 24)
@drawing
def pqfn(profile):
"""QFN with pulled back leads"""
A = ipc.Dimension(3.9, 4.1)
L = ipc.Dimension(3.4, 3.6)
T = ipc.Dimension(0.3, 0.5)
W = ipc.Dimension(0.18, 0.30)
pitch = 0.5
return ipc.in_line_pin_device(
A=A, B=A, LA=L, LB=L, T=T, W=W, pitch=pitch,
pins_leftright=5, pins_updown=5,
spec=ipc.LandPatternSize.QFN(profile))
@drawing
def dfn(profile):
"""PIC12F609"""
A = ipc.Dimension.from_nominal(3, 0.1)
T = ipc.Dimension(0.2, 0.55)
W = ipc.Dimension(0.25, 0.35)
pitch = 0.65
return ipc.in_line_pin_device(
A=A, B=A, LA=A, LB=A, T=T, W=W, pitch=pitch,
pins_leftright=4, pins_updown=0,
spec=ipc.LandPatternSize.DFN(profile))
@drawing
def soic(profile):
"""PIC12F609 microcontroller"""
A = ipc.Dimension.from_nominal(3.9, 0.1)
B = ipc.Dimension.from_nominal(4.9, 0.1)
L = ipc.Dimension.from_nominal(6.0, 0.1)
T = ipc.Dimension(0.4, 1.27)
W = ipc.Dimension(0.31, 0.51)
return lib.SOIC(profile, A, B, L, T, W, 8)
@drawing
def ssop(profile):
"""Some MAX-something transceiver"""
A = ipc.Dimension(5.2, 5.38)
B = ipc.Dimension(6.07, 6.33)
L = ipc.Dimension(7.65, 7.90)
T = ipc.Dimension(0.63, 0.95)
W = ipc.Dimension(0.25, 0.38)
pitch = 0.65
return lib.SOP(profile, A, B, L, T, W, 16, pitch)
@drawing
def sc70(profile):
"""SCJW-8"""
A = ipc.Dimension.from_nominal(1.75, 0.1)
B = ipc.Dimension.from_nominal(2, 0.2)
L = ipc.Dimension.from_nominal(2.1, 0.2)
T = ipc.Dimension.from_nominal(0.45, 0.1)
W = ipc.Dimension.from_nominal(0.225, 0.075)
pitch = 0.5
spec = ipc.LandPatternSize.SOJ(profile)
return ipc.in_line_pin_device(
A=A, B=B, LA=L, LB=B, T=T, W=W, pitch=pitch,
pins_leftright=4, pins_updown=0, spec=spec)
@drawing
def tsopj(profile):
"""AAT1232 step-up converter"""
A = ipc.Dimension.from_nominal(2.4, 0.1)
B = ipc.Dimension.from_nominal(3, 0.1)
L = ipc.Dimension.from_nominal(2.85, 0.2)
T = ipc.Dimension.from_nominal(0.45, 0.15)
W = ipc.Dimension.from_nominal(0.2, 0.1, 0.05)
pitch = 0.5
spec = ipc.LandPatternSize.SOJ(profile)
return ipc.in_line_pin_device(
A=A, B=B, LA=L, LB=B, T=T, W=W, pitch=pitch,
pins_leftright=6, pins_updown=0, spec=spec)
@drawing
def SOD(profile, polarized):
A = ipc.Dimension(2.55, 2.85)
B = ipc.Dimension(1.4, 1.7)
L = ipc.Dimension(3.55, 3.85)
T = ipc.Dimension(0.25, 0.4)
W = ipc.Dimension.from_nominal(0.55, 0.1)
return ipc.two_terminal_symmetric_device(
A=A, B=B, L=L, T=T, W=W,
spec=ipc.LandPatternSize.SOD(
profile, A=A, L=L, T=T),
polarized=polarized)
@drawing
def Molded(profile, polarized):
A = ipc.Dimension.from_nominal(3.5, 0.2)
B = ipc.Dimension.from_nominal(2.8, 0.2)
T = ipc.Dimension.from_nominal(0.8, 0.3)
W = ipc.Dimension.from_nominal(2.2, 0.1)
return ipc.two_terminal_symmetric_device(
A=A, B=B, L=A, T=T, W=W,
spec=ipc.LandPatternSize.inward_L_leads(profile),
polarized=polarized)
@drawing
def MELF(profile, polarized):
A = ipc.Dimension(4.7, 5.2)
B = ipc.Dimension(2.41, 2.67)
T = ipc.Dimension(0.46, 0.56)
return ipc.two_terminal_symmetric_device(
A=A, B=B, L=A, T=T, W=B,
spec=ipc.LandPatternSize.MELF(profile),
polarized=polarized)
PROFILE = {
ipc.LandPatternSize.Most: "M",
ipc.LandPatternSize.Nominal: "N",
ipc.LandPatternSize.Least: "L",
}
fps = []
for p, letter in PROFILE.items():
fps.extend([
("32-TQFP-" + letter, tqfp(p)),
("24-QFN-" + letter, qfn(p)),
("20-PQFN-" + letter, pqfn(p)),
("8-DFN-" + letter, dfn(p)),
("8-SOIC-" + letter, soic(p)),
("16-SSOP-" + letter, ssop(p)),
("8-SC70-" + letter, sc70(p)),
("12-TSOPJ-" + letter, tsopj(p)),
])
for polarized in (True, False):
pol = "P" if polarized else ""
for s in ("0402", "0603", "0805", "1206"):
fps.append((f"{s}-{pol}-{letter}",
lib.chip(p, lib.imperial(s), polarized)))
fps.append(("SOD-%s-%s" % (pol, letter), SOD(p, polarized)))
fps.append(("Molded-%s-%s" % (pol, letter), Molded(p, polarized)))
fps.append(("MELF-%s-%s" % (pol, letter), MELF(p, polarized)))
for s in (3, 5, 6, 8):
fps.append((f"SOT23-{s}", lib.SOT23(p, s)))
with open("card.svg", "w") as f:
f.write(binpack([(n, x.scale(30)) for n, x in fps], w=1200))