Factor out SPI resource definition.
authorJean-François Nguyen <jf@lambdaconcept.com>
Wed, 3 Jul 2019 16:31:21 +0000 (18:31 +0200)
committerwhitequark <whitequark@whitequark.org>
Wed, 3 Jul 2019 16:28:55 +0000 (16:28 +0000)
nmigen_boards/dev/__init__.py
nmigen_boards/dev/spi.py [new file with mode: 0644]

index f89e46ad39c4362da4d9a4d0a0e3c4011e01cb6c..1af4fe2b255bcb136f74925230b8cdfaf619af55 100644 (file)
@@ -1,2 +1,3 @@
 from .uart import UARTResource
 from .flash import SPIFlashResources
+from .spi import SPIResource
diff --git a/nmigen_boards/dev/spi.py b/nmigen_boards/dev/spi.py
new file mode 100644 (file)
index 0000000..e8baae0
--- /dev/null
@@ -0,0 +1,19 @@
+from nmigen.build import *
+
+
+__all__ = ["SPIResource"]
+
+
+def SPIResource(number, *, cs, clk, mosi, miso, int=None, reset=None, attrs=None):
+    io = []
+    io.append(Subsignal("cs", PinsN(cs, dir="o")))
+    io.append(Subsignal("clk", Pins(clk, dir="o")))
+    io.append(Subsignal("mosi", Pins(mosi, dir="o")))
+    io.append(Subsignal("miso", Pins(miso, dir="i")))
+    if int is not None:
+        io.append(Subsignal("int", Pins(int, dir="i")))
+    if reset is not None:
+        io.append(Subsignal("reset", Pins(reset, dir="o")))
+    if attrs is not None:
+        io.append(attrs)
+    return Resource("spi", number, *io)