Updated functionality of the extend_bus method.
This commit is contained in:
parent
2083ed35a1
commit
c8ed08691f
@ -48,19 +48,24 @@ class Bus():
|
|||||||
"""
|
"""
|
||||||
return self.out_bus
|
return self.out_bus
|
||||||
|
|
||||||
def bus_extend(self, N: int, prefix: str = "bus"):
|
def bus_extend(self, N: int, prefix: str = "bus", last_wire_extend: bool = True):
|
||||||
"""Provides bus extension to contain more wires.
|
"""Provides bus extension to contain more wires.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
N (int): Number of wires in the bus. Defaults to 1.
|
N (int): Number of wires in the bus. Defaults to 1.
|
||||||
prefix (str, optional): Prefix name of the bus. Defaults to "bus".
|
prefix (str, optional): Prefix name of the bus. Defaults to "bus".
|
||||||
|
last_wire_extend (bool, optional): Specifies whether the last wire of the bus should be extended (connected) to all the extending wires. Defaults to True.
|
||||||
"""
|
"""
|
||||||
# Checks if any extension is neccesarry and if so, proceeds to wire extend the bus
|
# Checks if any extension is neccesarry and if so, proceeds to wire extend the bus
|
||||||
if self.N < N:
|
if self.N < N:
|
||||||
# Adding wires into current bus's wires list (wire names are concatenated from bus prefix and their index position inside the bus in square brackets)
|
# Adding wires into current bus's wires list (wire names are concatenated from bus prefix and their index position inside the bus in square brackets)
|
||||||
self.bus += [Wire(name=prefix+f"[{i}]", prefix=prefix, index=i, parent_bus=self) for i in range(self.N, N)]
|
self.bus += [Wire(name=prefix+f"[{i}]", prefix=prefix, index=i, parent_bus=self) for i in range(self.N, N)]
|
||||||
|
if last_wire_extend is True:
|
||||||
|
for w_index in range(self.N, N):
|
||||||
|
self.connect(bus_wire_index=w_index, inner_component_out_wire=self.get_wire(self.N - 1))
|
||||||
self.N = N
|
self.N = N
|
||||||
|
|
||||||
|
|
||||||
def get_wire(self, wire_index: int = 0):
|
def get_wire(self, wire_index: int = 0):
|
||||||
"""Retrieves a wire from the bus by a given index.
|
"""Retrieves a wire from the bus by a given index.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user