From 52bcf5f6faa09e2ac74a4c446090215e89a8e0fa Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 23 Sep 2019 08:16:07 +0000 Subject: =?UTF-8?q?=5Fblinky=E2=86=92test.blinky?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Expose blinky as a stable component, to make writing out-of-tree board files a bit nicer. --- nmigen_boards/test/blinky.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 nmigen_boards/test/blinky.py (limited to 'nmigen_boards/test/blinky.py') diff --git a/nmigen_boards/test/blinky.py b/nmigen_boards/test/blinky.py new file mode 100644 index 0000000..5e20191 --- /dev/null +++ b/nmigen_boards/test/blinky.py @@ -0,0 +1,30 @@ +import itertools + +from nmigen import * +from nmigen.build import ResourceError + + +__all__ = ["Blinky"] + + +class Blinky(Elaboratable): + def elaborate(self, platform): + m = Module() + + leds = [] + for n in itertools.count(): + try: + leds.append(platform.request("led", n)) + except ResourceError: + break + leds = Cat(led.o for led in leds) + + clk_freq = platform.default_clk_frequency + ctr = Signal(max=int(clk_freq//2), reset=int(clk_freq//2) - 1) + with m.If(ctr == 0): + m.d.sync += ctr.eq(ctr.reset) + m.d.sync += leds.eq(~leds) + with m.Else(): + m.d.sync += ctr.eq(ctr - 1) + + return m -- cgit v1.2.3