Skip to content
Open
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
72 changes: 54 additions & 18 deletions src/fn/stampboard.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import {
length,
type AnyCircuitElement,
type PcbPlatedHole,
type PcbSilkscreenPath,
type PcbSilkscreenText,
length,
} from "circuit-json"
import { platedhole } from "src/helpers/platedhole"
import { type SilkscreenRef, silkscreenRef } from "src/helpers/silkscreenRef"
import { z } from "zod"
import { rectpad } from "../helpers/rectpad"
import { platedhole } from "src/helpers/platedhole"
import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef"
import { base_def } from "../helpers/zod/base_def"
import { dim2d } from "../helpers/zod/dim-2d"

export const stampboard_def = base_def.extend({
fn: z.string(),
Expand All @@ -22,26 +23,40 @@ export const stampboard_def = base_def.extend({
p: length.default(length.parse("2.54mm")),
pw: length.default(length.parse("1.6mm")),
pl: length.default(length.parse("2.4mm")),
leftrowoffsety: length
.default(0)
.describe("left pad row y offset from its default placement"),
rightrowoffsety: length
.default(0)
.describe("right pad row y offset from its default placement"),
innergrid: dim2d.optional().describe("inner SMT pad columns by rows"),
innerp: length.default("1mm").describe("inner SMT pad pitch"),
innerpw: length.default("1mm").describe("inner SMT pad width"),
innerph: length.default("1mm").describe("inner SMT pad height"),
innergridoffsetx: length
.default(0)
.describe("inner SMT pad grid x offset from the footprint origin"),
innergridoffsety: length
.default(0)
.describe("inner SMT pad grid y offset from the footprint origin"),
innerhole: z.boolean().default(false),
innerholeedgedistance: length.default(length.parse("1.61mm")),
silkscreenlabels: z.boolean().default(false),
silkscreenlabelmargin: length.default(length.parse("0.1mm")),
})

export type Stampboard_def = z.input<typeof stampboard_def>
type StampboardParams = z.output<typeof stampboard_def>

const getHeight = (parameters: Stampboard_def) => {
const params = stampboard_def.parse(parameters)
if (params.left && params.right) {
return Math.max(params.left, params.right) * params.p
}
if (params.left) {
return params.left * params.p
}
if (params.right) {
return params.right * params.p
}
return 51 // Default height if no pins are provided
const getHeight = (params: StampboardParams) => {
const leftHalfHeight = params.left
? Math.abs(params.leftrowoffsety) + (params.left * params.p) / 2
: 0
const rightHalfHeight = params.right
? Math.abs(params.rightrowoffsety) + (params.right * params.p) / 2
: 0
const halfHeight = Math.max(leftHalfHeight, rightHalfHeight)
return halfHeight > 0 ? halfHeight * 2 : 51
}
const getTriangleDir = (x: number, y: number, side: string) => {
let routes: { x: number; y: number }[] = []
Expand Down Expand Up @@ -141,12 +156,16 @@ export const stampboard = (
let routes: { x: number; y: number }[] = []
const innerDiameter = 1
const outerDiameter = innerDiameter
const totalPadsNumber =
const perimeterPadCount =
params.left + params.right + (params.bottom ?? 0) + (params.top ?? 0)
const innerPadCount = params.innergrid
? params.innergrid.x * params.innergrid.y
: 0
const totalPadsNumber = perimeterPadCount + innerPadCount
const maxLabelLength = `pin${totalPadsNumber}`.length
const textHalf = (maxLabelLength * 0.7) / 2
if (params.right) {
const yoff = -((params.right - 1) / 2) * params.p
const yoff = -((params.right - 1) / 2) * params.p + params.rightrowoffsety
for (let i = 0; i < params.right; i++) {
if (
i === 0 &&
Expand Down Expand Up @@ -213,7 +232,7 @@ export const stampboard = (
}
}
if (params.left) {
const yoff = ((params.left - 1) / 2) * params.p
const yoff = ((params.left - 1) / 2) * params.p + params.leftrowoffsety
for (let i = 0; i < params.left; i++) {
if (i === 0 && !params.silkscreenlabels) {
routes = getTriangleDir(
Expand Down Expand Up @@ -417,6 +436,23 @@ export const stampboard = (
}
}
}
if (params.innergrid) {
const { x: columns, y: rows } = params.innergrid
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
rectpads.push(
rectpad(
perimeterPadCount + row * columns + column + 1,
params.innergridoffsetx +
(column - (columns - 1) / 2) * params.innerp,
params.innergridoffsety + (row - (rows - 1) / 2) * params.innerp,
params.innerpw,
params.innerph,
),
)
}
}
}

const silkscreenTriangle: PcbSilkscreenPath = {
type: "pcb_silkscreen_path",
Expand Down
8 changes: 8 additions & 0 deletions src/footprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,14 @@ export type Footprinter = {
| "p"
| "pw"
| "pl"
| "leftrowoffsety"
| "rightrowoffsety"
| "innergrid"
| "innerp"
| "innerpw"
| "innerph"
| "innergridoffsetx"
| "innergridoffsety"
| "innerhole"
| "innerholeedgedistance"
| "silkscreenlabels"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading