From a66d9744afafbfdf3119631e4401aead50a31ecc Mon Sep 17 00:00:00 2001 From: Anas sarkiz Date: Fri, 8 Nov 2024 16:37:16 +0200 Subject: [PATCH 1/8] Implemented sot235 (sot23-5) footprint with testing --- src/fn/index.ts | 1 + src/fn/sot235.ts | 94 +++++++++++++++++++++++++++++ src/footprinter.ts | 1 + tests/__snapshots__/sot235.snap.svg | 13 ++++ tests/sot235.test.ts | 10 +++ 5 files changed, 119 insertions(+) create mode 100644 src/fn/sot235.ts create mode 100644 tests/__snapshots__/sot235.snap.svg create mode 100644 tests/sot235.test.ts diff --git a/src/fn/index.ts b/src/fn/index.ts index c604405..f6fd289 100644 --- a/src/fn/index.ts +++ b/src/fn/index.ts @@ -26,3 +26,4 @@ export { pushbutton } from "./pushbutton" export { stampboard } from "./stampboard" export { stampreceiver } from "./stampreceiver" export { lqfp } from "./lqfp" +export {sot235} from "./sot235" diff --git a/src/fn/sot235.ts b/src/fn/sot235.ts new file mode 100644 index 0000000..e7042ea --- /dev/null +++ b/src/fn/sot235.ts @@ -0,0 +1,94 @@ +import type { AnyCircuitElement, PcbSilkscreenPath, PcbSilkscreenRect } from "circuit-json" +import { z } from "zod" +import { rectpad } from "../helpers/rectpad" +import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef" +import { u_curve } from "src/helpers/u-curve" + +export const sot235_def = z.object({ + fn: z.string(), + h: z.string().default("1.6mm"), + pl: z.string().default("1mm"), + pw: z.string().default("0.7mm"), + p: z.string().default("0.95mm"), +}) +const num_pins = 5 +export const sot235 = ( + raw_params: z.input, +): { circuitJson: AnyCircuitElement[]; parameters: any } => { + const parameters = sot235_def.parse(raw_params) + return { + circuitJson: sot23_5WithoutParsing(parameters), + parameters: parameters, + } +} + +export const getCcwSot235Coords = (parameters: { + h: number + p: number + pn: number +}) => { + const { p, h ,pn } = parameters + if (pn === 1) { + return { x:h/2 + 0.5 , y: -p } + } + if (pn === 2) { + return { x: h/2 + 0.5, y: p } + } + if (pn === 3) { + return { x: -h/2 - 0.5, y: -p } + } + if (pn === 4) { + return { x: -h/2 - 0.5, y: 0 } + } + if (pn === 5) { + return { x: -h/2 - 0.5, y: p } + } + throw new Error("Invalid pin number") +} + +export const sot23_5WithoutParsing = (parameters: z.infer) => { + const pads: AnyCircuitElement[] = [] + for (let i = 1; i <= num_pins; i++) { + const { x, y } = getCcwSot235Coords({ + h: Number.parseFloat(parameters.h), + p: Number.parseFloat(parameters.p), + pn: i + }) + pads.push( + rectpad( + i, + x, + y, + Number.parseFloat(parameters.pl), + Number.parseFloat(parameters.pw), + ), + ) + } + + const width = (num_pins+1)/2 * Number.parseFloat(parameters.p) + const height = Number.parseFloat(parameters.h) + const silkscreenBorder: PcbSilkscreenPath = { + layer: "top", + pcb_component_id: "", + pcb_silkscreen_path_id: "silkscreen_path_1", + route: [ + { x: -height / 2, y: -width / 2 }, + { x: -height / 2, y: width / 2 }, + ...u_curve.map(({ x, y }) => ({ + x: (x * height) / 6, + y: (y * height) / 6 + width / 2, + })), + { x: height / 2, y: width / 2 }, + { x: height / 2, y: -width / 2 }, + { x: -height / 2, y: -width / 2 }, + ], + type: "pcb_silkscreen_path", + stroke_width: 0.1, + } + const silkscreenRefText: SilkscreenRef = silkscreenRef( + 0, + height+ 0.3, + 0.3, + ) + return [...pads, silkscreenRefText, silkscreenBorder as AnyCircuitElement] +} diff --git a/src/footprinter.ts b/src/footprinter.ts index 21d6d5e..df4d560 100644 --- a/src/footprinter.ts +++ b/src/footprinter.ts @@ -50,6 +50,7 @@ export type Footprinter = { dfn: (num_pins: number) => FootprinterParamsBuilder<"w" | "p"> pinrow: (num_pins: number) => FootprinterParamsBuilder<"p" | "id" | "od"> axial: () => FootprinterParamsBuilder<"p" | "id" | "od"> + sot235: () => FootprinterParamsBuilder<"h" | "p" | "pl" | "pw"> lqfp: (num_pins: number) => FootprinterParamsBuilder<"w" | "h" | "pl" | "pw"> pushbutton: () => FootprinterParamsBuilder< "tllabel" | "trlabel" | "bllabel" | "brlabel" diff --git a/tests/__snapshots__/sot235.snap.svg b/tests/__snapshots__/sot235.snap.svg new file mode 100644 index 0000000..7b95a3f --- /dev/null +++ b/tests/__snapshots__/sot235.snap.svg @@ -0,0 +1,13 @@ +{REF} \ No newline at end of file diff --git a/tests/sot235.test.ts b/tests/sot235.test.ts new file mode 100644 index 0000000..c646218 --- /dev/null +++ b/tests/sot235.test.ts @@ -0,0 +1,10 @@ +import { test, expect } from "bun:test" +import { convertCircuitJsonToPcbSvg } from "circuit-to-svg" +import { fp } from "../src/footprinter" + +test("sot235", () => { + const soup = fp.string("sot235").circuitJson() + console.log(soup) + const svgContent = convertCircuitJsonToPcbSvg(soup) + expect(svgContent).toMatchSvgSnapshot(import.meta.path, "sot235") +}) From c5f05acdabf7ca61e8aa91f53395d7db36bdcb59 Mon Sep 17 00:00:00 2001 From: Anas sarkiz Date: Fri, 8 Nov 2024 16:38:19 +0200 Subject: [PATCH 2/8] formated --- src/fn/index.ts | 2 +- src/fn/sot235.ts | 55 ++++++++++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/fn/index.ts b/src/fn/index.ts index f6fd289..9b66301 100644 --- a/src/fn/index.ts +++ b/src/fn/index.ts @@ -26,4 +26,4 @@ export { pushbutton } from "./pushbutton" export { stampboard } from "./stampboard" export { stampreceiver } from "./stampreceiver" export { lqfp } from "./lqfp" -export {sot235} from "./sot235" +export { sot235 } from "./sot235" diff --git a/src/fn/sot235.ts b/src/fn/sot235.ts index e7042ea..3820636 100644 --- a/src/fn/sot235.ts +++ b/src/fn/sot235.ts @@ -1,4 +1,7 @@ -import type { AnyCircuitElement, PcbSilkscreenPath, PcbSilkscreenRect } from "circuit-json" +import type { + AnyCircuitElement, + PcbSilkscreenPath, +} from "circuit-json" import { z } from "zod" import { rectpad } from "../helpers/rectpad" import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef" @@ -27,32 +30,34 @@ export const getCcwSot235Coords = (parameters: { p: number pn: number }) => { - const { p, h ,pn } = parameters - if (pn === 1) { - return { x:h/2 + 0.5 , y: -p } - } - if (pn === 2) { - return { x: h/2 + 0.5, y: p } - } - if (pn === 3) { - return { x: -h/2 - 0.5, y: -p } - } - if (pn === 4) { - return { x: -h/2 - 0.5, y: 0 } - } - if (pn === 5) { - return { x: -h/2 - 0.5, y: p } - } - throw new Error("Invalid pin number") + const { p, h, pn } = parameters + if (pn === 1) { + return { x: h / 2 + 0.5, y: -p } + } + if (pn === 2) { + return { x: h / 2 + 0.5, y: p } + } + if (pn === 3) { + return { x: -h / 2 - 0.5, y: -p } + } + if (pn === 4) { + return { x: -h / 2 - 0.5, y: 0 } + } + if (pn === 5) { + return { x: -h / 2 - 0.5, y: p } + } + throw new Error("Invalid pin number") } -export const sot23_5WithoutParsing = (parameters: z.infer) => { +export const sot23_5WithoutParsing = ( + parameters: z.infer, +) => { const pads: AnyCircuitElement[] = [] for (let i = 1; i <= num_pins; i++) { const { x, y } = getCcwSot235Coords({ h: Number.parseFloat(parameters.h), p: Number.parseFloat(parameters.p), - pn: i + pn: i, }) pads.push( rectpad( @@ -64,8 +69,8 @@ export const sot23_5WithoutParsing = (parameters: z.infer) => ), ) } - - const width = (num_pins+1)/2 * Number.parseFloat(parameters.p) + + const width = ((num_pins + 1) / 2) * Number.parseFloat(parameters.p) const height = Number.parseFloat(parameters.h) const silkscreenBorder: PcbSilkscreenPath = { layer: "top", @@ -85,10 +90,6 @@ export const sot23_5WithoutParsing = (parameters: z.infer) => type: "pcb_silkscreen_path", stroke_width: 0.1, } - const silkscreenRefText: SilkscreenRef = silkscreenRef( - 0, - height+ 0.3, - 0.3, - ) + const silkscreenRefText: SilkscreenRef = silkscreenRef(0, height + 0.3, 0.3) return [...pads, silkscreenRefText, silkscreenBorder as AnyCircuitElement] } From a7e1826596f0144528364d58496e54b73585d09e Mon Sep 17 00:00:00 2001 From: Anas sarkiz Date: Fri, 8 Nov 2024 16:41:05 +0200 Subject: [PATCH 3/8] Bun format --- src/fn/sot235.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/fn/sot235.ts b/src/fn/sot235.ts index 3820636..6bcf588 100644 --- a/src/fn/sot235.ts +++ b/src/fn/sot235.ts @@ -1,7 +1,4 @@ -import type { - AnyCircuitElement, - PcbSilkscreenPath, -} from "circuit-json" +import type { AnyCircuitElement, PcbSilkscreenPath } from "circuit-json" import { z } from "zod" import { rectpad } from "../helpers/rectpad" import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef" From ed92c8cd4ab66cff86f4f3bfa91d9030284284e7 Mon Sep 17 00:00:00 2001 From: Anas sarkiz Date: Fri, 8 Nov 2024 21:08:04 +0200 Subject: [PATCH 4/8] Refactor silkscreen and added pin 1 indecator --- src/fn/sot235.ts | 68 ++++++++++++++++++++++++----- tests/__snapshots__/sot235.snap.svg | 2 +- tests/sot235.test.ts | 1 - 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/fn/sot235.ts b/src/fn/sot235.ts index 6bcf588..daf9a21 100644 --- a/src/fn/sot235.ts +++ b/src/fn/sot235.ts @@ -69,24 +69,68 @@ export const sot23_5WithoutParsing = ( const width = ((num_pins + 1) / 2) * Number.parseFloat(parameters.p) const height = Number.parseFloat(parameters.h) - const silkscreenBorder: PcbSilkscreenPath = { + const silkscreenPath1: PcbSilkscreenPath = { layer: "top", pcb_component_id: "", pcb_silkscreen_path_id: "silkscreen_path_1", route: [ - { x: -height / 2, y: -width / 2 }, - { x: -height / 2, y: width / 2 }, - ...u_curve.map(({ x, y }) => ({ - x: (x * height) / 6, - y: (y * height) / 6 + width / 2, - })), - { x: height / 2, y: width / 2 }, - { x: height / 2, y: -width / 2 }, - { x: -height / 2, y: -width / 2 }, + { x: -width / 3, y: height / 2 + Number.parseFloat(parameters.p) / 1.3 }, + { x: width / 3, y: height / 2 + Number.parseFloat(parameters.p) / 1.3 }, ], type: "pcb_silkscreen_path", - stroke_width: 0.1, + stroke_width: 0.05, + } + const silkscreenPath2: PcbSilkscreenPath = { + layer: "top", + pcb_component_id: "", + pcb_silkscreen_path_id: "silkscreen_path_2", + route: [ + { x: -width / 3, y: -height / 2 - Number.parseFloat(parameters.p) / 1.3 }, + { x: width / 3, y: -height / 2 - Number.parseFloat(parameters.p) / 1.3 }, + ], + type: "pcb_silkscreen_path", + stroke_width: 0.05, } const silkscreenRefText: SilkscreenRef = silkscreenRef(0, height + 0.3, 0.3) - return [...pads, silkscreenRefText, silkscreenBorder as AnyCircuitElement] + const pin1Position = getCcwSot235Coords({ + h: Number.parseFloat(parameters.h), + p: Number.parseFloat(parameters.p), + pn: 5, + }) + pin1Position.x = pin1Position.x - Number.parseFloat(parameters.pw) * 1.5 + const triangleHeight = 0.7 // Adjust triangle size as needed + const triangleWidth = 0.3 // Adjust triangle width as needed + const pin1Indicator: PcbSilkscreenPath = { + type: "pcb_silkscreen_path", + layer: "top", + pcb_component_id: "", + pcb_silkscreen_path_id: "pin1_indicator", + route: [ + { + x: pin1Position.x + triangleHeight / 2, + y: pin1Position.y, + }, // Tip of the triangle (pointing right) + { + x: pin1Position.x - triangleHeight / 2, + y: pin1Position.y + triangleWidth / 2, + }, // Bottom corner of the base + { + x: pin1Position.x - triangleHeight / 2, + y: pin1Position.y - triangleWidth / 2, + }, // Top corner of the base + { + x: pin1Position.x + triangleHeight / 2, + y: pin1Position.y, + }, // Close the path at the tip + ], + stroke_width: 0.05, + } + + return [ + ...pads, + silkscreenRefText, + silkscreenPath1, + silkscreenPath2, + pin1Indicator as AnyCircuitElement, + ] } diff --git a/tests/__snapshots__/sot235.snap.svg b/tests/__snapshots__/sot235.snap.svg index 7b95a3f..bbbf4df 100644 --- a/tests/__snapshots__/sot235.snap.svg +++ b/tests/__snapshots__/sot235.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 diff --git a/tests/sot235.test.ts b/tests/sot235.test.ts index c646218..bf79fe0 100644 --- a/tests/sot235.test.ts +++ b/tests/sot235.test.ts @@ -4,7 +4,6 @@ import { fp } from "../src/footprinter" test("sot235", () => { const soup = fp.string("sot235").circuitJson() - console.log(soup) const svgContent = convertCircuitJsonToPcbSvg(soup) expect(svgContent).toMatchSvgSnapshot(import.meta.path, "sot235") }) From 66ef37bca6c3be21616af9925051e72cc8ef78ca Mon Sep 17 00:00:00 2001 From: Anas sarkiz Date: Tue, 19 Nov 2024 21:31:02 +0200 Subject: [PATCH 5/8] Refactor all footprinter functions by updating its scheme, all footprints now have defualt value of num_pins --- src/fn/axial.ts | 2 +- src/fn/bga.ts | 14 ++------- src/fn/cap.ts | 2 +- src/fn/diode.ts | 4 +-- src/fn/dip.ts | 2 +- src/fn/led.ts | 2 +- src/fn/pinrow.ts | 4 +-- src/fn/pushbutton.ts | 10 +++++-- src/fn/quad.ts | 4 +-- src/fn/sod123.ts | 9 +++--- src/fn/soic.ts | 3 +- src/fn/sot23.ts | 3 +- src/fn/sot235.ts | 9 +++--- src/fn/sot723.ts | 10 +++---- src/fn/stampboard.ts | 4 +-- src/fn/stampreceiver.ts | 4 +-- src/footprinter.ts | 30 ++++++++++--------- src/helpers/passive-fn.ts | 2 +- tests/__snapshots__/0402.snap.svg | 2 +- tests/__snapshots__/cap footprint.snap.svg | 2 +- tests/__snapshots__/cap_imperial0402.snap.svg | 2 +- tests/__snapshots__/diode0402.snap.svg | 2 +- tests/__snapshots__/led_hole.snap.svg | 2 +- tests/__snapshots__/led_rect.snap.svg | 2 +- .../lqfp64_w10_h10_pl1_pw0.25mm.snap.svg | 2 +- tests/__snapshots__/sod123.snap.svg | 2 +- tests/__snapshots__/sot723.snap.svg | 2 +- 27 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/fn/axial.ts b/src/fn/axial.ts index 672adf8..f2b73b9 100644 --- a/src/fn/axial.ts +++ b/src/fn/axial.ts @@ -11,7 +11,7 @@ import { silkscreenRef, type SilkscreenRef } from "../helpers/silkscreenRef" export const axial_def = z.object({ fn: z.string(), - num_pins: z.any().transform(() => 2), + num_pins: z.literal(2).default(2), p: length.optional().default("2.54mm"), id: length.optional().default("0.7mm"), od: length.optional().default("1mm"), diff --git a/src/fn/bga.ts b/src/fn/bga.ts index 7ae01af..4cc8906 100644 --- a/src/fn/bga.ts +++ b/src/fn/bga.ts @@ -1,7 +1,7 @@ import type { AnySoupElement, PCBSMTPad } from "@tscircuit/soup" import { rectpad } from "../helpers/rectpad" import { ALPHABET } from "../helpers/zod/ALPHABET" -import { z } from "zod" +import { number, z } from "zod" import { length, distance } from "@tscircuit/soup" import { dim2d } from "src/helpers/zod/dim-2d" import { function_call } from "src/helpers/zod/function-call" @@ -11,7 +11,7 @@ import { type SilkscreenRef, silkscreenRef } from "src/helpers/silkscreenRef" export const bga_def = z .object({ fn: z.string(), - num_pins: z.number(), + num_pins: z.number().optional().default(64), grid: dim2d.optional(), p: distance.default("0.8mm"), w: length.optional(), @@ -106,16 +106,6 @@ export const bga = ( missing_pin_nums.push(1) } - if (num_pins_missing !== missing_pin_nums.length) { - throw new Error( - `not able to create bga component, unable to determine missing pins (try specifying them with "missing+1+2+..."\n\n${JSON.stringify( - parameters, - null, - " ", - )}`, - ) - } - const missing_pin_nums_set = new Set(missing_pin_nums) let missing_pins_passed = 0 diff --git a/src/fn/cap.ts b/src/fn/cap.ts index 5d43374..4f182e3 100644 --- a/src/fn/cap.ts +++ b/src/fn/cap.ts @@ -4,6 +4,6 @@ import { type PassiveDef, passive } from "../helpers/passive-fn" export const cap = ( parameters: PassiveDef, -): { circuitJson: AnySoupElement[]; parameters: any } => { +): { circuitJson: AnySoupElement[]; parameters: PassiveDef } => { return { circuitJson: passive(parameters), parameters } } diff --git a/src/fn/diode.ts b/src/fn/diode.ts index dac74f9..46da63d 100644 --- a/src/fn/diode.ts +++ b/src/fn/diode.ts @@ -1,9 +1,9 @@ import type { AnySoupElement } from "@tscircuit/soup" -import { passive } from "src/helpers/passive-fn" +import { passive, type PassiveDef } from "src/helpers/passive-fn" export const diode = (parameters: { tht: boolean p: number -}): { circuitJson: AnySoupElement[]; parameters: any } => { +}): { circuitJson: AnySoupElement[]; parameters: PassiveDef } => { return { circuitJson: passive(parameters), parameters } } diff --git a/src/fn/dip.ts b/src/fn/dip.ts index b08ebaf..a6e3482 100644 --- a/src/fn/dip.ts +++ b/src/fn/dip.ts @@ -15,7 +15,7 @@ export const extendDipDef = (newDefaults: { w?: string; p?: string }) => .object({ fn: z.string(), dip: z.literal(true), - num_pins: z.number(), + num_pins: z.number().optional().default(6), wide: z.boolean().optional(), narrow: z.boolean().optional(), w: length.optional(), diff --git a/src/fn/led.ts b/src/fn/led.ts index 0249234..596c8d0 100644 --- a/src/fn/led.ts +++ b/src/fn/led.ts @@ -3,6 +3,6 @@ import { type PassiveDef, passive } from "../helpers/passive-fn" export const led = ( parameters: PassiveDef, -): { circuitJson: AnySoupElement[]; parameters: any } => { +): { circuitJson: AnySoupElement[]; parameters: PassiveDef } => { return { circuitJson: passive(parameters), parameters } } diff --git a/src/fn/pinrow.ts b/src/fn/pinrow.ts index fc9a962..9be18b1 100644 --- a/src/fn/pinrow.ts +++ b/src/fn/pinrow.ts @@ -1,11 +1,11 @@ -import { z } from "zod" +import { number, z } from "zod" import { length, type AnySoupElement } from "@tscircuit/soup" import { platedhole } from "../helpers/platedhole" import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef" export const pinrow_def = z.object({ fn: z.string(), - num_pins: z.number(), + num_pins: number().optional().default(6), p: length.default("0.1in").describe("pitch"), id: length.default("1.0mm").describe("inner diameter"), od: length.default("1.2mm").describe("outer diameter"), diff --git a/src/fn/pushbutton.ts b/src/fn/pushbutton.ts index d200b9e..b3c7d0d 100644 --- a/src/fn/pushbutton.ts +++ b/src/fn/pushbutton.ts @@ -6,6 +6,10 @@ import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef" export const pushbutton_def = z.object({ fn: z.literal("pushbutton"), + w: z.literal(4.5).default(4.5), + h: z.literal(6.5).default(6.5), + id: z.literal(1).default(1), + od: z.literal(1.2).default(1.2), }) export const pushbutton = ( @@ -13,9 +17,9 @@ export const pushbutton = ( ): { circuitJson: AnyCircuitElement[]; parameters: any } => { const parameters = pushbutton_def.parse(raw_params) - const width = 4.5 - const height = 6.5 - const holeDiameter = 1 + const width = parameters.w + const height = parameters.h + const holeDiameter = parameters.id const holes: AnyCircuitElement[] = [ platedhole(1, -width / 2, height / 2, holeDiameter, holeDiameter * 1.2), diff --git a/src/fn/quad.ts b/src/fn/quad.ts index 032ebfd..4d7c7d0 100644 --- a/src/fn/quad.ts +++ b/src/fn/quad.ts @@ -1,5 +1,5 @@ import type { AnySoupElement, PcbSilkscreenPath } from "@tscircuit/soup" -import { z } from "zod" +import { optional, z } from "zod" import { length } from "@tscircuit/soup" import type { NowDefined } from "../helpers/zod/now-defined" import { rectpad } from "../helpers/rectpad" @@ -18,7 +18,7 @@ export const base_quad_def = z.object({ .transform((a) => (typeof a === "string" ? a.slice(1, -1).split(",") : a)) .pipe(z.array(pin_order_specifier)) .optional(), - num_pins: z.number(), + num_pins: z.number().optional().default(64), w: length.optional(), h: length.optional(), p: length.default(length.parse("0.5mm")), diff --git a/src/fn/sod123.ts b/src/fn/sod123.ts index 4467cfc..ccf4768 100644 --- a/src/fn/sod123.ts +++ b/src/fn/sod123.ts @@ -6,6 +6,7 @@ import { length } from "circuit-json" export const sod_def = z.object({ fn: z.string(), + num_pins: z.literal(3).default(3), w: z.string().default("2.36mm"), h: z.string().default("1.22mm"), pl: z.string().default("0.9mm"), @@ -19,7 +20,7 @@ export const sod123 = ( const parameters = sod_def.parse(raw_params) const silkscreenRefText: SilkscreenRef = silkscreenRef( 0, - Number(parameters.h) / 4 + 0.4, + length.parse(parameters.h) / 4 + 0.4, 0.3, ) @@ -48,14 +49,14 @@ export const getSodCoords = (parameters: { export const sodWithoutParsing = (parameters: z.infer) => { const pads: AnySoupElement[] = [] - for (let i = 0; i < 2; i++) { + for (let i = 1; i <= parameters.num_pins; i++) { const { x, y } = getSodCoords({ - pn: i + 1, + pn: i, pad_spacing: Number.parseFloat(parameters.pad_spacing), }) pads.push( rectpad( - i + 1, + i, x, y, Number.parseFloat(parameters.pl), diff --git a/src/fn/soic.ts b/src/fn/soic.ts index 8b34ed0..069af70 100644 --- a/src/fn/soic.ts +++ b/src/fn/soic.ts @@ -9,12 +9,13 @@ import { silkscreenRef, type SilkscreenRef } from "../helpers/silkscreenRef" export const extendSoicDef = (newDefaults: { w?: string p?: string + num_pins?: number legsoutside?: boolean }) => z .object({ fn: z.string(), - num_pins: z.number(), + num_pins: z.number().optional().default(8), w: length.default(length.parse(newDefaults.w ?? "5.3mm")), p: length.default(length.parse(newDefaults.p ?? "1.27mm")), pw: length.optional(), diff --git a/src/fn/sot23.ts b/src/fn/sot23.ts index 7c0f9d7..37ee913 100644 --- a/src/fn/sot23.ts +++ b/src/fn/sot23.ts @@ -5,7 +5,7 @@ import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef" export const sot23_def = z.object({ fn: z.string(), - num_pins: z.number().default(3), + num_pins: z.literal(3).default(3), w: z.string().default("1.92mm"), h: z.string().default("2.74mm"), pl: z.string().default("0.8mm"), @@ -61,6 +61,7 @@ export const sot23WithoutParsing = (parameters: z.infer) => { ), ) } + const silkscreenRefText: SilkscreenRef = silkscreenRef( 0, Number(parameters.h), diff --git a/src/fn/sot235.ts b/src/fn/sot235.ts index daf9a21..3ce7f09 100644 --- a/src/fn/sot235.ts +++ b/src/fn/sot235.ts @@ -2,16 +2,16 @@ import type { AnyCircuitElement, PcbSilkscreenPath } from "circuit-json" import { z } from "zod" import { rectpad } from "../helpers/rectpad" import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef" -import { u_curve } from "src/helpers/u-curve" export const sot235_def = z.object({ fn: z.string(), + num_pins: z.literal(5).default(5), h: z.string().default("1.6mm"), pl: z.string().default("1mm"), pw: z.string().default("0.7mm"), p: z.string().default("0.95mm"), }) -const num_pins = 5 + export const sot235 = ( raw_params: z.input, ): { circuitJson: AnyCircuitElement[]; parameters: any } => { @@ -50,7 +50,7 @@ export const sot23_5WithoutParsing = ( parameters: z.infer, ) => { const pads: AnyCircuitElement[] = [] - for (let i = 1; i <= num_pins; i++) { + for (let i = 1; i <= parameters.num_pins; i++) { const { x, y } = getCcwSot235Coords({ h: Number.parseFloat(parameters.h), p: Number.parseFloat(parameters.p), @@ -67,7 +67,8 @@ export const sot23_5WithoutParsing = ( ) } - const width = ((num_pins + 1) / 2) * Number.parseFloat(parameters.p) + const width = + ((parameters.num_pins + 1) / 2) * Number.parseFloat(parameters.p) const height = Number.parseFloat(parameters.h) const silkscreenPath1: PcbSilkscreenPath = { layer: "top", diff --git a/src/fn/sot723.ts b/src/fn/sot723.ts index a37ceeb..3b72864 100644 --- a/src/fn/sot723.ts +++ b/src/fn/sot723.ts @@ -1,11 +1,11 @@ -import type { AnySoupElement } from "@tscircuit/soup" +import { length, type AnySoupElement } from "@tscircuit/soup" import { z } from "zod" import { rectpad } from "../helpers/rectpad" import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef" export const sot723_def = z.object({ fn: z.string(), - num_pins: z.number().default(3), + num_pins: z.literal(3).default(3), w: z.string().default("1.2mm"), h: z.string().default("1.2mm"), pl: z.string().default("0.3mm"), @@ -18,9 +18,9 @@ export const sot723 = ( const parameters = sot723_def.parse(raw_params) const pad = sot723WithoutParsing(parameters) const silkscreenRefText: SilkscreenRef = silkscreenRef( - 0, - Number(parameters.h), - 0.3, + 0.4, + length.parse(parameters.h), + 0.2, ) return { circuitJson: [...pad, silkscreenRefText as AnySoupElement], diff --git a/src/fn/stampboard.ts b/src/fn/stampboard.ts index 0f0748a..788d568 100644 --- a/src/fn/stampboard.ts +++ b/src/fn/stampboard.ts @@ -12,8 +12,8 @@ import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef" export const stampboard_def = z.object({ fn: z.string(), w: length.default("22.58mm"), - left: length.optional(), - right: length.optional(), + left: length.optional().default(20), + right: length.optional().default(20), top: length.optional(), bottom: length.optional(), p: length.default(length.parse("2.54mm")), diff --git a/src/fn/stampreceiver.ts b/src/fn/stampreceiver.ts index b15d932..a5de325 100644 --- a/src/fn/stampreceiver.ts +++ b/src/fn/stampreceiver.ts @@ -12,8 +12,8 @@ import { platedhole } from "src/helpers/platedhole" export const stampreceiver_def = z.object({ fn: z.string(), w: length.default("22.58mm"), - left: length.optional(), - right: length.optional(), + left: length.optional().default(20), + right: length.optional().default(20), top: length.optional(), bottom: length.optional(), p: length.default(length.parse("2.54mm")), diff --git a/src/footprinter.ts b/src/footprinter.ts index df4d560..e87aca0 100644 --- a/src/footprinter.ts +++ b/src/footprinter.ts @@ -22,36 +22,36 @@ type CommonPassiveOptionKey = export type Footprinter = { dip: ( - num_pins: number, + num_pins?: number, ) => FootprinterParamsBuilder<"w" | "p" | "id" | "od" | "wide" | "narrow"> cap: () => FootprinterParamsBuilder res: () => FootprinterParamsBuilder diode: () => FootprinterParamsBuilder led: () => FootprinterParamsBuilder - lr: (num_pins: number) => FootprinterParamsBuilder<"w" | "l" | "pl" | "pr"> + lr: (num_pins?: number) => FootprinterParamsBuilder<"w" | "l" | "pl" | "pr"> qfp: ( - num_pins: number, + num_pins?: number, ) => FootprinterParamsBuilder<"w" | "p" | "id" | "od" | "wide" | "narrow"> quad: ( - num_pins: number, + num_pins?: number, ) => FootprinterParamsBuilder< "w" | "l" | "square" | "pl" | "pr" | "pb" | "pt" | "p" | "pw" | "ph" > bga: ( - num_pins: number, + num_pins?: number, ) => FootprinterParamsBuilder< "grid" | "p" | "w" | "h" | "ball" | "pad" | "missing" > - qfn: (num_pins: number) => FootprinterParamsBuilder<"w" | "h" | "p"> - soic: (num_pins: number) => FootprinterParamsBuilder<"w" | "p" | "id" | "od"> - mlp: (num_pins: number) => FootprinterParamsBuilder<"w" | "h" | "p"> - ssop: (num_pins: number) => FootprinterParamsBuilder<"w" | "p"> - tssop: (num_pins: number) => FootprinterParamsBuilder<"w" | "p"> - dfn: (num_pins: number) => FootprinterParamsBuilder<"w" | "p"> - pinrow: (num_pins: number) => FootprinterParamsBuilder<"p" | "id" | "od"> + qfn: (num_pins?: number) => FootprinterParamsBuilder<"w" | "h" | "p"> + soic: (num_pins?: number) => FootprinterParamsBuilder<"w" | "p" | "id" | "od"> + mlp: (num_pins?: number) => FootprinterParamsBuilder<"w" | "h" | "p"> + ssop: (num_pins?: number) => FootprinterParamsBuilder<"w" | "p"> + tssop: (num_pins?: number) => FootprinterParamsBuilder<"w" | "p"> + dfn: (num_pins?: number) => FootprinterParamsBuilder<"w" | "p"> + pinrow: (num_pins?: number) => FootprinterParamsBuilder<"p" | "id" | "od"> axial: () => FootprinterParamsBuilder<"p" | "id" | "od"> sot235: () => FootprinterParamsBuilder<"h" | "p" | "pl" | "pw"> - lqfp: (num_pins: number) => FootprinterParamsBuilder<"w" | "h" | "pl" | "pw"> + lqfp: (num_pins?: number) => FootprinterParamsBuilder<"w" | "h" | "pl" | "pw"> pushbutton: () => FootprinterParamsBuilder< "tllabel" | "trlabel" | "bllabel" | "brlabel" > @@ -183,7 +183,9 @@ export const footprinter = (): Footprinter & { target.imperial = v // res0402, cap0603 etc. } } else { - target.num_pins = Number.parseFloat(v) + target.num_pins = Number.isNaN(Number.parseFloat(v)) + ? undefined + : Number.parseFloat(v) } } } else { diff --git a/src/helpers/passive-fn.ts b/src/helpers/passive-fn.ts index 19d6a92..8362c3d 100644 --- a/src/helpers/passive-fn.ts +++ b/src/helpers/passive-fn.ts @@ -169,7 +169,7 @@ export const passive = (params: PassiveDef): AnySoupElement[] => { if (pw === undefined) throw new Error("could not infer pad width") if (ph === undefined) throw new Error("could not infer pad width") - const silkscreenRefText: SilkscreenRef = silkscreenRef(0, h / 2, h / 12) + const silkscreenRefText: SilkscreenRef = silkscreenRef(0, 0.9, 0.2) if (tht) { return [ platedhole(1, -p / 2, 0, pw, (pw * 1) / 0.8), diff --git a/tests/__snapshots__/0402.snap.svg b/tests/__snapshots__/0402.snap.svg index 666d007..40009f8 100644 --- a/tests/__snapshots__/0402.snap.svg +++ b/tests/__snapshots__/0402.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 diff --git a/tests/__snapshots__/cap footprint.snap.svg b/tests/__snapshots__/cap footprint.snap.svg index 666d007..40009f8 100644 --- a/tests/__snapshots__/cap footprint.snap.svg +++ b/tests/__snapshots__/cap footprint.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 diff --git a/tests/__snapshots__/cap_imperial0402.snap.svg b/tests/__snapshots__/cap_imperial0402.snap.svg index 666d007..40009f8 100644 --- a/tests/__snapshots__/cap_imperial0402.snap.svg +++ b/tests/__snapshots__/cap_imperial0402.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 diff --git a/tests/__snapshots__/diode0402.snap.svg b/tests/__snapshots__/diode0402.snap.svg index 666d007..40009f8 100644 --- a/tests/__snapshots__/diode0402.snap.svg +++ b/tests/__snapshots__/diode0402.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 diff --git a/tests/__snapshots__/led_hole.snap.svg b/tests/__snapshots__/led_hole.snap.svg index 98868c1..b02642c 100644 --- a/tests/__snapshots__/led_hole.snap.svg +++ b/tests/__snapshots__/led_hole.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 diff --git a/tests/__snapshots__/led_rect.snap.svg b/tests/__snapshots__/led_rect.snap.svg index 24a6436..d55e5d8 100644 --- a/tests/__snapshots__/led_rect.snap.svg +++ b/tests/__snapshots__/led_rect.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 diff --git a/tests/__snapshots__/lqfp64_w10_h10_pl1_pw0.25mm.snap.svg b/tests/__snapshots__/lqfp64_w10_h10_pl1_pw0.25mm.snap.svg index 38a7932..0da3843 100644 --- a/tests/__snapshots__/lqfp64_w10_h10_pl1_pw0.25mm.snap.svg +++ b/tests/__snapshots__/lqfp64_w10_h10_pl1_pw0.25mm.snap.svg @@ -10,4 +10,4 @@ .pcb-silkscreen-top { stroke: #f2eda1; } .pcb-silkscreen-bottom { stroke: #f2eda1; } .pcb-silkscreen-text { fill: #f2eda1; } - \ No newline at end of file + {REF} \ No newline at end of file diff --git a/tests/__snapshots__/sod123.snap.svg b/tests/__snapshots__/sod123.snap.svg index 0be0753..c2a5915 100644 --- a/tests/__snapshots__/sod123.snap.svg +++ b/tests/__snapshots__/sod123.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 diff --git a/tests/__snapshots__/sot723.snap.svg b/tests/__snapshots__/sot723.snap.svg index a43392a..23b81fa 100644 --- a/tests/__snapshots__/sot723.snap.svg +++ b/tests/__snapshots__/sot723.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 From b0e616b373f7c8ab35e35312cce303a8a0ebd64b Mon Sep 17 00:00:00 2001 From: Anas sarkiz Date: Tue, 19 Nov 2024 23:19:52 +0200 Subject: [PATCH 6/8] removed unneeded importes --- src/fn/soic.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fn/soic.ts b/src/fn/soic.ts index 069af70..83b271f 100644 --- a/src/fn/soic.ts +++ b/src/fn/soic.ts @@ -1,6 +1,6 @@ import type { AnySoupElement, PcbSilkscreenPath } from "@tscircuit/soup" import { platedhole } from "../helpers/platedhole" -import { z, type AnyZodObject } from "zod" +import { z } from "zod" import { length } from "@tscircuit/soup" import type { NowDefined } from "../helpers/zod/now-defined" import { u_curve } from "../helpers/u-curve" From 6679bfb0edac1e8e453709eb6c30b1054df20ea9 Mon Sep 17 00:00:00 2001 From: Anas sarkiz Date: Tue, 19 Nov 2024 23:23:34 +0200 Subject: [PATCH 7/8] removed import number from zod --- src/fn/bga.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fn/bga.ts b/src/fn/bga.ts index 4cc8906..0fbae44 100644 --- a/src/fn/bga.ts +++ b/src/fn/bga.ts @@ -1,7 +1,7 @@ import type { AnySoupElement, PCBSMTPad } from "@tscircuit/soup" import { rectpad } from "../helpers/rectpad" import { ALPHABET } from "../helpers/zod/ALPHABET" -import { number, z } from "zod" +import { z } from "zod" import { length, distance } from "@tscircuit/soup" import { dim2d } from "src/helpers/zod/dim-2d" import { function_call } from "src/helpers/zod/function-call" From df042d38c92a6b1e0098e9260389a41326ba45cb Mon Sep 17 00:00:00 2001 From: Anas sarkiz Date: Wed, 20 Nov 2024 20:31:14 +0200 Subject: [PATCH 8/8] removed unneeded imports --- src/fn/pinrow.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fn/pinrow.ts b/src/fn/pinrow.ts index cdbf6b7..e865708 100644 --- a/src/fn/pinrow.ts +++ b/src/fn/pinrow.ts @@ -1,11 +1,11 @@ -import { number, z } from "zod" +import { z } from "zod" import { length, type AnySoupElement } from "@tscircuit/soup" import { platedhole } from "../helpers/platedhole" import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef" export const pinrow_def = z.object({ fn: z.string(), - num_pins: number().optional().default(6), + num_pins: z.number().optional().default(6), p: length.default("0.1in").describe("pitch"), id: length.default("1.0mm").describe("inner diameter"), od: length.default("1.5mm").describe("outer diameter"),