@tscircuit/footprinter 0.0.12 → 0.0.14

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.12",
4
+ "version": "0.0.14",
5
5
  "description": "",
6
6
  "main": "dist/index.cjs",
7
7
  "scripts": {
package/src/fn/quad.ts ADDED
@@ -0,0 +1,124 @@
1
+ import type { AnySoupElement } from "@tscircuit/soup"
2
+ import { z } from "zod"
3
+ import { length } from "@tscircuit/soup"
4
+ import type { NowDefined } from "../helpers/zod/now-defined"
5
+ import { rectpad } from "../helpers/rectpad"
6
+ import { pin_order_specifier } from "src/helpers/zod/pin-order-specifier"
7
+ import { getQuadPinMap } from "src/helpers/get-quad-pin-map"
8
+
9
+ const base_quad_def = z.object({
10
+ quad: z.literal(true),
11
+ cc: z.literal(true).optional(),
12
+ ccw: z.literal(true).optional(),
13
+ startingpin: z.array(pin_order_specifier).optional(),
14
+ num_pins: z.number(),
15
+ w: length.optional(),
16
+ h: length.optional(),
17
+ p: length.default(length.parse("0.5mm")),
18
+ pw: length.optional(),
19
+ pl: length.optional(),
20
+ })
21
+
22
+ const quad_def = base_quad_def.transform((v) => {
23
+ if (v.w && !v.h) {
24
+ v.h = v.w
25
+ } else if (!v.w && v.h) {
26
+ v.w = v.h
27
+ }
28
+
29
+ const side_pin_count = v.num_pins / 4
30
+
31
+ if (!v.p && !v.pw && !v.pl && v.w) {
32
+ // HACK: This is wayyy underspecified
33
+ const approx_pin_size_of_side = side_pin_count + 4
34
+ v.p = v.w / approx_pin_size_of_side
35
+ }
36
+
37
+ if (!v.p && v.w && v.h && v.pw && v.pl) {
38
+ // HACK: This is wayyy underspecified
39
+ v.p = (v.w - v.pl * 2) / (side_pin_count - 1)
40
+ }
41
+
42
+ if (v.p && !v.pw && !v.pl) {
43
+ v.pw = v.p / 2
44
+ v.pl = v.p / 2
45
+ } else if (!v.pw) {
46
+ v.pw = v.pl! * (0.6 / 1.0)
47
+ } else if (!v.pl) {
48
+ v.pl = v.pw! * (1.0 / 0.6)
49
+ }
50
+
51
+ return v as NowDefined<typeof v, "w" | "h" | "p" | "pw" | "pl">
52
+ })
53
+
54
+ const SIDES_CCW = ["left", "bottom", "right", "top"] as const
55
+
56
+ export const getQuadCoords = (
57
+ pinCount: number,
58
+ pn: number, // pin number
59
+ w: number, // width of the package
60
+ h: number, // height (length) of the package
61
+ p: number // pitch between pins
62
+ ) => {
63
+ const sidePinCount = pinCount / 4
64
+ const side = SIDES_CCW[Math.floor((pn - 1) / sidePinCount)]
65
+ const pos = (pn - 1) % sidePinCount
66
+
67
+ const halfW = w / 2
68
+ const halfH = h / 2
69
+
70
+ /** inner box width */
71
+ const ibw = p * (sidePinCount - 1)
72
+ /** inner box height */
73
+ const ibh = p * (sidePinCount - 1)
74
+
75
+ switch (side) {
76
+ case "left":
77
+ return { x: -halfW / 2, y: ibh / 2 - pos * p, o: "vert" }
78
+ case "bottom":
79
+ return { x: -ibw / 2 + pos * p, y: -halfH / 2, o: "horz" }
80
+ case "right":
81
+ return { x: halfW / 2, y: -ibh / 2 + pos * p, o: "vert" }
82
+ case "top":
83
+ return { x: ibw / 2 - pos * p, y: halfH / 2, o: "horz" }
84
+ default:
85
+ throw new Error("Invalid pin number")
86
+ }
87
+ }
88
+
89
+ export const quad = (raw_params: {
90
+ quad: true
91
+ num_pins: number
92
+ w: number
93
+ l: number
94
+ p?: number
95
+ id?: string | number
96
+ od?: string | number
97
+ }): AnySoupElement[] => {
98
+ const params = quad_def.parse(raw_params)
99
+ const pads: AnySoupElement[] = []
100
+ const pin_map = getQuadPinMap(params)
101
+ for (let i = 0; i < params.num_pins; i++) {
102
+ const {
103
+ x,
104
+ y,
105
+ o: orientation,
106
+ } = getQuadCoords(
107
+ params.num_pins,
108
+ i + 1,
109
+ params.w,
110
+ params.h,
111
+ params.p ?? 0.5
112
+ )
113
+
114
+ let pw = params.pw,
115
+ pl = params.pl
116
+ if (orientation === "vert") {
117
+ ;[pw, pl] = [pl, pw]
118
+ }
119
+
120
+ const pn = getQuadPinMap(params)[i + 1]
121
+ pads.push(rectpad(pn!, x, y, pw, pl))
122
+ }
123
+ return pads
124
+ }
@@ -5,6 +5,7 @@ import { led } from "./fn/led"
5
5
  import { res } from "./fn/res"
6
6
  import { bga } from "./fn/bga"
7
7
  import { soic } from "./fn/soic"
8
+ import { quad } from "./fn/quad"
8
9
  import type { AnySoupElement } from "@tscircuit/soup"
9
10
  import { isNotNull } from "./helpers/is-not-null"
10
11
 
@@ -81,6 +82,7 @@ export const footprinter = (): Footprinter & { string: typeof string } => {
81
82
  if ("res" in target) return () => res(target)
82
83
  if ("bga" in target) return () => bga(target)
83
84
  if ("soic" in target) return () => soic(target)
85
+ if ("quad" in target) return () => quad(target)
84
86
 
85
87
  return () => {
86
88
  // TODO improve error
@@ -0,0 +1,105 @@
1
+ import type { PinOrderSpecifier } from "./zod/pin-order-specifier"
2
+
3
+ /**
4
+ * A counter-clockwise pin map is [1,2,3,4,5,6,7,8] for an 8-pin package
5
+ *
6
+ * 8 7
7
+ * 1 6
8
+ * 2 5
9
+ * 3 4
10
+ *
11
+ * Given some parameters, we're returning how to map the pins in a quad package
12
+ * with a different order. For example, if we pass in cw=true, we'll get the
13
+ * following mapping
14
+ *
15
+ * 1 -> 1
16
+ * 2 -> 8
17
+ * 3 -> 7
18
+ * 4 -> 6
19
+ * 5 -> 5
20
+ * 6 -> 4
21
+ * 7 -> 3
22
+ * 8 -> 2
23
+ *
24
+ * Which allows us to create the CW version of the package:
25
+ *
26
+ * 2 3
27
+ * 1 4
28
+ * 8 5
29
+ * 7 6
30
+ */
31
+ export const getQuadPinMap = ({
32
+ num_pins,
33
+ cw,
34
+ ccw,
35
+ startingpin,
36
+ }: {
37
+ num_pins: number
38
+ cw?: boolean
39
+ ccw?: boolean
40
+ startingpin?: PinOrderSpecifier[]
41
+ }): number[] => {
42
+ const pin_map: number[] = []
43
+ const pins_per_side = num_pins / 4
44
+ let current_position_ccw_normal = 1
45
+
46
+ /** Starting Flag Pins */
47
+ const sfp: Record<PinOrderSpecifier, boolean> = {} as any
48
+ for (const specifier of startingpin ?? []) {
49
+ sfp[specifier] = true
50
+ }
51
+ if (!sfp.leftside && !sfp.topside && !sfp.rightside && !sfp.bottomside) {
52
+ sfp.leftside = true
53
+ }
54
+ if (!sfp.bottompin && !sfp.leftpin && !sfp.rightpin && !sfp.toppin) {
55
+ if (sfp.leftside) {
56
+ sfp.toppin = true
57
+ } else if (sfp.topside) {
58
+ sfp.rightpin = true
59
+ } else if (sfp.rightside) {
60
+ sfp.bottompin = true
61
+ } else if (sfp.bottomside) {
62
+ sfp.leftpin = true
63
+ }
64
+ }
65
+
66
+ if (sfp.leftside && sfp.toppin) {
67
+ current_position_ccw_normal = 1
68
+ } else if (sfp.leftside && sfp.bottompin) {
69
+ current_position_ccw_normal = pins_per_side
70
+ } else if (sfp.bottomside && sfp.leftpin) {
71
+ current_position_ccw_normal = pins_per_side + 1
72
+ } else if (sfp.bottomside && sfp.rightpin) {
73
+ current_position_ccw_normal = pins_per_side * 2
74
+ } else if (sfp.rightside && sfp.bottompin) {
75
+ current_position_ccw_normal = pins_per_side * 2 + 1
76
+ } else if (sfp.rightside && sfp.toppin) {
77
+ current_position_ccw_normal = pins_per_side * 3
78
+ } else if (sfp.topside && sfp.rightpin) {
79
+ current_position_ccw_normal = pins_per_side * 3 + 1
80
+ } else if (sfp.topside && sfp.leftpin) {
81
+ current_position_ccw_normal = pins_per_side * 4
82
+ }
83
+
84
+ pin_map.push(-1) // the first index is meaningless
85
+
86
+ // Each iteration we move the current position to the next pin, if we're
87
+ // going CCW this means incrementing, if we're going CW this means
88
+ // decrementing
89
+ for (let i = 0; i < num_pins; i++) {
90
+ pin_map.push(current_position_ccw_normal)
91
+ if (ccw) {
92
+ current_position_ccw_normal++
93
+ if (current_position_ccw_normal > num_pins) {
94
+ current_position_ccw_normal = 1
95
+ }
96
+ } else {
97
+ current_position_ccw_normal--
98
+ if (current_position_ccw_normal < 1) {
99
+ current_position_ccw_normal = num_pins
100
+ }
101
+ }
102
+ }
103
+
104
+ return pin_map
105
+ }
@@ -0,0 +1,13 @@
1
+ import { z } from "zod"
2
+ export const pin_order_specifier = z.enum([
3
+ "leftside",
4
+ "topside",
5
+ "rightside",
6
+ "bottomside",
7
+ "toppin",
8
+ "bottompin",
9
+ "leftpin",
10
+ "rightpin",
11
+ ])
12
+
13
+ export type PinOrderSpecifier = z.infer<typeof pin_order_specifier>
@@ -0,0 +1,37 @@
1
+ import test from "ava"
2
+ import { fp } from "../src/footprinter"
3
+ import type { AnySoupElement } from "@tscircuit/soup"
4
+ import { getTestFixture, toPinPositionString } from "./fixtures"
5
+
6
+ test("quad16_w4_l4_p0.4_pw0.25_pl0.4", async (t) => {
7
+ const { fp, logSoup } = await getTestFixture(t)
8
+ const soup = fp.string("quad16_w4_l4_p0.4_pw0.25_pl0.4").soup()
9
+
10
+ await logSoup(soup)
11
+ t.pass()
12
+ })
13
+
14
+ // const ps = toPinPositionString(soup)
15
+
16
+ // t.is(
17
+ // ps,
18
+ // `
19
+ // 1 : -1.75 -2.00
20
+ // 2 : -1.25 -2.00
21
+ // 3 : -0.75 -2.00
22
+ // 4 : -0.25 -2.00
23
+ // 5 : 0.25 -2.00
24
+ // 6 : 0.75 -2.00
25
+ // 7 : 1.25 -2.00
26
+ // 8 : 1.75 -2.00
27
+ // 9 : 2.00 -1.75
28
+ // 10: 2.00 -1.25
29
+ // 11: 2.00 -0.75
30
+ // 12: 2.00 -0.25
31
+ // 13: 2.00 0.25
32
+ // 14: 2.00 0.75
33
+ // 15: 2.00 1.25
34
+ // 16: 2.00 1.75
35
+ // `.trim()
36
+ // )
37
+ // })