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/dimensions.ts

/**
 * Enclosure dimensions (mm). Coordinates are the board's own: x right, y towards the PCB "top edge"
 * (the back of the box), z up, board centred at z = 0 so the board top is z = +0.8 (tscircuit 3D frame).
 * Board facts come from reference-board.json (bun measure-reference.ts); part heights from datasheets / 3D models.
 *
 * Layout (concept v1, accepted 2026-12-01): front = PCB bottom edge (no cables), stop button, lights and
 * reset on the lid; right wall = PD OUT 1-4 + USB 1-4; left wall = PD IN, PC, microSD; back = CAM + STOP IN.
 * No text or colour marks are modelled: labels will be UV printed on the finished lid later.
 */
import ref from "./reference-board.json"

export const board = ref.board
export const parts = ref.parts as Record<string, { x: number; y: number; width: number; height: number; rotation: number }>
export const mountingHoles = ref.mountingHoles
export const legsNearHoles = ref.legsNearHoles
export const partsNearHoles = ref.partsNearHoles
if (board.width !== 90 || board.height !== 98 || mountingHoles.length !== 4) throw new Error("Board outline changed: review the enclosure")

const BT = board.thickness, TOP = BT / 2               // board top surface z = 0.8
export const design = {
  boardTop: TOP,
  boardBottom: -TOP,
  clearance: 0.4,             // board edge to inside of the wall
  wall: 2.2,
  cornerRadius: 4,            // outside corner radius
  bottom: -TOP - 6.0,         // underside of the base (z = -6.8)
  floorTop: -TOP - 4.0,       // 4 mm standoffs under the board
  wallTop: TOP + 9.0,         // = lid underside; 0.85 mm above the stop switch body (8.15 mm)
  lidThickness: 2.0,
  get top() { return this.wallTop + this.lidThickness },      // lid top z = 11.8
  // Fixing, with the rp2040-bldc-motor-controller's case hardware: M2 x 3 heat-set inserts (Ø3.6 mm, 3.4 mm pilot,
  // Ø5.4 mm boss) and M2 pan-head screws (head Ø4.2 x 1.3 mm). Four screws go UP from under the base, through the
  // standoffs and the board's 3.2 mm corner holes, into inserts in the lid bosses: one set clamps base, board and lid,
  // and the lid top has no holes. That project's M3 board hardware does not fit here: the USB-C sockets sit 2.1-2.9 mm
  // from the hole centres, inside an M3 insert (Ø4.6) or head (Ø5.6). The screw is M2 x 14, not that project's
  // M2 x 4, because it passes through the base and the board. Each insert sits above the USB-C shells (the boss is
  // relieved over them below that), so its wall is complete; it drops in through a Ø3.8 entry bore and is heat-set
  // into the Ø3.4 pilot. Standoffs are notched under USB-C legs; heads sit in Ø4.6 recesses under the base.
  standoff: { radius: 2.9, clearanceRadius: 1.2, headRadius: 2.3, headDepth: 1.6, legClearance: 0.5, legNotchDepth: 1.6 },
  screw: { length: 14, headRadius: 2.1, headHeight: 1.3, bossRadius: 2.7, entryRadius: 1.9, insertRadius: 1.8, insertHole: 3.4 / 2,
    insertLength: 3.0, insertGap: 0.3, tipClearance: 0.4, partClearance: 0.3 },
  /** Derived fixing heights (z): head seat, screw tip, insert and pilot hole in the lid boss. */
  get fixing() {
    const seat = this.bottom + this.standoff.headDepth, tip = seat + this.screw.length
    const reliefTop = this.boardTop + Math.max(...partsNearHoles.map((p) => p.tall)) + this.screw.partClearance
    const insertBottom = reliefTop + this.screw.insertGap, insertTop = insertBottom + this.screw.insertLength
    const holeTop = tip + this.screw.tipClearance
    if (!(tip >= insertTop && holeTop <= this.wallTop - 0.5)) throw new Error(`Screw does not suit the lid boss: tip ${tip}, insert ${insertBottom}-${insertTop}, hole top ${holeTop}`)
    return { seat, tip, reliefTop, insertBottom, insertTop, holeTop, engagement: Math.min(tip, insertTop) - insertBottom }
  },
  // USB-C sockets: shell 8.94 x 3.26 mm on the board top, mouth 0.3 mm inside the board edge.
  // The wall opening is sized for a cable's plastic head (it has to reach through the wall).
  usbc: { z: TOP + 1.63, width: 10.2, height: 6.2, radius: 2.0 },
  microSd: { slotZ: TOP + 1.15, slotWidth: 12.6, slotHeight: 2.2, recessZ: TOP + 1.6, recessWidth: 17, recessHeight: 8.5, recessDepth: 1.2 },
  // STOP IN (JESTOP, JST SH 2-pin, side entry): normally bypassed by a 0R link on the board, so the
  // wall stays closed with a 0.6 mm knock-out skin on the outside. Cut it out to use a wired stop button.
  stopIn: { z: TOP + 1.45, width: 5.4, height: 4.2, radius: 0.8, skin: 0.6 },
  frontGrille: { xs: [14, 17, 20, 23, 26, 29, 32], z: TOP + 4.2, width: 1.5, height: 5.2 },
  // Stop button XKB8080-Z (datasheet): body top 8.15 mm, post top 13.66 mm above the board (button up),
  // post tip 2.00 (x) x 2.98 (y) mm, 3 mm tall; lock travel 2.0 mm, full travel 2.5 mm.
  stopSwitch: { bodyTop: TOP + 8.15, postTop: TOP + 13.66, tipX: 2.0, tipY: 2.98, fullTravel: 2.5 },
  // Printed cap: socket grips the post tip, head lands on the lid at full travel (hard stop),
  // so a hard press loads the lid, not the switch. Shaft bottom stays 0.3 mm above the switch body then.
  cap: { headRadius: 5.5, headHeight: 2.7, chamfer: 0.6, shaftRadius: 3.0, lidHoleRadius: 3.4, socketX: 2.1, socketY: 3.05 },
  // Light pipes: 1.5 mm clear PMMA rod (not printed), held by a block under the lid. LEDs are 2 mm apart.
  lightPipe: { radius: 0.75, holeRadius: 0.8, holderBottom: TOP + 2.6, holderWidth: 3.2, holderDepth: 6.6 },
  // Reset: paperclip pinhole (as on a router). 2 mm hole with a 45 degree lead-in; a solid 6 mm guide under
  // the lid ends 1 mm above the switch (TS-1088 top 1.95 mm) so the wire can only land on the switch.
  pinhole: { radius: 1.0, leadInRadius: 1.5, leadInDepth: 0.5, guideRadius: 3.0, switchTop: TOP + 1.95, gap: 1.0 },
  // Vents over the four PD output power stages (lid), five slots each.
  vents: { x: 16, length: 19, width: 1.4, pitch: 2.8, count: 5 },
}

export const body = {
  innerHalfX: board.width / 2 + design.clearance,
  innerHalfY: board.height / 2 + design.clearance,
  get outerHalfX() { return this.innerHalfX + design.wall },
  get outerHalfY() { return this.innerHalfY + design.wall },
  get innerRadius() { return design.cornerRadius - design.wall },
}

export const stopButton = { x: parts.SWSTOP.x, y: parts.SWSTOP.y }
export const resetButton = { x: parts.SWRST.x, y: parts.SWRST.y }
export const leds = [parts.LEDSTAT, parts.LEDACT, parts.LEDHWEN].map((p) => ({ x: p.x, y: p.y }))
export const pdOutY = [1, 2, 3, 4].map((i) => parts[`JOUT${i}`].y)

/** Wall openings; `side` is the wall, `at` the position along it (y for left/right walls, x for front/back). */
export type Opening = { name: string; side: "left" | "right" | "back" | "front"; at: number; z: number; width: number; height: number; radius: number; skin?: number }
const usb = (name: string, side: Opening["side"], at: number): Opening =>
  ({ name, side, at, z: design.usbc.z, width: design.usbc.width, height: design.usbc.height, radius: design.usbc.radius })
export const openings: Opening[] = [
  ...[1, 2, 3, 4].flatMap((i) => [usb(`PD OUT ${i}`, "right", parts[`JOUT${i}`].y), usb(`USB ${i}`, "right", parts[`JUSB${i}`].y)]),
  usb("PD IN", "left", parts.JPD.y),
  usb("PC", "left", parts.JPC.y),
  usb("CAM", "back", parts.JCAM.x),
  { name: "STOP IN", side: "back", at: parts.JESTOP.x, z: design.stopIn.z, width: design.stopIn.width, height: design.stopIn.height, radius: design.stopIn.radius, skin: design.stopIn.skin },
  ...design.frontGrille.xs.map((x, k): Opening => ({ name: `grille ${k + 1}`, side: "front", at: x, z: design.frontGrille.z, width: design.frontGrille.width, height: design.frontGrille.height, radius: design.frontGrille.width / 2 })),
]
export const microSd = { y: parts.JSD.y }