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 @@ -81,3 +81,4 @@ export { sot343 } from "./sot343"
export { m2host } from "./m2host"
export { mountedpcbmodule } from "./mountedpcbmodule"
export { to92l } from "./to92l"
export { sip } from "./sip"
106 changes: 106 additions & 0 deletions src/fn/sip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import type {
AnyCircuitElement,
PcbCourtyardRect,
PcbSilkscreenPath,
} from "circuit-json"
import { length } from "circuit-json"
import { z } from "zod"
import { platedhole } from "../helpers/platedhole"
import { platedHoleWithRectPad } from "../helpers/platedHoleWithRectPad"
import { type SilkscreenRef, silkscreenRef } from "../helpers/silkscreenRef"
import { base_def } from "../helpers/zod/base_def"

export const sip_def = base_def.extend({
fn: z.string(),
num_pins: z.number().optional().default(5),
p: length.optional().default("2.54mm"),
id: length.optional().default("0.8mm"),
od: length.optional().default("1.6mm"),
w: length.optional().default("2.5mm"),
string: z.string().optional(),
})

export type SipDef = z.input<typeof sip_def>

export const sip = (
raw_params: SipDef,
): { circuitJson: AnyCircuitElement[]; parameters: any } => {
const match = raw_params.string?.match(/^sip(\d+)/i)
const numPinsFromString = match ? Number.parseInt(match[1]!, 10) : undefined

const parameters = sip_def.parse({
...raw_params,
num_pins: numPinsFromString ?? raw_params.num_pins ?? 5,
})

const { id, od, p, w } = parameters
const numPins = parameters.num_pins

const totalWidth = (numPins - 1) * p

const platedHoles: AnyCircuitElement[] = []
for (let i = 0; i < numPins; i++) {
const x = -totalWidth / 2 + i * p
const y = 0
if (i === 0) {
platedHoles.push(
platedHoleWithRectPad({
pn: 1,
x,
y,
holeDiameter: id,
rectPadWidth: od,
rectPadHeight: od,
}),
)
} else {
platedHoles.push(platedhole(i + 1, x, y, id, od))
}
}

// Silkscreen body: rectangle enclosing the component body
const bodyHalfW = totalWidth / 2 + od / 2 + 0.2
const bodyHalfH = w / 2

const silkscreenBody: PcbSilkscreenPath = {
type: "pcb_silkscreen_path",
layer: "top",
pcb_component_id: "",
route: [
{ x: -bodyHalfW, y: -bodyHalfH },
{ x: bodyHalfW, y: -bodyHalfH },
{ x: bodyHalfW, y: bodyHalfH },
{ x: -bodyHalfW, y: bodyHalfH },
{ x: -bodyHalfW, y: -bodyHalfH },
],
stroke_width: 0.1,
pcb_silkscreen_path_id: "",
}

const silkscreenRefText: SilkscreenRef = silkscreenRef(
0,
-(bodyHalfH + 0.6),
0.4,
)

const padding = 0.25
const courtyard: PcbCourtyardRect = {
type: "pcb_courtyard_rect",
pcb_courtyard_rect_id: "",
pcb_component_id: "",
center: { x: 0, y: 0 },
width: bodyHalfW * 2 + padding * 2,
height: bodyHalfH * 2 + padding * 2,
layer: "top",
}

return {
circuitJson: [
...platedHoles,
silkscreenBody,
silkscreenRefText as AnyCircuitElement,
courtyard,
],
parameters,
}
}
1 change: 1 addition & 0 deletions src/footprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export type Footprinter = {
solderjumper: (
num_pins?: number,
) => FootprinterParamsBuilder<"bridged" | "p" | "pw" | "ph">
sip: (num_pins?: number) => FootprinterParamsBuilder<"p" | "w" | "id" | "od">

params: () => any
/** @deprecated use circuitJson() instead */
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/sip10_w10mm_p2.54mm.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__/sip5_w8.5mm_p2.54mm.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions tests/sip1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { fp } from "../src/footprinter"

test("sip5_w8.5mm_p2.54mm", () => {
const circuitJson = fp.string("sip5_w8.5mm_p2.54mm").circuitJson()
const svgContent = convertCircuitJsonToPcbSvg(circuitJson)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "sip5_w8.5mm_p2.54mm")
})
9 changes: 9 additions & 0 deletions tests/sip2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { fp } from "../src/footprinter"

test("sip10_w10mm_p2.54mm", () => {
const circuitJson = fp.string("sip10_w10mm_p2.54mm").circuitJson()
const svgContent = convertCircuitJsonToPcbSvg(circuitJson)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "sip10_w10mm_p2.54mm")
})
Loading