Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented VSSOP-8-0.65mm #184

Merged
merged 18 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/fn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ export { micromelf } from "./micromelf"
export { sma } from "./sma"
export { smf } from "./smf"
export { smb } from "./smb"
export { vssop8 } from "./vssop8"
export { smc } from "./smc"
131 changes: 131 additions & 0 deletions src/fn/vssop8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import type {
AnySoupElement,
PcbFabricationNoteText,
PcbSilkscreenPath,
} from "circuit-json"
import { z } from "zod"
import { rectpad } from "../helpers/rectpad"
import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef"
import { length } from "circuit-json"

export const vssop8_def = z.object({
fn: z.string(),
num_pins: z.literal(8).default(8),
w: z.string().default("3.06mm"),
h: z.string().default("3.14mm"),
p: z.string().default("0.65mm"),
pl: z.string().default("1.6mm"),
pw: z.string().default("0.5mm"),
})

export const vssop8 = (
raw_params: z.input<typeof vssop8_def>,
): { circuitJson: AnySoupElement[]; parameters: any } => {
const parameters = vssop8_def.parse(raw_params)

const pad_spacing = length.parse(parameters.p)

const silkscreenRefText: SilkscreenRef = silkscreenRef(
0,
length.parse(parameters.h) / 2 + 0.5,
0.3,
)

const silkscreenBoxWidth = length.parse(parameters.w)
const silkscreenBoxHeight = length.parse(parameters.h)

const silkscreenTopLine: PcbSilkscreenPath = {
type: "pcb_silkscreen_path",
layer: "top",
pcb_component_id: "",
route: [
{ x: -silkscreenBoxWidth / 2, y: silkscreenBoxHeight / 2 },
{ x: silkscreenBoxWidth / 2, y: silkscreenBoxHeight / 2 },
],
stroke_width: 0.05,
pcb_silkscreen_path_id: "",
}

const silkscreenBottomLine: PcbSilkscreenPath = {
type: "pcb_silkscreen_path",
layer: "top",
pcb_component_id: "",
route: [
{ x: -silkscreenBoxWidth / 2, y: -silkscreenBoxHeight / 2 },
{ x: silkscreenBoxWidth / 2, y: -silkscreenBoxHeight / 2 },
],
stroke_width: 0.05,
pcb_silkscreen_path_id: "",
}

const pin1Position = getVssop8PadCoord({ pn: 1, pad_spacing })
const pin1MarkerPosition = {
x: pin1Position.x - 0.8,
y: pin1Position.y,
}
const pin1Marking: PcbSilkscreenPath = {
type: "pcb_silkscreen_path",
layer: "top",
pcb_component_id: "pin_marker_1",
route: [
{ x: pin1MarkerPosition.x - 0.4, y: pin1MarkerPosition.y },
{ x: pin1MarkerPosition.x - 0.7, y: pin1MarkerPosition.y + 0.3 },
{ x: pin1MarkerPosition.x - 0.7, y: pin1MarkerPosition.y - 0.3 },
{ x: pin1MarkerPosition.x - 0.4, y: pin1MarkerPosition.y },
],
stroke_width: 0.05,
pcb_silkscreen_path_id: "pin_marker_1",
}

return {
circuitJson: getVssop8Pads(parameters, pad_spacing).concat(
silkscreenTopLine as AnySoupElement,
silkscreenBottomLine as AnySoupElement,
silkscreenRefText as AnySoupElement,
pin1Marking as AnySoupElement,
),
parameters,
}
}

// Get coordinates for VSSOP-8 pads
export const getVssop8PadCoord = (parameters: {
pn: number
pad_spacing: number
}) => {
const { pn, pad_spacing } = parameters

const col = pn <= 4 ? -1 : 1

const row = 1.5 - ((pn - 1) % 4)

return {
x: col * length.parse("1.8mm"),
y: row * pad_spacing,
}
}

// Generate pads for VSSOP-8
export const getVssop8Pads = (
parameters: z.infer<typeof vssop8_def>,
pad_spacing: number,
) => {
const pads: AnySoupElement[] = []

for (let i = 1; i <= parameters.num_pins; i++) {
const { x, y } = getVssop8PadCoord({
pn: i,
pad_spacing,
})
pads.push(
rectpad(
i,
x,
y,
Number.parseFloat(parameters.pl),
Number.parseFloat(parameters.pw),
),
)
}
return pads
}
1 change: 1 addition & 0 deletions src/footprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export type Footprinter = {
smf: () => FootprinterParamsBuilder<"w" | "h" | "p" | "pl" | "pw">
smb: () => FootprinterParamsBuilder<"w" | "h" | "p" | "pl" | "pw">
sod923: () => FootprinterParamsBuilder<"w" | "h" | "p" | "pl" | "pw">
vssop8: () => FootprinterParamsBuilder<"w" | "h" | "p" | "pl" | "pw">
sod882: () => FootprinterParamsBuilder<"w" | "h" | "p" | "pl" | "pw">
sod882d: () => FootprinterParamsBuilder<"w" | "h" | "p" | "pl" | "pw">
sod723: () => FootprinterParamsBuilder<"w" | "h" | "p" | "pl" | "pw">
Expand Down
13 changes: 13 additions & 0 deletions tests/__snapshots__/vssop8_h4.14mm_pl1.8mm_pw0.8mm_p1mm.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions tests/__snapshots__/vssop8_p0.65mm.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions tests/__snapshots__/vssop8_p0.75mm.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions tests/__snapshots__/vssop8_w4.1mm_h4.14mm_p0.65mm.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions tests/vssop8.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { test, expect } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { fp } from "../src/footprinter"

test("vssop8", () => {
const circuitJson = fp.string("vssop8_p0.65mm").circuitJson()
const svgContent = convertCircuitJsonToPcbSvg(circuitJson)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "vssop8_p0.65mm")
})

test("vssop8_w4.1mm_h4.14mm_p0.65mm", () => {
const circuitJson = fp.string("vssop8_w4.1mm_h4.14mm_p0.65mm").circuitJson()
const svgContent = convertCircuitJsonToPcbSvg(circuitJson)
expect(svgContent).toMatchSvgSnapshot(
import.meta.path,
"vssop8_w4.1mm_h4.14mm_p0.65mm",
)
})

test("vssop8_p0.75mm", () => {
const circuitJson = fp.string("vssop8_p0.75mm").circuitJson()
const svgContent = convertCircuitJsonToPcbSvg(circuitJson)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "vssop8_p0.75mm")
})

test("vssop8_h4.14mm_pl1.8mm_pw0.8mm_p1mm", () => {
const circuitJson = fp
.string("vssop8_h4.14mm_pl1.8mm_pw0.8mm_p1mm")
.circuitJson()
const svgContent = convertCircuitJsonToPcbSvg(circuitJson)
expect(svgContent).toMatchSvgSnapshot(
import.meta.path,
"vssop8_h4.14mm_pl1.8mm_pw0.8mm_p1mm",
)
})