-
Notifications
You must be signed in to change notification settings - Fork 0
/
blinky.py
43 lines (32 loc) · 1.14 KB
/
blinky.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import itertools
from nmigen import *
from nmigen.build import ResourceError
from pym.icesugar_nano import *
__all__ = ["Blinky"]
class Blinky(Elaboratable):
def elaborate(self, platform):
m = Module()
def get_all_resources(name):
resources = []
for number in itertools.count():
try:
resources.append(platform.request(name, number))
except ResourceError:
break
return resources
leds = [res.o for res in get_all_resources("led")]
clk_freq = platform.default_clk_frequency
timer = Signal(range(int(clk_freq//2)), reset=int(clk_freq//2) - 1)
flops = Signal(len(leds))
inverts = [0 for _ in leds]
m.d.comb += Cat(leds).eq(flops ^ Cat(inverts))
with m.If(timer == 0):
m.d.sync += timer.eq(timer.reset)
m.d.sync += flops.eq(~flops)
with m.Else():
m.d.sync += timer.eq(timer - 1)
return m
if __name__ == "__main__":
p = iCESugarNanoPlatform()
p.add_resources(p.pmod_led)
p.build(Blinky(), do_program=True)