From 18f05c13d3dd2adefa493a2ac315da38a94028c9 Mon Sep 17 00:00:00 2001 From: hneemann Date: Wed, 8 Jun 2016 12:41:06 +0200 Subject: [PATCH] Added a driver with inverted select input. This makes it possible to implement transmission gates more simple. --- .../neemann/digital/core/wiring/Driver.java | 12 +++++- .../digital/core/wiring/DriverInvSel.java | 39 +++++++++++++++++++ .../digital/draw/library/ElementLibrary.java | 1 + .../digital/draw/shapes/DriverShape.java | 28 +++++++++++-- .../digital/draw/shapes/ShapeFactory.java | 1 + src/main/resources/lang/lang_de.properties | 1 + src/main/resources/lang/lang_en.properties | 1 + 7 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 src/main/java/de/neemann/digital/core/wiring/DriverInvSel.java diff --git a/src/main/java/de/neemann/digital/core/wiring/Driver.java b/src/main/java/de/neemann/digital/core/wiring/Driver.java index de9ae892a..564e79b9d 100644 --- a/src/main/java/de/neemann/digital/core/wiring/Driver.java +++ b/src/main/java/de/neemann/digital/core/wiring/Driver.java @@ -53,7 +53,17 @@ public class Driver extends Node implements Element { @Override public void writeOutputs() throws NodeException { - output.set(value, !sel); + output.set(value, isOutHigh(sel)); + } + + /** + * Returns the highZ state depending of the sel state + * + * @param sel the selected input + * @return the highZ state + */ + protected boolean isOutHigh(boolean sel) { + return !sel; } @Override diff --git a/src/main/java/de/neemann/digital/core/wiring/DriverInvSel.java b/src/main/java/de/neemann/digital/core/wiring/DriverInvSel.java new file mode 100644 index 000000000..31e39eea9 --- /dev/null +++ b/src/main/java/de/neemann/digital/core/wiring/DriverInvSel.java @@ -0,0 +1,39 @@ +package de.neemann.digital.core.wiring; + +import de.neemann.digital.core.element.ElementAttributes; +import de.neemann.digital.core.element.ElementTypeDescription; +import de.neemann.digital.core.element.Keys; + +import static de.neemann.digital.core.element.PinInfo.input; + +/** + * The Driver + * + * @author hneemann + */ +public class DriverInvSel extends Driver { + + /** + * The Driver description + */ + public static final ElementTypeDescription DESCRIPTION = new ElementTypeDescription(DriverInvSel.class, + input("in"), + input("sel")) + .addAttribute(Keys.ROTATE) + .addAttribute(Keys.BITS) + .addAttribute(Keys.FLIP_SEL_POSITON); + + /** + * Creates a new instance + * + * @param attributes the attributes + */ + public DriverInvSel(ElementAttributes attributes) { + super(attributes); + } + + @Override + protected boolean isOutHigh(boolean sel) { + return sel; + } +} diff --git a/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java b/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java index 327e94a9f..96f99b43f 100644 --- a/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java +++ b/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java @@ -66,6 +66,7 @@ public class ElementLibrary implements Iterable add(Delay.DESCRIPTION, menu); add(Tunnel.DESCRIPTION, menu); add(Driver.DESCRIPTION, menu); + add(DriverInvSel.DESCRIPTION, menu); add(Reset.DESCRIPTION, menu); add(Break.DESCRIPTION, menu); diff --git a/src/main/java/de/neemann/digital/draw/shapes/DriverShape.java b/src/main/java/de/neemann/digital/draw/shapes/DriverShape.java index a5a689922..fd1ff6fd7 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/DriverShape.java +++ b/src/main/java/de/neemann/digital/draw/shapes/DriverShape.java @@ -22,6 +22,7 @@ import static de.neemann.digital.draw.shapes.GenericShape.SIZE2; */ public class DriverShape implements Shape { private final boolean bottom; + private final boolean invertedInput; private final PinDescriptions inputs; private final PinDescriptions outputs; private Pins pins; @@ -34,9 +35,21 @@ public class DriverShape implements Shape { * @param outputs the outputs */ public DriverShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) { + this(attr, inputs, outputs, false); + } + + /** + * Creates a new instance + * + * @param attr the attributes + * @param inputs the inputs + * @param outputs the outputs + */ + public DriverShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs, boolean invertedInput) { this.inputs = inputs; this.outputs = outputs; this.bottom = attr.get(Keys.FLIP_SEL_POSITON); + this.invertedInput = invertedInput; } @Override @@ -63,9 +76,16 @@ public class DriverShape implements Shape { .add(SIZE - 1, 0) .add(-SIZE + 1, SIZE2 + 2), Style.NORMAL ); - if (bottom) - graphic.drawLine(new Vector(0, SIZE), new Vector(0, 7), Style.NORMAL); - else - graphic.drawLine(new Vector(0, -SIZE), new Vector(0, -7), Style.NORMAL); + if (bottom) { + if (invertedInput) + graphic.drawCircle(new Vector(-SIZE2 + 4, SIZE), new Vector(SIZE2 - 4, 8), Style.NORMAL); + else + graphic.drawLine(new Vector(0, SIZE), new Vector(0, 7), Style.NORMAL); + } else { + if (invertedInput) + graphic.drawCircle(new Vector(-SIZE2 + 4, -SIZE), new Vector(SIZE2 - 4, -8), Style.NORMAL); + else + graphic.drawLine(new Vector(0, -SIZE), new Vector(0, -7), Style.NORMAL); + } } } diff --git a/src/main/java/de/neemann/digital/draw/shapes/ShapeFactory.java b/src/main/java/de/neemann/digital/draw/shapes/ShapeFactory.java index 9a3beda0a..731819eaa 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/ShapeFactory.java +++ b/src/main/java/de/neemann/digital/draw/shapes/ShapeFactory.java @@ -92,6 +92,7 @@ public final class ShapeFactory { map.put(Splitter.DESCRIPTION.getName(), SplitterShape::new); map.put(Driver.DESCRIPTION.getName(), DriverShape::new); + map.put(DriverInvSel.DESCRIPTION.getName(), (attributes, inputs, outputs) -> new DriverShape(attributes, inputs, outputs, true)); map.put(Tunnel.DESCRIPTION.getName(), TunnelShape::new); map.put(DummyElement.TEXTDESCRIPTION.getName(), TextShape::new); diff --git a/src/main/resources/lang/lang_de.properties b/src/main/resources/lang/lang_de.properties index 672fc9bdb..8b57890c7 100644 --- a/src/main/resources/lang/lang_de.properties +++ b/src/main/resources/lang/lang_de.properties @@ -103,6 +103,7 @@ elem_Clock_tt=Ein Takstignal. Dieses Taksignal kann \u00FCber die Echtzeituhr ge elem_Delay=Verz\u00F6gerung elem_Delay_tt=Verz\u00F6gert ein Signal f\u00FCr eine Gatterlaufzeit. elem_Driver=Treiber +elem_DriverInvSel=Treiber, invertierte Auswahl elem_Reset=Reset elem_Reset_tt=Der Ausgang dieses Elements ist Null, solange sich die Schaltung nach dem Einschalten in der Stabilisierungsphase befindet.\nHat sich die Schaltung stabilisiert wird der Ausgang auf Eins gesetzt. elem_Break=Break diff --git a/src/main/resources/lang/lang_en.properties b/src/main/resources/lang/lang_en.properties index eba57e26e..f33116030 100644 --- a/src/main/resources/lang/lang_en.properties +++ b/src/main/resources/lang/lang_en.properties @@ -91,6 +91,7 @@ elem_Clock_tt=A clock signal. Its possible to control it by the real time clock. elem_Delay=Delay elem_Delay_tt=Delays the signal by on gate delay elem_Driver=Driver +elem_DriverInvSel=Driver, inverted select elem_Reset=Reset elem_Reset_tt=The output of this element is hold down during the initialisation of the circuit.\nAfter the circuit has stabilized the output goes up. elem_Break=Break