libttl - A Rust library for simulating TTL logic chips.
This library provides basic building blocks like logic levels and gates, and implements several common 74xx series TTL chips.
Features
LogicLevel
enum (High, Low) with boolean conversions and NOT operation.- Basic logic gate implementations (
NotGate
,AndGate
,OrGate
,NandGate
) behind aGate
trait. Chip
trait defining common chip behavior (pin configuration, input/output, update).- Implementations for:
Chip7400
(Quad 2-Input NAND)Chip7404
(Hex Inverter)Chip7408
(Quad 2-Input AND)Chip7432
(Quad 2-Input OR)
- Clocking support is implicit via the
update()
method on chips, simulating propagation for combinational logic. For sequential circuits (not yet implemented), a circuit simulator would callupdate()
repeatedly.
Example Usage (Testing a 7404 Inverter)
use ;
use ;
// Create a new 7404 chip instance
let mut chip = new;
// --- Test Gate 1 (Input Pin 1, Output Pin 2) ---
// Set Input Pin 1 to Low
chip.set_input;
// Update the chip's internal state
chip.update;
// Check Output Pin 2 (should be High)
assert_eq!;
// Set Input Pin 1 to High
chip.set_input;
// Update the chip's internal state
chip.update;
// Check Output Pin 2 (should be Low)
assert_eq!;