From 5f30a7890a60824ac0a76c409d10b5df0e3c043f Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 3 Oct 2019 02:56:47 +0000 Subject: [PATCH] [breaking-change] Factor out "display_7seg" resource. 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 | 29 ++++++++++++++++++++++++----- nmigen_boards/mercury.py | 21 +++++++++------------ 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/nmigen_boards/dev/user.py b/nmigen_boards/dev/user.py index 3adcbe7..336595e 100644 --- a/nmigen_boards/dev/user.py +++ b/nmigen_boards/dev/user.py @@ -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) diff --git a/nmigen_boards/mercury.py b/nmigen_boards/mercury.py index c14e85c..5395fba 100644 --- a/nmigen_boards/mercury.py +++ b/nmigen_boards/mercury.py @@ -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") ) ] -- 2.30.2