Skip to content

Commit

Permalink
wip- expand pad definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Jun 4, 2024
1 parent 542e099 commit afddfd2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# @tscircuit/kicad-mod-converter

This module converts kicad files into a [tscircuit soup json](https://docs.tscircuit.com/quickstart), an easy-to-use JSON format for electronics.

You should read about the [kicad sexpr syntax](https://dev-docs.kicad.org/en/file-formats/sexpr-intro/) to understand how to read the footprint files.
29 changes: 27 additions & 2 deletions src/kicad-zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,40 @@ export const property_def = z.object({

export const pad_def = z.object({
name: z.string(),
pad_type: z.literal("smd"),
pad_shape: z.enum(["roundrect", "circle", "rect"]),
pad_type: z.enum(["thru_hole", "smd", "np_thru_hole", "connect"]),
pad_shape: z.enum([
"roundrect",
"circle",
"rect",
"oval",
"trapezoid",
"custom",
]),
at: point,
size: point2,
layers: z.array(z.string()).optional(),
roundrect_rratio: z.number().optional(),
chamfer_ratio: z.number().optional(),
solder_paste_margin: z.number().optional(),
solder_paste_margin_ratio: z.number().optional(),
clearance: z.number().optional(),
zone_connection: z.union([
z.literal("0").describe("Pad is not connect to zone"),
z.literal("1").describe("Pad is connected to zone using thermal relief"),
z.literal("2").describe("Pad is connected to zone using solid fill"),
]),
thermal_width: z.number().optional(),
thermal_gap: z.number().optional(),
uuid: z.string().optional(),
})

export const drill_def = z.object({
oval: z.boolean().default(false),
diameter: z.number(),
width: z.number().optional(),
offset: point2.optional(),
})

export const effects_def = z
.object({
font: z.object({
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/kicad-file-paths.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const kicadFilePaths = [
"Reverb_BTDR-1H.kicad_mod",
"Balun_Johanson_1.6x0.8mm.kicad_mod",
"Balun_Johanson_0900PC15J0013.kicad_mod",
"Anaren_0805_2012Metric-6.kicad_mod",
Expand Down
13 changes: 13 additions & 0 deletions tests/kicad-file-tests/reverb.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import test from "ava"
import { parseKicadModToTscircuitSoup } from "src"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

test("Reverb_BTDR-1H.kicad_mod", async (t) => {
const fixture = await getTestFixture(t)
const fileContent = fixture.getKicadFile("Reverb_BTDR-1H.kicad_mod")

const soup = await parseKicadModToTscircuitSoup(fileContent)

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

0 comments on commit afddfd2

Please sign in to comment.