From 8dd28fecc6348474d61d57fda5eedfbb78cdb7e9 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 2 Jul 2020 22:22:44 +0000 Subject: [PATCH] compat.fhdl.specials: fix handling of tristate (i=None) pins. Fixes #406. --- nmigen/compat/fhdl/specials.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/nmigen/compat/fhdl/specials.py b/nmigen/compat/fhdl/specials.py index eef5a57..901fc67 100644 --- a/nmigen/compat/fhdl/specials.py +++ b/nmigen/compat/fhdl/specials.py @@ -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, -- 2.30.2