nmigen-learning/fpga/icebreaker.py

29 lines
718 B
Python
Raw Normal View History

2020-08-06 20:52:49 +02:00
from nmigen import *
from nmigen.cli import main
from nmigen_boards.icebreaker import ICEBreakerPlatform
class Blinker(Elaboratable):
def __init__(self, maxperiod: int):
self.maxperiod = maxperiod
def elaborate(self, platform):
led = platform.request("led_r")
m = Module()
counter = Signal(range(self.maxperiod + 1))
with m.If(counter == 0):
2020-08-06 22:48:07 +02:00
m.d.sync += led.eq(~led)
m.d.sync += counter.eq(self.maxperiod)
2020-08-06 20:52:49 +02:00
with m.Else():
m.d.sync += counter.eq(counter - 1)
return m
if __name__ == "__main__":
plat = ICEBreakerPlatform()
#main(plat, ports=[plat.led])
plat.build(Blinker(10000000), do_program=True)