75 lines
3.0 KiB
TypeScript
75 lines
3.0 KiB
TypeScript
|
|
/**
|
|||
|
|
* Synthetic pin numbers for custom-chip output pins.
|
|||
|
|
*
|
|||
|
|
* A custom-chip output pin wired DIRECTLY to a component (e.g. a wokwi-led)
|
|||
|
|
* has no board GPIO on its net, so the wire-graph trace returns null and the
|
|||
|
|
* chip can drive nothing through the digital PinManager. We give every such
|
|||
|
|
* chip pin a stable synthetic pin NUMBER, far above any real board pin
|
|||
|
|
* (max ~69), so the chip's driver and every component on the same net share
|
|||
|
|
* one PinManager key — making the chip a first-class pin source.
|
|||
|
|
*
|
|||
|
|
* The same (chipId, pinName) identity keys the SPICE chip voltage source (see
|
|||
|
|
* chipPinDrives + spice/componentToSpice) so the analog engine drives the net
|
|||
|
|
* too. Kept in this dependency-light module so both the resolver
|
|||
|
|
* (components/DynamicComponent) and the chip runtime (ChipRuntime) can import
|
|||
|
|
* it without pulling in React / the store.
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
export const SYNTHETIC_CHIP_PIN_BASE = 100000;
|
|||
|
|
|
|||
|
|
const synthChipPinMap = new Map<string, number>();
|
|||
|
|
let nextSyntheticChipPin = SYNTHETIC_CHIP_PIN_BASE;
|
|||
|
|
|
|||
|
|
/** Stable synthetic pin number for a custom-chip pin. Allocate-on-first-use. */
|
|||
|
|
export function syntheticChipPin(chipId: string, pinName: string): number {
|
|||
|
|
const key = `${chipId} |