aboutsummaryrefslogtreecommitdiff
path: root/nmigen_boards/test/blinky.py
diff options
context:
space:
mode:
authorwhitequark <whitequark@whitequark.org>2019-09-23 08:16:07 +0000
committerwhitequark <whitequark@whitequark.org>2019-09-23 08:16:07 +0000
commit52bcf5f6faa09e2ac74a4c446090215e89a8e0fa (patch)
tree87d6190b1432b7194f58f4ee31e2dad651ca4676 /nmigen_boards/test/blinky.py
parentdd87f472af92a73d18b3ef363603f20bd071306e (diff)
_blinky→test.blinky
Expose blinky as a stable component, to make writing out-of-tree board files a bit nicer.
Diffstat (limited to 'nmigen_boards/test/blinky.py')
-rw-r--r--nmigen_boards/test/blinky.py30
1 files changed, 30 insertions, 0 deletions
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