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.

enclosure/parts.tsx

import { jscad } from "jscad-fiber/headless"
import { body, design as d, leds, legsNearHoles, microSd, mountingHoles, openings, partsNearHoles, pdOutY, resetButton, stopButton, type Opening } from "./dimensions"

// ---------------- primitives (only operations export_solid.py can evaluate) ----------------
export function Box({ x, y, z0, z1, w, h }: { x: number; y: number; z0: number; z1: number; w: number; h: number }) {
  return <jscad.cuboid size={[w, h, z1 - z0]} center={[x, y, (z0 + z1) / 2]} />
}
/** Vertical cylinder. JSCAD's default 32 segments are used everywhere (the plan carries no segment count). */
export function Cylinder({ x, y, z0, z1, r }: { x: number; y: number; z0: number; z1: number; r: number }) {
  return <jscad.cylinder radius={r} height={z1 - z0} center={[x, y, (z0 + z1) / 2]} />
}
/** Rounded rectangle prism, vertical. */
export function RoundBox({ x, y, z0, z1, w, h, r }: { x: number; y: number; z0: number; z1: number; w: number; h: number; r: number }) {
  return <jscad.hull>{[-1, 1].flatMap((sx) => [-1, 1].map((sy) =>
    <Cylinder key={`${sx}${sy}`} x={x + sx * (w / 2 - r)} y={y + sy * (h / 2 - r)} z0={z0} z1={z1} r={r} />))}</jscad.hull>
}
/** Cylinder whose axis runs along X (from x0 to x1). */
function XCylinder({ x0, x1, y, z, r }: { x0: number; x1: number; y: number; z: number; r: number }) {
  return <jscad.translate offset={[(x0 + x1) / 2, y, z]}><jscad.rotate angles={[0, Math.PI / 2, 0]}><jscad.cylinder radius={r} height={x1 - x0} /></jscad.rotate></jscad.translate>
}
/** Cylinder whose axis runs along Y (from y0 to y1). */
function YCylinder({ y0, y1, x, z, r }: { y0: number; y1: number; x: number; z: number; r: number }) {
  return <jscad.translate offset={[x, (y0 + y1) / 2, z]}><jscad.rotate angles={[Math.PI / 2, 0, 0]}><jscad.cylinder radius={r} height={y1 - y0} /></jscad.rotate></jscad.translate>
}
/** Rounded rectangle through a wall: w along the wall, h vertical, from depth a to b across the wall. */
function WallCut({ side, at, z, w, h, r, a, b }: { side: Opening["side"]; at: number; z: number; w: number; h: number; r: number; a: number; b: number }) {
  const du = [-1, 1].map((s) => s * Math.max(w / 2 - r, 0)), dz = [-1, 1].map((s) => s * Math.max(h / 2 - r, 0))
  const corners = du.flatMap((u) => dz.map((v) => [u, v] as const))
  return <jscad.hull>{corners.map(([u, v], k) => side === "left" || side === "right"
    ? <XCylinder key={k} x0={Math.min(a, b)} x1={Math.max(a, b)} y={at + u} z={z + v} r={r} />
    : <YCylinder key={k} y0={Math.min(a, b)} y1={Math.max(a, b)} x={at + u} z={z + v} r={r} />)}</jscad.hull>
}
/** Inner and outer face coordinates of each wall (signed). */
function wallFaces(side: Opening["side"]) {
  const s = side === "right" || side === "back" ? 1 : -1
  const half = side === "left" || side === "right" ? [body.innerHalfX, body.outerHalfX] : [body.innerHalfY, body.outerHalfY]
  return { inner: s * half[0], outer: s * half[1], s }
}
function OpeningCut({ o }: { o: Opening }) {
  const { inner, outer, s } = wallFaces(o.side)
  // A knock-out keeps `skin` mm of wall on the outside: closed until cut out.
  const end = o.skin ? outer - s * o.skin : outer + s * 0.6
  return <WallCut side={o.side} at={o.at} z={o.z} w={o.width} h={o.height} r={o.radius} a={inner - s * 0.6} b={end} />
}
const Outer = ({ z0, z1 }: { z0: number; z1: number }) =>
  <RoundBox x={0} y={0} w={2 * body.outerHalfX} h={2 * body.outerHalfY} r={d.cornerRadius} z0={z0} z1={z1} />

// ---------------- base ----------------
/** Tray: floor, four walls with every port opening, four standoffs with screw holes; screw heads sit in recesses underneath. */
export function Base() {
  const st = d.standoff, sd = d.microSd, left = wallFaces("left")
  return <jscad.subtract>
    <jscad.union>
      <jscad.subtract>
        <Outer z0={d.bottom} z1={d.wallTop} />
        <RoundBox x={0} y={0} w={2 * body.innerHalfX} h={2 * body.innerHalfY} r={body.innerRadius} z0={d.floorTop} z1={d.wallTop + 1} />
      </jscad.subtract>
      {mountingHoles.map((h, k) => <Cylinder key={k} x={h.x} y={h.y} z0={d.floorTop - 0.1} z1={d.boardBottom} r={st.radius} />)}
    </jscad.union>
    {openings.map((o) => <OpeningCut key={o.name} o={o} />)}
    {/* microSD: card slot through the wall, plus a finger recess in the outer 1.2 mm around it */}
    <WallCut side="left" at={microSd.y} z={sd.slotZ} w={sd.slotWidth} h={sd.slotHeight} r={0.6} a={left.inner + 0.6} b={left.outer - 0.6} />
    <WallCut side="left" at={microSd.y} z={sd.recessZ} w={sd.recessWidth} h={sd.recessHeight} r={3.5} a={left.outer + sd.recessDepth} b={left.outer - 0.6} />
    {/* screw clearance holes up through the standoffs, head recesses in the underside; notches where a USB-C socket leg sticks out under the board */}
    {mountingHoles.map((h, k) => <Cylinder key={`clr${k}`} x={h.x} y={h.y} z0={d.bottom - 1} z1={d.boardBottom + 0.1} r={st.clearanceRadius} />)}
    {mountingHoles.map((h, k) => <Cylinder key={`head${k}`} x={h.x} y={h.y} z0={d.bottom - 1} z1={d.fixing.seat} r={st.headRadius} />)}
    {legsNearHoles.map((l, k) => <Cylinder key={`leg${k}`} x={l.x} y={l.y} z0={d.boardBottom - st.legNotchDepth} z1={d.boardBottom + 0.1} r={l.radius + st.legClearance} />)}
  </jscad.subtract>
}

// ---------------- lid ----------------
/** Lid: flat plate on the wall tops, locating lip, four insert bosses that clamp the board, light-pipe holder,
 *  reset guide. No screw holes on top and no text (labels are UV printed later). */
export function Lid() {
  const lp = d.lightPipe, ph = d.pinhole, ledY = leds.map((l) => l.y), ledMid = (Math.min(...ledY) + Math.max(...ledY)) / 2
  const guideBottom = ph.switchTop + ph.gap
  return <jscad.subtract>
    <jscad.union>
      <Outer z0={d.wallTop} z1={d.top} />
      <jscad.subtract>
        <RoundBox x={0} y={0} w={2 * body.innerHalfX - 0.3} h={2 * body.innerHalfY - 0.3} r={body.innerRadius - 0.15} z0={d.wallTop - 0.7} z1={d.wallTop + 0.01} />
        <RoundBox x={0} y={0} w={2 * body.innerHalfX - 2.5} h={2 * body.innerHalfY - 2.5} r={0.6} z0={d.wallTop - 1} z1={d.wallTop + 0.1} />
      </jscad.subtract>
      {mountingHoles.map((h, k) => <Cylinder key={`boss${k}`} x={h.x} y={h.y} z0={d.boardTop} z1={d.wallTop + 0.01} r={d.screw.bossRadius} />)}
      <RoundBox x={leds[0].x} y={ledMid} w={lp.holderWidth} h={lp.holderDepth} r={0.6} z0={lp.holderBottom} z1={d.wallTop + 0.01} />
      <Cylinder x={resetButton.x} y={resetButton.y} z0={guideBottom} z1={d.wallTop + 0.01} r={ph.guideRadius} />
    </jscad.union>
    <Cylinder x={stopButton.x} y={stopButton.y} z0={d.wallTop - 1} z1={d.top + 1} r={d.cap.lidHoleRadius} />
    {/* blind insert holes from below (entry bore, then the pilot the insert is heat-set into), and boss reliefs over nearby parts */}
    {mountingHoles.map((h, k) => <Cylinder key={`entry${k}`} x={h.x} y={h.y} z0={d.boardTop - 1} z1={d.fixing.insertBottom} r={d.screw.entryRadius} />)}
    {mountingHoles.map((h, k) => <Cylinder key={`pilot${k}`} x={h.x} y={h.y} z0={d.fixing.insertBottom - 0.01} z1={d.fixing.holeTop} r={d.screw.insertHole} />)}
    {partsNearHoles.map((p) => <Box key={`rel${p.name}`} x={p.x} y={p.y} w={p.width + 2 * d.screw.partClearance} h={p.height + 2 * d.screw.partClearance} z0={d.boardTop - 1} z1={d.boardTop + p.tall + d.screw.partClearance} />)}
    {leds.map((l, k) => <Cylinder key={`led${k}`} x={l.x} y={l.y} z0={lp.holderBottom - 1} z1={d.top + 1} r={lp.holeRadius} />)}
    <Cylinder x={resetButton.x} y={resetButton.y} z0={guideBottom - 1} z1={d.top + 1} r={ph.radius} />
    <jscad.hull>
      <Cylinder x={resetButton.x} y={resetButton.y} z0={d.top - ph.leadInDepth - 0.01} z1={d.top - ph.leadInDepth} r={ph.radius} />
      <Cylinder x={resetButton.x} y={resetButton.y} z0={d.top} z1={d.top + 0.01} r={ph.leadInRadius} />
    </jscad.hull>
    {pdOutY.flatMap((y0, i) => Array.from({ length: d.vents.count }, (_, k) =>
      <RoundBox key={`v${i}${k}`} x={d.vents.x} y={y0 + d.vents.pitch * (k - (d.vents.count - 1) / 2)} w={d.vents.length} h={d.vents.width} r={d.vents.width / 2} z0={d.wallTop - 1} z1={d.top + 1} />))}
  </jscad.subtract>
}

// ---------------- stop button cap ----------------
/** Red cap for the XKB8080-Z. A 2.1 x 3.05 mm socket pushes onto the post tip. The head lands on the lid at the
 *  switch's full travel (2.5 mm): a hard press loads the lid, and the shaft then stays 0.35 mm above the switch body. */
export function StopCap() {
  const c = d.cap, s = d.stopSwitch, { x, y } = stopButton
  const shaftBottom = d.top, headBottom = d.top + s.fullTravel, headTop = headBottom + c.headHeight
  return <jscad.subtract>
    <jscad.union>
      <Cylinder x={x} y={y} z0={shaftBottom} z1={headBottom + 0.01} r={c.shaftRadius} />
      <Cylinder x={x} y={y} z0={headBottom} z1={headTop - c.chamfer} r={c.headRadius} />
      <jscad.hull>
        <Cylinder x={x} y={y} z0={headTop - c.chamfer - 0.01} z1={headTop - c.chamfer} r={c.headRadius} />
        <Cylinder x={x} y={y} z0={headTop - 0.01} z1={headTop} r={c.headRadius - c.chamfer} />
      </jscad.hull>
    </jscad.union>
    <Box x={x} y={y} w={c.socketX} h={c.socketY} z0={shaftBottom - 1} z1={s.postTop + 0.05} />
  </jscad.subtract>
}

/** name -> part; `flip` parts print upside down (their top face on the bed). */
export const printableParts = { base: Base, lid: Lid, "stop-cap": StopCap }
export const printOrientation: Record<string, "as-built" | "flip"> = { base: "as-built", lid: "flip", "stop-cap": "flip" }
export const printQuantity: Record<string, number> = { base: 1, lid: 1, "stop-cap": 1 }