2024-09-27 06:04:17 +00:00
|
|
|
import shutil
|
|
|
|
import pytest
|
2024-09-22 03:33:47 +00:00
|
|
|
from amaranth import Elaboratable, Module, Signal
|
|
|
|
from amaranth.lib.io import Buffer
|
|
|
|
from groovylight.platforms.colorlight_5a75b_v8_2 import Colorlight_5A75B_R82Platform
|
|
|
|
|
|
|
|
|
2024-09-27 06:04:17 +00:00
|
|
|
def progs_exist(programs) -> bool:
|
|
|
|
for p in programs:
|
|
|
|
if shutil.which(p) is None:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2024-09-22 03:33:47 +00:00
|
|
|
class Blinky(Elaboratable):
|
|
|
|
def elaborate(self, platform):
|
|
|
|
m = Module()
|
|
|
|
|
|
|
|
m.submodules.led = led = Buffer("o", platform.request("led", dir="-"))
|
|
|
|
state = Signal()
|
|
|
|
counter = Signal(24)
|
|
|
|
|
|
|
|
with m.If(counter == 0):
|
|
|
|
m.d.sync += [counter.eq(~0), state.eq(~state)]
|
|
|
|
with m.Else():
|
|
|
|
m.d.sync += counter.eq(counter - 1)
|
|
|
|
|
|
|
|
m.d.comb += led.o.eq(state)
|
|
|
|
|
|
|
|
return m
|
|
|
|
|
|
|
|
|
|
|
|
def test_platform():
|
2024-09-27 06:04:17 +00:00
|
|
|
if not progs_exist(["yosys", "nextpnr-ecp5", "openFPGALoader"]):
|
|
|
|
pytest.skip("missing toolchain programs")
|
2024-09-22 03:33:47 +00:00
|
|
|
plat = Colorlight_5A75B_R82Platform()
|
2024-09-27 06:04:17 +00:00
|
|
|
|
2024-09-22 03:33:47 +00:00
|
|
|
plat.build(Blinky())
|