Trait Chip

Source
pub trait Chip:
    Debug
    + Send
    + Sync {
    // Required methods
    fn pin_count(&self) -> usize;
    fn get_pin_type(&self, pin: usize) -> PinType;
    fn set_input(&mut self, pin: usize, level: LogicLevel);
    fn get_output(&self, pin: usize) -> LogicLevel;
    fn update(&mut self);
    fn name(&self) -> &'static str;
    fn box_clone(&self) -> Box<dyn Chip>;
}
Expand description

Trait representing a TTL chip.

Chips are composed of internal gates and have external pins. They maintain the state of their pins and update their outputs based on inputs. The update method simulates one clock cycle or propagation delay step.

Required Methods§

Source

fn pin_count(&self) -> usize

Returns the total number of pins on the chip package.

Source

fn get_pin_type(&self, pin: usize) -> PinType

Gets the type (Input, Output, Vcc, Gnd, Nc) of a specific pin. Pin numbers are typically 1-based, matching datasheets.

§Arguments
  • pin - The 1-based pin number.
§Panics

Panics if the pin number is invalid (0 or > pin_count).

Source

fn set_input(&mut self, pin: usize, level: LogicLevel)

Sets the logic level of an input pin. Pin numbers are 1-based.

§Arguments
  • pin - The 1-based pin number.
  • level - The logic level to set.
§Panics

Panics if the pin number is invalid or if the specified pin is not an Input pin.

Source

fn get_output(&self, pin: usize) -> LogicLevel

Gets the current logic level of an output pin. Pin numbers are 1-based.

§Arguments
  • pin - The 1-based pin number.
§Panics

Panics if the pin number is invalid or if the specified pin is not an Output pin.

Source

fn update(&mut self)

Updates the chip’s internal state. This typically involves:

  1. Reading the current state of input pins.
  2. Propagating these levels through the internal gates.
  3. Updating the state of the output pins based on the gate results. This method simulates a clock tick or propagation delay for combinational logic.
Source

fn name(&self) -> &'static str

Returns the name of the chip (e.g., “7400”).

Source

fn box_clone(&self) -> Box<dyn Chip>

Creates a boxed clone of the chip.

Trait Implementations§

Source§

impl Clone for Box<dyn Chip>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Implementors§