mirror of
https://github.com/diodeinc/pcb.git
synced 2026-09-14 20:17:19 +08:00
e852477546
* Initial release * cargo-dist * build and test CI * update ubuntu workflow * fmt * ubuntu: install deps * clippy: 0.1.88 fixes * format * install clippy * Update README.md * Don't run cargo-dist on PRs
219 lines
4.3 KiB
Rust
219 lines
4.3 KiB
Rust
mod common;
|
|
use common::TestProject;
|
|
|
|
#[test]
|
|
fn interface_net_template_basic() {
|
|
let env = TestProject::new();
|
|
|
|
env.add_file(
|
|
"test.star",
|
|
r#"
|
|
# Basic interface with net template
|
|
MyInterface = interface(test = Net("MYTEST", prop=True, value="123"))
|
|
instance = MyInterface("PREFIX")
|
|
|
|
# Create component to generate netlist
|
|
Component(
|
|
name = "R1",
|
|
type = "resistor",
|
|
pin_defs = {"1": "1", "2": "2"},
|
|
footprint = "SMD:0805",
|
|
pins = {"1": instance.test, "2": Net("GND")},
|
|
)
|
|
"#,
|
|
);
|
|
|
|
star_snapshot!(env, "test.star");
|
|
}
|
|
|
|
#[test]
|
|
fn interface_multiple_net_templates() {
|
|
let env = TestProject::new();
|
|
|
|
env.add_file(
|
|
"test.star",
|
|
r#"
|
|
# Interface with multiple net templates
|
|
Power = interface(
|
|
vcc = Net("3V3", voltage="3.3V", type="power"),
|
|
gnd = Net("GND", type="ground"),
|
|
enable = Net("EN", active="high")
|
|
)
|
|
|
|
# Create instances
|
|
pwr1 = Power("MCU")
|
|
pwr2 = Power("SENSOR")
|
|
|
|
# Create components
|
|
Component(
|
|
name = "U1",
|
|
type = "mcu",
|
|
pin_defs = {"VCC": "1", "GND": "2", "EN": "3"},
|
|
footprint = "QFN:32",
|
|
pins = {
|
|
"VCC": pwr1.vcc,
|
|
"GND": pwr1.gnd,
|
|
"EN": pwr1.enable,
|
|
}
|
|
)
|
|
|
|
Component(
|
|
name = "U2",
|
|
type = "sensor",
|
|
pin_defs = {"VDD": "1", "VSS": "2", "ENABLE": "3"},
|
|
footprint = "SOT:23-6",
|
|
pins = {
|
|
"VDD": pwr2.vcc,
|
|
"VSS": pwr2.gnd,
|
|
"ENABLE": pwr2.enable,
|
|
}
|
|
)
|
|
"#,
|
|
);
|
|
|
|
star_snapshot!(env, "test.star");
|
|
}
|
|
|
|
#[test]
|
|
fn interface_nested_template() {
|
|
let env = TestProject::new();
|
|
|
|
env.add_file(
|
|
"test.star",
|
|
r#"
|
|
# Nested interface templates
|
|
PowerNets = interface(
|
|
vcc = Net("VCC", type="power"),
|
|
gnd = Net("GND", type="ground")
|
|
)
|
|
|
|
# Create a pre-configured power instance
|
|
usb_power = PowerNets("USB")
|
|
|
|
# Use as template in another interface
|
|
Device = interface(
|
|
power = usb_power,
|
|
data_p = Net("D+"),
|
|
data_n = Net("D-")
|
|
)
|
|
|
|
# Create device instance
|
|
dev = Device("PORT1")
|
|
|
|
# Wire up components
|
|
Component(
|
|
name = "J1",
|
|
type = "usb_connector",
|
|
pin_defs = {"VBUS": "1", "D+": "2", "D-": "3", "GND": "4"},
|
|
footprint = "USB:TYPE-C",
|
|
pins = {
|
|
"VBUS": dev.power.vcc,
|
|
"D+": dev.data_p,
|
|
"D-": dev.data_n,
|
|
"GND": dev.power.gnd,
|
|
}
|
|
)
|
|
"#,
|
|
);
|
|
|
|
star_snapshot!(env, "test.star");
|
|
}
|
|
|
|
#[test]
|
|
fn interface_template_property_inheritance() {
|
|
let env = TestProject::new();
|
|
|
|
env.add_file(
|
|
"test.star",
|
|
r#"
|
|
# Test that properties are properly copied from templates
|
|
SignalInterface = interface(
|
|
clk = Net("CLK", frequency="100MHz", type="clock"),
|
|
data = Net("DATA", width="8", direction="bidirectional"),
|
|
valid = Net("VALID", active="high")
|
|
)
|
|
|
|
# Create multiple instances
|
|
bus1 = SignalInterface("CPU")
|
|
bus2 = SignalInterface("MEM")
|
|
|
|
# Connect them
|
|
Component(
|
|
name = "CPU",
|
|
type = "processor",
|
|
pin_defs = {"CLK": "1", "DATA": "2", "VALID": "3"},
|
|
footprint = "BGA:256",
|
|
pins = {
|
|
"CLK": bus1.clk,
|
|
"DATA": bus1.data,
|
|
"VALID": bus1.valid,
|
|
}
|
|
)
|
|
|
|
Component(
|
|
name = "MEM",
|
|
type = "memory",
|
|
pin_defs = {"CLK": "1", "DATA": "2", "VALID": "3"},
|
|
footprint = "TSOP:48",
|
|
pins = {
|
|
"CLK": bus2.clk,
|
|
"DATA": bus2.data,
|
|
"VALID": bus2.valid,
|
|
}
|
|
)
|
|
"#,
|
|
);
|
|
|
|
star_snapshot!(env, "test.star");
|
|
}
|
|
|
|
#[test]
|
|
fn interface_mixed_templates_and_types() {
|
|
let env = TestProject::new();
|
|
|
|
env.add_file(
|
|
"test.star",
|
|
r#"
|
|
# Mix of templates and regular types
|
|
MixedInterface = interface(
|
|
# Template nets with properties
|
|
power = Net("VDD", voltage="1.8V"),
|
|
ground = Net("VSS", type="ground"),
|
|
# Regular net type
|
|
signal = Net,
|
|
# Nested interface template
|
|
control = interface(
|
|
enable = Net("EN"),
|
|
reset = Net("RST", active="low")
|
|
)()
|
|
)
|
|
|
|
# Create instance
|
|
mixed = MixedInterface("CHIP")
|
|
|
|
# Use all the nets
|
|
Component(
|
|
name = "IC1",
|
|
type = "asic",
|
|
pin_defs = {
|
|
"VDD": "1",
|
|
"VSS": "2",
|
|
"SIG": "3",
|
|
"EN": "4",
|
|
"RST": "5"
|
|
},
|
|
footprint = "QFN:48",
|
|
pins = {
|
|
"VDD": mixed.power,
|
|
"VSS": mixed.ground,
|
|
"SIG": mixed.signal,
|
|
"EN": mixed.control.enable,
|
|
"RST": mixed.control.reset,
|
|
}
|
|
)
|
|
"#,
|
|
);
|
|
|
|
star_snapshot!(env, "test.star");
|
|
}
|