From 53830a3d10da3912204d9ba19c25b4e8bc372d01 Mon Sep 17 00:00:00 2001 From: techmannih Date: Thu, 6 Feb 2025 02:23:05 +0530 Subject: [PATCH 1/2] add sod323 --- src/fn/index.ts | 1 + src/fn/sod323.ts | 101 ++++++++++++++++++++++++++++ tests/__snapshots__/sod323.snap.svg | 13 ++++ tests/sod323.test.ts | 9 +++ 4 files changed, 124 insertions(+) create mode 100644 src/fn/sod323.ts create mode 100644 tests/__snapshots__/sod323.snap.svg create mode 100644 tests/sod323.test.ts diff --git a/src/fn/index.ts b/src/fn/index.ts index 4282800..11b390c 100644 --- a/src/fn/index.ts +++ b/src/fn/index.ts @@ -33,3 +33,4 @@ export { hc49 } from "./hc49" export { pad } from "./pad" export { to92 } from "./to92" export { sop8 } from "./sop8" +export { sod323 } from "./sod323" diff --git a/src/fn/sod323.ts b/src/fn/sod323.ts new file mode 100644 index 0000000..7c83edb --- /dev/null +++ b/src/fn/sod323.ts @@ -0,0 +1,101 @@ +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("2.7mm"), + h: z.string().default("1.20mm"), + pl: z.string().default("0.59mm"), + pw: z.string().default("0.45mm"), + pad_spacing: z.string().default("1.4mm"), +}) + +export const sod323 = ( + raw_params: z.input, +): { 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, + ) + + // Define silkscreen path that goes till half of the second pad + // Define silkscreen path that goes till half of the second pad + const silkscreenLine: PcbSilkscreenPath = { + type: "pcb_silkscreen_path", + layer: "top", + pcb_component_id: "", + route: [ + { + x: length.parse(parameters.pad_spacing) / 2, + y: length.parse(parameters.h) / 2, // Reduced offset to bring closer + }, + { + x: -length.parse(parameters.w) / 2, // Slightly reduced x offset + y: length.parse(parameters.h) / 2, // Same y adjustment + }, + { + x: -length.parse(parameters.w) / 2, // Reduced x to bring closer + y: -length.parse(parameters.h) / 2, // Reduced y offset + }, + { + x: length.parse(parameters.pad_spacing) / 2, + y: -length.parse(parameters.h) / 2, // Same y adjustment + }, + ], + 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 + pad_spacing: number +}) => { + const { pn, pad_spacing } = parameters + + if (pn === 1) { + return { x: -pad_spacing / 2, y: 0 } + // biome-ignore lint/style/noUselessElse: + } else { + return { x: pad_spacing / 2, y: 0 } + } +} + +// Function to generate SOD pads +export const sodWithoutParsing = (parameters: z.infer) => { + const pads: AnySoupElement[] = [] + + for (let i = 1; i <= parameters.num_pins; i++) { + const { x, y } = getSodCoords({ + pn: i, + pad_spacing: Number.parseFloat(parameters.pad_spacing), + }) + pads.push( + rectpad( + i, + x, + y, + Number.parseFloat(parameters.pl), + Number.parseFloat(parameters.pw), + ), + ) + } + return pads +} diff --git a/tests/__snapshots__/sod323.snap.svg b/tests/__snapshots__/sod323.snap.svg new file mode 100644 index 0000000..39c7bc4 --- /dev/null +++ b/tests/__snapshots__/sod323.snap.svg @@ -0,0 +1,13 @@ +{REF} \ No newline at end of file diff --git a/tests/sod323.test.ts b/tests/sod323.test.ts new file mode 100644 index 0000000..244cc1a --- /dev/null +++ b/tests/sod323.test.ts @@ -0,0 +1,9 @@ +import { test, expect } from "bun:test" +import { convertCircuitJsonToPcbSvg } from "circuit-to-svg" +import { fp } from "../src/footprinter" + +test("sod323", () => { + const soup = fp.string("sod323").circuitJson() + const svgContent = convertCircuitJsonToPcbSvg(soup) + expect(svgContent).toMatchSvgSnapshot(import.meta.path, "sod323") +}) From 48c38d97b05130d8b67f4f33380a8e828559f446 Mon Sep 17 00:00:00 2001 From: techmannih Date: Thu, 6 Feb 2025 02:43:29 +0530 Subject: [PATCH 2/2] update footprint --- src/fn/sod323.ts | 8 +++----- tests/__snapshots__/sod323.snap.svg | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/fn/sod323.ts b/src/fn/sod323.ts index 7c83edb..7f7954f 100644 --- a/src/fn/sod323.ts +++ b/src/fn/sod323.ts @@ -11,7 +11,7 @@ export const sod_def = z.object({ h: z.string().default("1.20mm"), pl: z.string().default("0.59mm"), pw: z.string().default("0.45mm"), - pad_spacing: z.string().default("1.4mm"), + pad_spacing: z.string().default("2.2mm"), }) export const sod323 = ( @@ -26,8 +26,6 @@ export const sod323 = ( 0.3, ) - // Define silkscreen path that goes till half of the second pad - // Define silkscreen path that goes till half of the second pad const silkscreenLine: PcbSilkscreenPath = { type: "pcb_silkscreen_path", layer: "top", @@ -38,11 +36,11 @@ export const sod323 = ( y: length.parse(parameters.h) / 2, // Reduced offset to bring closer }, { - x: -length.parse(parameters.w) / 2, // Slightly reduced x offset + x: -length.parse(parameters.w) / 2 - 0.2, // Slightly reduced x offset y: length.parse(parameters.h) / 2, // Same y adjustment }, { - x: -length.parse(parameters.w) / 2, // Reduced x to bring closer + x: -length.parse(parameters.w) / 2 - 0.2, // Reduced x to bring closer y: -length.parse(parameters.h) / 2, // Reduced y offset }, { diff --git a/tests/__snapshots__/sod323.snap.svg b/tests/__snapshots__/sod323.snap.svg index 39c7bc4..0e7843d 100644 --- a/tests/__snapshots__/sod323.snap.svg +++ b/tests/__snapshots__/sod323.snap.svg @@ -10,4 +10,4 @@ .pcb-silkscreen-top { stroke: #f2eda1; } .pcb-silkscreen-bottom { stroke: #f2eda1; } .pcb-silkscreen-text { fill: #f2eda1; } - {REF} \ No newline at end of file + {REF} \ No newline at end of file