Crates.io | virt-ic |
lib.rs | virt-ic |
version | 0.5.2 |
source | src |
created_at | 2020-06-06 22:07:51.717244 |
updated_at | 2023-03-24 23:55:24.546482 |
description | virtual integrated circuits - an backend IC emulator |
homepage | |
repository | https://github.com/VincentFoulon80/virt-ic |
max_upload_size | |
id | 250824 |
size | 220,552 |
This library is a Integrated Circuit Emulator backend that can simulate interactions between multiple chips.
Note that for now there is mostly Digital circuit emulation, Analog signals are kinda present but still need work.
You start by creating a Board, register Chips and Traces, and link Chip pins together to form a virtual circuit. You can then run the circuit to emulate the chips and links between them.
This library is a Backend emulator, it means that there is no GUI to create boards.
The entire library has been rewritten from scratch in order to ease the use of this crate, remove all those Rc<RefCell>
that were degrading the readability of your code. Thus, virt-ic up before 0.5.0 is completely incompatible with newer versions.
This project is open to any contribution, from code reviewing to direct contribution ! You can :
use std::time::Duration;
use virt_ic::{
board::{Board, Trace},
chip::{gates::AndGate, generators::Generator, Chip, ChipBuilder, ChipType},
};
fn main() {
// create a new board
let mut board: Board<ChipType> = Board::new();
// place an AND gate to the board
let and_gate = board.register_chip(AndGate::build());
// also place a generator
let vcc = board.register_chip(Generator::build().into());
let gnd = board.register_chip(Generator::build().with_state(virt_ic::State::Low).into());
// Connect the AndGate's VCC, A and B pins with the Generator
let mut trace = Trace::new();
trace.connect(vcc, Generator::OUT);
trace.connect(and_gate, AndGate::VCC);
trace.connect(and_gate, AndGate::A);
trace.connect(and_gate, AndGate::B);
let trace_vcc = board.register_trace(trace);
// Alternative way to connect chips via board, connect GND pins
let trace_gnd = board.connect(gnd, Generator::OUT, and_gate, AndGate::GND);
// simulate the board for 10ms
board.run(Duration::from_millis(10));
// check the results
if let Some(chip) = board.get_chip(&and_gate) {
println!(
"A={:?}, \tB={:?}, \tA&B={:?}",
chip.get_pin(AndGate::A).map(|p| p.state),
chip.get_pin(AndGate::B).map(|p| p.state),
chip.get_pin(AndGate::AB).map(|p| p.state)
);
}
// disconnect AndGate's pin B from VCC and connect it instead to GND
if let Some(t) = board.get_trace_mut(&trace_vcc) {
t.disconnect(and_gate, AndGate::B)
}
if let Some(t) = board.get_trace_mut(&trace_gnd) {
t.connect(and_gate, AndGate::B)
}
// simulate the board for another 10ms
board.run(Duration::from_millis(10));
// check the results
if let Some(chip) = board.get_chip(&and_gate) {
println!(
"A={:?}, \tB={:?}, \tA&B={:?}",
chip.get_pin(AndGate::A).map(|p| p.state),
chip.get_pin(AndGate::B).map(|p| p.state),
chip.get_pin(AndGate::AB).map(|p| p.state)
);
}
}
Take a look at the generated documentation.
See examples :