ShiboSoftwareDev/nema8-20mm-dual-usbc-stepper-controller

A compact 4-layer USB‑C PD/data controller board using a CH32X035 MCU and TMC2209 driver to power and control a NEMA‑8 stepper motor, with 3.3‑V regulation, USB ESD/reverse-polarity/TVS protection, current sensing, and boot control.

Version
1.0.12
License
unset
Stars
0

scripts/inspect-direct-vcp-route.mjs

import fs from "node:fs"
import { runAllRoutingChecks } from "@tscircuit/checks"

const original = JSON.parse(fs.readFileSync("dist/index/circuit.json", "utf8"))
  .filter((element) => !String(element.type).endsWith("error"))
const before = await runAllRoutingChecks(original)
const beforeMessages = new Set(before.map((error) => error.message))

const wire = (x, y, layer, extra = {}) => ({ route_type: "wire", x, y, width: 0.15, layer, ...extra })
const viaPoint = (x, y) => ({
  route_type: "via", x, y,
  from_layer: "bottom", to_layer: "top",
  via_diameter: 0.45, via_hole_diameter: 0.3,
})

const replace = (topPoints, via, bottomPoints) => original.flatMap((element) => {
  if (element.type === "pcb_via" && element.pcb_trace_id === "source_net_30_0") {
    if (element.pcb_via_id !== "pcb_via_9") return []
    return [{ ...element, x: via[0], y: via[1] }]
  }
  if (element.type !== "pcb_trace" || element.pcb_trace_id !== "source_net_30_0") return [element]
  return [{
    ...element,
    route: [
      ...topPoints.map(([x, y], index) => wire(x, y, "top", index === 0 ? { start_pcb_port_id: "pcb_port_105" } : {})),
      wire(via[0], via[1], "top"),
      viaPoint(via[0], via[1]),
      wire(via[0], via[1], "bottom"),
      ...bottomPoints.map(([x, y], index) => wire(x, y, "bottom", index === bottomPoints.length - 1 ? { end_pcb_port_id: "pcb_port_133" } : {})),
    ],
  }]
})

const candidates = [
  { name: "right-24-via-20", top: [[0.1,1.7],[0.1,2.4],[4.5,2.4]], via: [4.5,-2], bottom: [[3.625,-2]] },
  { name: "right-27-via-20", top: [[0.1,1.7],[0.1,2.7],[4.5,2.7]], via: [4.5,-2], bottom: [[3.625,-2]] },
  { name: "right-24-via-bottom", top: [[0.1,1.7],[0.1,2.4],[4.5,2.4],[4.5,-3.9]], via: [4.5,-3.9], bottom: [[4.5,-2],[3.625,-2]] },
  { name: "right-27-via-bottom", top: [[0.1,1.7],[0.1,2.7],[4.5,2.7],[4.5,-3.9]], via: [4.5,-3.9], bottom: [[4.5,-2],[3.625,-2]] },
  { name: "far-right", top: [[0.1,1.7],[0.1,2.7],[5.8,2.7],[5.8,-3.9]], via: [5.8,-3.9], bottom: [[5.8,-2],[3.625,-2]] },
  { name: "bottom-around-left", top: [[0.1,1.7],[-2,2.4],[-2,-4.2],[2.8,-4.2]], via: [2.8,-4.2], bottom: [[2.8,-2],[3.625,-2]] },
]

for (const candidate of candidates) {
  const after = await runAllRoutingChecks(replace(candidate.top, candidate.via, candidate.bottom))
  const afterMessages = new Set(after.map((error) => error.message))
  console.log(`\n${candidate.name}: ${after.length}`)
  console.log("removed:", [...beforeMessages].filter((message) => !afterMessages.has(message)))
  console.log("added:", [...afterMessages].filter((message) => !beforeMessages.has(message)))
}