Skip to content

Commit 7c17ae6

Browse files
committed
wip
1 parent 91b05de commit 7c17ae6

File tree

2 files changed

+38
-39
lines changed

2 files changed

+38
-39
lines changed

amaranth_orchard/base/gpio.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
class GPIOPins(wiring.PureInterface):
1313
class Signature(wiring.Signature):
1414
def __init__(self, width):
15+
if width > 32:
16+
raise ValueError(f"Pin width must be lesser than or equal to 32, not {len(pins.o)}")
1517
self._width = width
16-
super().__init__({
17-
"o": Out(BidirPinSignature(width)),
18-
})
18+
super().__init__(
19+
# each pin has seperate output enable
20+
{f"gpio{n}":Out(BidirPinSignature(1)) for n in range(width)}
21+
)
1922

2023
@property
2124
def width(self):
@@ -26,6 +29,10 @@ def create(self, *, path=(), src_loc_at=0):
2629

2730
def __init__(self, width, *, path=(), src_loc_at=0):
2831
super().__init__(self.Signature(width), path=path, src_loc_at=1 + src_loc_at)
32+
33+
@property
34+
def width(self):
35+
return self.signature.width
2936

3037

3138
class GPIOPeripheral(wiring.Component):
@@ -49,10 +56,8 @@ def __init__(self, width):
4956
All pins default to input at power up.
5057
"""
5158
def __init__(self, *, name, pins):
52-
if len(pins.o) > 32:
53-
raise ValueError(f"Pin width must be lesser than or equal to 32, not {len(pins.o)}")
5459

55-
self.width = len(pins.o)
60+
self.width = pins.width
5661
self.pins = pins
5762

5863
regs = csr.Builder(addr_width=4, data_width=8, name=name)
@@ -74,10 +79,8 @@ def elaborate(self, platform):
7479

7580
connect(m, flipped(self.bus), self._bridge.bus)
7681

77-
m.d.comb += [
78-
self.pins.o .eq(self._do.f.pins.data),
79-
self.pins.oe.eq(self._oe.f.pins.data),
80-
]
81-
m.d.sync += self._di.f.pins.r_data.eq(self.pins.i)
82+
m.d.comb += [ getattr(self.pins, f"gpio{n}").o.eq(self._do.f.pins.data[n]) for n in range(self.width)]
83+
m.d.comb += [ getattr(self.pins, f"gpio{n}").oe.eq(self._oe.f.pins.data[n]) for n in range(self.width)]
84+
m.d.comb += [ self._di.f.pins.r_data[n].eq(getattr(self.pins, f"gpio{n}").i) for n in range(self.width)]
8285

8386
return m

amaranth_orchard/memory/spimemio.py

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def __init__(self):
1818
super().__init__({
1919
"clk": Out(OutputPinSignature(1)),
2020
"csn": Out(OutputPinSignature(1)),
21-
"d": Out(BidirPinSignature(4)),
22-
})
21+
} |
22+
{f"d{n}": Out(BidirPinSignature(1)) for n in range(4)})
2323

2424
def create(self, *, path=(), src_loc_at=0):
2525
return QSPIPins(path=path, src_loc_at=1 + src_loc_at)
@@ -83,32 +83,28 @@ def elaborate(self, platform):
8383
spi_ready = Signal()
8484
# TODO : QSPI
8585

86-
m.submodules.spimemio = Instance(
87-
"spimemio",
88-
i_clk=ClockSignal(),
89-
i_resetn=~ResetSignal(),
90-
i_valid=self.data_bus.cyc & self.data_bus.stb,
91-
o_ready=spi_ready,
92-
i_addr=Cat(Const(0, 2), self.data_bus.adr), # Hack to force a 1MB offset
93-
o_rdata=self.data_bus.dat_r,
94-
o_flash_csb=self.flash.csn.o,
95-
o_flash_clk=self.flash.clk.o,
96-
o_flash_io0_oe=self.flash.d.oe[0],
97-
o_flash_io1_oe=self.flash.d.oe[1],
98-
o_flash_io2_oe=self.flash.d.oe[2],
99-
o_flash_io3_oe=self.flash.d.oe[3],
100-
o_flash_io0_do=self.flash.d.o[0],
101-
o_flash_io1_do=self.flash.d.o[1],
102-
o_flash_io2_do=self.flash.d.o[2],
103-
o_flash_io3_do=self.flash.d.o[3],
104-
i_flash_io0_di=self.flash.d.i[0],
105-
i_flash_io1_di=self.flash.d.i[1],
106-
i_flash_io2_di=self.flash.d.i[2],
107-
i_flash_io3_di=self.flash.d.i[3],
108-
i_cfgreg_we=ctrl_bridge.cfgreg_we,
109-
i_cfgreg_di=ctrl_bridge.cfgreg_di,
110-
o_cfgreg_do=ctrl_bridge.cfgreg_do,
111-
)
86+
verilog_map = {
87+
"i_clk": ClockSignal(),
88+
"i_resetn": ~ResetSignal(),
89+
"i_valid": self.data_bus.cyc & self.data_bus.stb,
90+
"o_ready": spi_ready,
91+
"i_addr": Cat(Const(0, 2), self.data_bus.adr), # Hack to force a 1MB offset
92+
"o_rdata": self.data_bus.dat_r,
93+
"o_flash_csb": self.flash.csn.o,
94+
"o_flash_clk": self.flash.clk.o,
95+
"i_cfgreg_we": ctrl_bridge.cfgreg_we,
96+
"i_cfgreg_di": ctrl_bridge.cfgreg_di,
97+
"o_cfgreg_do": ctrl_bridge.cfgreg_do,
98+
} | {
99+
f"o_flash_io{n}_oe": getattr(self.flash, f"d{n}").oe for n in range(4)
100+
} | {
101+
f"o_flash_io{n}_o": getattr(self.flash, f"d{n}").o for n in range(4)
102+
} | {
103+
f"o_flash_io{n}_i": getattr(self.flash, f"d{n}").i for n in range(4)
104+
}
105+
106+
m.submodules.spimemio = Instance("spimemio", **verilog_map)
107+
112108
# From https://github.com/im-tomu/foboot/blob/master/hw/rtl/picorvspi.py
113109
read_active = Signal()
114110
with m.If(self.data_bus.stb & self.data_bus.cyc & ~read_active):

0 commit comments

Comments
 (0)