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-motherboard

In 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.

tools/power-report.ts

// Copper per power net: pour area (by layer), via count, trace copper area. bun tools/power-report.ts
import { readFileSync } from "node:fs"
import { getFullConnectivityMapFromCircuitJson } from "circuit-json-to-connectivity-map"
const cj = JSON.parse(readFileSync(process.env.CJ ?? "dist/index/circuit.json", "utf8")); const cm = getFullConnectivityMapFromCircuitJson(cj)
const nk = new Map<string, string>(); for (const n of cj.filter((e: any) => e.type === "source_net")) { const k = cm.getNetConnectedToId(n.source_net_id); if (k && !nk.has(k)) nk.set(k, n.name) }
const nameOf = (...ids: (string | undefined)[]) => { for (const id of ids) { const k = id && cm.getNetConnectedToId(id); if (k) return nk.get(k) ?? k } }
const srcName = new Map(cj.filter((e: any) => e.type === "source_net").map((n: any) => [n.source_net_id, n.name]))
const area = (pts: { x: number; y: number }[]) => Math.abs(pts.reduce((s, p, i) => { const q = pts[(i + 1) % pts.length]; return s + p.x * q.y - q.x * p.y }, 0)) / 2
const brepArea = (b: any) => area(b.outer_ring.vertices) - (b.inner_rings ?? []).reduce((s: number, r: any) => s + area(r.vertices), 0)
const row: Record<string, any> = {}
const R = (n: string) => (row[n] ??= { pourTop: 0, pourIn: 0, vias: 0, traceArea: 0 })
const re = /^(VBUS_IN|VIN_SYS|V5V0|BUCK5_SW|VDDCORE|M\d_(SW1|SW2|VBB_PRE|VBB|VBUS))$/
for (const e of cj) {
  if (e.type === "pcb_copper_pour") { const n = srcName.get(e.source_net_id) as string; if (!re.test(n)) continue; const a = e.brep_shape ? brepArea(e.brep_shape) : 0; if (e.layer === "top" || e.layer === "bottom") R(n).pourTop += a; else R(n).pourIn += a }
  if (e.type === "pcb_via") { const n = nameOf(e.pcb_trace_id, e.pcb_via_id, e.source_net_id) ?? (srcName.get(e.source_net_id) as string); if (n && re.test(n)) R(n).vias++ }
  if (e.type === "pcb_trace") { const n = nameOf(e.pcb_trace_id, e.source_trace_id); if (!n || !re.test(n)) continue
    const r = e.route; for (let i = 0; i + 1 < r.length; i++) { const a = r[i], b = r[i + 1]; if (a.route_type === "via") R(n).vias++; if (a.route_type === "wire" && b.route_type === "wire" && a.layer === b.layer) R(n).traceArea += Math.hypot(b.x - a.x, b.y - a.y) * (b.width ?? 0.1) }
    if (r.at(-1)?.route_type === "via") R(n).vias++ }
}
console.log("net".padEnd(12), "top pour mm2".padStart(13), "plane mm2".padStart(10), "vias".padStart(5), "trace mm2".padStart(10))
for (const [n, v] of Object.entries(row).sort()) console.log(n.padEnd(12), v.pourTop.toFixed(1).padStart(13), v.pourIn.toFixed(0).padStart(10), String(v.vias).padStart(5), v.traceArea.toFixed(1).padStart(10))