@tscircuit/footprinter 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/footprinter",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.0.9",
5
5
  "description": "",
6
6
  "main": "dist/index.cjs",
7
7
  "scripts": {
package/src/fn/bga.ts CHANGED
@@ -1,7 +1,61 @@
1
1
  import type { AnySoupElement, PCBSMTPad } from "@tscircuit/soup"
2
2
  import { rectpad } from "../helpers/rectpad"
3
- import { type BgaDefInput, bga_def } from "../helpers/zod/bga-def"
4
3
  import { ALPHABET } from "../helpers/zod/ALPHABET"
4
+ import { z } from "zod"
5
+ import { length, distance } from "@tscircuit/soup"
6
+ import { dim2d } from "src/helpers/zod/dim-2d"
7
+ import { function_call } from "src/helpers/zod/function-call"
8
+ import type { NowDefined } from "src/helpers/zod/now-defined"
9
+
10
+ export const bga_def = z
11
+ .object({
12
+ num_pins: z.number(),
13
+ grid: dim2d.optional(),
14
+ p: distance.default("0.8mm"),
15
+ w: length.optional(),
16
+ h: length.optional(),
17
+ ball: length.optional().describe("ball diameter"),
18
+ pad: length.optional().describe("pad width/height"),
19
+
20
+ tlorigin: z.boolean().optional(),
21
+ blorigin: z.boolean().optional(),
22
+ trorigin: z.boolean().optional(),
23
+ brorigin: z.boolean().optional(),
24
+
25
+ missing: function_call.default([]),
26
+ })
27
+ .transform((a) => {
28
+ let origin: "tl" | "bl" | "tr" | "br" = "tl"
29
+ if (a.blorigin) origin = "bl"
30
+ if (a.trorigin) origin = "tr"
31
+ if (a.brorigin) origin = "br"
32
+
33
+ if (!a.grid) {
34
+ // find the largest square for the number of pins
35
+ const largest_square = Math.ceil(Math.sqrt(a.num_pins))
36
+ a.grid = { x: largest_square, y: largest_square }
37
+ }
38
+
39
+ if (a.missing) {
40
+ a.missing = a.missing.map((s) => {
41
+ if (typeof s === "number") return s
42
+ if (s === "center") return "center"
43
+ if (s === "topleft") return "topleft"
44
+ const m = s.match(/([A-Z]+)(\d+)/)
45
+ if (!m) return s
46
+ let Y = ALPHABET.indexOf(m[1]!)
47
+ let X = parseInt(m[2]!) - 1
48
+ return Y * a.grid!.x + X + 1
49
+ })
50
+ }
51
+
52
+ const new_def = { ...a, origin }
53
+
54
+ return new_def as NowDefined<typeof new_def, "w" | "h" | "grid">
55
+ })
56
+
57
+ export type BgaDefInput = z.input<typeof bga_def>
58
+ export type BgaDef = z.infer<typeof bga_def>
5
59
 
6
60
  export const bga = (params: BgaDefInput): AnySoupElement[] => {
7
61
  const bga_params = bga_def.parse(params)
package/src/fn/soic.ts ADDED
@@ -0,0 +1,82 @@
1
+ import type { AnySoupElement } from "@tscircuit/soup"
2
+ import { platedhole } from "../helpers/platedhole"
3
+ import { z } from "zod"
4
+ import { length } from "@tscircuit/soup"
5
+ import type { NowDefined } from "../helpers/zod/now-defined"
6
+
7
+ const soic_def = z
8
+ .object({
9
+ soic: z.literal(true),
10
+ num_pins: z.number(),
11
+ w: length,
12
+ p: length.default(length.parse("1.27mm")),
13
+ id: length.optional(),
14
+ od: length.optional(),
15
+ })
16
+ .transform((v) => {
17
+ // Default inner diameter and outer diameter
18
+ if (!v.id && !v.od) {
19
+ v.id = length.parse("0.6mm")
20
+ v.od = length.parse("1.0mm")
21
+ } else if (!v.id) {
22
+ v.id = v.od! * (0.6 / 1.0)
23
+ } else if (!v.od) {
24
+ v.od = v.id! * (1.0 / 0.6)
25
+ }
26
+ return v as NowDefined<typeof v, "w" | "p" | "id" | "od">
27
+ })
28
+
29
+ export const getCcwSoicCoords = (
30
+ pinCount: number,
31
+ pn: number,
32
+ w: number,
33
+ p: number
34
+ ) => {
35
+ /** pin height */
36
+ const ph = pinCount / 2
37
+ const isLeft = pn <= ph
38
+
39
+ /** Number of gaps between pins on each side, e.g. 4 pins = 3 spaces */
40
+ const leftPinGaps = ph - 1
41
+
42
+ /** gap size (pitch) */
43
+ const gs = p
44
+
45
+ const h = gs * leftPinGaps
46
+
47
+ if (isLeft) {
48
+ // The y position starts at h/2, then goes down by gap size
49
+ // for each pin
50
+ return { x: -w / 2, y: h / 2 - (pn - 1) * gs }
51
+ } else {
52
+ // The y position starts at -h/2, then goes up by gap size
53
+ return { x: w / 2, y: -h / 2 + (pn - ph - 1) * gs }
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Returns the plated holes for a SOIC package.
59
+ */
60
+ export const soic = (raw_params: {
61
+ soic: true
62
+ num_pins: number
63
+ w: number
64
+ p?: number
65
+ id?: string | number
66
+ od?: string | number
67
+ }): AnySoupElement[] => {
68
+ const params = soic_def.parse(raw_params)
69
+ const platedHoles: AnySoupElement[] = []
70
+ for (let i = 0; i < params.num_pins; i++) {
71
+ const { x, y } = getCcwSoicCoords(
72
+ params.num_pins,
73
+ i + 1,
74
+ params.w,
75
+ params.p ?? 1.27
76
+ )
77
+ platedHoles.push(
78
+ platedhole(i + 1, x, y, params.id ?? "0.6mm", params.od ?? "1mm")
79
+ )
80
+ }
81
+ return platedHoles
82
+ }
@@ -4,6 +4,7 @@ import { cap } from "./fn/cap"
4
4
  import { led } from "./fn/led"
5
5
  import { res } from "./fn/res"
6
6
  import { bga } from "./fn/bga"
7
+ import { soic } from "./fn/soic"
7
8
  import type { AnySoupElement } from "@tscircuit/soup"
8
9
  import { isNotNull } from "./helpers/is-not-null"
9
10
 
@@ -42,6 +43,7 @@ export type Footprinter = {
42
43
  ) => FootprinterParamsBuilder<
43
44
  "grid" | "p" | "w" | "h" | "ball" | "pad" | "missing"
44
45
  >
46
+ soic: (num_pins: number) => FootprinterParamsBuilder<"w" | "p" | "id" | "od">
45
47
  params: () => any
46
48
  soup: () => AnySoupElement[]
47
49
  }
@@ -78,6 +80,7 @@ export const footprinter = (): Footprinter & { string: typeof string } => {
78
80
  if ("led" in target) return () => led(target)
79
81
  if ("res" in target) return () => res(target)
80
82
  if ("bga" in target) return () => bga(target)
83
+ if ("soic" in target) return () => soic(target)
81
84
 
82
85
  return () => {
83
86
  // TODO improve error
@@ -91,9 +94,15 @@ export const footprinter = (): Footprinter & { string: typeof string } => {
91
94
  return () => target
92
95
  }
93
96
  return (v: any) => {
94
- if (["bga", "lr", "quad", "dip"].includes(prop as string)) {
97
+ if (Object.keys(target).length === 0) {
95
98
  target[prop] = true
96
- target.num_pins = parseFloat(v)
99
+ if (prop === "res" || prop === "cap") {
100
+ if (v) {
101
+ target.imperial = v // res0402, cap0603 etc.
102
+ }
103
+ } else {
104
+ target.num_pins = parseFloat(v)
105
+ }
97
106
  } else {
98
107
  target[prop] = v ?? true
99
108
  }
@@ -0,0 +1,11 @@
1
+ import test from "ava"
2
+ import { getTestFixture } from "tests/fixtures/get-test-fixture"
3
+ import { su } from "@tscircuit/soup-util"
4
+
5
+ test("res_imperial0402", async (t) => {
6
+ const { fp } = await getTestFixture(t)
7
+ const soup = fp.string("res_imperial0402").soup()
8
+
9
+ t.is(su(soup).pcb_smtpad.list().length, 2)
10
+ t.is(su(soup).pcb_plated_hole.list().length, 0)
11
+ })
@@ -0,0 +1,10 @@
1
+ import test from "ava"
2
+ import { getTestFixture } from "tests/fixtures/get-test-fixture"
3
+ import { su } from "@tscircuit/soup-util"
4
+
5
+ test("soic8_w5.3mm_p1.27mm", async (t) => {
6
+ const { fp } = await getTestFixture(t)
7
+ const soup = fp.string("soic8_w5.3mm_p1.27mm").soup()
8
+
9
+ t.is(su(soup).pcb_plated_hole.list().length, 8)
10
+ })
package/tsconfig.json CHANGED
@@ -5,6 +5,7 @@
5
5
  "skipLibCheck": true,
6
6
  "target": "es2022",
7
7
  "allowJs": true,
8
+ "baseUrl": ".",
8
9
  "resolveJsonModule": true,
9
10
  "moduleDetection": "force",
10
11
  "isolatedModules": true,
@@ -1,56 +0,0 @@
1
- import { z } from "zod"
2
- import { length, distance } from "@tscircuit/soup"
3
- import { dim2d } from "./dim-2d"
4
- import { function_call } from "./function-call"
5
- import type { NowDefined } from "./now-defined"
6
- import { ALPHABET } from "./ALPHABET"
7
-
8
- export const bga_def = z
9
- .object({
10
- num_pins: z.number(),
11
- grid: dim2d.optional(),
12
- p: distance.default("0.8mm"),
13
- w: length.optional(),
14
- h: length.optional(),
15
- ball: length.optional().describe("ball diameter"),
16
- pad: length.optional().describe("pad width/height"),
17
-
18
- tlorigin: z.boolean().optional(),
19
- blorigin: z.boolean().optional(),
20
- trorigin: z.boolean().optional(),
21
- brorigin: z.boolean().optional(),
22
-
23
- missing: function_call.default([]),
24
- })
25
- .transform((a) => {
26
- let origin: "tl" | "bl" | "tr" | "br" = "tl"
27
- if (a.blorigin) origin = "bl"
28
- if (a.trorigin) origin = "tr"
29
- if (a.brorigin) origin = "br"
30
-
31
- if (!a.grid) {
32
- // find the largest square for the number of pins
33
- const largest_square = Math.ceil(Math.sqrt(a.num_pins))
34
- a.grid = { x: largest_square, y: largest_square }
35
- }
36
-
37
- if (a.missing) {
38
- a.missing = a.missing.map((s) => {
39
- if (typeof s === "number") return s
40
- if (s === "center") return "center"
41
- if (s === "topleft") return "topleft"
42
- const m = s.match(/([A-Z]+)(\d+)/)
43
- if (!m) return s
44
- let Y = ALPHABET.indexOf(m[1]!)
45
- let X = parseInt(m[2]!) - 1
46
- return Y * a.grid!.x + X + 1
47
- })
48
- }
49
-
50
- const new_def = { ...a, origin }
51
-
52
- return new_def as NowDefined<typeof new_def, "w" | "h" | "grid">
53
- })
54
-
55
- export type BgaDefInput = z.input<typeof bga_def>
56
- export type BgaDef = z.infer<typeof bga_def>