22
33from amaranth import *
44from amaranth .build import ResourceError
5+ from amaranth .lib import io
56
67
78__all__ = ["Blinky" ]
@@ -15,32 +16,34 @@ def get_all_resources(name):
1516 resources = []
1617 for number in itertools .count ():
1718 try :
18- resources .append (platform .request (name , number ))
19+ resources .append (platform .request (name , number , dir = "-" ))
1920 except ResourceError :
2021 break
2122 return resources
2223
2324 rgb_leds = [res for res in get_all_resources ("rgb_led" )]
24- leds = [res .o for res in get_all_resources ("led" )]
25- leds .extend ([led .r .o for led in rgb_leds ])
26- leds .extend ([led .g .o for led in rgb_leds ])
27- leds .extend ([led .b .o for led in rgb_leds ])
28- buttons = [res .i for res in get_all_resources ("button" )]
29- switches = [res .i for res in get_all_resources ("switch" )]
25+ leds = [io .Buffer ("o" , res ) for res in get_all_resources ("led" )]
26+ leds .extend ([io .Buffer ("o" , led .r ) for led in rgb_leds ])
27+ leds .extend ([io .Buffer ("o" , led .g ) for led in rgb_leds ])
28+ leds .extend ([io .Buffer ("o" , led .b ) for led in rgb_leds ])
29+ buttons = [io .Buffer ("i" , res ) for res in get_all_resources ("button" )]
30+ switches = [io .Buffer ("i" , res ) for res in get_all_resources ("switch" )]
31+
32+ m .submodules += leds + buttons + switches
3033
3134 inverts = [0 for _ in leds ]
3235 for index , button in zip (itertools .cycle (range (len (inverts ))), buttons ):
33- inverts [index ] ^= button
36+ inverts [index ] ^= button . i
3437 for index , switch in zip (itertools .cycle (range (len (inverts ))), switches ):
35- inverts [index ] ^= switch
38+ inverts [index ] ^= switch . i
3639
3740 clk_freq = platform .default_clk_frequency
38- timer = Signal (range (int (clk_freq // 2 )), reset = int (clk_freq // 2 ) - 1 )
41+ timer = Signal (range (int (clk_freq // 2 )), init = int (clk_freq // 2 ) - 1 )
3942 flops = Signal (len (leds ))
4043
41- m .d .comb += Cat (leds ).eq (flops ^ Cat (inverts ))
44+ m .d .comb += Cat (led . o for led in leds ).eq (flops ^ Cat (inverts ))
4245 with m .If (timer == 0 ):
43- m .d .sync += timer .eq (timer .reset )
46+ m .d .sync += timer .eq (timer .init )
4447 m .d .sync += flops .eq (~ flops )
4548 with m .Else ():
4649 m .d .sync += timer .eq (timer - 1 )
0 commit comments