Crates.io | rust_play_digital |
lib.rs | rust_play_digital |
version | |
source | src |
created_at | 2025-04-11 10:25:55.771683+00 |
updated_at | 2025-04-12 06:46:55.737262+00 |
description | This crate implements analog functions of digital circuits.You can build and match different circuits as you want. |
homepage | |
repository | |
max_upload_size | |
id | 1629653 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
This crate implements analog functions of digital circuits.You can build and match different circuits as you want.
A total of 6 structures are provided
Do not use this crate to design unstable circuits. crate will not give correct simulation results in unstable circuits
A circuit contains inputs, logic gates, and outputs. Unstable circuits can occur in the loop circuit, and the loop circuit can occur in the latch circuit. A latch is a special circuit that can maintain the previous output state. It can be used to implement storage units and registers. Suppose you have an OR gate circuit that has one output (o) and two inputs (i1,i2). We connect the output (o) to the input (i1). You can use this crate to simulate this circuit in any input situation. Because the circuit provides a constant fixed output based on the input. When the input (i2) is low, the output (o) will continue to have no electrical signal. When the input (i2) is high once, the output (o) will remain high forever. Suppose you have an XOR gate circuit with one output (o) and two inputs (i1,i2). We connect the output (o) to the input (i1). You cannot use this crate to simulate certain input situations. Because the circuit can't determine the output in those situations. In the real world this circuit is always stable ,and you will never have an active level output because XOR can't provide an output with only one input, We just use the following example to show what you can't simulate with this crate. Suppose at this time the output (o) is high for some reason, and input i2 inputs a high level, the output will be low for the first time, high for the second time, and low for the third time.... We only provide this input and the output will never be certain, that's what you can't simulate with this crate,crate doesn't simulate this phenomenon.
use rust_play_digital::{Digital, Digital1Line, InitSig, OrElectric, TwoInputDigital};
use rust_play_digital::State::{ONE, ZERO};
fn or_loop_circuit() {
let times = 3;
let sig = InitSig::new(vec![Some(ZERO), Some(ONE), Some(ZERO)]);
// OrElectric::process(input_a, input_b)
let or_electric = OrElectric::process(Some(sig),None);
let or_electric = or_electric.set_input_b(Some(or_electric.clone()));
println!("{:?}", or_electric.get_digital_output().output_line_x(0));
}
License: MIT OR Apache-2.0