Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #150 from evanshultz/bga
Browse files Browse the repository at this point in the history
Mask/paste global footprint support & new BGA entries
  • Loading branch information
pointhi committed Sep 13, 2018
2 parents f6a7c87 + c5f0b1a commit 17f34ec
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 116 deletions.
12 changes: 12 additions & 0 deletions KicadModTree/KicadFileHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ def serialize(self, **kwargs):
sexpr.append(['attr', self.kicad_mod.attribute])
sexpr.append(SexprSerializer.NEW_LINE)

if self.kicad_mod.maskMargin:
sexpr.append(['solder_mask_margin', self.kicad_mod.maskMargin])
sexpr.append(SexprSerializer.NEW_LINE)

if self.kicad_mod.pasteMargin:
sexpr.append(['solder_paste_margin', self.kicad_mod.pasteMargin])
sexpr.append(SexprSerializer.NEW_LINE)

if self.kicad_mod.pasteMarginRatio:
sexpr.append(['solder_paste_ratio', self.kicad_mod.pasteMarginRatio])
sexpr.append(SexprSerializer.NEW_LINE)

sexpr.extend(self._serializeTree())

return str(SexprSerializer(sexpr))
Expand Down
19 changes: 18 additions & 1 deletion KicadModTree/nodes/Footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
'''

# define in which order the general "lisp" operators are arranged
render_order = ['descr', 'tags', 'attr', 'fp_text', 'fp_circle', 'fp_line', 'pad', 'model']
render_order = ['descr', 'tags', 'attr', 'solder_mask_margin',
'solder_paste_margin', 'solder_paste_ratio', 'fp_text',
'fp_circle', 'fp_line', 'pad', 'model']
# TODO: sort Text by type


Expand All @@ -45,6 +47,9 @@ def __init__(self, name):
self.description = None
self.tags = None
self.attribute = None
self.maskMargin = None
self.pasteMargin = None
self.pasteMarginRatio = None

def setName(self, name):
self.name = name
Expand All @@ -57,3 +62,15 @@ def setTags(self, tags):

def setAttribute(self, value):
self.attribute = value

def setMaskMargin(self, value):
self.maskMargin = value

def setPasteMargin(self, value):
self.pasteMargin = value

def setPasteMarginRatio(self, value):
# paste_margin_ratio is unitless between 0 and 1 while GUI uses percentage
assert abs(value) <= 1, "Solder paste margin must be between -1 and 1. {} is too large.".format(value)

self.pasteMarginRatio = value
13 changes: 7 additions & 6 deletions KicadModTree/nodes/base/Pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class Pad(Node):
number/name of the pad (default: \"\")
* *type* (``Pad.TYPE_THT``, ``Pad.TYPE_SMT``, ``Pad.TYPE_CONNECT``, ``Pad.TYPE_NPTH``) --
type of the pad
* *shape* (``Pad.SHAPE_CIRCLE``, ``Pad.SHAPE_OVAL``, ``Pad.SHAPE_RECT``, ``Pad.SHAPE_TRAPEZE``) --
* *shape* (``Pad.SHAPE_CIRCLE``, ``Pad.SHAPE_OVAL``, ``Pad.SHAPE_RECT``, ``SHAPE_ROUNDRECT``,
``Pad.SHAPE_TRAPEZE``, ``SHAPE_CUSTOM``) --
shape of the pad
* *at* (``Vector2D``) --
center position of the pad
Expand All @@ -52,7 +53,7 @@ class Pad(Node):
Ignored for every other shape.
* *maximum_radius* (``float``) --
The maximum radius for the rounded rectangle.
If the radius produced by the radius ratio parameter for this pad would
If the radius produced by the radius_ratio parameter for the pad would
exceed the maximum radius, the ratio is reduced to limit the ratio.
(This is useful for IPC-7351C compliance as it suggests 25% ratio with limit 0.25mm)
Ignored for every other shape.
Expand Down Expand Up @@ -215,16 +216,16 @@ def _initRadiusRatio(self, **kwargs):
if radius_ratio >= 0 and radius_ratio <= 0.5:
self.radius_ratio = radius_ratio
else:
raise ValueError('radius ratio out of allowed range (0 < rr <= 0.5)')
raise ValueError('radius ratio out of allowed range (0 <= rr <= 0.5)')

if kwargs.get('maximum_radius') is not None:
maximum_radius = kwargs.get('maximum_radius')
if type(maximum_radius) not in [int, float]:
raise TypeError('maximum radius needs to be of type int or float')

shortest_sidlength = min(self.size)
if self.radius_ratio*shortest_sidlength > maximum_radius:
self.radius_ratio = maximum_radius/shortest_sidlength
shortest_sidelength = min(self.size)
if self.radius_ratio*shortest_sidelength > maximum_radius:
self.radius_ratio = maximum_radius/shortest_sidelength

if self.radius_ratio == 0:
self.shape = Pad.SHAPE_RECT
Expand Down
70 changes: 32 additions & 38 deletions scripts/Package_BGA/bga.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ def bga(args):

pitch = args["pitch"]
padDiameter = args["pad_diameter"]
maskMargin = args["mask_margin"]
pasteMargin = args["paste_margin"]
pasteRatio = args["paste_ratio"]
pasteDiameter = args["paste_diameter"]
layoutX = args["layout_x"]
layoutY = args["layout_y"]
rowNames = args["row_names"]
Expand All @@ -28,19 +29,15 @@ def bga(args):
f = Footprint(footprint_name)
f.setDescription(desc)
f.setAttribute("smd")
f.setMaskMargin(maskMargin)
f.setPasteMargin(pasteMargin)
f.setPasteMarginRatio(pasteRatio)

package_type = 'CSP' if 'BGA' not in footprint_name and 'CSP' in footprint_name else 'BGA'

# If this looks like a CSP footprint, use the CSP 3dshapes library
if 'BGA' not in footprint_name and 'CSP' in footprint_name:
f.append(Model(filename="${{KISYS3DMOD}}/Package_CSP.3dshapes"
"/{}.wrl".format(footprint_name),
at=[0.0, 0.0, 0.0],
scale=[1.0, 1.0, 1.0],
rotate=[0.0, 0.0, 0.0]))
else:
f.append(Model(filename="${{KISYS3DMOD}}/Package_BGA.3dshapes"
"/{}.wrl".format(footprint_name),
at=[0.0, 0.0, 0.0],
scale=[1.0, 1.0, 1.0],
rotate=[0.0, 0.0, 0.0]))
f.append(Model(filename="${{KISYS3DMOD}}/Package_{}.3dshapes/{}.wrl".format(
package_type, footprint_name)))

s1 = [1.0, 1.0]
s2 = [min(1.0, round(pkgWidth / 4.3, 2))] * 2
Expand All @@ -50,40 +47,37 @@ def bga(args):

padShape = Pad.SHAPE_CIRCLE

chamfer = min(1.0, min(pkgWidth, pkgHeight)*0.25)
silkOffset = 0.125
crtYd = 1.0

if pasteDiameter:
pasteRatio = (pasteDiameter / padDiameter - 1) / 2

chamfer = min(1.0, min(pkgWidth, pkgHeight) * 0.25)
silkOffset = 0.11
crtYdOffset = 1.0

def crtYdRound(x):
# Round away from zero for proper courtyard calculation
neg = x < 0
if neg:
x = -x
x = math.ceil(x * 100) / 100
x = math.ceil(x * 100) / 100.0
if neg:
x = -x
return x

xCenter = 0.0
xLeftFab = xCenter - pkgWidth / 2
xRightFab = xCenter + pkgWidth / 2
xLeftFab = xCenter - pkgWidth / 2.0
xRightFab = xCenter + pkgWidth / 2.0
xChamferFab = xLeftFab + chamfer
xPadLeft = xCenter - pitch * ((layoutX - 1) / 2)
xPadRight = xCenter + pitch * ((layoutX - 1) / 2)
xLeftCrtYd = crtYdRound(xCenter - (pkgWidth / 2 + crtYd))
xRightCrtYd = crtYdRound(xCenter + (pkgWidth / 2 + crtYd))
xPadLeft = xCenter - pitch * ((layoutX - 1) / 2.0)
xPadRight = xCenter + pitch * ((layoutX - 1) / 2.0)
xLeftCrtYd = crtYdRound(xCenter - (pkgWidth / 2.0 + crtYdOffset))
xRightCrtYd = crtYdRound(xCenter + (pkgWidth / 2.0 + crtYdOffset))

yCenter = 0.0
yTopFab = yCenter - pkgHeight / 2
yBottomFab = yCenter + pkgHeight / 2
yTopFab = yCenter - pkgHeight / 2.0
yBottomFab = yCenter + pkgHeight / 2.0
yChamferFab = yTopFab + chamfer
yPadTop = yCenter - pitch * ((layoutY - 1) / 2)
yPadBottom = yCenter + pitch * ((layoutY - 1) / 2)
yTopCrtYd = crtYdRound(yCenter - (pkgHeight / 2 + crtYd))
yBottomCrtYd = crtYdRound(yCenter + (pkgHeight / 2 + crtYd))
yPadTop = yCenter - pitch * ((layoutY - 1) / 2.0)
yPadBottom = yCenter + pitch * ((layoutY - 1) / 2.0)
yTopCrtYd = crtYdRound(yCenter - (pkgHeight / 2.0 + crtYdOffset))
yBottomCrtYd = crtYdRound(yCenter + (pkgHeight / 2.0 + crtYdOffset))
yRef = yTopFab - 1.0
yValue = yBottomFab + 1.0

Expand Down Expand Up @@ -149,11 +143,10 @@ def crtYdRound(x):
shape=padShape,
at=[xPadLeft + (col-1) * pitch, yPadTop + rowNum * pitch],
size=[padDiameter, padDiameter],
layers=Pad.LAYERS_SMT,
solder_paste_margin_ratio=pasteRatio))

f.setTags("BGA {} {}".format(balls, pitch))
layers=Pad.LAYERS_SMT))

f.setTags("{} {} {}".format(package_type, balls, pitch))

file_handler = KicadFileHandler(f)
file_handler.writeFile(footprint_name + ".kicad_mod")

Expand All @@ -166,8 +159,9 @@ def crtYdRound(x):
parser.add_parameter("pkg_height", type=float, required=True)
parser.add_parameter("pitch", type=float, required=True)
parser.add_parameter("pad_diameter", type=float, required=True)
parser.add_parameter("mask_margin", type=float, required=False, default=0)
parser.add_parameter("paste_margin", type=float, required=False, default=0)
parser.add_parameter("paste_ratio", type=float, required=False, default=0)
parser.add_parameter("paste_diameter", type=float, required=False, default=0)
parser.add_parameter("layout_x", type=int, required=True)
parser.add_parameter("layout_y", type=int, required=True)
parser.add_parameter("row_names", type=list, required=False, default=[
Expand Down
81 changes: 67 additions & 14 deletions scripts/Package_BGA/bga.yml
Original file line number Diff line number Diff line change
@@ -1,110 +1,163 @@
LFBGA-100_10x10mm_Layout10x10_P0.8mm:
description: "LFBGA-100, 10x10 raster, 10x10mm package, pitch 0.8mm; see section 6.3 of http://www.st.com/resource/en/datasheet/stm32f103tb.pdf"
description: "LFBGA-100, 10x10 raster, 10x10mm package, pitch 0.8mm; http://www.st.com/resource/en/datasheet/stm32f103tb.pdf#page=87"
pkg_width: 10.0
pkg_height: 10.0
pitch: 0.8
pad_diameter: 0.5
mask_margin: 0.035
paste_margin: 0.000001
layout_x: 10
layout_y: 10
LFBGA-144_10x10mm_Layout12x12_P0.8mm:
description: "LFBGA-144, 12x12 raster, 10x10mm package, pitch 0.8mm; see section 6.1 of http://www.st.com/resource/en/datasheet/stm32f103ze.pdf"
description: "LFBGA-144, 12x12 raster, 10x10mm package, pitch 0.8mm; http://www.st.com/resource/en/datasheet/stm32f103ze.pdf#page=114"
pkg_width: 10.0
pkg_height: 10.0
pitch: 0.8
pad_diameter: 0.4
mask_margin: 0.035
paste_margin: 0.000001
layout_x: 12
layout_y: 12
Texas_DSBGA-49_3.33x3.488mm_Layout7x7_P0.4mm:
description: "Texas Instruments, DSBGA, 3.33x3.488x0.625mm, 49 ball 7x7 area grid, NSMD pad definition (http://www.ti.com/lit/ds/symlink/msp430f2234.pdf, http://www.ti.com/lit/an/snva009ag/snva009ag.pdf)"
pkg_width: 3.33
pkg_height: 3.488
pitch: 0.4
pad_diameter: 0.225
layout_x: 7
layout_y: 7
mask_margin: 0.05
Texas_DSBGA-64_3.415x3.535mm_Layout8x8_P0.4mm:
description: "Texas Instruments, DSBGA, 3.415x3.535x0.625mm, 64 ball 8x8 area grid, NSMD pad definition (http://www.ti.com/lit/ds/slas718g/slas718g.pdf, http://www.ti.com/lit/an/snva009ag/snva009ag.pdf)"
pkg_width: 3.415
pkg_height: 3.535
pitch: 0.4
pad_diameter: 0.225
layout_x: 8
layout_y: 8
mask_margin: 0.05
Texas_MicroStar_Junior_BGA-113_7.0x7.0mm_Layout12x12_P0.5mm:
description: "Texas Instruments, BGA Microstar Junior, 7x7mm, 113 ball 12x12 grid, NSMD pad definition (http://www.ti.com/lit/ml/mpbg674/mpbg674.pdf, http://www.ti.com/lit/wp/ssyz015b/ssyz015b.pdf)"
pkg_width: 7
pkg_height: 7
pitch: 0.5
pad_diameter: 0.25
layout_x: 12
layout_y: 12
mask_margin: 0.025
row_skips: [[], [], [[4, 11]], [3, 10], [3, 10], [3, 6, 7, 10], [3, 6, 7, 10], [3, 10], [3, 10], [[3, 11]], [], []]
TFBGA-64_5x5mm_Layout8x8_P0.5mm:
description: "TFBGA-64, 8x8 raster, 5x5mm package, pitch 0.5mm; see section 6.3 of http://www.st.com/resource/en/datasheet/stm32f100v8.pdf"
description: "TFBGA-64, 8x8 raster, 5x5mm package, pitch 0.5mm; http://www.st.com/resource/en/datasheet/stm32f100v8.pdf#page=83"
pkg_width: 5.0
pkg_height: 5.0
pitch: 0.5
pad_diameter: 0.28
mask_margin: 0.045
paste_margin: 0.000001
layout_x: 8
layout_y: 8
TFBGA-100_8x8mm_Layout10x10_P0.8mm:
description: "TFBGA-100, 10x10 raster, 8x8mm package, pitch 0.8mm; see section 6.2 of http://www.st.com/resource/en/datasheet/stm32f746zg.pdf"
description: "TFBGA-100, 10x10 raster, 8x8mm package, pitch 0.8mm; http://www.st.com/resource/en/datasheet/stm32f746zg.pdf#page=199"
pkg_width: 8.0
pkg_height: 8.0
pitch: 0.8
pad_diameter: 0.4
mask_margin: 0.035
paste_margin: 0.000001
layout_x: 10
layout_y: 10
TFBGA-216_13x13mm_Layout15x15_P0.8mm:
description: "TFBGA-216, 15x15 raster, 13x13mm package, pitch 0.8mm; see section 6.8 of http://www.st.com/resource/en/datasheet/stm32f746zg.pdf"
description: "TFBGA-216, 15x15 raster, 13x13mm package, pitch 0.8mm; http://www.st.com/resource/en/datasheet/stm32f746zg.pdf#page=219"
pkg_width: 13.0
pkg_height: 13.0
pitch: 0.8
pad_diameter: 0.4
mask_margin: 0.035
paste_margin: 0.000001
layout_x: 15
layout_y: 15
row_skips: [[], [], [], [], [], [], [[7, 10]], [[7, 10]], [[7, 10]], [], [], [], [], [], []]
TFBGA-265_14x14mm_Layout17x17_P0.8mm:
description: "TFBGA-265, 17x17 raster, 14x14mm package, pitch 0.8mm; see section 7.8 of http://www.st.com/resource/en/datasheet/DM00387108.pdf"
description: "TFBGA-265, 17x17 raster, 14x14mm package, pitch 0.8mm; http://www.st.com/resource/en/datasheet/DM00387108.pdf#page=223"
pkg_width: 14.0
pkg_height: 14.0
pitch: 0.8
pad_diameter: 0.325
paste_ratio: -.115
mask_margin: 0.0325
paste_ratio: 0.0125
layout_x: 17
layout_y: 17
row_skips: [[], [], [], [], [], [[6, 13]], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [[6, 13]], [], [], [], [], []]
UFBGA-64_5x5mm_Layout8x8_P0.5mm:
description: "UFBGA-64, 8x8 raster, 5x5mm package, pitch 0.5mm; see section 7.1 of http://www.st.com/resource/en/datasheet/stm32f051t8.pdf"
description: "UFBGA-64, 8x8 raster, 5x5mm package, pitch 0.5mm; http://www.st.com/resource/en/datasheet/stm32f051t8.pdf#page=91"
pkg_width: 5.0
pkg_height: 5.0
pitch: 0.5
pad_diameter: 0.28
mask_margin: 0.045
paste_margin: 0.000001
layout_x: 8
layout_y: 8
UFBGA-100_7x7mm_Layout12x12_P0.5mm:
description: "UFBGA-100, 12x12 raster, 7x7mm package, pitch 0.5mm; see section 7.1 of http://www.st.com/resource/en/datasheet/stm32f103tb.pdf"
description: "UFBGA-100, 12x12 raster, 7x7mm package, pitch 0.5mm; http://www.st.com/resource/en/datasheet/stm32f103tb.pdf#page=93"
pkg_width: 7.0
pkg_height: 7.0
pitch: 0.5
pad_diameter: 0.28
mask_margin: 0.045
paste_margin: 0.000001
layout_x: 12
layout_y: 12
row_skips: [[], [], [6, 7], [[4, 10]], [[4, 10]], [[3, 11]], [[3, 11]], [[4, 10]], [[4, 10]], [6, 7], [], []]
UFBGA-132_7x7mm_Layout12x12_P0.5mm:
description: "UFBGA-132, 12x12 raster, 7x7mm package, pitch 0.5mm; see section 7.4 of http://www.st.com/resource/en/datasheet/stm32l152zc.pdf"
description: "UFBGA-132, 12x12 raster, 7x7mm package, pitch 0.5mm; http://www.st.com/resource/en/datasheet/stm32l152zc.pdf#page=123"
pkg_width: 7.0
pkg_height: 7.0
pitch: 0.5
pad_diameter: 0.27
mask_margin: 0.04
paste_margin: 0.000001
layout_x: 12
layout_y: 12
row_skips: [[], [], [], [], [[5, 9]], [5, 8], [5, 8], [[5, 9]], [], [], [], []]
UFBGA-144_7x7mm_Layout12x12_P0.5mm:
description: "UFBGA-144, 12x12 raster, 7x7mm package, pitch 0.5mm; see section 7.4 of http://www.st.com/resource/en/datasheet/stm32f446ze.pdf"
description: "UFBGA-144, 12x12 raster, 7x7mm package, pitch 0.5mm; http://www.st.com/resource/en/datasheet/stm32f446ze.pdf#page=186"
pkg_width: 7.0
pkg_height: 7.0
pitch: 0.5
pad_diameter: 0.28
mask_margin: 0.045
paste_margin: 0.000001
layout_x: 12
layout_y: 12
UFBGA-144_10x10mm_Layout12x12_P0.8mm:
description: "UFBGA-144, 12x12 raster, 10x10mm package, pitch 0.8mm; see section 7.5 of http://www.st.com/resource/en/datasheet/stm32f446ze.pdf"
description: "UFBGA-144, 12x12 raster, 10x10mm package, pitch 0.8mm; http://www.st.com/resource/en/datasheet/stm32f446ze.pdf#page=189"
pkg_width: 10.0
pkg_height: 10.0
pitch: 0.8
pad_diameter: 0.4
mask_margin: 0.075
paste_margin: 0.000001
layout_x: 12
layout_y: 12
UFBGA-169_7x7mm_Layout13x13_P0.5mm:
description: "UFBGA-169, 13x13 raster, 7x7mm package, pitch 0.5mm; see section 7.6 of http://www.st.com/resource/en/datasheet/stm32f429ng.pdf"
description: "UFBGA-169, 13x13 raster, 7x7mm package, pitch 0.5mm; http://www.st.com/resource/en/datasheet/stm32f429ng.pdf#page=218"
pkg_width: 7.0
pkg_height: 7.0
pitch: 0.5
pad_diameter: 0.27
mask_margin: 0.04
paste_margin: 0.000001
layout_x: 13
layout_y: 13
UFBGA-201_10x10mm_Layout15x15_P0.65mm:
description: "UFBGA-201, 15x15 raster, 10x10mm package, pitch 0.65mm; see section 7.6 of http://www.st.com/resource/en/datasheet/stm32f207vg.pdf"
description: "UFBGA-201, 15x15 raster, 10x10mm package, pitch 0.65mm; http://www.st.com/resource/en/datasheet/stm32f207vg.pdf#page=166"
pkg_width: 10.0
pkg_height: 10.0
pitch: 0.65
pad_diameter: 0.3
mask_margin: 0.05
paste_margin: 0.000001
layout_x: 15
layout_y: 15
row_skips: [[], [], [], [], [[5, 12]], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [[5, 12]], [], [], [], []]
Loading

0 comments on commit 17f34ec

Please sign in to comment.