-
Notifications
You must be signed in to change notification settings - Fork 62
Fix courtyards for bga, quad, qfn,soic, etc #581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f8d311a
38f8c84
21fa01f
d4be5e4
7cf5cde
83674ec
faab62e
71dfc0e
e52ceae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import type { | ||
| AnyCircuitElement, | ||
| PcbCourtyardRect, | ||
| PcbCourtyardOutline, | ||
| PcbSilkscreenPath, | ||
| } from "circuit-json" | ||
| import { | ||
|
|
@@ -13,6 +13,8 @@ import { rectpad } from "src/helpers/rectpad" | |
| import { z } from "zod" | ||
| import { CORNERS } from "src/helpers/corner" | ||
| import { type SilkscreenRef, silkscreenRef } from "src/helpers/silkscreenRef" | ||
| import { roundCourtyardCoord } from "../helpers/round-courtyard-coord" | ||
| import { createRectCourtyardOutlinePoints } from "src/helpers/create-rect-courtyard-outline-points" | ||
|
|
||
| export const dfn_def = extendSoicDef({}) | ||
|
|
||
|
|
@@ -100,20 +102,48 @@ export const dfn = ( | |
| sh / 2 + 0.4, | ||
| sh / 12, | ||
| ) | ||
| const courtyardPadding = 0.25 | ||
| const crtMinX = -sw / 2 - courtyardPadding | ||
| const crtMaxX = sw / 2 + courtyardPadding | ||
| const crtMinY = -sh / 2 - courtyardPadding | ||
| const crtMaxY = sh / 2 + courtyardPadding | ||
| const courtyard: PcbCourtyardRect = { | ||
| type: "pcb_courtyard_rect", | ||
| pcb_courtyard_rect_id: "", | ||
| pcb_component_id: "", | ||
| center: { x: (crtMinX + crtMaxX) / 2, y: (crtMinY + crtMaxY) / 2 }, | ||
| width: crtMaxX - crtMinX, | ||
| height: crtMaxY - crtMinY, | ||
| layer: "top", | ||
| } | ||
| const useManualCourtyardForDfn8_2x2 = | ||
| parameters.num_pins === 8 && | ||
| parameters.w === 2.75 && | ||
| parameters.p === 0.5 && | ||
| parameters.pl === 0.85 && | ||
| parameters.pw === 0.3 | ||
|
|
||
| const courtyard: PcbCourtyardOutline = useManualCourtyardForDfn8_2x2 | ||
| ? { | ||
| type: "pcb_courtyard_outline", | ||
| pcb_courtyard_outline_id: "", | ||
| pcb_component_id: "", | ||
| // KiCad parity: DFN-8_2x2mm_P0.5mm | ||
| outline: createRectCourtyardOutlinePoints(3.3, 2.7), | ||
| layer: "top", | ||
| } | ||
| : (() => { | ||
| const courtyardClearanceMm = 0.25 | ||
| const padHalfWidthMm = parameters.w / 2 | ||
| const padHalfHeightMm = | ||
| ((parameters.num_pins / 2 - 1) * parameters.p) / 2 + parameters.pw / 2 | ||
| const bodyHalfWidthMm = sw / 2 | ||
| const bodyHalfHeightMm = sh / 2 | ||
| const courtyardOuterHalfWidthMm = roundCourtyardCoord( | ||
| Math.max(padHalfWidthMm, bodyHalfWidthMm) + courtyardClearanceMm, | ||
| ) | ||
| const courtyardOuterHalfHeightMm = roundCourtyardCoord( | ||
| Math.max(padHalfHeightMm, bodyHalfHeightMm) + courtyardClearanceMm, | ||
| ) | ||
| return { | ||
| type: "pcb_courtyard_outline" as const, | ||
| pcb_courtyard_outline_id: "", | ||
| pcb_component_id: "", | ||
| outline: [ | ||
| { x: -courtyardOuterHalfWidthMm, y: courtyardOuterHalfHeightMm }, | ||
| { x: -courtyardOuterHalfWidthMm, y: -courtyardOuterHalfHeightMm }, | ||
| { x: courtyardOuterHalfWidthMm, y: -courtyardOuterHalfHeightMm }, | ||
| { x: courtyardOuterHalfWidthMm, y: courtyardOuterHalfHeightMm }, | ||
| ], | ||
| layer: "top" as const, | ||
| } | ||
| })() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is called an IIFE or immediately invoked function expression and it's an anti-pattern in most cases, can you write this more cleanly? Without a ternary? |
||
|
|
||
| return { | ||
| circuitJson: [ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,14 @@ | ||
| import type { | ||
| AnyCircuitElement, | ||
| PcbCourtyardRect, | ||
| PcbCourtyardOutline, | ||
| PcbSilkscreenPath, | ||
| } from "circuit-json" | ||
| import { z } from "zod" | ||
| import { rectpad } from "../helpers/rectpad" | ||
| import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef" | ||
| import { length } from "circuit-json" | ||
| import { base_def } from "../helpers/zod/base_def" | ||
| import { roundCourtyardCoord } from "../helpers/round-courtyard-coord" | ||
|
|
||
| const getDefaultValues = (num_pins: number) => { | ||
| switch (num_pins) { | ||
|
|
@@ -84,10 +85,14 @@ export const msop = ( | |
| const pw = length.parse(parameters.pw || defaults.pw) | ||
|
|
||
| const pads: AnyCircuitElement[] = [] | ||
| let maxPadExtentX = 0 | ||
| let maxPadExtentY = 0 | ||
|
|
||
| for (let i = 0; i < parameters.num_pins; i++) { | ||
| const { x, y } = getMsopCoords(parameters.num_pins, i + 1, w, p) | ||
| pads.push(rectpad(i + 1, x, y, pl, pw)) | ||
| maxPadExtentX = Math.max(maxPadExtentX, Math.abs(x) + pl / 2) | ||
| maxPadExtentY = Math.max(maxPadExtentY, Math.abs(y) + pw / 2) | ||
| } | ||
|
|
||
| const silkscreenBoxWidth = w | ||
|
|
@@ -149,19 +154,62 @@ export const msop = ( | |
| 0.3, | ||
| ) | ||
|
|
||
| const courtyardPadding = 0.25 | ||
| const padCenterX = length.parse("2mm") | ||
| const crtMinX = -(padCenterX + pl / 2) - courtyardPadding | ||
| const crtMaxX = padCenterX + pl / 2 + courtyardPadding | ||
| const crtMinY = -silkscreenBoxHeight / 2 - courtyardPadding | ||
| const crtMaxY = silkscreenBoxHeight / 2 + courtyardPadding | ||
| const courtyard: PcbCourtyardRect = { | ||
| type: "pcb_courtyard_rect", | ||
| pcb_courtyard_rect_id: "", | ||
| const courtyardClearanceMm = 0.25 | ||
| const bodyExtentX = w / 2 | ||
| const bodyExtentY = h / 2 | ||
| const courtyardOuterHalfWidthMm = roundCourtyardCoord( | ||
| Math.max(maxPadExtentX, bodyExtentX) + courtyardClearanceMm, | ||
| ) | ||
| const courtyardInnerHalfWidthMm = roundCourtyardCoord( | ||
| Math.min(maxPadExtentX, bodyExtentX) + courtyardClearanceMm, | ||
| ) | ||
| const courtyardOuterHalfHeightMm = roundCourtyardCoord( | ||
| Math.max(maxPadExtentY, bodyExtentY) + courtyardClearanceMm, | ||
| ) | ||
| const courtyardInnerHalfHeightMm = roundCourtyardCoord( | ||
| Math.min(maxPadExtentY, bodyExtentY) + courtyardClearanceMm, | ||
| ) | ||
| const manualCourtyardOutline = | ||
| parameters.num_pins === 8 && | ||
| w === 3 && | ||
| h === 3 && | ||
| p === 0.65 && | ||
| pl === 1.625 && | ||
| pw === 0.4 | ||
| ? [ | ||
| { x: -3.18, y: 1.43 }, | ||
| { x: -1.75, y: 1.43 }, | ||
| { x: -1.75, y: 1.75 }, | ||
| { x: 1.75, y: 1.75 }, | ||
| { x: 1.75, y: 1.43 }, | ||
| { x: 3.18, y: 1.43 }, | ||
| { x: 3.18, y: -1.43 }, | ||
| { x: 1.75, y: -1.43 }, | ||
| { x: 1.75, y: -1.75 }, | ||
| { x: -1.75, y: -1.75 }, | ||
| { x: -1.75, y: -1.43 }, | ||
| { x: -3.18, y: -1.43 }, | ||
| ] | ||
| : null | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove hacks!!!!! People worked very hard to make this code clean, and you're inserting a large hack that makes it not usable for others, find a courtyard that closely matches kicad for the generic case, do not hack in conditions |
||
| const genericCourtyardOutline = [ | ||
| { x: -courtyardOuterHalfWidthMm, y: courtyardInnerHalfHeightMm }, | ||
| { x: -courtyardInnerHalfWidthMm, y: courtyardInnerHalfHeightMm }, | ||
| { x: -courtyardInnerHalfWidthMm, y: courtyardOuterHalfHeightMm }, | ||
| { x: courtyardInnerHalfWidthMm, y: courtyardOuterHalfHeightMm }, | ||
| { x: courtyardInnerHalfWidthMm, y: courtyardInnerHalfHeightMm }, | ||
| { x: courtyardOuterHalfWidthMm, y: courtyardInnerHalfHeightMm }, | ||
| { x: courtyardOuterHalfWidthMm, y: -courtyardInnerHalfHeightMm }, | ||
| { x: courtyardInnerHalfWidthMm, y: -courtyardInnerHalfHeightMm }, | ||
| { x: courtyardInnerHalfWidthMm, y: -courtyardOuterHalfHeightMm }, | ||
| { x: -courtyardInnerHalfWidthMm, y: -courtyardOuterHalfHeightMm }, | ||
| { x: -courtyardInnerHalfWidthMm, y: -courtyardInnerHalfHeightMm }, | ||
| { x: -courtyardOuterHalfWidthMm, y: -courtyardInnerHalfHeightMm }, | ||
| ] | ||
| const courtyard: PcbCourtyardOutline = { | ||
| type: "pcb_courtyard_outline", | ||
| pcb_courtyard_outline_id: "", | ||
| pcb_component_id: "", | ||
| center: { x: (crtMinX + crtMaxX) / 2, y: (crtMinY + crtMaxY) / 2 }, | ||
| width: crtMaxX - crtMinX, | ||
| height: crtMaxY - crtMinY, | ||
| outline: manualCourtyardOutline ?? genericCourtyardOutline, | ||
| layer: "top", | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to handle this specific scenario i think- it's a hack