-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented sot235 (sot23-5) footprint with testing (#78)
* Implemented sot235 (sot23-5) footprint with testing * formated * Bun format * Refactor silkscreen and added pin 1 indecator
- Loading branch information
1 parent
8c58517
commit 8c44fd0
Showing
5 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
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(), | ||
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<typeof sot235_def>, | ||
): { 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<typeof sot235_def>, | ||
) => { | ||
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 silkscreenPath1: PcbSilkscreenPath = { | ||
layer: "top", | ||
pcb_component_id: "", | ||
pcb_silkscreen_path_id: "silkscreen_path_1", | ||
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 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) | ||
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, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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() | ||
const svgContent = convertCircuitJsonToPcbSvg(soup) | ||
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "sot235") | ||
}) |