From: whitequark Date: Mon, 23 Sep 2019 08:16:07 +0000 (+0000) Subject: _blinky→test.blinky X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=52bcf5f6faa09e2ac74a4c446090215e89a8e0fa;p=nmigen-boards.git _blinky→test.blinky Expose blinky as a stable component, to make writing out-of-tree board files a bit nicer. --- diff --git a/nmigen_boards/_blinky.py b/nmigen_boards/_blinky.py deleted file mode 100644 index 4a173d4..0000000 --- a/nmigen_boards/_blinky.py +++ /dev/null @@ -1,27 +0,0 @@ -import itertools - -from nmigen import * -from nmigen.build import ResourceError - - -class Blinky(Elaboratable): - def elaborate(self, platform): - m = Module() - - leds = [] - for n in itertools.count(): - try: - leds.append(platform.request("led", n)) - except ResourceError: - break - leds = Cat(led.o for led in leds) - - clk_freq = platform.default_clk_frequency - ctr = Signal(max=int(clk_freq//2), reset=int(clk_freq//2) - 1) - with m.If(ctr == 0): - m.d.sync += ctr.eq(ctr.reset) - m.d.sync += leds.eq(~leds) - with m.Else(): - m.d.sync += ctr.eq(ctr - 1) - - return m diff --git a/nmigen_boards/arty_a7.py b/nmigen_boards/arty_a7.py index 53869a3..57fe765 100644 --- a/nmigen_boards/arty_a7.py +++ b/nmigen_boards/arty_a7.py @@ -215,5 +215,5 @@ class ArtyA7Platform(Xilinx7SeriesPlatform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * ArtyA7Platform().build(Blinky(), do_program=True) diff --git a/nmigen_boards/atlys.py b/nmigen_boards/atlys.py index d010307..d70c6d0 100644 --- a/nmigen_boards/atlys.py +++ b/nmigen_boards/atlys.py @@ -226,5 +226,5 @@ class AtlysPlatform(XilinxSpartan6Platform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * AtlysPlatform().build(Blinky(), do_program=True) diff --git a/nmigen_boards/blackice.py b/nmigen_boards/blackice.py index ec67def..385401d 100644 --- a/nmigen_boards/blackice.py +++ b/nmigen_boards/blackice.py @@ -56,5 +56,5 @@ class BlackIcePlatform(LatticeICE40Platform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * BlackIcePlatform().build(Blinky(), do_program=True) diff --git a/nmigen_boards/blackice_ii.py b/nmigen_boards/blackice_ii.py index baa135c..86e381d 100644 --- a/nmigen_boards/blackice_ii.py +++ b/nmigen_boards/blackice_ii.py @@ -58,5 +58,5 @@ class BlackIceIIPlatform(LatticeICE40Platform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * BlackIceIIPlatform().build(Blinky(), do_program=True) diff --git a/nmigen_boards/fomu_hacker.py b/nmigen_boards/fomu_hacker.py index 2ff0038..0ddfe49 100644 --- a/nmigen_boards/fomu_hacker.py +++ b/nmigen_boards/fomu_hacker.py @@ -50,5 +50,5 @@ class FomuHackerPlatform(LatticeICE40Platform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * FomuHackerPlatform().build(Blinky(), do_program=True) diff --git a/nmigen_boards/ice40_hx1k_blink_evn.py b/nmigen_boards/ice40_hx1k_blink_evn.py index 2a76603..ae46f24 100644 --- a/nmigen_boards/ice40_hx1k_blink_evn.py +++ b/nmigen_boards/ice40_hx1k_blink_evn.py @@ -44,5 +44,5 @@ class ICE40HX1KBlinkEVNPlatform(LatticeICE40Platform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * ICE40HX1KBlinkEVNPlatform().build(Blinky(), do_program=True) diff --git a/nmigen_boards/ice40_hx8k_b_evn.py b/nmigen_boards/ice40_hx8k_b_evn.py index e27218a..ce55e81 100644 --- a/nmigen_boards/ice40_hx8k_b_evn.py +++ b/nmigen_boards/ice40_hx8k_b_evn.py @@ -63,5 +63,5 @@ class ICE40HX8KBEVNPlatform(LatticeICE40Platform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * ICE40HX8KBEVNPlatform().build(Blinky(), do_program=True) diff --git a/nmigen_boards/icebreaker.py b/nmigen_boards/icebreaker.py index 9971ee0..2f3034c 100644 --- a/nmigen_boards/icebreaker.py +++ b/nmigen_boards/icebreaker.py @@ -82,7 +82,7 @@ class ICEBreakerPlatform(LatticeICE40Platform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * p = ICEBreakerPlatform() p.add_resources(p.break_off_pmod) p.build(Blinky(), do_program=True) diff --git a/nmigen_boards/icestick.py b/nmigen_boards/icestick.py index 99302e7..763eaee 100644 --- a/nmigen_boards/icestick.py +++ b/nmigen_boards/icestick.py @@ -49,5 +49,5 @@ class ICEStickPlatform(LatticeICE40Platform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * ICEStickPlatform().build(Blinky(), do_program=True) diff --git a/nmigen_boards/kc705.py b/nmigen_boards/kc705.py index f179d10..bc889de 100644 --- a/nmigen_boards/kc705.py +++ b/nmigen_boards/kc705.py @@ -38,5 +38,5 @@ class KC705Platform(Xilinx7SeriesPlatform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * KC705Platform().build(Blinky(), do_program=True) diff --git a/nmigen_boards/mercury.py b/nmigen_boards/mercury.py index 5ad6254..c14e85c 100644 --- a/nmigen_boards/mercury.py +++ b/nmigen_boards/mercury.py @@ -218,7 +218,7 @@ class MercuryPlatform(XilinxSpartan3APlatform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * plat = MercuryPlatform() plat.add_resources(plat.leds) plat.build(Blinky(), do_program=True) diff --git a/nmigen_boards/numato_mimas.py b/nmigen_boards/numato_mimas.py index d484fa2..c094528 100644 --- a/nmigen_boards/numato_mimas.py +++ b/nmigen_boards/numato_mimas.py @@ -47,5 +47,5 @@ class NumatoMimasPlatform(XilinxSpartan6Platform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * NumatoMimasPlatform().build(Blinky()) diff --git a/nmigen_boards/test/blinky.py b/nmigen_boards/test/blinky.py new file mode 100644 index 0000000..5e20191 --- /dev/null +++ b/nmigen_boards/test/blinky.py @@ -0,0 +1,30 @@ +import itertools + +from nmigen import * +from nmigen.build import ResourceError + + +__all__ = ["Blinky"] + + +class Blinky(Elaboratable): + def elaborate(self, platform): + m = Module() + + leds = [] + for n in itertools.count(): + try: + leds.append(platform.request("led", n)) + except ResourceError: + break + leds = Cat(led.o for led in leds) + + clk_freq = platform.default_clk_frequency + ctr = Signal(max=int(clk_freq//2), reset=int(clk_freq//2) - 1) + with m.If(ctr == 0): + m.d.sync += ctr.eq(ctr.reset) + m.d.sync += leds.eq(~leds) + with m.Else(): + m.d.sync += ctr.eq(ctr - 1) + + return m diff --git a/nmigen_boards/tinyfpga_bx.py b/nmigen_boards/tinyfpga_bx.py index c563565..537d0fe 100644 --- a/nmigen_boards/tinyfpga_bx.py +++ b/nmigen_boards/tinyfpga_bx.py @@ -52,5 +52,5 @@ class TinyFPGABXPlatform(LatticeICE40Platform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * TinyFPGABXPlatform().build(Blinky(), do_program=True) diff --git a/nmigen_boards/versa_ecp5.py b/nmigen_boards/versa_ecp5.py index 6b26d4f..a3890ac 100644 --- a/nmigen_boards/versa_ecp5.py +++ b/nmigen_boards/versa_ecp5.py @@ -172,5 +172,5 @@ class VersaECP5Platform(LatticeECP5Platform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * VersaECP5Platform().build(Blinky(), do_program=True) diff --git a/nmigen_boards/versa_ecp5_5g.py b/nmigen_boards/versa_ecp5_5g.py index 02fa8b1..36e6997 100644 --- a/nmigen_boards/versa_ecp5_5g.py +++ b/nmigen_boards/versa_ecp5_5g.py @@ -10,5 +10,5 @@ class VersaECP55GPlatform(VersaECP5Platform): if __name__ == "__main__": - from ._blinky import Blinky + from .test.blinky import * VersaECP55GPlatform().build(Blinky(), do_program=True)