Expand description
§DESCRIBE
§WHAT THIS CRATE FUNCTION
This crate implements analog functions of digital circuits.You can build and match different circuits as you want.
§WHAT THIS CRATE PROVIDE FOR YOU
A total of 6 structures are provided
- The four structures represent the AND, OR, NOT, and XOR logic circuits
- One structure represents the initial set of signals provided by the power supply
- One structure represents the high and low levels, or sampling points.
§NOTES
Do not use this crate to design unstable circuits. crate will not give correct simulation results in unstable circuits
§WHAT IS 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.
§EXAMPLE
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));
}
Macros§
Structs§
- AndElectric
- AndElectric structure represent the AND logic circuit
- Digital
State - The DigitalState structure represents the output of the digital circuit The output may have multiple lines, and each line may have a continuous signal (State).
- InitSig
- The InitSig structure provides the initial input level signal source for the circuit.
- NotElectric
- NotElectric structure represent the NOT logic circuit
- OrElectric
- OrElectric structure represent the OR logic circuit
- XORElectric
- XORElectric structure represent the XOR logic circuit
Enums§
- State
- represents the high and low levels, or sampling points.
Traits§
- Digital
- All six provided structs implement Digital traits
- Digital1
Line - OneInput
Electric - NOT structures implement OneInputElectric trait
- TwoInput
Digital - AND OR XOR, these three structures implement TwoInputDigital trait