[breaking-change] Factor out "display_7seg" resource.
authorwhitequark <whitequark@whitequark.org>
Thu, 3 Oct 2019 02:56:47 +0000 (02:56 +0000)
committerwhitequark <whitequark@whitequark.org>
Thu, 3 Oct 2019 02:59:20 +0000 (02:59 +0000)
With the expectation that "display_9seg", "display_14seg" and
"display_16seg" will be forthcoming.

There are no provisions in this resource itself for multiplexing
the display. It is expected that on boards with multiplexed displays,
an additional resource "display_7seg_ctrl" will be provided, and it
would have either an n-bit signal "sel" (binary encoded) or an n-bit
signal "en" (one-hot encoded). (This may be revisited in the future.)

Fixes #17.

nmigen_boards/dev/user.py
nmigen_boards/mercury.py

index 3adcbe7df6ec9c1c7902f2ac90f5285f333a70aa..336595eaa7b648a8938ff179fe37af4dc7c318cc 100644 (file)
@@ -1,7 +1,10 @@
 from nmigen.build import *
 
 
-__all__ = ["LEDResources", "RGBLEDResource", "ButtonResources", "SwitchResources"]
+__all__ = [
+    "LEDResources", "RGBLEDResource", "ButtonResources", "SwitchResources",
+    "Display7SegResource",
+]
 
 
 def _SplitResources(*args, pins, invert=False, attrs=None, default_name, dir):
@@ -14,7 +17,7 @@ def _SplitResources(*args, pins, invert=False, attrs=None, default_name, dir):
 
     resources = []
     for number, pin in pins.items():
-        ios = [PinsN(pin, dir=dir) if invert else Pins(pin, dir=dir)]
+        ios = [Pins(pin, dir=dir, invert=invert)]
         if attrs is not None:
             ios.append(attrs)
         resources.append(Resource.family(*args, number, default_name=default_name, ios=ios))
@@ -27,9 +30,9 @@ def LEDResources(*args, **kwargs):
 
 def RGBLEDResource(*args, r, g, b, invert=False, attrs=None):
     ios = []
-    ios.append(Subsignal("r", Pins(r, dir="o", assert_width=1)))
-    ios.append(Subsignal("g", Pins(g, dir="o", assert_width=1)))
-    ios.append(Subsignal("b", Pins(b, dir="o", assert_width=1)))
+    ios.append(Subsignal("r", Pins(r, dir="o", invert=invert, assert_width=1)))
+    ios.append(Subsignal("g", Pins(g, dir="o", invert=invert, assert_width=1)))
+    ios.append(Subsignal("b", Pins(b, dir="o", invert=invert, assert_width=1)))
     if attrs is not None:
         ios.append(attrs)
     return Resource.family(*args, default_name="rgb_led", ios=ios)
@@ -41,3 +44,19 @@ def ButtonResources(*args, **kwargs):
 
 def SwitchResources(*args, **kwargs):
     return _SplitResources(*args, **kwargs, default_name="switch", dir="i")
+
+
+def Display7SegResource(*args, a, b, c, d, e, f, g, dp=None, invert=False, attrs=None):
+    ios = []
+    ios.append(Subsignal("a", Pins(a, dir="o", invert=invert, assert_width=1)))
+    ios.append(Subsignal("b", Pins(b, dir="o", invert=invert, assert_width=1)))
+    ios.append(Subsignal("c", Pins(c, dir="o", invert=invert, assert_width=1)))
+    ios.append(Subsignal("d", Pins(d, dir="o", invert=invert, assert_width=1)))
+    ios.append(Subsignal("e", Pins(e, dir="o", invert=invert, assert_width=1)))
+    ios.append(Subsignal("f", Pins(f, dir="o", invert=invert, assert_width=1)))
+    ios.append(Subsignal("g", Pins(g, dir="o", invert=invert, assert_width=1)))
+    if dp is not None:
+        ios.append(Subsignal("dp", Pins(dp, dir="o", assert_width=1)))
+    if attrs is not None:
+        ios.append(attrs)
+    return Resource.family(*args, default_name="display_7seg", ios=ios)
index c14e85cb8272acfe08b4d1e9dcae473e9f71bbd0..5395fba24433587b731bfe8da6bcf9cab5cc320e 100644 (file)
@@ -4,6 +4,7 @@ import subprocess
 from nmigen.build import *
 from nmigen.vendor.xilinx_spartan_3_6 import *
 from .dev import *
+from .dev.user import Display7SegResource
 
 
 __all__ = ["MercuryPlatform"]
@@ -176,18 +177,14 @@ class MercuryPlatform(XilinxSpartan3APlatform):
     ]
 
     _sevenseg = [
-        Resource("sevenseg", 0,
-             Subsignal("a", PinsN("13", dir="o", conn=("gpio", 0))),
-             Subsignal("b", PinsN("14", dir="o", conn=("gpio", 0))),
-             Subsignal("c", PinsN("15", dir="o", conn=("gpio", 0))),
-             Subsignal("d", PinsN("16", dir="o", conn=("gpio", 0))),
-             Subsignal("e", PinsN("17", dir="o", conn=("gpio", 0))),
-             Subsignal("f", PinsN("18", dir="o", conn=("gpio", 0))),
-             Subsignal("g", PinsN("19", dir="o", conn=("gpio", 0))),
-             Subsignal("dp", PinsN("20", dir="o", conn=("gpio", 0))),
-             Subsignal("en", Pins("9 10 11 12", dir="o",
-                                  conn=("gpio", 0))),
-             Attrs(IOSTANDARD="LVTTL")
+        Display7SegResource(0,
+            a="gpio_0:13", b="gpio_0:14", c="gpio_0:15", d="gpio_0:16",
+            e="gpio_0:17", f="gpio_0:18", g="gpio_0:19", dp="gpio_0:20",
+            invert=True, attrs=Attrs(IOSTANDARD="LVTTL")
+        ),
+        Resource("display_7seg_ctrl", 0,
+            Subsignal("en", Pins("9 10 11 12", dir="o", conn=("gpio", 0))),
+            Attrs(IOSTANDARD="LVTTL")
         )
     ]