core/led: simplify LedChaser (to have the same user interface than GPIOOut).

This commit is contained in:
Florent Kermarrec 2020-05-08 22:13:47 +02:00
parent 05869beb72
commit fbbbdf03b5
1 changed files with 11 additions and 12 deletions

View File

@ -8,27 +8,26 @@ from litex.soc.interconnect.csr import *
# Led Chaser --------------------------------------------------------------------------------------- # Led Chaser ---------------------------------------------------------------------------------------
_CHASER_MODE = 0
_CONTROL_MODE = 1
class LedChaser(Module, AutoCSR): class LedChaser(Module, AutoCSR):
def __init__(self, pads, sys_clk_freq, period=1e0): def __init__(self, pads, sys_clk_freq, period=1e0):
self.control = CSRStorage(fields=[ self._out = CSRStorage(len(pads), description="Led Output(s) Control.")
CSRField("mode", size=2, values=[
("``0b0``", "Chaser mode."),
("``0b1``", "CPU mode."),
])
])
self.value = CSRStorage(len(pads), description="Control value when in CPU mode.")
# # # # # #
n = len(pads) n = len(pads)
chaser = Signal(n) chaser = Signal(n)
timer = WaitTimer(int(period*sys_clk_freq/(2*n))) mode = Signal(reset=_CHASER_MODE)
timer = WaitTimer(int(period*sys_clk_freq/(2*n)))
self.submodules += timer self.submodules += timer
self.comb += timer.wait.eq(~timer.done) self.comb += timer.wait.eq(~timer.done)
self.sync += If(timer.done, chaser.eq(Cat(~chaser[-1], chaser))) self.sync += If(timer.done, chaser.eq(Cat(~chaser[-1], chaser)))
self.sync += If(self._out.re, mode.eq(_CONTROL_MODE))
self.comb += [ self.comb += [
If(self.control.fields.mode, If(mode == _CONTROL_MODE,
pads.eq(self.value.storage) pads.eq(self._out.storage)
).Else( ).Else(
pads.eq(chaser) pads.eq(chaser)
) )