MustafaMulla29/usb-pd-motherboard
4-layer USB-C PD hub motherboard with 20 V USB-C input, Linux T113-S3 computer, CH338F USB hub, four individually controlled 5–20 V PD outputs, USB data/camera ports, regulated rails, and hardware watchdog/E-stop safety interlock.
- Version
- 1.0.24
- License
- unset
- Stars
- 0
Use with the tscircuit CLI
tsci is the tscircuit CLI. Install it with npm install -g tscircuit.
tsci clone MustafaMulla29/usb-pd-motherboard # download the package files into ./usb-pd-motherboard
tsci add MustafaMulla29/usb-pd-motherboard # add it to your project as @tsci/MustafaMulla29.usb-pd-motherboardIn a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.
enclosure/measure-reference.ts
// Extract the few board facts the enclosure needs from the built board (../dist/index/circuit.json)
// into a small, reviewable reference-board.json. Run after every board change: bun measure-reference.ts
import { readFileSync, writeFileSync } from "node:fs"
import { createHash } from "node:crypto"
export function measure() {
const bytes = readFileSync(new URL("../dist/index/circuit.json", import.meta.url))
const cj: any[] = JSON.parse(bytes.toString())
const board = cj.find((e) => e.type === "pcb_board")
const src = new Map(cj.filter((e) => e.type === "source_component").map((e) => [e.source_component_id, e]))
const pcb = cj.filter((e) => e.type === "pcb_component")
const nameOf = (pid: string) => {
const p = pcb.find((q) => q.pcb_component_id === pid)
return p ? src.get(p.source_component_id)?.name : undefined
}
const r3 = (v: number) => Math.round(v * 1000) / 1000
const wanted = ["JPD", "JPC", "JSD", "JCAM", "JESTOP", "SWSTOP", "SWRST", "LEDSTAT", "LEDACT", "LEDHWEN",
"JOUT1", "JOUT2", "JOUT3", "JOUT4", "JUSB1", "JUSB2", "JUSB3", "JUSB4", "JUART", "JSUPASWD", "JSUPBSWD"]
const parts: Record<string, any> = {}
for (const p of pcb) {
const name = src.get(p.source_component_id)?.name
if (!wanted.includes(name)) continue
parts[name] = { x: r3(p.center.x), y: r3(p.center.y), width: r3(p.width), height: r3(p.height), rotation: p.rotation ?? 0 }
}
for (const n of wanted) if (!parts[n]) throw new Error(`Board is missing ${n}`)
const mountingHoles = cj.filter((e) => e.type === "pcb_hole" && !e.pcb_component_id && e.hole_diameter >= 3)
.map((h) => ({ x: r3(h.x), y: r3(h.y), diameter: h.hole_diameter }))
// Through-hole legs within 4.5 mm of a mounting hole stick out under the board: the standoffs get a notch there.
const tht = cj.filter((e) => e.type === "pcb_plated_hole")
const legsNearHoles = tht.filter((t) => mountingHoles.some((h) => Math.hypot(t.x - h.x, t.y - h.y) < 4.5)).map((t) => ({
part: nameOf(t.pcb_component_id), x: r3(t.x), y: r3(t.y),
radius: r3(Math.max(t.outer_width ?? t.outer_diameter ?? 1.5, t.outer_height ?? t.outer_diameter ?? 1.5) / 2),
}))
// Top-side parts within 3 mm of a mounting hole: the lid boss that clamps the board there is relieved over them.
const partsNearHoles = pcb.filter((p) => mountingHoles.some((h) => {
const dx = Math.max(Math.abs(p.center.x - h.x) - p.width / 2, 0), dy = Math.max(Math.abs(p.center.y - h.y) - p.height / 2, 0)
return Math.hypot(dx, dy) < 3.0
})).map((p) => {
const name = src.get(p.source_component_id)?.name
return { name, x: r3(p.center.x), y: r3(p.center.y), width: r3(p.width), height: r3(p.height), tall: name?.startsWith("J") ? 3.3 : 0.8 }
})
return {
source: "dist/index/circuit.json",
sha256: createHash("sha256").update(bytes).digest("hex"),
board: { width: board.width, height: board.height, thickness: board.thickness ?? 1.6, center: board.center },
mountingHoles, legsNearHoles, partsNearHoles, parts,
}
}
if (import.meta.main) {
const m = measure()
writeFileSync(new URL("reference-board.json", import.meta.url), JSON.stringify(m, null, 1) + "\n")
console.log(`reference-board.json: ${Object.keys(m.parts).length} parts, ${m.mountingHoles.length} holes, ${m.legsNearHoles.length} legs near holes`)
}