Skip to content

Commit 497149e

Browse files
jfngwhitequark
authored andcommitted
platforms/silicon: remove usage of lib.io.Pin (deprecated).
Fixes #19.
1 parent d92258e commit 497149e

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

chipflow_lib/platforms/silicon.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from amaranth import *
99
from amaranth.back import rtlil
1010
from amaranth.hdl import Fragment
11-
from amaranth.lib.io import Pin
11+
from amaranth.lib.io import Direction, Buffer
1212
from amaranth.hdl._ir import PortDirection
1313

1414
from .. import ChipFlowError
@@ -33,11 +33,19 @@ def request(self, name):
3333
if name in self._pins:
3434
raise NameError(f"Pad `{name}` has already been requested")
3535

36-
pin_type = self._pads[name]["type"]
37-
if pin_type == "clk":
38-
pin_type = "i" # `clk` is used for clock tree synthesis, but treated as `i` in frontend
39-
self._pins[name] = Pin(1, dir=pin_type)
40-
return self._pins[name]
36+
pad_type = self._pads[name]["type"]
37+
# `clk` is used for clock tree synthesis, but treated as `i` in frontend
38+
if pad_type in ("i", "clk"):
39+
direction = Direction.Input
40+
elif pad_type in ("o", "oe"):
41+
direction = Direction.Output
42+
elif pad_type == "io":
43+
direction = Direction.Bidir
44+
else:
45+
assert False
46+
47+
self._pins[name] = pin = Buffer.Signature(direction, 1).create(path=(name,))
48+
return pin
4149

4250
def add_file(self, filename, content):
4351
if hasattr(content, "read"):
@@ -65,14 +73,12 @@ def _prepare(self, elaboratable, name="top"):
6573

6674
# Prepare toplevel ports according to chipflow.toml.
6775
ports = []
68-
for pad_name in self._pins:
69-
pad, pin = self._pads[pad_name], self._pins[pad_name]
70-
if pad["type"] in ("io", "i", "clk"):
71-
ports.append((f"io${pad_name}$i", pin.i, PortDirection.Input))
72-
if pad["type"] in ("oe", "io", "o"):
73-
ports.append((f"io${pad_name}$o", pin.o, PortDirection.Output))
74-
if pad["type"] in ("oe", "io"):
75-
ports.append((f"io${pad_name}$oe", pin.oe, PortDirection.Output))
76+
for pin_name, pin in self._pins.items():
77+
if pin.signature.direction in (Direction.Input, Direction.Bidir):
78+
ports.append((f"io${pin_name}$i", pin.i, PortDirection.Input))
79+
if pin.signature.direction in (Direction.Output, Direction.Bidir):
80+
ports.append((f"io${pin_name}$o", pin.o, PortDirection.Output))
81+
ports.append((f"io${pin_name}$oe", pin.oe, PortDirection.Output))
7682

7783
# Prepare design for RTLIL conversion.
7884
return fragment.prepare(ports)

0 commit comments

Comments
 (0)