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.
tools/routeviz.ts
// Picture of a board region from the router's files: bun tools/routeviz.ts x0 y0 x1 y1 out.png [--fr file] [--routed file] [--hl NET,NET] [--labels] [--w 1800]
// Top copper red, bottom copper blue, highlighted nets in their own colours, pads grey (labelled with their net with --labels).
import { Resvg } from "@resvg/resvg-js"
import { readFileSync, writeFileSync } from "node:fs"
const a = process.argv.slice(2); const [x0, y0, x1, y1] = a.slice(0, 4).map(Number); const out = a[4]
const opt = (k: string, d?: string) => { const i = a.indexOf(k); return i >= 0 ? a[i + 1] : d }
const fr = readFileSync(opt("--fr", "routing/inputs/ALL.fr.txt")!, "utf8").split("\n")
const routed = JSON.parse(readFileSync(opt("--routed", "routing/ALL.routed.json")!, "utf8"))
const hl = (opt("--hl", "") || "").split(",").filter(Boolean); const W = Number(opt("--w", "1800")); const labels = a.includes("--labels")
const only = (opt("--layers", "top,bottom") || "").split(",")
const s = W / (x1 - x0), H = Math.round((y1 - y0) * s)
const X = (x: number) => ((x - x0) * s).toFixed(1), Y = (y: number) => ((y1 - y)* s).toFixed(1)
const names: Record<number, string> = {}; const pads: any[] = []
for (const l of fr) { const t = l.split(" "); if (t[0] === "N") names[+t[1]] = t[2]; if (t[0] === "PAD") pads.push({ net: +t[1], mask: +t[2], x: +t[3], y: +t[4], w: +t[5], h: +t[6], kind: +t[7], circle: +t[8] }) }
const palette = ["#ffd400", "#00e5ff", "#7CFC00", "#ff66ff", "#ff9900", "#ffffff", "#66ffcc", "#c0a0ff", "#ff5555", "#aaff00", "#00aaff", "#ffaa88"]
const col = (net: string, layer: string) => { const i = hl.indexOf(net); return i >= 0 ? palette[i % palette.length] : layer === "top" ? "#b03030" : "#3050c0" }
const ins = (x: number, y: number) => x >= x0 - 1 && x <= x1 + 1 && y >= y0 - 1 && y <= y1 + 1
let svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}"><rect width="100%" height="100%" fill="#000"/>`
// grid every 1 mm (faint), 5 mm (stronger) with numbers
for (let gx = Math.ceil(x0); gx <= x1; gx++) svg += `<line x1="${X(gx)}" y1="0" x2="${X(gx)}" y2="${H}" stroke="${gx % 5 === 0 ? "#333" : "#161616"}" stroke-width="1"/>` + (gx % 5 === 0 ? `<text x="${X(gx)}" y="12" fill="#888" font-size="12">${gx}</text>` : "")
for (let gy = Math.ceil(y0); gy <= y1; gy++) svg += `<line x1="0" y1="${Y(gy)}" x2="${W}" y2="${Y(gy)}" stroke="${gy % 5 === 0 ? "#333" : "#161616"}" stroke-width="1"/>` + (gy % 5 === 0 ? `<text x="2" y="${Y(gy)}" fill="#888" font-size="12">${gy}</text>` : "")
const order = ["bottom", "top"]
for (const layer of order) { if (!only.includes(layer)) continue
for (const pass of [0, 1]) for (const r of routed) { const isHl = hl.includes(r.net); if ((pass === 1) !== isHl) continue
const pts = r.route
for (let k = 1; k < pts.length; k++) { const p = pts[k - 1], q = pts[k]
if (p.route_type !== "wire" || q.route_type !== "wire" || p.layer !== layer || q.layer !== layer) continue
if (!ins(p.x, p.y) && !ins(q.x, q.y)) continue
svg += `<line x1="${X(p.x)}" y1="${Y(p.y)}" x2="${X(q.x)}" y2="${Y(q.y)}" stroke="${col(r.net, layer)}" stroke-width="${(Math.max(p.width, q.width) * s).toFixed(1)}" stroke-linecap="round" opacity="${layer === "top" ? 0.9 : 0.75}"/>` } } }
for (const p of pads) { if (!ins(p.x, p.y)) continue
const top = p.mask & 1, bot = p.mask & 8; if (!(top && only.includes("top")) && !(bot && only.includes("bottom"))) continue
const f = p.kind === 1 ? "#553300" : p.kind === 2 ? "#aa00aa" : top ? "#999" : "#446"
svg += p.circle || p.kind === 2 ? `<circle cx="${X(p.x)}" cy="${Y(p.y)}" r="${(p.w / 2 * s).toFixed(1)}" fill="${f}" opacity="0.8"/>` : `<rect x="${X(p.x - p.w / 2)}" y="${Y(p.y + p.h / 2)}" width="${(p.w * s).toFixed(1)}" height="${(p.h * s).toFixed(1)}" fill="${f}" opacity="0.8"/>`
if (labels && p.net >= 0 && p.kind === 0) svg += `<text x="${X(p.x)}" y="${Y(p.y)}" fill="#fff" font-size="${Math.max(7, Math.min(11, s * 0.28)).toFixed(0)}" text-anchor="middle">${names[p.net]}</text>` }
for (const r of routed) for (const p of r.route) if (p.route_type === "via" && ins(p.x, p.y)) svg += `<circle cx="${X(p.x)}" cy="${Y(p.y)}" r="${(0.225 * s).toFixed(1)}" fill="${hl.includes(r.net) ? col(r.net, "top") : "#d0d"}" stroke="#000" stroke-width="1"/>`
hl.forEach((n, i) => { svg += `<text x="${W - 190}" y="${20 + 16 * i}" fill="${palette[i % palette.length]}" font-size="14">${n}</text>` })
svg += "</svg>"
writeFileSync(out, new Resvg(svg).render().asPng())