From: whitequark Date: Thu, 3 Oct 2019 02:44:43 +0000 (+0000) Subject: build.dsl: accept Pins(invert=True). X-Git-Tag: v0.1rc1~41 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=751ae33fe1a9b34ae9e17e3558fc54df8f74f055;p=nmigen.git build.dsl: accept Pins(invert=True). The PinsN() form is still preferred, but Pins(invert=) form is useful for code generic over pin polarity. --- 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"])