Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/nmigen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 84f2c3df2bfe
Choose a base ref
...
head repository: m-labs/nmigen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8e048c5a7ce0
Choose a head ref
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Aug 18, 2019

  1. build.dsl: add conn argument to Connector.

    rroohhh authored and whitequark committed Aug 18, 2019
    Copy the full SHA
    8e048c5 View commit details
Showing with 49 additions and 4 deletions.
  1. +15 −4 nmigen/build/dsl.py
  2. +13 −0 nmigen/test/test_build_dsl.py
  3. +21 −0 nmigen/test/test_build_res.py
19 changes: 15 additions & 4 deletions nmigen/build/dsl.py
Original file line number Diff line number Diff line change
@@ -210,10 +210,10 @@ def __repr__(self):


class Connector:
def __init__(self, name, number, io):
def __init__(self, name, number, io, *, conn=None):
self.name = name
self.number = number
self.mapping = OrderedDict()
mapping = OrderedDict()

if isinstance(io, dict):
for conn_pin, plat_pin in io.items():
@@ -223,18 +223,29 @@ def __init__(self, name, number, io):
if not isinstance(plat_pin, str):
raise TypeError("Platform pin name must be a string, not {!r}"
.format(plat_pin))
self.mapping[conn_pin] = plat_pin
mapping[conn_pin] = plat_pin

elif isinstance(io, str):
for conn_pin, plat_pin in enumerate(io.split(), start=1):
if plat_pin == "-":
continue
self.mapping[str(conn_pin)] = plat_pin

mapping[str(conn_pin)] = plat_pin
else:
raise TypeError("Connector I/Os must be a dictionary or a string, not {!r}"
.format(io))

if conn is not None:
conn_name, conn_number = conn
if not (isinstance(conn_name, str) and isinstance(conn_number, int)):
raise TypeError("Connector must be None or a pair of string and integer, not {!r}"
.format(conn))

for conn_pin, plat_pin in mapping.items():
mapping[conn_pin] = "{}_{}:{}".format(conn_name, conn_number, plat_pin)

self.mapping = mapping

def __repr__(self):
return "(connector {} {} {})".format(self.name, self.number,
" ".join("{}=>{}".format(conn, plat)
13 changes: 13 additions & 0 deletions nmigen/test/test_build_dsl.py
Original file line number Diff line number Diff line change
@@ -278,6 +278,19 @@ def test_dict(self):
("DP1", "A1"),
]))

def test_conn(self):
c = Connector("pmod", 0, "0 1 2 3 - - 4 5 6 7 - -", conn=("expansion", 0))
self.assertEqual(c.mapping, OrderedDict([
("1", "expansion_0:0"),
("2", "expansion_0:1"),
("3", "expansion_0:2"),
("4", "expansion_0:3"),
("7", "expansion_0:4"),
("8", "expansion_0:5"),
("9", "expansion_0:6"),
("10", "expansion_0:7"),
]))

def test_wrong_io(self):
with self.assertRaises(TypeError,
msg="Connector I/Os must be a dictionary or a string, not []"):
21 changes: 21 additions & 0 deletions nmigen/test/test_build_res.py
Original file line number Diff line number Diff line change
@@ -168,6 +168,27 @@ def test_request_via_connector(self):
("spi_0__mosi__io", ["B3"], {}),
])

def test_request_via_nested_connector(self):
new_connectors = [
Connector("pmod_extension", 0, "1 2 3 4 - -", conn=("pmod", 0)),
]
self.cm.add_connectors(new_connectors)
self.cm.add_resources([
Resource("spi", 0,
Subsignal("ss", Pins("1", conn=("pmod_extension", 0))),
Subsignal("clk", Pins("2", conn=("pmod_extension", 0))),
Subsignal("miso", Pins("3", conn=("pmod_extension", 0))),
Subsignal("mosi", Pins("4", conn=("pmod_extension", 0))),
)
])
spi0 = self.cm.request("spi", 0)
self.assertEqual(list(self.cm.iter_port_constraints()), [
("spi_0__ss__io", ["B0"], {}),
("spi_0__clk__io", ["B1"], {}),
("spi_0__miso__io", ["B2"], {}),
("spi_0__mosi__io", ["B3"], {}),
])

def test_request_clock(self):
clk100 = self.cm.request("clk100", 0)
clk50 = self.cm.request("clk50", 0, dir="i")