amaranth/docs/_code/led_blinker.py

25 lines
589 B
Python
Raw Normal View History

2021-12-09 22:39:50 -07:00
from amaranth 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):
2024-05-04 18:56:30 -06:00
m.d.sync += led.o.eq(~led.o)
m.d.sync += timer.eq(0)
with m.Else():
m.d.sync += timer.eq(timer + 1)
return m
# --- BUILD ---
from amaranth_boards.icestick import ICEStickPlatform
ICEStickPlatform().build(LEDBlinker(), do_program=True)