From a7eeec20d79aa3022fbe8a5527ad597bcf307091 Mon Sep 17 00:00:00 2001 From: "William D. Jones" Date: Wed, 10 Jul 2019 12:05:45 -0400 Subject: [PATCH] dev: Refactor resource abstractions to use Resource.family. --- nmigen_boards/dev/flash.py | 11 +++++++---- nmigen_boards/dev/uart.py | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/nmigen_boards/dev/flash.py b/nmigen_boards/dev/flash.py index 747d239..9cb8d90 100644 --- a/nmigen_boards/dev/flash.py +++ b/nmigen_boards/dev/flash.py @@ -4,7 +4,7 @@ from nmigen.build import * __all__ = ["SPIFlashResources"] -def SPIFlashResources(number, *, cs, clk, mosi, miso, wp=None, hold=None, attrs=None): +def SPIFlashResources(*args, cs, clk, mosi, miso, wp=None, hold=None, attrs=None): resources = [] io_all = [] @@ -19,15 +19,18 @@ def SPIFlashResources(number, *, cs, clk, mosi, miso, wp=None, hold=None, attrs= if wp is not None and hold is not None: io_1x.append(Subsignal("wp", PinsN(wp, dir="o"))) io_1x.append(Subsignal("hold", PinsN(hold, dir="o"))) - resources.append(Resource("spi_flash", number, *io_1x)) + resources.append(Resource.family(*args, default_name="spi_flash", ios=io_1x, + name_suffix="1x")) io_2x = list(io_all) io_2x.append(Subsignal("dq", Pins(" ".join([mosi, miso]), dir="io"))) - resources.append(Resource("spi_flash_2x", number, *io_2x)) + resources.append(Resource.family(*args, default_name="spi_flash", ios=io_2x, + name_suffix="2x")) if wp is not None and hold is not None: io_4x = list(io_all) io_4x.append(Subsignal("dq", Pins(" ".join([mosi, miso, wp, hold]), dir="io"))) - resources.append(Resource("spi_flash_4x", number, *io_4x)) + resources.append(Resource.family(*args, default_name="spi_flash", ios=io_4x, + name_suffix="4x")) return resources diff --git a/nmigen_boards/dev/uart.py b/nmigen_boards/dev/uart.py index 495dbcf..ba2c1b0 100644 --- a/nmigen_boards/dev/uart.py +++ b/nmigen_boards/dev/uart.py @@ -4,7 +4,7 @@ from nmigen.build import * __all__ = ["UARTResource", "IrDAResource"] -def UARTResource(number, *, rx, tx, rts=None, cts=None, dtr=None, dsr=None, dcd=None, ri=None, +def UARTResource(*args, rx, tx, rts=None, cts=None, dtr=None, dsr=None, dcd=None, ri=None, attrs=None): io = [] io.append(Subsignal("rx", Pins(rx, dir="i"))) @@ -23,7 +23,7 @@ def UARTResource(number, *, rx, tx, rts=None, cts=None, dtr=None, dsr=None, dcd= io.append(Subsignal("ri", Pins(ri, dir="i"))) if attrs is not None: io.append(attrs) - return Resource("uart", number, *io) + return Resource.family(*args, default_name="uart", ios=io) def IrDAResource(number, *, rx, tx, en=None, sd=None, attrs=None): -- 2.30.2