Skip to content

Commit

Permalink
major improvements for soic sot236 footprints
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Jun 1, 2024
1 parent a7de9fb commit dd6570a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 27 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,20 @@ industry best practices or otherwise "reasonable" defaults. In theory, upgrading
footprinter could cause the defaults to change, which is why sloppy definitions
are generally not desirable.

## Adding new footprint functions
An example of a sloppy definition is `bga64`. It's very underconstrained and
unlikely to be correct (what's the pitch? pad size?). tscircuit strict mode
or a linter will eventually error if it sees these.

## Adding a new footprint function

You can add new footprint functions by introducing a new function in the [src/fn](https://github.com/tscircuit/footprinter/tree/main/src/fn)
directory. You'll also need to export it from the [footprint function index file](https://github.com/tscircuit/footprinter/blob/main/src/fn/index.ts)
You can add new footprint functions by introducing a new function in the [src/fn directory](https://github.com/tscircuit/footprinter/tree/main/src/fn). You'll also need to export it from the [footprint function index file](https://github.com/tscircuit/footprinter/blob/main/src/fn/index.ts)

After you've written the function, you can introduce a quick test, e.g. [soic.test.ts](https://github.com/tscircuit/footprinter/blob/main/tests/soic.test.ts)
Currently it's not possible to see if a given definition is sloppy.

An example of a sloppy definition is `bga64`. It's very underconstrained and
unlikely to be correct (what's the pitch? pad size?). tscircuit strict mode
or a linter will eventually error if it sees these.
To run tests, just run `npx ava ./tests/soic.test.ts` or whatever your test
file is.

You'll sometimes see this `logSoup` function- this makes some debug output
appear at https://debug.tscircuit.com. Make sure to hit "pcb" and "pcb_renderer"
after the design.
52 changes: 33 additions & 19 deletions src/fn/soic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ import type { NowDefined } from "../helpers/zod/now-defined"
import { u_curve } from "../helpers/u-curve"
import { rectpad } from "src/helpers/rectpad"

export const extendSoicDef = (newDefaults: { w?: string; p?: string }) =>
export const extendSoicDef = (newDefaults: {
w?: string
p?: string
legsoutside?: boolean
}) =>
z
.object({
soic: z.literal(true),
num_pins: z.number(),
w: length.default(length.parse(newDefaults.w ?? "5.3mm")),
p: length.default(length.parse(newDefaults.p ?? "1.27mm")),
pw: length.optional(),
pl: length.optional(),
legsoutside: z
.boolean()
.optional()
.default(newDefaults.legsoutside ?? false),
})
.transform((v) => {
// Default inner diameter and outer diameter
Expand All @@ -33,14 +40,17 @@ export const extendSoicDef = (newDefaults: { w?: string; p?: string }) =>
const soic_def = extendSoicDef({})
export type SoicInput = z.infer<typeof soic_def>

export const getCcwSoicCoords = (
pinCount: number,
pn: number,
w: number,
export const getCcwSoicCoords = (params: {
num_pins: number
pn: number
w: number
p: number
) => {
pl: number
legsoutside: boolean
}) => {
const { num_pins, pn, w, p, pl, legsoutside } = params
/** pin height */
const ph = pinCount / 2
const ph = num_pins / 2
const isLeft = pn <= ph

/** Number of gaps between pins on each side, e.g. 4 pins = 3 spaces */
Expand All @@ -51,13 +61,15 @@ export const getCcwSoicCoords = (

const h = gs * leftPinGaps

const legoffset = legsoutside ? pl / 2 : -pl / 2

if (isLeft) {
// The y position starts at h/2, then goes down by gap size
// for each pin
return { x: -w / 2, y: h / 2 - (pn - 1) * gs }
return { x: -w / 2 - legoffset, y: h / 2 - (pn - 1) * gs }
} else {
// The y position starts at -h/2, then goes up by gap size
return { x: w / 2, y: -h / 2 + (pn - ph - 1) * gs }
return { x: w / 2 + legoffset, y: -h / 2 + (pn - ph - 1) * gs }
}
}

Expand All @@ -78,18 +90,20 @@ export const soic = (raw_params: {
export const soicWithoutParsing = (params: z.infer<typeof soic_def>) => {
const pads: AnySoupElement[] = []
for (let i = 0; i < params.num_pins; i++) {
const { x, y } = getCcwSoicCoords(
params.num_pins,
i + 1,
params.w,
params.p ?? 1.27
)
pads.push(rectpad(i + 1, x, y, params.pw ?? "0.6mm", params.pl ?? "1mm"))
const { x, y } = getCcwSoicCoords({
num_pins: params.num_pins,
pn: i + 1,
w: params.w,
p: params.p ?? 1.27,
pl: params.pl,
legsoutside: params.legsoutside,
})
pads.push(rectpad(i + 1, x, y, params.pl ?? "1mm", params.pw ?? "0.6mm"))
}

/** silkscreen width */
const sw = params.w - params.pw - 0.4
const sh = (params.num_pins / 2 - 1) * params.p + params.pl + 0.4
const sw = params.w - (params.legsoutside ? 0 : params.pl * 2) - 0.2
const sh = (params.num_pins / 2 - 1) * params.p + params.pw
const silkscreenBorder: PcbSilkscreenPath = {
layer: "top",
pcb_component_id: "",
Expand Down
3 changes: 2 additions & 1 deletion src/fn/sot236.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import type { z } from "zod"
export const sot236_def = extendSoicDef({
p: "0.95mm",
w: "1.6mm",
legsoutside: true,
})

export const sot236 = (params: z.input<typeof sot236_def>) => {
return soicWithoutParsing(sot236_def.parse(params))
return soicWithoutParsing(sot236_def.parse({ ...params, num_pins: 6 }))
}
2 changes: 1 addition & 1 deletion tests/soic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ test("soic8_w5.3mm_p1.27mm", async (t) => {
const { fp, logSoup } = await getTestFixture(t)
const soup = fp.string("soic8_w5.3mm_p1.27mm").soup()

t.is(su(soup).pcb_plated_hole.list().length, 8)
t.is(su(soup).pcb_smtpad.list().length, 8)
await logSoup(soup)
})
11 changes: 11 additions & 0 deletions tests/sot236.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import test from "ava"
import { getTestFixture } from "tests/fixtures/get-test-fixture"
import { su } from "@tscircuit/soup-util"

test("sot236", async (t) => {
const { fp, logSoup } = await getTestFixture(t)
const soup = fp.string("sot236").soup()

await logSoup(soup)
t.pass()
})

0 comments on commit dd6570a

Please sign in to comment.