-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blink all LEDs at 1 Hz if any board is run as __main__.
- Loading branch information
whitequark
committed
Jun 4, 2019
1 parent
50403d6
commit ecda2a1
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import itertools | ||
|
||
from nmigen import * | ||
from nmigen.build import ConstraintError | ||
|
||
|
||
class Blinky(Elaboratable): | ||
def elaborate(self, platform): | ||
m = Module() | ||
|
||
clk_name, clk_freq = next(iter(platform.clocks.items())) | ||
clk = platform.request(*clk_name) | ||
m.domains.sync = ClockDomain() | ||
m.d.comb += ClockSignal().eq(clk.i) | ||
|
||
leds = [] | ||
for n in itertools.count(): | ||
try: | ||
leds.append(platform.request("user_led", n)) | ||
except ConstraintError: | ||
break | ||
leds = Cat(led.o for led in leds) | ||
|
||
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 | ||
|
||
|
||
def build_and_program(platform_cls, **kwargs): | ||
platform_cls().build(Blinky(), do_program=True, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters