--- /dev/null
+from types import SimpleNamespace
+from nmigen import *
+from nmigen.cli import main
+
+
+class FlatGPIO(Elaboratable):
+ def __init__(self, pins, bus):
+ self.pins = pins
+ self.bus = bus
+
+ def elaborate(self, platform):
+ bus = self.bus
+
+ m = Module()
+ m.d.comb += bus.r_data.eq(self.pins.word_select(bus.addr, len(bus.r_data)))
+ with m.If(bus.we):
+ m.d.sync += self.pins.word_select(bus.addr, len(bus.w_data)).eq(bus.w_data)
+ return m
+
+
+if __name__ == "__main__":
+ bus = Record([
+ ("addr", 3),
+ ("r_data", 2),
+ ("w_data", 2),
+ ("we", 1),
+ ])
+ pins = Signal(8)
+ gpio = FlatGPIO(pins, bus)
+ main(gpio, ports=[pins, bus.addr, bus.r_data, bus.w_data, bus.we])
def on_Part(self, value):
offset = self.s.expand(value.offset)
if isinstance(offset, ast.Const):
- return self(ast.Slice(value.value, offset.value, offset.value + value.width))
+ return self(ast.Slice(value.value,
+ offset.value * value.stride,
+ offset.value * value.stride + value.width))
else:
- raise LegalizeValue(value.offset, range((1 << len(value.offset))), value.src_loc)
+ raise LegalizeValue(value.offset,
+ range((1 << len(value.offset)) // value.stride),
+ value.src_loc)
def on_Repl(self, value):
raise TypeError # :nocov: