[breaking-change] Factor out "irda" resource.
authorwhitequark <whitequark@whitequark.org>
Fri, 28 Jun 2019 03:42:02 +0000 (03:42 +0000)
committerwhitequark <whitequark@whitequark.org>
Fri, 28 Jun 2019 03:42:02 +0000 (03:42 +0000)
nmigen_boards/dev/uart.py
nmigen_boards/icestick.py

index 27d1c8111fbaae5369aec923e528eb82a0ef6195..df03bd19dcb41cb003da1c6da897b1a283f0eb59 100644 (file)
@@ -1,7 +1,7 @@
 from nmigen.build import *
 
 
-__all__ = ["UARTResource"]
+__all__ = ["UARTResource", "IrDAResource"]
 
 
 def UARTResource(number, *, rx, tx, rts=None, cts=None, dtr=None, dsr=None, dcd=None, ri=None,
@@ -24,3 +24,19 @@ def UARTResource(number, *, rx, tx, rts=None, cts=None, dtr=None, dsr=None, dcd=
     if attrs is not None:
         io.append(attrs)
     return Resource("uart", number, *io)
+
+
+def IrDAResource(number, *, rx, tx, en=None, sd=None, attrs=None):
+    # Exactly one of en (active-high enable) or sd (shutdown, active-low enable) should
+    # be specified, and it is mapped to a logic level en subsignal.
+    assert (en is not None) ^ (sd is not None)
+    io = []
+    io.append(Subsignal("rx", Pins(rx, dir="i")))
+    io.append(Subsignal("tx", Pins(rx, dir="o")))
+    if en is not None:
+        io.append(Subsignal("en", Pins(en, dir="o")))
+    if sd is not None:
+        io.append(Subsignal("en", PinsN(sd, dir="o")))
+    if attrs is not None:
+        io.append(attrs)
+    return Resource("irda", number, *io)
index 5d0dd4bc059f93b51bcef697c1737e10f6c4b1ac..217e411e5dfb319665488451d4575189783aa7ba 100644 (file)
@@ -4,6 +4,7 @@ import subprocess
 from nmigen.build import *
 from nmigen.vendor.lattice_ice40 import *
 from .dev import *
+from .dev.uart import IrDAResource
 
 
 __all__ = ["ICEStickPlatform"]
@@ -27,11 +28,9 @@ class ICEStickPlatform(LatticeICE40Platform):
             attrs=Attrs(IO_STANDARD="SB_LVTTL", PULLUP="1")
         ),
 
-        Resource("irda", 0,
-            Subsignal("rx", Pins("106", dir="i")),
-            Subsignal("tx", Pins("105", dir="o")),
-            Subsignal("sd", Pins("107", dir="o")),
-            Attrs(IO_STANDARD="SB_LVCMOS33")
+        IrDAResource(0,
+            rx="106", tx="105", sd="107",
+            attrs=Attrs(IO_STANDARD="SB_LVCMOS33")
         ),
 
         *SPIFlashResources(0,