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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ cap0402
res0805
soic8_p1.27mm
dip16
pdip8
spdip8
pinrow10
tssop20_p0.5mm
sot23
Expand Down
2 changes: 2 additions & 0 deletions src/fn/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export { dip } from "./dip"
export { spdip } from "./spdip"
export { utdfn } from "./utdfn"
export { diode } from "./diode"
export { cap } from "./cap"
export { led } from "./led"
Expand Down
12 changes: 12 additions & 0 deletions src/fn/spdip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { AnyCircuitElement } from "circuit-json"
import { dip } from "./dip"

export const spdip = (
raw_params: any,
): { circuitJson: AnyCircuitElement[]; parameters: any } => {
return dip({
...raw_params,
p: raw_params.p ?? "1.778mm",
w: raw_params.w ?? "300mil",
})
}
138 changes: 138 additions & 0 deletions src/fn/utdfn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import type {
AnyCircuitElement,
PcbCourtyardRect,
PcbSilkscreenPath,
} from "circuit-json"
import { z } from "zod"
import { length } from "circuit-json"
import { rectpad } from "../helpers/rectpad"
import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef"
import { base_def } from "../helpers/zod/base_def"
import { getCcwSoicCoords } from "./soic"
import { CORNERS } from "src/helpers/corner"

export const utdfn_def = base_def.extend({
fn: z.string(),
num_pins: z.number().optional().default(4),
w: length.default(length.parse("1.45mm")),
p: length.default(length.parse("0.65mm")),
pl: length.default(length.parse("0.35mm")),
pw: length.default(length.parse("0.25mm")),
ep: z.boolean().default(false),
epw: length.default(length.parse("1mm")),
eph: length.default(length.parse("1mm")),
string: z.string().optional(),
})

export const utdfn = (
raw_params: any,
): { circuitJson: AnyCircuitElement[]; parameters: any } => {
if (raw_params.string?.includes("_ep")) {
raw_params.ep = true
const epMatch = raw_params.string.match(
/_ep(\d+(?:\.\d+)?)x(\d+(?:\.\d+)?)/,
)
if (epMatch) {
raw_params.epw = `${epMatch[1]}mm`
raw_params.eph = `${epMatch[2]}mm`
}
}

const parameters = utdfn_def.parse(raw_params)

const w = parameters.w
const p = parameters.p
const pl = parameters.pl
const pw = parameters.pw
const epw = parameters.epw
const eph = parameters.eph

const pads: AnyCircuitElement[] = []

for (let i = 0; i < parameters.num_pins; i++) {
const { x, y } = getCcwSoicCoords({
num_pins: parameters.num_pins,
pn: i + 1,
w,
p,
pl,
legsoutside: true,
})
pads.push(rectpad(i + 1, x, y, pl, pw))
}

if (parameters.ep) {
pads.push(rectpad(parameters.num_pins + 1, 0, 0, epw, eph))
}

const m = Math.min(0.5, p / 2)
const sw = w + m
const sh = (parameters.num_pins / 2 - 1) * p + pw + m

const silkscreenPaths: PcbSilkscreenPath[] = []

for (const corner of CORNERS) {
const { dx, dy } = corner
silkscreenPaths.push({
layer: "top",
pcb_component_id: "",
pcb_silkscreen_path_id: "",
route: [
{ x: (dx * sw) / 2 - dx * p, y: (dy * sh) / 2 },
{ x: (dx * sw) / 2, y: (dy * sh) / 2 },
{ x: (dx * sw) / 2, y: (dy * sh) / 2 - dy * p },
],
type: "pcb_silkscreen_path",
stroke_width: 0.1,
})
}

const as = p / 4
const atx = -sw / 2 - as / 2
const aty = sh / 2 - p / 2

silkscreenPaths.push({
layer: "top",
pcb_component_id: "",
pcb_silkscreen_path_id: "",
type: "pcb_silkscreen_path",
route: [
{ x: atx, y: aty },
{ x: atx - as, y: aty + as },
{ x: atx - as, y: aty - as },
{ x: atx, y: aty },
],
stroke_width: 0.1,
})

const silkscreenRefText: SilkscreenRef = silkscreenRef(
0,
sh / 2 + 0.4,
sh / 12,
)

const roundUpToCourtyardGrid = (value: number) =>
Math.ceil(value / 0.05) * 0.05
const pinRowSpanY = (parameters.num_pins / 2 - 1) * p + pw
const courtyardHalfWidthMm = roundUpToCourtyardGrid(w / 2 + 0.25)
const courtyardHalfHeightMm = roundUpToCourtyardGrid(pinRowSpanY / 2 + 0.45)
const courtyard: PcbCourtyardRect = {
type: "pcb_courtyard_rect",
pcb_courtyard_rect_id: "",
pcb_component_id: "",
center: { x: 0, y: 0 },
width: courtyardHalfWidthMm * 2,
height: courtyardHalfHeightMm * 2,
layer: "top",
}

return {
circuitJson: [
...pads,
silkscreenRefText,
...silkscreenPaths,
courtyard,
] as AnyCircuitElement[],
parameters,
}
}
8 changes: 8 additions & 0 deletions src/footprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export type Footprinter = {
dip: (
num_pins?: number,
) => FootprinterParamsBuilder<"w" | "p" | "id" | "od" | "wide" | "narrow">
spdip: (
num_pins?: number,
) => FootprinterParamsBuilder<"w" | "p" | "id" | "od" | "wide" | "narrow">
utdfn: (
num_pins?: number,
) => FootprinterParamsBuilder<"w" | "p" | "pw" | "pl" | "ep" | "epw" | "eph">
cap: () => FootprinterParamsBuilder<CommonPassiveOptionKey>
res: () => FootprinterParamsBuilder<CommonPassiveOptionKey>
diode: () => FootprinterParamsBuilder<CommonPassiveOptionKey>
Expand Down Expand Up @@ -274,7 +280,9 @@ const normalizeDefinition = (def: string): string => {
.replace(/^sot23-(\d+)(?=_|$)/i, "sot23_$1")
.replace(/^sot-223-(\d+)(?=_|$)/i, "sot223_$1")
.replace(/^to-220f-(\d+)(?=_|$)/i, "to220f_$1")
.replace(/^spdip-?(\d*)/i, "spdip$1")
.replace(/^jst_(ph|sh|zh)_(\d+)(?=_|$)/i, "jst$2_$1")
.replace(/^pdip-?(\d*)/i, "dip$1")
}

export const string = (def: string): Footprinter => {
Expand Down
22 changes: 22 additions & 0 deletions src/helpers/passive-fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ export const footprintSizes: StandardSize[] = [
stroke_width_mm: 0.12,
},
},
{
imperial: "2835",
metric: "2835",
p_mm_min: 2.4,
pw_mm_min: 1.2,
ph_mm_min: 1.5,
w_mm_min: 2.8,
h_mm_min: 3.5,
courtyard_width_mm: 3.3,
courtyard_height_mm: 4.0,
},
{
imperial: "5050",
metric: "5050",
p_mm_min: 4.0,
pw_mm_min: 1.5,
ph_mm_min: 2.0,
w_mm_min: 5.0,
h_mm_min: 5.0,
courtyard_width_mm: 5.5,
courtyard_height_mm: 5.5,
},
]

const metricMap = Object.fromEntries(footprintSizes.map((s) => [s.metric, s]))
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/led_2835.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__/led_5050.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__/led_5050_chained.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__/pdip8.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__/spdip28.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading