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/drawings.tsx
import { assembly } from "tscircuit"
import { board, body, design, mountingHoles, pdOutY, stopButton } from "./dimensions"
/**
* Engineering drawings of the printed enclosure: three ISO A3 landscape sheets (general arrangement,
* sections, printed parts), laid out as in the rp2040-bldc-motor-controller package.
*
* Every view is a plain `partRef` view, because the drawing export of the tscircuit command line tool
* (0.1.2488) draws only those: stage views, exploded views and part labels need a scene resolver it does
* not pass ("Assembly views require resolveSceneParts").
*
* HOW PLAIN VIEWS ARE DRAWN (measured with test pages on 2026-12-02; the BLDC package's drawings use the same
* rules). The renderer works in a frame turned half a turn about the vertical axis from the board's x / y:
* - direction "x+" shows the LEFT wall (the camera is at -x), "x-" the right wall, "y+" the FRONT wall,
* "y-" the back wall, "z+" the top with the front edge up;
* - a section plane on x or y lands at MINUS the offset, and keepSide "less" keeps the side with the larger
* board coordinate. So "cut at board y = Y, keep the back part" is offset = -Y, keepSide "less".
* z is not turned. The helpers below hide this: give them board coordinates.
*
* Dimension texts are measured from the model by tscircuit (widthOfView / heightOfView); none is typed in.
* Dimension lines work only on views of the printed parts: with board parts in the view tscircuit stops with
* "footprinter model cannot be loaded for drawing dimensions". So the dimensioned views show the enclosure
* alone, and only the section views (no dimension lines) can also show the board (`sectionRef`).
*
* Sheet coordinates are mm from the sheet centre. The title block covers x > 25, y < -104.
*
* Quick check without building the board (about half a minute per sheet):
* tsci export enclosure/drawings.circuit.tsx -f drawing-svg --drawing enclosure_general_arrangement -o ga.svg
*/
const ID = "PDHUB-ENC-01", REV = "A", DATE = "2026-12-02", SHEETS = 3
/** tscircuit fits a view into its viewport with a 10 % margin, so a viewport of size x 1.1 x scale gives that scale. */
const FIT = 1.1
const mm = (v: number) => String(Number(v.toFixed(2)))
// Outside of the case (mm), from the same numbers the printed parts are made from.
const W = 2 * body.outerHalfX, D = 2 * body.outerHalfY, H = design.top - design.bottom
const STRIP = 44 // viewport height of a 1:1 side view (the case with the stop cap is under 40 mm tall)
// Views by what they show (see the frame note above).
const SHOWS = { front: "y+", back: "y-", left: "x+", right: "x-", top: "z+", underside: "z-" } as const
/** Cut at board y = `y`, keep the part behind it (towards the back wall); look at it with SHOWS.front. */
const cutAtY = (y: number) => ({ axis: "y" as const, offset: -y, keepSide: "less" as const, hatchSpacing: 1 })
/** Cut at board x = `x`, keep the part to its left; look at it with SHOWS.right. */
const cutAtX = (x: number) => ({ axis: "x" as const, offset: -x, keepSide: "greater" as const, hatchSpacing: 1 })
// Section planes, all from enclosure/dimensions.ts.
const stopAxisY = stopButton.y // A-A: through the stop button post
const portAxisY = pdOutY[0] // B-B: through the middle of the PD OUT 1 opening
const screwAxisX = Math.max(...mountingHoles.map((h) => h.x)) // C-C: through the two right-hand screw columns
const TitleBlock = ({ title, sheet }: { title: string; sheet: number }) => (
<assembly.drawing.titleblock title={`USB PD hub enclosure / ${title}`} identificationNumber={ID} revisionIndex={REV}
dateOfIssue={DATE} sheetNumber={sheet} numberOfSheets={SHEETS} />
)
const Notes = ({ x, y, lines }: { x: number; y: number; lines: string[] }) => <>
{lines.map((text, k) => <assembly.drawing.note key={k} text={text} paperX={x} paperY={y - 6 * k} />)}
</>
/**
* @param assemblyRef selector of what the dimensioned views show: the printed enclosure.
* @param sectionRef selector of what the section views show. Default: the enclosure alone. In the full package
* pass "board": a view that selects the board draws the board, its parts and the enclosure
* around it (tested with a stand-in board; such views cannot carry dimension lines).
* @param partRefs selectors of the three printed parts.
*/
export function EnclosureDrawings({ assemblyRef = ".ENCLOSURE", sectionRef = assemblyRef, partRefs = { base: ".CASE_BASE", lid: ".CASE_LID", cap: ".STOP_CAP" } }:
{ assemblyRef?: string; sectionRef?: string; partRefs?: { base: string; lid: string; cap: string } } = {}) {
const S = 2 // section viewports are sized for 2:1 (the label says FIT: only a dimensioned view gets a scale)
const capD = 2 * design.cap.headRadius, CAP_S = 4
return <>
<assembly.drawing.page name="enclosure_general_arrangement" displayName="Enclosure / general arrangement" size="iso_a3">
<assembly.drawing.partview name="PLAN_VIEW" displayName="Plan (front edge up)" partRef={assemblyRef} direction={SHOWS.top}
centerX={-148} centerY={64} width={W * FIT} height={D * FIT}>
<assembly.drawing.dimension name="overall_width" widthOfView />
<assembly.drawing.dimension name="overall_depth" heightOfView />
</assembly.drawing.partview>
<assembly.drawing.partview name="FRONT_VIEW" displayName="Front view (grille; no sockets)" partRef={assemblyRef} direction={SHOWS.front}
centerX={-148} centerY={-30} width={W * FIT} height={STRIP}>
<assembly.drawing.dimension name="height_with_stop_cap" heightOfView />
</assembly.drawing.partview>
<assembly.drawing.partview name="BACK_VIEW" displayName="Back view (CAM; STOP IN is behind a knock-out skin)" partRef={assemblyRef} direction={SHOWS.back}
centerX={-148} centerY={-92} width={W * FIT} height={STRIP}>
<assembly.drawing.dimension name="back_width" widthOfView />
</assembly.drawing.partview>
<assembly.drawing.partview name="RIGHT_VIEW" displayName="Right view (USB 1, PD OUT 1 ... USB 4, PD OUT 4)" partRef={assemblyRef} direction={SHOWS.right}
centerX={-18} centerY={99} width={D * FIT} height={STRIP}>
<assembly.drawing.dimension name="right_depth" widthOfView />
</assembly.drawing.partview>
<assembly.drawing.partview name="LEFT_VIEW" displayName="Left view (PD IN, PC, microSD)" partRef={assemblyRef} direction={SHOWS.left}
centerX={-18} centerY={40} width={D * FIT} height={STRIP}>
<assembly.drawing.dimension name="left_depth" widthOfView />
</assembly.drawing.partview>
<assembly.drawing.partview name="ISOMETRIC" displayName="Assembled enclosure" partRef={assemblyRef} direction="isometric"
centerX={128} centerY={66} width={130} height={104} />
<Notes x={-75} y={-22} lines={[
`Case without the stop cap: ${mm(W)} x ${mm(D)} x ${mm(H)} mm. Wall ${mm(design.wall)} mm, lid ${mm(design.lidThickness)} mm.`,
`Board: ${mm(board.width)} x ${mm(board.height)} mm on ${mm(design.boardBottom - design.floorTop)} mm standoffs, ${mm(design.clearance)} mm clear of the walls.`,
`Fixing: ${mountingHoles.length} x M2 x ${mm(design.screw.length)} screws from under the base, through the board,`,
`into M2 x ${mm(design.screw.insertLength)} heat-set inserts in the lid.`,
`Front = the edge with the stop button. Sockets are on the right, left and back walls.`,
]} />
<TitleBlock title="general arrangement" sheet={1} />
</assembly.drawing.page>
<assembly.drawing.page name="enclosure_sections" displayName="Enclosure / sections" size="iso_a3">
<assembly.drawing.partview name="SECTION_A_A" displayName="Section A-A / stop button axis, seen from the front" partRef={sectionRef} direction={SHOWS.front}
centerX={-88} centerY={100} width={W * FIT * S} height={60} section={cutAtY(stopAxisY)} />
<assembly.drawing.partview name="SECTION_B_B" displayName="Section B-B / PD OUT 1 socket axis, seen from the front" partRef={sectionRef} direction={SHOWS.front}
centerX={-88} centerY={25} width={W * FIT * S} height={60} section={cutAtY(portAxisY)} />
<assembly.drawing.partview name="SECTION_C_C" displayName="Section C-C / right-hand screw columns, seen from the right" partRef={sectionRef} direction={SHOWS.right}
centerX={-88} centerY={-50} width={D * FIT * S} height={60} section={cutAtX(screwAxisX)} />
<assembly.drawing.partview name="SECTION_A_A_ISOMETRIC" displayName="Section A-A / isometric" partRef={sectionRef} direction="isometric"
centerX={120} centerY={78} width={146} height={112} section={cutAtY(stopAxisY)} />
<Notes x={48} y={-8} lines={[
`Planes, in board coordinates (0 = board centre,`,
`x to the right, y to the back):`,
`A-A y = ${mm(stopAxisY)} mm, stop button post`,
`B-B y = ${mm(portAxisY)} mm, middle of the PD OUT 1 opening`,
`C-C x = ${mm(screwAxisX)} mm, two screw columns`,
]} />
<TitleBlock title="sections" sheet={2} />
</assembly.drawing.page>
<assembly.drawing.page name="enclosure_printed_parts" displayName="Enclosure / printed parts" size="iso_a3">
<assembly.drawing.partview name="PART_1" displayName="1 / case base / qty 1" partRef={partRefs.base} direction="isometric"
centerX={-150} centerY={100} width={104} height={72} />
<assembly.drawing.partview name="PART_1_FRONT" displayName="1 / case base / front" partRef={partRefs.base} direction={SHOWS.front}
centerX={-150} centerY={38} width={W * FIT} height={30}>
<assembly.drawing.dimension name="base_height" heightOfView />
</assembly.drawing.partview>
<assembly.drawing.partview name="PART_1_PLAN" displayName="1 / case base / inside, front edge up" partRef={partRefs.base} direction={SHOWS.top}
centerX={-150} centerY={-48} width={W * FIT} height={D * FIT}>
<assembly.drawing.dimension name="base_width" widthOfView />
<assembly.drawing.dimension name="base_depth" heightOfView />
</assembly.drawing.partview>
<assembly.drawing.partview name="PART_2" displayName="2 / case lid / qty 1" partRef={partRefs.lid} direction="isometric"
centerX={-35} centerY={100} width={104} height={72} />
<assembly.drawing.partview name="PART_2_FRONT" displayName="2 / case lid / front" partRef={partRefs.lid} direction={SHOWS.front}
centerX={-35} centerY={38} width={W * FIT} height={30}>
<assembly.drawing.dimension name="lid_height" heightOfView />
</assembly.drawing.partview>
<assembly.drawing.partview name="PART_2_UNDERSIDE" displayName="2 / case lid / underside, front edge up" partRef={partRefs.lid} direction={SHOWS.underside}
centerX={-35} centerY={-48} width={W * FIT} height={D * FIT}>
<assembly.drawing.dimension name="lid_width" widthOfView />
<assembly.drawing.dimension name="lid_depth" heightOfView />
</assembly.drawing.partview>
<assembly.drawing.partview name="PART_3" displayName="3 / stop button cap / qty 1" partRef={partRefs.cap} direction="isometric"
centerX={120} centerY={100} width={60} height={60} />
<assembly.drawing.partview name="PART_3_FRONT" displayName="3 / stop button cap / front" partRef={partRefs.cap} direction={SHOWS.front}
centerX={120} centerY={28} width={capD * FIT * CAP_S} height={62}>
<assembly.drawing.dimension name="cap_diameter" widthOfView />
<assembly.drawing.dimension name="cap_height" heightOfView />
</assembly.drawing.partview>
<Notes x={78} y={-30} lines={[
`Material: PETG. Parts are shown as fitted,`,
`not in their printing position.`,
]} />
<TitleBlock title="printed parts" sheet={3} />
</assembly.drawing.page>
</>
}