Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/fn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export { sot886 } from "./sot886"
export { sot23 } from "./sot23"
export { sot25 } from "./sot25"
export { dfn } from "./dfn"
export { utdfn } from "./utdfn"
export { do219ad } from "./do219ad"
export { pinrow } from "./pinrow"
export { headermodule } from "./headermodule"
Expand Down
33 changes: 33 additions & 0 deletions src/fn/utdfn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { AnyCircuitElement } from "circuit-json"
import { dfn } from "./dfn"
import type { DfnInput } from "./dfn"

const defined = (v: Record<string, unknown>) =>
Object.fromEntries(
Object.entries(v).filter(([, value]) => value !== undefined),
)

/**
* UDFN / UTDFN with an exposed thermal pad.
*
* Defaults follow KiCad UDFN-4-1EP_1x1mm_P0.65mm_EP0.48x0.48mm:
* four 0.22mm x 0.25mm pads at +-0.54mm on 0.65mm pitch and a
* 0.48mm x 0.48mm center exposed pad. `utdfn4ep`, `utdfn-4-ep`, and
* `UTDFN-4-EP(1x1)` all resolve to this generator with four pins.
*/
export const utdfn = (
raw_params: DfnInput,
): { circuitJson: AnyCircuitElement[]; parameters: any } => {
return dfn({
...defined({
num_pins: 4,
w: "1.3mm",
p: "0.65mm",
pl: "0.22mm",
pw: "0.25mm",
thermalpad: "0.48mmx0.48mm",
}),
...defined(raw_params as Record<string, unknown>),
fn: "utdfn",
} as DfnInput)
}
61 changes: 31 additions & 30 deletions src/footprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,34 @@ type CommonPassiveOptionKey =
| "nonpolarized"
| "textbottom"

type DfnOptionKey =
| "w"
| "p"
| "pw"
| "pl"
| "missing"
| "pillpads"
| "thermalpad"
| "thermalpadcenteroffsetx"
| "thermalpadcenteroffsety"
| "thermalvias"
| "thermalviapitch"
| "thermalviaid"
| "thermalviaod"
| "cornerpads"
| "cornerpadcutlength"
| "bodywidth"
| "bodylength"
| "bodythickness"
| "standoff"
| "terminalinset"
| "terminallength"
| "terminalwidth"
| "terminalpitch"
| "terminalthickness"
| "pin1terminalchamfer"
| "pin1markwidth"

export type Footprinter = {
dip: (
num_pins?: number,
Expand Down Expand Up @@ -196,36 +224,8 @@ export type Footprinter = {
| "thermalpadcenteroffsetx"
| "thermalpadcenteroffsety"
>
dfn: (
num_pins?: number,
) => FootprinterParamsBuilder<
| "w"
| "p"
| "pw"
| "pl"
| "missing"
| "pillpads"
| "thermalpad"
| "thermalpadcenteroffsetx"
| "thermalpadcenteroffsety"
| "thermalvias"
| "thermalviapitch"
| "thermalviaid"
| "thermalviaod"
| "cornerpads"
| "cornerpadcutlength"
| "bodywidth"
| "bodylength"
| "bodythickness"
| "standoff"
| "terminalinset"
| "terminallength"
| "terminalwidth"
| "terminalpitch"
| "terminalthickness"
| "pin1terminalchamfer"
| "pin1markwidth"
>
dfn: (num_pins?: number) => FootprinterParamsBuilder<DfnOptionKey>
utdfn: (num_pins?: number) => FootprinterParamsBuilder<DfnOptionKey>
do219ad: () => FootprinterParamsBuilder<
| "p"
| "pw"
Expand Down Expand Up @@ -650,6 +650,7 @@ const normalizeDefinition = (def: string): string => {
.replace(/^sot-223-(\d+)(?=_|$)/i, "sot223_$1")
.replace(/^to-220f-(\d+)(?=_|$)/i, "to220f_$1")
.replace(/^jst_(ph|sh|zh|xh)_(\d+)(?=_|$)/i, "jst$2_$1")
.replace(/^u?t?dfn-(\d+)-ep(?:\([^)]*\))?(?=_|$)/i, "utdfn$1ep")
}

const normalizeMicrometerLengths = (value: string): string =>
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/utdfn4ep.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/__snapshots__/utdfn6.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions tests/utdfn.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { test, expect } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import type { PcbSmtPad } from "circuit-json"
import { fp } from "../src/footprinter"

const isSignalPad = (p: PcbSmtPad) =>
p.port_hints?.some((h) => /^\d+$/.test(h)) ?? false

test("utdfn4ep matches the KiCad UDFN-4-1EP_1x1mm_P0.65mm_EP0.48x0.48mm pad geometry", () => {
const soup = fp.string("utdfn4ep").circuitJson()
const pads = soup.filter(
(e): e is PcbSmtPad => e.type === "pcb_smtpad" && e.shape === "rect",
)

const signalPads = pads
.filter(isSignalPad)
.sort((a, b) => Number(a.port_hints?.[0]) - Number(b.port_hints?.[0]))

expect(signalPads).toHaveLength(4)
for (const pad of signalPads) {
if (pad.shape !== "rect") throw new Error("expected rect pad")
expect(pad.width).toBeCloseTo(0.22)
expect(pad.height).toBeCloseTo(0.25)
}
const padXY = (p: PcbSmtPad) => {
if (!("x" in p) || !("y" in p)) throw new Error("pad has no x/y")
return [p.x, p.y]
}
expect(signalPads.map(padXY)).toEqual([
[-0.54, 0.325],
[-0.54, -0.325],
[0.54, -0.325],
[0.54, 0.325],
])

const thermalPad = pads.find((p) => p.port_hints?.includes("thermalpad"))
if (!thermalPad || thermalPad.shape !== "rect") {
throw new Error("expected a rect thermal pad")
}
expect(thermalPad.x).toBeCloseTo(0)
expect(thermalPad.y).toBeCloseTo(0)
expect(thermalPad.width).toBeCloseTo(0.48)
expect(thermalPad.height).toBeCloseTo(0.48)

const svgContent = convertCircuitJsonToPcbSvg(soup)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "utdfn4ep")
})

test("utdfn accepts an explicit pin count", () => {
const soup = fp.string("utdfn6").circuitJson()
const signalPads = soup.filter(
(e): e is PcbSmtPad => e.type === "pcb_smtpad" && isSignalPad(e),
)
expect(signalPads).toHaveLength(6)
Comment on lines +50 to +54

const svgContent = convertCircuitJsonToPcbSvg(soup)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "utdfn6")
})
Loading