Skip to content

Commit 9243901

Browse files
wanda-phiwhitequark
authored andcommitted
build.res: allow dir="-" when requesting resources with subsignals.
This makes the only non-deprecated way to do I/O not be a pain when subsignals are involved.
1 parent c03e450 commit 9243901

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

amaranth/build/res.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ def request(self, name, number=0, *, dir=None, xdr=None):
152152

153153
def merge_options(subsignal, dir, xdr):
154154
if isinstance(subsignal.ios[0], Subsignal):
155-
if dir is None:
155+
orig_dir = dir
156+
if dir is None or dir == "-":
156157
dir = dict()
157158
if xdr is None:
158159
xdr = dict()
@@ -165,7 +166,7 @@ def merge_options(subsignal, dir, xdr):
165166
"has subsignals"
166167
.format(xdr, subsignal))
167168
for sub in subsignal.ios:
168-
sub_dir = dir.get(sub.name, None)
169+
sub_dir = "-" if orig_dir == "-" else dir.get(sub.name, None)
169170
sub_xdr = xdr.get(sub.name, None)
170171
dir[sub.name], xdr[sub.name] = merge_options(sub, sub_dir, sub_xdr)
171172
else:

docs/changes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ Standard library changes
8080
* Added: constants of :class:`amaranth.lib.data.ArrayLayout` are iterable.
8181

8282

83+
Platform integration changes
84+
----------------------------
85+
86+
.. currentmodule:: amaranth.vendor
87+
88+
* Added: :meth:`Platform.request` accepts :py:`dir="-"` for resources with subsignals.
89+
90+
8391
Version 0.5.1
8492
=============
8593

tests/test_build_res.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def test_request_with_dir(self):
8484
scl_buffer._MustUse__silence = True
8585
sda_buffer._MustUse__silence = True
8686

87+
def test_request_subsignal_dash(self):
88+
with _ignore_deprecated():
89+
i2c = self.cm.request("i2c", 0, dir="-")
90+
self.assertIsInstance(i2c.sda, SingleEndedPort)
91+
self.assertIsInstance(i2c.scl, SingleEndedPort)
92+
8793
def test_request_tristate(self):
8894
with _ignore_deprecated():
8995
i2c = self.cm.request("i2c", 0)

0 commit comments

Comments
 (0)