Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from amaranth import *
- from enum import IntEnum
- class Button(IntEnum):
- A = 0
- B = 1
- class ButtonDevice(Elaboratable):
- """
- Attributes
- ----------
- en : Signal(1), in
- enabled
- buttons : Signal(2), in
- list of button signals - the Button enum has indices
- out : Signal(1), out
- true if both all buttons are set
- ```
- """
- def __init__(self):
- # the `Button` enum contains indices
- self.buttons = Signal(2)
- self.en = Signal()
- self.out = Signal()
- def elaborate(self, platform):
- m = Module()
- # the comb domain is for logic about state which is all i have
- with m.If(self.en):
- m.d.comb += self.out.eq(self.buttons.all())
- # yells at me if i don't do anything on the sync domain
- m.d.sync += self.en.eq(self.en)
- return m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement