cores/gpio: add support for Record on GPIOOut, GPIOIn and GPIOInOut.
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Mon, 3 Aug 2020 16:47:17 +0000 (18:47 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Mon, 3 Aug 2020 16:47:17 +0000 (18:47 +0200)
litex/soc/cores/gpio.py

index 88f1fdce6bdaf978a679757e6ba357219f0a405e..b74d0c85d12d413cfde7c7ed89efc8b1a0cf86a4 100644 (file)
@@ -1,4 +1,5 @@
 # This file is Copyright (c) 2013-2015 Sebastien Bourdeauducq <sb@m-labs.hk>
+# This file is Copyright (c) 2019-2020 Florent Kermarrec <florent@enjoy-digital.fr>
 # 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()