examples: update blinky, add some explanatory text about domains.
authorwhitequark <whitequark@whitequark.org>
Wed, 9 Oct 2019 23:19:19 +0000 (23:19 +0000)
committerwhitequark <whitequark@whitequark.org>
Wed, 9 Oct 2019 23:19:28 +0000 (23:19 +0000)
examples/board/01_blinky.py [new file with mode: 0644]
examples/board/02_domain.py [new file with mode: 0644]
examples/board/blinky.py [deleted file]

diff --git a/examples/board/01_blinky.py b/examples/board/01_blinky.py
new file mode 100644 (file)
index 0000000..0a21a00
--- /dev/null
@@ -0,0 +1,21 @@
+# If the design does not create a "sync" clock domain, it is created by the nMigen build system
+# using the platform default clock (and default reset, if any).
+
+from nmigen import *
+from nmigen_boards.ice40_hx1k_blink_evn import *
+
+
+class Blinky(Elaboratable):
+    def elaborate(self, platform):
+        led   = platform.request("led", 0)
+        timer = Signal(20)
+
+        m = Module()
+        m.d.sync += timer.eq(timer + 1)
+        m.d.comb += led.o.eq(timer[-1])
+        return m
+
+
+if __name__ == "__main__":
+    platform = ICE40HX1KBlinkEVNPlatform()
+    platform.build(Blinky(), do_program=True)
diff --git a/examples/board/02_domain.py b/examples/board/02_domain.py
new file mode 100644 (file)
index 0000000..d359334
--- /dev/null
@@ -0,0 +1,25 @@
+# If more control over clocking and resets is required, a "sync" clock domain could be created
+# explicitly, which overrides the default behavior. Any other clock domains could also be
+# independently created in addition to the main "sync" domain.
+
+from nmigen import *
+from nmigen_boards.ice40_hx1k_blink_evn import *
+
+
+class BlinkyWithDomain(Elaboratable):
+    def elaborate(self, platform):
+        clk3p3 = platform.request("clk3p3")
+        led    = platform.request("led", 0)
+        timer  = Signal(20)
+
+        m = Module()
+        m.domains.sync = ClockDomain()
+        m.d.comb += ClockSignal().eq(clk3p3.i)
+        m.d.sync += timer.eq(timer + 1)
+        m.d.comb += led.o.eq(timer[-1])
+        return m
+
+
+if __name__ == "__main__":
+    platform = ICE40HX1KBlinkEVNPlatform()
+    platform.build(BlinkyWithDomain(), do_program=True)
diff --git a/examples/board/blinky.py b/examples/board/blinky.py
deleted file mode 100644 (file)
index 53f49d0..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-from nmigen import *
-from nmigen_boards.ice40_hx1k_blink_evn import *
-
-
-class Blinky(Elaboratable):
-    def elaborate(self, platform):
-        clk3p3   = platform.request("clk3p3")
-        user_led = platform.request("user_led", 0)
-        counter  = Signal(20)
-
-        m = Module()
-        m.domains.sync = ClockDomain()
-        m.d.comb += ClockSignal().eq(clk3p3.i)
-        m.d.sync += counter.eq(counter + 1)
-        m.d.comb += user_led.o.eq(counter[-1])
-        return m
-
-
-if __name__ == "__main__":
-    platform = ICE40HX1KBlinkEVNPlatform()
-    platform.build(Blinky(), do_program=True)