Skip to content

Commit

Permalink
Added tri-state buffer (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesjiang52 committed Nov 8, 2018
1 parent eb8e565 commit 063fe55
Show file tree
Hide file tree
Showing 22 changed files with 253 additions and 24 deletions.
39 changes: 39 additions & 0 deletions bitwise/wire/TRI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
The following classes are defined:
TristateBuffer
"""


class TristateBuffer:
"""Initialize a new tri-state buffer.
Args:
input_1: An object of type Wire.
switch: An object of type Wire.
output: An object of type Wire. Takes on the value of input_1 if switch
has value 1. Otherwise, value is independent of input_1.
"""
def __init__(self, input_1, switch, output):
self.input_1 = input_1
self.switch = switch
self.output = output

self.input_1._bind_to(self._update_input_1)
self.switch._bind_to(self._update_switch)

if switch.value == 1:
self.output.value = self.input_1.value
else:
pass

def _update_input_1(self, value):
if self.switch.value == 1:
self.output.value = value
else:
pass

def _update_switch(self, value):
if value == 1:
self.output.value = self.input_1.value
else:
pass
9 changes: 5 additions & 4 deletions bitwise/wire/WIRE.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@


class Wire:
"""Initialize a new wire with value 0. After initialization, the value of the wire can be both
accessed and mutated using wire.value.
"""Initialize a new wire with value 0. After initialization, the value of
the wire can be both accessed and mutated using wire.value.
Raises:
ValueError: If value assigned to wire is not 0 or 1.
"""
Expand All @@ -31,4 +31,5 @@ def value(self, value):
callback(self._value)

def _bind_to(self, callback):
self.connections.append(callback)
if callback not in self.connections:
self.connections.append(callback)
1 change: 1 addition & 0 deletions bitwise/wire/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .CLK import *
from .BUS import *
from .TRI import *
from .WIRE import *
Binary file modified docs/_build/doctrees/api.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/changelog.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/_build/doctrees/wire.doctree
Binary file not shown.
1 change: 1 addition & 0 deletions docs/_build/html/_sources/api.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,5 @@ API Documentation
* :ref:`Bus8`
* :ref:`Bus16`
* :ref:`BusSevenSegmentDisplay`
* :ref:`TristateBuffer`
* :ref:`Wire`
23 changes: 19 additions & 4 deletions docs/_build/html/_sources/changelog.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,32 @@ Unreleased

Added
-----
* Shift register classes to storage subpackage
* Tri-state buffer to wire subpackage
* Ring counter classes to state subpackage
* ``RingCounter4``
* ``RingCounter8``
* ``RingCounter16``

* Up- and down-counter classes to state subpackage
* ``UpCounterMod4``
* ``UpCounterMod8``
* ``UpCounterMod16``
* ``DownCounterMod4``
* ``DownCounterMod8``
* ``DownCounterMod16``

* ``IMPLY`` logic gate to gate subpackage
* Shift register classes to state subpackage
* ``ShiftRegister4``
* ``ShiftRegister8``
* ``ShiftRegister16``

* Parallel-to-serial converter classes to signal subpackage
* Parallel-to-serial converter classes to state subpackage
* ``ParallelToSerialConverter4To1``
* ``ParallelToSerialConverter8To1``
* ``ParallelToSerialConverter16To1``

* Serial-to-parallel converter classes to signal subpackage
* Serial-to-parallel converter classes to state subpackage
* ``SerialToParallelConverter1To4``
* ``SerialToParallelConverter1To8``
* ``SerialToParallelConverter1To16``
Expand All @@ -31,7 +46,7 @@ Added

Changed
-------
* Rewrote docstrings for all classes
* Rewrote docstrings for all existing classes
* Misc improvements


Expand Down
32 changes: 32 additions & 0 deletions docs/_build/html/_sources/wire.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,38 @@ Accessors:
* ``bus.wire_values``: A tuple of values of the wires in the bus.


.. _TristateBuffer:

TristateBuffer
==============

Class ``bw.wire.TristateBuffer``
--------------------------------

Defined in `bitwise/wire/TRI.py <https://github.com/jamesjiang52/Bitwise/blob/master/bitwise/wire/TRI.py>`_.

`Tri-state buffer <https://en.wikipedia.org/wiki/Three-state_logic>`_.

__init__
--------

::

__init__(
input_1,
switch,
output
)

Initialize a new tri-state buffer.

Args:
~~~~~
* ``input_1``: An object of type ``Wire``.
* ``switch``: An object of type ``Wire``.
* ``output``: An object of type ``Wire``. Takes on the value of ``input_1`` if ``switch`` has value 1. Otherwise, value is independent of ``input_1``.


.. _Wire:

Wire
Expand Down
3 changes: 2 additions & 1 deletion docs/_build/html/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ <h2><a class="reference internal" href="wire.html"><span class="doc">Wire</span>
<li><a class="reference internal" href="wire.html#bus8"><span class="std std-ref">Bus8</span></a></li>
<li><a class="reference internal" href="wire.html#bus16"><span class="std std-ref">Bus16</span></a></li>
<li><a class="reference internal" href="wire.html#bussevensegmentdisplay"><span class="std std-ref">BusSevenSegmentDisplay</span></a></li>
<li><a class="reference internal" href="wire.html#id17"><span class="std std-ref">Wire</span></a></li>
<li><a class="reference internal" href="wire.html#tristatebuffer"><span class="std std-ref">TristateBuffer</span></a></li>
<li><a class="reference internal" href="wire.html#id20"><span class="std std-ref">Wire</span></a></li>
</ul>
</div>
</div>
Expand Down
33 changes: 29 additions & 4 deletions docs/_build/html/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,33 @@ <h2>Unreleased</h2>
<div class="section" id="added">
<h3>Added</h3>
<ul class="simple">
<li>Tri-state buffer to wire subpackage</li>
<li><dl class="first docutils">
<dt>Shift register classes to storage subpackage</dt>
<dt>Ring counter classes to state subpackage</dt>
<dd><ul class="first last">
<li><code class="docutils literal"><span class="pre">RingCounter4</span></code></li>
<li><code class="docutils literal"><span class="pre">RingCounter8</span></code></li>
<li><code class="docutils literal"><span class="pre">RingCounter16</span></code></li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>Up- and down-counter classes to state subpackage</dt>
<dd><ul class="first last">
<li><code class="docutils literal"><span class="pre">UpCounterMod4</span></code></li>
<li><code class="docutils literal"><span class="pre">UpCounterMod8</span></code></li>
<li><code class="docutils literal"><span class="pre">UpCounterMod16</span></code></li>
<li><code class="docutils literal"><span class="pre">DownCounterMod4</span></code></li>
<li><code class="docutils literal"><span class="pre">DownCounterMod8</span></code></li>
<li><code class="docutils literal"><span class="pre">DownCounterMod16</span></code></li>
</ul>
</dd>
</dl>
</li>
<li><code class="docutils literal"><span class="pre">IMPLY</span></code> logic gate to gate subpackage</li>
<li><dl class="first docutils">
<dt>Shift register classes to state subpackage</dt>
<dd><ul class="first last">
<li><code class="docutils literal"><span class="pre">ShiftRegister4</span></code></li>
<li><code class="docutils literal"><span class="pre">ShiftRegister8</span></code></li>
Expand All @@ -115,7 +140,7 @@ <h3>Added</h3>
</dl>
</li>
<li><dl class="first docutils">
<dt>Parallel-to-serial converter classes to signal subpackage</dt>
<dt>Parallel-to-serial converter classes to state subpackage</dt>
<dd><ul class="first last">
<li><code class="docutils literal"><span class="pre">ParallelToSerialConverter4To1</span></code></li>
<li><code class="docutils literal"><span class="pre">ParallelToSerialConverter8To1</span></code></li>
Expand All @@ -125,7 +150,7 @@ <h3>Added</h3>
</dl>
</li>
<li><dl class="first docutils">
<dt>Serial-to-parallel converter classes to signal subpackage</dt>
<dt>Serial-to-parallel converter classes to state subpackage</dt>
<dd><ul class="first last">
<li><code class="docutils literal"><span class="pre">SerialToParallelConverter1To4</span></code></li>
<li><code class="docutils literal"><span class="pre">SerialToParallelConverter1To8</span></code></li>
Expand All @@ -141,7 +166,7 @@ <h3>Added</h3>
<div class="section" id="changed">
<h3>Changed</h3>
<ul class="simple">
<li>Rewrote docstrings for all classes</li>
<li>Rewrote docstrings for all existing classes</li>
<li>Misc improvements</li>
</ul>
</div>
Expand Down
Binary file modified docs/_build/html/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/_build/html/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/_build/html/signal.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<link rel="shortcut icon" href="_static/favicon.ico"/>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Storage" href="storage.html" />
<link rel="next" title="State" href="state.html" />
<link rel="prev" title="Logic" href="logic.html" />

<link rel="stylesheet" href="_static/custom.css" type="text/css" />
Expand Down
2 changes: 2 additions & 0 deletions docs/_build/html/state.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<link rel="shortcut icon" href="_static/favicon.ico"/>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Storage" href="storage.html" />
<link rel="prev" title="Signal" href="signal.html" />

<link rel="stylesheet" href="_static/custom.css" type="text/css" />

Expand Down
2 changes: 1 addition & 1 deletion docs/_build/html/storage.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Wire" href="wire.html" />
<link rel="prev" title="Signal" href="signal.html" />
<link rel="prev" title="State" href="state.html" />

<link rel="stylesheet" href="_static/custom.css" type="text/css" />

Expand Down
36 changes: 32 additions & 4 deletions docs/_build/html/wire.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ <h3><a href="index.html">Table Of Contents</a></h3>
<li><a class="reference internal" href="#bus8">Bus8</a></li>
<li><a class="reference internal" href="#bus16">Bus16</a></li>
<li><a class="reference internal" href="#bussevensegmentdisplay">BusSevenSegmentDisplay</a></li>
<li><a class="reference internal" href="#id17">Wire</a></li>
<li><a class="reference internal" href="#tristatebuffer">TristateBuffer</a></li>
<li><a class="reference internal" href="#id20">Wire</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -252,14 +253,41 @@ <h3>Accessors:</h3>
</ul>
</div>
</div>
<div class="section" id="id17">
<span id="id18"></span><h2>Wire</h2>
<div class="section" id="tristatebuffer">
<span id="id17"></span><h2>TristateBuffer</h2>
<div class="section" id="class-bw-wire-tristatebuffer">
<h3>Class <code class="docutils literal"><span class="pre">bw.wire.TristateBuffer</span></code></h3>
<p>Defined in <a class="reference external" href="https://github.com/jamesjiang52/Bitwise/blob/master/bitwise/wire/TRI.py">bitwise/wire/TRI.py</a>.</p>
<p><a class="reference external" href="https://en.wikipedia.org/wiki/Three-state_logic">Tri-state buffer</a>.</p>
</div>
<div class="section" id="id18">
<h3>__init__</h3>
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="fm">__init__</span><span class="p">(</span>
<span class="n">input_1</span><span class="p">,</span>
<span class="n">switch</span><span class="p">,</span>
<span class="n">output</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Initialize a new tri-state buffer.</p>
<div class="section" id="id19">
<h4>Args:</h4>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">input_1</span></code>: An object of type <code class="docutils literal"><span class="pre">Wire</span></code>.</li>
<li><code class="docutils literal"><span class="pre">switch</span></code>: An object of type <code class="docutils literal"><span class="pre">Wire</span></code>.</li>
<li><code class="docutils literal"><span class="pre">output</span></code>: An object of type <code class="docutils literal"><span class="pre">Wire</span></code>. Takes on the value of <code class="docutils literal"><span class="pre">input_1</span></code> if <code class="docutils literal"><span class="pre">switch</span></code> has value 1. Otherwise, value is independent of <code class="docutils literal"><span class="pre">input_1</span></code>.</li>
</ul>
</div>
</div>
</div>
<div class="section" id="id20">
<span id="id21"></span><h2>Wire</h2>
<div class="section" id="class-bw-wire-wire">
<h3>Class <code class="docutils literal"><span class="pre">bw.wire.Wire</span></code></h3>
<p>Defined in <a class="reference external" href="https://github.com/jamesjiang52/Bitwise/blob/master/bitwise/wire/WIRE.py">bitwise/wire/WIRE.py</a>.</p>
<p>A wire, with either a 0 or 1 integer value.</p>
</div>
<div class="section" id="id19">
<div class="section" id="id22">
<h3>__init__</h3>
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="fm">__init__</span><span class="p">()</span>
</pre></div>
Expand Down
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,5 @@ API Documentation
* :ref:`Bus8`
* :ref:`Bus16`
* :ref:`BusSevenSegmentDisplay`
* :ref:`TristateBuffer`
* :ref:`Wire`
23 changes: 19 additions & 4 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,32 @@ Unreleased

Added
-----
* Shift register classes to storage subpackage
* Tri-state buffer to wire subpackage
* Ring counter classes to state subpackage
* ``RingCounter4``
* ``RingCounter8``
* ``RingCounter16``

* Up- and down-counter classes to state subpackage
* ``UpCounterMod4``
* ``UpCounterMod8``
* ``UpCounterMod16``
* ``DownCounterMod4``
* ``DownCounterMod8``
* ``DownCounterMod16``

* ``IMPLY`` logic gate to gate subpackage
* Shift register classes to state subpackage
* ``ShiftRegister4``
* ``ShiftRegister8``
* ``ShiftRegister16``

* Parallel-to-serial converter classes to signal subpackage
* Parallel-to-serial converter classes to state subpackage
* ``ParallelToSerialConverter4To1``
* ``ParallelToSerialConverter8To1``
* ``ParallelToSerialConverter16To1``

* Serial-to-parallel converter classes to signal subpackage
* Serial-to-parallel converter classes to state subpackage
* ``SerialToParallelConverter1To4``
* ``SerialToParallelConverter1To8``
* ``SerialToParallelConverter1To16``
Expand All @@ -31,7 +46,7 @@ Added

Changed
-------
* Rewrote docstrings for all classes
* Rewrote docstrings for all existing classes
* Misc improvements


Expand Down
32 changes: 32 additions & 0 deletions docs/wire.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,38 @@ Accessors:
* ``bus.wire_values``: A tuple of values of the wires in the bus.


.. _TristateBuffer:

TristateBuffer
==============

Class ``bw.wire.TristateBuffer``
--------------------------------

Defined in `bitwise/wire/TRI.py <https://github.com/jamesjiang52/Bitwise/blob/master/bitwise/wire/TRI.py>`_.

`Tri-state buffer <https://en.wikipedia.org/wiki/Three-state_logic>`_.

__init__
--------

::

__init__(
input_1,
switch,
output
)

Initialize a new tri-state buffer.

Args:
~~~~~
* ``input_1``: An object of type ``Wire``.
* ``switch``: An object of type ``Wire``.
* ``output``: An object of type ``Wire``. Takes on the value of ``input_1`` if ``switch`` has value 1. Otherwise, value is independent of ``input_1``.


.. _Wire:

Wire
Expand Down
Loading

0 comments on commit 063fe55

Please sign in to comment.