[breaking-change] Factor out "led", "button" and "switch" resources.
authorwhitequark <whitequark@whitequark.org>
Mon, 23 Sep 2019 08:07:37 +0000 (08:07 +0000)
committerwhitequark <whitequark@whitequark.org>
Mon, 23 Sep 2019 08:07:37 +0000 (08:07 +0000)
These resources were renamed as:
  * user_led → led
  * user_btn → button
  * user_sw → switch

Fixes #13.

17 files changed:
nmigen_boards/_blinky.py
nmigen_boards/arty_a7.py
nmigen_boards/atlys.py
nmigen_boards/blackice.py
nmigen_boards/blackice_ii.py
nmigen_boards/dev/__init__.py
nmigen_boards/dev/user.py [new file with mode: 0644]
nmigen_boards/fomu_hacker.py
nmigen_boards/ice40_hx1k_blink_evn.py
nmigen_boards/ice40_hx8k_b_evn.py
nmigen_boards/icebreaker.py
nmigen_boards/icestick.py
nmigen_boards/kc705.py
nmigen_boards/mercury.py
nmigen_boards/numato_mimas.py
nmigen_boards/tinyfpga_bx.py
nmigen_boards/versa_ecp5.py

index a9bbde9e5e39aee52e6d104b6d4b84ce0686004b..4a173d4624f478a4e1e72fda347d982c2b50bbf3 100644 (file)
@@ -11,7 +11,7 @@ class Blinky(Elaboratable):
         leds = []
         for n in itertools.count():
             try:
-                leds.append(platform.request("user_led", n))
+                leds.append(platform.request("led", n))
             except ResourceError:
                 break
         leds = Cat(led.o for led in leds)
index 7012fbd5855942c02d8a418552c8fa1d1d873dca..53869a38c9cacca9289d6410210635969d7f7a99 100644 (file)
@@ -15,50 +15,18 @@ class ArtyA7Platform(Xilinx7SeriesPlatform):
     speed       = "1L"
     default_clk = "clk100"
     resources   = [
-        Resource("clk100", 0, Pins("E3", dir="i"), Clock(100e6), Attrs(IOSTANDARD="LVCMOS33")),
+        Resource("clk100", 0, Pins("E3", dir="i"),
+                 Clock(100e6), Attrs(IOSTANDARD="LVCMOS33")),
 
-        Resource("user_led", 0, Pins("H5",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_led", 1, Pins("J5",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_led", 2, Pins("T9",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_led", 3, Pins("T10", dir="o"), Attrs(IOSTANDARD="LVCMOS33")),
+        *LEDResources(pins="H5 J5 T9 T10", attrs=Attrs(IOSTANDARD="LVCMOS33")),
 
-        Resource("rgb_led", 0,
-            Subsignal("r", Pins("G6", dir="o")),
-            Subsignal("g", Pins("F6", dir="o")),
-            Subsignal("b", Pins("E1", dir="o")),
-            Attrs(IOSTANDARD="LVCMOS33")
-        ),
-
-        Resource("rgb_led", 1,
-            Subsignal("r", Pins("G3", dir="o")),
-            Subsignal("g", Pins("J4", dir="o")),
-            Subsignal("b", Pins("G4", dir="o")),
-            Attrs(IOSTANDARD="LVCMOS33")
-        ),
-
-        Resource("rgb_led", 2,
-            Subsignal("r", Pins("J3", dir="o")),
-            Subsignal("g", Pins("J2", dir="o")),
-            Subsignal("b", Pins("H4", dir="o")),
-            Attrs(IOSTANDARD="LVCMOS33")
-        ),
-
-        Resource("rgb_led", 3,
-            Subsignal("r", Pins("K1", dir="o")),
-            Subsignal("g", Pins("H6", dir="o")),
-            Subsignal("b", Pins("K2", dir="o")),
-            Attrs(IOSTANDARD="LVCMOS33")
-        ),
-
-        Resource("user_sw", 0, Pins("A8" , dir="i"), Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_sw", 1, Pins("C11", dir="i"), Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_sw", 2, Pins("C10", dir="i"), Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_sw", 3, Pins("A10", dir="i"), Attrs(IOSTANDARD="LVCMOS33")),
+        RGBLEDResource(0, r="G6", g="F6", b="E1", attrs=Attrs(IOSTANDARD="LVCMOS33")),
+        RGBLEDResource(1, r="G3", g="J4", b="G4", attrs=Attrs(IOSTANDARD="LVCMOS33")),
+        RGBLEDResource(2, r="J3", g="J2", b="H4", attrs=Attrs(IOSTANDARD="LVCMOS33")),
+        RGBLEDResource(3, r="K1", g="H6", b="K2", attrs=Attrs(IOSTANDARD="LVCMOS33")),
 
-        Resource("user_btn", 0, Pins("D9", dir="i"), Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_btn", 1, Pins("C9", dir="i"), Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_btn", 2, Pins("B9", dir="i"), Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_btn", 3, Pins("B8", dir="i"), Attrs(IOSTANDARD="LVCMOS33")),
+        *ButtonResources(pins="D9  C9  B9  B8 ", attrs=Attrs(IOSTANDARD="LVCMOS33")),
+        *SwitchResources(pins="A8  C11 C10 A10", attrs=Attrs(IOSTANDARD="LVCMOS33")),
 
         UARTResource(0,
             rx="A9", tx="D10",
index 70d9100e9ee9b4cc0495f0106287bfcf254f0ce8..d01030765298c38b643b70e67d67a8c074f07489 100644 (file)
@@ -13,9 +13,9 @@ class AtlysPlatform(XilinxSpartan6Platform):
     """Platform file for Digilent Atlys Spartan 6 board.
     https://reference.digilentinc.com/reference/programmable-logic/atlys/start"""
 
-    device     = "xc6slx45"
-    package    = "csg324"
-    speed      = "3"
+    device  = "xc6slx45"
+    package = "csg324"
+    speed   = "3"
 
     def __init__(self, *, JP12="2V5", **kwargs):
         super().__init__(**kwargs)
@@ -28,35 +28,36 @@ class AtlysPlatform(XilinxSpartan6Platform):
 
     default_clk = "clk100"
     resources   = [
-        Resource("clk100"  , 0, Pins("L15",  dir="i"), Attrs(IOSTANDARD="LVCMOS33"), Clock(100e6)), # GCLK
-
-        Resource("user_led", 0, Pins("U18",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),       # LD0
-        Resource("user_led", 1, Pins("M14",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),       # LD1
-        Resource("user_led", 2, Pins("N14",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),       # LD2
-        Resource("user_led", 3, Pins("L14",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),       # LD3
-        Resource("user_led", 4, Pins("M13",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),       # LD4
-        Resource("user_led", 5, Pins("D4",   dir="o"), Attrs(IOSTANDARD="LVCMOS33")),       # LD5
-        Resource("user_led", 6, Pins("P16",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),       # LD6
-        Resource("user_led", 7, Pins("N12",  dir="o"), Attrs(IOSTANDARD=bank2_iostandard)), # LD7
-
-        Resource("user_btn", 0, PinsN("T15", dir="i"), Attrs(IOSTANDARD=bank2_iostandard)), # RESET
-        Resource("reset"   , 0, PinsN("T15", dir="i"), Attrs(IOSTANDARD=bank2_iostandard)), # RESET
-        Resource("user_btn", 1, Pins("N4",   dir="i"), Attrs(IOSTANDARD="LVCMOS18")),       # BTNU
-        Resource("user_btn", 2, Pins("P4",   dir="i"), Attrs(IOSTANDARD="LVCMOS18")),       # BTNL
-        Resource("user_btn", 3, Pins("P3",   dir="i"), Attrs(IOSTANDARD="LVCMOS18")),       # BTND
-        Resource("user_btn", 4, Pins("F6",   dir="i"), Attrs(IOSTANDARD="LVCMOS18")),       # BTNR
-        Resource("user_btn", 5, Pins("F5",   dir="i"), Attrs(IOSTANDARD="LVCMOS18")),       # BTNC
-
-        Resource("user_sw" , 0, Pins("A10",  dir="i"), Attrs(IOSTANDARD="LVCMOS33")),       # SW0
-        Resource("user_sw" , 1, Pins("D14",  dir="i"), Attrs(IOSTANDARD="LVCMOS33")),       # SW1
-        Resource("user_sw" , 2, Pins("C14",  dir="i"), Attrs(IOSTANDARD="LVCMOS33")),       # SW2
-        Resource("user_sw" , 3, Pins("P15",  dir="i"), Attrs(IOSTANDARD="LVCMOS33")),       # SW3
-        Resource("user_sw" , 4, Pins("P12",  dir="i"), Attrs(IOSTANDARD=bank2_iostandard)), # SW4
-        Resource("user_sw" , 5, Pins("R5",   dir="i"), Attrs(IOSTANDARD=bank2_iostandard)), # SW5
-        Resource("user_sw" , 6, Pins("T5",   dir="i"), Attrs(IOSTANDARD=bank2_iostandard)), # SW6
-        Resource("user_sw" , 7, Pins("E4",   dir="i"), Attrs(IOSTANDARD="LVCMOS18")),       # SW7
-
-        UARTResource(0, rx="A16", tx="B16", attrs=Attrs(IOSTANDARD="LVCMOS33")),            # J17/UART
+        Resource("clk100", 0, Pins("L15",  dir="i"),
+                 Clock(100e6), Attrs(IOSTANDARD="LVCMOS33")), # GCLK
+
+        Resource("led",    0, Pins("U18",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),       # LD0
+        Resource("led",    1, Pins("M14",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),       # LD1
+        Resource("led",    2, Pins("N14",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),       # LD2
+        Resource("led",    3, Pins("L14",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),       # LD3
+        Resource("led",    4, Pins("M13",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),       # LD4
+        Resource("led",    5, Pins("D4",   dir="o"), Attrs(IOSTANDARD="LVCMOS33")),       # LD5
+        Resource("led",    6, Pins("P16",  dir="o"), Attrs(IOSTANDARD="LVCMOS33")),       # LD6
+        Resource("led",    7, Pins("N12",  dir="o"), Attrs(IOSTANDARD=bank2_iostandard)), # LD7
+
+        Resource("button", 0, PinsN("T15", dir="i"), Attrs(IOSTANDARD=bank2_iostandard)), # RESET
+        Resource("reset",  0, PinsN("T15", dir="i"), Attrs(IOSTANDARD=bank2_iostandard)), # RESET
+        Resource("button", 1, Pins("N4",   dir="i"), Attrs(IOSTANDARD="LVCMOS18")),       # BTNU
+        Resource("button", 2, Pins("P4",   dir="i"), Attrs(IOSTANDARD="LVCMOS18")),       # BTNL
+        Resource("button", 3, Pins("P3",   dir="i"), Attrs(IOSTANDARD="LVCMOS18")),       # BTND
+        Resource("button", 4, Pins("F6",   dir="i"), Attrs(IOSTANDARD="LVCMOS18")),       # BTNR
+        Resource("button", 5, Pins("F5",   dir="i"), Attrs(IOSTANDARD="LVCMOS18")),       # BTNC
+
+        Resource("switch", 0, Pins("A10",  dir="i"), Attrs(IOSTANDARD="LVCMOS33")),       # SW0
+        Resource("switch", 1, Pins("D14",  dir="i"), Attrs(IOSTANDARD="LVCMOS33")),       # SW1
+        Resource("switch", 2, Pins("C14",  dir="i"), Attrs(IOSTANDARD="LVCMOS33")),       # SW2
+        Resource("switch", 3, Pins("P15",  dir="i"), Attrs(IOSTANDARD="LVCMOS33")),       # SW3
+        Resource("switch", 4, Pins("P12",  dir="i"), Attrs(IOSTANDARD=bank2_iostandard)), # SW4
+        Resource("switch", 5, Pins("R5",   dir="i"), Attrs(IOSTANDARD=bank2_iostandard)), # SW5
+        Resource("switch", 6, Pins("T5",   dir="i"), Attrs(IOSTANDARD=bank2_iostandard)), # SW6
+        Resource("switch", 7, Pins("E4",   dir="i"), Attrs(IOSTANDARD="LVCMOS18")),       # SW7
+
+        UARTResource(0, rx="A16", tx="B16", attrs=Attrs(IOSTANDARD="LVCMOS33")), # J17/UART
 
         Resource("ps2", 0, # PS/2 keyboard interface converted from J13 "HOST" USB connector
             Subsignal("clk",    Pins("P17", dir="i")),
index 4e0bb5ce996368a07cee28dde821ad7bbec7b8e1..ec67def5ae9d01ac3d7418045c483e5dc89217f4 100644 (file)
@@ -15,26 +15,17 @@ class BlackIcePlatform(LatticeICE40Platform):
     default_clk = "clk100"
     resources   = [
         Resource("clk100", 0, Pins("129", dir="i"),
-            Clock(100e6), Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")
-        ),
-
-        Resource("user_led", 0, Pins("71", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_led", 1, Pins("67", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_led", 2, Pins("68", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_led", 3, Pins("70", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        # Color aliases
-        Resource("user_ledb", 0, Pins("71", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_ledg", 0, Pins("67", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_ledo", 0, Pins("68", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_ledr", 0, Pins("70", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
+                 Clock(100e6), Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")),
 
-        Resource("user_btn", 0, PinsN("63", dir="i"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_btn", 1, PinsN("64", dir="i"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        *LEDResources(pins="71 67 68 70", attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
+        # Semantic aliases
+        Resource("led_b", 0, Pins("71", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        Resource("led_g", 0, Pins("67", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        Resource("led_o", 0, Pins("68", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        Resource("led_r", 0, Pins("70", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
 
-        Resource("user_sw", 0, PinsN("37", dir="i"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_sw", 1, PinsN("38", dir="i"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_sw", 2, PinsN("39", dir="i"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_sw", 3, PinsN("41", dir="i"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        *ButtonResources(pins="63 64",       invert=True, attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
+        *SwitchResources(pins="37 38 39 41", invert=True, attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
 
         UARTResource(0,
             rx="88", tx="85", rts="91", cts="94",
index e74d85503ddff7cafdd7e069f20ce6efb346861e..baa135ca8f1460c12c7065507a1d91d72ec5de87 100644 (file)
@@ -18,23 +18,15 @@ class BlackIceIIPlatform(LatticeICE40Platform):
             Clock(100e6), Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")
         ),
 
-        Resource("user_led", 0, Pins("71", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_led", 1, Pins("67", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_led", 2, Pins("68", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_led", 3, Pins("70", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        *LEDResources(pins="71 67 68 70", attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
         # Color aliases
-        Resource("user_ledb", 0, Pins("71", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_ledg", 0, Pins("67", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_ledo", 0, Pins("68", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_ledr", 0, Pins("70", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        Resource("led_b", 0, Pins("71", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        Resource("led_g", 0, Pins("67", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        Resource("led_o", 0, Pins("68", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        Resource("led_r", 0, Pins("70", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
 
-        Resource("user_btn", 0, PinsN("63", dir="i"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_btn", 1, PinsN("64", dir="i"), Attrs(IO_STANDARD="SB_LVCMOS")),
-
-        Resource("user_sw", 0, PinsN("37", dir="i"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_sw", 1, PinsN("38", dir="i"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_sw", 2, PinsN("39", dir="i"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_sw", 3, PinsN("41", dir="i"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        *ButtonResources(pins="63 64",       invert=True, attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
+        *SwitchResources(pins="37 38 39 41", invert=True, attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
 
         UARTResource(0,
             rx="88", tx="85", rts="91", cts="94",
index 242b0f9aeffaba3be8eddf4f82adfe4af5779da4..db4703fa17c88afcbc5d387c61da58bb55f42f52 100644 (file)
@@ -1,4 +1,5 @@
+from .user import LEDResources, RGBLEDResource, ButtonResources, SwitchResources
 from .uart import UARTResource
-from .flash import SPIFlashResources
 from .spi import SPIResource
+from .flash import SPIFlashResources
 from .sram import SRAMResource
diff --git a/nmigen_boards/dev/user.py b/nmigen_boards/dev/user.py
new file mode 100644 (file)
index 0000000..d2be28e
--- /dev/null
@@ -0,0 +1,43 @@
+from nmigen.build import *
+
+
+__all__ = ["UserLEDResource"]
+
+
+def _SplitResources(*args, pins, invert=False, attrs=None, default_name, dir):
+    assert isinstance(pins, (str, list, dict))
+
+    if isinstance(pins, str):
+        pins = pins.split()
+    if isinstance(pins, list):
+        pins = dict(enumerate(pins))
+
+    resources = []
+    for number, pin in pins.items():
+        ios = [PinsN(pin, dir=dir) if invert else Pins(pin, dir=dir)]
+        if attrs is not None:
+            ios.append(attrs)
+        resources.append(Resource.family(*args, number, default_name=default_name, ios=ios))
+    return resources
+
+
+def LEDResources(*args, **kwargs):
+    return _SplitResources(*args, **kwargs, default_name="led", dir="o")
+
+
+def RGBLEDResource(*args, r, g, b, invert=False, attrs=None):
+    ios = []
+    ios.append(Subsignal("r", Pins(r, dir="o", assert_width=1)))
+    ios.append(Subsignal("g", Pins(g, dir="o", assert_width=1)))
+    ios.append(Subsignal("b", Pins(b, dir="o", assert_width=1)))
+    if attrs is not None:
+        ios.append(attrs)
+    return Resource.family(*args, default_name="rgb_led", ios=ios)
+
+
+def ButtonResources(*args, **kwargs):
+    return _SplitResources(*args, **kwargs, default_name="button", dir="i")
+
+
+def SwitchResources(*args, **kwargs):
+    return _SplitResources(*args, **kwargs, default_name="switch", dir="i")
index 4a4e8533a62dcf04a112ad044ec83cd71d672e4a..2ff00387bb63af55c3ffcbe883687f4e597f7199 100644 (file)
@@ -17,12 +17,10 @@ class FomuHackerPlatform(LatticeICE40Platform):
         Resource("clk48", 0, Pins("F5", dir="i"),
                  Clock(48e6), Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")),
 
-        Resource("user_led", 0, PinsN("A5", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("rgb_led", 0,
-            Subsignal("r", PinsN("C5")),
-            Subsignal("g", PinsN("B5")),
-            Subsignal("b", PinsN("A5")),
-            Attrs(IO_STANDARD="SB_LVCMOS"),
+        *LEDResources(pins="A5", invert=True, attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
+        RGBLEDResource(0,
+            r="C5", g="B5", b="A5", invert=True,
+            attrs=Attrs(IO_STANDARD="SB_LVCMOS")
         ),
 
         Resource("usb", 0,
index 215e3103a25b703561868a3b8e46ae2a8cf4bada..2a766030f58b3e0fab1a5cc8dc58ad9630e10028 100644 (file)
@@ -17,15 +17,12 @@ class ICE40HX1KBlinkEVNPlatform(LatticeICE40Platform):
         Resource("clk3p3", 0, Pins("13", dir="i"), Clock(3.3e6),
                  Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")),
 
-        Resource("user_led", 0, Pins("59", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_led", 1, Pins("56", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_led", 2, Pins("53", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_led", 3, Pins("51", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-
-        Resource("user_btn", 0, Pins("60"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_btn", 1, Pins("57"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_btn", 2, Pins("54"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_btn", 3, Pins("52"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        *LEDResources(pins="59 56 53 51", attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
+
+        Resource("touch", 0, Pins("60"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        Resource("touch", 1, Pins("57"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        Resource("touch", 2, Pins("54"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        Resource("touch", 3, Pins("52"), Attrs(IO_STANDARD="SB_LVCMOS")),
 
         *SPIFlashResources(0,
             cs="49", clk="48", mosi="45", miso="46",
index ffa00eea7ba71cafdfd8fd630e740c1a86ab3c1a..e27218ab5b8c7ad3e939b049fe0d5054a75282af 100644 (file)
@@ -17,14 +17,10 @@ class ICE40HX8KBEVNPlatform(LatticeICE40Platform):
         Resource("clk12", 0, Pins("J3", dir="i"),
                  Clock(12e6), Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")),
 
-        Resource("user_led", 0, Pins("C3", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")), # D2
-        Resource("user_led", 1, Pins("B3", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")), # D3
-        Resource("user_led", 2, Pins("C4", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")), # D4
-        Resource("user_led", 3, Pins("C5", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")), # D5
-        Resource("user_led", 4, Pins("A1", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")), # D6
-        Resource("user_led", 5, Pins("A2", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")), # D7
-        Resource("user_led", 6, Pins("B4", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")), # D8
-        Resource("user_led", 7, Pins("B5", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")), # D9
+        *LEDResources(
+            pins="C3 B3 C4 C5 A1 A2 B4 B5",
+            attrs=Attrs(IO_STANDARD="SB_LVCMOS")
+        ), # D2..D9
 
         UARTResource(0,
             rx="B10", tx="B12", rts="B13", cts="A15", dtr="A16", dsr="B14", dcd="B15",
index ac4f23954d73d52fec0afce1c838f6b2e3a10eba..9971ee0e31fb94af1d3b0d125a23960b52e4d5d0 100644 (file)
@@ -17,13 +17,12 @@ class ICEBreakerPlatform(LatticeICE40Platform):
         Resource("clk12", 0, Pins("35", dir="i"),
                  Clock(12e6), Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")),
 
-        Resource("user_led",  0, PinsN("11", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_led",  1, PinsN("37", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        # Color-specific aliases
-        Resource("user_ledr", 0, PinsN("11", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_ledg", 0, PinsN("37", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        *LEDResources(pins="11 37", invert=True, attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
+        # Semantic aliases
+        Resource("led_r", 0, PinsN("11", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        Resource("led_g", 0, PinsN("37", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
 
-        Resource("user_btn",  0, PinsN("10", dir="i"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        *ButtonResources(pins="10", invert=True, attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
 
         UARTResource(0,
             rx="6", tx="9",
index bbcad5ee065275fca44be2168e4981b36818e452..99302e7654d1a2556c5b39b020bd280b2be4fc0d 100644 (file)
@@ -18,11 +18,7 @@ class ICEStickPlatform(LatticeICE40Platform):
         Resource("clk12", 0, Pins("21", dir="i"),
                  Clock(12e6), Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")),
 
-        Resource("user_led", 0, Pins("99", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_led", 1, Pins("98", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_led", 2, Pins("97", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_led", 3, Pins("96", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
-        Resource("user_led", 4, Pins("95", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        *LEDResources(pins="99 98 97 96 95", attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
 
         UARTResource(0,
             rx="9", tx="8", rts="7", cts="4", dtr="3", dsr="2", dcd="1",
index 613c0ba883364e35aad40be14de91c377c9cd575..f179d10936c5952dce1bbf3390869b25d6ea3a61 100644 (file)
@@ -18,14 +18,8 @@ class KC705Platform(Xilinx7SeriesPlatform):
         Resource("clk156", 0, DiffPairs("K28", "K29", dir="i"),
                  Clock(156e6), Attrs(IOSTANDARD="LVDS_25")),
 
-        Resource("user_led", 0, Pins("AB8", dir="o"), Attrs(IOSTANDARD="LVCMOS15")),
-        Resource("user_led", 1, Pins("AA8", dir="o"), Attrs(IOSTANDARD="LVCMOS15")),
-        Resource("user_led", 2, Pins("AC9", dir="o"), Attrs(IOSTANDARD="LVCMOS15")),
-        Resource("user_led", 3, Pins("AB9", dir="o"), Attrs(IOSTANDARD="LVCMOS15")),
-        Resource("user_led", 4, Pins("AE26", dir="o"), Attrs(IOSTANDARD="LVCMOS15")),
-        Resource("user_led", 5, Pins("G19", dir="o"), Attrs(IOSTANDARD="LVCMOS15")),
-        Resource("user_led", 6, Pins("E18", dir="o"), Attrs(IOSTANDARD="LVCMOS15")),
-        Resource("user_led", 7, Pins("F16", dir="o"), Attrs(IOSTANDARD="LVCMOS15")),
+        *LEDResources(pins="AB8 AA8 AC9 AB9 AE26 G19 E18 F16",
+                      attrs=Attrs(IOSTANDARD="LVCMOS15")),
 
         UARTResource(0,
             rx="M19", tx="K24",
index 8f072b09b2dddc170e8672d9a776c5ba9f7af420..5ad6254bdca1126c5fc50a9a7114ec1fd44284d3 100644 (file)
@@ -87,15 +87,15 @@ class MercuryPlatform(XilinxSpartan3APlatform):
 
     # Some default useful extensions. Attach to platform using:
     # p.add_resources(p.leds)
-    # pmod_btn = plat.request("user_led")
+    # pmod_btn = plat.request("led")
     leds = [
-        Resource("user_led", 0, Pins("1", dir="o", conn=("led", 0)),
+        Resource("led", 0, Pins("1", dir="o", conn=("led", 0)),
                  Attrs(IOSTANDARD="LVTTL")),
-        Resource("user_led", 1, Pins("2", dir="o", conn=("led", 0)),
+        Resource("led", 1, Pins("2", dir="o", conn=("led", 0)),
                  Attrs(IOSTANDARD="LVTTL")),
-        Resource("user_led", 2, Pins("3", dir="o", conn=("led", 0)),
+        Resource("led", 2, Pins("3", dir="o", conn=("led", 0)),
                  Attrs(IOSTANDARD="LVTTL")),
-        Resource("user_led", 3, Pins("4", dir="o", conn=("led", 0)),
+        Resource("led", 3, Pins("4", dir="o", conn=("led", 0)),
                  Attrs(IOSTANDARD="LVTTL")),
     ]
 
@@ -128,33 +128,33 @@ class MercuryPlatform(XilinxSpartan3APlatform):
 
     # The remaining peripherals only make sense w/ the Baseboard installed.
     # See: http://www.micro-nova.com/mercury-baseboard/
-    _user_sw = [
-        Resource("user_sw", 0, Pins("1", dir="i", conn=("gpio", 0)),
+    _switches = [
+        Resource("switch", 0, Pins("1", dir="i", conn=("gpio", 0)),
                  Attrs(IOSTANDARD="LVTTL")),
-        Resource("user_sw", 1, Pins("2", dir="i", conn=("gpio", 0)),
+        Resource("switch", 1, Pins("2", dir="i", conn=("gpio", 0)),
                  Attrs(IOSTANDARD="LVTTL")),
-        Resource("user_sw", 2, Pins("3", dir="i", conn=("gpio", 0)),
+        Resource("switch", 2, Pins("3", dir="i", conn=("gpio", 0)),
                  Attrs(IOSTANDARD="LVTTL")),
-        Resource("user_sw", 3, Pins("4", dir="i", conn=("gpio", 0)),
+        Resource("switch", 3, Pins("4", dir="i", conn=("gpio", 0)),
                  Attrs(IOSTANDARD="LVTTL")),
-        Resource("user_sw", 4, Pins("5", dir="i", conn=("gpio", 0)),
+        Resource("switch", 4, Pins("5", dir="i", conn=("gpio", 0)),
                  Attrs(IOSTANDARD="LVTTL")),
-        Resource("user_sw", 5, Pins("6", dir="i", conn=("gpio", 0)),
+        Resource("switch", 5, Pins("6", dir="i", conn=("gpio", 0)),
                  Attrs(IOSTANDARD="LVTTL")),
-        Resource("user_sw", 6, Pins("7", dir="i", conn=("gpio", 0)),
+        Resource("switch", 6, Pins("7", dir="i", conn=("gpio", 0)),
                  Attrs(IOSTANDARD="LVTTL")),
-        Resource("user_sw", 7, Pins("8", dir="i", conn=("gpio", 0)),
+        Resource("switch", 7, Pins("8", dir="i", conn=("gpio", 0)),
                  Attrs(IOSTANDARD="LVTTL"))
     ]
 
-    _user_btn = [
-        Resource("user_btn", 1, Pins("1", dir="i", conn=("input", 0)),
+    _buttons = [
+        Resource("button", 1, Pins("1", dir="i", conn=("input", 0)),
                  Attrs(IOSTANDARD="LVTTL")),
-        Resource("user_btn", 2, Pins("2", dir="i", conn=("input", 0)),
+        Resource("button", 2, Pins("2", dir="i", conn=("input", 0)),
                  Attrs(IOSTANDARD="LVTTL")),
-        Resource("user_btn", 3, Pins("3", dir="i", conn=("input", 0)),
+        Resource("button", 3, Pins("3", dir="i", conn=("input", 0)),
                  Attrs(IOSTANDARD="LVTTL")),
-        Resource("user_btn", 4, Pins("4", dir="i", conn=("input", 0)),
+        Resource("button", 4, Pins("4", dir="i", conn=("input", 0)),
                  Attrs(IOSTANDARD="LVTTL"))
     ]
 
@@ -207,9 +207,8 @@ class MercuryPlatform(XilinxSpartan3APlatform):
         )
     ]
 
-    baseboard_sram    = _user_btn + _vga + _extclk + _ps2
-    baseboard_no_sram = _user_btn + _vga + _extclk + _ps2 + \
-                        _user_sw + _sevenseg + _audio
+    baseboard_sram    = _buttons + _vga + _extclk + _ps2
+    baseboard_no_sram = baseboard_sram + _switches + _sevenseg + _audio
 
     def toolchain_program(self, products, name):
         # https://github.com/cr1901/mercpcl
index a85abc39a8d1417e46fd00d8f566b9fb8eb8677d..d484fa28d1175dade6687b3f0c720851d1a93f7f 100644 (file)
@@ -18,31 +18,10 @@ class NumatoMimasPlatform(XilinxSpartan6Platform):
         Resource("clk100", 0, Pins("P126", dir="i"),
                  Clock(100e6), Attrs(IOSTANDARD="LVCMOS33")),
 
-        Resource("user_led", 0, Pins("P119", dir="o"),
-                 Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_led", 1, Pins("P118", dir="o"),
-                 Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_led", 2, Pins("P117", dir="o"),
-                 Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_led", 3, Pins("P116", dir="o"),
-                 Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_led", 4, Pins("P115", dir="o"),
-                 Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_led", 5, Pins("P114", dir="o"),
-                 Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_led", 6, Pins("P112", dir="o"),
-                 Attrs(IOSTANDARD="LVCMOS33")),
-        Resource("user_led", 7, Pins("P111", dir="o"),
-                 Attrs(IOSTANDARD="LVCMOS33")),
-
-        Resource("user_btn", 0, Pins("P124", dir="i"),
-                 Attrs(IOSTANDARD="LVCMOS33", PULLUP="TRUE")),
-        Resource("user_btn", 1, Pins("P123", dir="i"),
-                 Attrs(IOSTANDARD="LVCMOS33", PULLUP="TRUE")),
-        Resource("user_btn", 2, Pins("P121", dir="i"),
-                 Attrs(IOSTANDARD="LVCMOS33", PULLUP="TRUE")),
-        Resource("user_btn", 3, Pins("P120", dir="i"),
-                 Attrs(IOSTANDARD="LVCMOS33", PULLUP="TRUE")),
+        *LEDResources(pins="P119 P118 P117 P116 P115 P114 P112 P111",
+                      attrs=Attrs(IOSTANDARD="LVCMOS33")),
+        *ButtonResources(pins="P124 P123 P121 P120",
+                         attrs=Attrs(IOSTANDARD="LVCMOS33", PULLUP="TRUE")),
 
         *SPIFlashResources(0,
             cs="P38", clk="P70", mosi="P64", miso="65",
index 4e136a7055c0c588b1793214f9ab5d5d0dc21966..c563565a9e2ef5143b6b5e7ef8b381d29fe8a70c 100644 (file)
@@ -17,7 +17,7 @@ class TinyFPGABXPlatform(LatticeICE40Platform):
         Resource("clk16", 0, Pins("B2", dir="i"),
                  Clock(16e6), Attrs(IO_STANDARD="SB_LVCMOS")),
 
-        Resource("user_led", 0, Pins("B3", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
+        *LEDResources(pins="B3", attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
 
         Resource("usb", 0,
             Subsignal("d_p",    Pins("B4", dir="io")),
index fdb79c0de3b4b7a3a923d29177e7ac914ad7970f..6b26d4f1bf6ad6e5a4400c5f589a55687dd1b6c7 100644 (file)
@@ -22,14 +22,8 @@ class VersaECP5Platform(LatticeECP5Platform):
         Resource("pclk", 0, DiffPairs("A4", "A5", dir="i"),
                  Attrs(IO_TYPE="LVDS")),
 
-        Resource("user_led", 0, PinsN("E16", dir="o"), Attrs(IO_TYPE="LVCMOS25")),
-        Resource("user_led", 1, PinsN("D17", dir="o"), Attrs(IO_TYPE="LVCMOS25")),
-        Resource("user_led", 2, PinsN("D18", dir="o"), Attrs(IO_TYPE="LVCMOS25")),
-        Resource("user_led", 3, PinsN("E18", dir="o"), Attrs(IO_TYPE="LVCMOS25")),
-        Resource("user_led", 4, PinsN("F17", dir="o"), Attrs(IO_TYPE="LVCMOS25")),
-        Resource("user_led", 5, PinsN("F18", dir="o"), Attrs(IO_TYPE="LVCMOS25")),
-        Resource("user_led", 6, PinsN("E17", dir="o"), Attrs(IO_TYPE="LVCMOS25")),
-        Resource("user_led", 7, PinsN("F16", dir="o"), Attrs(IO_TYPE="LVCMOS25")),
+        *LEDResources(pins="E16 D17 D18 E18 F17 F18 E17 F16",
+                      attrs=Attrs(IO_TYPE="LVCMOS25")),
 
         Resource("alnum_led", 0,
             Subsignal("a", PinsN("M20", dir="o")),
@@ -50,14 +44,10 @@ class VersaECP5Platform(LatticeECP5Platform):
             Attrs(IO_TYPE="LVCMOS25")
         ),
 
-        Resource("user_sw", 0, PinsN("H2",  dir="i"), Attrs(IO_TYPE="LVCMOS15")),
-        Resource("user_sw", 1, PinsN("K3",  dir="i"), Attrs(IO_TYPE="LVCMOS15")),
-        Resource("user_sw", 2, PinsN("G3",  dir="i"), Attrs(IO_TYPE="LVCMOS15")),
-        Resource("user_sw", 3, PinsN("F2",  dir="i"), Attrs(IO_TYPE="LVCMOS15")),
-        Resource("user_sw", 4, PinsN("J18", dir="i"), Attrs(IO_TYPE="LVCMOS25")),
-        Resource("user_sw", 5, PinsN("K18", dir="i"), Attrs(IO_TYPE="LVCMOS25")),
-        Resource("user_sw", 6, PinsN("K19", dir="i"), Attrs(IO_TYPE="LVCMOS25")),
-        Resource("user_sw", 7, PinsN("K20", dir="i"), Attrs(IO_TYPE="LVCMOS25")),
+        *SwitchResources(pins={0: "H2",  1: "K3",  2: "G3",  3: "F2" },
+                         attrs=Attrs(IO_TYPE="LVCMOS15")),
+        *SwitchResources(pins={4: "J18", 5: "K18", 6: "K19", 7: "K20"},
+                         attrs=Attrs(IO_TYPE="LVCMOS15")),
 
         UARTResource(0,
             rx="C11", tx="A11",