-
I could not find a way to select part of a from amaranth import *
from amaranth.lib import data
from amaranth.lib.enum import Enum
from amaranth.lib.wiring import Component, In, Out
class Kind(Enum, shape=1):
STICK = 0
HIT = 1
LineLayout = data.StructLayout({item.name: unsigned(2) for item in Kind})
class C(Component):
o: Out(unsigned(8))
def elaborate(self, platform):
m = Module()
l = Signal(LineLayout, init={"STICK": 2, "HIT": 1})
k = Signal(Kind)
m.d.sync += self.o.eq(getattr(l, k))
m.d.sync += Print(self.o)
m.d.sync += Print(k)
return m
from amaranth.sim import Period, Simulator
dut = C()
async def bench(ctx):
for _ in range(5):
await ctx.tick()
sim = Simulator(dut)
sim.add_clock(Period())
sim.add_testbench(bench)
sim.run() |
Beta Was this translation helpful? Give feedback.
Answered by
goekce
Apr 28, 2025
Replies: 1 comment 11 replies
-
Try using an |
Beta Was this translation helpful? Give feedback.
11 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using a
SwitchValue
improves readability:edit: the solution uses an internal API function, which may change. Read also the following comments.