seveibar/nema17-rp2040-stepper-controller

A tscircuit package created by seveibar.

Version
0.3.1
License
unset
Stars
0

schematic/ControllerSections.tsx

import { Children, cloneElement, isValidElement, type ReactElement, type ReactNode } from "react";
import { Microcontroller_RP2040 } from "../vendor/rp2040";
import { schematicSheets } from "./config";

// Keep the MCU/clock/flash/BOOTSEL implementation; replace its old USB and LDO
// supply at the JSX source level. No post-build netlist edits or stale copper.
const removed = new Set(["J_USB","R_CC1","R_CC2","D_VBUS","U3","R_3V3_EN","C_VBUS"]);
function revisedController(node: ReactNode): ReactNode {
  if (!isValidElement(node)) return node;
  const el = node as ReactElement<any>;
  if (removed.has(el.props.name)) return null;
  if (el.type === "trace") {
    if(el.props.name === "PLED_G") return cloneElement(el,{to:"net.GND"});
    const selectors = [el.props.from,el.props.to,...(el.props.path ?? [])].filter(x=>typeof x === "string");
    if(selectors.some(s=>[...removed].some(name=>s.includes(`.${name} >`)))) return null;
  }
  // The removed connector's old silk is no longer useful.
  if(el.type === "silkscreentext" && el.props.text === "USB-C") return null;
  return cloneElement(el,el.props.name === "SW_BOOT" ? {pcbX:-7.875,pcbY:14.75} : {},Children.map(el.props.children,revisedController));
}
export const ControllerSections = () => revisedController(Microcontroller_RP2040({
  name:"MCU", schAutoLayoutEnabled:true, schSheetName:schematicSheets.controller, pcbX:-3.5, pcbY:2.5,
}));