From f01f7c9b449189c8a934d769442ca2d5b92bb409 Mon Sep 17 00:00:00 2001 From: Severin Ibarluzea Date: Sun, 6 Jul 2025 13:12:21 -0700 Subject: [PATCH] feat: add m2host footprint --- bun.lock | 4 +-- package.json | 2 +- src/fn/index.ts | 1 + src/fn/m2host.ts | 41 +++++++++++++++++++++++++++++ tests/__snapshots__/m2host.snap.svg | 1 + tests/m2host.test.ts | 9 +++++++ 6 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/fn/m2host.ts create mode 100644 tests/__snapshots__/m2host.snap.svg create mode 100644 tests/m2host.test.ts diff --git a/bun.lock b/bun.lock index 6afde8d9..0df5e9dd 100644 --- a/bun.lock +++ b/bun.lock @@ -13,7 +13,7 @@ "@tscircuit/soup-util": "^0.0.41", "@types/bun": "^1.2.2", "@types/node": "^20.12.13", - "bun-match-svg": "^0.0.10", + "bun-match-svg": "^0.0.11", "circuit-json": "^0.0.190", "circuit-json-to-connectivity-map": "^0.0.18", "circuit-to-svg": "^0.0.152", @@ -215,7 +215,7 @@ "buffer": ["buffer@5.7.1", "", { "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.1.13" } }, "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ=="], - "bun-match-svg": ["bun-match-svg@0.0.10", "", { "dependencies": { "looks-same": "^9.0.1" }, "peerDependencies": { "typescript": "^5.0.0" }, "bin": { "bun-match-svg": "cli.ts" } }, "sha512-tlyULQxkC89TpTOCHrQSHxKNqk2RvFuq1PC6NQBJdMXMgJXf62hNc+riwKbLoQyEt+9Jwu1t2I54kGkYLLo5uw=="], + "bun-match-svg": ["bun-match-svg@0.0.11", "", { "dependencies": { "looks-same": "^9.0.1" }, "peerDependencies": { "typescript": "^5.0.0" }, "bin": { "bun-match-svg": "cli.ts" } }, "sha512-5ophqTjpK/1Q9vhU/pJnAq1FDXBisXsGZvgQJmlbiimsXIWUzO2C5jswSDzp5UUzDGKqM8e7f2JQ7ndeEhAyAA=="], "bun-types": ["bun-types@1.2.16", "", { "dependencies": { "@types/node": "*" } }, "sha512-ciXLrHV4PXax9vHvUrkvun9VPVGOVwbbbBF/Ev1cXz12lyEZMoJpIJABOfPcN9gDJRaiKF9MVbSygLg4NXu3/A=="], diff --git a/package.json b/package.json index 9365ad85..fc5cd35e 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "@tscircuit/soup-util": "^0.0.41", "@types/bun": "^1.2.2", "@types/node": "^20.12.13", - "bun-match-svg": "^0.0.10", + "bun-match-svg": "^0.0.11", "circuit-json": "^0.0.190", "circuit-json-to-connectivity-map": "^0.0.18", "circuit-to-svg": "^0.0.152", diff --git a/src/fn/index.ts b/src/fn/index.ts index 2a1eda53..76892359 100644 --- a/src/fn/index.ts +++ b/src/fn/index.ts @@ -70,3 +70,4 @@ export { sot323 } from "./sot323" export { smtpad } from "./smtpad" export { platedhole } from "./platedhole" export { sot } from "./sot" +export { m2host } from "./m2host" diff --git a/src/fn/m2host.ts b/src/fn/m2host.ts new file mode 100644 index 00000000..bd0ec5c7 --- /dev/null +++ b/src/fn/m2host.ts @@ -0,0 +1,41 @@ +import { length, type AnySoupElement } from "circuit-json" +import { z } from "zod" +import { mm } from "@tscircuit/mm" +import { rectpad } from "../helpers/rectpad" +import { silkscreenRef } from "../helpers/silkscreenRef" + +export const m2host_def = z.object({ + fn: z.string(), + pad_w: length.default("0.25mm"), + pad_l: length.default("0.60mm"), + pitch: length.default("0.50mm"), + row_spacing: length.default("0.25mm"), + edge_clearance: length.default("0.30mm"), +}) + +export type M2HostDef = z.input + +export const m2host = ( + raw_params: M2HostDef, +): { circuitJson: AnySoupElement[]; parameters: any } => { + const p = m2host_def.parse(raw_params) + const padW = mm(p.pad_w) + const padL = mm(p.pad_l) + const pitch = mm(p.pitch) + const rowSpacing = mm(p.row_spacing) + const edge = mm(p.edge_clearance) + const pads: AnySoupElement[] = [] + const total = 75 + const start = -((total - 1) / 2) * pitch + for (let i = 0; i < total; i++) { + const n = i + 1 + const x = start + i * pitch + const y = n % 2 === 1 ? edge : edge + rowSpacing + pads.push(rectpad(n, x, y, padL, padW)) + } + const silk = silkscreenRef(0, edge + rowSpacing + 1, 0.5) + return { + circuitJson: [...pads, silk], + parameters: p, + } +} diff --git a/tests/__snapshots__/m2host.snap.svg b/tests/__snapshots__/m2host.snap.svg new file mode 100644 index 00000000..5b90d162 --- /dev/null +++ b/tests/__snapshots__/m2host.snap.svg @@ -0,0 +1 @@ +{REF} diff --git a/tests/m2host.test.ts b/tests/m2host.test.ts new file mode 100644 index 00000000..59b72b9a --- /dev/null +++ b/tests/m2host.test.ts @@ -0,0 +1,9 @@ +import { test, expect } from "bun:test" +import { convertCircuitJsonToPcbSvg } from "circuit-to-svg" +import { fp } from "../src/footprinter" + +test("m2host", () => { + const circuitJson = fp.string("m2host").circuitJson() + const svgContent = convertCircuitJsonToPcbSvg(circuitJson) + expect(svgContent).toMatchSvgSnapshot(import.meta.path, "m2host") +})