Simplify after changes in nmigen.
authorwhitequark <whitequark@whitequark.org>
Wed, 5 Jun 2019 14:05:02 +0000 (14:05 +0000)
committerwhitequark <whitequark@whitequark.org>
Wed, 5 Jun 2019 14:05:02 +0000 (14:05 +0000)
nmigen_boards/_blinky.py
nmigen_boards/ice40_hx1k_blink_evn.py
nmigen_boards/icestick.py
nmigen_boards/tinyfpga_bx.py

index 4fc0cc8db8c07e84685fb24de6fb476245e2b6ef..b0a190e534e94409559c02cc6987d04d6fb44f1e 100644 (file)
@@ -5,14 +5,14 @@ from nmigen.build import ResourceError
 
 
 class Blinky(Elaboratable):
-    def __init__(self, clk_name, clk_freq):
+    def __init__(self, clk_name):
         self.clk_name = clk_name
-        self.clk_freq = clk_freq
 
     def elaborate(self, platform):
         m = Module()
 
         clk = platform.request(self.clk_name)
+        clk_freq = platform.get_clock_constraint(clk)
         m.domains.sync = ClockDomain()
         m.d.comb += ClockSignal().eq(clk.i)
 
@@ -24,7 +24,7 @@ class Blinky(Elaboratable):
                 break
         leds = Cat(led.o for led in leds)
 
-        ctr = Signal(max=int(self.clk_freq//2), reset=int(self.clk_freq//2) - 1)
+        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)
@@ -34,5 +34,5 @@ class Blinky(Elaboratable):
         return m
 
 
-def build_and_program(platform_cls, clk_name, clk_freq, **kwargs):
-    platform_cls().build(Blinky(clk_name, clk_freq), do_program=True, **kwargs)
+def build_and_program(platform_cls, clk_name, **kwargs):
+    platform_cls().build(Blinky(clk_name), do_program=True, **kwargs)
index 976091f9d8fd713977960bb13621fa110d18839e..1acac2d64fd607c105b46a66e2e672c1bf64a524 100644 (file)
@@ -49,4 +49,4 @@ class ICE40HX1KBlinkEVNPlatform(LatticeICE40Platform):
 
 if __name__ == "__main__":
     from ._blinky import build_and_program
-    build_and_program(ICE40HX1KBlinkEVNPlatform, "clk3p3", 3.3e6)
+    build_and_program(ICE40HX1KBlinkEVNPlatform, "clk3p3")
index b90573b2bb93ae11b45708415333e44fc5eb936a..a60f8c9315c1b9b13bf9b5c9ce99269e43cbd1aa 100644 (file)
@@ -62,4 +62,4 @@ class ICEStickPlatform(LatticeICE40Platform):
 
 if __name__ == "__main__":
     from ._blinky import build_and_program
-    build_and_program(ICEStickPlatform, "clk12", 12e6)
+    build_and_program(ICEStickPlatform, "clk12")
index 0ad94b90925b9d6ae68ab671a96ba5887f194a9c..d9b0116ad5bc863cec72a3e27f86596550cb40f9 100644 (file)
@@ -62,4 +62,4 @@ class TinyFPGABXPlatform(LatticeICE40Platform):
 
 if __name__ == "__main__":
     from ._blinky import build_and_program
-    build_and_program(TinyFPGABXPlatform, "clk16", 16e6)
+    build_and_program(TinyFPGABXPlatform, "clk16")