Initial commit

This commit is contained in:
2020-08-06 20:52:49 +02:00
commit cd7f2e511d
8 changed files with 574 additions and 0 deletions

17
fpga/__init__.py Normal file
View File

@@ -0,0 +1,17 @@
__version__ = '0.1.0'
def load_env():
import os, shutil
if shutil.which("yowasp-yosys"):
os.environ["NEXTPNR_ICE40"] = "yowasp-nextpnr-ice40"
if shutil.which("yowasp-nextpnr-ice40"):
os.environ["NEXTPNR_ICE40"] = "yowasp-nextpnr-ice40"
if shutil.which("yowasp-nextpnr-ecp5"):
os.environ["NEXTPNR_ECP5"] = "yowasp-nextpnr-ecp5"
load_env()
del load_env

31
fpga/ice40.py Normal file
View File

@@ -0,0 +1,31 @@
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):
m.d.sync += [
led.eq(~led),
counter.eq(self.maxperiod)
]
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)