Skip to content

Commit

Permalink
build.res: allow dir="-" when requesting resources with subsignals.
Browse files Browse the repository at this point in the history
This makes the only non-deprecated way to do I/O not be a pain when
subsignals are involved.
  • Loading branch information
wanda-phi authored and whitequark committed Aug 30, 2024
1 parent c03e450 commit 9243901
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions amaranth/build/res.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ Standard library changes
* Added: constants of :class:`amaranth.lib.data.ArrayLayout` are iterable.


Platform integration changes
----------------------------

.. currentmodule:: amaranth.vendor

* Added: :meth:`Platform.request` accepts :py:`dir="-"` for resources with subsignals.


Version 0.5.1
=============

Expand Down
6 changes: 6 additions & 0 deletions tests/test_build_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9243901

Please sign in to comment.