Skip to content

Commit

Permalink
Implemented sot235 (sot23-5) footprint with testing (#78)
Browse files Browse the repository at this point in the history
* Implemented sot235 (sot23-5) footprint with testing

* formated

* Bun format

* Refactor silkscreen and added pin 1 indecator
  • Loading branch information
anas-sarkez authored Nov 8, 2024
1 parent 8c58517 commit 8c44fd0
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/fn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export { pushbutton } from "./pushbutton"
export { stampboard } from "./stampboard"
export { stampreceiver } from "./stampreceiver"
export { lqfp } from "./lqfp"
export { sot235 } from "./sot235"
136 changes: 136 additions & 0 deletions src/fn/sot235.ts
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,
]
}
1 change: 1 addition & 0 deletions src/footprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions tests/__snapshots__/sot235.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions tests/sot235.test.ts
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")
})

0 comments on commit 8c44fd0

Please sign in to comment.