build.dsl: accept Pins(invert=True).
authorwhitequark <cz@m-labs.hk>
Thu, 3 Oct 2019 02:44:43 +0000 (02:44 +0000)
committerwhitequark <cz@m-labs.hk>
Thu, 3 Oct 2019 02:44:43 +0000 (02:44 +0000)
The PinsN() form is still preferred, but Pins(invert=) form is useful
for code generic over pin polarity.

nmigen/build/dsl.py
nmigen/test/test_build_dsl.py

index ce685f7e97ea39078dc1c8a86933ceac6039ebae..721f980ebc74f1b0ca41953f78d69693042f5913 100644 (file)
@@ -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)
index 06d2667225ea7a638f4850e8150a1c280412a2ac..1e37d1910dd6a531eb74111f38b38a6d3da42e32 100644 (file)
@@ -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"])