shibosoftwaredev/f1c100s-linux-nema17-stepper-controller

A four-layer NEMA 17 motor-controller PCB combining an Allwinner F1C100S Linux computer, USB‑PD/buck power system, W5500 Ethernet, STM32 real-time motion control, DRV8825 stepper driver, protection/temperature/current telemetry, USB interfaces, and local LED/buzzer diagnostics.

Version
0.4.56
License
unset
Stars
0

scripts/prepare-round7-usb.mjs

import fs from "node:fs"
import assert from "node:assert/strict"
import {routingSignature} from "../routing-signature"
const base="../../checkpoints/nema17-pre-round7-20261019-HTEis5/restore-verified"
const read=p=>JSON.parse(fs.readFileSync(p,"utf8"))
const before=read(`${base}/dist/index/circuit.json`),after=read("dist/index/circuit.json")
assert.equal(after.filter(e=>e.type.endsWith("_error")).length,0,"first obtain a valid placement")
function connectivity(c) {
  const parents=new Map(),root=id=>{if(!parents.has(id))parents.set(id,id);if(parents.get(id)!==id)parents.set(id,root(parents.get(id)));return parents.get(id)}
  for(const e of c) {const ids=e.type==="source_trace"?[...e.connected_source_port_ids??[],...e.connected_source_net_ids??[]]:e.type==="source_component_internal_connection"?e.source_port_ids:[];for(const id of ids.slice(1))parents.set(root(id),root(ids[0]))}
  return root
}
const root=connectivity(before),sources=new Map(before.filter(e=>e.type==="source_trace").map(e=>[e.source_trace_id,e]))
const currents=new Map(after.filter(e=>e.type==="source_trace").map(e=>[e.source_trace_id,e]))
const names=new Map(after.filter(e=>e.type==="source_trace").map(e=>[e.name,e]))
const oldNames=new Map(before.filter(e=>e.type==="source_component").map(e=>[e.source_component_id,e.name]))
const oldPorts=new Map(before.filter(e=>e.type==="source_port").map(e=>[e.source_port_id,{...e,part:oldNames.get(e.source_component_id)}]))
const nr=name=>root(before.find(e=>e.type==="source_net"&&e.name===name).source_net_id)
const removedRoots=new Set([nr("USB_N_PORT"),nr("USB_P_PORT")])
for(const id of ["source_trace_368"])
  removedRoots.add(root(sources.get(id).connected_source_port_ids[0]))
const retained=[],affected=[]
for(const t of read(`${base}/routing/complete-routes.json`)) {
  const s=sources.get(t.source_trace_id),ports=s.connected_source_port_ids.map(p=>oldPorts.get(p)),r=root([...s.connected_source_port_ids,...s.connected_source_net_ids][0])
  if(removedRoots.has(r)||ports.some(p=>["C_ESD","C_U_1V2_OUT","C_U_3V3_OUT","R_USB_DATA_CC2"].includes(p.part)||p.part==="U_USB_ESD"&&![4,6].includes(p.pin_number))) {affected.push(t.source_trace_id);continue}
  const esd=ports.find(p=>p.part==="U_USB_ESD")
  const target=esd?names.get(esd.pin_number===4?"USB_GATE_SOC_P":"USB_GATE_SOC_N"):currents.get(t.source_trace_id)
  assert.ok(target,`retained trace ${t.source_trace_id}`)
  retained.push({...t,source_trace_id:target.source_trace_id,subcircuit_id:target.subcircuit_id,
    subcircuit_connectivity_map_key:target.subcircuit_connectivity_map_key,
    route:t.route.map(p=>{const q={...p};if(esd){delete q.start_pcb_port_id;delete q.end_pcb_port_id}return q})})
}
fs.writeFileSync("routing/round7-usb-retained.json",JSON.stringify(retained,null,2)+"\n")
fs.writeFileSync("routing/placement.json",JSON.stringify(after,null,2)+"\n")
fs.writeFileSync("routing/expected-input.json",JSON.stringify(routingSignature(after),null,2)+"\n")
const changed=new Set(affected)
for(const s of after.filter(e=>e.type==="source_trace"))if(!sources.has(s.source_trace_id)||s.name?.startsWith("USB_GATE_")||s.name?.startsWith("USB_DATA_")||s.name?.startsWith("USB_BASE_")||s.name?.startsWith("USB_OE_")||s.name==="USB_ATTACH_EMITTER"||s.name==="USB_ATTACH_OE")changed.add(s.source_trace_id)
// The original ESD-to-SoC leaves were reassigned to gate-to-SoC above; the
// relocated ESD's two new host-side leaves still need their own copper.
for(const s of before.filter(e=>e.type==="source_trace"&&e.connected_source_port_ids.some(p=>oldPorts.get(p)?.part==="U_USB_ESD")))changed.add(s.source_trace_id)
const report={baseline:base,retainedPaths:retained.length,affectedSourceTraceIds:[...changed],notFabricationReady:true}
fs.writeFileSync("reports/round7-usb-routing-plan.json",JSON.stringify(report,null,2)+"\n")
console.log(JSON.stringify(report))