Merge pull request #1117 from enjoy-digital/gpio_tristate

cores/gpio/GPIOTristate: Allow passing platform resource with subsignals directly.
This commit is contained in:
enjoy-digital 2021-11-30 16:07:22 +01:00 committed by GitHub
commit 5e851bd09e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -73,8 +73,8 @@ class GPIOInOut(Module):
class GPIOTristate(_GPIOIRQ, Module, AutoCSR): class GPIOTristate(_GPIOIRQ, Module, AutoCSR):
def __init__(self, pads, with_irq=False): def __init__(self, pads, with_irq=False):
assert isinstance(pads, Signal) or isinstance(pads, Record) internal = not (hasattr(pads, "o") and hasattr(pads, "oe") and hasattr(pads, "i"))
nbits = len(pads) if isinstance(pads, Signal) else len(pads.o) nbits = len(pads) if internal else len(pads.o)
self._oe = CSRStorage(nbits, description="GPIO Tristate(s) Control.") self._oe = CSRStorage(nbits, description="GPIO Tristate(s) Control.")
self._in = CSRStatus(nbits, description="GPIO Input(s) Status.") self._in = CSRStatus(nbits, description="GPIO Input(s) Status.")
@ -82,7 +82,10 @@ class GPIOTristate(_GPIOIRQ, Module, AutoCSR):
# # # # # #
if isinstance(pads, Signal): # Internal Tristate.
if internal:
if isinstance(pads, Record):
pads = pads.flatten()
# Proper inout IOs. # Proper inout IOs.
for i in range(nbits): for i in range(nbits):
t = TSTriple() t = TSTriple()
@ -90,6 +93,8 @@ class GPIOTristate(_GPIOIRQ, Module, AutoCSR):
self.comb += t.oe.eq(self._oe.storage[i]) self.comb += t.oe.eq(self._oe.storage[i])
self.comb += t.o.eq(self._out.storage[i]) self.comb += t.o.eq(self._out.storage[i])
self.specials += MultiReg(t.i, self._in.status[i]) self.specials += MultiReg(t.i, self._in.status[i])
# External Tristate.
else: else:
# Tristate inout IOs (For external tristate IO chips or simulation). # Tristate inout IOs (For external tristate IO chips or simulation).
for i in range(nbits): for i in range(nbits):