Skip to content

Commit

Permalink
Remove settings from pushbutton and switch
Browse files Browse the repository at this point in the history
  • Loading branch information
freand76 committed Dec 9, 2023
1 parent 47ca408 commit 6753b85
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 106 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## vx.x.x
* Fix bug when detecting number of modules with yosys 0.9
* Improve error handling for yosys component
* Remove settings from pushbutton and switch

## v0.0.1 - First Release
* Simulation of a digital circuit using a python
Expand Down
58 changes: 40 additions & 18 deletions example_circuits/74162_counter.circuit
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
"name": "OnOffSwitch",
"display_name": "OnOffSwitch",
"type": "digsim.circuit.components.OnOffSwitch",
"settings": {
"start_on": false
}
"settings": {}
},
{
"name": "Led",
Expand All @@ -50,9 +48,7 @@
"name": "PushButton",
"display_name": "PushButton",
"type": "digsim.circuit.components.PushButton",
"settings": {
"inverted": false
}
"settings": {}
},
{
"name": "DipSwitch",
Expand All @@ -74,17 +70,25 @@
"name": "PushButton_1",
"display_name": "PushButton",
"type": "digsim.circuit.components.PushButton",
"settings": {
"inverted": true
}
"settings": {}
},
{
"name": "PushButton_2",
"display_name": "PushButton",
"type": "digsim.circuit.components.PushButton",
"settings": {
"inverted": true
}
"settings": {}
},
{
"name": "NOT",
"display_name": "NOT",
"type": "digsim.circuit.components.NOT",
"settings": {}
},
{
"name": "NOT_1",
"display_name": "NOT",
"type": "digsim.circuit.components.NOT",
"settings": {}
}
],
"wires": [
Expand Down Expand Up @@ -162,11 +166,19 @@
},
{
"src": "PushButton_1.O",
"dst": "ttl_74162.Clear_bar"
"dst": "NOT_1.A"
},
{
"src": "PushButton_2.O",
"dst": "NOT.A"
},
{
"src": "NOT.Y",
"dst": "ttl_74162.Load_bar"
},
{
"src": "NOT_1.Y",
"dst": "ttl_74162.Clear_bar"
}
]
},
Expand Down Expand Up @@ -198,7 +210,7 @@
},
"Led": {
"x": 735,
"y": 232,
"y": 231,
"z": 0.0
},
"PushButton": {
Expand All @@ -217,13 +229,23 @@
"z": 0.0
},
"PushButton_1": {
"x": 74,
"y": 110,
"x": -13,
"y": 41,
"z": 0.0
},
"PushButton_2": {
"x": -38,
"y": 172,
"x": -13,
"y": 142,
"z": 0.0
},
"NOT": {
"x": 172,
"y": 142,
"z": 0.0
},
"NOT_1": {
"x": 194,
"y": 41,
"z": 0.0
}
},
Expand Down
20 changes: 5 additions & 15 deletions example_circuits/buzzers.circuit
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,31 @@
"name": "PushButton",
"display_name": "PushButton",
"type": "digsim.circuit.components.PushButton",
"settings": {
"inverted": false
}
"settings": {}
},
{
"name": "PushButton_1",
"display_name": "PushButton",
"type": "digsim.circuit.components.PushButton",
"settings": {
"inverted": false
}
"settings": {}
},
{
"name": "PushButton_2",
"display_name": "PushButton",
"type": "digsim.circuit.components.PushButton",
"settings": {
"inverted": false
}
"settings": {}
},
{
"name": "PushButton_3",
"display_name": "PushButton",
"type": "digsim.circuit.components.PushButton",
"settings": {
"inverted": false
}
"settings": {}
},
{
"name": "PushButton_4",
"display_name": "PushButton",
"type": "digsim.circuit.components.PushButton",
"settings": {
"inverted": false
}
"settings": {}
},
{
"name": "Buzzer_2",
Expand Down
8 changes: 2 additions & 6 deletions example_circuits/counter_yosys_netlist.circuit
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
"name": "PushButton_2",
"display_name": "PushButton",
"type": "digsim.circuit.components.PushButton",
"settings": {
"inverted": false
}
"settings": {}
},
{
"name": "HexDigit_4",
Expand All @@ -39,9 +37,7 @@
"name": "OnOffSwitch",
"display_name": "OnOffSwitch",
"type": "digsim.circuit.components.OnOffSwitch",
"settings": {
"start_on": false
}
"settings": {}
},
{
"name": "Led",
Expand Down
8 changes: 2 additions & 6 deletions example_circuits/counter_yosys_verilog.circuit
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
"name": "PushButton_2",
"display_name": "PushButton",
"type": "digsim.circuit.components.PushButton",
"settings": {
"inverted": false
}
"settings": {}
},
{
"name": "HexDigit_4",
Expand All @@ -39,9 +37,7 @@
"name": "OnOffSwitch",
"display_name": "OnOffSwitch",
"type": "digsim.circuit.components.OnOffSwitch",
"settings": {
"start_on": false
}
"settings": {}
},
{
"name": "Led",
Expand Down
4 changes: 1 addition & 3 deletions example_circuits/shift_register.circuit
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@
"name": "PushButton",
"display_name": "PushButton",
"type": "digsim.circuit.components.PushButton",
"settings": {
"inverted": false
}
"settings": {}
},
{
"name": "Clock",
Expand Down
17 changes: 12 additions & 5 deletions examples/example_sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def led_callback(comp):


circuit = Circuit(vcd="sr.vcd")
BS = PushButton(circuit, "S-Button", inverted=True)
BR = PushButton(circuit, "R-Button", inverted=True)
BS = PushButton(circuit, "S-Button")
BR = PushButton(circuit, "R-Button")
SR = SR(circuit)
D1 = Led(circuit, "D1", callback=led_callback)
BS.O.wire = SR.nS
BR.O.wire = SR.nR
BS.O.wire = SR.S
BR.O.wire = SR.R
SR.Q.wire = D1.I
circuit.init()
circuit.run(ms=10)
Expand All @@ -43,6 +43,13 @@ def led_callback(comp):
circuit.run(ms=10)
BS.release()
circuit.run(ms=10)

print("Set (again)")
BS.push()
circuit.run(ms=10)
BS.release()
print("Reset")
BR.push()
circuit.run(ms=10)
BR.release()

circuit.vcd_close()
6 changes: 2 additions & 4 deletions examples/load_save/pulse_circuit.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"name": "Button",
"display_name": "PushButton",
"type": "digsim.circuit.components.PushButton",
"settings": {
"inverted": false
}
"settings": {}
},
{
"name": "not1",
Expand Down Expand Up @@ -70,4 +68,4 @@
}
]
}
}
}
26 changes: 6 additions & 20 deletions src/digsim/circuit/components/_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

""" A PushButton component """

import logging

from .atoms import CallbackComponent, PortOutImmediate


Expand All @@ -14,24 +16,19 @@ def __init__(self, circuit, name=None, inverted=False):
portout = PortOutImmediate(self, "O")
self.add_port(portout)
portout.update_parent(True)
self.parameter_set("inverted", inverted)
if inverted:
logging.warning("Setting 'inverted' has been removed")

def default_state(self):
self.release()

def push(self):
"""Push pushbutton"""
if self.parameter_get("inverted"):
self.O.value = 0
else:
self.O.value = 1
self.O.value = 1

def release(self):
"""Release pushbutton"""
if self.parameter_get("inverted"):
self.O.value = 1
else:
self.O.value = 0
self.O.value = 0

def reconfigure(self):
self.release()
Expand All @@ -49,14 +46,3 @@ def onpress(self):

def onrelease(self):
self.release()

@classmethod
def get_parameters(cls):
return {
"inverted": {
"type": bool,
"default": False,
"description": "Button output is inverted",
"reconfigurable": True,
},
}
16 changes: 8 additions & 8 deletions src/digsim/circuit/components/_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,18 @@ class SR(MultiComponent):

def __init__(self, circuit, name=None):
super().__init__(circuit, name)
_nands = NAND(circuit)
_nandr = NAND(circuit)
_nands = NOR(circuit)
_nandr = NOR(circuit)
self.add(_nands)
self.add(_nandr)
_nands.Y.wire = _nandr.A
_nandr.Y.wire = _nands.B
self.add_port(PortWire(self, "nS"))
self.add_port(PortWire(self, "nR"))
self.add_port(PortWire(self, "S"))
self.add_port(PortWire(self, "R"))
self.add_port(PortWire(self, "Q"))
self.add_port(PortWire(self, "nQ"))

self.nS.wire = _nands.A
self.nR.wire = _nandr.B
_nands.Y.wire = self.Q
_nandr.Y.wire = self.nQ
self.S.wire = _nands.A
self.R.wire = _nandr.B
_nands.Y.wire = self.nQ
_nandr.Y.wire = self.Q
Loading

0 comments on commit 6753b85

Please sign in to comment.