From dda5a167881ddbad69b372a28e208db5fafe4220 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 3 Oct 2019 02:44:43 +0000 Subject: [PATCH] build.dsl: accept Pins(invert=True). The PinsN() form is still preferred, but Pins(invert=) form is useful for code generic over pin polarity. --- nmigen/build/dsl.py | 4 ++-- nmigen/test/test_build_dsl.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nmigen/build/dsl.py b/nmigen/build/dsl.py index ce685f7..721f980 100644 --- a/nmigen/build/dsl.py +++ b/nmigen/build/dsl.py @@ -6,7 +6,7 @@ __all__ = ["Pins", "PinsN", "DiffPairs", "DiffPairsN", class Pins: - def __init__(self, names, *, dir="io", conn=None, assert_width=None): + def __init__(self, names, *, dir="io", invert=False, conn=None, assert_width=None): if not isinstance(names, str): raise TypeError("Names must be a whitespace-separated string, not {!r}" .format(names)) @@ -29,7 +29,7 @@ class Pins: self.names = names self.dir = dir - self.invert = False + self.invert = bool(invert) def __len__(self): return len(self.names) diff --git a/nmigen/test/test_build_dsl.py b/nmigen/test/test_build_dsl.py index 06d2667..1e37d19 100644 --- a/nmigen/test/test_build_dsl.py +++ b/nmigen/test/test_build_dsl.py @@ -18,6 +18,10 @@ class PinsTestCase(FHDLTestCase): self.assertEqual(repr(p), "(pins-n io A0)") self.assertEqual(p.invert, True) + def test_invert_arg(self): + p = Pins("A0", invert=True) + self.assertEqual(p.invert, True) + def test_conn(self): p = Pins("0 1 2", conn=("pmod", 0)) self.assertEqual(list(p), ["pmod_0:0", "pmod_0:1", "pmod_0:2"]) -- 2.30.2