From 9113c1a2f9015e2fa86dadb4c61d1993d0e6bced Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Sat, 20 Mar 2021 21:49:12 +0100 Subject: [PATCH] cores/gpio/GPIOIRQ: Add mode CSR (Edge or Change) and rename polarity CSR to edge. Allow interrupts on Change, Rising Edge or Falling Edge. --- litex/soc/cores/gpio.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/litex/soc/cores/gpio.py b/litex/soc/cores/gpio.py index 12239f4c7..daaf9c453 100644 --- a/litex/soc/cores/gpio.py +++ b/litex/soc/cores/gpio.py @@ -20,14 +20,25 @@ def _to_signal(obj): class _GPIOIRQ: def add_irq(self, in_pads): - self._polarity = CSRStorage(len(in_pads), description="GPIO IRQ Polarity: 0: Rising Edge, 1: Falling Edge.") + self._mode = CSRStorage(len(in_pads), description="GPIO IRQ Mode: 0: Edge, 1: Change.") + self._edge = CSRStorage(len(in_pads), description="GPIO IRQ Edge (when in Edge mode): 0: Rising Edge, 1: Falling Edge.") # # # self.submodules.ev = EventManager() for n in range(len(in_pads)): + in_pads_n_d = Signal() + self.sync += in_pads_n_d.eq(in_pads[n]) esp = EventSourceProcess(name=f"i{n}", edge="rising") - self.comb += esp.trigger.eq(in_pads[n] ^ self._polarity.storage[n]) + self.comb += [ + # Change mode. + If(self._mode.storage[n], + esp.trigger.eq(in_pads[n] ^ in_pads_n_d) + # Edge mode. + ).Else( + esp.trigger.eq(in_pads[n] ^ self._edge.storage[n]) + ) + ] setattr(self.ev, f"i{n}", esp) # GPIO Input ---------------------------------------------------------------------------------------