MyHDL

Enumerating resources

I am using the following code to help manage my hardware resources.

# output control register bitmap
(   CHANNEL_OUTPUT,
    INPUT0,
    INPUT1,
    INPUT2,
    ACTIVE_STATE,
    *RESERVED) = range(8)

_inputs = (
    INPUT0,
    INPUT1,
    INPUT2) = range(3)

_outputs = (
    OUTPUT0,
    OUTPUT1,
    OUTPUT2,
    OUTPUT3,
    OUTPUT4,
    OUTPUT5,
    OUTPUT6,
    OUTPUT7) = range(8)

This, of course, doesn’t work since I redefine INPUT0, for instance, in the second statement.

Is there a better way to enumerate bit fields and address maps in MyHDL that can keep the names separate as enum does for machine states? Are there better approaches to what I’m doing presently?

from enum import IntEnum

class MyInputs(IntEnum):
    Input0 = 0
    Input1 = 1
    Input2 = 2

   . . .

  SelectedInput = Signal(intbv(0)[2:])

  . . .

  if  SelectedInput == MyInputs.Input0:
       pass

Thank you, @josyb, for your excellent help!