From 3ac35241ad7e014047398cc3af7d335cb134cb15 Mon Sep 17 00:00:00 2001 From: Wanda Date: Thu, 29 Aug 2024 21:11:52 +0200 Subject: [PATCH] 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. --- amaranth/build/res.py | 5 +++-- tests/test_build_res.py | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/amaranth/build/res.py b/amaranth/build/res.py index f6d3c93eb3..effe44e148 100644 --- a/amaranth/build/res.py +++ b/amaranth/build/res.py @@ -152,7 +152,8 @@ def request(self, name, number=0, *, dir=None, xdr=None): def merge_options(subsignal, dir, xdr): if isinstance(subsignal.ios[0], Subsignal): - if dir is None: + orig_dir = dir + if dir is None or dir == "-": dir = dict() if xdr is None: xdr = dict() @@ -165,7 +166,7 @@ def merge_options(subsignal, dir, xdr): "has subsignals" .format(xdr, subsignal)) for sub in subsignal.ios: - sub_dir = dir.get(sub.name, None) + sub_dir = "-" if orig_dir == "-" else dir.get(sub.name, None) sub_xdr = xdr.get(sub.name, None) dir[sub.name], xdr[sub.name] = merge_options(sub, sub_dir, sub_xdr) else: diff --git a/tests/test_build_res.py b/tests/test_build_res.py index a0dbc555e6..758cdce63f 100644 --- a/tests/test_build_res.py +++ b/tests/test_build_res.py @@ -84,6 +84,12 @@ def test_request_with_dir(self): scl_buffer._MustUse__silence = True sda_buffer._MustUse__silence = True + def test_request_subsignal_dash(self): + with _ignore_deprecated(): + i2c = self.cm.request("i2c", 0, dir="-") + self.assertIsInstance(i2c.sda, SingleEndedPort) + self.assertIsInstance(i2c.scl, SingleEndedPort) + def test_request_tristate(self): with _ignore_deprecated(): i2c = self.cm.request("i2c", 0)