From a0cb436467043cb487e8f0e1ddd4e962c3c0ccca Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Tue, 7 Nov 2023 20:15:07 +0100 Subject: [PATCH] build/gowin/common: adding Tristate support --- litex/build/gowin/common.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/litex/build/gowin/common.py b/litex/build/gowin/common.py index 395d8c66a..4510a1dc6 100644 --- a/litex/build/gowin/common.py +++ b/litex/build/gowin/common.py @@ -96,6 +96,25 @@ class GowinDifferentialOutput: def lower(dr): return GowinDifferentialOutputImpl(dr.i, dr.o_p, dr.o_n) +# Gowin Tristate ----------------------------------------------------------------------------------- + +class GowinTristateImpl(Module): + def __init__(self, io, o, oe, i): + nbits, _ = value_bits_sign(io) + for bit in range(nbits): + self.specials += Instance("IOBUF", + io_IO = io[bit] if nbits > 1 else io, + o_O = i[bit] if nbits > 1 else i, + i_I = o[bit] if nbits > 1 else o, + i_OEN = ~oe, + ) + +class GowinTristate: + @staticmethod + def lower(dr): + print(dr) + return GowinTristateImpl(dr.target, dr.o, dr.oe, dr.i) + # Gowin Special Overrides -------------------------------------------------------------------------- gowin_special_overrides = { @@ -104,4 +123,5 @@ gowin_special_overrides = { DDROutput: GowinDDROutput, DifferentialInput: GowinDifferentialInput, DifferentialOutput: GowinDifferentialOutput, + Tristate: GowinTristate, }