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
46 changes: 30 additions & 16 deletions src/fn/breakoutheaders.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
import {
length,
type AnyCircuitElement,
type PcbPlatedHole,
type PcbSilkscreenPath,
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 { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef"
import { platedhole } from "src/helpers/platedhole"
import { base_def } from "../helpers/zod/base_def"

export const breakoutheaders_def = base_def.extend({
fn: z.string(),
w: length.default("10mm"),
h: length.optional(),
left: length.optional().default(20),
right: length.optional().default(20),
top: length.optional().default(0),
bottom: length.optional().default(0),
p: length.default(length.parse("2.54mm")),
id: length.optional().default(length.parse("1mm")),
od: length.optional().default(length.parse("1.5mm")),
})
export const breakoutheaders_def = base_def
.extend({
fn: z.string(),
w: length.default("10mm"),
h: length.optional(),
left: z.coerce.number().int().nonnegative().default(20),
right: z.coerce.number().int().nonnegative().default(20),
top: z.coerce.number().int().nonnegative().default(0),
bottom: z.coerce.number().int().nonnegative().default(0),
p: length.default(length.parse("2.54mm")),
id: length.optional().default(length.parse("1mm")),
od: length.optional().default(length.parse("1.5mm")),
})
.refine(
(data) => {
const left = data.left ?? 0
const right = data.right ?? 0
const top = data.top ?? 0
const bottom = data.bottom ?? 0
return left + right + top + bottom > 0
},
{
message:
"At least one of left, right, top, or bottom pins must be greater than 0",
},
)

export type breakoutheaders_def = z.input<typeof breakoutheaders_def>

Expand Down Expand Up @@ -119,7 +133,7 @@ export const breakoutheaders = (
if (params.left) {
const yoff = -((params.left - 1) / 2) * params.p
for (let i = 0; i < params.left; i++) {
if (i === params.left - 1) {
if (i === 0) {
silkscreenTriangleRoutes = getTrianglePath(
-params.w / 2 - outerDiameter * 1.4,
yoff + i * params.p,
Expand Down
33 changes: 11 additions & 22 deletions src/fn/dip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,19 @@ import type {
PcbFabricationNoteText,
PcbSilkscreenPath,
} from "circuit-json"
import { length } from "circuit-json"
import { type SilkscreenRef, silkscreenRef } from "src/helpers/silkscreenRef"
import { base_def } from "../helpers/zod/base_def"

import { z } from "zod"
import { platedhole } from "../helpers/platedhole"
import { platedHoleWithRectPad } from "../helpers/platedHoleWithRectPad"
import { platedhole } from "../helpers/platedhole"

import { createRectUnionOutline } from "src/helpers/rect-union-outline"
import { u_curve } from "../helpers/u-curve"
import type { NowDefined } from "../helpers/zod/now-defined"
import { createRectUnionOutline } from "src/helpers/rect-union-outline"

function convertMilToMm(value: string | number): number {
if (typeof value === "string") {
if (value.trim().toLowerCase().endsWith("mil")) {
return parseFloat(value) * 0.0254
}
return parseFloat(value)
}
return Number(value)
}

const lengthInMm = z
.union([z.string(), z.number()])
.transform((val) => convertMilToMm(val))
const lengthInMm = length

export const extendDipDef = (newDefaults: { w?: string; p?: string }) =>
base_def
Expand All @@ -49,11 +38,11 @@ export const extendDipDef = (newDefaults: { w?: string; p?: string }) =>
.transform((v) => {
if (!v.id && !v.od) {
if (Math.abs(v.p - 1.27) < 0.01) {
v.id = convertMilToMm("0.55mm")
v.od = convertMilToMm("0.95mm")
v.id = length.parse("0.55mm")
v.od = length.parse("0.95mm")
} else {
v.id = convertMilToMm("0.8mm")
v.od = convertMilToMm("1.6mm")
v.id = length.parse("0.8mm")
v.od = length.parse("1.6mm")
}
} else if (!v.id) {
v.id = v.od! * (1.0 / 1.5)
Expand All @@ -63,11 +52,11 @@ export const extendDipDef = (newDefaults: { w?: string; p?: string }) =>

if (!v.w) {
if (v.wide) {
v.w = convertMilToMm("600mil")
v.w = length.parse("600mil")
} else if (v.narrow) {
v.w = convertMilToMm("300mil")
v.w = length.parse("300mil")
} else {
v.w = convertMilToMm(newDefaults.w ?? "300mil")
v.w = length.parse(newDefaults.w ?? "300mil")
}
}
return v as NowDefined<typeof v, "w" | "p" | "id" | "od">
Expand Down
15 changes: 5 additions & 10 deletions src/fn/mountedpcbmodule.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type AnyCircuitElement, length } from "circuit-json"
import { determinePinlabelAnchorSide } from "src/helpers/determine-pin-label-anchor-side"
import { silkscreenPin } from "src/helpers/silkscreenPin"
import { type SilkscreenRef, silkscreenRef } from "src/helpers/silkscreenRef"

import { z } from "zod"
import { platedHoleWithRectPad } from "../helpers/platedHoleWithRectPad"
import { platedhole } from "../helpers/platedhole"
Expand Down Expand Up @@ -512,7 +512,8 @@ export const mountedpcbmodule = (

// Add mounting holes
if (holes) {
for (const pos of holes) {
const holesArray = Array.isArray(holes) ? holes : [holes]
holesArray.forEach((pos, i) => {
let hx = 0
let hy = 0
if (pos === "topleft") {
Expand All @@ -534,10 +535,8 @@ export const mountedpcbmodule = (
// If hole_x_dist/hole_y_dist provided, use as offsets
if (holeXDist !== undefined) hx += holeXDist
if (holeYDist !== undefined) hy += holeYDist
elements.push(
platedhole(numPins + holes.indexOf(pos) + 1, hx, hy, id, od),
)
}
elements.push(platedhole(numPins + i + 1, hx, hy, id, od))
})
}

// Add silkscreen outline
Expand All @@ -552,10 +551,6 @@ export const mountedpcbmodule = (
elements.push(silkscreenpath(outline, { stroke_width: 0.1, layer: "top" }))
}

// Add silkscreen reference text
const refText: SilkscreenRef = silkscreenRef(0, height / 2 + 1, 0.5)
elements.push(refText)

// Add USB silkscreen rectangle if USB is configured
if (usbposition && usbtype) {
let usbRectWidth: number
Expand Down
6 changes: 3 additions & 3 deletions src/fn/potentiometer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { string, z } from "zod"
import { platedhole } from "src/helpers/platedhole"
import type {
AnyCircuitElement,
PcbCourtyardRect,
PcbSilkscreenPath,
} from "circuit-json"
import { silkscreenRef, type SilkscreenRef } from "../helpers/silkscreenRef"
import { platedhole } from "src/helpers/platedhole"
import { z } from "zod"
import { type SilkscreenRef, silkscreenRef } from "../helpers/silkscreenRef"
import { base_def } from "../helpers/zod/base_def"

export const potentiometer_def = base_def.extend({
Expand Down
22 changes: 11 additions & 11 deletions src/fn/quad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import type {
PcbCourtyardOutline,
PcbSilkscreenPath,
} from "circuit-json"
import { optional, z } from "zod"
import { length } from "circuit-json"
import type { NowDefined } from "../helpers/zod/now-defined"
import { rectpad } from "../helpers/rectpad"
import { pin_order_specifier } from "src/helpers/zod/pin-order-specifier"
import { getQuadPinMap } from "src/helpers/get-quad-pin-map"
import { dim2d } from "src/helpers/zod/dim-2d"
import { createRectUnionOutline } from "src/helpers/rect-union-outline"
import { type SilkscreenRef, silkscreenRef } from "src/helpers/silkscreenRef"
import { dim2d } from "src/helpers/zod/dim-2d"
import { pin_order_specifier } from "src/helpers/zod/pin-order-specifier"
import { optional, z } from "zod"
import { rectpad } from "../helpers/rectpad"
import { base_def } from "../helpers/zod/base_def"
import { createRectUnionOutline } from "src/helpers/rect-union-outline"
import type { NowDefined } from "../helpers/zod/now-defined"

export const base_quad_def = base_def.extend({
fn: z.string(),
Expand Down Expand Up @@ -102,13 +102,13 @@ export const getQuadCoords = (params: {

switch (side) {
case "left":
return { x: -w / 2 - pcdfe + 0.1, y: ibh / 2 - pos * p, o: "vert" }
return { x: -w / 2 - pcdfe, y: ibh / 2 - pos * p, o: "vert" }
case "bottom":
return { x: -ibw / 2 + pos * p, y: -h / 2 - pcdfe + 0.1, o: "horz" }
return { x: -ibw / 2 + pos * p, y: -h / 2 - pcdfe, o: "horz" }
case "right":
return { x: w / 2 + pcdfe - 0.1, y: -ibh / 2 + pos * p, o: "vert" }
return { x: w / 2 + pcdfe, y: -ibh / 2 + pos * p, o: "vert" }
case "top":
return { x: ibw / 2 - pos * p, y: h / 2 + pcdfe - 0.1, o: "horz" }
return { x: ibw / 2 - pos * p, y: h / 2 + pcdfe, o: "horz" }
default:
throw new Error("Invalid pin number")
}
Expand Down Expand Up @@ -263,7 +263,7 @@ export const quad = (
},
],
type: "pcb_silkscreen_path",
stroke_width: 0,
stroke_width: 0.1,
},
{
layer: "top",
Expand Down
26 changes: 19 additions & 7 deletions src/fn/sot457.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import type {
PcbCourtyardRect,
PcbSilkscreenPath,
} from "circuit-json"
import { createRectUnionOutline } from "src/helpers/rect-union-outline"
import { base_def } from "src/helpers/zod/base_def"
import { z } from "zod"
import { rectpad } from "../helpers/rectpad"
import { pillpad } from "../helpers/pillpad"
import { silkscreenRef, type SilkscreenRef } from "../helpers/silkscreenRef"
import { base_def } from "src/helpers/zod/base_def"
import { createRectUnionOutline } from "src/helpers/rect-union-outline"
import { rectpad } from "../helpers/rectpad"
import { type SilkscreenRef, silkscreenRef } from "../helpers/silkscreenRef"

// Common schema properties for both SOT-457 configurations
const commonSchema = {
Expand Down Expand Up @@ -65,12 +65,14 @@ const getCcwSot457Coords = ({
pitch,
width,
pinNumber,
padLength = 0.8,
}: {
pitch: number
width: number
pinNumber: number
padLength?: number
}): { x: number; y: number } => {
const offset = 0.1
const offset = padLength / 2 - 0.3
const coords: Record<number, { x: number; y: number }> = {
1: { x: -width / 2 - offset, y: pitch },
2: { x: -width / 2 - offset, y: 0 },
Expand Down Expand Up @@ -137,7 +139,12 @@ const generateSot457Elements = (
}
} else {
for (let i = 1; i <= params.num_pins; i++) {
const { x, y } = getCcwSot457Coords({ pitch, width, pinNumber: i })
const { x, y } = getCcwSot457Coords({
pitch,
width,
pinNumber: i,
padLength,
})
pads.push(rectpad(i, x, y, padLength, padWidth))
}
}
Expand Down Expand Up @@ -171,7 +178,12 @@ const generateSot457Elements = (
const silkscreenRefText: SilkscreenRef = silkscreenRef(0, height + 0.5, 0.3)

// Pin 1 indicator triangle
const pin1Position = getCcwSot457Coords({ pitch, width, pinNumber: 1 })
const pin1Position = getCcwSot457Coords({
pitch,
width,
pinNumber: 1,
padLength,
})
const triangleHeight = params.wave ? 1 : 0.5
const triangleWidth = params.wave ? 0.7 : 0.3
pin1Position.x -= params.wave ? padWidth : padWidth * 1.7
Expand Down
38 changes: 33 additions & 5 deletions src/fn/stampboard.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {
length,
type AnyCircuitElement,
type PcbCourtyardOutline,
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"

export const stampboard_def = base_def.extend({
Expand Down Expand Up @@ -140,7 +141,7 @@ export const stampboard = (
const pinLabels: PcbSilkscreenText[] = []
let routes: { x: number; y: number }[] = []
const innerDiameter = 1
const outerDiameter = innerDiameter
const outerDiameter = 1.5
const totalPadsNumber =
params.left + params.right + (params.bottom ?? 0) + (params.top ?? 0)
const maxLabelLength = `pin${totalPadsNumber}`.length
Expand Down Expand Up @@ -452,8 +453,35 @@ export const stampboard = (
...holes,
...pinLabels,
silkscreenPath,
...(params.silkscreenlabels ? [] : [silkscreenTriangle]),
...(params.silkscreenlabels || routes.length === 0
? []
: [silkscreenTriangle]),
silkscreenRefText,
{
type: "pcb_courtyard_outline",
pcb_courtyard_outline_id: "pcb_courtyard_outline_1",
pcb_component_id: "1",
layer: "top",
outline: [
{
x: -params.w / 2 - outerDiameter / 2,
y: height / 2 + params.p / 2,
},
{ x: params.w / 2 + outerDiameter / 2, y: height / 2 + params.p / 2 },
{
x: params.w / 2 + outerDiameter / 2,
y: -height / 2 - params.p / 2,
},
{
x: -params.w / 2 - outerDiameter / 2,
y: -height / 2 - params.p / 2,
},
{
x: -params.w / 2 - outerDiameter / 2,
y: height / 2 + params.p / 2,
},
],
} as PcbCourtyardOutline,
],
parameters: params,
}
Expand Down
Loading
Loading