amaranth/docs/_code/led_blinker.py
whitequark 399b8f9863 Add (heavily work in progress) documentation.
To render correctly, the docs require:
 * pygments/pygments#1441
2020-06-30 22:21:16 +00:00

25 lines
566 B
Python

from nmigen import *
class LEDBlinker(Elaboratable):
def elaborate(self, platform):
m = Module()
led = platform.request("led")
half_freq = int(platform.default_clk_frequency // 2)
timer = Signal(range(half_freq + 1))
with m.If(timer == half_freq):
m.d.sync += led.eq(~led)
m.d.sync += timer.eq(0)
with m.Else():
m.d.sync += timer.eq(timer + 1)
return m
# --- BUILD ---
from nmigen_boards.icestick import *
ICEStickPlatform().build(LEDBlinker(), do_program=True)