From 2ec4604c41a828634be9029babe17281d4be0825 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Mon, 3 Aug 2020 18:47:17 +0200 Subject: [PATCH] cores/gpio: add support for Record on GPIOOut, GPIOIn and GPIOInOut. --- litex/soc/cores/gpio.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/litex/soc/cores/gpio.py b/litex/soc/cores/gpio.py index 88f1fdce..b74d0c85 100644 --- a/litex/soc/cores/gpio.py +++ b/litex/soc/cores/gpio.py @@ -1,4 +1,5 @@ # This file is Copyright (c) 2013-2015 Sebastien Bourdeauducq +# This file is Copyright (c) 2019-2020 Florent Kermarrec # License: BSD from migen import * @@ -6,26 +7,33 @@ from migen.genlib.cdc import MultiReg from litex.soc.interconnect.csr import * -# GPIO Input ---------------------------------------------------------------------------------------- +# Helpers ------------------------------------------------------------------------------------------ + +def _to_signal(obj): + return obj.raw_bits() if isinstance(obj, Record) else obj + +# GPIO Input --------------------------------------------------------------------------------------- class GPIOIn(Module, AutoCSR): - def __init__(self, signal): - self._in = CSRStatus(len(signal), description="GPIO Input(s) Status.") - self.specials += MultiReg(signal, self._in.status) + def __init__(self, pads): + pads = _to_signal(pads) + self._in = CSRStatus(len(pads), description="GPIO Input(s) Status.") + self.specials += MultiReg(pads, self._in.status) # GPIO Output -------------------------------------------------------------------------------------- class GPIOOut(Module, AutoCSR): - def __init__(self, signal): - self._out = CSRStorage(len(signal), description="GPIO Output(s) Control.") - self.comb += signal.eq(self._out.storage) + def __init__(self, pads): + pads = _to_signal(pads) + self.out = CSRStorage(len(pads), description="GPIO Output(s) Control.") + self.comb += pads.eq(self.out.storage) # GPIO Input/Output -------------------------------------------------------------------------------- class GPIOInOut(Module): - def __init__(self, in_signal, out_signal): - self.submodules.gpio_in = GPIOIn(in_signal) - self.submodules.gpio_out = GPIOOut(out_signal) + def __init__(self, in_pads, out_pads): + self.submodules.gpio_in = GPIOIn(in_pads) + self.submodules.gpio_out = GPIOOut(out_pads) def get_csrs(self): return self.gpio_in.get_csrs() + self.gpio_out.get_csrs() -- 2.30.2