This repository has been archived by the owner on May 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
qfp_wizard.py
169 lines (132 loc) · 6.09 KB
/
qfp_wizard.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
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
from __future__ import division
import pcbnew
import FootprintWizardBase
import PadArray as PA
class QFPWizard(FootprintWizardBase.FootprintWizard):
def GetName(self):
return "QFP"
def GetDescription(self):
return "Quad Flat Package (QFP) footprint wizard"
def GenerateParameterList(self):
self.AddParam("Pads", "n", self.uInteger, 100, multiple=4, min_value=4)
self.AddParam("Pads", "pitch", self.uMM, 0.5, designator='e')
self.AddParam("Pads", "width", self.uMM, 0.25, designator='X1')
self.AddParam("Pads", "length", self.uMM, 1.5, designator='Y1')
self.AddParam("Pads", "horizontal spacing", self.uMM, 15, designator='C1')
self.AddParam("Pads", "vertical spacing", self.uMM, 15, designator='C2')
self.AddParam("Pads", "oval", self.uBool, True)
self.AddParam("Package", "width", self.uMM, 14, designator='D1')
self.AddParam("Package", "height", self.uMM, 14, designator='E1')
self.AddParam("Package", "courtyard margin", self.uMM, 0.25, min_value=0.2)
@property
def pads(self):
return self.parameters['Pads']
@property
def package(self):
return self.parameters['Package']
def CheckParameters(self):
# todo - custom checking
pass
def GetValue(self):
return "QFP-{n}_{x:g}x{y:g}_Pitch{p:g}mm".format(
n = self.pads['n'],
x = pcbnew.ToMM(self.package['width']),
y = pcbnew.ToMM(self.package['height']),
p = pcbnew.ToMM(self.pads['pitch'])
)
def BuildThisFootprint(self):
pad_pitch = self.pads["pitch"]
pad_length = self.pads["length"]
pad_width = self.pads["width"]
v_pitch = self.pads["vertical spacing"]
h_pitch = self.pads["horizontal spacing"]
pads_per_row = int(self.pads["n"] // 4)
row_len = (pads_per_row - 1) * pad_pitch
pad_shape = pcbnew.PAD_SHAPE_OVAL if self.pads["oval"] else pcbnew.PAD_SHAPE_RECT
h_pad = PA.PadMaker(self.module).SMDPad( pad_length, pad_width,
shape=pad_shape, rot_degree=90.0)
v_pad = PA.PadMaker(self.module).SMDPad( pad_length, pad_width, shape=pad_shape)
#left row
pin1Pos = pcbnew.wxPoint(-h_pitch / 2, 0)
array = PA.PadLineArray(h_pad, pads_per_row, pad_pitch, True, pin1Pos)
array.SetFirstPadInArray(1)
array.AddPadsToModule(self.draw)
#bottom row
pin1Pos = pcbnew.wxPoint(0, v_pitch / 2)
array = PA.PadLineArray(v_pad, pads_per_row, pad_pitch, False, pin1Pos)
array.SetFirstPadInArray(pads_per_row + 1)
array.AddPadsToModule(self.draw)
#right row
pin1Pos = pcbnew.wxPoint(h_pitch / 2, 0)
array = PA.PadLineArray(h_pad, pads_per_row, -pad_pitch, True,
pin1Pos)
array.SetFirstPadInArray(2*pads_per_row + 1)
array.AddPadsToModule(self.draw)
#top row
pin1Pos = pcbnew.wxPoint(0, -v_pitch / 2)
array = PA.PadLineArray(v_pad, pads_per_row, -pad_pitch, False,
pin1Pos)
array.SetFirstPadInArray(3*pads_per_row + 1)
array.AddPadsToModule(self.draw)
offset = pcbnew.FromMM(0.15)
x = self.parameters["Package"]["width"] / 2 + offset
y = self.parameters["Package"]["height"] / 2 + offset
inner = (row_len / 2) + pad_pitch
# Add outline to F_Fab layer
self.draw.SetLayer(pcbnew.F_Fab)
bevel = min( pcbnew.FromMM(1.0), self.package['width']/2, self.package['height']/2 )
w = self.package['width']
h = self.package['height']
# outermost limits of pins
right_edge = (h_pitch + pad_length) / 2
left_edge = -right_edge
bottom_edge = (v_pitch + pad_length) / 2
top_edge = -bottom_edge
self.draw.BoxWithDiagonalAtCorner(0, 0, w, h, bevel)
# Draw silkscreen
self.draw.SetLayer(pcbnew.F_SilkS)
#top left - as per IPC-7351C
self.draw.Polyline([(-inner, -y), (-x, -y), (-x, -inner), (left_edge, -inner)])
# top right
self.draw.Polyline([(inner, -y), (x, -y), (x, -inner)])
# bottom left
self.draw.Polyline([(-inner, y), (-x, y), (-x, inner)])
# bottom right
self.draw.Polyline([(inner, y), (x, y), (x, inner)])
# Courtyard
cmargin = self.parameters["Package"]["courtyard margin"]
self.draw.SetLayer(pcbnew.F_CrtYd)
sizex = (right_edge + cmargin) * 2
sizey = (bottom_edge + cmargin) * 2
# round size to nearest 0.1mm, rectangle will thus land on a 0.05mm grid
sizex = pcbnew.PutOnGridMM(sizex, 0.1)
sizey = pcbnew.PutOnGridMM(sizey, 0.1)
# set courtyard line thickness to the one defined in KLC
thick = self.draw.GetLineThickness()
self.draw.SetLineThickness(pcbnew.FromMM(0.05))
self.draw.Box(0, 0, sizex, sizey)
# restore line thickness to previous value
self.draw.SetLineThickness(pcbnew.FromMM(thick))
#reference and value
text_size = self.GetTextSize() # IPC nominal
text_offset = v_pitch / 2 + text_size + pad_length / 2
self.draw.Value(0, text_offset, text_size)
self.draw.Reference(0, -text_offset, text_size)
# set SMD attribute
self.module.SetAttributes(pcbnew.MOD_CMS)
QFPWizard().register()