From b968cfade961a329c26035ef8bfdf3058e95a9f1 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 10 Dec 2021 07:38:00 +0000 Subject: Rename nMigen to Amaranth HDL. --- amaranth_boards/test/blinky.py | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 amaranth_boards/test/blinky.py (limited to 'amaranth_boards/test/blinky.py') diff --git a/amaranth_boards/test/blinky.py b/amaranth_boards/test/blinky.py new file mode 100644 index 0000000..9999246 --- /dev/null +++ b/amaranth_boards/test/blinky.py @@ -0,0 +1,48 @@ +import itertools + +from amaranth import * +from amaranth.build import ResourceError + + +__all__ = ["Blinky"] + + +class Blinky(Elaboratable): + def elaborate(self, platform): + m = Module() + + def get_all_resources(name): + resources = [] + for number in itertools.count(): + try: + resources.append(platform.request(name, number)) + except ResourceError: + break + return resources + + rgb_leds = [res for res in get_all_resources("rgb_led")] + leds = [res.o for res in get_all_resources("led")] + leds.extend([led.r.o for led in rgb_leds]) + leds.extend([led.g.o for led in rgb_leds]) + leds.extend([led.b.o for led in rgb_leds]) + buttons = [res.i for res in get_all_resources("button")] + switches = [res.i for res in get_all_resources("switch")] + + inverts = [0 for _ in leds] + for index, button in zip(itertools.cycle(range(len(inverts))), buttons): + inverts[index] ^= button + for index, switch in zip(itertools.cycle(range(len(inverts))), switches): + inverts[index] ^= switch + + clk_freq = platform.default_clk_frequency + timer = Signal(range(int(clk_freq//2)), reset=int(clk_freq//2) - 1) + flops = Signal(len(leds)) + + m.d.comb += Cat(leds).eq(flops ^ Cat(inverts)) + with m.If(timer == 0): + m.d.sync += timer.eq(timer.reset) + m.d.sync += flops.eq(~flops) + with m.Else(): + m.d.sync += timer.eq(timer - 1) + + return m -- cgit v1.2.3