std::schematic
std::schematic is the standard library module that builds a cell's schematic: signals, the connections between them, devices, and schematic instances of other cells. See Schematics for how these fit together.
Importing
Nothing in std::schematic is in scope by default. Import the names a module uses:
use std::schematic::{Device, DeviceKind, Signal, connect, device, signals};
use std::schematic::inst as sinst;
std::layout also has an inst, so a module that places cells in both views imports at least one of them under another name, or calls it by full path. A name such as Signal or Device is only in scope once imported, in type position as well as in calls.
Signal, connect, device, and inst are implemented by the compiler. They can only be called, so a reference that isn't a call, such as let f = connect;, is an error. Device is only a type. DeviceKind is an ordinary enum, and signals an ordinary function.
The placement keywords x, y, angle, and reflect, and the route of a connection, are grid units that only say where the GUI draws an element. None of them can be read back.
Signal
Signal(x=Int, y=Int, angle=Int) -> Signal
Creates a signal of the current cell.
| Argument | Type | Requirement | Description |
|---|---|---|---|
x | Int | Optional keyword, with y | Where the signal's pin or label is drawn, in grid units. |
y | Int | Optional keyword, with x | Where the signal's pin or label is drawn, in grid units. |
angle | Int | Optional keyword | Counterclockwise rotation of the pin or label in degrees, a multiple of 90. |
Returns Signal. A new signal, on a net of its own until it is connected.
pub let vdd = Signal();
pub let a = Signal(x=-8, y=0);
Signal is also the type of a signal, as in fn tie(s: Signal).
connect
connect(a: Signal, b: Signal, route=[(Int, Int)]) -> ()
Joins the nets of two signals.
| Argument | Type | Requirement | Description |
|---|---|---|---|
a | Signal | Required, positional | A signal of the current cell. |
b | Signal | Required, positional | A signal of the current cell. |
route | [(Int, Int)] | Optional keyword | The corners of the wire that draws the connection, in grid units, from the pin of a to the pin of b. [] is a straight wire; without route, no wire is drawn. |
Returns (). Nothing; the two nets become one.
connect(out, nmos.d);
connect(a, nmos.g, route=[(-4, 0), (-4, -4)]);
device
device(kind: DeviceKind, terminals: [Signal], model: String, <name>=Float | Int | String, …, x=Int, y=Int, angle=Int, reflect=Bool) -> Device
Adds a primitive device to the current cell.
| Argument | Type | Requirement | Description |
|---|---|---|---|
kind | DeviceKind | Required, positional | The kind of device, which decides its terminals and whether it needs a model. |
terminals | [Signal] | Required, positional | The signals the device connects to, in the order its kind expects. signals(n) makes fresh ones. |
model | String | Required, positional | The model name, without whitespace, or "" for none. |
value | Float | Int | String | Optional keyword | The value of a Res or Cap device, in any case (VALUE also works). Other kinds do not take it. |
<name> | Float | Int | String | Optional keyword | A device parameter, kept in the order written. Names must differ other than in case. A Float must be solved to a finite number. |
x, y | Int | Optional keywords, together | Where the device is drawn, in grid units. Reserved in every case, so X=1 is an error rather than a parameter. |
angle | Int | Optional keyword | Counterclockwise rotation in degrees, a multiple of 90. |
reflect | Bool | Optional keyword | Mirror about the x axis before rotating. |
Returns Device. The device's handle, whose fields are its terminals.
device(DeviceKind::Mos, [d, g, s, b], "nch", w=2., l=0.15, nf=2);
device(DeviceKind::Res, [top, bottom], "", value=1000.);
let mn = device(DeviceKind::Nmos, signals(4), "nch", w=1., l=0.15, x=0, y=-4);
connect(a, mn.g);
The device table lists the terminals and model each kind requires.
inst
inst(cell: Cell, x=Int, y=Int, angle=Int, reflect=Bool) -> SchematicInst
Places a cell in the current cell's schematic.
| Argument | Type | Requirement | Description |
|---|---|---|---|
cell | Cell | Required, positional | The cell value to place, such as inv(2., 1., 2). |
x, y | Int | Optional keywords, together | Where the instance is drawn, in grid units. |
angle | Int | Optional keyword | Counterclockwise rotation in degrees, a multiple of 90. |
reflect | Bool | Optional keyword | Mirror about the x axis before rotating. |
Returns SchematicInst. The instance, whose ports read as its terminals.
let nmos = std::schematic::inst(mos(true, 1., 2), x=0, y=-4);
connect(a, nmos.g);
signals
signals(n: Int) -> [Signal]
Creates fresh signals.
| Argument | Type | Requirement | Description |
|---|---|---|---|
n | Int | Required, positional | How many signals to create. |
Returns [Signal]. n new signals of the current cell, each on a net of its own.
let mn = device(DeviceKind::Nmos, signals(4), "nch", w=1., l=0.15);
Written in Argon, so the signals belong to the cell that calls it. They have no placement of their own and draw nothing.
Device
The type of the handle device returns. Its fields are the device's terminals, named by its kind, and terminals, every terminal in order:
| Kind | Fields |
|---|---|
Mos, Nmos, Pmos | d, g, s, b |
Res, Cap, Diode | p, n |
Bjt, Npn, Pnp | c, b, e, and sub with 4 terminals |
Subckt | none by name |
| every kind | terminals: [Signal] |
Every named field has type Signal. The names are checked against the device's kind when the cell runs, so r.g on a resistor is an error. See device handles.
DeviceKind
enum DeviceKind {
Mos,
Nmos,
Pmos,
Res,
Cap,
Diode,
Bjt,
Npn,
Pnp,
Subckt,
}
The kind of a device placed with device: a MOSFET, a resistor, a capacitor, a diode, a bipolar transistor, or an instance of a subcircuit the cell does not define, such as a PDK model. Nmos and Pmos are Mos devices, and Npn and Pnp are Bjt devices, drawn with a polarity symbol; they netlist as their base kind.