Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build.dsl: add Resource.family abstraction.
- Loading branch information
whitequark
committed
Jul 9, 2019
1 parent
7b4fbf8
commit 367ad5a
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,6 +181,20 @@ def __repr__(self): | |
|
||
|
||
class Resource(Subsignal): | ||
@classmethod | ||
def family(cls, name_or_number, number=None, *, ios, default_name): | ||
# This constructor accepts two different forms: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
whitequark
Author
Contributor
|
||
# 1. Number-only form: | ||
# Resource.family(0, default_name="name", ios=[Pins("A0 A1")]) | ||
# 2. Name-and-number (name override) form: | ||
# Resource.family("override", 0, default_name="name", ios=...) | ||
# This makes it easier to build abstractions for resources, e.g. an SPIResource abstraction | ||
# could simply delegate to `Resource.family(*args, default_name="spi", ios=ios)`. | ||
if number is None: # name_or_number is number | ||
return cls(default_name, name_or_number, *ios) | ||
else: # name_or_number is name | ||
return cls(name_or_number, number, *ios) | ||
|
||
def __init__(self, name, number, *args): | ||
super().__init__(name, *args) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Should this be a docstring rather than a comment like this?