Advertisement
Guest User

Untitled

a guest
Apr 8th, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. from amaranth import *
  2. from enum import IntEnum
  3.  
  4. class Button(IntEnum):
  5.     A = 0
  6.     B = 1
  7.  
  8. class ButtonDevice(Elaboratable):
  9.     """
  10.    Attributes
  11.    ----------
  12.    en : Signal(1), in
  13.        enabled
  14.  
  15.    buttons : Signal(2), in
  16.        list of button signals - the Button enum has indices
  17.  
  18.    out : Signal(1), out
  19.        true if both all buttons are set
  20.        ```
  21.    """
  22.     def __init__(self):
  23.         # the `Button` enum contains indices
  24.         self.buttons = Signal(2)
  25.         self.en = Signal()
  26.         self.out = Signal()
  27.  
  28.     def elaborate(self, platform):
  29.         m = Module()
  30.  
  31.         # the comb domain is for logic about state which is all i have
  32.         with m.If(self.en):
  33.             m.d.comb += self.out.eq(self.buttons.all())
  34.  
  35.         # yells at me if i don't do anything on the sync domain
  36.         m.d.sync += self.en.eq(self.en)
  37.  
  38.         return m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement