Derive Macro substrate::io::Io

source ·
#[derive(Io)]
{
    // Attributes available to this derive:
    #[substrate]
}
Expand description

Derives Io for a struct.

§Examples

By default, deriving Io for a struct creates general purpose schematic and layout IO structs by suffixing the provided identifier with Schematic and Layout.

In the example below, BufferIoSchematic and BufferIoLayout are automatically created with default settings. These are the structs that users interact with when generating schematics and layout views, respectively.

#[derive(Io, Clone, Copy, Default)]
pub struct BufferIo {
    vdd: InOut<Signal>,
    vss: InOut<Signal>,
    din: Input<Signal>,
    dout: Output<Signal>,
}
// Autogenerated by `#[derive(Io)]`.
pub struct BufferIoSchematic {
    vdd: Node,
    vss: Node,
    din: Node,
    dout: Node,
}

pub struct BufferIoLayout {
    vdd: PortGeometry,
    vss: PortGeometry,
    din: PortGeometry,
    dout: PortGeometry,
}

However, the general purpose PortGeometry structs that represent the geometry of single net ports in BufferIoLayout are often unecessary since they contain multiple shapes, whereas most circuits often have a single shape for several of their ports.

Substrate allows you to customize the type of the ports you interact with when setting up IO in the layout view of a block using the #[substrate(layout_type = "...")] attribute.

#[derive(Io, Clone, Default)]
pub struct BufferIo {
    vdd: InOut<Signal>,
    vss: InOut<Signal>,
    #[substrate(layout_type = "ShapePort")]
    din: Input<Signal>,
    #[substrate(layout_type = "ShapePort")]
    dout: Output<Signal>,
}

This indicates that the din and dout of the buffer only have a single shape, making the ports easier to interact with when instantiating the buffer in other blocks.

If desired, you can even replace the whole IO struct with a layout type of your own (See the LayoutType derive macro).