imrishabh18/nema-23-stepper-controller
A curved NEMA23 rear-mount PCB combining an RP2040 controller, USB-C/USB-PD power input and protection, DRV8452 dual-winding stepper driver, current sensing, thermal interlock, status RGB LED, buzzer, and optional I²C encoder interface.
- Version
- 1.3.3
- License
- unset
- Stars
- 1
usb-c-compat.ts
import { Connector } from "tscircuit"
// Core 0.0.2050's native USB-C arrangement includes only VBUS1/2 and GND1/2.
// The retained 20-contact power receptacle exposes four of each. Include those
// additional physical contacts in the native power/ground rows; the connector
// engine still determines every pin position, spacing and USB illustration.
const prototype = Connector.prototype as any
const marker = Symbol.for("nema23.usbc-extra-supply-contacts")
if (!prototype[marker]) {
const arrange = prototype._getSchematicPortArrangement
prototype._getSchematicPortArrangement = function () {
const arrangement = arrange.call(this)
if (this._parsedProps.standard !== "usb_c" || !arrangement?.rightSide?.pins) return arrangement
const right = [...arrangement.rightSide.pins]
const used = new Set([...right, ...(arrangement.bottomSide?.pins ?? [])])
const rails = this.selectAll("port").flatMap((port: any) => {
const label = port.getNameAndAliases().find((alias: string) => /^(VBUS|GND)\d+$/i.test(alias))
return label ? [{ pin: port.props.pinNumber, label: label.toUpperCase() }] : []
})
for (const prefix of ["VBUS", "GND"]) {
const family = rails.filter((port: any) => port.label.startsWith(prefix))
.sort((a: any, b: any) => Number(a.label.slice(prefix.length)) - Number(b.label.slice(prefix.length)))
let after = Math.max(...family.map((port: any) => right.indexOf(port.pin)))
for (const port of family) if (!used.has(port.pin)) {
right.splice(++after, 0, port.pin)
used.add(port.pin)
}
}
return { ...arrangement, rightSide: { ...arrangement.rightSide, pins: right } }
}
prototype[marker] = true
}