compat.fhdl.specials: fix handling of tristate (i=None) pins.
authorwhitequark <whitequark@whitequark.org>
Thu, 2 Jul 2020 22:22:44 +0000 (22:22 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 31 Dec 2021 14:41:29 +0000 (14:41 +0000)
Fixes #406.

nmigen/compat/fhdl/specials.py

index eef5a577fea0ec57e25d087f212b19668f450c22..901fc67b45037c91ad207f310c31173a28f994a0 100644 (file)
@@ -39,16 +39,21 @@ class Tristate(Elaboratable):
         self.i = i if i is not None else None
 
     def elaborate(self, platform):
-        if hasattr(platform, "get_input_output"):
-            pin = Pin(len(self.target), dir="oe" if self.i is None else "io")
+        if self.i is None:
+            pin = Pin(len(self.target), dir="oe")
             pin.o = self.o
             pin.oe = self.oe
-            if self.i is not None:
-                pin.i = self.i
+            return platform.get_tristate(pin, self.target, attrs={}, invert=None)
+        else:
+            pin = Pin(len(self.target), dir="io")
+            pin.o = self.o
+            pin.oe = self.oe
+            pin.i = self.i
             return platform.get_input_output(pin, self.target, attrs={}, invert=None)
 
         m = Module()
-        m.d.comb += self.i.eq(self.target)
+        if self.i is not None:
+            m.d.comb += self.i.eq(self.target)
         m.submodules += Instance("$tribuf",
             p_WIDTH=len(self.target),
             i_EN=self.oe,