1 Star 1 Fork 0

x55aa/icsnano_nmigen

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
blinky.py 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
x55aa 提交于 2021-08-17 00:12 . update
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)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/x55aa/icsnano_nmigen.git
git@gitee.com:x55aa/icsnano_nmigen.git
x55aa
icsnano_nmigen
icsnano_nmigen
master

搜索帮助