Skip to content
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

add sod923 footprint #139

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions src/fn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export { pad } from "./pad"
export { to92 } from "./to92"
export { sod523 } from "./sod523"
export { sop8 } from "./sop8"
export { sod923 } from "./sod923"
export { sod882 } from "./sod882"
export { sod323f } from "./sod323f"
export { sod123f } from "./sod123f"
Expand Down
99 changes: 99 additions & 0 deletions src/fn/sod923.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import type { AnySoupElement, 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"

export const sod_def = z.object({
fn: z.string(),
num_pins: z.literal(2).default(2),
w: z.string().default("1.4mm"),
h: z.string().default("0.9mm"),
pl: z.string().default("0.35mm"),
pw: z.string().default("0.25mm"),
p: z.string().default("1.2mm"),
})

export const sod923 = (
raw_params: z.input<typeof sod_def>,
): { circuitJson: AnySoupElement[]; parameters: any } => {
const parameters = sod_def.parse(raw_params)

// Define silkscreen reference text
const silkscreenRefText: SilkscreenRef = silkscreenRef(
0,
length.parse(parameters.h),
0.3,
)

const silkscreenLine: PcbSilkscreenPath = {
type: "pcb_silkscreen_path",
layer: "top",
pcb_component_id: "",
route: [
{
x: length.parse(parameters.p) / 2 + 0.15,
y: length.parse(parameters.h) / 2,
},
{
x: -length.parse(parameters.w) / 2 - 0.4,
y: length.parse(parameters.h) / 2,
},
{
x: -length.parse(parameters.w) / 2 - 0.4,
y: -length.parse(parameters.h) / 2,
},
{
x: length.parse(parameters.p) / 2 + 0.15,
y: -length.parse(parameters.h) / 2,
},
],
stroke_width: 0.1,
pcb_silkscreen_path_id: "",
}

return {
circuitJson: sodWithoutParsing(parameters).concat(
silkscreenLine as AnySoupElement,
silkscreenRefText as AnySoupElement,
),
parameters,
}
}

// Get coordinates for SOD pads
export const getSodCoords = (parameters: {
pn: number
p: number
}) => {
const { pn, p } = parameters

if (pn === 1) {
return { x: -p / 2, y: 0 }
// biome-ignore lint/style/noUselessElse: <explanation>
} else {
return { x: p / 2, y: 0 }
}
}

// Function to generate SOD pads
export const sodWithoutParsing = (parameters: z.infer<typeof sod_def>) => {
const pads: AnySoupElement[] = []

for (let i = 1; i <= parameters.num_pins; i++) {
const { x, y } = getSodCoords({
pn: i,
p: Number.parseFloat(parameters.p),
})
pads.push(
rectpad(
i,
x,
y,
Number.parseFloat(parameters.pl),
Number.parseFloat(parameters.pw),
),
)
}
return pads
}
1 change: 1 addition & 0 deletions src/footprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type Footprinter = {
sot235: () => FootprinterParamsBuilder<"h" | "p" | "pl" | "pw">
to92: () => FootprinterParamsBuilder<"w" | "h" | "p" | "id" | "od">
lqfp: (num_pins?: number) => FootprinterParamsBuilder<"w" | "h" | "pl" | "pw">
sod923: () => FootprinterParamsBuilder<"w" | "h" | "p" | "pl" | "pw">
pushbutton: () => FootprinterParamsBuilder<
"tllabel" | "trlabel" | "bllabel" | "brlabel"
>
Expand Down
13 changes: 13 additions & 0 deletions tests/__snapshots__/sod923.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/sod923.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("sod923", () => {
const soup = fp.string("sod923").circuitJson()
const svgContent = convertCircuitJsonToPcbSvg(soup)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "sod923")
})