Idiomatic way to handle top-level IO from within an Instance
in a submodule
#1528
-
I have a design with a top-level module that has a submodule it shares some signals with, about like the following: class Foo(Elaboratable):
def elaborate(self, platform):
m = Module()
m.submodules.bar = bar = Bar()
m.submodules.led = led = io.Buffer("o", platform.request("led", 0, dir="-"))
m.d.comb += led.o.eq(bar.baz)
return m
class Bar(Elaboratable):
def __init__(self):
self.baz = Signal()
def elaborate(self, platform):
m = Module()
return m This is simple enough, but now I'd like to add an class Bar(Elaboratable):
def __init__(self):
self.baz = Signal()
def elaborate(self, platform):
m = Module()
m.submodules += Instance(
"io", "qux", IOPort(1),
...
)
return m My question is - if Ideally, I'd like to be able to assign the IOPort to some signal that's an attribute of Possible solutions I've thought of:
I'm using Amaranth 0.5.0 on Ubuntu 22.04, if that matters at all. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
When you use led = platform.request("led", 0, dir="-")
m.submodules += Instance("led_driver_external",
io_pin=led.io,
i_value=Const(1),
) There are a few ways in which you could structure this.
There is an intentional distinction between
I agree with this reasoning.
There isn't yet a well developed body of I/O components in Amaranth, but the ones that I've developed so far accept a single |
Beta Was this translation helpful? Give feedback.
-
Thank you! This answer makes sense. |
Beta Was this translation helpful? Give feedback.
-
As a follow-up question, how would I connect this bidirectional signal in the instance to an IO buffer? If I make an IO buffer with (I'm not sure if GitHub will send a notification for comments on Q&As that are marked as resolved, so I'll mention @whitequark just in case) |
Beta Was this translation helpful? Give feedback.
When you use
platform.request(..., dir="-")
, you get back aSingleEndedPort
object (or possibly aDifferentialPort
object, which works the same). Its.io
attribute holds anIOValue
that you can pass to anInstance
like this:There are a few ways in which you could structure this.